paykitjs 0.1.0-alpha.2

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.
Files changed (70) hide show
  1. package/LICENSE +21 -0
  2. package/dist/_virtual/_rolldown/runtime.js +13 -0
  3. package/dist/api/define-route.d.ts +94 -0
  4. package/dist/api/define-route.js +153 -0
  5. package/dist/api/methods.d.ts +422 -0
  6. package/dist/api/methods.js +67 -0
  7. package/dist/cli/commands/check.js +92 -0
  8. package/dist/cli/commands/init.js +264 -0
  9. package/dist/cli/commands/push.js +73 -0
  10. package/dist/cli/commands/telemetry.js +16 -0
  11. package/dist/cli/index.d.ts +1 -0
  12. package/dist/cli/index.js +21 -0
  13. package/dist/cli/templates/index.js +64 -0
  14. package/dist/cli/utils/detect.js +67 -0
  15. package/dist/cli/utils/format.js +58 -0
  16. package/dist/cli/utils/get-config.js +117 -0
  17. package/dist/cli/utils/telemetry.js +103 -0
  18. package/dist/client/index.d.ts +25 -0
  19. package/dist/client/index.js +27 -0
  20. package/dist/core/context.d.ts +17 -0
  21. package/dist/core/context.js +23 -0
  22. package/dist/core/create-paykit.d.ts +7 -0
  23. package/dist/core/create-paykit.js +52 -0
  24. package/dist/core/error-codes.d.ts +12 -0
  25. package/dist/core/error-codes.js +10 -0
  26. package/dist/core/errors.d.ts +41 -0
  27. package/dist/core/errors.js +47 -0
  28. package/dist/core/logger.d.ts +11 -0
  29. package/dist/core/logger.js +51 -0
  30. package/dist/core/utils.js +21 -0
  31. package/dist/customer/customer.api.js +47 -0
  32. package/dist/customer/customer.service.js +342 -0
  33. package/dist/customer/customer.types.d.ts +31 -0
  34. package/dist/database/index.d.ts +8 -0
  35. package/dist/database/index.js +32 -0
  36. package/dist/database/migrations/0000_init.sql +157 -0
  37. package/dist/database/migrations/meta/0000_snapshot.json +1222 -0
  38. package/dist/database/migrations/meta/_journal.json +13 -0
  39. package/dist/database/schema.d.ts +1767 -0
  40. package/dist/database/schema.js +150 -0
  41. package/dist/entitlement/entitlement.api.js +33 -0
  42. package/dist/entitlement/entitlement.service.d.ts +17 -0
  43. package/dist/entitlement/entitlement.service.js +123 -0
  44. package/dist/handlers/next.d.ts +9 -0
  45. package/dist/handlers/next.js +9 -0
  46. package/dist/index.d.ts +14 -0
  47. package/dist/index.js +6 -0
  48. package/dist/invoice/invoice.service.js +54 -0
  49. package/dist/payment/payment.service.js +49 -0
  50. package/dist/payment-method/payment-method.service.js +78 -0
  51. package/dist/product/product-sync.service.js +111 -0
  52. package/dist/product/product.service.js +127 -0
  53. package/dist/providers/provider.d.ts +159 -0
  54. package/dist/providers/stripe.js +547 -0
  55. package/dist/subscription/subscription.api.js +24 -0
  56. package/dist/subscription/subscription.service.js +896 -0
  57. package/dist/subscription/subscription.types.d.ts +18 -0
  58. package/dist/subscription/subscription.types.js +11 -0
  59. package/dist/testing/testing.api.js +29 -0
  60. package/dist/testing/testing.service.js +49 -0
  61. package/dist/types/events.d.ts +181 -0
  62. package/dist/types/instance.d.ts +88 -0
  63. package/dist/types/models.d.ts +11 -0
  64. package/dist/types/options.d.ts +32 -0
  65. package/dist/types/plugin.d.ts +11 -0
  66. package/dist/types/schema.d.ts +99 -0
  67. package/dist/types/schema.js +192 -0
  68. package/dist/webhook/webhook.api.js +29 -0
  69. package/dist/webhook/webhook.service.js +143 -0
  70. package/package.json +72 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Max Katz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,13 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return target;
