snapreq 0.0.8 → 0.0.10
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 +8 -5
- package/build/capabilities.d.ts +17 -17
- package/build/capabilities.d.ts.map +1 -1
- package/build/control.d.ts +12 -0
- package/build/control.d.ts.map +1 -0
- package/build/control.js +27 -0
- package/build/errors.d.ts +16 -16
- package/build/errors.d.ts.map +1 -1
- package/build/headers.d.ts +6 -6
- package/build/headers.d.ts.map +1 -1
- package/build/request.d.ts +15 -15
- package/build/request.d.ts.map +1 -1
- package/build/response.d.ts +27 -17
- package/build/response.d.ts.map +1 -1
- package/build/response.js +26 -2
- package/build/retry.d.ts +38 -37
- package/build/retry.d.ts.map +1 -1
- package/build/retry.js +40 -34
- package/build/snap-req.d.ts +116 -153
- package/build/snap-req.d.ts.map +1 -1
- package/build/snap-req.js +57 -102
- package/build/transports/fetch-transport.d.ts +10 -4
- package/build/transports/fetch-transport.d.ts.map +1 -1
- package/build/transports/fetch-transport.js +58 -12
- package/build/transports/fetch.d.ts.map +1 -1
- package/build/transports/node-transport.d.ts +23 -22
- package/build/transports/node-transport.d.ts.map +1 -1
- package/build/transports/node-transport.js +45 -10
- package/build/transports/proxy-bounce-transport.d.ts +4 -4
- package/build/transports/proxy-bounce-transport.d.ts.map +1 -1
- package/build/transports/select.d.ts +21 -21
- package/build/transports/select.d.ts.map +1 -1
- package/build/transports/xhr-transport.d.ts +2 -2
- package/build/transports/xhr-transport.d.ts.map +1 -1
- package/build/transports/xhr.d.ts.map +1 -1
- package/build/websocket/websocket-channel.d.ts +33 -22
- package/build/websocket/websocket-channel.d.ts.map +1 -1
- package/build/websocket/websocket-channel.js +27 -11
- package/build/websocket/websocket-client.d.ts +136 -65
- package/build/websocket/websocket-client.d.ts.map +1 -1
- package/build/websocket/websocket-client.js +221 -66
- package/build/websocket/websocket-connection.d.ts +19 -16
- package/build/websocket/websocket-connection.d.ts.map +1 -1
- package/build/websocket/websocket-connection.js +11 -3
- package/build/websocket.d.ts.map +1 -1
- package/package.json +6 -3
package/build/retry.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
import {
|
|
2
|
+
import { SnapReqTimeoutError } from "./errors.js";
|
|
3
|
+
import retry from "awaitery/build/retry.js";
|
|
3
4
|
const RETRYABLE_ERROR_CODES = new Set(["ECONNREFUSED", "ECONNRESET", "EHOSTUNREACH", "ENOENT", "ETIMEDOUT", "EPIPE"]);
|
|
4
5
|
const DEFAULT_RETRYABLE_STATUSES = [502, 503, 504];
|
|
5
6
|
/**
|
|
@@ -51,45 +52,50 @@ export function normalizeRetryOptions(retry) {
|
|
|
51
52
|
shouldRetry
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
class RetryableResponse extends Error {
|
|
56
|
+
/** @param {import("./response.js").default} response - Retryable response. */
|
|
57
|
+
constructor(response) {
|
|
58
|
+
super(`Retryable HTTP status ${response.status}`);
|
|
59
|
+
this.response = response;
|
|
60
|
+
}
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
63
|
* Runs a request attempt, retrying transient network errors and retryable HTTP
|
|
63
64
|
* statuses. Retries are only used for buffered requests — the caller must not
|
|
64
65
|
* apply this to streamed responses.
|
|
65
|
-
* @param {() => Promise<import("./response.js").default>} attempt - Performs one request attempt.
|
|
66
|
-
* @param {NormalizedRetryOptions}
|
|
66
|
+
* @param {(signal: AbortSignal | undefined) => Promise<import("./response.js").default>} attempt - Performs one request attempt.
|
|
67
|
+
* @param {NormalizedRetryOptions} retryOptions - Normalized retry settings.
|
|
68
|
+
* @param {AbortSignal} [signal] - Caller cancellation signal.
|
|
67
69
|
* @returns {Promise<import("./response.js").default>} - The successful (or final) response.
|
|
68
70
|
*/
|
|
69
|
-
export async function runWithRetry(attempt,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
71
|
+
export async function runWithRetry(attempt, retryOptions, signal) {
|
|
72
|
+
try {
|
|
73
|
+
return await retry({
|
|
74
|
+
tries: retryOptions.tries,
|
|
75
|
+
wait: retryOptions.waitMs,
|
|
76
|
+
signal,
|
|
77
|
+
shouldRetry: ({ error, tryNumber }) => {
|
|
78
|
+
if (error instanceof RetryableResponse) {
|
|
79
|
+
// Awaitery calls shouldRetry only when another attempt is available,
|
|
80
|
+
// and before its retry delay. The final response therefore remains
|
|
81
|
+
// caller-owned while every intermediate body is released promptly.
|
|
82
|
+
error.response._abortBody(error);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
return retryOptions.shouldRetry(error, tryNumber);
|
|
86
|
+
}
|
|
87
|
+
}, async ({ signal: attemptSignal } = /** @type {any} */ ({})) => {
|
|
88
|
+
const response = await attempt(attemptSignal);
|
|
89
|
+
if (retryOptions.retryableStatuses.includes(response.status)) {
|
|
90
|
+
throw new RetryableResponse(response);
|
|
91
|
+
}
|
|
92
|
+
return response;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (error instanceof RetryableResponse)
|
|
97
|
+
return error.response;
|
|
98
|
+
throw error;
|
|
87
99
|
}
|
|
88
|
-
throw new SnapReqHttpError({
|
|
89
|
-
message: "Retry loop exited without a response.",
|
|
90
|
-
method: "",
|
|
91
|
-
url: "",
|
|
92
|
-
status: 0
|
|
93
|
-
});
|
|
94
100
|
}
|
|
95
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
101
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmV0cnkuanMiLCJzb3VyY2VSb290IjoiIiw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SnapReqHeaders from "./headers.js";
|
|
3
|
+
export type CompressionEncoding = import("./request.js").CompressionEncoding;
|
|
4
|
+
export type NormalizedRequest = {
|
|
5
|
+
/**
|
|
6
|
+
* - Upper-cased HTTP method.
|
|
7
|
+
*/
|
|
8
|
+
method: string;
|
|
9
|
+
/**
|
|
10
|
+
* - Fully resolved request URL.
|
|
11
|
+
*/
|
|
12
|
+
url: string;
|
|
13
|
+
/**
|
|
14
|
+
* - Request headers.
|
|
15
|
+
*/
|
|
16
|
+
headers: SnapReqHeaders;
|
|
17
|
+
/**
|
|
18
|
+
* - Normalized request body.
|
|
19
|
+
*/
|
|
20
|
+
body: import("./request.js").NormalizedBody;
|
|
21
|
+
/**
|
|
22
|
+
* - Request body compression.
|
|
23
|
+
*/
|
|
24
|
+
bodyCompression: CompressionEncoding;
|
|
25
|
+
/**
|
|
26
|
+
* - Abort signal.
|
|
27
|
+
*/
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
/**
|
|
30
|
+
* - Request timeout in milliseconds.
|
|
31
|
+
*/
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
/**
|
|
34
|
+
* - Fetch credentials mode ("omit" | "same-origin" | "include").
|
|
35
|
+
*/
|
|
36
|
+
credentials?: string;
|
|
37
|
+
};
|
|
38
|
+
export type RequestOptions = {
|
|
39
|
+
/**
|
|
40
|
+
* - HTTP method. Defaults to GET.
|
|
41
|
+
*/
|
|
42
|
+
method?: string;
|
|
43
|
+
/**
|
|
44
|
+
* - Request path (joined with the client `baseUrl`) or absolute URL.
|
|
45
|
+
*/
|
|
46
|
+
path?: string;
|
|
47
|
+
/**
|
|
48
|
+
* - Alias for `path`.
|
|
49
|
+
*/
|
|
50
|
+
url?: string;
|
|
51
|
+
/**
|
|
52
|
+
* - Query parameters.
|
|
53
|
+
*/
|
|
54
|
+
query?: Record<string, string | number | boolean | null | undefined>;
|
|
55
|
+
/**
|
|
56
|
+
* - Per-request headers.
|
|
57
|
+
*/
|
|
58
|
+
headers?: Record<string, string | number> | SnapReqHeaders;
|
|
59
|
+
/**
|
|
60
|
+
* - Request body: string, object (JSON), Uint8Array/ArrayBuffer, or a stream/async-iterable.
|
|
61
|
+
*/
|
|
62
|
+
body?: any;
|
|
63
|
+
/**
|
|
64
|
+
* - Compress the request body (Node transport only).
|
|
65
|
+
*/
|
|
66
|
+
bodyCompression?: CompressionEncoding;
|
|
67
|
+
/**
|
|
68
|
+
* - Abort signal for the request.
|
|
69
|
+
*/
|
|
70
|
+
signal?: AbortSignal;
|
|
71
|
+
/**
|
|
72
|
+
* - Request timeout in milliseconds. Set to `0` to disable a client default.
|
|
73
|
+
*/
|
|
74
|
+
timeoutMs?: number;
|
|
75
|
+
/**
|
|
76
|
+
* - Fetch credentials mode.
|
|
77
|
+
*/
|
|
78
|
+
credentials?: string;
|
|
79
|
+
/**
|
|
80
|
+
* - Retry transient failures.
|
|
81
|
+
*/
|
|
82
|
+
retry?: boolean | import("./retry.js").RetryOptions;
|
|
83
|
+
/**
|
|
84
|
+
* - Throw `SnapReqHttpError` on non-2xx responses.
|
|
85
|
+
*/
|
|
86
|
+
throwOnError?: boolean;
|
|
87
|
+
};
|
|
1
88
|
/**
|
|
2
89
|
* @typedef {import("./request.js").CompressionEncoding} CompressionEncoding
|
|
3
90
|
*/
|
|
@@ -27,13 +114,6 @@
|
|
|
27
114
|
* @property {boolean | import("./retry.js").RetryOptions} [retry] - Retry transient failures.
|
|
28
115
|
* @property {boolean} [throwOnError] - Throw `SnapReqHttpError` on non-2xx responses.
|
|
29
116
|
*/
|
|
30
|
-
/**
|
|
31
|
-
* @typedef {object} RequestTimeout
|
|
32
|
-
* @property {AbortSignal | undefined} signal - Signal to use for the request.
|
|
33
|
-
* @property {() => void} clear - Clears timeout resources.
|
|
34
|
-
* @property {(response: import("./response.js").default, request: NormalizedRequest) => import("./response.js").default} response - Attaches timeout handling to a response.
|
|
35
|
-
* @property {(error: unknown, request: NormalizedRequest) => unknown} error - Maps a thrown error.
|
|
36
|
-
*/
|
|
37
117
|
/**
|
|
38
118
|
* A cross-platform HTTP client with one API across Node, web, Expo and React
|
|
39
119
|
* Native. The right transport is chosen at runtime; features a platform cannot
|
|
@@ -41,6 +121,27 @@
|
|
|
41
121
|
* behaviour.
|
|
42
122
|
*/
|
|
43
123
|
export default class SnapReq {
|
|
124
|
+
baseUrl: string;
|
|
125
|
+
defaultHeaders: Record<string, string | number> | (() => Record<string, string | number>);
|
|
126
|
+
defaultRetry: boolean | import("./retry.js").RetryOptions;
|
|
127
|
+
throwOnError: boolean;
|
|
128
|
+
timeoutMs: number;
|
|
129
|
+
credentials: string;
|
|
130
|
+
_transportPreference: import("./transports/select.js").Transport | import("./transports/select.js").TransportName;
|
|
131
|
+
_nodeConfig: {
|
|
132
|
+
socketPath: string;
|
|
133
|
+
tls: {
|
|
134
|
+
ca?: string | Buffer;
|
|
135
|
+
cert?: string | Buffer;
|
|
136
|
+
key?: string | Buffer;
|
|
137
|
+
rejectUnauthorized?: boolean;
|
|
138
|
+
};
|
|
139
|
+
keepAlive: boolean;
|
|
140
|
+
};
|
|
141
|
+
/** @type {Promise<import("./transports/select.js").Transport> | null} */
|
|
142
|
+
_transportPromise: Promise<import("./transports/select.js").Transport> | null;
|
|
143
|
+
/** @type {import("./transports/select.js").Transport | null} */
|
|
144
|
+
_transport: import("./transports/select.js").Transport | null;
|
|
44
145
|
/**
|
|
45
146
|
* @param {object} [config] - Client configuration.
|
|
46
147
|
* @param {string} [config.baseUrl] - Origin (and optional base path) prepended to relative paths.
|
|
@@ -71,27 +172,6 @@ export default class SnapReq {
|
|
|
71
172
|
credentials?: string;
|
|
72
173
|
transport?: import("./transports/select.js").TransportName | import("./transports/select.js").Transport;
|
|
73
174
|
});
|
|
74
|
-
baseUrl: string;
|
|
75
|
-
defaultHeaders: Record<string, string | number> | (() => Record<string, string | number>);
|
|
76
|
-
defaultRetry: boolean | import("./retry.js").RetryOptions;
|
|
77
|
-
throwOnError: boolean;
|
|
78
|
-
timeoutMs: number;
|
|
79
|
-
credentials: string;
|
|
80
|
-
_transportPreference: import("./transports/select.js").TransportName | import("./transports/select.js").Transport;
|
|
81
|
-
_nodeConfig: {
|
|
82
|
-
socketPath: string;
|
|
83
|
-
tls: {
|
|
84
|
-
ca?: string | Buffer;
|
|
85
|
-
cert?: string | Buffer;
|
|
86
|
-
key?: string | Buffer;
|
|
87
|
-
rejectUnauthorized?: boolean;
|
|
88
|
-
};
|
|
89
|
-
keepAlive: boolean;
|
|
90
|
-
};
|
|
91
|
-
/** @type {Promise<import("./transports/select.js").Transport> | null} */
|
|
92
|
-
_transportPromise: Promise<import("./transports/select.js").Transport> | null;
|
|
93
|
-
/** @type {import("./transports/select.js").Transport | null} */
|
|
94
|
-
_transport: import("./transports/select.js").Transport | null;
|
|
95
175
|
/** @returns {Promise<import("./transports/select.js").Transport>} - The resolved transport. */
|
|
96
176
|
_resolveTransport(): Promise<import("./transports/select.js").Transport>;
|
|
97
177
|
/** @returns {Promise<import("./capabilities.js").TransportCapabilities>} - The active transport's capabilities. */
|
|
@@ -103,32 +183,12 @@ export default class SnapReq {
|
|
|
103
183
|
* @returns {NormalizedRequest} - The normalized request.
|
|
104
184
|
*/
|
|
105
185
|
_normalize(options: RequestOptions): NormalizedRequest;
|
|
106
|
-
/**
|
|
107
|
-
* @param {RequestOptions} options - Request options.
|
|
108
|
-
* @returns {RequestTimeout} - Timeout handling for one request attempt.
|
|
109
|
-
*/
|
|
110
|
-
_requestTimeout(options: RequestOptions): RequestTimeout;
|
|
111
|
-
/**
|
|
112
|
-
* @param {AbortSignal | undefined} callerSignal - Caller-supplied signal.
|
|
113
|
-
* @param {AbortSignal} timeoutSignal - Timeout signal.
|
|
114
|
-
* @returns {{signal: AbortSignal, clear: () => void}} - Signal that aborts when either source aborts.
|
|
115
|
-
*/
|
|
116
|
-
_composeSignal(callerSignal: AbortSignal | undefined, timeoutSignal: AbortSignal): {
|
|
117
|
-
signal: AbortSignal;
|
|
118
|
-
clear: () => void;
|
|
119
|
-
};
|
|
120
186
|
/**
|
|
121
187
|
* @param {(() => void) | undefined} existing - Existing body-done callback.
|
|
122
188
|
* @param {() => void} next - Callback to add.
|
|
123
189
|
* @returns {() => void} - Combined callback.
|
|
124
190
|
*/
|
|
125
191
|
_chainBodyDone(existing: (() => void) | undefined, next: () => void): () => void;
|
|
126
|
-
/**
|
|
127
|
-
* @param {((error: unknown) => unknown) | undefined} existing - Existing error mapper.
|
|
128
|
-
* @param {(error: unknown) => unknown} next - Mapper to add.
|
|
129
|
-
* @returns {(error: unknown) => unknown} - Combined mapper.
|
|
130
|
-
*/
|
|
131
|
-
_chainBodyError(existing: ((error: unknown) => unknown) | undefined, next: (error: unknown) => unknown): (error: unknown) => unknown;
|
|
132
192
|
/**
|
|
133
193
|
* Performs a request and buffers nothing eagerly — read the body via the
|
|
134
194
|
* returned response (`json()`, `text()`, `bytes()`). Retries transient
|
|
@@ -151,6 +211,14 @@ export default class SnapReq {
|
|
|
151
211
|
* @returns {Promise<import("./response.js").default>} - Response with timeout handling attached.
|
|
152
212
|
*/
|
|
153
213
|
_requestWithTimeout(options: RequestOptions, performRequest: (request: NormalizedRequest) => Promise<import("./response.js").default>): Promise<import("./response.js").default>;
|
|
214
|
+
/**
|
|
215
|
+
* @param {unknown} error - Awaitery/transport error.
|
|
216
|
+
* @param {NormalizedRequest} request - Request metadata.
|
|
217
|
+
* @param {number | undefined} timeoutMs - Attempt timeout.
|
|
218
|
+
* @param {AbortSignal | undefined} callerSignal - Caller cancellation.
|
|
219
|
+
* @returns {unknown} - Stable public Snapreq error.
|
|
220
|
+
*/
|
|
221
|
+
_requestControlError(error: unknown, request: NormalizedRequest, timeoutMs: number | undefined, callerSignal: AbortSignal | undefined): unknown;
|
|
154
222
|
/**
|
|
155
223
|
* @param {string} path - Request path or absolute URL.
|
|
156
224
|
* @param {RequestOptions} [options] - Request options.
|
|
@@ -196,109 +264,4 @@ export default class SnapReq {
|
|
|
196
264
|
*/
|
|
197
265
|
close(): void;
|
|
198
266
|
}
|
|
199
|
-
export type CompressionEncoding = import("./request.js").CompressionEncoding;
|
|
200
|
-
export type NormalizedRequest = {
|
|
201
|
-
/**
|
|
202
|
-
* - Upper-cased HTTP method.
|
|
203
|
-
*/
|
|
204
|
-
method: string;
|
|
205
|
-
/**
|
|
206
|
-
* - Fully resolved request URL.
|
|
207
|
-
*/
|
|
208
|
-
url: string;
|
|
209
|
-
/**
|
|
210
|
-
* - Request headers.
|
|
211
|
-
*/
|
|
212
|
-
headers: SnapReqHeaders;
|
|
213
|
-
/**
|
|
214
|
-
* - Normalized request body.
|
|
215
|
-
*/
|
|
216
|
-
body: import("./request.js").NormalizedBody;
|
|
217
|
-
/**
|
|
218
|
-
* - Request body compression.
|
|
219
|
-
*/
|
|
220
|
-
bodyCompression: CompressionEncoding;
|
|
221
|
-
/**
|
|
222
|
-
* - Abort signal.
|
|
223
|
-
*/
|
|
224
|
-
signal?: AbortSignal;
|
|
225
|
-
/**
|
|
226
|
-
* - Request timeout in milliseconds.
|
|
227
|
-
*/
|
|
228
|
-
timeoutMs?: number;
|
|
229
|
-
/**
|
|
230
|
-
* - Fetch credentials mode ("omit" | "same-origin" | "include").
|
|
231
|
-
*/
|
|
232
|
-
credentials?: string;
|
|
233
|
-
};
|
|
234
|
-
export type RequestOptions = {
|
|
235
|
-
/**
|
|
236
|
-
* - HTTP method. Defaults to GET.
|
|
237
|
-
*/
|
|
238
|
-
method?: string;
|
|
239
|
-
/**
|
|
240
|
-
* - Request path (joined with the client `baseUrl`) or absolute URL.
|
|
241
|
-
*/
|
|
242
|
-
path?: string;
|
|
243
|
-
/**
|
|
244
|
-
* - Alias for `path`.
|
|
245
|
-
*/
|
|
246
|
-
url?: string;
|
|
247
|
-
/**
|
|
248
|
-
* - Query parameters.
|
|
249
|
-
*/
|
|
250
|
-
query?: Record<string, string | number | boolean | null | undefined>;
|
|
251
|
-
/**
|
|
252
|
-
* - Per-request headers.
|
|
253
|
-
*/
|
|
254
|
-
headers?: Record<string, string | number> | SnapReqHeaders;
|
|
255
|
-
/**
|
|
256
|
-
* - Request body: string, object (JSON), Uint8Array/ArrayBuffer, or a stream/async-iterable.
|
|
257
|
-
*/
|
|
258
|
-
body?: any;
|
|
259
|
-
/**
|
|
260
|
-
* - Compress the request body (Node transport only).
|
|
261
|
-
*/
|
|
262
|
-
bodyCompression?: CompressionEncoding;
|
|
263
|
-
/**
|
|
264
|
-
* - Abort signal for the request.
|
|
265
|
-
*/
|
|
266
|
-
signal?: AbortSignal;
|
|
267
|
-
/**
|
|
268
|
-
* - Request timeout in milliseconds. Set to `0` to disable a client default.
|
|
269
|
-
*/
|
|
270
|
-
timeoutMs?: number;
|
|
271
|
-
/**
|
|
272
|
-
* - Fetch credentials mode.
|
|
273
|
-
*/
|
|
274
|
-
credentials?: string;
|
|
275
|
-
/**
|
|
276
|
-
* - Retry transient failures.
|
|
277
|
-
*/
|
|
278
|
-
retry?: boolean | import("./retry.js").RetryOptions;
|
|
279
|
-
/**
|
|
280
|
-
* - Throw `SnapReqHttpError` on non-2xx responses.
|
|
281
|
-
*/
|
|
282
|
-
throwOnError?: boolean;
|
|
283
|
-
};
|
|
284
|
-
export type RequestTimeout = {
|
|
285
|
-
/**
|
|
286
|
-
* - Signal to use for the request.
|
|
287
|
-
*/
|
|
288
|
-
signal: AbortSignal | undefined;
|
|
289
|
-
/**
|
|
290
|
-
* - Clears timeout resources.
|
|
291
|
-
*/
|
|
292
|
-
clear: () => void;
|
|
293
|
-
/**
|
|
294
|
-
* - Attaches timeout handling to a response.
|
|
295
|
-
*/
|
|
296
|
-
response: (response: import("./response.js").default, request: NormalizedRequest) => import("./response.js").default;
|
|
297
|
-
/**
|
|
298
|
-
* - Maps a thrown error.
|
|
299
|
-
*/
|
|
300
|
-
error: (error: unknown, request: NormalizedRequest) => unknown;
|
|
301
|
-
};
|
|
302
|
-
import { SnapReqHttpError } from "./errors.js";
|
|
303
|
-
import SnapReqHeaders from "./headers.js";
|
|
304
267
|
//# sourceMappingURL=snap-req.d.ts.map
|
package/build/snap-req.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snap-req.d.ts","sourceRoot":"","sources":["../src/snap-req.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"snap-req.d.ts","sourceRoot":"","sources":["../src/snap-req.js"],"names":[],"mappings":"AAEA,OAAO,EAAoB,gBAAgB,EAAsD,MAAM,aAAa,CAAA;AACpH,OAAO,cAAc,MAAM,cAAc,CAAA;AAQtC,YAAsD,mBAAmB,GAA/D,OAAO,cAAc,EAAE,mBAAmB,CAAqB;AAIzE,YAAkB,iBAAiB,GACnC;;;;IAAmB,MAAM,EAAd,MAAM,CACjB;;;;IAAmB,GAAG,EAAX,MAAM,CACjB;;;;IAA2B,OAAO,EAAvB,cAAc,CACzB;;;;IAAkD,IAAI,EAA3C,OAAO,cAAc,EAAE,cAAc,CAChD;;;;IAAgC,eAAe,EAApC,mBAAmB,CAC9B;;;;IAAyB,MAAM,AAA/B,CACA,EADW,WAAW,CACtB;;;;IAAoB,SAAS,AAA7B,CACA,EADW,MAAM,CACjB;;;;IAAoB,WAAW,AAA/B,CACF,EADa,MAAM,CACnB;CAAA,CAAA;AAGE,YAAkB,cAAc,GAChC;;;;IAAoB,MAAM,AAA1B,CACA,EADW,MAAM,CACjB;;;;IAAoB,IAAI,AAAxB,CACA,EADW,MAAM,CACjB;;;;IAAoB,GAAG,AAAvB,CACA,EADW,MAAM,CACjB;;;;IAA0E,KAAK,AAA/E,CACA,EADW,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,CACvE;;;;IAA8D,OAAO,AAArE,CACA,EADW,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,cAAc,CAC3D;;;;IAAiB,IAAI,AAArB,CACA,EADW,GAAG,CACd;;;;IAAiC,eAAe,AAAhD,CACA,EADW,mBAAmB,CAC9B;;;;IA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