@sgedda/mockifyer-fetch 1.8.104 → 1.8.107

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.
@@ -39,13 +39,14 @@ import {
39
39
  MockData,
40
40
  TestGenerator,
41
41
  TestGenerationOptions,
42
+ getMockFilePath,
43
+ logger,
42
44
  } from "@sgedda/mockifyer-core";
43
- import { logger } from "@sgedda/mockifyer-core";
44
45
  import {
45
46
  POOL_ID_PATTERN,
46
47
  loadPoolResponseItem,
47
48
  type PoolResponseItem,
48
- mergeDomainPathRuleUpserts,
49
+ mergeDiscoveredDomainPathUpserts,
49
50
  parseDomainPathRules,
50
51
  readDomainPathRulesFile,
51
52
  writeDomainPathRulesFile,
@@ -366,58 +367,6 @@ function collectRequestBodyUtf8(
366
367
  req.on("error", (e: Error) => finish(e, ""));
367
368
  }
368
369
 
369
- function getMockFilePathLocal(
370
- mockData: MockData,
371
- dateStr: string,
372
- ): { dir: string; filename: string } {
373
- const url = mockData.request.url || "";
374
- const method = (mockData.request.method || "GET").toUpperCase();
375
- let host = "unknown";
376
- let pathSegments: string[] = [];
377
- try {
378
- const parsed = new URL(url);
379
- host = parsed.hostname;
380
- pathSegments = parsed.pathname.split("/").filter(Boolean);
381
- } catch {
382
- return { dir: "unknown", filename: `${method}_${dateStr}.json` };
383
- }
384
- const hostSafe = host.replace(/[^a-zA-Z0-9.-]/g, "_");
385
- const graphqlIdx = pathSegments.lastIndexOf("graphql");
386
- const restIdx = pathSegments.indexOf("rest");
387
- let type: string;
388
- let remainingSegments: string[];
389
- if (graphqlIdx >= 0) {
390
- type = "graphql";
391
- remainingSegments = pathSegments.slice(graphqlIdx + 1);
392
- } else if (restIdx >= 0) {
393
- type = "rest";
394
- remainingSegments = pathSegments.slice(restIdx + 1);
395
- } else {
396
- type = "";
397
- remainingSegments = pathSegments;
398
- }
399
- let identifier = "";
400
- if (mockData.request.data) {
401
- try {
402
- const body =
403
- typeof mockData.request.data === "string"
404
- ? JSON.parse(mockData.request.data)
405
- : mockData.request.data;
406
- if (body.operationName) identifier = body.operationName;
407
- else if (body.path) identifier = body.path;
408
- else if (body.webAppName) identifier = body.webAppName;
409
- } catch {
410
- /* ignore */
411
- }
412
- }
413
- identifier = identifier.replace(/[^a-zA-Z0-9_-]/g, "_").substring(0, 60);
414
- const dir = [hostSafe, type, ...remainingSegments].filter(Boolean).join("/");
415
- const filename = identifier
416
- ? `${method}_${identifier}_${dateStr}.json`
417
- : `${method}_${dateStr}.json`;
418
- return { dir, filename };
419
- }
420
-
421
370
  /**
422
371
  * Scenario folder names the dashboard accepts (one path segment).
423
372
  * `pool` is the fixture-pool directory and is not a scenario.
@@ -756,7 +705,7 @@ function saveMockToProjectFolder(
756
705
  .replace(/T/, "_")
757
706
  .replace(/\..+/, "")
758
707
  .replace(/:/g, "-");
759
- const { dir, filename } = getMockFilePathLocal(mockData, dateStr);
708
+ const { dir, filename } = getMockFilePath(mockData, dateStr);
760
709
  const fullDir = path.join(scenarioPath, dir);
761
710
  const filePath = path.join(fullDir, filename);
762
711
 
@@ -2237,7 +2186,7 @@ export function createMockSyncMiddleware(options?: MetroSyncMiddlewareOptions) {
2237
2186
  parsed.upserts ?? parsed.rules ?? {},
2238
2187
  );
2239
2188
  const existing = readDomainPathRulesFile(mockDataPath, scenarioName);
2240
- const { rules, changed } = mergeDomainPathRuleUpserts(
2189
+ const { rules, changed } = mergeDiscoveredDomainPathUpserts(
2241
2190
  existing,
2242
2191
  upserts,
2243
2192
  );