@raideno/convex-stripe 0.2.3 → 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/dist/index.d.ts CHANGED
@@ -151,25 +151,53 @@ declare const CreateCustomerImplementation: {
151
151
 
152
152
  export declare interface InputConfiguration {
153
153
  stripe: {
154
+ /** Stripe API version to pin against (recommended for stability). */
154
155
  version?: default_2.StripeConfig["apiVersion"];
156
+ /** Secret key for your Stripe account (starts with `sk_`). */
155
157
  secret_key: string;
158
+ /** Webhook signing secret for account-level webhooks (starts with `whsec_`). */
156
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
+ */
157
164
  connect_webhook_secret?: string;
158
165
  };
159
166
  sync: {
160
167
  catalog?: {
168
+ /** Products to ensure exist in Stripe (optional bootstrap). */
161
169
  products?: default_2.ProductCreateParams[];
170
+ /** Prices to ensure exist in Stripe (optional bootstrap). */
162
171
  prices?: default_2.PriceCreateParams[];
163
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
+ */
164
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
+ */
165
186
  onMissingKey?: "create" | "error";
166
187
  };
188
+ /**
189
+ * Metadata field used to match local definitions to Stripe objects.
190
+ * Example: "app_internal_key"
191
+ */
167
192
  metadataKey?: string;
168
193
  };
169
194
  webhooks?: {
170
195
  account: {
196
+ /** Metadata applied when creating/updating the Stripe webhook endpoint. */
171
197
  metadata?: Record<string, string>;
198
+ /** Description used for the Stripe webhook endpoint. */
172
199
  description?: string;
200
+ /** Override the default path (otherwise your code uses `/stripe/webhook`). */
173
201
  path?: string;
174
202
  };
175
203
  connect: {
@@ -178,13 +206,21 @@ export declare interface InputConfiguration {
178
206
  path?: string;
179
207
  };
180
208
  };
209
+ /** Optional Billing Portal configuration to create/sync. */
181
210
  portal?: default_2.BillingPortal.ConfigurationCreateParams;
211
+ /** Which Stripe tables you want to sync into Convex. */
182
212
  tables: Record<keyof typeof stripeTables, boolean>;
183
213
  };
184
214
  callbacks?: {
215
+ /** Called after a row is inserted/upserted/deleted in your Stripe tables. */
185
216
  afterChange?: CallbackAfterChange;
186
217
  };
218
+ /**
219
+ * If true, avoids attaching routes/state globally (depends on your library meaning).
220
+ * Document your intended behavior here.
221
+ */
187
222
  detached?: boolean;
223
+ /** TTL for redirect state (ms). */
188
224
  redirectTtlMs?: number;
189
225
  }
190
226
 
@@ -192,8 +228,29 @@ export declare type InputOptions = Partial<InternalOptions>;
192
228
 
193
229
  export declare type InternalConfiguration = RecursiveDeepRequired<InputConfiguration>;
194
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
+ */
195
251
  export declare const internalConvexStripe: (configuration_: InputConfiguration, options_?: InputOptions) => {
196
252
  stripe: {
253
+ /** Raw HTTP handler descriptors. Prefer `addHttpRoutes` unless you need manual control. */
197
254
  http: {
198
255
  webhook: {
199
256
  path: string;
@@ -206,12 +263,62 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration,
206
263
  readonly handler: (context: GenericActionCtx<GenericDataModel>, request: Request) => Promise<Response>;
207
264
  };
208
265
  };
266
+ /** A pre-configured Stripe SDK client using your `secret_key` and `version`. */
209
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
+ */
210
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
+ */
211
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
+ */
212
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
+ */
213
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>>;
214
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
+ */
215
322
  create: (context: GenericActionCtx<any>, args: Parameters<(typeof CreateCustomerImplementation)["handler"]>[1], options?: Parameters<(typeof CreateCustomerImplementation)["handler"]>[2]) => Promise<{
216
323
  _id: GenericId<"stripeCustomers">;
217
324
  _creationTime: number;
@@ -280,6 +387,14 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration,
280
387
  }>;
281
388
  };
282
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
+ */
283
398
  create: (context: GenericActionCtx<any>, args: Parameters<(typeof CreateAccountImplementation)["handler"]>[1], options?: Parameters<(typeof CreateAccountImplementation)["handler"]>[2]) => Promise<{
284
399
  _id: GenericId<"stripeAccounts">;
285
400
  _creationTime: number;
@@ -312,9 +427,21 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration,
312
427
  accountId: string;
313
428
  lastSyncedAt: number;
314
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
+ */
315
438
  link: (context: GenericActionCtx<any>, args: Parameters<(typeof CreateAccountLinkImplementation)["handler"]>[1], options?: Parameters<(typeof CreateAccountLinkImplementation)["handler"]>[2]) => Promise<default_2.Response<default_2.AccountLink>>;
316
439
  };
317
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
+ */
318
445
  store: RegisteredMutation<"internal", {
319
446
  id?: any;
320
447
  value?: any;
@@ -1444,6 +1571,11 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration,
1444
1571
  deleted?: undefined;
1445
1572
  doc?: undefined;
1446
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
+ */
1447
1579
  sync: RegisteredAction<"internal", {
1448
1580
  webhooks?: {
1449
1581
  account?: boolean | undefined;
package/dist/server.js CHANGED
@@ -9696,10 +9696,31 @@ const internalConvexStripe = (configuration_, options_) => {
9696
9696
  );
9697
9697
  return {
9698
9698
  stripe: {
9699
+ /** Raw HTTP handler descriptors. Prefer `addHttpRoutes` unless you need manual control. */
9699
9700
  http: http_,
9701
+ /** A pre-configured Stripe SDK client using your `secret_key` and `version`. */
9700
9702
  client: new Stripe(ConvexStripeInternalConfiguration.stripe.secret_key, {
9701
9703
  apiVersion: ConvexStripeInternalConfiguration.stripe.version
9702
9704
  }),
9705
+ /**
9706
+ * Registers the Stripe webhook and redirect routes on your Convex `HttpRouter`.
9707
+ * Call this inside your `convex/http.ts` file.
9708
+ *
9709
+ * - `POST /stripe/webhook` receives and verifies Stripe webhook events.
9710
+ * - `GET /stripe/return/*` handles post-payment/portal redirect flows.
9711
+ *
9712
+ * @param http - Your Convex `HttpRouter` instance.
9713
+ * @param config - Optional config override (defaults to the root configuration).
9714
+ *
9715
+ * @example
9716
+ * // convex/http.ts
9717
+ * import { httpRouter } from "convex/server";
9718
+ * import { stripe } from "./stripe";
9719
+ *
9720
+ * const http = httpRouter();
9721
+ * stripe.addHttpRoutes(http);
9722
+ * export default http;
9723
+ */
9703
9724
  addHttpRoutes: (http, config) => {
9704
9725
  config = normalizeConfiguration(config || configuration_);
9705
9726
  http.route({
@@ -9717,6 +9738,14 @@ const internalConvexStripe = (configuration_, options_) => {
9717
9738
  })
9718
9739
  });
9719
9740
  },
9741
+ /**
9742
+ * Opens a Stripe Billing Portal session for an existing customer.
9743
+ * Use this to let users manage their subscription, invoices, and payment methods.
9744
+ *
9745
+ * @param context - The Convex action context.
9746
+ * @param args - Customer identifier and return URL.
9747
+ * @param options - Optional overrides (e.g. portal configuration ID).
9748
+ */
9720
9749
  portal: (context, args, options = {}) => PortalImplementation.handler(
9721
9750
  context,
9722
9751
  args,
@@ -9724,6 +9753,14 @@ const internalConvexStripe = (configuration_, options_) => {
9724
9753
  ConvexStripeInternalConfiguration,
9725
9754
  ConvexStripeInternalOptions
9726
9755
  ),
9756
+ /**
9757
+ * Creates a Stripe Checkout session in `subscription` mode.
9758
+ * Redirects the user to Stripe Checkout to set up a recurring subscription.
9759
+ *
9760
+ * @param context - The Convex action context.
9761
+ * @param args - Price ID, customer info, and success/cancel URLs.
9762
+ * @param options - Optional overrides for the Checkout session.
9763
+ */
9727
9764
  subscribe: (context, args, options = {}) => SubscribeImplementation.handler(
9728
9765
  context,
9729
9766
  args,
@@ -9731,6 +9768,13 @@ const internalConvexStripe = (configuration_, options_) => {
9731
9768
  ConvexStripeInternalConfiguration,
9732
9769
  ConvexStripeInternalOptions
9733
9770
  ),
9771
+ /**
9772
+ * Creates a Stripe Checkout session in `payment` mode (one-time payment).
9773
+ *
9774
+ * @param context - The Convex action context.
9775
+ * @param args - Price ID, quantity, and success/cancel URLs.
9776
+ * @param options - Optional overrides for the Checkout session.
9777
+ */
9734
9778
  pay: (context, args, options = {}) => PayImplementation.handler(
9735
9779
  context,
9736
9780
  args,
@@ -9739,6 +9783,13 @@ const internalConvexStripe = (configuration_, options_) => {
9739
9783
  ConvexStripeInternalOptions
9740
9784
  ),
9741
9785
  customers: {
9786
+ /**
9787
+ * Creates a new Stripe Customer and stores it in your Convex database.
9788
+ *
9789
+ * @param context - The Convex action context.
9790
+ * @param args - Customer details (email, name, metadata, etc.).
9791
+ * @param options - Optional overrides for the customer creation.
9792
+ */
9742
9793
  create: (context, args, options = {}) => CreateCustomerImplementation.handler(
9743
9794
  context,
9744
9795
  args,
@@ -9748,6 +9799,14 @@ const internalConvexStripe = (configuration_, options_) => {
9748
9799
  )
9749
9800
  },
9750
9801
  accounts: {
9802
+ /**
9803
+ * Creates a new Stripe Connect account (Express or Custom).
9804
+ * Use this to onboard sellers, platforms, or service providers.
9805
+ *
9806
+ * @param context - The Convex action context.
9807
+ * @param args - Account type, email, and capabilities.
9808
+ * @param options - Optional overrides for the account creation.
9809
+ */
9751
9810
  create: (context, args, options = {}) => CreateAccountImplementation.handler(
9752
9811
  context,
9753
9812
  args,
@@ -9755,6 +9814,14 @@ const internalConvexStripe = (configuration_, options_) => {
9755
9814
  ConvexStripeInternalConfiguration,
9756
9815
  ConvexStripeInternalOptions
9757
9816
  ),
9817
+ /**
9818
+ * Creates a Stripe Connect Account Link for onboarding.
9819
+ * Redirects the connected account holder to Stripe's hosted onboarding flow.
9820
+ *
9821
+ * @param context - The Convex action context.
9822
+ * @param args - Account ID, refresh URL, and return URL.
9823
+ * @param options - Optional overrides for the account link.
9824
+ */
9758
9825
  link: (context, args, options = {}) => {
9759
9826
  return CreateAccountLinkImplementation.handler(
9760
9827
  context,
@@ -9766,6 +9833,10 @@ const internalConvexStripe = (configuration_, options_) => {
9766
9833
  }
9767
9834
  }
9768
9835
  },
9836
+ /**
9837
+ * Internal Convex mutation that persists a Stripe object into your database.
9838
+ * Typically called from within the webhook handler not meant for direct use.
9839
+ */
9769
9840
  store: internalMutationGeneric({
9770
9841
  args: StoreImplementation.args,
9771
9842
  handler: async (context, args) => StoreImplementation.handler(
@@ -9775,6 +9846,11 @@ const internalConvexStripe = (configuration_, options_) => {
9775
9846
  ConvexStripeInternalOptions
9776
9847
  )
9777
9848
  }),
9849
+ /**
9850
+ * Internal Convex action that syncs Stripe catalog data (products, prices,
9851
+ * webhooks, portal config) into Stripe based on your `sync` configuration.
9852
+ * Run this manually or on deploy to keep Stripe in sync with your config.
9853
+ */
9778
9854
  sync: internalActionGeneric({
9779
9855
  args: SyncImplementation.args,
9780
9856
  handler: (context, args) => SyncImplementation.handler(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raideno/convex-stripe",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Easy stripe billing for convex apps.",
5
5
  "keywords": [
6
6
  "billing",