@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
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Framework-agnostic base handler for Paid SDK integrations
3
+ * Provides consistent request handling, validation, and error handling
4
+ */
5
+ import type { PaidClient } from "../../Client.js";
6
+ import { type PaidClientConfig } from "../client.js";
7
+ export interface BaseRequestContext<TBody = any, TParams = Record<string, string>> {
8
+ body: TBody;
9
+ headers: Record<string, string>;
10
+ method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
11
+ params?: TParams;
12
+ query?: Record<string, string>;
13
+ }
14
+ export interface BaseResponseContext {
15
+ json: (data: any, status?: number) => any;
16
+ error: (message: string, status: number) => any;
17
+ }
18
+ export interface BaseHandlerConfig extends PaidClientConfig {
19
+ validate?: (body: any) => Promise<void> | void;
20
+ transformRequest?: (body: any) => any;
21
+ transformResponse?: (data: any) => any;
22
+ }
23
+ export type HandlerFunction<TRequest, TResponse> = (client: PaidClient, request: TRequest, params?: Record<string, string>, organizationId?: string) => Promise<{
24
+ success: boolean;
25
+ data?: TResponse;
26
+ error?: string;
27
+ status?: number;
28
+ }>;
29
+ /**
30
+ * Creates a framework-agnostic handler with automatic client initialization,
31
+ * validation, and error handling
32
+ *
33
+ * @param handler - Business logic handler function
34
+ * @param options - Handler configuration options
35
+ * @returns Framework-agnostic handler function
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const customersHandler = createHandler(
40
+ * async (client, body) => {
41
+ * const customer = await createCustomerWithDefaults(client, body);
42
+ * return { success: true, data: customer };
43
+ * },
44
+ * { requiredFields: ['externalId'] }
45
+ * );
46
+ * ```
47
+ */
48
+ export declare function createHandler<TRequest = any, TResponse = any>(handler: HandlerFunction<TRequest, TResponse>, options?: {
49
+ requiredFields?: (keyof TRequest)[];
50
+ allowedMethods?: Array<"GET" | "POST" | "PUT" | "DELETE" | "PATCH">;
51
+ requireOrganizationId?: boolean;
52
+ }): (request: BaseRequestContext<TRequest>, response: BaseResponseContext, config?: BaseHandlerConfig) => Promise<any>;
53
+ /**
54
+ * Helper to create a fetch-based handler for simple API calls
55
+ *
56
+ * @param endpoint - Function that generates the endpoint URL from org ID and request body
57
+ * @param options - Optional method, request/response transformations
58
+ * @returns Handler function that makes the API call
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const activateHandler = createHandler(
63
+ * createFetchHandler(
64
+ * (orgId, req) => `/api/organizations/${orgId}/orders/${req.orderId}/activate-sync`,
65
+ * {
66
+ * method: "POST",
67
+ * transformRequest: (req) => ({ confirmationToken: req.confirmationToken }),
68
+ * transformResponse: (data) => ({ order: data.order, billing: data.billing })
69
+ * }
70
+ * ),
71
+ * { requireOrganizationId: true }
72
+ * );
73
+ * ```
74
+ */
75
+ export declare function createFetchHandler<TRequest, TResponse>(endpoint: (orgId: string, body: TRequest, params?: Record<string, string>) => string, options?: {
76
+ method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
77
+ transformRequest?: (body: TRequest) => any;
78
+ transformResponse?: (data: any) => TResponse;
79
+ }): HandlerFunction<TRequest, TResponse>;
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ /**
3
+ * Framework-agnostic base handler for Paid SDK integrations
4
+ * Provides consistent request handling, validation, and error handling
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.createHandler = createHandler;
17
+ exports.createFetchHandler = createFetchHandler;
18
+ const client_js_1 = require("../client.js");
19
+ /**
20
+ * Creates a framework-agnostic handler with automatic client initialization,
21
+ * validation, and error handling
22
+ *
23
+ * @param handler - Business logic handler function
24
+ * @param options - Handler configuration options
25
+ * @returns Framework-agnostic handler function
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const customersHandler = createHandler(
30
+ * async (client, body) => {
31
+ * const customer = await createCustomerWithDefaults(client, body);
32
+ * return { success: true, data: customer };
33
+ * },
34
+ * { requiredFields: ['externalId'] }
35
+ * );
36
+ * ```
37
+ */
38
+ function createHandler(handler, options = {}) {
39
+ const { requiredFields = [], allowedMethods = ["POST"], requireOrganizationId = false } = options;
40
+ return function (request_1, response_1) {
41
+ return __awaiter(this, arguments, void 0, function* (request, response, config = {}) {
42
+ if (!allowedMethods.includes(request.method)) {
43
+ return response.error("Method not allowed", 405);
44
+ }
45
+ for (const field of requiredFields) {
46
+ if (!request.body[field]) {
47
+ return response.error(`${String(field)} is required`, 400);
48
+ }
49
+ }
50
+ if (config.validate) {
51
+ try {
52
+ yield config.validate(request.body);
53
+ }
54
+ catch (error) {
55
+ return response.error(error instanceof Error ? error.message : "Validation failed", 400);
56
+ }
57
+ }
58
+ try {
59
+ const client = (0, client_js_1.initializePaidClient)(config);
60
+ let organizationId;
61
+ if (requireOrganizationId) {
62
+ const orgId = yield (0, client_js_1.getOrganizationId)(config);
63
+ if (!orgId) {
64
+ return response.error("Organization not found", 500);
65
+ }
66
+ organizationId = orgId;
67
+ }
68
+ const requestData = config.transformRequest
69
+ ? config.transformRequest(request.body)
70
+ : request.body;
71
+ const result = yield handler(client, requestData, request.params, organizationId);
72
+ if (!result.success) {
73
+ return response.error(result.error || "Operation failed", result.status || 500);
74
+ }
75
+ const responseData = config.transformResponse
76
+ ? config.transformResponse(result.data)
77
+ : { data: result.data };
78
+ return response.json(responseData, 200);
79
+ }
80
+ catch (error) {
81
+ console.error("Handler error:", error);
82
+ if (error instanceof TypeError && error.message.includes("fetch")) {
83
+ return response.error("Network error: Unable to reach Paid API", 503);
84
+ }
85
+ return response.error(error instanceof Error ? error.message : "Internal server error", 500);
86
+ }
87
+ });
88
+ };
89
+ }
90
+ /**
91
+ * Helper to create a fetch-based handler for simple API calls
92
+ *
93
+ * @param endpoint - Function that generates the endpoint URL from org ID and request body
94
+ * @param options - Optional method, request/response transformations
95
+ * @returns Handler function that makes the API call
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * const activateHandler = createHandler(
100
+ * createFetchHandler(
101
+ * (orgId, req) => `/api/organizations/${orgId}/orders/${req.orderId}/activate-sync`,
102
+ * {
103
+ * method: "POST",
104
+ * transformRequest: (req) => ({ confirmationToken: req.confirmationToken }),
105
+ * transformResponse: (data) => ({ order: data.order, billing: data.billing })
106
+ * }
107
+ * ),
108
+ * { requireOrganizationId: true }
109
+ * );
110
+ * ```
111
+ */
112
+ function createFetchHandler(endpoint, options) {
113
+ return (client, requestBody, params, organizationId) => __awaiter(this, void 0, void 0, function* () {
114
+ var _a, _b;
115
+ if (!organizationId) {
116
+ return {
117
+ success: false,
118
+ error: "Organization ID is required for this operation",
119
+ status: 500,
120
+ };
121
+ }
122
+ try {
123
+ const url = endpoint(organizationId, requestBody, params);
124
+ const body = (options === null || options === void 0 ? void 0 : options.transformRequest)
125
+ ? options.transformRequest(requestBody)
126
+ : requestBody;
127
+ const baseUrl = ((_a = client._options) === null || _a === void 0 ? void 0 : _a.baseUrl) || "https://api.agentpaid.io/api/v1";
128
+ const apiKey = (_b = client._options) === null || _b === void 0 ? void 0 : _b.token;
129
+ if (!apiKey) {
130
+ return {
131
+ success: false,
132
+ error: "API key not found in client",
133
+ status: 500,
134
+ };
135
+ }
136
+ const fetchResponse = yield fetch(`${baseUrl}${url}`, {
137
+ method: (options === null || options === void 0 ? void 0 : options.method) || "POST",
138
+ headers: {
139
+ Authorization: `Bearer ${apiKey}`,
140
+ "Content-Type": "application/json",
141
+ },
142
+ body: (options === null || options === void 0 ? void 0 : options.method) !== "GET" ? JSON.stringify(body) : undefined,
143
+ });
144
+ if (!fetchResponse.ok) {
145
+ const errorText = yield fetchResponse.text();
146
+ console.error("API error:", errorText);
147
+ return {
148
+ success: false,
149
+ error: `API request failed: ${errorText}`,
150
+ status: fetchResponse.status,
151
+ };
152
+ }
153
+ const data = yield fetchResponse.json();
154
+ const transformedData = (options === null || options === void 0 ? void 0 : options.transformResponse)
155
+ ? options.transformResponse(data)
156
+ : data;
157
+ return { success: true, data: transformedData };
158
+ }
159
+ catch (error) {
160
+ console.error("Fetch error:", error);
161
+ return {
162
+ success: false,
163
+ error: error instanceof Error ? error.message : "Unknown error",
164
+ status: 500,
165
+ };
166
+ }
167
+ });
168
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Generic adapter factory - eliminates repetitive adapter code
3
+ * Works with any framework (Express, Fastify, Hono, Next.js, etc.)
4
+ */
5
+ /**
6
+ * Creates a framework adapter for any HTTP framework
7
+ * Automatically extracts headers and converts request/response
8
+ *
9
+ * @param extractors - Framework-specific extraction functions
10
+ * @returns Adapter function that wraps core handlers
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const nextjsAdapter = createFrameworkAdapter({
15
+ * getBody: async (req) => await req.json(),
16
+ * getHeaders: (req) => Object.fromEntries(req.headers),
17
+ * getMethod: (req) => req.method || "GET",
18
+ * sendJson: (data, status) => NextResponse.json(data, { status })
19
+ * });
20
+ * ```
21
+ */
22
+ export declare function createFrameworkAdapter<TFrameworkReq = any, TFrameworkRes = any>(extractors: {
23
+ getBody: (req: TFrameworkReq) => any | Promise<any>;
24
+ getHeaders: (req: TFrameworkReq) => Record<string, string>;
25
+ getMethod: (req: TFrameworkReq) => string;
26
+ getParams?: (req: TFrameworkReq, context?: any) => Record<string, string> | Promise<Record<string, string>>;
27
+ getQuery?: (req: TFrameworkReq) => Record<string, string>;
28
+ sendJson: (data: any, status: number) => TFrameworkRes;
29
+ }): (innerHandler: Function) => (req: TFrameworkReq, context?: any, config?: any) => Promise<any>;
@@ -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.1";
1
+ export declare const SDK_VERSION = "0.5.0-alpha2";
@@ -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.1";
4
+ exports.SDK_VERSION = "0.5.0-alpha2";
@@ -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.1",
28
- "User-Agent": "@paid-ai/paid-node/0.4.1",
27
+ "X-Fern-SDK-Version": "0.5.0-alpha2",
28
+ "User-Agent": "@paid-ai/paid-node/0.5.0-alpha2",
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) });
@@ -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, createGetCustomerRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, type ActivateOrderSyncRouteConfig, type OrdersRouteConfig, type ProvisioningRouteConfig, type SetupIntentRouteConfig, } 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, createGetCustomerRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, } from './routes.mjs';
@@ -0,0 +1,225 @@
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 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>;