@paid-ai/paid-node 0.4.1 → 0.5.0-alpha2

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 (75) hide show
  1. package/dist/cjs/Client.js +2 -2
  2. package/dist/cjs/index.d.ts +1 -0
  3. package/dist/cjs/index.js +2 -1
  4. package/dist/cjs/integrations/adapters/nextjs/base-adapter.d.ts +10 -0
  5. package/dist/cjs/integrations/adapters/nextjs/base-adapter.js +58 -0
  6. package/dist/cjs/integrations/adapters/nextjs/index.d.ts +5 -0
  7. package/dist/cjs/integrations/adapters/nextjs/index.js +17 -0
  8. package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +225 -0
  9. package/dist/cjs/integrations/adapters/nextjs/routes.js +246 -0
  10. package/dist/cjs/integrations/client.d.ts +49 -0
  11. package/dist/cjs/integrations/client.js +93 -0
  12. package/dist/cjs/integrations/controllers/billing.d.ts +196 -0
  13. package/dist/cjs/integrations/controllers/billing.js +267 -0
  14. package/dist/cjs/integrations/controllers/contacts.d.ts +66 -0
  15. package/dist/cjs/integrations/controllers/contacts.js +145 -0
  16. package/dist/cjs/integrations/controllers/customers.d.ts +96 -0
  17. package/dist/cjs/integrations/controllers/customers.js +206 -0
  18. package/dist/cjs/integrations/controllers/index.d.ts +6 -0
  19. package/dist/cjs/integrations/controllers/index.js +30 -0
  20. package/dist/cjs/integrations/controllers/invoices.d.ts +40 -0
  21. package/dist/cjs/integrations/controllers/invoices.js +72 -0
  22. package/dist/cjs/integrations/controllers/orders.d.ts +72 -0
  23. package/dist/cjs/integrations/controllers/orders.js +194 -0
  24. package/dist/cjs/integrations/controllers/provision-users.d.ts +62 -0
  25. package/dist/cjs/integrations/controllers/provision-users.js +130 -0
  26. package/dist/cjs/integrations/index.d.ts +29 -0
  27. package/dist/cjs/integrations/index.js +44 -0
  28. package/dist/cjs/integrations/types.d.ts +119 -0
  29. package/dist/cjs/integrations/types.js +2 -0
  30. package/dist/cjs/integrations/utils/api-fetch.d.ts +18 -0
  31. package/dist/cjs/integrations/utils/api-fetch.js +53 -0
  32. package/dist/cjs/integrations/utils/base-handler.d.ts +79 -0
  33. package/dist/cjs/integrations/utils/base-handler.js +168 -0
  34. package/dist/cjs/integrations/utils/create-adapter.d.ts +29 -0
  35. package/dist/cjs/integrations/utils/create-adapter.js +56 -0
  36. package/dist/cjs/version.d.ts +1 -1
  37. package/dist/cjs/version.js +1 -1
  38. package/dist/esm/Client.mjs +2 -2
  39. package/dist/esm/index.d.mts +1 -0
  40. package/dist/esm/index.mjs +1 -0
  41. package/dist/esm/integrations/adapters/nextjs/base-adapter.d.mts +10 -0
  42. package/dist/esm/integrations/adapters/nextjs/base-adapter.mjs +55 -0
  43. package/dist/esm/integrations/adapters/nextjs/index.d.mts +5 -0
  44. package/dist/esm/integrations/adapters/nextjs/index.mjs +5 -0
  45. package/dist/esm/integrations/adapters/nextjs/routes.d.mts +225 -0
  46. package/dist/esm/integrations/adapters/nextjs/routes.mjs +235 -0
  47. package/dist/esm/integrations/client.d.mts +49 -0
  48. package/dist/esm/integrations/client.mjs +89 -0
  49. package/dist/esm/integrations/controllers/billing.d.mts +196 -0
  50. package/dist/esm/integrations/controllers/billing.mjs +259 -0
  51. package/dist/esm/integrations/controllers/contacts.d.mts +66 -0
  52. package/dist/esm/integrations/controllers/contacts.mjs +140 -0
  53. package/dist/esm/integrations/controllers/customers.d.mts +96 -0
  54. package/dist/esm/integrations/controllers/customers.mjs +199 -0
  55. package/dist/esm/integrations/controllers/index.d.mts +6 -0
  56. package/dist/esm/integrations/controllers/index.mjs +6 -0
  57. package/dist/esm/integrations/controllers/invoices.d.mts +40 -0
  58. package/dist/esm/integrations/controllers/invoices.mjs +68 -0
  59. package/dist/esm/integrations/controllers/orders.d.mts +72 -0
  60. package/dist/esm/integrations/controllers/orders.mjs +189 -0
  61. package/dist/esm/integrations/controllers/provision-users.d.mts +62 -0
  62. package/dist/esm/integrations/controllers/provision-users.mjs +126 -0
  63. package/dist/esm/integrations/index.d.mts +29 -0
  64. package/dist/esm/integrations/index.mjs +28 -0
  65. package/dist/esm/integrations/types.d.mts +119 -0
  66. package/dist/esm/integrations/types.mjs +1 -0
  67. package/dist/esm/integrations/utils/api-fetch.d.mts +18 -0
  68. package/dist/esm/integrations/utils/api-fetch.mjs +50 -0
  69. package/dist/esm/integrations/utils/base-handler.d.mts +79 -0
  70. package/dist/esm/integrations/utils/base-handler.mjs +164 -0
  71. package/dist/esm/integrations/utils/create-adapter.d.mts +29 -0
  72. package/dist/esm/integrations/utils/create-adapter.mjs +53 -0
  73. package/dist/esm/version.d.mts +1 -1
  74. package/dist/esm/version.mjs +1 -1
  75. package/package.json +32 -3
