@sgedda/mockifyer-fetch 1.8.24 → 1.8.26

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.
@@ -7,6 +7,7 @@ export declare class FetchHTTPClient extends BaseHTTPClient<any, HTTPResponse<an
7
7
  private proxyScenario?;
8
8
  private proxyRecordOnMiss;
9
9
  private getClientId?;
10
+ private getStrictLaneScenario?;
10
11
  private clientIdSnapshot?;
11
12
  private deviceId?;
12
13
  constructor(config?: {
@@ -16,9 +17,11 @@ export declare class FetchHTTPClient extends BaseHTTPClient<any, HTTPResponse<an
16
17
  baseUrl: string;
17
18
  scenario?: string;
18
19
  recordOnMiss?: boolean;
20
+ strictLaneScenario?: boolean;
19
21
  };
20
22
  clientId?: string;
21
23
  getClientId?: () => string | undefined;
24
+ getStrictLaneScenario?: () => boolean;
22
25
  deviceId?: string;
23
26
  });
24
27
  private resolvedClientLane;
@@ -13,6 +13,7 @@ class FetchHTTPClient extends mockifyer_core_1.BaseHTTPClient {
13
13
  this.proxyScenario = config?.proxy?.scenario;
14
14
  this.proxyRecordOnMiss = config?.proxy?.recordOnMiss ?? false;
15
15
  this.getClientId = config?.getClientId;
16
+ this.getStrictLaneScenario = config?.getStrictLaneScenario;
16
17
  this.clientIdSnapshot = config?.clientId;
17
18
  this.deviceId = config?.deviceId;
18
19
  }
@@ -94,6 +95,7 @@ class FetchHTTPClient extends mockifyer_core_1.BaseHTTPClient {
94
95
  body: config.data ?? null,
95
96
  scenario: this.proxyScenario,
96
97
  record: this.proxyRecordOnMiss,
98
+ strictLaneScenario: this.getStrictLaneScenario?.() ?? true,
97
99
  }),
98
100
  });
