@paid-ai/paid-node 0.5.0-alpha1 → 0.5.0-alpha3
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/integrations/adapters/expressjs/base-adapter.d.ts +17 -0
- package/dist/cjs/integrations/adapters/expressjs/base-adapter.js +71 -0
- package/dist/cjs/integrations/adapters/expressjs/index.d.ts +6 -0
- package/dist/cjs/integrations/adapters/expressjs/index.js +20 -0
- package/dist/cjs/integrations/adapters/expressjs/routes.d.ts +162 -0
- package/dist/cjs/integrations/adapters/expressjs/routes.js +269 -0
- package/dist/cjs/integrations/adapters/nestjs/index.d.ts +7 -0
- package/dist/cjs/integrations/adapters/nestjs/index.js +23 -0
- package/dist/cjs/integrations/adapters/nextjs/index.d.ts +1 -1
- package/dist/cjs/integrations/adapters/nextjs/index.js +3 -1
- package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +51 -0
- package/dist/cjs/integrations/adapters/nextjs/routes.js +54 -0
- package/dist/cjs/integrations/controllers/billing.d.ts +83 -0
- package/dist/cjs/integrations/controllers/billing.js +104 -1
- package/dist/cjs/integrations/controllers/customers.d.ts +33 -0
- package/dist/cjs/integrations/controllers/customers.js +56 -0
- package/dist/cjs/integrations/controllers/index.d.ts +2 -2
- package/dist/cjs/integrations/controllers/index.js +5 -1
- 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/integrations/adapters/expressjs/base-adapter.d.mts +17 -0
- package/dist/esm/integrations/adapters/expressjs/base-adapter.mjs +67 -0
- package/dist/esm/integrations/adapters/expressjs/index.d.mts +6 -0
- package/dist/esm/integrations/adapters/expressjs/index.mjs +6 -0
- package/dist/esm/integrations/adapters/expressjs/routes.d.mts +162 -0
- package/dist/esm/integrations/adapters/expressjs/routes.mjs +258 -0
- package/dist/esm/integrations/adapters/nestjs/index.d.mts +7 -0
- package/dist/esm/integrations/adapters/nestjs/index.mjs +7 -0
- package/dist/esm/integrations/adapters/nextjs/index.d.mts +1 -1
- package/dist/esm/integrations/adapters/nextjs/index.mjs +1 -1
- package/dist/esm/integrations/adapters/nextjs/routes.d.mts +51 -0
- package/dist/esm/integrations/adapters/nextjs/routes.mjs +54 -2
- package/dist/esm/integrations/controllers/billing.d.mts +83 -0
- package/dist/esm/integrations/controllers/billing.mjs +102 -1
- package/dist/esm/integrations/controllers/customers.d.mts +33 -0
- package/dist/esm/integrations/controllers/customers.mjs +54 -0
- package/dist/esm/integrations/controllers/index.d.mts +2 -2
- package/dist/esm/integrations/controllers/index.mjs +2 -2
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +30 -1
|
@@ -111,7 +111,7 @@ export function activateOrderSync(config, request) {
|
|
|
111
111
|
if (!confirmationToken) {
|
|
112
112
|
throw new Error("confirmationToken is required");
|
|
113
113
|
}
|
|
114
|
-
const data = yield paidApiFetch(config, `/api/organizations/${config.organizationId}/orders/${orderId}/activate-
|
|
114
|
+
const data = yield paidApiFetch(config, `/api/organizations/${config.organizationId}/orders/${orderId}/activate-and-pay`, {
|
|
115
115
|
method: "POST",
|
|
116
116
|
body: Object.assign({ confirmationToken }, (returnUrl && { returnUrl })),
|
|
117
117
|
});
|
|
@@ -156,3 +156,104 @@ export function createActivateOrderSyncHandler(defaultReturnUrl) {
|
|
|
156
156
|
requireOrganizationId: true,
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Create a setup intent for adding payment methods without immediate charge
|
|
161
|
+
*
|
|
162
|
+
* Setup intents are used to save payment methods for future use without
|
|
163
|
+
* charging the customer immediately. This is useful for:
|
|
164
|
+
* - Adding payment methods for subscription billing
|
|
165
|
+
* - Updating payment methods
|
|
166
|
+
* - Pre-authorizing payment methods
|
|
167
|
+
*
|
|
168
|
+
* @param config - API configuration with organization context
|
|
169
|
+
* @param request - Setup intent request with customer ID and confirmation token
|
|
170
|
+
* @returns Setup intent result with payment method details
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* const result = await createSetupIntent(
|
|
175
|
+
* {
|
|
176
|
+
* apiUrl: 'https://api.agentpaid.io',
|
|
177
|
+
* apiKey: process.env.PAID_API_KEY,
|
|
178
|
+
* organizationId: 'org_123'
|
|
179
|
+
* },
|
|
180
|
+
* {
|
|
181
|
+
* customerId: 'cus_123',
|
|
182
|
+
* confirmationToken: 'seti_123_secret_456',
|
|
183
|
+
* returnUrl: 'https://example.com/return',
|
|
184
|
+
* metadata: { source: 'web' }
|
|
185
|
+
* }
|
|
186
|
+
* );
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
export function createSetupIntent(config, request) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
const { customerId, confirmationToken, returnUrl, metadata } = request;
|
|
192
|
+
if (!customerId) {
|
|
193
|
+
throw new Error("customerId is required");
|
|
194
|
+
}
|
|
195
|
+
if (!confirmationToken) {
|
|
196
|
+
throw new Error("confirmationToken is required");
|
|
197
|
+
}
|
|
198
|
+
const data = yield paidApiFetch(config, `/api/organizations/${config.organizationId}/payments/setup-intents-external`, {
|
|
199
|
+
method: "POST",
|
|
200
|
+
body: Object.assign(Object.assign({ customerId,
|
|
201
|
+
confirmationToken }, (returnUrl && { returnUrl })), (metadata && { metadata })),
|
|
202
|
+
});
|
|
203
|
+
return {
|
|
204
|
+
setupIntent: data.setupIntent || data,
|
|
205
|
+
message: "Setup intent created successfully",
|
|
206
|
+
};
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Create a framework-agnostic handler for setup intent creation
|
|
211
|
+
*
|
|
212
|
+
* This handler can be used with any framework adapter.
|
|
213
|
+
*
|
|
214
|
+
* @param defaultReturnUrl - Optional default return URL
|
|
215
|
+
* @returns Handler function
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* // Next.js API route
|
|
220
|
+
* import { createSetupIntentHandler } from '@paid-ai/paid-node/integrations';
|
|
221
|
+
*
|
|
222
|
+
* const handler = createSetupIntentHandler('https://myapp.com/billing');
|
|
223
|
+
*
|
|
224
|
+
* export async function POST(req: Request) {
|
|
225
|
+
* return handler(
|
|
226
|
+
* {
|
|
227
|
+
* body: await req.json(),
|
|
228
|
+
* headers: Object.fromEntries(req.headers),
|
|
229
|
+
* method: 'POST'
|
|
230
|
+
* },
|
|
231
|
+
* {
|
|
232
|
+
* json: (data, status = 200) => Response.json(data, { status }),
|
|
233
|
+
* error: (message, status) => Response.json({ error: message }, { status })
|
|
234
|
+
* }
|
|
235
|
+
* );
|
|
236
|
+
* }
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
export function createSetupIntentHandler(defaultReturnUrl) {
|
|
240
|
+
return createHandler((client, body, _params, organizationId) => __awaiter(this, void 0, void 0, function* () {
|
|
241
|
+
var _a, _b;
|
|
242
|
+
const apiKey = (_a = client._options) === null || _a === void 0 ? void 0 : _a.token;
|
|
243
|
+
const baseUrl = ((_b = client._options) === null || _b === void 0 ? void 0 : _b.baseUrl) || 'https://api.agentpaid.io/api/v1';
|
|
244
|
+
const apiUrl = baseUrl.replace('/api/v1', '');
|
|
245
|
+
const result = yield createSetupIntent({ apiUrl, apiKey, organizationId: organizationId }, {
|
|
246
|
+
customerId: body.customerId,
|
|
247
|
+
confirmationToken: body.confirmationToken,
|
|
248
|
+
returnUrl: body.returnUrl || defaultReturnUrl,
|
|
249
|
+
metadata: body.metadata,
|
|
250
|
+
});
|
|
251
|
+
return {
|
|
252
|
+
success: true,
|
|
253
|
+
data: result,
|
|
254
|
+
};
|
|
255
|
+
}), {
|
|
256
|
+
requiredFields: ['customerId', 'confirmationToken'],
|
|
257
|
+
requireOrganizationId: true,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
@@ -61,3 +61,36 @@ export declare function createCustomer(client: PaidClient, data: Required<Omit<C
|
|
|
61
61
|
* @returns Handler function
|
|
62
62
|
*/
|
|
63
63
|
export declare function createCustomersHandler(): (request: import("../utils/base-handler.mjs").BaseRequestContext<CustomerData, Record<string, string>>, response: import("../utils/base-handler.mjs").BaseResponseContext, config?: import("../utils/base-handler.mjs").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.mjs").BaseRequestContext<any, Record<string, string>>, response: import("../utils/base-handler.mjs").BaseResponseContext, config?: import("../utils/base-handler.mjs").BaseHandlerConfig) => Promise<any>;
|
|
@@ -143,3 +143,57 @@ export function createCustomersHandler() {
|
|
|
143
143
|
return { success: true, data: customer };
|
|
144
144
|
}), { requiredFields: ['externalId'] });
|
|
145
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Get a customer by external ID
|
|
148
|
+
*
|
|
149
|
+
* @param client - PaidClient instance
|
|
150
|
+
* @param customerExternalId - Customer's external ID
|
|
151
|
+
* @returns Customer data
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* const customer = await getCustomer(client, 'user-123');
|
|
156
|
+
* console.log(customer.name, customer.email);
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
export function getCustomer(client, customerExternalId) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
const customer = yield client.customers.getByExternalId(customerExternalId);
|
|
162
|
+
return customer;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Create a framework-agnostic handler for fetching a customer by external ID
|
|
167
|
+
*
|
|
168
|
+
* This handler can be used with any framework adapter.
|
|
169
|
+
* The customer external ID should be provided either in params or query string.
|
|
170
|
+
*
|
|
171
|
+
* @returns Handler function
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* // In Next.js route: /api/customers/[customerExternalId]/route.ts
|
|
176
|
+
* import { createGetCustomerHandler } from '@paid-ai/paid-node/integrations';
|
|
177
|
+
* import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
|
|
178
|
+
*
|
|
179
|
+
* const handler = createGetCustomerHandler();
|
|
180
|
+
* export const GET = nextjsAdapter(handler);
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
export function createGetCustomerHandler() {
|
|
184
|
+
return createHandler((client, _body, params) => __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
const customerExternalId = params === null || params === void 0 ? void 0 : params.customerExternalId;
|
|
186
|
+
if (!customerExternalId) {
|
|
187
|
+
return {
|
|
188
|
+
success: false,
|
|
189
|
+
error: "customerExternalId is required",
|
|
190
|
+
status: 400,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
const customer = yield getCustomer(client, customerExternalId);
|
|
194
|
+
return { success: true, data: customer };
|
|
195
|
+
}), {
|
|
196
|
+
allowedMethods: ['GET'],
|
|
197
|
+
requireOrganizationId: false,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { createCustomer, createCustomerWithDefaults, createCustomersHandler, } from "./customers.mjs";
|
|
1
|
+
export { createCustomer, createCustomerWithDefaults, getCustomer, createGetCustomerHandler, createCustomersHandler, } from "./customers.mjs";
|
|
2
2
|
export { createContact, createContactWithDefaults, createContactsHandler, } from "./contacts.mjs";
|
|
3
3
|
export { createOrder, createOrderWithDefaults, createOrdersHandler, } from "./orders.mjs";
|
|
4
|
-
export { payInvoice, createPayInvoiceHandler, type PayInvoiceConfig, type PayInvoiceRequest, type PayInvoiceResult, activateOrderSync, createActivateOrderSyncHandler, type ActivateOrderSyncConfig, type ActivateOrderSyncRequest, type ActivateOrderSyncResult, } from "./billing.mjs";
|
|
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.mjs";
|
|
5
5
|
export { getCustomerInvoices, createCustomerInvoicesHandler, type CustomerInvoicesResult, } from "./invoices.mjs";
|
|
6
6
|
export { provisionNewUser, createProvisioningHandler, } from "./provision-users.mjs";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { createCustomer, createCustomerWithDefaults, createCustomersHandler, } from "./customers.mjs";
|
|
1
|
+
export { createCustomer, createCustomerWithDefaults, getCustomer, createGetCustomerHandler, createCustomersHandler, } from "./customers.mjs";
|
|
2
2
|
export { createContact, createContactWithDefaults, createContactsHandler, } from "./contacts.mjs";
|
|
3
3
|
export { createOrder, createOrderWithDefaults, createOrdersHandler, } from "./orders.mjs";
|
|
4
|
-
export { payInvoice, createPayInvoiceHandler, activateOrderSync, createActivateOrderSyncHandler, } from "./billing.mjs";
|
|
4
|
+
export { payInvoice, createPayInvoiceHandler, activateOrderSync, createActivateOrderSyncHandler, createSetupIntent, createSetupIntentHandler, } from "./billing.mjs";
|
|
5
5
|
export { getCustomerInvoices, createCustomerInvoicesHandler, } from "./invoices.mjs";
|
|
6
6
|
export { provisionNewUser, createProvisioningHandler, } from "./provision-users.mjs";
|
package/dist/esm/version.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.5.0-
|
|
1
|
+
export declare const SDK_VERSION = "0.5.0-alpha3";
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.5.0-
|
|
1
|
+
export const SDK_VERSION = "0.5.0-alpha3";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paid-ai/paid-node",
|
|
3
|
-
"version": "0.5.0-
|
|
3
|
+
"version": "0.5.0-alpha3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": "https://github.com/paid-ai/paid-node",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -104,6 +104,30 @@
|
|
|
104
104
|
},
|
|
105
105
|
"default": "./dist/cjs/integrations/adapters/nextjs/index.js"
|
|
106
106
|
},
|
|
107
|
+
"./integrations/express": {
|
|
108
|
+
"types": "./dist/cjs/integrations/adapters/expressjs/index.d.ts",
|
|
109
|
+
"import": {
|
|
110
|
+
"types": "./dist/esm/integrations/adapters/expressjs/index.d.mts",
|
|
111
|
+
"default": "./dist/esm/integrations/adapters/expressjs/index.mjs"
|
|
112
|
+
},
|
|
113
|
+
"require": {
|
|
114
|
+
"types": "./dist/cjs/integrations/adapters/expressjs/index.d.ts",
|
|
115
|
+
"default": "./dist/cjs/integrations/adapters/expressjs/index.js"
|
|
116
|
+
},
|
|
117
|
+
"default": "./dist/cjs/integrations/adapters/expressjs/index.js"
|
|
118
|
+
},
|
|
119
|
+
"./integrations/nestjs": {
|
|
120
|
+
"types": "./dist/cjs/integrations/adapters/nestjs/index.d.ts",
|
|
121
|
+
"import": {
|
|
122
|
+
"types": "./dist/esm/integrations/adapters/nestjs/index.d.mts",
|
|
123
|
+
"default": "./dist/esm/integrations/adapters/nestjs/index.mjs"
|
|
124
|
+
},
|
|
125
|
+
"require": {
|
|
126
|
+
"types": "./dist/cjs/integrations/adapters/nestjs/index.d.ts",
|
|
127
|
+
"default": "./dist/cjs/integrations/adapters/nestjs/index.js"
|
|
128
|
+
},
|
|
129
|
+
"default": "./dist/cjs/integrations/adapters/nestjs/index.js"
|
|
130
|
+
},
|
|
107
131
|
"./package.json": "./package.json"
|
|
108
132
|
},
|
|
109
133
|
"files": [
|
|
@@ -137,6 +161,7 @@
|
|
|
137
161
|
"@anthropic-ai/sdk": ">=0.36.3",
|
|
138
162
|
"@langchain/core": ">=0.3.0",
|
|
139
163
|
"@mistralai/mistralai": ">=1.0.0",
|
|
164
|
+
"@types/express": ">=4.17.0",
|
|
140
165
|
"ai": ">=5.0.0",
|
|
141
166
|
"openai": ">=4.85.4",
|
|
142
167
|
"next": ">=13.0.0"
|
|
@@ -154,6 +179,9 @@
|
|
|
154
179
|
"@mistralai/mistralai": {
|
|
155
180
|
"optional": true
|
|
156
181
|
},
|
|
182
|
+
"@types/express": {
|
|
183
|
+
"optional": true
|
|
184
|
+
},
|
|
157
185
|
"ai": {
|
|
158
186
|
"optional": true
|
|
159
187
|
},
|
|
@@ -169,6 +197,7 @@
|
|
|
169
197
|
"@types/qs": "^6.9.17",
|
|
170
198
|
"@types/node-fetch": "^2.6.12",
|
|
171
199
|
"@types/readable-stream": "^4.0.18",
|
|
200
|
+
"@types/express": "^4.17.21",
|
|
172
201
|
"webpack": "^5.97.1",
|
|
173
202
|
"ts-loader": "^9.5.1",
|
|
174
203
|
"jest": "^29.7.0",
|