@sgedda/mockifyer-fetch 1.8.34 → 1.8.37

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.
@@ -9,6 +9,7 @@ export declare class FetchHTTPClient extends BaseHTTPClient<any, HTTPResponse<an
9
9
  private proxyRecordResponses;
10
10
  private getClientId?;
11
11
  private getStrictLaneScenario?;
12
+ private getUpstreamTlsInsecure?;
12
13
  private getExplicitProxyScenarioContext?;
13
14
  private clientIdSnapshot?;
14
15
  private deviceId?;
@@ -26,6 +27,7 @@ export declare class FetchHTTPClient extends BaseHTTPClient<any, HTTPResponse<an
26
27
  clientId?: string;
27
28
  getClientId?: () => string | undefined;
28
29
  getStrictLaneScenario?: () => boolean;
30
+ getUpstreamTlsInsecure?: () => boolean;
29
31
  /** When false, skip `/api/proxy` and call the real URL (devtools-friendly passthrough). */
30
32
  getExplicitProxyScenarioContext?: () => boolean;
31
33
  deviceId?: string;
@@ -14,6 +14,7 @@ class FetchHTTPClient extends mockifyer_core_1.BaseHTTPClient {
14
14
  this.proxyRecordResponses = config?.proxy?.recordResponses ?? false;
15
15
  this.getClientId = config?.getClientId;
16
16
  this.getStrictLaneScenario = config?.getStrictLaneScenario;
17
+ this.getUpstreamTlsInsecure = config?.getUpstreamTlsInsecure;
17
18
  this.getExplicitProxyScenarioContext = config?.getExplicitProxyScenarioContext;
18
19
  this.clientIdSnapshot = config?.clientId;
19
20
  this.deviceId = config?.deviceId;
@@ -101,6 +102,7 @@ class FetchHTTPClient extends mockifyer_core_1.BaseHTTPClient {
101
102
  recordOnMiss: this.proxyRecordOnMiss,
102
103
  recordResponses: this.proxyRecordResponses,
103
104
  strictLaneScenario: this.getStrictLaneScenario?.() ?? true,
105
+ upstreamTlsInsecure: this.getUpstreamTlsInsecure?.() ?? false,
104
106
  config,
105
107
  fetchFn,
106
108
  logTag: 'Mockifyer-Fetch',
package/dist/index.js CHANGED
@@ -36,6 +36,7 @@ catch (e) {
36
36
  const mockifyer_core_1 = require("@sgedda/mockifyer-core");
37
37
  const mockifyer_core_2 = require("@sgedda/mockifyer-core");
38
38
  const core_proxy_1 = require("./core-proxy");
39
+ const proxy_upstream_tls_insecure_1 = require("@sgedda/mockifyer-core/utils/proxy-upstream-tls-insecure");
39
40
  const fetch_client_1 = require("./clients/fetch-client");
40
41
  class MockifyerClass {
41
42
  /** Best-effort dashboard network log (skipped when traffic goes through `proxy.baseUrl`). */
@@ -182,6 +183,7 @@ class MockifyerClass {
182
183
  clientId: this.config.clientId,
183
184
  getClientId: () => this.config.clientId,
184
185
  getStrictLaneScenario: () => (0, mockifyer_core_1.resolveProxyStrictLaneScenario)(this.config),
186
+ getUpstreamTlsInsecure: () => (0, proxy_upstream_tls_insecure_1.resolveProxyUpstreamTlsInsecure)(this.config),
185
187
  getExplicitProxyScenarioContext: () => (0, mockifyer_core_1.isExplicitProxyScenarioContext)(this.config),
186
188
  deviceId: this.config.deviceId,
187
189
  });
@@ -409,6 +411,10 @@ class MockifyerClass {
409
411
  config.__mockifyer_bypass = true;
410
412
  return config;
411
413
  }
414
+ if ((0, mockifyer_core_1.shouldBypassMockifyerForUrl)(url, this.config.excludedUrls, this.config.baseUrl)) {
415
+ config.__mockifyer_bypass = true;
416
+ return config;
417
+ }
412
418
  if (!(0, mockifyer_core_1.shouldApplyMockifyer)(this.activationMode, config.headers, {
413
419
  useProxyLane: { proxyBaseUrl: this.config.proxy?.baseUrl, resolvedClientId: this.config.clientId },
414
420
  })) {
@@ -742,10 +748,10 @@ class MockifyerClass {
742
748
  return;
743
749
  }
744
750
  const url = response.config?.url || response.request?.responseURL || response.url || '';
745
- const recordingExclusions = (0, mockifyer_core_1.resolveRecordingExclusions)(this.config);
746
- if (url && (0, mockifyer_core_1.shouldExcludeUrl)(url, this.config.excludedUrls)) {
751
+ if (url && (0, mockifyer_core_1.shouldBypassMockifyerForUrl)(url, this.config.excludedUrls, this.config.baseUrl)) {
747
752
  return;
748
753
  }
754
+ const recordingExclusions = (0, mockifyer_core_1.resolveRecordingExclusions)(this.config);
749
755
  if (url &&
750
756
  (0, mockifyer_core_1.shouldExcludeRecording)(url, recordingExclusions, this.config.baseUrl)) {
751
757
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sgedda/mockifyer-fetch",
3
- "version": "1.8.34",
3
+ "version": "1.8.37",
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.2"
52
+ "@sgedda/mockifyer-core": "^1.10.12"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^20.11.24",
@@ -21,6 +21,7 @@ export class FetchHTTPClient extends BaseHTTPClient<any, HTTPResponse<any>> {
21
21
  private proxyRecordResponses: boolean;
22
22
  private getClientId?: () => string | undefined;
23
23
  private getStrictLaneScenario?: () => boolean;
24
+ private getUpstreamTlsInsecure?: () => boolean;
24
25
  private getExplicitProxyScenarioContext?: () => boolean;
25
26
  private clientIdSnapshot?: string;
26
27
  private deviceId?: string;
@@ -39,6 +40,7 @@ export class FetchHTTPClient extends BaseHTTPClient<any, HTTPResponse<any>> {
39
40
  clientId?: string;
40
41
  getClientId?: () => string | undefined;
41
42
  getStrictLaneScenario?: () => boolean;
43
+ getUpstreamTlsInsecure?: () => boolean;
42
44
  /** When false, skip `/api/proxy` and call the real URL (devtools-friendly passthrough). */
43
45
  getExplicitProxyScenarioContext?: () => boolean;
44
46
  deviceId?: string;
@@ -52,6 +54,7 @@ export class FetchHTTPClient extends BaseHTTPClient<any, HTTPResponse<any>> {
52
54
  this.proxyRecordResponses = config?.proxy?.recordResponses ?? false;
53
55
  this.getClientId = config?.getClientId;
54
56
  this.getStrictLaneScenario = config?.getStrictLaneScenario;
57
+ this.getUpstreamTlsInsecure = config?.getUpstreamTlsInsecure;
55
58
  this.getExplicitProxyScenarioContext = config?.getExplicitProxyScenarioContext;
56
59
  this.clientIdSnapshot = config?.clientId;
57
60
  this.deviceId = config?.deviceId;
@@ -149,6 +152,7 @@ export class FetchHTTPClient extends BaseHTTPClient<any, HTTPResponse<any>> {
149
152
  recordOnMiss: this.proxyRecordOnMiss,
150
153
  recordResponses: this.proxyRecordResponses,
151
154
  strictLaneScenario: this.getStrictLaneScenario?.() ?? true,
155
+ upstreamTlsInsecure: this.getUpstreamTlsInsecure?.() ?? false,
152
156
  config,
153
157
  fetchFn,
154
158
  logTag: 'Mockifyer-Fetch',
package/src/index.ts CHANGED
@@ -35,7 +35,7 @@ import {
35
35
  checkRequestLimit,
36
36
  prepareMockResponseBody,
37
37
  getCurrentDate,
38
- shouldExcludeUrl,
38
+ shouldBypassMockifyerForUrl,
39
39
  resolveRecordingExclusions,
40
40
  shouldExcludeRecording,
41
41
  mockPassesThroughToRealApi,
@@ -76,6 +76,7 @@ import {
76
76
  type InitMockifyerForDashboardProxyOptions,
77
77
  type InitMockifyerForLocalFilesystemOptions,
78
78
  } from './core-proxy';
79
+ import { resolveProxyUpstreamTlsInsecure } from '@sgedda/mockifyer-core/utils/proxy-upstream-tls-insecure';
79
80
 
80
81
  import { FetchHTTPClient } from './clients/fetch-client';
81
82
 
@@ -253,6 +254,7 @@ class MockifyerClass {
253
254
  clientId: this.config.clientId,
254
255
  getClientId: () => this.config.clientId,
255
256
  getStrictLaneScenario: () => resolveProxyStrictLaneScenario(this.config),
257
+ getUpstreamTlsInsecure: () => resolveProxyUpstreamTlsInsecure(this.config),
256
258
  getExplicitProxyScenarioContext: () => isExplicitProxyScenarioContext(this.config),
257
259
  deviceId: (this.config as any).deviceId,
258
260
  });
@@ -529,6 +531,11 @@ class MockifyerClass {
529
531
  return config;
530
532
  }
531
533
 
534
+ if (shouldBypassMockifyerForUrl(url, this.config.excludedUrls, this.config.baseUrl)) {
535
+ (config as any).__mockifyer_bypass = true;
536
+ return config;
537
+ }
538
+
532
539
  if (
533
540
  !shouldApplyMockifyer(this.activationMode, config.headers, {
534
541
  useProxyLane: { proxyBaseUrl: this.config.proxy?.baseUrl, resolvedClientId: this.config.clientId },
@@ -940,10 +947,10 @@ class MockifyerClass {
940
947
  }
941
948
 
942
949
  const url = response.config?.url || (response as any).request?.responseURL || (response as any).url || '';
943
- const recordingExclusions = resolveRecordingExclusions(this.config);
944
- if (url && shouldExcludeUrl(url, this.config.excludedUrls)) {
950
+ if (url && shouldBypassMockifyerForUrl(url, this.config.excludedUrls, this.config.baseUrl)) {
945
951
  return;
946
952
  }
953
+ const recordingExclusions = resolveRecordingExclusions(this.config);
947
954
  if (
948
955
  url &&
949
956
  shouldExcludeRecording(url, recordingExclusions, this.config.baseUrl)