@mythryl/app-sdk 0.1.4 → 0.1.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 +1 -1
- package/dist/channel.d.ts +4 -1
- package/dist/channel.js +13 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -78,7 +78,7 @@ const response = await fetch("/api/me", { headers });
|
|
|
78
78
|
### Errors
|
|
79
79
|
|
|
80
80
|
A call that fails rejects with a `ProtocolError`. Its `code` is `cancelled`, `unsupported`, `not_consented`,
|
|
81
|
-
`rate_limited` or `unavailable`. A call that gets no answer within 30 seconds rejects with `unavailable`.
|
|
81
|
+
`rate_limited` or `unavailable`. A call the host answers by itself that gets no answer within 30 seconds rejects with `unavailable`. A call that waits on the person (`openUrl`, `openApp`, `compose`, `follow`, `install`) has no time limit: it ends when they answer.
|
|
82
82
|
|
|
83
83
|
## Outside a host
|
|
84
84
|
|
package/dist/channel.d.ts
CHANGED
|
@@ -7,5 +7,8 @@ export interface Channel {
|
|
|
7
7
|
/** Removes the transport listener and rejects pending calls with `cancelled`. */
|
|
8
8
|
dispose: () => void;
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Correlates responses with requests by id, enforces the call timeout and dispatches events. A call that waits on a person
|
|
12
|
+
* has no timeout (`WAITS_ON_PERSON`): it ends when they answer or the SDK is disposed.
|
|
13
|
+
*/
|
|
11
14
|
export declare const createChannel: (transport: Transport, timeoutMs?: number) => Channel;
|
package/dist/channel.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { CALL_TIMEOUT_MS, MESSAGE_SOURCE, ProtocolError, isEventMessage, isResponseMessage, } from "@mythryl/protocol";
|
|
2
|
-
/**
|
|
1
|
+
import { CALL_TIMEOUT_MS, MESSAGE_SOURCE, ProtocolError, isEventMessage, isResponseMessage, WAITS_ON_PERSON, } from "@mythryl/protocol";
|
|
2
|
+
/**
|
|
3
|
+
* Correlates responses with requests by id, enforces the call timeout and dispatches events. A call that waits on a person
|
|
4
|
+
* has no timeout (`WAITS_ON_PERSON`): it ends when they answer or the SDK is disposed.
|
|
5
|
+
*/
|
|
3
6
|
export const createChannel = (transport, timeoutMs = CALL_TIMEOUT_MS) => {
|
|
4
7
|
const pending = new Map();
|
|
5
8
|
const listeners = new Map();
|
|
@@ -14,13 +17,16 @@ export const createChannel = (transport, timeoutMs = CALL_TIMEOUT_MS) => {
|
|
|
14
17
|
request: (method, params, version) => new Promise((resolve, reject) => {
|
|
15
18
|
const id = String((lastId += 1));
|
|
16
19
|
const done = () => {
|
|
17
|
-
|
|
20
|
+
if (timer)
|
|
21
|
+
clearTimeout(timer);
|
|
18
22
|
pending.delete(id);
|
|
19
23
|
};
|
|
20
|
-
const timer =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
const timer = WAITS_ON_PERSON[method]
|
|
25
|
+
? undefined
|
|
26
|
+
: setTimeout(() => {
|
|
27
|
+
done();
|
|
28
|
+
reject(new ProtocolError("unavailable", `${method} did not answer in ${timeoutMs} ms.`));
|
|
29
|
+
}, timeoutMs);
|
|
24
30
|
pending.set(id, {
|
|
25
31
|
timer,
|
|
26
32
|
fail: (error) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mythryl/app-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "The browser SDK for Mythryl mini apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@mythryl/protocol": "0.1.
|
|
29
|
+
"@mythryl/protocol": "0.1.5"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"typescript": "~6.0.3",
|