@mythryl/app-sdk 0.1.5 → 0.1.7
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 +11 -10
- package/dist/channel.d.ts +2 -2
- package/dist/channel.js +4 -4
- package/dist/lazy.js +1 -0
- package/dist/sdk.d.ts +14 -6
- package/dist/sdk.js +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -25,27 +25,28 @@ on the server. Call it from effects and event handlers, which run in the browser
|
|
|
25
25
|
| `sdk.ready()` | Signals that the app has loaded. The host removes its loading screen. |
|
|
26
26
|
| `sdk.close()` | Closes the app. |
|
|
27
27
|
| `sdk.getCapabilities()` | The capabilities the host supports. Check before calling optional features. |
|
|
28
|
-
| `sdk.getContext()` | The signed-in
|
|
29
|
-
| `sdk.auth.signin({ force? })` | `{ token }`: a JWT that authenticates the
|
|
28
|
+
| `sdk.getContext()` | The signed-in user, how the app was launched, and the client environment. |
|
|
29
|
+
| `sdk.auth.signin({ force? })` | `{ token }`: a JWT that authenticates the user to the app's own server. |
|
|
30
30
|
| `sdk.openProfile(actor)` | Opens a profile (handle or DID) in the host and minimises the app. |
|
|
31
31
|
| `sdk.openPost(uri)` | Opens a post, by its `at://` URI, and minimises the app. |
|
|
32
32
|
| `sdk.openTopic(slug)` | Opens a topic, by name without the slash, and minimises the app. |
|
|
33
|
-
| `sdk.openUrl(url)` | Opens an `https` address in the browser once the
|
|
33
|
+
| `sdk.openUrl(url)` | Opens an `https` address in the browser once the user confirms. Rejects with `cancelled` if they decline. |
|
|
34
34
|
| `sdk.openStorePage(domain?)` | Opens an app's store page in the host and minimises this app. Without a domain, it is this app's own page. |
|
|
35
35
|
| `sdk.openApp({ domain, url? })` | Opens another mini app and closes this one. `url` is where to start, on that app's domain. |
|
|
36
|
-
| `sdk.compose({ text?, embedUrl? })` | Opens the composer with a draft. `{ uri }` if the
|
|
37
|
-
| `sdk.
|
|
38
|
-
| `sdk.
|
|
36
|
+
| `sdk.compose({ text?, embedUrl? })` | Opens the composer with a draft. `{ uri }` if the user posted, `{}` if they did not. |
|
|
37
|
+
| `sdk.notifications.request()` | Asks the user to let the app notify them, adding it to their library too. On yes, Mythryl sends your server a notification token for the user (the `notifications.enabled` webhook). Resolves at once if they are already on; rejects with `cancelled` if they decline. |
|
|
38
|
+
| `sdk.install()` | Asks the user to add this app to their library. Resolves at once if it is already there; rejects with `cancelled` if they decline. |
|
|
39
|
+
| `sdk.follow(did)` | Asks the user to follow an account. Rejects with `cancelled` if they decline. |
|
|
39
40
|
| `sdk.on(event, listener)` | Subscribes to a host event. Returns a function that removes the listener. |
|
|
40
41
|
| `sdk.dispose()` | Removes listeners and rejects pending calls with `cancelled`. |
|
|
41
42
|
|
|
42
|
-
`openProfile`, `openPost`, `openTopic`, `openUrl` and `openApp` need the `navigation` capability. `compose`, `follow` and `
|
|
43
|
+
`openProfile`, `openPost`, `openTopic`, `openUrl` and `openApp` need the `navigation` capability. `compose`, `follow`, `install` and `notifications.request`
|
|
43
44
|
each have a capability of the same name. Older hosts have none of them: check `sdk.getCapabilities()`
|
|
44
|
-
first, or handle the `unsupported` rejection. Anything that writes (`compose`, `follow`, `install`) is confirmed by the
|
|
45
|
+
first, or handle the `unsupported` rejection. Anything that writes (`compose`, `follow`, `install`, `notifications.request`) is confirmed by the user. A target the host cannot open rejects with `unavailable`.
|
|
45
46
|
|
|
46
47
|
### Events
|
|
47
48
|
|
|
48
|
-
`minimised` and `maximised` are sent when the
|
|
49
|
+
`minimised` and `maximised` are sent when the user hides the app and brings it back. `colorSchemeChanged` is sent with
|
|
49
50
|
`"light"` or `"dark"` when the host switches mode. `closing` and `resized` are defined by the protocol; hosts do not send
|
|
50
51
|
them yet. `closing` is best effort and must not be relied on to save state.
|
|
51
52
|
|
|
@@ -78,7 +79,7 @@ const response = await fetch("/api/me", { headers });
|
|
|
78
79
|
### Errors
|
|
79
80
|
|
|
80
81
|
A call that fails rejects with a `ProtocolError`. Its `code` is `cancelled`, `unsupported`, `not_consented`,
|
|
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
|
|
82
|
+
`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 user (`openUrl`, `openApp`, `compose`, `follow`, `install`, `notifications.request`) has no time limit: it ends when they answer.
|
|
82
83
|
|
|
83
84
|
## Outside a host
|
|
84
85
|
|
package/dist/channel.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface Channel {
|
|
|
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
|
|
12
|
-
* has no timeout (`
|
|
11
|
+
* Correlates responses with requests by id, enforces the call timeout and dispatches events. A call that waits on a user
|
|
12
|
+
* has no timeout (`WAITS_ON_USER`): it ends when they answer or the SDK is disposed.
|
|
13
13
|
*/
|
|
14
14
|
export declare const createChannel: (transport: Transport, timeoutMs?: number) => Channel;
|
package/dist/channel.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CALL_TIMEOUT_MS, MESSAGE_SOURCE, ProtocolError, isEventMessage, isResponseMessage,
|
|
1
|
+
import { CALL_TIMEOUT_MS, MESSAGE_SOURCE, ProtocolError, isEventMessage, isResponseMessage, WAITS_ON_USER, } from "@mythryl/protocol";
|
|
2
2
|
/**
|
|
3
|
-
* Correlates responses with requests by id, enforces the call timeout and dispatches events. A call that waits on a
|
|
4
|
-
* has no timeout (`
|
|
3
|
+
* Correlates responses with requests by id, enforces the call timeout and dispatches events. A call that waits on a user
|
|
4
|
+
* has no timeout (`WAITS_ON_USER`): it ends when they answer or the SDK is disposed.
|
|
5
5
|
*/
|
|
6
6
|
export const createChannel = (transport, timeoutMs = CALL_TIMEOUT_MS) => {
|
|
7
7
|
const pending = new Map();
|
|
@@ -21,7 +21,7 @@ export const createChannel = (transport, timeoutMs = CALL_TIMEOUT_MS) => {
|
|
|
21
21
|
clearTimeout(timer);
|
|
22
22
|
pending.delete(id);
|
|
23
23
|
};
|
|
24
|
-
const timer =
|
|
24
|
+
const timer = WAITS_ON_USER[method]
|
|
25
25
|
? undefined
|
|
26
26
|
: setTimeout(() => {
|
|
27
27
|
done();
|
package/dist/lazy.js
CHANGED
|
@@ -20,6 +20,7 @@ export const lazySdk = (create) => {
|
|
|
20
20
|
compose: (options) => sdk().compose(options),
|
|
21
21
|
follow: (did) => sdk().follow(did),
|
|
22
22
|
install: () => sdk().install(),
|
|
23
|
+
notifications: { request: () => sdk().notifications.request() },
|
|
23
24
|
on: (event, listener) => sdk().on(event, listener),
|
|
24
25
|
dispose: () => {
|
|
25
26
|
current?.dispose();
|
package/dist/sdk.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface Sdk {
|
|
|
10
10
|
getContext: () => Promise<AppContext>;
|
|
11
11
|
auth: {
|
|
12
12
|
/**
|
|
13
|
-
* Returns a token that authenticates the
|
|
13
|
+
* Returns a token that authenticates the user to the app's own server.
|
|
14
14
|
*
|
|
15
15
|
* The token is a JWT signed by Mythryl. Its `aud` is the app's domain and it is valid for 10 minutes. Send it as a
|
|
16
16
|
* bearer token and verify it on the server. The SDK caches the token and requests a new one when less than a
|
|
@@ -25,13 +25,13 @@ export interface Sdk {
|
|
|
25
25
|
}>;
|
|
26
26
|
};
|
|
27
27
|
/** Subscribes to a host event. Returns a function that removes the listener. */
|
|
28
|
-
/** Opens a
|
|
28
|
+
/** Opens a user's profile in the host and minimises the app. `actor` is a handle or a DID. Check the `navigation` capability first. */
|
|
29
29
|
openProfile: (actor: string) => Promise<void>;
|
|
30
30
|
/** Opens a post in the host and minimises the app. `uri` is the post's `at://` URI. */
|
|
31
31
|
openPost: (uri: string) => Promise<void>;
|
|
32
32
|
/** Opens a topic in the host and minimises the app. `slug` is the topic's name without the leading slash. */
|
|
33
33
|
openTopic: (slug: string) => Promise<void>;
|
|
34
|
-
/** Opens an `https` address in the browser after the
|
|
34
|
+
/** Opens an `https` address in the browser after the user confirms. Rejects with `cancelled` if they decline. */
|
|
35
35
|
openUrl: (url: string) => Promise<void>;
|
|
36
36
|
/** Opens an app's store page in the host and minimises the calling app. `domain` names the app; left out, it is this app's own page. */
|
|
37
37
|
openStorePage: (domain?: string) => Promise<void>;
|
|
@@ -40,16 +40,24 @@ export interface Sdk {
|
|
|
40
40
|
domain: string;
|
|
41
41
|
url?: string;
|
|
42
42
|
}) => Promise<void>;
|
|
43
|
-
/** Opens the composer with a draft. Resolves with the post's URI if the
|
|
43
|
+
/** Opens the composer with a draft. Resolves with the post's URI if the user posted, and without one if they did not. Needs the `compose` capability. */
|
|
44
44
|
compose: (options?: {
|
|
45
45
|
text?: string;
|
|
46
46
|
embedUrl?: string;
|
|
47
47
|
}) => Promise<{
|
|
48
48
|
uri?: string;
|
|
49
49
|
}>;
|
|
50
|
-
/** Asks the
|
|
50
|
+
/** Asks the user to add this app to their library. Resolves at once if it is already there; rejects with `cancelled` if they decline. Needs the `install` capability. */
|
|
51
51
|
install: () => Promise<void>;
|
|
52
|
-
|
|
52
|
+
notifications: {
|
|
53
|
+
/**
|
|
54
|
+
* Asks the user to let the app notify them, which also adds it to their library. On yes, Mythryl sends your server a
|
|
55
|
+
* notification token for the user (the `notifications.enabled` webhook). Resolves at once if they are already on;
|
|
56
|
+
* rejects with `cancelled` if they decline. Needs the `notifications` capability.
|
|
57
|
+
*/
|
|
58
|
+
request: () => Promise<void>;
|
|
59
|
+
};
|
|
60
|
+
/** Asks the user to follow an account, by DID. Rejects with `cancelled` if they decline. Needs the `follow` capability. */
|
|
53
61
|
follow: (did: string) => Promise<void>;
|
|
54
62
|
on: <E extends EventName>(event: E, listener: (data: Events[E]) => void) => () => void;
|
|
55
63
|
/** Removes listeners and rejects pending calls with `cancelled`. */
|
package/dist/sdk.js
CHANGED
|
@@ -34,6 +34,7 @@ export const createSdk = (transport = windowTransport()) => {
|
|
|
34
34
|
compose: (options) => call("compose", options ?? {}),
|
|
35
35
|
follow: (did) => call("follow", { did }),
|
|
36
36
|
install: () => call("install", undefined),
|
|
37
|
+
notifications: { request: () => call("notifications.request", undefined) },
|
|
37
38
|
// The host sends events only after the handshake, so subscribing starts it.
|
|
38
39
|
on: (event, listener) => {
|
|
39
40
|
connect().catch(() => undefined);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mythryl/app-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
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.7"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"typescript": "~6.0.3",
|