@mythryl/app-sdk 0.1.3 → 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 CHANGED
@@ -31,16 +31,17 @@ on the server. Call it from effects and event handlers, which run in the browser
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
33
  | `sdk.openUrl(url)` | Opens an `https` address in the browser once the person confirms. Rejects with `cancelled` if they decline. |
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. |
34
35
  | `sdk.openApp({ domain, url? })` | Opens another mini app and closes this one. `url` is where to start, on that app's domain. |
35
36
  | `sdk.compose({ text?, embedUrl? })` | Opens the composer with a draft. `{ uri }` if the person posted, `{}` if they did not. |
37
+ | `sdk.install()` | Asks the person to add this app to their library. Resolves at once if it is already there; rejects with `cancelled` if they decline. |
36
38
  | `sdk.follow(did)` | Asks the person to follow an account. Rejects with `cancelled` if they decline. |
37
- | `sdk.share()` | Opens the share sheet with a link to the app. |
38
39
  | `sdk.on(event, listener)` | Subscribes to a host event. Returns a function that removes the listener. |
39
40
  | `sdk.dispose()` | Removes listeners and rejects pending calls with `cancelled`. |
40
41
 
41
- `openProfile`, `openPost`, `openTopic`, `openUrl` and `openApp` need the `navigation` capability. `compose`, `follow`
42
- and `share` each have a capability of the same name. Older hosts have none of them: check `sdk.getCapabilities()`
43
- first, or handle the `unsupported` rejection. Anything that writes (`compose`, `follow`) is confirmed by the person. A target the host cannot open rejects with `unavailable`.
42
+ `openProfile`, `openPost`, `openTopic`, `openUrl` and `openApp` need the `navigation` capability. `compose`, `follow` and `install`
43
+ 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 person. A target the host cannot open rejects with `unavailable`.
44
45
 
45
46
  ### Events
46
47
 
@@ -77,7 +78,7 @@ const response = await fetch("/api/me", { headers });
77
78
  ### Errors
78
79
 
79
80
  A call that fails rejects with a `ProtocolError`. Its `code` is `cancelled`, `unsupported`, `not_consented`,
80
- `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.
81
82
 
82
83
  ## Outside a host
83
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
- /** Correlates responses with requests by id, enforces the call timeout and dispatches events. Independent of which calls exist. */
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
- /** Correlates responses with requests by id, enforces the call timeout and dispatches events. Independent of which calls exist. */
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
- clearTimeout(timer);
20
+ if (timer)
21
+ clearTimeout(timer);
18
22
  pending.delete(id);
19
23
  };
20
- const timer = setTimeout(() => {
21
- done();
22
- reject(new ProtocolError("unavailable", `${method} did not answer in ${timeoutMs} ms.`));
23
- }, timeoutMs);
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/dist/lazy.js CHANGED
@@ -15,10 +15,11 @@ export const lazySdk = (create) => {
15
15
  openPost: (uri) => sdk().openPost(uri),
16
16
  openTopic: (slug) => sdk().openTopic(slug),
17
17
  openUrl: (url) => sdk().openUrl(url),
18
+ openStorePage: (domain) => sdk().openStorePage(domain),
18
19
  openApp: (options) => sdk().openApp(options),
19
20
  compose: (options) => sdk().compose(options),
20
21
  follow: (did) => sdk().follow(did),
21
- share: () => sdk().share(),
22
+ install: () => sdk().install(),
22
23
  on: (event, listener) => sdk().on(event, listener),
23
24
  dispose: () => {
24
25
  current?.dispose();
package/dist/sdk.d.ts CHANGED
@@ -33,6 +33,8 @@ export interface Sdk {
33
33
  openTopic: (slug: string) => Promise<void>;
34
34
  /** Opens an `https` address in the browser after the person confirms. Rejects with `cancelled` if they decline. */
35
35
  openUrl: (url: string) => Promise<void>;
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
+ openStorePage: (domain?: string) => Promise<void>;
36
38
  /** Opens another mini app by its domain and closes this one. `url` is where in that app to start, on its own domain. */
37
39
  openApp: (options: {
38
40
  domain: string;
@@ -45,10 +47,10 @@ export interface Sdk {
45
47
  }) => Promise<{
46
48
  uri?: string;
47
49
  }>;
50
+ /** Asks the person 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
+ install: () => Promise<void>;
48
52
  /** Asks the person to follow an account, by DID. Rejects with `cancelled` if they decline. Needs the `follow` capability. */
49
53
  follow: (did: string) => Promise<void>;
50
- /** Opens the share sheet with a link to the app. Needs the `share` capability. */
51
- share: () => Promise<void>;
52
54
  on: <E extends EventName>(event: E, listener: (data: Events[E]) => void) => () => void;
53
55
  /** Removes listeners and rejects pending calls with `cancelled`. */
54
56
  dispose: () => void;
package/dist/sdk.js CHANGED
@@ -29,10 +29,11 @@ export const createSdk = (transport = windowTransport()) => {
29
29
  openPost: (uri) => call("openPost", { uri }),
30
30
  openTopic: (slug) => call("openTopic", { slug }),
31
31
  openUrl: (url) => call("openUrl", { url }),
32
+ openStorePage: (domain) => call("openStorePage", domain === undefined ? {} : { domain }),
32
33
  openApp: (options) => call("openApp", options),
33
34
  compose: (options) => call("compose", options ?? {}),
34
35
  follow: (did) => call("follow", { did }),
35
- share: () => call("share", undefined),
36
+ install: () => call("install", undefined),
36
37
  // The host sends events only after the handshake, so subscribing starts it.
37
38
  on: (event, listener) => {
38
39
  connect().catch(() => undefined);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mythryl/app-sdk",
3
- "version": "0.1.3",
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.3"
29
+ "@mythryl/protocol": "0.1.5"
30
30
  },
31
31
  "devDependencies": {
32
32
  "typescript": "~6.0.3",