@limrun/api 0.48.4 → 0.49.1

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 (193) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/build-settings.d.mts.map +1 -1
  3. package/build-settings.d.ts.map +1 -1
  4. package/build-settings.js +4 -5
  5. package/build-settings.js.map +1 -1
  6. package/build-settings.mjs +4 -5
  7. package/build-settings.mjs.map +1 -1
  8. package/client.d.mts +8 -5
  9. package/client.d.mts.map +1 -1
  10. package/client.d.ts +8 -5
  11. package/client.d.ts.map +1 -1
  12. package/client.js +4 -4
  13. package/client.js.map +1 -1
  14. package/client.mjs +2 -2
  15. package/client.mjs.map +1 -1
  16. package/destination-tunnel-dialer.d.mts +30 -2
  17. package/destination-tunnel-dialer.d.mts.map +1 -1
  18. package/destination-tunnel-dialer.d.ts +30 -2
  19. package/destination-tunnel-dialer.d.ts.map +1 -1
  20. package/destination-tunnel-dialer.js +349 -65
  21. package/destination-tunnel-dialer.js.map +1 -1
  22. package/destination-tunnel-dialer.mjs +345 -64
  23. package/destination-tunnel-dialer.mjs.map +1 -1
  24. package/destination-tunnel-har.d.mts +23 -0
  25. package/destination-tunnel-har.d.mts.map +1 -0
  26. package/destination-tunnel-har.d.ts +23 -0
  27. package/destination-tunnel-har.d.ts.map +1 -0
  28. package/destination-tunnel-har.js +164 -0
  29. package/destination-tunnel-har.js.map +1 -0
  30. package/destination-tunnel-har.mjs +160 -0
  31. package/destination-tunnel-har.mjs.map +1 -0
  32. package/destination-tunnel-inspection.d.mts +71 -0
  33. package/destination-tunnel-inspection.d.mts.map +1 -0
  34. package/destination-tunnel-inspection.d.ts +71 -0
  35. package/destination-tunnel-inspection.d.ts.map +1 -0
  36. package/destination-tunnel-inspection.js +267 -0
  37. package/destination-tunnel-inspection.js.map +1 -0
  38. package/destination-tunnel-inspection.mjs +261 -0
  39. package/destination-tunnel-inspection.mjs.map +1 -0
  40. package/destination-tunnel.d.mts +119 -14
  41. package/destination-tunnel.d.mts.map +1 -1
  42. package/destination-tunnel.d.ts +119 -14
  43. package/destination-tunnel.d.ts.map +1 -1
  44. package/destination-tunnel.js +407 -98
  45. package/destination-tunnel.js.map +1 -1
  46. package/destination-tunnel.mjs +374 -73
  47. package/destination-tunnel.mjs.map +1 -1
  48. package/exec-client.d.mts +9 -0
  49. package/exec-client.d.mts.map +1 -1
  50. package/exec-client.d.ts +9 -0
  51. package/exec-client.d.ts.map +1 -1
  52. package/exec-client.js.map +1 -1
  53. package/exec-client.mjs.map +1 -1
  54. package/index.d.mts +8 -1
  55. package/index.d.mts.map +1 -1
  56. package/index.d.ts +8 -1
  57. package/index.d.ts.map +1 -1
  58. package/index.js +26 -2
  59. package/index.js.map +1 -1
  60. package/index.mjs +7 -1
  61. package/index.mjs.map +1 -1
  62. package/instance-client.d.mts +107 -1
  63. package/instance-client.d.mts.map +1 -1
  64. package/instance-client.d.ts +107 -1
  65. package/instance-client.d.ts.map +1 -1
  66. package/instance-client.js +83 -1
  67. package/instance-client.js.map +1 -1
  68. package/instance-client.mjs +83 -1
  69. package/instance-client.mjs.map +1 -1
  70. package/internal/destination-tunnel-management.d.mts +4 -3
  71. package/internal/destination-tunnel-management.d.mts.map +1 -1
  72. package/internal/destination-tunnel-management.d.ts +4 -3
  73. package/internal/destination-tunnel-management.d.ts.map +1 -1
  74. package/internal/destination-tunnel-management.js +64 -46
  75. package/internal/destination-tunnel-management.js.map +1 -1
  76. package/internal/destination-tunnel-management.mjs +55 -37
  77. package/internal/destination-tunnel-management.mjs.map +1 -1
  78. package/internal/destination-tunnel-url.d.mts +2 -0
  79. package/internal/destination-tunnel-url.d.mts.map +1 -1
  80. package/internal/destination-tunnel-url.d.ts +2 -0
  81. package/internal/destination-tunnel-url.d.ts.map +1 -1
  82. package/internal/destination-tunnel-url.js +45 -5
  83. package/internal/destination-tunnel-url.js.map +1 -1
  84. package/internal/destination-tunnel-url.mjs +44 -5
  85. package/internal/destination-tunnel-url.mjs.map +1 -1
  86. package/internal/destination-tunnel-wire-reader.d.mts +23 -0
  87. package/internal/destination-tunnel-wire-reader.d.mts.map +1 -0
  88. package/internal/destination-tunnel-wire-reader.d.ts +23 -0
  89. package/internal/destination-tunnel-wire-reader.d.ts.map +1 -0
  90. package/internal/destination-tunnel-wire-reader.js +110 -0
  91. package/internal/destination-tunnel-wire-reader.js.map +1 -0
  92. package/internal/destination-tunnel-wire-reader.mjs +93 -0
  93. package/internal/destination-tunnel-wire-reader.mjs.map +1 -0
  94. package/internal/persist-option.d.mts +14 -0
  95. package/internal/persist-option.d.mts.map +1 -0
  96. package/internal/persist-option.d.ts +14 -0
  97. package/internal/persist-option.d.ts.map +1 -0
  98. package/internal/persist-option.js +18 -0
  99. package/internal/persist-option.js.map +1 -0
  100. package/internal/persist-option.mjs +15 -0
  101. package/internal/persist-option.mjs.map +1 -0
  102. package/internal/proxy-transport.d.mts +27 -0
  103. package/internal/proxy-transport.d.mts.map +1 -1
  104. package/internal/proxy-transport.d.ts +27 -0
  105. package/internal/proxy-transport.d.ts.map +1 -1
  106. package/internal/proxy-transport.js +206 -0
  107. package/internal/proxy-transport.js.map +1 -1
  108. package/internal/proxy-transport.mjs +205 -0
  109. package/internal/proxy-transport.mjs.map +1 -1
  110. package/internal/session-stream.d.mts +39 -0
  111. package/internal/session-stream.d.mts.map +1 -0
  112. package/internal/session-stream.d.ts +39 -0
  113. package/internal/session-stream.d.ts.map +1 -0
  114. package/internal/session-stream.js +144 -0
  115. package/internal/session-stream.js.map +1 -0
  116. package/internal/session-stream.mjs +139 -0
  117. package/internal/session-stream.mjs.map +1 -0
  118. package/internal/tslib.js +4 -4
  119. package/ios-client.d.mts +63 -4
  120. package/ios-client.d.mts.map +1 -1
  121. package/ios-client.d.ts +63 -4
  122. package/ios-client.d.ts.map +1 -1
  123. package/ios-client.js +48 -2
  124. package/ios-client.js.map +1 -1
  125. package/ios-client.mjs +48 -2
  126. package/ios-client.mjs.map +1 -1
  127. package/package.json +22 -1
  128. package/resources/android-instances-helpers.d.mts +25 -0
  129. package/resources/android-instances-helpers.d.mts.map +1 -0
  130. package/resources/android-instances-helpers.d.ts +25 -0
  131. package/resources/android-instances-helpers.d.ts.map +1 -0
  132. package/resources/android-instances-helpers.js +37 -0
  133. package/resources/android-instances-helpers.js.map +1 -0
  134. package/resources/android-instances-helpers.mjs +33 -0
  135. package/resources/android-instances-helpers.mjs.map +1 -0
  136. package/resources/index.d.mts +6 -3
  137. package/resources/index.d.mts.map +1 -1
  138. package/resources/index.d.ts +6 -3
  139. package/resources/index.d.ts.map +1 -1
  140. package/resources/index.js +6 -5
  141. package/resources/index.js.map +1 -1
  142. package/resources/index.mjs +3 -3
  143. package/resources/index.mjs.map +1 -1
  144. package/resources/ios-instances-helpers.d.mts +25 -0
  145. package/resources/ios-instances-helpers.d.mts.map +1 -0
  146. package/resources/ios-instances-helpers.d.ts +25 -0
  147. package/resources/ios-instances-helpers.d.ts.map +1 -0
  148. package/resources/ios-instances-helpers.js +37 -0
  149. package/resources/ios-instances-helpers.js.map +1 -0
  150. package/resources/ios-instances-helpers.mjs +33 -0
  151. package/resources/ios-instances-helpers.mjs.map +1 -0
  152. package/resources/session-artifacts.d.mts +70 -0
  153. package/resources/session-artifacts.d.mts.map +1 -0
  154. package/resources/session-artifacts.d.ts +70 -0
  155. package/resources/session-artifacts.d.ts.map +1 -0
  156. package/resources/session-artifacts.js +8 -0
  157. package/resources/session-artifacts.js.map +1 -0
  158. package/resources/session-artifacts.mjs +7 -0
  159. package/resources/session-artifacts.mjs.map +1 -0
  160. package/resources/xcode-instances-helpers.d.mts +55 -0
  161. package/resources/xcode-instances-helpers.d.mts.map +1 -1
  162. package/resources/xcode-instances-helpers.d.ts +55 -0
  163. package/resources/xcode-instances-helpers.d.ts.map +1 -1
  164. package/resources/xcode-instances-helpers.js +49 -3
  165. package/resources/xcode-instances-helpers.js.map +1 -1
  166. package/resources/xcode-instances-helpers.mjs +47 -2
  167. package/resources/xcode-instances-helpers.mjs.map +1 -1
  168. package/src/build-settings.ts +4 -5
  169. package/src/client.ts +12 -2
  170. package/src/destination-tunnel-dialer.ts +403 -64
  171. package/src/destination-tunnel-har.ts +200 -0
  172. package/src/destination-tunnel-inspection.ts +367 -0
  173. package/src/destination-tunnel.ts +510 -88
  174. package/src/exec-client.ts +9 -0
  175. package/src/index.ts +58 -0
  176. package/src/instance-client.ts +273 -5
  177. package/src/internal/destination-tunnel-management.ts +67 -43
  178. package/src/internal/destination-tunnel-url.ts +61 -5
  179. package/src/internal/destination-tunnel-wire-reader.ts +109 -0
  180. package/src/internal/persist-option.ts +26 -0
  181. package/src/internal/proxy-transport.ts +248 -0
  182. package/src/internal/session-stream.ts +157 -0
  183. package/src/ios-client.ts +129 -8
  184. package/src/resources/android-instances-helpers.ts +45 -0
  185. package/src/resources/index.ts +14 -2
  186. package/src/resources/ios-instances-helpers.ts +45 -0
  187. package/src/resources/session-artifacts.ts +95 -0
  188. package/src/resources/xcode-instances-helpers.ts +116 -5
  189. package/src/version.ts +1 -1
  190. package/version.d.mts +1 -1
  191. package/version.d.ts +1 -1
  192. package/version.js +1 -1
  193. package/version.mjs +1 -1
