@paid-ai/paid-node 0.5.0-alpha2 → 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/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/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +30 -1
package/dist/cjs/Client.js
CHANGED
|
@@ -60,8 +60,8 @@ class PaidClient {
|
|
|
60
60
|
this._options = Object.assign(Object.assign({}, _options), { headers: (0, headers_js_1.mergeHeaders)({
|
|
61
61
|
"X-Fern-Language": "JavaScript",
|
|
62
62
|
"X-Fern-SDK-Name": "@paid-ai/paid-node",
|
|
63
|
-
"X-Fern-SDK-Version": "0.5.0-
|
|
64
|
-
"User-Agent": "@paid-ai/paid-node/0.5.0-
|
|
63
|
+
"X-Fern-SDK-Version": "0.5.0-alpha3",
|
|
64
|
+
"User-Agent": "@paid-ai/paid-node/0.5.0-alpha3",
|
|
65
65
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
66
66
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
67
67
|
}, _options === null || _options === void 0 ? void 0 : _options.headers) });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExpressJS adapter for Paid SDK
|
|
3
|
+
* Converts Express Request/Response to framework-agnostic format
|
|
4
|
+
*/
|
|
5
|
+
import { Request, Response } from "express";
|
|
6
|
+
/**
|
|
7
|
+
* Handles Express Request/Response conversion to base handler format
|
|
8
|
+
*/
|
|
9
|
+
export declare const expressjsAdapter: (innerHandler: Function) => (req: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, context?: any, config?: any) => Promise<any>;
|
|
10
|
+
/**
|
|
11
|
+
* Create response context for ExpressJS
|
|
12
|
+
* This converts the base handler response methods to ExpressJS/Express format
|
|
13
|
+
*/
|
|
14
|
+
export declare function createExpressJSResponseContext(res: Response): {
|
|
15
|
+
json: (data: any, status?: number) => Response<any, Record<string, any>>;
|
|
16
|
+
error: (message: string, status: number) => Response<any, Record<string, any>>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ExpressJS adapter for Paid SDK
|
|
4
|
+
* Converts Express Request/Response to framework-agnostic format
|
|
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.expressjsAdapter = void 0;
|
|
17
|
+
exports.createExpressJSResponseContext = createExpressJSResponseContext;
|
|
18
|
+
const create_adapter_js_1 = require("../../utils/create-adapter.js");
|
|
19
|
+
/**
|
|
20
|
+
* Handles Express Request/Response conversion to base handler format
|
|
21
|
+
*/
|
|
22
|
+
exports.expressjsAdapter = (0, create_adapter_js_1.createFrameworkAdapter)({
|
|
23
|
+
getBody: (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
return req.body || {};
|
|
25
|
+
}),
|
|
26
|
+
getHeaders: (req) => {
|
|
27
|
+
const headers = {};
|
|
28
|
+
Object.entries(req.headers).forEach(([key, value]) => {
|
|
29
|
+
if (typeof value === "string") {
|
|
30
|
+
headers[key] = value;
|
|
31
|
+
}
|
|
32
|
+
else if (Array.isArray(value)) {
|
|
33
|
+
headers[key] = value.join(", ");
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return headers;
|
|
37
|
+
},
|
|
38
|
+
getMethod: (req) => req.method || "GET",
|
|
39
|
+
getParams: (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
return req.params || {};
|
|
41
|
+
}),
|
|
42
|
+
getQuery: (req) => {
|
|
43
|
+
const query = {};
|
|
44
|
+
Object.entries(req.query).forEach(([key, value]) => {
|
|
45
|
+
if (typeof value === "string") {
|
|
46
|
+
query[key] = value;
|
|
47
|
+
}
|
|
48
|
+
else if (Array.isArray(value)) {
|
|
49
|
+
query[key] = value.join(", ");
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return query;
|
|
53
|
+
},
|
|
54
|
+
sendJson: (data, status) => {
|
|
55
|
+
throw new Error("ExpressJS adapter requires using response context from handler");
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Create response context for ExpressJS
|
|
60
|
+
* This converts the base handler response methods to ExpressJS/Express format
|
|
61
|
+
*/
|
|
62
|
+
function createExpressJSResponseContext(res) {
|
|
63
|
+
return {
|
|
64
|
+
json: (data, status = 200) => {
|
|
65
|
+
return res.status(status).json(data);
|
|
66
|
+
},
|
|
67
|
+
error: (message, status) => {
|
|
68
|
+
return res.status(status).json({ error: message });
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExpressJS integration for Paid SDK
|
|
3
|
+
* Drop-in handlers for ExpressJS controllers using Express Request/Response
|
|
4
|
+
*/
|
|
5
|
+
export { expressjsAdapter, createExpressJSResponseContext } from "./base-adapter.js";
|
|
6
|
+
export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createGetCustomerRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, type ActivateOrderSyncRouteConfig, type OrdersRouteConfig, type ProvisioningRouteConfig, type SetupIntentRouteConfig, } from "./routes.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ExpressJS integration for Paid SDK
|
|
4
|
+
* Drop-in handlers for ExpressJS controllers using Express Request/Response
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createSetupIntentRoute = exports.createProvisioningRoute = exports.createPayInvoiceRoute = exports.createOrdersRoute = exports.createGetCustomerRoute = exports.createCustomersRoute = exports.createCustomerInvoicesRoute = exports.createContactsRoute = exports.createActivateOrderSyncRoute = exports.createExpressJSResponseContext = exports.expressjsAdapter = void 0;
|
|
8
|
+
var base_adapter_js_1 = require("./base-adapter.js");
|
|
9
|
+
Object.defineProperty(exports, "expressjsAdapter", { enumerable: true, get: function () { return base_adapter_js_1.expressjsAdapter; } });
|
|
10
|
+
Object.defineProperty(exports, "createExpressJSResponseContext", { enumerable: true, get: function () { return base_adapter_js_1.createExpressJSResponseContext; } });
|
|
11
|
+
var routes_js_1 = require("./routes.js");
|
|
12
|
+
Object.defineProperty(exports, "createActivateOrderSyncRoute", { enumerable: true, get: function () { return routes_js_1.createActivateOrderSyncRoute; } });
|
|
13
|
+
Object.defineProperty(exports, "createContactsRoute", { enumerable: true, get: function () { return routes_js_1.createContactsRoute; } });
|
|
14
|
+
Object.defineProperty(exports, "createCustomerInvoicesRoute", { enumerable: true, get: function () { return routes_js_1.createCustomerInvoicesRoute; } });
|
|
15
|
+
Object.defineProperty(exports, "createCustomersRoute", { enumerable: true, get: function () { return routes_js_1.createCustomersRoute; } });
|
|
16
|
+
Object.defineProperty(exports, "createGetCustomerRoute", { enumerable: true, get: function () { return routes_js_1.createGetCustomerRoute; } });
|
|
17
|
+
Object.defineProperty(exports, "createOrdersRoute", { enumerable: true, get: function () { return routes_js_1.createOrdersRoute; } });
|
|
18
|
+
Object.defineProperty(exports, "createPayInvoiceRoute", { enumerable: true, get: function () { return routes_js_1.createPayInvoiceRoute; } });
|
|
19
|
+
Object.defineProperty(exports, "createProvisioningRoute", { enumerable: true, get: function () { return routes_js_1.createProvisioningRoute; } });
|
|
20
|
+
Object.defineProperty(exports, "createSetupIntentRoute", { enumerable: true, get: function () { return routes_js_1.createSetupIntentRoute; } });
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExpressJS route helpers for Paid SDK
|
|
3
|
+
* These functions create handlers compatible with ExpressJS controllers
|
|
4
|
+
*/
|
|
5
|
+
import { Request, Response } from "express";
|
|
6
|
+
import { BaseHandlerConfig } from "../../utils/base-handler.js";
|
|
7
|
+
import { OrderOptions } from "../../types.js";
|
|
8
|
+
export interface ActivateOrderSyncRouteConfig extends BaseHandlerConfig {
|
|
9
|
+
defaultReturnUrl?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create an Express handler for synchronous order activation
|
|
13
|
+
*
|
|
14
|
+
* Use this in your Express app to handle order activation with payment.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import express from 'express';
|
|
19
|
+
* import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/express';
|
|
20
|
+
*
|
|
21
|
+
* const app = express();
|
|
22
|
+
* const activateOrderSyncHandler = createActivateOrderSyncRoute();
|
|
23
|
+
*
|
|
24
|
+
* app.post('/paid/payments/activate-order-sync', activateOrderSyncHandler);
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example With NestJS
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { Controller, Post, Req, Res } from '@nestjs/common';
|
|
30
|
+
* import { Request, Response } from 'express';
|
|
31
|
+
* import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/nestjs';
|
|
32
|
+
*
|
|
33
|
+
* @Controller('paid/payments')
|
|
34
|
+
* export class PaymentsController {
|
|
35
|
+
* private activateOrderSyncHandler = createActivateOrderSyncRoute();
|
|
36
|
+
*
|
|
37
|
+
* @Post('activate-order-sync')
|
|
38
|
+
* async activateOrderSync(@Req() req: Request, @Res() res: Response) {
|
|
39
|
+
* return this.activateOrderSyncHandler(req, res);
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function createActivateOrderSyncRoute(config?: ActivateOrderSyncRouteConfig): (req: Request, res: Response) => Promise<any>;
|
|
45
|
+
/**
|
|
46
|
+
* Create an Express handler for contact creation
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import express from 'express';
|
|
51
|
+
* import { createContactsRoute } from '@paid-ai/paid-node/integrations/express';
|
|
52
|
+
*
|
|
53
|
+
* const app = express();
|
|
54
|
+
* app.post('/paid/contacts', createContactsRoute());
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function createContactsRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
|
|
58
|
+
/**
|
|
59
|
+
* Create an Express handler for fetching customer invoices
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import express from 'express';
|
|
64
|
+
* import { createCustomerInvoicesRoute } from '@paid-ai/paid-node/integrations/express';
|
|
65
|
+
*
|
|
66
|
+
* const app = express();
|
|
67
|
+
* app.get('/paid/customers/:customerExternalId/invoices', createCustomerInvoicesRoute());
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function createCustomerInvoicesRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
|
|
71
|
+
/**
|
|
72
|
+
* Create an Express handler for fetching a customer by external ID
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* import express from 'express';
|
|
77
|
+
* import { createGetCustomerRoute } from '@paid-ai/paid-node/integrations/express';
|
|
78
|
+
*
|
|
79
|
+
* const app = express();
|
|
80
|
+
* app.get('/paid/customers/:customerExternalId', createGetCustomerRoute());
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function createGetCustomerRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
|
|
84
|
+
/**
|
|
85
|
+
* Create an Express handler for customer creation
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* import express from 'express';
|
|
90
|
+
* import { createCustomersRoute } from '@paid-ai/paid-node/integrations/express';
|
|
91
|
+
*
|
|
92
|
+
* const app = express();
|
|
93
|
+
* app.post('/paid/customers', createCustomersRoute());
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare function createCustomersRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
|
|
97
|
+
export interface OrdersRouteConfig extends BaseHandlerConfig {
|
|
98
|
+
helperOptions?: OrderOptions;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Create an Express handler for order creation
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* import express from 'express';
|
|
106
|
+
* import { createOrdersRoute } from '@paid-ai/paid-node/integrations/express';
|
|
107
|
+
*
|
|
108
|
+
* const app = express();
|
|
109
|
+
* app.post('/paid/orders', createOrdersRoute({ helperOptions: { autoActivate: true } }));
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare function createOrdersRoute(config?: OrdersRouteConfig): (req: Request, res: Response) => Promise<any>;
|
|
113
|
+
/**
|
|
114
|
+
* Create an Express handler for invoice payment
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* import express from 'express';
|
|
119
|
+
* import { createPayInvoiceRoute } from '@paid-ai/paid-node/integrations/express';
|
|
120
|
+
*
|
|
121
|
+
* const app = express();
|
|
122
|
+
* app.post('/paid/invoices/:invoiceId/pay', createPayInvoiceRoute());
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare function createPayInvoiceRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
|
|
126
|
+
export interface ProvisioningRouteConfig extends BaseHandlerConfig {
|
|
127
|
+
defaultAgentExternalId?: string;
|
|
128
|
+
orderOptions?: OrderOptions;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Create an Express handler for user provisioning
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* import express from 'express';
|
|
136
|
+
* import { createProvisioningRoute } from '@paid-ai/paid-node/integrations/express';
|
|
137
|
+
*
|
|
138
|
+
* const app = express();
|
|
139
|
+
* app.post('/paid/provision', createProvisioningRoute({
|
|
140
|
+
* defaultAgentExternalId: process.env.PAID_AGENT_ID
|
|
141
|
+
* }));
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export declare function createProvisioningRoute(config?: ProvisioningRouteConfig): (req: Request, res: Response) => Promise<any>;
|
|
145
|
+
export interface SetupIntentRouteConfig extends BaseHandlerConfig {
|
|
146
|
+
defaultReturnUrl?: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Create an Express handler for setup intent creation
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* import express from 'express';
|
|
154
|
+
* import { createSetupIntentRoute } from '@paid-ai/paid-node/integrations/express';
|
|
155
|
+
*
|
|
156
|
+
* const app = express();
|
|
157
|
+
* app.post('/paid/payments/setup-intent', createSetupIntentRoute({
|
|
158
|
+
* defaultReturnUrl: process.env.APP_URL + '/billing'
|
|
159
|
+
* }));
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
export declare function createSetupIntentRoute(config?: SetupIntentRouteConfig): (req: Request, res: Response) => Promise<any>;
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ExpressJS route helpers for Paid SDK
|
|
4
|
+
* These functions create handlers compatible with ExpressJS controllers
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createActivateOrderSyncRoute = createActivateOrderSyncRoute;
|
|
8
|
+
exports.createContactsRoute = createContactsRoute;
|
|
9
|
+
exports.createCustomerInvoicesRoute = createCustomerInvoicesRoute;
|
|
10
|
+
exports.createGetCustomerRoute = createGetCustomerRoute;
|
|
11
|
+
exports.createCustomersRoute = createCustomersRoute;
|
|
12
|
+
exports.createOrdersRoute = createOrdersRoute;
|
|
13
|
+
exports.createPayInvoiceRoute = createPayInvoiceRoute;
|
|
14
|
+
exports.createProvisioningRoute = createProvisioningRoute;
|
|
15
|
+
exports.createSetupIntentRoute = createSetupIntentRoute;
|
|
16
|
+
const base_adapter_js_1 = require("./base-adapter.js");
|
|
17
|
+
const contacts_js_1 = require("../../controllers/contacts.js");
|
|
18
|
+
const invoices_js_1 = require("../../controllers/invoices.js");
|
|
19
|
+
const customers_js_1 = require("../../controllers/customers.js");
|
|
20
|
+
const orders_js_1 = require("../../controllers/orders.js");
|
|
21
|
+
const provision_users_js_1 = require("../../controllers/provision-users.js");
|
|
22
|
+
const billing_js_1 = require("../../controllers/billing.js");
|
|
23
|
+
/**
|
|
24
|
+
* Helper to extract headers from Express Request
|
|
25
|
+
*/
|
|
26
|
+
function extractHeaders(req) {
|
|
27
|
+
const headers = {};
|
|
28
|
+
Object.entries(req.headers).forEach(([key, value]) => {
|
|
29
|
+
if (typeof value === "string") {
|
|
30
|
+
headers[key] = value;
|
|
31
|
+
}
|
|
32
|
+
else if (Array.isArray(value)) {
|
|
33
|
+
headers[key] = value.join(", ");
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return headers;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create an Express handler for synchronous order activation
|
|
40
|
+
*
|
|
41
|
+
* Use this in your Express app to handle order activation with payment.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import express from 'express';
|
|
46
|
+
* import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/express';
|
|
47
|
+
*
|
|
48
|
+
* const app = express();
|
|
49
|
+
* const activateOrderSyncHandler = createActivateOrderSyncRoute();
|
|
50
|
+
*
|
|
51
|
+
* app.post('/paid/payments/activate-order-sync', activateOrderSyncHandler);
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example With NestJS
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { Controller, Post, Req, Res } from '@nestjs/common';
|
|
57
|
+
* import { Request, Response } from 'express';
|
|
58
|
+
* import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/nestjs';
|
|
59
|
+
*
|
|
60
|
+
* @Controller('paid/payments')
|
|
61
|
+
* export class PaymentsController {
|
|
62
|
+
* private activateOrderSyncHandler = createActivateOrderSyncRoute();
|
|
63
|
+
*
|
|
64
|
+
* @Post('activate-order-sync')
|
|
65
|
+
* async activateOrderSync(@Req() req: Request, @Res() res: Response) {
|
|
66
|
+
* return this.activateOrderSyncHandler(req, res);
|
|
67
|
+
* }
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
function createActivateOrderSyncRoute(config = {}) {
|
|
72
|
+
const handler = (0, billing_js_1.createActivateOrderSyncHandler)(config.defaultReturnUrl);
|
|
73
|
+
return (req, res) => {
|
|
74
|
+
return handler({
|
|
75
|
+
body: req.body,
|
|
76
|
+
headers: extractHeaders(req),
|
|
77
|
+
method: "POST",
|
|
78
|
+
params: req.params,
|
|
79
|
+
}, (0, base_adapter_js_1.createExpressJSResponseContext)(res), config);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Create an Express handler for contact creation
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* import express from 'express';
|
|
88
|
+
* import { createContactsRoute } from '@paid-ai/paid-node/integrations/express';
|
|
89
|
+
*
|
|
90
|
+
* const app = express();
|
|
91
|
+
* app.post('/paid/contacts', createContactsRoute());
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
function createContactsRoute(config = {}) {
|
|
95
|
+
const handler = (0, contacts_js_1.createContactsHandler)();
|
|
96
|
+
return (req, res) => {
|
|
97
|
+
return handler({
|
|
98
|
+
body: req.body,
|
|
99
|
+
headers: extractHeaders(req),
|
|
100
|
+
method: "POST",
|
|
101
|
+
params: req.params,
|
|
102
|
+
}, (0, base_adapter_js_1.createExpressJSResponseContext)(res), config);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Create an Express handler for fetching customer invoices
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* import express from 'express';
|
|
111
|
+
* import { createCustomerInvoicesRoute } from '@paid-ai/paid-node/integrations/express';
|
|
112
|
+
*
|
|
113
|
+
* const app = express();
|
|
114
|
+
* app.get('/paid/customers/:customerExternalId/invoices', createCustomerInvoicesRoute());
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
function createCustomerInvoicesRoute(config = {}) {
|
|
118
|
+
const handler = (0, invoices_js_1.createCustomerInvoicesHandler)();
|
|
119
|
+
return (req, res) => {
|
|
120
|
+
return handler({
|
|
121
|
+
body: req.body,
|
|
122
|
+
headers: extractHeaders(req),
|
|
123
|
+
method: "GET",
|
|
124
|
+
params: req.params,
|
|
125
|
+
}, (0, base_adapter_js_1.createExpressJSResponseContext)(res), config);
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Create an Express handler for fetching a customer by external ID
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* import express from 'express';
|
|
134
|
+
* import { createGetCustomerRoute } from '@paid-ai/paid-node/integrations/express';
|
|
135
|
+
*
|
|
136
|
+
* const app = express();
|
|
137
|
+
* app.get('/paid/customers/:customerExternalId', createGetCustomerRoute());
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
function createGetCustomerRoute(config = {}) {
|
|
141
|
+
const handler = (0, customers_js_1.createGetCustomerHandler)();
|
|
142
|
+
return (req, res) => {
|
|
143
|
+
return handler({
|
|
144
|
+
body: req.body,
|
|
145
|
+
headers: extractHeaders(req),
|
|
146
|
+
method: "GET",
|
|
147
|
+
params: req.params,
|
|
148
|
+
}, (0, base_adapter_js_1.createExpressJSResponseContext)(res), config);
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Create an Express handler for customer creation
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* import express from 'express';
|
|
157
|
+
* import { createCustomersRoute } from '@paid-ai/paid-node/integrations/express';
|
|
158
|
+
*
|
|
159
|
+
* const app = express();
|
|
160
|
+
* app.post('/paid/customers', createCustomersRoute());
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
function createCustomersRoute(config = {}) {
|
|
164
|
+
const handler = (0, customers_js_1.createCustomersHandler)();
|
|
165
|
+
return (req, res) => {
|
|
166
|
+
return handler({
|
|
167
|
+
body: req.body,
|
|
168
|
+
headers: extractHeaders(req),
|
|
169
|
+
method: "POST",
|
|
170
|
+
params: req.params,
|
|
171
|
+
}, (0, base_adapter_js_1.createExpressJSResponseContext)(res), config);
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Create an Express handler for order creation
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* import express from 'express';
|
|
180
|
+
* import { createOrdersRoute } from '@paid-ai/paid-node/integrations/express';
|
|
181
|
+
*
|
|
182
|
+
* const app = express();
|
|
183
|
+
* app.post('/paid/orders', createOrdersRoute({ helperOptions: { autoActivate: true } }));
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
function createOrdersRoute(config = {}) {
|
|
187
|
+
const handler = (0, orders_js_1.createOrdersHandler)(config.helperOptions);
|
|
188
|
+
return (req, res) => {
|
|
189
|
+
return handler({
|
|
190
|
+
body: req.body,
|
|
191
|
+
headers: extractHeaders(req),
|
|
192
|
+
method: "POST",
|
|
193
|
+
params: req.params,
|
|
194
|
+
}, (0, base_adapter_js_1.createExpressJSResponseContext)(res), config);
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Create an Express handler for invoice payment
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* import express from 'express';
|
|
203
|
+
* import { createPayInvoiceRoute } from '@paid-ai/paid-node/integrations/express';
|
|
204
|
+
*
|
|
205
|
+
* const app = express();
|
|
206
|
+
* app.post('/paid/invoices/:invoiceId/pay', createPayInvoiceRoute());
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
function createPayInvoiceRoute(config = {}) {
|
|
210
|
+
const handler = (0, billing_js_1.createPayInvoiceHandler)();
|
|
211
|
+
return (req, res) => {
|
|
212
|
+
return handler({
|
|
213
|
+
body: req.body,
|
|
214
|
+
headers: extractHeaders(req),
|
|
215
|
+
method: "POST",
|
|
216
|
+
params: req.params,
|
|
217
|
+
}, (0, base_adapter_js_1.createExpressJSResponseContext)(res), config);
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Create an Express handler for user provisioning
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```typescript
|
|
225
|
+
* import express from 'express';
|
|
226
|
+
* import { createProvisioningRoute } from '@paid-ai/paid-node/integrations/express';
|
|
227
|
+
*
|
|
228
|
+
* const app = express();
|
|
229
|
+
* app.post('/paid/provision', createProvisioningRoute({
|
|
230
|
+
* defaultAgentExternalId: process.env.PAID_AGENT_ID
|
|
231
|
+
* }));
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
function createProvisioningRoute(config = {}) {
|
|
235
|
+
const handler = (0, provision_users_js_1.createProvisioningHandler)(config.orderOptions, config.defaultAgentExternalId);
|
|
236
|
+
return (req, res) => {
|
|
237
|
+
return handler({
|
|
238
|
+
body: req.body,
|
|
239
|
+
headers: extractHeaders(req),
|
|
240
|
+
method: "POST",
|
|
241
|
+
params: req.params,
|
|
242
|
+
}, (0, base_adapter_js_1.createExpressJSResponseContext)(res), config);
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Create an Express handler for setup intent creation
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```typescript
|
|
250
|
+
* import express from 'express';
|
|
251
|
+
* import { createSetupIntentRoute } from '@paid-ai/paid-node/integrations/express';
|
|
252
|
+
*
|
|
253
|
+
* const app = express();
|
|
254
|
+
* app.post('/paid/payments/setup-intent', createSetupIntentRoute({
|
|
255
|
+
* defaultReturnUrl: process.env.APP_URL + '/billing'
|
|
256
|
+
* }));
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
function createSetupIntentRoute(config = {}) {
|
|
260
|
+
const handler = (0, billing_js_1.createSetupIntentHandler)(config.defaultReturnUrl);
|
|
261
|
+
return (req, res) => {
|
|
262
|
+
return handler({
|
|
263
|
+
body: req.body,
|
|
264
|
+
headers: extractHeaders(req),
|
|
265
|
+
method: "POST",
|
|
266
|
+
params: req.params,
|
|
267
|
+
}, (0, base_adapter_js_1.createExpressJSResponseContext)(res), config);
|
|
268
|
+
};
|
|
269
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* NestJS integration for Paid SDK
|
|
4
|
+
*
|
|
5
|
+
* NestJS uses Express under the hood, so this is a re-export of the Express adapter.
|
|
6
|
+
* All functionality is identical to the Express adapter.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("../expressjs/index.js"), exports);
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.5.0-
|
|
1
|
+
export declare const SDK_VERSION = "0.5.0-alpha3";
|
package/dist/cjs/version.js
CHANGED
package/dist/esm/Client.mjs
CHANGED
|
@@ -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.5.0-
|
|
28
|
-
"User-Agent": "@paid-ai/paid-node/0.5.0-
|
|
27
|
+
"X-Fern-SDK-Version": "0.5.0-alpha3",
|
|
28
|
+
"User-Agent": "@paid-ai/paid-node/0.5.0-alpha3",
|
|
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) });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExpressJS adapter for Paid SDK
|
|
3
|
+
* Converts Express Request/Response to framework-agnostic format
|
|
4
|
+
*/
|
|
5
|
+
import { Request, Response } from "express";
|
|
6
|
+
/**
|
|
7
|
+
* Handles Express Request/Response conversion to base handler format
|
|
8
|
+
*/
|
|
9
|
+
export declare const expressjsAdapter: (innerHandler: Function) => (req: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, context?: any, config?: any) => Promise<any>;
|
|
10
|
+
/**
|
|
11
|
+
* Create response context for ExpressJS
|
|
12
|
+
* This converts the base handler response methods to ExpressJS/Express format
|
|
13
|
+
*/
|
|
14
|
+
export declare function createExpressJSResponseContext(res: Response): {
|
|
15
|
+
json: (data: any, status?: number) => Response<any, Record<string, any>>;
|
|
16
|
+
error: (message: string, status: number) => Response<any, Record<string, any>>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExpressJS adapter for Paid SDK
|
|
3
|
+
* Converts Express Request/Response 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 { createFrameworkAdapter } from "../../utils/create-adapter.mjs";
|
|
15
|
+
/**
|
|
16
|
+
* Handles Express Request/Response conversion to base handler format
|
|
17
|
+
*/
|
|
18
|
+
export const expressjsAdapter = createFrameworkAdapter({
|
|
19
|
+
getBody: (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
return req.body || {};
|
|
21
|
+
}),
|
|
22
|
+
getHeaders: (req) => {
|
|
23
|
+
const headers = {};
|
|
24
|
+
Object.entries(req.headers).forEach(([key, value]) => {
|
|
25
|
+
if (typeof value === "string") {
|
|
26
|
+
headers[key] = value;
|
|
27
|
+
}
|
|
28
|
+
else if (Array.isArray(value)) {
|
|
29
|
+
headers[key] = value.join(", ");
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return headers;
|
|
33
|
+
},
|
|
34
|
+
getMethod: (req) => req.method || "GET",
|
|
35
|
+
getParams: (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
return req.params || {};
|
|
37
|
+
}),
|
|
38
|
+
getQuery: (req) => {
|
|
39
|
+
const query = {};
|
|
40
|
+
Object.entries(req.query).forEach(([key, value]) => {
|
|
41
|
+
if (typeof value === "string") {
|
|
42
|
+
query[key] = value;
|
|
43
|
+
}
|
|
44
|
+
else if (Array.isArray(value)) {
|
|
45
|
+
query[key] = value.join(", ");
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return query;
|
|
49
|
+
},
|
|
50
|
+
sendJson: (data, status) => {
|
|
51
|
+
throw new Error("ExpressJS adapter requires using response context from handler");
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Create response context for ExpressJS
|
|
56
|
+
* This converts the base handler response methods to ExpressJS/Express format
|
|
57
|
+
*/
|
|
58
|
+
export function createExpressJSResponseContext(res) {
|
|
59
|
+
return {
|
|
60
|
+
json: (data, status = 200) => {
|
|
61
|
+
return res.status(status).json(data);
|
|
62
|
+
},
|
|
63
|
+
error: (message, status) => {
|
|
64
|
+
return res.status(status).json({ error: message });
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExpressJS integration for Paid SDK
|
|
3
|
+
* Drop-in handlers for ExpressJS controllers using Express Request/Response
|
|
4
|
+
*/
|
|
5
|
+
export { expressjsAdapter, createExpressJSResponseContext } from "./base-adapter.mjs";
|
|
6
|
+
export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createGetCustomerRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, type ActivateOrderSyncRouteConfig, type OrdersRouteConfig, type ProvisioningRouteConfig, type SetupIntentRouteConfig, } from "./routes.mjs";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExpressJS integration for Paid SDK
|
|
3
|
+
* Drop-in handlers for ExpressJS controllers using Express Request/Response
|
|
4
|
+
*/
|
|
5
|
+
export { expressjsAdapter, createExpressJSResponseContext } from "./base-adapter.mjs";
|
|
6
|
+
export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createGetCustomerRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, } from "./routes.mjs";
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExpressJS route helpers for Paid SDK
|
|
3
|
+
* These functions create handlers compatible with ExpressJS controllers
|
|
4
|
+
*/
|
|
5
|
+
import { Request, Response } from "express";
|
|
6
|
+
import { BaseHandlerConfig } from "../../utils/base-handler.mjs";
|
|
7
|
+
import { OrderOptions } from "../../types.mjs";
|
|
8
|
+
export interface ActivateOrderSyncRouteConfig extends BaseHandlerConfig {
|
|
9
|
+
defaultReturnUrl?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create an Express handler for synchronous order activation
|
|
13
|
+
*
|
|
14
|
+
* Use this in your Express app to handle order activation with payment.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import express from 'express';
|
|
19
|
+
* import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/express';
|
|
20
|
+
*
|
|
21
|
+
* const app = express();
|
|
22
|
+
* const activateOrderSyncHandler = createActivateOrderSyncRoute();
|
|
23
|
+
*
|
|
24
|
+
* app.post('/paid/payments/activate-order-sync', activateOrderSyncHandler);
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example With NestJS
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { Controller, Post, Req, Res } from '@nestjs/common';
|
|
30
|
+
* import { Request, Response } from 'express';
|
|
31
|
+
* import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/nestjs';
|
|
32
|
+
*
|
|
33
|
+
* @Controller('paid/payments')
|
|
34
|
+
* export class PaymentsController {
|
|
35
|
+
* private activateOrderSyncHandler = createActivateOrderSyncRoute();
|
|
36
|
+
*
|
|
37
|
+
* @Post('activate-order-sync')
|
|
38
|
+
* async activateOrderSync(@Req() req: Request, @Res() res: Response) {
|
|
39
|
+
* return this.activateOrderSyncHandler(req, res);
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function createActivateOrderSyncRoute(config?: ActivateOrderSyncRouteConfig): (req: Request, res: Response) => Promise<any>;
|
|
45
|
+
/**
|
|
46
|
+
* Create an Express handler for contact creation
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import express from 'express';
|
|
51
|
+
* import { createContactsRoute } from '@paid-ai/paid-node/integrations/express';
|
|
52
|
+
*
|
|
53
|
+
* const app = express();
|
|
54
|
+
* app.post('/paid/contacts', createContactsRoute());
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function createContactsRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
|
|
58
|
+
/**
|
|
59
|
+
* Create an Express handler for fetching customer invoices
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import express from 'express';
|
|
64
|
+
* import { createCustomerInvoicesRoute } from '@paid-ai/paid-node/integrations/express';
|
|
65
|
+
*
|
|
66
|
+
* const app = express();
|
|
67
|
+
* app.get('/paid/customers/:customerExternalId/invoices', createCustomerInvoicesRoute());
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function createCustomerInvoicesRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
|
|
71
|
+
/**
|
|
72
|
+
* Create an Express handler for fetching a customer by external ID
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* import express from 'express';
|
|
77
|
+
* import { createGetCustomerRoute } from '@paid-ai/paid-node/integrations/express';
|
|
78
|
+
*
|
|
79
|
+
* const app = express();
|
|
80
|
+
* app.get('/paid/customers/:customerExternalId', createGetCustomerRoute());
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function createGetCustomerRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
|
|
84
|
+
/**
|
|
85
|
+
* Create an Express handler for customer creation
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* import express from 'express';
|
|
90
|
+
* import { createCustomersRoute } from '@paid-ai/paid-node/integrations/express';
|
|
91
|
+
*
|
|
92
|
+
* const app = express();
|
|
93
|
+
* app.post('/paid/customers', createCustomersRoute());
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare function createCustomersRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
|
|
97
|
+
export interface OrdersRouteConfig extends BaseHandlerConfig {
|
|
98
|
+
helperOptions?: OrderOptions;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Create an Express handler for order creation
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* import express from 'express';
|
|
106
|
+
* import { createOrdersRoute } from '@paid-ai/paid-node/integrations/express';
|
|
107
|
+
*
|
|
108
|
+
* const app = express();
|
|
109
|
+
* app.post('/paid/orders', createOrdersRoute({ helperOptions: { autoActivate: true } }));
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare function createOrdersRoute(config?: OrdersRouteConfig): (req: Request, res: Response) => Promise<any>;
|
|
113
|
+
/**
|
|
114
|
+
* Create an Express handler for invoice payment
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* import express from 'express';
|
|
119
|
+
* import { createPayInvoiceRoute } from '@paid-ai/paid-node/integrations/express';
|
|
120
|
+
*
|
|
121
|
+
* const app = express();
|
|
122
|
+
* app.post('/paid/invoices/:invoiceId/pay', createPayInvoiceRoute());
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare function createPayInvoiceRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
|
|
126
|
+
export interface ProvisioningRouteConfig extends BaseHandlerConfig {
|
|
127
|
+
defaultAgentExternalId?: string;
|
|
128
|
+
orderOptions?: OrderOptions;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Create an Express handler for user provisioning
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* import express from 'express';
|
|
136
|
+
* import { createProvisioningRoute } from '@paid-ai/paid-node/integrations/express';
|
|
137
|
+
*
|
|
138
|
+
* const app = express();
|
|
139
|
+
* app.post('/paid/provision', createProvisioningRoute({
|
|
140
|
+
* defaultAgentExternalId: process.env.PAID_AGENT_ID
|
|
141
|
+
* }));
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export declare function createProvisioningRoute(config?: ProvisioningRouteConfig): (req: Request, res: Response) => Promise<any>;
|
|
145
|
+
export interface SetupIntentRouteConfig extends BaseHandlerConfig {
|
|
146
|
+
defaultReturnUrl?: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Create an Express handler for setup intent creation
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* import express from 'express';
|
|
154
|
+
* import { createSetupIntentRoute } from '@paid-ai/paid-node/integrations/express';
|
|
155
|
+
*
|
|
156
|
+
* const app = express();
|
|
157
|
+
* app.post('/paid/payments/setup-intent', createSetupIntentRoute({
|
|
158
|
+
* defaultReturnUrl: process.env.APP_URL + '/billing'
|
|
159
|
+
* }));
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
export declare function createSetupIntentRoute(config?: SetupIntentRouteConfig): (req: Request, res: Response) => Promise<any>;
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExpressJS route helpers for Paid SDK
|
|
3
|
+
* These functions create handlers compatible with ExpressJS controllers
|
|
4
|
+
*/
|
|
5
|
+
import { createExpressJSResponseContext } from "./base-adapter.mjs";
|
|
6
|
+
import { createContactsHandler } from "../../controllers/contacts.mjs";
|
|
7
|
+
import { createCustomerInvoicesHandler } from "../../controllers/invoices.mjs";
|
|
8
|
+
import { createCustomersHandler, createGetCustomerHandler } from "../../controllers/customers.mjs";
|
|
9
|
+
import { createOrdersHandler } from "../../controllers/orders.mjs";
|
|
10
|
+
import { createProvisioningHandler } from "../../controllers/provision-users.mjs";
|
|
11
|
+
import { createActivateOrderSyncHandler, createPayInvoiceHandler, createSetupIntentHandler, } from "../../controllers/billing.mjs";
|
|
12
|
+
/**
|
|
13
|
+
* Helper to extract headers from Express Request
|
|
14
|
+
*/
|
|
15
|
+
function extractHeaders(req) {
|
|
16
|
+
const headers = {};
|
|
17
|
+
Object.entries(req.headers).forEach(([key, value]) => {
|
|
18
|
+
if (typeof value === "string") {
|
|
19
|
+
headers[key] = value;
|
|
20
|
+
}
|
|
21
|
+
else if (Array.isArray(value)) {
|
|
22
|
+
headers[key] = value.join(", ");
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return headers;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create an Express handler for synchronous order activation
|
|
29
|
+
*
|
|
30
|
+
* Use this in your Express app to handle order activation with payment.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import express from 'express';
|
|
35
|
+
* import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/express';
|
|
36
|
+
*
|
|
37
|
+
* const app = express();
|
|
38
|
+
* const activateOrderSyncHandler = createActivateOrderSyncRoute();
|
|
39
|
+
*
|
|
40
|
+
* app.post('/paid/payments/activate-order-sync', activateOrderSyncHandler);
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example With NestJS
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { Controller, Post, Req, Res } from '@nestjs/common';
|
|
46
|
+
* import { Request, Response } from 'express';
|
|
47
|
+
* import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/nestjs';
|
|
48
|
+
*
|
|
49
|
+
* @Controller('paid/payments')
|
|
50
|
+
* export class PaymentsController {
|
|
51
|
+
* private activateOrderSyncHandler = createActivateOrderSyncRoute();
|
|
52
|
+
*
|
|
53
|
+
* @Post('activate-order-sync')
|
|
54
|
+
* async activateOrderSync(@Req() req: Request, @Res() res: Response) {
|
|
55
|
+
* return this.activateOrderSyncHandler(req, res);
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export function createActivateOrderSyncRoute(config = {}) {
|
|
61
|
+
const handler = createActivateOrderSyncHandler(config.defaultReturnUrl);
|
|
62
|
+
return (req, res) => {
|
|
63
|
+
return handler({
|
|
64
|
+
body: req.body,
|
|
65
|
+
headers: extractHeaders(req),
|
|
66
|
+
method: "POST",
|
|
67
|
+
params: req.params,
|
|
68
|
+
}, createExpressJSResponseContext(res), config);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create an Express handler for contact creation
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* import express from 'express';
|
|
77
|
+
* import { createContactsRoute } from '@paid-ai/paid-node/integrations/express';
|
|
78
|
+
*
|
|
79
|
+
* const app = express();
|
|
80
|
+
* app.post('/paid/contacts', createContactsRoute());
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export function createContactsRoute(config = {}) {
|
|
84
|
+
const handler = createContactsHandler();
|
|
85
|
+
return (req, res) => {
|
|
86
|
+
return handler({
|
|
87
|
+
body: req.body,
|
|
88
|
+
headers: extractHeaders(req),
|
|
89
|
+
method: "POST",
|
|
90
|
+
params: req.params,
|
|
91
|
+
}, createExpressJSResponseContext(res), config);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create an Express handler for fetching customer invoices
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* import express from 'express';
|
|
100
|
+
* import { createCustomerInvoicesRoute } from '@paid-ai/paid-node/integrations/express';
|
|
101
|
+
*
|
|
102
|
+
* const app = express();
|
|
103
|
+
* app.get('/paid/customers/:customerExternalId/invoices', createCustomerInvoicesRoute());
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export function createCustomerInvoicesRoute(config = {}) {
|
|
107
|
+
const handler = createCustomerInvoicesHandler();
|
|
108
|
+
return (req, res) => {
|
|
109
|
+
return handler({
|
|
110
|
+
body: req.body,
|
|
111
|
+
headers: extractHeaders(req),
|
|
112
|
+
method: "GET",
|
|
113
|
+
params: req.params,
|
|
114
|
+
}, createExpressJSResponseContext(res), config);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Create an Express handler for fetching a customer by external ID
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* import express from 'express';
|
|
123
|
+
* import { createGetCustomerRoute } from '@paid-ai/paid-node/integrations/express';
|
|
124
|
+
*
|
|
125
|
+
* const app = express();
|
|
126
|
+
* app.get('/paid/customers/:customerExternalId', createGetCustomerRoute());
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export function createGetCustomerRoute(config = {}) {
|
|
130
|
+
const handler = createGetCustomerHandler();
|
|
131
|
+
return (req, res) => {
|
|
132
|
+
return handler({
|
|
133
|
+
body: req.body,
|
|
134
|
+
headers: extractHeaders(req),
|
|
135
|
+
method: "GET",
|
|
136
|
+
params: req.params,
|
|
137
|
+
}, createExpressJSResponseContext(res), config);
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Create an Express handler for customer creation
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* import express from 'express';
|
|
146
|
+
* import { createCustomersRoute } from '@paid-ai/paid-node/integrations/express';
|
|
147
|
+
*
|
|
148
|
+
* const app = express();
|
|
149
|
+
* app.post('/paid/customers', createCustomersRoute());
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export function createCustomersRoute(config = {}) {
|
|
153
|
+
const handler = createCustomersHandler();
|
|
154
|
+
return (req, res) => {
|
|
155
|
+
return handler({
|
|
156
|
+
body: req.body,
|
|
157
|
+
headers: extractHeaders(req),
|
|
158
|
+
method: "POST",
|
|
159
|
+
params: req.params,
|
|
160
|
+
}, createExpressJSResponseContext(res), config);
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Create an Express handler for order creation
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* import express from 'express';
|
|
169
|
+
* import { createOrdersRoute } from '@paid-ai/paid-node/integrations/express';
|
|
170
|
+
*
|
|
171
|
+
* const app = express();
|
|
172
|
+
* app.post('/paid/orders', createOrdersRoute({ helperOptions: { autoActivate: true } }));
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
export function createOrdersRoute(config = {}) {
|
|
176
|
+
const handler = createOrdersHandler(config.helperOptions);
|
|
177
|
+
return (req, res) => {
|
|
178
|
+
return handler({
|
|
179
|
+
body: req.body,
|
|
180
|
+
headers: extractHeaders(req),
|
|
181
|
+
method: "POST",
|
|
182
|
+
params: req.params,
|
|
183
|
+
}, createExpressJSResponseContext(res), config);
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Create an Express handler for invoice payment
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* import express from 'express';
|
|
192
|
+
* import { createPayInvoiceRoute } from '@paid-ai/paid-node/integrations/express';
|
|
193
|
+
*
|
|
194
|
+
* const app = express();
|
|
195
|
+
* app.post('/paid/invoices/:invoiceId/pay', createPayInvoiceRoute());
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export function createPayInvoiceRoute(config = {}) {
|
|
199
|
+
const handler = createPayInvoiceHandler();
|
|
200
|
+
return (req, res) => {
|
|
201
|
+
return handler({
|
|
202
|
+
body: req.body,
|
|
203
|
+
headers: extractHeaders(req),
|
|
204
|
+
method: "POST",
|
|
205
|
+
params: req.params,
|
|
206
|
+
}, createExpressJSResponseContext(res), config);
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Create an Express handler for user provisioning
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* import express from 'express';
|
|
215
|
+
* import { createProvisioningRoute } from '@paid-ai/paid-node/integrations/express';
|
|
216
|
+
*
|
|
217
|
+
* const app = express();
|
|
218
|
+
* app.post('/paid/provision', createProvisioningRoute({
|
|
219
|
+
* defaultAgentExternalId: process.env.PAID_AGENT_ID
|
|
220
|
+
* }));
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
export function createProvisioningRoute(config = {}) {
|
|
224
|
+
const handler = createProvisioningHandler(config.orderOptions, config.defaultAgentExternalId);
|
|
225
|
+
return (req, res) => {
|
|
226
|
+
return handler({
|
|
227
|
+
body: req.body,
|
|
228
|
+
headers: extractHeaders(req),
|
|
229
|
+
method: "POST",
|
|
230
|
+
params: req.params,
|
|
231
|
+
}, createExpressJSResponseContext(res), config);
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Create an Express handler for setup intent creation
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* import express from 'express';
|
|
240
|
+
* import { createSetupIntentRoute } from '@paid-ai/paid-node/integrations/express';
|
|
241
|
+
*
|
|
242
|
+
* const app = express();
|
|
243
|
+
* app.post('/paid/payments/setup-intent', createSetupIntentRoute({
|
|
244
|
+
* defaultReturnUrl: process.env.APP_URL + '/billing'
|
|
245
|
+
* }));
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
export function createSetupIntentRoute(config = {}) {
|
|
249
|
+
const handler = createSetupIntentHandler(config.defaultReturnUrl);
|
|
250
|
+
return (req, res) => {
|
|
251
|
+
return handler({
|
|
252
|
+
body: req.body,
|
|
253
|
+
headers: extractHeaders(req),
|
|
254
|
+
method: "POST",
|
|
255
|
+
params: req.params,
|
|
256
|
+
}, createExpressJSResponseContext(res), config);
|
|
257
|
+
};
|
|
258
|
+
}
|
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",
|