@podium/podlet 5.0.0-next.7 → 5.0.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,131 @@
1
+ # [5.0.0](https://github.com/podium-lib/podlet/compare/v4.5.0...v5.0.0) (2023-11-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Use latest proxy ([42f622c](https://github.com/podium-lib/podlet/commit/42f622c64f86b49796cc34e0871371ae74088cf1))
7
+
8
+
9
+ ### Features
10
+
11
+ * add support for strategy and scope via @podium/schemas and @podium/utils update ([128eaa1](https://github.com/podium-lib/podlet/commit/128eaa1b3de35581d8fe537c63ebc001ce82c282))
12
+ * Convert to ESM ([cedb222](https://github.com/podium-lib/podlet/commit/cedb222127c25469bf856942463ce02491d5ad08))
13
+ * Drop node 10.x support ([1f9ca4f](https://github.com/podium-lib/podlet/commit/1f9ca4f97e8da9addac4e70813ba981e7742ec9e))
14
+ * Remove deprecated return value on .js and .css methods ([4052c02](https://github.com/podium-lib/podlet/commit/4052c02750a0071487bfa1ffb76ccebcc55bf185))
15
+
16
+
17
+ ### BREAKING CHANGES
18
+
19
+ * Convert from CommonJS module to ESM
20
+ * In version 4 of podium it became possible to set multiple assets to a podlet through its `.js()` and `.css()` methods. This did make it impossible to let these methods return a resonable value, but to keep a backwards compabillity with version 3 of Podium, the first item passed in was returned for compabillity. This removes this compaillity with version 3 of Podium.
21
+ * Only support node 12 and 14.
22
+
23
+ # [5.0.0-next.8](https://github.com/podium-lib/podlet/compare/v5.0.0-next.7...v5.0.0-next.8) (2023-11-22)
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * adding type information closes [#344](https://github.com/podium-lib/podlet/issues/344) ([28e6ed9](https://github.com/podium-lib/podlet/commit/28e6ed9508d9218046f925e85fd97d17479bf390))
29
+ * CJS-shaped export in type definition ([fd96046](https://github.com/podium-lib/podlet/commit/fd96046ca16b89d02526453ff3cbf6d3ace694bd))
30
+ * **deps:** update all dependencies (non-major) ([bf963ad](https://github.com/podium-lib/podlet/commit/bf963ad4f82ca1dabad6a960c2a836f075512385))
31
+ * **deps:** update all dependencies (non-major) ([4475c67](https://github.com/podium-lib/podlet/commit/4475c67d637af2bcc7f843eed386614efc3d7c61))
32
+ * **deps:** update all dependencies (non-major) ([0a47c72](https://github.com/podium-lib/podlet/commit/0a47c7289869c023235d32d301e83fd5de77f7f2))
33
+ * **deps:** update all dependencies (non-major) ([08a5c70](https://github.com/podium-lib/podlet/commit/08a5c702797432b7668195d10c96def7bfc0c0bf))
34
+ * **deps:** update all dependencies (non-major) ([0d14c8a](https://github.com/podium-lib/podlet/commit/0d14c8aae8a69ba80a32021fcd87f7f6e06b791f))
35
+ * **deps:** update all dependencies (non-major) ([94707a5](https://github.com/podium-lib/podlet/commit/94707a5f92f72af94b23b77ac6b27b1dd379efcb))
36
+ * **deps:** update all dependencies (non-major) ([6ab8c85](https://github.com/podium-lib/podlet/commit/6ab8c85ff5ef299049a21e0dc3882d1a8ae1a837))
37
+ * **deps:** update all dependencies (non-major) ([bf8620d](https://github.com/podium-lib/podlet/commit/bf8620dc2693a5c25daa9ae26969b591848ec541))
38
+ * **types:** Add pathname() method to Podium type ([779f8c3](https://github.com/podium-lib/podlet/commit/779f8c33dc92183acec90cd647865a83a99b558e))
39
+
40
+
41
+ ### Features
42
+
43
+ * filter assets by scope if scope is provided ([95129b3](https://github.com/podium-lib/podlet/commit/95129b3e2de5b955cc4b5a2aa5942ddc0af39e8e))
44
+
45
+ # [4.5.0](https://github.com/podium-lib/podlet/compare/v4.4.75...v4.5.0) (2023-11-22)
46
+
47
+
48
+ ### Features
49
+
50
+ * filter assets by scope if scope is provided ([95129b3](https://github.com/podium-lib/podlet/commit/95129b3e2de5b955cc4b5a2aa5942ddc0af39e8e))
51
+
52
+ ## [4.4.75](https://github.com/podium-lib/podlet/compare/v4.4.74...v4.4.75) (2023-11-20)
53
+
54
+
55
+ ### Bug Fixes
56
+
57
+ * **deps:** update all dependencies (non-major) ([bf963ad](https://github.com/podium-lib/podlet/commit/bf963ad4f82ca1dabad6a960c2a836f075512385))
58
+
59
+ ## [4.4.74](https://github.com/podium-lib/podlet/compare/v4.4.73...v4.4.74) (2023-10-23)
60
+
61
+
62
+ ### Bug Fixes
63
+
64
+ * **deps:** update all dependencies (non-major) ([4475c67](https://github.com/podium-lib/podlet/commit/4475c67d637af2bcc7f843eed386614efc3d7c61))
65
+
66
+ ## [4.4.73](https://github.com/podium-lib/podlet/compare/v4.4.72...v4.4.73) (2023-10-09)
67
+
68
+
69
+ ### Bug Fixes
70
+
71
+ * CJS-shaped export in type definition ([fd96046](https://github.com/podium-lib/podlet/commit/fd96046ca16b89d02526453ff3cbf6d3ace694bd))
72
+
73
+ ## [4.4.72](https://github.com/podium-lib/podlet/compare/v4.4.71...v4.4.72) (2023-09-25)
74
+
75
+
76
+ ### Bug Fixes
77
+
78
+ * **deps:** update all dependencies (non-major) ([0a47c72](https://github.com/podium-lib/podlet/commit/0a47c7289869c023235d32d301e83fd5de77f7f2))
79
+
80
+ ## [4.4.71](https://github.com/podium-lib/podlet/compare/v4.4.70...v4.4.71) (2023-09-18)
81
+
82
+
83
+ ### Bug Fixes
84
+
85
+ * **deps:** update all dependencies (non-major) ([08a5c70](https://github.com/podium-lib/podlet/commit/08a5c702797432b7668195d10c96def7bfc0c0bf))
86
+
87
+ ## [4.4.70](https://github.com/podium-lib/podlet/compare/v4.4.69...v4.4.70) (2023-09-13)
88
+
89
+
90
+ ### Bug Fixes
91
+
92
+ * adding type information closes [#344](https://github.com/podium-lib/podlet/issues/344) ([28e6ed9](https://github.com/podium-lib/podlet/commit/28e6ed9508d9218046f925e85fd97d17479bf390))
93
+
94
+ ## [4.4.69](https://github.com/podium-lib/podlet/compare/v4.4.68...v4.4.69) (2023-01-09)
95
+
96
+
97
+ ### Bug Fixes
98
+
99
+ * **deps:** update all dependencies (non-major) ([0d14c8a](https://github.com/podium-lib/podlet/commit/0d14c8aae8a69ba80a32021fcd87f7f6e06b791f))
100
+
101
+ ## [4.4.68](https://github.com/podium-lib/podlet/compare/v4.4.67...v4.4.68) (2022-12-12)
102
+
103
+
104
+ ### Bug Fixes
105
+
106
+ * **deps:** update all dependencies (non-major) ([94707a5](https://github.com/podium-lib/podlet/commit/94707a5f92f72af94b23b77ac6b27b1dd379efcb))
107
+
108
+ ## [4.4.67](https://github.com/podium-lib/podlet/compare/v4.4.66...v4.4.67) (2022-11-21)
109
+
110
+
111
+ ### Bug Fixes
112
+
113
+ * **deps:** update all dependencies (non-major) ([6ab8c85](https://github.com/podium-lib/podlet/commit/6ab8c85ff5ef299049a21e0dc3882d1a8ae1a837))
114
+
115
+ ## [4.4.66](https://github.com/podium-lib/podlet/compare/v4.4.65...v4.4.66) (2022-11-14)
116
+
117
+
118
+ ### Bug Fixes
119
+
120
+ * **deps:** update all dependencies (non-major) ([bf8620d](https://github.com/podium-lib/podlet/commit/bf8620dc2693a5c25daa9ae26969b591848ec541))
121
+
122
+ ## [4.4.65](https://github.com/podium-lib/podlet/compare/v4.4.64...v4.4.65) (2022-09-02)
123
+
124
+
125
+ ### Bug Fixes
126
+
127
+ * **types:** Add pathname() method to Podium type ([779f8c3](https://github.com/podium-lib/podlet/commit/779f8c33dc92183acec90cd647865a83a99b558e))
128
+
1
129
  # [5.0.0-next.7](https://github.com/podium-lib/podlet/compare/v5.0.0-next.6...v5.0.0-next.7) (2023-11-20)
2
130
 
3
131
 
package/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { HttpIncoming, AssetJs, AssetCss } from '@podium/utils';
2
+ import PodiumProxy from '@podium/proxy';
3
+ import MetricsClient from '@metrics/client';
2
4
 
3
5
  // Use declaration merging to extend Express.
4
6
  declare global {
@@ -9,19 +11,38 @@ declare global {
9
11
  }
10
12
  }
11
13
 
12
- export interface PodletOptions {
14
+ declare class Podlet {
15
+ constructor(options: Podlet.PodletOptions);
16
+
13
17
  name: string;
14
- pathname: string;
18
+
15
19
  version: string;
16
- manifest?: string;
17
- content?: string;
18
- fallback?: string;
19
- logger?: any;
20
- development?: boolean;
21
- }
22
20
 
23
- export default class Podlet {
24
- constructor(options: PodletOptions);
21
+ manifestRoute: string;
22
+
23
+ contentRoute: string;
24
+
25
+ fallbackRoute: string;
26
+
27
+ cssRoute: AssetCss[];
28
+
29
+ jsRoute: AssetJs[];
30
+
31
+ proxyRoutes: Record<string, string>;
32
+
33
+ log: Podlet.AbsLogger;
34
+
35
+ development: boolean;
36
+
37
+ httpProxy: PodiumProxy;
38
+
39
+ baseContext: Podlet.PodletContext;
40
+
41
+ defaultContext: Podlet.PodletContext;
42
+
43
+ metrics: MetricsClient;
44
+
45
+ pathname(): string;
25
46
 
26
47
  middleware(): (req: any, res: any, next: any) => Promise<void>;
27
48
 
@@ -39,19 +60,55 @@ export default class Podlet {
39
60
 
40
61
  defaults(context: any): any;
41
62
 
42
- view(
63
+ view<T = { [key: string]: unknown }>(
43
64
  template: (
44
- incoming: HttpIncoming,
65
+ incoming: HttpIncoming<T>,
45
66
  fragment: string,
46
67
  ...args: unknown[]
47
68
  ) => string,
48
69
  ): void;
49
70
 
50
- render(
51
- incoming: HttpIncoming,
71
+ render<T = { [key: string]: unknown }>(
72
+ incoming: HttpIncoming<T>,
52
73
  fragment: string,
53
74
  ...args: unknown[]
54
75
  ): string;
55
76
 
56
77
  process(incoming: HttpIncoming): Promise<HttpIncoming>;
57
78
  }
79
+
80
+ declare namespace Podlet {
81
+ export type AbsLogger = {
82
+ trace: LogFunction;
83
+ debug: LogFunction;
84
+ info: LogFunction;
85
+ warn: LogFunction;
86
+ error: LogFunction;
87
+ fatal: LogFunction;
88
+ };
89
+
90
+ type LogFunction = (...args: any) => void;
91
+
92
+ export type PodletContext = {
93
+ debug: 'true' | 'false';
94
+ locale: string;
95
+ deviceType: string;
96
+ requestedBy: string;
97
+ mountOrigin: string;
98
+ mountPathname: string;
99
+ publicPathname: string;
100
+ };
101
+
102
+ export interface PodletOptions {
103
+ name: string;
104
+ pathname: string;
105
+ version: string;
106
+ manifest?: string;
107
+ content?: string;
108
+ fallback?: string;
109
+ logger?: Console | AbsLogger;
110
+ development?: boolean;
111
+ }
112
+ }
113
+
114
+ export = Podlet;
package/lib/podlet.js CHANGED
@@ -28,6 +28,7 @@ const { template } = utils;
28
28
  const _sanitize = Symbol('_sanitize');
29
29
  const _addCssAsset = Symbol('_addCssAsset');
30
30
  const _addJsAsset = Symbol('_addJsAsset');
31
+ const _currentScope = Symbol('_currentScope');
31
32
 
32
33
 
33
34
  export default class PodiumPodlet {
@@ -314,8 +315,16 @@ export default class PodiumPodlet {
314
315
 
315
316
  async process(incoming, { proxy = true } = {}) {
316
317
  incoming.name = this.name;
317
- incoming.css = this.cssRoute;
318
- incoming.js = this.jsRoute;
318
+ incoming.css = this.cssRoute.filter(
319
+ ({ scope = 'all' }) =>
320
+ scope === this[_currentScope](incoming) ||
321
+ scope === 'all',
322
+ );
323
+ incoming.js = this.jsRoute.filter(
324
+ ({ scope = 'all' }) =>
325
+ scope === this[_currentScope](incoming) ||
326
+ scope === 'all',
327
+ );
319
328
 
320
329
  // Determine if request comes from layout server or not
321
330
  if (
@@ -397,4 +406,21 @@ export default class PodiumPodlet {
397
406
  }
398
407
  return uri;
399
408
  }
409
+
410
+ [_currentScope](incoming) {
411
+ const fallback = this.fallback({ prefix: true });
412
+ const content = this.content({ prefix: true });
413
+ const { pathname } = incoming.url;
414
+
415
+ // only check fallback if defined
416
+ // match fallback first since fallback is a more accurate match since
417
+ // fallback cannot take dynamic path segments and we can use exact matching
418
+ if (!!fallback && pathname === fallback) return 'fallback';
419
+
420
+ // fallback didn't match so check content
421
+ // we have to use startsWith since content may contain dynamic path segments
422
+ if (pathname.startsWith(content)) return 'content';
423
+
424
+ return 'all';
425
+ }
400
426
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@podium/podlet",
3
- "version": "5.0.0-next.7",
3
+ "version": "5.0.0",
4
4
  "type": "module",
5
5
  "description": "Module for building page fragment servers in a micro frontend architecture.",
6
6
  "license": "MIT",
@@ -29,27 +29,31 @@
29
29
  "test": "tap --no-check-coverage"
30
30
  },
31
31
  "dependencies": {
32
- "@metrics/client": "2.5.0",
33
- "@podium/proxy": "5.0.0-next.7",
34
- "@podium/schemas": "5.0.0-next.7",
35
- "@podium/utils": "5.0.0-next.10",
32
+ "@podium/schemas": "5.0.0",
33
+ "@podium/utils": "5.0.0",
34
+ "@podium/proxy": "5.0.0",
35
+ "@metrics/client": "2.5.2",
36
36
  "abslog": "2.4.0",
37
- "ajv": "8.11.0",
37
+ "ajv": "8.12.0",
38
38
  "objobj": "1.0.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@semantic-release/changelog": "6.0.1",
42
- "@semantic-release/git": "10.0.1",
43
- "semantic-release": "19.0.5",
44
- "@podium/test-utils": "2.5.2",
45
41
  "@babel/eslint-parser": "7.19.1",
46
42
  "eslint": "8.23.1",
47
43
  "eslint-config-airbnb-base": "15.0.0",
48
- "eslint-config-prettier": "8.5.0",
49
- "eslint-plugin-import": "2.26.0",
50
44
  "eslint-plugin-prettier": "4.2.1",
51
- "express": "4.18.1",
52
- "prettier": "2.7.1",
53
- "tap": "16.3.0"
45
+ "@semantic-release/changelog": "6.0.3",
46
+ "@semantic-release/commit-analyzer": "9.0.2",
47
+ "@semantic-release/git": "10.0.1",
48
+ "@semantic-release/github": "8.1.0",
49
+ "@semantic-release/npm": "9.0.2",
50
+ "@semantic-release/release-notes-generator": "10.0.3",
51
+ "semantic-release": "19.0.5",
52
+ "@podium/test-utils": "2.5.2",
53
+ "eslint-config-prettier": "8.10.0",
54
+ "eslint-plugin-import": "2.29.0",
55
+ "express": "4.18.2",
56
+ "prettier": "2.8.8",
57
+ "tap": "16.3.9"
54
58
  }
55
59
  }