@sgedda/mockifyer-fetch 1.8.87 → 1.8.96
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.
- package/dist/index.js +36 -26
- package/dist/metro-atlas-key-handlers.d.ts +29 -15
- package/dist/metro-atlas-key-handlers.js +59 -23
- package/dist/metro-config.d.ts +2 -2
- package/dist/metro-config.js +2 -2
- package/dist/metro-sync-middleware.d.ts +11 -5
- package/dist/metro-sync-middleware.js +539 -63
- package/package.json +2 -2
- package/src/index.ts +49 -25
- package/src/metro-atlas-key-handlers.ts +76 -30
- package/src/metro-config.ts +2 -2
- package/src/metro-sync-middleware.ts +693 -90
package/dist/index.js
CHANGED
|
@@ -70,15 +70,28 @@ class MockifyerClass {
|
|
|
70
70
|
transport: this.usesDashboardProxy() ? 'proxy' : 'fetch',
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
applyOutboundCorrelation(config) {
|
|
74
|
-
return (0, mockifyer_core_1.applyOutboundRequestCorrelation)(config, (0, mockifyer_core_1.
|
|
73
|
+
async applyOutboundCorrelation(config) {
|
|
74
|
+
return (0, mockifyer_core_1.applyOutboundRequestCorrelation)(config, await (0, mockifyer_core_1.resolveNetworkLogIncludeTraceOptionsAsync)(this.config));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Full outbound URL including `params` — hop logs / Atlas curl / include-trace
|
|
78
|
+
* must not drop the query string (fetch splits search into `config.params`).
|
|
79
|
+
*/
|
|
80
|
+
resolveLoggedRequestUrl(config, fallbackUrl) {
|
|
81
|
+
const raw = (fallbackUrl || config?.url || '').trim();
|
|
82
|
+
if (!raw)
|
|
83
|
+
return '';
|
|
84
|
+
return (0, mockifyer_core_1.appendParamsToUrl)(raw, config?.params);
|
|
75
85
|
}
|
|
76
86
|
/** Best-effort dashboard network log. */
|
|
77
|
-
logNetworkEvent(partial, correlation
|
|
87
|
+
logNetworkEvent(partial, correlation,
|
|
88
|
+
/** Final outbound header bag (after auth interceptors). */
|
|
89
|
+
requestHeadersSource) {
|
|
78
90
|
const scenario = this.config.proxy?.scenario?.trim() ||
|
|
79
91
|
(0, mockifyer_core_1.getCurrentScenario)(this.config.mockDataPath);
|
|
80
92
|
const { requestBody, responseBody, ...eventPartial } = partial;
|
|
81
93
|
const businessResponseBody = (0, mockifyer_core_1.getInlineTraceEnvelopeBusinessBody)(responseBody);
|
|
94
|
+
const requestHeaders = eventPartial.requestHeaders ?? (0, mockifyer_core_1.outboundHeadersToRecord)(requestHeadersSource);
|
|
82
95
|
if (!this.config.proxy?.baseUrl) {
|
|
83
96
|
(0, mockifyer_core_1.recordInlineTraceHopFromExchange)({
|
|
84
97
|
method: eventPartial.method,
|
|
@@ -91,6 +104,7 @@ class MockifyerClass {
|
|
|
91
104
|
durationMs: eventPartial.durationMs,
|
|
92
105
|
clientId: this.config.clientId ?? eventPartial.clientId ?? null,
|
|
93
106
|
errorMessage: eventPartial.errorMessage,
|
|
107
|
+
requestHeaders,
|
|
94
108
|
requestBody,
|
|
95
109
|
responseBody,
|
|
96
110
|
});
|
|
@@ -107,6 +121,7 @@ class MockifyerClass {
|
|
|
107
121
|
transport: eventPartial.transport ?? 'fetch',
|
|
108
122
|
requestId: correlation?.requestId ?? eventPartial.requestId,
|
|
109
123
|
parentRequestId: correlation?.parentRequestId ?? eventPartial.parentRequestId,
|
|
124
|
+
requestHeaders,
|
|
110
125
|
requestBodyPreview: eventPartial.requestBodyPreview,
|
|
111
126
|
responseBodyPreview: eventPartial.responseBodyPreview,
|
|
112
127
|
},
|
|
@@ -619,7 +634,7 @@ class MockifyerClass {
|
|
|
619
634
|
if (!(0, mockifyer_core_1.shouldApplyMockifyer)(this.activationMode, config.headers, {
|
|
620
635
|
useProxyLane: { proxyBaseUrl: this.config.proxy?.baseUrl, resolvedClientId: this.config.clientId },
|
|
621
636
|
})) {
|
|
622
|
-
this.applyOutboundCorrelation(config);
|
|
637
|
+
await this.applyOutboundCorrelation(config);
|
|
623
638
|
config.__mockifyer_bypass = true;
|
|
624
639
|
return config;
|
|
625
640
|
}
|
|
@@ -628,7 +643,7 @@ class MockifyerClass {
|
|
|
628
643
|
config.__mockifyer_bypass = true;
|
|
629
644
|
return config;
|
|
630
645
|
}
|
|
631
|
-
let correlation = this.applyOutboundCorrelation(config);
|
|
646
|
+
let correlation = await this.applyOutboundCorrelation(config);
|
|
632
647
|
this.stashRequestCorrelation(config, correlation);
|
|
633
648
|
// Normalize empty params: treat {} the same as undefined for consistent matching
|
|
634
649
|
const rawParams = config.params || {};
|
|
@@ -678,13 +693,13 @@ class MockifyerClass {
|
|
|
678
693
|
const mockResponseBody = this.prepareStoredResponseBody(mockData, filename, hitScenarioPath);
|
|
679
694
|
this.logNetworkEvent({
|
|
680
695
|
method: (request.method || 'GET').toUpperCase(),
|
|
681
|
-
url: request.url,
|
|
696
|
+
url: this.resolveLoggedRequestUrl(config, request.url),
|
|
682
697
|
source: 'mock-hit',
|
|
683
698
|
status: mockData.response.status,
|
|
684
699
|
requestHash: (0, mockifyer_core_1.networkEventHashFromRequestKey)(requestKey),
|
|
685
700
|
requestBody: request.data,
|
|
686
701
|
responseBody: mockResponseBody,
|
|
687
|
-
}, correlation);
|
|
702
|
+
}, correlation, request.headers ?? config.headers);
|
|
688
703
|
const responseHeaders = {
|
|
689
704
|
...mockData.response.headers,
|
|
690
705
|
'x-mockifyer': 'true',
|
|
@@ -820,7 +835,7 @@ class MockifyerClass {
|
|
|
820
835
|
// be recorded here before early return (otherwise flight recorder stays empty).
|
|
821
836
|
const shouldLogMockOrLimit = isLimitReached || (isMocked && this.usesDashboardProxy());
|
|
822
837
|
if (shouldLogMockOrLimit) {
|
|
823
|
-
const reqUrl = response.config
|
|
838
|
+
const reqUrl = this.resolveLoggedRequestUrl(response.config, url);
|
|
824
839
|
const reqMethod = (response.config?.method || 'GET').toUpperCase();
|
|
825
840
|
const startTime = response.config.__mockifyer_startTime;
|
|
826
841
|
const durationMs = startTime ? Date.now() - startTime : undefined;
|
|
@@ -842,8 +857,11 @@ class MockifyerClass {
|
|
|
842
857
|
: 'Request limit reached',
|
|
843
858
|
}
|
|
844
859
|
: {}),
|
|
845
|
-
}, this.readRequestCorrelation(response.config));
|
|
860
|
+
}, this.readRequestCorrelation(response.config), response.config?.headers);
|
|
846
861
|
}
|
|
862
|
+
// Mock hits return before the upstream path. Still emit nested service
|
|
863
|
+
// hops and strip mockifyerTrace so the caller sees the business body.
|
|
864
|
+
this.unwrapResponseInlineTrace(response);
|
|
847
865
|
return response;
|
|
848
866
|
}
|
|
849
867
|
if (this.config.proxy?.baseUrl && this.config.proxy?.mirrorRecordedMocksToClient) {
|
|
@@ -853,9 +871,9 @@ class MockifyerClass {
|
|
|
853
871
|
if (matchedMock) {
|
|
854
872
|
const startTime = response.config.__mockifyer_startTime;
|
|
855
873
|
const durationMs = startTime ? Date.now() - startTime : undefined;
|
|
856
|
-
const reqUrl = response.config
|
|
874
|
+
const reqUrl = this.resolveLoggedRequestUrl(response.config, url);
|
|
857
875
|
const reqMethod = (response.config?.method || 'GET').toUpperCase();
|
|
858
|
-
// Parent hop first, then unwrap nested
|
|
876
|
+
// Parent hop first, then unwrap nested service hops from downstream services.
|
|
859
877
|
this.logNetworkEvent({
|
|
860
878
|
method: reqMethod,
|
|
861
879
|
url: reqUrl,
|
|
@@ -864,7 +882,7 @@ class MockifyerClass {
|
|
|
864
882
|
durationMs,
|
|
865
883
|
requestBody: response.config?.data,
|
|
866
884
|
responseBody: response.data,
|
|
867
|
-
}, this.readRequestCorrelation(response.config));
|
|
885
|
+
}, this.readRequestCorrelation(response.config), response.config?.headers);
|
|
868
886
|
this.unwrapResponseInlineTrace(response);
|
|
869
887
|
const capturedResponse = {
|
|
870
888
|
status: response.status,
|
|
@@ -886,7 +904,7 @@ class MockifyerClass {
|
|
|
886
904
|
delete response.config.__mockifyer_matchedMock;
|
|
887
905
|
return response;
|
|
888
906
|
}
|
|
889
|
-
const reqUrl = response.config
|
|
907
|
+
const reqUrl = this.resolveLoggedRequestUrl(response.config, url);
|
|
890
908
|
const reqMethod = (response.config?.method || 'GET').toUpperCase();
|
|
891
909
|
this.logNetworkEvent({
|
|
892
910
|
method: reqMethod,
|
|
@@ -898,7 +916,7 @@ class MockifyerClass {
|
|
|
898
916
|
: undefined,
|
|
899
917
|
requestBody: response.config?.data,
|
|
900
918
|
responseBody: response.data,
|
|
901
|
-
}, this.readRequestCorrelation(response.config));
|
|
919
|
+
}, this.readRequestCorrelation(response.config), response.config?.headers);
|
|
902
920
|
this.unwrapResponseInlineTrace(response);
|
|
903
921
|
// Only save locally if recordMode is enabled AND we're not proxying upstream calls.
|
|
904
922
|
// When proxy is configured, recording should happen on the proxy (e.g. dashboard → Redis).
|
|
@@ -911,7 +929,7 @@ class MockifyerClass {
|
|
|
911
929
|
if (requestKey) {
|
|
912
930
|
this.processingRequests.delete(requestKey);
|
|
913
931
|
}
|
|
914
|
-
const reqUrl = error.config
|
|
932
|
+
const reqUrl = this.resolveLoggedRequestUrl(error.config);
|
|
915
933
|
if (reqUrl) {
|
|
916
934
|
this.logNetworkEvent({
|
|
917
935
|
method: (error.config?.method || 'GET').toUpperCase(),
|
|
@@ -921,7 +939,7 @@ class MockifyerClass {
|
|
|
921
939
|
errorMessage: error?.message ?? String(error),
|
|
922
940
|
requestBody: error.config?.data,
|
|
923
941
|
responseBody: error.response?.data,
|
|
924
|
-
}, this.readRequestCorrelation(error.config));
|
|
942
|
+
}, this.readRequestCorrelation(error.config), error.config?.headers);
|
|
925
943
|
}
|
|
926
944
|
this.throwWithMockifyerRequestId(error);
|
|
927
945
|
});
|
|
@@ -1116,6 +1134,7 @@ class MockifyerClass {
|
|
|
1116
1134
|
: this.currentSessionId,
|
|
1117
1135
|
requestId: hopIds.requestId,
|
|
1118
1136
|
parentRequestId: hopIds.parentRequestId,
|
|
1137
|
+
parentRequestIds: hopIds.parentRequestIds,
|
|
1119
1138
|
...((0, mockifyer_core_1.newRecordingUsesAlwaysUseRealApi)() ? { alwaysUseRealApi: true } : {}),
|
|
1120
1139
|
};
|
|
1121
1140
|
(0, mockifyer_core_1.applyRecordingPassthroughFlag)(mockData, saveDecision.alwaysUseRealApi);
|
|
@@ -1168,16 +1187,7 @@ class MockifyerClass {
|
|
|
1168
1187
|
}
|
|
1169
1188
|
async persistMatchedMockAfterLiveCapture(cachedMock, capturedResponse, durationMs, liveCorrelation) {
|
|
1170
1189
|
const updated = (0, mockifyer_core_1.buildMockDataAfterLiveCapture)(cachedMock.mockData, capturedResponse, durationMs);
|
|
1171
|
-
|
|
1172
|
-
if (hopIds.requestId) {
|
|
1173
|
-
updated.requestId = hopIds.requestId;
|
|
1174
|
-
}
|
|
1175
|
-
if (hopIds.parentRequestId) {
|
|
1176
|
-
updated.parentRequestId = hopIds.parentRequestId;
|
|
1177
|
-
}
|
|
1178
|
-
else {
|
|
1179
|
-
delete updated.parentRequestId;
|
|
1180
|
-
}
|
|
1190
|
+
(0, mockifyer_core_1.applyPersistedHopIds)(updated, (0, mockifyer_core_1.resolvePersistedHopIds)(cachedMock.mockData, liveCorrelation));
|
|
1181
1191
|
if (this.databaseProvider) {
|
|
1182
1192
|
await this.databaseProvider.save(updated);
|
|
1183
1193
|
return;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Metro terminal keys for Mockifyer:
|
|
3
|
-
* - `t` (default): start/stop Atlas capture (
|
|
4
|
-
*
|
|
3
|
+
* - `t` (default): start/stop Atlas capture (start opens the live stream page
|
|
4
|
+
* and signals the app to call `enableMockifyer()` for `runtimeMode: 'manual'`;
|
|
5
|
+
* stop ends capture — generate HTML from the live page “Render docs” button)
|
|
6
|
+
* - dashboard key is off unless `dashboardKey` is set (for example `"m"`)
|
|
5
7
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
+
* Capture starts only when `t` is pressed. Opening the live page or connecting
|
|
9
|
+
* the SSE stream does not start it. Press `t` again to stop, or use Render docs
|
|
10
|
+
* on the live page without stopping.
|
|
8
11
|
*
|
|
9
12
|
* `a` is reserved by Metro for Android (`i` iOS, `r` reload, `d` Dev Menu, `j` DevTools).
|
|
10
|
-
* Disable Atlas with `atlasKey: false
|
|
13
|
+
* Disable Atlas with `atlasKey: false`.
|
|
11
14
|
*/
|
|
12
15
|
import * as readline from "readline";
|
|
13
16
|
/** `t` — `a` launches Android in the Metro / RN CLI. */
|
|
@@ -24,8 +27,8 @@ export interface AttachMetroAtlasKeyHandlerOptions {
|
|
|
24
27
|
*/
|
|
25
28
|
atlasKey?: AtlasKeyOption;
|
|
26
29
|
/**
|
|
27
|
-
* Key that opens the dashboard in the browser
|
|
28
|
-
* Pass `false` to
|
|
30
|
+
* Key that opens the dashboard in the browser.
|
|
31
|
+
* Off unless set (for example `"m"`). Pass `false` to keep it off.
|
|
29
32
|
*/
|
|
30
33
|
dashboardKey?: AtlasKeyOption;
|
|
31
34
|
/**
|
|
@@ -33,9 +36,9 @@ export interface AttachMetroAtlasKeyHandlerOptions {
|
|
|
33
36
|
* Mount prefix from `MOCKIFYER_DASHBOARD_BASE` is appended when set.
|
|
34
37
|
*/
|
|
35
38
|
dashboardUrl?: string;
|
|
36
|
-
/** Called
|
|
37
|
-
onSessionStart?: () => void;
|
|
38
|
-
/** Called on session stop —
|
|
39
|
+
/** Called when capture starts. Only the Atlas key (`t`) starts a session. */
|
|
40
|
+
onSessionStart?: (reason: MetroAtlasSessionStartReason) => void;
|
|
41
|
+
/** Called on session stop — end capture (HTML is rendered from the live page). */
|
|
39
42
|
onSessionStop?: () => void | Promise<void>;
|
|
40
43
|
/** Override stdin (tests). */
|
|
41
44
|
stdin?: NodeJS.ReadStream;
|
|
@@ -51,6 +54,8 @@ export interface AttachedMetroAtlasKeyHandler {
|
|
|
51
54
|
dashboardKey: string | null;
|
|
52
55
|
/** Resolved dashboard browse URL. */
|
|
53
56
|
dashboardUrl: string | null;
|
|
57
|
+
/** Live Atlas stream page opened when capture starts via the Atlas key. */
|
|
58
|
+
liveUrl: string | null;
|
|
54
59
|
/** Detach listener and clear module attach flag. */
|
|
55
60
|
detach: () => void;
|
|
56
61
|
}
|
|
@@ -63,7 +68,8 @@ export declare function resolveKeyOption(value: AtlasKeyOption | undefined, defa
|
|
|
63
68
|
*/
|
|
64
69
|
export declare function resolveAtlasKeyOption(atlasKey?: AtlasKeyOption): string | null;
|
|
65
70
|
/**
|
|
66
|
-
* Normalize `dashboardKey
|
|
71
|
+
* Normalize `dashboardKey`. Omitted or `false` → disabled.
|
|
72
|
+
* An explicit letter (for example `"m"`) opens the dashboard.
|
|
67
73
|
*/
|
|
68
74
|
export declare function resolveDashboardKeyOption(dashboardKey?: AtlasKeyOption): string | null;
|
|
69
75
|
/**
|
|
@@ -72,6 +78,11 @@ export declare function resolveDashboardKeyOption(dashboardKey?: AtlasKeyOption)
|
|
|
72
78
|
* then append `MOCKIFYER_DASHBOARD_BASE` when set.
|
|
73
79
|
*/
|
|
74
80
|
export declare function resolveMetroDashboardUrl(explicit?: string): string;
|
|
81
|
+
/**
|
|
82
|
+
* Browser URL for the Metro live Atlas hop stream page.
|
|
83
|
+
* Uses `MOCKIFYER_METRO_URL` when set, otherwise `http://localhost:<METRO_PORT|8081>`.
|
|
84
|
+
*/
|
|
85
|
+
export declare function resolveMetroAtlasLiveUrl(explicitBase?: string): string;
|
|
75
86
|
/**
|
|
76
87
|
* Open a URL with the OS default handler (browser / file).
|
|
77
88
|
*/
|
|
@@ -89,19 +100,22 @@ export declare function getMetroAtlasStreamSubscriberCount(): number;
|
|
|
89
100
|
* @returns true if a new session was started
|
|
90
101
|
*/
|
|
91
102
|
export declare function startMetroAtlasSession(reason?: MetroAtlasSessionStartReason): boolean;
|
|
103
|
+
/** Open the live hop stream page in the browser (Atlas key start). */
|
|
104
|
+
export declare function openMetroAtlasLivePage(): boolean;
|
|
92
105
|
/**
|
|
93
|
-
* Stop capture
|
|
94
|
-
* @returns true if stop
|
|
106
|
+
* Stop capture when capturing (does not write Atlas HTML — use live page Render docs).
|
|
107
|
+
* @returns true if stop was kicked off
|
|
95
108
|
*/
|
|
96
109
|
export declare function stopMetroAtlasSession(): boolean;
|
|
97
110
|
/** Open the dashboard URL when the dashboard key is enabled. */
|
|
98
111
|
export declare function openMetroDashboard(): boolean;
|
|
99
112
|
/**
|
|
100
|
-
*
|
|
113
|
+
* SSE client connected to `/mockifyer-network-events/stream`.
|
|
114
|
+
* Does not start capture — that happens only when the Atlas key (`t`) is pressed.
|
|
101
115
|
*/
|
|
102
116
|
export declare function notifyMetroAtlasStreamClientConnected(): void;
|
|
103
117
|
/**
|
|
104
|
-
* SSE client disconnected — capture stays open until
|
|
118
|
+
* SSE client disconnected — capture stays open until the Atlas key is pressed again.
|
|
105
119
|
*/
|
|
106
120
|
export declare function notifyMetroAtlasStreamClientDisconnected(): void;
|
|
107
121
|
/**
|
|
@@ -38,11 +38,13 @@ exports.resolveKeyOption = resolveKeyOption;
|
|
|
38
38
|
exports.resolveAtlasKeyOption = resolveAtlasKeyOption;
|
|
39
39
|
exports.resolveDashboardKeyOption = resolveDashboardKeyOption;
|
|
40
40
|
exports.resolveMetroDashboardUrl = resolveMetroDashboardUrl;
|
|
41
|
+
exports.resolveMetroAtlasLiveUrl = resolveMetroAtlasLiveUrl;
|
|
41
42
|
exports.openMetroBrowseUrl = openMetroBrowseUrl;
|
|
42
43
|
exports.matchesAtlasKey = matchesAtlasKey;
|
|
43
44
|
exports.getMetroAtlasSessionPhase = getMetroAtlasSessionPhase;
|
|
44
45
|
exports.getMetroAtlasStreamSubscriberCount = getMetroAtlasStreamSubscriberCount;
|
|
45
46
|
exports.startMetroAtlasSession = startMetroAtlasSession;
|
|
47
|
+
exports.openMetroAtlasLivePage = openMetroAtlasLivePage;
|
|
46
48
|
exports.stopMetroAtlasSession = stopMetroAtlasSession;
|
|
47
49
|
exports.openMetroDashboard = openMetroDashboard;
|
|
48
50
|
exports.notifyMetroAtlasStreamClientConnected = notifyMetroAtlasStreamClientConnected;
|
|
@@ -51,14 +53,17 @@ exports.detachMetroAtlasKeyHandler = detachMetroAtlasKeyHandler;
|
|
|
51
53
|
exports.attachMetroAtlasKeyHandler = attachMetroAtlasKeyHandler;
|
|
52
54
|
/**
|
|
53
55
|
* Metro terminal keys for Mockifyer:
|
|
54
|
-
* - `t` (default): start/stop Atlas capture (
|
|
55
|
-
*
|
|
56
|
+
* - `t` (default): start/stop Atlas capture (start opens the live stream page
|
|
57
|
+
* and signals the app to call `enableMockifyer()` for `runtimeMode: 'manual'`;
|
|
58
|
+
* stop ends capture — generate HTML from the live page “Render docs” button)
|
|
59
|
+
* - dashboard key is off unless `dashboardKey` is set (for example `"m"`)
|
|
56
60
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
61
|
+
* Capture starts only when `t` is pressed. Opening the live page or connecting
|
|
62
|
+
* the SSE stream does not start it. Press `t` again to stop, or use Render docs
|
|
63
|
+
* on the live page without stopping.
|
|
59
64
|
*
|
|
60
65
|
* `a` is reserved by Metro for Android (`i` iOS, `r` reload, `d` Dev Menu, `j` DevTools).
|
|
61
|
-
* Disable Atlas with `atlasKey: false
|
|
66
|
+
* Disable Atlas with `atlasKey: false`.
|
|
62
67
|
*/
|
|
63
68
|
const readline = __importStar(require("readline"));
|
|
64
69
|
const child_process_1 = require("child_process");
|
|
@@ -108,9 +113,12 @@ function resolveAtlasKeyOption(atlasKey) {
|
|
|
108
113
|
return resolveKeyOption(atlasKey, exports.DEFAULT_METRO_ATLAS_KEY);
|
|
109
114
|
}
|
|
110
115
|
/**
|
|
111
|
-
* Normalize `dashboardKey
|
|
116
|
+
* Normalize `dashboardKey`. Omitted or `false` → disabled.
|
|
117
|
+
* An explicit letter (for example `"m"`) opens the dashboard.
|
|
112
118
|
*/
|
|
113
119
|
function resolveDashboardKeyOption(dashboardKey) {
|
|
120
|
+
if (dashboardKey === undefined || dashboardKey === false)
|
|
121
|
+
return null;
|
|
114
122
|
return resolveKeyOption(dashboardKey, exports.DEFAULT_METRO_DASHBOARD_KEY);
|
|
115
123
|
}
|
|
116
124
|
/**
|
|
@@ -134,6 +142,16 @@ function resolveMetroDashboardUrl(explicit) {
|
|
|
134
142
|
return base;
|
|
135
143
|
return `${base}${mount.startsWith("/") ? mount : `/${mount}`}`;
|
|
136
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Browser URL for the Metro live Atlas hop stream page.
|
|
147
|
+
* Uses `MOCKIFYER_METRO_URL` when set, otherwise `http://localhost:<METRO_PORT|8081>`.
|
|
148
|
+
*/
|
|
149
|
+
function resolveMetroAtlasLiveUrl(explicitBase) {
|
|
150
|
+
const fromExplicit = typeof explicitBase === "string" ? explicitBase.trim() : "";
|
|
151
|
+
const fromEnv = typeof process !== "undefined" ? process.env.MOCKIFYER_METRO_URL?.trim() : "";
|
|
152
|
+
const base = (fromExplicit || fromEnv || `http://localhost:${(0, mockifyer_core_1.resolveMetroNetworkStreamPort)()}`).replace(/\/+$/, "");
|
|
153
|
+
return `${base}${mockifyer_core_1.ATLAS_LIVE_STREAM_PATH}`;
|
|
154
|
+
}
|
|
137
155
|
/**
|
|
138
156
|
* Open a URL with the OS default handler (browser / file).
|
|
139
157
|
*/
|
|
@@ -200,7 +218,7 @@ function startMetroAtlasSession(reason = "key") {
|
|
|
200
218
|
sessionPhase = "capturing";
|
|
201
219
|
sessionStartedAt = Date.now();
|
|
202
220
|
try {
|
|
203
|
-
onSessionStart();
|
|
221
|
+
onSessionStart(reason);
|
|
204
222
|
}
|
|
205
223
|
catch (err) {
|
|
206
224
|
sessionPhase = "idle";
|
|
@@ -210,16 +228,34 @@ function startMetroAtlasSession(reason = "key") {
|
|
|
210
228
|
return false;
|
|
211
229
|
}
|
|
212
230
|
if (reason === "stream") {
|
|
213
|
-
console.log(`[Mockifyer] Atlas capture started (stream connected) —
|
|
231
|
+
console.log(`[Mockifyer] Atlas capture started (stream connected) — Mockifyer activated (turns off again on stop if it was off). Press ${key} to stop, or Render docs on the live page.`);
|
|
214
232
|
}
|
|
215
233
|
else {
|
|
216
|
-
console.log(`[Mockifyer] Atlas capture started —
|
|
234
|
+
console.log(`[Mockifyer] Atlas capture started — Mockifyer activated (turns off again on stop if it was off). Press ${key} again to stop, or Render docs on the live page.`);
|
|
235
|
+
openMetroAtlasLivePage();
|
|
236
|
+
}
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
/** Open the live hop stream page in the browser (Atlas key start). */
|
|
240
|
+
function openMetroAtlasLivePage() {
|
|
241
|
+
const url = sessionCallbacks?.liveUrl;
|
|
242
|
+
if (!url || !sessionCallbacks?.openUrl) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
console.log(`[Mockifyer] Opening Atlas live stream → ${url}`);
|
|
246
|
+
try {
|
|
247
|
+
sessionCallbacks.openUrl(url);
|
|
248
|
+
}
|
|
249
|
+
catch (err) {
|
|
250
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
251
|
+
console.error(`[Mockifyer] Could not open Atlas live stream: ${message}`);
|
|
252
|
+
return false;
|
|
217
253
|
}
|
|
218
254
|
return true;
|
|
219
255
|
}
|
|
220
256
|
/**
|
|
221
|
-
* Stop capture
|
|
222
|
-
* @returns true if stop
|
|
257
|
+
* Stop capture when capturing (does not write Atlas HTML — use live page Render docs).
|
|
258
|
+
* @returns true if stop was kicked off
|
|
223
259
|
*/
|
|
224
260
|
function stopMetroAtlasSession() {
|
|
225
261
|
if (!sessionCallbacks?.onSessionStop)
|
|
@@ -230,12 +266,12 @@ function stopMetroAtlasSession() {
|
|
|
230
266
|
const startedAt = sessionStartedAt ?? Date.now();
|
|
231
267
|
const duration = formatSessionDuration(startedAt);
|
|
232
268
|
sessionPhase = "rendering";
|
|
233
|
-
console.log(`[Mockifyer] Atlas capture stopped (${duration}) —
|
|
269
|
+
console.log(`[Mockifyer] Atlas capture stopped (${duration}) — Mockifyer turns off again if it was off before press t.`);
|
|
234
270
|
Promise.resolve()
|
|
235
271
|
.then(() => onSessionStop())
|
|
236
272
|
.catch((err) => {
|
|
237
273
|
const message = err instanceof Error ? err.message : String(err);
|
|
238
|
-
console.error(`[Mockifyer] Atlas
|
|
274
|
+
console.error(`[Mockifyer] Atlas session stop failed: ${message}`);
|
|
239
275
|
})
|
|
240
276
|
.finally(() => {
|
|
241
277
|
sessionPhase = "idle";
|
|
@@ -261,16 +297,14 @@ function openMetroDashboard() {
|
|
|
261
297
|
return true;
|
|
262
298
|
}
|
|
263
299
|
/**
|
|
264
|
-
*
|
|
300
|
+
* SSE client connected to `/mockifyer-network-events/stream`.
|
|
301
|
+
* Does not start capture — that happens only when the Atlas key (`t`) is pressed.
|
|
265
302
|
*/
|
|
266
303
|
function notifyMetroAtlasStreamClientConnected() {
|
|
267
304
|
streamSubscriberCount += 1;
|
|
268
|
-
if (streamSubscriberCount === 1) {
|
|
269
|
-
startMetroAtlasSession("stream");
|
|
270
|
-
}
|
|
271
305
|
}
|
|
272
306
|
/**
|
|
273
|
-
* SSE client disconnected — capture stays open until
|
|
307
|
+
* SSE client disconnected — capture stays open until the Atlas key is pressed again.
|
|
274
308
|
*/
|
|
275
309
|
function notifyMetroAtlasStreamClientDisconnected() {
|
|
276
310
|
streamSubscriberCount = Math.max(0, streamSubscriberCount - 1);
|
|
@@ -327,6 +361,7 @@ function attachMetroAtlasKeyHandler(options) {
|
|
|
327
361
|
key: null,
|
|
328
362
|
dashboardKey: null,
|
|
329
363
|
dashboardUrl: null,
|
|
364
|
+
liveUrl: null,
|
|
330
365
|
detach: () => undefined,
|
|
331
366
|
};
|
|
332
367
|
}
|
|
@@ -340,10 +375,12 @@ function attachMetroAtlasKeyHandler(options) {
|
|
|
340
375
|
mockifyer_core_1.logger.warn(`[Mockifyer] atlasKey and dashboardKey are both "${atlasKey}" — dashboard key ignored`);
|
|
341
376
|
}
|
|
342
377
|
const effectiveDashboardKey = atlasKey != null && dashboardKey === atlasKey ? null : dashboardKey;
|
|
378
|
+
const liveUrl = atlasKey != null ? resolveMetroAtlasLiveUrl() : null;
|
|
343
379
|
sessionCallbacks = {
|
|
344
380
|
key: atlasKey,
|
|
345
381
|
dashboardKey: effectiveDashboardKey,
|
|
346
382
|
dashboardUrl: effectiveDashboardKey != null ? dashboardUrl : null,
|
|
383
|
+
liveUrl,
|
|
347
384
|
onSessionStart: options.onSessionStart,
|
|
348
385
|
onSessionStop: options.onSessionStop,
|
|
349
386
|
openUrl: options.openUrl ?? openMetroBrowseUrl,
|
|
@@ -353,6 +390,7 @@ function attachMetroAtlasKeyHandler(options) {
|
|
|
353
390
|
key: atlasKey,
|
|
354
391
|
dashboardKey: effectiveDashboardKey,
|
|
355
392
|
dashboardUrl: sessionCallbacks.dashboardUrl,
|
|
393
|
+
liveUrl,
|
|
356
394
|
detach: detachMetroAtlasKeyHandler,
|
|
357
395
|
};
|
|
358
396
|
}
|
|
@@ -380,7 +418,7 @@ function attachMetroAtlasKeyHandler(options) {
|
|
|
380
418
|
if (!atlasKey || !matchesAtlasKey(str, keyObj, atlasKey))
|
|
381
419
|
return;
|
|
382
420
|
if (sessionPhase === "rendering") {
|
|
383
|
-
console.log("[Mockifyer] Atlas
|
|
421
|
+
console.log("[Mockifyer] Atlas stop already in progress…");
|
|
384
422
|
return;
|
|
385
423
|
}
|
|
386
424
|
if (sessionPhase === "idle") {
|
|
@@ -416,10 +454,7 @@ function attachMetroAtlasKeyHandler(options) {
|
|
|
416
454
|
attached = true;
|
|
417
455
|
const parts = [];
|
|
418
456
|
if (atlasKey) {
|
|
419
|
-
parts.push(`Press ${atlasKey} to start/stop Atlas capture (
|
|
420
|
-
}
|
|
421
|
-
if (effectiveDashboardKey && dashboardUrl) {
|
|
422
|
-
parts.push(`Press ${effectiveDashboardKey} to open dashboard (${dashboardUrl})`);
|
|
457
|
+
parts.push(`Press ${atlasKey} to start/stop Atlas capture (activates Mockifyer if off, restores off on stop; start opens live stream; Render docs on the page writes HTML)`);
|
|
423
458
|
}
|
|
424
459
|
if (parts.length > 0) {
|
|
425
460
|
console.log(`[Mockifyer] info ${parts.join(". ")}.`);
|
|
@@ -443,6 +478,7 @@ function attachMetroAtlasKeyHandler(options) {
|
|
|
443
478
|
key: atlasKey,
|
|
444
479
|
dashboardKey: effectiveDashboardKey,
|
|
445
480
|
dashboardUrl: sessionCallbacks.dashboardUrl,
|
|
481
|
+
liveUrl,
|
|
446
482
|
detach: detachMetroAtlasKeyHandler,
|
|
447
483
|
};
|
|
448
484
|
}
|
package/dist/metro-config.d.ts
CHANGED
|
@@ -108,8 +108,8 @@ export interface ConfigureMetroOptions {
|
|
|
108
108
|
* syncMiddleware: {
|
|
109
109
|
* projectRoot: __dirname,
|
|
110
110
|
* mockDataPath: './mock-data',
|
|
111
|
-
* // atlasKey: 't' (default) — Metro terminal: start/stop Atlas
|
|
112
|
-
* // dashboardKey: 'm'
|
|
111
|
+
* // atlasKey: 't' (default) — Metro terminal: start/stop Atlas (start opens live stream; stop → HTML). `a` is Android.
|
|
112
|
+
* // dashboardKey: 'm' — optional; off unless set. Opens the dashboard in the browser
|
|
113
113
|
* // dashboardUrl: 'http://localhost:3002' — or MOCKIFYER_DASHBOARD_URL
|
|
114
114
|
* },
|
|
115
115
|
* });
|
package/dist/metro-config.js
CHANGED
|
@@ -127,8 +127,8 @@ function resolveMockifyerCoreReactNativeEntry(moduleName, platform) {
|
|
|
127
127
|
* syncMiddleware: {
|
|
128
128
|
* projectRoot: __dirname,
|
|
129
129
|
* mockDataPath: './mock-data',
|
|
130
|
-
* // atlasKey: 't' (default) — Metro terminal: start/stop Atlas
|
|
131
|
-
* // dashboardKey: 'm'
|
|
130
|
+
* // atlasKey: 't' (default) — Metro terminal: start/stop Atlas (start opens live stream; stop → HTML). `a` is Android.
|
|
131
|
+
* // dashboardKey: 'm' — optional; off unless set. Opens the dashboard in the browser
|
|
132
132
|
* // dashboardUrl: 'http://localhost:3002' — or MOCKIFYER_DASHBOARD_URL
|
|
133
133
|
* },
|
|
134
134
|
* });
|
|
@@ -19,8 +19,12 @@
|
|
|
19
19
|
* 15. POST /mockifyer-network-events/snapshot — write hops JSON/NDJSON under atlas-html/
|
|
20
20
|
* 16. POST /mockifyer-network-events/render — render Atlas HTML from buffer hops
|
|
21
21
|
* 17. POST /mockifyer-network-events/clear — clear ring buffer
|
|
22
|
-
* 18.
|
|
23
|
-
* 19.
|
|
22
|
+
* 18. GET /mockifyer-atlas-live — live hop stream web page (SSE + expand/collapse)
|
|
23
|
+
* 19. GET /mockifyer-atlas-trace?id= — re-call a hop with X-Mockifyer-Include-Trace (`&format=html` opens a result tab)
|
|
24
|
+
* 20. GET /mockifyer-atlas-capture — Atlas `t` capture session (`active` plus `activateMockifyer` for the app)
|
|
25
|
+
* 21. Metro terminal key `t` — start/stop Atlas capture (start opens live stream and signals enableMockifyer; stop ends capture; Render docs on the live page writes HTML; capture does not start until `t`; `atlasKey: false` to disable). `a` is reserved for Android.
|
|
26
|
+
* 22. Optional Metro `dashboardKey` — open the dashboard in the browser (off unless set)
|
|
27
|
+
* 23. On hop ingest / Atlas render — pull nested hops from dashboard `/api/network-events/trace` (remote BFF → dashboard → Atlas)
|
|
24
28
|
*
|
|
25
29
|
* The Hybrid Provider (recommended) uses POST /mockifyer-save for instant file sync.
|
|
26
30
|
* Legacy polling-based sync is still available for backward compatibility.
|
|
@@ -35,13 +39,15 @@ export interface MetroSyncMiddlewareOptions {
|
|
|
35
39
|
mockDataPath?: string;
|
|
36
40
|
/**
|
|
37
41
|
* Metro terminal key that starts/stops Atlas capture (default `"t"`).
|
|
38
|
-
* Start clears the hop buffer
|
|
42
|
+
* Start clears the hop buffer and signals the app to enable Mockifyer; stop ends
|
|
43
|
+
* capture. Write HTML via live page “Render docs” (`POST /mockifyer-network-events/render`)
|
|
44
|
+
* or the CLI.
|
|
39
45
|
* Pass `false` to disable. `a` is reserved by Metro for Android.
|
|
40
46
|
*/
|
|
41
47
|
atlasKey?: AtlasKeyOption;
|
|
42
48
|
/**
|
|
43
|
-
* Metro terminal key that opens the dashboard in the browser
|
|
44
|
-
*
|
|
49
|
+
* Metro terminal key that opens the dashboard in the browser.
|
|
50
|
+
* Off unless set (for example `"m"`).
|
|
45
51
|
*/
|
|
46
52
|
dashboardKey?: AtlasKeyOption;
|
|
47
53
|
/**
|