@sgedda/mockifyer-fetch 1.8.40 → 1.8.41
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 +19 -16
- package/package.json +2 -2
- package/src/index.ts +26 -20
package/dist/index.js
CHANGED
|
@@ -704,13 +704,24 @@ class MockifyerClass {
|
|
|
704
704
|
}
|
|
705
705
|
const matchedMock = response.config.__mockifyer_matchedMock;
|
|
706
706
|
if (matchedMock) {
|
|
707
|
+
const startTime = response.config.__mockifyer_startTime;
|
|
708
|
+
const durationMs = startTime ? Date.now() - startTime : undefined;
|
|
709
|
+
const reqUrl = response.config?.url || url;
|
|
710
|
+
const reqMethod = (response.config?.method || 'GET').toUpperCase();
|
|
711
|
+
// Parent hop first, then unwrap nested mockifyerTrace from downstream services.
|
|
712
|
+
this.logNetworkEvent({
|
|
713
|
+
method: reqMethod,
|
|
714
|
+
url: reqUrl,
|
|
715
|
+
source: 'upstream',
|
|
716
|
+
status: response.status,
|
|
717
|
+
durationMs,
|
|
718
|
+
}, this.readRequestCorrelation(response.config));
|
|
719
|
+
response.data = (0, mockifyer_core_1.unwrapAndMergeInlineTraceEnvelope)(response.data);
|
|
707
720
|
const capturedResponse = {
|
|
708
721
|
status: response.status,
|
|
709
722
|
data: response.data,
|
|
710
723
|
headers: response.headers || {},
|
|
711
724
|
};
|
|
712
|
-
const startTime = response.config.__mockifyer_startTime;
|
|
713
|
-
const durationMs = startTime ? Date.now() - startTime : undefined;
|
|
714
725
|
if ((0, mockifyer_core_1.resolveShouldPersistLiveCapture)(matchedMock.mockData, this.config)) {
|
|
715
726
|
await this.persistMatchedMockAfterLiveCapture(matchedMock, capturedResponse, durationMs);
|
|
716
727
|
}
|
|
@@ -718,22 +729,8 @@ class MockifyerClass {
|
|
|
718
729
|
response.data = clientResponse.data;
|
|
719
730
|
response.status = clientResponse.status;
|
|
720
731
|
delete response.config.__mockifyer_matchedMock;
|
|
721
|
-
const reqUrl = response.config?.url || url;
|
|
722
|
-
const reqMethod = (response.config?.method || 'GET').toUpperCase();
|
|
723
|
-
this.logNetworkEvent({
|
|
724
|
-
method: reqMethod,
|
|
725
|
-
url: reqUrl,
|
|
726
|
-
source: 'upstream',
|
|
727
|
-
status: response.status,
|
|
728
|
-
durationMs,
|
|
729
|
-
}, this.readRequestCorrelation(response.config));
|
|
730
732
|
return response;
|
|
731
733
|
}
|
|
732
|
-
// Only save locally if recordMode is enabled AND we're not proxying upstream calls.
|
|
733
|
-
// When proxy is configured, recording should happen on the proxy (e.g. dashboard → Redis).
|
|
734
|
-
if (this.config.recordMode && !this.config.proxy?.baseUrl) {
|
|
735
|
-
await this.saveResponse(response);
|
|
736
|
-
}
|
|
737
734
|
const reqUrl = response.config?.url || url;
|
|
738
735
|
const reqMethod = (response.config?.method || 'GET').toUpperCase();
|
|
739
736
|
this.logNetworkEvent({
|
|
@@ -745,6 +742,12 @@ class MockifyerClass {
|
|
|
745
742
|
? response.config.metadata.durationMs
|
|
746
743
|
: undefined,
|
|
747
744
|
}, this.readRequestCorrelation(response.config));
|
|
745
|
+
response.data = (0, mockifyer_core_1.unwrapAndMergeInlineTraceEnvelope)(response.data);
|
|
746
|
+
// Only save locally if recordMode is enabled AND we're not proxying upstream calls.
|
|
747
|
+
// When proxy is configured, recording should happen on the proxy (e.g. dashboard → Redis).
|
|
748
|
+
if (this.config.recordMode && !this.config.proxy?.baseUrl) {
|
|
749
|
+
await this.saveResponse(response);
|
|
750
|
+
}
|
|
748
751
|
return response;
|
|
749
752
|
}, async (error) => {
|
|
750
753
|
const requestKey = error.config?.__mockifyer_requestKey;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sgedda/mockifyer-fetch",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.41",
|
|
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.
|
|
52
|
+
"@sgedda/mockifyer-core": "^1.10.23"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/node": "^20.11.24",
|
package/src/index.ts
CHANGED
|
@@ -69,6 +69,7 @@ import {
|
|
|
69
69
|
emitMockifyerNetworkEvent,
|
|
70
70
|
networkEventHashFromRequestKey,
|
|
71
71
|
recordInlineTraceHopFromExchange,
|
|
72
|
+
unwrapAndMergeInlineTraceEnvelope,
|
|
72
73
|
resolveRecordResponses,
|
|
73
74
|
applyOutboundRequestCorrelation,
|
|
74
75
|
type RequestCorrelationContext,
|
|
@@ -901,13 +902,29 @@ class MockifyerClass {
|
|
|
901
902
|
|
|
902
903
|
const matchedMock = (response.config as any).__mockifyer_matchedMock as CachedMockData | undefined;
|
|
903
904
|
if (matchedMock) {
|
|
905
|
+
const startTime = (response.config as any).__mockifyer_startTime;
|
|
906
|
+
const durationMs = startTime ? Date.now() - startTime : undefined;
|
|
907
|
+
|
|
908
|
+
const reqUrl = response.config?.url || url;
|
|
909
|
+
const reqMethod = (response.config?.method || 'GET').toUpperCase();
|
|
910
|
+
// Parent hop first, then unwrap nested mockifyerTrace from downstream services.
|
|
911
|
+
this.logNetworkEvent(
|
|
912
|
+
{
|
|
913
|
+
method: reqMethod,
|
|
914
|
+
url: reqUrl,
|
|
915
|
+
source: 'upstream',
|
|
916
|
+
status: response.status,
|
|
917
|
+
durationMs,
|
|
918
|
+
},
|
|
919
|
+
this.readRequestCorrelation(response.config)
|
|
920
|
+
);
|
|
921
|
+
response.data = unwrapAndMergeInlineTraceEnvelope(response.data);
|
|
922
|
+
|
|
904
923
|
const capturedResponse: StoredResponse = {
|
|
905
924
|
status: response.status,
|
|
906
925
|
data: response.data,
|
|
907
926
|
headers: (response.headers as Record<string, string>) || {},
|
|
908
927
|
};
|
|
909
|
-
const startTime = (response.config as any).__mockifyer_startTime;
|
|
910
|
-
const durationMs = startTime ? Date.now() - startTime : undefined;
|
|
911
928
|
|
|
912
929
|
if (resolveShouldPersistLiveCapture(matchedMock.mockData, this.config)) {
|
|
913
930
|
await this.persistMatchedMockAfterLiveCapture(matchedMock, capturedResponse, durationMs);
|
|
@@ -922,27 +939,9 @@ class MockifyerClass {
|
|
|
922
939
|
response.status = clientResponse.status;
|
|
923
940
|
delete (response.config as any).__mockifyer_matchedMock;
|
|
924
941
|
|
|
925
|
-
const reqUrl = response.config?.url || url;
|
|
926
|
-
const reqMethod = (response.config?.method || 'GET').toUpperCase();
|
|
927
|
-
this.logNetworkEvent(
|
|
928
|
-
{
|
|
929
|
-
method: reqMethod,
|
|
930
|
-
url: reqUrl,
|
|
931
|
-
source: 'upstream',
|
|
932
|
-
status: response.status,
|
|
933
|
-
durationMs,
|
|
934
|
-
},
|
|
935
|
-
this.readRequestCorrelation(response.config)
|
|
936
|
-
);
|
|
937
942
|
return response;
|
|
938
943
|
}
|
|
939
944
|
|
|
940
|
-
// Only save locally if recordMode is enabled AND we're not proxying upstream calls.
|
|
941
|
-
// When proxy is configured, recording should happen on the proxy (e.g. dashboard → Redis).
|
|
942
|
-
if (this.config.recordMode && !this.config.proxy?.baseUrl) {
|
|
943
|
-
await this.saveResponse(response);
|
|
944
|
-
}
|
|
945
|
-
|
|
946
945
|
const reqUrl = response.config?.url || url;
|
|
947
946
|
const reqMethod = (response.config?.method || 'GET').toUpperCase();
|
|
948
947
|
this.logNetworkEvent(
|
|
@@ -958,6 +957,13 @@ class MockifyerClass {
|
|
|
958
957
|
},
|
|
959
958
|
this.readRequestCorrelation(response.config)
|
|
960
959
|
);
|
|
960
|
+
response.data = unwrapAndMergeInlineTraceEnvelope(response.data);
|
|
961
|
+
|
|
962
|
+
// Only save locally if recordMode is enabled AND we're not proxying upstream calls.
|
|
963
|
+
// When proxy is configured, recording should happen on the proxy (e.g. dashboard → Redis).
|
|
964
|
+
if (this.config.recordMode && !this.config.proxy?.baseUrl) {
|
|
965
|
+
await this.saveResponse(response);
|
|
966
|
+
}
|
|
961
967
|
|
|
962
968
|
return response;
|
|
963
969
|
},
|