@paid-ai/paid-node 1.0.1-alpha0 → 1.0.1-alpha2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Client.js +2 -2
- package/dist/cjs/api/resources/plans/client/Client.d.ts +70 -0
- package/dist/cjs/api/resources/plans/client/Client.js +282 -2
- 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 +3 -0
- 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/Plan.d.ts +33 -0
- package/dist/cjs/api/types/Plan.js +19 -0
- package/dist/cjs/api/types/PlanWithFeatures.d.ts +67 -0
- package/dist/cjs/api/types/PlanWithFeatures.js +22 -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 +6 -1
- package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +75 -0
- package/dist/cjs/integrations/adapters/nextjs/routes.js +101 -0
- package/dist/cjs/integrations/controllers/index.d.ts +1 -0
- package/dist/cjs/integrations/controllers/index.js +13 -1
- package/dist/cjs/integrations/controllers/orders.js +52 -17
- package/dist/cjs/integrations/controllers/plans.d.ts +208 -0
- package/dist/cjs/integrations/controllers/plans.js +365 -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 +70 -0
- package/dist/esm/api/resources/plans/client/Client.mjs +282 -2
- 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 +3 -0
- 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/Plan.d.mts +33 -0
- package/dist/esm/api/types/Plan.mjs +18 -1
- package/dist/esm/api/types/PlanWithFeatures.d.mts +67 -0
- package/dist/esm/api/types/PlanWithFeatures.mjs +19 -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 +75 -0
- package/dist/esm/integrations/adapters/nextjs/routes.mjs +96 -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 +208 -0
- package/dist/esm/integrations/controllers/plans.mjs +353 -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 +280 -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-alpha2",
|
|
54
|
+
"User-Agent": "@paid-ai/paid-node/1.0.1-alpha2",
|
|
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) });
|
|
@@ -42,6 +42,62 @@ export declare class Plans {
|
|
|
42
42
|
*/
|
|
43
43
|
getUsage(planId: string, request: Paid.PlansGetUsageRequest, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.UsageSummariesResponse>;
|
|
44
44
|
private __getUsage;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new order for a customer subscribing to a plan. The order will be created with the plan's products and pricing attributes.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} planId - The ID of the plan
|
|
49
|
+
* @param {Paid.PlansSubscribeRequest} request
|
|
50
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
51
|
+
*
|
|
52
|
+
* @throws {@link Paid.BadRequestError}
|
|
53
|
+
* @throws {@link Paid.ForbiddenError}
|
|
54
|
+
* @throws {@link Paid.NotFoundError}
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* await client.plans.subscribe("planId", {
|
|
58
|
+
* customerExternalId: "customerExternalId",
|
|
59
|
+
* currency: "currency"
|
|
60
|
+
* })
|
|
61
|
+
*/
|
|
62
|
+
subscribe(planId: string, request: Paid.PlansSubscribeRequest, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.Order>;
|
|
63
|
+
private __subscribe;
|
|
64
|
+
/**
|
|
65
|
+
* Cancels the renewal of an active order for a customer's plan subscription. The order will remain active until the cancellation date.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} planId - The ID of the plan
|
|
68
|
+
* @param {Paid.PlansUnsubscribeRequest} request
|
|
69
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
70
|
+
*
|
|
71
|
+
* @throws {@link Paid.BadRequestError}
|
|
72
|
+
* @throws {@link Paid.ForbiddenError}
|
|
73
|
+
* @throws {@link Paid.NotFoundError}
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* await client.plans.unsubscribe("planId", {
|
|
77
|
+
* customerExternalId: "customerExternalId"
|
|
78
|
+
* })
|
|
79
|
+
*/
|
|
80
|
+
unsubscribe(planId: string, request: Paid.PlansUnsubscribeRequest, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.CancelRenewalResponse>;
|
|
81
|
+
private __unsubscribe;
|
|
82
|
+
/**
|
|
83
|
+
* 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.
|
|
84
|
+
*
|
|
85
|
+
* @param {Paid.PlansUpgradeRequest} 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.upgrade({
|
|
94
|
+
* customerExternalId: "customerExternalId",
|
|
95
|
+
* oldPlanId: "oldPlanId",
|
|
96
|
+
* newPlanId: "newPlanId"
|
|
97
|
+
* })
|
|
98
|
+
*/
|
|
99
|
+
upgrade(request: Paid.PlansUpgradeRequest, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.ProrationUpgradeResponse>;
|
|
100
|
+
private __upgrade;
|
|
45
101
|
/**
|
|
46
102
|
* @param {string} planGroupId - The ID of the plan group
|
|
47
103
|
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -54,5 +110,19 @@ export declare class Plans {
|
|
|
54
110
|
*/
|
|
55
111
|
getGroupById(planGroupId: string, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.PlanGroup>;
|
|
56
112
|
private __getGroupById;
|
|
113
|
+
/**
|
|
114
|
+
* Retrieves all plans in a plan group with their features (product-attribute pairs)
|
|
115
|
+
*
|
|
116
|
+
* @param {string} planGroupId - The ID of the plan group
|
|
117
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
118
|
+
*
|
|
119
|
+
* @throws {@link Paid.ForbiddenError}
|
|
120
|
+
* @throws {@link Paid.NotFoundError}
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* await client.plans.getGroupPlans("planGroupId")
|
|
124
|
+
*/
|
|
125
|
+
getGroupPlans(planGroupId: string, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.PlanWithFeatures[]>;
|
|
126
|
+
private __getGroupPlans;
|
|
57
127
|
protected _getAuthorizationHeader(): Promise<string | undefined>;
|
|
58
128
|
}
|
|
@@ -198,6 +198,224 @@ class Plans {
|
|
|
198
198
|
}
|
|
199
199
|
});
|
|
200
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Creates a new order for a customer subscribing to a plan. The order will be created with the plan's products and pricing attributes.
|
|
203
|
+
*
|
|
204
|
+
* @param {string} planId - The ID of the plan
|
|
205
|
+
* @param {Paid.PlansSubscribeRequest} request
|
|
206
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
207
|
+
*
|
|
208
|
+
* @throws {@link Paid.BadRequestError}
|
|
209
|
+
* @throws {@link Paid.ForbiddenError}
|
|
210
|
+
* @throws {@link Paid.NotFoundError}
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* await client.plans.subscribe("planId", {
|
|
214
|
+
* customerExternalId: "customerExternalId",
|
|
215
|
+
* currency: "currency"
|
|
216
|
+
* })
|
|
217
|
+
*/
|
|
218
|
+
subscribe(planId, request, requestOptions) {
|
|
219
|
+
return core.HttpResponsePromise.fromPromise(this.__subscribe(planId, request, requestOptions));
|
|
220
|
+
}
|
|
221
|
+
__subscribe(planId, request, requestOptions) {
|
|
222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
224
|
+
const { customerExternalId, currency } = request;
|
|
225
|
+
const _queryParams = {};
|
|
226
|
+
_queryParams.customerExternalId = customerExternalId;
|
|
227
|
+
_queryParams.currency = currency;
|
|
228
|
+
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);
|
|
229
|
+
const _response = yield core.fetcher({
|
|
230
|
+
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`),
|
|
231
|
+
method: "POST",
|
|
232
|
+
headers: _headers,
|
|
233
|
+
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
|
|
234
|
+
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,
|
|
235
|
+
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,
|
|
236
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
237
|
+
});
|
|
238
|
+
if (_response.ok) {
|
|
239
|
+
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
240
|
+
}
|
|
241
|
+
if (_response.error.reason === "status-code") {
|
|
242
|
+
switch (_response.error.statusCode) {
|
|
243
|
+
case 400:
|
|
244
|
+
throw new Paid.BadRequestError(_response.error.body, _response.rawResponse);
|
|
245
|
+
case 403:
|
|
246
|
+
throw new Paid.ForbiddenError(_response.error.body, _response.rawResponse);
|
|
247
|
+
case 404:
|
|
248
|
+
throw new Paid.NotFoundError(_response.error.body, _response.rawResponse);
|
|
249
|
+
default:
|
|
250
|
+
throw new errors.PaidError({
|
|
251
|
+
statusCode: _response.error.statusCode,
|
|
252
|
+
body: _response.error.body,
|
|
253
|
+
rawResponse: _response.rawResponse,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
switch (_response.error.reason) {
|
|
258
|
+
case "non-json":
|
|
259
|
+
throw new errors.PaidError({
|
|
260
|
+
statusCode: _response.error.statusCode,
|
|
261
|
+
body: _response.error.rawBody,
|
|
262
|
+
rawResponse: _response.rawResponse,
|
|
263
|
+
});
|
|
264
|
+
case "timeout":
|
|
265
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling POST /plans/{planId}/subscribe.");
|
|
266
|
+
case "unknown":
|
|
267
|
+
throw new errors.PaidError({
|
|
268
|
+
message: _response.error.errorMessage,
|
|
269
|
+
rawResponse: _response.rawResponse,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Cancels the renewal of an active order for a customer's plan subscription. The order will remain active until the cancellation date.
|
|
276
|
+
*
|
|
277
|
+
* @param {string} planId - The ID of the plan
|
|
278
|
+
* @param {Paid.PlansUnsubscribeRequest} request
|
|
279
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
280
|
+
*
|
|
281
|
+
* @throws {@link Paid.BadRequestError}
|
|
282
|
+
* @throws {@link Paid.ForbiddenError}
|
|
283
|
+
* @throws {@link Paid.NotFoundError}
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* await client.plans.unsubscribe("planId", {
|
|
287
|
+
* customerExternalId: "customerExternalId"
|
|
288
|
+
* })
|
|
289
|
+
*/
|
|
290
|
+
unsubscribe(planId, request, requestOptions) {
|
|
291
|
+
return core.HttpResponsePromise.fromPromise(this.__unsubscribe(planId, request, requestOptions));
|
|
292
|
+
}
|
|
293
|
+
__unsubscribe(planId, request, requestOptions) {
|
|
294
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
295
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
296
|
+
const { customerExternalId } = request;
|
|
297
|
+
const _queryParams = {};
|
|
298
|
+
_queryParams.customerExternalId = customerExternalId;
|
|
299
|
+
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);
|
|
300
|
+
const _response = yield core.fetcher({
|
|
301
|
+
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`),
|
|
302
|
+
method: "POST",
|
|
303
|
+
headers: _headers,
|
|
304
|
+
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
|
|
305
|
+
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,
|
|
306
|
+
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,
|
|
307
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
308
|
+
});
|
|
309
|
+
if (_response.ok) {
|
|
310
|
+
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
311
|
+
}
|
|
312
|
+
if (_response.error.reason === "status-code") {
|
|
313
|
+
switch (_response.error.statusCode) {
|
|
314
|
+
case 400:
|
|
315
|
+
throw new Paid.BadRequestError(_response.error.body, _response.rawResponse);
|
|
316
|
+
case 403:
|
|
317
|
+
throw new Paid.ForbiddenError(_response.error.body, _response.rawResponse);
|
|
318
|
+
case 404:
|
|
319
|
+
throw new Paid.NotFoundError(_response.error.body, _response.rawResponse);
|
|
320
|
+
default:
|
|
321
|
+
throw new errors.PaidError({
|
|
322
|
+
statusCode: _response.error.statusCode,
|
|
323
|
+
body: _response.error.body,
|
|
324
|
+
rawResponse: _response.rawResponse,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
switch (_response.error.reason) {
|
|
329
|
+
case "non-json":
|
|
330
|
+
throw new errors.PaidError({
|
|
331
|
+
statusCode: _response.error.statusCode,
|
|
332
|
+
body: _response.error.rawBody,
|
|
333
|
+
rawResponse: _response.rawResponse,
|
|
334
|
+
});
|
|
335
|
+
case "timeout":
|
|
336
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling POST /plans/{planId}/unsubscribe.");
|
|
337
|
+
case "unknown":
|
|
338
|
+
throw new errors.PaidError({
|
|
339
|
+
message: _response.error.errorMessage,
|
|
340
|
+
rawResponse: _response.rawResponse,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* 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.
|
|
347
|
+
*
|
|
348
|
+
* @param {Paid.PlansUpgradeRequest} 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.upgrade({
|
|
357
|
+
* customerExternalId: "customerExternalId",
|
|
358
|
+
* oldPlanId: "oldPlanId",
|
|
359
|
+
* newPlanId: "newPlanId"
|
|
360
|
+
* })
|
|
361
|
+
*/
|
|
362
|
+
upgrade(request, requestOptions) {
|
|
363
|
+
return core.HttpResponsePromise.fromPromise(this.__upgrade(request, requestOptions));
|
|
364
|
+
}
|
|
365
|
+
__upgrade(request, requestOptions) {
|
|
366
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
367
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
368
|
+
const { customerExternalId, oldPlanId, newPlanId } = request;
|
|
369
|
+
const _queryParams = {};
|
|
370
|
+
_queryParams.customerExternalId = customerExternalId;
|
|
371
|
+
_queryParams.oldPlanId = oldPlanId;
|
|
372
|
+
_queryParams.newPlanId = newPlanId;
|
|
373
|
+
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);
|
|
374
|
+
const _response = yield core.fetcher({
|
|
375
|
+
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"),
|
|
376
|
+
method: "POST",
|
|
377
|
+
headers: _headers,
|
|
378
|
+
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
|
|
379
|
+
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,
|
|
380
|
+
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,
|
|
381
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
382
|
+
});
|
|
383
|
+
if (_response.ok) {
|
|
384
|
+
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
385
|
+
}
|
|
386
|
+
if (_response.error.reason === "status-code") {
|
|
387
|
+
switch (_response.error.statusCode) {
|
|
388
|
+
case 400:
|
|
389
|
+
throw new Paid.BadRequestError(_response.error.body, _response.rawResponse);
|
|
390
|
+
case 403:
|
|
391
|
+
throw new Paid.ForbiddenError(_response.error.body, _response.rawResponse);
|
|
392
|
+
case 404:
|
|
393
|
+
throw new Paid.NotFoundError(_response.error.body, _response.rawResponse);
|
|
394
|
+
default:
|
|
395
|
+
throw new errors.PaidError({
|
|
396
|
+
statusCode: _response.error.statusCode,
|
|
397
|
+
body: _response.error.body,
|
|
398
|
+
rawResponse: _response.rawResponse,
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
switch (_response.error.reason) {
|
|
403
|
+
case "non-json":
|
|
404
|
+
throw new errors.PaidError({
|
|
405
|
+
statusCode: _response.error.statusCode,
|
|
406
|
+
body: _response.error.rawBody,
|
|
407
|
+
rawResponse: _response.rawResponse,
|
|
408
|
+
});
|
|
409
|
+
case "timeout":
|
|
410
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling POST /plans/upgrade.");
|
|
411
|
+
case "unknown":
|
|
412
|
+
throw new errors.PaidError({
|
|
413
|
+
message: _response.error.errorMessage,
|
|
414
|
+
rawResponse: _response.rawResponse,
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
}
|
|
201
419
|
/**
|
|
202
420
|
* @param {string} planGroupId - The ID of the plan group
|
|
203
421
|
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -216,7 +434,69 @@ class Plans {
|
|
|
216
434
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
217
435
|
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
436
|
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/
|
|
437
|
+
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)}`),
|
|
438
|
+
method: "GET",
|
|
439
|
+
headers: _headers,
|
|
440
|
+
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
|
|
441
|
+
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,
|
|
442
|
+
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,
|
|
443
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
444
|
+
});
|
|
445
|
+
if (_response.ok) {
|
|
446
|
+
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
447
|
+
}
|
|
448
|
+
if (_response.error.reason === "status-code") {
|
|
449
|
+
switch (_response.error.statusCode) {
|
|
450
|
+
case 403:
|
|
451
|
+
throw new Paid.ForbiddenError(_response.error.body, _response.rawResponse);
|
|
452
|
+
case 404:
|
|
453
|
+
throw new Paid.NotFoundError(_response.error.body, _response.rawResponse);
|
|
454
|
+
default:
|
|
455
|
+
throw new errors.PaidError({
|
|
456
|
+
statusCode: _response.error.statusCode,
|
|
457
|
+
body: _response.error.body,
|
|
458
|
+
rawResponse: _response.rawResponse,
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
switch (_response.error.reason) {
|
|
463
|
+
case "non-json":
|
|
464
|
+
throw new errors.PaidError({
|
|
465
|
+
statusCode: _response.error.statusCode,
|
|
466
|
+
body: _response.error.rawBody,
|
|
467
|
+
rawResponse: _response.rawResponse,
|
|
468
|
+
});
|
|
469
|
+
case "timeout":
|
|
470
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /plans/planGroup/{planGroupId}.");
|
|
471
|
+
case "unknown":
|
|
472
|
+
throw new errors.PaidError({
|
|
473
|
+
message: _response.error.errorMessage,
|
|
474
|
+
rawResponse: _response.rawResponse,
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Retrieves all plans in a plan group with their features (product-attribute pairs)
|
|
481
|
+
*
|
|
482
|
+
* @param {string} planGroupId - The ID of the plan group
|
|
483
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
484
|
+
*
|
|
485
|
+
* @throws {@link Paid.ForbiddenError}
|
|
486
|
+
* @throws {@link Paid.NotFoundError}
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* await client.plans.getGroupPlans("planGroupId")
|
|
490
|
+
*/
|
|
491
|
+
getGroupPlans(planGroupId, requestOptions) {
|
|
492
|
+
return core.HttpResponsePromise.fromPromise(this.__getGroupPlans(planGroupId, requestOptions));
|
|
493
|
+
}
|
|
494
|
+
__getGroupPlans(planGroupId, requestOptions) {
|
|
495
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
496
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
497
|
+
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);
|
|
498
|
+
const _response = yield core.fetcher({
|
|
499
|
+
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`),
|
|
220
500
|
method: "GET",
|
|
221
501
|
headers: _headers,
|
|
222
502
|
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
|
|
@@ -249,7 +529,7 @@ class Plans {
|
|
|
249
529
|
rawResponse: _response.rawResponse,
|
|
250
530
|
});
|
|
251
531
|
case "timeout":
|
|
252
|
-
throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /plans/
|
|
532
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /plans/planGroup/{planGroupId}/plans.");
|
|
253
533
|
case "unknown":
|
|
254
534
|
throw new errors.PaidError({
|
|
255
535
|
message: _response.error.errorMessage,
|
|
@@ -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,4 @@
|
|
|
1
1
|
export type { PlansGetUsageRequest } from "./PlansGetUsageRequest.js";
|
|
2
|
+
export type { PlansSubscribeRequest } from "./PlansSubscribeRequest.js";
|
|
3
|
+
export type { PlansUnsubscribeRequest } from "./PlansUnsubscribeRequest.js";
|
|
4
|
+
export type { PlansUpgradeRequest } from "./PlansUpgradeRequest.js";
|
|
@@ -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,
|
|
@@ -13,6 +13,10 @@ export interface Plan {
|
|
|
13
13
|
name: string;
|
|
14
14
|
/** The description of the plan */
|
|
15
15
|
description?: string;
|
|
16
|
+
/** The type of plan (flat for fixed pricing, usage for usage-based, credit for prepaid credits) */
|
|
17
|
+
type: Plan.Type;
|
|
18
|
+
/** The pricing configuration for the plan */
|
|
19
|
+
pricing: Plan.Pricing;
|
|
16
20
|
/** The ID of the next plan in the sequence */
|
|
17
21
|
nextPlanId?: string;
|
|
18
22
|
/** The ID of the previous plan in the sequence */
|
|
@@ -25,6 +29,35 @@ export interface Plan {
|
|
|
25
29
|
planProducts?: Plan.PlanProducts.Item[];
|
|
26
30
|
}
|
|
27
31
|
export declare namespace Plan {
|
|
32
|
+
/** The type of plan (flat for fixed pricing, usage for usage-based, credit for prepaid credits) */
|
|
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
|
+
/**
|
|
40
|
+
* The pricing configuration for the plan
|
|
41
|
+
*/
|
|
42
|
+
interface Pricing {
|
|
43
|
+
/** The currency code (e.g., "USD", "EUR") */
|
|
44
|
+
currency: string;
|
|
45
|
+
/** The fixed amount for flat plans (in smallest currency unit, e.g., cents) */
|
|
46
|
+
amount?: number;
|
|
47
|
+
/** The billing frequency for the plan */
|
|
48
|
+
billingFrequency: Pricing.BillingFrequency;
|
|
49
|
+
/** Custom billing frequency in months (if not using standard frequencies) */
|
|
50
|
+
billingFrequencyCustomMonths?: number;
|
|
51
|
+
}
|
|
52
|
+
namespace Pricing {
|
|
53
|
+
/** The billing frequency for the plan */
|
|
54
|
+
const BillingFrequency: {
|
|
55
|
+
readonly Monthly: "monthly";
|
|
56
|
+
readonly Quarterly: "quarterly";
|
|
57
|
+
readonly Annual: "annual";
|
|
58
|
+
};
|
|
59
|
+
type BillingFrequency = (typeof BillingFrequency)[keyof typeof BillingFrequency];
|
|
60
|
+
}
|
|
28
61
|
type PlanProducts = PlanProducts.Item[];
|
|
29
62
|
namespace PlanProducts {
|
|
30
63
|
interface Item {
|
|
@@ -1,3 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// This file was auto-generated by Fern from our API Definition.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Plan = void 0;
|
|
5
|
+
var Plan;
|
|
6
|
+
(function (Plan) {
|
|
7
|
+
/** The type of plan (flat for fixed pricing, usage for usage-based, credit for prepaid credits) */
|
|
8
|
+
Plan.Type = {
|
|
9
|
+
Flat: "flat",
|
|
10
|
+
Usage: "usage",
|
|
11
|
+
Credit: "credit",
|
|
12
|
+
};
|
|
13
|
+
let Pricing;
|
|
14
|
+
(function (Pricing) {
|
|
15
|
+
/** The billing frequency for the plan */
|
|
16
|
+
Pricing.BillingFrequency = {
|
|
17
|
+
Monthly: "monthly",
|
|
18
|
+
Quarterly: "quarterly",
|
|
19
|
+
Annual: "annual",
|
|
20
|
+
};
|
|
21
|
+
})(Pricing = Plan.Pricing || (Plan.Pricing = {}));
|
|
22
|
+
})(Plan || (exports.Plan = Plan = {}));
|