@sgedda/mockifyer-fetch 1.8.21 → 1.8.22

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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FetchHTTPClient = void 0;
4
4
  const mockifyer_core_1 = require("@sgedda/mockifyer-core");
5
5
  const mockifyer_core_2 = require("@sgedda/mockifyer-core");
6
+ const join_proxy_dashboard_api_url_1 = require("../utils/join-proxy-dashboard-api-url");
6
7
  class FetchHTTPClient extends mockifyer_core_1.BaseHTTPClient {
7
8
  constructor(config) {
8
9
  super();
@@ -56,7 +57,7 @@ class FetchHTTPClient extends mockifyer_core_1.BaseHTTPClient {
56
57
  }
57
58
  // Proxy mode (e.g. React Native → dashboard → Redis)
58
59
  if (this.proxyBaseUrl) {
59
- const proxyUrl = new URL('/api/proxy', this.proxyBaseUrl).toString();
60
+ const proxyUrl = (0, join_proxy_dashboard_api_url_1.joinProxyDashboardApiUrl)(this.proxyBaseUrl, 'api/proxy');
60
61
  const proxyResponse = await fetchFn(proxyUrl, {
61
62
  method: 'POST',
62
63
  headers: {
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY = exports.tryGetClientIdFromLaunchArguments = void 0;
10
10
  exports.isMockifyerReactNativeActive = isMockifyerReactNativeActive;
11
11
  exports.setupMockifyerForReactNative = setupMockifyerForReactNative;
12
+ const join_proxy_dashboard_api_url_1 = require("./utils/join-proxy-dashboard-api-url");
12
13
  const index_1 = require("./index");
13
14
  const mockifyer_core_1 = require("@sgedda/mockifyer-core");
14
15
  const mockifyer_core_2 = require("@sgedda/mockifyer-core");
@@ -26,7 +27,7 @@ async function canUseStrictRedisProxy(proxyBaseUrl) {
26
27
  try {
27
28
  const controller = typeof AbortController !== 'undefined' ? new AbortController() : undefined;
28
29
  const timeout = setTimeout(() => controller?.abort(), 800);
29
- const url = new URL('/api/health', proxyBaseUrl).toString();
30
+ const url = (0, join_proxy_dashboard_api_url_1.joinProxyDashboardApiUrl)(proxyBaseUrl, 'api/health');
30
31
  const res = await fetch(url, { signal: controller?.signal });
31
32
  clearTimeout(timeout);
32
33
  if (!res.ok)
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Builds a full URL to the Mockifyer dashboard HTTP API under a given `proxyBaseUrl`.
3
+ *
4
+ * `proxyBaseUrl` may include a path prefix (e.g. `https://host/apim-prefix/mockifyer/`).
5
+ * Avoid `new URL('/api/...', proxyBaseUrl)` — a leading `/` on the second argument replaces the
6
+ * entire pathname of the base URL, so the gateway prefix is lost.
7
+ *
8
+ * @param proxyBaseUrl - Origin and optional path prefix (with or without trailing slash)
9
+ * @param apiSubPath - Path under that prefix without a leading slash (e.g. `api/health`, `api/proxy`)
10
+ */
11
+ export declare function joinProxyDashboardApiUrl(proxyBaseUrl: string, apiSubPath: string): string;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.joinProxyDashboardApiUrl = joinProxyDashboardApiUrl;
4
+ /**
5
+ * Builds a full URL to the Mockifyer dashboard HTTP API under a given `proxyBaseUrl`.
6
+ *
7
+ * `proxyBaseUrl` may include a path prefix (e.g. `https://host/apim-prefix/mockifyer/`).
8
+ * Avoid `new URL('/api/...', proxyBaseUrl)` — a leading `/` on the second argument replaces the
9
+ * entire pathname of the base URL, so the gateway prefix is lost.
10
+ *
11
+ * @param proxyBaseUrl - Origin and optional path prefix (with or without trailing slash)
12
+ * @param apiSubPath - Path under that prefix without a leading slash (e.g. `api/health`, `api/proxy`)
13
+ */
14
+ function joinProxyDashboardApiUrl(proxyBaseUrl, apiSubPath) {
15
+ const normalizedBase = proxyBaseUrl.trim().replace(/\/+$/, '');
16
+ const normalizedPath = apiSubPath.trim().replace(/^\/+/, '');
17
+ return `${normalizedBase}/${normalizedPath}`;
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sgedda/mockifyer-fetch",
3
- "version": "1.8.21",
3
+ "version": "1.8.22",
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.26"
49
+ "@sgedda/mockifyer-core": "^1.8.27"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/node": "^20.11.24",
@@ -6,6 +6,7 @@ import {
6
6
  MOCKIFYER_CLIENT_ID_HEADER,
7
7
  MOCKIFYER_DEVICE_ID_HEADER,
8
8
  } from '@sgedda/mockifyer-core';
9
+ import { joinProxyDashboardApiUrl } from '../utils/join-proxy-dashboard-api-url';
9
10
 
10
11
  export class FetchHTTPClient extends BaseHTTPClient<any, HTTPResponse<any>> {
11
12
  private baseUrl?: string;
@@ -80,7 +81,7 @@ export class FetchHTTPClient extends BaseHTTPClient<any, HTTPResponse<any>> {
80
81
 
81
82
  // Proxy mode (e.g. React Native → dashboard → Redis)
82
83
  if (this.proxyBaseUrl) {
83
- const proxyUrl = new URL('/api/proxy', this.proxyBaseUrl).toString();
84
+ const proxyUrl = joinProxyDashboardApiUrl(this.proxyBaseUrl, 'api/proxy');
84
85
  const proxyResponse = await fetchFn(proxyUrl, {
85
86
  method: 'POST',
86
87
  headers: {
@@ -5,6 +5,7 @@
5
5
  * conditional provider selection (FileSystem in dev, Memory in prod)
6
6
  */
7
7
 
8
+ import { joinProxyDashboardApiUrl } from './utils/join-proxy-dashboard-api-url';
8
9
  import { setupMockifyer } from './index';
9
10
  import { MemoryProvider, ExpoFileSystemProvider, MockData, HTTPClient } from '@sgedda/mockifyer-core';
10
11
  import {
@@ -100,7 +101,7 @@ async function canUseStrictRedisProxy(proxyBaseUrl?: string): Promise<boolean> {
100
101
  try {
101
102
  const controller = typeof AbortController !== 'undefined' ? new AbortController() : undefined;
102
103
  const timeout = setTimeout(() => controller?.abort(), 800);
103
- const url = new URL('/api/health', proxyBaseUrl).toString();
104
+ const url = joinProxyDashboardApiUrl(proxyBaseUrl, 'api/health');
104
105
  const res = await fetch(url, { signal: controller?.signal });
105
106
  clearTimeout(timeout);
106
107
  if (!res.ok) return false;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Builds a full URL to the Mockifyer dashboard HTTP API under a given `proxyBaseUrl`.
3
+ *
4
+ * `proxyBaseUrl` may include a path prefix (e.g. `https://host/apim-prefix/mockifyer/`).
5
+ * Avoid `new URL('/api/...', proxyBaseUrl)` — a leading `/` on the second argument replaces the
6
+ * entire pathname of the base URL, so the gateway prefix is lost.
7
+ *
8
+ * @param proxyBaseUrl - Origin and optional path prefix (with or without trailing slash)
9
+ * @param apiSubPath - Path under that prefix without a leading slash (e.g. `api/health`, `api/proxy`)
10
+ */
11
+ export function joinProxyDashboardApiUrl(proxyBaseUrl: string, apiSubPath: string): string {
12
+ const normalizedBase = proxyBaseUrl.trim().replace(/\/+$/, '');
13
+ const normalizedPath = apiSubPath.trim().replace(/^\/+/, '');
14
+ return `${normalizedBase}/${normalizedPath}`;
15
+ }