@genesislcap/foundation-comms 15.0.0 → 15.1.0-GENC-1461.6

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.
@@ -10,6 +10,14 @@ export interface HttpRequestInit extends RequestInit {
10
10
  * This can be used to transform the request body to a specific format such as JSON or XML.
11
11
  */
12
12
  serializer?: JSONSerializer;
13
+ /**
14
+ * Optional hook invoked with the raw `Response` before its body is deserialized.
15
+ * @remarks
16
+ * Use it to read response metadata the deserialized body omits — for example the HTTP status
17
+ * code or headers such as `ETag` and `Cache-Control`. Only read metadata here; the body is
18
+ * consumed by the deserializer afterwards.
19
+ */
20
+ onResponse?: (response: Response) => void;
13
21
  }
14
22
  /**
15
23
  * An interface representing an HTTP client that can make GET and POST requests and return a promise with the response data.
@@ -29,6 +37,14 @@ export interface HttpError extends Error {
29
37
  }
30
38
  /**
31
39
  * The default implementation of the Http interface.
40
+ *
41
+ * @remarks
42
+ * Caching is delegated to the browser's HTTP cache. Requests use the default `fetch` cache mode, so
43
+ * a response carrying an `ETag` (and a storable `Cache-Control`) is cached, revalidated with
44
+ * `If-None-Match`, and replayed by the browser automatically — the client keeps no cache of its own.
45
+ * Callers that send their own conditional headers receive the raw `304 Not Modified` (resolved as no
46
+ * body) instead of an error, and can inspect any response via {@link HttpRequestInit.onResponse}.
47
+ *
32
48
  * @public
33
49
  */
