@paid-ai/paid-node 1.0.1-alpha0 → 1.0.1-alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Client.js +2 -2
- package/dist/cjs/api/resources/plans/client/Client.d.ts +12 -0
- package/dist/cjs/api/resources/plans/client/Client.js +62 -2
- package/dist/cjs/api/resources/usage/client/Client.d.ts +3 -3
- package/dist/cjs/api/resources/usage/client/Client.js +3 -3
- package/dist/cjs/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.ts +3 -3
- package/dist/cjs/api/types/PlanWithFeatures.d.ts +34 -0
- package/dist/cjs/api/types/PlanWithFeatures.js +3 -0
- package/dist/cjs/api/types/SignalV2.d.ts +5 -5
- package/dist/cjs/api/types/index.d.ts +1 -0
- package/dist/cjs/api/types/index.js +1 -0
- package/dist/cjs/integrations/adapters/expressjs/index.d.ts +2 -2
- package/dist/cjs/integrations/adapters/expressjs/index.js +2 -1
- package/dist/cjs/integrations/adapters/expressjs/routes.d.ts +16 -0
- package/dist/cjs/integrations/adapters/expressjs/routes.js +28 -0
- package/dist/cjs/integrations/adapters/nextjs/index.d.ts +1 -1
- package/dist/cjs/integrations/adapters/nextjs/index.js +2 -1
- package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +15 -0
- package/dist/cjs/integrations/adapters/nextjs/routes.js +21 -0
- package/dist/cjs/integrations/controllers/index.d.ts +1 -0
- package/dist/cjs/integrations/controllers/index.js +3 -1
- package/dist/cjs/integrations/controllers/orders.js +52 -17
- package/dist/cjs/integrations/controllers/plans.d.ts +50 -0
- package/dist/cjs/integrations/controllers/plans.js +88 -0
- package/dist/cjs/integrations/types.d.ts +5 -2
- 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/api/resources/plans/client/Client.d.mts +12 -0
- package/dist/esm/api/resources/plans/client/Client.mjs +62 -2
- package/dist/esm/api/resources/usage/client/Client.d.mts +3 -3
- package/dist/esm/api/resources/usage/client/Client.mjs +3 -3
- package/dist/esm/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.mts +3 -3
- package/dist/esm/api/types/PlanWithFeatures.d.mts +34 -0
- package/dist/esm/api/types/PlanWithFeatures.mjs +2 -0
- package/dist/esm/api/types/SignalV2.d.mts +5 -5
- package/dist/esm/api/types/index.d.mts +1 -0
- package/dist/esm/api/types/index.mjs +1 -0
- package/dist/esm/integrations/adapters/expressjs/index.d.mts +2 -2
- package/dist/esm/integrations/adapters/expressjs/index.mjs +2 -2
- package/dist/esm/integrations/adapters/expressjs/routes.d.mts +16 -0
- package/dist/esm/integrations/adapters/expressjs/routes.mjs +27 -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 +15 -0
- package/dist/esm/integrations/adapters/nextjs/routes.mjs +20 -0
- package/dist/esm/integrations/controllers/index.d.mts +1 -0
- package/dist/esm/integrations/controllers/index.mjs +1 -0
- package/dist/esm/integrations/controllers/orders.mjs +52 -17
- package/dist/esm/integrations/controllers/plans.d.mts +50 -0
- package/dist/esm/integrations/controllers/plans.mjs +84 -0
- package/dist/esm/integrations/types.d.mts +5 -2
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +36 -2
- package/reference.md +52 -3
package/dist/cjs/Client.js
CHANGED
|
@@ -50,8 +50,8 @@ class PaidClient {
|
|
|
50
50
|
this._options = Object.assign(Object.assign({}, _options), { headers: (0, headers_js_1.mergeHeaders)({
|
|
51
51
|
"X-Fern-Language": "JavaScript",
|
|
52
52
|
"X-Fern-SDK-Name": "@paid-ai/paid-node",
|
|
53
|
-
"X-Fern-SDK-Version": "1.0.1-
|
|
54
|
-
"User-Agent": "@paid-ai/paid-node/1.0.1-
|
|
53
|
+
"X-Fern-SDK-Version": "1.0.1-alpha1",
|
|
54
|
+
"User-Agent": "@paid-ai/paid-node/1.0.1-alpha1",
|
|
55
55
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
56
56
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
57
57
|
}, _options === null || _options === void 0 ? void 0 : _options.headers) });
|
|
@@ -54,5 +54,17 @@ export declare class Plans {
|
|
|
54
54
|
*/
|
|
55
55
|
getGroupById(planGroupId: string, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.PlanGroup>;
|
|
56
56
|
private __getGroupById;
|
|
57
|
+
/**
|
|
58
|
+
* @param {string} planGroupId - The ID of the plan group
|
|
59
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
60
|
+
*
|
|
61
|
+
* @throws {@link Paid.ForbiddenError}
|
|
62
|
+
* @throws {@link Paid.NotFoundError}
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* await client.plans.getGroupPlans("planGroupId")
|
|
66
|
+
*/
|
|
67
|
+
getGroupPlans(planGroupId: string, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.PlanWithFeatures[]>;
|
|
68
|
+
private __getGroupPlans;
|
|
57
69
|
protected _getAuthorizationHeader(): Promise<string | undefined>;
|
|
58
70
|
}
|
|
@@ -216,7 +216,7 @@ class Plans {
|
|
|
216
216
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
217
217
|
const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
218
218
|
const _response = yield core.fetcher({
|
|
219
|
-
url: core.url.join((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.PaidEnvironment.Production, `plans/
|
|
219
|
+
url: core.url.join((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.PaidEnvironment.Production, `plans/planGroup/${core.url.encodePathParam(planGroupId)}`),
|
|
220
220
|
method: "GET",
|
|
221
221
|
headers: _headers,
|
|
222
222
|
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
|
|
@@ -249,7 +249,67 @@ class Plans {
|
|
|
249
249
|
rawResponse: _response.rawResponse,
|
|
250
250
|
});
|
|
251
251
|
case "timeout":
|
|
252
|
-
throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /plans/
|
|
252
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /plans/planGroup/{planGroupId}.");
|
|
253
|
+
case "unknown":
|
|
254
|
+
throw new errors.PaidError({
|
|
255
|
+
message: _response.error.errorMessage,
|
|
256
|
+
rawResponse: _response.rawResponse,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* @param {string} planGroupId - The ID of the plan group
|
|
263
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
264
|
+
*
|
|
265
|
+
* @throws {@link Paid.ForbiddenError}
|
|
266
|
+
* @throws {@link Paid.NotFoundError}
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* await client.plans.getGroupPlans("planGroupId")
|
|
270
|
+
*/
|
|
271
|
+
getGroupPlans(planGroupId, requestOptions) {
|
|
272
|
+
return core.HttpResponsePromise.fromPromise(this.__getGroupPlans(planGroupId, requestOptions));
|
|
273
|
+
}
|
|
274
|
+
__getGroupPlans(planGroupId, requestOptions) {
|
|
275
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
276
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
277
|
+
const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
278
|
+
const _response = yield core.fetcher({
|
|
279
|
+
url: core.url.join((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.PaidEnvironment.Production, `plans/planGroup/${core.url.encodePathParam(planGroupId)}/plans`),
|
|
280
|
+
method: "GET",
|
|
281
|
+
headers: _headers,
|
|
282
|
+
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
|
|
283
|
+
timeoutMs: ((_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.timeoutInSeconds) !== null && _f !== void 0 ? _f : 60) * 1000,
|
|
284
|
+
maxRetries: (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.maxRetries,
|
|
285
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
286
|
+
});
|
|
287
|
+
if (_response.ok) {
|
|
288
|
+
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
289
|
+
}
|
|
290
|
+
if (_response.error.reason === "status-code") {
|
|
291
|
+
switch (_response.error.statusCode) {
|
|
292
|
+
case 403:
|
|
293
|
+
throw new Paid.ForbiddenError(_response.error.body, _response.rawResponse);
|
|
294
|
+
case 404:
|
|
295
|
+
throw new Paid.NotFoundError(_response.error.body, _response.rawResponse);
|
|
296
|
+
default:
|
|
297
|
+
throw new errors.PaidError({
|
|
298
|
+
statusCode: _response.error.statusCode,
|
|
299
|
+
body: _response.error.body,
|
|
300
|
+
rawResponse: _response.rawResponse,
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
switch (_response.error.reason) {
|
|
305
|
+
case "non-json":
|
|
306
|
+
throw new errors.PaidError({
|
|
307
|
+
statusCode: _response.error.statusCode,
|
|
308
|
+
body: _response.error.rawBody,
|
|
309
|
+
rawResponse: _response.rawResponse,
|
|
310
|
+
});
|
|
311
|
+
case "timeout":
|
|
312
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /plans/planGroup/{planGroupId}/plans.");
|
|
253
313
|
case "unknown":
|
|
254
314
|
throw new errors.PaidError({
|
|
255
315
|
message: _response.error.errorMessage,
|
|
@@ -33,15 +33,15 @@ export declare class Usage {
|
|
|
33
33
|
* await client.usage.usageRecordBulkV2({
|
|
34
34
|
* signals: [{
|
|
35
35
|
* event_name: "emails_sent",
|
|
36
|
-
* product_id: "
|
|
37
|
-
* customer_id: "
|
|
36
|
+
* product_id: "prod_abc123def",
|
|
37
|
+
* customer_id: "cus_xyz789ghi"
|
|
38
38
|
* }, {
|
|
39
39
|
* event_name: "emails_sent",
|
|
40
40
|
* external_product_id: "acme-product",
|
|
41
41
|
* external_customer_id: "acme-inc"
|
|
42
42
|
* }, {
|
|
43
43
|
* event_name: "meeting_booked",
|
|
44
|
-
* product_id: "
|
|
44
|
+
* product_id: "prod_abc123def",
|
|
45
45
|
* external_customer_id: "acme-inc",
|
|
46
46
|
* data: {
|
|
47
47
|
* "meeting_duration": 30,
|
|
@@ -120,15 +120,15 @@ class Usage {
|
|
|
120
120
|
* await client.usage.usageRecordBulkV2({
|
|
121
121
|
* signals: [{
|
|
122
122
|
* event_name: "emails_sent",
|
|
123
|
-
* product_id: "
|
|
124
|
-
* customer_id: "
|
|
123
|
+
* product_id: "prod_abc123def",
|
|
124
|
+
* customer_id: "cus_xyz789ghi"
|
|
125
125
|
* }, {
|
|
126
126
|
* event_name: "emails_sent",
|
|
127
127
|
* external_product_id: "acme-product",
|
|
128
128
|
* external_customer_id: "acme-inc"
|
|
129
129
|
* }, {
|
|
130
130
|
* event_name: "meeting_booked",
|
|
131
|
-
* product_id: "
|
|
131
|
+
* product_id: "prod_abc123def",
|
|
132
132
|
* external_customer_id: "acme-inc",
|
|
133
133
|
* data: {
|
|
134
134
|
* "meeting_duration": 30,
|
|
@@ -4,15 +4,15 @@ import type * as Paid from "../../../../index.js";
|
|
|
4
4
|
* {
|
|
5
5
|
* signals: [{
|
|
6
6
|
* event_name: "emails_sent",
|
|
7
|
-
* product_id: "
|
|
8
|
-
* customer_id: "
|
|
7
|
+
* product_id: "prod_abc123def",
|
|
8
|
+
* customer_id: "cus_xyz789ghi"
|
|
9
9
|
* }, {
|
|
10
10
|
* event_name: "emails_sent",
|
|
11
11
|
* external_product_id: "acme-product",
|
|
12
12
|
* external_customer_id: "acme-inc"
|
|
13
13
|
* }, {
|
|
14
14
|
* event_name: "meeting_booked",
|
|
15
|
-
* product_id: "
|
|
15
|
+
* product_id: "prod_abc123def",
|
|
16
16
|
* external_customer_id: "acme-inc",
|
|
17
17
|
* data: {
|
|
18
18
|
* "meeting_duration": 30,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A plan with its features (product-attribute pairs) for display
|
|
3
|
+
*/
|
|
4
|
+
export interface PlanWithFeatures {
|
|
5
|
+
/** The unique identifier of the plan */
|
|
6
|
+
id: string;
|
|
7
|
+
/** The name of the plan */
|
|
8
|
+
name: string;
|
|
9
|
+
/** The description of the plan */
|
|
10
|
+
description?: string;
|
|
11
|
+
/** When the plan was created */
|
|
12
|
+
createdAt: string;
|
|
13
|
+
/** When the plan was last updated */
|
|
14
|
+
updatedAt: string;
|
|
15
|
+
/** The ID of the next plan in the sequence */
|
|
16
|
+
nextPlanId?: string;
|
|
17
|
+
/** The ID of the previous plan in the sequence */
|
|
18
|
+
prevPlanId?: string;
|
|
19
|
+
/** The features (product-attribute pairs) included in this plan */
|
|
20
|
+
features: PlanWithFeatures.Features.Item[];
|
|
21
|
+
}
|
|
22
|
+
export declare namespace PlanWithFeatures {
|
|
23
|
+
type Features = Features.Item[];
|
|
24
|
+
namespace Features {
|
|
25
|
+
interface Item {
|
|
26
|
+
/** The name of the product */
|
|
27
|
+
productName: string;
|
|
28
|
+
/** The name of the product attribute */
|
|
29
|
+
attributeName: string;
|
|
30
|
+
/** The pricing configuration for this feature */
|
|
31
|
+
pricing: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* V2 signal schema with clean field names.
|
|
2
|
+
* V2 signal schema with clean field names. IMPORTANT: Exactly one customer ID field (customer_id OR external_customer_id) and exactly one product ID field (product_id OR external_product_id) must be provided per signal.
|
|
3
3
|
*/
|
|
4
4
|
export interface SignalV2 {
|
|
5
5
|
/** The name of the event being tracked */
|
|
6
6
|
event_name: string;
|
|
7
|
-
/** Paid's
|
|
7
|
+
/** Paid's display ID for the product (e.g., prod_abc123). Cannot be used with external_product_id. Either this or external_product_id is required. */
|
|
8
8
|
product_id?: string;
|
|
9
|
-
/** Your system's product ID.
|
|
9
|
+
/** Your system's product ID. Cannot be used with product_id. Either this or product_id is required. */
|
|
10
10
|
external_product_id?: string;
|
|
11
|
-
/** Paid's
|
|
11
|
+
/** Paid's display ID for the customer (e.g., cus_xyz789). Cannot be used with external_customer_id. Either this or external_customer_id is required. */
|
|
12
12
|
customer_id?: string;
|
|
13
|
-
/** Your system's customer ID.
|
|
13
|
+
/** Your system's customer ID. Cannot be used with customer_id. Either this or customer_id is required. */
|
|
14
14
|
external_customer_id?: string;
|
|
15
15
|
/** Optional additional data/metadata for the signal */
|
|
16
16
|
data?: Record<string, unknown>;
|
|
@@ -30,6 +30,7 @@ export * from "./PaginationMeta.js";
|
|
|
30
30
|
export * from "./PaymentMethod.js";
|
|
31
31
|
export * from "./Plan.js";
|
|
32
32
|
export * from "./PlanGroup.js";
|
|
33
|
+
export * from "./PlanWithFeatures.js";
|
|
33
34
|
export * from "./PricePoint.js";
|
|
34
35
|
export * from "./Pricing.js";
|
|
35
36
|
export * from "./PricingModelType.js";
|
|
@@ -46,6 +46,7 @@ __exportStar(require("./PaginationMeta.js"), exports);
|
|
|
46
46
|
__exportStar(require("./PaymentMethod.js"), exports);
|
|
47
47
|
__exportStar(require("./Plan.js"), exports);
|
|
48
48
|
__exportStar(require("./PlanGroup.js"), exports);
|
|
49
|
+
__exportStar(require("./PlanWithFeatures.js"), exports);
|
|
49
50
|
__exportStar(require("./PricePoint.js"), exports);
|
|
50
51
|
__exportStar(require("./Pricing.js"), exports);
|
|
51
52
|
__exportStar(require("./PricingModelType.js"), exports);
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* ExpressJS integration for Paid SDK
|
|
3
3
|
* Drop-in handlers for ExpressJS controllers using Express Request/Response
|
|
4
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";
|
|
5
|
+
export { expressjsAdapter, createExpressJSResponseContext, } from "./base-adapter.js";
|
|
6
|
+
export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createGetCustomerRoute, createGetPlanGroupByIdRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, type ActivateOrderSyncRouteConfig, type OrdersRouteConfig, type ProvisioningRouteConfig, type SetupIntentRouteConfig, } from "./routes.js";
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Drop-in handlers for ExpressJS controllers using Express Request/Response
|
|
5
5
|
*/
|
|
6
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;
|
|
7
|
+
exports.createSetupIntentRoute = exports.createProvisioningRoute = exports.createPayInvoiceRoute = exports.createOrdersRoute = exports.createGetPlanGroupByIdRoute = exports.createGetCustomerRoute = exports.createCustomersRoute = exports.createCustomerInvoicesRoute = exports.createContactsRoute = exports.createActivateOrderSyncRoute = exports.createExpressJSResponseContext = exports.expressjsAdapter = void 0;
|
|
8
8
|
var base_adapter_js_1 = require("./base-adapter.js");
|
|
9
9
|
Object.defineProperty(exports, "expressjsAdapter", { enumerable: true, get: function () { return base_adapter_js_1.expressjsAdapter; } });
|
|
10
10
|
Object.defineProperty(exports, "createExpressJSResponseContext", { enumerable: true, get: function () { return base_adapter_js_1.createExpressJSResponseContext; } });
|
|
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "createContactsRoute", { enumerable: true, get: f
|
|
|
14
14
|
Object.defineProperty(exports, "createCustomerInvoicesRoute", { enumerable: true, get: function () { return routes_js_1.createCustomerInvoicesRoute; } });
|
|
15
15
|
Object.defineProperty(exports, "createCustomersRoute", { enumerable: true, get: function () { return routes_js_1.createCustomersRoute; } });
|
|
16
16
|
Object.defineProperty(exports, "createGetCustomerRoute", { enumerable: true, get: function () { return routes_js_1.createGetCustomerRoute; } });
|
|
17
|
+
Object.defineProperty(exports, "createGetPlanGroupByIdRoute", { enumerable: true, get: function () { return routes_js_1.createGetPlanGroupByIdRoute; } });
|
|
17
18
|
Object.defineProperty(exports, "createOrdersRoute", { enumerable: true, get: function () { return routes_js_1.createOrdersRoute; } });
|
|
18
19
|
Object.defineProperty(exports, "createPayInvoiceRoute", { enumerable: true, get: function () { return routes_js_1.createPayInvoiceRoute; } });
|
|
19
20
|
Object.defineProperty(exports, "createProvisioningRoute", { enumerable: true, get: function () { return routes_js_1.createProvisioningRoute; } });
|
|
@@ -161,4 +161,20 @@ export interface SetupIntentRouteConfig extends BaseHandlerConfig {
|
|
|
161
161
|
* ```
|
|
162
162
|
*/
|
|
163
163
|
export declare function createSetupIntentRoute(config?: SetupIntentRouteConfig): ExpressHandler;
|
|
164
|
+
/**
|
|
165
|
+
* Create an Express handler for getting a plan group by ID
|
|
166
|
+
*
|
|
167
|
+
* @param config - Handler configuration options
|
|
168
|
+
* @returns Express route handler function
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* import express from 'express';
|
|
173
|
+
* import { createGetPlanGroupByIdRoute } from '@paid-ai/paid-node/integrations/express';
|
|
174
|
+
*
|
|
175
|
+
* const app = express();
|
|
176
|
+
* app.get('/paid/plans/:planGroupId', createGetPlanGroupByIdRoute());
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export declare function createGetPlanGroupByIdRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
|
|
164
180
|
export {};
|
|
@@ -13,6 +13,7 @@ exports.createOrdersRoute = createOrdersRoute;
|
|
|
13
13
|
exports.createPayInvoiceRoute = createPayInvoiceRoute;
|
|
14
14
|
exports.createProvisioningRoute = createProvisioningRoute;
|
|
15
15
|
exports.createSetupIntentRoute = createSetupIntentRoute;
|
|
16
|
+
exports.createGetPlanGroupByIdRoute = createGetPlanGroupByIdRoute;
|
|
16
17
|
const base_adapter_js_1 = require("./base-adapter.js");
|
|
17
18
|
const contacts_js_1 = require("../../controllers/contacts.js");
|
|
18
19
|
const invoices_js_1 = require("../../controllers/invoices.js");
|
|
@@ -20,6 +21,7 @@ const customers_js_1 = require("../../controllers/customers.js");
|
|
|
20
21
|
const orders_js_1 = require("../../controllers/orders.js");
|
|
21
22
|
const provision_users_js_1 = require("../../controllers/provision-users.js");
|
|
22
23
|
const billing_js_1 = require("../../controllers/billing.js");
|
|
24
|
+
const plans_js_1 = require("../../controllers/plans.js");
|
|
23
25
|
/**
|
|
24
26
|
* Helper to extract headers from Express Request
|
|
25
27
|
*/
|
|
@@ -276,3 +278,29 @@ function createSetupIntentRoute(config = {}) {
|
|
|
276
278
|
};
|
|
277
279
|
return route;
|
|
278
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Create an Express handler for getting a plan group by ID
|
|
283
|
+
*
|
|
284
|
+
* @param config - Handler configuration options
|
|
285
|
+
* @returns Express route handler function
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```typescript
|
|
289
|
+
* import express from 'express';
|
|
290
|
+
* import { createGetPlanGroupByIdRoute } from '@paid-ai/paid-node/integrations/express';
|
|
291
|
+
*
|
|
292
|
+
* const app = express();
|
|
293
|
+
* app.get('/paid/plans/:planGroupId', createGetPlanGroupByIdRoute());
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
function createGetPlanGroupByIdRoute(config = {}) {
|
|
297
|
+
const handler = (0, plans_js_1.createGetPlanGroupByIdHandler)();
|
|
298
|
+
return (req, res) => {
|
|
299
|
+
return handler({
|
|
300
|
+
body: req.body,
|
|
301
|
+
headers: extractHeaders(req),
|
|
302
|
+
method: "GET",
|
|
303
|
+
params: req.params,
|
|
304
|
+
}, (0, base_adapter_js_1.createExpressJSResponseContext)(res), config);
|
|
305
|
+
};
|
|
306
|
+
}
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* Next.js API Route handlers for Paid integration
|
|
3
3
|
* Drop-in handlers for Next.js App Router
|
|
4
4
|
*/
|
|
5
|
-
export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createGetCustomerRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, type ActivateOrderSyncRouteConfig, type OrdersRouteConfig, type ProvisioningRouteConfig, type SetupIntentRouteConfig, } from
|
|
5
|
+
export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createGetCustomerRoute, createGetPlanGroupByIdRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, type ActivateOrderSyncRouteConfig, type OrdersRouteConfig, type ProvisioningRouteConfig, type SetupIntentRouteConfig, } from "./routes.js";
|
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
* Drop-in handlers for Next.js App Router
|
|
5
5
|
*/
|
|
6
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 = void 0;
|
|
7
|
+
exports.createSetupIntentRoute = exports.createProvisioningRoute = exports.createPayInvoiceRoute = exports.createOrdersRoute = exports.createGetPlanGroupByIdRoute = exports.createGetCustomerRoute = exports.createCustomersRoute = exports.createCustomerInvoicesRoute = exports.createContactsRoute = exports.createActivateOrderSyncRoute = void 0;
|
|
8
8
|
var routes_js_1 = require("./routes.js");
|
|
9
9
|
Object.defineProperty(exports, "createActivateOrderSyncRoute", { enumerable: true, get: function () { return routes_js_1.createActivateOrderSyncRoute; } });
|
|
10
10
|
Object.defineProperty(exports, "createContactsRoute", { enumerable: true, get: function () { return routes_js_1.createContactsRoute; } });
|
|
11
11
|
Object.defineProperty(exports, "createCustomerInvoicesRoute", { enumerable: true, get: function () { return routes_js_1.createCustomerInvoicesRoute; } });
|
|
12
12
|
Object.defineProperty(exports, "createCustomersRoute", { enumerable: true, get: function () { return routes_js_1.createCustomersRoute; } });
|
|
13
13
|
Object.defineProperty(exports, "createGetCustomerRoute", { enumerable: true, get: function () { return routes_js_1.createGetCustomerRoute; } });
|
|
14
|
+
Object.defineProperty(exports, "createGetPlanGroupByIdRoute", { enumerable: true, get: function () { return routes_js_1.createGetPlanGroupByIdRoute; } });
|
|
14
15
|
Object.defineProperty(exports, "createOrdersRoute", { enumerable: true, get: function () { return routes_js_1.createOrdersRoute; } });
|
|
15
16
|
Object.defineProperty(exports, "createPayInvoiceRoute", { enumerable: true, get: function () { return routes_js_1.createPayInvoiceRoute; } });
|
|
16
17
|
Object.defineProperty(exports, "createProvisioningRoute", { enumerable: true, get: function () { return routes_js_1.createProvisioningRoute; } });
|
|
@@ -224,4 +224,19 @@ export interface SetupIntentRouteConfig extends BaseHandlerConfig {
|
|
|
224
224
|
* ```
|
|
225
225
|
*/
|
|
226
226
|
export declare function createSetupIntentRoute(config?: SetupIntentRouteConfig): NextJsHandler;
|
|
227
|
+
/**
|
|
228
|
+
* Create a Next.js API route handler for getting a plan group by ID
|
|
229
|
+
*
|
|
230
|
+
* @param config - Handler configuration options
|
|
231
|
+
* @returns Next.js route handler function
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* // src/app/api/plans/[planGroupId]/route.ts
|
|
236
|
+
* import { createGetPlanGroupByIdRoute } from '@paid-ai/paid-node/integrations/nextjs';
|
|
237
|
+
*
|
|
238
|
+
* export const GET = createGetPlanGroupByIdRoute();
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
export declare function createGetPlanGroupByIdRoute(config?: BaseHandlerConfig): (request: any, context?: any) => Promise<any>;
|
|
227
242
|
export {};
|
|
@@ -9,6 +9,7 @@ exports.createOrdersRoute = createOrdersRoute;
|
|
|
9
9
|
exports.createPayInvoiceRoute = createPayInvoiceRoute;
|
|
10
10
|
exports.createProvisioningRoute = createProvisioningRoute;
|
|
11
11
|
exports.createSetupIntentRoute = createSetupIntentRoute;
|
|
12
|
+
exports.createGetPlanGroupByIdRoute = createGetPlanGroupByIdRoute;
|
|
12
13
|
const base_adapter_js_1 = require("./base-adapter.js");
|
|
13
14
|
const contacts_js_1 = require("../../controllers/contacts.js");
|
|
14
15
|
const invoices_js_1 = require("../../controllers/invoices.js");
|
|
@@ -16,6 +17,7 @@ const customers_js_1 = require("../../controllers/customers.js");
|
|
|
16
17
|
const orders_js_1 = require("../../controllers/orders.js");
|
|
17
18
|
const provision_users_js_1 = require("../../controllers/provision-users.js");
|
|
18
19
|
const billing_js_1 = require("../../controllers/billing.js");
|
|
20
|
+
const plans_js_1 = require("../../controllers/plans.js");
|
|
19
21
|
/**
|
|
20
22
|
* Create a Next.js API route handler for synchronous order activation
|
|
21
23
|
*
|
|
@@ -253,3 +255,22 @@ function createSetupIntentRoute(config = {}) {
|
|
|
253
255
|
const route = (request, context) => adaptedHandler(request, context, config);
|
|
254
256
|
return route;
|
|
255
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Create a Next.js API route handler for getting a plan group by ID
|
|
260
|
+
*
|
|
261
|
+
* @param config - Handler configuration options
|
|
262
|
+
* @returns Next.js route handler function
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* // src/app/api/plans/[planGroupId]/route.ts
|
|
267
|
+
* import { createGetPlanGroupByIdRoute } from '@paid-ai/paid-node/integrations/nextjs';
|
|
268
|
+
*
|
|
269
|
+
* export const GET = createGetPlanGroupByIdRoute();
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
function createGetPlanGroupByIdRoute(config = {}) {
|
|
273
|
+
const handler = (0, plans_js_1.createGetPlanGroupByIdHandler)();
|
|
274
|
+
const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
|
|
275
|
+
return (request, context) => adaptedHandler(request, context, config);
|
|
276
|
+
}
|
|
@@ -4,3 +4,4 @@ export { createOrder, createOrderWithDefaults, createOrdersHandler, } from "./or
|
|
|
4
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
5
|
export { getCustomerInvoices, createCustomerInvoicesHandler, type CustomerInvoicesResult, } from "./invoices.js";
|
|
6
6
|
export { provisionNewUser, createProvisioningHandler, } from "./provision-users.js";
|
|
7
|
+
export { createGetPlanGroupByIdHandler, } from "./plans.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
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;
|
|
3
|
+
exports.createGetPlanGroupByIdHandler = 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
4
|
var customers_js_1 = require("./customers.js");
|
|
5
5
|
Object.defineProperty(exports, "createCustomer", { enumerable: true, get: function () { return customers_js_1.createCustomer; } });
|
|
6
6
|
Object.defineProperty(exports, "createCustomerWithDefaults", { enumerable: true, get: function () { return customers_js_1.createCustomerWithDefaults; } });
|
|
@@ -28,3 +28,5 @@ Object.defineProperty(exports, "createCustomerInvoicesHandler", { enumerable: tr
|
|
|
28
28
|
var provision_users_js_1 = require("./provision-users.js");
|
|
29
29
|
Object.defineProperty(exports, "provisionNewUser", { enumerable: true, get: function () { return provision_users_js_1.provisionNewUser; } });
|
|
30
30
|
Object.defineProperty(exports, "createProvisioningHandler", { enumerable: true, get: function () { return provision_users_js_1.createProvisioningHandler; } });
|
|
31
|
+
var plans_js_1 = require("./plans.js");
|
|
32
|
+
Object.defineProperty(exports, "createGetPlanGroupByIdHandler", { enumerable: true, get: function () { return plans_js_1.createGetPlanGroupByIdHandler; } });
|
|
@@ -13,11 +13,17 @@ exports.createOrderWithDefaults = createOrderWithDefaults;
|
|
|
13
13
|
exports.createOrder = createOrder;
|
|
14
14
|
exports.createOrdersHandler = createOrdersHandler;
|
|
15
15
|
const base_handler_js_1 = require("../utils/base-handler.js");
|
|
16
|
+
const plans_js_1 = require("./plans.js");
|
|
17
|
+
function hasProductWithExternalId(pp) {
|
|
18
|
+
if (!pp.product) {
|
|
19
|
+
throw new Error(`Plan product ${pp.id} is missing nested product data`);
|
|
20
|
+
}
|
|
21
|
+
return !!pp.product.externalId;
|
|
22
|
+
}
|
|
16
23
|
/**
|
|
17
24
|
* Generate default values for missing order fields
|
|
18
25
|
*/
|
|
19
26
|
function generateOrderDefaults(config, options = {}) {
|
|
20
|
-
var _a;
|
|
21
27
|
const { defaultDurationDays = 365 } = options;
|
|
22
28
|
const startDate = config.startDate || new Date().toISOString().split("T")[0];
|
|
23
29
|
const endDate = config.endDate ||
|
|
@@ -27,20 +33,31 @@ function generateOrderDefaults(config, options = {}) {
|
|
|
27
33
|
const name = config.name || "Subscription Order";
|
|
28
34
|
const description = config.description || "Annual subscription";
|
|
29
35
|
const currency = config.currency || "USD";
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
// defensive guard
|
|
37
|
+
if (!config.orderLines && !config.planId && !config.agentExternalId) {
|
|
38
|
+
throw new Error("Either orderLines, planId, or agentExternalId must be provided");
|
|
39
|
+
}
|
|
40
|
+
const orderLines = config.orderLines
|
|
41
|
+
? config.orderLines.map(line => {
|
|
42
|
+
var _a;
|
|
43
|
+
return ({
|
|
44
|
+
agentExternalId: line.agentExternalId,
|
|
45
|
+
name: line.name || name,
|
|
46
|
+
description: line.description || description,
|
|
47
|
+
planProductId: (_a = line.planProductId) !== null && _a !== void 0 ? _a : undefined,
|
|
48
|
+
});
|
|
49
|
+
})
|
|
50
|
+
: [{
|
|
51
|
+
agentExternalId: config.agentExternalId,
|
|
52
|
+
name,
|
|
53
|
+
description,
|
|
54
|
+
}];
|
|
39
55
|
return {
|
|
40
56
|
customerId: config.customerId,
|
|
41
57
|
customerExternalId: config.customerExternalId,
|
|
42
58
|
billingContactId: config.billingContactId,
|
|
43
59
|
agentExternalId: config.agentExternalId,
|
|
60
|
+
planId: config.planId,
|
|
44
61
|
name,
|
|
45
62
|
description,
|
|
46
63
|
startDate,
|
|
@@ -69,8 +86,12 @@ function createAndActivateOrder(client, config, autoActivate) {
|
|
|
69
86
|
orderLine.name = line.name;
|
|
70
87
|
if (line.description)
|
|
71
88
|
orderLine.description = line.description;
|
|
89
|
+
// planProductId is not in the create orders api spec - this is functioning but greptile will complain
|
|
90
|
+
if (line.planProductId)
|
|
91
|
+
orderLine.planProductId = line.planProductId;
|
|
72
92
|
return orderLine;
|
|
73
93
|
}),
|
|
94
|
+
planId: config.planId,
|
|
74
95
|
});
|
|
75
96
|
if (!order.id) {
|
|
76
97
|
throw new Error("Order created but missing ID");
|
|
@@ -177,18 +198,32 @@ function createOrder(client_1, config_1) {
|
|
|
177
198
|
*/
|
|
178
199
|
function createOrdersHandler(helperOptions) {
|
|
179
200
|
return (0, base_handler_js_1.createHandler)((client, body) => __awaiter(this, void 0, void 0, function* () {
|
|
180
|
-
var _a, _b;
|
|
181
|
-
if (!body.customerId) {
|
|
182
|
-
throw new Error("customerId is required");
|
|
183
|
-
}
|
|
201
|
+
var _a, _b, _c;
|
|
184
202
|
if (!body.customerExternalId) {
|
|
185
203
|
throw new Error("customerExternalId is required");
|
|
186
204
|
}
|
|
187
|
-
if (!body.agentExternalId) {
|
|
188
|
-
throw new Error("agentExternalId
|
|
205
|
+
if (!body.agentExternalId && !body.planId) {
|
|
206
|
+
throw new Error("agentExternalId or planId are required");
|
|
189
207
|
}
|
|
190
208
|
const orderOptions = Object.assign(Object.assign({}, helperOptions), { autoActivate: (_b = (_a = body.autoActivate) !== null && _a !== void 0 ? _a : helperOptions === null || helperOptions === void 0 ? void 0 : helperOptions.autoActivate) !== null && _b !== void 0 ? _b : true });
|
|
209
|
+
if (body.planId) {
|
|
210
|
+
const plan = yield (0, plans_js_1.getPlanById)(client, body.planId);
|
|
211
|
+
if (!((_c = plan.planProducts) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
212
|
+
throw new Error(`Plan ${body.planId} has no products`);
|
|
213
|
+
}
|
|
214
|
+
body.orderLines = plan.planProducts
|
|
215
|
+
.filter(hasProductWithExternalId)
|
|
216
|
+
.map((pp) => ({
|
|
217
|
+
agentExternalId: pp.product.externalId,
|
|
218
|
+
name: pp.product.name,
|
|
219
|
+
description: pp.product.description,
|
|
220
|
+
planProductId: pp.id,
|
|
221
|
+
}));
|
|
222
|
+
if (body.orderLines.length === 0) {
|
|
223
|
+
throw new Error(`Plan ${body.planId} has no products with externalId`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
191
226
|
const order = yield createOrderWithDefaults(client, body, orderOptions);
|
|
192
227
|
return { success: true, data: order };
|
|
193
|
-
}), { requiredFields: ['
|
|
228
|
+
}), { requiredFields: ['customerExternalId'] });
|
|
194
229
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { PaidClient } from "../../Client.js";
|
|
2
|
+
import type { PlanGroup } from "../../api/types/PlanGroup.js";
|
|
3
|
+
import type { Plan } from "../../api/types/Plan.js";
|
|
4
|
+
/**
|
|
5
|
+
* Get a plan by ID
|
|
6
|
+
*
|
|
7
|
+
* @param client - PaidClient instance
|
|
8
|
+
* @param planId - Plan's ID
|
|
9
|
+
* @returns Plan data
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const plan = await getPlanById(client, 'plan-123');
|
|
14
|
+
* console.log(plan.name, plan.id);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function getPlanById(client: PaidClient, planId: string): Promise<Plan>;
|
|
18
|
+
/**
|
|
19
|
+
* Get a plan group by ID
|
|
20
|
+
*
|
|
21
|
+
* @param client - PaidClient instance
|
|
22
|
+
* @param planGroupId - Plan group's ID
|
|
23
|
+
* @returns Plan group data
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const planGroup = await getPlanGroupById(client, 'plan-group-123');
|
|
28
|
+
* console.log(planGroup.name, planGroup.id);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function getPlanGroupById(client: PaidClient, planGroupId: string): Promise<PlanGroup>;
|
|
32
|
+
/**
|
|
33
|
+
* Create a framework-agnostic handler for fetching a plan group by ID
|
|
34
|
+
*
|
|
35
|
+
* This handler can be used with any framework adapter.
|
|
36
|
+
* The plan group ID should be provided either in params or query string.
|
|
37
|
+
*
|
|
38
|
+
* @returns Handler function
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // In Next.js route: /api/plans/[planGroupId]/route.ts
|
|
43
|
+
* import { createGetPlanGroupByIdHandler } from '@paid-ai/paid-node/integrations';
|
|
44
|
+
* import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
|
|
45
|
+
*
|
|
46
|
+
* const handler = createGetPlanGroupByIdHandler();
|
|
47
|
+
* export const GET = nextjsAdapter(handler);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function createGetPlanGroupByIdHandler(): (request: any, response: any, config?: any) => Promise<any>;
|