@@ -0,0 +1,71 @@
1
+ import type { Entry, Header } from 'har-format';
2
+ export { deriveDestinationTunnelInspectionURL } from "./internal/destination-tunnel-url.js";
3
+ export interface DestinationTunnelInspectionExtension {
4
+ tunnelId: string;
5
+ selectorId: string;
6
+ error?: string;
7
+ requestBodyTruncated?: boolean;
8
+ responseBodyTruncated?: boolean;
9
+ responseTrailers?: Header[];
10
+ responseCookieSameSite?: Array<{
11
+ index: number;
12
+ value: string;
13
+ }>;
14
+ }
15
+ export type DestinationTunnelInspectionComplete = Entry & {
16
+ _limrun: DestinationTunnelInspectionExtension;
17
+ };
18
+ export interface DestinationTunnelInspectionGap {
19
+ fromSequence: number;
20
+ toSequence: number;
21
+ message: string;
22
+ }
23
+ export type DestinationTunnelInspectionMetadataEvent = {
24
+ type: 'complete';
25
+ sequence: number;
26
+ requestId: string;
27
+ data: DestinationTunnelInspectionComplete;
28
+ } | {
29
+ type: 'gap';
30
+ sequence: number;
31
+ data: DestinationTunnelInspectionGap;
32
+ } | {
33
+ type: 'inspection_error';
34
+ sequence: number;
35
+ requestId?: string;
36
+ data: {
37
+ message: string;
38
+ [key: string]: unknown;
39
+ };
40
+ };
41
+ export interface DestinationTunnelInspectionBodyEvent {
42
+ type: 'body';
43
+ sequence: number;
44
+ requestId: string;
45
+ direction: 'request' | 'response';
46
+ body: Uint8Array;
47
+ }
48
+ export type DestinationTunnelInspectionEvent = DestinationTunnelInspectionMetadataEvent | DestinationTunnelInspectionBodyEvent;
49
+ export type DestinationTunnelInspectionEventCallback = (event: DestinationTunnelInspectionEvent) => void;
50
+ export type DestinationTunnelInspectionErrorCallback = (error: Error) => void;
51
+ export interface DestinationTunnelInspectionStreamOptions {
52
+ onEvent?: DestinationTunnelInspectionEventCallback;
53
+ onError?: DestinationTunnelInspectionErrorCallback;
54
+ reconnectInitialDelayMs?: number;
55
+ reconnectMaxDelayMs?: number;
56
+ }
57
+ export interface DestinationTunnelInspectionStream {
58
+ close: () => void;
59
+ }
60
+ /**
61
+ * Follow one tunnel's inspection SSE feed independently from its data
62
+ * WebSocket. Authentication is carried in `?token=` so the same endpoint can
63
+ * be consumed by browser-native EventSource.
64
+ */
65
+ export declare function startDestinationTunnelInspectionStream(remoteURL: string, tunnelId: string, token: string, options?: DestinationTunnelInspectionStreamOptions): DestinationTunnelInspectionStream;
66
+ /**
67
+ * Decode one browser/EventSource message while keeping the public inspection
68
+ * event API independent of SSE transport details.
69
+ */
70
+ export declare function decodeDestinationTunnelInspectionSSEEvent(lastEventId: string | undefined, text: string): DestinationTunnelInspectionEvent;
71
+ //# sourceMappingURL=destination-tunnel-inspection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"destination-tunnel-inspection.d.ts","sourceRoot":"","sources":["src/destination-tunnel-inspection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE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AAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,SAAS,GAAG,UAAU,CAAC;IAClC,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,MAAM,gCAAgC,GACxC,wCAAwC,GACxC,oCAAoC,CAAC;AAEzC,MAAM,MAAM,wCAAwC,GAAG,CAAC,KAAK,EAAE,gCAAgC,KAAK,IAAI,CAAC;AACzG,MAAM,MAAM,wCAAwC,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;AAE9E,MAAM,WAAW,wCAAwC;IACvD,OAAO,CAAC,EAAE,wCAAwC,CAAC;IACnD,OAAO,CAAC,EAAE,wCAAwC,CAAC;IACnD,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,iCAAiC;IAChD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,sCAAsC,CACpD,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,wCAA6C,GACrD,iCAAiC,CAiFnC;AAED;;;GAGG;AACH,wBAAgB,yCAAyC,CACvD,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,IAAI,EAAE,MAAM,GACX,gCAAgC,CAyClC"}
@@ -0,0 +1,267 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deriveDestinationTunnelInspectionURL = void 0;
4
+ exports.startDestinationTunnelInspectionStream = startDestinationTunnelInspectionStream;
5
+ exports.decodeDestinationTunnelInspectionSSEEvent = decodeDestinationTunnelInspectionSSEEvent;
6
+ const eventsource_client_1 = require("eventsource-client");
7
+ const proxy_transport_1 = require("./internal/proxy-transport.js");
8
+ const destination_tunnel_url_1 = require("./internal/destination-tunnel-url.js");
9
+ const destination_tunnel_wire_reader_1 = require("./internal/destination-tunnel-wire-reader.js");
10
+ var destination_tunnel_url_2 = require("./internal/destination-tunnel-url.js");
11
+ Object.defineProperty(exports, "deriveDestinationTunnelInspectionURL", { enumerable: true, get: function () { return destination_tunnel_url_2.deriveDestinationTunnelInspectionURL; } });
12
+ /**
13
+ * Follow one tunnel's inspection SSE feed independently from its data
14
+ * WebSocket. Authentication is carried in `?token=` so the same endpoint can
15
+ * be consumed by browser-native EventSource.
16
+ */
17
+ function startDestinationTunnelInspectionStream(remoteURL, tunnelId, token, options = {}) {
18
+ let active = true;
19
+ let lastSequence = 0;
20
+ const reportError = (error) => {
21
+ invokeSafely(options.onError, error);
22
+ };
23
+ const emitGap = (fromSequence, toSequence) => {
24
+ invokeSafely(options.onEvent, {
25
+ type: 'gap',
26
+ sequence: toSequence,
27
+ data: {
28
+ fromSequence,
29
+ toSequence,
30
+ message: `Inspection stream gap: missing sequences ${fromSequence}-${toSequence}`,
31
+ },
32
+ }, reportError);
33
+ };
34
+ const acceptSequence = (sequence, explicitGap) => {
35
+ if (!Number.isSafeInteger(sequence) || sequence < 0) {
36
+ throw new destination_tunnel_wire_reader_1.DestinationTunnelProtocolError('inspection sequence must be a safe non-negative integer');
37
+ }
38
+ if (sequence <= lastSequence) {
39
+ throw new destination_tunnel_wire_reader_1.DestinationTunnelProtocolError(`inspection sequence ${sequence} is not newer than ${lastSequence}`);
40
+ }
41
+ if (explicitGap) {
42
+ if (explicitGap.fromSequence !== lastSequence + 1 ||
43
+ explicitGap.toSequence !== sequence ||
44
+ explicitGap.fromSequence > explicitGap.toSequence) {
45
+ throw new destination_tunnel_wire_reader_1.DestinationTunnelProtocolError('invalid inspection gap range');
46
+ }
47
+ emitGap(explicitGap.fromSequence, explicitGap.toSequence);
48
+ }
49
+ else if (sequence > lastSequence + 1) {
50
+ emitGap(lastSequence + 1, sequence - 1);
51
+ }
52
+ lastSequence = sequence;
53
+ };
54
+ const url = (0, destination_tunnel_url_1.deriveDestinationTunnelInspectionURL)(remoteURL, tunnelId, lastSequence, token);
55
+ const source = (0, eventsource_client_1.createEventSource)({
56
+ url,
57
+ fetch: proxy_transport_1.nodeProxyTransport.fetch.bind(proxy_transport_1.nodeProxyTransport),
58
+ onMessage: (message) => {
59
+ if (!active)
60
+ return;
61
+ try {
62
+ const event = decodeDestinationTunnelInspectionSSEEvent(message.id, message.data);
63
+ if (event.type === 'gap') {
64
+ acceptSequence(event.sequence, event.data);
65
+ }
66
+ else {
67
+ acceptSequence(event.sequence);
68
+ invokeSafely(options.onEvent, event, reportError);
69
+ }
70
+ }
71
+ catch (error) {
72
+ reportError(error instanceof Error ? error : new Error(String(error)));
73
+ }
74
+ },
75
+ onDisconnect: () => {
76
+ if (active)
77
+ reportError(new Error('Inspection SSE disconnected; reconnecting'));
78
+ },
79
+ });
80
+ const close = () => {
81
+ if (!active)
82
+ return;
83
+ active = false;
84
+ source.close();
85
+ };
86
+ return { close };
87
+ }
88
+ /**
89
+ * Decode one browser/EventSource message while keeping the public inspection
90
+ * event API independent of SSE transport details.
91
+ */
92
+ function decodeDestinationTunnelInspectionSSEEvent(lastEventId, text) {
93
+ if (lastEventId === undefined || !/^(0|[1-9]\d*)$/.test(lastEventId)) {
94
+ throw new destination_tunnel_wire_reader_1.DestinationTunnelProtocolError('inspection SSE event ID must be an unsigned integer');
95
+ }
96
+ const sequence = Number(lastEventId);
97
+ if (!Number.isSafeInteger(sequence)) {
98
+ throw new destination_tunnel_wire_reader_1.DestinationTunnelProtocolError('inspection sequence must be a safe non-negative integer');
99
+ }
100
+ let parsed;
101
+ try {
102
+ parsed = JSON.parse(text);
103
+ }
104
+ catch {
105
+ throw new destination_tunnel_wire_reader_1.DestinationTunnelProtocolError('inspection SSE data must be valid JSON');
106
+ }
107
+ const record = (0, destination_tunnel_wire_reader_1.readRecord)(parsed, 'inspection event');
108
+ if (record['sequence'] !== undefined) {
109
+ const envelopeSequence = (0, destination_tunnel_wire_reader_1.readSafeNonNegativeInteger)(record['sequence'], 'inspection sequence');
110
+ if (envelopeSequence !== sequence) {
111
+ throw new destination_tunnel_wire_reader_1.DestinationTunnelProtocolError('inspection SSE event ID does not match envelope sequence');
112
+ }
113
+ }
114
+ if ((0, destination_tunnel_wire_reader_1.readString)(record, 'type') !== 'body') {
115
+ return decodeDestinationTunnelInspectionMetadataRecord(record, sequence);
116
+ }
117
+ const requestId = readRequiredRequestId(record);
118
+ const data = (0, destination_tunnel_wire_reader_1.readRecord)(record['data'], 'inspection body data');
119
+ const direction = (0, destination_tunnel_wire_reader_1.readString)(data, 'direction');
120
+ if (direction !== 'request' && direction !== 'response') {
121
+ throw new destination_tunnel_wire_reader_1.DestinationTunnelProtocolError('invalid inspection body direction');
122
+ }
123
+ if ((0, destination_tunnel_wire_reader_1.readString)(data, 'encoding') !== 'base64') {
124
+ throw new destination_tunnel_wire_reader_1.DestinationTunnelProtocolError('inspection body encoding must be base64');
125
+ }
126
+ const body = decodeCanonicalBase64((0, destination_tunnel_wire_reader_1.readString)(data, 'chunk'));
127
+ return {
128
+ type: 'body',
129
+ sequence,
130
+ requestId,
131
+ direction,
132
+ body,
133
+ };
134
+ }
135
+ function decodeDestinationTunnelInspectionMetadataRecord(record, sequence) {
136
+ const type = (0, destination_tunnel_wire_reader_1.readString)(record, 'type');
137
+ const data = (0, destination_tunnel_wire_reader_1.readRecord)(record['data'], 'inspection metadata data');
138
+ switch (type) {
139
+ case 'complete':
140
+ return {
141
+ type,
142
+ sequence,
143
+ requestId: readRequiredRequestId(record),
144
+ data: readComplete(data),
145
+ };
146
+ case 'gap': {
147
+ const fromSequence = (0, destination_tunnel_wire_reader_1.readSafeNonNegativeInteger)(data['fromSequence'], 'inspection sequence');
148
+ const toSequence = (0, destination_tunnel_wire_reader_1.readSafeNonNegativeInteger)(data['toSequence'], 'inspection sequence');
149
+ return {
150
+ type,
151
+ sequence,
152
+ data: {
153
+ fromSequence,
154
+ toSequence,
155
+ message: `Inspection stream gap: missing sequences ${fromSequence}-${toSequence}`,
156
+ },
157
+ };
158
+ }
159
+ case 'inspection_error':
160
+ return {
161
+ type,
162
+ sequence,
163
+ ...(record['requestId'] === undefined ? {} : { requestId: readRequiredRequestId(record) }),
164
+ data: { ...data, message: (0, destination_tunnel_wire_reader_1.readString)(data, 'message') },
165
+ };
166
+ default:
167
+ throw new destination_tunnel_wire_reader_1.DestinationTunnelProtocolError(`unknown inspection metadata type ${type}`);
168
+ }
169
+ }
170
+ function readComplete(record) {
171
+ readDateTime(record, 'startedDateTime');
172
+ (0, destination_tunnel_wire_reader_1.readFiniteNumber)(record, 'time');
173
+ readRequest((0, destination_tunnel_wire_reader_1.readRecord)(record['request'], 'inspection request'));
174
+ readResponse((0, destination_tunnel_wire_reader_1.readRecord)(record['response'], 'inspection response'));
175
+ readExtension((0, destination_tunnel_wire_reader_1.readRecord)(record['_limrun'], 'inspection extension'));
176
+ return record;
177
+ }
178
+ function readExtension(record) {
179
+ (0, destination_tunnel_wire_reader_1.readString)(record, 'tunnelId');
180
+ (0, destination_tunnel_wire_reader_1.readString)(record, 'selectorId');
181
+ (0, destination_tunnel_wire_reader_1.readOptionalString)(record, 'error');
182
+ (0, destination_tunnel_wire_reader_1.readOptionalBoolean)(record, 'requestBodyTruncated');
183
+ (0, destination_tunnel_wire_reader_1.readOptionalBoolean)(record, 'responseBodyTruncated');
184
+ if (record['responseTrailers'] !== undefined) {
185
+ readNameValueArray(record['responseTrailers'], 'response trailers');
186
+ }
187
+ if (record['responseCookieSameSite'] !== undefined) {
188
+ for (const item of (0, destination_tunnel_wire_reader_1.readArray)(record, 'responseCookieSameSite')) {
189
+ const sameSite = (0, destination_tunnel_wire_reader_1.readRecord)(item, 'response cookie same-site metadata');
190
+ (0, destination_tunnel_wire_reader_1.readSafeNonNegativeInteger)(sameSite['index'], 'response cookie same-site index');
191
+ (0, destination_tunnel_wire_reader_1.readString)(sameSite, 'value');
192
+ }
193
+ }
194
+ }
195
+ function readRequest(record) {
196
+ (0, destination_tunnel_wire_reader_1.readString)(record, 'method');
197
+ (0, destination_tunnel_wire_reader_1.readString)(record, 'url');
198
+ (0, destination_tunnel_wire_reader_1.readString)(record, 'httpVersion');
199
+ readNameValueArray(record['headers'], 'request headers');
200
+ readNameValueArray(record['queryString'], 'request query string');
201
+ readNameValueArray(record['cookies'], 'request cookies');
202
+ (0, destination_tunnel_wire_reader_1.readFiniteNumber)(record, 'headersSize');
203
+ (0, destination_tunnel_wire_reader_1.readFiniteNumber)(record, 'bodySize');
204
+ if (record['postData'] !== undefined) {
205
+ (0, destination_tunnel_wire_reader_1.readRecord)(record['postData'], 'request post data');
206
+ }
207
+ }
208
+ function readResponse(record) {
209
+ (0, destination_tunnel_wire_reader_1.readFiniteNumber)(record, 'status');
210
+ (0, destination_tunnel_wire_reader_1.readString)(record, 'statusText');
211
+ (0, destination_tunnel_wire_reader_1.readString)(record, 'httpVersion');
212
+ readNameValueArray(record['headers'], 'response headers');
213
+ readNameValueArray(record['cookies'], 'response cookies');
214
+ const content = (0, destination_tunnel_wire_reader_1.readRecord)(record['content'], 'response content');
215
+ (0, destination_tunnel_wire_reader_1.readFiniteNumber)(content, 'size');
216
+ (0, destination_tunnel_wire_reader_1.readString)(content, 'mimeType');
217
+ (0, destination_tunnel_wire_reader_1.readString)(record, 'redirectURL');
218
+ (0, destination_tunnel_wire_reader_1.readFiniteNumber)(record, 'headersSize');
219
+ (0, destination_tunnel_wire_reader_1.readFiniteNumber)(record, 'bodySize');
220
+ }
221
+ function readNameValueArray(value, name) {
222
+ if (!Array.isArray(value)) {
223
+ throw new destination_tunnel_wire_reader_1.DestinationTunnelProtocolError(`${name} must be an array`);
224
+ }
225
+ for (const item of value) {
226
+ const record = (0, destination_tunnel_wire_reader_1.readRecord)(item, name);
227
+ (0, destination_tunnel_wire_reader_1.readString)(record, 'name');
228
+ (0, destination_tunnel_wire_reader_1.readString)(record, 'value');
229
+ }
230
+ }
231
+ function readRequiredRequestId(record) {
232
+ const requestId = (0, destination_tunnel_wire_reader_1.readString)(record, 'requestId');
233
+ if (!requestId)
234
+ throw new destination_tunnel_wire_reader_1.DestinationTunnelProtocolError('inspection request ID must not be empty');
235
+ return requestId;
236
+ }
237
+ function readDateTime(record, key) {
238
+ const value = (0, destination_tunnel_wire_reader_1.readString)(record, key);
239
+ if (!Number.isFinite(Date.parse(value))) {
240
+ throw new destination_tunnel_wire_reader_1.DestinationTunnelProtocolError(`${key} must be an ISO date-time`);
241
+ }
242
+ return value;
243
+ }
244
+ function invokeSafely(callback, value, onFailure) {
245
+ if (!callback)
246
+ return;
247
+ try {
248
+ callback(value);
249
+ }
250
+ catch (error) {
251
+ onFailure?.(error instanceof Error ? error : new Error(String(error)));
252
+ }
253
+ }
254
+ function decodeCanonicalBase64(value) {
255
+ try {
256
+ if (value.length % 4 !== 0)
257
+ throw new Error('invalid base64 length');
258
+ const binary = atob(value);
259
+ if (btoa(binary) !== value)
260
+ throw new Error('non-canonical base64');
261
+ return Uint8Array.from(binary, (character) => character.charCodeAt(0));
262
+ }
263
+ catch {
264
+ throw new destination_tunnel_wire_reader_1.DestinationTunnelProtocolError('inspection body chunk must be valid base64');
265
+ }
266
+ }
267
+ //# sourceMappingURL=destination-tunnel-inspection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"destination-tunnel-inspection.js","sourceRoot":"","sources":["src/destination-tunnel-inspection.ts"],"names":[],"mappings":";;;AAuFA,wFAsFC;AAMD,8FA4CC;AA/ND,2DAA+E;AAE/E,mEAAgE;AAChE,iFAAyF;AACzF,iGASmD;AAEnD,+EAAyF;AAAhF,8IAAA,oCAAoC,OAAA;AAmE7C;;;;GAIG;AACH,SAAgB,sCAAsC,CACpD,SAAiB,EACjB,QAAgB,EAChB,KAAa,EACb,UAAoD,EAAE;IAEtD,IAAI,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,MAAM,WAAW,GAAG,CAAC,KAAY,EAAQ,EAAE;QACzC,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC,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,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACzE,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,+DAA8B,CAAC,4CAA4C,CAAC,CAAC;IACzF,CAAC;AACH,CAAC"}
@@ -0,0 +1,261 @@
1
+ import { createEventSource } from 'eventsource-client';
2
+ import { nodeProxyTransport } from "./internal/proxy-transport.mjs";
3
+ import { deriveDestinationTunnelInspectionURL } from "./internal/destination-tunnel-url.mjs";
4
+ import { DestinationTunnelProtocolError, readArray, readFiniteNumber, readOptionalBoolean, readOptionalString, readRecord, readSafeNonNegativeInteger, readString, } from "./internal/destination-tunnel-wire-reader.mjs";
5
+ export { deriveDestinationTunnelInspectionURL } from "./internal/destination-tunnel-url.mjs";
6
+ /**
7
+ * Follow one tunnel's inspection SSE feed independently from its data
8
+ * WebSocket. Authentication is carried in `?token=` so the same endpoint can
9
+ * be consumed by browser-native EventSource.
10
+ */
11
+ export function startDestinationTunnelInspectionStream(remoteURL, tunnelId, token, options = {}) {
12
+ let active = true;
13
+ let lastSequence = 0;
14
+ const reportError = (error) => {
15
+ invokeSafely(options.onError, error);
16
+ };
17
+ const emitGap = (fromSequence, toSequence) => {
18
+ invokeSafely(options.onEvent, {
19
+ type: 'gap',
20
+ sequence: toSequence,
21
+ data: {
22
+ fromSequence,
23
+ toSequence,
24
+ message: `Inspection stream gap: missing sequences ${fromSequence}-${toSequence}`,
25
+ },
26
+ }, reportError);
27
+ };
28
+ const acceptSequence = (sequence, explicitGap) => {
29
+ if (!Number.isSafeInteger(sequence) || sequence < 0) {
30
+ throw new DestinationTunnelProtocolError('inspection sequence must be a safe non-negative integer');
31
+ }
32
+ if (sequence <= lastSequence) {
33
+ throw new DestinationTunnelProtocolError(`inspection sequence ${sequence} is not newer than ${lastSequence}`);
34
+ }
35
+ if (explicitGap) {
36
+ if (explicitGap.fromSequence !== lastSequence + 1 ||
37
+ explicitGap.toSequence !== sequence ||
38
+ explicitGap.fromSequence > explicitGap.toSequence) {
39
+ throw new DestinationTunnelProtocolError('invalid inspection gap range');
40
+ }
41
+ emitGap(explicitGap.fromSequence, explicitGap.toSequence);
42
+ }
43
+ else if (sequence > lastSequence + 1) {
44
+ emitGap(lastSequence + 1, sequence - 1);
45
+ }
46
+ lastSequence = sequence;
47
+ };
48
+ const url = deriveDestinationTunnelInspectionURL(remoteURL, tunnelId, lastSequence, token);
49
+ const source = createEventSource({
50
+ url,
51
+ fetch: nodeProxyTransport.fetch.bind(nodeProxyTransport),
52
+ onMessage: (message) => {
53
+ if (!active)
54
+ return;
55
+ try {
56
+ const event = decodeDestinationTunnelInspectionSSEEvent(message.id, message.data);
57
+ if (event.type === 'gap') {
58
+ acceptSequence(event.sequence, event.data);
59
+ }
60
+ else {
61
+ acceptSequence(event.sequence);
62
+ invokeSafely(options.onEvent, event, reportError);
63
+ }
64
+ }
65
+ catch (error) {
66
+ reportError(error instanceof Error ? error : new Error(String(error)));
67
+ }
68
+ },
69
+ onDisconnect: () => {
70
+ if (active)
71
+ reportError(new Error('Inspection SSE disconnected; reconnecting'));
72
+ },
73
+ });
74
+ const close = () => {
75
+ if (!active)
76
+ return;
77
+ active = false;
78
+ source.close();
79
+ };
80
+ return { close };
81
+ }
82
+ /**
83
+ * Decode one browser/EventSource message while keeping the public inspection
84
+ * event API independent of SSE transport details.
85
+ */
86
+ export function decodeDestinationTunnelInspectionSSEEvent(lastEventId, text) {
87
+ if (lastEventId === undefined || !/^(0|[1-9]\d*)$/.test(lastEventId)) {
88
+ throw new DestinationTunnelProtocolError('inspection SSE event ID must be an unsigned integer');
89
+ }
90
+ const sequence = Number(lastEventId);
91
+ if (!Number.isSafeInteger(sequence)) {
92
+ throw new DestinationTunnelProtocolError('inspection sequence must be a safe non-negative integer');
93
+ }
94
+ let parsed;
95
+ try {
96
+ parsed = JSON.parse(text);
97
+ }
98
+ catch {
99
+ throw new DestinationTunnelProtocolError('inspection SSE data must be valid JSON');
100
+ }
101
+ const record = readRecord(parsed, 'inspection event');
102
+ if (record['sequence'] !== undefined) {
103
+ const envelopeSequence = readSafeNonNegativeInteger(record['sequence'], 'inspection sequence');
104
+ if (envelopeSequence !== sequence) {
105
+ throw new DestinationTunnelProtocolError('inspection SSE event ID does not match envelope sequence');
106
+ }
107
+ }
108
+ if (readString(record, 'type') !== 'body') {
109
+ return decodeDestinationTunnelInspectionMetadataRecord(record, sequence);
110
+ }
111
+ const requestId = readRequiredRequestId(record);
112
+ const data = readRecord(record['data'], 'inspection body data');
113
+ const direction = readString(data, 'direction');
114
+ if (direction !== 'request' && direction !== 'response') {
115
+ throw new DestinationTunnelProtocolError('invalid inspection body direction');
116
+ }
117
+ if (readString(data, 'encoding') !== 'base64') {
118
+ throw new DestinationTunnelProtocolError('inspection body encoding must be base64');
119
+ }
120
+ const body = decodeCanonicalBase64(readString(data, 'chunk'));
121
+ return {
122
+ type: 'body',
123
+ sequence,
124
+ requestId,
125
+ direction,
126
+ body,
127
+ };
128
+ }
129
+ function decodeDestinationTunnelInspectionMetadataRecord(record, sequence) {
130
+ const type = readString(record, 'type');
131
+ const data = readRecord(record['data'], 'inspection metadata data');
132
+ switch (type) {
133
+ case 'complete':
134
+ return {
135
+ type,
136
+ sequence,
137
+ requestId: readRequiredRequestId(record),
138
+ data: readComplete(data),
139
+ };
140
+ case 'gap': {
141
+ const fromSequence = readSafeNonNegativeInteger(data['fromSequence'], 'inspection sequence');
142
+ const toSequence = readSafeNonNegativeInteger(data['toSequence'], 'inspection sequence');
143
+ return {
144
+ type,
145
+ sequence,
146
+ data: {
147
+ fromSequence,
148
+ toSequence,
149
+ message: `Inspection stream gap: missing sequences ${fromSequence}-${toSequence}`,
150
+ },
151
+ };
152
+ }
153
+ case 'inspection_error':
154
+ return {
155
+ type,
156
+ sequence,
157
+ ...(record['requestId'] === undefined ? {} : { requestId: readRequiredRequestId(record) }),
158
+ data: { ...data, message: readString(data, 'message') },
159
+ };
160
+ default:
161
+ throw new DestinationTunnelProtocolError(`unknown inspection metadata type ${type}`);
162
+ }
163
+ }
164
+ function readComplete(record) {
165
+ readDateTime(record, 'startedDateTime');
166
+ readFiniteNumber(record, 'time');
167
+ readRequest(readRecord(record['request'], 'inspection request'));
168
+ readResponse(readRecord(record['response'], 'inspection response'));
169
+ readExtension(readRecord(record['_limrun'], 'inspection extension'));
170
+ return record;
171
+ }
172
+ function readExtension(record) {
173
+ readString(record, 'tunnelId');
174
+ readString(record, 'selectorId');
175
+ readOptionalString(record, 'error');
176
+ readOptionalBoolean(record, 'requestBodyTruncated');
177
+ readOptionalBoolean(record, 'responseBodyTruncated');
178
+ if (record['responseTrailers'] !== undefined) {
179
+ readNameValueArray(record['responseTrailers'], 'response trailers');
180
+ }
181
+ if (record['responseCookieSameSite'] !== undefined) {
182
+ for (const item of readArray(record, 'responseCookieSameSite')) {
183
+ const sameSite = readRecord(item, 'response cookie same-site metadata');
184
+ readSafeNonNegativeInteger(sameSite['index'], 'response cookie same-site index');
185
+ readString(sameSite, 'value');
186
+ }
187
+ }
188
+ }
189
+ function readRequest(record) {
190
+ readString(record, 'method');
191
+ readString(record, 'url');
192
+ readString(record, 'httpVersion');
193
+ readNameValueArray(record['headers'], 'request headers');
194
+ readNameValueArray(record['queryString'], 'request query string');
195
+ readNameValueArray(record['cookies'], 'request cookies');
196
+ readFiniteNumber(record, 'headersSize');
197
+ readFiniteNumber(record, 'bodySize');
198
+ if (record['postData'] !== undefined) {
199
+ readRecord(record['postData'], 'request post data');
200
+ }
201
+ }
202
+ function readResponse(record) {
203
+ readFiniteNumber(record, 'status');
204
+ readString(record, 'statusText');
205
+ readString(record, 'httpVersion');
206
+ readNameValueArray(record['headers'], 'response headers');
207
+ readNameValueArray(record['cookies'], 'response cookies');
208
+ const content = readRecord(record['content'], 'response content');
209
+ readFiniteNumber(content, 'size');
210
+ readString(content, 'mimeType');
211
+ readString(record, 'redirectURL');
212
+ readFiniteNumber(record, 'headersSize');
213
+ readFiniteNumber(record, 'bodySize');
214
+ }
215
+ function readNameValueArray(value, name) {
216
+ if (!Array.isArray(value)) {
217
+ throw new DestinationTunnelProtocolError(`${name} must be an array`);
218
+ }
219
+ for (const item of value) {
220
+ const record = readRecord(item, name);
221
+ readString(record, 'name');
222
+ readString(record, 'value');
223
+ }
224
+ }
225
+ function readRequiredRequestId(record) {
226
+ const requestId = readString(record, 'requestId');
227
+ if (!requestId)
228
+ throw new DestinationTunnelProtocolError('inspection request ID must not be empty');
229
+ return requestId;
230
+ }
231
+ function readDateTime(record, key) {
232
+ const value = readString(record, key);
233
+ if (!Number.isFinite(Date.parse(value))) {
234
+ throw new DestinationTunnelProtocolError(`${key} must be an ISO date-time`);
235
+ }
236
+ return value;
237
+ }
238
+ function invokeSafely(callback, value, onFailure) {
239
+ if (!callback)
240
+ return;
241
+ try {
242
+ callback(value);
243
+ }
244
+ catch (error) {
245
+ onFailure?.(error instanceof Error ? error : new Error(String(error)));
246
+ }
247
+ }
248
+ function decodeCanonicalBase64(value) {
249
+ try {
250
+ if (value.length % 4 !== 0)
251
+ throw new Error('invalid base64 length');
252
+ const binary = atob(value);
253
+ if (btoa(binary) !== value)
254
+ throw new Error('non-canonical base64');
255
+ return Uint8Array.from(binary, (character) => character.charCodeAt(0));
256
+ }
257
+ catch {
258
+ throw new DestinationTunnelProtocolError('inspection body chunk must be valid base64');
259
+ }
260
+ }
261
+ //# sourceMappingURL=destination-tunnel-inspection.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"destination-tunnel-inspection.mjs","sourceRoot":"","sources":["src/destination-tunnel-inspection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA0B,MAAM,oBAAoB,CAAC;AAE/E,OAAO,EAAE,kBAAkB,EAAE,uCAAmC;AAChE,OAAO,EAAE,oCAAoC,EAAE,8CAA0C;AACzF,OAAO,EACL,8BAA8B,EAC9B,SAAS,EACT,gBAAgB,EAChB,mBAAmB,EACnB,kBAA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