celitech-sdk 2.0.4 → 2.0.7
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 +3 -3
- package/dist/index.d.ts +204 -211
- package/dist/index.js +128 -31
- package/dist/index.mjs +128 -31
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -382,7 +382,7 @@ var TransportHookAdapter = class {
|
|
|
382
382
|
function getContentTypeDefinition(contentType) {
|
|
383
383
|
const ct = contentType.toLowerCase();
|
|
384
384
|
if (ct.startsWith("application/") && ct.includes("xml")) {
|
|
385
|
-
return "
|
|
385
|
+
return "text" /* Text */;
|
|
386
386
|
}
|
|
387
387
|
if (ct === "application/x-www-form-urlencoded") {
|
|
388
388
|
return "form" /* FormUrlEncoded */;
|
|
@@ -455,7 +455,7 @@ var HookHandler = class {
|
|
|
455
455
|
} catch (e) {
|
|
456
456
|
}
|
|
457
457
|
}
|
|
458
|
-
const customError =
|
|
458
|
+
const customError = error.error.from((json == null ? void 0 : json.message) || "", json);
|
|
459
459
|
customError.metadata = response.metadata;
|
|
460
460
|
customError.throw();
|
|
461
461
|
}
|
|
@@ -592,7 +592,6 @@ var ResponseValidationHandler = class {
|
|
|
592
592
|
["image" /* Image */]: this.decodeFile,
|
|
593
593
|
["multipartFormData" /* MultipartFormData */]: this.decodeMultipartFormData,
|
|
594
594
|
["text" /* Text */]: this.decodeText,
|
|
595
|
-
["xml" /* Xml */]: this.decodeText,
|
|
596
595
|
["form" /* FormUrlEncoded */]: this.decodeFormUrlEncoded,
|
|
597
596
|
["eventStream" /* EventStream */]: this.decodeEventStream
|
|
598
597
|
};
|
|
@@ -808,7 +807,7 @@ var RequestValidationHandler = class {
|
|
|
808
807
|
}
|
|
809
808
|
throw error;
|
|
810
809
|
}
|
|
811
|
-
} else if (request.requestContentType === "
|
|
810
|
+
} else if (request.requestContentType === "text" /* Text */ || request.requestContentType === "image" /* Image */ || request.requestContentType === "binary" /* Binary */) {
|
|
812
811
|
request.body = request.body;
|
|
813
812
|
} else if (request.requestContentType === "form" /* FormUrlEncoded */) {
|
|
814
813
|
request.body = this.toFormUrlEncoded(request);
|
|
@@ -844,7 +843,7 @@ var RequestValidationHandler = class {
|
|
|
844
843
|
});
|
|
845
844
|
return params.toString();
|
|
846
845
|
}
|
|
847
|
-
if (typeof validatedBody === "object" && !Array.isArray(validatedBody)) {
|
|
846
|
+
if (typeof validatedBody === "object" && validatedBody !== null && !Array.isArray(validatedBody)) {
|
|
848
847
|
const params = new URLSearchParams();
|
|
849
848
|
for (const [key, value] of Object.entries(validatedBody)) {
|
|
850
849
|
if (value != null) {
|
|
@@ -1060,10 +1059,7 @@ var RequestFetchAdapter = class {
|
|
|
1060
1059
|
return headers;
|
|
1061
1060
|
}
|
|
1062
1061
|
toArrayBuffer(uint8Array) {
|
|
1063
|
-
return uint8Array.buffer
|
|
1064
|
-
uint8Array.byteOffset,
|
|
1065
|
-
uint8Array.byteOffset + uint8Array.byteLength
|
|
1066
|
-
);
|
|
1062
|
+
return new Uint8Array(uint8Array).buffer;
|
|
1067
1063
|
}
|
|
1068
1064
|
};
|
|
1069
1065
|
|
|
@@ -1113,7 +1109,7 @@ var RetryHandler = class {
|
|
|
1113
1109
|
if (!this.shouldRetry(error, request) || attempt === maxAttempts) {
|
|
1114
1110
|
throw error;
|
|
1115
1111
|
}
|
|
1116
|
-
const delayMs = this.calculateDelay(attempt, request);
|
|
1112
|
+
const delayMs = this.calculateDelay(attempt, request, error);
|
|
1117
1113
|
await this.delay(delayMs);
|
|
1118
1114
|
}
|
|
1119
1115
|
}
|
|
@@ -1140,7 +1136,7 @@ var RetryHandler = class {
|
|
|
1140
1136
|
if (!this.shouldRetry(error, request) || attempt === maxAttempts) {
|
|
1141
1137
|
throw error;
|
|
1142
1138
|
}
|
|
1143
|
-
const delayMs = this.calculateDelay(attempt, request);
|
|
1139
|
+
const delayMs = this.calculateDelay(attempt, request, error);
|
|
1144
1140
|
await this.delay(delayMs);
|
|
1145
1141
|
}
|
|
1146
1142
|
}
|
|
@@ -1173,18 +1169,25 @@ var RetryHandler = class {
|
|
|
1173
1169
|
return shouldRetryStatus && shouldRetryMethod;
|
|
1174
1170
|
}
|
|
1175
1171
|
/**
|
|
1176
|
-
* Calculates the delay before the next retry attempt
|
|
1177
|
-
*
|
|
1172
|
+
* Calculates the delay before the next retry attempt. A server rate-limit timing header
|
|
1173
|
+
* (Retry-After / X-RateLimit-Reset) on the error, when present, overrides the computed
|
|
1174
|
+
* exponential backoff; otherwise falls back to exponential backoff with optional jitter.
|
|
1178
1175
|
* @param attempt - The current retry attempt number (1-indexed)
|
|
1179
1176
|
* @param request - The HTTP request being retried
|
|
1177
|
+
* @param error - The error that triggered the retry (carries the response headers)
|
|
1180
1178
|
* @returns The delay in milliseconds, capped at the configured maximum delay
|
|
1181
1179
|
*/
|
|
1182
|
-
calculateDelay(attempt, request) {
|
|
1183
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1184
|
-
const
|
|
1185
|
-
const
|
|
1186
|
-
|
|
1187
|
-
|
|
1180
|
+
calculateDelay(attempt, request, error) {
|
|
1181
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1182
|
+
const maxRetryAfterDelay = (_b = (_a = request.config.retry) == null ? void 0 : _a.maxRetryAfterDelayMs) != null ? _b : 6e4;
|
|
1183
|
+
const headerDelay = this.retryAfterDelay(error, maxRetryAfterDelay);
|
|
1184
|
+
if (headerDelay !== null) {
|
|
1185
|
+
return Math.floor(headerDelay);
|
|
1186
|
+
}
|
|
1187
|
+
const baseDelay = (_d = (_c = request.config.retry) == null ? void 0 : _c.delayMs) != null ? _d : 150;
|
|
1188
|
+
const backoffFactor = (_f = (_e = request.config.retry) == null ? void 0 : _e.backoffFactor) != null ? _f : 2;
|
|
1189
|
+
const maxDelay = (_h = (_g = request.config.retry) == null ? void 0 : _g.maxDelayMs) != null ? _h : 5e3;
|
|
1190
|
+
const jitter = (_j = (_i = request.config.retry) == null ? void 0 : _i.jitterMs) != null ? _j : 50;
|
|
1188
1191
|
let delay = baseDelay * Math.pow(backoffFactor, attempt - 1);
|
|
1189
1192
|
delay = Math.min(delay, maxDelay);
|
|
1190
1193
|
if (jitter > 0) {
|
|
@@ -1192,6 +1195,65 @@ var RetryHandler = class {
|
|
|
1192
1195
|
}
|
|
1193
1196
|
return Math.floor(delay);
|
|
1194
1197
|
}
|
|
1198
|
+
/**
|
|
1199
|
+
* Returns the server-directed retry delay (ms) from rate-limit response headers,
|
|
1200
|
+
* honoring Retry-After (delta-seconds or HTTP-date) and, when absent, X-RateLimit-Reset
|
|
1201
|
+
* (epoch seconds), clamped to maxRetryAfterDelayMs. Returns null when no usable header is
|
|
1202
|
+
* present so the caller falls back to the computed exponential backoff.
|
|
1203
|
+
* @param error - The error that triggered the retry (carries the response headers)
|
|
1204
|
+
* @param maxRetryAfterDelayMs - Upper bound for a server-directed delay
|
|
1205
|
+
* @returns The delay in milliseconds, or null to use exponential backoff
|
|
1206
|
+
*/
|
|
1207
|
+
retryAfterDelay(error, maxRetryAfterDelayMs) {
|
|
1208
|
+
var _a;
|
|
1209
|
+
const headers = (_a = error == null ? void 0 : error.metadata) == null ? void 0 : _a.headers;
|
|
1210
|
+
if (!headers || maxRetryAfterDelayMs <= 0) {
|
|
1211
|
+
return null;
|
|
1212
|
+
}
|
|
1213
|
+
const retryAfterMs = headers["retry-after-ms"];
|
|
1214
|
+
if (retryAfterMs !== void 0 && /^\d+(\.\d+)?$/.test(retryAfterMs.trim())) {
|
|
1215
|
+
return Math.min(Number(retryAfterMs.trim()), maxRetryAfterDelayMs);
|
|
1216
|
+
}
|
|
1217
|
+
const seconds = this.parseRetryAfter(headers["retry-after"]);
|
|
1218
|
+
if (seconds !== null) {
|
|
1219
|
+
return Math.min(Math.max(seconds * 1e3, 0), maxRetryAfterDelayMs);
|
|
1220
|
+
}
|
|
1221
|
+
const reset = headers["x-ratelimit-reset"];
|
|
1222
|
+
if (reset !== void 0 && reset.trim() !== "") {
|
|
1223
|
+
const epoch = Number(reset);
|
|
1224
|
+
if (Number.isFinite(epoch)) {
|
|
1225
|
+
const deltaMs = epoch * 1e3 - Date.now();
|
|
1226
|
+
if (deltaMs > 0) {
|
|
1227
|
+
return Math.min(deltaMs, maxRetryAfterDelayMs);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
return null;
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* Parses a Retry-After header value: an integer/float number of seconds, or an HTTP-date
|
|
1235
|
+
* (a past date yields 0). Returns the delay in seconds, or null if empty/unparseable.
|
|
1236
|
+
* @param value - The raw Retry-After header value
|
|
1237
|
+
* @returns The delay in seconds, or null
|
|
1238
|
+
*/
|
|
1239
|
+
parseRetryAfter(value) {
|
|
1240
|
+
if (value === void 0) {
|
|
1241
|
+
return null;
|
|
1242
|
+
}
|
|
1243
|
+
const trimmed = value.trim();
|
|
1244
|
+
if (trimmed === "") {
|
|
1245
|
+
return null;
|
|
1246
|
+
}
|
|
1247
|
+
if (/^\d+(\.\d+)?$/.test(trimmed)) {
|
|
1248
|
+
return Number(trimmed);
|
|
1249
|
+
}
|
|
1250
|
+
const dateMs = Date.parse(trimmed);
|
|
1251
|
+
if (!Number.isNaN(dateMs)) {
|
|
1252
|
+
const deltaSeconds = (dateMs - Date.now()) / 1e3;
|
|
1253
|
+
return deltaSeconds > 0 ? deltaSeconds : 0;
|
|
1254
|
+
}
|
|
1255
|
+
return null;
|
|
1256
|
+
}
|
|
1195
1257
|
/**
|
|
1196
1258
|
* Delays execution for a specified duration before retrying.
|
|
1197
1259
|
* @param delayMs - The delay in milliseconds
|
|
@@ -1553,7 +1615,7 @@ var QuerySerializer = class extends Serializer {
|
|
|
1553
1615
|
}
|
|
1554
1616
|
const query = [];
|
|
1555
1617
|
queryParams.forEach((param) => {
|
|
1556
|
-
if (param.value === void 0) {
|
|
1618
|
+
if (param.value === void 0 || param.value === null) {
|
|
1557
1619
|
return;
|
|
1558
1620
|
}
|
|
1559
1621
|
return query.push(`${this.serializeValue(param)}`);
|
|
@@ -1575,7 +1637,7 @@ var HeaderSerializer = class extends Serializer {
|
|
|
1575
1637
|
}
|
|
1576
1638
|
const headers = {};
|
|
1577
1639
|
headerParams.forEach((param) => {
|
|
1578
|
-
if (!param.key) {
|
|
1640
|
+
if (!param.key || param.value === void 0 || param.value === null) {
|
|
1579
1641
|
return;
|
|
1580
1642
|
}
|
|
1581
1643
|
headers[param.key] = this.serializeValue(param);
|
|
@@ -1597,7 +1659,7 @@ var CookieSerializer = class {
|
|
|
1597
1659
|
}
|
|
1598
1660
|
const cookies = {};
|
|
1599
1661
|
cookieParams.forEach((param) => {
|
|
1600
|
-
if (!param.key || param.value === void 0) {
|
|
1662
|
+
if (!param.key || param.value === void 0 || param.value === null) {
|
|
1601
1663
|
return;
|
|
1602
1664
|
}
|
|
1603
1665
|
cookies[param.key] = this.serializeCookieValue(param);
|
|
@@ -1917,7 +1979,6 @@ var RequestBuilder = class {
|
|
|
1917
1979
|
clientId: "",
|
|
1918
1980
|
clientSecret: "",
|
|
1919
1981
|
retry: {
|
|
1920
|
-
attempts: 3,
|
|
1921
1982
|
delayMs: 150,
|
|
1922
1983
|
maxDelayMs: 5e3,
|
|
1923
1984
|
backoffFactor: 2,
|
|
@@ -1938,7 +1999,7 @@ var RequestBuilder = class {
|
|
|
1938
1999
|
};
|
|
1939
2000
|
this.addHeaderParam({
|
|
1940
2001
|
key: "User-Agent",
|
|
1941
|
-
value: "postman-codegen/
|
|
2002
|
+
value: "postman-codegen/2.6.0 celitech-sdk/2.0.7 (typescript)"
|
|
1942
2003
|
});
|
|
1943
2004
|
}
|
|
1944
2005
|
setConfig(config) {
|
|
@@ -2438,6 +2499,22 @@ var ThrowableError = class extends Error {
|
|
|
2438
2499
|
this.message = message;
|
|
2439
2500
|
this.response = response;
|
|
2440
2501
|
}
|
|
2502
|
+
/**
|
|
2503
|
+
* Creates an error instance from a response body.
|
|
2504
|
+
* Parsing (which can throw) is kept out of the constructor so that constructing
|
|
2505
|
+
* an error while handling an error response never throws. The base implementation
|
|
2506
|
+
* simply constructs the instance; subclasses may override to populate typed fields.
|
|
2507
|
+
*
|
|
2508
|
+
* Contract: every subclass constructor must accept `(message, response?)`. The base
|
|
2509
|
+
* uses `new this(message, response)`, so a subclass with a different constructor
|
|
2510
|
+
* signature must override `from()`.
|
|
2511
|
+
* @param message - The error message
|
|
2512
|
+
* @param response - Optional response data associated with the error
|
|
2513
|
+
* @returns A new error instance
|
|
2514
|
+
*/
|
|
2515
|
+
static from(message, response) {
|
|
2516
|
+
return new this(message, response);
|
|
2517
|
+
}
|
|
2441
2518
|
/**
|
|
2442
2519
|
* Throws this error instance.
|
|
2443
2520
|
* Convenience method for explicitly throwing the error.
|
|
@@ -2461,11 +2538,16 @@ var BadRequest = class extends ThrowableError {
|
|
|
2461
2538
|
super(message);
|
|
2462
2539
|
this.message = message;
|
|
2463
2540
|
this.response = response;
|
|
2464
|
-
|
|
2465
|
-
|
|
2541
|
+
}
|
|
2542
|
+
static from(message, response) {
|
|
2543
|
+
const error = new BadRequest(message, response);
|
|
2544
|
+
const result = badRequestResponse.safeParse(response);
|
|
2545
|
+
const parsedResponse = result.success ? result.data : response || {};
|
|
2546
|
+
error.message = parsedResponse.message || "";
|
|
2547
|
+
return error;
|
|
2466
2548
|
}
|
|
2467
2549
|
throw() {
|
|
2468
|
-
const error =
|
|
2550
|
+
const error = BadRequest.from(this.message, this.response);
|
|
2469
2551
|
error.metadata = this.metadata;
|
|
2470
2552
|
throw error;
|
|
2471
2553
|
}
|
|
@@ -2485,11 +2567,16 @@ var Unauthorized = class extends ThrowableError {
|
|
|
2485
2567
|
super(message);
|
|
2486
2568
|
this.message = message;
|
|
2487
2569
|
this.response = response;
|
|
2488
|
-
|
|
2489
|
-
|
|
2570
|
+
}
|
|
2571
|
+
static from(message, response) {
|
|
2572
|
+
const error = new Unauthorized(message, response);
|
|
2573
|
+
const result = unauthorizedResponse.safeParse(response);
|
|
2574
|
+
const parsedResponse = result.success ? result.data : response || {};
|
|
2575
|
+
error.message = parsedResponse.message || "";
|
|
2576
|
+
return error;
|
|
2490
2577
|
}
|
|
2491
2578
|
throw() {
|
|
2492
|
-
const error =
|
|
2579
|
+
const error = Unauthorized.from(this.message, this.response);
|
|
2493
2580
|
error.metadata = this.metadata;
|
|
2494
2581
|
throw error;
|
|
2495
2582
|
}
|
|
@@ -2633,12 +2720,14 @@ var PackagesService = class extends BaseService {
|
|
|
2633
2720
|
/**
|
|
2634
2721
|
* List Packages
|
|
2635
2722
|
* @param {string} [params.destination] - ISO representation of the package's destination. Supports both ISO2 (e.g., 'FR') and ISO3 (e.g., 'FRA') country codes.
|
|
2723
|
+
* @param {number} [params.dataLimitInGb] - Filter packages by data limit in GB. When provided, only packages with this exact data limit are returned. Use `-1` together with `includeUnlimited=true` to return only unlimited packages. A value of `0` is ignored.
|
|
2636
2724
|
* @param {string} [params.startDate] - Start date of the package's validity in the format 'yyyy-MM-dd'. This date can be set to the current day or any day within the next 12 months.
|
|
2637
2725
|
* @param {string} [params.endDate] - End date of the package's validity in the format 'yyyy-MM-dd'. End date can be maximum 90 days after Start date.
|
|
2638
2726
|
* @param {string} [params.afterCursor] - To get the next batch of results, use this parameter. It tells the API where to start fetching data after the last item you received. It helps you avoid repeats and efficiently browse through large sets of data.
|
|
2639
2727
|
* @param {number} [params.limit] - Maximum number of packages to be returned in the response. The value must be greater than 0 and less than or equal to 160. If not provided, the default value is 20
|
|
2640
2728
|
* @param {number} [params.startTime] - Epoch value representing the start time of the package's validity. This timestamp can be set to the current time or any time within the next 12 months
|
|
2641
2729
|
* @param {number} [params.endTime] - Epoch value representing the end time of the package's validity. End time can be maximum 90 days after Start time
|
|
2730
|
+
* @param {boolean} [params.includeUnlimited] - Whether to include unlimited (date-based) packages in the results. Unlimited packages are excluded by default; set this to `true` to include them. An unlimited package has `dataLimitInGB` and `dataLimitInBytes` equal to `-1`, and is offered for 3 to 30 days with `minDays` equal to `maxDays`.
|
|
2642
2731
|
* @param {Partial<SdkConfig>} [requestConfig] - The request configuration for retry and validation.
|
|
2643
2732
|
* @returns {Promise<HttpResponse<ListPackagesOkResponse>>} - Successful Response
|
|
2644
2733
|
*/
|
|
@@ -2646,12 +2735,14 @@ var PackagesService = class extends BaseService {
|
|
|
2646
2735
|
const resolvedConfig = this.getResolvedConfig(this.listPackagesConfig, requestConfig);
|
|
2647
2736
|
import_zod13.z.object({
|
|
2648
2737
|
destination: import_zod13.z.string().optional(),
|
|
2738
|
+
dataLimitInGb: import_zod13.z.number().optional(),
|
|
2649
2739
|
startDate: import_zod13.z.string().optional(),
|
|
2650
2740
|
endDate: import_zod13.z.string().optional(),
|
|
2651
2741
|
afterCursor: import_zod13.z.string().optional(),
|
|
2652
2742
|
limit: import_zod13.z.number().optional(),
|
|
2653
2743
|
startTime: import_zod13.z.number().optional(),
|
|
2654
|
-
endTime: import_zod13.z.number().optional()
|
|
2744
|
+
endTime: import_zod13.z.number().optional(),
|
|
2745
|
+
includeUnlimited: import_zod13.z.boolean().optional()
|
|
2655
2746
|
}).parse(params != null ? params : {});
|
|
2656
2747
|
const request = new RequestBuilder().setConfig(resolvedConfig).setBaseUrl(resolvedConfig).setMethod("GET").setPath("/packages").setRequestSchema(import_zod13.z.any()).setScopes([]).setTokenManager(this.tokenManager).setRequestContentType("json" /* Json */).addResponse({
|
|
2657
2748
|
schema: listPackagesOkResponseResponse,
|
|
@@ -2668,6 +2759,9 @@ var PackagesService = class extends BaseService {
|
|
|
2668
2759
|
}).addQueryParam({
|
|
2669
2760
|
key: "destination",
|
|
2670
2761
|
value: params == null ? void 0 : params.destination
|
|
2762
|
+
}).addQueryParam({
|
|
2763
|
+
key: "dataLimitInGB",
|
|
2764
|
+
value: params == null ? void 0 : params.dataLimitInGb
|
|
2671
2765
|
}).addQueryParam({
|
|
2672
2766
|
key: "startDate",
|
|
2673
2767
|
value: params == null ? void 0 : params.startDate
|
|
@@ -2686,6 +2780,9 @@ var PackagesService = class extends BaseService {
|
|
|
2686
2780
|
}).addQueryParam({
|
|
2687
2781
|
key: "endTime",
|
|
2688
2782
|
value: params == null ? void 0 : params.endTime
|
|
2783
|
+
}).addQueryParam({
|
|
2784
|
+
key: "includeUnlimited",
|
|
2785
|
+
value: params == null ? void 0 : params.includeUnlimited
|
|
2689
2786
|
}).build();
|
|
2690
2787
|
return this.client.callDirect(request);
|
|
2691
2788
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -336,7 +336,7 @@ var TransportHookAdapter = class {
|
|
|
336
336
|
function getContentTypeDefinition(contentType) {
|
|
337
337
|
const ct = contentType.toLowerCase();
|
|
338
338
|
if (ct.startsWith("application/") && ct.includes("xml")) {
|
|
339
|
-
return "
|
|
339
|
+
return "text" /* Text */;
|
|
340
340
|
}
|
|
341
341
|
if (ct === "application/x-www-form-urlencoded") {
|
|
342
342
|
return "form" /* FormUrlEncoded */;
|
|
@@ -409,7 +409,7 @@ var HookHandler = class {
|
|
|
409
409
|
} catch (e) {
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
|
-
const customError =
|
|
412
|
+
const customError = error.error.from((json == null ? void 0 : json.message) || "", json);
|
|
413
413
|
customError.metadata = response.metadata;
|
|
414
414
|
customError.throw();
|
|
415
415
|
}
|
|
@@ -546,7 +546,6 @@ var ResponseValidationHandler = class {
|
|
|
546
546
|
["image" /* Image */]: this.decodeFile,
|
|
547
547
|
["multipartFormData" /* MultipartFormData */]: this.decodeMultipartFormData,
|
|
548
548
|
["text" /* Text */]: this.decodeText,
|
|
549
|
-
["xml" /* Xml */]: this.decodeText,
|
|
550
549
|
["form" /* FormUrlEncoded */]: this.decodeFormUrlEncoded,
|
|
551
550
|
["eventStream" /* EventStream */]: this.decodeEventStream
|
|
552
551
|
};
|
|
@@ -762,7 +761,7 @@ var RequestValidationHandler = class {
|
|
|
762
761
|
}
|
|
763
762
|
throw error;
|
|
764
763
|
}
|
|
765
|
-
} else if (request.requestContentType === "
|
|
764
|
+
} else if (request.requestContentType === "text" /* Text */ || request.requestContentType === "image" /* Image */ || request.requestContentType === "binary" /* Binary */) {
|
|
766
765
|
request.body = request.body;
|
|
767
766
|
} else if (request.requestContentType === "form" /* FormUrlEncoded */) {
|
|
768
767
|
request.body = this.toFormUrlEncoded(request);
|
|
@@ -798,7 +797,7 @@ var RequestValidationHandler = class {
|
|
|
798
797
|
});
|
|
799
798
|
return params.toString();
|
|
800
799
|
}
|
|
801
|
-
if (typeof validatedBody === "object" && !Array.isArray(validatedBody)) {
|
|
800
|
+
if (typeof validatedBody === "object" && validatedBody !== null && !Array.isArray(validatedBody)) {
|
|
802
801
|
const params = new URLSearchParams();
|
|
803
802
|
for (const [key, value] of Object.entries(validatedBody)) {
|
|
804
803
|
if (value != null) {
|
|
@@ -1014,10 +1013,7 @@ var RequestFetchAdapter = class {
|
|
|
1014
1013
|
return headers;
|
|
1015
1014
|
}
|
|
1016
1015
|
toArrayBuffer(uint8Array) {
|
|
1017
|
-
return uint8Array.buffer
|
|
1018
|
-
uint8Array.byteOffset,
|
|
1019
|
-
uint8Array.byteOffset + uint8Array.byteLength
|
|
1020
|
-
);
|
|
1016
|
+
return new Uint8Array(uint8Array).buffer;
|
|
1021
1017
|
}
|
|
1022
1018
|
};
|
|
1023
1019
|
|
|
@@ -1067,7 +1063,7 @@ var RetryHandler = class {
|
|
|
1067
1063
|
if (!this.shouldRetry(error, request) || attempt === maxAttempts) {
|
|
1068
1064
|
throw error;
|
|
1069
1065
|
}
|
|
1070
|
-
const delayMs = this.calculateDelay(attempt, request);
|
|
1066
|
+
const delayMs = this.calculateDelay(attempt, request, error);
|
|
1071
1067
|
await this.delay(delayMs);
|
|
1072
1068
|
}
|
|
1073
1069
|
}
|
|
@@ -1094,7 +1090,7 @@ var RetryHandler = class {
|
|
|
1094
1090
|
if (!this.shouldRetry(error, request) || attempt === maxAttempts) {
|
|
1095
1091
|
throw error;
|
|
1096
1092
|
}
|
|
1097
|
-
const delayMs = this.calculateDelay(attempt, request);
|
|
1093
|
+
const delayMs = this.calculateDelay(attempt, request, error);
|
|
1098
1094
|
await this.delay(delayMs);
|
|
1099
1095
|
}
|
|
1100
1096
|
}
|
|
@@ -1127,18 +1123,25 @@ var RetryHandler = class {
|
|
|
1127
1123
|
return shouldRetryStatus && shouldRetryMethod;
|
|
1128
1124
|
}
|
|
1129
1125
|
/**
|
|
1130
|
-
* Calculates the delay before the next retry attempt
|
|
1131
|
-
*
|
|
1126
|
+
* Calculates the delay before the next retry attempt. A server rate-limit timing header
|
|
1127
|
+
* (Retry-After / X-RateLimit-Reset) on the error, when present, overrides the computed
|
|
1128
|
+
* exponential backoff; otherwise falls back to exponential backoff with optional jitter.
|
|
1132
1129
|
* @param attempt - The current retry attempt number (1-indexed)
|
|
1133
1130
|
* @param request - The HTTP request being retried
|
|
1131
|
+
* @param error - The error that triggered the retry (carries the response headers)
|
|
1134
1132
|
* @returns The delay in milliseconds, capped at the configured maximum delay
|
|
1135
1133
|
*/
|
|
1136
|
-
calculateDelay(attempt, request) {
|
|
1137
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1138
|
-
const
|
|
1139
|
-
const
|
|
1140
|
-
|
|
1141
|
-
|
|
1134
|
+
calculateDelay(attempt, request, error) {
|
|
1135
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1136
|
+
const maxRetryAfterDelay = (_b = (_a = request.config.retry) == null ? void 0 : _a.maxRetryAfterDelayMs) != null ? _b : 6e4;
|
|
1137
|
+
const headerDelay = this.retryAfterDelay(error, maxRetryAfterDelay);
|
|
1138
|
+
if (headerDelay !== null) {
|
|
1139
|
+
return Math.floor(headerDelay);
|
|
1140
|
+
}
|
|
1141
|
+
const baseDelay = (_d = (_c = request.config.retry) == null ? void 0 : _c.delayMs) != null ? _d : 150;
|
|
1142
|
+
const backoffFactor = (_f = (_e = request.config.retry) == null ? void 0 : _e.backoffFactor) != null ? _f : 2;
|
|
1143
|
+
const maxDelay = (_h = (_g = request.config.retry) == null ? void 0 : _g.maxDelayMs) != null ? _h : 5e3;
|
|
1144
|
+
const jitter = (_j = (_i = request.config.retry) == null ? void 0 : _i.jitterMs) != null ? _j : 50;
|
|
1142
1145
|
let delay = baseDelay * Math.pow(backoffFactor, attempt - 1);
|
|
1143
1146
|
delay = Math.min(delay, maxDelay);
|
|
1144
1147
|
if (jitter > 0) {
|
|
@@ -1146,6 +1149,65 @@ var RetryHandler = class {
|
|
|
1146
1149
|
}
|
|
1147
1150
|
return Math.floor(delay);
|
|
1148
1151
|
}
|
|
1152
|
+
/**
|
|
1153
|
+
* Returns the server-directed retry delay (ms) from rate-limit response headers,
|
|
1154
|
+
* honoring Retry-After (delta-seconds or HTTP-date) and, when absent, X-RateLimit-Reset
|
|
1155
|
+
* (epoch seconds), clamped to maxRetryAfterDelayMs. Returns null when no usable header is
|
|
1156
|
+
* present so the caller falls back to the computed exponential backoff.
|
|
1157
|
+
* @param error - The error that triggered the retry (carries the response headers)
|
|
1158
|
+
* @param maxRetryAfterDelayMs - Upper bound for a server-directed delay
|
|
1159
|
+
* @returns The delay in milliseconds, or null to use exponential backoff
|
|
1160
|
+
*/
|
|
1161
|
+
retryAfterDelay(error, maxRetryAfterDelayMs) {
|
|
1162
|
+
var _a;
|
|
1163
|
+
const headers = (_a = error == null ? void 0 : error.metadata) == null ? void 0 : _a.headers;
|
|
1164
|
+
if (!headers || maxRetryAfterDelayMs <= 0) {
|
|
1165
|
+
return null;
|
|
1166
|
+
}
|
|
1167
|
+
const retryAfterMs = headers["retry-after-ms"];
|
|
1168
|
+
if (retryAfterMs !== void 0 && /^\d+(\.\d+)?$/.test(retryAfterMs.trim())) {
|
|
1169
|
+
return Math.min(Number(retryAfterMs.trim()), maxRetryAfterDelayMs);
|
|
1170
|
+
}
|
|
1171
|
+
const seconds = this.parseRetryAfter(headers["retry-after"]);
|
|
1172
|
+
if (seconds !== null) {
|
|
1173
|
+
return Math.min(Math.max(seconds * 1e3, 0), maxRetryAfterDelayMs);
|
|
1174
|
+
}
|
|
1175
|
+
const reset = headers["x-ratelimit-reset"];
|
|
1176
|
+
if (reset !== void 0 && reset.trim() !== "") {
|
|
1177
|
+
const epoch = Number(reset);
|
|
1178
|
+
if (Number.isFinite(epoch)) {
|
|
1179
|
+
const deltaMs = epoch * 1e3 - Date.now();
|
|
1180
|
+
if (deltaMs > 0) {
|
|
1181
|
+
return Math.min(deltaMs, maxRetryAfterDelayMs);
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
return null;
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Parses a Retry-After header value: an integer/float number of seconds, or an HTTP-date
|
|
1189
|
+
* (a past date yields 0). Returns the delay in seconds, or null if empty/unparseable.
|
|
1190
|
+
* @param value - The raw Retry-After header value
|
|
1191
|
+
* @returns The delay in seconds, or null
|
|
1192
|
+
*/
|
|
1193
|
+
parseRetryAfter(value) {
|
|
1194
|
+
if (value === void 0) {
|
|
1195
|
+
return null;
|
|
1196
|
+
}
|
|
1197
|
+
const trimmed = value.trim();
|
|
1198
|
+
if (trimmed === "") {
|
|
1199
|
+
return null;
|
|
1200
|
+
}
|
|
1201
|
+
if (/^\d+(\.\d+)?$/.test(trimmed)) {
|
|
1202
|
+
return Number(trimmed);
|
|
1203
|
+
}
|
|
1204
|
+
const dateMs = Date.parse(trimmed);
|
|
1205
|
+
if (!Number.isNaN(dateMs)) {
|
|
1206
|
+
const deltaSeconds = (dateMs - Date.now()) / 1e3;
|
|
1207
|
+
return deltaSeconds > 0 ? deltaSeconds : 0;
|
|
1208
|
+
}
|
|
1209
|
+
return null;
|
|
1210
|
+
}
|
|
1149
1211
|
/**
|
|
1150
1212
|
* Delays execution for a specified duration before retrying.
|
|
1151
1213
|
* @param delayMs - The delay in milliseconds
|
|
@@ -1507,7 +1569,7 @@ var QuerySerializer = class extends Serializer {
|
|
|
1507
1569
|
}
|
|
1508
1570
|
const query = [];
|
|
1509
1571
|
queryParams.forEach((param) => {
|
|
1510
|
-
if (param.value === void 0) {
|
|
1572
|
+
if (param.value === void 0 || param.value === null) {
|
|
1511
1573
|
return;
|
|
1512
1574
|
}
|
|
1513
1575
|
return query.push(`${this.serializeValue(param)}`);
|
|
@@ -1529,7 +1591,7 @@ var HeaderSerializer = class extends Serializer {
|
|
|
1529
1591
|
}
|
|
1530
1592
|
const headers = {};
|
|
1531
1593
|
headerParams.forEach((param) => {
|
|
1532
|
-
if (!param.key) {
|
|
1594
|
+
if (!param.key || param.value === void 0 || param.value === null) {
|
|
1533
1595
|
return;
|
|
1534
1596
|
}
|
|
1535
1597
|
headers[param.key] = this.serializeValue(param);
|
|
@@ -1551,7 +1613,7 @@ var CookieSerializer = class {
|
|
|
1551
1613
|
}
|
|
1552
1614
|
const cookies = {};
|
|
1553
1615
|
cookieParams.forEach((param) => {
|
|
1554
|
-
if (!param.key || param.value === void 0) {
|
|
1616
|
+
if (!param.key || param.value === void 0 || param.value === null) {
|
|
1555
1617
|
return;
|
|
1556
1618
|
}
|
|
1557
1619
|
cookies[param.key] = this.serializeCookieValue(param);
|
|
@@ -1871,7 +1933,6 @@ var RequestBuilder = class {
|
|
|
1871
1933
|
clientId: "",
|
|
1872
1934
|
clientSecret: "",
|
|
1873
1935
|
retry: {
|
|
1874
|
-
attempts: 3,
|
|
1875
1936
|
delayMs: 150,
|
|
1876
1937
|
maxDelayMs: 5e3,
|
|
1877
1938
|
backoffFactor: 2,
|
|
@@ -1892,7 +1953,7 @@ var RequestBuilder = class {
|
|
|
1892
1953
|
};
|
|
1893
1954
|
this.addHeaderParam({
|
|
1894
1955
|
key: "User-Agent",
|
|
1895
|
-
value: "postman-codegen/
|
|
1956
|
+
value: "postman-codegen/2.6.0 celitech-sdk/2.0.7 (typescript)"
|
|
1896
1957
|
});
|
|
1897
1958
|
}
|
|
1898
1959
|
setConfig(config) {
|
|
@@ -2392,6 +2453,22 @@ var ThrowableError = class extends Error {
|
|
|
2392
2453
|
this.message = message;
|
|
2393
2454
|
this.response = response;
|
|
2394
2455
|
}
|
|
2456
|
+
/**
|
|
2457
|
+
* Creates an error instance from a response body.
|
|
2458
|
+
* Parsing (which can throw) is kept out of the constructor so that constructing
|
|
2459
|
+
* an error while handling an error response never throws. The base implementation
|
|
2460
|
+
* simply constructs the instance; subclasses may override to populate typed fields.
|
|
2461
|
+
*
|
|
2462
|
+
* Contract: every subclass constructor must accept `(message, response?)`. The base
|
|
2463
|
+
* uses `new this(message, response)`, so a subclass with a different constructor
|
|
2464
|
+
* signature must override `from()`.
|
|
2465
|
+
* @param message - The error message
|
|
2466
|
+
* @param response - Optional response data associated with the error
|
|
2467
|
+
* @returns A new error instance
|
|
2468
|
+
*/
|
|
2469
|
+
static from(message, response) {
|
|
2470
|
+
return new this(message, response);
|
|
2471
|
+
}
|
|
2395
2472
|
/**
|
|
2396
2473
|
* Throws this error instance.
|
|
2397
2474
|
* Convenience method for explicitly throwing the error.
|
|
@@ -2415,11 +2492,16 @@ var BadRequest = class extends ThrowableError {
|
|
|
2415
2492
|
super(message);
|
|
2416
2493
|
this.message = message;
|
|
2417
2494
|
this.response = response;
|
|
2418
|
-
|
|
2419
|
-
|
|
2495
|
+
}
|
|
2496
|
+
static from(message, response) {
|
|
2497
|
+
const error = new BadRequest(message, response);
|
|
2498
|
+
const result = badRequestResponse.safeParse(response);
|
|
2499
|
+
const parsedResponse = result.success ? result.data : response || {};
|
|
2500
|
+
error.message = parsedResponse.message || "";
|
|
2501
|
+
return error;
|
|
2420
2502
|
}
|
|
2421
2503
|
throw() {
|
|
2422
|
-
const error =
|
|
2504
|
+
const error = BadRequest.from(this.message, this.response);
|
|
2423
2505
|
error.metadata = this.metadata;
|
|
2424
2506
|
throw error;
|
|
2425
2507
|
}
|
|
@@ -2439,11 +2521,16 @@ var Unauthorized = class extends ThrowableError {
|
|
|
2439
2521
|
super(message);
|
|
2440
2522
|
this.message = message;
|
|
2441
2523
|
this.response = response;
|
|
2442
|
-
|
|
2443
|
-
|
|
2524
|
+
}
|
|
2525
|
+
static from(message, response) {
|
|
2526
|
+
const error = new Unauthorized(message, response);
|
|
2527
|
+
const result = unauthorizedResponse.safeParse(response);
|
|
2528
|
+
const parsedResponse = result.success ? result.data : response || {};
|
|
2529
|
+
error.message = parsedResponse.message || "";
|
|
2530
|
+
return error;
|
|
2444
2531
|
}
|
|
2445
2532
|
throw() {
|
|
2446
|
-
const error =
|
|
2533
|
+
const error = Unauthorized.from(this.message, this.response);
|
|
2447
2534
|
error.metadata = this.metadata;
|
|
2448
2535
|
throw error;
|
|
2449
2536
|
}
|
|
@@ -2587,12 +2674,14 @@ var PackagesService = class extends BaseService {
|
|
|
2587
2674
|
/**
|
|
2588
2675
|
* List Packages
|
|
2589
2676
|
* @param {string} [params.destination] - ISO representation of the package's destination. Supports both ISO2 (e.g., 'FR') and ISO3 (e.g., 'FRA') country codes.
|
|
2677
|
+
* @param {number} [params.dataLimitInGb] - Filter packages by data limit in GB. When provided, only packages with this exact data limit are returned. Use `-1` together with `includeUnlimited=true` to return only unlimited packages. A value of `0` is ignored.
|
|
2590
2678
|
* @param {string} [params.startDate] - Start date of the package's validity in the format 'yyyy-MM-dd'. This date can be set to the current day or any day within the next 12 months.
|
|
2591
2679
|
* @param {string} [params.endDate] - End date of the package's validity in the format 'yyyy-MM-dd'. End date can be maximum 90 days after Start date.
|
|
2592
2680
|
* @param {string} [params.afterCursor] - To get the next batch of results, use this parameter. It tells the API where to start fetching data after the last item you received. It helps you avoid repeats and efficiently browse through large sets of data.
|
|
2593
2681
|
* @param {number} [params.limit] - Maximum number of packages to be returned in the response. The value must be greater than 0 and less than or equal to 160. If not provided, the default value is 20
|
|
2594
2682
|
* @param {number} [params.startTime] - Epoch value representing the start time of the package's validity. This timestamp can be set to the current time or any time within the next 12 months
|
|
2595
2683
|
* @param {number} [params.endTime] - Epoch value representing the end time of the package's validity. End time can be maximum 90 days after Start time
|
|
2684
|
+
* @param {boolean} [params.includeUnlimited] - Whether to include unlimited (date-based) packages in the results. Unlimited packages are excluded by default; set this to `true` to include them. An unlimited package has `dataLimitInGB` and `dataLimitInBytes` equal to `-1`, and is offered for 3 to 30 days with `minDays` equal to `maxDays`.
|
|
2596
2685
|
* @param {Partial<SdkConfig>} [requestConfig] - The request configuration for retry and validation.
|
|
2597
2686
|
* @returns {Promise<HttpResponse<ListPackagesOkResponse>>} - Successful Response
|
|
2598
2687
|
*/
|
|
@@ -2600,12 +2689,14 @@ var PackagesService = class extends BaseService {
|
|
|
2600
2689
|
const resolvedConfig = this.getResolvedConfig(this.listPackagesConfig, requestConfig);
|
|
2601
2690
|
z11.object({
|
|
2602
2691
|
destination: z11.string().optional(),
|
|
2692
|
+
dataLimitInGb: z11.number().optional(),
|
|
2603
2693
|
startDate: z11.string().optional(),
|
|
2604
2694
|
endDate: z11.string().optional(),
|
|
2605
2695
|
afterCursor: z11.string().optional(),
|
|
2606
2696
|
limit: z11.number().optional(),
|
|
2607
2697
|
startTime: z11.number().optional(),
|
|
2608
|
-
endTime: z11.number().optional()
|
|
2698
|
+
endTime: z11.number().optional(),
|
|
2699
|
+
includeUnlimited: z11.boolean().optional()
|
|
2609
2700
|
}).parse(params != null ? params : {});
|
|
2610
2701
|
const request = new RequestBuilder().setConfig(resolvedConfig).setBaseUrl(resolvedConfig).setMethod("GET").setPath("/packages").setRequestSchema(z11.any()).setScopes([]).setTokenManager(this.tokenManager).setRequestContentType("json" /* Json */).addResponse({
|
|
2611
2702
|
schema: listPackagesOkResponseResponse,
|
|
@@ -2622,6 +2713,9 @@ var PackagesService = class extends BaseService {
|
|
|
2622
2713
|
}).addQueryParam({
|
|
2623
2714
|
key: "destination",
|
|
2624
2715
|
value: params == null ? void 0 : params.destination
|
|
2716
|
+
}).addQueryParam({
|
|
2717
|
+
key: "dataLimitInGB",
|
|
2718
|
+
value: params == null ? void 0 : params.dataLimitInGb
|
|
2625
2719
|
}).addQueryParam({
|
|
2626
2720
|
key: "startDate",
|
|
2627
2721
|
value: params == null ? void 0 : params.startDate
|
|
@@ -2640,6 +2734,9 @@ var PackagesService = class extends BaseService {
|
|
|
2640
2734
|
}).addQueryParam({
|
|
2641
2735
|
key: "endTime",
|
|
2642
2736
|
value: params == null ? void 0 : params.endTime
|
|
2737
|
+
}).addQueryParam({
|
|
2738
|
+
key: "includeUnlimited",
|
|
2739
|
+
value: params == null ? void 0 : params.includeUnlimited
|
|
2643
2740
|
}).build();
|
|
2644
2741
|
return this.client.callDirect(request);
|
|
2645
2742
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "celitech-sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"description": "Welcome to the CELITECH API documentation! Useful links: [Homepage](https://www.celitech.com) | [Support email](mailto:support@celitech.com) | [Blog](https://www.celitech.com/blog/)",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"tsup": "^6.7.0"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"zod": "3.22.
|
|
39
|
+
"zod": "3.22.3"
|
|
40
40
|
},
|
|
41
41
|
"exports": {
|
|
42
42
|
".": {
|