@raideno/convex-stripe 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -45,13 +45,16 @@ export default defineSchema({
45
45
  ```ts
46
46
  // convex/stripe.ts
47
47
 
48
- import { internalConvexStripe } from "@raideno/convex-stripe/server";
48
+ import { internalConvexStripe, syncAllTables } from "@raideno/convex-stripe/server";
49
49
 
50
50
  export const { stripe, store, sync } = internalConvexStripe({
51
51
  stripe: {
52
52
  secret_key: process.env.STRIPE_SECRET_KEY!,
53
53
  account_webhook_secret: process.env.STRIPE_ACCOUNT_WEBHOOK_SECRET!,
54
54
  },
55
+ sync: {
56
+ tables: syncAllTables(),
57
+ },
55
58
  });
56
59
 
57
60
  export const createCustomer = internalAction({
@@ -165,6 +168,9 @@ Now you can use the provided functions to:
165
168
 
166
169
  If you wish to also add stripe connect, below is a guide on how to do it. You can find a full example in [`examples/marketplaces/README.md`](examples/marketplace/README.md).
167
170
 
171
+ ### 0. Enable connect on your stripe dashboard.
172
+ ...
173
+
168
174
  ### 1. Create a connect webhook using `sync` method.
169
175
  ...
170
176
 
@@ -243,8 +249,8 @@ This action is typically manually called or setup to be automatically called in
243
249
  }
244
250
  ```
245
251
 
246
- - `data` (optional, default: `true`): Syncs all existing Stripe resources to Convex tables.
247
- - `data.withConnect` (option, default: `false`): Syncs all existing Stripe resources from linked accounts to Convex tables.
252
+ - `tables` (optional, default: `true`): Syncs all existing Stripe resources to Convex tables.
253
+ - `tables.withConnect` (option, default: `false`): Syncs all existing Stripe resources from linked accounts to Convex tables.
248
254
  - `webhook.account` (optional, default: `false`): Creates/updates the account webhook endpoint. Returns the webhook secret if a new endpoint is created. You must set it in your convex environment variables as `STRIPE_ACCOUNT_WEBHOOK_SECRET`.
249
255
  - `webhook.connect` (optional, default: `false`): Creates/updates the connect webhook endpoint. Returns the webhook secret if a new endpoint is created. You must set it in your convex environment variables as `STRIPE_CONNECT_WEBHOOK_SECRET`.
250
256
  - `portal` (optional, default: `false`): Creates the default billing portal configuration if it doesn't exist.
package/dist/index.d.ts CHANGED
@@ -149,41 +149,108 @@ declare const CreateCustomerImplementation: {
149
149
  }>;
150
150
  };
151
151
 
152
- export declare type InputConfiguration = WithOptional<InternalConfiguration, "portal" | "sync" | "redirectTtlMs" | "webhook" | "detached" | "catalog">;
153
-
154
- export declare type InputOptions = WithOptional<InternalOptions, "store" | "debug" | "logger" | "base">;
155
-
156
- export declare interface InternalConfiguration {
152
+ export declare interface InputConfiguration {
157
153
  stripe: {
154
+ /** Stripe API version to pin against (recommended for stability). */
155
+ version?: default_2.StripeConfig["apiVersion"];
156
+ /** Secret key for your Stripe account (starts with `sk_`). */
158
157
  secret_key: string;
158
+ /** Webhook signing secret for account-level webhooks (starts with `whsec_`). */
159
159
  account_webhook_secret: string;
160
+ /**
161
+ * Webhook signing secret for Stripe Connect webhooks (if you use Connect).
162
+ * If omitted, Connect webhooks are treated as disabled/unverified.
163
+ */
160
164
  connect_webhook_secret?: string;
161
165
  };
162
- catalog: {
163
- products: default_2.ProductCreateParams[];
164
- prices: default_2.PriceCreateParams[];
165
- behavior: {
166
- onExisting: "update" | "archive_and_recreate" | "skip" | "error";
167
- onMissingKey: "create" | "error";
166
+ sync: {
167
+ catalog?: {
168
+ /** Products to ensure exist in Stripe (optional bootstrap). */
169
+ products?: default_2.ProductCreateParams[];
170
+ /** Prices to ensure exist in Stripe (optional bootstrap). */
171
+ prices?: default_2.PriceCreateParams[];
172
+ behavior?: {
173
+ /**
174
+ * What to do if a product/price already exists in Stripe.
175
+ * - update: update fields
176
+ * - archive_and_recreate: archive and create a new object
177
+ * - skip: leave as-is
178
+ * - error: throw
179
+ */
180
+ onExisting?: "update" | "archive_and_recreate" | "skip" | "error";
181
+ /**
182
+ * What to do if the "metadata key" is missing on an object.
183
+ * - create: create it
184
+ * - error: throw
185
+ */
186
+ onMissingKey?: "create" | "error";
187
+ };
188
+ /**
189
+ * Metadata field used to match local definitions to Stripe objects.
190
+ * Example: "app_internal_key"
191
+ */
192
+ metadataKey?: string;
168
193
  };
169
- metadataKey: string;
170
- };
171
- webhook: {
172
- metadata: Record<string, string>;
173
- description: string;
174
- path: string;
194
+ webhooks?: {
195
+ account: {
196
+ /** Metadata applied when creating/updating the Stripe webhook endpoint. */
197
+ metadata?: Record<string, string>;
198
+ /** Description used for the Stripe webhook endpoint. */
199
+ description?: string;
200
+ /** Override the default path (otherwise your code uses `/stripe/webhook`). */
201
+ path?: string;
202
+ };
203
+ connect: {
204
+ metadata?: Record<string, string>;
205
+ description?: string;
206
+ path?: string;
207
+ };
208
+ };
209
+ /** Optional Billing Portal configuration to create/sync. */
210
+ portal?: default_2.BillingPortal.ConfigurationCreateParams;
211
+ /** Which Stripe tables you want to sync into Convex. */
212
+ tables: Record<keyof typeof stripeTables, boolean>;
175
213
  };
176
- portal: default_2.BillingPortal.ConfigurationCreateParams;
177
- callback?: {
178
- unstable__afterChange?: CallbackAfterChange;
214
+ callbacks?: {
215
+ /** Called after a row is inserted/upserted/deleted in your Stripe tables. */
216
+ afterChange?: CallbackAfterChange;
179
217
  };
180
- detached: boolean;
181
- sync: Partial<Record<keyof typeof stripeTables, boolean>>;
182
- redirectTtlMs: number;
218
+ /**
219
+ * If true, avoids attaching routes/state globally (depends on your library meaning).
220
+ * Document your intended behavior here.
221
+ */
222
+ detached?: boolean;
223
+ /** TTL for redirect state (ms). */
224
+ redirectTtlMs?: number;
183
225
  }
184
226
 
227
+ export declare type InputOptions = Partial<InternalOptions>;
228
+
229
+ export declare type InternalConfiguration = RecursiveDeepRequired<InputConfiguration>;
230
+
231
+ /**
232
+ * Initializes the Convex Stripe integration.
233
+ *
234
+ * Returns a set of utilities to wire up HTTP routes, trigger Stripe actions,
235
+ * and keep your Convex database in sync with Stripe events.
236
+ *
237
+ * @param configuration_ - Your Stripe and sync configuration.
238
+ * @param options_ - Optional internal options (logger, debug mode, etc.).
239
+ *
240
+ * @example
241
+ * export const { stripe, store, sync } = internalConvexStripe({
242
+ * stripe: {
243
+ * secret_key: process.env.STRIPE_SECRET_KEY!,
244
+ * account_webhook_secret: process.env.STRIPE_WHSEC!,
245
+ * },
246
+ * sync: {
247
+ * tables: { customers: true, subscriptions: true },
248
+ * },
249
+ * });
250
+ */
185
251
  export declare const internalConvexStripe: (configuration_: InputConfiguration, options_?: InputOptions) => {
186
252
  stripe: {
253
+ /** Raw HTTP handler descriptors. Prefer `addHttpRoutes` unless you need manual control. */
187
254
  http: {
188
255
  webhook: {
189
256
  path: string;
@@ -196,12 +263,62 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration,
196
263
  readonly handler: (context: GenericActionCtx<GenericDataModel>, request: Request) => Promise<Response>;
197
264
  };
198
265
  };
266
+ /** A pre-configured Stripe SDK client using your `secret_key` and `version`. */
199
267
  client: default_2;
268
+ /**
269
+ * Registers the Stripe webhook and redirect routes on your Convex `HttpRouter`.
270
+ * Call this inside your `convex/http.ts` file.
271
+ *
272
+ * - `POST /stripe/webhook` receives and verifies Stripe webhook events.
273
+ * - `GET /stripe/return/*` handles post-payment/portal redirect flows.
274
+ *
275
+ * @param http - Your Convex `HttpRouter` instance.
276
+ * @param config - Optional config override (defaults to the root configuration).
277
+ *
278
+ * @example
279
+ * // convex/http.ts
280
+ * import { httpRouter } from "convex/server";
281
+ * import { stripe } from "./stripe";
282
+ *
283
+ * const http = httpRouter();
284
+ * stripe.addHttpRoutes(http);
285
+ * export default http;
286
+ */
200
287
  addHttpRoutes: (http: HttpRouter, config?: InputConfiguration) => void;
288
+ /**
289
+ * Opens a Stripe Billing Portal session for an existing customer.
290
+ * Use this to let users manage their subscription, invoices, and payment methods.
291
+ *
292
+ * @param context - The Convex action context.
293
+ * @param args - Customer identifier and return URL.
294
+ * @param options - Optional overrides (e.g. portal configuration ID).
295
+ */
201
296
  portal: (context: GenericActionCtx<any>, args: Parameters<(typeof PortalImplementation)["handler"]>[1], options?: Parameters<(typeof PortalImplementation)["handler"]>[2]) => Promise<default_2.Response<default_2.BillingPortal.Session>>;
297
+ /**
298
+ * Creates a Stripe Checkout session in `subscription` mode.
299
+ * Redirects the user to Stripe Checkout to set up a recurring subscription.
300
+ *
301
+ * @param context - The Convex action context.
302
+ * @param args - Price ID, customer info, and success/cancel URLs.
303
+ * @param options - Optional overrides for the Checkout session.
304
+ */
202
305
  subscribe: (context: GenericActionCtx<any>, args: Parameters<(typeof SubscribeImplementation)["handler"]>[1], options?: Parameters<(typeof SubscribeImplementation)["handler"]>[2]) => Promise<default_2.Response<default_2.Checkout.Session>>;
306
+ /**
307
+ * Creates a Stripe Checkout session in `payment` mode (one-time payment).
308
+ *
309
+ * @param context - The Convex action context.
310
+ * @param args - Price ID, quantity, and success/cancel URLs.
311
+ * @param options - Optional overrides for the Checkout session.
312
+ */
203
313
  pay: (context: GenericActionCtx<any>, args: Parameters<(typeof PayImplementation)["handler"]>[1], options?: Parameters<(typeof PayImplementation)["handler"]>[2]) => Promise<default_2.Response<default_2.Checkout.Session>>;
204
314
  customers: {
315
+ /**
316
+ * Creates a new Stripe Customer and stores it in your Convex database.
317
+ *
318
+ * @param context - The Convex action context.
319
+ * @param args - Customer details (email, name, metadata, etc.).
320
+ * @param options - Optional overrides for the customer creation.
321
+ */
205
322
  create: (context: GenericActionCtx<any>, args: Parameters<(typeof CreateCustomerImplementation)["handler"]>[1], options?: Parameters<(typeof CreateCustomerImplementation)["handler"]>[2]) => Promise<{
206
323
  _id: GenericId<"stripeCustomers">;
207
324
  _creationTime: number;
@@ -270,6 +387,14 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration,
270
387
  }>;
271
388
  };
272
389
  accounts: {
390
+ /**
391
+ * Creates a new Stripe Connect account (Express or Custom).
392
+ * Use this to onboard sellers, platforms, or service providers.
393
+ *
394
+ * @param context - The Convex action context.
395
+ * @param args - Account type, email, and capabilities.
396
+ * @param options - Optional overrides for the account creation.
397
+ */
273
398
  create: (context: GenericActionCtx<any>, args: Parameters<(typeof CreateAccountImplementation)["handler"]>[1], options?: Parameters<(typeof CreateAccountImplementation)["handler"]>[2]) => Promise<{
274
399
  _id: GenericId<"stripeAccounts">;
275
400
  _creationTime: number;
@@ -302,9 +427,21 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration,
302
427
  accountId: string;
303
428
  lastSyncedAt: number;
304
429
  }>;
430
+ /**
431
+ * Creates a Stripe Connect Account Link for onboarding.
432
+ * Redirects the connected account holder to Stripe's hosted onboarding flow.
433
+ *
434
+ * @param context - The Convex action context.
435
+ * @param args - Account ID, refresh URL, and return URL.
436
+ * @param options - Optional overrides for the account link.
437
+ */
305
438
  link: (context: GenericActionCtx<any>, args: Parameters<(typeof CreateAccountLinkImplementation)["handler"]>[1], options?: Parameters<(typeof CreateAccountLinkImplementation)["handler"]>[2]) => Promise<default_2.Response<default_2.AccountLink>>;
306
439
  };
307
440
  };
441
+ /**
442
+ * Internal Convex mutation that persists a Stripe object into your database.
443
+ * Typically called from within the webhook handler not meant for direct use.
444
+ */
308
445
  store: RegisteredMutation<"internal", {
309
446
  id?: any;
310
447
  value?: any;
@@ -1434,14 +1571,19 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration,
1434
1571
  deleted?: undefined;
1435
1572
  doc?: undefined;
1436
1573
  } | undefined>>;
1574
+ /**
1575
+ * Internal Convex action that syncs Stripe catalog data (products, prices,
1576
+ * webhooks, portal config) into Stripe based on your `sync` configuration.
1577
+ * Run this manually or on deploy to keep Stripe in sync with your config.
1578
+ */
1437
1579
  sync: RegisteredAction<"internal", {
1438
- portal?: boolean | undefined;
1439
1580
  webhooks?: {
1440
1581
  account?: boolean | undefined;
1441
1582
  connect?: boolean | undefined;
1442
1583
  } | undefined;
1584
+ portal?: boolean | undefined;
1443
1585
  unstable_catalog?: boolean | undefined;
1444
- data: boolean | {
1586
+ tables: boolean | {
1445
1587
  withConnect?: boolean | undefined;
1446
1588
  };
1447
1589
  }, Promise<void>>;
@@ -1486,6 +1628,10 @@ declare const PortalImplementation: {
1486
1628
  } & Omit<default_2.BillingPortal.SessionCreateParams, "customer" | "return_url">, stripeOptions: default_2.RequestOptions, configuration: InternalConfiguration, options: InternalOptions) => Promise<default_2.Response<default_2.BillingPortal.Session>>;
1487
1629
  };
1488
1630
 
1631
+ declare type RecursiveDeepRequired<T> = T extends (...args: any[]) => any ? T : T extends object ? {
1632
+ [K in keyof T]-?: RecursiveDeepRequired<T[K]>;
1633
+ } : T;
1634
+
1489
1635
  declare type StripeDataModel = DataModelFromSchemaDefinition<typeof stripeSchema>;
1490
1636
 
1491
1637
  declare const stripeSchema: SchemaDefinition< {
@@ -8857,6 +9003,10 @@ declare const SubscribeImplementation: {
8857
9003
  } & Omit<default_2.Checkout.SessionCreateParams, "mode" | "customer" | "client_reference_id" | "line_items" | "success_url" | "ui_mode" | "cancel_url">, stripeOptions: default_2.RequestOptions, configuration: InternalConfiguration, options: InternalOptions) => Promise<default_2.Response<default_2.Checkout.Session>>;
8858
9004
  };
8859
9005
 
8860
- declare type WithOptional<T, K extends keyof T = never> = Omit<T, K> & Partial<Pick<T, K>>;
9006
+ export declare const syncAllTables: () => Record<keyof typeof stripeTables, boolean>;
9007
+
9008
+ export declare const syncAllTablesExcept: (tables: Array<keyof typeof stripeTables>) => Record<keyof typeof stripeTables, boolean>;
9009
+
9010
+ export declare const syncOnlyTables: (tables: Array<keyof typeof stripeTables>) => Record<keyof typeof stripeTables, boolean>;
8861
9011
 
8862
9012
  export { }