@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
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ /**
3
+ * Generic adapter factory - eliminates repetitive adapter code
4
+ * Works with any framework (Express, Fastify, Hono, Next.js, etc.)
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.createFrameworkAdapter = createFrameworkAdapter;
17
+ /**
18
+ * Creates a framework adapter for any HTTP framework
19
+ * Automatically extracts headers and converts request/response
20
+ *
21
+ * @param extractors - Framework-specific extraction functions
22
+ * @returns Adapter function that wraps core handlers
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const nextjsAdapter = createFrameworkAdapter({
27
+ * getBody: async (req) => await req.json(),
28
+ * getHeaders: (req) => Object.fromEntries(req.headers),
29
+ * getMethod: (req) => req.method || "GET",
30
+ * sendJson: (data, status) => NextResponse.json(data, { status })
31
+ * });
32
+ * ```
33
+ */
34
+ function createFrameworkAdapter(extractors) {
35
+ return function adaptHandler(innerHandler) {
36
+ return (req, context, config) => __awaiter(this, void 0, void 0, function* () {
37
+ var _a;
38
+ const body = yield extractors.getBody(req);
39
+ const params = extractors.getParams
40
+ ? yield extractors.getParams(req, context)
41
+ : undefined;
42
+ const requestContext = {
43
+ body,
44
+ headers: extractors.getHeaders(req),
45
+ method: extractors.getMethod(req),
46
+ params,
47
+ query: (_a = extractors.getQuery) === null || _a === void 0 ? void 0 : _a.call(extractors, req),
48
+ };
49
+ const responseContext = {
50
+ json: (data, status = 200) => extractors.sendJson(data, status),
51
+ error: (message, status) => extractors.sendJson({ error: message }, status),
52
+ };
53
+ return innerHandler(requestContext, responseContext, config);
54
+ });
55
+ };
56
+ }
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.4.0";
1
+ export declare const SDK_VERSION = "0.5.0-alpha1";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "0.4.0";
4
+ exports.SDK_VERSION = "0.5.0-alpha1";
@@ -24,8 +24,8 @@ export class PaidClient {
24
24
  this._options = Object.assign(Object.assign({}, _options), { headers: mergeHeaders({
25
25
  "X-Fern-Language": "JavaScript",
26
26
  "X-Fern-SDK-Name": "@paid-ai/paid-node",
27
- "X-Fern-SDK-Version": "0.4.0",
28
- "User-Agent": "@paid-ai/paid-node/0.4.0",
27
+ "X-Fern-SDK-Version": "0.5.0-alpha1",
28
+ "User-Agent": "@paid-ai/paid-node/0.5.0-alpha1",
29
29
  "X-Fern-Runtime": core.RUNTIME.type,
30
30
  "X-Fern-Runtime-Version": core.RUNTIME.version,
31
31
  }, _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.mjs";
2
2
  export { PaidClient } from "./Client.mjs";
3
3
  export { PaidEnvironment } from "./environments.mjs";
4
4
  export { PaidError, PaidTimeoutError } from "./errors/index.mjs";
5
+ export * as PaidIntegrations from "./integrations/index.mjs";
@@ -2,3 +2,4 @@ export * as Paid from "./api/index.mjs";
2
2
  export { PaidClient } from "./Client.mjs";
3
3
  export { PaidEnvironment } from "./environments.mjs";
4
4
  export { PaidError, PaidTimeoutError } from "./errors/index.mjs";
5
+ export * as PaidIntegrations from "./integrations/index.mjs";
@@ -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,55 @@
1
+ /**
2
+ * Next.js adapter for Paid SDK
3
+ * Converts Next.js App Router requests to framework-agnostic format
4
+ */
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ import { NextResponse } from "next/server";
15
+ import { createFrameworkAdapter } from "../../utils/create-adapter.mjs";
16
+ /**
17
+ * Next.js adapter for App Router
18
+ * Handles NextRequest/NextResponse conversion to base handler format
19
+ */
20
+ export const nextjsAdapter = createFrameworkAdapter({
21
+ getBody: (req) => __awaiter(void 0, void 0, void 0, function* () {
22
+ if (req.method === "GET" || req.method === "HEAD") {
23
+ return {};
24
+ }
25
+ try {
26
+ return yield req.json();
27
+ }
28
+ catch (error) {
29
+ return {};
30
+ }
31
+ }),
32
+ getHeaders: (req) => {
33
+ const headers = {};
34
+ req.headers.forEach((value, key) => {
35
+ headers[key] = value;
36
+ });
37
+ return headers;
38
+ },
39
+ getMethod: (req) => req.method || "GET",
40
+ getParams: (_req, context) => __awaiter(void 0, void 0, void 0, function* () {
41
+ if (!(context === null || context === void 0 ? void 0 : context.params)) {
42
+ return {};
43
+ }
44
+ const params = context.params instanceof Promise ? yield context.params : context.params;
45
+ return params || {};
46
+ }),
47
+ getQuery: (req) => {
48
+ const query = {};
49
+ req.nextUrl.searchParams.forEach((value, key) => {
50
+ query[key] = value;
51
+ });
52
+ return query;
53
+ },
54
+ sendJson: (data, status) => NextResponse.json(data, { status }),
55
+ });
@@ -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.mjs';
@@ -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, } from './routes.mjs';
@@ -0,0 +1,174 @@
1
+ import { BaseHandlerConfig } from "../../utils/base-handler.mjs";
2
+ import { OrderOptions } from "../../types.mjs";
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,183 @@
1
+ import { nextjsAdapter } from "./base-adapter.mjs";
2
+ import { createContactsHandler } from "../../controllers/contacts.mjs";
3
+ import { createCustomerInvoicesHandler } from "../../controllers/invoices.mjs";
4
+ import { createCustomersHandler } from "../../controllers/customers.mjs";
5
+ import { createOrdersHandler } from "../../controllers/orders.mjs";
6
+ import { createProvisioningHandler } from "../../controllers/provision-users.mjs";
7
+ import { createActivateOrderSyncHandler, createPayInvoiceHandler } from "../../controllers/billing.mjs";
8
+ /**
9
+ * Create a Next.js API route handler for synchronous order activation
10
+ *
11
+ * This creates an endpoint that activates an order and immediately charges
12
+ * the customer using a confirmation token from a payment provider.
13
+ *
14
+ * Organization ID is automatically fetched from the API key.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // src/app/api/orders/[orderId]/activate-sync/route.ts
19
+ * import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/nextjs';
20
+ *
21
+ * export const POST = createActivateOrderSyncRoute({
22
+ * defaultReturnUrl: process.env.NEXT_PUBLIC_BASE_URL + '/orders'
23
+ * });
24
+ * ```
25
+ *
26
+ * @example Client-side usage with route params
27
+ * ```typescript
28
+ * await fetch('/api/orders/ord_123/activate-sync', {
29
+ * method: 'POST',
30
+ * body: JSON.stringify({
31
+ * confirmationToken: 'pi_123_secret_456',
32
+ * returnUrl: 'https://example.com/return'
33
+ * })
34
+ * });
35
+ * ```
36
+ *
37
+ * @example Client-side usage with body params
38
+ * ```typescript
39
+ * await fetch('/api/orders/activate-sync', {
40
+ * method: 'POST',
41
+ * body: JSON.stringify({
42
+ * orderId: 'ord_123',
43
+ * confirmationToken: 'pi_123_secret_456'
44
+ * })
45
+ * });
46
+ * ```
47
+ */
48
+ export function createActivateOrderSyncRoute(config = {}) {
49
+ const handler = createActivateOrderSyncHandler(config.defaultReturnUrl);
50
+ const adaptedHandler = nextjsAdapter(handler);
51
+ return (request, context) => adaptedHandler(request, context, config);
52
+ }
53
+ /**
54
+ * Create a Next.js API route handler for contact creation
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * // src/app/api/contacts/route.ts
59
+ * import { createContactsRoute } from '@paid-ai/paid-node/integrations/nextjs';
60
+ *
61
+ * export const POST = createContactsRoute();
62
+ * ```
63
+ */
64
+ export function createContactsRoute(config = {}) {
65
+ const handler = createContactsHandler();
66
+ const adaptedHandler = nextjsAdapter(handler);
67
+ return (request, context) => adaptedHandler(request, context, config);
68
+ }
69
+ /**
70
+ * Create a Next.js API route handler for fetching customer invoices
71
+ *
72
+ * Organization ID is automatically fetched from the API key.
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * // src/app/api/customers/[customerExternalId]/invoices/route.ts
77
+ * import { createCustomerInvoicesRoute } from '@paid-ai/paid-node/integrations/nextjs';
78
+ *
79
+ * export const GET = createCustomerInvoicesRoute();
80
+ * ```
81
+ */
82
+ export function createCustomerInvoicesRoute(config = {}) {
83
+ const handler = createCustomerInvoicesHandler();
84
+ const adaptedHandler = nextjsAdapter(handler);
85
+ return (request, context) => adaptedHandler(request, context, config);
86
+ }
87
+ /**
88
+ * Create a Next.js API route handler for customer creation
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * // src/app/api/customers/route.ts
93
+ * import { createCustomersRoute } from '@paid-ai/paid-node/integrations/nextjs';
94
+ *
95
+ * export const POST = createCustomersRoute();
96
+ * ```
97
+ *
98
+ * @example With custom config
99
+ * ```typescript
100
+ * export const POST = createCustomersRoute({
101
+ * validate: async (body) => {
102
+ * if (!body.email.includes('@company.com')) {
103
+ * throw new Error('Only company emails allowed');
104
+ * }
105
+ * }
106
+ * });
107
+ * ```
108
+ */
109
+ export function createCustomersRoute(config = {}) {
110
+ const handler = createCustomersHandler();
111
+ const adaptedHandler = nextjsAdapter(handler);
112
+ return (request, context) => adaptedHandler(request, context, config);
113
+ }
114
+ /**
115
+ * Create a Next.js API route handler for order creation
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * // src/app/api/orders/route.ts
120
+ * import { createOrdersRoute } from '@paid-ai/paid-node/integrations/nextjs';
121
+ *
122
+ * export const POST = createOrdersRoute();
123
+ * ```
124
+ *
125
+ * @example With auto-activation disabled
126
+ * ```typescript
127
+ * export const POST = createOrdersRoute({
128
+ * helperOptions: { autoActivate: false }
129
+ * });
130
+ * ```
131
+ */
132
+ export function createOrdersRoute(config = {}) {
133
+ const handler = createOrdersHandler(config.helperOptions);
134
+ const adaptedHandler = nextjsAdapter(handler);
135
+ return (request, context) => adaptedHandler(request, context, config);
136
+ }
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 function createPayInvoiceRoute(config = {}) {
151
+ const handler = createPayInvoiceHandler();
152
+ const adaptedHandler = nextjsAdapter(handler);
153
+ return (request, context) => adaptedHandler(request, context, config);
154
+ }
155
+ /**
156
+ * Create a Next.js API route handler for user provisioning
157
+ *
158
+ * This creates a single endpoint that provisions a complete user
159
+ * with customer, contact, and optional order.
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * // src/app/api/provision/route.ts
164
+ * import { createProvisioningRoute } from '@paid-ai/paid-node/integrations/nextjs';
165
+ *
166
+ * export const POST = createProvisioningRoute({
167
+ * defaultAgentExternalId: process.env.PAID_AGENT_ID
168
+ * });
169
+ * ```
170
+ *
171
+ * @example Client-side usage
172
+ * ```typescript
173
+ * await fetch('/api/provision', {
174
+ * method: 'POST',
175
+ * body: JSON.stringify({ email: 'user@example.com' })
176
+ * });
177
+ * ```
178
+ */
179
+ export function createProvisioningRoute(config = {}) {
180
+ const handler = createProvisioningHandler(config.orderOptions, config.defaultAgentExternalId);
181
+ const adaptedHandler = nextjsAdapter(handler);
182
+ return (request, context) => adaptedHandler(request, context, config);
183
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Shared Paid client initialization utility
3
+ * Framework-agnostic
4
+ */
5
+ import { PaidClient } from '../Client.mjs';
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,89 @@
1
+ /**
2
+ * Shared Paid client initialization utility
3
+ * Framework-agnostic
4
+ */
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ import { PaidClient } from '../Client.mjs';
15
+ /**
16
+ * Initialize a Paid client with environment variable fallbacks
17
+ *
18
+ * @param config - Optional configuration overrides
19
+ * @returns Configured PaidClient instance
20
+ * @throws Error if API key is not provided or found in environment
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const client = initializePaidClient();
25
+ * // Uses process.env.PAID_API_KEY
26
+ *
27
+ * const client = initializePaidClient({ apiKey: 'pk_xxx' });
28
+ * // Uses provided key
29
+ * ```
30
+ */
31
+ export function initializePaidClient(config = {}) {
32
+ const apiKey = config.apiKey || process.env.PAID_API_KEY;
33
+ if (!apiKey) {
34
+ throw new Error('PAID_API_KEY not configured. Set process.env.PAID_API_KEY or pass apiKey in config.');
35
+ }
36
+ return new PaidClient({
37
+ token: apiKey,
38
+ baseUrl: config.apiUrl
39
+ ? `${config.apiUrl}/api/v1`
40
+ : process.env.PAID_API_URL
41
+ ? `${process.env.PAID_API_URL}/api/v1`
42
+ : undefined,
43
+ });
44
+ }
45
+ /**
46
+ * Get organization ID from API key
47
+ *
48
+ * Calls the Paid API to resolve the organization ID associated with the API key.
49
+ *
50
+ * @param config - API configuration
51
+ * @returns Organization ID or null if not found
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const orgId = await getOrganizationId({
56
+ * apiKey: process.env.PAID_API_KEY,
57
+ * apiUrl: 'https://api.agentpaid.io'
58
+ * });
59
+ * ```
60
+ */
61
+ export function getOrganizationId() {
62
+ return __awaiter(this, arguments, void 0, function* (config = {}) {
63
+ var _a;
64
+ const apiKey = config.apiKey || process.env.PAID_API_KEY;
65
+ const apiUrl = config.apiUrl || process.env.PAID_API_URL || 'https://api.agentpaid.io';
66
+ if (!apiKey) {
67
+ throw new Error('PAID_API_KEY not configured');
68
+ }
69
+ try {
70
+ const response = yield fetch(`${apiUrl}/api/organizations/organizationId`, {
71
+ method: 'GET',
72
+ headers: {
73
+ Authorization: `Bearer ${apiKey}`,
74
+ 'Content-Type': 'application/json',
75
+ },
76
+ });
77
+ if (!response.ok) {
78
+ console.error('Failed to get organization ID:', yield response.text());
79
+ return null;
80
+ }
81
+ const data = yield response.json();
82
+ return ((_a = data.data) === null || _a === void 0 ? void 0 : _a.organizationId) || null;
83
+ }
84
+ catch (error) {
85
+ console.error('Error fetching organization ID:', error);
86
+ return null;
87
+ }
88
+ });
89
+ }