refactor: remove supabase auth
This commit is contained in:
@@ -39,7 +39,7 @@
|
||||
"@kan/db": "workspace:*",
|
||||
"@kan/email": "workspace:^",
|
||||
"@kan/shared": "workspace:^",
|
||||
"@kan/supabase": "workspace:^",
|
||||
"@kan/stripe": "workspace:^",
|
||||
"@trpc/server": "catalog:",
|
||||
"superjson": "2.2.1",
|
||||
"trpc-to-openapi": "^2.1.0",
|
||||
|
||||
@@ -2,12 +2,16 @@ import type { inferRouterInputs, inferRouterOutputs } from "@trpc/server";
|
||||
|
||||
import type { AppRouter } from "./root";
|
||||
import { appRouter } from "./root";
|
||||
import { createCallerFactory, createTRPCContext } from "./trpc";
|
||||
import {
|
||||
createCallerFactory,
|
||||
createNextApiContext,
|
||||
createTRPCContext,
|
||||
} from "./trpc";
|
||||
|
||||
const createCaller = createCallerFactory(appRouter);
|
||||
|
||||
type RouterInputs = inferRouterInputs<AppRouter>;
|
||||
type RouterOutputs = inferRouterOutputs<AppRouter>;
|
||||
|
||||
export { createTRPCContext, appRouter, createCaller };
|
||||
export { createTRPCContext, appRouter, createCaller, createNextApiContext };
|
||||
export type { AppRouter, RouterInputs, RouterOutputs };
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { authRouter } from "./routers/auth";
|
||||
import { boardRouter } from "./routers/board";
|
||||
import { cardRouter } from "./routers/card";
|
||||
import { feedbackRouter } from "./routers/feedback";
|
||||
@@ -11,7 +10,6 @@ import { workspaceRouter } from "./routers/workspace";
|
||||
import { createTRPCRouter } from "./trpc";
|
||||
|
||||
export const appRouter = createTRPCRouter({
|
||||
auth: authRouter,
|
||||
board: boardRouter,
|
||||
card: cardRouter,
|
||||
feedback: feedbackRouter,
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createTRPCRouter, publicProcedure } from "../trpc";
|
||||
|
||||
export const authRouter = createTRPCRouter({
|
||||
loginWithEmail: publicProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: "POST",
|
||||
path: "/auth/login/email",
|
||||
summary: "Login with email",
|
||||
description: "Sends a login URL to the provided email address",
|
||||
tags: ["Auth"],
|
||||
},
|
||||
})
|
||||
.input(z.object({ email: z.string() }))
|
||||
.output(z.object({ success: z.boolean() }))
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const { data } = await ctx.supabaseClient.auth.signInWithOtp({
|
||||
email: input.email,
|
||||
options: {
|
||||
emailRedirectTo: `${process.env.WEBSITE_URL}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (!data)
|
||||
throw new TRPCError({
|
||||
message: `Failed to login with email`,
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
});
|
||||
|
||||
return { success: true };
|
||||
}),
|
||||
loginWithOAuth: publicProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: "POST",
|
||||
path: "/auth/login/oauth",
|
||||
summary: "Login with OAuth",
|
||||
description:
|
||||
"Initiates the login process for a user with the given OAuth provider",
|
||||
tags: ["Auth"],
|
||||
},
|
||||
})
|
||||
.input(z.object({ provider: z.string() }))
|
||||
.output(z.object({ url: z.string() }))
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
if (input.provider !== "google")
|
||||
throw new TRPCError({
|
||||
message: `Unsupported OAuth provider: ${input.provider}`,
|
||||
code: "BAD_REQUEST",
|
||||
});
|
||||
|
||||
const { data } = await ctx.supabaseClient.auth.signInWithOAuth({
|
||||
provider: "google",
|
||||
options: {
|
||||
queryParams: {
|
||||
access_type: "offline",
|
||||
prompt: "consent",
|
||||
},
|
||||
redirectTo: `${process.env.WEBSITE_URL}/api/auth/confirm`,
|
||||
},
|
||||
});
|
||||
|
||||
if (!data.url)
|
||||
throw new TRPCError({
|
||||
message: `Failed to login with OAuth`,
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
});
|
||||
|
||||
return { url: data.url };
|
||||
}),
|
||||
});
|
||||
@@ -1,24 +1,14 @@
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { Stripe } from "stripe";
|
||||
import { z } from "zod";
|
||||
|
||||
import * as memberRepo from "@kan/db/repository/member.repo";
|
||||
import * as userRepo from "@kan/db/repository/user.repo";
|
||||
import * as workspaceRepo from "@kan/db/repository/workspace.repo";
|
||||
import { sendEmail } from "@kan/email";
|
||||
import { createStripeClient } from "@kan/stripe";
|
||||
|
||||
import { createTRPCRouter, protectedProcedure } from "../trpc";
|
||||
|
||||
const stripeSecretKey = process.env.STRIPE_SECRET_KEY;
|
||||
|
||||
if (!stripeSecretKey) {
|
||||
throw new Error("STRIPE_SECRET_KEY is not defined");
|
||||
}
|
||||
|
||||
const stripe = new Stripe(stripeSecretKey, {
|
||||
apiVersion: "2024-12-18.acacia",
|
||||
});
|
||||
|
||||
export const memberRouter = createTRPCRouter({
|
||||
invite: protectedProcedure
|
||||
.meta({
|
||||
@@ -75,57 +65,57 @@ export const memberRouter = createTRPCRouter({
|
||||
|
||||
const existingUser = await userRepo.getByEmail(ctx.db, input.email);
|
||||
|
||||
if (existingUser) {
|
||||
invitedUserId = existingUser.id;
|
||||
// if (existingUser) {
|
||||
// invitedUserId = existingUser.id;
|
||||
|
||||
const magicLink = await ctx.supabaseClient.auth.admin.generateLink({
|
||||
type: "magiclink",
|
||||
email: input.email,
|
||||
options: {
|
||||
redirectTo: process.env.WEBSITE_URL,
|
||||
},
|
||||
});
|
||||
// const magicLink = await ctx.supabaseClient.auth.admin.generateLink({
|
||||
// type: "magiclink",
|
||||
// email: input.email,
|
||||
// options: {
|
||||
// redirectTo: process.env.WEBSITE_URL,
|
||||
// },
|
||||
// });
|
||||
|
||||
hashedToken = magicLink.data.properties?.hashed_token;
|
||||
verificationType = magicLink.data.properties?.verification_type;
|
||||
} else {
|
||||
const invite = await ctx.supabaseClient.auth.admin.generateLink({
|
||||
type: "invite",
|
||||
email: input.email,
|
||||
options: {
|
||||
redirectTo: process.env.WEBSITE_URL,
|
||||
},
|
||||
});
|
||||
// hashedToken = magicLink.data.properties?.hashed_token;
|
||||
// verificationType = magicLink.data.properties?.verification_type;
|
||||
// } else {
|
||||
// const invite = await ctx.supabaseClient.auth.admin.generateLink({
|
||||
// type: "invite",
|
||||
// email: input.email,
|
||||
// options: {
|
||||
// redirectTo: process.env.WEBSITE_URL,
|
||||
// },
|
||||
// });
|
||||
|
||||
hashedToken = invite.data.properties?.hashed_token;
|
||||
verificationType = invite.data.properties?.verification_type;
|
||||
// hashedToken = invite.data.properties?.hashed_token;
|
||||
// verificationType = invite.data.properties?.verification_type;
|
||||
|
||||
const invitedUserAuthId = invite.data.user?.id;
|
||||
const invitedUserEmail = invite.data.user?.email;
|
||||
// const invitedUserAuthId = invite.data.user?.id;
|
||||
// const invitedUserEmail = invite.data.user?.email;
|
||||
|
||||
if (invitedUserAuthId && invitedUserEmail) {
|
||||
const stripeCustomer = await stripe.customers.create({
|
||||
email: invitedUserEmail,
|
||||
metadata: {
|
||||
userId: invitedUserAuthId,
|
||||
},
|
||||
});
|
||||
// if (invitedUserAuthId && invitedUserEmail) {
|
||||
// const stripeCustomer = await stripe.customers.create({
|
||||
// email: invitedUserEmail,
|
||||
// metadata: {
|
||||
// userId: invitedUserAuthId,
|
||||
// },
|
||||
// });
|
||||
|
||||
const newUser = await userRepo.create(ctx.db, {
|
||||
email: invitedUserEmail,
|
||||
id: invitedUserAuthId,
|
||||
stripeCustomerId: stripeCustomer.id,
|
||||
});
|
||||
// const newUser = await userRepo.create(ctx.db, {
|
||||
// email: invitedUserEmail,
|
||||
// id: invitedUserAuthId,
|
||||
// stripeCustomerId: stripeCustomer.id,
|
||||
// });
|
||||
|
||||
if (!newUser)
|
||||
throw new TRPCError({
|
||||
message: `Failed to create a new user for email ${invitedUserEmail}`,
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
});
|
||||
// if (!newUser)
|
||||
// throw new TRPCError({
|
||||
// message: `Failed to create a new user for email ${invitedUserEmail}`,
|
||||
// code: "INTERNAL_SERVER_ERROR",
|
||||
// });
|
||||
|
||||
invitedUserId = newUser.id;
|
||||
}
|
||||
}
|
||||
// invitedUserId = newUser.id;
|
||||
// }
|
||||
// }
|
||||
|
||||
if (!invitedUserId)
|
||||
throw new TRPCError({
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { FetchCreateContextFnOptions } from "@trpc/server/adapters/fetch";
|
||||
import type { CreateNextContextOptions } from "@trpc/server/adapters/next";
|
||||
import type { NextRequest } from "next/server";
|
||||
import type { OpenApiMeta } from "trpc-to-openapi";
|
||||
import { initTRPC, TRPCError } from "@trpc/server";
|
||||
import superjson from "superjson";
|
||||
@@ -44,6 +45,16 @@ export const createTRPCContext = async ({
|
||||
return createInnerTRPCContext({ db, user: session?.user });
|
||||
};
|
||||
|
||||
export const createNextApiContext = async (req: NextRequest) => {
|
||||
const session = await auth.api.getSession({
|
||||
headers: req.headers,
|
||||
});
|
||||
|
||||
const db = createDrizzleClient();
|
||||
|
||||
return createInnerTRPCContext({ db, user: session?.user });
|
||||
};
|
||||
|
||||
export const createRESTContext = async ({ req }: CreateNextContextOptions) => {
|
||||
const authHeader = req.headers.authorization;
|
||||
const accessToken = authHeader?.startsWith("Bearer ")
|
||||
@@ -57,7 +68,8 @@ export const createRESTContext = async ({ req }: CreateNextContextOptions) => {
|
||||
}
|
||||
|
||||
const session = await auth.api.getSession({
|
||||
headers: req.headers,
|
||||
// @ts-expect-error
|
||||
headers: new Headers(req.headers),
|
||||
});
|
||||
|
||||
return createInnerTRPCContext({ db, user: session?.user });
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kan/db": "workspace:*",
|
||||
"@kan/email": "workspace:*",
|
||||
"@kan/eslint-config": "workspace:*",
|
||||
"@kan/prettier-config": "workspace:*",
|
||||
"@kan/shared": "workspace:*",
|
||||
"@kan/stripe": "workspace:*",
|
||||
"@kan/tsconfig": "workspace:*",
|
||||
"eslint": "catalog:",
|
||||
"prettier": "catalog:",
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { betterAuth } from "better-auth";
|
||||
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
||||
import { createAuthMiddleware } from "better-auth/api";
|
||||
import { apiKey } from "better-auth/plugins";
|
||||
import { magicLink } from "better-auth/plugins/magic-link";
|
||||
|
||||
import { createDrizzleClient } from "@kan/db/client";
|
||||
import * as userRepo from "@kan/db/repository/user.repo";
|
||||
import * as schema from "@kan/db/schema";
|
||||
import { sendEmail } from "@kan/email";
|
||||
import { createStripeClient } from "@kan/stripe";
|
||||
|
||||
const db = createDrizzleClient();
|
||||
|
||||
@@ -38,11 +42,36 @@ export const auth = betterAuth({
|
||||
plugins: [
|
||||
apiKey(),
|
||||
magicLink({
|
||||
sendMagicLink: async ({ email, token, url }, request) => {
|
||||
// send email to user
|
||||
sendMagicLink: async ({ email, url }) => {
|
||||
await sendEmail(email, "Sign in to kan.bn", "MAGIC_LINK", {
|
||||
magicLoginUrl: url,
|
||||
});
|
||||
},
|
||||
}),
|
||||
],
|
||||
hooks: {
|
||||
// after: createAuthMiddleware(async (ctx) => {
|
||||
// if (ctx.path.startsWith("/sign-up") || ctx.path.startsWith("/sign-in")) {
|
||||
// const session = ctx.context.session;
|
||||
// if (
|
||||
// session &&
|
||||
// process.env.NEXT_PUBLIC_KAN_ENV === "cloud" &&
|
||||
// !session.user.stripeCustomerId
|
||||
// ) {
|
||||
// const stripe = createStripeClient();
|
||||
// const stripeCustomer = await stripe.customers.create({
|
||||
// email: session.user.email,
|
||||
// metadata: {
|
||||
// userId: session.user.id,
|
||||
// },
|
||||
// });
|
||||
// await userRepo.update(db, session.user.id, {
|
||||
// stripeCustomerId: stripeCustomer.id,
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }),
|
||||
},
|
||||
advanced: {
|
||||
cookiePrefix: "kan",
|
||||
database: {
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import { magicLinkClient } from "better-auth/client/plugins";
|
||||
import { createAuthClient } from "better-auth/react";
|
||||
|
||||
export const authClient = createAuthClient();
|
||||
export const authClient = createAuthClient({
|
||||
plugins: [magicLinkClient()],
|
||||
});
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import type { SupabaseClient } from "@supabase/supabase-js";
|
||||
import { and, asc, desc, eq, gt, inArray, isNull, sql } from "drizzle-orm";
|
||||
|
||||
import type { dbClient } from "@kan/db/client";
|
||||
import type { Database } from "@kan/db/types/database.types";
|
||||
import {
|
||||
cardActivities,
|
||||
cards,
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import type { SupabaseClient } from "@supabase/supabase-js";
|
||||
import { and, desc, eq, gt, isNull, sql } from "drizzle-orm";
|
||||
|
||||
import type { dbClient } from "@kan/db/client";
|
||||
import type { Database } from "@kan/db/types/database.types";
|
||||
import { lists } from "@kan/db/schema";
|
||||
import { generateUID } from "@kan/shared/utils";
|
||||
|
||||
|
||||
@@ -47,18 +47,20 @@ export const create = async (
|
||||
export const update = async (
|
||||
db: dbClient,
|
||||
userId: string,
|
||||
updates: { image?: string; name?: string },
|
||||
updates: { image?: string; name?: string; stripeCustomerId?: string },
|
||||
) => {
|
||||
const [result] = await db
|
||||
.update(users)
|
||||
.set({
|
||||
name: updates.name,
|
||||
image: updates.image,
|
||||
stripeCustomerId: updates.stripeCustomerId,
|
||||
})
|
||||
.where(eq(users.id, userId))
|
||||
.returning({
|
||||
name: users.name,
|
||||
image: users.image,
|
||||
stripeCustomerId: users.stripeCustomerId,
|
||||
});
|
||||
|
||||
return result;
|
||||
|
||||
@@ -1,940 +0,0 @@
|
||||
export type Json =
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| null
|
||||
| { [key: string]: Json | undefined }
|
||||
| Json[]
|
||||
|
||||
export type Database = {
|
||||
public: {
|
||||
Tables: {
|
||||
_card_labels: {
|
||||
Row: {
|
||||
cardId: number
|
||||
labelId: number
|
||||
}
|
||||
Insert: {
|
||||
cardId: number
|
||||
labelId: number
|
||||
}
|
||||
Update: {
|
||||
cardId?: number
|
||||
labelId?: number
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "_card_labels_cardId_card_id_fk"
|
||||
columns: ["cardId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "card"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "_card_labels_labelId_label_id_fk"
|
||||
columns: ["labelId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "label"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
]
|
||||
}
|
||||
_card_workspace_members: {
|
||||
Row: {
|
||||
cardId: number
|
||||
workspaceMemberId: number
|
||||
}
|
||||
Insert: {
|
||||
cardId: number
|
||||
workspaceMemberId: number
|
||||
}
|
||||
Update: {
|
||||
cardId?: number
|
||||
workspaceMemberId?: number
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "_card_workspace_members_cardId_card_id_fk"
|
||||
columns: ["cardId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "card"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "_card_workspace_members_workspaceMemberId_workspace_members_id_"
|
||||
columns: ["workspaceMemberId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "workspace_members"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
]
|
||||
}
|
||||
board: {
|
||||
Row: {
|
||||
createdAt: string
|
||||
createdBy: string
|
||||
deletedAt: string | null
|
||||
deletedBy: string | null
|
||||
description: string | null
|
||||
id: number
|
||||
importId: number | null
|
||||
name: string
|
||||
publicId: string
|
||||
slug: string
|
||||
updatedAt: string | null
|
||||
visibility: Database["public"]["Enums"]["board_visibility"]
|
||||
workspaceId: number
|
||||
}
|
||||
Insert: {
|
||||
createdAt?: string
|
||||
createdBy: string
|
||||
deletedAt?: string | null
|
||||
deletedBy?: string | null
|
||||
description?: string | null
|
||||
id?: number
|
||||
importId?: number | null
|
||||
name: string
|
||||
publicId: string
|
||||
slug: string
|
||||
updatedAt?: string | null
|
||||
visibility?: Database["public"]["Enums"]["board_visibility"]
|
||||
workspaceId: number
|
||||
}
|
||||
Update: {
|
||||
createdAt?: string
|
||||
createdBy?: string
|
||||
deletedAt?: string | null
|
||||
deletedBy?: string | null
|
||||
description?: string | null
|
||||
id?: number
|
||||
importId?: number | null
|
||||
name?: string
|
||||
publicId?: string
|
||||
slug?: string
|
||||
updatedAt?: string | null
|
||||
visibility?: Database["public"]["Enums"]["board_visibility"]
|
||||
workspaceId?: number
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "board_createdBy_user_id_fk"
|
||||
columns: ["createdBy"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "board_deletedBy_user_id_fk"
|
||||
columns: ["deletedBy"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "board_importId_import_id_fk"
|
||||
columns: ["importId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "import"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "board_workspaceId_workspace_id_fk"
|
||||
columns: ["workspaceId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "workspace"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
]
|
||||
}
|
||||
card: {
|
||||
Row: {
|
||||
createdAt: string
|
||||
createdBy: string
|
||||
deletedAt: string | null
|
||||
deletedBy: string | null
|
||||
description: string | null
|
||||
id: number
|
||||
importId: number | null
|
||||
index: number
|
||||
listId: number
|
||||
publicId: string
|
||||
title: string
|
||||
updatedAt: string | null
|
||||
}
|
||||
Insert: {
|
||||
createdAt?: string
|
||||
createdBy: string
|
||||
deletedAt?: string | null
|
||||
deletedBy?: string | null
|
||||
description?: string | null
|
||||
id?: number
|
||||
importId?: number | null
|
||||
index: number
|
||||
listId: number
|
||||
publicId: string
|
||||
title: string
|
||||
updatedAt?: string | null
|
||||
}
|
||||
Update: {
|
||||
createdAt?: string
|
||||
createdBy?: string
|
||||
deletedAt?: string | null
|
||||
deletedBy?: string | null
|
||||
description?: string | null
|
||||
id?: number
|
||||
importId?: number | null
|
||||
index?: number
|
||||
listId?: number
|
||||
publicId?: string
|
||||
title?: string
|
||||
updatedAt?: string | null
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "card_createdBy_user_id_fk"
|
||||
columns: ["createdBy"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "card_deletedBy_user_id_fk"
|
||||
columns: ["deletedBy"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "card_importId_import_id_fk"
|
||||
columns: ["importId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "import"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "card_listId_list_id_fk"
|
||||
columns: ["listId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "list"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
]
|
||||
}
|
||||
card_activity: {
|
||||
Row: {
|
||||
cardId: number
|
||||
commentId: number | null
|
||||
createdAt: string
|
||||
createdBy: string
|
||||
fromComment: string | null
|
||||
fromDescription: string | null
|
||||
fromIndex: number | null
|
||||
fromListId: number | null
|
||||
fromTitle: string | null
|
||||
id: number
|
||||
labelId: number | null
|
||||
publicId: string
|
||||
toComment: string | null
|
||||
toDescription: string | null
|
||||
toIndex: number | null
|
||||
toListId: number | null
|
||||
toTitle: string | null
|
||||
type: Database["public"]["Enums"]["card_activity_type"]
|
||||
workspaceMemberId: number | null
|
||||
}
|
||||
Insert: {
|
||||
cardId: number
|
||||
commentId?: number | null
|
||||
createdAt?: string
|
||||
createdBy: string
|
||||
fromComment?: string | null
|
||||
fromDescription?: string | null
|
||||
fromIndex?: number | null
|
||||
fromListId?: number | null
|
||||
fromTitle?: string | null
|
||||
id?: number
|
||||
labelId?: number | null
|
||||
publicId: string
|
||||
toComment?: string | null
|
||||
toDescription?: string | null
|
||||
toIndex?: number | null
|
||||
toListId?: number | null
|
||||
toTitle?: string | null
|
||||
type: Database["public"]["Enums"]["card_activity_type"]
|
||||
workspaceMemberId?: number | null
|
||||
}
|
||||
Update: {
|
||||
cardId?: number
|
||||
commentId?: number | null
|
||||
createdAt?: string
|
||||
createdBy?: string
|
||||
fromComment?: string | null
|
||||
fromDescription?: string | null
|
||||
fromIndex?: number | null
|
||||
fromListId?: number | null
|
||||
fromTitle?: string | null
|
||||
id?: number
|
||||
labelId?: number | null
|
||||
publicId?: string
|
||||
toComment?: string | null
|
||||
toDescription?: string | null
|
||||
toIndex?: number | null
|
||||
toListId?: number | null
|
||||
toTitle?: string | null
|
||||
type?: Database["public"]["Enums"]["card_activity_type"]
|
||||
workspaceMemberId?: number | null
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "card_activity_cardId_card_id_fk"
|
||||
columns: ["cardId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "card"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "card_activity_commentId_card_comments_id_fk"
|
||||
columns: ["commentId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "card_comments"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "card_activity_createdBy_user_id_fk"
|
||||
columns: ["createdBy"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "card_activity_fromListId_list_id_fk"
|
||||
columns: ["fromListId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "list"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "card_activity_labelId_label_id_fk"
|
||||
columns: ["labelId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "label"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "card_activity_toListId_list_id_fk"
|
||||
columns: ["toListId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "list"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "card_activity_workspaceMemberId_workspace_members_id_fk"
|
||||
columns: ["workspaceMemberId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "workspace_members"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
]
|
||||
}
|
||||
card_comments: {
|
||||
Row: {
|
||||
cardId: number
|
||||
comment: string
|
||||
createdAt: string
|
||||
createdBy: string
|
||||
deletedAt: string | null
|
||||
deletedBy: string | null
|
||||
id: number
|
||||
publicId: string
|
||||
updatedAt: string | null
|
||||
}
|
||||
Insert: {
|
||||
cardId: number
|
||||
comment: string
|
||||
createdAt?: string
|
||||
createdBy: string
|
||||
deletedAt?: string | null
|
||||
deletedBy?: string | null
|
||||
id?: number
|
||||
publicId: string
|
||||
updatedAt?: string | null
|
||||
}
|
||||
Update: {
|
||||
cardId?: number
|
||||
comment?: string
|
||||
createdAt?: string
|
||||
createdBy?: string
|
||||
deletedAt?: string | null
|
||||
deletedBy?: string | null
|
||||
id?: number
|
||||
publicId?: string
|
||||
updatedAt?: string | null
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "card_comments_cardId_card_id_fk"
|
||||
columns: ["cardId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "card"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "card_comments_createdBy_user_id_fk"
|
||||
columns: ["createdBy"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "card_comments_deletedBy_user_id_fk"
|
||||
columns: ["deletedBy"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
]
|
||||
}
|
||||
feedback: {
|
||||
Row: {
|
||||
createdAt: string
|
||||
createdBy: string
|
||||
feedback: string
|
||||
id: number
|
||||
reviewed: boolean
|
||||
updatedAt: string | null
|
||||
url: string
|
||||
}
|
||||
Insert: {
|
||||
createdAt?: string
|
||||
createdBy: string
|
||||
feedback: string
|
||||
id?: number
|
||||
reviewed?: boolean
|
||||
updatedAt?: string | null
|
||||
url: string
|
||||
}
|
||||
Update: {
|
||||
createdAt?: string
|
||||
createdBy?: string
|
||||
feedback?: string
|
||||
id?: number
|
||||
reviewed?: boolean
|
||||
updatedAt?: string | null
|
||||
url?: string
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "feedback_createdBy_user_id_fk"
|
||||
columns: ["createdBy"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
]
|
||||
}
|
||||
import: {
|
||||
Row: {
|
||||
createdAt: string
|
||||
createdBy: string
|
||||
id: number
|
||||
publicId: string
|
||||
source: Database["public"]["Enums"]["source"]
|
||||
status: Database["public"]["Enums"]["status"]
|
||||
}
|
||||
Insert: {
|
||||
createdAt?: string
|
||||
createdBy: string
|
||||
id?: number
|
||||
publicId: string
|
||||
source: Database["public"]["Enums"]["source"]
|
||||
status: Database["public"]["Enums"]["status"]
|
||||
}
|
||||
Update: {
|
||||
createdAt?: string
|
||||
createdBy?: string
|
||||
id?: number
|
||||
publicId?: string
|
||||
source?: Database["public"]["Enums"]["source"]
|
||||
status?: Database["public"]["Enums"]["status"]
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "import_createdBy_user_id_fk"
|
||||
columns: ["createdBy"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
]
|
||||
}
|
||||
label: {
|
||||
Row: {
|
||||
boardId: number
|
||||
colourCode: string | null
|
||||
createdAt: string
|
||||
createdBy: string
|
||||
id: number
|
||||
importId: number | null
|
||||
name: string
|
||||
publicId: string
|
||||
updatedAt: string | null
|
||||
}
|
||||
Insert: {
|
||||
boardId: number
|
||||
colourCode?: string | null
|
||||
createdAt?: string
|
||||
createdBy: string
|
||||
id?: number
|
||||
importId?: number | null
|
||||
name: string
|
||||
publicId: string
|
||||
updatedAt?: string | null
|
||||
}
|
||||
Update: {
|
||||
boardId?: number
|
||||
colourCode?: string | null
|
||||
createdAt?: string
|
||||
createdBy?: string
|
||||
id?: number
|
||||
importId?: number | null
|
||||
name?: string
|
||||
publicId?: string
|
||||
updatedAt?: string | null
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "label_boardId_board_id_fk"
|
||||
columns: ["boardId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "board"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "label_createdBy_user_id_fk"
|
||||
columns: ["createdBy"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "label_importId_import_id_fk"
|
||||
columns: ["importId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "import"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
]
|
||||
}
|
||||
list: {
|
||||
Row: {
|
||||
boardId: number
|
||||
createdAt: string
|
||||
createdBy: string
|
||||
deletedAt: string | null
|
||||
deletedBy: string | null
|
||||
id: number
|
||||
importId: number | null
|
||||
index: number
|
||||
name: string
|
||||
publicId: string
|
||||
updatedAt: string | null
|
||||
}
|
||||
Insert: {
|
||||
boardId: number
|
||||
createdAt?: string
|
||||
createdBy: string
|
||||
deletedAt?: string | null
|
||||
deletedBy?: string | null
|
||||
id?: number
|
||||
importId?: number | null
|
||||
index: number
|
||||
name: string
|
||||
publicId: string
|
||||
updatedAt?: string | null
|
||||
}
|
||||
Update: {
|
||||
boardId?: number
|
||||
createdAt?: string
|
||||
createdBy?: string
|
||||
deletedAt?: string | null
|
||||
deletedBy?: string | null
|
||||
id?: number
|
||||
importId?: number | null
|
||||
index?: number
|
||||
name?: string
|
||||
publicId?: string
|
||||
updatedAt?: string | null
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "list_boardId_board_id_fk"
|
||||
columns: ["boardId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "board"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "list_createdBy_user_id_fk"
|
||||
columns: ["createdBy"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "list_deletedBy_user_id_fk"
|
||||
columns: ["deletedBy"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "list_importId_import_id_fk"
|
||||
columns: ["importId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "import"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
]
|
||||
}
|
||||
user: {
|
||||
Row: {
|
||||
email: string
|
||||
emailVerified: string | null
|
||||
id: string
|
||||
image: string | null
|
||||
name: string | null
|
||||
stripeCustomerId: string | null
|
||||
}
|
||||
Insert: {
|
||||
email: string
|
||||
emailVerified?: string | null
|
||||
id: string
|
||||
image?: string | null
|
||||
name?: string | null
|
||||
stripeCustomerId?: string | null
|
||||
}
|
||||
Update: {
|
||||
email?: string
|
||||
emailVerified?: string | null
|
||||
id?: string
|
||||
image?: string | null
|
||||
name?: string | null
|
||||
stripeCustomerId?: string | null
|
||||
}
|
||||
Relationships: []
|
||||
}
|
||||
workspace: {
|
||||
Row: {
|
||||
createdAt: string
|
||||
createdBy: string
|
||||
deletedAt: string | null
|
||||
deletedBy: string | null
|
||||
description: string | null
|
||||
id: number
|
||||
name: string
|
||||
plan: Database["public"]["Enums"]["workspace_plan"]
|
||||
publicId: string
|
||||
slug: string
|
||||
updatedAt: string | null
|
||||
}
|
||||
Insert: {
|
||||
createdAt?: string
|
||||
createdBy: string
|
||||
deletedAt?: string | null
|
||||
deletedBy?: string | null
|
||||
description?: string | null
|
||||
id?: number
|
||||
name: string
|
||||
plan?: Database["public"]["Enums"]["workspace_plan"]
|
||||
publicId: string
|
||||
slug: string
|
||||
updatedAt?: string | null
|
||||
}
|
||||
Update: {
|
||||
createdAt?: string
|
||||
createdBy?: string
|
||||
deletedAt?: string | null
|
||||
deletedBy?: string | null
|
||||
description?: string | null
|
||||
id?: number
|
||||
name?: string
|
||||
plan?: Database["public"]["Enums"]["workspace_plan"]
|
||||
publicId?: string
|
||||
slug?: string
|
||||
updatedAt?: string | null
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "workspace_createdBy_user_id_fk"
|
||||
columns: ["createdBy"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "workspace_deletedBy_user_id_fk"
|
||||
columns: ["deletedBy"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
]
|
||||
}
|
||||
workspace_members: {
|
||||
Row: {
|
||||
createdAt: string
|
||||
createdBy: string
|
||||
deletedAt: string | null
|
||||
deletedBy: string | null
|
||||
id: number
|
||||
publicId: string
|
||||
role: Database["public"]["Enums"]["role"]
|
||||
status: Database["public"]["Enums"]["member_status"]
|
||||
updatedAt: string | null
|
||||
userId: string
|
||||
workspaceId: number
|
||||
}
|
||||
Insert: {
|
||||
createdAt?: string
|
||||
createdBy: string
|
||||
deletedAt?: string | null
|
||||
deletedBy?: string | null
|
||||
id?: number
|
||||
publicId: string
|
||||
role: Database["public"]["Enums"]["role"]
|
||||
status?: Database["public"]["Enums"]["member_status"]
|
||||
updatedAt?: string | null
|
||||
userId: string
|
||||
workspaceId: number
|
||||
}
|
||||
Update: {
|
||||
createdAt?: string
|
||||
createdBy?: string
|
||||
deletedAt?: string | null
|
||||
deletedBy?: string | null
|
||||
id?: number
|
||||
publicId?: string
|
||||
role?: Database["public"]["Enums"]["role"]
|
||||
status?: Database["public"]["Enums"]["member_status"]
|
||||
updatedAt?: string | null
|
||||
userId?: string
|
||||
workspaceId?: number
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "workspace_members_deletedBy_user_id_fk"
|
||||
columns: ["deletedBy"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "workspace_members_userId_user_id_fk"
|
||||
columns: ["userId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "user"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "workspace_members_workspaceId_workspace_id_fk"
|
||||
columns: ["workspaceId"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "workspace"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
]
|
||||
}
|
||||
workspace_slugs: {
|
||||
Row: {
|
||||
slug: string
|
||||
type: Database["public"]["Enums"]["slug_type"]
|
||||
}
|
||||
Insert: {
|
||||
slug: string
|
||||
type: Database["public"]["Enums"]["slug_type"]
|
||||
}
|
||||
Update: {
|
||||
slug?: string
|
||||
type?: Database["public"]["Enums"]["slug_type"]
|
||||
}
|
||||
Relationships: []
|
||||
}
|
||||
}
|
||||
Views: {
|
||||
[_ in never]: never
|
||||
}
|
||||
Functions: {
|
||||
is_workspace_admin: {
|
||||
Args: {
|
||||
user_id: string
|
||||
workspace_id: number
|
||||
}
|
||||
Returns: boolean
|
||||
}
|
||||
push_card_index: {
|
||||
Args: {
|
||||
list_id: number
|
||||
card_index: number
|
||||
}
|
||||
Returns: undefined
|
||||
}
|
||||
reorder_cards: {
|
||||
Args: {
|
||||
card_id: number
|
||||
current_list_id: number
|
||||
new_list_id: number
|
||||
current_index: number
|
||||
new_index: number
|
||||
}
|
||||
Returns: boolean
|
||||
}
|
||||
reorder_lists: {
|
||||
Args: {
|
||||
board_id: number
|
||||
list_id: number
|
||||
current_index: number
|
||||
new_index: number
|
||||
}
|
||||
Returns: boolean
|
||||
}
|
||||
shift_card_index: {
|
||||
Args: {
|
||||
list_id: number
|
||||
card_index: number
|
||||
}
|
||||
Returns: undefined
|
||||
}
|
||||
shift_list_index: {
|
||||
Args: {
|
||||
board_id: number
|
||||
list_index: number
|
||||
}
|
||||
Returns: undefined
|
||||
}
|
||||
}
|
||||
Enums: {
|
||||
board_visibility: "private" | "public"
|
||||
card_activity_type:
|
||||
| "card.created"
|
||||
| "card.updated.title"
|
||||
| "card.updated.description"
|
||||
| "card.updated.index"
|
||||
| "card.updated.list"
|
||||
| "card.updated.label.added"
|
||||
| "card.updated.label.removed"
|
||||
| "card.updated.member.added"
|
||||
| "card.updated.member.removed"
|
||||
| "card.archived"
|
||||
| "card.updated.comment.added"
|
||||
| "card.updated.comment.updated"
|
||||
| "card.updated.comment.deleted"
|
||||
member_status: "invited" | "active" | "removed"
|
||||
role: "admin" | "member" | "guest"
|
||||
slug_type: "reserved" | "premium"
|
||||
source: "trello"
|
||||
status: "started" | "success" | "failed"
|
||||
workspace_invite_status: "pending" | "accepted" | "cancelled"
|
||||
workspace_plan: "free" | "pro" | "enterprise"
|
||||
}
|
||||
CompositeTypes: {
|
||||
[_ in never]: never
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type PublicSchema = Database[Extract<keyof Database, "public">]
|
||||
|
||||
export type Tables<
|
||||
PublicTableNameOrOptions extends
|
||||
| keyof (PublicSchema["Tables"] & PublicSchema["Views"])
|
||||
| { schema: keyof Database },
|
||||
TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
|
||||
? keyof (Database[PublicTableNameOrOptions["schema"]]["Tables"] &
|
||||
Database[PublicTableNameOrOptions["schema"]]["Views"])
|
||||
: never = never,
|
||||
> = PublicTableNameOrOptions extends { schema: keyof Database }
|
||||
? (Database[PublicTableNameOrOptions["schema"]]["Tables"] &
|
||||
Database[PublicTableNameOrOptions["schema"]]["Views"])[TableName] extends {
|
||||
Row: infer R
|
||||
}
|
||||
? R
|
||||
: never
|
||||
: PublicTableNameOrOptions extends keyof (PublicSchema["Tables"] &
|
||||
PublicSchema["Views"])
|
||||
? (PublicSchema["Tables"] &
|
||||
PublicSchema["Views"])[PublicTableNameOrOptions] extends {
|
||||
Row: infer R
|
||||
}
|
||||
? R
|
||||
: never
|
||||
: never
|
||||
|
||||
export type TablesInsert<
|
||||
PublicTableNameOrOptions extends
|
||||
| keyof PublicSchema["Tables"]
|
||||
| { schema: keyof Database },
|
||||
TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
|
||||
? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"]
|
||||
: never = never,
|
||||
> = PublicTableNameOrOptions extends { schema: keyof Database }
|
||||
? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends {
|
||||
Insert: infer I
|
||||
}
|
||||
? I
|
||||
: never
|
||||
: PublicTableNameOrOptions extends keyof PublicSchema["Tables"]
|
||||
? PublicSchema["Tables"][PublicTableNameOrOptions] extends {
|
||||
Insert: infer I
|
||||
}
|
||||
? I
|
||||
: never
|
||||
: never
|
||||
|
||||
export type TablesUpdate<
|
||||
PublicTableNameOrOptions extends
|
||||
| keyof PublicSchema["Tables"]
|
||||
| { schema: keyof Database },
|
||||
TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
|
||||
? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"]
|
||||
: never = never,
|
||||
> = PublicTableNameOrOptions extends { schema: keyof Database }
|
||||
? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends {
|
||||
Update: infer U
|
||||
}
|
||||
? U
|
||||
: never
|
||||
: PublicTableNameOrOptions extends keyof PublicSchema["Tables"]
|
||||
? PublicSchema["Tables"][PublicTableNameOrOptions] extends {
|
||||
Update: infer U
|
||||
}
|
||||
? U
|
||||
: never
|
||||
: never
|
||||
|
||||
export type Enums<
|
||||
PublicEnumNameOrOptions extends
|
||||
| keyof PublicSchema["Enums"]
|
||||
| { schema: keyof Database },
|
||||
EnumName extends PublicEnumNameOrOptions extends { schema: keyof Database }
|
||||
? keyof Database[PublicEnumNameOrOptions["schema"]]["Enums"]
|
||||
: never = never,
|
||||
> = PublicEnumNameOrOptions extends { schema: keyof Database }
|
||||
? Database[PublicEnumNameOrOptions["schema"]]["Enums"][EnumName]
|
||||
: PublicEnumNameOrOptions extends keyof PublicSchema["Enums"]
|
||||
? PublicSchema["Enums"][PublicEnumNameOrOptions]
|
||||
: never
|
||||
|
||||
export type CompositeTypes<
|
||||
PublicCompositeTypeNameOrOptions extends
|
||||
| keyof PublicSchema["CompositeTypes"]
|
||||
| { schema: keyof Database },
|
||||
CompositeTypeName extends PublicCompositeTypeNameOrOptions extends {
|
||||
schema: keyof Database
|
||||
}
|
||||
? keyof Database[PublicCompositeTypeNameOrOptions["schema"]]["CompositeTypes"]
|
||||
: never = never,
|
||||
> = PublicCompositeTypeNameOrOptions extends { schema: keyof Database }
|
||||
? Database[PublicCompositeTypeNameOrOptions["schema"]]["CompositeTypes"][CompositeTypeName]
|
||||
: PublicCompositeTypeNameOrOptions extends keyof PublicSchema["CompositeTypes"]
|
||||
? PublicSchema["CompositeTypes"][PublicCompositeTypeNameOrOptions]
|
||||
: never
|
||||
@@ -1,11 +1,10 @@
|
||||
{
|
||||
"name": "@kan/supabase",
|
||||
"name": "@kan/stripe",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./clients": "./src/clients.ts"
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
@@ -21,15 +20,11 @@
|
||||
"@kan/prettier-config": "workspace:*",
|
||||
"@kan/tsconfig": "workspace:*",
|
||||
"eslint": "catalog:",
|
||||
"next": "^14.2.15",
|
||||
"prettier": "catalog:",
|
||||
"typescript": "catalog:"
|
||||
},
|
||||
"prettier": "@kan/prettier-config",
|
||||
"dependencies": {
|
||||
"@edge-runtime/cookies": "^6.0.0",
|
||||
"@kan/db": "workspace:^",
|
||||
"@supabase/ssr": "^0.5.2",
|
||||
"@supabase/supabase-js": "^2.47.3"
|
||||
"stripe": "^18.1.0"
|
||||
}
|
||||
}
|
||||
20
packages/stripe/src/index.ts
Normal file
20
packages/stripe/src/index.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Stripe } from "stripe";
|
||||
|
||||
export const name = "stripe";
|
||||
|
||||
const stripeSecretKey = process.env.STRIPE_SECRET_KEY;
|
||||
|
||||
const createStripeClient = () => {
|
||||
if (!stripeSecretKey) {
|
||||
throw new Error("STRIPE_SECRET_KEY is not set");
|
||||
}
|
||||
|
||||
const stripe = new Stripe(stripeSecretKey, {
|
||||
apiVersion: "2025-04-30.basil",
|
||||
httpClient: Stripe.createFetchHttpClient(),
|
||||
});
|
||||
|
||||
return stripe;
|
||||
};
|
||||
|
||||
export { createStripeClient };
|
||||
@@ -1,103 +0,0 @@
|
||||
import type { CookieOptions } from "@supabase/ssr";
|
||||
import type { NextApiRequest } from "next";
|
||||
import type { NextRequest, NextResponse } from "next/server";
|
||||
import { RequestCookies } from "@edge-runtime/cookies";
|
||||
import { createServerClient, serialize } from "@supabase/ssr";
|
||||
|
||||
import type { Database } from "@kan/db/types/database.types";
|
||||
|
||||
export function createNextClient(req: NextRequest, res: NextResponse) {
|
||||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
|
||||
const serviceKey = process.env.SUPABASE_SERVICE_API_KEY;
|
||||
|
||||
if (!supabaseUrl || !serviceKey) {
|
||||
throw new Error("Missing Supabase environment variables");
|
||||
}
|
||||
|
||||
const supabase = createServerClient<Database, "public">(
|
||||
supabaseUrl,
|
||||
serviceKey,
|
||||
{
|
||||
cookies: {
|
||||
get(name: string) {
|
||||
return req.cookies.get(name)?.value;
|
||||
},
|
||||
set(name: string, value: string, options: CookieOptions) {
|
||||
res.headers.append("Set-Cookie", serialize(name, value, options));
|
||||
},
|
||||
remove(name: string, options: CookieOptions) {
|
||||
res.headers.append("Set-Cookie", serialize(name, "", options));
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return supabase;
|
||||
}
|
||||
|
||||
export function createNextApiClient(req: NextApiRequest) {
|
||||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
|
||||
const serviceKey = process.env.SUPABASE_SERVICE_API_KEY;
|
||||
|
||||
if (!supabaseUrl || !serviceKey) {
|
||||
throw new Error("Missing Supabase environment variables");
|
||||
}
|
||||
|
||||
const authHeader = req.headers.authorization;
|
||||
const accessToken = authHeader?.startsWith("Bearer ")
|
||||
? authHeader.substring(7)
|
||||
: null;
|
||||
|
||||
const supabase = createServerClient<Database, "public">(
|
||||
supabaseUrl,
|
||||
serviceKey,
|
||||
{
|
||||
auth: {
|
||||
persistSession: false,
|
||||
...(accessToken && {
|
||||
autoRefreshToken: false,
|
||||
detectSessionInUrl: false,
|
||||
access_token: accessToken,
|
||||
}),
|
||||
},
|
||||
cookies: {
|
||||
get: (_name: string) => "",
|
||||
set: (_name: string, _value: string, _options: CookieOptions) =>
|
||||
undefined,
|
||||
remove: (_name: string, _options: CookieOptions) => undefined,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return supabase;
|
||||
}
|
||||
|
||||
export function createTRPCClient(req: Request, resHeaders: Headers) {
|
||||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
|
||||
const serviceKey = process.env.SUPABASE_SERVICE_API_KEY;
|
||||
|
||||
if (!supabaseUrl || !serviceKey) {
|
||||
throw new Error("Missing Supabase environment variables");
|
||||
}
|
||||
|
||||
const supabase = createServerClient<Database, "public">(
|
||||
supabaseUrl,
|
||||
serviceKey,
|
||||
{
|
||||
cookies: {
|
||||
get(name: string) {
|
||||
const cookies = new RequestCookies(req.headers);
|
||||
return cookies.get(name)?.value;
|
||||
},
|
||||
set(name: string, value: string, options: CookieOptions) {
|
||||
resHeaders.set("Set-Cookie", serialize(name, value, options));
|
||||
},
|
||||
remove(name: string, options: CookieOptions) {
|
||||
resHeaders.set("Set-Cookie", serialize(name, "", options));
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return supabase;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
export const name = "supabase";
|
||||
|
||||
export * from "@supabase/supabase-js";
|
||||
export * from "./clients";
|
||||
Reference in New Issue
Block a user