@sgedda/mockifyer-fetch 1.8.18 → 1.8.19
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 +15 -2
- package/dist/react-native.d.ts +9 -0
- package/dist/react-native.js +19 -6
- package/package.json +2 -2
- package/src/index.ts +18 -3
- package/src/react-native.ts +32 -7
package/dist/index.js
CHANGED
|
@@ -80,10 +80,23 @@ class MockifyerClass {
|
|
|
80
80
|
config.useSimilarMatch = true;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
+
let launchClientId;
|
|
84
|
+
if (config.useLaunchArgumentsClientId) {
|
|
85
|
+
const key = config.launchArgumentClientIdKey ?? mockifyer_core_1.MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY;
|
|
86
|
+
launchClientId = (0, mockifyer_core_1.tryGetClientIdFromLaunchArguments)(key);
|
|
87
|
+
if (launchClientId) {
|
|
88
|
+
mockifyer_core_2.logger.info(`[Mockifyer-Fetch] clientId from launch arguments (${key}): ${launchClientId}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
83
91
|
// Store config BEFORE any modifications
|
|
84
92
|
this.config = { ...config }; // Create a copy to avoid mutations
|
|
85
|
-
//
|
|
86
|
-
|
|
93
|
+
// Launch arg wins over MOCKIFYER_CLIENT_ID / config.clientId when present (E2E).
|
|
94
|
+
if (launchClientId) {
|
|
95
|
+
this.config.clientId = launchClientId;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
this.config.clientId = (0, mockifyer_core_1.resolveClientId)(this.config);
|
|
99
|
+
}
|
|
87
100
|
mockifyer_core_2.logger.info(`[Mockifyer-Fetch] clientId: ${this.config.clientId}`);
|
|
88
101
|
// Initialize test generator if test generation is enabled
|
|
89
102
|
if (config.generateTests?.enabled) {
|
package/dist/react-native.d.ts
CHANGED
|
@@ -31,6 +31,14 @@ export interface ReactNativeMockifyerConfig {
|
|
|
31
31
|
* Deprecated: prefer using `recordMode` when `proxyBaseUrl` is provided.
|
|
32
32
|
*/
|
|
33
33
|
proxyRecordOnMiss?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* When true, read `clientId` from Maestro/native launch arguments (optional peer `react-native-launch-arguments`).
|
|
36
|
+
* Prefer this over passing scenario from E2E if the dashboard/Redis should control scenario on the fly for that lane.
|
|
37
|
+
* Forwards to {@link MockifyerConfig.useLaunchArgumentsClientId} on the merged config passed to `setupMockifyer`.
|
|
38
|
+
*/
|
|
39
|
+
useLaunchArgumentsClientId?: boolean;
|
|
40
|
+
/** Launch-argument key for the client lane id (default: `mockifyerClientId`). */
|
|
41
|
+
launchArgumentClientIdKey?: string;
|
|
34
42
|
}
|
|
35
43
|
/**
|
|
36
44
|
* Setup Mockifyer for React Native/Expo with automatic conditional provider selection
|
|
@@ -51,3 +59,4 @@ export interface ReactNativeMockifyerConfig {
|
|
|
51
59
|
* ```
|
|
52
60
|
*/
|
|
53
61
|
export declare function setupMockifyerForReactNative(options: ReactNativeMockifyerConfig): Promise<MockifyerInstance | null>;
|
|
62
|
+
export { tryGetClientIdFromLaunchArguments, MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY } from '@sgedda/mockifyer-core';
|
package/dist/react-native.js
CHANGED
|
@@ -6,6 +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
10
|
exports.setupMockifyerForReactNative = setupMockifyerForReactNative;
|
|
10
11
|
const index_1 = require("./index");
|
|
11
12
|
const mockifyer_core_1 = require("@sgedda/mockifyer-core");
|
|
@@ -82,8 +83,17 @@ async function loadBundledMockData(bundledDataPath) {
|
|
|
82
83
|
* ```
|
|
83
84
|
*/
|
|
84
85
|
async function setupMockifyerForReactNative(options) {
|
|
85
|
-
const { isDev, mockDataPath = 'mock-data', bundledDataPath = './assets/mock-data', recordMode = false, config = {}, proxyBaseUrl, proxyScenario, proxyRecordOnMiss, } = options;
|
|
86
|
+
const { isDev, mockDataPath = 'mock-data', bundledDataPath = './assets/mock-data', recordMode = false, config = {}, proxyBaseUrl, proxyScenario, proxyRecordOnMiss, useLaunchArgumentsClientId = false, launchArgumentClientIdKey = mockifyer_core_2.MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY, } = options;
|
|
86
87
|
const proxyShouldRecordOnMiss = proxyRecordOnMiss ?? recordMode;
|
|
88
|
+
const mergedConfig = {
|
|
89
|
+
...config,
|
|
90
|
+
...(useLaunchArgumentsClientId
|
|
91
|
+
? {
|
|
92
|
+
useLaunchArgumentsClientId: true,
|
|
93
|
+
launchArgumentClientIdKey: launchArgumentClientIdKey ?? mockifyer_core_2.MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY,
|
|
94
|
+
}
|
|
95
|
+
: {}),
|
|
96
|
+
};
|
|
87
97
|
// Check if Mockifyer is enabled
|
|
88
98
|
const isEnabled = process.env.MOCKIFYER_ENABLED === 'true' || isDev;
|
|
89
99
|
if (!isEnabled) {
|
|
@@ -106,13 +116,13 @@ async function setupMockifyerForReactNative(options) {
|
|
|
106
116
|
},
|
|
107
117
|
};
|
|
108
118
|
// Merge with config.databaseProvider if provided
|
|
109
|
-
const databaseProviderConfig =
|
|
119
|
+
const databaseProviderConfig = mergedConfig.databaseProvider
|
|
110
120
|
? {
|
|
111
121
|
...baseDatabaseProvider,
|
|
112
|
-
...
|
|
122
|
+
...mergedConfig.databaseProvider,
|
|
113
123
|
options: {
|
|
114
124
|
...baseDatabaseProvider.options,
|
|
115
|
-
...(
|
|
125
|
+
...(mergedConfig.databaseProvider.options || {}),
|
|
116
126
|
metroPort, // Always ensure metroPort is set
|
|
117
127
|
},
|
|
118
128
|
}
|
|
@@ -130,7 +140,7 @@ async function setupMockifyerForReactNative(options) {
|
|
|
130
140
|
proxy: strictProxyEnabled && proxyBaseUrl
|
|
131
141
|
? { baseUrl: proxyBaseUrl, scenario: proxyScenario, recordOnMiss: proxyShouldRecordOnMiss }
|
|
132
142
|
: undefined,
|
|
133
|
-
...
|
|
143
|
+
...mergedConfig,
|
|
134
144
|
});
|
|
135
145
|
if (strictProxyEnabled) {
|
|
136
146
|
mockifyer_core_2.logger.info('[Mockifyer] Development mode: Strict proxy enabled (dashboard Redis is healthy) — local mocks disabled');
|
|
@@ -179,9 +189,12 @@ async function setupMockifyerForReactNative(options) {
|
|
|
179
189
|
proxy: proxyBaseUrl
|
|
180
190
|
? { baseUrl: proxyBaseUrl, scenario: proxyScenario, recordOnMiss: proxyShouldRecordOnMiss }
|
|
181
191
|
: undefined,
|
|
182
|
-
...
|
|
192
|
+
...mergedConfig,
|
|
183
193
|
});
|
|
184
194
|
mockifyer_core_2.logger.info(`[Mockifyer] Production mode: Loaded ${mockDataArray.length} mocks from bundle`);
|
|
185
195
|
return instance;
|
|
186
196
|
}
|
|
187
197
|
}
|
|
198
|
+
var mockifyer_core_3 = require("@sgedda/mockifyer-core");
|
|
199
|
+
Object.defineProperty(exports, "tryGetClientIdFromLaunchArguments", { enumerable: true, get: function () { return mockifyer_core_3.tryGetClientIdFromLaunchArguments; } });
|
|
200
|
+
Object.defineProperty(exports, "MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY", { enumerable: true, get: function () { return mockifyer_core_3.MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sgedda/mockifyer-fetch",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.19",
|
|
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",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"author": "sgedda",
|
|
47
47
|
"license": "MIT",
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@sgedda/mockifyer-core": "^1.8.
|
|
49
|
+
"@sgedda/mockifyer-core": "^1.8.24"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/node": "^20.11.24",
|
package/src/index.ts
CHANGED
|
@@ -37,7 +37,9 @@ import {
|
|
|
37
37
|
getCurrentDate,
|
|
38
38
|
shouldExcludeUrl,
|
|
39
39
|
mockPassesThroughToRealApi,
|
|
40
|
-
resolveClientId
|
|
40
|
+
resolveClientId,
|
|
41
|
+
tryGetClientIdFromLaunchArguments,
|
|
42
|
+
MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY
|
|
41
43
|
} from '@sgedda/mockifyer-core';
|
|
42
44
|
import { logger, setLogLevel } from '@sgedda/mockifyer-core';
|
|
43
45
|
|
|
@@ -106,11 +108,24 @@ class MockifyerClass {
|
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
|
|
111
|
+
let launchClientId: string | undefined;
|
|
112
|
+
if (config.useLaunchArgumentsClientId) {
|
|
113
|
+
const key = config.launchArgumentClientIdKey ?? MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY;
|
|
114
|
+
launchClientId = tryGetClientIdFromLaunchArguments(key);
|
|
115
|
+
if (launchClientId) {
|
|
116
|
+
logger.info(`[Mockifyer-Fetch] clientId from launch arguments (${key}): ${launchClientId}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
109
120
|
// Store config BEFORE any modifications
|
|
110
121
|
this.config = { ...config }; // Create a copy to avoid mutations
|
|
111
122
|
|
|
112
|
-
//
|
|
113
|
-
|
|
123
|
+
// Launch arg wins over MOCKIFYER_CLIENT_ID / config.clientId when present (E2E).
|
|
124
|
+
if (launchClientId) {
|
|
125
|
+
this.config.clientId = launchClientId;
|
|
126
|
+
} else {
|
|
127
|
+
this.config.clientId = resolveClientId(this.config);
|
|
128
|
+
}
|
|
114
129
|
logger.info(`[Mockifyer-Fetch] clientId: ${this.config.clientId}`);
|
|
115
130
|
|
|
116
131
|
// Initialize test generator if test generation is enabled
|
package/src/react-native.ts
CHANGED
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
import { setupMockifyer } from './index';
|
|
9
9
|
import { MemoryProvider, ExpoFileSystemProvider, MockData, HTTPClient } from '@sgedda/mockifyer-core';
|
|
10
|
-
import
|
|
11
|
-
|
|
10
|
+
import {
|
|
11
|
+
logger,
|
|
12
|
+
MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY,
|
|
13
|
+
} from '@sgedda/mockifyer-core';
|
|
12
14
|
|
|
13
15
|
// Re-export MockifyerInstance type to avoid circular dependency
|
|
14
16
|
export interface MockifyerInstance extends HTTPClient {
|
|
@@ -37,6 +39,14 @@ export interface ReactNativeMockifyerConfig {
|
|
|
37
39
|
* Deprecated: prefer using `recordMode` when `proxyBaseUrl` is provided.
|
|
38
40
|
*/
|
|
39
41
|
proxyRecordOnMiss?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* When true, read `clientId` from Maestro/native launch arguments (optional peer `react-native-launch-arguments`).
|
|
44
|
+
* Prefer this over passing scenario from E2E if the dashboard/Redis should control scenario on the fly for that lane.
|
|
45
|
+
* Forwards to {@link MockifyerConfig.useLaunchArgumentsClientId} on the merged config passed to `setupMockifyer`.
|
|
46
|
+
*/
|
|
47
|
+
useLaunchArgumentsClientId?: boolean;
|
|
48
|
+
/** Launch-argument key for the client lane id (default: `mockifyerClientId`). */
|
|
49
|
+
launchArgumentClientIdKey?: string;
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
type DashboardHealth = {
|
|
@@ -130,10 +140,23 @@ export async function setupMockifyerForReactNative(
|
|
|
130
140
|
proxyBaseUrl,
|
|
131
141
|
proxyScenario,
|
|
132
142
|
proxyRecordOnMiss,
|
|
143
|
+
useLaunchArgumentsClientId = false,
|
|
144
|
+
launchArgumentClientIdKey = MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY,
|
|
133
145
|
} = options;
|
|
134
146
|
|
|
135
147
|
const proxyShouldRecordOnMiss = proxyRecordOnMiss ?? recordMode;
|
|
136
148
|
|
|
149
|
+
const mergedConfig: typeof config = {
|
|
150
|
+
...config,
|
|
151
|
+
...(useLaunchArgumentsClientId
|
|
152
|
+
? {
|
|
153
|
+
useLaunchArgumentsClientId: true as const,
|
|
154
|
+
launchArgumentClientIdKey:
|
|
155
|
+
launchArgumentClientIdKey ?? MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY,
|
|
156
|
+
}
|
|
157
|
+
: {}),
|
|
158
|
+
};
|
|
159
|
+
|
|
137
160
|
// Check if Mockifyer is enabled
|
|
138
161
|
const isEnabled = process.env.MOCKIFYER_ENABLED === 'true' || isDev;
|
|
139
162
|
if (!isEnabled) {
|
|
@@ -160,13 +183,13 @@ export async function setupMockifyerForReactNative(
|
|
|
160
183
|
};
|
|
161
184
|
|
|
162
185
|
// Merge with config.databaseProvider if provided
|
|
163
|
-
const databaseProviderConfig =
|
|
186
|
+
const databaseProviderConfig = mergedConfig.databaseProvider
|
|
164
187
|
? {
|
|
165
188
|
...baseDatabaseProvider,
|
|
166
|
-
...
|
|
189
|
+
...mergedConfig.databaseProvider,
|
|
167
190
|
options: {
|
|
168
191
|
...baseDatabaseProvider.options,
|
|
169
|
-
...(
|
|
192
|
+
...(mergedConfig.databaseProvider.options || {}),
|
|
170
193
|
metroPort, // Always ensure metroPort is set
|
|
171
194
|
},
|
|
172
195
|
}
|
|
@@ -185,7 +208,7 @@ export async function setupMockifyerForReactNative(
|
|
|
185
208
|
proxy: strictProxyEnabled && proxyBaseUrl
|
|
186
209
|
? { baseUrl: proxyBaseUrl, scenario: proxyScenario, recordOnMiss: proxyShouldRecordOnMiss }
|
|
187
210
|
: undefined,
|
|
188
|
-
...
|
|
211
|
+
...mergedConfig,
|
|
189
212
|
});
|
|
190
213
|
|
|
191
214
|
if (strictProxyEnabled) {
|
|
@@ -240,7 +263,7 @@ export async function setupMockifyerForReactNative(
|
|
|
240
263
|
proxy: proxyBaseUrl
|
|
241
264
|
? { baseUrl: proxyBaseUrl, scenario: proxyScenario, recordOnMiss: proxyShouldRecordOnMiss }
|
|
242
265
|
: undefined,
|
|
243
|
-
...
|
|
266
|
+
...mergedConfig,
|
|
244
267
|
});
|
|
245
268
|
|
|
246
269
|
logger.info(`[Mockifyer] Production mode: Loaded ${mockDataArray.length} mocks from bundle`);
|
|
@@ -248,3 +271,5 @@ export async function setupMockifyerForReactNative(
|
|
|
248
271
|
}
|
|
249
272
|
}
|
|
250
273
|
|
|
274
|
+
export { tryGetClientIdFromLaunchArguments, MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY } from '@sgedda/mockifyer-core';
|
|
275
|
+
|