@raideno/convex-stripe 0.2.6 → 0.2.8
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 +14 -1
- package/dist/server.js +20 -12
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -164,6 +164,8 @@ declare const CreateCustomerImplementation: {
|
|
|
164
164
|
|
|
165
165
|
export declare function defineRedirectHandler<const T extends readonly string[], S extends ArgSchema = {}>(handler: RedirectHandler<T, S>): RedirectHandler<T, S>;
|
|
166
166
|
|
|
167
|
+
export declare function defineWebhookHandler<const T extends default_2.Event.Type>(handler: WebhookHandler<T>): WebhookHandler<T>;
|
|
168
|
+
|
|
167
169
|
declare type InferArgs<S extends ArgSchema> = {
|
|
168
170
|
[K in keyof S as S[K] extends Validator<any, "required", any> ? K : never]: Infer<S[K]>;
|
|
169
171
|
} & {
|
|
@@ -241,6 +243,10 @@ export declare interface InputConfiguration {
|
|
|
241
243
|
* Document your intended behavior here.
|
|
242
244
|
*/
|
|
243
245
|
detached?: boolean;
|
|
246
|
+
webhook?: {
|
|
247
|
+
/** Optional additional webhook handlers to handle custom Stripe events or override default behavior. */
|
|
248
|
+
handlers?: Array<ReturnType<typeof defineWebhookHandler>>;
|
|
249
|
+
};
|
|
244
250
|
redirect?: {
|
|
245
251
|
/** TTL for redirect state (ms). */
|
|
246
252
|
ttlMs?: number;
|
|
@@ -1602,12 +1608,12 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration,
|
|
|
1602
1608
|
* Run this manually or on deploy to keep Stripe in sync with your config.
|
|
1603
1609
|
*/
|
|
1604
1610
|
sync: RegisteredAction<"internal", {
|
|
1611
|
+
catalog?: boolean | undefined;
|
|
1605
1612
|
webhooks?: {
|
|
1606
1613
|
account?: boolean | undefined;
|
|
1607
1614
|
connect?: boolean | undefined;
|
|
1608
1615
|
} | undefined;
|
|
1609
1616
|
portal?: boolean | undefined;
|
|
1610
|
-
unstable_catalog?: boolean | undefined;
|
|
1611
1617
|
tables: boolean | {
|
|
1612
1618
|
withConnect?: boolean | undefined;
|
|
1613
1619
|
};
|
|
@@ -9050,4 +9056,11 @@ export declare const syncAllTablesExcept: (tables: Array<keyof typeof stripeTabl
|
|
|
9050
9056
|
|
|
9051
9057
|
export declare const syncOnlyTables: (tables: Array<keyof typeof stripeTables>) => Record<keyof typeof stripeTables, boolean>;
|
|
9052
9058
|
|
|
9059
|
+
declare type WebhookHandler<TEvents extends default_2.Event.Type> = {
|
|
9060
|
+
events: readonly TEvents[];
|
|
9061
|
+
handle: (event_: Extract<default_2.Event, {
|
|
9062
|
+
type: TEvents;
|
|
9063
|
+
}>, context: GenericActionCtx<StripeDataModel>, configuration: InternalConfiguration, options: InternalOptions) => Promise<void>;
|
|
9064
|
+
};
|
|
9065
|
+
|
|
9053
9066
|
export { }
|
package/dist/server.js
CHANGED
|
@@ -5632,6 +5632,9 @@ const DEFAULT_CONFIGURATION = {
|
|
|
5632
5632
|
ttlMs: 15 * 60 * 1e3,
|
|
5633
5633
|
handlers: []
|
|
5634
5634
|
},
|
|
5635
|
+
webhook: {
|
|
5636
|
+
handlers: []
|
|
5637
|
+
},
|
|
5635
5638
|
detached: false,
|
|
5636
5639
|
callbacks: {
|
|
5637
5640
|
afterChange: async () => {
|
|
@@ -8282,9 +8285,7 @@ const SyncPortalImplementation = defineActionImplementation({
|
|
|
8282
8285
|
);
|
|
8283
8286
|
return;
|
|
8284
8287
|
}
|
|
8285
|
-
await stripe.billingPortal.configurations.create(
|
|
8286
|
-
configuration.sync.portal
|
|
8287
|
-
);
|
|
8288
|
+
await stripe.billingPortal.configurations.create(configuration.sync.portal);
|
|
8288
8289
|
console.info(
|
|
8289
8290
|
"[STRIPE SYNC PORTAL](Created) Default billing portal configuration created."
|
|
8290
8291
|
);
|
|
@@ -9482,6 +9483,18 @@ const webhookImplementation = async (configuration, options, context, request, c
|
|
|
9482
9483
|
}
|
|
9483
9484
|
}
|
|
9484
9485
|
}
|
|
9486
|
+
for (const handler of configuration.webhook.handlers) {
|
|
9487
|
+
if (handler.events.includes(event.type)) {
|
|
9488
|
+
try {
|
|
9489
|
+
await handler.handle(event, context, configuration, options);
|
|
9490
|
+
options.logger.debug(`[STRIPE HOOK](HANDLED BY CONFIG): ${event.type}`);
|
|
9491
|
+
} catch (error) {
|
|
9492
|
+
options.logger.error(
|
|
9493
|
+
`[STRIPE HOOK](Error in config handler): ${error}`
|
|
9494
|
+
);
|
|
9495
|
+
}
|
|
9496
|
+
}
|
|
9497
|
+
}
|
|
9485
9498
|
return new Response("OK", { status: 200 });
|
|
9486
9499
|
};
|
|
9487
9500
|
const SyncAccountWebhookImplementation = defineActionImplementation({
|
|
@@ -9591,19 +9604,13 @@ const SyncImplementation = defineActionImplementation({
|
|
|
9591
9604
|
})
|
|
9592
9605
|
),
|
|
9593
9606
|
portal: v.optional(v.boolean()),
|
|
9594
|
-
|
|
9607
|
+
catalog: v.optional(v.boolean())
|
|
9595
9608
|
}),
|
|
9596
9609
|
name: "sync",
|
|
9597
|
-
handler: async (context, {
|
|
9598
|
-
tables,
|
|
9599
|
-
webhooks,
|
|
9600
|
-
// TODO: enable catalog and portal setup for accounts as well, except if enabling it on root enables it on sub accounts too
|
|
9601
|
-
portal,
|
|
9602
|
-
unstable_catalog
|
|
9603
|
-
}, configuration, options) => {
|
|
9610
|
+
handler: async (context, { tables, webhooks, portal, catalog }, configuration, options) => {
|
|
9604
9611
|
const tasks = [
|
|
9605
9612
|
[
|
|
9606
|
-
Boolean(
|
|
9613
|
+
Boolean(catalog),
|
|
9607
9614
|
() => SyncCatalogImplementation.handler(
|
|
9608
9615
|
context,
|
|
9609
9616
|
{},
|
|
@@ -9870,6 +9877,7 @@ export {
|
|
|
9870
9877
|
Logger,
|
|
9871
9878
|
buildSignedReturnUrl,
|
|
9872
9879
|
defineRedirectHandler,
|
|
9880
|
+
defineWebhookHandler,
|
|
9873
9881
|
internalConvexStripe,
|
|
9874
9882
|
stripeTables,
|
|
9875
9883
|
syncAllTables,
|