@paid-ai/paid-node 0.4.0 → 0.5.0-alpha1

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 (77) hide show
  1. package/dist/cjs/Client.js +2 -2
  2. package/dist/cjs/api/types/Signal.d.ts +5 -0
  3. package/dist/cjs/index.d.ts +1 -0
  4. package/dist/cjs/index.js +2 -1
  5. package/dist/cjs/integrations/adapters/nextjs/base-adapter.d.ts +10 -0
  6. package/dist/cjs/integrations/adapters/nextjs/base-adapter.js +58 -0
  7. package/dist/cjs/integrations/adapters/nextjs/index.d.ts +5 -0
  8. package/dist/cjs/integrations/adapters/nextjs/index.js +15 -0
  9. package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +174 -0
  10. package/dist/cjs/integrations/adapters/nextjs/routes.js +192 -0
  11. package/dist/cjs/integrations/client.d.ts +49 -0
  12. package/dist/cjs/integrations/client.js +93 -0
  13. package/dist/cjs/integrations/controllers/billing.d.ts +113 -0
  14. package/dist/cjs/integrations/controllers/billing.js +164 -0
  15. package/dist/cjs/integrations/controllers/contacts.d.ts +66 -0
  16. package/dist/cjs/integrations/controllers/contacts.js +145 -0
  17. package/dist/cjs/integrations/controllers/customers.d.ts +63 -0
  18. package/dist/cjs/integrations/controllers/customers.js +150 -0
  19. package/dist/cjs/integrations/controllers/index.d.ts +6 -0
  20. package/dist/cjs/integrations/controllers/index.js +26 -0
  21. package/dist/cjs/integrations/controllers/invoices.d.ts +40 -0
  22. package/dist/cjs/integrations/controllers/invoices.js +72 -0
  23. package/dist/cjs/integrations/controllers/orders.d.ts +72 -0
  24. package/dist/cjs/integrations/controllers/orders.js +194 -0
  25. package/dist/cjs/integrations/controllers/provision-users.d.ts +62 -0
  26. package/dist/cjs/integrations/controllers/provision-users.js +130 -0
  27. package/dist/cjs/integrations/index.d.ts +29 -0
  28. package/dist/cjs/integrations/index.js +44 -0
  29. package/dist/cjs/integrations/types.d.ts +119 -0
  30. package/dist/cjs/integrations/types.js +2 -0
  31. package/dist/cjs/integrations/utils/api-fetch.d.ts +18 -0
  32. package/dist/cjs/integrations/utils/api-fetch.js +53 -0
  33. package/dist/cjs/integrations/utils/base-handler.d.ts +79 -0
  34. package/dist/cjs/integrations/utils/base-handler.js +168 -0
  35. package/dist/cjs/integrations/utils/create-adapter.d.ts +29 -0
  36. package/dist/cjs/integrations/utils/create-adapter.js +56 -0
  37. package/dist/cjs/version.d.ts +1 -1
  38. package/dist/cjs/version.js +1 -1
  39. package/dist/esm/Client.mjs +2 -2
  40. package/dist/esm/api/types/Signal.d.mts +5 -0
  41. package/dist/esm/index.d.mts +1 -0
  42. package/dist/esm/index.mjs +1 -0
  43. package/dist/esm/integrations/adapters/nextjs/base-adapter.d.mts +10 -0
  44. package/dist/esm/integrations/adapters/nextjs/base-adapter.mjs +55 -0
  45. package/dist/esm/integrations/adapters/nextjs/index.d.mts +5 -0
  46. package/dist/esm/integrations/adapters/nextjs/index.mjs +5 -0
  47. package/dist/esm/integrations/adapters/nextjs/routes.d.mts +174 -0
  48. package/dist/esm/integrations/adapters/nextjs/routes.mjs +183 -0
  49. package/dist/esm/integrations/client.d.mts +49 -0
  50. package/dist/esm/integrations/client.mjs +89 -0
  51. package/dist/esm/integrations/controllers/billing.d.mts +113 -0
  52. package/dist/esm/integrations/controllers/billing.mjs +158 -0
  53. package/dist/esm/integrations/controllers/contacts.d.mts +66 -0
  54. package/dist/esm/integrations/controllers/contacts.mjs +140 -0
  55. package/dist/esm/integrations/controllers/customers.d.mts +63 -0
  56. package/dist/esm/integrations/controllers/customers.mjs +145 -0
  57. package/dist/esm/integrations/controllers/index.d.mts +6 -0
  58. package/dist/esm/integrations/controllers/index.mjs +6 -0
  59. package/dist/esm/integrations/controllers/invoices.d.mts +40 -0
  60. package/dist/esm/integrations/controllers/invoices.mjs +68 -0
  61. package/dist/esm/integrations/controllers/orders.d.mts +72 -0
  62. package/dist/esm/integrations/controllers/orders.mjs +189 -0
  63. package/dist/esm/integrations/controllers/provision-users.d.mts +62 -0
  64. package/dist/esm/integrations/controllers/provision-users.mjs +126 -0
  65. package/dist/esm/integrations/index.d.mts +29 -0
  66. package/dist/esm/integrations/index.mjs +28 -0
  67. package/dist/esm/integrations/types.d.mts +119 -0
  68. package/dist/esm/integrations/types.mjs +1 -0
  69. package/dist/esm/integrations/utils/api-fetch.d.mts +18 -0
  70. package/dist/esm/integrations/utils/api-fetch.mjs +50 -0
  71. package/dist/esm/integrations/utils/base-handler.d.mts +79 -0
  72. package/dist/esm/integrations/utils/base-handler.mjs +164 -0
  73. package/dist/esm/integrations/utils/create-adapter.d.mts +29 -0
  74. package/dist/esm/integrations/utils/create-adapter.mjs +53 -0
  75. package/dist/esm/version.d.mts +1 -1
  76. package/dist/esm/version.mjs +1 -1
  77. 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.0",
