@raideno/convex-stripe 0.3.7 → 0.3.9

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
@@ -33,7 +33,7 @@ declare type ActionOperation = "createCustomer";
33
33
 
34
34
  declare type AllRedirectHandlers = (typeof REDIRECT_HANDLERS)[number];
35
35
 
36
- export declare const allStripeTablesExcept: (tables: Array<keyof typeof stripeTables>) => typeof stripeTables;
36
+ export declare const allStripeTablesExcept: <const T extends Array<keyof typeof stripeTables>>(tables: T) => Omit<typeof stripeTables, T[number]>;
37
37
 
38
38
  declare type ArgSchema = Record<string, Validator<any, "optional" | "required", any>>;
39
39
 
@@ -62,14 +62,14 @@ export declare function buildSignedReturnUrl<O extends ReturnOrigin>({ configura
62
62
  data: ReturnDataMap[O];
63
63
  }): Promise<string>;
64
64
 
65
- export declare type CallbackAfterChange = (context: GenericMutationCtx<any>, operation: "upsert" | "delete" | "insert", event: CallbackEvent) => Promise<void>;
65
+ export declare type CallbackAfterChange<Schema extends SchemaDefinition<GenericSchema, boolean> = SchemaDefinition<GenericSchema, boolean>> = (context: GenericMutationCtx<DataModelFromSchemaDefinition<Schema>>, operation: "upsert" | "delete" | "insert", event: CallbackEvent<Schema>) => Promise<void>;
66
66
 
