Skip to content

Instantly share code, notes, and snippets.

View feliche93's full-sized avatar

Felix Vemmer feliche93

View GitHub Profile
@feliche93
feliche93 / attestation.txt
Created April 11, 2022 22:30
Attestation
I contributed to the Semaphore Trusted Setup Multi-Party Ceremony.
The following are my contribution signatures:
Circuit: semaphore17
Contributor # 293
Hash: undefined
Circuit: semaphore16
Contributor # 297
Hash: 553aec2e 09336e08 75a1639b c81d87b7
151430b2 d1e6f37c e08a0abc 17208418
@feliche93
feliche93 / lemon-squeezy.ts
Created June 26, 2023 08:23
Fetch Lemon Squeezy Products
"use server"
import { revalidatePath } from "next/cache";
import { SLemonSqueezyRequest, TLemonSqueezyRequest } from "./zod-lemon-squeezy";
const lemonSqueezyBaseUrl = 'https://api.lemonsqueezy.com/v1';
const lemonSqueezyApiKey = process.env.LEMON_SQUEEZY_API_KEY;
if (!lemonSqueezyApiKey) throw new Error("No LEMON_SQUEEZY_API_KEY environment variable set");
@feliche93
feliche93 / zod-lemon-squeezy.ts
Created June 26, 2023 08:27
Zod Models for Lemon Squeezy Fetching Products Request
import { z } from 'zod';
const SPagination = z.object({
currentPage: z.number(),
from: z.number(),
lastPage: z.number(),
perPage: z.number(),
to: z.number(),
total: z.number(),
});
@feliche93
feliche93 / pricing.tsx
Last active June 26, 2023 08:30
Pricing Table with Lemon Squeezy Data Fetching
import { currentUser } from '@clerk/nextjs'
import { User } from '@clerk/nextjs/dist/types/server'
import { CheckIcon } from '@heroicons/react/20/solid'
import { getProductVariants } from '@lib/lemon-squeezy'
import { cn } from '@lib/utils'
import { JSDOM } from 'jsdom'
import { CheckoutButton } from './checkout-button'
import { Badge } from './ui/badge'
export default async function Pricing({
@feliche93
feliche93 / zod-lemon-squeezy-subscription.ts
Created June 26, 2023 09:00
Models to parse Lemon Squeezy Webhook Request
import { z } from 'zod';
import camelcaseKeys from 'camelcase-keys'
const camelize = <T extends readonly unknown[] | Record<string, unknown>>(
val: T,
) => camelcaseKeys(val)
const Urls = z.object({
update_payment_method: z.string(),
}).transform(camelize);
@feliche93
feliche93 / lemon-squeezy-schema.ts
Created June 26, 2023 09:02
Lemon Squeezy Table Schemas for Drizzle
// declaring enum in database for subscription status
export const subscriptionStatusEnum = pgEnum('subscription_status', [
'on_trial',
'active',
'paused',
'past_due',
'unpaid',
'cancelled',
'expired',
]);
@feliche93
feliche93 / route.ts
Created June 26, 2023 09:04
Route Handler for Lemon Squeezy Subscription Webhook
import crypto from 'crypto';
import { NextResponse } from 'next/server';
import { SLemonSqueezyWebhookRequest } from './models';
import { db } from '@lib/db';
import { subscriptions } from '@schema';
import { eq } from 'drizzle-orm';
import camelcaseKeys from 'camelcase-keys'
import { CamelCasedPropertiesDeep } from 'type-fest' // need CamelCasedPropertiesDeep because of https://github.com/sindresorhus/camelcase-keys/issues/77#issuecomment-1339844470
import { ZodEffects, z } from 'zod';
import PostHogClient from '@lib/posthog';
@feliche93
feliche93 / sync-products-route.ts
Created June 26, 2023 09:08
Route handlers for synching products, product variants and stores
import { NextResponse } from 'next/server';
import { z } from 'zod';
import camelcaseKeys from 'camelcase-keys'
import { db } from '@lib/db';
import { products } from '@schema';
export const runtime = 'edge' // 'nodejs' is the default
const camelize = <T extends readonly unknown[] | Record<string, unknown>>(
@feliche93
feliche93 / lemon-squeezy-server-actions.ts
Created June 26, 2023 09:16
Server Actions to manage lemon squeezy subscriptions
"use server"
import { revalidatePath } from "next/cache";
import { SLemonSqueezyRequest, TLemonSqueezyRequest } from "./zod-lemon-squeezy";
const lemonSqueezyBaseUrl = 'https://api.lemonsqueezy.com/v1';
const lemonSqueezyApiKey = process.env.LEMON_SQUEEZY_API_KEY;
if (!lemonSqueezyApiKey) throw new Error("No LEMON_SQUEEZY_API_KEY environment variable set");
@feliche93
feliche93 / account-button.tsx
Created June 26, 2023 09:19
Account Button to cancel or resume lemon squeezy subscription
'use client'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,