@sgedda/mockifyer-fetch 1.8.96 → 1.8.98

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 CHANGED
@@ -631,10 +631,7 @@ class MockifyerClass {
631
631
  config.__mockifyer_bypass = true;
632
632
  return config;
633
633
  }
634
- if (!(0, mockifyer_core_1.shouldApplyMockifyer)(this.activationMode, config.headers, {
635
- useProxyLane: { proxyBaseUrl: this.config.proxy?.baseUrl, resolvedClientId: this.config.clientId },
636
- })) {
637
- await this.applyOutboundCorrelation(config);
634
+ if (!(0, mockifyer_core_1.shouldApplyMockifyer)(this.activationMode, config.headers)) {
638
635
  config.__mockifyer_bypass = true;
639
636
  return config;
640
637
  }
@@ -53,12 +53,18 @@ export interface MetroConfig {
53
53
  } | null | undefined;
54
54
  extraNodeModules?: Record<string, string>;
55
55
  nodeModulesPaths?: string[];
56
+ blockList?: RegExp | RegExp[];
56
57
  };
57
58
  watchFolders?: string[];
58
59
  transformer?: any;
59
60
  server?: any;
60
61
  [key: string]: any;
61
62
  }
63
+ /**
64
+ * Regex for `<projectRoot>/<mockDataPath>/atlas-html/…`. Atlas renders and snapshots
65
+ * write there; without the block every write makes Metro send a fast-refresh update.
66
+ */
67
+ export declare function atlasHtmlBlockListPattern(projectRoot: string, mockDataPath: string): RegExp;
62
68
  /**
63
69
  * Options for configuring Metro for Mockifyer
64
70
  */