11
+ };
12
+ //#endregion
13
+ export { __exportAll };
@@ -0,0 +1,94 @@
1
+ import { PayKitContext } from "../core/context.js";
2
+ import { Customer } from "../types/models.js";
3
+ import * as better_call0 from "better-call";
4
+ import { EndpointContext, createEndpoint } from "better-call";
5
+ import * as z from "zod";
6
+
7
+ //#region src/api/define-route.d.ts
8
+ declare const paykitMiddleware: better_call0.Middleware<(inputContext: Record<string, any>) => Promise<PayKitContext>>;
9
+ declare const createPayKitEndpoint: ReturnType<typeof createEndpoint.create<{
10
+ use: [typeof paykitMiddleware];
11
+ }>>;
12
+ type BetterCallOptions = Parameters<typeof createPayKitEndpoint>[1];
13
+ type OptionalCustomer<TRequireCustomer extends boolean> = TRequireCustomer extends true ? {
14
+ customer: Customer;
15
+ } : {
16
+ customer?: undefined;
17
+ };
18
+ type PayKitMethodContext<TInput, TRequireCustomer extends boolean = false, TParams = Record<string, string> | undefined, THeaders = Headers, TRequest = Request | undefined> = {
19
+ headers: THeaders;
20
+ input: TInput;
21
+ params: TParams;
22
+ paykit: PayKitContext;
23
+ request: TRequest;
24
+ } & OptionalCustomer<TRequireCustomer>;
25
+ type PayKitMethod<TServerInput, TResult> = ((paykit: PayKitContext, input: TServerInput, request?: Request) => Promise<TResult>) & {
26
+ client?: boolean;
27
+ endpoint?: {
28
+ options: unknown;
29
+ path: string;
30
+ } & Record<string, unknown>;
31
+ };
32
+ type PayKitMethodRouteConfig = Omit<BetterCallOptions, "body" | "method"> & {
33
+ client?: boolean;
34
+ method: NonNullable<BetterCallOptions["method"]>;
35
+ path: string;
36
+ resolveInput?: (ctx: BetterCallEndpointContext) => Promise<unknown> | unknown;
37
+ };
38
+ interface PayKitMethodConfig {
39
+ input?: BetterCallOptions extends {
40
+ body?: infer TBody;
41
+ } ? TBody : never;
42
+ requireCustomer?: boolean;
43
+ route?: PayKitMethodRouteConfig;
44
+ resolveServerCustomerId?: (input: unknown) => string | undefined;
45
+ }
46
+ type InferSchemaInput<TSchema> = TSchema extends {
47
+ _output: infer TOutput;
48
+ } ? TOutput : never;
49
+ type PayKitReturnUrlSchema = z.ZodURL & {
50
+ __paykitReturnUrl: true;
51
+ };
52
+ type InferMethodInput<TConfig extends PayKitMethodConfig> = TConfig["input"] extends undefined ? TConfig["route"] extends {
53
+ resolveInput: (...args: unknown[]) => infer TResolved;
54
+ } ? Awaited<TResolved> : undefined : InferSchemaInput<NonNullable<TConfig["input"]>>;
55
+ type InferRequireCustomer<TConfig extends PayKitMethodConfig> = TConfig["requireCustomer"] extends true ? true : false;
56
+ type ServerMethodInput<TConfig extends PayKitMethodConfig> = InferRequireCustomer<TConfig> extends true ? AddCustomerId<InferMethodInput<TConfig>> : InferMethodInput<TConfig>;
57
+ type AddCustomerId<TInput> = TInput extends undefined ? {
58
+ customerId: string;
59
+ } : TInput extends object ? TInput & {
60
+ customerId: string;
61
+ } : TInput;
62
+ type BetterCallEndpointContext = EndpointContext<string, NonNullable<BetterCallOptions["method"]>, object | undefined, undefined, [], boolean, boolean, PayKitContext>;
63
+ type InferRouteContext<TConfig extends PayKitMethodConfig> = TConfig["route"] extends {
64
+ path: infer TPath extends string;
65
+ method: infer TMethod extends NonNullable<BetterCallOptions["method"]>;
66
+ requireHeaders?: infer TRequireHeaders extends boolean;
67
+ requireRequest?: infer TRequireRequest extends boolean;
68
+ } ? EndpointContext<TPath, TMethod, TConfig["input"] extends object ? TConfig["input"] : undefined, undefined, [], TRequireHeaders, TRequireRequest, PayKitContext> : EndpointContext<never, NonNullable<BetterCallOptions["method"]>, TConfig["input"] extends object ? TConfig["input"] : undefined, undefined, [], false, false, PayKitContext>;
69
+ type InferRoutePath<TConfig extends PayKitMethodConfig> = TConfig["route"] extends {
70
+ path: infer TPath extends string;
71
+ } ? TPath : never;
72
+ type InferClientRoute<TConfig extends PayKitMethodConfig> = TConfig["route"] extends {
73
+ client: true;
74
+ } ? true : false;
75
+ type InferMethodMeta<TConfig extends PayKitMethodConfig> = [InferRoutePath<TConfig>] extends [never] ? {
76
+ client?: boolean;
77
+ endpoint?: {
78
+ options: unknown;
79
+ path: string;
80
+ } & Record<string, unknown>;
81
+ } : {
82
+ endpoint: {
83
+ options: unknown;
84
+ path: InferRoutePath<TConfig>;
85
+ } & Record<string, unknown>;
86
+ } & (InferClientRoute<TConfig> extends true ? {
87
+ client: true;
88
+ } : {
89
+ client?: false | undefined;
90
+ });
91
+ declare function definePayKitMethod<const TConfig extends PayKitMethodConfig, TResult>(config: TConfig, handler: (ctx: PayKitMethodContext<InferMethodInput<TConfig>, InferRequireCustomer<TConfig>, InferRouteContext<TConfig>["params"], InferRouteContext<TConfig>["headers"], InferRouteContext<TConfig>["request"]>) => Promise<TResult> | TResult): PayKitMethod<ServerMethodInput<TConfig>, TResult> & InferMethodMeta<TConfig>;
92
+ declare function returnUrl(): PayKitReturnUrlSchema;
93
+ //#endregion
94
+ export { PayKitMethod, createPayKitEndpoint, definePayKitMethod, returnUrl };
@@ -0,0 +1,153 @@
1
+ import { PAYKIT_ERROR_CODES, PayKitError } from "../core/errors.js";
2
+ import { getCustomerByIdOrThrow, syncCustomerWithDefaults } from "../customer/customer.service.js";
3
+ import { createEndpoint, createMiddleware } from "better-call";
4
+ import * as z from "zod";
5
+ //#region src/api/define-route.ts
6
+ const paykitMiddleware = createMiddleware(async () => {
7
+ return {};
8
+ });
9
+ const createPayKitEndpoint = createEndpoint.create({ use: [paykitMiddleware] });
10
+ const returnUrlBrand = "__paykitReturnUrl";
11
+ function definePayKitMethod(config, handler) {
12
+ const call = async (paykit, input, request) => {
13
+ const normalizedInput = normalizeMethodInput(config.input, stripCustomerId(input), request, request?.headers);
14
+ const customer = config.requireCustomer ? await resolveCustomer(paykit, request, config.resolveServerCustomerId?.(input) ?? getInputCustomerId(input)) : void 0;
15
+ return handler({
16
+ headers: request?.headers ?? new Headers(),
17
+ input: normalizedInput,
18
+ params: {},
19
+ paykit,
20
+ request,
21
+ ...customer ? { customer } : {}
22
+ });
23
+ };
24
+ if (config.route) {
25
+ const endpoint = createPayKitEndpoint(config.route.path, {
26
+ body: createRouteInputSchema(config.input),
27
+ ...config.route,
28
+ client: void 0,
29
+ path: void 0,
30
+ resolveInput: void 0
31
+ }, async (ctx) => {
32
+ const routeInput = normalizeMethodInput(config.input, config.route?.resolveInput ? await config.route.resolveInput(ctx) : ctx.body, ctx.request, ctx.headers);
33
+ const customer = config.requireCustomer ? await resolveCustomer(ctx.context, ctx.request) : void 0;
34
+ return handler({
35
+ headers: ctx.headers,
36
+ input: routeInput,
37
+ params: ctx.params,
38
+ paykit: ctx.context,
39
+ request: ctx.request,
40
+ ...customer ? { customer } : {}
41
+ });
42
+ });
43
+ call.client = config.route.client === true;
44
+ call.endpoint = endpoint;
45
+ }
46
+ return call;
47
+ }
48
+ function returnUrl() {
49
+ const schema = z.url();
50
+ Object.defineProperty(schema, returnUrlBrand, {
51
+ configurable: false,
52
+ enumerable: false,
53
+ value: true,
54
+ writable: false
55
+ });
56
+ return schema;
57
+ }
58
+ function getInputCustomerId(input) {
59
+ if (!input || typeof input !== "object") return;
60
+ return "customerId" in input && typeof input.customerId === "string" ? input.customerId : void 0;
61
+ }
62
+ function stripCustomerId(input) {
63
+ if (!input || typeof input !== "object" || !("customerId" in input)) return input;
64
+ const { customerId: _customerId, ...rest } = input;
65
+ return rest;
66
+ }
67
+ function normalizeMethodInput(schema, input, request, headers) {
68
+ if (!(schema instanceof z.ZodObject) || !input || typeof input !== "object") return input;
69
+ const fields = getReturnUrlFields(schema);
70
+ if (fields.length === 0) return input;
71
+ const normalized = { ...input };
72
+ for (const field of fields) {
73
+ const value = normalized[field];
74
+ if (typeof value === "string") {
75
+ normalized[field] = normalizeReturnUrlValue(field, value, request, headers);
76
+ continue;
77
+ }
78
+ if (value == null && shouldDefaultReturnUrlField(field)) normalized[field] = resolveAbsoluteUrl("/", request, headers, field);
79
+ }
80
+ return normalized;
81
+ }
82
+ function createRouteInputSchema(schema) {
83
+ if (!(schema instanceof z.ZodObject)) return schema;
84
+ const shape = schema.shape;
85
+ const overrides = {};
86
+ for (const [key, fieldSchema] of Object.entries(shape)) {
87
+ if (!isReturnUrlSchema(fieldSchema)) continue;
88
+ overrides[key] = createRoutedReturnUrlSchema(key, fieldSchema);
89
+ }
90
+ return Object.keys(overrides).length > 0 ? schema.extend(overrides) : schema;
91
+ }
92
+ function createRoutedReturnUrlSchema(field, schema) {
93
+ const typedSchema = schema;
94
+ if (typedSchema instanceof z.ZodOptional) return createRoutedReturnUrlSchema(field, typedSchema.unwrap()).optional();
95
+ const routedSchema = z.string().refine((value) => isAbsoluteUrl(value) || isAbsolutePath(value), { message: "Invalid URL" });
96
+ return shouldDefaultReturnUrlField(field) ? routedSchema.optional() : routedSchema;
97
+ }
98
+ function getReturnUrlFields(schema) {
99
+ return Object.entries(schema.shape).filter(([, fieldSchema]) => isReturnUrlSchema(fieldSchema)).map(([field]) => field);
100
+ }
101
+ function isReturnUrlSchema(schema) {
102
+ const typedSchema = schema;
103
+ if (typedSchema instanceof z.ZodOptional) return isReturnUrlSchema(typedSchema.unwrap());
104
+ return typedSchema[returnUrlBrand] === true;
105
+ }
106
+ function normalizeReturnUrlValue(field, value, request, headers) {
107
+ if (isAbsolutePath(value)) return resolveAbsoluteUrl(value, request, headers, field);
108
+ return value;
109
+ }
110
+ function shouldDefaultReturnUrlField(field) {
111
+ return field !== "cancelUrl";
112
+ }
113
+ function resolveAbsoluteUrl(value, request, headers, field) {
114
+ const origin = resolveOrigin(request, headers);
115
+ if (!origin) throw PayKitError.from("BAD_REQUEST", PAYKIT_ERROR_CODES.SUCCESS_URL_REQUIRED, `A ${field} is required when this method is called without a request context`);
116
+ return new URL(value, origin).toString();
117
+ }
118
+ function resolveOrigin(request, headers) {
119
+ if (request?.url) return new URL("/", request.url).toString();
120
+ const explicitOrigin = headers?.get("origin");
121
+ if (explicitOrigin && isAbsoluteUrl(explicitOrigin)) return explicitOrigin.endsWith("/") ? explicitOrigin : `${explicitOrigin}/`;
122
+ const host = headers?.get("x-forwarded-host") ?? headers?.get("host");
123
+ if (!host) return null;
124
+ return `${headers?.get("x-forwarded-proto") ?? "https"}://${host}/`;
125
+ }
126
+ function isAbsoluteUrl(value) {
127
+ try {
128
+ new URL(value);
129
+ return true;
130
+ } catch {
131
+ return false;
132
+ }
133
+ }
134
+ function isAbsolutePath(value) {
135
+ return /^\/(?!\/)/u.test(value);
136
+ }
137
+ async function resolveCustomer(ctx, request, explicitCustomerId) {
138
+ if (ctx.options.identify && request) {
139
+ const identity = await ctx.options.identify(request);
140
+ if (!identity) throw PayKitError.from("UNAUTHORIZED", PAYKIT_ERROR_CODES.IDENTIFY_REQUIRED);
141
+ if (explicitCustomerId && explicitCustomerId !== identity.customerId) throw PayKitError.from("FORBIDDEN", PAYKIT_ERROR_CODES.CUSTOMER_ID_MISMATCH);
142
+ return syncCustomerWithDefaults(ctx, {
143
+ id: identity.customerId,
144
+ email: identity.email,
145
+ name: identity.name
146
+ });
147
+ }
148
+ if (request) throw PayKitError.from("UNAUTHORIZED", PAYKIT_ERROR_CODES.IDENTIFY_REQUIRED);
149
+ if (explicitCustomerId) return getCustomerByIdOrThrow(ctx.database, explicitCustomerId);
150
+ throw PayKitError.from("UNAUTHORIZED", PAYKIT_ERROR_CODES.CUSTOMER_ID_REQUIRED);
151
+ }
152
+ //#endregion
153
+ export { createPayKitEndpoint, definePayKitMethod, returnUrl };
@@ -0,0 +1,422 @@
1
+ import { ProviderCustomerMap, ProviderTestClock } from "../providers/provider.js";
2
+ import { PayKitContext } from "../core/context.js";
3
+ import { PayKitMethod } from "./define-route.js";
4
+ import { SubscribeResult } from "../subscription/subscription.types.js";
5
+ import { CustomerWithDetails, ListCustomersResult } from "../customer/customer.types.js";
6
+ import { CheckResult, ReportResult } from "../entitlement/entitlement.service.js";
7
+ //#region src/api/methods.d.ts
8
+ declare const testingMethods: {
9
+ readonly getTestClock: ((paykit: PayKitContext, input: Record<string, never> & {
10
+ customerId: string;
11
+ }, request?: Request) => Promise<ProviderTestClock>) & {
12
+ client?: boolean;
13
+ endpoint?: {
14
+ options: unknown;
15
+ path: string;
16
+ } & Record<string, unknown>;
17
+ } & {
18
+ endpoint: {
19
+ options: unknown;
20
+ path: "/get-test-clock";
21
+ } & Record<string, unknown>;
22
+ } & {
23
+ client: true;
24
+ };
25
+ readonly advanceTestClock: ((paykit: PayKitContext, input: {
26
+ frozenTime: Date;
27
+ } & {
28
+ customerId: string;
29
+ }, request?: Request) => Promise<ProviderTestClock>) & {
30
+ client?: boolean;
31
+ endpoint?: {
32
+ options: unknown;
33
+ path: string;
34
+ } & Record<string, unknown>;
35
+ } & {
36
+ endpoint: {
37
+ options: unknown;
38
+ path: "/advance-test-clock";
39
+ } & Record<string, unknown>;
40
+ } & {
41
+ client: true;
42
+ };
43
+ };
44
+ declare const methods: {
45
+ readonly getTestClock: ((paykit: PayKitContext, input: Record<string, never> & {
46
+ customerId: string;
47
+ }, request?: Request) => Promise<ProviderTestClock>) & {
48
+ client?: boolean;
49
+ endpoint?: {
50
+ options: unknown;
51
+ path: string;
52
+ } & Record<string, unknown>;
53
+ } & {
54
+ endpoint: {
55
+ options: unknown;
56
+ path: "/get-test-clock";
57
+ } & Record<string, unknown>;
58
+ } & {
59
+ client: true;
60
+ };
61
+ readonly advanceTestClock: ((paykit: PayKitContext, input: {
62
+ frozenTime: Date;
63
+ } & {
64
+ customerId: string;
65
+ }, request?: Request) => Promise<ProviderTestClock>) & {
66
+ client?: boolean;
67
+ endpoint?: {
68
+ options: unknown;
69
+ path: string;
70
+ } & Record<string, unknown>;
71
+ } & {
72
+ endpoint: {
73
+ options: unknown;
74
+ path: "/advance-test-clock";
75
+ } & Record<string, unknown>;
76
+ } & {
77
+ client: true;
78
+ };
79
+ readonly subscribe: ((paykit: PayKitContext, input: {
80
+ planId: string;
81
+ successUrl: string;
82
+ forceCheckout?: boolean | undefined;
83
+ cancelUrl?: string | undefined;
84
+ } & {
85
+ customerId: string;
86
+ }, request?: Request) => Promise<SubscribeResult>) & {
87
+ client?: boolean;
88
+ endpoint?: {
89
+ options: unknown;
90
+ path: string;
91
+ } & Record<string, unknown>;
92
+ } & {
93
+ endpoint: {
94
+ options: unknown;
95
+ path: "/subscribe";
96
+ } & Record<string, unknown>;
97
+ } & {
98
+ client: true;
99
+ };
100
+ readonly customerPortal: ((paykit: PayKitContext, input: {
101
+ returnUrl: string;
102
+ } & {
103
+ customerId: string;
104
+ }, request?: Request) => Promise<{
105
+ url: string;
106
+ }>) & {
107
+ client?: boolean;
108
+ endpoint?: {
109
+ options: unknown;
110
+ path: string;
111
+ } & Record<string, unknown>;
112
+ } & {
113
+ endpoint: {
114
+ options: unknown;
115
+ path: "/customer-portal";
116
+ } & Record<string, unknown>;
117
+ } & {
118
+ client: true;
119
+ };
120
+ readonly upsertCustomer: ((paykit: PayKitContext, input: {
121
+ id: string;
122
+ email?: string | undefined;
123
+ name?: string | undefined;
124
+ metadata?: Record<string, string> | undefined;
125
+ }, request?: Request) => Promise<{
126
+ metadata: Record<string, string> | null;
127
+ id: string;
128
+ email: string | null;
129
+ name: string | null;
130
+ provider: ProviderCustomerMap;
131
+ deletedAt: Date | null;
132
+ createdAt: Date;
133
+ updatedAt: Date;
134
+ }>) & {
135
+ client?: boolean;
136
+ endpoint?: {
137
+ options: unknown;
138
+ path: string;
139
+ } & Record<string, unknown>;
140
+ } & {
141
+ client?: boolean;
142
+ endpoint?: {
143
+ options: unknown;
144
+ path: string;
145
+ } & Record<string, unknown>;
146
+ };
147
+ readonly getCustomer: ((paykit: PayKitContext, input: {
148
+ id: string;
149
+ }, request?: Request) => Promise<CustomerWithDetails | null>) & {
150
+ client?: boolean;
151
+ endpoint?: {
152
+ options: unknown;
153
+ path: string;
154
+ } & Record<string, unknown>;
155
+ } & {
156
+ client?: boolean;
157
+ endpoint?: {
158
+ options: unknown;
159
+ path: string;
160
+ } & Record<string, unknown>;
161
+ };
162
+ readonly deleteCustomer: ((paykit: PayKitContext, input: {
163
+ id: string;
164
+ }, request?: Request) => Promise<{
165
+ success: boolean;
166
+ }>) & {
167
+ client?: boolean;
168
+ endpoint?: {
169
+ options: unknown;
170
+ path: string;
171
+ } & Record<string, unknown>;
172
+ } & {
173
+ client?: boolean;
174
+ endpoint?: {
175
+ options: unknown;
176
+ path: string;
177
+ } & Record<string, unknown>;
178
+ };
179
+ readonly listCustomers: ((paykit: PayKitContext, input: {
180
+ limit?: number | undefined;
181
+ offset?: number | undefined;
182
+ planIds?: string[] | undefined;
183
+ } | undefined, request?: Request) => Promise<ListCustomersResult>) & {
184
+ client?: boolean;
185
+ endpoint?: {
186
+ options: unknown;
187
+ path: string;
188
+ } & Record<string, unknown>;
189
+ } & {
190
+ client?: boolean;
191
+ endpoint?: {
192
+ options: unknown;
193
+ path: string;
194
+ } & Record<string, unknown>;
195
+ };
196
+ readonly check: ((paykit: PayKitContext, input: {
197
+ featureId: string;
198
+ required?: number | undefined;
199
+ } & {
200
+ customerId: string;
201
+ }, request?: Request) => Promise<CheckResult>) & {
202
+ client?: boolean;
203
+ endpoint?: {
204
+ options: unknown;
205
+ path: string;
206
+ } & Record<string, unknown>;
207
+ } & {
208
+ client?: boolean;
209
+ endpoint?: {
210
+ options: unknown;
211
+ path: string;
212
+ } & Record<string, unknown>;
213
+ };
214
+ readonly report: ((paykit: PayKitContext, input: {
215
+ featureId: string;
216
+ amount?: number | undefined;
217
+ } & {
218
+ customerId: string;
219
+ }, request?: Request) => Promise<ReportResult>) & {
220
+ client?: boolean;
221
+ endpoint?: {
222
+ options: unknown;
223
+ path: string;
224
+ } & Record<string, unknown>;
225
+ } & {
226
+ client?: boolean;
227
+ endpoint?: {
228
+ options: unknown;
229
+ path: string;
230
+ } & Record<string, unknown>;
231
+ };
232
+ readonly handleWebhook: ((paykit: PayKitContext, input: never, request?: Request) => Promise<{
233
+ received: true;
234
+ }>) & {
235
+ client?: boolean;
236
+ endpoint?: {
237
+ options: unknown;
238
+ path: string;
239
+ } & Record<string, unknown>;
240
+ } & {
241
+ endpoint: {
242
+ options: unknown;
243
+ path: "/webhook/:providerId";
244
+ } & Record<string, unknown>;
245
+ } & {
246
+ client?: false | undefined;
247
+ };
248
+ };
249
+ type MethodMap = Record<string, PayKitMethod<never, unknown>>;
250
+ declare const clientMethods: Pick<{
251
+ readonly subscribe: ((paykit: PayKitContext, input: {
252
+ planId: string;
253
+ successUrl: string;
254
+ forceCheckout?: boolean | undefined;
255
+ cancelUrl?: string | undefined;
256
+ } & {
257
+ customerId: string;
258
+ }, request?: Request) => Promise<SubscribeResult>) & {
259
+ client?: boolean;
260
+ endpoint?: {
261
+ options: unknown;
262
+ path: string;
263
+ } & Record<string, unknown>;
264
+ } & {
265
+ endpoint: {
266
+ options: unknown;
267
+ path: "/subscribe";
268
+ } & Record<string, unknown>;
269
+ } & {
270
+ client: true;
271
+ };
272
+ readonly customerPortal: ((paykit: PayKitContext, input: {
273
+ returnUrl: string;
274
+ } & {
275
+ customerId: string;
276
+ }, request?: Request) => Promise<{
277
+ url: string;
278
+ }>) & {
279
+ client?: boolean;
280
+ endpoint?: {
281
+ options: unknown;
282
+ path: string;
283
+ } & Record<string, unknown>;
284
+ } & {
285
+ endpoint: {
286
+ options: unknown;
287
+ path: "/customer-portal";
288
+ } & Record<string, unknown>;
289
+ } & {
290
+ client: true;
291
+ };
292
+ readonly upsertCustomer: ((paykit: PayKitContext, input: {
293
+ id: string;
294
+ email?: string | undefined;
295
+ name?: string | undefined;
296
+ metadata?: Record<string, string> | undefined;
297
+ }, request?: Request) => Promise<{
298
+ metadata: Record<string, string> | null;
299
+ id: string;
300
+ email: string | null;
301
+ name: string | null;
302
+ provider: ProviderCustomerMap;
303
+ deletedAt: Date | null;
304
+ createdAt: Date;
305
+ updatedAt: Date;
306
+ }>) & {
307
+ client?: boolean;
308
+ endpoint?: {
309
+ options: unknown;
310
+ path: string;
311
+ } & Record<string, unknown>;
312
+ } & {
313
+ client?: boolean;
314
+ endpoint?: {
315
+ options: unknown;
316
+ path: string;
317
+ } & Record<string, unknown>;
318
+ };
319
+ readonly getCustomer: ((paykit: PayKitContext, input: {
320
+ id: string;
321
+ }, request?: Request) => Promise<CustomerWithDetails | null>) & {
322
+ client?: boolean;
323
+ endpoint?: {
324
+ options: unknown;
325
+ path: string;
326
+ } & Record<string, unknown>;
327
+ } & {
328
+ client?: boolean;
329
+ endpoint?: {
330
+ options: unknown;
331
+ path: string;
332
+ } & Record<string, unknown>;
333
+ };
334
+ readonly deleteCustomer: ((paykit: PayKitContext, input: {
335
+ id: string;
336
+ }, request?: Request) => Promise<{
337
+ success: boolean;
338
+ }>) & {
339
+ client?: boolean;
340
+ endpoint?: {
341
+ options: unknown;
342
+ path: string;
343
+ } & Record<string, unknown>;
344
+ } & {
345
+ client?: boolean;
346
+ endpoint?: {
347
+ options: unknown;
348
+ path: string;
349
+ } & Record<string, unknown>;
350
+ };
351
+ readonly listCustomers: ((paykit: PayKitContext, input: {
352
+ limit?: number | undefined;
353
+ offset?: number | undefined;
354
+ planIds?: string[] | undefined;
355
+ } | undefined, request?: Request) => Promise<ListCustomersResult>) & {
356
+ client?: boolean;
357
+ endpoint?: {
358
+ options: unknown;
359
+ path: string;
360
+ } & Record<string, unknown>;
361
+ } & {
362
+ client?: boolean;
363
+ endpoint?: {
364
+ options: unknown;
365
+ path: string;
366
+ } & Record<string, unknown>;
367
+ };
368
+ readonly check: ((paykit: PayKitContext, input: {
369
+ featureId: string;
370
+ required?: number | undefined;
371
+ } & {
372
+ customerId: string;
373
+ }, request?: Request) => Promise<CheckResult>) & {
374
+ client?: boolean;
375
+ endpoint?: {
376
+ options: unknown;
377
+ path: string;
378
+ } & Record<string, unknown>;
379
+ } & {
380
+ client?: boolean;
381
+ endpoint?: {
382
+ options: unknown;
383
+ path: string;
384
+ } & Record<string, unknown>;
385
+ };
386
+ readonly report: ((paykit: PayKitContext, input: {
387
+ featureId: string;
388
+ amount?: number | undefined;
389
+ } & {
390
+ customerId: string;
391
+ }, request?: Request) => Promise<ReportResult>) & {
392
+ client?: boolean;
393
+ endpoint?: {
394
+ options: unknown;
395
+ path: string;
396
+ } & Record<string, unknown>;
397
+ } & {
398
+ client?: boolean;
399
+ endpoint?: {
400
+ options: unknown;
401
+ path: string;
402
+ } & Record<string, unknown>;
403
+ };
404
+ readonly handleWebhook: ((paykit: PayKitContext, input: never, request?: Request) => Promise<{
405
+ received: true;
406
+ }>) & {
407
+ client?: boolean;
408
+ endpoint?: {
409
+ options: unknown;
410
+ path: string;
411
+ } & Record<string, unknown>;
412
+ } & {
413
+ endpoint: {
414
+ options: unknown;
415
+ path: "/webhook/:providerId";
416
+ } & Record<string, unknown>;
417
+ } & {
418
+ client?: false | undefined;
419
+ };
420
+ } & MethodMap, never>;
421
+ //#endregion
422
+ export { clientMethods, methods, testingMethods };