@raideno/convex-stripe 0.2.4 → 0.2.6
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 -4
- 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 = {
|
|
@@ -33,7 +47,6 @@ declare const CreateAccountImplementation: {
|
|
|
33
47
|
name: string;
|
|
34
48
|
handler: (context: GenericActionCtx<StripeDataModel>, args: {
|
|
35
49
|
entityId: string;
|
|
36
|
-
type: "express" | "custom";
|
|
37
50
|
} & Omit<default_2.AccountCreateParams, "type">, stripeOptions: default_2.RequestOptions, configuration: InternalConfiguration, options: InternalOptions) => Promise<{
|
|
38
51
|
_id: GenericId<"stripeAccounts">;
|
|
39
52
|
_creationTime: number;
|
|
@@ -149,6 +162,14 @@ declare const CreateCustomerImplementation: {
|
|
|
149
162
|
}>;
|
|
150
163
|
};
|
|
151
164
|
|
|
165
|
+
export declare function defineRedirectHandler<const T extends readonly string[], S extends ArgSchema = {}>(handler: RedirectHandler<T, S>): RedirectHandler<T, S>;
|
|
166
|
+
|
|
167
|
+
declare type InferArgs<S extends ArgSchema> = {
|
|
168
|
+
[K in keyof S as S[K] extends Validator<any, "required", any> ? K : never]: Infer<S[K]>;
|
|
169
|
+
} & {
|
|
170
|
+
[K in keyof S as S[K] extends Validator<any, "optional", any> ? K : never]?: Infer<S[K]>;
|
|
171
|
+
};
|
|
172
|
+
|
|
152
173
|
export declare interface InputConfiguration {
|
|
153
174
|
stripe: {
|
|
154
175
|
/** Stripe API version to pin against (recommended for stability). */
|
|
@@ -220,8 +241,12 @@ export declare interface InputConfiguration {
|
|
|
220
241
|
* Document your intended behavior here.
|
|
221
242
|
*/
|
|
222
243
|
detached?: boolean;
|
|
223
|
-
|
|
224
|
-
|
|
244
|
+
redirect?: {
|
|
245
|
+
/** TTL for redirect state (ms). */
|
|
246
|
+
ttlMs?: number;
|
|
247
|
+
/** Additional handlers for redirect-based flows (e.g. Checkout, OAuth). */
|
|
248
|
+
handlers?: Array<ReturnType<typeof defineRedirectHandler>>;
|
|
249
|
+
};
|
|
225
250
|
}
|
|
226
251
|
|
|
227
252
|
export declare type InputOptions = Partial<InternalOptions>;
|
|
@@ -445,9 +470,9 @@ export declare const internalConvexStripe: (configuration_: InputConfiguration,
|
|
|
445
470
|
store: RegisteredMutation<"internal", {
|
|
446
471
|
id?: any;
|
|
447
472
|
value?: any;
|
|
473
|
+
data?: any;
|
|
448
474
|
indexName?: string | undefined;
|
|
449
475
|
idField?: string | undefined;
|
|
450
|
-
data?: any;
|
|
451
476
|
idValue?: any;
|
|
452
477
|
field?: string | undefined;
|
|
453
478
|
operation: string;
|
|
@@ -1632,6 +1657,22 @@ declare type RecursiveDeepRequired<T> = T extends (...args: any[]) => any ? T :
|
|
|
1632
1657
|
[K in keyof T]-?: RecursiveDeepRequired<T[K]>;
|
|
1633
1658
|
} : T;
|
|
1634
1659
|
|
|
1660
|
+
declare const REDIRECT_HANDLERS: RedirectHandler<readonly string[], ArgSchema>[];
|
|
1661
|
+
|
|
1662
|
+
export declare type RedirectHandler<TOrigins extends readonly string[], S extends ArgSchema = {}> = {
|
|
1663
|
+
origins: TOrigins;
|
|
1664
|
+
data?: S;
|
|
1665
|
+
handle: (origin: TOrigins[number], context: GenericActionCtx<StripeDataModel>, data: InferArgs<S>, configuration: InternalConfiguration, options: InternalOptions) => Promise<void>;
|
|
1666
|
+
};
|
|
1667
|
+
|
|
1668
|
+
declare const RETURN_ORIGINS: string[];
|
|
1669
|
+
|
|
1670
|
+
declare type ReturnDataMap = {
|
|
1671
|
+
[H in AllRedirectHandlers as H["origins"][number]]: H extends RedirectHandler<any, infer S> ? InferArgs<S> : never;
|
|
1672
|
+
};
|
|
1673
|
+
|
|
1674
|
+
declare type ReturnOrigin = (typeof RETURN_ORIGINS)[number];
|
|
1675
|
+
|
|
1635
1676
|
declare type StripeDataModel = DataModelFromSchemaDefinition<typeof stripeSchema>;
|
|
1636
1677
|
|
|
1637
1678
|
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,
|