@genesislcap/foundation-comms 14.406.0 → 14.406.1-alpha-21d7d7f.0

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.
@@ -36,6 +36,12 @@ export declare class DefaultHttp implements Http {
36
36
  constructor(serializer: JSONSerializer);
37
37
  get<T>(url: string, requestInit: HttpRequestInit): Promise<T>;
38
38
  post<T>(url: string, requestInit: HttpRequestInit): Promise<T>;
39
+ /**
40
+ * Performs fetch and manually follows redirects (301, 302, 303, 307, 308) using the Location header.
41
+ * 301/302/303 use GET for the redirect; 307/308 preserve the original method.
42
+ * @internal
43
+ */
44
+ private fetchWithRedirectHandling;
39
45
  }
40
46
  /**
41
47
  * The DI token for the Http interface.
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/connect/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAG/D;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,WAAW;IAClD;;;;OAIG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,IAAI;IACnB,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACpE,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACtE;AAED;;;GAGG;AACH,MAAM,WAAW,SAAU,SAAQ,KAAK;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AASD;;;GAGG;AACH,qBAAa,WAAY,YAAW,IAAI;IACV,OAAO,CAAC,UAAU;gBAAV,UAAU,EAAE,cAAc;IAEjD,GAAG,CAAC,CAAC,EAAE,GA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IAAI,4DAA4D,CAAC"}
@@ -1,12 +1,34 @@
1
1
  import { __awaiter, __decorate, __param } from "tslib";
2
2
  import { JSONSerializer } from '@genesislcap/foundation-utils';
3
3
  import { DI } from '@microsoft/fast-foundation';
4
+ import { StatusCodes } from 'http-status-codes';
5
+ /** Redirect status codes that change to GET (301, 302, 303) */
6
+ const REDIRECT_TO_GET = new Set([
7
+ StatusCodes.MOVED_PERMANENTLY,
8
+ StatusCodes.MOVED_TEMPORARILY,
9
+ StatusCodes.SEE_OTHER,
10
+ ]);
11
+ /** Redirect status codes that preserve the original method (307, 308) */
12
+ const REDIRECT_PRESERVE_METHOD = new Set([
13
+ StatusCodes.TEMPORARY_REDIRECT,
14
+ StatusCodes.PERMANENT_REDIRECT,
15
+ ]);
16
+ const REDIRECT_STATUSES = new Set([...REDIRECT_TO_GET, ...REDIRECT_PRESERVE_METHOD]);
17
+ const MAX_REDIRECTS = 10;
4
18
  function createHttpError(response) {
5
19
  const error = new Error(`HTTP error: ${response.status} ${response.statusText}`);
6
20
  error.status = response.status;
7
21
  error.message = response.statusText;
8
22
  return error;
9
23
  }
24
+ function resolveRedirectUrl(location, baseUrl) {
25
+ try {
26
+ return new URL(location, baseUrl).href;
27
+ }
28
+ catch (_a) {
29
+ return location;
30
+ }
31
+ }
10
32
  /**
11
33
  * The default implementation of the Http interface.
12
34
  * @public
@@ -17,7 +39,7 @@ let DefaultHttp = class DefaultHttp {
17
39
  }
18
40
  get(url, requestInit) {
19
41
  return __awaiter(this, void 0, void 0, function* () {
20
- const response = yield fetch(url, Object.assign(Object.assign({ credentials: 'include', headers: { 'Content-type': 'application/json; charset=UTF-8' } }, requestInit), { method: 'GET' }));
42
+ const response = yield this.fetchWithRedirectHandling(url, Object.assign(Object.assign({ credentials: 'include', headers: { 'Content-type': 'application/json; charset=UTF-8' } }, requestInit), { method: 'GET' }));
21
43
  if (!response.ok) {
22
44
  throw createHttpError(response);
23
45
  }
@@ -27,7 +49,7 @@ let DefaultHttp = class DefaultHttp {
27
49
  }
28
50
  post(url, requestInit) {
29
51
  return __awaiter(this, void 0, void 0, function* () {
30
- const response = yield fetch(url, Object.assign(Object.assign({ credentials: 'include', headers: { 'Content-type': 'application/json; charset=UTF-8' } }, requestInit), { method: 'POST' }));
52
+ const response = yield this.fetchWithRedirectHandling(url, Object.assign(Object.assign({ credentials: 'include', headers: { 'Content-type': 'application/json; charset=UTF-8' } }, requestInit), { method: 'POST' }));
31
53
  if (!response.ok) {
32
54
  throw createHttpError(response);
33
55
  }
@@ -35,6 +57,29 @@ let DefaultHttp = class DefaultHttp {
35
57
  return serializer.deserialize(response);
36
58
  });
37
59
  }
60
+ /**
61
+ * Performs fetch and manually follows redirects (301, 302, 303, 307, 308) using the Location header.
62
+ * 301/302/303 use GET for the redirect; 307/308 preserve the original method.
63
+ * @internal
64
+ */
65
+ fetchWithRedirectHandling(url_1, init_1) {
66
+ return __awaiter(this, arguments, void 0, function* (url, init, redirectCount = 0) {
67
+ if (redirectCount >= MAX_REDIRECTS) {
68
+ throw new Error(`Maximum redirect limit (${MAX_REDIRECTS}) exceeded`);
69
+ }
70
+ const response = yield fetch(url, Object.assign(Object.assign({}, init), { redirect: 'manual' }));
71
+ if (REDIRECT_STATUSES.has(response.status)) {
72
+ const location = response.headers.get('Location');
73
+ if (!location) {
74
+ throw createHttpError(response);
75
+ }
76
+ const redirectUrl = resolveRedirectUrl(location, url);
77
+ const preserveMethod = REDIRECT_PRESERVE_METHOD.has(response.status);
78
+ return this.fetchWithRedirectHandling(redirectUrl, Object.assign(Object.assign({}, init), { method: preserveMethod ? init.method : 'GET', body: preserveMethod ? init.body : undefined }), redirectCount + 1);
79
+ }
80
+ return response;
81
+ });
82
+ }
38
83
  };
