@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
|
@@ -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
|
}
|
|
@@ -162,6 +162,224 @@ export class Plans {
|
|
|
162
162
|
}
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Creates a new order for a customer subscribing to a plan. The order will be created with the plan's products and pricing attributes.
|
|
167
|
+
*
|
|
168
|
+
* @param {string} planId - The ID of the plan
|
|
169
|
+
* @param {Paid.PlansSubscribeRequest} request
|
|
170
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
171
|
+
*
|
|
172
|
+
* @throws {@link Paid.BadRequestError}
|
|
173
|
+
* @throws {@link Paid.ForbiddenError}
|
|
174
|
+
* @throws {@link Paid.NotFoundError}
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* await client.plans.subscribe("planId", {
|
|
178
|
+
* customerExternalId: "customerExternalId",
|
|
179
|
+
* currency: "currency"
|
|
180
|
+
* })
|
|
181
|
+
*/
|
|
182
|
+
subscribe(planId, request, requestOptions) {
|
|
183
|
+
return core.HttpResponsePromise.fromPromise(this.__subscribe(planId, request, requestOptions));
|
|
184
|
+
}
|
|
185
|
+
__subscribe(planId, request, requestOptions) {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
188
|
+
const { customerExternalId, currency } = request;
|
|
189
|
+
const _queryParams = {};
|
|
190
|
+
_queryParams.customerExternalId = customerExternalId;
|
|
191
|
+
_queryParams.currency = currency;
|
|
192
|
+
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
193
|
+
const _response = yield core.fetcher({
|
|
194
|
+
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`),
|
|
195
|
+
method: "POST",
|
|
196
|
+
headers: _headers,
|
|
197
|
+
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
|
|
198
|
+
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,
|
|
199
|
+
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,
|
|
200
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
201
|
+
});
|
|
202
|
+
if (_response.ok) {
|
|
203
|
+
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
204
|
+
}
|
|
205
|
+
if (_response.error.reason === "status-code") {
|
|
206
|
+
switch (_response.error.statusCode) {
|
|
207
|
+
case 400:
|
|
208
|
+
throw new Paid.BadRequestError(_response.error.body, _response.rawResponse);
|
|
209
|
+
case 403:
|
|
210
|
+
throw new Paid.ForbiddenError(_response.error.body, _response.rawResponse);
|
|
211
|
+
case 404:
|
|
212
|
+
throw new Paid.NotFoundError(_response.error.body, _response.rawResponse);
|
|
213
|
+
default:
|
|
214
|
+
throw new errors.PaidError({
|
|
215
|
+
statusCode: _response.error.statusCode,
|
|
216
|
+
body: _response.error.body,
|
|
217
|
+
rawResponse: _response.rawResponse,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
switch (_response.error.reason) {
|
|
222
|
+
case "non-json":
|
|
223
|
+
throw new errors.PaidError({
|
|
224
|
+
statusCode: _response.error.statusCode,
|
|
225
|
+
body: _response.error.rawBody,
|
|
226
|
+
rawResponse: _response.rawResponse,
|
|
227
|
+
});
|
|
228
|
+
case "timeout":
|
|
229
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling POST /plans/{planId}/subscribe.");
|
|
230
|
+
case "unknown":
|
|
231
|
+
throw new errors.PaidError({
|
|
232
|
+
message: _response.error.errorMessage,
|
|
233
|
+
rawResponse: _response.rawResponse,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Cancels the renewal of an active order for a customer's plan subscription. The order will remain active until the cancellation date.
|
|
240
|
+
*
|
|
241
|
+
* @param {string} planId - The ID of the plan
|
|
242
|
+
* @param {Paid.PlansUnsubscribeRequest} request
|
|
243
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
244
|
+
*
|
|
245
|
+
* @throws {@link Paid.BadRequestError}
|
|
246
|
+
* @throws {@link Paid.ForbiddenError}
|
|
247
|
+
* @throws {@link Paid.NotFoundError}
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* await client.plans.unsubscribe("planId", {
|
|
251
|
+
* customerExternalId: "customerExternalId"
|
|
252
|
+
* })
|
|
253
|
+
*/
|
|
254
|
+
unsubscribe(planId, request, requestOptions) {
|
|
255
|
+
return core.HttpResponsePromise.fromPromise(this.__unsubscribe(planId, request, requestOptions));
|
|
256
|
+
}
|
|
257
|
+
__unsubscribe(planId, request, requestOptions) {
|
|
258
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
259
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
260
|
+
const { customerExternalId } = request;
|
|
261
|
+
const _queryParams = {};
|
|
262
|
+
_queryParams.customerExternalId = customerExternalId;
|
|
263
|
+
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
264
|
+
const _response = yield core.fetcher({
|
|
265
|
+
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`),
|
|
266
|
+
method: "POST",
|
|
267
|
+
headers: _headers,
|
|
268
|
+
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
|
|
269
|
+
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,
|
|
270
|
+
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,
|
|
271
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
272
|
+
});
|
|
273
|
+
if (_response.ok) {
|
|
274
|
+
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
275
|
+
}
|
|
276
|
+
if (_response.error.reason === "status-code") {
|
|
277
|
+
switch (_response.error.statusCode) {
|
|
278
|
+
case 400:
|
|
279
|
+
throw new Paid.BadRequestError(_response.error.body, _response.rawResponse);
|
|
280
|
+
case 403:
|
|
281
|
+
throw new Paid.ForbiddenError(_response.error.body, _response.rawResponse);
|
|
282
|
+
case 404:
|
|
283
|
+
throw new Paid.NotFoundError(_response.error.body, _response.rawResponse);
|
|
284
|
+
default:
|
|
285
|
+
throw new errors.PaidError({
|
|
286
|
+
statusCode: _response.error.statusCode,
|
|
287
|
+
body: _response.error.body,
|
|
288
|
+
rawResponse: _response.rawResponse,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
switch (_response.error.reason) {
|
|
293
|
+
case "non-json":
|
|
294
|
+
throw new errors.PaidError({
|
|
295
|
+
statusCode: _response.error.statusCode,
|
|
296
|
+
body: _response.error.rawBody,
|
|
297
|
+
rawResponse: _response.rawResponse,
|
|
298
|
+
});
|
|
299
|
+
case "timeout":
|
|
300
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling POST /plans/{planId}/unsubscribe.");
|
|
301
|
+
case "unknown":
|
|
302
|
+
throw new errors.PaidError({
|
|
303
|
+
message: _response.error.errorMessage,
|
|
304
|
+
rawResponse: _response.rawResponse,
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* 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.
|
|
311
|
+
*
|
|
312
|
+
* @param {Paid.PlansUpgradeRequest} request
|
|
313
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
314
|
+
*
|
|
315
|
+
* @throws {@link Paid.BadRequestError}
|
|
316
|
+
* @throws {@link Paid.ForbiddenError}
|
|
317
|
+
* @throws {@link Paid.NotFoundError}
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* await client.plans.upgrade({
|
|
321
|
+
* customerExternalId: "customerExternalId",
|
|
322
|
+
* oldPlanId: "oldPlanId",
|
|
323
|
+
* newPlanId: "newPlanId"
|
|
324
|
+
* })
|
|
325
|
+
*/
|
|
326
|
+
upgrade(request, requestOptions) {
|
|
327
|
+
return core.HttpResponsePromise.fromPromise(this.__upgrade(request, requestOptions));
|
|
328
|
+
}
|
|
329
|
+
__upgrade(request, requestOptions) {
|
|
330
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
331
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
332
|
+
const { customerExternalId, oldPlanId, newPlanId } = request;
|
|
333
|
+
const _queryParams = {};
|
|
334
|
+
_queryParams.customerExternalId = customerExternalId;
|
|
335
|
+
_queryParams.oldPlanId = oldPlanId;
|
|
336
|
+
_queryParams.newPlanId = newPlanId;
|
|
337
|
+
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
338
|
+
const _response = yield core.fetcher({
|
|
339
|
+
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"),
|
|
340
|
+
method: "POST",
|
|
341
|
+
headers: _headers,
|
|
342
|
+
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
|
|
343
|
+
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,
|
|
344
|
+
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,
|
|
345
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
346
|
+
});
|
|
347
|
+
if (_response.ok) {
|
|
348
|
+
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
349
|
+
}
|
|
350
|
+
if (_response.error.reason === "status-code") {
|
|
351
|
+
switch (_response.error.statusCode) {
|
|
352
|
+
case 400:
|
|
353
|
+
throw new Paid.BadRequestError(_response.error.body, _response.rawResponse);
|
|
354
|
+
case 403:
|
|
355
|
+
throw new Paid.ForbiddenError(_response.error.body, _response.rawResponse);
|
|
356
|
+
case 404:
|
|
357
|
+
throw new Paid.NotFoundError(_response.error.body, _response.rawResponse);
|
|
358
|
+
default:
|
|
359
|
+
throw new errors.PaidError({
|
|
360
|
+
statusCode: _response.error.statusCode,
|
|
361
|
+
body: _response.error.body,
|
|
362
|
+
rawResponse: _response.rawResponse,
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
switch (_response.error.reason) {
|
|
367
|
+
case "non-json":
|
|
368
|
+
throw new errors.PaidError({
|
|
369
|
+
statusCode: _response.error.statusCode,
|
|
370
|
+
body: _response.error.rawBody,
|
|
371
|
+
rawResponse: _response.rawResponse,
|
|
372
|
+
});
|
|
373
|
+
case "timeout":
|
|
374
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling POST /plans/upgrade.");
|
|
375
|
+
case "unknown":
|
|
376
|
+
throw new errors.PaidError({
|
|
377
|
+
message: _response.error.errorMessage,
|
|
378
|
+
rawResponse: _response.rawResponse,
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
165
383
|
/**
|
|
166
384
|
* @param {string} planGroupId - The ID of the plan group
|
|
167
385
|
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -180,7 +398,69 @@ export class Plans {
|
|
|
180
398
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
181
399
|
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
182
400
|
const _response = yield core.fetcher({
|
|
183
|
-
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/
|
|
401
|
+
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)}`),
|
|
402
|
+
method: "GET",
|
|
403
|
+
headers: _headers,
|
|
404
|
+
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
|
|
405
|
+
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,
|
|
406
|
+
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,
|
|
407
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
408
|
+
});
|
|
409
|
+
if (_response.ok) {
|
|
410
|
+
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
411
|
+
}
|
|
412
|
+
if (_response.error.reason === "status-code") {
|
|
413
|
+
switch (_response.error.statusCode) {
|
|
414
|
+
case 403:
|
|
415
|
+
throw new Paid.ForbiddenError(_response.error.body, _response.rawResponse);
|
|
416
|
+
case 404:
|
|
417
|
+
throw new Paid.NotFoundError(_response.error.body, _response.rawResponse);
|
|
418
|
+
default:
|
|
419
|
+
throw new errors.PaidError({
|
|
420
|
+
statusCode: _response.error.statusCode,
|
|
421
|
+
body: _response.error.body,
|
|
422
|
+
rawResponse: _response.rawResponse,
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
switch (_response.error.reason) {
|
|
427
|
+
case "non-json":
|
|
428
|
+
throw new errors.PaidError({
|
|
429
|
+
statusCode: _response.error.statusCode,
|
|
430
|
+
body: _response.error.rawBody,
|
|
431
|
+
rawResponse: _response.rawResponse,
|
|
432
|
+
});
|
|
433
|
+
case "timeout":
|
|
434
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /plans/planGroup/{planGroupId}.");
|
|
435
|
+
case "unknown":
|
|
436
|
+
throw new errors.PaidError({
|
|
437
|
+
message: _response.error.errorMessage,
|
|
438
|
+
rawResponse: _response.rawResponse,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Retrieves all plans in a plan group with their features (product-attribute pairs)
|
|
445
|
+
*
|
|
446
|
+
* @param {string} planGroupId - The ID of the plan group
|
|
447
|
+
* @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
|
|
448
|
+
*
|
|
449
|
+
* @throws {@link Paid.ForbiddenError}
|
|
450
|
+
* @throws {@link Paid.NotFoundError}
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* await client.plans.getGroupPlans("planGroupId")
|
|
454
|
+
*/
|
|
455
|
+
getGroupPlans(planGroupId, requestOptions) {
|
|
456
|
+
return core.HttpResponsePromise.fromPromise(this.__getGroupPlans(planGroupId, requestOptions));
|
|
457
|
+
}
|
|
458
|
+
__getGroupPlans(planGroupId, requestOptions) {
|
|
459
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
460
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
461
|
+
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
462
|
+
const _response = yield core.fetcher({
|
|
463
|
+
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`),
|
|
184
464
|
method: "GET",
|
|
185
465
|
headers: _headers,
|
|
186
466
|
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
|
|
@@ -213,7 +493,7 @@ export class Plans {
|
|
|
213
493
|
rawResponse: _response.rawResponse,
|
|
214
494
|
});
|
|
215
495
|
case "timeout":
|
|
216
|
-
throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /plans/
|
|
496
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /plans/planGroup/{planGroupId}/plans.");
|
|
217
497
|
case "unknown":
|
|
218
498
|
throw new errors.PaidError({
|
|
219
499
|
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.mjs";
|
|
2
|
+
export type { PlansSubscribeRequest } from "./PlansSubscribeRequest.mjs";
|
|
3
|
+
export type { PlansUnsubscribeRequest } from "./PlansUnsubscribeRequest.mjs";
|
|
4
|
+
export type { PlansUpgradeRequest } from "./PlansUpgradeRequest.mjs";
|
|
@@ -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,
|
|
@@ -84,15 +84,15 @@ export class Usage {
|
|
|
84
84
|
* await client.usage.usageRecordBulkV2({
|
|
85
85
|
* signals: [{
|
|
86
86
|
* event_name: "emails_sent",
|
|
87
|
-
* product_id: "
|
|
88
|
-
* customer_id: "
|
|
87
|
+
* product_id: "prod_abc123def",
|
|
88
|
+
* customer_id: "cus_xyz789ghi"
|
|
89
89
|
* }, {
|
|
90
90
|
* event_name: "emails_sent",
|
|
91
91
|
* external_product_id: "acme-product",
|
|
92
92
|
* external_customer_id: "acme-inc"
|
|
93
93
|
* }, {
|
|
94
94
|
* event_name: "meeting_booked",
|
|
95
|
-
* product_id: "
|
|
95
|
+
* product_id: "prod_abc123def",
|
|
96
96
|
* external_customer_id: "acme-inc",
|
|
97
97
|
* data: {
|
|
98
98
|
* "meeting_duration": 30,
|
|
@@ -4,15 +4,15 @@ import type * as Paid from "../../../../index.mjs";
|
|
|
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,2 +1,19 @@
|
|
|
1
1
|
// This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
export
|
|
2
|
+
export var Plan;
|
|
3
|
+
(function (Plan) {
|
|
4
|
+
/** The type of plan (flat for fixed pricing, usage for usage-based, credit for prepaid credits) */
|
|
5
|
+
Plan.Type = {
|
|
6
|
+
Flat: "flat",
|
|
7
|
+
Usage: "usage",
|
|
8
|
+
Credit: "credit",
|
|
9
|
+
};
|
|
10
|
+
let Pricing;
|
|
11
|
+
(function (Pricing) {
|
|
12
|
+
/** The billing frequency for the plan */
|
|
13
|
+
Pricing.BillingFrequency = {
|
|
14
|
+
Monthly: "monthly",
|
|
15
|
+
Quarterly: "quarterly",
|
|
16
|
+
Annual: "annual",
|
|
17
|
+
};
|
|
18
|
+
})(Pricing = Plan.Pricing || (Plan.Pricing = {}));
|
|
19
|
+
})(Plan || (Plan = {}));
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
/** The type of plan (flat for fixed pricing, usage for usage-based, credit for prepaid credits) */
|
|
12
|
+
type: PlanWithFeatures.Type;
|
|
13
|
+
/** The pricing configuration for the plan */
|
|
14
|
+
pricing: PlanWithFeatures.Pricing;
|
|
15
|
+
/** When the plan was created */
|
|
16
|
+
createdAt: string;
|
|
17
|
+
/** When the plan was last updated */
|
|
18
|
+
updatedAt: string;
|
|
19
|
+
/** The ID of the next plan in the sequence */
|
|
20
|
+
nextPlanId?: string;
|
|
21
|
+
/** The ID of the previous plan in the sequence */
|
|
22
|
+
prevPlanId?: string;
|
|
23
|
+
/** The features (product-attribute pairs) included in this plan */
|
|
24
|
+
features: PlanWithFeatures.Features.Item[];
|
|
25
|
+
}
|
|
26
|
+
export declare namespace PlanWithFeatures {
|
|
27
|
+
/** The type of plan (flat for fixed pricing, usage for usage-based, credit for prepaid credits) */
|
|
28
|
+
const Type: {
|
|
29
|
+
readonly Flat: "flat";
|
|
30
|
+
readonly Usage: "usage";
|
|
31
|
+
readonly Credit: "credit";
|
|
32
|
+
};
|
|
33
|
+
type Type = (typeof Type)[keyof typeof Type];
|
|
34
|
+
/**
|
|
35
|
+
* The pricing configuration for the plan
|
|
36
|
+
*/
|
|
37
|
+
interface Pricing {
|
|
38
|
+
/** The currency code (e.g., "USD", "EUR") */
|
|
39
|
+
currency: string;
|
|
40
|
+
/** The fixed amount for flat plans (in smallest currency unit, e.g., cents) */
|
|
41
|
+
amount?: number;
|
|
42
|
+
/** The billing frequency for the plan */
|
|
43
|
+
billingFrequency: Pricing.BillingFrequency;
|
|
44
|
+
/** Custom billing frequency in months (if not using standard frequencies) */
|
|
45
|
+
billingFrequencyCustomMonths?: number;
|
|
46
|
+
}
|
|
47
|
+
namespace Pricing {
|
|
48
|
+
/** The billing frequency for the plan */
|
|
49
|
+
const BillingFrequency: {
|
|
50
|
+
readonly Monthly: "monthly";
|
|
51
|
+
readonly Quarterly: "quarterly";
|
|
52
|
+
readonly Annual: "annual";
|
|
53
|
+
};
|
|
54
|
+
type BillingFrequency = (typeof BillingFrequency)[keyof typeof BillingFrequency];
|
|
55
|
+
}
|
|
56
|
+
type Features = Features.Item[];
|
|
57
|
+
namespace Features {
|
|
58
|
+
interface Item {
|
|
59
|
+
/** The name of the product */
|
|
60
|
+
productName: string;
|
|
61
|
+
/** The name of the product attribute */
|
|
62
|
+
attributeName: string;
|
|
63
|
+
/** The pricing configuration for this feature */
|
|
64
|
+
pricing: Record<string, unknown>;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|