@tauri-apps/plugin-http 2.0.0-alpha.3 → 2.0.0-alpha.5

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 CHANGED
@@ -71,6 +71,22 @@ const response = await fetch("http://localhost:3003/users/2", {
71
71
 
72
72
  PRs accepted. Please make sure to read the Contributing Guide before making a pull request.
73
73
 
74
+ ## Partners
75
+
76
+ <table>
77
+ <tbody>
78
+ <tr>
79
+ <td align="center" valign="middle">
80
+ <a href="https://crabnebula.dev" target="_blank">
81
+ <img src="https://github.com/tauri-apps/plugins-workspace/raw/v2/.github/sponsors/crabnebula.svg" alt="CrabNebula" width="283">
82
+ </a>
83
+ </td>
84
+ </tr>
85
+ </tbody>
86
+ </table>
87
+
88
+ For the complete list of sponsors please visit our [website](https://tauri.app#sponsors) and [Open Collective](https://opencollective.com/tauri).
89
+
74
90
  ## License
75
91
 
76
92
  Code: (c) 2015 - Present - The Tauri Programme within The Commons Conservancy.
@@ -0,0 +1,83 @@
1
+ 'use strict';
2
+
3
+ var core = require('@tauri-apps/api/core');
4
+
5
+ // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
6
+ // SPDX-License-Identifier: Apache-2.0
7
+ // SPDX-License-Identifier: MIT
8
+ /**
9
+ * Make HTTP requests with the Rust backend.
10
+ *
11
+ * ## Security
12
+ *
13
+ * This API has a scope configuration that forces you to restrict the URLs and paths that can be accessed using glob patterns.
14
+ *
15
+ * For instance, this scope configuration only allows making HTTP requests to the GitHub API for the `tauri-apps` organization:
16
+ * ```json
17
+ * {
18
+ * "plugins": {
19
+ * "http": {
20
+ * "scope": ["https://api.github.com/repos/tauri-apps/*"]
21
+ * }
22
+ * }
23
+ * }
24
+ * ```
25
+ * Trying to execute any API with a URL not configured on the scope results in a promise rejection due to denied access.
26
+ *
27
+ * @module
28
+ */
29
+ /**
30
+ * Fetch a resource from the network. It returns a `Promise` that resolves to the
31
+ * `Response` to that `Request`, whether it is successful or not.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const response = await fetch("http://my.json.host/data.json");
36
+ * console.log(response.status); // e.g. 200
37
+ * console.log(response.statusText); // e.g. "OK"
38
+ * const jsonData = await response.json();
39
+ * ```
40
+ *
41
+ * @since 2.0.0
42
+ */
43
+ async function fetch(input, init) {
44
+ const maxRedirections = init?.maxRedirections;
45
+ const connectTimeout = init?.maxRedirections;
46
+ // Remove these fields before creating the request
47
+ if (init) {
48
+ delete init.maxRedirections;
49
+ delete init.connectTimeout;
50
+ }
51
+ const req = new Request(input, init);
52
+ const buffer = await req.arrayBuffer();
53
+ const reqData = buffer.byteLength ? Array.from(new Uint8Array(buffer)) : null;
54
+ const rid = await core.invoke("plugin:http|fetch", {
55
+ method: req.method,
56
+ url: req.url,
57
+ headers: Array.from(req.headers.entries()),
58
+ data: reqData,
59
+ maxRedirections,
60
+ connectTimeout,
61
+ });
62
+ req.signal.addEventListener("abort", () => {
63
+ core.invoke("plugin:http|fetch_cancel", {
64
+ rid,
65
+ });
66
+ });
67
+ const { status, statusText, url, headers } = await core.invoke("plugin:http|fetch_send", {
68
+ rid,
69
+ });
70
+ const body = await core.invoke("plugin:http|fetch_read_body", {
71
+ rid,
72
+ });
73
+ const res = new Response(new Uint8Array(body), {
74
+ headers,
75
+ status,
76
+ statusText,
77
+ });
78
+ // url is read only but seems like we can do this
79
+ Object.defineProperty(res, "url", { value: url });
80
+ return res;
81
+ }
82
+
83
+ exports.fetch = fetch;
@@ -1,4 +1,4 @@
1
- import { invoke } from '@tauri-apps/api/primitives';
1
+ import { invoke } from '@tauri-apps/api/core';
2
2
 
3
3
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
4
4
  // SPDX-License-Identifier: Apache-2.0
@@ -39,8 +39,8 @@ import { invoke } from '@tauri-apps/api/primitives';
39
39
  * @since 2.0.0
40
40
  */
41
41
  async function fetch(input, init) {
42
- const maxRedirections = init === null || init === void 0 ? void 0 : init.maxRedirections;
43
- const connectTimeout = init === null || init === void 0 ? void 0 : init.maxRedirections;
42
+ const maxRedirections = init?.maxRedirections;
43
+ const connectTimeout = init?.maxRedirections;
44
44
  // Remove these fields before creating the request
45
45
  if (init) {
46
46
  delete init.maxRedirections;
@@ -79,4 +79,3 @@ async function fetch(input, init) {
79
79
  }
80
80
 
81
81
  export { fetch };
82
- //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,30 +1,26 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-http",
3
- "version": "2.0.0-alpha.3",
3
+ "version": "2.0.0-alpha.5",
4
4
  "license": "MIT or APACHE-2.0",
5
5
  "authors": [
6
6
  "Tauri Programme within The Commons Conservancy"
7
7
  ],
8
8
  "type": "module",
9
- "browser": "dist-js/index.min.js",
10
- "module": "dist-js/index.mjs",
11
- "types": "dist-js/index.d.ts",
9
+ "types": "./dist-js/index.d.ts",
10
+ "main": "./dist-js/index.cjs",
11
+ "module": "./dist-js/index.js",
12
12
  "exports": {
13
- "import": "./dist-js/index.mjs",
14
13
  "types": "./dist-js/index.d.ts",
15
- "browser": "./dist-js/index.min.js"
14
+ "import": "./dist-js/index.js",
15
+ "require": "./dist-js/index.cjs"
16
16
  },
17
17
  "files": [
18
18
  "dist-js",
19
- "!dist-js/**/*.map",
20
19
  "README.md",
21
20
  "LICENSE"
22
21
  ],
23
- "devDependencies": {
24
- "tslib": "^2.5.0"
25
- },
26
22
  "dependencies": {
27
- "@tauri-apps/api": "2.0.0-alpha.11"
23
+ "@tauri-apps/api": "2.0.0-alpha.13"
28
24
  },
29
25
  "scripts": {
30
26
  "build": "rollup -c"
@@ -1,121 +0,0 @@
1
- /******************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
- /* global Reflect, Promise, SuppressedError, Symbol */
16
-
17
-
18
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
19
- var e = new Error(message);
20
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
21
- };
22
-
23
- /**
24
- * Sends a message to the backend.
25
- * @example
26
- * ```typescript
27
- * import { invoke } from '@tauri-apps/api/primitives';
28
- * await invoke('login', { user: 'tauri', password: 'poiwe3h4r5ip3yrhtew9ty' });
29
- * ```
30
- *
31
- * @param cmd The command name.
32
- * @param args The optional arguments to pass to the command.
33
- * @param options The request options.
34
- * @return A promise resolving or rejecting to the backend response.
35
- *
36
- * @since 1.0.0
37
- */
38
- async function invoke(cmd, args = {}, options) {
39
- return window.__TAURI_INTERNALS__.invoke(cmd, args, options);
40
- }
41
-
42
- // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
43
- // SPDX-License-Identifier: Apache-2.0
44
- // SPDX-License-Identifier: MIT
45
- /**
46
- * Make HTTP requests with the Rust backend.
47
- *
48
- * ## Security
49
- *
50
- * This API has a scope configuration that forces you to restrict the URLs and paths that can be accessed using glob patterns.
51
- *
52
- * For instance, this scope configuration only allows making HTTP requests to the GitHub API for the `tauri-apps` organization:
53
- * ```json
54
- * {
55
- * "plugins": {
56
- * "http": {
57
- * "scope": ["https://api.github.com/repos/tauri-apps/*"]
58
- * }
59
- * }
60
- * }
61
- * ```
62
- * Trying to execute any API with a URL not configured on the scope results in a promise rejection due to denied access.
63
- *
64
- * @module
65
- */
66
- /**
67
- * Fetch a resource from the network. It returns a `Promise` that resolves to the
68
- * `Response` to that `Request`, whether it is successful or not.
69
- *
70
- * @example
71
- * ```typescript
72
- * const response = await fetch("http://my.json.host/data.json");
73
- * console.log(response.status); // e.g. 200
74
- * console.log(response.statusText); // e.g. "OK"
75
- * const jsonData = await response.json();
76
- * ```
77
- *
78
- * @since 2.0.0
79
- */
80
- async function fetch(input, init) {
81
- const maxRedirections = init === null || init === void 0 ? void 0 : init.maxRedirections;
82
- const connectTimeout = init === null || init === void 0 ? void 0 : init.maxRedirections;
83
- // Remove these fields before creating the request
84
- if (init) {
85
- delete init.maxRedirections;
86
- delete init.connectTimeout;
87
- }
88
- const req = new Request(input, init);
89
- const buffer = await req.arrayBuffer();
90
- const reqData = buffer.byteLength ? Array.from(new Uint8Array(buffer)) : null;
91
- const rid = await invoke("plugin:http|fetch", {
92
- method: req.method,
93
- url: req.url,
94
- headers: Array.from(req.headers.entries()),
95
- data: reqData,
96
- maxRedirections,
97
- connectTimeout,
98
- });
99
- req.signal.addEventListener("abort", () => {
100
- invoke("plugin:http|fetch_cancel", {
101
- rid,
102
- });
103
- });
104
- const { status, statusText, url, headers } = await invoke("plugin:http|fetch_send", {
105
- rid,
106
- });
107
- const body = await invoke("plugin:http|fetch_read_body", {
108
- rid,
109
- });
110
- const res = new Response(new Uint8Array(body), {
111
- headers,
112
- status,
113
- statusText,
114
- });
115
- // url is read only but seems like we can do this
116
- Object.defineProperty(res, "url", { value: url });
117
- return res;
118
- }
119
-
120
- export { fetch };
121
- //# sourceMappingURL=index.min.js.map