@raideno/convex-stripe 0.2.4 → 0.2.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/dist/index.d.ts +45 -3
- package/dist/server.js +10 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,11 +5,13 @@ import { GenericDataModel } from 'convex/server';
|
|
|
5
5
|
import { GenericId } from 'convex/values';
|
|
6
6
|
import { GenericMutationCtx } from 'convex/server';
|
|
7
7
|
import { HttpRouter } from 'convex/server';
|
|
8
|
+
import { Infer } from 'convex/values';
|
|
8
9
|
import { RegisteredAction } from 'convex/server';
|
|
9
10
|
import { RegisteredMutation } from 'convex/server';
|
|
10
11
|
import { RoutableMethod } from 'convex/server';
|
|
11
12
|
import { SchemaDefinition } from 'convex/server';
|
|
12
13
|
import { TableDefinition } from 'convex/server';
|
|
14
|
+
import { Validator } from 'convex/values';
|
|
13
15
|
import { VAny } from 'convex/values';
|
|
14
16
|
import { VArray } from 'convex/values';
|
|
15
17
|
import { VBoolean } from 'convex/values';
|
|
@@ -21,6 +23,18 @@ import { VRecord } from 'convex/values';
|
|
|
21
23
|
import { VString } from 'convex/values';
|
|
22
24
|
import { VUnion } from 'convex/values';
|
|
23
25
|
|
|
26
|
+
declare type AllRedirectHandlers = (typeof REDIRECT_HANDLERS)[number];
|
|
27
|
+
|
|
28
|
+
declare type ArgSchema = Record<string, Validator<any, "optional" | "required", any>>;
|
|
29
|
+
|
|
30
|
+
export declare function buildSignedReturnUrl<O extends ReturnOrigin>({ configuration, origin, failureUrl, targetUrl, data, }: {
|
|
31
|
+
configuration: InternalConfiguration;
|
|
32
|
+
origin: O;
|
|
33
|
+
failureUrl?: string;
|
|
34
|
+
targetUrl: string;
|
|
35
|
+
data: ReturnDataMap[O];
|
|
36
|
+
}): Promise<string>;
|
|
37
|
+
|
|
24
38
|
export declare type CallbackAfterChange = (context: GenericMutationCtx<any>, operation: "upsert" | "delete" | "insert", event: CallbackEvent) => Promise<void>;
|
|
25
39
|
|
|
26
40
|
export declare type CallbackEvent = {
|
|
@@ -149,6 +163,14 @@ declare const CreateCustomerImplementation: {
|
|
|
149
163
|
}>;
|
|
150
164
|
};
|
|
151
165
|
|
|
166
|
+
export declare function defineRedirectHandler<const T extends readonly string[], S extends ArgSchema = {}>(handler: RedirectHandler<T, S>): RedirectHandler<T, S>;
|
|
167
|
+
|
|
168
|
+
declare type InferArgs<S extends ArgSchema> = {
|
|
169
|
+
[K in keyof S as S[K] extends Validator<any, "required", any> ? K : never]: Infer<S[K]>;
|
|
170
|
+
} & {
|
|
171
|
+
[K in keyof S as S[K] extends Validator<any, "optional", any> ? K : never]?: Infer<S[K]>;
|
|
172
|
+
};
|
|
173
|
+
|
|
152
174
|
export declare interface InputConfiguration {
|
|
153
175
|
stripe: {
|
|
154
176
|
/** Stripe API version to pin against (recommended for stability). */
|
|
@@ -220,8 +242,12 @@ export declare interface InputConfiguration {
|
|
|
220
242
|
* Document your intended behavior here.
|
|
221
243
|
*/
|
|
222
244
|
detached?: boolean;
|
|
223
|
-
|
|
224
|
-
|
|
245
|
+
redirect?: {
|
|
246
|
+
/** TTL for redirect state (ms). */
|
|
247
|
+
ttlMs?: number;
|
|
248
|
+
/** Additional handlers for redirect-based flows (e.g. Checkout, OAuth). */
|
|
249
|
+
handlers?: Array<ReturnType<typeof defineRedirectHandler>>;
|
|
250
|
+
};
|
|
225
251
|
}
|
|
226
252
|
|
|
227
253
|
export declare type InputOptions = Partial<InternalOptions>;
|
|
@@ -445,9 +471,9 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration,
|
|
|
445
471
|
store: RegisteredMutation<"internal", {
|
|
446
472
|
id?: any;
|
|
447
473
|
value?: any;
|
|
474
|
+
data?: any;
|
|
448
475
|
indexName?: string | undefined;
|
|
449
476
|
idField?: string | undefined;
|
|
450
|
-
data?: any;
|
|
451
477
|
idValue?: any;
|
|
452
478
|
field?: string | undefined;
|
|
453
479
|
operation: string;
|
|
@@ -1632,6 +1658,22 @@ declare type RecursiveDeepRequired<T> = T extends (...args: any[]) => any ? T :
|
|
|
1632
1658
|
[K in keyof T]-?: RecursiveDeepRequired<T[K]>;
|
|
1633
1659
|
} : T;
|
|
1634
1660
|
|
|
1661
|
+
declare const REDIRECT_HANDLERS: RedirectHandler<readonly string[], ArgSchema>[];
|
|
1662
|
+
|
|
1663
|
+
export declare type RedirectHandler<TOrigins extends readonly string[], S extends ArgSchema = {}> = {
|
|
1664
|
+
origins: TOrigins;
|
|
1665
|
+
data?: S;
|
|
1666
|
+
handle: (origin: TOrigins[number], context: GenericActionCtx<StripeDataModel>, data: InferArgs<S>, configuration: InternalConfiguration, options: InternalOptions) => Promise<void>;
|
|
1667
|
+
};
|
|
1668
|
+
|
|
1669
|
+
declare const RETURN_ORIGINS: string[];
|
|
1670
|
+
|
|
1671
|
+
declare type ReturnDataMap = {
|
|
1672
|
+
[H in AllRedirectHandlers as H["origins"][number]]: H extends RedirectHandler<any, infer S> ? InferArgs<S> : never;
|
|
1673
|
+
};
|
|
1674
|
+
|
|
1675
|
+
declare type ReturnOrigin = (typeof RETURN_ORIGINS)[number];
|
|
1676
|
+
|
|
1635
1677
|
declare type StripeDataModel = DataModelFromSchemaDefinition<typeof stripeSchema>;
|
|
1636
1678
|
|
|
1637
1679
|
declare const stripeSchema: SchemaDefinition< {
|
package/dist/server.js
CHANGED
|
@@ -5628,7 +5628,10 @@ const DEFAULT_CONFIGURATION = {
|
|
|
5628
5628
|
account_webhook_secret: "",
|
|
5629
5629
|
connect_webhook_secret: ""
|
|
5630
5630
|
},
|
|
5631
|
-
|
|
5631
|
+
redirect: {
|
|
5632
|
+
ttlMs: 15 * 60 * 1e3,
|
|
5633
|
+
handlers: []
|
|
5634
|
+
},
|
|
5632
5635
|
detached: false,
|
|
5633
5636
|
callbacks: {
|
|
5634
5637
|
afterChange: async () => {
|
|
@@ -6322,7 +6325,7 @@ async function buildSignedReturnUrl({
|
|
|
6322
6325
|
data,
|
|
6323
6326
|
targetUrl,
|
|
6324
6327
|
failureUrl,
|
|
6325
|
-
exp: Date.now() + configuration.
|
|
6328
|
+
exp: Date.now() + configuration.redirect.ttlMs
|
|
6326
6329
|
};
|
|
6327
6330
|
const data_ = toBase64Url(JSON.stringify(payload));
|
|
6328
6331
|
const expected = await signData(
|
|
@@ -6365,10 +6368,11 @@ REDIRECT_HANDLERS.map(
|
|
|
6365
6368
|
(handler) => handler.origins
|
|
6366
6369
|
).flat();
|
|
6367
6370
|
const redirectImplementation = async (configuration, options, context, request) => {
|
|
6371
|
+
const handlers = [...REDIRECT_HANDLERS, ...configuration.redirect.handlers];
|
|
6368
6372
|
const url = new URL(request.url);
|
|
6369
6373
|
const segments = url.pathname.split("/").filter(Boolean);
|
|
6370
6374
|
const origin_ = segments[segments.length - 1];
|
|
6371
|
-
if (!origin_ || !
|
|
6375
|
+
if (!origin_ || !handlers.map((handler) => handler.origins).flat().includes(origin_)) {
|
|
6372
6376
|
return new Response("Invalid return origin", { status: 400 });
|
|
6373
6377
|
}
|
|
6374
6378
|
const origin = origin_;
|
|
@@ -6419,7 +6423,7 @@ const redirectImplementation = async (configuration, options, context, request)
|
|
|
6419
6423
|
}
|
|
6420
6424
|
return new Response("Invalid target", { status: 400 });
|
|
6421
6425
|
}
|
|
6422
|
-
for (const handler of
|
|
6426
|
+
for (const handler of handlers) {
|
|
6423
6427
|
if (handler.origins.includes(origin)) {
|
|
6424
6428
|
try {
|
|
6425
6429
|
await handler.handle(
|
|
@@ -9864,6 +9868,8 @@ const internalConvexStripe = (configuration_, options_) => {
|
|
|
9864
9868
|
};
|
|
9865
9869
|
export {
|
|
9866
9870
|
Logger,
|
|
9871
|
+
buildSignedReturnUrl,
|
|
9872
|
+
defineRedirectHandler,
|
|
9867
9873
|
internalConvexStripe,
|
|
9868
9874
|
stripeTables,
|
|
9869
9875
|
syncAllTables,
|