@proxyrequest/sdk 2.1.0 → 4.0.0
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 +25 -2
- package/README.md +3 -0
- package/dist/index.cjs +876 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +882 -4
- package/dist/index.js.map +1 -1
- package/dist/{models-Ci7ojtEW.d.cts → models-CqqQyGmO.d.ts} +6 -3
- package/dist/models-CqqQyGmO.d.ts.map +1 -0
- package/dist/{models-rpFTQLRE.d.ts → models-D20OBuAe.d.cts} +6 -3
- package/dist/models-D20OBuAe.d.cts.map +1 -0
- 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-B2orTIrr.d.ts → schema-Dj3NSLe5.d.cts} +84 -57
- package/dist/schema-Dj3NSLe5.d.cts.map +1 -0
- package/dist/{schema-B2orTIrr.d.cts → schema-Dj3NSLe5.d.ts} +84 -57
- package/dist/schema-Dj3NSLe5.d.ts.map +1 -0
- package/docs/analytics.md +47 -0
- package/docs/reference/sdk-reference.json +16730 -0
- package/docs/third-party-notices.md +38 -0
- package/package.json +5 -3
- package/dist/models-Ci7ojtEW.d.cts.map +0 -1
- package/dist/models-rpFTQLRE.d.ts.map +0 -1
- package/dist/schema-B2orTIrr.d.cts.map +0 -1
- package/dist/schema-B2orTIrr.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
|
+
}
|
|
120
|
+
}
|
|
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;
|
|
18
313
|
}
|
|
314
|
+
search.push(serializePrimitiveParam(name, value, options));
|
|
19
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
|
+
}
|
|
531
|
+
|
|
532
|
+
//#endregion
|
|
533
|
+
//#region node_modules/lossless-json/lib/esm/numberParsers.js
|
|
534
|
+
function parseLosslessNumber(value) {
|
|
535
|
+
return new LosslessNumber(value);
|
|
536
|
+
}
|
|
27
537
|
|
|
28
538
|
//#endregion
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
}
|
|
31
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 {
|
|
@@ -1973,7 +2823,7 @@ function offsetFromUrl(url) {
|
|
|
1973
2823
|
//#endregion
|
|
1974
2824
|
//#region src/client.ts
|
|
1975
2825
|
const DEFAULT_BASE_URL = "https://api.proxyrequest.com/api/v1";
|
|
1976
|
-
const SDK_VERSION = "
|
|
2826
|
+
const SDK_VERSION = "4.0.0";
|
|
1977
2827
|
var ProxyRequestClient = class ProxyRequestClient {
|
|
1978
2828
|
apiKeys;
|
|
1979
2829
|
affiliates;
|
|
@@ -2011,7 +2861,7 @@ var ProxyRequestClient = class ProxyRequestClient {
|
|
|
2011
2861
|
this.#headers.set("Accept-Language", this.language);
|
|
2012
2862
|
if (options.apiKey !== void 0) this.#headers.set("Authorization", `Static ${options.apiKey}`);
|
|
2013
2863
|
if (options.bearerToken !== void 0) this.#headers.set("Authorization", `Bearer ${options.bearerToken}`);
|
|
2014
|
-
this.#openapi = (
|
|
2864
|
+
this.#openapi = createClient({
|
|
2015
2865
|
baseUrl: this.baseUrl,
|
|
2016
2866
|
fetch: this.#fetch,
|
|
2017
2867
|
headers: this.#headers
|
|
@@ -2085,10 +2935,10 @@ var ProxyRequestClient = class ProxyRequestClient {
|
|
|
2085
2935
|
...data.body === void 0 ? {} : { body: data.body },
|
|
2086
2936
|
...[...controlHeaders].length === 0 ? {} : { headers: controlHeaders },
|
|
2087
2937
|
signal: timeout.signal,
|
|
2088
|
-
...spec.binary ? { parseAs: "arrayBuffer" } : {}
|
|
2938
|
+
...spec.binary ? { parseAs: "arrayBuffer" } : spec.operationId === "analytics_feed_retrieve" ? { parseAs: "text" } : {}
|
|
2089
2939
|
});
|
|
2090
2940
|
if (result.error !== void 0) throw ApiError.unexpected(`ProxyRequest returned an undocumented error for ${spec.operationId}.`, result.error);
|
|
2091
|
-
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;
|
|
2092
2942
|
const headers = headersToRecord(result.response.headers);
|
|
2093
2943
|
const etag = headers.etag;
|
|
2094
2944
|
return {
|