@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.
- package/README.md +155 -0
- package/dist/clients/fetch-client.d.ts +1 -1
- package/dist/clients/fetch-client.js +4 -2
- package/dist/core-proxy.browser.d.ts +19 -0
- package/dist/core-proxy.browser.js +57 -0
- package/dist/index.browser.d.ts +52 -0
- package/dist/index.browser.js +107 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +32 -1540
- package/dist/metro-sync-middleware.js +2 -56
- package/dist/mockifyer-class.d.ts +123 -0
- package/dist/mockifyer-class.js +1306 -0
- package/dist/node-capabilities.browser.d.ts +6 -0
- package/dist/node-capabilities.browser.js +110 -0
- package/dist/node-capabilities.d.ts +51 -0
- package/dist/node-capabilities.js +6 -0
- package/dist/node-capabilities.node.d.ts +6 -0
- package/dist/node-capabilities.node.js +31 -0
- package/dist/react-native.js +2 -1
- package/package.json +14 -3
- package/src/clients/fetch-client.ts +6 -3
- package/src/core-proxy.browser.ts +62 -0
- package/src/index.browser.ts +166 -0
- package/src/index.ts +36 -1887
- package/src/metro-sync-middleware.ts +5 -56
- package/src/mockifyer-class.ts +1700 -0
- package/src/node-capabilities.browser.ts +123 -0
- package/src/node-capabilities.node.ts +40 -0
- package/src/node-capabilities.ts +60 -0
- package/src/react-native.ts +2 -1
|
@@ -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
|
-
|
|
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 } =
|
|
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 } =
|
|
2189
|
+
const { rules, changed } = mergeDiscoveredDomainPathUpserts(
|
|
2241
2190
|
existing,
|
|
2242
2191
|
upserts,
|
|
2243
2192
|
);
|