@paid-ai/paid-node 1.0.1-alpha1 → 1.0.1-alpha5
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/README.md +4 -4
- package/dist/cjs/Client.js +2 -2
- package/dist/cjs/api/resources/index.d.ts +1 -0
- package/dist/cjs/api/resources/index.js +1 -0
- package/dist/cjs/api/resources/plans/client/Client.d.ts +75 -0
- package/dist/cjs/api/resources/plans/client/Client.js +290 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansGetCurrentRequest.d.ts +15 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansGetCurrentRequest.js +3 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansSubscribeRequest.d.ts +13 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansSubscribeRequest.js +3 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansUnsubscribeRequest.d.ts +10 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansUnsubscribeRequest.js +3 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansUpgradeRequest.d.ts +16 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansUpgradeRequest.js +3 -0
- package/dist/cjs/api/resources/plans/client/requests/index.d.ts +4 -0
- package/dist/cjs/api/resources/plans/index.d.ts +1 -0
- package/dist/cjs/api/resources/plans/index.js +1 -0
- package/dist/cjs/api/resources/plans/types/PlansGetCurrentResponse.d.ts +83 -0
- package/dist/cjs/api/resources/plans/types/PlansGetCurrentResponse.js +16 -0
- package/dist/cjs/api/resources/plans/types/index.d.ts +1 -0
- package/dist/cjs/api/resources/plans/types/index.js +17 -0
- package/dist/cjs/api/types/Plan.d.ts +10 -0
- package/dist/cjs/api/types/Plan.js +10 -0
- package/dist/cjs/api/types/PlanPricing.d.ts +23 -0
- package/dist/cjs/api/types/PlanPricing.js +15 -0
- package/dist/cjs/api/types/PlanWithFeatures.d.ts +11 -0
- package/dist/cjs/api/types/PlanWithFeatures.js +10 -0
- package/dist/cjs/api/types/index.d.ts +1 -0
- package/dist/cjs/api/types/index.js +1 -0
- package/dist/cjs/integrations/adapters/nextjs/index.d.ts +1 -1
- package/dist/cjs/integrations/adapters/nextjs/index.js +6 -1
- package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +76 -0
- package/dist/cjs/integrations/adapters/nextjs/routes.js +101 -0
- package/dist/cjs/integrations/controllers/index.d.ts +1 -1
- package/dist/cjs/integrations/controllers/index.js +13 -1
- package/dist/cjs/integrations/controllers/plans.d.ts +198 -0
- package/dist/cjs/integrations/controllers/plans.js +339 -0
- package/dist/cjs/tracing/autoInstrumentation.d.ts +1 -1
- package/dist/cjs/tracing/autoInstrumentation.js +115 -39
- package/dist/cjs/tracing/signal.js +1 -4
- package/dist/cjs/tracing/spanProcessor.js +12 -0
- package/dist/cjs/tracing/tracing.js +3 -6
- 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/index.d.mts +1 -0
- package/dist/esm/api/resources/index.mjs +1 -0
- package/dist/esm/api/resources/plans/client/Client.d.mts +75 -0
- package/dist/esm/api/resources/plans/client/Client.mjs +290 -0
- package/dist/esm/api/resources/plans/client/requests/PlansGetCurrentRequest.d.mts +15 -0
- package/dist/esm/api/resources/plans/client/requests/PlansGetCurrentRequest.mjs +2 -0
- package/dist/esm/api/resources/plans/client/requests/PlansSubscribeRequest.d.mts +13 -0
- package/dist/esm/api/resources/plans/client/requests/PlansSubscribeRequest.mjs +2 -0
- package/dist/esm/api/resources/plans/client/requests/PlansUnsubscribeRequest.d.mts +10 -0
- package/dist/esm/api/resources/plans/client/requests/PlansUnsubscribeRequest.mjs +2 -0
- package/dist/esm/api/resources/plans/client/requests/PlansUpgradeRequest.d.mts +16 -0
- package/dist/esm/api/resources/plans/client/requests/PlansUpgradeRequest.mjs +2 -0
- package/dist/esm/api/resources/plans/client/requests/index.d.mts +4 -0
- package/dist/esm/api/resources/plans/index.d.mts +1 -0
- package/dist/esm/api/resources/plans/index.mjs +1 -0
- package/dist/esm/api/resources/plans/types/PlansGetCurrentResponse.d.mts +83 -0
- package/dist/esm/api/resources/plans/types/PlansGetCurrentResponse.mjs +13 -0
- package/dist/esm/api/resources/plans/types/index.d.mts +1 -0
- package/dist/esm/api/resources/plans/types/index.mjs +1 -0
- package/dist/esm/api/types/Plan.d.mts +10 -0
- package/dist/esm/api/types/Plan.mjs +9 -1
- package/dist/esm/api/types/PlanPricing.d.mts +23 -0
- package/dist/esm/api/types/PlanPricing.mjs +12 -0
- package/dist/esm/api/types/PlanWithFeatures.d.mts +11 -0
- package/dist/esm/api/types/PlanWithFeatures.mjs +9 -1
- package/dist/esm/api/types/index.d.mts +1 -0
- package/dist/esm/api/types/index.mjs +1 -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 +76 -0
- package/dist/esm/integrations/adapters/nextjs/routes.mjs +97 -1
- package/dist/esm/integrations/controllers/index.d.mts +1 -1
- package/dist/esm/integrations/controllers/index.mjs +1 -1
- package/dist/esm/integrations/controllers/plans.d.mts +198 -0
- package/dist/esm/integrations/controllers/plans.mjs +329 -0
- package/dist/esm/tracing/autoInstrumentation.d.mts +1 -1
- package/dist/esm/tracing/autoInstrumentation.mjs +82 -39
- package/dist/esm/tracing/signal.mjs +1 -4
- package/dist/esm/tracing/spanProcessor.mjs +12 -0
- package/dist/esm/tracing/tracing.mjs +3 -6
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -1
- package/reference.md +293 -0
package/README.md
CHANGED
|
@@ -142,7 +142,7 @@ For maximum convenience, you can use OpenTelemetry auto-instrumentation to autom
|
|
|
142
142
|
``` typescript
|
|
143
143
|
// Import and call auto-instrumentation before importing instrumented libraries
|
|
144
144
|
import { paidAutoInstrument } from "@paid-ai/paid-node/tracing";
|
|
145
|
-
paidAutoInstrument()
|
|
145
|
+
await paidAutoInstrument()
|
|
146
146
|
|
|
147
147
|
import openai from "openai";
|
|
148
148
|
|
|
@@ -192,7 +192,7 @@ import openai from "openai";
|
|
|
192
192
|
|
|
193
193
|
// If your module management is too complex and the previous approach didn't work
|
|
194
194
|
// you can provide libraries directly
|
|
195
|
-
paidAutoInstrument({ openai })
|
|
195
|
+
await paidAutoInstrument({ openai })
|
|
196
196
|
```
|
|
197
197
|
|
|
198
198
|
|
|
@@ -310,7 +310,7 @@ async function main() {
|
|
|
310
310
|
|
|
311
311
|
await trace({
|
|
312
312
|
externalCustomerId: "<your_external_customer_id>",
|
|
313
|
-
|
|
313
|
+
externalProductId: "<your_external_product_id>"
|
|
314
314
|
}, async () => {
|
|
315
315
|
// ...do some work...
|
|
316
316
|
signal("<your_signal_name>", false, {
|
|
@@ -367,7 +367,7 @@ async function main() {
|
|
|
367
367
|
|
|
368
368
|
await trace({
|
|
369
369
|
externalCustomerId: "<your_external_customer_id>",
|
|
370
|
-
|
|
370
|
+
externalProductId: "<your_external_product_id>"
|
|
371
371
|
}, async () => {
|
|
372
372
|
// ...do some work...
|
|
373
373
|
signal("<your_signal_name>", false, {
|
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-alpha5",
|
|
54
|
+
"User-Agent": "@paid-ai/paid-node/1.0.1-alpha5",
|
|
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) });
|
|
@@ -9,6 +9,7 @@ export * from "./orders/client/requests/index.js";
|
|
|
9
9
|
export * as orders from "./orders/index.js";
|
|
10
10
|
export * from "./plans/client/requests/index.js";
|
|
11
11
|
export * as plans from "./plans/index.js";
|
|
12
|
+
export * from "./plans/types/index.js";
|
|
12
13
|
export * from "./products/client/requests/index.js";
|
|
13
14
|
export * as products from "./products/index.js";
|
|
14
15
|
export * from "./traces/client/requests/index.js";
|
|
@@ -48,6 +48,7 @@ __exportStar(require("./orders/client/requests/index.js"), exports);
|
|
|
48
48
|
exports.orders = __importStar(require("./orders/index.js"));
|
|
49
49
|
__exportStar(require("./plans/client/requests/index.js"), exports);
|
|
50
50
|
exports.plans = __importStar(require("./plans/index.js"));
|
|
51
|
+
__exportStar(require("./plans/types/index.js"), exports);
|
|
51
52
|
__exportStar(require("./products/client/requests/index.js"), exports);
|
|
52
53
|
exports.products = __importStar(require("./products/index.js"));
|
|
53
54
|
__exportStar(require("./traces/client/requests/index.js"), exports);
|
|
@@ -10,6 +10,23 @@ export declare namespace Plans {
|
|
|
10
10
|
export declare class Plans {
|
|
11
11
|
protected readonly _options: Plans.Options;
|
|
12
12
|
constructor(_options?: Plans.Options);
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves the currently active plan subscription for a customer by their external ID. Returns the plan details and subscription information.
|
|
15
|
+
*
|
|
16
|
+
* @param {Paid.PlansGetCurrentRequest} request
|
|
17
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
18
|
+
*
|
|
19
|
+
* @throws {@link Paid.BadRequestError}
|
|
20
|
+
* @throws {@link Paid.ForbiddenError}
|
|
21
|
+
* @throws {@link Paid.NotFoundError}
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* await client.plans.getCurrent({
|
|
25
|
+
* customerExternalId: "customerExternalId"
|
|
26
|
+
* })
|
|
27
|
+
*/
|
|
28
|
+
getCurrent(request: Paid.PlansGetCurrentRequest, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.PlansGetCurrentResponse>;
|
|
29
|
+
private __getCurrent;
|
|
13
30
|
/**
|
|
14
31
|
* @param {string} planId - The ID of the plan
|
|
15
32
|
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -42,6 +59,62 @@ export declare class Plans {
|
|
|
42
59
|
*/
|
|
43
60
|
getUsage(planId: string, request: Paid.PlansGetUsageRequest, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.UsageSummariesResponse>;
|
|
44
61
|
private __getUsage;
|
|
62
|
+
/**
|
|
63
|
+
* Creates a new order for a customer subscribing to a plan. The order will be created with the plan's products and pricing attributes.
|
|
64
|
+
*
|
|
65
|
+
* @param {string} planId - The ID of the plan
|
|
66
|
+
* @param {Paid.PlansSubscribeRequest} request
|
|
67
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
68
|
+
*
|
|
69
|
+
* @throws {@link Paid.BadRequestError}
|
|
70
|
+
* @throws {@link Paid.ForbiddenError}
|
|
71
|
+
* @throws {@link Paid.NotFoundError}
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* await client.plans.subscribe("planId", {
|
|
75
|
+
* customerExternalId: "customerExternalId",
|
|
76
|
+
* currency: "currency"
|
|
77
|
+
* })
|
|
78
|
+
*/
|
|
79
|
+
subscribe(planId: string, request: Paid.PlansSubscribeRequest, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.Order>;
|
|
80
|
+
private __subscribe;
|
|
81
|
+
/**
|
|
82
|
+
* Cancels the renewal of an active order for a customer's plan subscription. The order will remain active until the cancellation date.
|
|
83
|
+
*
|
|
84
|
+
* @param {string} planId - The ID of the plan
|
|
85
|
+
* @param {Paid.PlansUnsubscribeRequest} request
|
|
86
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
87
|
+
*
|
|
88
|
+
* @throws {@link Paid.BadRequestError}
|
|
89
|
+
* @throws {@link Paid.ForbiddenError}
|
|
90
|
+
* @throws {@link Paid.NotFoundError}
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* await client.plans.unsubscribe("planId", {
|
|
94
|
+
* customerExternalId: "customerExternalId"
|
|
95
|
+
* })
|
|
96
|
+
*/
|
|
97
|
+
unsubscribe(planId: string, request: Paid.PlansUnsubscribeRequest, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.CancelRenewalResponse>;
|
|
98
|
+
private __unsubscribe;
|
|
99
|
+
/**
|
|
100
|
+
* Upgrades a customer from one plan to another with automatic proration. Credits are applied for the unused portion of the current billing period, and the order is updated with the new plan's pricing.
|
|
101
|
+
*
|
|
102
|
+
* @param {Paid.PlansUpgradeRequest} request
|
|
103
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
104
|
+
*
|
|
105
|
+
* @throws {@link Paid.BadRequestError}
|
|
106
|
+
* @throws {@link Paid.ForbiddenError}
|
|
107
|
+
* @throws {@link Paid.NotFoundError}
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* await client.plans.upgrade({
|
|
111
|
+
* customerExternalId: "customerExternalId",
|
|
112
|
+
* oldPlanId: "oldPlanId",
|
|
113
|
+
* newPlanId: "newPlanId"
|
|
114
|
+
* })
|
|
115
|
+
*/
|
|
116
|
+
upgrade(request: Paid.PlansUpgradeRequest, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.ProrationUpgradeResponse>;
|
|
117
|
+
private __upgrade;
|
|
45
118
|
/**
|
|
46
119
|
* @param {string} planGroupId - The ID of the plan group
|
|
47
120
|
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -55,6 +128,8 @@ export declare class Plans {
|
|
|
55
128
|
getGroupById(planGroupId: string, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.PlanGroup>;
|
|
56
129
|
private __getGroupById;
|
|
57
130
|
/**
|
|
131
|
+
* Retrieves all plans in a plan group with their features (product-attribute pairs)
|
|
132
|
+
*
|
|
58
133
|
* @param {string} planGroupId - The ID of the plan group
|
|
59
134
|
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
60
135
|
*
|
|
@@ -53,6 +53,76 @@ class Plans {
|
|
|
53
53
|
constructor(_options = {}) {
|
|
54
54
|
this._options = _options;
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Retrieves the currently active plan subscription for a customer by their external ID. Returns the plan details and subscription information.
|
|
58
|
+
*
|
|
59
|
+
* @param {Paid.PlansGetCurrentRequest} request
|
|
60
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
61
|
+
*
|
|
62
|
+
* @throws {@link Paid.BadRequestError}
|
|
63
|
+
* @throws {@link Paid.ForbiddenError}
|
|
64
|
+
* @throws {@link Paid.NotFoundError}
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* await client.plans.getCurrent({
|
|
68
|
+
* customerExternalId: "customerExternalId"
|
|
69
|
+
* })
|
|
70
|
+
*/
|
|
71
|
+
getCurrent(request, requestOptions) {
|
|
72
|
+
return core.HttpResponsePromise.fromPromise(this.__getCurrent(request, requestOptions));
|
|
73
|
+
}
|
|
74
|
+
__getCurrent(request, requestOptions) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
77
|
+
const { customerExternalId } = request;
|
|
78
|
+
const _queryParams = {};
|
|
79
|
+
_queryParams.customerExternalId = customerExternalId;
|
|
80
|
+
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);
|
|
81
|
+
const _response = yield core.fetcher({
|
|
82
|
+
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/current"),
|
|
83
|
+
method: "GET",
|
|
84
|
+
headers: _headers,
|
|
85
|
+
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
|
|
86
|
+
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,
|
|
87
|
+
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,
|
|
88
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
89
|
+
});
|
|
90
|
+
if (_response.ok) {
|
|
91
|
+
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
92
|
+
}
|
|
93
|
+
if (_response.error.reason === "status-code") {
|
|
94
|
+
switch (_response.error.statusCode) {
|
|
95
|
+
case 400:
|
|
96
|
+
throw new Paid.BadRequestError(_response.error.body, _response.rawResponse);
|
|
97
|
+
case 403:
|
|
98
|
+
throw new Paid.ForbiddenError(_response.error.body, _response.rawResponse);
|
|
99
|
+
case 404:
|
|
100
|
+
throw new Paid.NotFoundError(_response.error.body, _response.rawResponse);
|
|
101
|
+
default:
|
|
102
|
+
throw new errors.PaidError({
|
|
103
|
+
statusCode: _response.error.statusCode,
|
|
104
|
+
body: _response.error.body,
|
|
105
|
+
rawResponse: _response.rawResponse,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
switch (_response.error.reason) {
|
|
110
|
+
case "non-json":
|
|
111
|
+
throw new errors.PaidError({
|
|
112
|
+
statusCode: _response.error.statusCode,
|
|
113
|
+
body: _response.error.rawBody,
|
|
114
|
+
rawResponse: _response.rawResponse,
|
|
115
|
+
});
|
|
116
|
+
case "timeout":
|
|
117
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /plans/current.");
|
|
118
|
+
case "unknown":
|
|
119
|
+
throw new errors.PaidError({
|
|
120
|
+
message: _response.error.errorMessage,
|
|
121
|
+
rawResponse: _response.rawResponse,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
56
126
|
/**
|
|
57
127
|
* @param {string} planId - The ID of the plan
|
|
58
128
|
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -198,6 +268,224 @@ class Plans {
|
|
|
198
268
|
}
|
|
199
269
|
});
|
|
200
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Creates a new order for a customer subscribing to a plan. The order will be created with the plan's products and pricing attributes.
|
|
273
|
+
*
|
|
274
|
+
* @param {string} planId - The ID of the plan
|
|
275
|
+
* @param {Paid.PlansSubscribeRequest} request
|
|
276
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
277
|
+
*
|
|
278
|
+
* @throws {@link Paid.BadRequestError}
|
|
279
|
+
* @throws {@link Paid.ForbiddenError}
|
|
280
|
+
* @throws {@link Paid.NotFoundError}
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* await client.plans.subscribe("planId", {
|
|
284
|
+
* customerExternalId: "customerExternalId",
|
|
285
|
+
* currency: "currency"
|
|
286
|
+
* })
|
|
287
|
+
*/
|
|
288
|
+
subscribe(planId, request, requestOptions) {
|
|
289
|
+
return core.HttpResponsePromise.fromPromise(this.__subscribe(planId, request, requestOptions));
|
|
290
|
+
}
|
|
291
|
+
__subscribe(planId, request, requestOptions) {
|
|
292
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
293
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
294
|
+
const { customerExternalId, currency } = request;
|
|
295
|
+
const _queryParams = {};
|
|
296
|
+
_queryParams.customerExternalId = customerExternalId;
|
|
297
|
+
_queryParams.currency = currency;
|
|
298
|
+
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);
|
|
299
|
+
const _response = yield core.fetcher({
|
|
300
|
+
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/${core.url.encodePathParam(planId)}/subscribe`),
|
|
301
|
+
method: "POST",
|
|
302
|
+
headers: _headers,
|
|
303
|
+
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
|
|
304
|
+
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,
|
|
305
|
+
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,
|
|
306
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
307
|
+
});
|
|
308
|
+
if (_response.ok) {
|
|
309
|
+
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
310
|
+
}
|
|
311
|
+
if (_response.error.reason === "status-code") {
|
|
312
|
+
switch (_response.error.statusCode) {
|
|
313
|
+
case 400:
|
|
314
|
+
throw new Paid.BadRequestError(_response.error.body, _response.rawResponse);
|
|
315
|
+
case 403:
|
|
316
|
+
throw new Paid.ForbiddenError(_response.error.body, _response.rawResponse);
|
|
317
|
+
case 404:
|
|
318
|
+
throw new Paid.NotFoundError(_response.error.body, _response.rawResponse);
|
|
319
|
+
default:
|
|
320
|
+
throw new errors.PaidError({
|
|
321
|
+
statusCode: _response.error.statusCode,
|
|
322
|
+
body: _response.error.body,
|
|
323
|
+
rawResponse: _response.rawResponse,
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
switch (_response.error.reason) {
|
|
328
|
+
case "non-json":
|
|
329
|
+
throw new errors.PaidError({
|
|
330
|
+
statusCode: _response.error.statusCode,
|
|
331
|
+
body: _response.error.rawBody,
|
|
332
|
+
rawResponse: _response.rawResponse,
|
|
333
|
+
});
|
|
334
|
+
case "timeout":
|
|
335
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling POST /plans/{planId}/subscribe.");
|
|
336
|
+
case "unknown":
|
|
337
|
+
throw new errors.PaidError({
|
|
338
|
+
message: _response.error.errorMessage,
|
|
339
|
+
rawResponse: _response.rawResponse,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Cancels the renewal of an active order for a customer's plan subscription. The order will remain active until the cancellation date.
|
|
346
|
+
*
|
|
347
|
+
* @param {string} planId - The ID of the plan
|
|
348
|
+
* @param {Paid.PlansUnsubscribeRequest} request
|
|
349
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
350
|
+
*
|
|
351
|
+
* @throws {@link Paid.BadRequestError}
|
|
352
|
+
* @throws {@link Paid.ForbiddenError}
|
|
353
|
+
* @throws {@link Paid.NotFoundError}
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* await client.plans.unsubscribe("planId", {
|
|
357
|
+
* customerExternalId: "customerExternalId"
|
|
358
|
+
* })
|
|
359
|
+
*/
|
|
360
|
+
unsubscribe(planId, request, requestOptions) {
|
|
361
|
+
return core.HttpResponsePromise.fromPromise(this.__unsubscribe(planId, request, requestOptions));
|
|
362
|
+
}
|
|
363
|
+
__unsubscribe(planId, request, requestOptions) {
|
|
364
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
365
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
366
|
+
const { customerExternalId } = request;
|
|
367
|
+
const _queryParams = {};
|
|
368
|
+
_queryParams.customerExternalId = customerExternalId;
|
|
369
|
+
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);
|
|
370
|
+
const _response = yield core.fetcher({
|
|
371
|
+
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/${core.url.encodePathParam(planId)}/unsubscribe`),
|
|
372
|
+
method: "POST",
|
|
373
|
+
headers: _headers,
|
|
374
|
+
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
|
|
375
|
+
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,
|
|
376
|
+
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,
|
|
377
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
378
|
+
});
|
|
379
|
+
if (_response.ok) {
|
|
380
|
+
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
381
|
+
}
|
|
382
|
+
if (_response.error.reason === "status-code") {
|
|
383
|
+
switch (_response.error.statusCode) {
|
|
384
|
+
case 400:
|
|
385
|
+
throw new Paid.BadRequestError(_response.error.body, _response.rawResponse);
|
|
386
|
+
case 403:
|
|
387
|
+
throw new Paid.ForbiddenError(_response.error.body, _response.rawResponse);
|
|
388
|
+
case 404:
|
|
389
|
+
throw new Paid.NotFoundError(_response.error.body, _response.rawResponse);
|
|
390
|
+
default:
|
|
391
|
+
throw new errors.PaidError({
|
|
392
|
+
statusCode: _response.error.statusCode,
|
|
393
|
+
body: _response.error.body,
|
|
394
|
+
rawResponse: _response.rawResponse,
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
switch (_response.error.reason) {
|
|
399
|
+
case "non-json":
|
|
400
|
+
throw new errors.PaidError({
|
|
401
|
+
statusCode: _response.error.statusCode,
|
|
402
|
+
body: _response.error.rawBody,
|
|
403
|
+
rawResponse: _response.rawResponse,
|
|
404
|
+
});
|
|
405
|
+
case "timeout":
|
|
406
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling POST /plans/{planId}/unsubscribe.");
|
|
407
|
+
case "unknown":
|
|
408
|
+
throw new errors.PaidError({
|
|
409
|
+
message: _response.error.errorMessage,
|
|
410
|
+
rawResponse: _response.rawResponse,
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Upgrades a customer from one plan to another with automatic proration. Credits are applied for the unused portion of the current billing period, and the order is updated with the new plan's pricing.
|
|
417
|
+
*
|
|
418
|
+
* @param {Paid.PlansUpgradeRequest} request
|
|
419
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
420
|
+
*
|
|
421
|
+
* @throws {@link Paid.BadRequestError}
|
|
422
|
+
* @throws {@link Paid.ForbiddenError}
|
|
423
|
+
* @throws {@link Paid.NotFoundError}
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* await client.plans.upgrade({
|
|
427
|
+
* customerExternalId: "customerExternalId",
|
|
428
|
+
* oldPlanId: "oldPlanId",
|
|
429
|
+
* newPlanId: "newPlanId"
|
|
430
|
+
* })
|
|
431
|
+
*/
|
|
432
|
+
upgrade(request, requestOptions) {
|
|
433
|
+
return core.HttpResponsePromise.fromPromise(this.__upgrade(request, requestOptions));
|
|
434
|
+
}
|
|
435
|
+
__upgrade(request, requestOptions) {
|
|
436
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
437
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
438
|
+
const { customerExternalId, oldPlanId, newPlanId } = request;
|
|
439
|
+
const _queryParams = {};
|
|
440
|
+
_queryParams.customerExternalId = customerExternalId;
|
|
441
|
+
_queryParams.oldPlanId = oldPlanId;
|
|
442
|
+
_queryParams.newPlanId = newPlanId;
|
|
443
|
+
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);
|
|
444
|
+
const _response = yield core.fetcher({
|
|
445
|
+
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/upgrade"),
|
|
446
|
+
method: "POST",
|
|
447
|
+
headers: _headers,
|
|
448
|
+
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
|
|
449
|
+
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,
|
|
450
|
+
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,
|
|
451
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
452
|
+
});
|
|
453
|
+
if (_response.ok) {
|
|
454
|
+
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
455
|
+
}
|
|
456
|
+
if (_response.error.reason === "status-code") {
|
|
457
|
+
switch (_response.error.statusCode) {
|
|
458
|
+
case 400:
|
|
459
|
+
throw new Paid.BadRequestError(_response.error.body, _response.rawResponse);
|
|
460
|
+
case 403:
|
|
461
|
+
throw new Paid.ForbiddenError(_response.error.body, _response.rawResponse);
|
|
462
|
+
case 404:
|
|
463
|
+
throw new Paid.NotFoundError(_response.error.body, _response.rawResponse);
|
|
464
|
+
default:
|
|
465
|
+
throw new errors.PaidError({
|
|
466
|
+
statusCode: _response.error.statusCode,
|
|
467
|
+
body: _response.error.body,
|
|
468
|
+
rawResponse: _response.rawResponse,
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
switch (_response.error.reason) {
|
|
473
|
+
case "non-json":
|
|
474
|
+
throw new errors.PaidError({
|
|
475
|
+
statusCode: _response.error.statusCode,
|
|
476
|
+
body: _response.error.rawBody,
|
|
477
|
+
rawResponse: _response.rawResponse,
|
|
478
|
+
});
|
|
479
|
+
case "timeout":
|
|
480
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling POST /plans/upgrade.");
|
|
481
|
+
case "unknown":
|
|
482
|
+
throw new errors.PaidError({
|
|
483
|
+
message: _response.error.errorMessage,
|
|
484
|
+
rawResponse: _response.rawResponse,
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
}
|
|
201
489
|
/**
|
|
202
490
|
* @param {string} planGroupId - The ID of the plan group
|
|
203
491
|
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -259,6 +547,8 @@ class Plans {
|
|
|
259
547
|
});
|
|
260
548
|
}
|
|
261
549
|
/**
|
|
550
|
+
* Retrieves all plans in a plan group with their features (product-attribute pairs)
|
|
551
|
+
*
|
|
262
552
|
* @param {string} planGroupId - The ID of the plan group
|
|
263
553
|
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
264
554
|
*
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @example
|
|
3
|
+
* {
|
|
4
|
+
* customerExternalId: "customerExternalId"
|
|
5
|
+
* }
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* {
|
|
9
|
+
* customerExternalId: "customerExternalId"
|
|
10
|
+
* }
|
|
11
|
+
*/
|
|
12
|
+
export interface PlansGetCurrentRequest {
|
|
13
|
+
/** The external ID of the customer */
|
|
14
|
+
customerExternalId: string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @example
|
|
3
|
+
* {
|
|
4
|
+
* customerExternalId: "customerExternalId",
|
|
5
|
+
* currency: "currency"
|
|
6
|
+
* }
|
|
7
|
+
*/
|
|
8
|
+
export interface PlansSubscribeRequest {
|
|
9
|
+
/** The external ID of the customer */
|
|
10
|
+
customerExternalId: string;
|
|
11
|
+
/** The currency code for the order (e.g., "USD", "EUR") */
|
|
12
|
+
currency: string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @example
|
|
3
|
+
* {
|
|
4
|
+
* customerExternalId: "customerExternalId",
|
|
5
|
+
* oldPlanId: "oldPlanId",
|
|
6
|
+
* newPlanId: "newPlanId"
|
|
7
|
+
* }
|
|
8
|
+
*/
|
|
9
|
+
export interface PlansUpgradeRequest {
|
|
10
|
+
/** The external ID of the customer */
|
|
11
|
+
customerExternalId: string;
|
|
12
|
+
/** The ID of the current plan */
|
|
13
|
+
oldPlanId: string;
|
|
14
|
+
/** The ID of the plan to upgrade to */
|
|
15
|
+
newPlanId: string;
|
|
16
|
+
}
|
|
@@ -1 +1,5 @@
|
|
|
1
|
+
export type { PlansGetCurrentRequest } from "./PlansGetCurrentRequest.js";
|
|
1
2
|
export type { PlansGetUsageRequest } from "./PlansGetUsageRequest.js";
|
|
3
|
+
export type { PlansSubscribeRequest } from "./PlansSubscribeRequest.js";
|
|
4
|
+
export type { PlansUnsubscribeRequest } from "./PlansUnsubscribeRequest.js";
|
|
5
|
+
export type { PlansUpgradeRequest } from "./PlansUpgradeRequest.js";
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type * as Paid from "../../../index.js";
|
|
2
|
+
export interface PlansGetCurrentResponse {
|
|
3
|
+
/** The plan details, or null if the customer has no active plan */
|
|
4
|
+
plan?: PlansGetCurrentResponse.Plan;
|
|
5
|
+
/** The subscription details, or null if the customer has no active plan */
|
|
6
|
+
subscription?: PlansGetCurrentResponse.Subscription;
|
|
7
|
+
}
|
|
8
|
+
export declare namespace PlansGetCurrentResponse {
|
|
9
|
+
/**
|
|
10
|
+
* The plan details, or null if the customer has no active plan
|
|
11
|
+
*/
|
|
12
|
+
interface Plan {
|
|
13
|
+
/** The unique identifier of the plan */
|
|
14
|
+
id: string;
|
|
15
|
+
/** The name of the plan */
|
|
16
|
+
name: string;
|
|
17
|
+
/** The description of the plan */
|
|
18
|
+
description?: string;
|
|
19
|
+
/** The type of plan */
|
|
20
|
+
type: Plan.Type;
|
|
21
|
+
pricing: Paid.PlanPricing;
|
|
22
|
+
/** The plan group ID this plan belongs to */
|
|
23
|
+
planGroupId: string;
|
|
24
|
+
/** The ID of the next plan in the sequence */
|
|
25
|
+
nextPlanId?: string;
|
|
26
|
+
/** The ID of the previous plan in the sequence */
|
|
27
|
+
prevPlanId?: string;
|
|
28
|
+
/** The features (product-attribute pairs) included in this plan with usage and limits */
|
|
29
|
+
features: Plan.Features.Item[];
|
|
30
|
+
}
|
|
31
|
+
namespace Plan {
|
|
32
|
+
/** The type of plan */
|
|
33
|
+
const Type: {
|
|
34
|
+
readonly Flat: "flat";
|
|
35
|
+
readonly Usage: "usage";
|
|
36
|
+
readonly Credit: "credit";
|
|
37
|
+
};
|
|
38
|
+
type Type = (typeof Type)[keyof typeof Type];
|
|
39
|
+
type Features = Features.Item[];
|
|
40
|
+
namespace Features {
|
|
41
|
+
interface Item {
|
|
42
|
+
/** The name of the product */
|
|
43
|
+
productName: string;
|
|
44
|
+
/** The name of the product attribute */
|
|
45
|
+
attributeName: string;
|
|
46
|
+
/** The pricing configuration for this feature */
|
|
47
|
+
pricing: Record<string, unknown>;
|
|
48
|
+
/** Current usage and limits for this feature */
|
|
49
|
+
usage: Item.Usage;
|
|
50
|
+
}
|
|
51
|
+
namespace Item {
|
|
52
|
+
/**
|
|
53
|
+
* Current usage and limits for this feature
|
|
54
|
+
*/
|
|
55
|
+
interface Usage {
|
|
56
|
+
/** The event name used to track usage for this feature */
|
|
57
|
+
eventName?: string;
|
|
58
|
+
/** The current usage quantity for this feature on the order */
|
|
59
|
+
currentUsage: number;
|
|
60
|
+
/** The usage limit for this feature (null if unlimited) */
|
|
61
|
+
limit?: number;
|
|
62
|
+
/** Whether this feature has unlimited usage */
|
|
63
|
+
isUnlimited: boolean;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The subscription details, or null if the customer has no active plan
|
|
70
|
+
*/
|
|
71
|
+
interface Subscription {
|
|
72
|
+
/** The ID of the order */
|
|
73
|
+
orderId: string;
|
|
74
|
+
/** The display ID of the order */
|
|
75
|
+
orderDisplayId?: string;
|
|
76
|
+
/** The start date of the subscription */
|
|
77
|
+
startDate: string;
|
|
78
|
+
/** The end date of the subscription (null if ongoing) */
|
|
79
|
+
endDate?: string;
|
|
80
|
+
/** The total usage quantity across all features on this order */
|
|
81
|
+
totalUsage: number;
|
|
82
|
+
}
|
|
83
|
+
}
|