@atcute/util-fetch 1.0.4 → 2.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/README.md +7 -1
- package/dist/doh-json.d.ts +73 -0
- package/dist/doh-json.d.ts.map +1 -0
- package/dist/doh-json.js +46 -0
- package/dist/doh-json.js.map +1 -0
- package/dist/errors.d.ts +3 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +3 -6
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/streams/size-limit.d.ts.map +1 -1
- package/dist/transformers.d.ts +2 -4
- package/dist/transformers.d.ts.map +1 -1
- package/dist/transformers.js +3 -3
- package/dist/transformers.js.map +1 -1
- package/lib/doh-json.ts +64 -0
- package/lib/errors.ts +14 -14
- package/lib/index.ts +4 -3
- package/lib/streams/size-limit.ts +1 -1
- package/lib/transformers.ts +6 -8
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
/** DoH JSON response schema for TXT record queries */
|
|
3
|
+
export declare const dohJsonTxtResult: v.LooseObjectSchema<{
|
|
4
|
+
/** DNS response code */
|
|
5
|
+
readonly Status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.CheckAction<number, undefined>]>;
|
|
6
|
+
/** whether response is truncated */
|
|
7
|
+
readonly TC: v.BooleanSchema<undefined>;
|
|
8
|
+
/** whether recursive desired bit is set, always true for Google and Cloudflare DoH */
|
|
9
|
+
readonly RD: v.BooleanSchema<undefined>;
|
|
10
|
+
/** whether recursive available bit is set, always true for Google and Cloudflare DoH */
|
|
11
|
+
readonly RA: v.BooleanSchema<undefined>;
|
|
12
|
+
/** whether response data was validated with DNSSEC */
|
|
13
|
+
readonly AD: v.BooleanSchema<undefined>;
|
|
14
|
+
/** whether client asked to disable DNSSEC validation */
|
|
15
|
+
readonly CD: v.BooleanSchema<undefined>;
|
|
16
|
+
/** requested records */
|
|
17
|
+
readonly Question: v.TupleSchema<[v.LooseObjectSchema<{
|
|
18
|
+
readonly name: v.StringSchema<undefined>;
|
|
19
|
+
readonly type: v.LiteralSchema<16, undefined>;
|
|
20
|
+
}, undefined>], undefined>;
|
|
21
|
+
/** answers */
|
|
22
|
+
readonly Answer: v.OptionalSchema<v.ArraySchema<v.LooseObjectSchema<{
|
|
23
|
+
readonly name: v.StringSchema<undefined>;
|
|
24
|
+
readonly type: v.LiteralSchema<16, undefined>;
|
|
25
|
+
readonly TTL: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.CheckAction<number, undefined>]>;
|
|
26
|
+
readonly data: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>]>;
|
|
27
|
+
}, undefined>, undefined>, () => never[]>;
|
|
28
|
+
/** authority */
|
|
29
|
+
readonly Authority: v.OptionalSchema<v.ArraySchema<v.LooseObjectSchema<{
|
|
30
|
+
readonly name: v.StringSchema<undefined>;
|
|
31
|
+
readonly type: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.CheckAction<number, undefined>]>;
|
|
32
|
+
readonly TTL: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.CheckAction<number, undefined>]>;
|
|
33
|
+
readonly data: v.StringSchema<undefined>;
|
|
34
|
+
}, undefined>, undefined>, undefined>;
|
|
35
|
+
/** comment from the DNS server */
|
|
36
|
+
readonly Comment: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>], undefined>, undefined>;
|
|
37
|
+
}, undefined>;
|
|
38
|
+
export type DohJsonTxtResult = v.InferOutput<typeof dohJsonTxtResult>;
|
|
39
|
+
/** fetch handler pipeline for DoH JSON TXT record responses */
|
|
40
|
+
export declare const fetchDohJsonTxt: (input: Response) => Promise<import("./transformers.ts").ParsedJsonResponse<{
|
|
41
|
+
Status: number;
|
|
42
|
+
TC: boolean;
|
|
43
|
+
RD: boolean;
|
|
44
|
+
RA: boolean;
|
|
45
|
+
AD: boolean;
|
|
46
|
+
CD: boolean;
|
|
47
|
+
Question: [{
|
|
48
|
+
name: string;
|
|
49
|
+
type: 16;
|
|
50
|
+
} & {
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
}];
|
|
53
|
+
Answer: ({
|
|
54
|
+
name: string;
|
|
55
|
+
type: 16;
|
|
56
|
+
TTL: number;
|
|
57
|
+
data: string;
|
|
58
|
+
} & {
|
|
59
|
+
[key: string]: unknown;
|
|
60
|
+
})[];
|
|
61
|
+
Authority?: ({
|
|
62
|
+
name: string;
|
|
63
|
+
type: number;
|
|
64
|
+
TTL: number;
|
|
65
|
+
data: string;
|
|
66
|
+
} & {
|
|
67
|
+
[key: string]: unknown;
|
|
68
|
+
})[] | undefined;
|
|
69
|
+
Comment?: string | string[] | undefined;
|
|
70
|
+
} & {
|
|
71
|
+
[key: string]: unknown;
|
|
72
|
+
}>>;
|
|
73
|
+
//# sourceMappingURL=doh-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doh-json.d.ts","sourceRoot":"","sources":["../lib/doh-json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAgC7B,sDAAsD;AACtD,eAAO,MAAM,gBAAgB;IAC5B,wBAAwB;;IAExB,oCAAoC;;IAEpC,sFAAsF;;IAEtF,wFAAwF;;IAExF,sDAAsD;;IAEtD,wDAAwD;;IAExD,wBAAwB;;;;;IAExB,cAAc;;;;;;;IAEd,gBAAgB;;;;;;;IAEhB,kCAAkC;;aAEjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEtE,+DAA+D;AAC/D,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAI3B,CAAC"}
|
package/dist/doh-json.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { pipe } from './pipeline.js';
|
|
3
|
+
import { isResponseOk, parseResponseAsJson, validateJsonWith } from './transformers.js';
|
|
4
|
+
const uint32 = v.pipe(v.number(), v.check((input) => Number.isInteger(input) && input >= 0 && input <= 2 ** 32 - 1));
|
|
5
|
+
const question = v.looseObject({
|
|
6
|
+
name: v.string(),
|
|
7
|
+
type: v.literal(16), // TXT
|
|
8
|
+
});
|
|
9
|
+
const answer = v.looseObject({
|
|
10
|
+
name: v.string(),
|
|
11
|
+
type: v.literal(16), // TXT
|
|
12
|
+
TTL: uint32,
|
|
13
|
+
data: v.pipe(v.string(), v.transform((input) => input.replace(/^"|"$/g, '').replace(/\\"/g, '"'))),
|
|
14
|
+
});
|
|
15
|
+
const authority = v.looseObject({
|
|
16
|
+
name: v.string(),
|
|
17
|
+
type: uint32,
|
|
18
|
+
TTL: uint32,
|
|
19
|
+
data: v.string(),
|
|
20
|
+
});
|
|
21
|
+
/** DoH JSON response schema for TXT record queries */
|
|
22
|
+
export const dohJsonTxtResult = v.looseObject({
|
|
23
|
+
/** DNS response code */
|
|
24
|
+
Status: uint32,
|
|
25
|
+
/** whether response is truncated */
|
|
26
|
+
TC: v.boolean(),
|
|
27
|
+
/** whether recursive desired bit is set, always true for Google and Cloudflare DoH */
|
|
28
|
+
RD: v.boolean(),
|
|
29
|
+
/** whether recursive available bit is set, always true for Google and Cloudflare DoH */
|
|
30
|
+
RA: v.boolean(),
|
|
31
|
+
/** whether response data was validated with DNSSEC */
|
|
32
|
+
AD: v.boolean(),
|
|
33
|
+
/** whether client asked to disable DNSSEC validation */
|
|
34
|
+
CD: v.boolean(),
|
|
35
|
+
/** requested records */
|
|
36
|
+
Question: v.tuple([question]),
|
|
37
|
+
/** answers */
|
|
38
|
+
Answer: v.optional(v.array(answer), () => []),
|
|
39
|
+
/** authority */
|
|
40
|
+
Authority: v.optional(v.array(authority)),
|
|
41
|
+
/** comment from the DNS server */
|
|
42
|
+
Comment: v.optional(v.union([v.string(), v.array(v.string())])),
|
|
43
|
+
});
|
|
44
|
+
/** fetch handler pipeline for DoH JSON TXT record responses */
|
|
45
|
+
export const fetchDohJsonTxt = pipe(isResponseOk, parseResponseAsJson(/^application\/(dns-)?json$/, 16 * 1024), validateJsonWith(dohJsonTxtResult));
|
|
46
|
+
//# sourceMappingURL=doh-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doh-json.js","sourceRoot":"","sources":["../lib/doh-json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAExF,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,CACpB,CAAC,CAAC,MAAM,EAAE,EACV,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CACjF,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAC,CAAC,WAAW,CAAC;IAC9B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,MAAM;CAC3B,CAAC,CAAC;AAEH,MAAM,MAAM,GAAG,CAAC,CAAC,WAAW,CAAC;IAC5B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,MAAM;IAC3B,GAAG,EAAE,MAAM;IACX,IAAI,EAAE,CAAC,CAAC,IAAI,CACX,CAAC,CAAC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AAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;CAC/D,CAAC,CAAC;AAIH,+DAA+D;AAC/D,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAClC,YAAY,EACZ,mBAAmB,CAAC,4BAA4B,EAAE,EAAE,GAAG,IAAI,CAAC,EAC5D,gBAAgB,CAAC,gBAAgB,CAAC,CAClC,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -2,24 +2,23 @@ export declare class FetchResponseError extends Error {
|
|
|
2
2
|
name: string;
|
|
3
3
|
}
|
|
4
4
|
export declare class FailedResponseError extends FetchResponseError {
|
|
5
|
-
response: Response;
|
|
6
5
|
name: string;
|
|
6
|
+
response: Response;
|
|
7
7
|
constructor(response: Response);
|
|
8
8
|
get status(): number;
|
|
9
9
|
}
|
|
10
10
|
export declare class ImproperContentTypeError extends FetchResponseError {
|
|
11
|
-
contentType: string | null;
|
|
12
11
|
name: string;
|
|
12
|
+
contentType: string | null;
|
|
13
13
|
constructor(contentType: string | null, reason: string);
|
|
14
14
|
}
|
|
15
15
|
export declare class ImproperContentLengthError extends FetchResponseError {
|
|
16
|
+
name: string;
|
|
16
17
|
expectedSize: number;
|
|
17
18
|
actualSize: number | null;
|
|
18
|
-
name: string;
|
|
19
19
|
constructor(expectedSize: number, actualSize: number | null, reason: string);
|
|
20
20
|
}
|
|
21
21
|
export declare class ImproperResponseError extends FetchResponseError {
|
|
22
22
|
name: string;
|
|
23
|
-
constructor(reason: string, options?: ErrorOptions);
|
|
24
23
|
}
|
|
25
24
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../lib/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAmB,SAAQ,KAAK;IACnC,IAAI,SAAwB;CACrC;AAED,qBAAa,mBAAoB,SAAQ,kBAAkB;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../lib/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAmB,SAAQ,KAAK;IACnC,IAAI,SAAwB;CACrC;AAED,qBAAa,mBAAoB,SAAQ,kBAAkB;IACjD,IAAI,SAAyB;IAEtC,QAAQ,EAAE,QAAQ,CAAC;IAEnB,YAAY,QAAQ,EAAE,QAAQ,EAG7B;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;CACD;AAED,qBAAa,wBAAyB,SAAQ,kBAAkB;IACtD,IAAI,SAA8B;IAE3C,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAE3B,YAAY,WAAW,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,EAGrD;CACD;AAED,qBAAa,0BAA2B,SAAQ,kBAAkB;IACxD,IAAI,SAAgC;IAE7C,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAE1B,YAAY,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,EAI1E;CACD;AAED,qBAAa,qBAAsB,SAAQ,kBAAkB;IACnD,IAAI,SAA2B;CACxC"}
|
package/dist/errors.js
CHANGED
|
@@ -2,8 +2,8 @@ export class FetchResponseError extends Error {
|
|
|
2
2
|
name = 'FetchResponseError';
|
|
3
3
|
}
|
|
4
4
|
export class FailedResponseError extends FetchResponseError {
|
|
5
|
-
response;
|
|
6
5
|
name = 'FailedResponseError';
|
|
6
|
+
response;
|
|
7
7
|
constructor(response) {
|
|
8
8
|
super(`got http ${response.status}`);
|
|
9
9
|
this.response = response;
|
|
@@ -13,17 +13,17 @@ export class FailedResponseError extends FetchResponseError {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
export class ImproperContentTypeError extends FetchResponseError {
|
|
16
|
-
contentType;
|
|
17
16
|
name = 'ImproperContentTypeError';
|
|
17
|
+
contentType;
|
|
18
18
|
constructor(contentType, reason) {
|
|
19
19
|
super(reason);
|
|
20
20
|
this.contentType = contentType;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
export class ImproperContentLengthError extends FetchResponseError {
|
|
24
|
+
name = 'ImproperContentLengthError';
|
|
24
25
|
expectedSize;
|
|
25
26
|
actualSize;
|
|
26
|
-
name = 'ImproperContentLengthError';
|
|
27
27
|
constructor(expectedSize, actualSize, reason) {
|
|
28
28
|
super(reason);
|
|
29
29
|
this.expectedSize = expectedSize;
|
|
@@ -32,8 +32,5 @@ export class ImproperContentLengthError extends FetchResponseError {
|
|
|
32
32
|
}
|
|
33
33
|
export class ImproperResponseError extends FetchResponseError {
|
|
34
34
|
name = 'ImproperResponseError';
|
|
35
|
-
constructor(reason, options) {
|
|
36
|
-
super(reason, options);
|
|
37
|
-
}
|
|
38
35
|
}
|
|
39
36
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../lib/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IACnC,IAAI,GAAG,oBAAoB,CAAC;CACrC;AAED,MAAM,OAAO,mBAAoB,SAAQ,kBAAkB;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../lib/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IACnC,IAAI,GAAG,oBAAoB,CAAC;CACrC;AAED,MAAM,OAAO,mBAAoB,SAAQ,kBAAkB;IACjD,IAAI,GAAG,qBAAqB,CAAC;IAEtC,QAAQ,CAAW;IAEnB,YAAY,QAAkB;QAC7B,KAAK,CAAC,YAAY,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC7B,CAAC;CACD;AAED,MAAM,OAAO,wBAAyB,SAAQ,kBAAkB;IACtD,IAAI,GAAG,0BAA0B,CAAC;IAE3C,WAAW,CAAgB;IAE3B,YAAY,WAA0B,EAAE,MAAc;QACrD,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IAChC,CAAC;CACD;AAED,MAAM,OAAO,0BAA2B,SAAQ,kBAAkB;IACxD,IAAI,GAAG,4BAA4B,CAAC;IAE7C,YAAY,CAAS;IACrB,UAAU,CAAgB;IAE1B,YAAY,YAAoB,EAAE,UAAyB,EAAE,MAAc;QAC1E,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;CACD;AAED,MAAM,OAAO,qBAAsB,SAAQ,kBAAkB;IACnD,IAAI,GAAG,uBAAuB,CAAC;CACxC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
1
|
+
export * from './doh-json.ts';
|
|
2
|
+
export * from './errors.ts';
|
|
3
|
+
export * from './pipeline.ts';
|
|
4
|
+
export * from './transformers.ts';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"size-limit.d.ts","sourceRoot":"","sources":["../../lib/streams/size-limit.ts"],"names":[],"mappings":"AAEA,qBAAa,eAAgB,SAAQ,eAAe,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"size-limit.d.ts","sourceRoot":"","sources":["../../lib/streams/size-limit.ts"],"names":[],"mappings":"AAEA,qBAAa,eAAgB,SAAQ,eAAe,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IACrG,YAAY,OAAO,EAAE,MAAM,EAkB1B;CACD"}
|
package/dist/transformers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as v from '
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
export type TextResponse = {
|
|
3
3
|
response: Response;
|
|
4
4
|
text: string;
|
|
@@ -10,7 +10,5 @@ export type ParsedJsonResponse<T = unknown> = {
|
|
|
10
10
|
export declare const isResponseOk: (response: Response) => Promise<Response>;
|
|
11
11
|
export declare const readResponseAsText: (maxSize: number) => (response: Response) => Promise<TextResponse>;
|
|
12
12
|
export declare const parseResponseAsJson: (typeRegex: RegExp, maxSize: number) => (response: Response) => Promise<ParsedJsonResponse>;
|
|
13
|
-
|
|
14
|
-
export declare const validateJsonWith: <T>(schema: v.Type<T>, options?: ParseOptions) => (parsed: ParsedJsonResponse) => Promise<ParsedJsonResponse<T>>;
|
|
15
|
-
export {};
|
|
13
|
+
export declare const validateJsonWith: <TOutput>(schema: v.GenericSchema<unknown, TOutput>) => (parsed: ParsedJsonResponse) => Promise<ParsedJsonResponse<TOutput>>;
|
|
16
14
|
//# sourceMappingURL=transformers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../lib/transformers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../lib/transformers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAK7B,MAAM,MAAM,YAAY,GAAG;IAC1B,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,OAAO,IAAI;IAC7C,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,CAAC,CAAC;CACR,CAAC;AAEF,eAAO,MAAM,YAAY,aAAoB,QAAQ,KAAG,OAAO,CAAC,QAAQ,CAMvE,CAAC;AAEF,eAAO,MAAM,kBAAkB,YACpB,MAAM,gBACC,QAAQ,KAAG,OAAO,CAAC,YAAY,CAG/C,CAAC;AAEH,eAAO,MAAM,mBAAmB,cACnB,MAAM,WAAW,MAAM,gBAClB,QAAQ,KAAG,OAAO,CAAC,kBAAkB,CAWrD,CAAC;AAEH,eAAO,MAAM,gBAAgB,GAC3B,OAAO,UAAU,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,cACpC,kBAAkB,KAAG,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAGtE,CAAC"}
|
package/dist/transformers.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as v from '
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
import * as err from './errors.js';
|
|
3
3
|
import { SizeLimitStream } from './streams/size-limit.js';
|
|
4
4
|
export const isResponseOk = async (response) => {
|
|
@@ -22,8 +22,8 @@ export const parseResponseAsJson = (typeRegex, maxSize) => async (response) => {
|
|
|
22
22
|
throw new err.ImproperResponseError(`unexpected json data`, { cause: error });
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
-
export const validateJsonWith = (schema
|
|
26
|
-
const json =
|
|
25
|
+
export const validateJsonWith = (schema) => async (parsed) => {
|
|
26
|
+
const json = v.parse(schema, parsed.json);
|
|
27
27
|
return { response: parsed.response, json };
|
|
28
28
|
};
|
|
29
29
|
const assertContentType = async (response, typeRegex) => {
|
package/dist/transformers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.js","sourceRoot":"","sources":["../lib/transformers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"transformers.js","sourceRoot":"","sources":["../lib/transformers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAY1D,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,QAAkB,EAAqB,EAAE;IAC3E,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED,MAAM,IAAI,GAAG,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AAC7C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAC9B,CAAC,OAAe,EAAE,EAAE,CACpB,KAAK,EAAE,QAAkB,EAAyB,EAAE;IACnD,MAAM,IAAI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K,CAAC,WAAW,CAAC,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;SAC/C,WAAW,CAAC,IAAI,iBAAiB,EAAE,CAAC,CAAC;IAEvC,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,oBAAoB,CAAC,MAAM,CAAC,EAAE,CAAC;QACxD,IAAI,IAAI,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,oBAAoB,GACzB,MAAM,CAAC,aAAa,IAAI,cAAc,CAAC,SAAS;IAC/C,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE;IAC5C,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE;QACX,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QAElC,OAAO;YACN,CAAC,MAAM,CAAC,aAAa,CAAC;gBACrB,OAAO,IAAI,CAAC;YACb,CAAC;YACD,IAAI;gBACH,OAAO,MAAM,CAAC,IAAI,EAAkC,CAAC;YACtD,CAAC;YACD,KAAK,CAAC,MAAM;gBACX,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;gBACtB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;YACzC,CAAC;YACD,KAAK,CAAC,KAAK,CAAC,KAAc;gBACzB,MAAM,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC3B,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;YACzC,CAAC;SACD,CAAC;IACH,CAAC,CAAC"}
|
package/lib/doh-json.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
|
|
3
|
+
import { pipe } from './pipeline.ts';
|
|
4
|
+
import { isResponseOk, parseResponseAsJson, validateJsonWith } from './transformers.ts';
|
|
5
|
+
|
|
6
|
+
const uint32 = v.pipe(
|
|
7
|
+
v.number(),
|
|
8
|
+
v.check((input) => Number.isInteger(input) && input >= 0 && input <= 2 ** 32 - 1),
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const question = v.looseObject({
|
|
12
|
+
name: v.string(),
|
|
13
|
+
type: v.literal(16), // TXT
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const answer = v.looseObject({
|
|
17
|
+
name: v.string(),
|
|
18
|
+
type: v.literal(16), // TXT
|
|
19
|
+
TTL: uint32,
|
|
20
|
+
data: v.pipe(
|
|
21
|
+
v.string(),
|
|
22
|
+
v.transform((input) => input.replace(/^"|"$/g, '').replace(/\\"/g, '"')),
|
|
23
|
+
),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const authority = v.looseObject({
|
|
27
|
+
name: v.string(),
|
|
28
|
+
type: uint32,
|
|
29
|
+
TTL: uint32,
|
|
30
|
+
data: v.string(),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/** DoH JSON response schema for TXT record queries */
|
|
34
|
+
export const dohJsonTxtResult = v.looseObject({
|
|
35
|
+
/** DNS response code */
|
|
36
|
+
Status: uint32,
|
|
37
|
+
/** whether response is truncated */
|
|
38
|
+
TC: v.boolean(),
|
|
39
|
+
/** whether recursive desired bit is set, always true for Google and Cloudflare DoH */
|
|
40
|
+
RD: v.boolean(),
|
|
41
|
+
/** whether recursive available bit is set, always true for Google and Cloudflare DoH */
|
|
42
|
+
RA: v.boolean(),
|
|
43
|
+
/** whether response data was validated with DNSSEC */
|
|
44
|
+
AD: v.boolean(),
|
|
45
|
+
/** whether client asked to disable DNSSEC validation */
|
|
46
|
+
CD: v.boolean(),
|
|
47
|
+
/** requested records */
|
|
48
|
+
Question: v.tuple([question]),
|
|
49
|
+
/** answers */
|
|
50
|
+
Answer: v.optional(v.array(answer), () => []),
|
|
51
|
+
/** authority */
|
|
52
|
+
Authority: v.optional(v.array(authority)),
|
|
53
|
+
/** comment from the DNS server */
|
|
54
|
+
Comment: v.optional(v.union([v.string(), v.array(v.string())])),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export type DohJsonTxtResult = v.InferOutput<typeof dohJsonTxtResult>;
|
|
58
|
+
|
|
59
|
+
/** fetch handler pipeline for DoH JSON TXT record responses */
|
|
60
|
+
export const fetchDohJsonTxt = pipe(
|
|
61
|
+
isResponseOk,
|
|
62
|
+
parseResponseAsJson(/^application\/(dns-)?json$/, 16 * 1024),
|
|
63
|
+
validateJsonWith(dohJsonTxtResult),
|
|
64
|
+
);
|
package/lib/errors.ts
CHANGED
|
@@ -5,8 +5,11 @@ export class FetchResponseError extends Error {
|
|
|
5
5
|
export class FailedResponseError extends FetchResponseError {
|
|
6
6
|
override name = 'FailedResponseError';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
response: Response;
|
|
9
|
+
|
|
10
|
+
constructor(response: Response) {
|
|
9
11
|
super(`got http ${response.status}`);
|
|
12
|
+
this.response = response;
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
get status(): number {
|
|
@@ -17,30 +20,27 @@ export class FailedResponseError extends FetchResponseError {
|
|
|
17
20
|
export class ImproperContentTypeError extends FetchResponseError {
|
|
18
21
|
override name = 'ImproperContentTypeError';
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
) {
|
|
23
|
+
contentType: string | null;
|
|
24
|
+
|
|
25
|
+
constructor(contentType: string | null, reason: string) {
|
|
24
26
|
super(reason);
|
|
27
|
+
this.contentType = contentType;
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
export class ImproperContentLengthError extends FetchResponseError {
|
|
29
32
|
override name = 'ImproperContentLengthError';
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
) {
|
|
34
|
+
expectedSize: number;
|
|
35
|
+
actualSize: number | null;
|
|
36
|
+
|
|
37
|
+
constructor(expectedSize: number, actualSize: number | null, reason: string) {
|
|
36
38
|
super(reason);
|
|
39
|
+
this.expectedSize = expectedSize;
|
|
40
|
+
this.actualSize = actualSize;
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
export class ImproperResponseError extends FetchResponseError {
|
|
41
45
|
override name = 'ImproperResponseError';
|
|
42
|
-
|
|
43
|
-
constructor(reason: string, options?: ErrorOptions) {
|
|
44
|
-
super(reason, options);
|
|
45
|
-
}
|
|
46
46
|
}
|
package/lib/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
1
|
+
export * from './doh-json.ts';
|
|
2
|
+
export * from './errors.ts';
|
|
3
|
+
export * from './pipeline.ts';
|
|
4
|
+
export * from './transformers.ts';
|
package/lib/transformers.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as v from '
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
|
|
3
|
-
import * as err from './errors.
|
|
4
|
-
import { SizeLimitStream } from './streams/size-limit.
|
|
3
|
+
import * as err from './errors.ts';
|
|
4
|
+
import { SizeLimitStream } from './streams/size-limit.ts';
|
|
5
5
|
|
|
6
6
|
export type TextResponse = {
|
|
7
7
|
response: Response;
|
|
@@ -43,12 +43,10 @@ export const parseResponseAsJson =
|
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
type ParseOptions = NonNullable<Parameters<v.Type['parse']>[1]>;
|
|
47
|
-
|
|
48
46
|
export const validateJsonWith =
|
|
49
|
-
<
|
|
50
|
-
async (parsed: ParsedJsonResponse): Promise<ParsedJsonResponse<
|
|
51
|
-
const json =
|
|
47
|
+
<TOutput>(schema: v.GenericSchema<unknown, TOutput>) =>
|
|
48
|
+
async (parsed: ParsedJsonResponse): Promise<ParsedJsonResponse<TOutput>> => {
|
|
49
|
+
const json = v.parse(schema, parsed.json);
|
|
52
50
|
return { response: parsed.response, json };
|
|
53
51
|
};
|
|
54
52
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"type": "module",
|
|
3
2
|
"name": "@atcute/util-fetch",
|
|
4
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
5
4
|
"description": "internal fetch utilities",
|
|
6
5
|
"keywords": [
|
|
7
6
|
"atproto",
|
|
@@ -16,17 +15,22 @@
|
|
|
16
15
|
"dist/",
|
|
17
16
|
"lib/",
|
|
18
17
|
"!lib/**/*.bench.ts",
|
|
19
|
-
"!lib/**/*.test.ts"
|
|
18
|
+
"!lib/**/*.test.ts",
|
|
19
|
+
"!dist/**/*.{test,bench}.*"
|
|
20
20
|
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"sideEffects": false,
|
|
21
23
|
"exports": {
|
|
22
24
|
".": "./dist/index.js"
|
|
23
25
|
},
|
|
24
|
-
"
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
25
29
|
"dependencies": {
|
|
26
|
-
"
|
|
30
|
+
"valibot": "^1.4.0"
|
|
27
31
|
},
|
|
28
32
|
"scripts": {
|
|
29
|
-
"build": "
|
|
33
|
+
"build": "tsgo",
|
|
30
34
|
"prepublish": "rm -rf dist; pnpm run build"
|
|
31
35
|
}
|
|
32
36
|
}
|