@sgedda/mockifyer-fetch 1.8.72 → 1.8.85
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.d.ts +3 -0
- package/dist/index.js +92 -8
- package/dist/metro-atlas-key-handlers.d.ts +113 -0
- package/dist/metro-atlas-key-handlers.js +436 -0
- package/dist/metro-config.d.ts +3 -0
- package/dist/metro-config.js +31 -3
- package/dist/metro-sync-middleware.d.ts +19 -0
- package/dist/metro-sync-middleware.js +54 -11
- package/dist/react-native.d.ts +26 -2
- package/dist/react-native.js +39 -21
- package/package.json +2 -2
- package/src/index.ts +130 -11
- package/src/metro-atlas-key-handlers.ts +503 -0
- package/src/metro-config.ts +31 -3
- package/src/metro-sync-middleware.ts +92 -20
- package/src/react-native.ts +78 -24
package/dist/react-native.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { setupMockifyer } from './index';
|
|
8
8
|
import { HTTPClient } from '@sgedda/mockifyer-core';
|
|
9
|
-
import { type MockifyerRuntimeMode } from '@sgedda/mockifyer-core';
|
|
9
|
+
import { type MockifyerRuntimeMode, type MockifyerRuntimeEnabledStorage } from '@sgedda/mockifyer-core';
|
|
10
10
|
export { setupMockifyer } from './index';
|
|
11
11
|
export * from '@sgedda/mockifyer-core';
|
|
12
12
|
export interface MockifyerInstance extends HTTPClient {
|
|
@@ -15,6 +15,9 @@ export interface MockifyerInstance extends HTTPClient {
|
|
|
15
15
|
clearAllMocks: () => Promise<void>;
|
|
16
16
|
setClientId: (lane: string) => void;
|
|
17
17
|
getClientId: () => string | undefined;
|
|
18
|
+
enableMockifyer: () => void;
|
|
19
|
+
disableMockifyer: () => void;
|
|
20
|
+
isMockifyerEnabled: () => boolean;
|
|
18
21
|
}
|
|
19
22
|
/**
|
|
20
23
|
* Outcome of {@link setupMockifyerForReactNative}.
|
|
@@ -51,9 +54,27 @@ export interface ReactNativeMockifyerConfig {
|
|
|
51
54
|
bundledDataPath?: string;
|
|
52
55
|
/** Enable recording mode (development only) */
|
|
53
56
|
recordMode?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* When true, Mockifyer starts disabled (all requests bypass).
|
|
59
|
+
* Use `instance.enableMockifyer()` to turn it on via GUI.
|
|
60
|
+
*
|
|
61
|
+
* **Prefer `runtimeMode: 'manual'`** for clearer intent.
|
|
62
|
+
*
|
|
63
|
+
* Default: false (starts enabled).
|
|
64
|
+
*/
|
|
65
|
+
startDisabled?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Persist enable/disable across app restarts (AsyncStorage when `true`).
|
|
68
|
+
* With `runtimeMode: 'manual'`, first launch is off; after the user enables,
|
|
69
|
+
* the next launch stays on.
|
|
70
|
+
*/
|
|
71
|
+
persistRuntimeEnabled?: boolean | MockifyerRuntimeEnabledStorage;
|
|
54
72
|
/**
|
|
55
73
|
* When true, reads `scenario` from `react-native-launch-arguments` (optional peer).
|
|
56
74
|
* Highest priority over MOCKIFYER_SCENARIO, config.scenarios, Metro scenario sync, and scenario-config.json.
|
|
75
|
+
* When a launch `scenario` is present, Mockifyer also **starts enabled** (even with `runtimeMode: 'manual'`).
|
|
76
|
+
* Set to `false` to ignore launch scenario args entirely.
|
|
77
|
+
* Default: auto-detect when a non-empty launch `scenario` is present.
|
|
57
78
|
*/
|
|
58
79
|
useLaunchArgumentsScenario?: boolean;
|
|
59
80
|
/**
|
|
@@ -93,7 +114,10 @@ export interface ReactNativeMockifyerConfig {
|
|
|
93
114
|
launchArgumentClientIdKey?: string;
|
|
94
115
|
/**
|
|
95
116
|
* When Mockifyer may patch `fetch` at startup. Overrides **`MOCKIFYER_MODE`** env and `config.runtimeMode`.
|
|
96
|
-
* Prefer env **`MOCKIFYER_MODE`**: `off` | `on` | `launch_client`
|
|
117
|
+
* Prefer env **`MOCKIFYER_MODE`**: `off` | `on` | `launch_client` | `manual`.
|
|
118
|
+
*
|
|
119
|
+
* Use **`manual`** to patch but start disabled (enable via GUI toggle).
|
|
120
|
+
* Aliases: `e2e`, `maestro` → `launch_client`; `gui`, `toggle` → `manual`.
|
|
97
121
|
*/
|
|
98
122
|
runtimeMode?: MockifyerRuntimeMode;
|
|
99
123
|
}
|
package/dist/react-native.js
CHANGED
|
@@ -41,32 +41,26 @@ function isMockifyerReactNativeActive(result) {
|
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Apply scenario from launch arguments and/or defaultScenario (highest priority in getCurrentScenario).
|
|
44
|
+
* @returns `true` when a native launch-argument `scenario` was applied (forces runtime toggle on).
|
|
44
45
|
*/
|
|
45
46
|
function applyReactNativeScenarioOptions(options) {
|
|
46
|
-
let
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const raw = LaunchArguments && typeof LaunchArguments.value === 'function' ? LaunchArguments.value() : undefined;
|
|
54
|
-
const scenario = raw?.scenario;
|
|
55
|
-
if (scenario !== undefined && scenario !== null && String(scenario).trim() !== '') {
|
|
56
|
-
(0, mockifyer_core_1.setScenarioLaunchOverride)(String(scenario).trim());
|
|
57
|
-
applied = true;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
// Package not installed or native module unavailable
|
|
47
|
+
let appliedFromLaunchArgs = false;
|
|
48
|
+
// Auto-detect launch `scenario` when present (E2E). Opt out with useLaunchArgumentsScenario: false.
|
|
49
|
+
if (options.useLaunchArgumentsScenario !== false) {
|
|
50
|
+
const scenarioFromLaunch = (0, mockifyer_core_2.tryGetScenarioFromLaunchArguments)();
|
|
51
|
+
if (scenarioFromLaunch) {
|
|
52
|
+
(0, mockifyer_core_1.setScenarioLaunchOverride)(scenarioFromLaunch, { fromLaunchArguments: true });
|
|
53
|
+
appliedFromLaunchArgs = true;
|
|
62
54
|
}
|
|
63
55
|
}
|
|
64
|
-
if (!
|
|
56
|
+
if (!appliedFromLaunchArgs && options.defaultScenario !== undefined && options.defaultScenario !== null) {
|
|
65
57
|
const t = String(options.defaultScenario).trim();
|
|
66
58
|
if (t !== '') {
|
|
59
|
+
// App config default — not a native launch arg; do not force runtime toggle on.
|
|
67
60
|
(0, mockifyer_core_1.setScenarioLaunchOverride)(t);
|
|
68
61
|
}
|
|
69
62
|
}
|
|
63
|
+
return appliedFromLaunchArgs;
|
|
70
64
|
}
|
|
71
65
|
// Lazy load bundled data (only used in production builds)
|
|
72
66
|
let bundledMockData = null;
|
|
@@ -125,7 +119,7 @@ async function loadBundledMockData(bundledDataPath) {
|
|
|
125
119
|
* ```
|
|
126
120
|
*/
|
|
127
121
|
async function setupMockifyerForReactNative(options) {
|
|
128
|
-
const { isDev, mockDataPath = 'mock-data', bundledDataPath = './assets/mock-data', recordMode = false, config: userConfig = {}, proxyBaseUrl, proxyScenario, proxyRecordOnMiss, proxyRecordResponses, skipDashboardRedisHealthCheck, useLaunchArgumentsClientId = false, launchArgumentClientIdKey = mockifyer_core_2.MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY, runtimeMode: runtimeModeOption, } = options;
|
|
122
|
+
const { isDev, mockDataPath = 'mock-data', bundledDataPath = './assets/mock-data', recordMode = false, startDisabled = false, persistRuntimeEnabled, config: userConfig = {}, proxyBaseUrl, proxyScenario, proxyRecordOnMiss, proxyRecordResponses, skipDashboardRedisHealthCheck, useLaunchArgumentsClientId = false, launchArgumentClientIdKey = mockifyer_core_2.MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY, runtimeMode: runtimeModeOption, } = options;
|
|
129
123
|
const proxyShouldRecordOnMiss = proxyRecordOnMiss ?? recordMode;
|
|
130
124
|
const proxyShouldRecordResponses = (0, mockifyer_core_2.resolveRecordResponses)(proxyRecordResponses ?? userConfig.proxy?.recordResponses);
|
|
131
125
|
const launchClientIdKey = launchArgumentClientIdKey ?? mockifyer_core_2.MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY;
|
|
@@ -134,9 +128,27 @@ async function setupMockifyerForReactNative(options) {
|
|
|
134
128
|
const resolvedRuntimeMode = (0, mockifyer_core_2.resolveMockifyerRuntimeMode)({
|
|
135
129
|
configMode: runtimeModeOption ?? userConfig.runtimeMode,
|
|
136
130
|
});
|
|
131
|
+
const persistOption = persistRuntimeEnabled ?? userConfig.persistRuntimeEnabled;
|
|
132
|
+
const runtimeEnabledStorage = (0, mockifyer_core_2.resolveRuntimeEnabledStorage)(persistOption);
|
|
133
|
+
let initialRuntimeEnabled = userConfig.initialRuntimeEnabled;
|
|
134
|
+
if (runtimeEnabledStorage && typeof initialRuntimeEnabled !== 'boolean') {
|
|
135
|
+
const saved = await (0, mockifyer_core_2.loadPersistedRuntimeEnabled)(runtimeEnabledStorage);
|
|
136
|
+
if (typeof saved === 'boolean') {
|
|
137
|
+
initialRuntimeEnabled = saved;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Apply scenario launch override early so we know if E2E forced a scenario.
|
|
141
|
+
const launchScenarioApplied = applyReactNativeScenarioOptions(options);
|
|
142
|
+
if (launchScenarioApplied) {
|
|
143
|
+
// Launch `scenario` arg → start enabled (wins over persisted off for this session).
|
|
144
|
+
initialRuntimeEnabled = true;
|
|
145
|
+
mockifyer_core_2.logger.info('[Mockifyer] Launch argument scenario present — starting with Mockifyer ENABLED');
|
|
146
|
+
}
|
|
137
147
|
const mergedConfig = {
|
|
138
148
|
...userConfig,
|
|
139
149
|
runtimeMode: resolvedRuntimeMode,
|
|
150
|
+
...(persistOption !== undefined ? { persistRuntimeEnabled: persistOption } : {}),
|
|
151
|
+
...(typeof initialRuntimeEnabled === 'boolean' ? { initialRuntimeEnabled } : {}),
|
|
140
152
|
...(shouldApplyLaunchClientId
|
|
141
153
|
? {
|
|
142
154
|
useLaunchArgumentsClientId: true,
|
|
@@ -152,8 +164,13 @@ async function setupMockifyerForReactNative(options) {
|
|
|
152
164
|
}
|
|
153
165
|
return 'React Native dev · hybrid (device + Metro)';
|
|
154
166
|
};
|
|
155
|
-
|
|
156
|
-
|
|
167
|
+
// Patch fetch for on / manual; launch_client only when lane id is present.
|
|
168
|
+
// Launch `scenario` forces runtime toggle on after activation — it does not replace client id.
|
|
169
|
+
const isEnabled = (0, mockifyer_core_2.shouldActivateMockifyerForReactNative)({
|
|
170
|
+
runtimeMode: resolvedRuntimeMode,
|
|
171
|
+
hasLaunchClientId: Boolean(clientIdFromLaunchArgs),
|
|
172
|
+
hasLaunchScenario: launchScenarioApplied,
|
|
173
|
+
});
|
|
157
174
|
if (!isEnabled) {
|
|
158
175
|
(0, mockifyer_core_2.logMockifyerNotActivated)(resolvedRuntimeMode, {
|
|
159
176
|
launchClientIdKey,
|
|
@@ -161,7 +178,6 @@ async function setupMockifyerForReactNative(options) {
|
|
|
161
178
|
});
|
|
162
179
|
return { status: 'not_activated', instance: null };
|
|
163
180
|
}
|
|
164
|
-
applyReactNativeScenarioOptions(options);
|
|
165
181
|
if (isDev === true) {
|
|
166
182
|
const strictProxyEnabled = proxyBaseUrl
|
|
167
183
|
? skipDashboardRedisHealthCheck === true ||
|
|
@@ -210,6 +226,7 @@ async function setupMockifyerForReactNative(options) {
|
|
|
210
226
|
: databaseProviderConfig,
|
|
211
227
|
recordMode,
|
|
212
228
|
useGlobalFetch: true,
|
|
229
|
+
startDisabled,
|
|
213
230
|
proxy: strictProxyEnabled && proxyBaseUrl
|
|
214
231
|
? {
|
|
215
232
|
baseUrl: proxyBaseUrl,
|
|
@@ -271,6 +288,7 @@ async function setupMockifyerForReactNative(options) {
|
|
|
271
288
|
},
|
|
272
289
|
recordMode: false, // Can't record in production builds
|
|
273
290
|
useGlobalFetch: true,
|
|
291
|
+
startDisabled,
|
|
274
292
|
proxy: proxyBaseUrl
|
|
275
293
|
? {
|
|
276
294
|
baseUrl: proxyBaseUrl,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sgedda/mockifyer-fetch",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.85",
|
|
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.162"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/node": "^20.11.24",
|
package/src/index.ts
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
getScenarioFolderPath,
|
|
32
32
|
ensureScenarioFolder,
|
|
33
33
|
initializeScenario,
|
|
34
|
+
isScenarioLaunchFromNativeArguments,
|
|
34
35
|
TestGenerator,
|
|
35
36
|
TestGenerationOptions,
|
|
36
37
|
checkRequestLimit,
|
|
@@ -74,7 +75,8 @@ import {
|
|
|
74
75
|
networkEventHashFromRequestKey,
|
|
75
76
|
recordInlineTraceHopFromExchange,
|
|
76
77
|
unwrapAndMergeInlineTraceEnvelope,
|
|
77
|
-
|
|
78
|
+
unwrapInlineTraceEnvelopeEmittingNetworkEvents,
|
|
79
|
+
resolveNetworkLogIncludeTraceOptions,
|
|
78
80
|
getInlineTraceEnvelopeBusinessBody,
|
|
79
81
|
resolveRecordResponses,
|
|
80
82
|
applyOutboundRequestCorrelation,
|
|
@@ -91,6 +93,10 @@ import {
|
|
|
91
93
|
DomainPathRulesSession,
|
|
92
94
|
installNodeInboundRequestCorrelationCapture,
|
|
93
95
|
stripMockifyerTraceFromBody,
|
|
96
|
+
resolveInitialRuntimeEnabled,
|
|
97
|
+
resolveRuntimeEnabledStorage,
|
|
98
|
+
savePersistedRuntimeEnabled,
|
|
99
|
+
type MockifyerRuntimeEnabledStorage,
|
|
94
100
|
} from '@sgedda/mockifyer-core';
|
|
95
101
|
import { logger, setLogLevel } from '@sgedda/mockifyer-core';
|
|
96
102
|
import {
|
|
@@ -131,6 +137,10 @@ class MockifyerClass {
|
|
|
131
137
|
*/
|
|
132
138
|
private readonly poolResponseCache = new Map<string, PoolResponseItem>();
|
|
133
139
|
private readonly domainPathRules: DomainPathRulesSession;
|
|
140
|
+
/** Runtime toggle: when false, all Mockifyer logic is bypassed (no dashboard, Redis, proxy, or mock lookup). */
|
|
141
|
+
private runtimeEnabled: boolean;
|
|
142
|
+
/** Optional storage for persisting enable/disable across restarts. */
|
|
143
|
+
private readonly runtimeEnabledStorage?: MockifyerRuntimeEnabledStorage;
|
|
134
144
|
|
|
135
145
|
/** Session id for timeline hops — per-screen id from {@link setFlightRecorderRuntimeContext} when set. */
|
|
136
146
|
private getRuntimeSessionId(): string {
|
|
@@ -145,6 +155,36 @@ class MockifyerClass {
|
|
|
145
155
|
});
|
|
146
156
|
}
|
|
147
157
|
|
|
158
|
+
private unwrapResponseInlineTrace(response: {
|
|
159
|
+
data?: unknown;
|
|
160
|
+
config?: unknown;
|
|
161
|
+
}): void {
|
|
162
|
+
const correlation = this.readRequestCorrelation(response.config);
|
|
163
|
+
const parentRequestId = correlation?.requestId?.trim();
|
|
164
|
+
if (!parentRequestId) {
|
|
165
|
+
response.data = unwrapAndMergeInlineTraceEnvelope(response.data);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const scenario =
|
|
169
|
+
this.config.proxy?.scenario?.trim() ||
|
|
170
|
+
getCurrentScenario(this.config.mockDataPath);
|
|
171
|
+
response.data = unwrapInlineTraceEnvelopeEmittingNetworkEvents(response.data, {
|
|
172
|
+
parentRequestId,
|
|
173
|
+
config: this.config,
|
|
174
|
+
scenario,
|
|
175
|
+
clientId: this.config.clientId,
|
|
176
|
+
sessionId: this.getRuntimeSessionId(),
|
|
177
|
+
transport: this.usesDashboardProxy() ? 'proxy' : 'fetch',
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private applyOutboundCorrelation(config: unknown): RequestCorrelationContext {
|
|
182
|
+
return applyOutboundRequestCorrelation(
|
|
183
|
+
config as { headers?: unknown; url?: unknown; method?: unknown },
|
|
184
|
+
resolveNetworkLogIncludeTraceOptions(this.config)
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
148
188
|
/** Best-effort dashboard network log. */
|
|
149
189
|
private logNetworkEvent(
|
|
150
190
|
partial: Parameters<typeof emitMockifyerNetworkEvent>[0]['event'] & {
|
|
@@ -191,12 +231,8 @@ class MockifyerClass {
|
|
|
191
231
|
transport: eventPartial.transport ?? 'fetch',
|
|
192
232
|
requestId: correlation?.requestId ?? eventPartial.requestId,
|
|
193
233
|
parentRequestId: correlation?.parentRequestId ?? eventPartial.parentRequestId,
|
|
194
|
-
requestBodyPreview:
|
|
195
|
-
|
|
196
|
-
(requestBody !== undefined ? toNetworkLogBodyPreview(requestBody) : undefined),
|
|
197
|
-
responseBodyPreview:
|
|
198
|
-
eventPartial.responseBodyPreview ??
|
|
199
|
-
(responseBody !== undefined ? toNetworkLogBodyPreview(businessResponseBody) : undefined),
|
|
234
|
+
requestBodyPreview: eventPartial.requestBodyPreview,
|
|
235
|
+
responseBodyPreview: eventPartial.responseBodyPreview,
|
|
200
236
|
},
|
|
201
237
|
});
|
|
202
238
|
}
|
|
@@ -414,6 +450,41 @@ class MockifyerClass {
|
|
|
414
450
|
}
|
|
415
451
|
this.activationMode = resolveActivationMode(this.config);
|
|
416
452
|
this.domainPathRules = new DomainPathRulesSession({ config: this.config });
|
|
453
|
+
|
|
454
|
+
this.runtimeEnabledStorage = resolveRuntimeEnabledStorage(config.persistRuntimeEnabled);
|
|
455
|
+
if (config.persistRuntimeEnabled === true && !this.runtimeEnabledStorage) {
|
|
456
|
+
logger.warn(
|
|
457
|
+
'[Mockifyer-Fetch] persistRuntimeEnabled: true but no storage found. ' +
|
|
458
|
+
'Install @react-native-async-storage/async-storage (RN) or use a custom { getItem, setItem }.'
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
this.runtimeEnabled = resolveInitialRuntimeEnabled({
|
|
462
|
+
initialRuntimeEnabled: config.initialRuntimeEnabled,
|
|
463
|
+
startDisabled: config.startDisabled,
|
|
464
|
+
runtimeMode: config.runtimeMode,
|
|
465
|
+
launchScenarioPresent: isScenarioLaunchFromNativeArguments(),
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
if (!this.runtimeEnabled) {
|
|
469
|
+
const reason =
|
|
470
|
+
typeof config.initialRuntimeEnabled === 'boolean'
|
|
471
|
+
? 'persisted / initialRuntimeEnabled: false'
|
|
472
|
+
: config.runtimeMode === 'manual'
|
|
473
|
+
? 'runtimeMode: "manual"'
|
|
474
|
+
: 'startDisabled: true';
|
|
475
|
+
logger.info(
|
|
476
|
+
`[Mockifyer-Fetch] Starting with Mockifyer DISABLED (${reason}). Call enableMockifyer() to activate.`
|
|
477
|
+
);
|
|
478
|
+
} else if (isScenarioLaunchFromNativeArguments()) {
|
|
479
|
+
logger.info(
|
|
480
|
+
'[Mockifyer-Fetch] Starting with Mockifyer ENABLED (native launch scenario argument).'
|
|
481
|
+
);
|
|
482
|
+
} else if (typeof config.initialRuntimeEnabled === 'boolean' && config.initialRuntimeEnabled) {
|
|
483
|
+
logger.info(
|
|
484
|
+
'[Mockifyer-Fetch] Starting with Mockifyer ENABLED (restored from persisted preference).'
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
|
|
417
488
|
configureFlightRecorder(resolveFlightRecorderConfig(this.config));
|
|
418
489
|
configureAtlas(this.config, {
|
|
419
490
|
scenario: getCurrentScenario(this.config.mockDataPath, this.config.clientId),
|
|
@@ -744,6 +815,12 @@ class MockifyerClass {
|
|
|
744
815
|
|
|
745
816
|
private setupMockResponses(): void {
|
|
746
817
|
this.httpClient.interceptors.request.use(async (config: any) => {
|
|
818
|
+
// CRITICAL: Runtime toggle — if disabled, bypass all Mockifyer logic
|
|
819
|
+
if (!this.runtimeEnabled) {
|
|
820
|
+
(config as any).__mockifyer_bypass = true;
|
|
821
|
+
return config;
|
|
822
|
+
}
|
|
823
|
+
|
|
747
824
|
// CRITICAL: Completely bypass Mockifyer interception for sync endpoints
|
|
748
825
|
// This prevents any Mockifyer processing (mocking, saving, etc.) for these endpoints
|
|
749
826
|
const url = config.url || '';
|
|
@@ -764,7 +841,7 @@ class MockifyerClass {
|
|
|
764
841
|
useProxyLane: { proxyBaseUrl: this.config.proxy?.baseUrl, resolvedClientId: this.config.clientId },
|
|
765
842
|
})
|
|
766
843
|
) {
|
|
767
|
-
|
|
844
|
+
this.applyOutboundCorrelation(config);
|
|
768
845
|
(config as any).__mockifyer_bypass = true;
|
|
769
846
|
return config;
|
|
770
847
|
}
|
|
@@ -777,7 +854,7 @@ class MockifyerClass {
|
|
|
777
854
|
return config;
|
|
778
855
|
}
|
|
779
856
|
|
|
780
|
-
let correlation =
|
|
857
|
+
let correlation = this.applyOutboundCorrelation(config);
|
|
781
858
|
this.stashRequestCorrelation(config, correlation);
|
|
782
859
|
|
|
783
860
|
// Normalize empty params: treat {} the same as undefined for consistent matching
|
|
@@ -1068,7 +1145,7 @@ class MockifyerClass {
|
|
|
1068
1145
|
},
|
|
1069
1146
|
this.readRequestCorrelation(response.config)
|
|
1070
1147
|
);
|
|
1071
|
-
|
|
1148
|
+
this.unwrapResponseInlineTrace(response);
|
|
1072
1149
|
|
|
1073
1150
|
const capturedResponse: StoredResponse = {
|
|
1074
1151
|
status: response.status,
|
|
@@ -1124,7 +1201,7 @@ class MockifyerClass {
|
|
|
1124
1201
|
},
|
|
1125
1202
|
this.readRequestCorrelation(response.config)
|
|
1126
1203
|
);
|
|
1127
|
-
|
|
1204
|
+
this.unwrapResponseInlineTrace(response);
|
|
1128
1205
|
|
|
1129
1206
|
// Only save locally if recordMode is enabled AND we're not proxying upstream calls.
|
|
1130
1207
|
// When proxy is configured, recording should happen on the proxy (e.g. dashboard → Redis).
|
|
@@ -1678,6 +1755,42 @@ class MockifyerClass {
|
|
|
1678
1755
|
return this.config.clientId;
|
|
1679
1756
|
}
|
|
1680
1757
|
|
|
1758
|
+
/**
|
|
1759
|
+
* Enable Mockifyer at runtime. All subsequent requests will go through Mockifyer
|
|
1760
|
+
* (mock lookup, recording, dashboard/Redis proxy, etc.).
|
|
1761
|
+
* When `persistRuntimeEnabled` is set, the preference is saved for the next app launch.
|
|
1762
|
+
*/
|
|
1763
|
+
enableMockifyer(): void {
|
|
1764
|
+
this.runtimeEnabled = true;
|
|
1765
|
+
logger.info('[Mockifyer-Fetch] Mockifyer enabled at runtime');
|
|
1766
|
+
void this.persistRuntimeEnabledState(true);
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
/**
|
|
1770
|
+
* Disable Mockifyer at runtime. All subsequent requests will bypass Mockifyer completely
|
|
1771
|
+
* (no dashboard, Redis, proxy, mock lookup, or recording).
|
|
1772
|
+
* When `persistRuntimeEnabled` is set, the preference is saved for the next app launch.
|
|
1773
|
+
*/
|
|
1774
|
+
disableMockifyer(): void {
|
|
1775
|
+
this.runtimeEnabled = false;
|
|
1776
|
+
logger.info('[Mockifyer-Fetch] Mockifyer disabled at runtime - all requests will bypass');
|
|
1777
|
+
void this.persistRuntimeEnabledState(false);
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
/**
|
|
1781
|
+
* Check if Mockifyer is currently enabled at runtime.
|
|
1782
|
+
*/
|
|
1783
|
+
isMockifyerEnabled(): boolean {
|
|
1784
|
+
return this.runtimeEnabled;
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
private async persistRuntimeEnabledState(enabled: boolean): Promise<void> {
|
|
1788
|
+
if (!this.runtimeEnabledStorage) {
|
|
1789
|
+
return;
|
|
1790
|
+
}
|
|
1791
|
+
await savePersistedRuntimeEnabled(this.runtimeEnabledStorage, enabled);
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1681
1794
|
getHTTPClient(): HTTPClient {
|
|
1682
1795
|
return this.httpClient;
|
|
1683
1796
|
}
|
|
@@ -1724,6 +1837,9 @@ export interface MockifyerInstance extends HTTPClient {
|
|
|
1724
1837
|
clearAllMocks: () => Promise<void>;
|
|
1725
1838
|
setClientId: (lane: string) => void;
|
|
1726
1839
|
getClientId: () => string | undefined;
|
|
1840
|
+
enableMockifyer: () => void;
|
|
1841
|
+
disableMockifyer: () => void;
|
|
1842
|
+
isMockifyerEnabled: () => boolean;
|
|
1727
1843
|
}
|
|
1728
1844
|
|
|
1729
1845
|
export function setupMockifyer(config: MockifyerConfig): MockifyerInstance {
|
|
@@ -1898,6 +2014,9 @@ export function setupMockifyer(config: MockifyerConfig): MockifyerInstance {
|
|
|
1898
2014
|
extendedClient.clearAllMocks = () => mockifyer.clearAllMocks();
|
|
1899
2015
|
extendedClient.setClientId = (lane: string) => mockifyer.setClientId(lane);
|
|
1900
2016
|
extendedClient.getClientId = () => mockifyer.getClientId();
|
|
2017
|
+
extendedClient.enableMockifyer = () => mockifyer.enableMockifyer();
|
|
2018
|
+
extendedClient.disableMockifyer = () => mockifyer.disableMockifyer();
|
|
2019
|
+
extendedClient.isMockifyerEnabled = () => mockifyer.isMockifyerEnabled();
|
|
1901
2020
|
|
|
1902
2021
|
registerMockifyerInstance(extendedClient);
|
|
1903
2022
|
|