@sgedda/mockifyer-fetch 1.8.42 → 1.8.44

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
@@ -91,6 +91,16 @@ class MockifyerClass {
91
91
  const parentRequestId = config.__mockifyer_parentRequestId;
92
92
  return parentRequestId ? { requestId, parentRequestId } : { requestId };
93
93
  }
94
+ /** Attach dashboard lookup id onto thrown fetch/client errors. */
95
+ throwWithMockifyerRequestId(error) {
96
+ const err = error;
97
+ const hopRequestId = err?.config?.__mockifyer_requestId;
98
+ const requestId = (0, mockifyer_core_1.resolveMockifyerRequestIdForError)({
99
+ hopRequestId,
100
+ responseHeaders: err?.response?.headers,
101
+ });
102
+ throw (0, mockifyer_core_1.attachMockifyerRequestIdToError)(error, requestId);
103
+ }
94
104
  /**
95
105
  * Serve stored mock body with optional `$pool` resolution from the local fixture pool.
96
106
  * Always passes `loadPoolResponse` — including React Native where Node `fs`/`path` are
@@ -781,7 +791,7 @@ class MockifyerClass {
781
791
  responseBody: error.response?.data,
782
792
  }, this.readRequestCorrelation(error.config));
783
793
  }
784
- throw error;
794
+ this.throwWithMockifyerRequestId(error);
785
795
  });
786
796
  }
787
797
  /**
@@ -1293,8 +1303,12 @@ function setupMockifyer(config) {
1293
1303
  const method = init?.method || 'GET';
1294
1304
  const headers = init?.headers || {};
1295
1305
  const body = init?.body;
1296
- // Skip Mockifyer sync endpoints and Resend API to prevent infinite loops
1297
- if (url.includes('/mockifyer-save') || url.includes('/mockifyer-clear') || url.includes('/mockifyer-sync') || url.includes('api.resend.com')) {
1306
+ // Skip Mockifyer sync endpoints, dashboard `/api/proxy` plumbing, and Resend API
1307
+ if (url.includes('/mockifyer-save') ||
1308
+ url.includes('/mockifyer-clear') ||
1309
+ url.includes('/mockifyer-sync') ||
1310
+ url.includes('api.resend.com') ||
1311
+ (0, mockifyer_core_1.isMockifyerDashboardProxyApiUrl)(url)) {
1298
1312
  return await originalFetchForPatched(input, init);
1299
1313
  }
1300
1314
  const simpleRequestKey = `${method}:${url}`;
@@ -1372,7 +1386,11 @@ function setupMockifyer(config) {
1372
1386
  headers: responseHeaders
1373
1387
  });
1374
1388
  }
1375
- throw error;
1389
+ throw (0, mockifyer_core_1.attachMockifyerRequestIdToError)(error, (0, mockifyer_core_1.resolveMockifyerRequestIdForError)({
1390
+ hopRequestId: error?.config
1391
+ ?.__mockifyer_requestId,
1392
+ responseHeaders: error?.response?.headers,
1393
+ }));
1376
1394
  }
1377
1395
  };
1378
1396
  mockifyer_core_2.logger.info('[Mockifyer] ✅ Patched global fetch (useGlobalFetch: true)');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sgedda/mockifyer-fetch",
3
- "version": "1.8.42",
3
+ "version": "1.8.44",
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.23"
52
+ "@sgedda/mockifyer-core": "^1.10.27"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^20.11.24",
package/src/index.ts CHANGED
@@ -42,6 +42,7 @@ import {
42
42
  isUsableNodeLikePoolFs,
43
43
  type PoolResponseItem,
44
44
  shouldBypassMockifyerForUrl,
45
+ isMockifyerDashboardProxyApiUrl,
45
46
  resolveRecordingExclusions,
46
47
  shouldExcludeRecording,
47
48
  mockPassesThroughToRealApi,
@@ -74,6 +75,8 @@ import {
74
75
  getInlineTraceEnvelopeBusinessBody,
75
76
  resolveRecordResponses,
76
77
  applyOutboundRequestCorrelation,
78
+ attachMockifyerRequestIdToError,
79
+ resolveMockifyerRequestIdForError,
77
80
  type RequestCorrelationContext,
78
81
  installNodeInboundRequestCorrelationCapture,
79
82
  } from '@sgedda/mockifyer-core';
@@ -183,6 +186,17 @@ class MockifyerClass {
183
186
  return parentRequestId ? { requestId, parentRequestId } : { requestId };
184
187
  }
185
188
 
189
+ /** Attach dashboard lookup id onto thrown fetch/client errors. */
190
+ private throwWithMockifyerRequestId(error: unknown): never {
191
+ const err = error as { config?: unknown; response?: { headers?: unknown } };
192
+ const hopRequestId = (err?.config as { __mockifyer_requestId?: string } | undefined)?.__mockifyer_requestId;
193
+ const requestId = resolveMockifyerRequestIdForError({
194
+ hopRequestId,
195
+ responseHeaders: err?.response?.headers,
196
+ });
197
+ throw attachMockifyerRequestIdToError(error, requestId);
198
+ }
199
+
186
200
  /**
187
201
  * Serve stored mock body with optional `$pool` resolution from the local fixture pool.
188
202
  * Always passes `loadPoolResponse` — including React Native where Node `fs`/`path` are
@@ -1012,7 +1026,7 @@ class MockifyerClass {
1012
1026
  this.readRequestCorrelation(error.config)
1013
1027
  );
1014
1028
  }
1015
- throw error;
1029
+ this.throwWithMockifyerRequestId(error);
1016
1030
  }
1017
1031
  );
1018
1032
  }
@@ -1623,8 +1637,14 @@ export function setupMockifyer(config: MockifyerConfig): MockifyerInstance {
1623
1637
  const headers = init?.headers || {};
1624
1638
  const body = init?.body;
1625
1639
 
1626
- // Skip Mockifyer sync endpoints and Resend API to prevent infinite loops
1627
- if (url.includes('/mockifyer-save') || url.includes('/mockifyer-clear') || url.includes('/mockifyer-sync') || url.includes('api.resend.com')) {
1640
+ // Skip Mockifyer sync endpoints, dashboard `/api/proxy` plumbing, and Resend API
1641
+ if (
1642
+ url.includes('/mockifyer-save') ||
1643
+ url.includes('/mockifyer-clear') ||
1644
+ url.includes('/mockifyer-sync') ||
1645
+ url.includes('api.resend.com') ||
1646
+ isMockifyerDashboardProxyApiUrl(url)
1647
+ ) {
1628
1648
  return await originalFetchForPatched(input, init);
1629
1649
  }
1630
1650
 
@@ -1708,7 +1728,14 @@ export function setupMockifyer(config: MockifyerConfig): MockifyerInstance {
1708
1728
  headers: responseHeaders
1709
1729
  });
1710
1730
  }
1711
- throw error;
1731
+ throw attachMockifyerRequestIdToError(
1732
+ error,
1733
+ resolveMockifyerRequestIdForError({
1734
+ hopRequestId: (error as { config?: { __mockifyer_requestId?: string } })?.config
1735
+ ?.__mockifyer_requestId,
1736
+ responseHeaders: (error as { response?: { headers?: unknown } })?.response?.headers,
1737
+ })
1738
+ );
1712
1739
  }
1713
1740
  } as typeof fetch;
1714
1741