@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,113 @@
1
+ export interface PayInvoiceConfig {
2
+ apiUrl: string;
3
+ apiKey: string;
4
+ organizationId: string;
5
+ }
6
+ export interface PayInvoiceRequest {
7
+ invoiceId: string;
8
+ confirmationToken: string;
9
+ returnUrl?: string;
10
+ }
11
+ export interface PayInvoiceResult {
12
+ success: boolean;
13
+ data?: any;
14
+ }
15
+ /**
16
+ * Pay an invoice with a payment confirmation token
17
+ * This helper processes payment for an existing invoice using a Stripe confirmation token.
18
+ *
19
+ * @param config - API configuration with organization context
20
+ * @param request - Payment request details
21
+ * @returns Payment result
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const result = await payInvoice(
26
+ * {
27
+ * apiUrl: 'https://api.agentpaid.io',
28
+ * apiKey: process.env.PAID_API_KEY,
29
+ * organizationId: 'org_123'
30
+ * },
31
+ * {
32
+ * invoiceId: 'inv_123',
33
+ * confirmationToken: 'pm_tok_xxx',
34
+ * returnUrl: 'https://example.com/thanks'
35
+ * }
36
+ * );
37
+ * ```
38
+ */
39
+ export declare function payInvoice(config: PayInvoiceConfig, request: PayInvoiceRequest): Promise<PayInvoiceResult>;
40
+ interface PayInvoiceRequestWithBody {
41
+ invoiceId?: string;
42
+ confirmationToken: string;
43
+ returnUrl?: string;
44
+ }
45
+ /**
46
+ * Create a framework-agnostic handler for invoice payment
47
+ *
48
+ * This handler can be used with any framework adapter.
49
+ * Organization ID is automatically fetched from the API key.
50
+ *
51
+ * @returns Handler function
52
+ */
53
+ export declare function createPayInvoiceHandler(): (request: import("../utils/base-handler.js").BaseRequestContext<PayInvoiceRequestWithBody, Record<string, string>>, response: import("../utils/base-handler.js").BaseResponseContext, config?: import("../utils/base-handler.js").BaseHandlerConfig) => Promise<any>;
54
+ export interface ActivateOrderSyncConfig {
55
+ apiUrl: string;
56
+ apiKey: string;
57
+ organizationId: string;
58
+ }
59
+ export interface ActivateOrderSyncRequest {
60
+ orderId: string;
61
+ confirmationToken: string;
62
+ returnUrl?: string;
63
+ }
64
+ export interface ActivateOrderSyncResult {
65
+ success: boolean;
66
+ order: any;
67
+ billing: any;
68
+ }
69
+ /**
70
+ * Activate an order synchronously with payment
71
+ *
72
+ * This operation activates an order and immediately charges the customer
73
+ * using the provided confirmation token (from Stripe or other payment provider).
74
+ *
75
+ * @param config - API configuration with organization context
76
+ * @param request - Activation request with order ID and confirmation token
77
+ * @returns Activation result with order and billing information
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const result = await activateOrderSync(
82
+ * {
83
+ * apiUrl: 'https://api.agentpaid.io',
84
+ * apiKey: process.env.PAID_API_KEY,
85
+ * organizationId: 'org_123'
86
+ * },
87
+ * {
88
+ * orderId: 'ord_123',
89
+ * confirmationToken: 'pi_123_secret_456',
90
+ * returnUrl: 'https://example.com/return'
91
+ * }
92
+ * );
93
+ * ```
94
+ */
95
+ export declare function activateOrderSync(config: ActivateOrderSyncConfig, request: ActivateOrderSyncRequest): Promise<ActivateOrderSyncResult>;
96
+ /**
97
+ * Internal request body type for the handler
98
+ */
99
+ interface ActivateOrderSyncRequestBody {
100
+ orderId?: string;
101
+ confirmationToken: string;
102
+ returnUrl?: string;
103
+ }
104
+ /**
105
+ * Create a framework-agnostic handler for synchronous order activation
106
+ *
107
+ * This handler can be used with any framework adapter.
108
+ *
109
+ * @param defaultReturnUrl - Optional default return URL
110
+ * @returns Handler function
111
+ */
112
+ export declare function createActivateOrderSyncHandler(defaultReturnUrl?: string): (request: import("../utils/base-handler.js").BaseRequestContext<ActivateOrderSyncRequestBody, Record<string, string>>, response: import("../utils/base-handler.js").BaseResponseContext, config?: import("../utils/base-handler.js").BaseHandlerConfig) => Promise<any>;
113
+ export {};
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.payInvoice = payInvoice;
13
+ exports.createPayInvoiceHandler = createPayInvoiceHandler;
14
+ exports.activateOrderSync = activateOrderSync;
15
+ exports.createActivateOrderSyncHandler = createActivateOrderSyncHandler;
16
+ const api_fetch_js_1 = require("../utils/api-fetch.js");
17
+ const base_handler_js_1 = require("../utils/base-handler.js");
18
+ /**
19
+ * Pay an invoice with a payment confirmation token
20
+ * This helper processes payment for an existing invoice using a Stripe confirmation token.
21
+ *
22
+ * @param config - API configuration with organization context
23
+ * @param request - Payment request details
24
+ * @returns Payment result
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const result = await payInvoice(
29
+ * {
30
+ * apiUrl: 'https://api.agentpaid.io',
31
+ * apiKey: process.env.PAID_API_KEY,
32
+ * organizationId: 'org_123'
33
+ * },
34
+ * {
35
+ * invoiceId: 'inv_123',
36
+ * confirmationToken: 'pm_tok_xxx',
37
+ * returnUrl: 'https://example.com/thanks'
38
+ * }
39
+ * );
40
+ * ```
41
+ */
42
+ function payInvoice(config, request) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const { invoiceId, confirmationToken, returnUrl } = request;
45
+ if (!invoiceId || !confirmationToken) {
46
+ throw new Error("invoiceId and confirmationToken are required");
47
+ }
48
+ const data = yield (0, api_fetch_js_1.paidApiFetch)(config, `/api/organizations/${config.organizationId}/invoices/${invoiceId}/pay`, {
49
+ method: "PUT",
50
+ body: Object.assign({ confirmationToken }, (returnUrl && { returnUrl })),
51
+ });
52
+ return { success: true, data };
53
+ });
54
+ }
55
+ /**
56
+ * Create a framework-agnostic handler for invoice payment
57
+ *
58
+ * This handler can be used with any framework adapter.
59
+ * Organization ID is automatically fetched from the API key.
60
+ *
61
+ * @returns Handler function
62
+ */
63
+ function createPayInvoiceHandler() {
64
+ return (0, base_handler_js_1.createHandler)((_client, body, params, organizationId) => __awaiter(this, void 0, void 0, function* () {
65
+ if (!organizationId) {
66
+ return { success: false, error: 'Organization ID not found', status: 500 };
67
+ }
68
+ const invoiceId = (params === null || params === void 0 ? void 0 : params.invoiceId) || body.invoiceId;
69
+ const { confirmationToken, returnUrl } = body;
70
+ if (!invoiceId) {
71
+ return { success: false, error: 'invoiceId is required', status: 400 };
72
+ }
73
+ if (!confirmationToken) {
74
+ return { success: false, error: 'confirmationToken is required', status: 400 };
75
+ }
76
+ const apiKey = process.env.PAID_API_KEY || '';
77
+ const apiUrl = process.env.PAID_API_URL || 'https://api.agentpaid.io';
78
+ const result = yield payInvoice({ apiUrl, apiKey, organizationId }, { invoiceId, confirmationToken, returnUrl });
79
+ return {
80
+ success: true,
81
+ data: result.data,
82
+ };
83
+ }), { requiredFields: ['confirmationToken'], requireOrganizationId: true });
84
+ }
85
+ /**
86
+ * Activate an order synchronously with payment
87
+ *
88
+ * This operation activates an order and immediately charges the customer
89
+ * using the provided confirmation token (from Stripe or other payment provider).
90
+ *
91
+ * @param config - API configuration with organization context
92
+ * @param request - Activation request with order ID and confirmation token
93
+ * @returns Activation result with order and billing information
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * const result = await activateOrderSync(
98
+ * {
99
+ * apiUrl: 'https://api.agentpaid.io',
100
+ * apiKey: process.env.PAID_API_KEY,
101
+ * organizationId: 'org_123'
102
+ * },
103
+ * {
104
+ * orderId: 'ord_123',
105
+ * confirmationToken: 'pi_123_secret_456',
106
+ * returnUrl: 'https://example.com/return'
107
+ * }
108
+ * );
109
+ * ```
110
+ */
111
+ function activateOrderSync(config, request) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ const { orderId, confirmationToken, returnUrl } = request;
114
+ if (!orderId) {
115
+ throw new Error("orderId is required");
116
+ }
117
+ if (!confirmationToken) {
118
+ throw new Error("confirmationToken is required");
119
+ }
120
+ const data = yield (0, api_fetch_js_1.paidApiFetch)(config, `/api/organizations/${config.organizationId}/orders/${orderId}/activate-sync`, {
121
+ method: "POST",
122
+ body: Object.assign({ confirmationToken }, (returnUrl && { returnUrl })),
123
+ });
124
+ return {
125
+ success: true,
126
+ order: data.order,
127
+ billing: data.billing,
128
+ };
129
+ });
130
+ }
131
+ /**
132
+ * Create a framework-agnostic handler for synchronous order activation
133
+ *
134
+ * This handler can be used with any framework adapter.
135
+ *
136
+ * @param defaultReturnUrl - Optional default return URL
137
+ * @returns Handler function
138
+ */
139
+ function createActivateOrderSyncHandler(defaultReturnUrl) {
140
+ return (0, base_handler_js_1.createHandler)((client, body, params, organizationId) => __awaiter(this, void 0, void 0, function* () {
141
+ var _a, _b;
142
+ const apiKey = (_a = client._options) === null || _a === void 0 ? void 0 : _a.token;
143
+ const baseUrl = ((_b = client._options) === null || _b === void 0 ? void 0 : _b.baseUrl) || 'https://api.agentpaid.io/api/v1';
144
+ const apiUrl = baseUrl.replace('/api/v1', '');
145
+ const orderId = (params === null || params === void 0 ? void 0 : params.orderId) || body.orderId;
146
+ const result = yield activateOrderSync({ apiUrl, apiKey, organizationId: organizationId }, {
147
+ orderId: orderId,
148
+ confirmationToken: body.confirmationToken,
149
+ returnUrl: body.returnUrl || defaultReturnUrl,
150
+ });
151
+ return {
152
+ success: true,
153
+ data: {
154
+ success: true,
155
+ order: result.order,
156
+ billing: result.billing,
157
+ message: 'Order activated and charged successfully',
158
+ },
159
+ };
160
+ }), {
161
+ requiredFields: ['confirmationToken'],
162
+ requireOrganizationId: true,
163
+ });
164
+ }
@@ -0,0 +1,66 @@
1
+ import type { PaidClient } from "../../Client.js";
2
+ import type { ContactData, ContactCreationResult, Address } from "../types.js";
3
+ /**
4
+ * Create a contact with defaults for missing fields
5
+ *
6
+ * This helper generates reasonable placeholder values for any missing data,
7
+ * making it easy to create contacts for prototyping and development.
8
+ *
9
+ * @param client - PaidClient instance
10
+ * @param data - Contact data (only customerExternalId is required)
11
+ * @returns Created contact with ID
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const contact = await createContactWithDefaults(client, {
16
+ * customerExternalId: 'user-123',
17
+ * email: 'user@example.com'
18
+ * });
19
+ * // Generates: firstName, lastName, address, etc.
20
+ * ```
21
+ */
22
+ export declare function createContactWithDefaults(client: PaidClient, data: ContactData): Promise<ContactCreationResult>;
23
+ /**
24
+ * Create a contact with explicit data (NO defaults applied)
25
+ *
26
+ * Required fields: customerExternalId, email, firstName, lastName, phone, salutation,
27
+ * and complete billingAddress (line1, line2, city, state, zipCode, country)
28
+ *
29
+ * Use createContactWithDefaults() if you want automatic default values for missing fields.
30
+ *
31
+ * @param client - PaidClient instance
32
+ * @param data - Complete contact data with ALL required fields
33
+ * @returns Created contact with ID
34
+ * @throws Error if any required fields are missing
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const contact = await createContact(client, {
39
+ * customerExternalId: 'user-123',
40
+ * email: 'john@example.com',
41
+ * firstName: 'John',
42
+ * lastName: 'Doe',
43
+ * phone: '+1234567890',
44
+ * salutation: 'Mr',
45
+ * billingAddress: {
46
+ * line1: '123 Main St',
47
+ * line2: 'Suite 100',
48
+ * city: 'San Francisco',
49
+ * state: 'CA',
50
+ * zipCode: '94105',
51
+ * country: 'US'
52
+ * }
53
+ * });
54
+ * ```
55
+ */
56
+ export declare function createContact(client: PaidClient, data: Required<Omit<ContactData, 'billingAddress'>> & {
57
+ billingAddress: Required<Address>;
58
+ }): Promise<ContactCreationResult>;
59
+ /**
60
+ * Create a framework-agnostic handler for contact creation
61
+ *
62
+ * This handler can be used with any framework adapter.
63
+ *
64
+ * @returns Handler function
65
+ */
66
+ export declare function createContactsHandler(): (request: import("../utils/base-handler.js").BaseRequestContext<ContactData, Record<string, string>>, response: import("../utils/base-handler.js").BaseResponseContext, config?: import("../utils/base-handler.js").BaseHandlerConfig) => Promise<any>;
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createContactWithDefaults = createContactWithDefaults;
13
+ exports.createContact = createContact;
14
+ exports.createContactsHandler = createContactsHandler;
15
+ const base_handler_js_1 = require("../utils/base-handler.js");
16
+ function generateContactDefaults(data) {
17
+ var _a, _b, _c, _d, _e, _f;
18
+ const timestamp = Date.now();
19
+ const email = data.email || `contact_${timestamp}@example.com`;
20
+ const firstName = data.firstName || "Joe";
21
+ const lastName = data.lastName || "Bloggs";
22
+ const phone = data.phone || "";
23
+ const salutation = data.salutation || "Mr";
24
+ const billingAddress = {
25
+ line1: ((_a = data.billingAddress) === null || _a === void 0 ? void 0 : _a.line1) || "123 Placeholder Street",
26
+ line2: ((_b = data.billingAddress) === null || _b === void 0 ? void 0 : _b.line2) || "",
27
+ city: ((_c = data.billingAddress) === null || _c === void 0 ? void 0 : _c.city) || "London",
28
+ state: ((_d = data.billingAddress) === null || _d === void 0 ? void 0 : _d.state) || "London",
29
+ zipCode: ((_e = data.billingAddress) === null || _e === void 0 ? void 0 : _e.zipCode) || "SW1A 1AA",
30
+ country: ((_f = data.billingAddress) === null || _f === void 0 ? void 0 : _f.country) || "UK",
31
+ };
32
+ return {
33
+ customerExternalId: data.customerExternalId,
34
+ email,
35
+ firstName,
36
+ lastName,
37
+ phone,
38
+ salutation,
39
+ billingAddress,
40
+ };
41
+ }
42
+ /**
43
+ * Internal helper to create a contact
44
+ */
45
+ function createContactInternal(client, data) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ const contact = yield client.contacts.create({
48
+ customerExternalId: data.customerExternalId,
49
+ salutation: data.salutation,
50
+ firstName: data.firstName,
51
+ lastName: data.lastName,
52
+ email: data.email,
53
+ phone: data.phone,
54
+ billingStreet: data.billingAddress.line1,
55
+ billingCity: data.billingAddress.city,
56
+ billingCountry: data.billingAddress.country,
57
+ billingPostalCode: data.billingAddress.zipCode,
58
+ });
59
+ if (!contact.id) {
60
+ throw new Error("Contact created but missing ID");
61
+ }
62
+ return {
63
+ id: contact.id,
64
+ };
65
+ });
66
+ }
67
+ /**
68
+ * Create a contact with defaults for missing fields
69
+ *
70
+ * This helper generates reasonable placeholder values for any missing data,
71
+ * making it easy to create contacts for prototyping and development.
72
+ *
73
+ * @param client - PaidClient instance
74
+ * @param data - Contact data (only customerExternalId is required)
75
+ * @returns Created contact with ID
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const contact = await createContactWithDefaults(client, {
80
+ * customerExternalId: 'user-123',
81
+ * email: 'user@example.com'
82
+ * });
83
+ * // Generates: firstName, lastName, address, etc.
84
+ * ```
85
+ */
86
+ function createContactWithDefaults(client, data) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ if (!data.customerExternalId) {
89
+ throw new Error("customerExternalId is required");
90
+ }
91
+ const completeData = generateContactDefaults(data);
92
+ return createContactInternal(client, completeData);
93
+ });
94
+ }
95
+ /**
96
+ * Create a contact with explicit data (NO defaults applied)
97
+ *
98
+ * Required fields: customerExternalId, email, firstName, lastName, phone, salutation,
99
+ * and complete billingAddress (line1, line2, city, state, zipCode, country)
100
+ *
101
+ * Use createContactWithDefaults() if you want automatic default values for missing fields.
102
+ *
103
+ * @param client - PaidClient instance
104
+ * @param data - Complete contact data with ALL required fields
105
+ * @returns Created contact with ID
106
+ * @throws Error if any required fields are missing
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const contact = await createContact(client, {
111
+ * customerExternalId: 'user-123',
112
+ * email: 'john@example.com',
113
+ * firstName: 'John',
114
+ * lastName: 'Doe',
115
+ * phone: '+1234567890',
116
+ * salutation: 'Mr',
117
+ * billingAddress: {
118
+ * line1: '123 Main St',
119
+ * line2: 'Suite 100',
120
+ * city: 'San Francisco',
121
+ * state: 'CA',
122
+ * zipCode: '94105',
123
+ * country: 'US'
124
+ * }
125
+ * });
126
+ * ```
127
+ */
128
+ function createContact(client, data) {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ return createContactInternal(client, data);
131
+ });
132
+ }
133
+ /**
134
+ * Create a framework-agnostic handler for contact creation
135
+ *
136
+ * This handler can be used with any framework adapter.
137
+ *
138
+ * @returns Handler function
139
+ */
140
+ function createContactsHandler() {
141
+ return (0, base_handler_js_1.createHandler)((client, body) => __awaiter(this, void 0, void 0, function* () {
142
+ const contact = yield createContactWithDefaults(client, body);
143
+ return { success: true, data: contact };
144
+ }), { requiredFields: ['customerExternalId'] });
145
+ }
@@ -0,0 +1,63 @@
1
+ import { PaidClient } from "../../Client.js";
2
+ import type { CustomerData, CustomerCreationResult, Address } from "../types.js";
3
+ /**
4
+ * Create a customer with defaults for missing fields
5
+ *
6
+ * This helper generates reasonable placeholder values for any missing data,
7
+ * making it easy to create customers for prototyping and development.
8
+ *
9
+ * @param client - PaidClient instance
10
+ * @param data - Customer data (only externalId is required)
11
+ * @returns Created customer with ID
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const customer = await createCustomerWithDefaults(client, {
16
+ * externalId: 'user-123',
17
+ * email: 'user@example.com'
18
+ * });
19
+ * // Generates: name, address, etc.
20
+ * ```
21
+ */
22
+ export declare function createCustomerWithDefaults(client: PaidClient, data: CustomerData): Promise<CustomerCreationResult>;
23
+ /**
24
+ * Create a customer with explicit data (NO defaults applied)
25
+ *
26
+ * Required fields: externalId, name, email, and complete billingAddress
27
+ * (line1, line2, city, state, zipCode, country)
28
+ *
29
+ * Use createCustomerWithDefaults() if you want automatic default values for missing fields.
30
+ *
31
+ * @param client - PaidClient instance
32
+ * @param data - Complete customer data with ALL required fields
33
+ * @returns Created customer with ID
34
+ * @throws Error if any required fields are missing
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const customer = await createCustomer(client, {
39
+ * externalId: 'user-123',
40
+ * email: 'user@example.com',
41
+ * name: 'John Doe',
42
+ * billingAddress: {
43
+ * line1: '123 Main St',
44
+ * line2: '',
45
+ * city: 'San Francisco',
46
+ * state: 'CA',
47
+ * zipCode: '94105',
48
+ * country: 'US'
49
+ * }
50
+ * });
51
+ * ```
52
+ */
53
+ export declare function createCustomer(client: PaidClient, data: Required<Omit<CustomerData, 'firstName' | 'lastName' | 'company' | 'phone' | 'metadata' | 'billingAddress'>> & {
54
+ billingAddress: Required<Address>;
55
+ }): Promise<CustomerCreationResult>;
56
+ /**
57
+ * Create a framework-agnostic handler for customer creation
58
+ *
59
+ * This handler can be used with any framework adapter.
60
+ *
61
+ * @returns Handler function
62
+ */
63
+ export declare function createCustomersHandler(): (request: import("../utils/base-handler.js").BaseRequestContext<CustomerData, Record<string, string>>, response: import("../utils/base-handler.js").BaseResponseContext, config?: import("../utils/base-handler.js").BaseHandlerConfig) => Promise<any>;