@mythryl/app-sdk 0.1.6 → 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 +4 -3
- package/dist/lazy.js +1 -0
- package/dist/sdk.d.ts +8 -0
- package/dist/sdk.js +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -34,14 +34,15 @@ on the server. Call it from effects and event handlers, which run in the browser
|
|
|
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
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. |
|
|
37
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. |
|
|
38
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 user. A target the host cannot open rejects with `unavailable`.
|
|
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
|
|
|
@@ -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 user (`openUrl`, `openApp`, `compose`, `follow`, `install`) has no time limit: it ends when they answer.
|
|
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/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
|
@@ -49,6 +49,14 @@ export interface Sdk {
|
|
|
49
49
|
}>;
|
|
50
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
|
+
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
|
+
};
|
|
52
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;
|
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",
|