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

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
@@ -4,7 +4,7 @@ Access the HTTP client written in Rust.
4
4
 
5
5
  ## Install
6
6
 
7
- _This plugin requires a Rust version of at least **1.65**_
7
+ _This plugin requires a Rust version of at least **1.70**_
8
8
 
9
9
  There are three general methods of installation that we can recommend.
10
10
 
@@ -1,29 +1,3 @@
1
- /**
2
- * Make HTTP requests with the Rust backend.
3
- *
4
- * ## Security
5
- *
6
- * This API has a scope configuration that forces you to restrict the URLs and paths that can be accessed using glob patterns.
7
- *
8
- * For instance, this scope configuration only allows making HTTP requests to the GitHub API for the `tauri-apps` organization:
9
- * ```json
10
- * {
11
- * "plugins": {
12
- * "http": {
13
- * "scope": ["https://api.github.com/repos/tauri-apps/*"]
14
- * }
15
- * }
16
- * }
17
- * ```
18
- * Trying to execute any API with a URL not configured on the scope results in a promise rejection due to denied access.
19
- *
20
- * @module
21
- */
22
- declare global {
23
- interface Window {
24
- __TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
25
- }
26
- }
27
1
  /**
28
2
  * Options to configure the Rust client used to make fetch requests
29
3
  *
@@ -1,6 +1,68 @@
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
+
1
42
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2
43
  // SPDX-License-Identifier: Apache-2.0
3
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
+ */
4
66
  /**
5
67
  * Fetch a resource from the network. It returns a `Promise` that resolves to the
6
68
  * `Response` to that `Request`, whether it is successful or not.
@@ -26,8 +88,7 @@ async function fetch(input, init) {
26
88
  const req = new Request(input, init);
27
89
  const buffer = await req.arrayBuffer();
28
90
  const reqData = buffer.byteLength ? Array.from(new Uint8Array(buffer)) : null;
29
- const rid = await window.__TAURI_INVOKE__("plugin:http|fetch", {
30
- cmd: "fetch",
91
+ const rid = await invoke("plugin:http|fetch", {
31
92
  method: req.method,
32
93
  url: req.url,
33
94
  headers: Array.from(req.headers.entries()),
@@ -36,17 +97,17 @@ async function fetch(input, init) {
36
97
  connectTimeout,
37
98
  });
38
99
  req.signal.addEventListener("abort", () => {
39
- window.__TAURI_INVOKE__("plugin:http|fetch_cancel", {
100
+ invoke("plugin:http|fetch_cancel", {
40
101
  rid,
41
102
  });
42
103
  });
43
- const { status, statusText, url, headers } = await window.__TAURI_INVOKE__("plugin:http|fetch_send", {
104
+ const { status, statusText, url, headers } = await invoke("plugin:http|fetch_send", {
44
105
  rid,
45
106
  });
46
- const body = await window.__TAURI_INVOKE__("plugin:http|fetch_read_body", {
107
+ const body = await invoke("plugin:http|fetch_read_body", {
47
108
  rid,
48
109
  });
49
- const res = new Response(Uint8Array.from(body), {
110
+ const res = new Response(new Uint8Array(body), {
50
111
  headers,
51
112
  status,
52
113
  statusText,
package/dist-js/index.mjs CHANGED
@@ -1,6 +1,29 @@
1
+ import { invoke } from '@tauri-apps/api/primitives';
2
+
1
3
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2
4
  // SPDX-License-Identifier: Apache-2.0
3
5
  // SPDX-License-Identifier: MIT
6
+ /**
7
+ * Make HTTP requests with the Rust backend.
8
+ *
9
+ * ## Security
10
+ *
11
+ * This API has a scope configuration that forces you to restrict the URLs and paths that can be accessed using glob patterns.
12
+ *
13
+ * For instance, this scope configuration only allows making HTTP requests to the GitHub API for the `tauri-apps` organization:
14
+ * ```json
15
+ * {
16
+ * "plugins": {
17
+ * "http": {
18
+ * "scope": ["https://api.github.com/repos/tauri-apps/*"]
19
+ * }
20
+ * }
21
+ * }
22
+ * ```
23
+ * Trying to execute any API with a URL not configured on the scope results in a promise rejection due to denied access.
24
+ *
25
+ * @module
26
+ */
4
27
  /**
5
28
  * Fetch a resource from the network. It returns a `Promise` that resolves to the
6
29
  * `Response` to that `Request`, whether it is successful or not.
@@ -26,8 +49,7 @@ async function fetch(input, init) {
26
49
  const req = new Request(input, init);
27
50
  const buffer = await req.arrayBuffer();
28
51
  const reqData = buffer.byteLength ? Array.from(new Uint8Array(buffer)) : null;
29
- const rid = await window.__TAURI_INVOKE__("plugin:http|fetch", {
30
- cmd: "fetch",
52
+ const rid = await invoke("plugin:http|fetch", {
31
53
  method: req.method,
32
54
  url: req.url,
33
55
  headers: Array.from(req.headers.entries()),
@@ -36,17 +58,17 @@ async function fetch(input, init) {
36
58
  connectTimeout,
37
59
  });
38
60
  req.signal.addEventListener("abort", () => {
39
- window.__TAURI_INVOKE__("plugin:http|fetch_cancel", {
61
+ invoke("plugin:http|fetch_cancel", {
40
62
  rid,
41
63
  });
42
64
  });
43
- const { status, statusText, url, headers } = await window.__TAURI_INVOKE__("plugin:http|fetch_send", {
65
+ const { status, statusText, url, headers } = await invoke("plugin:http|fetch_send", {
44
66
  rid,
45
67
  });
46
- const body = await window.__TAURI_INVOKE__("plugin:http|fetch_read_body", {
68
+ const body = await invoke("plugin:http|fetch_read_body", {
47
69
  rid,
48
70
  });
49
- const res = new Response(Uint8Array.from(body), {
71
+ const res = new Response(new Uint8Array(body), {
50
72
  headers,
51
73
  status,
52
74
  statusText,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-http",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.0-alpha.3",
4
4
  "license": "MIT or APACHE-2.0",
5
5
  "authors": [
6
6
  "Tauri Programme within The Commons Conservancy"
@@ -24,7 +24,7 @@
24
24
  "tslib": "^2.5.0"
25
25
  },
26
26
  "dependencies": {
27
- "@tauri-apps/api": "2.0.0-alpha.6"
27
+ "@tauri-apps/api": "2.0.0-alpha.11"
28
28
  },
29
29
  "scripts": {
30
30
  "build": "rollup -c"