39
84
  DefaultHttp = __decorate([
40
85
  __param(0, JSONSerializer)
@@ -2141,6 +2141,12 @@ export declare class DefaultHttp implements Http {
2141
2141
  constructor(serializer: JSONSerializer);
2142
2142
  get<T>(url: string, requestInit: HttpRequestInit): Promise<T>;
2143
2143
  post<T>(url: string, requestInit: HttpRequestInit): Promise<T>;
2144
+ /**
2145
+ * Performs fetch and manually follows redirects (301, 302, 303, 307, 308) using the Location header.
2146
+ * 301/302/303 use GET for the redirect; 307/308 preserve the original method.
2147
+ * @internal
2148
+ */
2149
+ private fetchWithRedirectHandling;
2144
2150
  }
2145
2151
 
2146
2152
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/foundation-comms",
3
3
  "description": "Genesis Foundation UI Comms",
4
- "version": "14.406.0",
4
+ "version": "14.406.1-alpha-21d7d7f.0",
5
5
  "sideEffects": false,
6
6
  "license": "SEE LICENSE IN license.txt",
7
7
  "main": "dist/esm/index.js",
@@ -77,24 +77,24 @@
77
77
  }
78
78
  },
79
79
  "devDependencies": {
80
- "@genesislcap/foundation-testing": "14.406.0",
81
- "@genesislcap/genx": "14.406.0",
82
- "@genesislcap/rollup-builder": "14.406.0",
83
- "@genesislcap/ts-builder": "14.406.0",
84
- "@genesislcap/uvu-playwright-builder": "14.406.0",
85
- "@genesislcap/vite-builder": "14.406.0",
86
- "@genesislcap/webpack-builder": "14.406.0",
80
+ "@genesislcap/foundation-testing": "14.406.1-alpha-21d7d7f.0",
81
+ "@genesislcap/genx": "14.406.1-alpha-21d7d7f.0",
82
+ "@genesislcap/rollup-builder": "14.406.1-alpha-21d7d7f.0",
83
+ "@genesislcap/ts-builder": "14.406.1-alpha-21d7d7f.0",
84
+ "@genesislcap/uvu-playwright-builder": "14.406.1-alpha-21d7d7f.0",
85
+ "@genesislcap/vite-builder": "14.406.1-alpha-21d7d7f.0",
86
+ "@genesislcap/webpack-builder": "14.406.1-alpha-21d7d7f.0",
87
87
  "@types/js-cookie": "^3.0.2",
88
88
  "@types/json-schema": "^7.0.11",
89
89
  "@types/webappsec-credential-management": "^0.6.2",
90
90
  "sinon": "^17.0.1"
91
91
  },
92
92
  "dependencies": {
93
- "@genesislcap/foundation-broadcast-channel": "14.406.0",
94
- "@genesislcap/foundation-logger": "14.406.0",
95
- "@genesislcap/foundation-user": "14.406.0",
96
- "@genesislcap/foundation-utils": "14.406.0",
97
- "@genesislcap/web-core": "14.406.0",
93
+ "@genesislcap/foundation-broadcast-channel": "14.406.1-alpha-21d7d7f.0",
94
+ "@genesislcap/foundation-logger": "14.406.1-alpha-21d7d7f.0",
95
+ "@genesislcap/foundation-user": "14.406.1-alpha-21d7d7f.0",
96
+ "@genesislcap/foundation-utils": "14.406.1-alpha-21d7d7f.0",
97
+ "@genesislcap/web-core": "14.406.1-alpha-21d7d7f.0",
98
98
  "@microsoft/fast-element": "1.14.0",
99
99
  "@microsoft/fast-foundation": "2.50.0",
100
100
  "analytics": "0.8.16",
@@ -113,5 +113,5 @@
113
113
  "publishConfig": {
114
114
  "access": "public"
115
115
  },
116
- "gitHead": "69e2b4662605a6e5e60efe537b8871a7e0c00f44"
116
+ "gitHead": "fd59078c8a2ca3c3459eeb5b5e8ca6069223cca9"
117
117
  }