@podium/client 5.2.4 → 5.2.5-beta.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [5.2.5-beta.2](https://github.com/podium-lib/client/compare/v5.2.5-beta.1...v5.2.5-beta.2) (2025-01-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * update @podium/http-client to version 1.0.0-beta.9 ([e64596a](https://github.com/podium-lib/client/commit/e64596a8bf194ecee5702f2dda61674c9a5f8772))
7
+
8
+ ## [5.2.5-beta.1](https://github.com/podium-lib/client/compare/v5.2.4...v5.2.5-beta.1) (2024-12-02)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * adding @podium/http-client beta ([e300bde](https://github.com/podium-lib/client/commit/e300bde2fd8e6356227e03a8d9ae847e509cd1f4))
14
+
1
15
  ## [5.2.4](https://github.com/podium-lib/client/compare/v5.2.3...v5.2.4) (2024-11-21)
2
16
 
3
17
 
@@ -6,9 +6,9 @@ import { Boom, badGateway } from '@hapi/boom';
6
6
  import { join, dirname } from 'path';
7
7
  import { fileURLToPath } from 'url';
8
8
  import fs from 'fs';
9
+ import HttpClient from '@podium/http-client';
9
10
  import * as utils from './utils.js';
10
11
  import Response from './response.js';
11
- import HTTP from './http.js';
12
12
  import { parseLinkHeaders, filterAssets } from './utils.js';
13
13
  import { AssetJs, AssetCss } from '@podium/utils';
14
14
 
@@ -25,7 +25,7 @@ const UA_STRING = `${pkg.name} ${pkg.version}`;
25
25
  /**
26
26
  * @typedef {object} PodletClientContentResolverOptions
27
27
  * @property {string} clientName
28
- * @property {import('./http.js').default} [http]
28
+ * @property {import('@podium/http-client').default} [http]
29
29
  * @property {import('abslog').AbstractLoggerOptions} [logger]
30
30
  */
31
31
 
@@ -41,9 +41,9 @@ export default class PodletClientContentResolver {
41
41
  */
42
42
  // @ts-expect-error Deliberate default empty options for better error messages
43
43
  constructor(options = {}) {
44
- this.#http = options.http || new HTTP();
45
44
  const name = options.clientName;
46
45
  this.#log = abslog(options.logger);
46
+ this.#http = options.http || new HttpClient({ logger: options.logger });
47
47
  this.#metrics = new Metrics();
48
48
  this.#histogram = this.#metrics.histogram({
49
49
  name: 'podium_client_resolver_content_resolve',
@@ -62,6 +62,7 @@ export default class PodletClientContentResolver {
62
62
  error,
63
63
  );
64
64
  });
65
+ this.#http.metrics.pipe(this.#metrics);
65
66
  }
66
67
 
67
68
  get metrics() {
@@ -153,11 +154,16 @@ export default class PodletClientContentResolver {
153
154
  );
154
155
 
155
156
  try {
157
+ const url = new URL(uri);
156
158
  const {
157
159
  statusCode,
158
160
  headers: hdrs,
159
161
  body,
160
- } = await this.#http.request(uri, reqOptions);
162
+ } = await this.#http.request({
163
+ origin: url.origin,
164
+ path: url.pathname,
165
+ ...reqOptions,
166
+ });
161
167
 
162
168
  const parsedAssetObjects = parseLinkHeaders(hdrs.link);
163
169
 
@@ -252,7 +258,6 @@ export default class PodletClientContentResolver {
252
258
  if (outgoing.redirectable && statusCode >= 300) {
253
259
  outgoing.redirect = {
254
260
  statusCode,
255
- // @ts-expect-error TODO: look into what happens if the podlet returns more than one location header
256
261
  location: hdrs && hdrs.location,
257
262
  };
258
263
  }
@@ -3,9 +3,9 @@ import Metrics from '@metrics/client';
3
3
  import { join, dirname } from 'path';
4
4
  import { fileURLToPath } from 'url';
5
5
  import fs from 'fs';
6
- import HTTP from './http.js';
7
6
  import { parseLinkHeaders, filterAssets } from './utils.js';
8
7
  import { AssetJs, AssetCss } from '@podium/utils';
8
+ import HttpClient from '@podium/http-client';
9
9
 
10
10
  const currentDirectory = dirname(fileURLToPath(import.meta.url));
11
11
 
@@ -20,7 +20,7 @@ const UA_STRING = `${pkg.name} ${pkg.version}`;
20
20
  /**
21
21
  * @typedef {object} PodletClientFallbackResolverOptions
22
22
  * @property {string} clientName
23
- * @property {import('./http.js').default} [http]
23
+ * @property {import('@podium/http-client').default} [http]
24
24
  * @property {import('abslog').AbstractLoggerOptions} [logger]
25
25
  */
26
26
 
@@ -36,9 +36,9 @@ export default class PodletClientFallbackResolver {
36
36
  */
37
37
  // @ts-expect-error Deliberate default empty options for better error messages
38
38
  constructor(options = {}) {
39
- this.#http = options.http || new HTTP();
40
39
  const name = options.clientName;
41
40
  this.#log = abslog(options.logger);
41
+ this.#http = options.http || new HttpClient({ logger: options.logger });
42
42
  this.#metrics = new Metrics();
43
43
  this.#histogram = this.#metrics.histogram({
44
44
  name: 'podium_client_resolver_fallback_resolve',
@@ -57,6 +57,7 @@ export default class PodletClientFallbackResolver {
57
57
  error,
58
58
  );
59
59
  });
60
+ this.#http.metrics.pipe(this.#metrics);
60
61
  }