34
50
  export declare class DefaultHttp implements Http {
@@ -36,6 +52,7 @@ export declare class DefaultHttp implements Http {
36
52
  constructor(serializer: JSONSerializer);
37
53
  get<T>(url: string, requestInit: HttpRequestInit): Promise<T>;
38
54
  post<T>(url: string, requestInit: HttpRequestInit): Promise<T>;
55
+ private handleResponse;
39
56
  }
40
57
  /**
41
58
  * 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;AA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,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;AAYD;;;;;;;;;;;GAWG;AACH,qBAAa,WAAY,YAAW,IAAI;IACV,OAAO,CAAC,UAAU;gBAAV,UAAU,EAAE,cAAc;IAEjD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,GAAG,OAAO,CAAC,CAAC,CAAC;IAU7D,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,GAAG,OAAO,CAAC,CAAC,CAAC;YAU7D,cAAc;CAkB7B;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,4DAA4D,CAAC"}
@@ -7,8 +7,18 @@ function createHttpError(response) {
7
7
  error.message = response.statusText;
8
8
  return error;
9
9
  }
10
+ /** HTTP status for a successful conditional request whose resource is unchanged. */
11
+ const HTTP_STATUS_NOT_MODIFIED = 304;
10
12
  /**
11
13
  * The default implementation of the Http interface.
14
+ *
15
+ * @remarks
16
+ * Caching is delegated to the browser's HTTP cache. Requests use the default `fetch` cache mode, so
17
+ * a response carrying an `ETag` (and a storable `Cache-Control`) is cached, revalidated with
18
+ * `If-None-Match`, and replayed by the browser automatically — the client keeps no cache of its own.
19
+ * Callers that send their own conditional headers receive the raw `304 Not Modified` (resolved as no
20
+ * body) instead of an error, and can inspect any response via {@link HttpRequestInit.onResponse}.
21
+ *
12
22
  * @public
13
23
  */
14
24
  let DefaultHttp = class DefaultHttp {
@@ -18,24 +28,29 @@ let DefaultHttp = class DefaultHttp {
18
28
  get(url, requestInit) {
19
29
  return __awaiter(this, void 0, void 0, function* () {
20
30
  const response = yield fetch(url, Object.assign(Object.assign({ credentials: 'include', headers: { 'Content-type': 'application/json; charset=UTF-8' } }, requestInit), { method: 'GET' }));
21
- if (response.redirected) {
22
- window.location.href = response.url;
23
- return new Promise(() => { });
24
- }
25
- if (!response.ok) {
26
- throw createHttpError(response);
27
- }
28
- const serializer = requestInit.serializer || this.serializer;
29
- return serializer.deserialize(response);
31
+ return this.handleResponse(response, requestInit);
30
32
  });
31
33
  }
32
34
  post(url, requestInit) {
33
35
  return __awaiter(this, void 0, void 0, function* () {
34
36
  const response = yield fetch(url, Object.assign(Object.assign({ credentials: 'include', headers: { 'Content-type': 'application/json; charset=UTF-8' } }, requestInit), { method: 'POST' }));
37
+ return this.handleResponse(response, requestInit);
38
+ });
39
+ }
40
+ handleResponse(response, requestInit) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ var _a;
35
43
  if (response.redirected) {
36
44
  window.location.href = response.url;
37
45
  return new Promise(() => { });
38
46
  }
47
+ // Expose response metadata (status, headers such as ETag) before the body is consumed.
48
+ (_a = requestInit.onResponse) === null || _a === void 0 ? void 0 : _a.call(requestInit, response);
49
+ // 304 Not Modified is a successful conditional response with no body; surface it via
50
+ // onResponse rather than treating it as an error, and return no data.
51
+ if (response.status === HTTP_STATUS_NOT_MODIFIED) {
52
+ return undefined;
53
+ }
39
54
  if (!response.ok) {
40
55
  throw createHttpError(response);
41
56
  }
@@ -17878,7 +17878,7 @@
17878
17878
  {
17879
17879
  "kind": "Class",
17880
17880
  "canonicalReference": "@genesislcap/foundation-comms!DefaultHttp:class",
17881
- "docComment": "/**\n * The default implementation of the Http interface.\n *\n * @public\n */\n",
17881
+ "docComment": "/**\n * The default implementation of the Http interface.\n *\n * @remarks\n *\n * Caching is delegated to the browser's HTTP cache. Requests use the default `fetch` cache mode, so a response carrying an `ETag` (and a storable `Cache-Control`) is cached, revalidated with `If-None-Match`, and replayed by the browser automatically — the client keeps no cache of its own. Callers that send their own conditional headers receive the raw `304 Not Modified` (resolved as no body) instead of an error, and can inspect any response via {@link HttpRequestInit.onResponse}.\n *\n * @public\n */\n",
17882
17882
  "excerptTokens": [
17883
17883
  {
17884
17884
  "kind": "Content",
@@ -27883,6 +27883,42 @@
27883
27883
  "name": "HttpRequestInit",
27884
27884
  "preserveMemberOrder": false,
27885
27885
  "members": [
27886
+ {
27887
+ "kind": "PropertySignature",
27888
+ "canonicalReference": "@genesislcap/foundation-comms!HttpRequestInit#onResponse:member",
27889
+ "docComment": "/**\n * Optional hook invoked with the raw `Response` before its body is deserialized.\n *\n * @remarks\n *\n * Use it to read response metadata the deserialized body omits — for example the HTTP status code or headers such as `ETag` and `Cache-Control`. Only read metadata here; the body is consumed by the deserializer afterwards.\n */\n",
27890
+ "excerptTokens": [
27891
+ {
27892
+ "kind": "Content",
27893
+ "text": "onResponse?: "
27894
+ },
27895
+ {
27896
+ "kind": "Content",
27897
+ "text": "(response: "
27898
+ },
27899
+ {
27900
+ "kind": "Reference",
27901
+ "text": "Response",
27902
+ "canonicalReference": "!Response:interface"
27903
+ },
27904
+ {
27905
+ "kind": "Content",
27906
+ "text": ") => void"
27907
+ },
27908
+ {
27909
+ "kind": "Content",
27910
+ "text": ";"
27911
+ }
27912
+ ],
27913
+ "isReadonly": false,
27914
+ "isOptional": true,
27915
+ "releaseTag": "Public",
27916
+ "name": "onResponse",
27917
+ "propertyTypeTokenRange": {
27918
+ "startIndex": 1,
27919
+ "endIndex": 4
27920
+ }
27921
+ },
27886
27922
  {
27887
27923
  "kind": "PropertySignature",
27888
27924
  "canonicalReference": "@genesislcap/foundation-comms!HttpRequestInit#serializer:member",
@@ -2175,6 +2175,14 @@ export declare const defaultGenesisResourcesConfig: GenesisResourcesConfig;
2175
2175
 
2176
2176
  /**
2177
2177
  * The default implementation of the Http interface.
2178
+ *
2179
+ * @remarks
2180
+ * Caching is delegated to the browser's HTTP cache. Requests use the default `fetch` cache mode, so
2181
+ * a response carrying an `ETag` (and a storable `Cache-Control`) is cached, revalidated with
2182
+ * `If-None-Match`, and replayed by the browser automatically — the client keeps no cache of its own.
2183
+ * Callers that send their own conditional headers receive the raw `304 Not Modified` (resolved as no
2184
+ * body) instead of an error, and can inspect any response via {@link HttpRequestInit.onResponse}.
2185
+ *
2178
2186
  * @public
2179
2187
  */
2180
2188
  export declare class DefaultHttp implements Http {
@@ -2182,6 +2190,7 @@ export declare class DefaultHttp implements Http {
2182
2190
  constructor(serializer: JSONSerializer);
2183
2191
  get<T>(url: string, requestInit: HttpRequestInit): Promise<T>;
2184
2192
  post<T>(url: string, requestInit: HttpRequestInit): Promise<T>;
2193
+ private handleResponse;
2185
2194
  }
2186
2195
 
2187
2196
  /**
@@ -3373,6 +3382,14 @@ export declare interface HttpRequestInit extends RequestInit {
3373
3382
  * This can be used to transform the request body to a specific format such as JSON or XML.
3374
3383
  */
3375
3384
  serializer?: JSONSerializer;
3385
+ /**
3386
+ * Optional hook invoked with the raw `Response` before its body is deserialized.
3387
+ * @remarks
3388
+ * Use it to read response metadata the deserialized body omits — for example the HTTP status
3389
+ * code or headers such as `ETag` and `Cache-Control`. Only read metadata here; the body is
3390
+ * consumed by the deserializer afterwards.
3391
+ */
3392
+ onResponse?: (response: Response) => void;
3376
3393
  }
3377
3394
 
3378
3395
  /**
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": "15.0.0",
4
+ "version": "15.1.0-GENC-1461.6",
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": "15.0.0",
81
- "@genesislcap/genx": "15.0.0",
82
- "@genesislcap/rollup-builder": "15.0.0",
83
- "@genesislcap/ts-builder": "15.0.0",
84
- "@genesislcap/uvu-playwright-builder": "15.0.0",
85
- "@genesislcap/vite-builder": "15.0.0",
86
- "@genesislcap/webpack-builder": "15.0.0",
80
+ "@genesislcap/foundation-testing": "15.1.0-GENC-1461.6",
81
+ "@genesislcap/genx": "15.1.0-GENC-1461.6",
82
+ "@genesislcap/rollup-builder": "15.1.0-GENC-1461.6",
83
+ "@genesislcap/ts-builder": "15.1.0-GENC-1461.6",
84
+ "@genesislcap/uvu-playwright-builder": "15.1.0-GENC-1461.6",
85
+ "@genesislcap/vite-builder": "15.1.0-GENC-1461.6",
86
+ "@genesislcap/webpack-builder": "15.1.0-GENC-1461.6",
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": "15.0.0",
94
- "@genesislcap/foundation-logger": "15.0.0",
95
- "@genesislcap/foundation-user": "15.0.0",
96
- "@genesislcap/foundation-utils": "15.0.0",
97
- "@genesislcap/web-core": "15.0.0",
93
+ "@genesislcap/foundation-broadcast-channel": "15.1.0-GENC-1461.6",
94
+ "@genesislcap/foundation-logger": "15.1.0-GENC-1461.6",
95
+ "@genesislcap/foundation-user": "15.1.0-GENC-1461.6",
96
+ "@genesislcap/foundation-utils": "15.1.0-GENC-1461.6",
97
+ "@genesislcap/web-core": "15.1.0-GENC-1461.6",
98
98
  "@microsoft/fast-element": "1.14.0",
99
99
  "@microsoft/fast-foundation": "2.50.0",
100
100
  "bowser": "^2.11.0",
@@ -112,5 +112,5 @@
112
112
  "publishConfig": {
113
113
  "access": "public"
114
114
  },
115
- "gitHead": "035852ede9f26ea4434f1b3dfaff98db41490246"
115
+ "gitHead": "fe4c3b94eb819877d8a0a9879743e6070548bf34"
116
116
  }