67
- export declare type CallbackEvent = {
68
- [K in keyof StripeDataModel]: {
67
+ export declare type CallbackEvent<Schema extends SchemaDefinition<GenericSchema, boolean> = SchemaDefinition<GenericSchema, boolean>> = {
68
+ [K in SchemaStripeTableKeys<Schema>]: {
69
69
  table: K;
70
70
  _id: StripeDataModel[K]["document"]["_id"];
71
71
  };
72
- }[keyof StripeDataModel];
72
+ }[SchemaStripeTableKeys<Schema>];
73
73
 
74
74
  declare const CreateAccountImplementation: {
75
75
  name: string;
@@ -226,8 +226,8 @@ declare type InferArgs<S extends ArgSchema> = {
226
226
  [K in keyof S as S[K] extends Validator<any, "optional", any> ? K : never]?: Infer<S[K]>;
227
227
  };
228
228
 
229
- export declare interface InputConfiguration {
230
- schema: SchemaDefinition<GenericSchema, true>;
229
+ export declare interface InputConfiguration<Schema extends SchemaDefinition<GenericSchema, boolean> = SchemaDefinition<GenericSchema, boolean>> {
230
+ schema: Schema;
231
231
  stripe: {
232
232
  /** Stripe API version to pin against (recommended for stability). */
233
233
  version?: default_2.StripeConfig["apiVersion"];
@@ -291,7 +291,7 @@ export declare interface InputConfiguration {
291
291
  };
292
292
  callbacks?: {
293
293
  /** Called after a row is inserted/upserted/deleted in your Stripe tables. */
294
- afterChange?: CallbackAfterChange;
294
+ afterChange?: CallbackAfterChange<Schema>;
295
295
  };
296
296
  /**
297
297
  * If true, avoids attaching routes/state globally (depends on your library meaning).
@@ -334,7 +334,7 @@ export declare type InternalConfiguration = RecursiveDeepRequired<InputConfigura
334
334
  * },
335
335
  * });
336
336
  */
337
- export declare const internalConvexStripe: (configuration_: InputConfiguration & {
337
+ export declare const internalConvexStripe: <Schema extends SchemaDefinition<GenericSchema, boolean>>(configuration_: InputConfiguration<Schema> & {
338
338
  sync?: {
339
339
  tables?: never;
340
340
  };
@@ -383,7 +383,7 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration &
383
383
  * @param args - Customer identifier and return URL.
384
384
  * @param options - Optional overrides (e.g. portal configuration ID).
385
385
  */
386
- portal: (context: GenericActionCtx<any>, args: Parameters<(typeof PortalImplementation)["handler"]>[1], options?: Parameters<(typeof PortalImplementation)["handler"]>[2]) => Promise<default_2.Response<default_2.BillingPortal.Session>>;
386
+ portal: (context: GenericActionCtx<DataModelFromSchemaDefinition<Schema>>, args: Parameters<(typeof PortalImplementation)["handler"]>[1], options?: Parameters<(typeof PortalImplementation)["handler"]>[2]) => Promise<default_2.Response<default_2.BillingPortal.Session>>;
387
387
  /**
388
388
  * Creates a Stripe Checkout session in `subscription` mode.
389
389
  * Redirects the user to Stripe Checkout to set up a recurring subscription.
@@ -392,7 +392,7 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration &
392
392
  * @param args - Price ID, customer info, and success/cancel URLs.
393
393
  * @param options - Optional overrides for the Checkout session.
394
394
  */
395
- subscribe: (context: GenericActionCtx<any>, args: Parameters<(typeof SubscribeImplementation)["handler"]>[1], options?: Parameters<(typeof SubscribeImplementation)["handler"]>[2]) => Promise<default_2.Response<default_2.Checkout.Session>>;
395
+ subscribe: (context: GenericActionCtx<DataModelFromSchemaDefinition<Schema>>, args: Parameters<(typeof SubscribeImplementation)["handler"]>[1], options?: Parameters<(typeof SubscribeImplementation)["handler"]>[2]) => Promise<default_2.Response<default_2.Checkout.Session>>;
396
396
  /**
397
397
  * Creates a Stripe Checkout session in `payment` mode (one-time payment).
398
398
  *
@@ -400,7 +400,7 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration &
400
400
  * @param args - Price ID, quantity, and success/cancel URLs.
401
401
  * @param options - Optional overrides for the Checkout session.
402
402
  */
403
- pay: (context: GenericActionCtx<any>, args: Parameters<(typeof PayImplementation)["handler"]>[1], options?: Parameters<(typeof PayImplementation)["handler"]>[2]) => Promise<default_2.Response<default_2.Checkout.Session>>;
403
+ pay: (context: GenericActionCtx<DataModelFromSchemaDefinition<Schema>>, args: Parameters<(typeof PayImplementation)["handler"]>[1], options?: Parameters<(typeof PayImplementation)["handler"]>[2]) => Promise<default_2.Response<default_2.Checkout.Session>>;
404
404
  customers: {
405
405
  /**
406
406
  * Creates a new Stripe Customer and stores it in your Convex database.
@@ -409,7 +409,7 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration &
409
409
  * @param args - Customer details (email, name, metadata, etc.).
410
410
  * @param options - Optional overrides for the customer creation.
411
411
  */
412
- create: (context: GenericActionCtx<any>, args: Parameters<(typeof CreateCustomerImplementation)["handler"]>[1], options?: Parameters<(typeof CreateCustomerImplementation)["handler"]>[2]) => Promise<{
412
+ create: (context: GenericActionCtx<DataModelFromSchemaDefinition<Schema>>, args: Parameters<(typeof CreateCustomerImplementation)["handler"]>[1], options?: Parameters<(typeof CreateCustomerImplementation)["handler"]>[2]) => Promise<{
413
413
  _id: GenericId<"stripeCustomers">;
414
414
  _creationTime: number;
415
415
  accountId?: string | undefined;
@@ -485,7 +485,7 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration &
485
485
  * @param args - Account type, email, and capabilities.
486
486
  * @param options - Optional overrides for the account creation.
487
487
  */
488
- create: (context: GenericActionCtx<any>, args: Parameters<(typeof CreateAccountImplementation)["handler"]>[1], options?: Parameters<(typeof CreateAccountImplementation)["handler"]>[2]) => Promise<{
488
+ create: (context: GenericActionCtx<DataModelFromSchemaDefinition<Schema>>, args: Parameters<(typeof CreateAccountImplementation)["handler"]>[1], options?: Parameters<(typeof CreateAccountImplementation)["handler"]>[2]) => Promise<{
489
489
  _id: GenericId<"stripeAccounts">;
490
490
  _creationTime: number;
491
491
  entityId?: string | undefined;
@@ -525,7 +525,7 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration &
525
525
  * @param args - Account ID, refresh URL, and return URL.
526
526
  * @param options - Optional overrides for the account link.
527
527
  */
528
- link: (context: GenericActionCtx<any>, args: Parameters<(typeof CreateAccountLinkImplementation)["handler"]>[1], options?: Parameters<(typeof CreateAccountLinkImplementation)["handler"]>[2]) => Promise<default_2.Response<default_2.AccountLink>>;
528
+ link: (context: GenericActionCtx<DataModelFromSchemaDefinition<Schema>>, args: Parameters<(typeof CreateAccountLinkImplementation)["handler"]>[1], options?: Parameters<(typeof CreateAccountLinkImplementation)["handler"]>[2]) => Promise<default_2.Response<default_2.AccountLink>>;
529
529
  };
530
530
  /**
531
531
  * Returns a set of pre-built, authorization-aware Convex functions
@@ -1964,7 +1964,7 @@ export declare class Logger {
1964
1964
  debug(message: string): void;
1965
1965
  }
1966
1966
 
1967
- export declare const onlyStripeTables: (tables: Array<keyof typeof stripeTables>) => typeof stripeTables;
1967
+ export declare const onlyStripeTables: <const T extends Array<keyof typeof stripeTables>>(tables: T) => Pick<typeof stripeTables, T[number]>;
1968
1968
 
1969
1969
  declare const PayImplementation: {
1970
1970
  name: string;
@@ -2027,6 +2027,9 @@ declare type ReturnDataMap = {
2027
2027
 
2028
2028
  declare type ReturnOrigin = (typeof RETURN_ORIGINS)[number];
2029
2029
 
2030
+ /** The stripe table keys that are present in the user's schema. */
2031
+ declare type SchemaStripeTableKeys<Schema extends SchemaDefinition<GenericSchema, boolean>> = Extract<keyof StripeDataModel, keyof Schema["tables"]>;
2032
+
2030
2033
  declare type StripeDataModel = DataModelFromSchemaDefinition<typeof stripeSchema>;
2031
2034
 
2032
2035
  /**
package/dist/server.js CHANGED
@@ -5638,16 +5638,14 @@ const stripeTables = {
5638
5638
  };
5639
5639
  defineSchema(stripeTables);
5640
5640
  const allStripeTablesExcept = (tables) => Object.fromEntries(
5641
- Object.entries(stripeTables).map(([table, definition]) => [
5642
- table,
5643
- !tables.includes(table) ? definition : void 0
5644
- ])
5641
+ Object.entries(stripeTables).filter(
5642
+ ([table]) => !tables.includes(table)
5643
+ )
5645
5644
  );
5646
5645
  const onlyStripeTables = (tables) => Object.fromEntries(
5647
- Object.entries(stripeTables).map(([table, definition]) => [
5648
- table,
5649
- tables.includes(table) ? definition : void 0
5650
- ])
5646
+ Object.entries(stripeTables).filter(
5647
+ ([table]) => tables.includes(table)
5648
+ )
5651
5649
  );
5652
5650
  const DEFAULT_CONFIGURATION = {
5653
5651
  schema: void 0,
@@ -5775,7 +5773,10 @@ const DEFAULT_CONFIGURATION = {
5775
5773
  }
5776
5774
  };
5777
5775
  const normalizeConfiguration = (configuration) => {
5778
- const output = deepmerge(DEFAULT_CONFIGURATION, configuration);
5776
+ const output = deepmerge(
5777
+ DEFAULT_CONFIGURATION,
5778
+ configuration
5779
+ );
5779
5780
  const stripeTableNames = Object.keys(stripeTables);
5780
5781
  output.sync.tables = Object.fromEntries(
5781
5782
  Object.keys(configuration.schema.tables).filter((table) => stripeTableNames.includes(table)).map((table) => [table, true])
@@ -8979,8 +8980,6 @@ const PricesHandlerImplementation = defineWebhookHandler({
8979
8980
  options
8980
8981
  );
8981
8982
  break;
8982
- // TODO: careful here as the deletion is just a soft delete in Stripe
8983
- // so maybe we want to keep the record and just mark it as deleted?
8984
8983
  case "price.deleted":
8985
8984
  await storeDispatchTyped(
8986
8985
  {
@@ -9024,8 +9023,6 @@ const ProductsHandlerImplementation = defineWebhookHandler({
9024
9023
  options
9025
9024
  );
9026
9025
  break;
9027
- // TODO: careful here as the deletion is just a soft delete in Stripe
9028
- // so maybe we want to keep the record and just mark it as deleted?
9029
9026
  case "product.deleted":
9030
9027
  await storeDispatchTyped(
9031
9028
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raideno/convex-stripe",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "description": "Easy stripe billing for convex apps.",
5
5
  "keywords": [
6
6
  "billing",
@@ -54,4 +54,4 @@
54
54
  "dependencies": {
55
55
  "deepmerge": "^4.3.1"
56
56
  }
57
- }
57
+ }