61
62
 
62
63
  get metrics() {
@@ -114,11 +115,16 @@ export default class PodletClientFallbackResolver {
114
115
  this.#log.debug(
115
116
  `start reading fallback content from remote resource - resource: ${outgoing.name} - url: ${outgoing.fallbackUri}`,
116
117
  );
118
+ const url = new URL(outgoing.fallbackUri);
117
119
  const {
118
120
  statusCode,
119
121
  body,
120
122
  headers: resHeaders,
121
- } = await this.#http.request(outgoing.fallbackUri, reqOptions);
123
+ } = await this.#http.request({
124
+ origin: url.origin,
125
+ path: url.pathname,
126
+ ...reqOptions,
127
+ });
122
128
 
123
129
  const parsedAssetObjects = parseLinkHeaders(resHeaders.link);
124
130
 
package/lib/resolver.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import Metrics from '@metrics/client';
2
2
  import abslog from 'abslog';
3
3
  import assert from 'assert';
4
- import HTTP from './http.js';
4
+ import HttpClient from '@podium/http-client';
5
5
  import Manifest from './resolver.manifest.js';
6
6
  import Fallback from './resolver.fallback.js';
7
7
  import Content from './resolver.content.js';
@@ -34,18 +34,18 @@ export default class PodletClientResolver {
34
34
  );
35
35
 
36
36
  const log = abslog(options.logger);
37
- const http = new HTTP();
37
+ const httpClient = new HttpClient({
38
+ clientName: options.clientName,
39
+ logger: options.logger,
40
+ });
38
41
  this.#cache = new Cache(registry, options);
39
42
  this.#manifest = new Manifest({
40
43
  clientName: options.clientName,
41
44
  logger: options.logger,
42
- http,
43
- });
44
- this.#fallback = new Fallback({ ...options, http });
45
- this.#content = new Content({
46
- ...options,
47
- http,
45
+ http: httpClient,
48
46
  });
47
+ this.#fallback = new Fallback({ ...options, http: httpClient });
48
+ this.#content = new Content({ ...options, http: httpClient });
49
49
  this.#metrics = new Metrics();
50
50
 
51
51
  this.#metrics.on('error', (error) => {
@@ -55,6 +55,7 @@ export default class PodletClientResolver {
55
55
  );
56
56
  });
57
57
 
58
+ httpClient.metrics.pipe(this.#metrics);
58
59
  this.#content.metrics.pipe(this.#metrics);
59
60
  this.#fallback.metrics.pipe(this.#metrics);
60
61
  this.#manifest.metrics.pipe(this.#metrics);
@@ -6,7 +6,7 @@ import * as utils from '@podium/utils';
6
6
  import { join, dirname } from 'path';
7
7
  import { fileURLToPath } from 'url';
8
8
  import fs from 'fs';
9
- import HTTP from './http.js';
9
+ import HttpClient from '@podium/http-client';
10
10
 
11
11
  const currentDirectory = dirname(fileURLToPath(import.meta.url));
12
12
 
@@ -22,7 +22,7 @@ const UA_STRING = `${pkg.name} ${pkg.version}`;
22
22
  * @typedef {object} PodletClientManifestResolverOptions
23
23
  * @property {string} clientName
24
24
  * @property {import('abslog').AbstractLoggerOptions} [logger]
25
- * @property {import('./http.js').default} [http]
25
+ * @property {import('@podium/http-client').default} [http]
26
26
  */
27
27
 
28
28
  export default class PodletClientManifestResolver {
@@ -37,9 +37,9 @@ export default class PodletClientManifestResolver {
37
37
  */
38
38
  // @ts-expect-error Deliberate default empty options for better error messages
39
39
  constructor(options = {}) {
40
- this.#http = options.http || new HTTP();
41
40
  const name = options.clientName;
42
41
  this.#log = abslog(options.logger);
42
+ this.#http = options.http || new HttpClient({ logger: this.#log });
43
43
  this.#metrics = new Metrics();
44
44
  this.#histogram = this.#metrics.histogram({
45
45
  name: 'podium_client_resolver_manifest_resolve',
@@ -58,6 +58,7 @@ export default class PodletClientManifestResolver {
58
58
  error,
59
59
  );
60
60
  });
61
+ this.#http.metrics.pipe(this.#metrics);
61
62
  }
62
63
 
63
64
  get metrics() {
@@ -97,10 +98,12 @@ export default class PodletClientManifestResolver {
97
98
  );
98
99
 
99
100
  try {
100
- const response = await this.#http.request(
101
- outgoing.manifestUri,
102
- reqOptions,
103
- );
101
+ const url = new URL(outgoing.manifestUri);
102
+ const response = await this.#http.request({
103
+ origin: url.origin,
104
+ path: url.pathname,
105
+ ...reqOptions,
106
+ });
104
107
  const { statusCode, headers: hdrs, body } = response;
