@full-self-browsing/phantom-stream 0.1.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 (102) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +263 -0
  3. package/bin/phantom-stream.js +193 -0
  4. package/dist/types/adapters/bookmarklet.d.ts +22 -0
  5. package/dist/types/adapters/bookmarklet.d.ts.map +1 -0
  6. package/dist/types/adapters/browser-inject.d.ts +7 -0
  7. package/dist/types/adapters/browser-inject.d.ts.map +1 -0
  8. package/dist/types/adapters/extension.d.ts +43 -0
  9. package/dist/types/adapters/extension.d.ts.map +1 -0
  10. package/dist/types/adapters/playwright-inject.d.ts +2 -0
  11. package/dist/types/adapters/playwright-inject.d.ts.map +1 -0
  12. package/dist/types/adapters/playwright.d.ts +14 -0
  13. package/dist/types/adapters/playwright.d.ts.map +1 -0
  14. package/dist/types/capture/index.d.ts +241 -0
  15. package/dist/types/capture/index.d.ts.map +1 -0
  16. package/dist/types/index.d.ts +6 -0
  17. package/dist/types/index.d.ts.map +1 -0
  18. package/dist/types/protocol/constants.d.ts +35 -0
  19. package/dist/types/protocol/constants.d.ts.map +1 -0
  20. package/dist/types/protocol/envelope.d.ts +41 -0
  21. package/dist/types/protocol/envelope.d.ts.map +1 -0
  22. package/dist/types/protocol/index.d.ts +5 -0
  23. package/dist/types/protocol/index.d.ts.map +1 -0
  24. package/dist/types/protocol/messages.d.ts +520 -0
  25. package/dist/types/protocol/messages.d.ts.map +1 -0
  26. package/dist/types/protocol/remote-control.d.ts +70 -0
  27. package/dist/types/protocol/remote-control.d.ts.map +1 -0
  28. package/dist/types/relay/backends/ws.d.ts +39 -0
  29. package/dist/types/relay/backends/ws.d.ts.map +1 -0
  30. package/dist/types/relay/index.d.ts +4 -0
  31. package/dist/types/relay/index.d.ts.map +1 -0
  32. package/dist/types/relay/limits.d.ts +54 -0
  33. package/dist/types/relay/limits.d.ts.map +1 -0
  34. package/dist/types/relay/relay.d.ts +73 -0
  35. package/dist/types/relay/relay.d.ts.map +1 -0
  36. package/dist/types/renderer/diff.d.ts +62 -0
  37. package/dist/types/renderer/diff.d.ts.map +1 -0
  38. package/dist/types/renderer/index.d.ts +211 -0
  39. package/dist/types/renderer/index.d.ts.map +1 -0
  40. package/dist/types/renderer/overlays.d.ts +166 -0
  41. package/dist/types/renderer/overlays.d.ts.map +1 -0
  42. package/dist/types/renderer/sanitize.d.ts +73 -0
  43. package/dist/types/renderer/sanitize.d.ts.map +1 -0
  44. package/dist/types/renderer/snapshot.d.ts +41 -0
  45. package/dist/types/renderer/snapshot.d.ts.map +1 -0
  46. package/dist/types/transport/websocket.d.ts +44 -0
  47. package/dist/types/transport/websocket.d.ts.map +1 -0
  48. package/docs/ARCHITECTURE.md +273 -0
  49. package/docs/DESIGN-HISTORY.md +120 -0
  50. package/docs/QUICKSTARTS.md +289 -0
  51. package/docs/RELEASE.md +60 -0
  52. package/docs/SECURITY.md +156 -0
  53. package/docs/paper/OUTLINE.md +100 -0
  54. package/examples/bookmarklet-demo/demo.css +102 -0
  55. package/examples/bookmarklet-demo/server.js +297 -0
  56. package/examples/bookmarklet-demo/source.html +52 -0
  57. package/examples/bookmarklet-demo/viewer.html +48 -0
  58. package/examples/extension-mv3/demo.css +102 -0
  59. package/examples/extension-mv3/server.js +350 -0
  60. package/examples/extension-mv3/source.html +48 -0
  61. package/examples/extension-mv3/viewer.html +48 -0
  62. package/examples/loopback-mirror.html +369 -0
  63. package/examples/loopback-transport.js +65 -0
  64. package/examples/playwright-demo/demo.css +462 -0
  65. package/examples/playwright-demo/fixture.html +56 -0
  66. package/examples/playwright-demo/fixture.js +57 -0
  67. package/examples/playwright-demo/server.js +517 -0
  68. package/examples/playwright-demo/viewer.html +112 -0
  69. package/examples/playwright-demo/viewer.js +414 -0
  70. package/examples/serve.js +97 -0
  71. package/examples/two-tab-demo/demo.css +266 -0
  72. package/examples/two-tab-demo/server.js +233 -0
  73. package/examples/two-tab-demo/source.html +70 -0
  74. package/examples/two-tab-demo/source.js +213 -0
  75. package/examples/two-tab-demo/viewer.html +72 -0
  76. package/examples/two-tab-demo/viewer.js +121 -0
  77. package/package.json +107 -0
  78. package/src/adapters/bookmarklet.js +98 -0
  79. package/src/adapters/browser-inject.js +17 -0
  80. package/src/adapters/extension.js +322 -0
  81. package/src/adapters/playwright-inject.js +4401 -0
  82. package/src/adapters/playwright.js +540 -0
  83. package/src/capture/README.md +302 -0
  84. package/src/capture/index.js +4361 -0
  85. package/src/index.js +5 -0
  86. package/src/protocol/constants.js +49 -0
  87. package/src/protocol/envelope.js +75 -0
  88. package/src/protocol/index.js +4 -0
  89. package/src/protocol/messages.js +268 -0
  90. package/src/protocol/remote-control.js +300 -0
  91. package/src/relay/README.md +22 -0
  92. package/src/relay/backends/ws.js +186 -0
  93. package/src/relay/index.js +3 -0
  94. package/src/relay/limits.js +105 -0
  95. package/src/relay/relay.js +397 -0
  96. package/src/renderer/README.md +443 -0
  97. package/src/renderer/diff.js +389 -0
  98. package/src/renderer/index.js +1401 -0
  99. package/src/renderer/overlays.js +528 -0
  100. package/src/renderer/sanitize.js +366 -0
  101. package/src/renderer/snapshot.js +202 -0
  102. package/src/transport/websocket.js +553 -0
