@podium/client 5.2.1 → 5.3.0-next.1

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,9 +1,9 @@
1
- ## [5.2.1](https://github.com/podium-lib/client/compare/v5.2.0...v5.2.1) (2024-11-13)
1
+ # [5.3.0-next.1](https://github.com/podium-lib/client/compare/v5.2.0...v5.3.0-next.1) (2024-11-13)
2
2
 
3
3
 
4
- ### Bug Fixes
4
+ ### Features
5
5
 
6
- * **deps:** update dependency @podium/utils to v5.4.0 ([#443](https://github.com/podium-lib/client/issues/443)) ([efbe56b](https://github.com/podium-lib/client/commit/efbe56bbed26871566705856adbfa622702bdfa0))
6
+ * track podlet assets ([39022a3](https://github.com/podium-lib/client/commit/39022a3c87184e5f524828591c8185d8a3fc2995))
7
7
 
8
8
  # [5.2.0](https://github.com/podium-lib/client/compare/v5.1.18...v5.2.0) (2024-11-06)
9
9
 
package/README.md CHANGED
@@ -152,7 +152,6 @@ The following values can be provided:
152
152
  - `throwable` - {Boolean} - Defines whether an error should be thrown if a failure occurs during the process of fetching a podium component. Defaults to `false` - Optional.
153
153
  - `excludeBy` - {Object} - Lets you define a set of rules where a `fetch` call will not be resolved if it matches. - Optional.
154
154
  - `includeBy` - {Object} - Inverse of `excludeBy`. Setting both at the same time will throw. - Optional.
155
- - `earlyHints` - {boolean} - Can be used to disable early hints from being sent to the browser for this resource, see [HTTP Status 103 Early Hints](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/103).
156
155
 
157
156
  ##### `excludeBy` and `includeBy`
158
157
 
@@ -1,6 +1,6 @@
1
1
  import { PassThrough } from 'stream';
2
2
  import assert from 'assert';
3
- import { toPreloadAssetObjects, filterAssets } from './utils.js';
3
+ import { filterAssets } from './utils.js';
4
4
 
5
5
  /**
6
6
  * @typedef {object} PodiumClientHttpOutgoingOptions
@@ -70,6 +70,7 @@ export default class PodletClientHttpOutgoing extends PassThrough {
70
70
  #uri;
71
71
  #js;
72
72
  #css;
73
+ #assetsReceived = false;
73
74
 
74
75
  /**
75
76
  * @constructor
@@ -332,6 +333,26 @@ export default class PodletClientHttpOutgoing extends PassThrough {
332
333
  return this.#isFallback;
333
334
  }
334
335
 
336
+ get assetsReceived() {
337
+ return this.#assetsReceived;
338
+ }
339
+
340
+ /**
341
+ * Set the assetsReceived flag.
342
+ * This is used to signal to the assets object that the client has received assets for a given podlet so it can track
343
+ * which podlets have sent their assets.
344
+ * @param {boolean} value
345
+ */
346
+ set assetsReceived(value) {
347
+ this.#assetsReceived = value;
348
+ if (this.#assetsReceived) {
349
+ this.#incoming?.assets?.addReceivedAsset(this.#name, {
350
+ js: this.js,
351
+ css: this.css,
352
+ });
353
+ }
354
+ }
355
+
335
356
  pushFallback() {
336
357
  // @ts-expect-error Internal property
337
358
  this.push(this.#manifest._fallback);
@@ -349,21 +370,8 @@ export default class PodletClientHttpOutgoing extends PassThrough {
349
370
  : filterAssets('fallback', this.#manifest.css);
350
371
  this.push(null);
351
372
  this.#isFallback = true;
352
- // assume the hints from the podlet have failed and fallback assets will be used
353
- this.hintsReceived = true;
354
- }
355
-
356
- writeEarlyHints(cb = () => {}) {
357
- if (this.#incoming.response.writeEarlyHints) {
358
- const preloads = toPreloadAssetObjects([
359
- ...(this.js || []),
360
- ...(this.css || []),
361
- ]);
362
- const link = preloads.map((preload) => preload.toHeader());
363
- if (link.length) {
364
- this.#incoming.response.writeEarlyHints({ link }, cb);
365
- }
366
- }
373
+ // assume the assets from the podlet have failed and fallback assets will be used
374
+ this.assetsReceived = true;
367
375
  }
368
376
 
369
377
  get [Symbol.toStringTag]() {
@@ -267,6 +267,9 @@ export default class PodletClientContentResolver {
267
267
  }),
268
268
  );
269
269
 
270
+ // mark assets as received
271
+ outgoing.assetsReceived = true;
272
+
270
273
  // @ts-ignore
271
274
  pipeline([body, outgoing], (err) => {
272
275
  if (err) {
package/lib/resolver.js CHANGED
@@ -11,7 +11,6 @@ import Cache from './resolver.cache.js';
11
11
  * @typedef {object} PodletClientResolverOptions
12
12
  * @property {string} clientName
13
13
  * @property {import('abslog').AbstractLoggerOptions} [logger]
14
- * @property {boolean} [earlyHints]
15
14
  */
16
15
 
17
16
  export default class PodletClientResolver {
package/lib/resource.js CHANGED
@@ -105,6 +105,8 @@ export default class PodiumClientResource {
105
105
  throw new TypeError(
106
106
  'you must pass an instance of "HttpIncoming" as the first argument to the .fetch() method',
107
107
  );
108
+ // set expectation to receive a response from this podlet.
109
+ incoming.assets.addExpectedAsset(this.#options.name);
108
110
  const outgoing = new HttpOutgoing(this.#options, reqOptions, incoming);
109
111
 
110
112
  if (this.#options.excludeBy) {
@@ -192,6 +194,8 @@ export default class PodiumClientResource {
192
194
  throw new TypeError(
193
195
  'you must pass an instance of "HttpIncoming" as the first argument to the .stream() method',
194
196
  );
197
+ // set expectation to receive a response from this podlet.
198
+ incoming.assets.addExpectedAsset(this.#options.name);
195
199
  const outgoing = new HttpOutgoing(this.#options, reqOptions, incoming);
196
200
  this.#state.setInitializingState();
197
201
  this.#resolver.resolve(outgoing);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@podium/client",
3
- "version": "5.2.1",
3
+ "version": "5.3.0-next.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -124,9 +124,15 @@ export default class PodletClientHttpOutgoing extends PassThrough {
124
124
  * @see https://podium-lib.io/docs/podlet/fallbacks
125
125
  */
126
126
  get isFallback(): boolean;
127
+ /**
128
+ * Set the assetsReceived flag.
129
+ * This is used to signal to the assets object that the client has received assets for a given podlet so it can track
130
+ * which podlets have sent their assets.
131
+ * @param {boolean} value
132
+ */
133
+ set assetsReceived(value: boolean);
134
+ get assetsReceived(): boolean;
127
135
  pushFallback(): void;
128
- hintsReceived: boolean;
129
- writeEarlyHints(cb?: () => void): void;
130
136
  get [Symbol.toStringTag](): string;
131
137
  #private;
132
138
  }
@@ -2,7 +2,6 @@
2
2
  * @typedef {object} PodletClientResolverOptions
3
3
  * @property {string} clientName
4
4
  * @property {import('abslog').AbstractLoggerOptions} [logger]
5
- * @property {boolean} [earlyHints]
6
5
  */
7
6
  export default class PodletClientResolver {
8
7
  /**
@@ -32,6 +31,5 @@ export default class PodletClientResolver {
32
31
  export type PodletClientResolverOptions = {
33
32
  clientName: string;
34
33
  logger?: import("abslog").AbstractLoggerOptions;
35
- earlyHints?: boolean;
36
34
  };
37
35
  import Metrics from '@metrics/client';