@sgedda/mockifyer-fetch 1.8.33 → 1.8.34
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/clients/fetch-client.js +2 -1
- package/dist/core-proxy.d.ts +7 -0
- package/dist/core-proxy.js +15 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -4
- package/dist/metro-config.js +20 -0
- package/dist/utils/dashboard-redis-health.d.ts +1 -1
- package/dist/utils/dashboard-redis-health.js +3 -3
- package/package.json +2 -2
- package/src/clients/fetch-client.ts +1 -1
- package/src/core-proxy.ts +12 -0
- package/src/index.ts +8 -6
- package/src/metro-config.ts +24 -0
- package/src/utils/dashboard-redis-health.ts +1 -1
- package/tsconfig.json +5 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FetchHTTPClient = void 0;
|
|
4
4
|
const mockifyer_core_1 = require("@sgedda/mockifyer-core");
|
|
5
|
+
const core_proxy_1 = require("../core-proxy");
|
|
5
6
|
class FetchHTTPClient extends mockifyer_core_1.BaseHTTPClient {
|
|
6
7
|
constructor(config) {
|
|
7
8
|
super();
|
|
@@ -86,7 +87,7 @@ class FetchHTTPClient extends mockifyer_core_1.BaseHTTPClient {
|
|
|
86
87
|
headers.forEach((value, key) => {
|
|
87
88
|
headerRecord[key] = value;
|
|
88
89
|
});
|
|
89
|
-
return (0,
|
|
90
|
+
return (0, core_proxy_1.performDashboardProxyRequest)({
|
|
90
91
|
proxyBaseUrl: this.proxyBaseUrl,
|
|
91
92
|
url,
|
|
92
93
|
method: String(requestConfig.method || 'GET'),
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy/dashboard helpers from core via subpath exports (RN-safe; avoids barrel resolution).
|
|
3
|
+
*/
|
|
4
|
+
export { applyProxyRecordOnMissEnv } from '@sgedda/mockifyer-core/utils/apply-proxy-record-on-miss-env';
|
|
5
|
+
export { mirrorProxyRecordingToClient } from '@sgedda/mockifyer-core/utils/mirror-proxy-recording-to-client';
|
|
6
|
+
export { initMockifyerForDashboardProxy, initMockifyerForLocalFilesystem, type InitMockifyerForDashboardProxyOptions, type InitMockifyerForLocalFilesystemOptions, } from '@sgedda/mockifyer-core/utils/init-mockifyer-presets';
|
|
7
|
+
export { performDashboardProxyRequest } from '@sgedda/mockifyer-core/utils/perform-dashboard-proxy-request';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.performDashboardProxyRequest = exports.initMockifyerForLocalFilesystem = exports.initMockifyerForDashboardProxy = exports.mirrorProxyRecordingToClient = exports.applyProxyRecordOnMissEnv = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Proxy/dashboard helpers from core via subpath exports (RN-safe; avoids barrel resolution).
|
|
6
|
+
*/
|
|
7
|
+
var apply_proxy_record_on_miss_env_1 = require("@sgedda/mockifyer-core/utils/apply-proxy-record-on-miss-env");
|
|
8
|
+
Object.defineProperty(exports, "applyProxyRecordOnMissEnv", { enumerable: true, get: function () { return apply_proxy_record_on_miss_env_1.applyProxyRecordOnMissEnv; } });
|
|
9
|
+
var mirror_proxy_recording_to_client_1 = require("@sgedda/mockifyer-core/utils/mirror-proxy-recording-to-client");
|
|
10
|
+
Object.defineProperty(exports, "mirrorProxyRecordingToClient", { enumerable: true, get: function () { return mirror_proxy_recording_to_client_1.mirrorProxyRecordingToClient; } });
|
|
11
|
+
var init_mockifyer_presets_1 = require("@sgedda/mockifyer-core/utils/init-mockifyer-presets");
|
|
12
|
+
Object.defineProperty(exports, "initMockifyerForDashboardProxy", { enumerable: true, get: function () { return init_mockifyer_presets_1.initMockifyerForDashboardProxy; } });
|
|
13
|
+
Object.defineProperty(exports, "initMockifyerForLocalFilesystem", { enumerable: true, get: function () { return init_mockifyer_presets_1.initMockifyerForLocalFilesystem; } });
|
|
14
|
+
var perform_dashboard_proxy_request_1 = require("@sgedda/mockifyer-core/utils/perform-dashboard-proxy-request");
|
|
15
|
+
Object.defineProperty(exports, "performDashboardProxyRequest", { enumerable: true, get: function () { return perform_dashboard_proxy_request_1.performDashboardProxyRequest; } });
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { MockifyerConfig, HTTPClient
|
|
1
|
+
import { MockifyerConfig, HTTPClient } from '@sgedda/mockifyer-core';
|
|
2
|
+
import { type InitMockifyerForDashboardProxyOptions, type InitMockifyerForLocalFilesystemOptions } from './core-proxy';
|
|
2
3
|
export interface MockifyerInstance extends HTTPClient {
|
|
3
4
|
reloadMockData: (syncFromProject?: boolean) => Promise<void>;
|
|
4
5
|
clearStaleCacheEntries: () => number;
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ catch (e) {
|
|
|
35
35
|
// Import from core package
|
|
36
36
|
const mockifyer_core_1 = require("@sgedda/mockifyer-core");
|
|
37
37
|
const mockifyer_core_2 = require("@sgedda/mockifyer-core");
|
|
38
|
+
const core_proxy_1 = require("./core-proxy");
|
|
38
39
|
const fetch_client_1 = require("./clients/fetch-client");
|
|
39
40
|
class MockifyerClass {
|
|
40
41
|
/** Best-effort dashboard network log (skipped when traffic goes through `proxy.baseUrl`). */
|
|
@@ -671,7 +672,7 @@ class MockifyerClass {
|
|
|
671
672
|
const scenarioName = rec.scenarioName?.trim();
|
|
672
673
|
const mockData = rec.storedMock;
|
|
673
674
|
const providerType = this.config.databaseProvider?.type;
|
|
674
|
-
await (0,
|
|
675
|
+
await (0, core_proxy_1.mirrorProxyRecordingToClient)({
|
|
675
676
|
config: this.config,
|
|
676
677
|
mockDataPath: this.config.mockDataPath,
|
|
677
678
|
recording: rec,
|
|
@@ -1114,7 +1115,7 @@ function setupMockifyer(config) {
|
|
|
1114
1115
|
if (typeof mockifyer_core_1.installNodeInboundRequestCorrelationCapture === 'function') {
|
|
1115
1116
|
(0, mockifyer_core_1.installNodeInboundRequestCorrelationCapture)();
|
|
1116
1117
|
}
|
|
1117
|
-
const resolvedConfig = (0,
|
|
1118
|
+
const resolvedConfig = (0, core_proxy_1.applyProxyRecordOnMissEnv)(config);
|
|
1118
1119
|
// Initialize logger with config level (default to 'info' if not specified)
|
|
1119
1120
|
(0, mockifyer_core_2.setLogLevel)(resolvedConfig.logging || 'info');
|
|
1120
1121
|
// Set environment variables for Metro middleware to read test generation config
|
|
@@ -1264,13 +1265,13 @@ function setupMockifyer(config) {
|
|
|
1264
1265
|
* For full control, use {@link setupMockifyer} directly.
|
|
1265
1266
|
*/
|
|
1266
1267
|
async function initMockifyerForDashboardProxy(options) {
|
|
1267
|
-
return (0,
|
|
1268
|
+
return (0, core_proxy_1.initMockifyerForDashboardProxy)({ ...options, useGlobalFetch: options.useGlobalFetch ?? options.config?.useGlobalFetch ?? true }, setupMockifyer);
|
|
1268
1269
|
}
|
|
1269
1270
|
/**
|
|
1270
1271
|
* Preset: local filesystem mocks. No dashboard proxy.
|
|
1271
1272
|
*/
|
|
1272
1273
|
function initMockifyerForLocalFilesystem(options = {}) {
|
|
1273
|
-
return (0,
|
|
1274
|
+
return (0, core_proxy_1.initMockifyerForLocalFilesystem)({ ...options, useGlobalFetch: options.useGlobalFetch ?? options.config?.useGlobalFetch ?? true }, setupMockifyer);
|
|
1274
1275
|
}
|
|
1275
1276
|
/** Shared with {@link setupMockifyerForReactNative} strict-proxy branching. */
|
|
1276
1277
|
var dashboard_redis_health_1 = require("./utils/dashboard-redis-health");
|
package/dist/metro-config.js
CHANGED
|
@@ -75,6 +75,22 @@ function isMockifyerStubbedModule(moduleName) {
|
|
|
75
75
|
return (NODE_BUILTINS.includes(moduleName) ||
|
|
76
76
|
OPTIONAL_RN_PEER_MODULES.includes(moduleName));
|
|
77
77
|
}
|
|
78
|
+
/** Metro often resolves `@sgedda/mockifyer-core` to `main` instead of the RN entry. */
|
|
79
|
+
function resolveMockifyerCoreReactNativeEntry(moduleName, platform) {
|
|
80
|
+
if (moduleName !== '@sgedda/mockifyer-core') {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
if (platform === 'web') {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const filePath = require.resolve('@sgedda/mockifyer-core/dist/index.react-native.js');
|
|
88
|
+
return { filePath, type: 'sourceFile' };
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
78
94
|
/**
|
|
79
95
|
* Configure Metro bundler for Mockifyer
|
|
80
96
|
*
|
|
@@ -151,6 +167,10 @@ function configureMetroForMockifyer(config, options) {
|
|
|
151
167
|
type: 'sourceFile',
|
|
152
168
|
};
|
|
153
169
|
}
|
|
170
|
+
const mockifyerCoreRn = resolveMockifyerCoreReactNativeEntry(moduleName, platform);
|
|
171
|
+
if (mockifyerCoreRn) {
|
|
172
|
+
return mockifyerCoreRn;
|
|
173
|
+
}
|
|
154
174
|
// Call existing resolver if present
|
|
155
175
|
if (existingResolveRequest) {
|
|
156
176
|
const result = existingResolveRequest(context, moduleName, platform);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { canUseDashboardCentralProxy, canUseDashboardRedisProxy, type DashboardHealthPayload, } from '@sgedda/mockifyer-core';
|
|
1
|
+
export { canUseDashboardCentralProxy, canUseDashboardRedisProxy, type DashboardHealthPayload, } from '@sgedda/mockifyer-core/utils/dashboard-central-proxy-health';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.canUseDashboardRedisProxy = exports.canUseDashboardCentralProxy = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "canUseDashboardCentralProxy", { enumerable: true, get: function () { return
|
|
6
|
-
Object.defineProperty(exports, "canUseDashboardRedisProxy", { enumerable: true, get: function () { return
|
|
4
|
+
var dashboard_central_proxy_health_1 = require("@sgedda/mockifyer-core/utils/dashboard-central-proxy-health");
|
|
5
|
+
Object.defineProperty(exports, "canUseDashboardCentralProxy", { enumerable: true, get: function () { return dashboard_central_proxy_health_1.canUseDashboardCentralProxy; } });
|
|
6
|
+
Object.defineProperty(exports, "canUseDashboardRedisProxy", { enumerable: true, get: function () { return dashboard_central_proxy_health_1.canUseDashboardRedisProxy; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sgedda/mockifyer-fetch",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.34",
|
|
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.2"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/node": "^20.11.24",
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
getOutboundMockifyerDeviceIdHeader,
|
|
9
9
|
MOCKIFYER_CLIENT_ID_HEADER,
|
|
10
10
|
MOCKIFYER_DEVICE_ID_HEADER,
|
|
11
|
-
performDashboardProxyRequest,
|
|
12
11
|
} from '@sgedda/mockifyer-core';
|
|
12
|
+
import { performDashboardProxyRequest } from '../core-proxy';
|
|
13
13
|
|
|
14
14
|
export class FetchHTTPClient extends BaseHTTPClient<any, HTTPResponse<any>> {
|
|
15
15
|
private baseUrl?: string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy/dashboard helpers from core via subpath exports (RN-safe; avoids barrel resolution).
|
|
3
|
+
*/
|
|
4
|
+
export { applyProxyRecordOnMissEnv } from '@sgedda/mockifyer-core/utils/apply-proxy-record-on-miss-env';
|
|
5
|
+
export { mirrorProxyRecordingToClient } from '@sgedda/mockifyer-core/utils/mirror-proxy-recording-to-client';
|
|
6
|
+
export {
|
|
7
|
+
initMockifyerForDashboardProxy,
|
|
8
|
+
initMockifyerForLocalFilesystem,
|
|
9
|
+
type InitMockifyerForDashboardProxyOptions,
|
|
10
|
+
type InitMockifyerForLocalFilesystemOptions,
|
|
11
|
+
} from '@sgedda/mockifyer-core/utils/init-mockifyer-presets';
|
|
12
|
+
export { performDashboardProxyRequest } from '@sgedda/mockifyer-core/utils/perform-dashboard-proxy-request';
|
package/src/index.ts
CHANGED
|
@@ -56,12 +56,6 @@ import {
|
|
|
56
56
|
resolveActivationMode,
|
|
57
57
|
shouldApplyMockifyer,
|
|
58
58
|
isExplicitProxyScenarioContext,
|
|
59
|
-
applyProxyRecordOnMissEnv,
|
|
60
|
-
mirrorProxyRecordingToClient,
|
|
61
|
-
initMockifyerForDashboardProxy as coreInitMockifyerForDashboardProxy,
|
|
62
|
-
initMockifyerForLocalFilesystem as coreInitMockifyerForLocalFilesystem,
|
|
63
|
-
type InitMockifyerForDashboardProxyOptions,
|
|
64
|
-
type InitMockifyerForLocalFilesystemOptions,
|
|
65
59
|
newRecordingUsesAlwaysUseRealApi,
|
|
66
60
|
shouldBlockLocalMockRecording,
|
|
67
61
|
resolveStrictScenarioResolution,
|
|
@@ -74,6 +68,14 @@ import {
|
|
|
74
68
|
installNodeInboundRequestCorrelationCapture,
|
|
75
69
|
} from '@sgedda/mockifyer-core';
|
|
76
70
|
import { logger, setLogLevel } from '@sgedda/mockifyer-core';
|
|
71
|
+
import {
|
|
72
|
+
applyProxyRecordOnMissEnv,
|
|
73
|
+
mirrorProxyRecordingToClient,
|
|
74
|
+
initMockifyerForDashboardProxy as coreInitMockifyerForDashboardProxy,
|
|
75
|
+
initMockifyerForLocalFilesystem as coreInitMockifyerForLocalFilesystem,
|
|
76
|
+
type InitMockifyerForDashboardProxyOptions,
|
|
77
|
+
type InitMockifyerForLocalFilesystemOptions,
|
|
78
|
+
} from './core-proxy';
|
|
77
79
|
|
|
78
80
|
import { FetchHTTPClient } from './clients/fetch-client';
|
|
79
81
|
|
package/src/metro-config.ts
CHANGED
|
@@ -97,6 +97,25 @@ function isMockifyerStubbedModule(moduleName: string): boolean {
|
|
|
97
97
|
);
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/** Metro often resolves `@sgedda/mockifyer-core` to `main` instead of the RN entry. */
|
|
101
|
+
function resolveMockifyerCoreReactNativeEntry(
|
|
102
|
+
moduleName: string,
|
|
103
|
+
platform: string | null
|
|
104
|
+
): { filePath: string; type: 'sourceFile' } | null {
|
|
105
|
+
if (moduleName !== '@sgedda/mockifyer-core') {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
if (platform === 'web') {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const filePath = require.resolve('@sgedda/mockifyer-core/dist/index.react-native.js');
|
|
113
|
+
return { filePath, type: 'sourceFile' };
|
|
114
|
+
} catch {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
100
119
|
/**
|
|
101
120
|
* Options for configuring Metro for Mockifyer
|
|
102
121
|
*/
|
|
@@ -201,6 +220,11 @@ export function configureMetroForMockifyer(
|
|
|
201
220
|
};
|
|
202
221
|
}
|
|
203
222
|
|
|
223
|
+
const mockifyerCoreRn = resolveMockifyerCoreReactNativeEntry(moduleName, platform);
|
|
224
|
+
if (mockifyerCoreRn) {
|
|
225
|
+
return mockifyerCoreRn;
|
|
226
|
+
}
|
|
227
|
+
|
|
204
228
|
// Call existing resolver if present
|
|
205
229
|
if (existingResolveRequest) {
|
|
206
230
|
const result = existingResolveRequest(context, moduleName, platform);
|
package/tsconfig.json
CHANGED
|
@@ -11,7 +11,11 @@
|
|
|
11
11
|
"skipLibCheck": true,
|
|
12
12
|
"forceConsistentCasingInFileNames": true,
|
|
13
13
|
"resolveJsonModule": true,
|
|
14
|
-
"moduleResolution": "node"
|
|
14
|
+
"moduleResolution": "node",
|
|
15
|
+
"baseUrl": ".",
|
|
16
|
+
"paths": {
|
|
17
|
+
"@sgedda/mockifyer-core/utils/*": ["../mockifyer-core/dist/utils/*"]
|
|
18
|
+
}
|
|
15
19
|
},
|
|
16
20
|
"include": ["src/**/*"],
|
|
17
21
|
"exclude": ["node_modules", "dist"]
|