input-from-fetch 0.2.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/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ # MIT License
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ <h1 align="center">input-from-fetch</h1>
2
+
3
+ <p align="center">Bingo input that calls to <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API"><code>fetch</code></a>.</p>
4
+
5
+ <p align="center">
6
+ <a href="https://github.com/JoshuaKGoldberg/bingo/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="🤝 Code of Conduct: Kept" src="https://img.shields.io/badge/%F0%9F%A4%9D_code_of_conduct-kept-21bb42" /></a>
7
+ <a href="https://github.com/JoshuaKGoldberg/bingo/blob/main/LICENSE.md" target="_blank"><img alt="📝 License: MIT" src="https://img.shields.io/badge/%F0%9F%93%9D_license-MIT-21bb42.svg"></a>
8
+ <a href="http://npmjs.com/package/input-from-fetch"><img alt="📦 npm version" src="https://img.shields.io/npm/v/input-from-fetch?color=21bb42&label=%F0%9F%93%A6%20npm" /></a>
9
+ <img alt="💪 TypeScript: Strict" src="https://img.shields.io/badge/%F0%9F%92%AA_typescript-strict-21bb42.svg" />
10
+ </p>
11
+
12
+ ```shell
13
+ npm i input-from-fetch
14
+ ```
15
+
16
+ ```ts
17
+ import { inputFromScript } from "input-from-fetch";
18
+
19
+ await take(inputFromScript, { command: "npm whoami" });
20
+ ```
21
+
22
+ ## Options
23
+
24
+ `inputFromFetch` defines two parameters:
25
+
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
+ - `options` _(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
+
29
+ It sends a request to the `resource` with [Input Context `fetch`](https://create.bingo/build/details/contexts#input-fetchers) and returns either:
30
+
31
+ - `undefined`: If the [`offline`](https://create.bingo/cli#--offline) flag is enabled
32
+ - [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error): If an error was caught running the fetch
33
+ - [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response): The awaited response from `fetch()`
34
+
35
+ See **[create.bingo > Templates > Concepts > Inputs](https://create.bingo/build/concepts/inputs)** for more documentation on Inputs.
package/lib/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { z } from "zod";
2
+ export declare const inputFromFetch: import("bingo").InputWithArgs<Promise<Error | Response | undefined>, {
3
+ options: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
4
+ resource: z.ZodString;
5
+ }>;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,cAAc;;;EAoBzB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,24 @@
1
+ import { createInput } from "bingo";
2
+ import { z } from "zod";
3
+ export const inputFromFetch = createInput({
4
+ args: {
5
+ options: z
6
+ .object({
7
+ // TODO: fill out!
8
+ })
9
+ .optional(),
10
+ resource: z.string(),
11
+ },
12
+ async produce({ args, fetchers, offline }) {
13
+ if (offline) {
14
+ return undefined;
15
+ }
16
+ try {
17
+ return await fetchers.fetch(args.resource, args.options);
18
+ }
19
+ catch (error) {
20
+ return error;
21
+ }
22
+ },
23
+ });
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,OAAO,EAAE,CAAC;aACR,MAAM,CAAC;QACP,kBAAkB;SAClB,CAAC;aACD,QAAQ,EAAE;QACZ,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,OAAO,CAAC,CAAC;QAC1D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,KAAc,CAAC;QACvB,CAAC;IACF,CAAC;CACD,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ import { createMockFetchers, testInput } from "bingo-testers";
2
+ import { describe, expect, it, vi } from "vitest";
3
+ import { inputFromFetch } from "./index.js";
4
+ describe("inputFromFetch", () => {
5
+ it("returns the result from running the network request", async () => {
6
+ const resource = "https://example.com";
7
+ const expected = { stdout: "123" };
8
+ const fetch = vi.fn().mockResolvedValue(expected);
9
+ const actual = await testInput(inputFromFetch, {
10
+ args: { resource },
11
+ fetchers: createMockFetchers(fetch),
12
+ });
13
+ expect(actual).toBe(expected);
14
+ expect(fetch).toHaveBeenCalledWith(resource, undefined);
15
+ });
16
+ });
17
+ //# sourceMappingURL=index.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC9D,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,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9B,MAAM,CAAC,KAAK,CAAC,CAAC,oBAAoB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "input-from-fetch",
3
+ "version": "0.2.0",
4
+ "description": "create input that runs a network request.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/JoshuaKGoldberg/bingo",
8
+ "directory": "packages/input-from-fetch"
9
+ },
10
+ "license": "MIT",
11
+ "author": {
12
+ "name": "Josh Goldberg ✨",
13
+ "email": "npm@joshuakgoldberg.com"
14
+ },
15
+ "type": "module",
16
+ "main": "./lib/index.js",
17
+ "files": [
18
+ "lib/",
19
+ "package.json",
20
+ "LICENSE.md",
21
+ "README.md"
22
+ ],
23
+ "dependencies": {
24
+ "zod": "^3.24.2"
25
+ },
26
+ "devDependencies": {
27
+ "bingo-testers": "^0.3.0"
28
+ },
29
+ "peerDependencies": {
30
+ "bingo": "^0.3.0"
31
+ },
32
+ "engines": {
33
+ "node": ">=18"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc"
37
+ }
38
+ }