99
101
  if (!proxyResponse.ok) {
package/dist/index.js CHANGED
@@ -97,11 +97,7 @@ class MockifyerClass {
97
97
  else {
98
98
  this.config.clientId = (0, mockifyer_core_1.resolveClientId)(this.config);
99
99
  }
100
- mockifyer_core_2.logger.info(`[Mockifyer-Fetch] clientId: ${this.config.clientId}`);
101
100
  this.activationMode = (0, mockifyer_core_1.resolveActivationMode)(this.config);
102
- if (this.activationMode !== 'always') {
103
- mockifyer_core_2.logger.info(`[Mockifyer-Fetch] activationMode: ${this.activationMode}`);
104
- }
105
101
  // Initialize test generator if test generation is enabled
106
102
  if (config.generateTests?.enabled) {
107
103
  this.testGenerator = new mockifyer_core_1.TestGenerator();
@@ -137,6 +133,7 @@ class MockifyerClass {
137
133
  proxy: config.proxy,
138
134
  clientId: this.config.clientId,
139
135
  getClientId: () => this.config.clientId,
136
+ getStrictLaneScenario: () => (0, mockifyer_core_1.resolveProxyStrictLaneScenario)(this.config),
140
137
  deviceId: this.config.deviceId,
141
138
  });
142
139
  if (!config.recordSameEndpoints) {
@@ -146,6 +143,10 @@ class MockifyerClass {
146
143
  this.setupMockResponses();
147
144
  // Set up response interceptor to save responses when recordMode is enabled
148
145
  this.setupResponseInterceptor();
146
+ (0, mockifyer_core_1.logMockifyerInitSummary)(this.config, {
147
+ runtimeMode: this.config.runtimeMode,
148
+ headline: this.config.initLog?.headline,
149
+ });
149
150
  }
150
151
  ensureMockDataDirectory() {
151
152
  // Only use fs if available (Node.js environment) and no database provider is set
@@ -1024,6 +1025,7 @@ function setupMockifyer(config) {
1024
1025
  extendedClient.clearAllMocks = () => mockifyer.clearAllMocks();
1025
1026
  extendedClient.setClientId = (lane) => mockifyer.setClientId(lane);
1026
1027
  extendedClient.getClientId = () => mockifyer.getClientId();
1028
+ (0, mockifyer_core_1.registerMockifyerInstance)(extendedClient);
1027
1029
  return extendedClient;
1028
1030
  }
1029
1031
  // Re-export types from core
@@ -97,4 +97,4 @@ export interface ReactNativeMockifyerConfig {
97
97
  * ```
98
98
  */
99
99
  export declare function setupMockifyerForReactNative(options: ReactNativeMockifyerConfig): Promise<SetupMockifyerForReactNativeResult>;
100
- export { tryGetClientIdFromLaunchArguments, MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY } from '@sgedda/mockifyer-core';
100
+ export { tryGetClientIdFromLaunchArguments, MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY, getClientId, setClientId, registerMockifyerInstance, clearMockifyerClientIdRuntime, } from '@sgedda/mockifyer-core';
@@ -6,7 +6,7 @@
6
6
  * conditional provider selection (FileSystem in dev, Memory in prod)
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY = exports.tryGetClientIdFromLaunchArguments = void 0;
9
+ exports.clearMockifyerClientIdRuntime = exports.registerMockifyerInstance = exports.setClientId = exports.getClientId = exports.MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY = exports.tryGetClientIdFromLaunchArguments = void 0;
10
10
  exports.isMockifyerReactNativeActive = isMockifyerReactNativeActive;
11
11
  exports.setupMockifyerForReactNative = setupMockifyerForReactNative;
12
12
  const join_proxy_dashboard_api_url_1 = require("./utils/join-proxy-dashboard-api-url");
@@ -111,20 +111,18 @@ async function setupMockifyerForReactNative(options) {
111
111
  }
112
112
  : {}),
113
113
  };
114
+ const devInitHeadline = (strictProxy) => strictProxy
115
+ ? 'React Native dev · dashboard Redis proxy'
116
+ : 'React Native dev · hybrid (device + Metro)';
114
117
  const isEnabled = resolvedRuntimeMode === 'on' ||
115
118
  (resolvedRuntimeMode === 'launch_client' && Boolean(clientIdFromLaunchArgs));
116
119
  if (!isEnabled) {
117
- const hint = resolvedRuntimeMode === 'off'
118
- ? 'MOCKIFYER_MODE=off (or runtimeMode off) — launch args are ignored.'
119
- : resolvedRuntimeMode === 'launch_client'
120
- ? 'MOCKIFYER_MODE=launch_client — pass mockifyerClientId via launch args, or set MOCKIFYER_MODE=on for always-on dev.'
121
- : 'Adjust MOCKIFYER_MODE / runtimeMode.';
122
- mockifyer_core_2.logger.info(`[Mockifyer] Not activated (${hint})`);
120
+ (0, mockifyer_core_2.logMockifyerNotActivated)(resolvedRuntimeMode, {
121
+ launchClientIdKey,
122
+ hadLaunchClientId: Boolean(clientIdFromLaunchArgs),
123
+ });
123
124
  return { status: 'not_activated', instance: null };
124
125
  }
125
- if (clientIdFromLaunchArgs && !useLaunchArgumentsClientId) {
126
- mockifyer_core_2.logger.info(`[Mockifyer] Enabled via launch argument "${launchClientIdKey}" (E2E lane "${clientIdFromLaunchArgs}")`);
127
- }
128
126
  if (isDev === true) {
129
127
  const strictProxyEnabled = await canUseStrictRedisProxy(proxyBaseUrl);
130
128
  // DEVELOPMENT MODE (React Native app running in dev)
@@ -166,17 +164,10 @@ async function setupMockifyerForReactNative(options) {
166
164
  ? { baseUrl: proxyBaseUrl, scenario: proxyScenario, recordOnMiss: proxyShouldRecordOnMiss }
167
165
  : undefined,
168
166
  ...mergedConfig,
167
+ initLog: { headline: mergedConfig.initLog?.headline ?? devInitHeadline(strictProxyEnabled) },
169
168
  });
170
- if (strictProxyEnabled) {
171
- mockifyer_core_2.logger.info('[Mockifyer] Development mode: Strict proxy enabled (dashboard Redis is healthy) — local mocks disabled');
172
- }
173
- else {
174
- mockifyer_core_2.logger.info('[Mockifyer] Development mode: Using Hybrid provider (device + project folder)');
175
- mockifyer_core_2.logger.info(`[Mockifyer] Metro endpoint: http://localhost:${metroPort}/mockifyer-save`);
176
- mockifyer_core_2.logger.info(`[Mockifyer] Project→device sync: /mockifyer-sync-to-device-manifest + per-file fetch (on reloadMockData); Metro port ${metroPort}`);
177
- }
178
- if (recordMode) {
179
- mockifyer_core_2.logger.info('[Mockifyer] Recording mode enabled - new API responses will be saved');
169
+ if (!strictProxyEnabled) {
170
+ mockifyer_core_2.logger.info(`[Mockifyer] Metro: http://localhost:${metroPort}/mockifyer-save · scenario: /mockifyer-scenario-config`);
180
171
  }
181
172
  if (!strictProxyEnabled) {
182
173
  // Pull repo mock-data onto device once Metro + provider are ready (HybridProvider.reload)
@@ -215,11 +206,18 @@ async function setupMockifyerForReactNative(options) {
215
206
  ? { baseUrl: proxyBaseUrl, scenario: proxyScenario, recordOnMiss: proxyShouldRecordOnMiss }
216
207
  : undefined,
217
208
  ...mergedConfig,
209
+ initLog: {
210
+ headline: mergedConfig.initLog?.headline ??
211
+ `React Native production · ${mockDataArray.length} bundled mock(s)`,
212
+ },
218
213
  });
219
- mockifyer_core_2.logger.info(`[Mockifyer] Production mode: Loaded ${mockDataArray.length} mocks from bundle`);
220
214
  return { status: 'active', instance };
221
215
  }
222
216
  }
223
217
  var mockifyer_core_3 = require("@sgedda/mockifyer-core");
224
218
  Object.defineProperty(exports, "tryGetClientIdFromLaunchArguments", { enumerable: true, get: function () { return mockifyer_core_3.tryGetClientIdFromLaunchArguments; } });
225
219
  Object.defineProperty(exports, "MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY", { enumerable: true, get: function () { return mockifyer_core_3.MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY; } });
220
+ Object.defineProperty(exports, "getClientId", { enumerable: true, get: function () { return mockifyer_core_3.getClientId; } });
221
+ Object.defineProperty(exports, "setClientId", { enumerable: true, get: function () { return mockifyer_core_3.setClientId; } });
222
+ Object.defineProperty(exports, "registerMockifyerInstance", { enumerable: true, get: function () { return mockifyer_core_3.registerMockifyerInstance; } });
223
+ Object.defineProperty(exports, "clearMockifyerClientIdRuntime", { enumerable: true, get: function () { return mockifyer_core_3.clearMockifyerClientIdRuntime; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sgedda/mockifyer-fetch",
3
- "version": "1.8.24",
3
+ "version": "1.8.26",
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.8.29"
52
+ "@sgedda/mockifyer-core": "^1.8.31"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^20.11.24",
@@ -15,15 +15,17 @@ export class FetchHTTPClient extends BaseHTTPClient<any, HTTPResponse<any>> {
15
15
  private proxyScenario?: string;
16
16
  private proxyRecordOnMiss: boolean;
17
17
  private getClientId?: () => string | undefined;
18
+ private getStrictLaneScenario?: () => boolean;
18
19
  private clientIdSnapshot?: string;
19
20
  private deviceId?: string;
20
21
 
21
22
  constructor(config?: {
22
23
  baseUrl?: string;
23
24
  defaultHeaders?: Record<string, string>;
24
- proxy?: { baseUrl: string; scenario?: string; recordOnMiss?: boolean };
25
+ proxy?: { baseUrl: string; scenario?: string; recordOnMiss?: boolean; strictLaneScenario?: boolean };
25
26
  clientId?: string;
26
27
  getClientId?: () => string | undefined;
28
+ getStrictLaneScenario?: () => boolean;
27
29
  deviceId?: string;
28
30
  }) {
29
31
  super();
@@ -33,6 +35,7 @@ export class FetchHTTPClient extends BaseHTTPClient<any, HTTPResponse<any>> {
33
35
  this.proxyScenario = config?.proxy?.scenario;
34
36
  this.proxyRecordOnMiss = config?.proxy?.recordOnMiss ?? false;
35
37
  this.getClientId = config?.getClientId;
38
+ this.getStrictLaneScenario = config?.getStrictLaneScenario;
36
39
  this.clientIdSnapshot = config?.clientId;
37
40
  this.deviceId = config?.deviceId;
38
41
  }
@@ -122,6 +125,7 @@ export class FetchHTTPClient extends BaseHTTPClient<any, HTTPResponse<any>> {
122
125
  body: config.data ?? null,
123
126
  scenario: this.proxyScenario,
124
127
  record: this.proxyRecordOnMiss,
128
+ strictLaneScenario: this.getStrictLaneScenario?.() ?? true,
125
129
  }),
126
130
  });
127
131
  if (!proxyResponse.ok) {
package/src/index.ts CHANGED
@@ -38,6 +38,9 @@ import {
38
38
  shouldExcludeUrl,
39
39
  mockPassesThroughToRealApi,
40
40
  resolveClientId,
41
+ resolveProxyStrictLaneScenario,
42
+ registerMockifyerInstance,
43
+ logMockifyerInitSummary,
41
44
  tryGetClientIdFromLaunchArguments,
42
45
  MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY,
43
46
  resolveActivationMode,
@@ -131,12 +134,7 @@ class MockifyerClass {
131
134
  } else {
132
135
  this.config.clientId = resolveClientId(this.config);
133
136
  }
134
- logger.info(`[Mockifyer-Fetch] clientId: ${this.config.clientId}`);
135
-
136
137
  this.activationMode = resolveActivationMode(this.config);
137
- if (this.activationMode !== 'always') {
138
- logger.info(`[Mockifyer-Fetch] activationMode: ${this.activationMode}`);
139
- }
140
138
 
141
139
  // Initialize test generator if test generation is enabled
142
140
  if (config.generateTests?.enabled) {
@@ -169,12 +167,13 @@ class MockifyerClass {
169
167
  }
170
168
 
171
169
  // Create fetch HTTP client
172
- this.httpClient = new FetchHTTPClient({
173
- baseUrl: config.baseUrl,
170
+ this.httpClient = new FetchHTTPClient({
171
+ baseUrl: config.baseUrl,
174
172
  defaultHeaders: config.defaultHeaders,
175
173
  proxy: config.proxy,
176
174
  clientId: this.config.clientId,
177
175
  getClientId: () => this.config.clientId,
176
+ getStrictLaneScenario: () => resolveProxyStrictLaneScenario(this.config),
178
177
  deviceId: (this.config as any).deviceId,
179
178
  });
180
179
 
@@ -186,6 +185,11 @@ class MockifyerClass {
186
185
 
187
186
  // Set up response interceptor to save responses when recordMode is enabled
188
187
  this.setupResponseInterceptor();
188
+
189
+ logMockifyerInitSummary(this.config, {
190
+ runtimeMode: this.config.runtimeMode,
191
+ headline: this.config.initLog?.headline,
192
+ });
189
193
  }
190
194
 
191
195
  private ensureMockDataDirectory(): void {
@@ -1211,7 +1215,9 @@ export function setupMockifyer(config: MockifyerConfig): MockifyerInstance {
1211
1215
  extendedClient.clearAllMocks = () => mockifyer.clearAllMocks();
1212
1216
  extendedClient.setClientId = (lane: string) => mockifyer.setClientId(lane);
1213
1217
  extendedClient.getClientId = () => mockifyer.getClientId();
1214
-
1218
+
1219
+ registerMockifyerInstance(extendedClient);
1220
+
1215
1221
  return extendedClient;
1216
1222
  }
1217
1223
 
@@ -13,6 +13,7 @@ import {
13
13
  MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY,
14
14
  tryGetClientIdFromLaunchArguments,
15
15
  resolveMockifyerRuntimeMode,
16
+ logMockifyerNotActivated,
16
17
  type MockifyerRuntimeMode,
17
18
  } from '@sgedda/mockifyer-core';
18
19
 
@@ -210,26 +211,22 @@ export async function setupMockifyerForReactNative(
210
211
  : {}),
211
212
  };
212
213
 
214
+ const devInitHeadline = (strictProxy: boolean) =>
215
+ strictProxy
216
+ ? 'React Native dev · dashboard Redis proxy'
217
+ : 'React Native dev · hybrid (device + Metro)';
218
+
213
219
  const isEnabled =
214
220
  resolvedRuntimeMode === 'on' ||
215
221
  (resolvedRuntimeMode === 'launch_client' && Boolean(clientIdFromLaunchArgs));
216
222
  if (!isEnabled) {
217
- const hint =
218
- resolvedRuntimeMode === 'off'
219
- ? 'MOCKIFYER_MODE=off (or runtimeMode off) — launch args are ignored.'
220
- : resolvedRuntimeMode === 'launch_client'
221
- ? 'MOCKIFYER_MODE=launch_client — pass mockifyerClientId via launch args, or set MOCKIFYER_MODE=on for always-on dev.'
222
- : 'Adjust MOCKIFYER_MODE / runtimeMode.';
223
- logger.info(`[Mockifyer] Not activated (${hint})`);
223
+ logMockifyerNotActivated(resolvedRuntimeMode, {
224
+ launchClientIdKey,
225
+ hadLaunchClientId: Boolean(clientIdFromLaunchArgs),
226
+ });
224
227
  return { status: 'not_activated', instance: null } as const;
225
228
  }
226
229
 
227
- if (clientIdFromLaunchArgs && !useLaunchArgumentsClientId) {
228
- logger.info(
229
- `[Mockifyer] Enabled via launch argument "${launchClientIdKey}" (E2E lane "${clientIdFromLaunchArgs}")`
230
- );
231
- }
232
-
233
230
  if (isDev === true) {
234
231
  const strictProxyEnabled = await canUseStrictRedisProxy(proxyBaseUrl);
235
232
 
@@ -275,19 +272,11 @@ export async function setupMockifyerForReactNative(
275
272
  ? { baseUrl: proxyBaseUrl, scenario: proxyScenario, recordOnMiss: proxyShouldRecordOnMiss }
276
273
  : undefined,
277
274
  ...mergedConfig,
275
+ initLog: { headline: mergedConfig.initLog?.headline ?? devInitHeadline(strictProxyEnabled) },
278
276
  });
279
277
 
280
- if (strictProxyEnabled) {
281
- logger.info('[Mockifyer] Development mode: Strict proxy enabled (dashboard Redis is healthy) — local mocks disabled');
282
- } else {
283
- logger.info('[Mockifyer] Development mode: Using Hybrid provider (device + project folder)');
284
- logger.info(`[Mockifyer] Metro endpoint: http://localhost:${metroPort}/mockifyer-save`);
285
- logger.info(
286
- `[Mockifyer] Project→device sync: /mockifyer-sync-to-device-manifest + per-file fetch (on reloadMockData); Metro port ${metroPort}`
287
- );
288
- }
289
- if (recordMode) {
290
- logger.info('[Mockifyer] Recording mode enabled - new API responses will be saved');
278
+ if (!strictProxyEnabled) {
279
+ logger.info(`[Mockifyer] Metro: http://localhost:${metroPort}/mockifyer-save · scenario: /mockifyer-scenario-config`);
291
280
  }
292
281
 
293
282
  if (!strictProxyEnabled) {
@@ -332,12 +321,23 @@ export async function setupMockifyerForReactNative(
332
321
  ? { baseUrl: proxyBaseUrl, scenario: proxyScenario, recordOnMiss: proxyShouldRecordOnMiss }
333
322
  : undefined,
334
323
  ...mergedConfig,
324
+ initLog: {
325
+ headline:
326
+ mergedConfig.initLog?.headline ??
327
+ `React Native production · ${mockDataArray.length} bundled mock(s)`,
328
+ },
335
329
  });
336
330
 
337
- logger.info(`[Mockifyer] Production mode: Loaded ${mockDataArray.length} mocks from bundle`);
338
331
  return { status: 'active', instance } as const;
339
332
  }
340
333
  }
341
334
 
342
- export { tryGetClientIdFromLaunchArguments, MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY } from '@sgedda/mockifyer-core';
335
+ export {
336
+ tryGetClientIdFromLaunchArguments,
337
+ MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY,
338
+ getClientId,
339
+ setClientId,
340
+ registerMockifyerInstance,
341
+ clearMockifyerClientIdRuntime,
342
+ } from '@sgedda/mockifyer-core';
343
343