@tauri-apps/plugin-http 2.0.0-alpha.1 → 2.0.0-alpha.2
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/dist-js/index.d.ts +0 -26
- package/dist-js/index.min.js +30 -6
- package/dist-js/index.mjs +28 -6
- package/package.json +2 -2
package/README.md
CHANGED
package/dist-js/index.d.ts
CHANGED
|
@@ -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
|
*
|
package/dist-js/index.min.js
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
|
+
var f=Object.defineProperty;var g=(a,b)=>{for(var c in b)f(a,c,{get:b[c],enumerable:!0});};var e=(a,b,c)=>{if(!b.has(a))throw TypeError("Cannot "+c)};var h=(a,b,c)=>(e(a,b,"read from private field"),c?c.call(a):b.get(a)),i$1=(a,b,c)=>{if(b.has(a))throw TypeError("Cannot add the same private member more than once");b instanceof WeakSet?b.add(a):b.set(a,c);},j=(a,b,c,d)=>(e(a,b,"write to private field"),d?d.call(a,c):b.set(a,c),c);
|
|
2
|
+
|
|
3
|
+
var T={};g(T,{Channel:()=>i,PluginListener:()=>o,addPluginListener:()=>l,convertFileSrc:()=>v,invoke:()=>u,transformCallback:()=>_});function _(e,n=!1){return window.__TAURI_INTERNALS__.transformCallback(e,n)}var r,i=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0;i$1(this,r,()=>{});this.id=_(n=>{h(this,r).call(this,n);});}set onmessage(n){j(this,r,n);}get onmessage(){return h(this,r)}toJSON(){return `__CHANNEL__:${this.id}`}};r=new WeakMap;var o=class{constructor(n,s,t){this.plugin=n,this.event=s,this.channelId=t;}async unregister(){return u(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function l(e,n,s){let t=new i;return t.onmessage=s,u(`plugin:${e}|register_listener`,{event:n,handler:t}).then(()=>new o(e,n,t.id))}async function u(e,n={},s){return window.__TAURI_INTERNALS__.invoke(e,n,s)}function v(e,n="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(e,n)}
|
|
4
|
+
|
|
1
5
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
2
6
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
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
|
+
*/
|
|
4
29
|
/**
|
|
5
30
|
* Fetch a resource from the network. It returns a `Promise` that resolves to the
|
|
6
31
|
* `Response` to that `Request`, whether it is successful or not.
|
|
@@ -26,8 +51,7 @@ async function fetch(input, init) {
|
|
|
26
51
|
const req = new Request(input, init);
|
|
27
52
|
const buffer = await req.arrayBuffer();
|
|
28
53
|
const reqData = buffer.byteLength ? Array.from(new Uint8Array(buffer)) : null;
|
|
29
|
-
const rid = await
|
|
30
|
-
cmd: "fetch",
|
|
54
|
+
const rid = await u("plugin:http|fetch", {
|
|
31
55
|
method: req.method,
|
|
32
56
|
url: req.url,
|
|
33
57
|
headers: Array.from(req.headers.entries()),
|
|
@@ -36,17 +60,17 @@ async function fetch(input, init) {
|
|
|
36
60
|
connectTimeout,
|
|
37
61
|
});
|
|
38
62
|
req.signal.addEventListener("abort", () => {
|
|
39
|
-
|
|
63
|
+
u("plugin:http|fetch_cancel", {
|
|
40
64
|
rid,
|
|
41
65
|
});
|
|
42
66
|
});
|
|
43
|
-
const { status, statusText, url, headers } = await
|
|
67
|
+
const { status, statusText, url, headers } = await u("plugin:http|fetch_send", {
|
|
44
68
|
rid,
|
|
45
69
|
});
|
|
46
|
-
const body = await
|
|
70
|
+
const body = await u("plugin:http|fetch_read_body", {
|
|
47
71
|
rid,
|
|
48
72
|
});
|
|
49
|
-
const res = new Response(Uint8Array
|
|
73
|
+
const res = new Response(new Uint8Array(body), {
|
|
50
74
|
headers,
|
|
51
75
|
status,
|
|
52
76
|
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
|
|
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
|
-
|
|
61
|
+
invoke("plugin:http|fetch_cancel", {
|
|
40
62
|
rid,
|
|
41
63
|
});
|
|
42
64
|
});
|
|
43
|
-
const { status, statusText, url, headers } = await
|
|
65
|
+
const { status, statusText, url, headers } = await invoke("plugin:http|fetch_send", {
|
|
44
66
|
rid,
|
|
45
67
|
});
|
|
46
|
-
const body = await
|
|
68
|
+
const body = await invoke("plugin:http|fetch_read_body", {
|
|
47
69
|
rid,
|
|
48
70
|
});
|
|
49
|
-
const res = new Response(Uint8Array
|
|
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.
|
|
3
|
+
"version": "2.0.0-alpha.2",
|
|
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.
|
|
27
|
+
"@tauri-apps/api": "2.0.0-alpha.9"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "rollup -c"
|