@frockbot/protocol 0.3.40 → 0.3.42

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +43 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frockbot/protocol",
3
- "version": "0.3.40",
3
+ "version": "0.3.42",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
package/src/index.ts CHANGED
@@ -14,6 +14,49 @@ export interface PromptRequest {
14
14
  */
15
15
  export const DEPLOYMENT_HEADER_V1 = "x-frockbot-application-v1";
16
16
 
17
+ /**
18
+ * What the Electron main process hands back for one hosted API call.
19
+ *
20
+ * The desktop shell does not fetch from the renderer: the main process holds
21
+ * the session cookie and makes the request, and the renderer gets this DTO
22
+ * across IPC instead of the answer itself. The DTO is therefore the whole of
23
+ * what the renderer can know about an answer, and anything left out of it is
24
+ * lost — which is how a desktop window came to run a released-over client
25
+ * against a newer backend forever: the deployment header stopped at the main
26
+ * process and the shell's release watcher never saw a second application.
27
+ *
28
+ * `deployment` closes that, and it is one named field rather than a header
29
+ * map on purpose. This is a trust seam; the renderer is handed the single
30
+ * identifier it reads and nothing else the backend happened to say.
31
+ */
32
+ export interface DesktopApiResponseV1 {
33
+ schemaVersion: 1;
34
+ status: number;
35
+ contentType: string | null;
36
+ body: string;
37
+ /**
38
+ * The application that answered, as `DEPLOYMENT_HEADER_V1` named it.
39
+ * Absent where the answer carried no such name, which is every answer a
40
+ * development document serves.
41
+ */
42
+ deployment?: string;
43
+ }
44
+
45
+ /**
46
+ * The renderer's side of that DTO: the answer, as a `Response` the ordinary
47
+ * client code can read, carrying back the deployment name the main process
48
+ * preserved so the shared release watcher sees it on the one path every
49
+ * request already takes.
50
+ */
51
+ export function responseFromDesktopApiV1(
52
+ result: DesktopApiResponseV1,
53
+ ): Response {
54
+ const headers = new Headers();
55
+ if (result.contentType) headers.set("content-type", result.contentType);
56
+ if (result.deployment) headers.set(DEPLOYMENT_HEADER_V1, result.deployment);
57
+ return new Response(result.body, { status: result.status, headers });
58
+ }
59
+
17
60
  /**
18
61
  * Version 1 of the Bot-state observer protocol. Frames are invalidations, not
19
62
  * authority: a client that receives one re-reads the owning HTTP projection.