@mythryl/app-sdk 0.1.1 → 0.1.3

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
@@ -27,13 +27,38 @@ on the server. Call it from effects and event handlers, which run in the browser
27
27
  | `sdk.getCapabilities()` | The capabilities the host supports. Check before calling optional features. |
28
28
  | `sdk.getContext()` | The signed-in person, how the app was launched, and the client environment. |
29
29
  | `sdk.auth.signin({ force? })` | `{ token }`: a JWT that authenticates the person to the app's own server. |
30
+ | `sdk.openProfile(actor)` | Opens a profile (handle or DID) in the host and minimises the app. |
31
+ | `sdk.openPost(uri)` | Opens a post, by its `at://` URI, and minimises the app. |
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 person confirms. Rejects with `cancelled` if they decline. |
34
+ | `sdk.openApp({ domain, url? })` | Opens another mini app and closes this one. `url` is where to start, on that app's domain. |
35
+ | `sdk.compose({ text?, embedUrl? })` | Opens the composer with a draft. `{ uri }` if the person posted, `{}` if they did not. |
36
+ | `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. |
30
38
  | `sdk.on(event, listener)` | Subscribes to a host event. Returns a function that removes the listener. |
31
39
  | `sdk.dispose()` | Removes listeners and rejects pending calls with `cancelled`. |
32
40
 
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`.
44
+
33
45
  ### Events
34
46
 
35
- `minimised` and `maximised` are sent when the person hides the app and brings it back. `closing` and `resized` are
36
- defined by the protocol; hosts do not send them yet. `closing` is best effort and must not be relied on to save state.
47
+ `minimised` and `maximised` are sent when the person hides the app and brings it back. `colorSchemeChanged` is sent with
48
+ `"light"` or `"dark"` when the host switches mode. `closing` and `resized` are defined by the protocol; hosts do not send
49
+ them yet. `closing` is best effort and must not be relied on to save state.
50
+
51
+ ### Light and dark mode
52
+
53
+ `sdk.getContext()` returns the host's current mode in `client.colorScheme`, and the `colorSchemeChanged` event reports
54
+ each change. What the app does with it is up to the app.
55
+
56
+ ```ts
57
+ const { client } = await sdk.getContext();
58
+ setMode(client.colorScheme);
59
+
60
+ sdk.on("colorSchemeChanged", setMode);
61
+ ```
37
62
 
38
63
  ### Signing in to your server
39
64
 
package/dist/index.d.ts CHANGED
@@ -4,4 +4,4 @@ export default sdk;
4
4
  export { sdk };
5
5
  export { createSdk, type Sdk } from "./sdk.js";
6
6
  export { isEmbedded, windowTransport, type Transport } from "./transport.js";
7
- export { EVENT_NAMES, ProtocolError, type AppContext, type Capability, type ErrorCode, type EventName, type Events } from "@mythryl/protocol";
7
+ export { EVENT_NAMES, ProtocolError, type AppContext, type Capability, type ColorScheme, type ErrorCode, type EventName, type Events, } from "@mythryl/protocol";
package/dist/index.js CHANGED
@@ -6,4 +6,4 @@ export default sdk;
6
6
  export { sdk };
7
7
  export { createSdk } from "./sdk.js";
8
8
  export { isEmbedded, windowTransport } from "./transport.js";
9
- export { EVENT_NAMES, ProtocolError } from "@mythryl/protocol";
9
+ export { EVENT_NAMES, ProtocolError, } from "@mythryl/protocol";
package/dist/lazy.js CHANGED
@@ -11,6 +11,14 @@ export const lazySdk = (create) => {
11
11
  getCapabilities: () => sdk().getCapabilities(),
12
12
  getContext: () => sdk().getContext(),
13
13
  auth: { signin: (options) => sdk().auth.signin(options) },
14
+ openProfile: (actor) => sdk().openProfile(actor),
15
+ openPost: (uri) => sdk().openPost(uri),
16
+ openTopic: (slug) => sdk().openTopic(slug),
17
+ openUrl: (url) => sdk().openUrl(url),
18
+ openApp: (options) => sdk().openApp(options),
19
+ compose: (options) => sdk().compose(options),
20
+ follow: (did) => sdk().follow(did),
21
+ share: () => sdk().share(),
14
22
  on: (event, listener) => sdk().on(event, listener),
15
23
  dispose: () => {
16
24
  current?.dispose();
package/dist/sdk.d.ts CHANGED
@@ -25,6 +25,30 @@ export interface Sdk {
25
25
  }>;
26
26
  };
27
27
  /** Subscribes to a host event. Returns a function that removes the listener. */
28
+ /** Opens a person's profile in the host and minimises the app. `actor` is a handle or a DID. Check the `navigation` capability first. */
29
+ openProfile: (actor: string) => Promise<void>;
30
+ /** Opens a post in the host and minimises the app. `uri` is the post's `at://` URI. */
31
+ openPost: (uri: string) => Promise<void>;
32
+ /** Opens a topic in the host and minimises the app. `slug` is the topic's name without the leading slash. */
33
+ openTopic: (slug: string) => Promise<void>;
34
+ /** Opens an `https` address in the browser after the person confirms. Rejects with `cancelled` if they decline. */
35
+ openUrl: (url: string) => Promise<void>;
36
+ /** Opens another mini app by its domain and closes this one. `url` is where in that app to start, on its own domain. */
37
+ openApp: (options: {
38
+ domain: string;
39
+ url?: string;
40
+ }) => Promise<void>;
41
+ /** Opens the composer with a draft. Resolves with the post's URI if the person posted, and without one if they did not. Needs the `compose` capability. */
42
+ compose: (options?: {
43
+ text?: string;
44
+ embedUrl?: string;
45
+ }) => Promise<{
46
+ uri?: string;
47
+ }>;
48
+ /** Asks the person to follow an account, by DID. Rejects with `cancelled` if they decline. Needs the `follow` capability. */
49
+ follow: (did: string) => Promise<void>;
50
+ /** Opens the share sheet with a link to the app. Needs the `share` capability. */
51
+ share: () => Promise<void>;
28
52
  on: <E extends EventName>(event: E, listener: (data: Events[E]) => void) => () => void;
29
53
  /** Removes listeners and rejects pending calls with `cancelled`. */
30
54
  dispose: () => void;
package/dist/sdk.js CHANGED
@@ -25,6 +25,14 @@ export const createSdk = (transport = windowTransport()) => {
25
25
  getCapabilities: async () => (await connect()).capabilities,
26
26
  getContext: () => call("getContext", undefined),
27
27
  auth: { signin: (options) => tokens.get(options?.force) },
28
+ openProfile: (actor) => call("openProfile", { actor }),
29
+ openPost: (uri) => call("openPost", { uri }),
30
+ openTopic: (slug) => call("openTopic", { slug }),
31
+ openUrl: (url) => call("openUrl", { url }),
32
+ openApp: (options) => call("openApp", options),
33
+ compose: (options) => call("compose", options ?? {}),
34
+ follow: (did) => call("follow", { did }),
35
+ share: () => call("share", undefined),
28
36
  // The host sends events only after the handshake, so subscribing starts it.
29
37
  on: (event, listener) => {
30
38
  connect().catch(() => undefined);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mythryl/app-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
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.1"
29
+ "@mythryl/protocol": "0.1.3"
30
30
  },
31
31
  "devDependencies": {
32
32
  "typescript": "~6.0.3",