@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.
- package/dist/cjs/Client.js +2 -2
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/integrations/adapters/nextjs/base-adapter.d.ts +10 -0
- package/dist/cjs/integrations/adapters/nextjs/base-adapter.js +58 -0
- package/dist/cjs/integrations/adapters/nextjs/index.d.ts +5 -0
- package/dist/cjs/integrations/adapters/nextjs/index.js +17 -0
- package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +225 -0
- package/dist/cjs/integrations/adapters/nextjs/routes.js +246 -0
- package/dist/cjs/integrations/client.d.ts +49 -0
- package/dist/cjs/integrations/client.js +93 -0
- package/dist/cjs/integrations/controllers/billing.d.ts +196 -0
- package/dist/cjs/integrations/controllers/billing.js +267 -0
- package/dist/cjs/integrations/controllers/contacts.d.ts +66 -0
- package/dist/cjs/integrations/controllers/contacts.js +145 -0
- package/dist/cjs/integrations/controllers/customers.d.ts +96 -0
- package/dist/cjs/integrations/controllers/customers.js +206 -0
- package/dist/cjs/integrations/controllers/index.d.ts +6 -0
- package/dist/cjs/integrations/controllers/index.js +30 -0
- package/dist/cjs/integrations/controllers/invoices.d.ts +40 -0
- package/dist/cjs/integrations/controllers/invoices.js +72 -0
- package/dist/cjs/integrations/controllers/orders.d.ts +72 -0
- package/dist/cjs/integrations/controllers/orders.js +194 -0
- package/dist/cjs/integrations/controllers/provision-users.d.ts +62 -0
- package/dist/cjs/integrations/controllers/provision-users.js +130 -0
- package/dist/cjs/integrations/index.d.ts +29 -0
- package/dist/cjs/integrations/index.js +44 -0
- package/dist/cjs/integrations/types.d.ts +119 -0
- package/dist/cjs/integrations/types.js +2 -0
- package/dist/cjs/integrations/utils/api-fetch.d.ts +18 -0
- package/dist/cjs/integrations/utils/api-fetch.js +53 -0
- package/dist/cjs/integrations/utils/base-handler.d.ts +79 -0
- package/dist/cjs/integrations/utils/base-handler.js +168 -0
- package/dist/cjs/integrations/utils/create-adapter.d.ts +29 -0
- package/dist/cjs/integrations/utils/create-adapter.js +56 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Client.mjs +2 -2
- package/dist/esm/index.d.mts +1 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/integrations/adapters/nextjs/base-adapter.d.mts +10 -0
- package/dist/esm/integrations/adapters/nextjs/base-adapter.mjs +55 -0
- package/dist/esm/integrations/adapters/nextjs/index.d.mts +5 -0
- package/dist/esm/integrations/adapters/nextjs/index.mjs +5 -0
- package/dist/esm/integrations/adapters/nextjs/routes.d.mts +225 -0
- package/dist/esm/integrations/adapters/nextjs/routes.mjs +235 -0
- package/dist/esm/integrations/client.d.mts +49 -0
- package/dist/esm/integrations/client.mjs +89 -0
- package/dist/esm/integrations/controllers/billing.d.mts +196 -0
- package/dist/esm/integrations/controllers/billing.mjs +259 -0
- package/dist/esm/integrations/controllers/contacts.d.mts +66 -0
- package/dist/esm/integrations/controllers/contacts.mjs +140 -0
- package/dist/esm/integrations/controllers/customers.d.mts +96 -0
- package/dist/esm/integrations/controllers/customers.mjs +199 -0
- package/dist/esm/integrations/controllers/index.d.mts +6 -0
- package/dist/esm/integrations/controllers/index.mjs +6 -0
- package/dist/esm/integrations/controllers/invoices.d.mts +40 -0
- package/dist/esm/integrations/controllers/invoices.mjs +68 -0
- package/dist/esm/integrations/controllers/orders.d.mts +72 -0
- package/dist/esm/integrations/controllers/orders.mjs +189 -0
- package/dist/esm/integrations/controllers/provision-users.d.mts +62 -0
- package/dist/esm/integrations/controllers/provision-users.mjs +126 -0
- package/dist/esm/integrations/index.d.mts +29 -0
- package/dist/esm/integrations/index.mjs +28 -0
- package/dist/esm/integrations/types.d.mts +119 -0
- package/dist/esm/integrations/types.mjs +1 -0
- package/dist/esm/integrations/utils/api-fetch.d.mts +18 -0
- package/dist/esm/integrations/utils/api-fetch.mjs +50 -0
- package/dist/esm/integrations/utils/base-handler.d.mts +79 -0
- package/dist/esm/integrations/utils/base-handler.mjs +164 -0
- package/dist/esm/integrations/utils/create-adapter.d.mts +29 -0
- package/dist/esm/integrations/utils/create-adapter.mjs +53 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +32 -3
|
@@ -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,96 @@
|
|
|
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>;
|
|
64
|
+
/**
|
|
65
|
+
* Get a customer by external ID
|
|
66
|
+
*
|
|
67
|
+
* @param client - PaidClient instance
|
|
68
|
+
* @param customerExternalId - Customer's external ID
|
|
69
|
+
* @returns Customer data
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const customer = await getCustomer(client, 'user-123');
|
|
74
|
+
* console.log(customer.name, customer.email);
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function getCustomer(client: PaidClient, customerExternalId: string): Promise<any>;
|
|
78
|
+
/**
|
|
79
|
+
* Create a framework-agnostic handler for fetching a customer by external ID
|
|
80
|
+
*
|
|
81
|
+
* This handler can be used with any framework adapter.
|
|
82
|
+
* The customer external ID should be provided either in params or query string.
|
|
83
|
+
*
|
|
84
|
+
* @returns Handler function
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* // In Next.js route: /api/customers/[customerExternalId]/route.ts
|
|
89
|
+
* import { createGetCustomerHandler } from '@paid-ai/paid-node/integrations';
|
|
90
|
+
* import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
|
|
91
|
+
*
|
|
92
|
+
* const handler = createGetCustomerHandler();
|
|
93
|
+
* export const GET = nextjsAdapter(handler);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare function createGetCustomerHandler(): (request: import("../utils/base-handler.js").BaseRequestContext<any, Record<string, string>>, response: import("../utils/base-handler.js").BaseResponseContext, config?: import("../utils/base-handler.js").BaseHandlerConfig) => Promise<any>;
|
|
@@ -0,0 +1,206 @@
|
|
|
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.createCustomerWithDefaults = createCustomerWithDefaults;
|
|
13
|
+
exports.createCustomer = createCustomer;
|
|
14
|
+
exports.createCustomersHandler = createCustomersHandler;
|
|
15
|
+
exports.getCustomer = getCustomer;
|
|
16
|
+
exports.createGetCustomerHandler = createGetCustomerHandler;
|
|
17
|
+
const base_handler_js_1 = require("../utils/base-handler.js");
|
|
18
|
+
/**
|
|
19
|
+
* Generate placeholder values for missing customer fields
|
|
20
|
+
* Creates valid but fake data for rapid prototyping
|
|
21
|
+
*/
|
|
22
|
+
function generateCustomerDefaults(data) {
|
|
23
|
+
var _a, _b, _c, _d, _e, _f;
|
|
24
|
+
const timestamp = Date.now();
|
|
25
|
+
const randomId = Math.random().toString(36).substring(7);
|
|
26
|
+
const email = data.email || `user_${timestamp}@example.com`;
|
|
27
|
+
const name = data.name || `User ${randomId}`;
|
|
28
|
+
const nameParts = name.split(" ");
|
|
29
|
+
const firstName = data.firstName || nameParts[0] || "Joe";
|
|
30
|
+
const lastName = data.lastName || nameParts.slice(1).join(" ") || "Bloggs";
|
|
31
|
+
const billingAddress = {
|
|
32
|
+
line1: ((_a = data.billingAddress) === null || _a === void 0 ? void 0 : _a.line1) || "123 Placeholder Street",
|
|
33
|
+
line2: ((_b = data.billingAddress) === null || _b === void 0 ? void 0 : _b.line2) || "",
|
|
34
|
+
city: ((_c = data.billingAddress) === null || _c === void 0 ? void 0 : _c.city) || "London",
|
|
35
|
+
state: ((_d = data.billingAddress) === null || _d === void 0 ? void 0 : _d.state) || "London",
|
|
36
|
+
zipCode: ((_e = data.billingAddress) === null || _e === void 0 ? void 0 : _e.zipCode) || "SW1A 1AA",
|
|
37
|
+
country: ((_f = data.billingAddress) === null || _f === void 0 ? void 0 : _f.country) || "UK",
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
externalId: data.externalId,
|
|
41
|
+
email,
|
|
42
|
+
name,
|
|
43
|
+
firstName,
|
|
44
|
+
lastName,
|
|
45
|
+
company: data.company || "",
|
|
46
|
+
phone: data.phone || "",
|
|
47
|
+
billingAddress,
|
|
48
|
+
metadata: data.metadata || {},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Internal helper to create a customer
|
|
53
|
+
*/
|
|
54
|
+
function createCustomerInternal(client, data) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const customer = yield client.customers.create({
|
|
57
|
+
externalId: data.externalId,
|
|
58
|
+
name: data.name,
|
|
59
|
+
billingAddress: {
|
|
60
|
+
line1: data.billingAddress.line1,
|
|
61
|
+
line2: data.billingAddress.line2,
|
|
62
|
+
city: data.billingAddress.city,
|
|
63
|
+
state: data.billingAddress.state,
|
|
64
|
+
zipCode: data.billingAddress.zipCode,
|
|
65
|
+
country: data.billingAddress.country,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
if (!customer.id) {
|
|
69
|
+
throw new Error("Customer created but missing ID");
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
id: customer.id,
|
|
73
|
+
externalId: data.externalId,
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create a customer with defaults for missing fields
|
|
79
|
+
*
|
|
80
|
+
* This helper generates reasonable placeholder values for any missing data,
|
|
81
|
+
* making it easy to create customers for prototyping and development.
|
|
82
|
+
*
|
|
83
|
+
* @param client - PaidClient instance
|
|
84
|
+
* @param data - Customer data (only externalId is required)
|
|
85
|
+
* @returns Created customer with ID
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const customer = await createCustomerWithDefaults(client, {
|
|
90
|
+
* externalId: 'user-123',
|
|
91
|
+
* email: 'user@example.com'
|
|
92
|
+
* });
|
|
93
|
+
* // Generates: name, address, etc.
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
function createCustomerWithDefaults(client, data) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const completeData = generateCustomerDefaults(data);
|
|
99
|
+
return createCustomerInternal(client, completeData);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Create a customer with explicit data (NO defaults applied)
|
|
104
|
+
*
|
|
105
|
+
* Required fields: externalId, name, email, and complete billingAddress
|
|
106
|
+
* (line1, line2, city, state, zipCode, country)
|
|
107
|
+
*
|
|
108
|
+
* Use createCustomerWithDefaults() if you want automatic default values for missing fields.
|
|
109
|
+
*
|
|
110
|
+
* @param client - PaidClient instance
|
|
111
|
+
* @param data - Complete customer data with ALL required fields
|
|
112
|
+
* @returns Created customer with ID
|
|
113
|
+
* @throws Error if any required fields are missing
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const customer = await createCustomer(client, {
|
|
118
|
+
* externalId: 'user-123',
|
|
119
|
+
* email: 'user@example.com',
|
|
120
|
+
* name: 'John Doe',
|
|
121
|
+
* billingAddress: {
|
|
122
|
+
* line1: '123 Main St',
|
|
123
|
+
* line2: '',
|
|
124
|
+
* city: 'San Francisco',
|
|
125
|
+
* state: 'CA',
|
|
126
|
+
* zipCode: '94105',
|
|
127
|
+
* country: 'US'
|
|
128
|
+
* }
|
|
129
|
+
* });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
function createCustomer(client, data) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
return createCustomerInternal(client, data);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Create a framework-agnostic handler for customer creation
|
|
139
|
+
*
|
|
140
|
+
* This handler can be used with any framework adapter.
|
|
141
|
+
*
|
|
142
|
+
* @returns Handler function
|
|
143
|
+
*/
|
|
144
|
+
function createCustomersHandler() {
|
|
145
|
+
return (0, base_handler_js_1.createHandler)((client, body) => __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
if (!body.externalId) {
|
|
147
|
+
throw new Error("externalId is required");
|
|
148
|
+
}
|
|
149
|
+
const customer = yield createCustomerWithDefaults(client, body);
|
|
150
|
+
return { success: true, data: customer };
|
|
151
|
+
}), { requiredFields: ['externalId'] });
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get a customer by external ID
|
|
155
|
+
*
|
|
156
|
+
* @param client - PaidClient instance
|
|
157
|
+
* @param customerExternalId - Customer's external ID
|
|
158
|
+
* @returns Customer data
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const customer = await getCustomer(client, 'user-123');
|
|
163
|
+
* console.log(customer.name, customer.email);
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
function getCustomer(client, customerExternalId) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
const customer = yield client.customers.getByExternalId(customerExternalId);
|
|
169
|
+
return customer;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Create a framework-agnostic handler for fetching a customer by external ID
|
|
174
|
+
*
|
|
175
|
+
* This handler can be used with any framework adapter.
|
|
176
|
+
* The customer external ID should be provided either in params or query string.
|
|
177
|
+
*
|
|
178
|
+
* @returns Handler function
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* // In Next.js route: /api/customers/[customerExternalId]/route.ts
|
|
183
|
+
* import { createGetCustomerHandler } from '@paid-ai/paid-node/integrations';
|
|
184
|
+
* import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
|
|
185
|
+
*
|
|
186
|
+
* const handler = createGetCustomerHandler();
|
|
187
|
+
* export const GET = nextjsAdapter(handler);
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
function createGetCustomerHandler() {
|
|
191
|
+
return (0, base_handler_js_1.createHandler)((client, _body, params) => __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
const customerExternalId = params === null || params === void 0 ? void 0 : params.customerExternalId;
|
|
193
|
+
if (!customerExternalId) {
|
|
194
|
+
return {
|
|
195
|
+
success: false,
|
|
196
|
+
error: "customerExternalId is required",
|
|
197
|
+
status: 400,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
const customer = yield getCustomer(client, customerExternalId);
|
|
201
|
+
return { success: true, data: customer };
|
|
202
|
+
}), {
|
|
203
|
+
allowedMethods: ['GET'],
|
|
204
|
+
requireOrganizationId: false,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createCustomer, createCustomerWithDefaults, getCustomer, createGetCustomerHandler, createCustomersHandler, } from "./customers.js";
|
|
2
|
+
export { createContact, createContactWithDefaults, createContactsHandler, } from "./contacts.js";
|
|
3
|
+
export { createOrder, createOrderWithDefaults, createOrdersHandler, } from "./orders.js";
|
|
4
|
+
export { payInvoice, createPayInvoiceHandler, type PayInvoiceConfig, type PayInvoiceRequest, type PayInvoiceResult, activateOrderSync, createActivateOrderSyncHandler, type ActivateOrderSyncConfig, type ActivateOrderSyncRequest, type ActivateOrderSyncResult, createSetupIntent, createSetupIntentHandler, type SetupIntentConfig, type SetupIntentRequest, type SetupIntentResponse, } from "./billing.js";
|
|
5
|
+
export { getCustomerInvoices, createCustomerInvoicesHandler, type CustomerInvoicesResult, } from "./invoices.js";
|
|
6
|
+
export { provisionNewUser, createProvisioningHandler, } from "./provision-users.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createProvisioningHandler = exports.provisionNewUser = exports.createCustomerInvoicesHandler = exports.getCustomerInvoices = exports.createSetupIntentHandler = exports.createSetupIntent = exports.createActivateOrderSyncHandler = exports.activateOrderSync = exports.createPayInvoiceHandler = exports.payInvoice = exports.createOrdersHandler = exports.createOrderWithDefaults = exports.createOrder = exports.createContactsHandler = exports.createContactWithDefaults = exports.createContact = exports.createCustomersHandler = exports.createGetCustomerHandler = exports.getCustomer = exports.createCustomerWithDefaults = exports.createCustomer = void 0;
|
|
4
|
+
var customers_js_1 = require("./customers.js");
|
|
5
|
+
Object.defineProperty(exports, "createCustomer", { enumerable: true, get: function () { return customers_js_1.createCustomer; } });
|
|
6
|
+
Object.defineProperty(exports, "createCustomerWithDefaults", { enumerable: true, get: function () { return customers_js_1.createCustomerWithDefaults; } });
|
|
7
|
+
Object.defineProperty(exports, "getCustomer", { enumerable: true, get: function () { return customers_js_1.getCustomer; } });
|
|
8
|
+
Object.defineProperty(exports, "createGetCustomerHandler", { enumerable: true, get: function () { return customers_js_1.createGetCustomerHandler; } });
|
|
9
|
+
Object.defineProperty(exports, "createCustomersHandler", { enumerable: true, get: function () { return customers_js_1.createCustomersHandler; } });
|
|
10
|
+
var contacts_js_1 = require("./contacts.js");
|
|
11
|
+
Object.defineProperty(exports, "createContact", { enumerable: true, get: function () { return contacts_js_1.createContact; } });
|
|
12
|
+
Object.defineProperty(exports, "createContactWithDefaults", { enumerable: true, get: function () { return contacts_js_1.createContactWithDefaults; } });
|
|
13
|
+
Object.defineProperty(exports, "createContactsHandler", { enumerable: true, get: function () { return contacts_js_1.createContactsHandler; } });
|
|
14
|
+
var orders_js_1 = require("./orders.js");
|
|
15
|
+
Object.defineProperty(exports, "createOrder", { enumerable: true, get: function () { return orders_js_1.createOrder; } });
|
|
16
|
+
Object.defineProperty(exports, "createOrderWithDefaults", { enumerable: true, get: function () { return orders_js_1.createOrderWithDefaults; } });
|
|
17
|
+
Object.defineProperty(exports, "createOrdersHandler", { enumerable: true, get: function () { return orders_js_1.createOrdersHandler; } });
|
|
18
|
+
var billing_js_1 = require("./billing.js");
|
|
19
|
+
Object.defineProperty(exports, "payInvoice", { enumerable: true, get: function () { return billing_js_1.payInvoice; } });
|
|
20
|
+
Object.defineProperty(exports, "createPayInvoiceHandler", { enumerable: true, get: function () { return billing_js_1.createPayInvoiceHandler; } });
|
|
21
|
+
Object.defineProperty(exports, "activateOrderSync", { enumerable: true, get: function () { return billing_js_1.activateOrderSync; } });
|
|
22
|
+
Object.defineProperty(exports, "createActivateOrderSyncHandler", { enumerable: true, get: function () { return billing_js_1.createActivateOrderSyncHandler; } });
|
|
23
|
+
Object.defineProperty(exports, "createSetupIntent", { enumerable: true, get: function () { return billing_js_1.createSetupIntent; } });
|
|
24
|
+
Object.defineProperty(exports, "createSetupIntentHandler", { enumerable: true, get: function () { return billing_js_1.createSetupIntentHandler; } });
|
|
25
|
+
var invoices_js_1 = require("./invoices.js");
|
|
26
|
+
Object.defineProperty(exports, "getCustomerInvoices", { enumerable: true, get: function () { return invoices_js_1.getCustomerInvoices; } });
|
|
27
|
+
Object.defineProperty(exports, "createCustomerInvoicesHandler", { enumerable: true, get: function () { return invoices_js_1.createCustomerInvoicesHandler; } });
|
|
28
|
+
var provision_users_js_1 = require("./provision-users.js");
|
|
29
|
+
Object.defineProperty(exports, "provisionNewUser", { enumerable: true, get: function () { return provision_users_js_1.provisionNewUser; } });
|
|
30
|
+
Object.defineProperty(exports, "createProvisioningHandler", { enumerable: true, get: function () { return provision_users_js_1.createProvisioningHandler; } });
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PayInvoiceConfig } from "./billing.js";
|
|
2
|
+
export interface CustomerInvoicesResult {
|
|
3
|
+
data: any[];
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Get customer invoices
|
|
7
|
+
* Fetches all invoices for a customer by their external ID.
|
|
8
|
+
*
|
|
9
|
+
* @param config - API configuration with organization context
|
|
10
|
+
* @param customerExternalId - Customer's external ID
|
|
11
|
+
* @returns Customer invoices
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const result = await getCustomerInvoices(
|
|
16
|
+
* {
|
|
17
|
+
* apiUrl: 'https://api.agentpaid.io',
|
|
18
|
+
* apiKey: process.env.PAID_API_KEY,
|
|
19
|
+
* organizationId: 'org_123'
|
|
20
|
+
* },
|
|
21
|
+
* 'user-123'
|
|
22
|
+
* );
|
|
23
|
+
*
|
|
24
|
+
* console.log(`Found ${result.data.length} invoices`);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function getCustomerInvoices(config: PayInvoiceConfig, customerExternalId: string): Promise<CustomerInvoicesResult>;
|
|
28
|
+
interface CustomerInvoicesRequest {
|
|
29
|
+
customerExternalId: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a framework-agnostic handler for fetching customer invoices
|
|
33
|
+
*
|
|
34
|
+
* This handler can be used with any framework adapter.
|
|
35
|
+
* Organization ID is automatically fetched from the API key.
|
|
36
|
+
*
|
|
37
|
+
* @returns Handler function
|
|
38
|
+
*/
|
|
39
|
+
export declare function createCustomerInvoicesHandler(): (request: import("../utils/base-handler.js").BaseRequestContext<CustomerInvoicesRequest, Record<string, string>>, response: import("../utils/base-handler.js").BaseResponseContext, config?: import("../utils/base-handler.js").BaseHandlerConfig) => Promise<any>;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
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.getCustomerInvoices = getCustomerInvoices;
|
|
13
|
+
exports.createCustomerInvoicesHandler = createCustomerInvoicesHandler;
|
|
14
|
+
const api_fetch_js_1 = require("../utils/api-fetch.js");
|
|
15
|
+
const base_handler_js_1 = require("../utils/base-handler.js");
|
|
16
|
+
/**
|
|
17
|
+
* Get customer invoices
|
|
18
|
+
* Fetches all invoices for a customer by their external ID.
|
|
19
|
+
*
|
|
20
|
+
* @param config - API configuration with organization context
|
|
21
|
+
* @param customerExternalId - Customer's external ID
|
|
22
|
+
* @returns Customer invoices
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const result = await getCustomerInvoices(
|
|
27
|
+
* {
|
|
28
|
+
* apiUrl: 'https://api.agentpaid.io',
|
|
29
|
+
* apiKey: process.env.PAID_API_KEY,
|
|
30
|
+
* organizationId: 'org_123'
|
|
31
|
+
* },
|
|
32
|
+
* 'user-123'
|
|
33
|
+
* );
|
|
34
|
+
*
|
|
35
|
+
* console.log(`Found ${result.data.length} invoices`);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function getCustomerInvoices(config, customerExternalId) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
if (!customerExternalId) {
|
|
41
|
+
throw new Error("customerExternalId is required");
|
|
42
|
+
}
|
|
43
|
+
const data = yield (0, api_fetch_js_1.paidApiFetch)(config, `/api/organizations/${config.organizationId}/customer/external/${customerExternalId}/invoices`, { method: "GET" });
|
|
44
|
+
return { data: data.data || data || [] };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a framework-agnostic handler for fetching customer invoices
|
|
49
|
+
*
|
|
50
|
+
* This handler can be used with any framework adapter.
|
|
51
|
+
* Organization ID is automatically fetched from the API key.
|
|
52
|
+
*
|
|
53
|
+
* @returns Handler function
|
|
54
|
+
*/
|
|
55
|
+
function createCustomerInvoicesHandler() {
|
|
56
|
+
return (0, base_handler_js_1.createHandler)((_client, _body, params, organizationId) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
if (!organizationId) {
|
|
58
|
+
return { success: false, error: 'Organization ID not found', status: 500 };
|
|
59
|
+
}
|
|
60
|
+
const customerExternalId = params === null || params === void 0 ? void 0 : params.customerExternalId;
|
|
61
|
+
if (!customerExternalId) {
|
|
62
|
+
return { success: false, error: 'customerExternalId is required', status: 400 };
|
|
63
|
+
}
|
|
64
|
+
const apiKey = process.env.PAID_API_KEY || '';
|
|
65
|
+
const apiUrl = process.env.PAID_API_URL || 'https://api.agentpaid.io';
|
|
66
|
+
const result = yield getCustomerInvoices({ apiUrl, apiKey, organizationId }, customerExternalId);
|
|
67
|
+
return {
|
|
68
|
+
success: true,
|
|
69
|
+
data: result.data,
|
|
70
|
+
};
|
|
71
|
+
}), { allowedMethods: ['GET'], requireOrganizationId: true });
|
|
72
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { PaidClient } from "../../Client.js";
|
|
2
|
+
import type { OrderConfig, OrderCreationResult, OrderOptions } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create an order with defaults for missing fields
|
|
5
|
+
*
|
|
6
|
+
* This helper generates reasonable defaults for dates, names, and other fields,
|
|
7
|
+
* making it easy to create orders for prototyping and development.
|
|
8
|
+
*
|
|
9
|
+
* @param client - PaidClient instance
|
|
10
|
+
* @param config - Order configuration (customerId, customerExternalId, agentExternalId required)
|
|
11
|
+
* @param options - Additional options for order creation
|
|
12
|
+
* @returns Created order with ID
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const order = await createOrderWithDefaults(client, {
|
|
17
|
+
* customerId: 'cus_123',
|
|
18
|
+
* customerExternalId: 'user-123',
|
|
19
|
+
* agentExternalId: 'agent-prod'
|
|
20
|
+
* });
|
|
21
|
+
* // Generates: startDate, endDate (1 year), name, description, currency (USD)
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function createOrderWithDefaults(client: PaidClient, config: OrderConfig, options?: OrderOptions): Promise<OrderCreationResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Create an order with explicit configuration (NO defaults applied)
|
|
27
|
+
*
|
|
28
|
+
* Required fields: customerId, customerExternalId, agentExternalId, name, description,
|
|
29
|
+
* startDate, endDate, currency, orderLines
|
|
30
|
+
*
|
|
31
|
+
* Use createOrderWithDefaults() if you want automatic default values for missing fields.
|
|
32
|
+
*
|
|
33
|
+
* @param client - PaidClient instance
|
|
34
|
+
* @param config - Complete order configuration with ALL required fields
|
|
35
|
+
* @param options - Additional options for order creation
|
|
36
|
+
* @returns Created order with ID
|
|
37
|
+
* @throws Error if any required fields are missing
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const order = await createOrder(client, {
|
|
42
|
+
* customerId: 'cus_123',
|
|
43
|
+
* customerExternalId: 'user-123',
|
|
44
|
+
* billingContactId: 'contact_123',
|
|
45
|
+
* agentExternalId: 'agent-prod',
|
|
46
|
+
* name: 'Pro Plan Subscription',
|
|
47
|
+
* description: 'Monthly subscription to Pro plan',
|
|
48
|
+
* startDate: '2024-01-01',
|
|
49
|
+
* endDate: '2025-01-01',
|
|
50
|
+
* currency: 'USD',
|
|
51
|
+
* orderLines: [{
|
|
52
|
+
* agentExternalId: 'agent-prod',
|
|
53
|
+
* name: 'Pro Plan',
|
|
54
|
+
* description: 'Pro plan features'
|
|
55
|
+
* }]
|
|
56
|
+
* }, { autoActivate: true });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function createOrder(client: PaidClient, config: Required<OrderConfig>, options?: OrderOptions): Promise<OrderCreationResult>;
|
|
60
|
+
interface OrderRequest extends OrderConfig {
|
|
61
|
+
autoActivate?: boolean;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a framework-agnostic handler for order creation
|
|
65
|
+
*
|
|
66
|
+
* This handler can be used with any framework adapter.
|
|
67
|
+
*
|
|
68
|
+
* @param helperOptions - Default options for order creation
|
|
69
|
+
* @returns Handler function
|
|
70
|
+
*/
|
|
71
|
+
export declare function createOrdersHandler(helperOptions?: OrderOptions): (request: import("../utils/base-handler.js").BaseRequestContext<OrderRequest, Record<string, string>>, response: import("../utils/base-handler.js").BaseResponseContext, config?: import("../utils/base-handler.js").BaseHandlerConfig) => Promise<any>;
|
|
72
|
+
export {};
|