105
108
 
106
109
  // Remote responds but with an http error code
@@ -120,11 +123,10 @@ export default class PodletClientManifestResolver {
120
123
  await body.text();
121
124
  return outgoing;
122
125
  }
123
-
126
+ // Body must be consumed; https://github.com/nodejs/undici/issues/583#issuecomment-855384858
127
+ const schema = await body.json();
124
128
  const manifest = validateManifest(
125
- /** @type {import("@podium/schemas").PodletManifestSchema} */ (
126
- await body.json()
127
- ),
129
+ /** @type {import("@podium/schemas").PodletManifestSchema} */ schema,
128
130
  );
129
131
 
130
132
  // Manifest validation error
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@podium/client",
3
- "version": "5.2.4",
3
+ "version": "5.2.5-beta.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -39,11 +39,13 @@
39
39
  "dependencies": {
40
40
  "@hapi/boom": "10.0.1",
41
41
  "@metrics/client": "2.5.4",
42
+ "@podium/http-client": "1.0.0-beta.9",
42
43
  "@podium/schemas": "5.1.0",
43
44
  "@podium/utils": "5.4.0",
44
45
  "abslog": "2.4.4",
45
46
  "http-cache-semantics": "^4.0.3",
46
47
  "lodash.clonedeep": "^4.5.0",
48
+ "opossum": "^8.3.0",
47
49
  "ttl-mem-cache": "4.1.0",
48
50
  "undici": "6.21.0"
49
51
  },
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @typedef {object} PodletClientContentResolverOptions
3
3
  * @property {string} clientName
4
- * @property {import('./http.js').default} [http]
4
+ * @property {import('@podium/http-client').default} [http]
5
5
  * @property {import('abslog').AbstractLoggerOptions} [logger]
6
6
  */
7
7
  export default class PodletClientContentResolver {
@@ -23,7 +23,7 @@ export default class PodletClientContentResolver {
23
23
  }
24
24
  export type PodletClientContentResolverOptions = {
25
25
  clientName: string;
26
- http?: import("./http.js").default;
26
+ http?: any;
27
27
  logger?: import("abslog").AbstractLoggerOptions;
28
28
  };
29
29
  import Metrics from '@metrics/client';
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @typedef {object} PodletClientFallbackResolverOptions
3
3
  * @property {string} clientName
4
- * @property {import('./http.js').default} [http]
4
+ * @property {import('@podium/http-client').default} [http]
5
5
  * @property {import('abslog').AbstractLoggerOptions} [logger]
6
6
  */
7
7
  export default class PodletClientFallbackResolver {
@@ -23,7 +23,7 @@ export default class PodletClientFallbackResolver {
23
23
  }
24
24
  export type PodletClientFallbackResolverOptions = {
25
25
  clientName: string;
26
- http?: import("./http.js").default;
26
+ http?: any;
27
27
  logger?: import("abslog").AbstractLoggerOptions;
28
28
  };
29
29
  import Metrics from '@metrics/client';
@@ -2,7 +2,7 @@
2
2
  * @typedef {object} PodletClientManifestResolverOptions
3
3
  * @property {string} clientName
4
4
  * @property {import('abslog').AbstractLoggerOptions} [logger]
5
- * @property {import('./http.js').default} [http]
5
+ * @property {import('@podium/http-client').default} [http]
6
6
  */
7
7
  export default class PodletClientManifestResolver {
8
8
  /**
@@ -22,6 +22,6 @@ export default class PodletClientManifestResolver {
22
22
  export type PodletClientManifestResolverOptions = {
23
23
  clientName: string;
24
24
  logger?: import("abslog").AbstractLoggerOptions;
25
- http?: import("./http.js").default;
25
+ http?: any;
26
26
  };
27
27
  import Metrics from '@metrics/client';