@@ -46,6 +46,7 @@
46
46
  * ```
47
47
  */
48
48
  Object.defineProperty(exports, "__esModule", { value: true });
49
+ exports.atlasHtmlBlockListPattern = atlasHtmlBlockListPattern;
49
50
  exports.configureMetroForMockifyer = configureMetroForMockifyer;
50
51
  const mockifyer_core_1 = require("@sgedda/mockifyer-core");
51
52
  /**
@@ -96,6 +97,27 @@ function resolveMockifyerCoreReactNativeEntry(moduleName, platform) {
96
97
  return null;
97
98
  }
98
99
  }
100
+ const ATLAS_HTML_DIR_NAME = 'atlas-html';
101
+ const DEFAULT_MOCK_DATA_PATH = 'mock-data';
102
+ function escapeRegExp(value) {
103
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
104
+ }
105
+ /**
106
+ * Regex for `<projectRoot>/<mockDataPath>/atlas-html/…`. Atlas renders and snapshots
107
+ * write there; without the block every write makes Metro send a fast-refresh update.
108
+ */
109
+ function atlasHtmlBlockListPattern(projectRoot, mockDataPath) {
110
+ const path = require('path');
111
+ const dir = path.resolve(projectRoot, mockDataPath, ATLAS_HTML_DIR_NAME);
112
+ const separators = '[\\\\/]';
113
+ const body = dir.split(/[\\/]+/).map(escapeRegExp).join(separators);
114
+ return new RegExp(`^${body}${separators}.*$`);
115
+ }
116
+ function appendBlockList(existing, pattern) {
117
+ if (!existing)
118
+ return [pattern];
119
+ return [...(Array.isArray(existing) ? existing : [existing]), pattern];
120
+ }
99
121
  /**
100
122
  * Configure Metro bundler for Mockifyer
101
123
  *
@@ -212,7 +234,7 @@ function configureMetroForMockifyer(config, options) {
212
234
  const { createMockSyncMiddleware } = require('./metro-sync-middleware');
213
235
  const syncMiddleware = createMockSyncMiddleware({
214
236
  projectRoot: options.syncMiddleware.projectRoot || process.cwd(),
215
- mockDataPath: options.syncMiddleware.mockDataPath || 'mock-data',
237
+ mockDataPath: options.syncMiddleware.mockDataPath || DEFAULT_MOCK_DATA_PATH,
216
238
  testGeneration: options.syncMiddleware.testGeneration,
217
239
  atlasKey: options.syncMiddleware.atlasKey,
218
240
  dashboardKey: options.syncMiddleware.dashboardKey,
@@ -253,7 +275,7 @@ function configureMetroForMockifyer(config, options) {
253
275
  const { startAutoSync } = require('./metro-sync-middleware');
254
276
  const intervalMs = options.autoSync.intervalMs || 5000;
255
277
  const projectRoot = options.autoSync.projectRoot || process.cwd();
256
- const mockDataPath = options.autoSync.mockDataPath || 'mock-data';
278
+ const mockDataPath = options.autoSync.mockDataPath || DEFAULT_MOCK_DATA_PATH;
257
279
  startAutoSync(intervalMs, {
258
280
  projectRoot,
259
281
  mockDataPath,
@@ -264,11 +286,16 @@ function configureMetroForMockifyer(config, options) {
264
286
  mockifyer_core_1.logger.warn('[Metro] Could not set up Mockifyer auto-sync:', e);
265
287
  }
266
288
  }
289
+ const syncOptions = options?.syncMiddleware;
290
+ const blockList = syncOptions
291
+ ? appendBlockList(existingResolver.blockList, atlasHtmlBlockListPattern(syncOptions.projectRoot || process.cwd(), syncOptions.mockDataPath || DEFAULT_MOCK_DATA_PATH))
292
+ : existingResolver.blockList;
267
293
  // Merge config with new resolver
268
294
  return {
269
295
  ...config,
270
296
  resolver: {
271
297
  ...existingResolver,
298
+ ...(blockList ? { blockList } : {}),
272
299
  resolveRequest: newResolveRequest,
273
300
  },
274
301
  };
@@ -12,7 +12,7 @@
12
12
  * 8. GET /atlas-html[/…] (legacy: /mockifyer-atlas-html[/…]) — serve atlas-html static files (index.html, pages, incidents, screenshots)
13
13
  * 9. POST /mockifyer-atlas-screenshot — write screen image (png/jpg/webp) under mock-data/atlas-html/screenshots/
14
14
  * 10. POST /mockifyer-atlas-render — write full interactive Atlas HTML under mock-data/atlas-html/
15
- * 11. POST /mockifyer-atlas-body-spill — write full hop body text under mock-data/atlas-html/bodies/
15
+ * 11. POST /mockifyer-atlas-body-spill — hold full hop body text in Metro memory (written to mock-data/atlas-html/bodies/ on Render)
16
16
  * 12. POST/GET /mockifyer-network-events — live hop ring buffer for `mockifyer-atlas` CLI
17
17
  * 13. GET /mockifyer-network-events/stream — SSE hop stream
18
18
  * 14. GET /mockifyer-network-events/analyze — hop summary JSON
@@ -82,6 +82,15 @@ declare function syncFromIOSSimulator(projectRoot: string, mockDataPath: string)
82
82
  syncedFiles?: string[];
83
83
  error?: string;
84
84
  };
85
+ /**
86
+ * Hold a full hop body from the device (RN) in Metro memory.
87
+ * Written under atlas-html/bodies/ only when Atlas HTML is rendered.
88
+ */
89
+ export declare function bufferAtlasBodySpill(relativePath: string, text: string): {
90
+ success: boolean;
91
+ relativePath?: string;
92
+ error?: string;
93
+ };
85
94
  /**
86
95
  * Metro middleware function
87
96
  */
@@ -13,7 +13,7 @@
13
13
  * 8. GET /atlas-html[/…] (legacy: /mockifyer-atlas-html[/…]) — serve atlas-html static files (index.html, pages, incidents, screenshots)
14
14
  * 9. POST /mockifyer-atlas-screenshot — write screen image (png/jpg/webp) under mock-data/atlas-html/screenshots/
15
15
  * 10. POST /mockifyer-atlas-render — write full interactive Atlas HTML under mock-data/atlas-html/
16
- * 11. POST /mockifyer-atlas-body-spill — write full hop body text under mock-data/atlas-html/bodies/
16
+ * 11. POST /mockifyer-atlas-body-spill — hold full hop body text in Metro memory (written to mock-data/atlas-html/bodies/ on Render)
17
17
  * 12. POST/GET /mockifyer-network-events — live hop ring buffer for `mockifyer-atlas` CLI
18
18
  * 13. GET /mockifyer-network-events/stream — SSE hop stream
19
19
  * 14. GET /mockifyer-network-events/analyze — hop summary JSON
@@ -66,6 +66,7 @@ var __importStar = (this && this.__importStar) || (function () {
66
66
  };
67
67
  })();
68
68
  Object.defineProperty(exports, "__esModule", { value: true });
69
+ exports.bufferAtlasBodySpill = bufferAtlasBodySpill;
69
70
  exports.createMockSyncMiddleware = createMockSyncMiddleware;
70
71
  exports.startAutoSync = startAutoSync;
71
72
  exports.stopAutoSync = stopAutoSync;
@@ -145,8 +146,7 @@ async function enrichMetroBufferFromDashboard(options) {
145
146
  });
146
147
  let added = 0;
147
148
  for (const child of children) {
148
- const stored = buffer.append(child);
149
- appendNetworkEventNdjson(options.mockDataPath, stored);
149
+ buffer.append(child);
150
150
  added += 1;
151
151
  }
152
152
  return added;
@@ -948,9 +948,8 @@ function candidateBodyRelPaths(event, side) {
948
948
  }
949
949
  const BODY_SPILL_REL_PATTERN = /^bodies\/[A-Za-z0-9._-]+-(req|res)\.(json|txt)$/;
950
950
  /**
951
- * Locate a full body on disk or in the Metro spill buffer.
952
- * Writes a buffer hit for *this* hop only — never flushes the whole spill map
953
- * (that blocked Metro for seconds on every req/res/trace click).
951
+ * Locate a full body in the Metro spill buffer or on disk (after a Render).
952
+ * Never writes: files under the project tree trigger Metro fast refresh.
954
953
  */
955
954
  function findExistingBodyFile(options) {
956
955
  const outDir = path.join(options.mockDataPath, "atlas-html");
@@ -970,15 +969,7 @@ function findExistingBodyFile(options) {
970
969
  }
971
970
  const fromBuffer = snapshot[rel];
972
971
  if (typeof fromBuffer === "string" && fromBuffer.length > 0) {
973
- const saved = saveAtlasBodySpill(options.projectRoot, options.mockDataPath, rel, fromBuffer);
974
- if (saved.success && saved.filePath) {
975
- return { abs: saved.filePath, rel, text: fromBuffer };
976
- }
977
- return {
978
- abs,
979
- rel,
980
- text: fromBuffer,
981
- };
972
+ return { abs, rel, text: fromBuffer };
982
973
  }
983
974
  if (fs.existsSync(abs)) {
984
975
  return { abs, rel };
@@ -1052,11 +1043,12 @@ function formatCapturedTraceLines(events, root) {
1052
1043
  return lines;
1053
1044
  }
1054
1045
  /**
1055
- * Persist a full hop body spill from the device (RN) under atlas-html/bodies/.
1046
+ * Hold a full hop body from the device (RN) in Metro memory.
1047
+ * Written under atlas-html/bodies/ only when Atlas HTML is rendered.
1056
1048
  */
1057
- function saveAtlasBodySpill(projectRoot, mockDataPath, relativePath, text) {
1049
+ function bufferAtlasBodySpill(relativePath, text) {
1058
1050
  const rel = relativePath.trim().replace(/^\/+/, "").replace(/\\/g, "/");
1059
- if (!rel || typeof text !== "string") {
1051
+ if (!rel || typeof text !== "string" || !text) {
1060
1052
  return { success: false, error: "relativePath and text are required" };
1061
1053
  }
1062
1054
  if (rel.includes("..") || !BODY_SPILL_REL_PATTERN.test(rel)) {
@@ -1065,21 +1057,11 @@ function saveAtlasBodySpill(projectRoot, mockDataPath, relativePath, text) {
1065
1057
  error: "relativePath must be bodies/<id>-req.json or bodies/<id>-res.json",
1066
1058
  };
1067
1059
  }
1068
- try {
1069
- const filePath = path.join(mockDataPath, "atlas-html", rel);
1070
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
1071
- const body = rel.endsWith(".json") ? (0, mockifyer_core_2.prettyPrintJsonText)(text) : text;
1072
- fs.writeFileSync(filePath, body, "utf8");
1073
- const relativeFromRoot = path.relative(projectRoot, filePath);
1074
- return {
1075
- success: true,
1076
- filePath,
1077
- relativePath: relativeFromRoot.split(path.sep).join("/"),
1078
- };
1079
- }
1080
- catch (error) {
1081
- return { success: false, error: error.message };
1060
+ const buffered = (0, mockifyer_core_2.bufferNetworkBodySpill)(rel, text);
1061
+ if (!buffered) {
1062
+ return { success: false, error: "body could not be buffered" };
1082
1063
  }
1064
+ return { success: true, relativePath: buffered };
1083
1065
  }
1084
1066
  const ATLAS_HTML_CONTENT_TYPES = {
1085
1067
  ".html": "text/html; charset=utf-8",
@@ -1163,17 +1145,6 @@ function serveAtlasHtmlStatic(mockDataPath, relativeUrlPath, res) {
1163
1145
  res.end(fs.readFileSync(filePath));
1164
1146
  return true;
1165
1147
  }
1166
- const NETWORK_STREAM_NDJSON_REL = path.join("atlas-html", "atlas.ndjson");
1167
- function appendNetworkEventNdjson(mockDataPath, event) {
1168
- try {
1169
- const filePath = path.join(mockDataPath, NETWORK_STREAM_NDJSON_REL);
1170
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
1171
- fs.appendFileSync(filePath, `${JSON.stringify(event)}\n`, "utf8");
1172
- }
1173
- catch {
1174
- // disk append is best-effort
1175
- }
1176
- }
1177
1148
  function writeNetworkEventsSnapshot(mockDataPath, events) {
1178
1149
  const dir = path.join(mockDataPath, "atlas-html");
1179
1150
  fs.mkdirSync(dir, { recursive: true });
@@ -1441,11 +1412,7 @@ function createMockSyncMiddleware(options) {
1441
1412
  return;
1442
1413
  }
1443
1414
  const buffer = (0, mockifyer_core_2.getMetroNetworkEventBuffer)();
1444
- const saved = incoming.map((e) => {
1445
- const stored = buffer.append(e);
1446
- appendNetworkEventNdjson(mockDataPath, stored);
1447
- return stored;
1448
- });
1415
+ const saved = incoming.map((e) => buffer.append(e));
1449
1416
  const dashboardBaseUrl = resolveAtlasEnrichmentDashboardUrl(options?.dashboardUrl, parsed.dashboardBaseUrl);
1450
1417
  if (dashboardBaseUrl) {
1451
1418
  scheduleDashboardTraceEnrichment({ dashboardBaseUrl, mockDataPath });
@@ -1875,7 +1842,7 @@ function createMockSyncMiddleware(options) {
1875
1842
  const parsed = JSON.parse(body);
1876
1843
  const relativePath = typeof parsed.relativePath === "string" ? parsed.relativePath : "";
1877
1844
  const text = typeof parsed.text === "string" ? parsed.text : "";
1878
- const result = saveAtlasBodySpill(projectRoot, mockDataPath, relativePath, text);
1845
+ const result = bufferAtlasBodySpill(relativePath, text);
1879
1846
  res.setHeader("Content-Type", "application/json");
1880
1847
  res.statusCode = result.success ? 201 : 400;
1881
1848
  res.end(JSON.stringify(result));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sgedda/mockifyer-fetch",
3
- "version": "1.8.96",
3
+ "version": "1.8.98",
4
4
  "description": "Mockifyer for Fetch - API mocking and logging utility for storing and replaying API responses",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "license": "MIT",
51
51
  "dependencies": {
52
- "@sgedda/mockifyer-core": "^1.10.176"
52
+ "@sgedda/mockifyer-core": "^1.10.178"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^20.11.24",
package/src/index.ts CHANGED
@@ -859,12 +859,7 @@ class MockifyerClass {
859
859
  return config;
860
860
  }
861
861
 
862
- if (
863
- !shouldApplyMockifyer(this.activationMode, config.headers, {
864
- useProxyLane: { proxyBaseUrl: this.config.proxy?.baseUrl, resolvedClientId: this.config.clientId },
865
- })
866
- ) {
867
- await this.applyOutboundCorrelation(config);
862
+ if (!shouldApplyMockifyer(this.activationMode, config.headers)) {
868
863
  (config as any).__mockifyer_bypass = true;
869
864
  return config;
870
865
  }
@@ -58,6 +58,7 @@ export interface MetroConfig {
58
58
  ) => { filePath: string; type: string } | null | undefined;
59
59
  extraNodeModules?: Record<string, string>;
60
60
  nodeModulesPaths?: string[];
61
+ blockList?: RegExp | RegExp[];
61
62
  };
62
63
  watchFolders?: string[];
63
64
  transformer?: any;
@@ -121,6 +122,33 @@ function resolveMockifyerCoreReactNativeEntry(
121
122
  }
122
123
  }
123
124
 
125
+ const ATLAS_HTML_DIR_NAME = 'atlas-html';
126
+ const DEFAULT_MOCK_DATA_PATH = 'mock-data';
127
+
128
+ function escapeRegExp(value: string): string {
129
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
130
+ }
131
+
132
+ /**
133
+ * Regex for `<projectRoot>/<mockDataPath>/atlas-html/…`. Atlas renders and snapshots
134
+ * write there; without the block every write makes Metro send a fast-refresh update.
135
+ */
136
+ export function atlasHtmlBlockListPattern(projectRoot: string, mockDataPath: string): RegExp {
137
+ const path = require('path') as typeof import('path');
138
+ const dir = path.resolve(projectRoot, mockDataPath, ATLAS_HTML_DIR_NAME);
139
+ const separators = '[\\\\/]';
140
+ const body = dir.split(/[\\/]+/).map(escapeRegExp).join(separators);
141
+ return new RegExp(`^${body}${separators}.*$`);
142
+ }
143
+
144
+ function appendBlockList(
145
+ existing: RegExp | RegExp[] | undefined,
146
+ pattern: RegExp
147
+ ): RegExp[] {
148
+ if (!existing) return [pattern];
149
+ return [...(Array.isArray(existing) ? existing : [existing]), pattern];
150
+ }
151
+
124
152
  /**
125
153
  * Options for configuring Metro for Mockifyer
126
154
  */
@@ -268,7 +296,7 @@ export function configureMetroForMockifyer(
268
296
  const { createMockSyncMiddleware } = require('./metro-sync-middleware');
269
297
  const syncMiddleware = createMockSyncMiddleware({
270
298
  projectRoot: options.syncMiddleware.projectRoot || process.cwd(),
271
- mockDataPath: options.syncMiddleware.mockDataPath || 'mock-data',
299
+ mockDataPath: options.syncMiddleware.mockDataPath || DEFAULT_MOCK_DATA_PATH,
272
300
  testGeneration: options.syncMiddleware.testGeneration,
273
301
  atlasKey: options.syncMiddleware.atlasKey,
274
302
  dashboardKey: options.syncMiddleware.dashboardKey,
@@ -311,7 +339,7 @@ export function configureMetroForMockifyer(
311
339
  const { startAutoSync } = require('./metro-sync-middleware');
312
340
  const intervalMs = options.autoSync.intervalMs || 5000;
313
341
  const projectRoot = options.autoSync.projectRoot || process.cwd();
314
- const mockDataPath = options.autoSync.mockDataPath || 'mock-data';
342
+ const mockDataPath = options.autoSync.mockDataPath || DEFAULT_MOCK_DATA_PATH;
315
343
 
316
344
  startAutoSync(intervalMs, {
317
345
  projectRoot,
@@ -323,11 +351,23 @@ export function configureMetroForMockifyer(
323
351
  }
324
352
  }
325
353
 
354
+ const syncOptions = options?.syncMiddleware;
355
+ const blockList = syncOptions
356
+ ? appendBlockList(
357
+ existingResolver.blockList,
358
+ atlasHtmlBlockListPattern(
359
+ syncOptions.projectRoot || process.cwd(),
360
+ syncOptions.mockDataPath || DEFAULT_MOCK_DATA_PATH
361
+ )
362
+ )
363
+ : existingResolver.blockList;
364
+
326
365
  // Merge config with new resolver
327
366
  return {
328
367
  ...config,
329
368
  resolver: {
330
369
  ...existingResolver,
370
+ ...(blockList ? { blockList } : {}),
331
371
  resolveRequest: newResolveRequest,
332
372
  },
333
373
  };
@@ -12,7 +12,7 @@
12
12
  * 8. GET /atlas-html[/…] (legacy: /mockifyer-atlas-html[/…]) — serve atlas-html static files (index.html, pages, incidents, screenshots)
13
13
  * 9. POST /mockifyer-atlas-screenshot — write screen image (png/jpg/webp) under mock-data/atlas-html/screenshots/
14
14
  * 10. POST /mockifyer-atlas-render — write full interactive Atlas HTML under mock-data/atlas-html/
15
- * 11. POST /mockifyer-atlas-body-spill — write full hop body text under mock-data/atlas-html/bodies/
15
+ * 11. POST /mockifyer-atlas-body-spill — hold full hop body text in Metro memory (written to mock-data/atlas-html/bodies/ on Render)
16
16
  * 12. POST/GET /mockifyer-network-events — live hop ring buffer for `mockifyer-atlas` CLI
17
17
  * 13. GET /mockifyer-network-events/stream — SSE hop stream
18
18
  * 14. GET /mockifyer-network-events/analyze — hop summary JSON
@@ -55,10 +55,10 @@ import {
55
55
  flushAtlasDocHtmlRewrite,
56
56
  setAtlasDocHtmlOutputPath,
57
57
  writeAtlasDocHtml,
58
- writeNetworkBodySpillMap,
58
+ bufferNetworkBodySpill,
59
59
  flushNetworkBodySpillsToDir,
60
+ writeNetworkBodySpillMap,
60
61
  getNetworkBodySpillSnapshot,
61
- prettyPrintJsonText,
62
62
  setAtlasDocMap,
63
63
  type AtlasDocMap,
64
64
  type NetworkEvent,
@@ -226,8 +226,7 @@ async function enrichMetroBufferFromDashboard(options: {
226
226
 
227
227
  let added = 0;
228
228
  for (const child of children) {
229
- const stored = buffer.append(child);
230
- appendNetworkEventNdjson(options.mockDataPath, stored);
229
+ buffer.append(child);
231
230
  added += 1;
232
231
  }
233
232
  return added;
@@ -1259,9 +1258,8 @@ const BODY_SPILL_REL_PATTERN =
1259
1258
  /^bodies\/[A-Za-z0-9._-]+-(req|res)\.(json|txt)$/;
1260
1259
 
1261
1260
  /**
1262
- * Locate a full body on disk or in the Metro spill buffer.
1263
- * Writes a buffer hit for *this* hop only — never flushes the whole spill map
1264
- * (that blocked Metro for seconds on every req/res/trace click).
1261
+ * Locate a full body in the Metro spill buffer or on disk (after a Render).
1262
+ * Never writes: files under the project tree trigger Metro fast refresh.
1265
1263
  */
1266
1264
  function findExistingBodyFile(options: {
1267
1265
  projectRoot: string;
@@ -1288,20 +1286,7 @@ function findExistingBodyFile(options: {
1288
1286
 
1289
1287
  const fromBuffer = snapshot[rel];
1290
1288
  if (typeof fromBuffer === "string" && fromBuffer.length > 0) {
1291
- const saved = saveAtlasBodySpill(
1292
- options.projectRoot,
1293
- options.mockDataPath,
1294
- rel,
1295
- fromBuffer,
1296
- );
1297
- if (saved.success && saved.filePath) {
1298
- return { abs: saved.filePath, rel, text: fromBuffer };
1299
- }
1300
- return {
1301
- abs,
1302
- rel,
1303
- text: fromBuffer,
1304
- };
1289
+ return { abs, rel, text: fromBuffer };
1305
1290
  }
1306
1291
  if (fs.existsSync(abs)) {
1307
1292
  return { abs, rel };
@@ -1383,21 +1368,19 @@ function formatCapturedTraceLines(
1383
1368
  }
1384
1369
 
1385
1370
  /**
1386
- * Persist a full hop body spill from the device (RN) under atlas-html/bodies/.
1371
+ * Hold a full hop body from the device (RN) in Metro memory.
1372
+ * Written under atlas-html/bodies/ only when Atlas HTML is rendered.
1387
1373
  */
1388
- function saveAtlasBodySpill(
1389
- projectRoot: string,
1390
- mockDataPath: string,
1374
+ export function bufferAtlasBodySpill(
1391
1375
  relativePath: string,
1392
1376
  text: string,
1393
1377
  ): {
1394
1378
  success: boolean;
1395
- filePath?: string;
1396
1379
  relativePath?: string;
1397
1380
  error?: string;
1398
1381
  } {
1399
1382
  const rel = relativePath.trim().replace(/^\/+/, "").replace(/\\/g, "/");
1400
- if (!rel || typeof text !== "string") {
1383
+ if (!rel || typeof text !== "string" || !text) {
1401
1384
  return { success: false, error: "relativePath and text are required" };
1402
1385
  }
1403
1386
  if (rel.includes("..") || !BODY_SPILL_REL_PATTERN.test(rel)) {
@@ -1407,20 +1390,11 @@ function saveAtlasBodySpill(
1407
1390
  "relativePath must be bodies/<id>-req.json or bodies/<id>-res.json",
1408
1391
  };
1409
1392
  }
1410
- try {
1411
- const filePath = path.join(mockDataPath, "atlas-html", rel);
1412
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
1413
- const body = rel.endsWith(".json") ? prettyPrintJsonText(text) : text;
1414
- fs.writeFileSync(filePath, body, "utf8");
1415
- const relativeFromRoot = path.relative(projectRoot, filePath);
1416
- return {
1417
- success: true,
1418
- filePath,
1419
- relativePath: relativeFromRoot.split(path.sep).join("/"),
1420
- };
1421
- } catch (error) {
1422
- return { success: false, error: (error as Error).message };
1393
+ const buffered = bufferNetworkBodySpill(rel, text);
1394
+ if (!buffered) {
1395
+ return { success: false, error: "body could not be buffered" };
1423
1396
  }
1397
+ return { success: true, relativePath: buffered };
1424
1398
  }
1425
1399
 
1426
1400
  const ATLAS_HTML_CONTENT_TYPES: Record<string, string> = {
@@ -1522,21 +1496,6 @@ function serveAtlasHtmlStatic(
1522
1496
  return true;
1523
1497
  }
1524
1498
 
1525
- const NETWORK_STREAM_NDJSON_REL = path.join("atlas-html", "atlas.ndjson");
1526
-
1527
- function appendNetworkEventNdjson(
1528
- mockDataPath: string,
1529
- event: NetworkEvent,
1530
- ): void {
1531
- try {
1532
- const filePath = path.join(mockDataPath, NETWORK_STREAM_NDJSON_REL);
1533
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
1534
- fs.appendFileSync(filePath, `${JSON.stringify(event)}\n`, "utf8");
1535
- } catch {
1536
- // disk append is best-effort
1537
- }
1538
- }
1539
-
1540
1499
  function writeNetworkEventsSnapshot(
1541
1500
  mockDataPath: string,
1542
1501
  events: NetworkEvent[],
@@ -1881,11 +1840,7 @@ export function createMockSyncMiddleware(options?: MetroSyncMiddlewareOptions) {
1881
1840
  return;
1882
1841
  }
1883
1842
  const buffer = getMetroNetworkEventBuffer();
1884
- const saved = incoming.map((e) => {
1885
- const stored = buffer.append(e);
1886
- appendNetworkEventNdjson(mockDataPath, stored);
1887
- return stored;
1888
- });
1843
+ const saved = incoming.map((e) => buffer.append(e));
1889
1844
  const dashboardBaseUrl = resolveAtlasEnrichmentDashboardUrl(
1890
1845
  options?.dashboardUrl,
1891
1846
  parsed.dashboardBaseUrl,
@@ -2430,12 +2385,7 @@ export function createMockSyncMiddleware(options?: MetroSyncMiddlewareOptions) {
2430
2385
  const relativePath =
2431
2386
  typeof parsed.relativePath === "string" ? parsed.relativePath : "";
2432
2387
  const text = typeof parsed.text === "string" ? parsed.text : "";
2433
- const result = saveAtlasBodySpill(
2434
- projectRoot,
2435
- mockDataPath,
2436
- relativePath,
2437
- text,
2438
- );
2388
+ const result = bufferAtlasBodySpill(relativePath, text);
2439
2389
  res.setHeader("Content-Type", "application/json");
2440
2390
  res.statusCode = result.success ? 201 : 400;
2441
2391
  res.end(JSON.stringify(result));
@@ -2497,10 +2447,7 @@ export function createMockSyncMiddleware(options?: MetroSyncMiddlewareOptions) {
2497
2447
  }
2498
2448
  setAtlasDocMap(doc);
2499
2449
  setAtlasDocHtmlOutputPath(outDir);
2500
- const spillWritten = writeNetworkBodySpillMap(
2501
- outDir,
2502
- parsed.bodySpills,
2503
- );
2450
+ const spillWritten = writeNetworkBodySpillMap(outDir, parsed.bodySpills);
2504
2451
  const events = Array.isArray(parsed.events) ? parsed.events : [];
2505
2452
  const written = writeAtlasDocHtml(outDir, doc, events);
2506
2453
  const relativeFromRoot = path