64
- "User-Agent": "@paid-ai/paid-node/0.4.0",
63
+ "X-Fern-SDK-Version": "0.5.0-alpha1",
64
+ "User-Agent": "@paid-ai/paid-node/0.5.0-alpha1",
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) });
@@ -5,8 +5,13 @@ export interface Signal {
5
5
  event_name?: string;
6
6
  agent_id?: string;
7
7
  external_agent_id?: string;
8
+ /** Deprecated. The external customer id. Use `external_customer_id` or `internal_customer_id` instead. */
8
9
  customer_id?: string;
9
10
  data?: Record<string, unknown>;
10
11
  /** A unique key to ensure idempotent signal processing */
11
12
  idempotency_key?: string;
13
+ /** Paid's internal customer ID */
14
+ internal_customer_id?: string;
15
+ /** Your system's customer ID */
16
+ external_customer_id?: string;
12
17
  }
@@ -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, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, type ActivateOrderSyncRouteConfig, type OrdersRouteConfig, type ProvisioningRouteConfig, } from './routes.js';
@@ -0,0 +1,15 @@
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.createProvisioningRoute = exports.createPayInvoiceRoute = exports.createOrdersRoute = 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, "createOrdersRoute", { enumerable: true, get: function () { return routes_js_1.createOrdersRoute; } });
14
+ Object.defineProperty(exports, "createPayInvoiceRoute", { enumerable: true, get: function () { return routes_js_1.createPayInvoiceRoute; } });
15
+ Object.defineProperty(exports, "createProvisioningRoute", { enumerable: true, get: function () { return routes_js_1.createProvisioningRoute; } });
@@ -0,0 +1,174 @@
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 customer creation
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // src/app/api/customers/route.ts
83
+ * import { createCustomersRoute } from '@paid-ai/paid-node/integrations/nextjs';
84
+ *
85
+ * export const POST = createCustomersRoute();
86
+ * ```
87
+ *
88
+ * @example With custom config
89
+ * ```typescript
90
+ * export const POST = createCustomersRoute({
91
+ * validate: async (body) => {
92
+ * if (!body.email.includes('@company.com')) {
93
+ * throw new Error('Only company emails allowed');
94
+ * }
95
+ * }
96
+ * });
97
+ * ```
98
+ */
99
+ export declare function createCustomersRoute(config?: BaseHandlerConfig): (request: any, context?: any) => Promise<any>;
100
+ export interface OrdersRouteConfig extends BaseHandlerConfig {
101
+ /**
102
+ * Default helper options for order creation
103
+ */
104
+ helperOptions?: OrderOptions;
105
+ }
106
+ /**
107
+ * Create a Next.js API route handler for order creation
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * // src/app/api/orders/route.ts
112
+ * import { createOrdersRoute } from '@paid-ai/paid-node/integrations/nextjs';
113
+ *
114
+ * export const POST = createOrdersRoute();
115
+ * ```
116
+ *
117
+ * @example With auto-activation disabled
118
+ * ```typescript
119
+ * export const POST = createOrdersRoute({
120
+ * helperOptions: { autoActivate: false }
121
+ * });
122
+ * ```
123
+ */
124
+ export declare function createOrdersRoute(config?: OrdersRouteConfig): (request: any, context?: any) => Promise<any>;
125
+ /**
126
+ * Create a Next.js API route handler for invoice payment
127
+ *
128
+ * Organization ID is automatically fetched from the API key.
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * // src/app/api/invoices/[invoiceId]/pay/route.ts
133
+ * import { createPayInvoiceRoute } from '@paid-ai/paid-node/integrations/nextjs';
134
+ *
135
+ * export const POST = createPayInvoiceRoute();
136
+ * ```
137
+ */
138
+ export declare function createPayInvoiceRoute(config?: BaseHandlerConfig): (request: any, context?: any) => Promise<any>;
139
+ export interface ProvisioningRouteConfig extends BaseHandlerConfig {
140
+ /**
141
+ * Default agent external ID
142
+ * Can be overridden by request body
143
+ */
144
+ defaultAgentExternalId?: string;
145
+ /**
146
+ * Default order options
147
+ */
148
+ orderOptions?: OrderOptions;
149
+ }
150
+ /**
151
+ * Create a Next.js API route handler for user provisioning
152
+ *
153
+ * This creates a single endpoint that provisions a complete user
154
+ * with customer, contact, and optional order.
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * // src/app/api/provision/route.ts
159
+ * import { createProvisioningRoute } from '@paid-ai/paid-node/integrations/nextjs';
160
+ *
161
+ * export const POST = createProvisioningRoute({
162
+ * defaultAgentExternalId: process.env.PAID_AGENT_ID
163
+ * });
164
+ * ```
165
+ *
166
+ * @example Client-side usage
167
+ * ```typescript
168
+ * await fetch('/api/provision', {
169
+ * method: 'POST',
170
+ * body: JSON.stringify({ email: 'user@example.com' })
171
+ * });
172
+ * ```
173
+ */
174
+ export declare function createProvisioningRoute(config?: ProvisioningRouteConfig): (request: any, context?: any) => Promise<any>;
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createActivateOrderSyncRoute = createActivateOrderSyncRoute;
4
+ exports.createContactsRoute = createContactsRoute;
5
+ exports.createCustomerInvoicesRoute = createCustomerInvoicesRoute;
6
+ exports.createCustomersRoute = createCustomersRoute;
7
+ exports.createOrdersRoute = createOrdersRoute;
8
+ exports.createPayInvoiceRoute = createPayInvoiceRoute;
9
+ exports.createProvisioningRoute = createProvisioningRoute;
10
+ const base_adapter_js_1 = require("./base-adapter.js");
11
+ const contacts_js_1 = require("../../controllers/contacts.js");
12
+ const invoices_js_1 = require("../../controllers/invoices.js");
13
+ const customers_js_1 = require("../../controllers/customers.js");
14
+ const orders_js_1 = require("../../controllers/orders.js");
15
+ const provision_users_js_1 = require("../../controllers/provision-users.js");
16
+ const billing_js_1 = require("../../controllers/billing.js");
17
+ /**
18
+ * Create a Next.js API route handler for synchronous order activation
19
+ *
20
+ * This creates an endpoint that activates an order and immediately charges
21
+ * the customer using a confirmation token from a payment provider.
22
+ *
23
+ * Organization ID is automatically fetched from the API key.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * // src/app/api/orders/[orderId]/activate-sync/route.ts
28
+ * import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/nextjs';
29
+ *
30
+ * export const POST = createActivateOrderSyncRoute({
31
+ * defaultReturnUrl: process.env.NEXT_PUBLIC_BASE_URL + '/orders'
32
+ * });
33
+ * ```
34
+ *
35
+ * @example Client-side usage with route params
36
+ * ```typescript
37
+ * await fetch('/api/orders/ord_123/activate-sync', {
38
+ * method: 'POST',
39
+ * body: JSON.stringify({
40
+ * confirmationToken: 'pi_123_secret_456',
41
+ * returnUrl: 'https://example.com/return'
42
+ * })
43
+ * });
44
+ * ```
45
+ *
46
+ * @example Client-side usage with body params
47
+ * ```typescript
48
+ * await fetch('/api/orders/activate-sync', {
49
+ * method: 'POST',
50
+ * body: JSON.stringify({
51
+ * orderId: 'ord_123',
52
+ * confirmationToken: 'pi_123_secret_456'
53
+ * })
54
+ * });
55
+ * ```
56
+ */
57
+ function createActivateOrderSyncRoute(config = {}) {
58
+ const handler = (0, billing_js_1.createActivateOrderSyncHandler)(config.defaultReturnUrl);
59
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
60
+ return (request, context) => adaptedHandler(request, context, config);
61
+ }
62
+ /**
63
+ * Create a Next.js API route handler for contact creation
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * // src/app/api/contacts/route.ts
68
+ * import { createContactsRoute } from '@paid-ai/paid-node/integrations/nextjs';
69
+ *
70
+ * export const POST = createContactsRoute();
71
+ * ```
72
+ */
73
+ function createContactsRoute(config = {}) {
74
+ const handler = (0, contacts_js_1.createContactsHandler)();
75
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
76
+ return (request, context) => adaptedHandler(request, context, config);
77
+ }
78
+ /**
79
+ * Create a Next.js API route handler for fetching customer invoices
80
+ *
81
+ * Organization ID is automatically fetched from the API key.
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * // src/app/api/customers/[customerExternalId]/invoices/route.ts
86
+ * import { createCustomerInvoicesRoute } from '@paid-ai/paid-node/integrations/nextjs';
87
+ *
88
+ * export const GET = createCustomerInvoicesRoute();
89
+ * ```
90
+ */
91
+ function createCustomerInvoicesRoute(config = {}) {
92
+ const handler = (0, invoices_js_1.createCustomerInvoicesHandler)();
93
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
94
+ return (request, context) => adaptedHandler(request, context, config);
95
+ }
96
+ /**
97
+ * Create a Next.js API route handler for customer creation
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * // src/app/api/customers/route.ts
102
+ * import { createCustomersRoute } from '@paid-ai/paid-node/integrations/nextjs';
103
+ *
104
+ * export const POST = createCustomersRoute();
105
+ * ```
106
+ *
107
+ * @example With custom config
108
+ * ```typescript
109
+ * export const POST = createCustomersRoute({
110
+ * validate: async (body) => {
111
+ * if (!body.email.includes('@company.com')) {
112
+ * throw new Error('Only company emails allowed');
113
+ * }
114
+ * }
115
+ * });
116
+ * ```
117
+ */
118
+ function createCustomersRoute(config = {}) {
119
+ const handler = (0, customers_js_1.createCustomersHandler)();
120
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
121
+ return (request, context) => adaptedHandler(request, context, config);
122
+ }
123
+ /**
124
+ * Create a Next.js API route handler for order creation
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * // src/app/api/orders/route.ts
129
+ * import { createOrdersRoute } from '@paid-ai/paid-node/integrations/nextjs';
130
+ *
131
+ * export const POST = createOrdersRoute();
132
+ * ```
133
+ *
134
+ * @example With auto-activation disabled
135
+ * ```typescript
136
+ * export const POST = createOrdersRoute({
137
+ * helperOptions: { autoActivate: false }
138
+ * });
139
+ * ```
140
+ */
141
+ function createOrdersRoute(config = {}) {
142
+ const handler = (0, orders_js_1.createOrdersHandler)(config.helperOptions);
143
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
144
+ return (request, context) => adaptedHandler(request, context, config);
145
+ }
146
+ /**
147
+ * Create a Next.js API route handler for invoice payment
148
+ *
149
+ * Organization ID is automatically fetched from the API key.
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * // src/app/api/invoices/[invoiceId]/pay/route.ts
154
+ * import { createPayInvoiceRoute } from '@paid-ai/paid-node/integrations/nextjs';
155
+ *
156
+ * export const POST = createPayInvoiceRoute();
157
+ * ```
158
+ */
159
+ function createPayInvoiceRoute(config = {}) {
160
+ const handler = (0, billing_js_1.createPayInvoiceHandler)();
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 user provisioning
166
+ *
167
+ * This creates a single endpoint that provisions a complete user
168
+ * with customer, contact, and optional order.
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * // src/app/api/provision/route.ts
173
+ * import { createProvisioningRoute } from '@paid-ai/paid-node/integrations/nextjs';
174
+ *
175
+ * export const POST = createProvisioningRoute({
176
+ * defaultAgentExternalId: process.env.PAID_AGENT_ID
177
+ * });
178
+ * ```
179
+ *
180
+ * @example Client-side usage
181
+ * ```typescript
182
+ * await fetch('/api/provision', {
183
+ * method: 'POST',
184
+ * body: JSON.stringify({ email: 'user@example.com' })
185
+ * });
186
+ * ```
187
+ */
188
+ function createProvisioningRoute(config = {}) {
189
+ const handler = (0, provision_users_js_1.createProvisioningHandler)(config.orderOptions, config.defaultAgentExternalId);
190
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
191
+ return (request, context) => adaptedHandler(request, context, config);
192
+ }
@@ -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>;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ /**
3
+ * Shared Paid client initialization utility
4
+ * Framework-agnostic
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.initializePaidClient = initializePaidClient;
17
+ exports.getOrganizationId = getOrganizationId;
18
+ const Client_js_1 = require("../Client.js");
19
+ /**
20
+ * Initialize a Paid client with environment variable fallbacks
21
+ *
22
+ * @param config - Optional configuration overrides
23
+ * @returns Configured PaidClient instance
24
+ * @throws Error if API key is not provided or found in environment
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const client = initializePaidClient();
29
+ * // Uses process.env.PAID_API_KEY
30
+ *
31
+ * const client = initializePaidClient({ apiKey: 'pk_xxx' });
32
+ * // Uses provided key
33
+ * ```
34
+ */
35
+ function initializePaidClient(config = {}) {
36
+ const apiKey = config.apiKey || process.env.PAID_API_KEY;
37
+ if (!apiKey) {
38
+ throw new Error('PAID_API_KEY not configured. Set process.env.PAID_API_KEY or pass apiKey in config.');
39
+ }
40
+ return new Client_js_1.PaidClient({
41
+ token: apiKey,
42
+ baseUrl: config.apiUrl
43
+ ? `${config.apiUrl}/api/v1`
44
+ : process.env.PAID_API_URL
45
+ ? `${process.env.PAID_API_URL}/api/v1`
46
+ : undefined,
47
+ });
48
+ }
49
+ /**
50
+ * Get organization ID from API key
51
+ *
52
+ * Calls the Paid API to resolve the organization ID associated with the API key.
53
+ *
54
+ * @param config - API configuration
55
+ * @returns Organization ID or null if not found
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const orgId = await getOrganizationId({
60
+ * apiKey: process.env.PAID_API_KEY,
61
+ * apiUrl: 'https://api.agentpaid.io'
62
+ * });
63
+ * ```
64
+ */
65
+ function getOrganizationId() {
66
+ return __awaiter(this, arguments, void 0, function* (config = {}) {
67
+ var _a;
68
+ const apiKey = config.apiKey || process.env.PAID_API_KEY;
69
+ const apiUrl = config.apiUrl || process.env.PAID_API_URL || 'https://api.agentpaid.io';
70
+ if (!apiKey) {
71
+ throw new Error('PAID_API_KEY not configured');
72
+ }
73
+ try {
74
+ const response = yield fetch(`${apiUrl}/api/organizations/organizationId`, {
75
+ method: 'GET',
76
+ headers: {
77
+ Authorization: `Bearer ${apiKey}`,
78
+ 'Content-Type': 'application/json',
79
+ },
80
+ });
81
+ if (!response.ok) {
82
+ console.error('Failed to get organization ID:', yield response.text());
83
+ return null;
84
+ }
85
+ const data = yield response.json();
86
+ return ((_a = data.data) === null || _a === void 0 ? void 0 : _a.organizationId) || null;
87
+ }
88
+ catch (error) {
89
+ console.error('Error fetching organization ID:', error);
90
+ return null;
91
+ }
92
+ });
93
+ }