@raideno/convex-stripe 0.3.4 → 0.3.5
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 +15 -35
- package/dist/index.d.ts +10 -10
- package/dist/server.js +33 -46
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,9 +17,9 @@ Stripe [syncing](./documentation/references/tables.md), subscriptions, [checkout
|
|
|
17
17
|
- [7. Run the `sync` Action](#7-run-the-sync-action)
|
|
18
18
|
- [8. Start Building](#8-start-building)
|
|
19
19
|
- [Configuration](#configuration)
|
|
20
|
+
- [Schema Configuration](#schema-configuration)
|
|
20
21
|
- [Stripe Configuration](#stripe-configuration)
|
|
21
22
|
- [Sync Configuration](#sync-configuration)
|
|
22
|
-
- [Table Selection](#table-selection)
|
|
23
23
|
- [Catalog (Unstable)](#catalog-unstable)
|
|
24
24
|
- [Webhook Configuration](#webhook-configuration)
|
|
25
25
|
- [Portal Configuration](#portal-configuration)
|
|
@@ -113,8 +113,7 @@ export default defineSchema({
|
|
|
113
113
|
});
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
> Ensure that your table configuration in `convex/schema.ts` matches your `sync.tables` configuration in `convex/stripe.ts` exactly! If your `sync.tables` tries to sync a table that is excluded from your schema, Convex Stripe will throw a runtime error when processing webhooks.
|
|
116
|
+
The package will only sync the tables you defined.
|
|
118
117
|
|
|
119
118
|
See [Tables Reference](./documentation/references/tables.md) for the full list of tables and their schemas.
|
|
120
119
|
|
|
@@ -125,16 +124,16 @@ Call `internalConvexStripe` with your Stripe credentials and sync configuration.
|
|
|
125
124
|
```ts
|
|
126
125
|
// convex/stripe.ts
|
|
127
126
|
|
|
128
|
-
import { internalConvexStripe
|
|
127
|
+
import { internalConvexStripe } from "@raideno/convex-stripe/server";
|
|
128
|
+
|
|
129
|
+
import schema from "./schema";
|
|
129
130
|
|
|
130
131
|
export const { stripe, store, sync } = internalConvexStripe({
|
|
132
|
+
schema: schema,
|
|
131
133
|
stripe: {
|
|
132
134
|
secret_key: process.env.STRIPE_SECRET_KEY!,
|
|
133
135
|
account_webhook_secret: process.env.STRIPE_ACCOUNT_WEBHOOK_SECRET!,
|
|
134
136
|
},
|
|
135
|
-
sync: {
|
|
136
|
-
tables: syncAllTables(),
|
|
137
|
-
},
|
|
138
137
|
});
|
|
139
138
|
```
|
|
140
139
|
|
|
@@ -260,6 +259,9 @@ The `internalConvexStripe` function accepts a configuration object and an option
|
|
|
260
259
|
```ts
|
|
261
260
|
const { stripe, store, sync } = internalConvexStripe(configuration, options);
|
|
262
261
|
```
|
|
262
|
+
### Schema Configuration
|
|
263
|
+
|
|
264
|
+
The `schema` key holds your convex app schema, from it the package will infer which stripe tables should be synced or not depending on what stripeTables where defined.
|
|
263
265
|
|
|
264
266
|
### Stripe Configuration
|
|
265
267
|
|
|
@@ -276,29 +278,6 @@ The `stripe` key in the configuration object holds your Stripe credentials and A
|
|
|
276
278
|
|
|
277
279
|
The `sync` key controls which tables are synced and allows you to define catalog items, webhook endpoints, and billing portal configuration.
|
|
278
280
|
|
|
279
|
-
#### Table Selection
|
|
280
|
-
|
|
281
|
-
Three helper functions are provided to control which Stripe tables are synced into Convex:
|
|
282
|
-
|
|
283
|
-
```ts
|
|
284
|
-
import {
|
|
285
|
-
syncAllTables,
|
|
286
|
-
syncAllTablesExcept,
|
|
287
|
-
syncOnlyTables,
|
|
288
|
-
} from "@raideno/convex-stripe/server";
|
|
289
|
-
|
|
290
|
-
// Sync all 24 tables (default)
|
|
291
|
-
{ tables: syncAllTables() }
|
|
292
|
-
|
|
293
|
-
// Sync all tables except specific ones
|
|
294
|
-
{ tables: syncAllTablesExcept(["stripeReviews", "stripePlans"]) }
|
|
295
|
-
|
|
296
|
-
// Sync only specific tables
|
|
297
|
-
{ tables: syncOnlyTables(["stripeCustomers", "stripeSubscriptions", "stripeProducts", "stripePrices"]) }
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
All 24 available tables are listed in the [Synced Tables](#synced-tables) section.
|
|
301
|
-
|
|
302
281
|
#### Catalog (Unstable)
|
|
303
282
|
|
|
304
283
|
The `sync.catalog` key lets you pre-define products and prices that should exist in Stripe. When the `sync` action is called with `{ catalog: true }`, the library ensures these objects exist in your Stripe account.
|
|
@@ -307,7 +286,6 @@ The `sync.catalog` key lets you pre-define products and prices that should exist
|
|
|
307
286
|
internalConvexStripe({
|
|
308
287
|
// ...
|
|
309
288
|
sync: {
|
|
310
|
-
tables: syncAllTables(),
|
|
311
289
|
catalog: {
|
|
312
290
|
products: [
|
|
313
291
|
{ name: "Pro Plan", metadata: { convex_stripe_key: "pro" } },
|
|
@@ -502,15 +480,17 @@ Then update your configuration to include it:
|
|
|
502
480
|
```ts
|
|
503
481
|
// convex/stripe.ts
|
|
504
482
|
|
|
483
|
+
import { internalConvexStripe } from "@raideno/convex-stripe/server";
|
|
484
|
+
|
|
485
|
+
import schema from "./schema";
|
|
486
|
+
|
|
505
487
|
export const { stripe, store, sync } = internalConvexStripe({
|
|
488
|
+
schema: schema,
|
|
506
489
|
stripe: {
|
|
507
490
|
secret_key: process.env.STRIPE_SECRET_KEY!,
|
|
508
491
|
account_webhook_secret: process.env.STRIPE_ACCOUNT_WEBHOOK_SECRET!,
|
|
509
492
|
connect_webhook_secret: process.env.STRIPE_CONNECT_WEBHOOK_SECRET!,
|
|
510
|
-
}
|
|
511
|
-
sync: {
|
|
512
|
-
tables: syncAllTables(),
|
|
513
|
-
},
|
|
493
|
+
}
|
|
514
494
|
});
|
|
515
495
|
```
|
|
516
496
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { GenericActionCtx } from 'convex/server';
|
|
|
4
4
|
import { GenericDataModel } from 'convex/server';
|
|
5
5
|
import { GenericId } from 'convex/values';
|
|
6
6
|
import { GenericMutationCtx } from 'convex/server';
|
|
7
|
+
import { GenericSchema } from 'convex/server';
|
|
7
8
|
import { HttpRouter } from 'convex/server';
|
|
8
9
|
import { Infer } from 'convex/values';
|
|
9
10
|
import { RegisteredAction } from 'convex/server';
|
|
@@ -176,6 +177,7 @@ declare type InferArgs<S extends ArgSchema> = {
|
|
|
176
177
|
};
|
|
177
178
|
|
|
178
179
|
export declare interface InputConfiguration {
|
|
180
|
+
schema: SchemaDefinition<GenericSchema, true>;
|
|
179
181
|
stripe: {
|
|
180
182
|
/** Stripe API version to pin against (recommended for stability). */
|
|
181
183
|
version?: default_2.StripeConfig["apiVersion"];
|
|
@@ -189,7 +191,7 @@ export declare interface InputConfiguration {
|
|
|
189
191
|
*/
|
|
190
192
|
connect_webhook_secret?: string;
|
|
191
193
|
};
|
|
192
|
-
sync
|
|
194
|
+
sync?: {
|
|
193
195
|
catalog?: {
|
|
194
196
|
/** Products to ensure exist in Stripe (optional bootstrap). */
|
|
195
197
|
products?: default_2.ProductCreateParams[];
|
|
@@ -235,7 +237,7 @@ export declare interface InputConfiguration {
|
|
|
235
237
|
/** Optional Billing Portal configuration to create/sync. */
|
|
236
238
|
portal?: default_2.BillingPortal.ConfigurationCreateParams;
|
|
237
239
|
/** Which Stripe tables you want to sync into Convex. */
|
|
238
|
-
tables
|
|
240
|
+
tables?: Record<keyof typeof stripeTables, boolean>;
|
|
239
241
|
};
|
|
240
242
|
callbacks?: {
|
|
241
243
|
/** Called after a row is inserted/upserted/deleted in your Stripe tables. */
|
|
@@ -282,7 +284,11 @@ export declare type InternalConfiguration = RecursiveDeepRequired<InputConfigura
|
|
|
282
284
|
* },
|
|
283
285
|
* });
|
|
284
286
|
*/
|
|
285
|
-
export declare const internalConvexStripe: (configuration_: InputConfiguration
|
|
287
|
+
export declare const internalConvexStripe: (configuration_: InputConfiguration & {
|
|
288
|
+
sync?: {
|
|
289
|
+
tables?: never;
|
|
290
|
+
};
|
|
291
|
+
}, options_?: InputOptions) => {
|
|
286
292
|
stripe: {
|
|
287
293
|
/** Raw HTTP handler descriptors. Prefer `addHttpRoutes` unless you need manual control. */
|
|
288
294
|
http: {
|
|
@@ -318,7 +324,7 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration,
|
|
|
318
324
|
* stripe.addHttpRoutes(http);
|
|
319
325
|
* export default http;
|
|
320
326
|
*/
|
|
321
|
-
addHttpRoutes: (http: HttpRouter
|
|
327
|
+
addHttpRoutes: (http: HttpRouter) => void;
|
|
322
328
|
/**
|
|
323
329
|
* Opens a Stripe Billing Portal session for an existing customer.
|
|
324
330
|
* Use this to let users manage their subscription, invoices, and payment methods.
|
|
@@ -9312,12 +9318,6 @@ export declare const SYNC_HANDLERS: readonly [{
|
|
|
9312
9318
|
}, configuration: InternalConfiguration, options: InternalOptions) => Promise<void>;
|
|
9313
9319
|
}];
|
|
9314
9320
|
|
|
9315
|
-
export declare const syncAllTables: () => Record<keyof typeof stripeTables, boolean>;
|
|
9316
|
-
|
|
9317
|
-
export declare const syncAllTablesExcept: (tables: Array<keyof typeof stripeTables>) => Record<keyof typeof stripeTables, boolean>;
|
|
9318
|
-
|
|
9319
|
-
export declare const syncOnlyTables: (tables: Array<keyof typeof stripeTables>) => Record<keyof typeof stripeTables, boolean>;
|
|
9320
|
-
|
|
9321
9321
|
export declare const WEBHOOK_HANDLERS: readonly [WebhookHandler<"account.updated">, WebhookHandler<"billing_portal.configuration.created" | "billing_portal.configuration.updated">, WebhookHandler<"capability.updated">, WebhookHandler<"charge.captured" | "charge.expired" | "charge.failed" | "charge.pending" | "charge.refunded" | "charge.succeeded" | "charge.updated">, WebhookHandler<"checkout.session.async_payment_failed" | "checkout.session.async_payment_succeeded" | "checkout.session.completed" | "checkout.session.expired">, WebhookHandler<"coupon.created" | "coupon.deleted" | "coupon.updated">, WebhookHandler<"credit_note.created" | "credit_note.updated" | "credit_note.voided">, WebhookHandler<"customer.created" | "customer.deleted" | "customer.updated">, WebhookHandler<"charge.dispute.closed" | "charge.dispute.created" | "charge.dispute.funds_reinstated" | "charge.dispute.funds_withdrawn" | "charge.dispute.updated">, WebhookHandler<"radar.early_fraud_warning.created" | "radar.early_fraud_warning.updated">, WebhookHandler<"invoice.created" | "invoice.deleted" | "invoice.finalization_failed" | "invoice.finalized" | "invoice.marked_uncollectible" | "invoice.overdue" | "invoice.overpaid" | "invoice.paid" | "invoice.payment_action_required" | "invoice.payment_failed" | "invoice.payment_succeeded" | "invoice.sent" | "invoice.upcoming" | "invoice.updated" | "invoice.voided" | "invoice.will_be_due">, WebhookHandler<"mandate.updated">, WebhookHandler<"payment_intent.amount_capturable_updated" | "payment_intent.canceled" | "payment_intent.created" | "payment_intent.partially_funded" | "payment_intent.payment_failed" | "payment_intent.processing" | "payment_intent.requires_action" | "payment_intent.succeeded">, WebhookHandler<"payment_method.attached" | "payment_method.automatically_updated" | "payment_method.detached" | "payment_method.updated">, WebhookHandler<"payout.canceled" | "payout.created" | "payout.failed" | "payout.paid" | "payout.reconciliation_completed" | "payout.updated">, WebhookHandler<"plan.created" | "plan.deleted" | "plan.updated">, WebhookHandler<"price.created" | "price.deleted" | "price.updated">, WebhookHandler<"product.created" | "product.deleted" | "product.updated">, WebhookHandler<"promotion_code.created" | "promotion_code.updated">, WebhookHandler<"charge.refund.updated" | "refund.created" | "refund.failed" | "refund.updated">, WebhookHandler<"review.closed" | "review.opened">, WebhookHandler<"setup_intent.canceled" | "setup_intent.created" | "setup_intent.requires_action" | "setup_intent.setup_failed" | "setup_intent.succeeded">, WebhookHandler<"subscription_schedule.aborted" | "subscription_schedule.canceled" | "subscription_schedule.completed" | "subscription_schedule.created" | "subscription_schedule.expiring" | "subscription_schedule.released" | "subscription_schedule.updated">, WebhookHandler<"customer.subscription.created" | "customer.subscription.deleted" | "customer.subscription.paused" | "customer.subscription.pending_update_applied" | "customer.subscription.pending_update_expired" | "customer.subscription.resumed" | "customer.subscription.trial_will_end" | "customer.subscription.updated">, WebhookHandler<"customer.tax_id.created" | "customer.tax_id.deleted" | "customer.tax_id.updated">, WebhookHandler<"transfer.created" | "transfer.reversed" | "transfer.updated">];
|
|
9322
9322
|
|
|
9323
9323
|
declare type WebhookHandler<TEvents extends default_2.Event.Type> = {
|
package/dist/server.js
CHANGED
|
@@ -5612,21 +5612,6 @@ const stripeTables = {
|
|
|
5612
5612
|
}).index("byAccountId", ["accountId"]).index(BY_STRIPE_ID_INDEX_NAME, ["capabilityId"])
|
|
5613
5613
|
};
|
|
5614
5614
|
defineSchema(stripeTables);
|
|
5615
|
-
const syncAllTables = () => Object.fromEntries(
|
|
5616
|
-
Object.keys(stripeTables).map((table) => [table, true])
|
|
5617
|
-
);
|
|
5618
|
-
const syncAllTablesExcept = (tables) => Object.fromEntries(
|
|
5619
|
-
Object.keys(stripeTables).map((table) => [
|
|
5620
|
-
table,
|
|
5621
|
-
!tables.includes(table)
|
|
5622
|
-
])
|
|
5623
|
-
);
|
|
5624
|
-
const syncOnlyTables = (tables) => Object.fromEntries(
|
|
5625
|
-
Object.keys(stripeTables).map((table) => [
|
|
5626
|
-
table,
|
|
5627
|
-
tables.includes(table)
|
|
5628
|
-
])
|
|
5629
|
-
);
|
|
5630
5615
|
const allStripeTablesExcept = (tables) => Object.fromEntries(
|
|
5631
5616
|
Object.entries(stripeTables).map(([table, definition]) => [
|
|
5632
5617
|
table,
|
|
@@ -5640,6 +5625,7 @@ const onlyStripeTables = (tables) => Object.fromEntries(
|
|
|
5640
5625
|
])
|
|
5641
5626
|
);
|
|
5642
5627
|
const DEFAULT_CONFIGURATION = {
|
|
5628
|
+
schema: void 0,
|
|
5643
5629
|
stripe: {
|
|
5644
5630
|
version: "2025-08-27.basil",
|
|
5645
5631
|
secret_key: "",
|
|
@@ -5659,42 +5645,42 @@ const DEFAULT_CONFIGURATION = {
|
|
|
5659
5645
|
}
|
|
5660
5646
|
},
|
|
5661
5647
|
sync: {
|
|
5662
|
-
catalog: {
|
|
5663
|
-
products: [],
|
|
5664
|
-
prices: [],
|
|
5665
|
-
metadataKey: "convex_stripe_key",
|
|
5666
|
-
behavior: {
|
|
5667
|
-
onExisting: "update",
|
|
5668
|
-
onMissingKey: "create"
|
|
5669
|
-
}
|
|
5670
|
-
},
|
|
5671
5648
|
tables: {
|
|
5672
5649
|
stripeAccounts: true,
|
|
5650
|
+
stripeBillingPortalConfigurations: true,
|
|
5673
5651
|
stripeCapabilities: true,
|
|
5674
|
-
|
|
5652
|
+
stripeCharges: true,
|
|
5653
|
+
stripeCheckoutSessions: true,
|
|
5675
5654
|
stripeCoupons: true,
|
|
5655
|
+
stripeCreditNotes: true,
|
|
5676
5656
|
stripeCustomers: true,
|
|
5657
|
+
stripeDisputes: true,
|
|
5658
|
+
stripeEarlyFraudWarnings: true,
|
|
5659
|
+
stripeInvoices: true,
|
|
5660
|
+
stripeMandates: true,
|
|
5661
|
+
stripePaymentIntents: true,
|
|
5662
|
+
stripePaymentMethods: true,
|
|
5663
|
+
stripePayouts: true,
|
|
5664
|
+
stripePlans: true,
|
|
5677
5665
|
stripePrices: true,
|
|
5678
5666
|
stripeProducts: true,
|
|
5679
5667
|
stripePromotionCodes: true,
|
|
5680
|
-
stripeSubscriptions: true,
|
|
5681
|
-
stripePayouts: true,
|
|
5682
|
-
stripeCheckoutSessions: true,
|
|
5683
|
-
stripePaymentIntents: true,
|
|
5684
5668
|
stripeRefunds: true,
|
|
5685
|
-
stripeInvoices: true,
|
|
5686
5669
|
stripeReviews: true,
|
|
5687
|
-
stripeCharges: true,
|
|
5688
|
-
stripeCreditNotes: true,
|
|
5689
|
-
stripeDisputes: true,
|
|
5690
|
-
stripeEarlyFraudWarnings: true,
|
|
5691
|
-
stripePaymentMethods: true,
|
|
5692
|
-
stripePlans: true,
|
|
5693
5670
|
stripeSetupIntents: true,
|
|
5671
|
+
stripeSubscriptions: true,
|
|
5694
5672
|
stripeSubscriptionSchedules: true,
|
|
5695
5673
|
stripeTaxIds: true,
|
|
5696
|
-
|
|
5697
|
-
|
|
5674
|
+
stripeTransfers: true
|
|
5675
|
+
},
|
|
5676
|
+
catalog: {
|
|
5677
|
+
products: [],
|
|
5678
|
+
prices: [],
|
|
5679
|
+
metadataKey: "convex_stripe_key",
|
|
5680
|
+
behavior: {
|
|
5681
|
+
onExisting: "update",
|
|
5682
|
+
onMissingKey: "create"
|
|
5683
|
+
}
|
|
5698
5684
|
},
|
|
5699
5685
|
webhooks: {
|
|
5700
5686
|
account: {
|
|
@@ -5763,8 +5749,13 @@ const DEFAULT_CONFIGURATION = {
|
|
|
5763
5749
|
}
|
|
5764
5750
|
}
|
|
5765
5751
|
};
|
|
5766
|
-
const normalizeConfiguration = (
|
|
5767
|
-
|
|
5752
|
+
const normalizeConfiguration = (configuration) => {
|
|
5753
|
+
const output = deepmerge(DEFAULT_CONFIGURATION, configuration);
|
|
5754
|
+
const stripeTableNames = Object.keys(stripeTables);
|
|
5755
|
+
output.sync.tables = Object.fromEntries(
|
|
5756
|
+
Object.keys(configuration.schema.tables).filter((table) => stripeTableNames.includes(table)).map((table) => [table, true])
|
|
5757
|
+
);
|
|
5758
|
+
return output;
|
|
5768
5759
|
};
|
|
5769
5760
|
const DEFAULT_OPTIONS = {
|
|
5770
5761
|
store: "store",
|
|
@@ -9527,8 +9518,7 @@ const internalConvexStripe = (configuration_, options_) => {
|
|
|
9527
9518
|
* stripe.addHttpRoutes(http);
|
|
9528
9519
|
* export default http;
|
|
9529
9520
|
*/
|
|
9530
|
-
addHttpRoutes: (http
|
|
9531
|
-
config = normalizeConfiguration(config || configuration_);
|
|
9521
|
+
addHttpRoutes: (http) => {
|
|
9532
9522
|
http.route({
|
|
9533
9523
|
path: http_.webhook.path,
|
|
9534
9524
|
method: http_.webhook.method,
|
|
@@ -9679,8 +9669,5 @@ export {
|
|
|
9679
9669
|
defineWebhookHandler,
|
|
9680
9670
|
internalConvexStripe,
|
|
9681
9671
|
onlyStripeTables,
|
|
9682
|
-
stripeTables
|
|
9683
|
-
syncAllTables,
|
|
9684
|
-
syncAllTablesExcept,
|
|
9685
|
-
syncOnlyTables
|
|
9672
|
+
stripeTables
|
|
9686
9673
|
};
|