@@ -0,0 +1,241 @@
1
+ /**
2
+ * The host-injected message sink. `send` mirrors the fire-and-forget
3
+ * semantics of the reference's messaging call: the capture core never awaits
4
+ * delivery and never lets a transport failure propagate into the capture
5
+ * path (errors are routed to the injected logger instead — D-07).
6
+ *
7
+ * The implementation is injected rather than imported so this module works
8
+ * in any runtime and injection context (same pattern as the LZCodec seam in
9
+ * src/protocol/envelope.js).
10
+ *
11
+ * @typedef {Object} Transport
12
+ * @property {(type: string, payload: Object) => void} send
13
+ * Deliver one wire message. `type` is a STREAM.* protocol type; `payload`
14
+ * is the message payload (snapshot object, mutation batch, etc.).
15
+ * @property {() => void} [flush]
16
+ * Optional: drain any host-side buffering. Defaults to a no-op; invoked
17
+ * once at the end of stop().
18
+ */
19
+ /**
20
+ * @typedef {Object} CaptureLogger
21
+ * @property {(...args: *) => void} info
22
+ * @property {(...args: *) => void} warn
23
+ * @property {(...args: *) => void} error
24
+ */
25
+ /**
26
+ * Overlay side-channel state returned by an overlayProvider. `glow` and
27
+ * `progress` are the reference built-ins; every OTHER own enumerable key is
28
+ * forwarded on the wire as a custom overlay kind (Phase 2 VIEW-04 pass-
29
+ * through -- see broadcastOverlayState and README entry E1). The identity
30
+ * keys `streamSessionId` / `snapshotId` are reserved: the capture core
31
+ * stamps them after the provider keys, so a provider can never overwrite
32
+ * stream identity.
33
+ * @typedef {Object} OverlayState
34
+ * @property {Object|null} [glow] Action-highlight rect/state, or null
35
+ * @property {Object|null} [progress] Progress-card state, or null
36
+ */
37
+ /**
38
+ * @typedef {Object} CaptureOptions
39
+ * @property {Transport} transport
40
+ * Required. Factory throws Error('transport-send-required') when
41
+ * transport.send is not a function (factory-time validation may throw;
42
+ * the capture path after start never does).
43
+ * @property {CaptureLogger} [logger]
44
+ * Optional. Defaults to a console-backed logger.
45
+ * @property {(() => OverlayState|null)} [overlayProvider]
46
+ * Optional. Called by the overlay broadcaster to read host overlay state.
47
+ * ALL own enumerable provider keys are forwarded as overlay kinds (custom
48
+ * kinds included); glow/progress default null when omitted; the identity
49
+ * keys (streamSessionId / snapshotId) are reserved and never overwritten.
50
+ * Default null: overlay messages carry { glow: null, progress: null },
51
+ * preserving the reference's wire shape when no overlay system is present.
52
+ * @property {(el: Element) => boolean} [skipElement]
53
+ * Optional. Predicate marking elements the host wants excluded from
54
+ * capture (its own UI). Default returns false (nothing skipped).
55
+ * Applied ancestor-inclusively (closest()-like, reference parity): an
56
+ * element is excluded when the predicate matches it OR any of its
57
+ * ancestors, and skipped subtrees receive NO node-id assignment during
58
+ * serialization -- a root-only predicate (e.g. el.id === 'my-overlay')
59
+ * therefore excludes its whole subtree from both snapshots and diffs.
60
+ * @property {string} [blockSelector]
61
+ * Optional (SEC-03). CSS selector: matching elements are replaced on the
62
+ * wire by a dimension-preserving placeholder carrying ONLY rr_width /
63
+ * rr_height (px, from the live rect) and the nid -- no attributes, no
64
+ * children, no text; mutations anywhere inside a blocked subtree emit
65
+ * nothing. Invalid selectors THROW Error('invalid-mask-selector') at
66
+ * factory time (fail closed and loud -- a silently dropped mask selector
67
+ * would be a privacy leak).
68
+ * @property {string} [maskTextSelector]
69
+ * Optional (SEC-03). CSS selector: text of matching elements AND their
70
+ * descendants is masked (default mask: '*' per non-whitespace character,
71
+ * whitespace and length preserved -- rrweb-compatible). Same factory-time
72
+ * validation as blockSelector.
73
+ * @property {boolean} [maskInputs]
74
+ * Optional (SEC-03), default false. When true, ALL input/textarea/select
75
+ * values are masked. Independent of this option, input[type=password]
76
+ * values are ALWAYS masked (non-configurable rrweb-parity default).
77
+ * @property {(text: string, element: Element) => string} [maskTextFn]
78
+ * Optional (SEC-03). Custom text mask (rrweb signature). A THROWING fn
79
+ * falls back to the default asterisk mask -- raw text never leaks.
80
+ * @property {(text: string, element: Element) => string} [maskInputFn]
81
+ * Optional (SEC-03). Custom input-value mask (rrweb signature). Same
82
+ * fail-closed containment as maskTextFn.
83
+ */
84
+ /**
85
+ * @typedef {Object} CaptureHandle
86
+ * @property {() => void} start Fresh session: mint ids, snapshot, observe.
87
+ * @property {() => void} stop Stop observers (final flush included).
88
+ * @property {() => void} pause Stop observers, keep the session alive.
89
+ * @property {() => void} resume Re-arm observers; same session, no snapshot.
90
+ * @property {(element: Element) => string|null} getNodeId
91
+ * getNodeId(element) -> string|null
92
+ * Return the active PhantomStream nid for a tracked live element, or null
93
+ * for untracked, skipped, disconnected, or inactive-session nodes.
94
+ */
95
+ /**
96
+ * Create a capture instance bound to the ambient window/document.
97
+ *
98
+ * All reference module state lives in this closure, so multiple captures can
99
+ * coexist in one process (each against its own globals). No DOM access
100
+ * happens at module import time; the ambient globals are dereferenced when
101
+ * the factory and its functions run.
102
+ *
103
+ * @param {CaptureOptions} config
104
+ * @returns {CaptureHandle}
105
+ */
106
+ export function createCapture(config: CaptureOptions): CaptureHandle;
107
+ /**
108
+ * The host-injected message sink. `send` mirrors the fire-and-forget
109
+ * semantics of the reference's messaging call: the capture core never awaits
110
+ * delivery and never lets a transport failure propagate into the capture
111
+ * path (errors are routed to the injected logger instead — D-07).
112
+ *
113
+ * The implementation is injected rather than imported so this module works
114
+ * in any runtime and injection context (same pattern as the LZCodec seam in
115
+ * src/protocol/envelope.js).
116
+ */
117
+ export type Transport = {
118
+ /**
119
+ * Deliver one wire message. `type` is a STREAM.* protocol type; `payload`
120
+ * is the message payload (snapshot object, mutation batch, etc.).
121
+ */
122
+ send: (type: string, payload: any) => void;
123
+ /**
124
+ * Optional: drain any host-side buffering. Defaults to a no-op; invoked
125
+ * once at the end of stop().
126
+ */
127
+ flush?: () => void;
128
+ };
129
+ export type CaptureLogger = {
130
+ info: (...args: any) => void;
131
+ warn: (...args: any) => void;
132
+ error: (...args: any) => void;
133
+ };
134
+ /**
135
+ * Overlay side-channel state returned by an overlayProvider. `glow` and
136
+ * `progress` are the reference built-ins; every OTHER own enumerable key is
137
+ * forwarded on the wire as a custom overlay kind (Phase 2 VIEW-04 pass-
138
+ * through -- see broadcastOverlayState and README entry E1). The identity
139
+ * keys `streamSessionId` / `snapshotId` are reserved: the capture core
140
+ * stamps them after the provider keys, so a provider can never overwrite
141
+ * stream identity.
142
+ */
143
+ export type OverlayState = {
144
+ /**
145
+ * Action-highlight rect/state, or null
146
+ */
147
+ glow?: any | null;
148
+ /**
149
+ * Progress-card state, or null
150
+ */
151
+ progress?: any | null;
152
+ };
153
+ export type CaptureOptions = {
154
+ /**
155
+ * Required. Factory throws Error('transport-send-required') when
156
+ * transport.send is not a function (factory-time validation may throw;
157
+ * the capture path after start never does).
158
+ */
159
+ transport: Transport;
160
+ /**
161
+ * Optional. Defaults to a console-backed logger.
162
+ */
163
+ logger?: CaptureLogger;
164
+ /**
165
+ * Optional. Called by the overlay broadcaster to read host overlay state.
166
+ * ALL own enumerable provider keys are forwarded as overlay kinds (custom
167
+ * kinds included); glow/progress default null when omitted; the identity
168
+ * keys (streamSessionId / snapshotId) are reserved and never overwritten.
169
+ * Default null: overlay messages carry { glow: null, progress: null },
170
+ * preserving the reference's wire shape when no overlay system is present.
171
+ */
172
+ overlayProvider?: (() => OverlayState | null);
173
+ /**
174
+ * Optional. Predicate marking elements the host wants excluded from
175
+ * capture (its own UI). Default returns false (nothing skipped).
176
+ * Applied ancestor-inclusively (closest()-like, reference parity): an
177
+ * element is excluded when the predicate matches it OR any of its
178
+ * ancestors, and skipped subtrees receive NO node-id assignment during
179
+ * serialization -- a root-only predicate (e.g. el.id === 'my-overlay')
180
+ * therefore excludes its whole subtree from both snapshots and diffs.
181
+ */
182
+ skipElement?: (el: Element) => boolean;
183
+ /**
184
+ * Optional (SEC-03). CSS selector: matching elements are replaced on the
185
+ * wire by a dimension-preserving placeholder carrying ONLY rr_width /
186
+ * rr_height (px, from the live rect) and the nid -- no attributes, no
187
+ * children, no text; mutations anywhere inside a blocked subtree emit
188
+ * nothing. Invalid selectors THROW Error('invalid-mask-selector') at
189
+ * factory time (fail closed and loud -- a silently dropped mask selector
190
+ * would be a privacy leak).
191
+ */
192
+ blockSelector?: string;
193
+ /**
194
+ * Optional (SEC-03). CSS selector: text of matching elements AND their
195
+ * descendants is masked (default mask: '*' per non-whitespace character,
196
+ * whitespace and length preserved -- rrweb-compatible). Same factory-time
197
+ * validation as blockSelector.
198
+ */
199
+ maskTextSelector?: string;
200
+ /**
201
+ * Optional (SEC-03), default false. When true, ALL input/textarea/select
202
+ * values are masked. Independent of this option, input[type=password]
203
+ * values are ALWAYS masked (non-configurable rrweb-parity default).
204
+ */
205
+ maskInputs?: boolean;
206
+ /**
207
+ * Optional (SEC-03). Custom text mask (rrweb signature). A THROWING fn
208
+ * falls back to the default asterisk mask -- raw text never leaks.
209
+ */
210
+ maskTextFn?: (text: string, element: Element) => string;
211
+ /**
212
+ * Optional (SEC-03). Custom input-value mask (rrweb signature). Same
213
+ * fail-closed containment as maskTextFn.
214
+ */
215
+ maskInputFn?: (text: string, element: Element) => string;
216
+ };
217
+ export type CaptureHandle = {
218
+ /**
219
+ * Fresh session: mint ids, snapshot, observe.
220
+ */
221
+ start: () => void;
222
+ /**
223
+ * Stop observers (final flush included).
224
+ */
225
+ stop: () => void;
226
+ /**
227
+ * Stop observers, keep the session alive.
228
+ */
229
+ pause: () => void;
230
+ /**
231
+ * Re-arm observers; same session, no snapshot.
232
+ */
233
+ resume: () => void;
234
+ /**
235
+ * getNodeId(element) -> string|null
236
+ * Return the active PhantomStream nid for a tracked live element, or null
237
+ * for untracked, skipped, disconnected, or inactive-session nodes.
238
+ */
239
+ getNodeId: (element: Element) => string | null;
240
+ };
241
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/capture/index.js"],"names":[],"mappings":"AAqVA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;GAKG;AAEH;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH;;;;;;;;;;GAUG;AAEH;;;;;;;;;;GAUG;AACH,sCAHW,cAAc,GACZ,aAAa,CAu0HzB;;;;;;;;;;;;;;;;UAx6Ha,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAQ,KAAK,IAAI;;;;;YAGvC,MAAM,IAAI;;;UAOV,CAAC,GAAG,IAAI,EAAE,GAAC,KAAK,IAAI;UACpB,CAAC,GAAG,IAAI,EAAE,GAAC,KAAK,IAAI;WACpB,CAAC,GAAG,IAAI,EAAE,GAAC,KAAK,IAAI;;;;;;;;;;;;;;;WAYpB,MAAO,IAAI;;;;eACX,MAAO,IAAI;;;;;;;;eAKX,SAAS;;;;aAIT,aAAa;;;;;;;;;sBAEb,CAAC,MAAM,YAAY,GAAC,IAAI,CAAC;;;;;;;;;;kBAOzB,CAAC,EAAE,EAAE,OAAO,KAAK,OAAO;;;;;;;;;;oBAQxB,MAAM;;;;;;;uBAQN,MAAM;;;;;;iBAKN,OAAO;;;;;iBAIP,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,MAAM;;;;;kBAG1C,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,MAAM;;;;;;WAO1C,MAAM,IAAI;;;;UACV,MAAM,IAAI;;;;WACV,MAAM,IAAI;;;;YACV,MAAM,IAAI;;;;;;eACV,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,GAAC,IAAI"}
@@ -0,0 +1,6 @@
1
+ export * from "./protocol/index.js";
2
+ export * from "./capture/index.js";
3
+ export * from "./renderer/index.js";
4
+ export * from "./relay/index.js";
5
+ export * from "./transport/websocket.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Hard per-message size cap enforced by the relay (bytes).
3
+ * Capture-side snapshot truncation budgets derive from this value.
4
+ */
5
+ export const RELAY_PER_MESSAGE_LIMIT_BYTES: 1048576;
6
+ /**
7
+ * Fraction of the relay cap a serialized snapshot may occupy. The remaining
8
+ * headroom absorbs envelope overhead and compression-resistant payloads
9
+ * where LZ does not reduce size.
10
+ */
11
+ export const SNAPSHOT_BUDGET_FRACTION: 0.8;
12
+ /** Snapshot truncation byte budget. */
13
+ export const SNAPSHOT_BUDGET_BYTES: number;
14
+ /**
15
+ * During truncation, subtrees whose live top exceeds this many viewport
16
+ * heights are dropped first (content far below the fold).
17
+ */
18
+ export const TRUNCATION_VIEWPORT_MULTIPLIER: 3;
19
+ /** Scroll side-channel throttle: at most one event per this many ms. */
20
+ export const SCROLL_THROTTLE_MS: 200;
21
+ /** Overlay side-channel throttle: at most one broadcast per this many ms. */
22
+ export const OVERLAY_THROTTLE_MS: 500;
23
+ /**
24
+ * Capture-side watchdog: if mutations are pending and nothing has drained
25
+ * for this long, force a flush and count a stale rescue.
26
+ */
27
+ export const MUTATION_STALE_THRESHOLD_MS: 5000;
28
+ /** Capture-side watchdog tick cadence. */
29
+ export const WATCHDOG_TICK_MS: 500;
30
+ /** Readiness probe: poll interval and total budget. */
31
+ export const READY_PROBE_INTERVAL_MS: 200;
32
+ export const READY_PROBE_BUDGET_MS: 5000;
33
+ /** Inline <style> tags larger than this are skipped during snapshot capture. */
34
+ export const INLINE_STYLE_MAX_BYTES: 500000;
35
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/protocol/constants.js"],"names":[],"mappings":"AAIA;;;GAGG;AACH,4CAA6C,OAAO,CAAC;AAErD;;;;GAIG;AACH,uCAAwC,GAAG,CAAC;AAE5C,uCAAuC;AACvC,2CAEE;AAEF;;;GAGG;AACH,6CAA8C,CAAC,CAAC;AAEhD,wEAAwE;AACxE,iCAAkC,GAAG,CAAC;AAEtC,6EAA6E;AAC7E,kCAAmC,GAAG,CAAC;AAEvC;;;GAGG;AACH,0CAA2C,IAAI,CAAC;AAEhD,0CAA0C;AAC1C,+BAAgC,GAAG,CAAC;AAEpC,uDAAuD;AACvD,sCAAuC,GAAG,CAAC;AAC3C,oCAAqC,IAAI,CAAC;AAE1C,gFAAgF;AAChF,qCAAsC,MAAM,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @typedef {Object} LZCodec
3
+ * @property {(s: string) => string} compressToBase64
4
+ * @property {(s: string) => string|null} decompressFromBase64
5
+ */
6
+ /**
7
+ * Encode a message object for the wire.
8
+ *
9
+ * @param {Object} msg The full message ({ type, payload, ... })
10
+ * @param {LZCodec} lz LZ-string (or compatible) codec
11
+ * @param {number} [thresholdBytes=0] Compress only when the JSON exceeds this size;
12
+ * 0 compresses everything
13
+ * @returns {string} JSON string ready to send
14
+ */
15
+ export function encodeEnvelope(msg: any, lz: LZCodec, thresholdBytes?: number): string;
16
+ /**
17
+ * Decode a wire string into a message object. Detects the compressed
18
+ * envelope by shape; falls through to plain JSON otherwise.
19
+ *
20
+ * @param {string} raw
21
+ * @param {LZCodec} [lz]
22
+ * @returns {{ok: true, msg: Object} | {ok: false, error: string}}
23
+ */
24
+ export function decodeEnvelope(raw: string, lz?: LZCodec): {
25
+ ok: true;
26
+ msg: any;
27
+ } | {
28
+ ok: false;
29
+ error: string;
30
+ };
31
+ /**
32
+ * Is this decoded wire object a compressed envelope (vs. a plain message)?
33
+ * Useful for relay-side diagnostics that classify traffic without decoding.
34
+ * @param {Object} obj
35
+ */
36
+ export function isCompressedEnvelope(obj: any): boolean;
37
+ export type LZCodec = {
38
+ compressToBase64: (s: string) => string;
39
+ decompressFromBase64: (s: string) => string | null;
40
+ };
41
+ //# sourceMappingURL=envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../../src/protocol/envelope.js"],"names":[],"mappings":"AAWA;;;;GAIG;AAEH;;;;;;;;GAQG;AACH,6CALW,OAAO,mBACP,MAAM,GAEJ,MAAM,CASlB;AAED;;;;;;;GAOG;AACH,oCAJW,MAAM,OACN,OAAO,GACL;IAAC,EAAE,EAAE,IAAI,CAAC;IAAC,GAAG,MAAQ;CAAC,GAAG;IAAC,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,CAwBhE;AAED;;;;GAIG;AACH,wDAEC;;sBA7Da,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM;0BACrB,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAAC,IAAI"}
@@ -0,0 +1,5 @@
1
+ export * from "./constants.js";
2
+ export * from "./messages.js";
3
+ export * from "./envelope.js";
4
+ export * from "./remote-control.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/protocol/index.js"],"names":[],"mappings":""}