@proxyrequest/sdk 2.0.0 → 3.0.1
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/CHANGELOG.md +21 -0
- package/README.md +21 -2
- package/dist/index.cjs +916 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -26
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +42 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +922 -19
- package/dist/index.js.map +1 -1
- package/dist/{models-CNN_LuGV.d.ts → models-2V3Llpqk.d.cts} +4 -3
- package/dist/{models-BDeknFzS.d.cts.map → models-2V3Llpqk.d.cts.map} +1 -1
- package/dist/{models-BDeknFzS.d.cts → models-Bemi0dKg.d.ts} +4 -3
- package/dist/{models-CNN_LuGV.d.ts.map → models-Bemi0dKg.d.ts.map} +1 -1
- package/dist/models.d.cts +2 -2
- package/dist/models.d.ts +2 -2
- package/dist/openapi.d.cts +1 -1
- package/dist/openapi.d.ts +1 -1
- package/dist/{schema-BNl4txEF.d.cts → schema-BZvnw81E.d.cts} +249 -81
- package/dist/schema-BZvnw81E.d.cts.map +1 -0
- package/dist/{schema-BNl4txEF.d.ts → schema-BZvnw81E.d.ts} +249 -81
- package/dist/schema-BZvnw81E.d.ts.map +1 -0
- package/docs/analytics.md +47 -0
- package/docs/third-party-notices.md +38 -0
- package/docs/webhooks.md +1 -1
- package/package.json +2 -1
- package/dist/schema-BNl4txEF.d.cts.map +0 -1
- package/dist/schema-BNl4txEF.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,34 +1,884 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
//#region
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
//#region node_modules/openapi-fetch/dist/index.mjs
|
|
3
|
+
const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
4
|
+
const supportsRequestInitExt = () => {
|
|
5
|
+
return typeof process === "object" && Number.parseInt(process?.versions?.node?.substring(0, 2)) >= 18 && process.versions.undici;
|
|
6
|
+
};
|
|
7
|
+
function randomID() {
|
|
8
|
+
return Math.random().toString(36).slice(2, 11);
|
|
9
|
+
}
|
|
10
|
+
function createClient(clientOptions) {
|
|
11
|
+
let { baseUrl = "", Request: CustomRequest = globalThis.Request, fetch: baseFetch = globalThis.fetch, querySerializer: globalQuerySerializer, bodySerializer: globalBodySerializer, pathSerializer: globalPathSerializer, headers: baseHeaders, requestInitExt = void 0, ...baseOptions } = { ...clientOptions };
|
|
12
|
+
requestInitExt = supportsRequestInitExt() ? requestInitExt : void 0;
|
|
13
|
+
baseUrl = removeTrailingSlash(baseUrl);
|
|
14
|
+
const globalMiddlewares = [];
|
|
15
|
+
async function coreFetch(schemaPath, fetchOptions) {
|
|
16
|
+
const { baseUrl: localBaseUrl, fetch = baseFetch, Request = CustomRequest, headers, params = {}, parseAs = "json", querySerializer: requestQuerySerializer, bodySerializer = globalBodySerializer ?? defaultBodySerializer, pathSerializer: requestPathSerializer, body, middleware: requestMiddlewares = [], ...init } = fetchOptions || {};
|
|
17
|
+
let finalBaseUrl = baseUrl;
|
|
18
|
+
if (localBaseUrl) finalBaseUrl = removeTrailingSlash(localBaseUrl) ?? baseUrl;
|
|
19
|
+
let querySerializer = typeof globalQuerySerializer === "function" ? globalQuerySerializer : createQuerySerializer(globalQuerySerializer);
|
|
20
|
+
if (requestQuerySerializer) querySerializer = typeof requestQuerySerializer === "function" ? requestQuerySerializer : createQuerySerializer({
|
|
21
|
+
...typeof globalQuerySerializer === "object" ? globalQuerySerializer : {},
|
|
22
|
+
...requestQuerySerializer
|
|
23
|
+
});
|
|
24
|
+
const pathSerializer = requestPathSerializer || globalPathSerializer || defaultPathSerializer;
|
|
25
|
+
const serializedBody = body === void 0 ? void 0 : bodySerializer(body, mergeHeaders(baseHeaders, headers, params.header));
|
|
26
|
+
const finalHeaders = mergeHeaders(serializedBody === void 0 || serializedBody instanceof FormData ? {} : { "Content-Type": "application/json" }, baseHeaders, headers, params.header);
|
|
27
|
+
const finalMiddlewares = [...globalMiddlewares, ...requestMiddlewares];
|
|
28
|
+
const requestInit = {
|
|
29
|
+
redirect: "follow",
|
|
30
|
+
...baseOptions,
|
|
31
|
+
...init,
|
|
32
|
+
body: serializedBody,
|
|
33
|
+
headers: finalHeaders
|
|
34
|
+
};
|
|
35
|
+
let id;
|
|
36
|
+
let options;
|
|
37
|
+
let request = new Request(createFinalURL(schemaPath, {
|
|
38
|
+
baseUrl: finalBaseUrl,
|
|
39
|
+
params,
|
|
40
|
+
querySerializer,
|
|
41
|
+
pathSerializer
|
|
42
|
+
}), requestInit);
|
|
43
|
+
let response;
|
|
44
|
+
for (const key in init) if (!(key in request)) request[key] = init[key];
|
|
45
|
+
if (finalMiddlewares.length) {
|
|
46
|
+
id = randomID();
|
|
47
|
+
options = Object.freeze({
|
|
48
|
+
baseUrl: finalBaseUrl,
|
|
49
|
+
fetch,
|
|
50
|
+
parseAs,
|
|
51
|
+
querySerializer,
|
|
52
|
+
bodySerializer,
|
|
53
|
+
pathSerializer
|
|
54
|
+
});
|
|
55
|
+
for (const m of finalMiddlewares) if (m && typeof m === "object" && typeof m.onRequest === "function") {
|
|
56
|
+
const result = await m.onRequest({
|
|
57
|
+
request,
|
|
58
|
+
schemaPath,
|
|
59
|
+
params,
|
|
60
|
+
options,
|
|
61
|
+
id
|
|
17
62
|
});
|
|
63
|
+
if (result) {
|
|
64
|
+
if (result instanceof Request) request = result;
|
|
65
|
+
else if (result instanceof Response) {
|
|
66
|
+
response = result;
|
|
67
|
+
break;
|
|
68
|
+
} else throw new Error("onRequest: must return new Request() or Response() when modifying the request");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!response) {
|
|
73
|
+
try {
|
|
74
|
+
response = await fetch(request, requestInitExt);
|
|
75
|
+
} catch (error2) {
|
|
76
|
+
let errorAfterMiddleware = error2;
|
|
77
|
+
if (finalMiddlewares.length) for (let i = finalMiddlewares.length - 1; i >= 0; i--) {
|
|
78
|
+
const m = finalMiddlewares[i];
|
|
79
|
+
if (m && typeof m === "object" && typeof m.onError === "function") {
|
|
80
|
+
const result = await m.onError({
|
|
81
|
+
request,
|
|
82
|
+
error: errorAfterMiddleware,
|
|
83
|
+
schemaPath,
|
|
84
|
+
params,
|
|
85
|
+
options,
|
|
86
|
+
id
|
|
87
|
+
});
|
|
88
|
+
if (result) {
|
|
89
|
+
if (result instanceof Response) {
|
|
90
|
+
errorAfterMiddleware = void 0;
|
|
91
|
+
response = result;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (result instanceof Error) {
|
|
95
|
+
errorAfterMiddleware = result;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
throw new Error("onError: must return new Response() or instance of Error");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (errorAfterMiddleware) throw errorAfterMiddleware;
|
|
103
|
+
}
|
|
104
|
+
if (finalMiddlewares.length) for (let i = finalMiddlewares.length - 1; i >= 0; i--) {
|
|
105
|
+
const m = finalMiddlewares[i];
|
|
106
|
+
if (m && typeof m === "object" && typeof m.onResponse === "function") {
|
|
107
|
+
const result = await m.onResponse({
|
|
108
|
+
request,
|
|
109
|
+
response,
|
|
110
|
+
schemaPath,
|
|
111
|
+
params,
|
|
112
|
+
options,
|
|
113
|
+
id
|
|
114
|
+
});
|
|
115
|
+
if (result) {
|
|
116
|
+
if (!(result instanceof Response)) throw new Error("onResponse: must return new Response() when modifying the response");
|
|
117
|
+
response = result;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
18
120
|
}
|
|
19
121
|
}
|
|
122
|
+
const contentLength = response.headers.get("Content-Length");
|
|
123
|
+
if (response.status === 204 || request.method === "HEAD" || contentLength === "0" && !response.headers.get("Transfer-Encoding")?.includes("chunked")) return response.ok ? {
|
|
124
|
+
data: void 0,
|
|
125
|
+
response
|
|
126
|
+
} : {
|
|
127
|
+
error: void 0,
|
|
128
|
+
response
|
|
129
|
+
};
|
|
130
|
+
if (response.ok) {
|
|
131
|
+
const getResponseData = async () => {
|
|
132
|
+
if (parseAs === "stream") return response.body;
|
|
133
|
+
if (parseAs === "json" && !contentLength) {
|
|
134
|
+
const raw = await response.text();
|
|
135
|
+
return raw ? JSON.parse(raw) : void 0;
|
|
136
|
+
}
|
|
137
|
+
return await response[parseAs]();
|
|
138
|
+
};
|
|
139
|
+
return {
|
|
140
|
+
data: await getResponseData(),
|
|
141
|
+
response
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
let error = await response.text();
|
|
145
|
+
try {
|
|
146
|
+
error = JSON.parse(error);
|
|
147
|
+
} catch {}
|
|
148
|
+
return {
|
|
149
|
+
error,
|
|
150
|
+
response
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
request(method, url, init) {
|
|
155
|
+
return coreFetch(url, {
|
|
156
|
+
...init,
|
|
157
|
+
method: method.toUpperCase()
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
/** Call a GET endpoint */
|
|
161
|
+
GET(url, init) {
|
|
162
|
+
return coreFetch(url, {
|
|
163
|
+
...init,
|
|
164
|
+
method: "GET"
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
/** Call a PUT endpoint */
|
|
168
|
+
PUT(url, init) {
|
|
169
|
+
return coreFetch(url, {
|
|
170
|
+
...init,
|
|
171
|
+
method: "PUT"
|
|
172
|
+
});
|
|
173
|
+
},
|
|
174
|
+
/** Call a POST endpoint */
|
|
175
|
+
POST(url, init) {
|
|
176
|
+
return coreFetch(url, {
|
|
177
|
+
...init,
|
|
178
|
+
method: "POST"
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
/** Call a DELETE endpoint */
|
|
182
|
+
DELETE(url, init) {
|
|
183
|
+
return coreFetch(url, {
|
|
184
|
+
...init,
|
|
185
|
+
method: "DELETE"
|
|
186
|
+
});
|
|
187
|
+
},
|
|
188
|
+
/** Call a OPTIONS endpoint */
|
|
189
|
+
OPTIONS(url, init) {
|
|
190
|
+
return coreFetch(url, {
|
|
191
|
+
...init,
|
|
192
|
+
method: "OPTIONS"
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
/** Call a HEAD endpoint */
|
|
196
|
+
HEAD(url, init) {
|
|
197
|
+
return coreFetch(url, {
|
|
198
|
+
...init,
|
|
199
|
+
method: "HEAD"
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
/** Call a PATCH endpoint */
|
|
203
|
+
PATCH(url, init) {
|
|
204
|
+
return coreFetch(url, {
|
|
205
|
+
...init,
|
|
206
|
+
method: "PATCH"
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
/** Call a TRACE endpoint */
|
|
210
|
+
TRACE(url, init) {
|
|
211
|
+
return coreFetch(url, {
|
|
212
|
+
...init,
|
|
213
|
+
method: "TRACE"
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
/** Register middleware */
|
|
217
|
+
use(...middleware) {
|
|
218
|
+
for (const m of middleware) {
|
|
219
|
+
if (!m) continue;
|
|
220
|
+
if (typeof m !== "object" || !("onRequest" in m || "onResponse" in m || "onError" in m)) throw new Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");
|
|
221
|
+
globalMiddlewares.push(m);
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
/** Unregister middleware */
|
|
225
|
+
eject(...middleware) {
|
|
226
|
+
for (const m of middleware) {
|
|
227
|
+
const i = globalMiddlewares.indexOf(m);
|
|
228
|
+
if (i !== -1) globalMiddlewares.splice(i, 1);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function serializePrimitiveParam(name, value, options) {
|
|
234
|
+
if (value === void 0 || value === null) return "";
|
|
235
|
+
if (typeof value === "object") throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
|
|
236
|
+
return `${name}=${options?.allowReserved === true ? value : encodeURIComponent(value)}`;
|
|
237
|
+
}
|
|
238
|
+
function serializeObjectParam(name, value, options) {
|
|
239
|
+
if (!value || typeof value !== "object") return "";
|
|
240
|
+
const values = [];
|
|
241
|
+
const joiner = {
|
|
242
|
+
simple: ",",
|
|
243
|
+
label: ".",
|
|
244
|
+
matrix: ";"
|
|
245
|
+
}[options.style] || "&";
|
|
246
|
+
if (options.style !== "deepObject" && options.explode === false) {
|
|
247
|
+
for (const k in value) values.push(k, options.allowReserved === true ? value[k] : encodeURIComponent(value[k]));
|
|
248
|
+
const final2 = values.join(",");
|
|
249
|
+
switch (options.style) {
|
|
250
|
+
case "form": return `${name}=${final2}`;
|
|
251
|
+
case "label": return `.${final2}`;
|
|
252
|
+
case "matrix": return `;${name}=${final2}`;
|
|
253
|
+
default: return final2;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
for (const k in value) {
|
|
257
|
+
const finalName = options.style === "deepObject" ? `${name}[${k}]` : k;
|
|
258
|
+
values.push(serializePrimitiveParam(finalName, value[k], options));
|
|
259
|
+
}
|
|
260
|
+
const final = values.join(joiner);
|
|
261
|
+
return options.style === "label" || options.style === "matrix" ? `${joiner}${final}` : final;
|
|
262
|
+
}
|
|
263
|
+
function serializeArrayParam(name, value, options) {
|
|
264
|
+
if (!Array.isArray(value)) return "";
|
|
265
|
+
if (options.explode === false) {
|
|
266
|
+
const joiner2 = {
|
|
267
|
+
form: ",",
|
|
268
|
+
spaceDelimited: "%20",
|
|
269
|
+
pipeDelimited: "|"
|
|
270
|
+
}[options.style] || ",";
|
|
271
|
+
const final = (options.allowReserved === true ? value : value.map((v) => encodeURIComponent(v))).join(joiner2);
|
|
272
|
+
switch (options.style) {
|
|
273
|
+
case "simple": return final;
|
|
274
|
+
case "label": return `.${final}`;
|
|
275
|
+
case "matrix": return `;${name}=${final}`;
|
|
276
|
+
default: return `${name}=${final}`;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const joiner = {
|
|
280
|
+
simple: ",",
|
|
281
|
+
label: ".",
|
|
282
|
+
matrix: ";"
|
|
283
|
+
}[options.style] || "&";
|
|
284
|
+
const values = [];
|
|
285
|
+
for (const v of value) if (options.style === "simple" || options.style === "label") values.push(options.allowReserved === true ? v : encodeURIComponent(v));
|
|
286
|
+
else values.push(serializePrimitiveParam(name, v, options));
|
|
287
|
+
return options.style === "label" || options.style === "matrix" ? `${joiner}${values.join(joiner)}` : values.join(joiner);
|
|
288
|
+
}
|
|
289
|
+
function createQuerySerializer(options) {
|
|
290
|
+
return function querySerializer(queryParams) {
|
|
291
|
+
const search = [];
|
|
292
|
+
if (queryParams && typeof queryParams === "object") for (const name in queryParams) {
|
|
293
|
+
const value = queryParams[name];
|
|
294
|
+
if (value === void 0 || value === null) continue;
|
|
295
|
+
if (Array.isArray(value)) {
|
|
296
|
+
if (value.length === 0) continue;
|
|
297
|
+
search.push(serializeArrayParam(name, value, {
|
|
298
|
+
style: "form",
|
|
299
|
+
explode: true,
|
|
300
|
+
...options?.array,
|
|
301
|
+
allowReserved: options?.allowReserved || false
|
|
302
|
+
}));
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (typeof value === "object") {
|
|
306
|
+
search.push(serializeObjectParam(name, value, {
|
|
307
|
+
style: "deepObject",
|
|
308
|
+
explode: true,
|
|
309
|
+
...options?.object,
|
|
310
|
+
allowReserved: options?.allowReserved || false
|
|
311
|
+
}));
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
search.push(serializePrimitiveParam(name, value, options));
|
|
315
|
+
}
|
|
316
|
+
return search.join("&");
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
function defaultPathSerializer(pathname, pathParams) {
|
|
320
|
+
let nextURL = pathname;
|
|
321
|
+
for (const match of pathname.match(PATH_PARAM_RE) ?? []) {
|
|
322
|
+
let name = match.substring(1, match.length - 1);
|
|
323
|
+
let explode = false;
|
|
324
|
+
let style = "simple";
|
|
325
|
+
if (name.endsWith("*")) {
|
|
326
|
+
explode = true;
|
|
327
|
+
name = name.substring(0, name.length - 1);
|
|
328
|
+
}
|
|
329
|
+
if (name.startsWith(".")) {
|
|
330
|
+
style = "label";
|
|
331
|
+
name = name.substring(1);
|
|
332
|
+
} else if (name.startsWith(";")) {
|
|
333
|
+
style = "matrix";
|
|
334
|
+
name = name.substring(1);
|
|
335
|
+
}
|
|
336
|
+
if (!pathParams || pathParams[name] === void 0 || pathParams[name] === null) continue;
|
|
337
|
+
const value = pathParams[name];
|
|
338
|
+
if (Array.isArray(value)) {
|
|
339
|
+
nextURL = nextURL.replace(match, serializeArrayParam(name, value, {
|
|
340
|
+
style,
|
|
341
|
+
explode
|
|
342
|
+
}));
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
if (typeof value === "object") {
|
|
346
|
+
nextURL = nextURL.replace(match, serializeObjectParam(name, value, {
|
|
347
|
+
style,
|
|
348
|
+
explode
|
|
349
|
+
}));
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (style === "matrix") {
|
|
353
|
+
nextURL = nextURL.replace(match, `;${serializePrimitiveParam(name, value)}`);
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
nextURL = nextURL.replace(match, style === "label" ? `.${encodeURIComponent(value)}` : encodeURIComponent(value));
|
|
357
|
+
}
|
|
358
|
+
return nextURL;
|
|
359
|
+
}
|
|
360
|
+
function defaultBodySerializer(body, headers) {
|
|
361
|
+
if (body instanceof FormData) return body;
|
|
362
|
+
if (headers) {
|
|
363
|
+
if ((headers.get instanceof Function ? headers.get("Content-Type") ?? headers.get("content-type") : headers["Content-Type"] ?? headers["content-type"]) === "application/x-www-form-urlencoded") return new URLSearchParams(body).toString();
|
|
364
|
+
}
|
|
365
|
+
return JSON.stringify(body);
|
|
366
|
+
}
|
|
367
|
+
function createFinalURL(pathname, options) {
|
|
368
|
+
let finalURL = `${options.baseUrl}${pathname}`;
|
|
369
|
+
if (options.params?.path) finalURL = options.pathSerializer(finalURL, options.params.path);
|
|
370
|
+
let search = options.querySerializer(options.params.query ?? {});
|
|
371
|
+
if (search.startsWith("?")) search = search.substring(1);
|
|
372
|
+
if (search) finalURL += `?${search}`;
|
|
373
|
+
return finalURL;
|
|
374
|
+
}
|
|
375
|
+
function mergeHeaders(...allHeaders) {
|
|
376
|
+
const finalHeaders = new Headers();
|
|
377
|
+
for (const h of allHeaders) {
|
|
378
|
+
if (!h || typeof h !== "object") continue;
|
|
379
|
+
const iterator = h instanceof Headers ? h.entries() : Object.entries(h);
|
|
380
|
+
for (const [k, v] of iterator) if (v === null) finalHeaders.delete(k);
|
|
381
|
+
else if (Array.isArray(v)) for (const v2 of v) finalHeaders.append(k, v2);
|
|
382
|
+
else if (v !== void 0) finalHeaders.set(k, v);
|
|
383
|
+
}
|
|
384
|
+
return finalHeaders;
|
|
385
|
+
}
|
|
386
|
+
function removeTrailingSlash(url) {
|
|
387
|
+
if (url.endsWith("/")) return url.substring(0, url.length - 1);
|
|
388
|
+
return url;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
//#endregion
|
|
392
|
+
//#region node_modules/lossless-json/lib/esm/utils.js
|
|
393
|
+
/**
|
|
394
|
+
* Test whether a string contains an integer number
|
|
395
|
+
*/
|
|
396
|
+
function isInteger(value) {
|
|
397
|
+
return INTEGER_REGEX.test(value);
|
|
398
|
+
}
|
|
399
|
+
const INTEGER_REGEX = /^-?[0-9]+$/;
|
|
400
|
+
/**
|
|
401
|
+
* Test whether a string contains a number
|
|
402
|
+
* http://stackoverflow.com/questions/13340717/json-numbers-regular-expression
|
|
403
|
+
*/
|
|
404
|
+
function isNumber(value) {
|
|
405
|
+
return NUMBER_REGEX.test(value);
|
|
406
|
+
}
|
|
407
|
+
const NUMBER_REGEX = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
|
|
408
|
+
/**
|
|
409
|
+
* Test whether a string can be safely represented with a number
|
|
410
|
+
* without information loss.
|
|
411
|
+
*
|
|
412
|
+
* When approx is true, floating point numbers that lose a few digits but
|
|
413
|
+
* are still approximately equal in value are considered safe too.
|
|
414
|
+
* Integer numbers must still be exactly equal.
|
|
415
|
+
*/
|
|
416
|
+
function isSafeNumber(value, config) {
|
|
417
|
+
if (isInteger(value)) return Number.isSafeInteger(Number.parseInt(value, 10));
|
|
418
|
+
const parsed = String(Number.parseFloat(value));
|
|
419
|
+
if (value === parsed) return true;
|
|
420
|
+
const valueDigits = extractSignificantDigits(value);
|
|
421
|
+
const parsedDigits = extractSignificantDigits(parsed);
|
|
422
|
+
if (valueDigits === parsedDigits) return true;
|
|
423
|
+
if (config?.approx === true) {
|
|
424
|
+
const requiredDigits = 14;
|
|
425
|
+
if (!isInteger(value) && parsedDigits.length >= requiredDigits && valueDigits.startsWith(parsedDigits.substring(0, requiredDigits))) return true;
|
|
426
|
+
}
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
let UnsafeNumberReason = /*#__PURE__*/ function(UnsafeNumberReason) {
|
|
430
|
+
UnsafeNumberReason["underflow"] = "underflow";
|
|
431
|
+
UnsafeNumberReason["overflow"] = "overflow";
|
|
432
|
+
UnsafeNumberReason["truncate_integer"] = "truncate_integer";
|
|
433
|
+
UnsafeNumberReason["truncate_float"] = "truncate_float";
|
|
434
|
+
return UnsafeNumberReason;
|
|
435
|
+
}({});
|
|
436
|
+
/**
|
|
437
|
+
* When the provided value is an unsafe number, describe what the reason is:
|
|
438
|
+
* overflow, underflow, truncate_integer, or truncate_float.
|
|
439
|
+
* Returns undefined when the value is safe.
|
|
440
|
+
*/
|
|
441
|
+
function getUnsafeNumberReason(value) {
|
|
442
|
+
if (isSafeNumber(value, { approx: false })) return;
|
|
443
|
+
if (isInteger(value)) return UnsafeNumberReason.truncate_integer;
|
|
444
|
+
const num = Number.parseFloat(value);
|
|
445
|
+
if (!Number.isFinite(num)) return UnsafeNumberReason.overflow;
|
|
446
|
+
if (num === 0) return UnsafeNumberReason.underflow;
|
|
447
|
+
return UnsafeNumberReason.truncate_float;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Get the significant digits of a number.
|
|
451
|
+
*
|
|
452
|
+
* For example:
|
|
453
|
+
* '2.34' returns '234'
|
|
454
|
+
* '-77' returns '77'
|
|
455
|
+
* '0.003400' returns '34'
|
|
456
|
+
* '120.5e+30' returns '1205'
|
|
457
|
+
**/
|
|
458
|
+
function extractSignificantDigits(value) {
|
|
459
|
+
const { start, end } = getSignificantDigitRange(value);
|
|
460
|
+
const digits = value.substring(start, end);
|
|
461
|
+
const dot = digits.indexOf(".");
|
|
462
|
+
if (dot === -1) return digits;
|
|
463
|
+
return digits.substring(0, dot) + digits.substring(dot + 1);
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Returns the range (start to end) of the significant digits of a value.
|
|
467
|
+
* Note that this range _may_ contain the decimal dot.
|
|
468
|
+
*
|
|
469
|
+
* For example:
|
|
470
|
+
*
|
|
471
|
+
* getSignificantDigitRange('0.0325900') // { start: 3, end: 7 }
|
|
472
|
+
* getSignificantDigitRange('2.0300') // { start: 0, end: 3 }
|
|
473
|
+
* getSignificantDigitRange('0.0') // { start: 3, end: 3 }
|
|
474
|
+
*
|
|
475
|
+
*/
|
|
476
|
+
function getSignificantDigitRange(value) {
|
|
477
|
+
let start = 0;
|
|
478
|
+
if (value[0] === "-") start++;
|
|
479
|
+
while (value[start] === "0" || value[start] === ".") start++;
|
|
480
|
+
let end = value.lastIndexOf("e");
|
|
481
|
+
if (end === -1) end = value.lastIndexOf("E");
|
|
482
|
+
if (end === -1) end = value.length;
|
|
483
|
+
while ((value[end - 1] === "0" || value[end - 1] === ".") && end > start) end--;
|
|
484
|
+
return {
|
|
485
|
+
start,
|
|
486
|
+
end
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
//#endregion
|
|
491
|
+
//#region node_modules/lossless-json/lib/esm/LosslessNumber.js
|
|
492
|
+
/**
|
|
493
|
+
* A lossless number. Stores its numeric value as string
|
|
494
|
+
*/
|
|
495
|
+
var LosslessNumber = class {
|
|
496
|
+
isLosslessNumber = true;
|
|
497
|
+
constructor(value) {
|
|
498
|
+
if (!isNumber(value)) throw new Error(`Invalid number (value: "${value}")`);
|
|
499
|
+
this.value = value;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Get the value of the LosslessNumber as number or bigint.
|
|
503
|
+
*
|
|
504
|
+
* - a number is returned for safe numbers and decimal values that only lose some insignificant digits
|
|
505
|
+
* - a bigint is returned for big integer numbers
|
|
506
|
+
* - an Error is thrown for values that will overflow or underflow
|
|
507
|
+
*
|
|
508
|
+
* Note that you can implement your own strategy for conversion by just getting the value as string
|
|
509
|
+
* via .toString(), and using util functions like isInteger, isSafeNumber, getUnsafeNumberReason,
|
|
510
|
+
* and toSafeNumberOrThrow to convert it to a numeric value.
|
|
511
|
+
*/
|
|
512
|
+
valueOf() {
|
|
513
|
+
const unsafeReason = getUnsafeNumberReason(this.value);
|
|
514
|
+
if (unsafeReason === void 0 || unsafeReason === UnsafeNumberReason.truncate_float) return Number.parseFloat(this.value);
|
|
515
|
+
if (isInteger(this.value)) return BigInt(this.value);
|
|
516
|
+
throw new Error(`Cannot safely convert to number: the value '${this.value}' would ${unsafeReason} and become ${Number.parseFloat(this.value)}`);
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Get the value of the LosslessNumber as string.
|
|
520
|
+
*/
|
|
521
|
+
toString() {
|
|
522
|
+
return this.value;
|
|
20
523
|
}
|
|
21
|
-
return to;
|
|
22
524
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
525
|
+
/**
|
|
526
|
+
* Test whether a value is a LosslessNumber
|
|
527
|
+
*/
|
|
528
|
+
function isLosslessNumber(value) {
|
|
529
|
+
return value && typeof value === "object" && value.isLosslessNumber || false;
|
|
530
|
+
}
|
|
27
531
|
|
|
28
532
|
//#endregion
|
|
29
|
-
|
|
30
|
-
|
|
533
|
+
//#region node_modules/lossless-json/lib/esm/numberParsers.js
|
|
534
|
+
function parseLosslessNumber(value) {
|
|
535
|
+
return new LosslessNumber(value);
|
|
536
|
+
}
|
|
31
537
|
|
|
538
|
+
//#endregion
|
|
539
|
+
//#region node_modules/lossless-json/lib/esm/revive.js
|
|
540
|
+
/**
|
|
541
|
+
* Revive a json object.
|
|
542
|
+
* Applies the reviver function recursively on all values in the JSON object.
|
|
543
|
+
* @param json A JSON Object, Array, or value
|
|
544
|
+
* @param reviver
|
|
545
|
+
* A reviver function invoked with arguments `key` and `value`,
|
|
546
|
+
* which must return a replacement value. The function context
|
|
547
|
+
* (`this`) is the Object or Array that contains the currently
|
|
548
|
+
* handled value.
|
|
549
|
+
*/
|
|
550
|
+
function revive(json, reviver) {
|
|
551
|
+
return reviveValue({ "": json }, "", json, reviver);
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Revive a value
|
|
555
|
+
*/
|
|
556
|
+
function reviveValue(context, key, value, reviver) {
|
|
557
|
+
if (Array.isArray(value)) return reviver.call(context, key, reviveArray(value, reviver));
|
|
558
|
+
if (value && typeof value === "object" && !isLosslessNumber(value)) return reviver.call(context, key, reviveObject(value, reviver));
|
|
559
|
+
return reviver.call(context, key, value);
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Revive the properties of an object
|
|
563
|
+
*/
|
|
564
|
+
function reviveObject(object, reviver) {
|
|
565
|
+
for (const key of Object.keys(object)) {
|
|
566
|
+
const value = reviveValue(object, key, object[key], reviver);
|
|
567
|
+
if (value !== void 0) object[key] = value;
|
|
568
|
+
else delete object[key];
|
|
569
|
+
}
|
|
570
|
+
return object;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Revive the properties of an Array
|
|
574
|
+
*/
|
|
575
|
+
function reviveArray(array, reviver) {
|
|
576
|
+
for (let i = 0; i < array.length; i++) array[i] = reviveValue(array, String(i), array[i], reviver);
|
|
577
|
+
return array;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
//#endregion
|
|
581
|
+
//#region node_modules/lossless-json/lib/esm/parse.js
|
|
582
|
+
/**
|
|
583
|
+
* The LosslessJSON.parse() method parses a string as JSON, optionally transforming
|
|
584
|
+
* the value produced by parsing.
|
|
585
|
+
*
|
|
586
|
+
* The parser is based on the parser of Tan Li Hou shared in
|
|
587
|
+
* https://lihautan.com/json-parser-with-javascript/
|
|
588
|
+
*
|
|
589
|
+
* @param text
|
|
590
|
+
* The string to parse as JSON. See the JSON object for a description of JSON syntax.
|
|
591
|
+
*
|
|
592
|
+
* @param [reviver]
|
|
593
|
+
* If a function, prescribes how the value originally produced by parsing is
|
|
594
|
+
* transformed, before being returned.
|
|
595
|
+
*
|
|
596
|
+
* @param [options=ParseOptions | NumberParserArgument]
|
|
597
|
+
* Pass a custom number parser. Input is a string, and the output can be unknown
|
|
598
|
+
* numeric value: number, bigint, LosslessNumber, or a custom BigNumber library.
|
|
599
|
+
*
|
|
600
|
+
* @returns Returns the Object corresponding to the given JSON text.
|
|
601
|
+
*
|
|
602
|
+
* @throws Throws a SyntaxError exception if the string to parse is not valid JSON.
|
|
603
|
+
*/
|
|
604
|
+
function parse(text, reviver, options) {
|
|
605
|
+
const optionsObj = typeof options === "function" ? { parseNumber: options } : options;
|
|
606
|
+
const parseNumber = optionsObj?.parseNumber ?? parseLosslessNumber;
|
|
607
|
+
const onDuplicateKey = optionsObj?.onDuplicateKey ?? throwDuplicateKey;
|
|
608
|
+
let i = 0;
|
|
609
|
+
const value = parseValue();
|
|
610
|
+
expectValue(value);
|
|
611
|
+
expectEndOfInput();
|
|
612
|
+
return reviver ? revive(value, reviver) : value;
|
|
613
|
+
function parseObject() {
|
|
614
|
+
if (text.charCodeAt(i) === codeOpeningBrace) {
|
|
615
|
+
i++;
|
|
616
|
+
skipWhitespace();
|
|
617
|
+
const object = {};
|
|
618
|
+
let initial = true;
|
|
619
|
+
while (i < text.length && text.charCodeAt(i) !== codeClosingBrace) {
|
|
620
|
+
if (!initial) {
|
|
621
|
+
eatComma();
|
|
622
|
+
skipWhitespace();
|
|
623
|
+
} else initial = false;
|
|
624
|
+
const start = i;
|
|
625
|
+
const key = parseString();
|
|
626
|
+
if (key === void 0) {
|
|
627
|
+
throwObjectKeyExpected();
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
skipWhitespace();
|
|
631
|
+
eatColon();
|
|
632
|
+
const value = parseValue();
|
|
633
|
+
if (value === void 0) {
|
|
634
|
+
throwObjectValueExpected();
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
if (Object.prototype.hasOwnProperty.call(object, key) && !isDeepEqual(value, object[key])) {
|
|
638
|
+
const returnedValue = onDuplicateKey({
|
|
639
|
+
key,
|
|
640
|
+
position: start + 1,
|
|
641
|
+
oldValue: object[key],
|
|
642
|
+
newValue: value
|
|
643
|
+
});
|
|
644
|
+
if (returnedValue !== void 0) object[key] = returnedValue;
|
|
645
|
+
} else object[key] = value;
|
|
646
|
+
}
|
|
647
|
+
if (text.charCodeAt(i) !== codeClosingBrace) throwObjectKeyOrEndExpected();
|
|
648
|
+
i++;
|
|
649
|
+
return object;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
function parseArray() {
|
|
653
|
+
if (text.charCodeAt(i) === codeOpeningBracket) {
|
|
654
|
+
i++;
|
|
655
|
+
skipWhitespace();
|
|
656
|
+
const array = [];
|
|
657
|
+
let initial = true;
|
|
658
|
+
while (i < text.length && text.charCodeAt(i) !== codeClosingBracket) {
|
|
659
|
+
if (!initial) eatComma();
|
|
660
|
+
else initial = false;
|
|
661
|
+
const value = parseValue();
|
|
662
|
+
expectArrayItem(value);
|
|
663
|
+
array.push(value);
|
|
664
|
+
}
|
|
665
|
+
if (text.charCodeAt(i) !== codeClosingBracket) throwArrayItemOrEndExpected();
|
|
666
|
+
i++;
|
|
667
|
+
return array;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
function parseValue() {
|
|
671
|
+
skipWhitespace();
|
|
672
|
+
const value = parseString() ?? parseNumeric() ?? parseObject() ?? parseArray() ?? parseKeyword("true", true) ?? parseKeyword("false", false) ?? parseKeyword("null", null);
|
|
673
|
+
skipWhitespace();
|
|
674
|
+
return value;
|
|
675
|
+
}
|
|
676
|
+
function parseKeyword(name, value) {
|
|
677
|
+
if (text.slice(i, i + name.length) === name) {
|
|
678
|
+
i += name.length;
|
|
679
|
+
return value;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
function skipWhitespace() {
|
|
683
|
+
while (isWhitespace(text.charCodeAt(i))) i++;
|
|
684
|
+
}
|
|
685
|
+
function parseString() {
|
|
686
|
+
if (text.charCodeAt(i) === codeDoubleQuote) {
|
|
687
|
+
i++;
|
|
688
|
+
let result = "";
|
|
689
|
+
while (i < text.length && text.charCodeAt(i) !== codeDoubleQuote) {
|
|
690
|
+
if (text.charCodeAt(i) === codeBackslash) {
|
|
691
|
+
const char = text[i + 1];
|
|
692
|
+
const escapeChar = escapeCharacters[char];
|
|
693
|
+
if (escapeChar !== void 0) {
|
|
694
|
+
result += escapeChar;
|
|
695
|
+
i++;
|
|
696
|
+
} else if (char === "u") {
|
|
697
|
+
if (isHex(text.charCodeAt(i + 2)) && isHex(text.charCodeAt(i + 3)) && isHex(text.charCodeAt(i + 4)) && isHex(text.charCodeAt(i + 5))) {
|
|
698
|
+
result += String.fromCharCode(Number.parseInt(text.slice(i + 2, i + 6), 16));
|
|
699
|
+
i += 5;
|
|
700
|
+
} else throwInvalidUnicodeCharacter(i);
|
|
701
|
+
} else throwInvalidEscapeCharacter(i);
|
|
702
|
+
} else if (isValidStringCharacter(text.charCodeAt(i))) result += text[i];
|
|
703
|
+
else throwInvalidCharacter(text[i]);
|
|
704
|
+
i++;
|
|
705
|
+
}
|
|
706
|
+
expectEndOfString();
|
|
707
|
+
i++;
|
|
708
|
+
return result;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
function parseNumeric() {
|
|
712
|
+
const start = i;
|
|
713
|
+
if (text.charCodeAt(i) === codeMinus) {
|
|
714
|
+
i++;
|
|
715
|
+
expectDigit(start);
|
|
716
|
+
}
|
|
717
|
+
if (text.charCodeAt(i) === codeZero) i++;
|
|
718
|
+
else if (isNonZeroDigit(text.charCodeAt(i))) {
|
|
719
|
+
i++;
|
|
720
|
+
while (isDigit(text.charCodeAt(i))) i++;
|
|
721
|
+
}
|
|
722
|
+
if (text.charCodeAt(i) === codeDot) {
|
|
723
|
+
i++;
|
|
724
|
+
expectDigit(start);
|
|
725
|
+
while (isDigit(text.charCodeAt(i))) i++;
|
|
726
|
+
}
|
|
727
|
+
if (text.charCodeAt(i) === 101 || text.charCodeAt(i) === 69) {
|
|
728
|
+
i++;
|
|
729
|
+
if (text.charCodeAt(i) === codeMinus || text.charCodeAt(i) === codePlus) i++;
|
|
730
|
+
expectDigit(start);
|
|
731
|
+
while (isDigit(text.charCodeAt(i))) i++;
|
|
732
|
+
}
|
|
733
|
+
if (i > start) return parseNumber(text.slice(start, i));
|
|
734
|
+
}
|
|
735
|
+
function eatComma() {
|
|
736
|
+
if (text.charCodeAt(i) !== codeComma) throw new SyntaxError(`Comma ',' expected after value ${gotAt()}`);
|
|
737
|
+
i++;
|
|
738
|
+
}
|
|
739
|
+
function eatColon() {
|
|
740
|
+
if (text.charCodeAt(i) !== codeColon) throw new SyntaxError(`Colon ':' expected after property name ${gotAt()}`);
|
|
741
|
+
i++;
|
|
742
|
+
}
|
|
743
|
+
function expectValue(value) {
|
|
744
|
+
if (value === void 0) throw new SyntaxError(`JSON value expected ${gotAt()}`);
|
|
745
|
+
}
|
|
746
|
+
function expectArrayItem(value) {
|
|
747
|
+
if (value === void 0) throw new SyntaxError(`Array item expected ${gotAt()}`);
|
|
748
|
+
}
|
|
749
|
+
function expectEndOfInput() {
|
|
750
|
+
if (i < text.length) throw new SyntaxError(`Expected end of input ${gotAt()}`);
|
|
751
|
+
}
|
|
752
|
+
function expectDigit(start) {
|
|
753
|
+
if (!isDigit(text.charCodeAt(i))) {
|
|
754
|
+
const numSoFar = text.slice(start, i);
|
|
755
|
+
throw new SyntaxError(`Invalid number '${numSoFar}', expecting a digit ${gotAt()}`);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
function expectEndOfString() {
|
|
759
|
+
if (text.charCodeAt(i) !== codeDoubleQuote) throw new SyntaxError(`End of string '"' expected ${gotAt()}`);
|
|
760
|
+
}
|
|
761
|
+
function throwObjectKeyExpected() {
|
|
762
|
+
throw new SyntaxError(`Quoted object key expected ${gotAt()}`);
|
|
763
|
+
}
|
|
764
|
+
function throwDuplicateKey(_ref) {
|
|
765
|
+
let { key, position } = _ref;
|
|
766
|
+
throw new SyntaxError(`Duplicate key '${key}' encountered at position ${position}`);
|
|
767
|
+
}
|
|
768
|
+
function throwObjectKeyOrEndExpected() {
|
|
769
|
+
throw new SyntaxError(`Quoted object key or end of object '}' expected ${gotAt()}`);
|
|
770
|
+
}
|
|
771
|
+
function throwArrayItemOrEndExpected() {
|
|
772
|
+
throw new SyntaxError(`Array item or end of array ']' expected ${gotAt()}`);
|
|
773
|
+
}
|
|
774
|
+
function throwInvalidCharacter(char) {
|
|
775
|
+
throw new SyntaxError(`Invalid character '${char}' ${pos()}`);
|
|
776
|
+
}
|
|
777
|
+
function throwInvalidEscapeCharacter(start) {
|
|
778
|
+
const chars = text.slice(start, start + 2);
|
|
779
|
+
throw new SyntaxError(`Invalid escape character '${chars}' ${pos()}`);
|
|
780
|
+
}
|
|
781
|
+
function throwObjectValueExpected() {
|
|
782
|
+
throw new SyntaxError(`Object value expected after ':' ${pos()}`);
|
|
783
|
+
}
|
|
784
|
+
function throwInvalidUnicodeCharacter(start) {
|
|
785
|
+
const chars = text.slice(start, start + 6);
|
|
786
|
+
throw new SyntaxError(`Invalid unicode character '${chars}' ${pos()}`);
|
|
787
|
+
}
|
|
788
|
+
function pos() {
|
|
789
|
+
return `at position ${i}`;
|
|
790
|
+
}
|
|
791
|
+
function got() {
|
|
792
|
+
return i < text.length ? `but got '${text[i]}'` : "but reached end of input";
|
|
793
|
+
}
|
|
794
|
+
function gotAt() {
|
|
795
|
+
return `${got()} ${pos()}`;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
function isWhitespace(code) {
|
|
799
|
+
return code === codeSpace || code === codeNewline || code === codeTab || code === codeReturn;
|
|
800
|
+
}
|
|
801
|
+
function isHex(code) {
|
|
802
|
+
return code >= codeZero && code <= codeNine || code >= 65 && code <= 70 || code >= 97 && code <= 102;
|
|
803
|
+
}
|
|
804
|
+
function isDigit(code) {
|
|
805
|
+
return code >= codeZero && code <= codeNine;
|
|
806
|
+
}
|
|
807
|
+
function isNonZeroDigit(code) {
|
|
808
|
+
return code >= codeOne && code <= codeNine;
|
|
809
|
+
}
|
|
810
|
+
function isValidStringCharacter(code) {
|
|
811
|
+
return code >= 32 && code <= 1114111;
|
|
812
|
+
}
|
|
813
|
+
function isDeepEqual(a, b) {
|
|
814
|
+
if (a === b) return true;
|
|
815
|
+
if (Array.isArray(a) && Array.isArray(b)) return a.length === b.length && a.every((item, index) => isDeepEqual(item, b[index]));
|
|
816
|
+
if (isObject$1(a) && isObject$1(b)) return [.../* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])].every((key) => isDeepEqual(a[key], b[key]));
|
|
817
|
+
return false;
|
|
818
|
+
}
|
|
819
|
+
function isObject$1(value) {
|
|
820
|
+
return typeof value === "object" && value !== null;
|
|
821
|
+
}
|
|
822
|
+
const escapeCharacters = {
|
|
823
|
+
"\"": "\"",
|
|
824
|
+
"\\": "\\",
|
|
825
|
+
"/": "/",
|
|
826
|
+
b: "\b",
|
|
827
|
+
f: "\f",
|
|
828
|
+
n: "\n",
|
|
829
|
+
r: "\r",
|
|
830
|
+
t: " "
|
|
831
|
+
};
|
|
832
|
+
const codeBackslash = 92;
|
|
833
|
+
const codeOpeningBrace = 123;
|
|
834
|
+
const codeClosingBrace = 125;
|
|
835
|
+
const codeOpeningBracket = 91;
|
|
836
|
+
const codeClosingBracket = 93;
|
|
837
|
+
const codeSpace = 32;
|
|
838
|
+
const codeNewline = 10;
|
|
839
|
+
const codeTab = 9;
|
|
840
|
+
const codeReturn = 13;
|
|
841
|
+
const codeDoubleQuote = 34;
|
|
842
|
+
const codePlus = 43;
|
|
843
|
+
const codeMinus = 45;
|
|
844
|
+
const codeZero = 48;
|
|
845
|
+
const codeOne = 49;
|
|
846
|
+
const codeNine = 57;
|
|
847
|
+
const codeComma = 44;
|
|
848
|
+
const codeDot = 46;
|
|
849
|
+
const codeColon = 58;
|
|
850
|
+
const codeUppercaseA = 65;
|
|
851
|
+
const codeLowercaseA = 97;
|
|
852
|
+
const codeUppercaseE = 69;
|
|
853
|
+
const codeLowercaseE = 101;
|
|
854
|
+
const codeUppercaseF = 70;
|
|
855
|
+
const codeLowercaseF = 102;
|
|
856
|
+
|
|
857
|
+
//#endregion
|
|
858
|
+
//#region src/analytics.ts
|
|
859
|
+
/** Decode feed IDs before a native JSON parser can round their UInt64 values. */
|
|
860
|
+
function parseFeedResponse(raw) {
|
|
861
|
+
const page = parse(raw, void 0, { onDuplicateKey: ({ newValue }) => newValue });
|
|
862
|
+
if (!isObject(page) || !Array.isArray(page.results)) throw new TypeError("Expected a feed response with a results array.");
|
|
863
|
+
for (const record of page.results) {
|
|
864
|
+
if (!isObject(record)) throw new TypeError("Expected a feed record.");
|
|
865
|
+
const id = isLosslessNumber(record.id) ? record.id.value : record.id;
|
|
866
|
+
if (typeof id !== "string" || !/^(0|[1-9]\d*)$/u.test(id) || id.length > 20 || id.length === 20 && id > "18446744073709551615") throw new TypeError("Expected a decimal UInt64 feed ID.");
|
|
867
|
+
record.id = id;
|
|
868
|
+
}
|
|
869
|
+
return nativeValues(page);
|
|
870
|
+
}
|
|
871
|
+
function isObject(value) {
|
|
872
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
873
|
+
}
|
|
874
|
+
function nativeValues(value) {
|
|
875
|
+
if (isLosslessNumber(value)) return Number(value.value);
|
|
876
|
+
if (Array.isArray(value)) return value.map(nativeValues);
|
|
877
|
+
if (isObject(value)) return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, nativeValues(item)]));
|
|
878
|
+
return value;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
//#endregion
|
|
32
882
|
//#region src/errors.ts
|
|
33
883
|
const encoder$1 = new TextEncoder();
|
|
34
884
|
var ProxyRequestError = class extends Error {
|
|
@@ -924,11 +1774,11 @@ var LocationsResource = class {
|
|
|
924
1774
|
this.#client = client;
|
|
925
1775
|
}
|
|
926
1776
|
/** List available autonomous systems */
|
|
927
|
-
async listAsns(options
|
|
1777
|
+
async listAsns(options) {
|
|
928
1778
|
return (await this.listAsnsWithResponse(options)).data;
|
|
929
1779
|
}
|
|
930
1780
|
/** List available autonomous systems; include response metadata. */
|
|
931
|
-
async listAsnsWithResponse(options
|
|
1781
|
+
async listAsnsWithResponse(options) {
|
|
932
1782
|
return this.#client._callWithResponse({
|
|
933
1783
|
operationId: "locations_asn_list",
|
|
934
1784
|
method: "GET",
|
|
@@ -950,11 +1800,11 @@ var LocationsResource = class {
|
|
|
950
1800
|
});
|
|
951
1801
|
}
|
|
952
1802
|
/** List available cities */
|
|
953
|
-
async listCities(options
|
|
1803
|
+
async listCities(options) {
|
|
954
1804
|
return (await this.listCitiesWithResponse(options)).data;
|
|
955
1805
|
}
|
|
956
1806
|
/** List available cities; include response metadata. */
|
|
957
|
-
async listCitiesWithResponse(options
|
|
1807
|
+
async listCitiesWithResponse(options) {
|
|
958
1808
|
return this.#client._callWithResponse({
|
|
959
1809
|
operationId: "locations_cities_list",
|
|
960
1810
|
method: "GET",
|
|
@@ -987,16 +1837,17 @@ var LocationsResource = class {
|
|
|
987
1837
|
path: "/locations/cities/{id}"
|
|
988
1838
|
}, {
|
|
989
1839
|
path: { id: options.id },
|
|
1840
|
+
query: { package_id: options.packageId },
|
|
990
1841
|
headers: { "Accept-Language": options.acceptLanguage },
|
|
991
1842
|
...options.request === void 0 ? {} : { request: options.request }
|
|
992
1843
|
});
|
|
993
1844
|
}
|
|
994
1845
|
/** List available continents */
|
|
995
|
-
async listContinents(options
|
|
1846
|
+
async listContinents(options) {
|
|
996
1847
|
return (await this.listContinentsWithResponse(options)).data;
|
|
997
1848
|
}
|
|
998
1849
|
/** List available continents; include response metadata. */
|
|
999
|
-
async listContinentsWithResponse(options
|
|
1850
|
+
async listContinentsWithResponse(options) {
|
|
1000
1851
|
return this.#client._callWithResponse({
|
|
1001
1852
|
operationId: "locations_continents_list",
|
|
1002
1853
|
method: "GET",
|
|
@@ -1027,16 +1878,17 @@ var LocationsResource = class {
|
|
|
1027
1878
|
path: "/locations/continents/{id}"
|
|
1028
1879
|
}, {
|
|
1029
1880
|
path: { id: options.id },
|
|
1881
|
+
query: { package_id: options.packageId },
|
|
1030
1882
|
headers: { "Accept-Language": options.acceptLanguage },
|
|
1031
1883
|
...options.request === void 0 ? {} : { request: options.request }
|
|
1032
1884
|
});
|
|
1033
1885
|
}
|
|
1034
1886
|
/** List available countries */
|
|
1035
|
-
async listCountries(options
|
|
1887
|
+
async listCountries(options) {
|
|
1036
1888
|
return (await this.listCountriesWithResponse(options)).data;
|
|
1037
1889
|
}
|
|
1038
1890
|
/** List available countries; include response metadata. */
|
|
1039
|
-
async listCountriesWithResponse(options
|
|
1891
|
+
async listCountriesWithResponse(options) {
|
|
1040
1892
|
return this.#client._callWithResponse({
|
|
1041
1893
|
operationId: "locations_countries_list",
|
|
1042
1894
|
method: "GET",
|
|
@@ -1067,16 +1919,17 @@ var LocationsResource = class {
|
|
|
1067
1919
|
path: "/locations/countries/{id}"
|
|
1068
1920
|
}, {
|
|
1069
1921
|
path: { id: options.id },
|
|
1922
|
+
query: { package_id: options.packageId },
|
|
1070
1923
|
headers: { "Accept-Language": options.acceptLanguage },
|
|
1071
1924
|
...options.request === void 0 ? {} : { request: options.request }
|
|
1072
1925
|
});
|
|
1073
1926
|
}
|
|
1074
1927
|
/** List available internet service providers */
|
|
1075
|
-
async listIsps(options
|
|
1928
|
+
async listIsps(options) {
|
|
1076
1929
|
return (await this.listIspsWithResponse(options)).data;
|
|
1077
1930
|
}
|
|
1078
1931
|
/** List available internet service providers; include response metadata. */
|
|
1079
|
-
async listIspsWithResponse(options
|
|
1932
|
+
async listIspsWithResponse(options) {
|
|
1080
1933
|
return this.#client._callWithResponse({
|
|
1081
1934
|
operationId: "locations_isps_list",
|
|
1082
1935
|
method: "GET",
|
|
@@ -1097,11 +1950,11 @@ var LocationsResource = class {
|
|
|
1097
1950
|
});
|
|
1098
1951
|
}
|
|
1099
1952
|
/** List available regions */
|
|
1100
|
-
async listRegions(options
|
|
1953
|
+
async listRegions(options) {
|
|
1101
1954
|
return (await this.listRegionsWithResponse(options)).data;
|
|
1102
1955
|
}
|
|
1103
1956
|
/** List available regions; include response metadata. */
|
|
1104
|
-
async listRegionsWithResponse(options
|
|
1957
|
+
async listRegionsWithResponse(options) {
|
|
1105
1958
|
return this.#client._callWithResponse({
|
|
1106
1959
|
operationId: "locations_regions_list",
|
|
1107
1960
|
method: "GET",
|
|
@@ -1133,6 +1986,7 @@ var LocationsResource = class {
|
|
|
1133
1986
|
path: "/locations/regions/{id}"
|
|
1134
1987
|
}, {
|
|
1135
1988
|
path: { id: options.id },
|
|
1989
|
+
query: { package_id: options.packageId },
|
|
1136
1990
|
headers: { "Accept-Language": options.acceptLanguage },
|
|
1137
1991
|
...options.request === void 0 ? {} : { request: options.request }
|
|
1138
1992
|
});
|
|
@@ -1645,11 +2499,11 @@ var UsersResource = class {
|
|
|
1645
2499
|
...options.request === void 0 ? {} : { request: options.request }
|
|
1646
2500
|
});
|
|
1647
2501
|
}
|
|
1648
|
-
/** Create a
|
|
2502
|
+
/** Create a customer account */
|
|
1649
2503
|
async create(options) {
|
|
1650
2504
|
return (await this.createWithResponse(options)).data;
|
|
1651
2505
|
}
|
|
1652
|
-
/** Create a
|
|
2506
|
+
/** Create a customer account; include response metadata. */
|
|
1653
2507
|
async createWithResponse(options) {
|
|
1654
2508
|
return this.#client._callWithResponse({
|
|
1655
2509
|
operationId: "users_create",
|
|
@@ -1764,6 +2618,27 @@ var UsersResource = class {
|
|
|
1764
2618
|
...options.request === void 0 ? {} : { request: options.request }
|
|
1765
2619
|
});
|
|
1766
2620
|
}
|
|
2621
|
+
/** Reset a user's remaining data */
|
|
2622
|
+
async resetData(options) {
|
|
2623
|
+
return (await this.resetDataWithResponse(options)).data;
|
|
2624
|
+
}
|
|
2625
|
+
/** Reset a user's remaining data; include response metadata. */
|
|
2626
|
+
async resetDataWithResponse(options) {
|
|
2627
|
+
return this.#client._callWithResponse({
|
|
2628
|
+
operationId: "users_data_reset_create",
|
|
2629
|
+
method: "POST",
|
|
2630
|
+
path: "/users/{id}/data/reset",
|
|
2631
|
+
idempotent: true
|
|
2632
|
+
}, {
|
|
2633
|
+
path: { id: options.id },
|
|
2634
|
+
headers: {
|
|
2635
|
+
"Idempotency-Key": options.idempotencyKey,
|
|
2636
|
+
"Accept-Language": options.acceptLanguage
|
|
2637
|
+
},
|
|
2638
|
+
body: options.body,
|
|
2639
|
+
...options.request === void 0 ? {} : { request: options.request }
|
|
2640
|
+
});
|
|
2641
|
+
}
|
|
1767
2642
|
/** List a sub-user's orders */
|
|
1768
2643
|
async listOrders(options) {
|
|
1769
2644
|
return (await this.listOrdersWithResponse(options)).data;
|
|
@@ -1801,7 +2676,7 @@ var UsersResource = class {
|
|
|
1801
2676
|
}, {
|
|
1802
2677
|
path: { id: options.id },
|
|
1803
2678
|
headers: { "Accept-Language": options.acceptLanguage },
|
|
1804
|
-
|
|
2679
|
+
body: options.body,
|
|
1805
2680
|
...options.request === void 0 ? {} : { request: options.request }
|
|
1806
2681
|
});
|
|
1807
2682
|
}
|
|
@@ -1948,7 +2823,7 @@ function offsetFromUrl(url) {
|
|
|
1948
2823
|
//#endregion
|
|
1949
2824
|
//#region src/client.ts
|
|
1950
2825
|
const DEFAULT_BASE_URL = "https://api.proxyrequest.com/api/v1";
|
|
1951
|
-
const SDK_VERSION = "
|
|
2826
|
+
const SDK_VERSION = "3.0.1";
|
|
1952
2827
|
var ProxyRequestClient = class ProxyRequestClient {
|
|
1953
2828
|
apiKeys;
|
|
1954
2829
|
affiliates;
|
|
@@ -1986,7 +2861,7 @@ var ProxyRequestClient = class ProxyRequestClient {
|
|
|
1986
2861
|
this.#headers.set("Accept-Language", this.language);
|
|
1987
2862
|
if (options.apiKey !== void 0) this.#headers.set("Authorization", `Static ${options.apiKey}`);
|
|
1988
2863
|
if (options.bearerToken !== void 0) this.#headers.set("Authorization", `Bearer ${options.bearerToken}`);
|
|
1989
|
-
this.#openapi = (
|
|
2864
|
+
this.#openapi = createClient({
|
|
1990
2865
|
baseUrl: this.baseUrl,
|
|
1991
2866
|
fetch: this.#fetch,
|
|
1992
2867
|
headers: this.#headers
|
|
@@ -2060,10 +2935,10 @@ var ProxyRequestClient = class ProxyRequestClient {
|
|
|
2060
2935
|
...data.body === void 0 ? {} : { body: data.body },
|
|
2061
2936
|
...[...controlHeaders].length === 0 ? {} : { headers: controlHeaders },
|
|
2062
2937
|
signal: timeout.signal,
|
|
2063
|
-
...spec.binary ? { parseAs: "arrayBuffer" } : {}
|
|
2938
|
+
...spec.binary ? { parseAs: "arrayBuffer" } : spec.operationId === "analytics_feed_retrieve" ? { parseAs: "text" } : {}
|
|
2064
2939
|
});
|
|
2065
2940
|
if (result.error !== void 0) throw ApiError.unexpected(`ProxyRequest returned an undocumented error for ${spec.operationId}.`, result.error);
|
|
2066
|
-
const dataValue = spec.binary ? binaryResult(spec, result.data, result.response.headers) : result.data;
|
|
2941
|
+
const dataValue = spec.binary ? binaryResult(spec, result.data, result.response.headers) : spec.operationId === "analytics_feed_retrieve" ? parseFeedResponse(result.data) : result.data;
|
|
2067
2942
|
const headers = headersToRecord(result.response.headers);
|
|
2068
2943
|
const etag = headers.etag;
|
|
2069
2944
|
return {
|