@atproto-labs/fetch 0.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 +10 -0
- package/LICENSE.txt +7 -0
- package/dist/fetch-error.d.ts +16 -0
- package/dist/fetch-error.d.ts.map +1 -0
- package/dist/fetch-error.js +73 -0
- package/dist/fetch-error.js.map +1 -0
- package/dist/fetch-request.d.ts +7 -0
- package/dist/fetch-request.d.ts.map +1 -0
- package/dist/fetch-request.js +69 -0
- package/dist/fetch-request.js.map +1 -0
- package/dist/fetch-response.d.ts +24 -0
- package/dist/fetch-response.d.ts.map +1 -0
- package/dist/fetch-response.js +151 -0
- package/dist/fetch-response.js.map +1 -0
- package/dist/fetch-wrap.d.ts +10 -0
- package/dist/fetch-wrap.d.ts.map +1 -0
- package/dist/fetch-wrap.js +73 -0
- package/dist/fetch-wrap.js.map +1 -0
- package/dist/fetch.d.ts +2 -0
- package/dist/fetch.d.ts.map +1 -0
- package/dist/fetch.js +3 -0
- package/dist/fetch.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/transformed-response.d.ts +12 -0
- package/dist/transformed-response.d.ts.map +1 -0
- package/dist/transformed-response.js +47 -0
- package/dist/transformed-response.js.map +1 -0
- package/dist/util.d.ts +24 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +51 -0
- package/dist/util.js.map +1 -0
- package/package.json +36 -0
- package/src/fetch-error.ts +77 -0
- package/src/fetch-request.ts +86 -0
- package/src/fetch-response.ts +212 -0
- package/src/fetch-wrap.ts +101 -0
- package/src/fetch.ts +4 -0
- package/src/index.ts +6 -0
- package/src/transformed-response.ts +33 -0
- package/src/util.ts +59 -0
- package/tsconfig.json +8 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# @atproto-labs/fetch
|
|
2
|
+
|
|
3
|
+
## 0.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`e134c79a0`](https://github.com/bluesky-social/atproto/commit/e134c79a0ffb000b2cb36437815673fa6bda664b) Thanks [@devinivy](https://github.com/devinivy)! - Initial publish of experimental oauth packages to @atproto-labs
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`e134c79a0`](https://github.com/bluesky-social/atproto/commit/e134c79a0ffb000b2cb36437815673fa6bda664b)]:
|
|
10
|
+
- @atproto-labs/transformer@0.0.1
|
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Dual MIT/Apache-2.0 License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-2024 Bluesky PBC, and Contributors
|
|
4
|
+
|
|
5
|
+
Except as otherwise noted in individual files, this software is licensed under the MIT license (<http://opensource.org/licenses/MIT>), or the Apache License, Version 2.0 (<http://www.apache.org/licenses/LICENSE-2.0>).
|
|
6
|
+
|
|
7
|
+
Downstream projects and end users may chose either license individually, or both together, at their discretion. The motivation for this dual-licensing is the additional software patent assurance provided by Apache 2.0.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Transformer } from '@atproto-labs/transformer';
|
|
2
|
+
export type FetchErrorOptions = {
|
|
3
|
+
cause?: unknown;
|
|
4
|
+
request?: Request;
|
|
5
|
+
response?: Response;
|
|
6
|
+
};
|
|
7
|
+
export declare class FetchError extends Error {
|
|
8
|
+
readonly statusCode: number;
|
|
9
|
+
readonly request?: Request;
|
|
10
|
+
readonly response?: Response;
|
|
11
|
+
constructor(statusCode: number, message?: string, { cause, request, response }?: FetchErrorOptions);
|
|
12
|
+
static from(err: unknown): Promise<FetchError>;
|
|
13
|
+
}
|
|
14
|
+
export declare const fetchFailureHandler: Transformer<unknown, never>;
|
|
15
|
+
export declare function extractInfo(err: unknown): [statusCode: number, message: string];
|
|
16
|
+
//# sourceMappingURL=fetch-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-error.d.ts","sourceRoot":"","sources":["../src/fetch-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAEvD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB,CAAA;AAED,qBAAa,UAAW,SAAQ,KAAK;aAKjB,UAAU,EAAE,MAAM;IAJpC,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjC,SAAgB,QAAQ,CAAC,EAAE,QAAQ,CAAA;gBAGjB,UAAU,EAAE,MAAM,EAClC,OAAO,CAAC,EAAE,MAAM,EAChB,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAE,iBAAsB;WAOzC,IAAI,CAAC,GAAG,EAAE,OAAO;CAI/B;AAED,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,OAAO,EAAE,KAAK,CAI3D,CAAA;AAgBD,wBAAgB,WAAW,CACzB,GAAG,EAAE,OAAO,GACX,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CA0BvC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractInfo = exports.fetchFailureHandler = exports.FetchError = void 0;
|
|
4
|
+
class FetchError extends Error {
|
|
5
|
+
constructor(statusCode, message, { cause, request, response } = {}) {
|
|
6
|
+
super(message, { cause });
|
|
7
|
+
Object.defineProperty(this, "statusCode", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: statusCode
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(this, "request", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: void 0
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(this, "response", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: void 0
|
|
24
|
+
});
|
|
25
|
+
this.request = request;
|
|
26
|
+
this.response = response;
|
|
27
|
+
}
|
|
28
|
+
static async from(err) {
|
|
29
|
+
const cause = extractCause(err);
|
|
30
|
+
return new FetchError(...extractInfo(cause), { cause });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.FetchError = FetchError;
|
|
34
|
+
const fetchFailureHandler = async (err) => {
|
|
35
|
+
throw await FetchError.from(err);
|
|
36
|
+
};
|
|
37
|
+
exports.fetchFailureHandler = fetchFailureHandler;
|
|
38
|
+
function extractCause(err) {
|
|
39
|
+
// Unwrap the Network error from undici (i.e. Node's internal fetch() implementation)
|
|
40
|
+
// https://github.com/nodejs/undici/blob/3274c975947ce11a08508743df026f73598bfead/lib/web/fetch/index.js#L223-L228
|
|
41
|
+
if (err instanceof TypeError &&
|
|
42
|
+
err.message === 'fetch failed' &&
|
|
43
|
+
err.cause instanceof Error) {
|
|
44
|
+
return err.cause;
|
|
45
|
+
}
|
|
46
|
+
return err;
|
|
47
|
+
}
|
|
48
|
+
function extractInfo(err) {
|
|
49
|
+
if (typeof err === 'string' && err.length > 0) {
|
|
50
|
+
return [502, err];
|
|
51
|
+
}
|
|
52
|
+
if (!(err instanceof Error)) {
|
|
53
|
+
return [502, 'Unable to fetch'];
|
|
54
|
+
}
|
|
55
|
+
if ('code' in err && typeof err.code === 'string') {
|
|
56
|
+
switch (true) {
|
|
57
|
+
case err.code === 'ENOTFOUND':
|
|
58
|
+
return [404, 'Invalid hostname'];
|
|
59
|
+
case err.code === 'ECONNREFUSED':
|
|
60
|
+
return [502, 'Connection refused'];
|
|
61
|
+
case err.code === 'DEPTH_ZERO_SELF_SIGNED_CERT':
|
|
62
|
+
return [502, 'Self-signed certificate'];
|
|
63
|
+
case err.code.startsWith('ERR_TLS'):
|
|
64
|
+
return [502, 'TLS error'];
|
|
65
|
+
case err.code.startsWith('ECONN'):
|
|
66
|
+
return [502, 'Connection error'];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Let's assume that other errors are "bad gateway" errors
|
|
70
|
+
return [502, err.message];
|
|
71
|
+
}
|
|
72
|
+
exports.extractInfo = extractInfo;
|
|
73
|
+
//# sourceMappingURL=fetch-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-error.js","sourceRoot":"","sources":["../src/fetch-error.ts"],"names":[],"mappings":";;;AAQA,MAAa,UAAW,SAAQ,KAAK;IAInC,YACkB,UAAkB,EAClC,OAAgB,EAChB,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,KAAwB,EAAE;QAEpD,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QAJzB;;;;mBAAgB,UAAU;WAAQ;QAJpB;;;;;WAAiB;QACjB;;;;;WAAmB;QAQjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAY;QAC5B,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,CAAA;QAC/B,OAAO,IAAI,UAAU,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IACzD,CAAC;CACF;AAlBD,gCAkBC;AAEM,MAAM,mBAAmB,GAAgC,KAAK,EACnE,GAAY,EACZ,EAAE;IACF,MAAM,MAAM,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAClC,CAAC,CAAA;AAJY,QAAA,mBAAmB,uBAI/B;AAED,SAAS,YAAY,CAAC,GAAY;IAChC,qFAAqF;IACrF,kHAAkH;IAClH,IAC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,kCA4BC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Transformer } from '@atproto-labs/transformer';
|
|
2
|
+
export type RequestTranformer = Transformer<Request>;
|
|
3
|
+
export declare function protocolCheckRequestTransform(protocols: Iterable<string>): RequestTranformer;
|
|
4
|
+
export declare function requireHostHeaderTranform(): RequestTranformer;
|
|
5
|
+
export declare const DEFAULT_FORBIDDEN_DOMAIN_NAMES: string[];
|
|
6
|
+
export declare function forbiddenDomainNameRequestTransform(denyList?: Iterable<string>): RequestTranformer;
|
|
7
|
+
//# sourceMappingURL=fetch-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-request.d.ts","sourceRoot":"","sources":["../src/fetch-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAKvD,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;AAEpD,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,GAC1B,iBAAiB,CAYnB;AAED,wBAAgB,yBAAyB,IAAI,iBAAiB,CAkB7D;AAED,eAAO,MAAM,8BAA8B,UAS1C,CAAA;AAED,wBAAgB,mCAAmC,CACjD,QAAQ,GAAE,QAAQ,CAAC,MAAM,CAAkC,GAC1D,iBAAiB,CA6BnB"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.forbiddenDomainNameRequestTransform = exports.DEFAULT_FORBIDDEN_DOMAIN_NAMES = exports.requireHostHeaderTranform = exports.protocolCheckRequestTransform = void 0;
|
|
4
|
+
const fetch_error_js_1 = require("./fetch-error.js");
|
|
5
|
+
const util_js_1 = require("./util.js");
|
|
6
|
+
function protocolCheckRequestTransform(protocols) {
|
|
7
|
+
const allowedProtocols = new Set(protocols);
|
|
8
|
+
return async (request) => {
|
|
9
|
+
const { protocol } = new URL(request.url);
|
|
10
|
+
if (!allowedProtocols.has(protocol)) {
|
|
11
|
+
throw new fetch_error_js_1.FetchError(400, `${protocol} is not allowed`, { request });
|
|
12
|
+
}
|
|
13
|
+
return request;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
exports.protocolCheckRequestTransform = protocolCheckRequestTransform;
|
|
17
|
+
function requireHostHeaderTranform() {
|
|
18
|
+
return async (request) => {
|
|
19
|
+
// Note that fetch() will automatically add the Host header from the URL and
|
|
20
|
+
// discard any Host header manually set in the request.
|
|
21
|
+
const { protocol, hostname } = new URL(request.url);
|
|
22
|
+
// "Host" header only makes sense in the context of an HTTP request
|
|
23
|
+
if (protocol !== 'http:' && protocol !== 'https') {
|
|
24
|
+
throw new fetch_error_js_1.FetchError(400, `Forbidden protocol ${protocol}`, { request });
|
|
25
|
+
}
|
|
26
|
+
if (!hostname || (0, util_js_1.isIp)(hostname)) {
|
|
27
|
+
throw new fetch_error_js_1.FetchError(400, 'Invalid hostname', { request });
|
|
28
|
+
}
|
|
29
|
+
return request;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
exports.requireHostHeaderTranform = requireHostHeaderTranform;
|
|
33
|
+
exports.DEFAULT_FORBIDDEN_DOMAIN_NAMES = [
|
|
34
|
+
'example.com',
|
|
35
|
+
'*.example.com',
|
|
36
|
+
'example.org',
|
|
37
|
+
'*.example.org',
|
|
38
|
+
'example.net',
|
|
39
|
+
'*.example.net',
|
|
40
|
+
'googleusercontent.com',
|
|
41
|
+
'*.googleusercontent.com',
|
|
42
|
+
];
|
|
43
|
+
function forbiddenDomainNameRequestTransform(denyList = exports.DEFAULT_FORBIDDEN_DOMAIN_NAMES) {
|
|
44
|
+
const denySet = new Set(denyList);
|
|
45
|
+
// Optimization: if no forbidden domain names are provided, we can skip the
|
|
46
|
+
// check entirely.
|
|
47
|
+
if (denySet.size === 0) {
|
|
48
|
+
return async (request) => request;
|
|
49
|
+
}
|
|
50
|
+
return async (request) => {
|
|
51
|
+
const { hostname } = new URL(request.url);
|
|
52
|
+
// Full domain name check
|
|
53
|
+
if (denySet.has(hostname)) {
|
|
54
|
+
throw new fetch_error_js_1.FetchError(403, 'Forbidden hostname', { request });
|
|
55
|
+
}
|
|
56
|
+
// Sub domain name check
|
|
57
|
+
let curDot = hostname.indexOf('.');
|
|
58
|
+
while (curDot !== -1) {
|
|
59
|
+
const subdomain = hostname.slice(curDot + 1);
|
|
60
|
+
if (denySet.has(`*.${subdomain}`)) {
|
|
61
|
+
throw new fetch_error_js_1.FetchError(403, 'Forbidden hostname', { request });
|
|
62
|
+
}
|
|
63
|
+
curDot = hostname.indexOf('.', curDot + 1);
|
|
64
|
+
}
|
|
65
|
+
return request;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
exports.forbiddenDomainNameRequestTransform = forbiddenDomainNameRequestTransform;
|
|
69
|
+
//# sourceMappingURL=fetch-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-request.js","sourceRoot":"","sources":["../src/fetch-request.ts"],"names":[],"mappings":";;;AAEA,qDAA6C;AAC7C,uCAAgC;AAIhC,SAAgB,6BAA6B,CAC3C,SAA2B;IAE3B,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAS,SAAS,CAAC,CAAA;IAEnD,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAEzC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YACpC,MAAM,IAAI,2BAAU,CAAC,GAAG,EAAE,GAAG,QAAQ,iBAAiB,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;QACtE,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC,CAAA;AACH,CAAC;AAdD,sEAcC;AAED,SAAgB,yBAAyB;IACvC,OAAO,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,GAAG,EAAE,oBAAoB,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;QAC9D,CAAC;QAED,wBAAwB;QACxB,IAAI,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAClC,OAAO,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC;YACrB,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;YAC5C,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC,EAAE,CAAC;gBAClC,MAAM,IAAI,2BAAU,CAAC,GAAG,EAAE,oBAAoB,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;YAC9D,CAAC;YACD,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,CAAA;QAC5C,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC,CAAA;AACH,CAAC;AA/BD,kFA+BC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Transformer } from '@atproto-labs/transformer';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { FetchError, FetchErrorOptions } from './fetch-error.js';
|
|
4
|
+
import { Json } from './util.js';
|
|
5
|
+
export type ResponseTranformer = Transformer<Response>;
|
|
6
|
+
export type ResponseMessageGetter = Transformer<Response, string | undefined>;
|
|
7
|
+
export declare class FetchResponseError extends FetchError {
|
|
8
|
+
constructor(response: Response, statusCode?: number, message?: string, options?: Omit<FetchErrorOptions, 'response'>);
|
|
9
|
+
static from(response: Response, statusCode?: number, customMessage?: string | ResponseMessageGetter, options?: Omit<FetchErrorOptions, 'response'>): Promise<FetchResponseError>;
|
|
10
|
+
}
|
|
11
|
+
export declare function fetchOkProcessor(customMessage?: string | ResponseMessageGetter): ResponseTranformer;
|
|
12
|
+
export declare function fetchMaxSizeProcessor(maxBytes: number): ResponseTranformer;
|
|
13
|
+
export declare function fetchResponseMaxSize(response: Response, maxBytes: number): Promise<Response>;
|
|
14
|
+
export type ContentTypeCheckFn = (contentType: string) => boolean;
|
|
15
|
+
export type ContentTypeCheck = string | RegExp | ContentTypeCheckFn;
|
|
16
|
+
export declare function fetchTypeProcessor(expectedType: ContentTypeCheck, contentTypeRequired?: boolean): ResponseTranformer;
|
|
17
|
+
export type ParsedJsonResponse<T = Json> = {
|
|
18
|
+
response: Response;
|
|
19
|
+
json: T;
|
|
20
|
+
};
|
|
21
|
+
export declare function jsonTranformer<T = Json>(response: Response): Promise<ParsedJsonResponse<T>>;
|
|
22
|
+
export declare function fetchJsonProcessor<T = Json>(contentType?: ContentTypeCheck, contentTypeRequired?: boolean): Transformer<Response, ParsedJsonResponse<T>>;
|
|
23
|
+
export declare function fetchJsonZodProcessor<S extends z.ZodTypeAny>(schema: S, params?: Partial<z.ParseParams>): Transformer<ParsedJsonResponse, z.infer<S>>;
|
|
24
|
+
//# sourceMappingURL=fetch-response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-response.d.ts","sourceRoot":"","sources":["../src/fetch-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAW,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAChE,OAAO,EAAE,IAAI,EAAsB,MAAM,WAAW,CAAA;AAGpD,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAA;AACtD,MAAM,MAAM,qBAAqB,GAAG,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;AAmC7E,qBAAa,kBAAmB,SAAQ,UAAU;gBAE9C,QAAQ,EAAE,QAAQ,EAClB,UAAU,GAAE,MAAwB,EACpC,OAAO,GAAE,MAA4B,EACrC,OAAO,CAAC,EAAE,IAAI,CAAC,iBA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,CAAC,CAAC,CAAC,WAAW,CAAC,GAC9B,WAAW,CAAC,kBAAkB,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAG7C"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchJsonZodProcessor = exports.fetchJsonProcessor = exports.jsonTranformer = exports.fetchTypeProcessor = exports.fetchResponseMaxSize = exports.fetchMaxSizeProcessor = exports.fetchOkProcessor = exports.FetchResponseError = void 0;
|
|
4
|
+
const transformer_1 = require("@atproto-labs/transformer");
|
|
5
|
+
const fetch_error_js_1 = require("./fetch-error.js");
|
|
6
|
+
const util_js_1 = require("./util.js");
|
|
7
|
+
const transformed_response_js_1 = require("./transformed-response.js");
|
|
8
|
+
const extractResponseMessage = async (response) => {
|
|
9
|
+
if (!response.body)
|
|
10
|
+
return undefined;
|
|
11
|
+
const contentType = response.headers.get('content-type');
|
|
12
|
+
if (!contentType)
|
|
13
|
+
return undefined;
|
|
14
|
+
const mimeType = contentType.split(';')[0].trim();
|
|
15
|
+
if (!mimeType)
|
|
16
|
+
return undefined;
|
|
17
|
+
try {
|
|
18
|
+
if (mimeType === 'text/plain') {
|
|
19
|
+
return await response.text();
|
|
20
|
+
}
|
|
21
|
+
else if (/^application\/(?:[^+]+\+)?json$/i.test(mimeType)) {
|
|
22
|
+
const json = await response.json();
|
|
23
|
+
if (typeof json === 'string')
|
|
24
|
+
return json;
|
|
25
|
+
const errorDescription = (0, util_js_1.ifString)((0, util_js_1.ifObject)(json)?.['error_description']);
|
|
26
|
+
if (errorDescription)
|
|
27
|
+
return errorDescription;
|
|
28
|
+
const error = (0, util_js_1.ifString)((0, util_js_1.ifObject)(json)?.['error']);
|
|
29
|
+
if (error)
|
|
30
|
+
return error;
|
|
31
|
+
const message = (0, util_js_1.ifString)((0, util_js_1.ifObject)(json)?.['message']);
|
|
32
|
+
if (message)
|
|
33
|
+
return message;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// noop
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
};
|
|
41
|
+
class FetchResponseError extends fetch_error_js_1.FetchError {
|
|
42
|
+
constructor(response, statusCode = response.status, message = response.statusText, options) {
|
|
43
|
+
super(statusCode, message, { response, ...options });
|
|
44
|
+
}
|
|
45
|
+
static async from(response, statusCode = response.status, customMessage = extractResponseMessage, options) {
|
|
46
|
+
const message = typeof customMessage === 'string'
|
|
47
|
+
? customMessage
|
|
48
|
+
: typeof customMessage === 'function'
|
|
49
|
+
? await customMessage(response)
|
|
50
|
+
: undefined;
|
|
51
|
+
// Make sure the body gets consumed as, in some environments (Node 👀), the
|
|
52
|
+
// response will not automatically be GC'd.
|
|
53
|
+
if (!response.bodyUsed)
|
|
54
|
+
await response.body?.cancel();
|
|
55
|
+
return new FetchResponseError(response, statusCode, message, options);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.FetchResponseError = FetchResponseError;
|
|
59
|
+
function fetchOkProcessor(customMessage) {
|
|
60
|
+
return async (response) => {
|
|
61
|
+
if (response.ok)
|
|
62
|
+
return response;
|
|
63
|
+
throw await FetchResponseError.from(response, undefined, customMessage);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
exports.fetchOkProcessor = fetchOkProcessor;
|
|
67
|
+
function fetchMaxSizeProcessor(maxBytes) {
|
|
68
|
+
if (maxBytes === Infinity)
|
|
69
|
+
return (response) => response;
|
|
70
|
+
if (!Number.isFinite(maxBytes) || maxBytes < 0) {
|
|
71
|
+
throw new TypeError('maxBytes must be a non-negative number');
|
|
72
|
+
}
|
|
73
|
+
return async (response) => fetchResponseMaxSize(response, maxBytes);
|
|
74
|
+
}
|
|
75
|
+
exports.fetchMaxSizeProcessor = fetchMaxSizeProcessor;
|
|
76
|
+
async function fetchResponseMaxSize(response, maxBytes) {
|
|
77
|
+
if (maxBytes === Infinity)
|
|
78
|
+
return response;
|
|
79
|
+
if (!response.body)
|
|
80
|
+
return response;
|
|
81
|
+
const contentLength = response.headers.get('content-length');
|
|
82
|
+
if (contentLength) {
|
|
83
|
+
const length = Number(contentLength);
|
|
84
|
+
if (!(length < maxBytes)) {
|
|
85
|
+
const err = new FetchResponseError(response, 502, 'Response too large');
|
|
86
|
+
await response.body.cancel(err);
|
|
87
|
+
throw err;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
let bytesRead = 0;
|
|
91
|
+
const transform = new TransformStream({
|
|
92
|
+
transform: (chunk, ctrl) => {
|
|
93
|
+
if ((bytesRead += chunk.length) <= maxBytes) {
|
|
94
|
+
ctrl.enqueue(chunk);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
ctrl.error(new FetchResponseError(response, 502, 'Response too large'));
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
return new transformed_response_js_1.TransformedResponse(response, transform);
|
|
102
|
+
}
|
|
103
|
+
exports.fetchResponseMaxSize = fetchResponseMaxSize;
|
|
104
|
+
function fetchTypeProcessor(expectedType, contentTypeRequired = true) {
|
|
105
|
+
const isExpected = typeof expectedType === 'string'
|
|
106
|
+
? (ct) => ct === expectedType
|
|
107
|
+
: expectedType instanceof RegExp
|
|
108
|
+
? (ct) => expectedType.test(ct)
|
|
109
|
+
: expectedType;
|
|
110
|
+
return async (response) => {
|
|
111
|
+
const contentType = response.headers
|
|
112
|
+
.get('content-type')
|
|
113
|
+
?.split(';')[0]
|
|
114
|
+
.trim();
|
|
115
|
+
if (contentType) {
|
|
116
|
+
if (!isExpected(contentType)) {
|
|
117
|
+
throw await FetchResponseError.from(response, 502, `Unexpected response Content-Type (${contentType})`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else if (contentTypeRequired) {
|
|
121
|
+
throw await FetchResponseError.from(response, 502, 'Missing response Content-Type header');
|
|
122
|
+
}
|
|
123
|
+
return response;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
exports.fetchTypeProcessor = fetchTypeProcessor;
|
|
127
|
+
async function jsonTranformer(response) {
|
|
128
|
+
if (response.body === null) {
|
|
129
|
+
throw new FetchResponseError(response, 502, 'No response body');
|
|
130
|
+
}
|
|
131
|
+
if (response.bodyUsed) {
|
|
132
|
+
throw new FetchResponseError(response, 500, 'Response body already used');
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const json = (await response.json());
|
|
136
|
+
return { response, json };
|
|
137
|
+
}
|
|
138
|
+
catch (cause) {
|
|
139
|
+
throw new FetchResponseError(response, 502, 'Unable to parse response as JSON', { cause });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.jsonTranformer = jsonTranformer;
|
|
143
|
+
function fetchJsonProcessor(contentType = /^application\/(?:[^+]+\+)?json$/, contentTypeRequired = true) {
|
|
144
|
+
return (0, transformer_1.compose)(fetchTypeProcessor(contentType, contentTypeRequired), (jsonTranformer));
|
|
145
|
+
}
|
|
146
|
+
exports.fetchJsonProcessor = fetchJsonProcessor;
|
|
147
|
+
function fetchJsonZodProcessor(schema, params) {
|
|
148
|
+
return async (jsonResponse) => schema.parseAsync(jsonResponse.json, params);
|
|
149
|
+
}
|
|
150
|
+
exports.fetchJsonZodProcessor = fetchJsonZodProcessor;
|
|
151
|
+
//# sourceMappingURL=fetch-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-response.js","sourceRoot":"","sources":["../src/fetch-response.ts"],"names":[],"mappings":";;;AAAA,2DAAgE;AAGhE,qDAAgE;AAChE,uCAAoD;AACpD,uEAA+D;AAK/D,MAAM,sBAAsB,GAA0B,KAAK,EAAE,QAAQ,EAAE,EAAE;IACvE,IAAI,CAAC,QAAQ,CAAC,IAAI;QAAE,OAAO,SAAS,CAAA;IAEpC,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;IACxD,IAAI,CA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A;IAC3E,CAAC;IAED,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAM,CAAA;QACzC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,kBAAkB,CAC1B,QAAQ,EACR,GAAG,EACH,kCAAkC,EAClC,EAAE,KAAK,EAAE,CACV,CAAA;IACH,CAAC;AACH,CAAC;AAtBD,wCAsBC;AAED,SAAgB,kBAAkB,CAChC,cAAgC,iCAAiC,EACjE,mBAAmB,GAAG,IAAI;IAE1B,OAAO,IAAA,qBAAO,EACZ,kBAAkB,CAAC,WAAW,EAAE,mBAAmB,CAAC,EACpD,CAAA,cAAiB,CAAA,CAClB,CAAA;AACH,CAAC;AARD,gDAQC;AAED,SAAgB,qBAAqB,CACnC,MAAS,EACT,MAA+B;IAE/B,OAAO,KAAK,EAAE,YAAgC,EAAuB,EAAE,CACrE,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AAChD,CAAC;AAND,sDAMC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Fetch } from './fetch.js';
|
|
2
|
+
export declare const loggedFetchWrap: ({ fetch, }?: {
|
|
3
|
+
fetch?: Fetch | undefined;
|
|
4
|
+
}) => Fetch;
|
|
5
|
+
export declare const timeoutFetchWrap: ({ fetch, timeout, }?: {
|
|
6
|
+
fetch?: Fetch | undefined;
|
|
7
|
+
timeout?: number | undefined;
|
|
8
|
+
}) => Fetch;
|
|
9
|
+
export declare function fetchTimeout(this: ThisParameterType<Fetch>, request: Request, timeout?: number, fetch?: Fetch): Promise<Response>;
|
|
10
|
+
//# sourceMappingURL=fetch-wrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-wrap.d.ts","sourceRoot":"","sources":["../src/fetch-wrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAGlC,eAAO,MAAM,eAAe;;MAEnB,KAIR,CAAA;AAyCD,eAAO,MAAM,gBAAgB;;;MAGpB,KAQR,CAAA;AAED,wBAAsB,YAAY,CAChC,IAAI,EAAE,iBAAiB,CAAC,KAAK,CAAC,EAC9B,OAAO,EAAE,OAAO,EAChB,OAAO,SAAO,EACd,KAAK,GAAE,KAAwB,GAC9B,OAAO,CAAC,QAAQ,CAAC,CAgCnB"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchTimeout = exports.timeoutFetchWrap = exports.loggedFetchWrap = void 0;
|
|
4
|
+
const transformed_response_js_1 = require("./transformed-response.js");
|
|
5
|
+
const loggedFetchWrap = ({ fetch = globalThis.fetch, } = {}) => {
|
|
6
|
+
return async function (request) {
|
|
7
|
+
return fetchLog.call(this, request, fetch);
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
exports.loggedFetchWrap = loggedFetchWrap;
|
|
11
|
+
async function fetchLog(request, fetch = globalThis.fetch) {
|
|
12
|
+
console.info(`> ${request.method} ${request.url}\n` +
|
|
13
|
+
stringifyPayload(request.headers, await request.clone().text()));
|
|
14
|
+
try {
|
|
15
|
+
const response = await fetch(request);
|
|
16
|
+
console.info(`< HTTP/1.1 ${response.status} ${response.statusText}\n` +
|
|
17
|
+
stringifyPayload(response.headers, await response.clone().text()));
|
|
18
|
+
return response;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.error(`< Error:`, error);
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const stringifyPayload = (headers, body) => [stringifyHeaders(headers), stringifyBody(body)]
|
|
26
|
+
.filter(Boolean)
|
|
27
|
+
.join('\n ') + '\n ';
|
|
28
|
+
const stringifyHeaders = (headers) => Array.from(headers)
|
|
29
|
+
.map(([name, value]) => ` ${name}: ${value}\n`)
|
|
30
|
+
.join('');
|
|
31
|
+
const stringifyBody = (body) => body ? `\n ${body.replace(/\r?\n/g, '\\n')}` : '';
|
|
32
|
+
const timeoutFetchWrap = ({ fetch = globalThis.fetch, timeout = 60e3, } = {}) => {
|
|
33
|
+
if (timeout === Infinity)
|
|
34
|
+
return fetch;
|
|
35
|
+
if (!Number.isFinite(timeout) || timeout <= 0) {
|
|
36
|
+
throw new TypeError('Timeout must be positive');
|
|
37
|
+
}
|
|
38
|
+
return async function (request) {
|
|
39
|
+
return fetchTimeout.call(this, request, timeout, fetch);
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
exports.timeoutFetchWrap = timeoutFetchWrap;
|
|
43
|
+
async function fetchTimeout(request, timeout = 30e3, fetch = globalThis.fetch) {
|
|
44
|
+
if (timeout === Infinity)
|
|
45
|
+
return fetch(request);
|
|
46
|
+
if (!Number.isFinite(timeout) || timeout <= 0) {
|
|
47
|
+
throw new TypeError('Timeout must be positive');
|
|
48
|
+
}
|
|
49
|
+
const controller = new AbortController();
|
|
50
|
+
const signal = controller.signal;
|
|
51
|
+
const abort = () => {
|
|
52
|
+
controller.abort();
|
|
53
|
+
};
|
|
54
|
+
const cleanup = () => {
|
|
55
|
+
clearTimeout(timeoutId);
|
|
56
|
+
request.signal?.removeEventListener('abort', abort);
|
|
57
|
+
};
|
|
58
|
+
const timeoutId = setTimeout(abort, timeout).unref();
|
|
59
|
+
request.signal?.addEventListener('abort', abort);
|
|
60
|
+
signal.addEventListener('abort', cleanup);
|
|
61
|
+
const response = await fetch(new Request(request, { signal }));
|
|
62
|
+
if (!response.body) {
|
|
63
|
+
cleanup();
|
|
64
|
+
return response;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// Cleanup the timer & event listeners when the body stream is closed
|
|
68
|
+
const transform = new TransformStream({ flush: cleanup });
|
|
69
|
+
return new transformed_response_js_1.TransformedResponse(response, transform);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.fetchTimeout = fetchTimeout;
|
|
73
|
+
//# sourceMappingURL=fetch-wrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-wrap.js","sourceRoot":"","sources":["../src/fetch-wrap.ts"],"names":[],"mappings":";;;AACA,uEAA+D;AAExD,MAAM,eAAe,GAAG,CAAC,EAC9B,KAAK,GAAG,UAAU,CAAC,KAAc,MAC/B,EAAE,EAAS,EAAE;IACf,OAAO,KAAK,WAAW,OAAO;QAC5B,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAA;IAC5C,CAAC,CAAA;AACH,CAAC,CAAA;AANY,QAAA,eAAe,mBAM3B;AAED,KAAK,UAAU,QAAQ,CAErB,OAAgB,EAChB,QAAe,UAAU,CAAC,KAAK;IAE/B,OAAO,CAAC,IAAI,CACV,KAAK,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,IAAI;QACpC,gBAAgB,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,CAClE,CAAA;IAED,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,CAAA;QAErC,OAAO,CAAC,IAAI,CACV,cAAc,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,IAAI;YACtD,gBAAgB,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,CACpE,CAAA;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;QAEhC,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC;AAED,MAAM,gBAAgB,GAAG,CAAC,O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@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG,CAClB,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,UAAU,EACrC,KAAK,EAAE,OAAO,KACX,OAAO,CAAC,QAAQ,CAAC,CAAA"}
|
package/dist/fetch.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./fetch-error.js"), exports);
|
|
18
|
+
__exportStar(require("./fetch-request.js"), exports);
|
|
19
|
+
__exportStar(require("./fetch-response.js"), exports);
|
|
20
|
+
__exportStar(require("./fetch-wrap.js"), exports);
|
|
21
|
+
__exportStar(require("./fetch.js"), exports);
|
|
22
|
+
__exportStar(require("./util.js"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC;AAChC,qDAAkC;AAClC,sDAAmC;AACnC,kDAA+B;AAC/B,6CAA0B;AAC1B,4CAAyB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class TransformedResponse extends Response {
|
|
2
|
+
#private;
|
|
3
|
+
constructor(response: Response, transform: TransformStream);
|
|
4
|
+
/**
|
|
5
|
+
* Some props can't be set through ResponseInit, so we need to proxy them
|
|
6
|
+
*/
|
|
7
|
+
get url(): string;
|
|
8
|
+
get redirected(): boolean;
|
|
9
|
+
get type(): ResponseType;
|
|
10
|
+
get statusText(): string;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=transformed-response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformed-response.d.ts","sourceRoot":"","sources":["../src/transformed-response.ts"],"names":[],"mappings":"AAAA,qBAAa,mBAAoB,SAAQ,QAAQ;;gBAGnC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe;IAc1D;;OAEG;IACH,IAAI,GAAG,WAEN;IACD,IAAI,UAAU,YAEb;IACD,IAAI,IAAI,iBAEP;IACD,IAAI,UAAU,WAEb;CACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _TransformedResponse_response;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.TransformedResponse = void 0;
|
|
16
|
+
class TransformedResponse extends Response {
|
|
17
|
+
constructor(response, transform) {
|
|
18
|
+
if (response.body && response.bodyUsed) {
|
|
19
|
+
throw new TypeError('Response body is already used');
|
|
20
|
+
}
|
|
21
|
+
super(response.body?.pipeThrough(transform) ?? null, {
|
|
22
|
+
status: response.status,
|
|
23
|
+
statusText: response.statusText,
|
|
24
|
+
headers: response.headers,
|
|
25
|
+
});
|
|
26
|
+
_TransformedResponse_response.set(this, void 0);
|
|
27
|
+
__classPrivateFieldSet(this, _TransformedResponse_response, response, "f");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Some props can't be set through ResponseInit, so we need to proxy them
|
|
31
|
+
*/
|
|
32
|
+
get url() {
|
|
33
|
+
return __classPrivateFieldGet(this, _TransformedResponse_response, "f").url;
|
|
34
|
+
}
|
|
35
|
+
get redirected() {
|
|
36
|
+
return __classPrivateFieldGet(this, _TransformedResponse_response, "f").redirected;
|
|
37
|
+
}
|
|
38
|
+
get type() {
|
|
39
|
+
return __classPrivateFieldGet(this, _TransformedResponse_response, "f").type;
|
|
40
|
+
}
|
|
41
|
+
get statusText() {
|
|
42
|
+
return __classPrivateFieldGet(this, _TransformedResponse_response, "f").statusText;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.TransformedResponse = TransformedResponse;
|
|
46
|
+
_TransformedResponse_response = new WeakMap();
|
|
47
|
+
//# sourceMappingURL=transformed-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformed-response.js","sourceRoot":"","sources":["../src/transformed-response.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,MAAa,mBAAoB,SAAQ,QAAQ;IAG/C,YAAY,QAAkB,EAAE,SAA0B;QACxD,IAAI,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACvC,MAAM,IAAI,SAAS,CAAC,+BAA+B,CAAC,CAAA;QACtD,CAAC;QAED,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE;YACnD,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,OAAO,EAAE,QAAQ,CAAC,OAAO;SAC1B,CAAC,CAAA;QAXJ,gDAAmB;QAajB,uBAAA,IAAI,iCAAa,QAAQ,MAAA,CAAA;IAC3B,CAAC;IAED;;OAEG;IACH,IAAI,GAAG;QACL,OAAO,uBAAA,IAAI,qCAAU,CAAC,GAAG,CAAA;IAC3B,CAAC;IACD,IAAI,UAAU;QACZ,OAAO,uBAAA,IAAI,qCAAU,CAAC,UAAU,CAAA;IAClC,CAAC;IACD,IAAI,IAAI;QACN,OAAO,uBAAA,IAAI,qCAAU,CAAC,IAAI,CAAA;IAC5B,CAAC;IACD,IAAI,UAAU;QACZ,OAAO,uBAAA,IAAI,qCAAU,CAAC,UAAU,CAAA;IAClC,CAAC;CACF;AAhCD,kDAgCC"}
|