@mythryl/app-sdk 0.1.2 → 0.1.4

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,9 +27,22 @@ 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.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
+ | `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 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. |
38
+ | `sdk.follow(did)` | Asks the person to follow an account. Rejects with `cancelled` if they decline. |
30
39
  | `sdk.on(event, listener)` | Subscribes to a host event. Returns a function that removes the listener. |
31
40
  | `sdk.dispose()` | Removes listeners and rejects pending calls with `cancelled`. |
32
41
 
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`.
45
+
33
46
  ### Events
34
47
 
35
48
  `minimised` and `maximised` are sent when the person hides the app and brings it back. `colorSchemeChanged` is sent with
package/dist/lazy.js CHANGED
@@ -11,6 +11,15 @@ 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
+ openStorePage: (domain) => sdk().openStorePage(domain),
19
+ openApp: (options) => sdk().openApp(options),
20
+ compose: (options) => sdk().compose(options),
21
+ follow: (did) => sdk().follow(did),
22
+ install: () => sdk().install(),
14
23
  on: (event, listener) => sdk().on(event, listener),
15
24
  dispose: () => {
16
25
  current?.dispose();
package/dist/sdk.d.ts CHANGED
@@ -25,6 +25,32 @@ 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 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>;
38
+ /** Opens another mini app by its domain and closes this one. `url` is where in that app to start, on its own domain. */
39
+ openApp: (options: {
40
+ domain: string;
41
+ url?: string;
42
+ }) => Promise<void>;
43
+ /** 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. */
44
+ compose: (options?: {
45
+ text?: string;
46
+ embedUrl?: string;
47
+ }) => Promise<{
48
+ uri?: string;
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>;
52
+ /** Asks the person to follow an account, by DID. Rejects with `cancelled` if they decline. Needs the `follow` capability. */
53
+ follow: (did: string) => Promise<void>;
28
54
  on: <E extends EventName>(event: E, listener: (data: Events[E]) => void) => () => void;
29
55
  /** Removes listeners and rejects pending calls with `cancelled`. */
30
56
  dispose: () => void;
package/dist/sdk.js CHANGED
@@ -25,6 +25,15 @@ 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
+ openStorePage: (domain) => call("openStorePage", domain === undefined ? {} : { domain }),
33
+ openApp: (options) => call("openApp", options),
34
+ compose: (options) => call("compose", options ?? {}),
35
+ follow: (did) => call("follow", { did }),
36
+ install: () => call("install", undefined),
28
37
  // The host sends events only after the handshake, so subscribing starts it.
29
38
  on: (event, listener) => {
30
39
  connect().catch(() => undefined);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mythryl/app-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
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.2"
29
+ "@mythryl/protocol": "0.1.4"
30
30
  },
31
31
  "devDependencies": {
32
32
  "typescript": "~6.0.3",