input-from-fetch 0.5.5 → 0.6.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/README.md +1 -1
- package/lib/fetchInit.d.ts +62 -0
- package/lib/fetchInit.d.ts.map +1 -0
- package/lib/fetchInit.js +146 -0
- package/lib/fetchInit.js.map +1 -0
- package/lib/index.d.ts +57 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -7
- package/lib/index.js.map +1 -1
- package/lib/index.test.js +84 -1
- package/lib/index.test.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ await take(inputFromScript, { command: "https://example.com" });
|
|
|
24
24
|
`inputFromFetch` defines two parameters:
|
|
25
25
|
|
|
26
26
|
- `resource` _(required)_: the `string` or [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) to be passed to [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
|
|
27
|
-
- `
|
|
27
|
+
- `init` _(optional)_: the [`RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit) object to be passed to [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
|
|
28
28
|
|
|
29
29
|
It sends a request to the `resource` with [Input Context `fetch`](https://create.bingo/build/details/contexts#input-fetchers) and returns either:
|
|
30
30
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod description of the `RequestInit` options object passed to `fetch`.
|
|
4
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit}
|
|
5
|
+
*/
|
|
6
|
+
export declare const fetchInit: z.ZodObject<{
|
|
7
|
+
attributionReporting: z.ZodOptional<z.ZodObject<{
|
|
8
|
+
eventSourceEligible: z.ZodOptional<z.ZodBoolean>;
|
|
9
|
+
triggerEligible: z.ZodOptional<z.ZodBoolean>;
|
|
10
|
+
}, z.core.$strip>>;
|
|
11
|
+
body: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<Blob, Blob>, z.ZodCustom<FormData, FormData>, z.ZodCustom<URLSearchParams, URLSearchParams>, z.ZodCustom<ArrayBuffer, ArrayBuffer>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<ArrayBufferView<ArrayBuffer>, ArrayBufferView<ArrayBuffer>>]>>>;
|
|
12
|
+
browsingTopics: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
cache: z.ZodOptional<z.ZodEnum<{
|
|
14
|
+
default: "default";
|
|
15
|
+
"no-store": "no-store";
|
|
16
|
+
reload: "reload";
|
|
17
|
+
"no-cache": "no-cache";
|
|
18
|
+
"force-cache": "force-cache";
|
|
19
|
+
"only-if-cached": "only-if-cached";
|
|
20
|
+
}>>;
|
|
21
|
+
credentials: z.ZodOptional<z.ZodEnum<{
|
|
22
|
+
omit: "omit";
|
|
23
|
+
"same-origin": "same-origin";
|
|
24
|
+
include: "include";
|
|
25
|
+
}>>;
|
|
26
|
+
duplex: z.ZodOptional<z.ZodLiteral<"half">>;
|
|
27
|
+
headers: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<Headers, Headers>, z.ZodRecord<z.ZodString, z.ZodString>, z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>>]>>;
|
|
28
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
29
|
+
keepalive: z.ZodOptional<z.ZodBoolean>;
|
|
30
|
+
method: z.ZodOptional<z.ZodString>;
|
|
31
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
32
|
+
"same-origin": "same-origin";
|
|
33
|
+
"no-cors": "no-cors";
|
|
34
|
+
cors: "cors";
|
|
35
|
+
navigate: "navigate";
|
|
36
|
+
}>>;
|
|
37
|
+
priority: z.ZodOptional<z.ZodEnum<{
|
|
38
|
+
high: "high";
|
|
39
|
+
low: "low";
|
|
40
|
+
auto: "auto";
|
|
41
|
+
}>>;
|
|
42
|
+
redirect: z.ZodOptional<z.ZodEnum<{
|
|
43
|
+
follow: "follow";
|
|
44
|
+
error: "error";
|
|
45
|
+
manual: "manual";
|
|
46
|
+
}>>;
|
|
47
|
+
referrer: z.ZodOptional<z.ZodString>;
|
|
48
|
+
referrerPolicy: z.ZodOptional<z.ZodEnum<{
|
|
49
|
+
"": "";
|
|
50
|
+
"same-origin": "same-origin";
|
|
51
|
+
"no-referrer": "no-referrer";
|
|
52
|
+
"no-referrer-when-downgrade": "no-referrer-when-downgrade";
|
|
53
|
+
origin: "origin";
|
|
54
|
+
"strict-origin": "strict-origin";
|
|
55
|
+
"origin-when-cross-origin": "origin-when-cross-origin";
|
|
56
|
+
"strict-origin-when-cross-origin": "strict-origin-when-cross-origin";
|
|
57
|
+
"unsafe-url": "unsafe-url";
|
|
58
|
+
}>>;
|
|
59
|
+
signal: z.ZodOptional<z.ZodNullable<z.ZodCustom<AbortSignal, AbortSignal>>>;
|
|
60
|
+
window: z.ZodOptional<z.ZodNull>;
|
|
61
|
+
}, z.core.$strip>;
|
|
62
|
+
//# sourceMappingURL=fetchInit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchInit.d.ts","sourceRoot":"","sources":["../src/fetchInit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8JpB,CAAC"}
|
package/lib/fetchInit.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod description of the `RequestInit` options object passed to `fetch`.
|
|
4
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit}
|
|
5
|
+
*/
|
|
6
|
+
export const fetchInit = z.object({
|
|
7
|
+
/**
|
|
8
|
+
* Indicates that the request's response should be able to register a
|
|
9
|
+
* JavaScript-based attribution source or trigger.
|
|
10
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#attributionreporting}
|
|
11
|
+
*/
|
|
12
|
+
attributionReporting: z
|
|
13
|
+
.object({
|
|
14
|
+
/**
|
|
15
|
+
* Whether the response is eligible to register an attribution source.
|
|
16
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#eventsourceeligible}
|
|
17
|
+
*/
|
|
18
|
+
eventSourceEligible: z.boolean().optional(),
|
|
19
|
+
/**
|
|
20
|
+
* Whether the response is eligible to register an attribution trigger.
|
|
21
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#triggereligible}
|
|
22
|
+
*/
|
|
23
|
+
triggerEligible: z.boolean().optional(),
|
|
24
|
+
})
|
|
25
|
+
.optional(),
|
|
26
|
+
/**
|
|
27
|
+
* Body to send with the request.
|
|
28
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#body}
|
|
29
|
+
*/
|
|
30
|
+
body: z
|
|
31
|
+
.union([
|
|
32
|
+
z.string(),
|
|
33
|
+
z.instanceof(Blob),
|
|
34
|
+
z.instanceof(FormData),
|
|
35
|
+
z.instanceof(URLSearchParams),
|
|
36
|
+
z.instanceof(ArrayBuffer),
|
|
37
|
+
z.instanceof(ReadableStream),
|
|
38
|
+
z.custom((value) => ArrayBuffer.isView(value)),
|
|
39
|
+
])
|
|
40
|
+
.nullish(),
|
|
41
|
+
/**
|
|
42
|
+
* Whether the selected topics for the request's URL should be sent in a
|
|
43
|
+
* `Sec-Browsing-Topics` header.
|
|
44
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#browsingtopics}
|
|
45
|
+
*/
|
|
46
|
+
browsingTopics: z.boolean().optional(),
|
|
47
|
+
/**
|
|
48
|
+
* How the request will interact with the browser's HTTP cache.
|
|
49
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#cache}
|
|
50
|
+
*/
|
|
51
|
+
cache: z
|
|
52
|
+
.enum([
|
|
53
|
+
"default",
|
|
54
|
+
"no-store",
|
|
55
|
+
"reload",
|
|
56
|
+
"no-cache",
|
|
57
|
+
"force-cache",
|
|
58
|
+
"only-if-cached",
|
|
59
|
+
])
|
|
60
|
+
.optional(),
|
|
61
|
+
/**
|
|
62
|
+
* Whether the user agent should send or receive cookies for the request.
|
|
63
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#credentials}
|
|
64
|
+
*/
|
|
65
|
+
credentials: z.enum(["omit", "same-origin", "include"]).optional(),
|
|
66
|
+
/**
|
|
67
|
+
* Duplex mode of the request. Must be present when `body` is a
|
|
68
|
+
* `ReadableStream`.
|
|
69
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#duplex}
|
|
70
|
+
*/
|
|
71
|
+
duplex: z.literal("half").optional(),
|
|
72
|
+
/**
|
|
73
|
+
* Headers to add to the request.
|
|
74
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#headers}
|
|
75
|
+
*/
|
|
76
|
+
headers: z
|
|
77
|
+
.union([
|
|
78
|
+
z.instanceof(Headers),
|
|
79
|
+
z.record(z.string(), z.string()),
|
|
80
|
+
z.array(z.tuple([z.string(), z.string()])),
|
|
81
|
+
])
|
|
82
|
+
.optional(),
|
|
83
|
+
/**
|
|
84
|
+
* Cryptographic hash used to verify the integrity of the fetched resource.
|
|
85
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#integrity}
|
|
86
|
+
*/
|
|
87
|
+
integrity: z.string().optional(),
|
|
88
|
+
/**
|
|
89
|
+
* Whether to allow the request to outlive the page.
|
|
90
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#keepalive}
|
|
91
|
+
*/
|
|
92
|
+
keepalive: z.boolean().optional(),
|
|
93
|
+
/**
|
|
94
|
+
* Request method.
|
|
95
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#method}
|
|
96
|
+
*/
|
|
97
|
+
method: z.string().optional(),
|
|
98
|
+
/**
|
|
99
|
+
* Mode to use for the request.
|
|
100
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#mode}
|
|
101
|
+
*/
|
|
102
|
+
mode: z.enum(["same-origin", "no-cors", "cors", "navigate"]).optional(),
|
|
103
|
+
/**
|
|
104
|
+
* Priority of the request relative to other requests of the same type.
|
|
105
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#priority}
|
|
106
|
+
*/
|
|
107
|
+
priority: z.enum(["high", "low", "auto"]).optional(),
|
|
108
|
+
/**
|
|
109
|
+
* How to handle a redirect response.
|
|
110
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#redirect}
|
|
111
|
+
*/
|
|
112
|
+
redirect: z.enum(["follow", "error", "manual"]).optional(),
|
|
113
|
+
/**
|
|
114
|
+
* Referrer of the request.
|
|
115
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#referrer}
|
|
116
|
+
*/
|
|
117
|
+
referrer: z.string().optional(),
|
|
118
|
+
/**
|
|
119
|
+
* Referrer policy to use for the request.
|
|
120
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#referrerpolicy}
|
|
121
|
+
*/
|
|
122
|
+
referrerPolicy: z
|
|
123
|
+
.enum([
|
|
124
|
+
"",
|
|
125
|
+
"no-referrer",
|
|
126
|
+
"no-referrer-when-downgrade",
|
|
127
|
+
"same-origin",
|
|
128
|
+
"origin",
|
|
129
|
+
"strict-origin",
|
|
130
|
+
"origin-when-cross-origin",
|
|
131
|
+
"strict-origin-when-cross-origin",
|
|
132
|
+
"unsafe-url",
|
|
133
|
+
])
|
|
134
|
+
.optional(),
|
|
135
|
+
/**
|
|
136
|
+
* Signal that can be used to abort the request.
|
|
137
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#signal}
|
|
138
|
+
*/
|
|
139
|
+
signal: z.instanceof(AbortSignal).nullish(),
|
|
140
|
+
/**
|
|
141
|
+
* Can only be `null`, used to disassociate the request from any window.
|
|
142
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#window}
|
|
143
|
+
*/
|
|
144
|
+
window: z.null().optional(),
|
|
145
|
+
});
|
|
146
|
+
//# sourceMappingURL=fetchInit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchInit.js","sourceRoot":"","sources":["../src/fetchInit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC;;;;OAIG;IACH,oBAAoB,EAAE,CAAC;SACrB,MAAM,CAAC;QACP;;;WAGG;QACH,mBAAmB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;QAE3C;;;WAGG;QACH,eAAe,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;KACvC,CAAC;SACD,QAAQ,EAAE;IAEZ;;;OAGG;IACH,IAAI,EAAE,CAAC;SACL,KAAK,CAAC;QACN,CAAC,CAAC,MAAM,EAAE;QACV,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;QAClB,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC;QACtB,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC;QAC7B,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC;QACzB,CAAC,CAAC,UAAU,CAAC,cAAc,CAAC;QAC5B,CAAC,CAAC,MAAM,CAAqC,CAAC,KAAK,EAAE,EAAE,CACtD,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CACzB;KACD,CAAC;SACD,OAAO,EAAE;IAEX;;;;OAIG;IACH,cAAc,EAAE,CAAC,CAAC,OAAO,EAAE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;;OAGG;IACH,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE;IAE1D;;;OAGG;IACH,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAE/B;;;OAGG;IACH,cAAc,EAAE,CAAC;SACf,IAAI,CAAC;QACL,EAAE;QACF,aAAa;QACb,4BAA4B;QAC5B,aAAa;QACb,QAAQ;QACR,eAAe;QACf,0BAA0B;QAC1B,iCAAiC;QACjC,YAAY;KACZ,CAAC;SACD,QAAQ,EAAE;IAEZ;;;OAGG;IACH,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE;IAE3C;;;OAGG;IACH,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;CAC3B,CAAC,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
export declare const inputFromFetch: import("bingo").InputWithArgs<Promise<
|
|
3
|
-
|
|
2
|
+
export declare const inputFromFetch: import("bingo").InputWithArgs<Promise<Error | Response | undefined>, {
|
|
3
|
+
init: z.ZodOptional<z.ZodObject<{
|
|
4
|
+
attributionReporting: z.ZodOptional<z.ZodObject<{
|
|
5
|
+
eventSourceEligible: z.ZodOptional<z.ZodBoolean>;
|
|
6
|
+
triggerEligible: z.ZodOptional<z.ZodBoolean>;
|
|
7
|
+
}, z.core.$strip>>;
|
|
8
|
+
body: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<Blob, Blob>, z.ZodCustom<FormData, FormData>, z.ZodCustom<URLSearchParams, URLSearchParams>, z.ZodCustom<ArrayBuffer, ArrayBuffer>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<ArrayBufferView<ArrayBuffer>, ArrayBufferView<ArrayBuffer>>]>>>;
|
|
9
|
+
browsingTopics: z.ZodOptional<z.ZodBoolean>;
|
|
10
|
+
cache: z.ZodOptional<z.ZodEnum<{
|
|
11
|
+
default: "default";
|
|
12
|
+
"no-store": "no-store";
|
|
13
|
+
reload: "reload";
|
|
14
|
+
"no-cache": "no-cache";
|
|
15
|
+
"force-cache": "force-cache";
|
|
16
|
+
"only-if-cached": "only-if-cached";
|
|
17
|
+
}>>;
|
|
18
|
+
credentials: z.ZodOptional<z.ZodEnum<{
|
|
19
|
+
omit: "omit";
|
|
20
|
+
"same-origin": "same-origin";
|
|
21
|
+
include: "include";
|
|
22
|
+
}>>;
|
|
23
|
+
duplex: z.ZodOptional<z.ZodLiteral<"half">>;
|
|
24
|
+
headers: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<Headers, Headers>, z.ZodRecord<z.ZodString, z.ZodString>, z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>>]>>;
|
|
25
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
26
|
+
keepalive: z.ZodOptional<z.ZodBoolean>;
|
|
27
|
+
method: z.ZodOptional<z.ZodString>;
|
|
28
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
29
|
+
"same-origin": "same-origin";
|
|
30
|
+
"no-cors": "no-cors";
|
|
31
|
+
cors: "cors";
|
|
32
|
+
navigate: "navigate";
|
|
33
|
+
}>>;
|
|
34
|
+
priority: z.ZodOptional<z.ZodEnum<{
|
|
35
|
+
high: "high";
|
|
36
|
+
low: "low";
|
|
37
|
+
auto: "auto";
|
|
38
|
+
}>>;
|
|
39
|
+
redirect: z.ZodOptional<z.ZodEnum<{
|
|
40
|
+
follow: "follow";
|
|
41
|
+
error: "error";
|
|
42
|
+
manual: "manual";
|
|
43
|
+
}>>;
|
|
44
|
+
referrer: z.ZodOptional<z.ZodString>;
|
|
45
|
+
referrerPolicy: z.ZodOptional<z.ZodEnum<{
|
|
46
|
+
"": "";
|
|
47
|
+
"same-origin": "same-origin";
|
|
48
|
+
"no-referrer": "no-referrer";
|
|
49
|
+
"no-referrer-when-downgrade": "no-referrer-when-downgrade";
|
|
50
|
+
origin: "origin";
|
|
51
|
+
"strict-origin": "strict-origin";
|
|
52
|
+
"origin-when-cross-origin": "origin-when-cross-origin";
|
|
53
|
+
"strict-origin-when-cross-origin": "strict-origin-when-cross-origin";
|
|
54
|
+
"unsafe-url": "unsafe-url";
|
|
55
|
+
}>>;
|
|
56
|
+
signal: z.ZodOptional<z.ZodNullable<z.ZodCustom<AbortSignal, AbortSignal>>>;
|
|
57
|
+
window: z.ZodOptional<z.ZodNull>;
|
|
58
|
+
}, z.core.$strip>>;
|
|
4
59
|
resource: z.ZodString;
|
|
5
60
|
}>;
|
|
6
61
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgBzB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { createInput } from "bingo";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { fetchInit } from "./fetchInit.js";
|
|
3
4
|
export const inputFromFetch = createInput({
|
|
4
5
|
args: {
|
|
5
|
-
|
|
6
|
-
.object({
|
|
7
|
-
// TODO: fill out!
|
|
8
|
-
// https://github.com/bingo-js/bingo/issues/282
|
|
9
|
-
})
|
|
10
|
-
.optional(),
|
|
6
|
+
init: fetchInit.optional(),
|
|
11
7
|
resource: z.string(),
|
|
12
8
|
},
|
|
13
9
|
async produce({ args, fetchers, offline }) {
|
|
@@ -15,7 +11,7 @@ export const inputFromFetch = createInput({
|
|
|
15
11
|
return undefined;
|
|
16
12
|
}
|
|
17
13
|
try {
|
|
18
|
-
return await fetchers.fetch(args.resource, args.
|
|
14
|
+
return await fetchers.fetch(args.resource, args.init);
|
|
19
15
|
}
|
|
20
16
|
catch (error) {
|
|
21
17
|
return error;
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;IACzC,IAAI,EAAE;QACL,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;IACzC,IAAI,EAAE;QACL,IAAI,EAAE,SAAS,CAAC,QAAQ,EAAE;QAC1B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;KACpB;IACD,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE;QACxC,IAAI,OAAO,EAAE,CAAC;YACb,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,IAAI,CAAC;YACJ,OAAO,MAAM,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACvD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,KAAc,CAAC;QACvB,CAAC;IACF,CAAC;CACD,CAAC,CAAC"}
|
package/lib/index.test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createMockFetchers, testInput } from "bingo-testers";
|
|
1
|
+
import { createMockFetchers, createMockSystems, testInput, } from "bingo-testers";
|
|
2
2
|
import { describe, expect, it, vi } from "vitest";
|
|
3
3
|
import { inputFromFetch } from "./index.js";
|
|
4
4
|
describe("inputFromFetch", () => {
|
|
@@ -13,5 +13,88 @@ describe("inputFromFetch", () => {
|
|
|
13
13
|
expect(actual).toBe(expected);
|
|
14
14
|
expect(fetch).toHaveBeenCalledWith(resource, undefined);
|
|
15
15
|
});
|
|
16
|
+
it("returns undefined when running offline", async () => {
|
|
17
|
+
const fetch = vi.fn();
|
|
18
|
+
const { system, take } = createMockSystems({
|
|
19
|
+
fetchers: createMockFetchers(fetch),
|
|
20
|
+
});
|
|
21
|
+
const actual = await inputFromFetch({
|
|
22
|
+
...system,
|
|
23
|
+
args: { resource: "https://example.com" },
|
|
24
|
+
offline: true,
|
|
25
|
+
take,
|
|
26
|
+
});
|
|
27
|
+
expect(actual).toBeUndefined();
|
|
28
|
+
expect(fetch).not.toHaveBeenCalled();
|
|
29
|
+
});
|
|
30
|
+
it("returns the error when the network request rejects", async () => {
|
|
31
|
+
const expected = new Error("Oh no!");
|
|
32
|
+
const fetch = vi.fn().mockRejectedValue(expected);
|
|
33
|
+
const actual = await testInput(inputFromFetch, {
|
|
34
|
+
args: { resource: "https://example.com" },
|
|
35
|
+
fetchers: createMockFetchers(fetch),
|
|
36
|
+
});
|
|
37
|
+
expect(actual).toBe(expected);
|
|
38
|
+
});
|
|
39
|
+
it("passes a typed array body through to fetch unchanged", async () => {
|
|
40
|
+
const resource = "https://example.com";
|
|
41
|
+
const init = { body: new Uint8Array([1, 2, 3]) };
|
|
42
|
+
const fetch = vi.fn().mockResolvedValue({});
|
|
43
|
+
await testInput(inputFromFetch, {
|
|
44
|
+
args: { init, resource },
|
|
45
|
+
fetchers: createMockFetchers(fetch),
|
|
46
|
+
});
|
|
47
|
+
expect(fetch).toHaveBeenCalledWith(resource, init);
|
|
48
|
+
});
|
|
49
|
+
it("passes a stream body and duplex through to fetch unchanged", async () => {
|
|
50
|
+
const resource = "https://example.com";
|
|
51
|
+
const init = {
|
|
52
|
+
body: new ReadableStream(),
|
|
53
|
+
duplex: "half",
|
|
54
|
+
method: "POST",
|
|
55
|
+
};
|
|
56
|
+
const fetch = vi.fn().mockResolvedValue({});
|
|
57
|
+
await testInput(inputFromFetch, {
|
|
58
|
+
args: { init, resource },
|
|
59
|
+
fetchers: createMockFetchers(fetch),
|
|
60
|
+
});
|
|
61
|
+
expect(fetch).toHaveBeenCalledWith(resource, init);
|
|
62
|
+
});
|
|
63
|
+
it("passes a null body through to fetch unchanged", async () => {
|
|
64
|
+
const resource = "https://example.com";
|
|
65
|
+
const init = { body: null };
|
|
66
|
+
const fetch = vi.fn().mockResolvedValue({});
|
|
67
|
+
await testInput(inputFromFetch, {
|
|
68
|
+
args: { init, resource },
|
|
69
|
+
fetchers: createMockFetchers(fetch),
|
|
70
|
+
});
|
|
71
|
+
expect(fetch).toHaveBeenCalledWith(resource, init);
|
|
72
|
+
});
|
|
73
|
+
it("passes class-based init values through to fetch unchanged", async () => {
|
|
74
|
+
const resource = "https://example.com";
|
|
75
|
+
const init = {
|
|
76
|
+
body: new URLSearchParams({ key: "value" }),
|
|
77
|
+
headers: new Headers({ "content-type": "text/plain" }),
|
|
78
|
+
signal: AbortSignal.timeout(1000),
|
|
79
|
+
};
|
|
80
|
+
const fetch = vi.fn().mockResolvedValue({});
|
|
81
|
+
await testInput(inputFromFetch, {
|
|
82
|
+
args: { init, resource },
|
|
83
|
+
fetchers: createMockFetchers(fetch),
|
|
84
|
+
});
|
|
85
|
+
expect(fetch).toHaveBeenCalledWith(resource, init);
|
|
86
|
+
});
|
|
87
|
+
it("passes init to fetch when provided", async () => {
|
|
88
|
+
const resource = "https://example.com";
|
|
89
|
+
const init = { method: "POST" };
|
|
90
|
+
const expected = { stdout: "123" };
|
|
91
|
+
const fetch = vi.fn().mockResolvedValue(expected);
|
|
92
|
+
const actual = await testInput(inputFromFetch, {
|
|
93
|
+
args: { init, resource },
|
|
94
|
+
fetchers: createMockFetchers(fetch),
|
|
95
|
+
});
|
|
96
|
+
expect(actual).toBe(expected);
|
|
97
|
+
expect(fetch).toHaveBeenCalledWith(resource, init);
|
|
98
|
+
});
|
|
16
99
|
});
|
|
17
100
|
//# sourceMappingURL=index.test.js.map
|
package/lib/index.test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,iBAAiB,EACjB,SAAS,GACT,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,qDAAqD,EAAE,KAAK,IAAI,EAAE;QACpE,MAAM,QAAQ,GAAG,qBAAqB,CAAC;QACvC,MAAM,QAAQ,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAElD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,cAAc,EAAE;YAC9C,IAAI,EAAE,EAAE,QAAQ,EAAE;YAClB,QAAQ,EAAE,kBAAkB,CAAC,KAAK,CAAC;SACnC,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,CAAC,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,CAAC,QAAQ,CAAC,CAAC;QAElD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,cAAc,EAAE;YAC9C,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACxB,QAAQ,EAAE,kBAAkB,CAAC,KAAK,CAAC;SACnC,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9B,MAAM,CAAC,KAAK,CAAC,CAAC,oBAAoB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "input-from-fetch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Bingo input that runs a network request.",
|
|
5
5
|
"homepage": "https://www.create.bingo",
|
|
6
6
|
"repository": {
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"lib/"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"zod": "^
|
|
22
|
+
"zod": "^4.4.3"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"bingo": "^0.
|
|
26
|
-
"bingo-testers": "^0.5.
|
|
25
|
+
"bingo": "^0.11.0",
|
|
26
|
+
"bingo-testers": "^0.5.10"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"bingo": "^0.
|
|
29
|
+
"bingo": "^0.11.0"
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
32
|
"node": ">=18"
|