@ghostlytools/sdk 1.11.0 → 1.11.2

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.
Files changed (41) hide show
  1. package/dist/app.js +5 -2
  2. package/dist/app.js.map +1 -1
  3. package/dist/core.js +280 -2
  4. package/dist/core.js.map +1 -1
  5. package/dist/{fakes-Cu6mpUKs.js → fakes-DCH5oJMm.js} +3 -3
  6. package/dist/{fakes-Cu6mpUKs.js.map → fakes-DCH5oJMm.js.map} +1 -1
  7. package/dist/fakes.js +1 -1
  8. package/dist/index.js +3 -3
  9. package/dist/{keet-identity-key-DHlSH_39.js → keet-identity-key-3EEmDkxz.js} +2 -2
  10. package/dist/{keet-identity-key-DHlSH_39.js.map → keet-identity-key-3EEmDkxz.js.map} +1 -1
  11. package/dist/{src-i6IUh-ng.js → src-DA7T3Gvo.js} +1247 -269
  12. package/dist/src-DA7T3Gvo.js.map +1 -0
  13. package/dist/testing.js +4 -4
  14. package/dist/types/browser/src/engine/paymentAdapters/providers/types.d.ts +6 -1
  15. package/dist/types/core/src/audioMetadata.d.ts +23 -0
  16. package/dist/types/core/src/catchUp.d.ts +2 -0
  17. package/dist/types/core/src/chatFiles.d.ts +6 -0
  18. package/dist/types/core/src/clipboardGuard.d.ts +43 -0
  19. package/dist/types/core/src/dhtDelivery.d.ts +13 -0
  20. package/dist/types/core/src/didDht.d.ts +6 -4
  21. package/dist/types/core/src/frames.d.ts +11 -0
  22. package/dist/types/core/src/ghostlink.d.ts +20 -0
  23. package/dist/types/core/src/groupCommunity.d.ts +7 -1
  24. package/dist/types/core/src/groupSession.d.ts +18 -1
  25. package/dist/types/core/src/http.d.ts +16 -2
  26. package/dist/types/core/src/identity.d.ts +8 -1
  27. package/dist/types/core/src/identityProofs.d.ts +7 -0
  28. package/dist/types/core/src/index.d.ts +3 -0
  29. package/dist/types/core/src/miniApp.d.ts +4 -1
  30. package/dist/types/core/src/pairedAppRanges.d.ts +5 -0
  31. package/dist/types/core/src/relay.d.ts +7 -4
  32. package/dist/types/core/src/transport.d.ts +3 -1
  33. package/dist/types/core/src/videoMetadata.d.ts +8 -2
  34. package/dist/types/core/src/viewerGuard.d.ts +20 -7
  35. package/dist/{types-DvtCy3WB.js → types-DYLIIkU8.js} +2 -1
  36. package/dist/types-DYLIIkU8.js.map +1 -0
  37. package/dist/{verify-BoaDPIrS.js → verify-DsXR5sRX.js} +2 -2
  38. package/dist/{verify-BoaDPIrS.js.map → verify-DsXR5sRX.js.map} +1 -1
  39. package/package.json +1 -1
  40. package/dist/src-i6IUh-ng.js.map +0 -1
  41. package/dist/types-DvtCy3WB.js.map +0 -1
package/dist/app.js CHANGED
@@ -61,8 +61,11 @@ function miniAppErrorCode(error) {
61
61
  }
62
62
  /** Limits the broker enforces (and an app can plan for). */
