diff --git a/example/convex/_generated/api.d.ts b/example/convex/_generated/api.d.ts index 6044faf..f54ef46 100644 --- a/example/convex/_generated/api.d.ts +++ b/example/convex/_generated/api.d.ts @@ -73,6 +73,7 @@ export declare const components: { storageVersion: string | null; version: string | null; }>; + metadata?: Record; modifiedAt: string | null; name: string; organizationId: string; @@ -105,6 +106,8 @@ export declare const components: { currency: string | null; currentPeriodEnd: string | null; currentPeriodStart: string; + customerCancellationComment?: string | null; + customerCancellationReason?: string | null; customerId: string; endedAt: string | null; id: string; @@ -131,6 +134,8 @@ export declare const components: { currency: string | null; currentPeriodEnd: string | null; currentPeriodStart: string; + customerCancellationComment?: string | null; + customerCancellationReason?: string | null; customerId: string; endedAt: string | null; id: string; @@ -162,6 +167,7 @@ export declare const components: { storageVersion: string | null; version: string | null; }>; + metadata?: Record; modifiedAt: string | null; name: string; organizationId: string; @@ -189,7 +195,7 @@ export declare const components: { "query", "internal", { userId: string }, - { id: string; userId: string } | null + { id: string; metadata?: Record; userId: string } | null >; getProduct: FunctionReference< "query", @@ -220,6 +226,7 @@ export declare const components: { storageVersion: string | null; version: string | null; }>; + metadata?: Record; modifiedAt: string | null; name: string; organizationId: string; @@ -250,6 +257,8 @@ export declare const components: { currency: string | null; currentPeriodEnd: string | null; currentPeriodStart: string; + customerCancellationComment?: string | null; + customerCancellationReason?: string | null; customerId: string; endedAt: string | null; id: string; @@ -265,7 +274,7 @@ export declare const components: { insertCustomer: FunctionReference< "mutation", "internal", - { id: string; userId: string }, + { id: string; metadata?: Record; userId: string }, string >; listCustomerSubscriptions: FunctionReference< @@ -280,6 +289,8 @@ export declare const components: { currency: string | null; currentPeriodEnd: string | null; currentPeriodStart: string; + customerCancellationComment?: string | null; + customerCancellationReason?: string | null; customerId: string; endedAt: string | null; id: string; @@ -321,6 +332,7 @@ export declare const components: { storageVersion: string | null; version: string | null; }>; + metadata?: Record; modifiedAt: string | null; name: string; organizationId: string; @@ -352,6 +364,8 @@ export declare const components: { currency: string | null; currentPeriodEnd: string | null; currentPeriodStart: string; + customerCancellationComment?: string | null; + customerCancellationReason?: string | null; customerId: string; endedAt: string | null; id: string; @@ -383,6 +397,7 @@ export declare const components: { storageVersion: string | null; version: string | null; }>; + metadata?: Record; modifiedAt: string | null; name: string; organizationId: string; @@ -435,6 +450,7 @@ export declare const components: { storageVersion: string | null; version: string | null; }>; + metadata?: Record; modifiedAt: string | null; name: string; organizationId: string; @@ -467,6 +483,8 @@ export declare const components: { currency: string | null; currentPeriodEnd: string | null; currentPeriodStart: string; + customerCancellationComment?: string | null; + customerCancellationReason?: string | null; customerId: string; endedAt: string | null; id: string; @@ -484,7 +502,7 @@ export declare const components: { upsertCustomer: FunctionReference< "mutation", "internal", - { customerId: string; userId: string }, + { id: string; metadata?: Record; userId: string }, string >; }; diff --git a/package.json b/package.json index d90732f..59abe55 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,6 @@ } }, "peerDependencies": { - "@polar-sh/sdk": "^0.26.1", "convex": "^1.19.2", "react": "^18", "react-dom": "^18" @@ -88,7 +87,8 @@ "types": "./dist/commonjs/client/index.d.ts", "module": "./dist/esm/client/index.js", "dependencies": { - "@polar-sh/checkout": "^0.1.9", + "@polar-sh/checkout": "^0.1.10", + "@polar-sh/sdk": "^0.28.0", "buffer": "^6.0.3", "convex-helpers": "^0.1.63", "remeda": "^2.20.2", diff --git a/src/component/_generated/api.d.ts b/src/component/_generated/api.d.ts index 6cd1920..fecdd31 100644 --- a/src/component/_generated/api.d.ts +++ b/src/component/_generated/api.d.ts @@ -59,6 +59,7 @@ export type Mounts = { storageVersion: string | null; version: string | null; }>; + metadata?: Record; modifiedAt: string | null; name: string; organizationId: string; @@ -91,6 +92,8 @@ export type Mounts = { currency: string | null; currentPeriodEnd: string | null; currentPeriodStart: string; + customerCancellationComment?: string | null; + customerCancellationReason?: string | null; customerId: string; endedAt: string | null; id: string; @@ -117,6 +120,8 @@ export type Mounts = { currency: string | null; currentPeriodEnd: string | null; currentPeriodStart: string; + customerCancellationComment?: string | null; + customerCancellationReason?: string | null; customerId: string; endedAt: string | null; id: string; @@ -148,6 +153,7 @@ export type Mounts = { storageVersion: string | null; version: string | null; }>; + metadata?: Record; modifiedAt: string | null; name: string; organizationId: string; @@ -175,7 +181,7 @@ export type Mounts = { "query", "public", { userId: string }, - { id: string; userId: string } | null + { id: string; metadata?: Record; userId: string } | null >; getProduct: FunctionReference< "query", @@ -206,6 +212,7 @@ export type Mounts = { storageVersion: string | null; version: string | null; }>; + metadata?: Record; modifiedAt: string | null; name: string; organizationId: string; @@ -236,6 +243,8 @@ export type Mounts = { currency: string | null; currentPeriodEnd: string | null; currentPeriodStart: string; + customerCancellationComment?: string | null; + customerCancellationReason?: string | null; customerId: string; endedAt: string | null; id: string; @@ -251,7 +260,7 @@ export type Mounts = { insertCustomer: FunctionReference< "mutation", "public", - { id: string; userId: string }, + { id: string; metadata?: Record; userId: string }, string >; listCustomerSubscriptions: FunctionReference< @@ -266,6 +275,8 @@ export type Mounts = { currency: string | null; currentPeriodEnd: string | null; currentPeriodStart: string; + customerCancellationComment?: string | null; + customerCancellationReason?: string | null; customerId: string; endedAt: string | null; id: string; @@ -307,6 +318,7 @@ export type Mounts = { storageVersion: string | null; version: string | null; }>; + metadata?: Record; modifiedAt: string | null; name: string; organizationId: string; @@ -338,6 +350,8 @@ export type Mounts = { currency: string | null; currentPeriodEnd: string | null; currentPeriodStart: string; + customerCancellationComment?: string | null; + customerCancellationReason?: string | null; customerId: string; endedAt: string | null; id: string; @@ -369,6 +383,7 @@ export type Mounts = { storageVersion: string | null; version: string | null; }>; + metadata?: Record; modifiedAt: string | null; name: string; organizationId: string; @@ -421,6 +436,7 @@ export type Mounts = { storageVersion: string | null; version: string | null; }>; + metadata?: Record; modifiedAt: string | null; name: string; organizationId: string; @@ -453,6 +469,8 @@ export type Mounts = { currency: string | null; currentPeriodEnd: string | null; currentPeriodStart: string; + customerCancellationComment?: string | null; + customerCancellationReason?: string | null; customerId: string; endedAt: string | null; id: string; @@ -470,7 +488,7 @@ export type Mounts = { upsertCustomer: FunctionReference< "mutation", "public", - { customerId: string; userId: string }, + { id: string; metadata?: Record; userId: string }, string >; }; diff --git a/src/component/lib.ts b/src/component/lib.ts index 54d59bb..6aff1e0 100644 --- a/src/component/lib.ts +++ b/src/component/lib.ts @@ -19,24 +19,19 @@ export const getCustomerByUserId = query({ }); export const insertCustomer = mutation({ - args: { - id: v.string(), - userId: v.string(), - }, + args: schema.tables.customers.validator, returns: v.id("customers"), handler: async (ctx, args) => { return ctx.db.insert("customers", { id: args.id, userId: args.userId, + metadata: args.metadata, }); }, }); export const upsertCustomer = mutation({ - args: { - userId: v.string(), - customerId: v.string(), - }, + args: schema.tables.customers.validator, returns: v.string(), handler: async (ctx, args) => { const customer = await ctx.db @@ -45,8 +40,9 @@ export const upsertCustomer = mutation({ .unique(); if (!customer) { const customerId = await ctx.db.insert("customers", { - id: args.customerId, + id: args.id, userId: args.userId, + metadata: args.metadata, }); const newCustomer = await ctx.db.get(customerId); if (!newCustomer) { @@ -203,7 +199,10 @@ export const createSubscription = mutation({ subscription: schema.tables.subscriptions.validator, }, handler: async (ctx, args) => { - await ctx.db.insert("subscriptions", args.subscription); + await ctx.db.insert("subscriptions", { + ...args.subscription, + metadata: args.subscription.metadata, + }); }, }); @@ -219,7 +218,10 @@ export const updateSubscription = mutation({ if (!existingSubscription) { throw new Error(`Subscription not found: ${args.subscription.id}`); } - await ctx.db.patch(existingSubscription._id, args.subscription); + await ctx.db.patch(existingSubscription._id, { + ...args.subscription, + metadata: args.subscription.metadata, + }); }, }); @@ -228,7 +230,10 @@ export const createProduct = mutation({ product: schema.tables.products.validator, }, handler: async (ctx, args) => { - await ctx.db.insert("products", args.product); + await ctx.db.insert("products", { + ...args.product, + metadata: args.product.metadata, + }); }, }); @@ -244,7 +249,10 @@ export const updateProduct = mutation({ if (!existingProduct) { throw new Error(`Product not found: ${args.product.id}`); } - await ctx.db.patch(existingProduct._id, args.product); + await ctx.db.patch(existingProduct._id, { + ...args.product, + metadata: args.product.metadata, + }); }, }); diff --git a/src/component/schema.ts b/src/component/schema.ts index 4def66f..3e89bed 100644 --- a/src/component/schema.ts +++ b/src/component/schema.ts @@ -6,6 +6,7 @@ export default defineSchema( customers: defineTable({ id: v.string(), userId: v.string(), + metadata: v.optional(v.record(v.string(), v.any())), }) .index("userId", ["userId"]) .index("id", ["id"]), @@ -21,6 +22,7 @@ export default defineSchema( isRecurring: v.boolean(), isArchived: v.boolean(), organizationId: v.string(), + metadata: v.optional(v.record(v.string(), v.any())), prices: v.array( v.object({ id: v.string(), diff --git a/src/component/util.ts b/src/component/util.ts index 7b291de..684631e 100644 --- a/src/component/util.ts +++ b/src/component/util.ts @@ -110,6 +110,7 @@ export const convertToDatabaseProduct = ( createdAt: product.createdAt.toISOString(), modifiedAt: product.modifiedAt?.toISOString() ?? null, recurringInterval: product.recurringInterval, + metadata: product.metadata, prices: product.prices.map((price) => ({ id: price.id, productId: price.productId,