@mostra/protocol 0.1.0 → 0.3.0

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 (44) hide show
  1. package/dist/artifact.d.ts.map +1 -1
  2. package/dist/artifact.js +8 -3
  3. package/dist/artifact.js.map +1 -1
  4. package/dist/diagnostics/codes/env.d.ts +1 -1
  5. package/dist/diagnostics/codes/env.d.ts.map +1 -1
  6. package/dist/diagnostics/codes/env.js +12 -1
  7. package/dist/diagnostics/codes/env.js.map +1 -1
  8. package/dist/diagnostics/codes/host.d.ts +1 -1
  9. package/dist/diagnostics/codes/host.d.ts.map +1 -1
  10. package/dist/diagnostics/codes/host.js +12 -1
  11. package/dist/diagnostics/codes/host.js.map +1 -1
  12. package/dist/diagnostics/codes/platform.js +2 -2
  13. package/dist/diagnostics/codes/platform.js.map +1 -1
  14. package/dist/index.d.ts +4 -3
  15. package/dist/index.js +3 -2
  16. package/dist/method.d.ts +12 -0
  17. package/dist/method.d.ts.map +1 -1
  18. package/dist/method.js.map +1 -1
  19. package/dist/methods/artifact/create.d.ts.map +1 -1
  20. package/dist/methods/artifact/create.js +2 -1
  21. package/dist/methods/artifact/create.js.map +1 -1
  22. package/dist/methods/index.d.ts +3 -1
  23. package/dist/methods/index.d.ts.map +1 -1
  24. package/dist/methods/index.js +22 -4
  25. package/dist/methods/index.js.map +1 -1
  26. package/dist/methods/mostra/initialize.d.ts +1 -1
  27. package/dist/methods/mostra/initialize.js.map +1 -1
  28. package/dist/methods/port/identity-resolve.d.ts +36 -0
  29. package/dist/methods/port/identity-resolve.d.ts.map +1 -0
  30. package/dist/methods/port/identity-resolve.js +35 -0
  31. package/dist/methods/port/identity-resolve.js.map +1 -0
  32. package/package.json +3 -3
  33. package/schemas/protocol.draft-07.json +416 -3
  34. package/schemas/protocol.schema.json +416 -3
  35. package/src/artifact.ts +7 -2
  36. package/src/diagnostics/codes/env.ts +12 -0
  37. package/src/diagnostics/codes/host.ts +12 -0
  38. package/src/diagnostics/codes/platform.ts +2 -2
  39. package/src/index.ts +9 -1
  40. package/src/method.ts +14 -0
  41. package/src/methods/artifact/create.ts +2 -1
  42. package/src/methods/index.ts +13 -3
  43. package/src/methods/mostra/initialize.ts +1 -1
  44. package/src/methods/port/identity-resolve.ts +67 -0
@@ -0,0 +1,67 @@
1
+ import * as z from "zod";
2
+ import { ArtifactId } from "../../ids.ts";
3
+ import { ViewerSpec } from "../../interaction.ts";
4
+ import { defineMethod, type MethodDefinition } from "../../method.ts";
5
+ import { wireRegistry } from "../../wire-registry.ts";
6
+
7
+ /**
8
+ * How a browser's request reached the gateway (D143 item 2): `local` on the gateway's own
9
+ * address; `tailnet` through Tailscale Serve and `token` through a public share, where the link is
10
+ * all that identifies the viewer (both WP-13). An open string on the wire, so a host meets a newer
11
+ * value instead of a refusal.
12
+ */
13
+ export type IdentityVia = "local" | "tailnet" | "token" | (string & {});
14
+
15
+ /** The params of `port/identity.resolve` (INTERFACES §7, D143 item 2). */
16
+ export interface PortIdentityResolveParams {
17
+ /** The artifact whose link is being opened. */
18
+ readonly artifactId: string;
19
+ /** How the request reached the gateway. */
20
+ readonly via: IdentityVia;
21
+ /**
22
+ * The request's headers, names in lower case, without `cookie` and without Mostra's own
23
+ * `x-mostra-*` headers: what a host's proxy or tunnel added (an identity header) is here.
24
+ */
25
+ readonly headers: Readonly<Record<string, string>>;
26
+ }
27
+
28
+ /**
29
+ * The result of `port/identity.resolve`: the person, as the host's stable key and display name
30
+ * (one viewer of kind `host` per `ref`), or `null` for the standalone default.
31
+ */
32
+ export type PortIdentityResolveResult = ViewerSpec | null;
33
+
34
+ const params: z.ZodType<PortIdentityResolveParams> = z
35
+ .object({
36
+ artifactId: ArtifactId.schema,
37
+ via: z.string().min(1),
38
+ headers: z.record(z.string(), z.string()),
39
+ })
40
+ .register(wireRegistry, {
41
+ id: "PortIdentityResolveParams",
42
+ description:
43
+ "A browser opening a link without a viewer: the artifact, how the request arrived and its headers (no cookies, no Mostra headers).",
44
+ });
45
+
46
+ const result: z.ZodType<PortIdentityResolveResult> = ViewerSpec.nullable().register(wireRegistry, {
47
+ id: "PortIdentityResolveResult",
48
+ description:
49
+ "The person the session acts for, by the host's stable key, or null for the default.",
50
+ });
51
+
52
+ /**
53
+ * `port/identity.resolve`: Mostra asks the host that registered the `identity` port who a browser
54
+ * is when it opens a link minted without a viewer (D143 item 2), with 5 seconds to answer. A
55
+ * failure, a timeout or an answer the schema refuses refuses the link's exchange with
56
+ * `MOSTRA_HOST_IDENTITY_UNAVAILABLE`; it never falls back to another person.
57
+ */
58
+ export const portIdentityResolveMethod: MethodDefinition<
59
+ PortIdentityResolveParams,
60
+ PortIdentityResolveResult
61
+ > = defineMethod({
62
+ method: "port/identity.resolve",
63
+ direction: "instance-to-host",
64
+ mutating: false,
65
+ params,
66
+ result,
67
+ });