63
63
  var MINI_APP_LIMITS = {
64
- /** One request, serialized. */
65
- requestBytes: 65536,
64
+ /**
65
+ * One request, serialized: a stored value's 64 KiB with room for its key (256 bytes, at most six times that as JSON)
66
+ * and `{"id", "type", "args"}` around them.
67
+ */
68
+ requestBytes: 67584,
66
69
  /** Requests per second, per app. */
67
70
  requestsPerSecond: 50,
68
71
  /**
package/dist/app.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.js","names":[],"sources":["../../core/src/miniApp.ts"],"sourcesContent":["/**\n * The mini-app API: what an app in the runner's sandbox can ask the client's broker for, and nothing more.\n *\n * Matches the broker table of WISP 1200 (docs/wisps/1200-marketplace.md, \"The runner and the broker\"). Types, limits and refusal codes only, with no imports: the broker (apps/ui) and\n * the apps (apps/mini/*) import this one module, so neither side can drift from the other, and app developers get it as\n * `@ghostlytools/sdk/app`. It is imported as `@ghostly/core/miniApp`, outside the\n * core barrel, because apps bundle it into their single HTML file.\n */\n\n/** A JSON value: what `storage` keeps and what `chat.send` carries. */\nexport type MiniAppJson = null | boolean | number | string | MiniAppJson[] | { [key: string]: MiniAppJson };\n\n/** `ghostly.context()`. */\nexport interface MiniAppContext {\n /** This app's version (its manifest's `version`). */\n version: string;\n /** Opened in a chat (true) or alone (false). */\n inChat: boolean;\n /** The same app on the contact's side, while it is open there; null when it is not. */\n peer: { version: string } | null;\n /** The person's display name in this chat, only with the `name` permission. */\n name?: string;\n /** The client's theme, so the app can match it. An app may fall back to `prefers-color-scheme` when it is missing. */\n theme?: \"light\" | \"dark\";\n /** The client's language (BCP 47, for example \"pt-BR\"). An app may fall back to `navigator.language` when it is missing. */\n locale?: string;\n}\n\n/** `chat.peer`: the peer opened the app (again, or in another version) or closed it. */\nexport type MiniAppPeerEvent = { open: true; version: string } | { open: false };\n\n/**\n * A file the person picked for the app (WISP 1200 · Linked files): the client keeps a link to it, never a copy, and the\n * app reads it by `id`, which the client chose. `path` is relative to what was picked, the picked folder's name first,\n * never where it is on the device.\n */\nexport interface MiniAppLinkedFile {\n /** 22 base64url characters. */\n id: string;\n path: string;\n /** Bytes, and when it last changed (ms), as when it was picked. */\n size: number;\n modified: number;\n /** Whether the client can read it now: false after a restart where the browser must be asked again, or before. */\n available: boolean;\n}\n\n/** `ghostly.files.pick`: a folder (with everything under it) or files, of these extensions only when `accept` names some. */\nexport interface MiniAppPickOptions {\n folder?: boolean;\n /** Extensions without the dot, lower case, at most `MINI_APP_LIMITS.filesAccept`. */\n accept?: string[];\n}\n\n/** `window.ghostly` inside the sandbox. */\nexport interface MiniAppApi {\n context(): Promise<MiniAppContext>;\n /** The bytes of a file of the bundle. */\n file(path: string): Promise<ArrayBuffer>;\n /** The app's storage in its scope: this app in this chat, or this app alone. */\n storage: {\n /** The value, or undefined when the key is not set. */\n get(key: string): Promise<MiniAppJson | undefined>;\n set(key: string, value: MiniAppJson): Promise<void>;\n delete(key: string): Promise<void>;\n keys(): Promise<string[]>;\n };\n chat: {\n /** One `apps/1` data frame to the same app on the contact's side. Refused unless the chat is live and the peer has the app open. */\n send(value: MiniAppJson): Promise<void>;\n /** A data frame from the peer, as the peer's app sent it: untrusted. Returns a function that removes the listener. */\n on(event: \"message\", listener: (data: MiniAppJson) => void): () => void;\n on(event: \"peer\", listener: (peer: MiniAppPeerEvent) => void): () => void;\n };\n /**\n * Files the person picks (the `files` permission): absent in a client that has none, so an app tests for it. The\n * client asks the person and shows its own picker; the app reads only what was picked, by id.\n */\n files?: {\n /** The entries picked now; refused with `cancelled` when the person picks nothing. */\n pick(options?: MiniAppPickOptions): Promise<MiniAppLinkedFile[]>;\n /** Every entry this app keeps. */\n list(): Promise<MiniAppLinkedFile[]>;\n /** At most `MINI_APP_LIMITS.filesReadBytes` from `offset`; fewer at the end of the file. */\n read(id: string, range: { offset: number; length: number }): Promise<ArrayBuffer>;\n /** Drops one link, or every link with \"all\". The file itself is never touched. */\n forget(id: string): Promise<void>;\n /**\n * Lets the same app on the contact's side read one kept file (the `chat` permission too, in a chat open on both\n * sides): answers a serve id for the app to tell its contact in its own `chat.send`. It lasts until `unserve`, or\n * until this side or the contact closes the app; a reconnect the app is kept open across keeps it.\n */\n serve(id: string): Promise<string>;\n /** Ends one serve. A serve id that is no longer served is no error. */\n unserve(serveId: string): Promise<void>;\n };\n /**\n * Files the contact's app serves in this chat (the `chat` permission): absent in a client that has no read lane, so\n * an app tests for it and keeps its own way for such a contact.\n */\n remote?: {\n /** At most `MINI_APP_LIMITS.remoteReadBytes` from `offset`; fewer at the end of the file. */\n read(serveId: string, range: { offset: number; length: number }): Promise<ArrayBuffer>;\n /** The served file's size in bytes. */\n stat(serveId: string): Promise<{ size: number }>;\n };\n /** Ends the app. */\n close(): Promise<void>;\n}\n\n/** The message types on the port (web, extension) or through `app_broker` (Desktop). */\nexport type MiniAppRequestType =\n | \"context\"\n | \"file\"\n | \"storage.get\"\n | \"storage.set\"\n | \"storage.delete\"\n | \"storage.keys\"\n | \"chat.send\"\n | \"files.pick\"\n | \"files.list\"\n | \"files.read\"\n | \"files.forget\"\n | \"files.serve\"\n | \"files.unserve\"\n | \"remote.read\"\n | \"remote.stat\"\n | \"close\";\n\n/** A request from the app: `{id, type, args}`. The broker refuses an unknown `type`. */\nexport interface MiniAppRequest {\n id: number;\n type: MiniAppRequestType;\n args: MiniAppJson[];\n}\n\n/**\n * Every code a refused request answers with (WISP 1200, \"The runner and the broker\"). In the sandbox every failed\n * `ghostly.*` call rejects with an `Error` whose `message` is one of these codes; `miniAppErrorCode` reads it back. The\n * runner turns its own failures (no answer from the client, a lost broker) into `failed`, and arguments that are not\n * JSON into `bad-request`.\n *\n * - `bad-key`: a storage key that is not a string of 1 to 256 bytes.\n * - `bad-path`: a `file` path that is not a string of 1 to 1024 characters.\n * - `bad-request`: a request that is not `{id, type, args}` with JSON arguments, or whose arguments are not the call's.\n * - `cancelled`: `files.pick` that the person closed without picking anything.\n * - `changed`: `files.read` (or the contact's `remote.read` of it) of a file whose size or date changed since it was\n * picked: it is picked again to be read.\n * - `failed`: anything else; the client's own words never reach the app.\n * - `full`: a storage write would take the scope past 5 MiB (each key counts 128 bytes, its own bytes eight times and\n * its value's), so the app can make room.\n * - `gone`: `files.read` (or the contact's `remote.read` of it) of a file that is no longer there, or that the client\n * cannot read now (`available` false), or of an id it does not keep; `files.serve` of such an id.\n * - `no-file`: the bundle has no such file.\n * - `not-allowed`: `chat.send` without the `chat` permission, or with the app opened alone; `files.*` without the\n * `files` permission, or in a client that cannot keep links; `files.serve` also without `chat` or with the app opened\n * alone, and `remote.*` without `chat` or with the app opened alone.\n * - `not-open`: `chat.send` before this side's chat has the app open.\n * - `not-served`: `remote.read` or `remote.stat` of a serve id the contact does not serve now (never, or no longer).\n * - `offline`: `chat.send`, `files.serve`, `remote.read` or `remote.stat` while the chat's session is not live.\n * Nothing is kept to send later.\n * - `peer-closed`: `chat.send` or `files.serve` while the contact has not opened the app (or its client does not offer\n * `apps/1`, or for `files.serve` and `remote.*` the read lane, `app-ranges/1`).\n * - `stopped`: a store removed or the publisher revoked the version running.\n * - `too-fast`: past 50 requests a second, past 48 `chat.send` frames a second, or a `chat.send` while the chat's\n * connection is still sending earlier ones (back off and send again).\n * - `too-large`: a request, a stored value or a `chat.send` value past its bound (`MINI_APP_LIMITS`).\n * - `unknown-type`: a request `type` the broker does not answer.\n *\n * A later client may add a code: treat one you do not know as `failed`.\n */\nexport const MINI_APP_ERROR_CODES = [\n \"bad-key\", \"bad-path\", \"bad-request\", \"cancelled\", \"changed\", \"failed\", \"full\", \"gone\", \"no-file\", \"not-allowed\", \"not-open\", \"not-served\", \"offline\",\n \"peer-closed\", \"stopped\", \"too-fast\", \"too-large\", \"unknown-type\",\n] as const;\nexport type MiniAppErrorCode = typeof MINI_APP_ERROR_CODES[number];\n\n/** The code of a refused `ghostly.*` call (the rejection's `Error`), or null for anything that is not one. */\nexport function miniAppErrorCode(error: unknown): MiniAppErrorCode | null {\n const code = error instanceof Error ? error.message : undefined;\n return (MINI_APP_ERROR_CODES as readonly string[]).includes(code as string) ? code as MiniAppErrorCode : null;\n}\n\n/**\n * The broker's answer to one request. `value` is JSON, or an `ArrayBuffer` for `file` on the port (web, extension). On\n * Desktop `app_broker` answers `file` with `bytes` instead, the file in base64, and the runner hands the app an\n * `ArrayBuffer` either way.\n *\n * `error` is one of `MINI_APP_ERROR_CODES` from this client; a later client may send a code this list does not have yet,\n * which an app reads as `failed`.\n */\nexport type MiniAppAnswer =\n | { id: number; ok: true; value?: MiniAppJson | ArrayBuffer }\n | { id: number; ok: true; bytes: string }\n | { id: number; ok: false; error: MiniAppErrorCode | (string & {}) };\n\n/** An event from the broker. */\nexport type MiniAppEvent = { event: \"chat.message\"; data: MiniAppJson } | { event: \"chat.peer\"; data: MiniAppPeerEvent };\n\n/** Limits the broker enforces (and an app can plan for). */\nexport const MINI_APP_LIMITS = {\n /** One request, serialized. */\n requestBytes: 64 * 1024,\n /** Requests per second, per app. */\n requestsPerSecond: 50,\n /**\n * Bytes of `file`, `files.read`, `files.list` and `remote.read` answers per second, per app, counted together: a whole bundle's\n * worth. A request that starts under it is answered whole; past it the request is refused with `too-fast` until the\n * second has gone.\n */\n fileBytesPerSecond: 16 * 1024 * 1024,\n /** One `files.read`, at most. */\n filesReadBytes: 1024 * 1024,\n /** One `remote.read`, at most: one `ar-get` of the read lane. */\n remoteReadBytes: 1024 * 1024,\n /** The links an app keeps, at most: a pick that would pass it is refused with `too-large`. */\n filesEntries: 100_000,\n /** Extensions a `files.pick` may name in `accept`, each 1 to 16 characters of `a-z` and `0-9`. */\n filesAccept: 32,\n /** A storage key, UTF-8. */\n storageKeyBytes: 256,\n /** One stored JSON value, serialized. */\n storageValueBytes: 64 * 1024,\n /** Counted for each stored key beside its own bytes and its value's: what keeping the key costs the device. */\n storageRowBytes: 128,\n /** How many times a stored key's bytes count: the device keeps each key several times, mostly as UTF-16. */\n storageKeyTimes: 8,\n /**\n * Everything an app keeps in one scope (per app and per chat, or alone): for each key `storageRowBytes`, the key's\n * bytes `storageKeyTimes` over and its value's.\n */\n storageScopeBytes: 5 * 1024 * 1024,\n /** One `chat.send` value, serialized: the `paired-app` data cap (decision D5 of the plan). */\n chatDataBytes: 32 * 1024,\n} as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2KA,IAAa,uBAAuB;CAClC;CAAW;CAAY;CAAe;CAAa;CAAW;CAAU;CAAQ;CAAQ;CAAW;CAAe;CAAY;CAAc;CAC5I;CAAe;CAAW;CAAY;CAAa;AACrD;;AAIA,SAAgB,iBAAiB,OAAyC;CACxE,MAAM,OAAO,iBAAiB,QAAQ,MAAM,UAAU,KAAA;CACtD,OAAQ,qBAA2C,SAAS,IAAc,IAAI,OAA2B;AAC3G;;AAmBA,IAAa,kBAAkB;;CAE7B,cAAc;;CAEd,mBAAmB;;;;;;CAMnB,oBAAoB;;CAEpB,gBAAgB;;CAEhB,iBAAiB;;CAEjB,cAAc;;CAEd,aAAa;;CAEb,iBAAiB;;CAEjB,mBAAmB;;CAEnB,iBAAiB;;CAEjB,iBAAiB;;;;;CAKjB,mBAAmB;;CAEnB,eAAe;AACjB"}
1
+ {"version":3,"file":"app.js","names":[],"sources":["../../core/src/miniApp.ts"],"sourcesContent":["/**\n * The mini-app API: what an app in the runner's sandbox can ask the client's broker for, and nothing more.\n *\n * Matches the broker table of WISP 1200 (docs/wisps/1200-marketplace.md, \"The runner and the broker\"). Types, limits and refusal codes only, with no imports: the broker (apps/ui) and\n * the apps (apps/mini/*) import this one module, so neither side can drift from the other, and app developers get it as\n * `@ghostlytools/sdk/app`. It is imported as `@ghostly/core/miniApp`, outside the\n * core barrel, because apps bundle it into their single HTML file.\n */\n\n/** A JSON value: what `storage` keeps and what `chat.send` carries. */\nexport type MiniAppJson = null | boolean | number | string | MiniAppJson[] | { [key: string]: MiniAppJson };\n\n/** `ghostly.context()`. */\nexport interface MiniAppContext {\n /** This app's version (its manifest's `version`). */\n version: string;\n /** Opened in a chat (true) or alone (false). */\n inChat: boolean;\n /** The same app on the contact's side, while it is open there; null when it is not. */\n peer: { version: string } | null;\n /** The person's display name in this chat, only with the `name` permission. */\n name?: string;\n /** The client's theme, so the app can match it. An app may fall back to `prefers-color-scheme` when it is missing. */\n theme?: \"light\" | \"dark\";\n /** The client's language (BCP 47, for example \"pt-BR\"). An app may fall back to `navigator.language` when it is missing. */\n locale?: string;\n}\n\n/** `chat.peer`: the peer opened the app (again, or in another version) or closed it. */\nexport type MiniAppPeerEvent = { open: true; version: string } | { open: false };\n\n/**\n * A file the person picked for the app (WISP 1200 · Linked files): the client keeps a link to it, never a copy, and the\n * app reads it by `id`, which the client chose. `path` is relative to what was picked, the picked folder's name first,\n * never where it is on the device.\n */\nexport interface MiniAppLinkedFile {\n /** 22 base64url characters. */\n id: string;\n path: string;\n /** Bytes, and when it last changed (ms), as when it was picked. */\n size: number;\n modified: number;\n /** Whether the client can read it now: false after a restart where the browser must be asked again, or before. */\n available: boolean;\n}\n\n/** `ghostly.files.pick`: a folder (with everything under it) or files, of these extensions only when `accept` names some. */\nexport interface MiniAppPickOptions {\n folder?: boolean;\n /** Extensions without the dot, lower case, at most `MINI_APP_LIMITS.filesAccept`. */\n accept?: string[];\n}\n\n/** `window.ghostly` inside the sandbox. */\nexport interface MiniAppApi {\n context(): Promise<MiniAppContext>;\n /** The bytes of a file of the bundle. */\n file(path: string): Promise<ArrayBuffer>;\n /** The app's storage in its scope: this app in this chat, or this app alone. */\n storage: {\n /** The value, or undefined when the key is not set. */\n get(key: string): Promise<MiniAppJson | undefined>;\n set(key: string, value: MiniAppJson): Promise<void>;\n delete(key: string): Promise<void>;\n keys(): Promise<string[]>;\n };\n chat: {\n /** One `apps/1` data frame to the same app on the contact's side. Refused unless the chat is live and the peer has the app open. */\n send(value: MiniAppJson): Promise<void>;\n /** A data frame from the peer, as the peer's app sent it: untrusted. Returns a function that removes the listener. */\n on(event: \"message\", listener: (data: MiniAppJson) => void): () => void;\n on(event: \"peer\", listener: (peer: MiniAppPeerEvent) => void): () => void;\n };\n /**\n * Files the person picks (the `files` permission): absent in a client that has none, so an app tests for it. The\n * client asks the person and shows its own picker; the app reads only what was picked, by id.\n */\n files?: {\n /** The entries picked now; refused with `cancelled` when the person picks nothing. */\n pick(options?: MiniAppPickOptions): Promise<MiniAppLinkedFile[]>;\n /** Every entry this app keeps. */\n list(): Promise<MiniAppLinkedFile[]>;\n /** At most `MINI_APP_LIMITS.filesReadBytes` from `offset`; fewer at the end of the file. */\n read(id: string, range: { offset: number; length: number }): Promise<ArrayBuffer>;\n /** Drops one link, or every link with \"all\". The file itself is never touched. */\n forget(id: string): Promise<void>;\n /**\n * Lets the same app on the contact's side read one kept file (the `chat` permission too, in a chat open on both\n * sides): answers a serve id for the app to tell its contact in its own `chat.send`. It lasts until `unserve`, or\n * until this side or the contact closes the app; a reconnect the app is kept open across keeps it.\n */\n serve(id: string): Promise<string>;\n /** Ends one serve. A serve id that is no longer served is no error. */\n unserve(serveId: string): Promise<void>;\n };\n /**\n * Files the contact's app serves in this chat (the `chat` permission): absent in a client that has no read lane, so\n * an app tests for it and keeps its own way for such a contact.\n */\n remote?: {\n /** At most `MINI_APP_LIMITS.remoteReadBytes` from `offset`; fewer at the end of the file. */\n read(serveId: string, range: { offset: number; length: number }): Promise<ArrayBuffer>;\n /** The served file's size in bytes. */\n stat(serveId: string): Promise<{ size: number }>;\n };\n /** Ends the app. */\n close(): Promise<void>;\n}\n\n/** The message types on the port (web, extension) or through `app_broker` (Desktop). */\nexport type MiniAppRequestType =\n | \"context\"\n | \"file\"\n | \"storage.get\"\n | \"storage.set\"\n | \"storage.delete\"\n | \"storage.keys\"\n | \"chat.send\"\n | \"files.pick\"\n | \"files.list\"\n | \"files.read\"\n | \"files.forget\"\n | \"files.serve\"\n | \"files.unserve\"\n | \"remote.read\"\n | \"remote.stat\"\n | \"close\";\n\n/** A request from the app: `{id, type, args}`. The broker refuses an unknown `type`. */\nexport interface MiniAppRequest {\n id: number;\n type: MiniAppRequestType;\n args: MiniAppJson[];\n}\n\n/**\n * Every code a refused request answers with (WISP 1200, \"The runner and the broker\"). In the sandbox every failed\n * `ghostly.*` call rejects with an `Error` whose `message` is one of these codes; `miniAppErrorCode` reads it back. The\n * runner turns its own failures (no answer from the client, a lost broker) into `failed`, and arguments that are not\n * JSON into `bad-request`.\n *\n * - `bad-key`: a storage key that is not a string of 1 to 256 bytes.\n * - `bad-path`: a `file` path that is not a string of 1 to 1024 characters.\n * - `bad-request`: a request that is not `{id, type, args}` with JSON arguments, or whose arguments are not the call's.\n * - `cancelled`: `files.pick` that the person closed without picking anything.\n * - `changed`: `files.read` (or the contact's `remote.read` of it) of a file whose size or date changed since it was\n * picked: it is picked again to be read.\n * - `failed`: anything else; the client's own words never reach the app.\n * - `full`: a storage write would take the scope past 5 MiB (each key counts 128 bytes, its own bytes eight times and\n * its value's), so the app can make room.\n * - `gone`: `files.read` (or the contact's `remote.read` of it) of a file that is no longer there, or that the client\n * cannot read now (`available` false), or of an id it does not keep; `files.serve` of such an id.\n * - `no-file`: the bundle has no such file.\n * - `not-allowed`: `chat.send` without the `chat` permission, or with the app opened alone; `files.*` without the\n * `files` permission, or in a client that cannot keep links; `files.serve` also without `chat` or with the app opened\n * alone, and `remote.*` without `chat` or with the app opened alone.\n * - `not-open`: `chat.send` before this side's chat has the app open.\n * - `not-served`: `remote.read` or `remote.stat` of a serve id the contact does not serve now (never, or no longer).\n * - `offline`: `chat.send`, `files.serve`, `remote.read` or `remote.stat` while the chat's session is not live.\n * Nothing is kept to send later.\n * - `peer-closed`: `chat.send` or `files.serve` while the contact has not opened the app (or its client does not offer\n * `apps/1`, or for `files.serve` and `remote.*` the read lane, `app-ranges/1`).\n * - `stopped`: a store removed or the publisher revoked the version running.\n * - `too-fast`: past 50 requests a second, past 48 `chat.send` frames a second, or a `chat.send` while the chat's\n * connection is still sending earlier ones (back off and send again).\n * - `too-large`: a request, a stored value or a `chat.send` value past its bound (`MINI_APP_LIMITS`).\n * - `unknown-type`: a request `type` the broker does not answer.\n *\n * A later client may add a code: treat one you do not know as `failed`.\n */\nexport const MINI_APP_ERROR_CODES = [\n \"bad-key\", \"bad-path\", \"bad-request\", \"cancelled\", \"changed\", \"failed\", \"full\", \"gone\", \"no-file\", \"not-allowed\", \"not-open\", \"not-served\", \"offline\",\n \"peer-closed\", \"stopped\", \"too-fast\", \"too-large\", \"unknown-type\",\n] as const;\nexport type MiniAppErrorCode = typeof MINI_APP_ERROR_CODES[number];\n\n/** The code of a refused `ghostly.*` call (the rejection's `Error`), or null for anything that is not one. */\nexport function miniAppErrorCode(error: unknown): MiniAppErrorCode | null {\n const code = error instanceof Error ? error.message : undefined;\n return (MINI_APP_ERROR_CODES as readonly string[]).includes(code as string) ? code as MiniAppErrorCode : null;\n}\n\n/**\n * The broker's answer to one request. `value` is JSON, or an `ArrayBuffer` for `file` on the port (web, extension). On\n * Desktop `app_broker` answers `file` with `bytes` instead, the file in base64, and the runner hands the app an\n * `ArrayBuffer` either way.\n *\n * `error` is one of `MINI_APP_ERROR_CODES` from this client; a later client may send a code this list does not have yet,\n * which an app reads as `failed`.\n */\nexport type MiniAppAnswer =\n | { id: number; ok: true; value?: MiniAppJson | ArrayBuffer }\n | { id: number; ok: true; bytes: string }\n | { id: number; ok: false; error: MiniAppErrorCode | (string & {}) };\n\n/** An event from the broker. */\nexport type MiniAppEvent = { event: \"chat.message\"; data: MiniAppJson } | { event: \"chat.peer\"; data: MiniAppPeerEvent };\n\n/** Limits the broker enforces (and an app can plan for). */\nexport const MINI_APP_LIMITS = {\n /**\n * One request, serialized: a stored value's 64 KiB with room for its key (256 bytes, at most six times that as JSON)\n * and `{\"id\", \"type\", \"args\"}` around them.\n */\n requestBytes: 66 * 1024,\n /** Requests per second, per app. */\n requestsPerSecond: 50,\n /**\n * Bytes of `file`, `files.read`, `files.list` and `remote.read` answers per second, per app, counted together: a whole bundle's\n * worth. A request that starts under it is answered whole; past it the request is refused with `too-fast` until the\n * second has gone.\n */\n fileBytesPerSecond: 16 * 1024 * 1024,\n /** One `files.read`, at most. */\n filesReadBytes: 1024 * 1024,\n /** One `remote.read`, at most: one `ar-get` of the read lane. */\n remoteReadBytes: 1024 * 1024,\n /** The links an app keeps, at most: a pick that would pass it is refused with `too-large`. */\n filesEntries: 100_000,\n /** Extensions a `files.pick` may name in `accept`, each 1 to 16 characters of `a-z` and `0-9`. */\n filesAccept: 32,\n /** A storage key, UTF-8. */\n storageKeyBytes: 256,\n /** One stored JSON value, serialized. */\n storageValueBytes: 64 * 1024,\n /** Counted for each stored key beside its own bytes and its value's: what keeping the key costs the device. */\n storageRowBytes: 128,\n /** How many times a stored key's bytes count: the device keeps each key several times, mostly as UTF-16. */\n storageKeyTimes: 8,\n /**\n * Everything an app keeps in one scope (per app and per chat, or alone): for each key `storageRowBytes`, the key's\n * bytes `storageKeyTimes` over and its value's.\n */\n storageScopeBytes: 5 * 1024 * 1024,\n /** One `chat.send` value, serialized: the `paired-app` data cap (decision D5 of the plan). */\n chatDataBytes: 32 * 1024,\n} as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2KA,IAAa,uBAAuB;CAClC;CAAW;CAAY;CAAe;CAAa;CAAW;CAAU;CAAQ;CAAQ;CAAW;CAAe;CAAY;CAAc;CAC5I;CAAe;CAAW;CAAY;CAAa;AACrD;;AAIA,SAAgB,iBAAiB,OAAyC;CACxE,MAAM,OAAO,iBAAiB,QAAQ,MAAM,UAAU,KAAA;CACtD,OAAQ,qBAA2C,SAAS,IAAc,IAAI,OAA2B;AAC3G;;AAmBA,IAAa,kBAAkB;;;;;CAK7B,cAAc;;CAEd,mBAAmB;;;;;;CAMnB,oBAAoB;;CAEpB,gBAAgB;;CAEhB,iBAAiB;;CAEjB,cAAc;;CAEd,aAAa;;CAEb,iBAAiB;;CAEjB,mBAAmB;;CAEnB,iBAAiB;;CAEjB,iBAAiB;;;;;CAKjB,mBAAmB;;CAEnB,eAAe;AACjB"}