@@ -60,8 +60,8 @@ class PaidClient {
60
60
  this._options = Object.assign(Object.assign({}, _options), { headers: (0, headers_js_1.mergeHeaders)({
61
61
  "X-Fern-Language": "JavaScript",
62
62
  "X-Fern-SDK-Name": "@paid-ai/paid-node",
63
- "X-Fern-SDK-Version": "0.4.1",
64
- "User-Agent": "@paid-ai/paid-node/0.4.1",
63
+ "X-Fern-SDK-Version": "0.5.0-alpha2",
64
+ "User-Agent": "@paid-ai/paid-node/0.5.0-alpha2",
65
65
  "X-Fern-Runtime": core.RUNTIME.type,
66
66
  "X-Fern-Runtime-Version": core.RUNTIME.version,
67
67
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -2,3 +2,4 @@ export * as Paid from "./api/index.js";
2
2
  export { PaidClient } from "./Client.js";
3
3
  export { PaidEnvironment } from "./environments.js";
4
4
  export { PaidError, PaidTimeoutError } from "./errors/index.js";
5
+ export * as PaidIntegrations from "./integrations/index.js";
package/dist/cjs/index.js CHANGED
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.PaidTimeoutError = exports.PaidError = exports.PaidEnvironment = exports.PaidClient = exports.Paid = void 0;
36
+ exports.PaidIntegrations = exports.PaidTimeoutError = exports.PaidError = exports.PaidEnvironment = exports.PaidClient = exports.Paid = void 0;
37
37
  exports.Paid = __importStar(require("./api/index.js"));
38
38
  var Client_js_1 = require("./Client.js");
39
39
  Object.defineProperty(exports, "PaidClient", { enumerable: true, get: function () { return Client_js_1.PaidClient; } });
@@ -42,3 +42,4 @@ Object.defineProperty(exports, "PaidEnvironment", { enumerable: true, get: funct
42
42
  var index_js_1 = require("./errors/index.js");
43
43
  Object.defineProperty(exports, "PaidError", { enumerable: true, get: function () { return index_js_1.PaidError; } });
44
44
  Object.defineProperty(exports, "PaidTimeoutError", { enumerable: true, get: function () { return index_js_1.PaidTimeoutError; } });
45
+ exports.PaidIntegrations = __importStar(require("./integrations/index.js"));
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Next.js adapter for Paid SDK
3
+ * Converts Next.js App Router requests to framework-agnostic format
4
+ */
5
+ import { NextRequest } from "next/server";
6
+ /**
7
+ * Next.js adapter for App Router
8
+ * Handles NextRequest/NextResponse conversion to base handler format
9
+ */
10
+ export declare const nextjsAdapter: (innerHandler: Function) => (req: NextRequest, context?: any, config?: any) => Promise<any>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ /**
3
+ * Next.js adapter for Paid SDK
4
+ * Converts Next.js App Router requests to framework-agnostic format
5
+ */
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.nextjsAdapter = void 0;
17
+ const server_1 = require("next/server");
18
+ const create_adapter_js_1 = require("../../utils/create-adapter.js");
19
+ /**
20
+ * Next.js adapter for App Router
21
+ * Handles NextRequest/NextResponse conversion to base handler format
22
+ */
23
+ exports.nextjsAdapter = (0, create_adapter_js_1.createFrameworkAdapter)({
24
+ getBody: (req) => __awaiter(void 0, void 0, void 0, function* () {
25
+ if (req.method === "GET" || req.method === "HEAD") {
26
+ return {};
27
+ }
28
+ try {
29
+ return yield req.json();
30
+ }
31
+ catch (error) {
32
+ return {};
33
+ }
34
+ }),
35
+ getHeaders: (req) => {
36
+ const headers = {};
37
+ req.headers.forEach((value, key) => {
38
+ headers[key] = value;
39
+ });
40
+ return headers;
41
+ },
42
+ getMethod: (req) => req.method || "GET",
43
+ getParams: (_req, context) => __awaiter(void 0, void 0, void 0, function* () {
44
+ if (!(context === null || context === void 0 ? void 0 : context.params)) {
45
+ return {};
46
+ }
47
+ const params = context.params instanceof Promise ? yield context.params : context.params;
48
+ return params || {};
49
+ }),
50
+ getQuery: (req) => {
51
+ const query = {};
52
+ req.nextUrl.searchParams.forEach((value, key) => {
53
+ query[key] = value;
54
+ });
55
+ return query;
56
+ },
57
+ sendJson: (data, status) => server_1.NextResponse.json(data, { status }),
58
+ });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Next.js API Route handlers for Paid integration
3
+ * Drop-in handlers for Next.js App Router
4
+ */
5
+ export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createGetCustomerRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, type ActivateOrderSyncRouteConfig, type OrdersRouteConfig, type ProvisioningRouteConfig, type SetupIntentRouteConfig, } from './routes.js';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /**
3
+ * Next.js API Route handlers for Paid integration
4
+ * Drop-in handlers for Next.js App Router
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.createSetupIntentRoute = exports.createProvisioningRoute = exports.createPayInvoiceRoute = exports.createOrdersRoute = exports.createGetCustomerRoute = exports.createCustomersRoute = exports.createCustomerInvoicesRoute = exports.createContactsRoute = exports.createActivateOrderSyncRoute = void 0;
8
+ var routes_js_1 = require("./routes.js");
9
+ Object.defineProperty(exports, "createActivateOrderSyncRoute", { enumerable: true, get: function () { return routes_js_1.createActivateOrderSyncRoute; } });
10
+ Object.defineProperty(exports, "createContactsRoute", { enumerable: true, get: function () { return routes_js_1.createContactsRoute; } });
11
+ Object.defineProperty(exports, "createCustomerInvoicesRoute", { enumerable: true, get: function () { return routes_js_1.createCustomerInvoicesRoute; } });
12
+ Object.defineProperty(exports, "createCustomersRoute", { enumerable: true, get: function () { return routes_js_1.createCustomersRoute; } });
13
+ Object.defineProperty(exports, "createGetCustomerRoute", { enumerable: true, get: function () { return routes_js_1.createGetCustomerRoute; } });
14
+ Object.defineProperty(exports, "createOrdersRoute", { enumerable: true, get: function () { return routes_js_1.createOrdersRoute; } });
15
+ Object.defineProperty(exports, "createPayInvoiceRoute", { enumerable: true, get: function () { return routes_js_1.createPayInvoiceRoute; } });
16
+ Object.defineProperty(exports, "createProvisioningRoute", { enumerable: true, get: function () { return routes_js_1.createProvisioningRoute; } });
17
+ Object.defineProperty(exports, "createSetupIntentRoute", { enumerable: true, get: function () { return routes_js_1.createSetupIntentRoute; } });
@@ -0,0 +1,225 @@
1
+ import { BaseHandlerConfig } from "../../utils/base-handler.js";
2
+ import { OrderOptions } from "../../types.js";
3
+ export interface ActivateOrderSyncRouteConfig extends BaseHandlerConfig {
4
+ /**
5
+ * Default return URL for payment flow
6
+ * Can be overridden by request body
7
+ */
8
+ defaultReturnUrl?: string;
9
+ }
10
+ /**
11
+ * Create a Next.js API route handler for synchronous order activation
12
+ *
13
+ * This creates an endpoint that activates an order and immediately charges
14
+ * the customer using a confirmation token from a payment provider.
15
+ *
16
+ * Organization ID is automatically fetched from the API key.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // src/app/api/orders/[orderId]/activate-sync/route.ts
21
+ * import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/nextjs';
22
+ *
23
+ * export const POST = createActivateOrderSyncRoute({
24
+ * defaultReturnUrl: process.env.NEXT_PUBLIC_BASE_URL + '/orders'
25
+ * });
26
+ * ```
27
+ *
28
+ * @example Client-side usage with route params
29
+ * ```typescript
30
+ * await fetch('/api/orders/ord_123/activate-sync', {
31
+ * method: 'POST',
32
+ * body: JSON.stringify({
33
+ * confirmationToken: 'pi_123_secret_456',
34
+ * returnUrl: 'https://example.com/return'
35
+ * })
36
+ * });
37
+ * ```
38
+ *
39
+ * @example Client-side usage with body params
40
+ * ```typescript
41
+ * await fetch('/api/orders/activate-sync', {
42
+ * method: 'POST',
43
+ * body: JSON.stringify({
44
+ * orderId: 'ord_123',
45
+ * confirmationToken: 'pi_123_secret_456'
46
+ * })
47
+ * });
48
+ * ```
49
+ */
50
+ export declare function createActivateOrderSyncRoute(config?: ActivateOrderSyncRouteConfig): (request: any, context?: any) => Promise<any>;
51
+ /**
52
+ * Create a Next.js API route handler for contact creation
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * // src/app/api/contacts/route.ts
57
+ * import { createContactsRoute } from '@paid-ai/paid-node/integrations/nextjs';
58
+ *
59
+ * export const POST = createContactsRoute();
60
+ * ```
61
+ */
62
+ export declare function createContactsRoute(config?: BaseHandlerConfig): (request: any, context?: any) => Promise<any>;
63
+ /**
64
+ * Create a Next.js API route handler for fetching customer invoices
65
+ *
66
+ * Organization ID is automatically fetched from the API key.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * // src/app/api/customers/[customerExternalId]/invoices/route.ts
71
+ * import { createCustomerInvoicesRoute } from '@paid-ai/paid-node/integrations/nextjs';
72
+ *
73
+ * export const GET = createCustomerInvoicesRoute();
74
+ * ```
75
+ */
76
+ export declare function createCustomerInvoicesRoute(config?: BaseHandlerConfig): (request: any, context?: any) => Promise<any>;
77
+ /**
78
+ * Create a Next.js API route handler for fetching a customer by external ID
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // src/app/api/customers/[customerExternalId]/route.ts
83
+ * import { createGetCustomerRoute } from '@paid-ai/paid-node/integrations/nextjs';
84
+ *
85
+ * export const GET = createGetCustomerRoute();
86
+ * ```
87
+ */
88
+ export declare function createGetCustomerRoute(config?: BaseHandlerConfig): (request: any, context?: any) => Promise<any>;
89
+ /**
90
+ * Create a Next.js API route handler for customer creation
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * // src/app/api/customers/route.ts
95
+ * import { createCustomersRoute } from '@paid-ai/paid-node/integrations/nextjs';
96
+ *
97
+ * export const POST = createCustomersRoute();
98
+ * ```
99
+ *
100
+ * @example With custom config
101
+ * ```typescript
102
+ * export const POST = createCustomersRoute({
103
+ * validate: async (body) => {
104
+ * if (!body.email.includes('@company.com')) {
105
+ * throw new Error('Only company emails allowed');
106
+ * }
107
+ * }
108
+ * });
109
+ * ```
110
+ */
111
+ export declare function createCustomersRoute(config?: BaseHandlerConfig): (request: any, context?: any) => Promise<any>;
112
+ export interface OrdersRouteConfig extends BaseHandlerConfig {
113
+ /**
114
+ * Default helper options for order creation
115
+ */
116
+ helperOptions?: OrderOptions;
117
+ }
118
+ /**
119
+ * Create a Next.js API route handler for order creation
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * // src/app/api/orders/route.ts
124
+ * import { createOrdersRoute } from '@paid-ai/paid-node/integrations/nextjs';
125
+ *
126
+ * export const POST = createOrdersRoute();
127
+ * ```
128
+ *
129
+ * @example With auto-activation disabled
130
+ * ```typescript
131
+ * export const POST = createOrdersRoute({
132
+ * helperOptions: { autoActivate: false }
133
+ * });
134
+ * ```
135
+ */
136
+ export declare function createOrdersRoute(config?: OrdersRouteConfig): (request: any, context?: any) => Promise<any>;
137
+ /**
138
+ * Create a Next.js API route handler for invoice payment
139
+ *
140
+ * Organization ID is automatically fetched from the API key.
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * // src/app/api/invoices/[invoiceId]/pay/route.ts
145
+ * import { createPayInvoiceRoute } from '@paid-ai/paid-node/integrations/nextjs';
146
+ *
147
+ * export const POST = createPayInvoiceRoute();
148
+ * ```
149
+ */
150
+ export declare function createPayInvoiceRoute(config?: BaseHandlerConfig): (request: any, context?: any) => Promise<any>;
151
+ export interface ProvisioningRouteConfig extends BaseHandlerConfig {
152
+ /**
153
+ * Default agent external ID
154
+ * Can be overridden by request body
155
+ */
156
+ defaultAgentExternalId?: string;
157
+ /**
158
+ * Default order options
159
+ */
160
+ orderOptions?: OrderOptions;
161
+ }
162
+ /**
163
+ * Create a Next.js API route handler for user provisioning
164
+ *
165
+ * This creates a single endpoint that provisions a complete user
166
+ * with customer, contact, and optional order.
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * // src/app/api/provision/route.ts
171
+ * import { createProvisioningRoute } from '@paid-ai/paid-node/integrations/nextjs';
172
+ *
173
+ * export const POST = createProvisioningRoute({
174
+ * defaultAgentExternalId: process.env.PAID_AGENT_ID
175
+ * });
176
+ * ```
177
+ *
178
+ * @example Client-side usage
179
+ * ```typescript
180
+ * await fetch('/api/provision', {
181
+ * method: 'POST',
182
+ * body: JSON.stringify({ email: 'user@example.com' })
183
+ * });
184
+ * ```
185
+ */
186
+ export declare function createProvisioningRoute(config?: ProvisioningRouteConfig): (request: any, context?: any) => Promise<any>;
187
+ export interface SetupIntentRouteConfig extends BaseHandlerConfig {
188
+ /**
189
+ * Default return URL for setup flow
190
+ * Can be overridden by request body
191
+ */
192
+ defaultReturnUrl?: string;
193
+ }
194
+ /**
195
+ * Create a Next.js API route handler for setup intent creation
196
+ *
197
+ * Setup intents are used to add payment methods without immediate charge.
198
+ * This is useful for saving payment methods for future billing.
199
+ *
200
+ * Organization ID is automatically fetched from the API key.
201
+ *
202
+ * @example
203
+ * ```typescript
204
+ * // src/app/api/payment-methods/setup/route.ts
205
+ * import { createSetupIntentRoute } from '@paid-ai/paid-node/integrations/nextjs';
206
+ *
207
+ * export const POST = createSetupIntentRoute({
208
+ * defaultReturnUrl: process.env.NEXT_PUBLIC_BASE_URL + '/billing'
209
+ * });
210
+ * ```
211
+ *
212
+ * @example Client-side usage
213
+ * ```typescript
214
+ * await fetch('/api/payment-methods/setup', {
215
+ * method: 'POST',
216
+ * body: JSON.stringify({
217
+ * customerId: 'cus_123',
218
+ * confirmationToken: 'seti_123_secret_456',
219
+ * returnUrl: 'https://example.com/billing',
220
+ * metadata: { source: 'settings_page' }
221
+ * })
222
+ * });
223
+ * ```
224
+ */
225
+ export declare function createSetupIntentRoute(config?: SetupIntentRouteConfig): (request: any, context?: any) => Promise<any>;
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createActivateOrderSyncRoute = createActivateOrderSyncRoute;
4
+ exports.createContactsRoute = createContactsRoute;
5
+ exports.createCustomerInvoicesRoute = createCustomerInvoicesRoute;
6
+ exports.createGetCustomerRoute = createGetCustomerRoute;
7
+ exports.createCustomersRoute = createCustomersRoute;
8
+ exports.createOrdersRoute = createOrdersRoute;
9
+ exports.createPayInvoiceRoute = createPayInvoiceRoute;
10
+ exports.createProvisioningRoute = createProvisioningRoute;
11
+ exports.createSetupIntentRoute = createSetupIntentRoute;
12
+ const base_adapter_js_1 = require("./base-adapter.js");
13
+ const contacts_js_1 = require("../../controllers/contacts.js");
14
+ const invoices_js_1 = require("../../controllers/invoices.js");
15
+ const customers_js_1 = require("../../controllers/customers.js");
16
+ const orders_js_1 = require("../../controllers/orders.js");
17
+ const provision_users_js_1 = require("../../controllers/provision-users.js");
18
+ const billing_js_1 = require("../../controllers/billing.js");
19
+ /**
20
+ * Create a Next.js API route handler for synchronous order activation
21
+ *
22
+ * This creates an endpoint that activates an order and immediately charges
23
+ * the customer using a confirmation token from a payment provider.
24
+ *
25
+ * Organization ID is automatically fetched from the API key.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * // src/app/api/orders/[orderId]/activate-sync/route.ts
30
+ * import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/nextjs';
31
+ *
32
+ * export const POST = createActivateOrderSyncRoute({
33
+ * defaultReturnUrl: process.env.NEXT_PUBLIC_BASE_URL + '/orders'
34
+ * });
35
+ * ```
36
+ *
37
+ * @example Client-side usage with route params
38
+ * ```typescript
39
+ * await fetch('/api/orders/ord_123/activate-sync', {
40
+ * method: 'POST',
41
+ * body: JSON.stringify({
42
+ * confirmationToken: 'pi_123_secret_456',
43
+ * returnUrl: 'https://example.com/return'
44
+ * })
45
+ * });
46
+ * ```
47
+ *
48
+ * @example Client-side usage with body params
49
+ * ```typescript
50
+ * await fetch('/api/orders/activate-sync', {
51
+ * method: 'POST',
52
+ * body: JSON.stringify({
53
+ * orderId: 'ord_123',
54
+ * confirmationToken: 'pi_123_secret_456'
55
+ * })
56
+ * });
57
+ * ```
58
+ */
59
+ function createActivateOrderSyncRoute(config = {}) {
60
+ const handler = (0, billing_js_1.createActivateOrderSyncHandler)(config.defaultReturnUrl);
61
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
62
+ return (request, context) => adaptedHandler(request, context, config);
63
+ }
64
+ /**
65
+ * Create a Next.js API route handler for contact creation
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * // src/app/api/contacts/route.ts
70
+ * import { createContactsRoute } from '@paid-ai/paid-node/integrations/nextjs';
71
+ *
72
+ * export const POST = createContactsRoute();
73
+ * ```
74
+ */
75
+ function createContactsRoute(config = {}) {
76
+ const handler = (0, contacts_js_1.createContactsHandler)();
77
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
78
+ return (request, context) => adaptedHandler(request, context, config);
79
+ }
80
+ /**
81
+ * Create a Next.js API route handler for fetching customer invoices
82
+ *
83
+ * Organization ID is automatically fetched from the API key.
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * // src/app/api/customers/[customerExternalId]/invoices/route.ts
88
+ * import { createCustomerInvoicesRoute } from '@paid-ai/paid-node/integrations/nextjs';
89
+ *
90
+ * export const GET = createCustomerInvoicesRoute();
91
+ * ```
92
+ */
93
+ function createCustomerInvoicesRoute(config = {}) {
94
+ const handler = (0, invoices_js_1.createCustomerInvoicesHandler)();
95
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
96
+ return (request, context) => adaptedHandler(request, context, config);
97
+ }
98
+ /**
99
+ * Create a Next.js API route handler for fetching a customer by external ID
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * // src/app/api/customers/[customerExternalId]/route.ts
104
+ * import { createGetCustomerRoute } from '@paid-ai/paid-node/integrations/nextjs';
105
+ *
106
+ * export const GET = createGetCustomerRoute();
107
+ * ```
108
+ */
109
+ function createGetCustomerRoute(config = {}) {
110
+ const handler = (0, customers_js_1.createGetCustomerHandler)();
111
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
112
+ return (request, context) => adaptedHandler(request, context, config);
113
+ }
114
+ /**
115
+ * Create a Next.js API route handler for customer creation
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * // src/app/api/customers/route.ts
120
+ * import { createCustomersRoute } from '@paid-ai/paid-node/integrations/nextjs';
121
+ *
122
+ * export const POST = createCustomersRoute();
123
+ * ```
124
+ *
125
+ * @example With custom config
126
+ * ```typescript
127
+ * export const POST = createCustomersRoute({
128
+ * validate: async (body) => {
129
+ * if (!body.email.includes('@company.com')) {
130
+ * throw new Error('Only company emails allowed');
131
+ * }
132
+ * }
133
+ * });
134
+ * ```
135
+ */
136
+ function createCustomersRoute(config = {}) {
137
+ const handler = (0, customers_js_1.createCustomersHandler)();
138
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
139
+ return (request, context) => adaptedHandler(request, context, config);
140
+ }
141
+ /**
142
+ * Create a Next.js API route handler for order creation
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * // src/app/api/orders/route.ts
147
+ * import { createOrdersRoute } from '@paid-ai/paid-node/integrations/nextjs';
148
+ *
149
+ * export const POST = createOrdersRoute();
150
+ * ```
151
+ *
152
+ * @example With auto-activation disabled
153
+ * ```typescript
154
+ * export const POST = createOrdersRoute({
155
+ * helperOptions: { autoActivate: false }
156
+ * });
157
+ * ```
158
+ */
159
+ function createOrdersRoute(config = {}) {
160
+ const handler = (0, orders_js_1.createOrdersHandler)(config.helperOptions);
161
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
162
+ return (request, context) => adaptedHandler(request, context, config);
163
+ }
164
+ /**
165
+ * Create a Next.js API route handler for invoice payment
166
+ *
167
+ * Organization ID is automatically fetched from the API key.
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * // src/app/api/invoices/[invoiceId]/pay/route.ts
172
+ * import { createPayInvoiceRoute } from '@paid-ai/paid-node/integrations/nextjs';
173
+ *
174
+ * export const POST = createPayInvoiceRoute();
175
+ * ```
176
+ */
177
+ function createPayInvoiceRoute(config = {}) {
178
+ const handler = (0, billing_js_1.createPayInvoiceHandler)();
179
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
180
+ return (request, context) => adaptedHandler(request, context, config);
181
+ }
182
+ /**
183
+ * Create a Next.js API route handler for user provisioning
184
+ *
185
+ * This creates a single endpoint that provisions a complete user
186
+ * with customer, contact, and optional order.
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * // src/app/api/provision/route.ts
191
+ * import { createProvisioningRoute } from '@paid-ai/paid-node/integrations/nextjs';
192
+ *
193
+ * export const POST = createProvisioningRoute({
194
+ * defaultAgentExternalId: process.env.PAID_AGENT_ID
195
+ * });
196
+ * ```
197
+ *
198
+ * @example Client-side usage
199
+ * ```typescript
200
+ * await fetch('/api/provision', {
201
+ * method: 'POST',
202
+ * body: JSON.stringify({ email: 'user@example.com' })
203
+ * });
204
+ * ```
205
+ */
206
+ function createProvisioningRoute(config = {}) {
207
+ const handler = (0, provision_users_js_1.createProvisioningHandler)(config.orderOptions, config.defaultAgentExternalId);
208
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
209
+ return (request, context) => adaptedHandler(request, context, config);
210
+ }
211
+ /**
212
+ * Create a Next.js API route handler for setup intent creation
213
+ *
214
+ * Setup intents are used to add payment methods without immediate charge.
215
+ * This is useful for saving payment methods for future billing.
216
+ *
217
+ * Organization ID is automatically fetched from the API key.
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * // src/app/api/payment-methods/setup/route.ts
222
+ * import { createSetupIntentRoute } from '@paid-ai/paid-node/integrations/nextjs';
223
+ *
224
+ * export const POST = createSetupIntentRoute({
225
+ * defaultReturnUrl: process.env.NEXT_PUBLIC_BASE_URL + '/billing'
226
+ * });
227
+ * ```
228
+ *
229
+ * @example Client-side usage
230
+ * ```typescript
231
+ * await fetch('/api/payment-methods/setup', {
232
+ * method: 'POST',
233
+ * body: JSON.stringify({
234
+ * customerId: 'cus_123',
235
+ * confirmationToken: 'seti_123_secret_456',
236
+ * returnUrl: 'https://example.com/billing',
237
+ * metadata: { source: 'settings_page' }
238
+ * })
239
+ * });
240
+ * ```
241
+ */
242
+ function createSetupIntentRoute(config = {}) {
243
+ const handler = (0, billing_js_1.createSetupIntentHandler)(config.defaultReturnUrl);
244
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
245
+ return (request, context) => adaptedHandler(request, context, config);
246
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Shared Paid client initialization utility
3
+ * Framework-agnostic
4
+ */
5
+ import { PaidClient } from '../Client.js';
6
+ export interface PaidClientConfig {
7
+ /**
8
+ * Paid API key - defaults to process.env.PAID_API_KEY
9
+ */
10
+ apiKey?: string;
11
+ /**
12
+ * Paid API URL - defaults to production
13
+ */
14
+ apiUrl?: string;
15
+ }
16
+ /**
17
+ * Initialize a Paid client with environment variable fallbacks
18
+ *
19
+ * @param config - Optional configuration overrides
20
+ * @returns Configured PaidClient instance
21
+ * @throws Error if API key is not provided or found in environment
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const client = initializePaidClient();
26
+ * // Uses process.env.PAID_API_KEY
27
+ *
28
+ * const client = initializePaidClient({ apiKey: 'pk_xxx' });
29
+ * // Uses provided key
30
+ * ```
31
+ */
32
+ export declare function initializePaidClient(config?: PaidClientConfig): PaidClient;
33
+ /**
34
+ * Get organization ID from API key
35
+ *
36
+ * Calls the Paid API to resolve the organization ID associated with the API key.
37
+ *
38
+ * @param config - API configuration
39
+ * @returns Organization ID or null if not found
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const orgId = await getOrganizationId({
44
+ * apiKey: process.env.PAID_API_KEY,
45
+ * apiUrl: 'https://api.agentpaid.io'
46
+ * });
47
+ * ```
48
+ */
49
+ export declare function getOrganizationId(config?: PaidClientConfig): Promise<string | null>;