@lwrjs/core 0.8.0-alpha.12 → 0.8.0-alpha.13

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.
@@ -31,6 +31,7 @@ var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
31
31
  var import_view_registry = __toModule(require("@lwrjs/view-registry"));
32
32
  var import_utils = __toModule(require("./utils.cjs"));
33
33
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
34
+ var import_router = __toModule(require("@lwrjs/router"));
34
35
  function uiMiddleware(app, context) {
35
36
  const {viewRegistry, moduleRegistry, runtimeEnvironment: defaultRuntimeEnvironment} = context;
36
37
  const {environment: environmentConfig, routes, errorRoutes} = context.appConfig;
@@ -145,16 +146,25 @@ function uiMiddleware(app, context) {
145
146
  await sendViewResponse(req, res, route);
146
147
  });
147
148
  } else {
148
- app.get(route.path, async (req, res) => {
149
- await sendViewResponse(req, res, route);
150
- });
151
- app.get([
152
- `/:apiVersion/application/:format/l/:locale/ai/:appId${route.path}`,
153
- `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId${route.path}`,
154
- `/:apiVersion/application/:format/ai/:appId${route.path}`,
155
- `/:apiVersion/application/:format/e/:environment/ai/:appId${route.path}`
156
- ], async (req, res) => {
157
- await sendViewResponse(req, res, route);
149
+ const serverPath = route.path;
150
+ const paths = [serverPath];
151
+ const subRoutes = route.subRoutes ? (0, import_router.getClientRoutes)(route.subRoutes) : void 0;
152
+ if (subRoutes) {
153
+ const prefix = serverPath === "/" ? "" : serverPath;
154
+ subRoutes.routes.forEach((r) => paths.push(`${prefix}${r.uri}`));
155
+ }
156
+ paths.forEach((path) => {
157
+ app.get(path, async (req, res) => {
158
+ await sendViewResponse(req, res, route);
159
+ });
160
+ app.get([
161
+ `/:apiVersion/application/:format/l/:locale/ai/:appId${path}`,
162
+ `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId${path}`,
163
+ `/:apiVersion/application/:format/ai/:appId${path}`,
164
+ `/:apiVersion/application/:format/e/:environment/ai/:appId${path}`
165
+ ], async (req, res) => {
166
+ await sendViewResponse(req, res, route);
167
+ });
158
168
  });
159
169
  }
160
170
  });
@@ -212,7 +212,7 @@ var SiteGenerator = class {
212
212
  const assets = viewDefinition.viewRecord.assetReferences || [];
213
213
  for (const asset of assets) {
214
214
  const assetUrl = asset.override?.uri || asset.url;
215
- if (assetUrl && !assetUrl.startsWith("data:")) {
215
+ if (assetUrl && !(0, import_shared_utils.isSelfUrl)(assetUrl)) {
216
216
  dispatchRequests.push(this.dispatchResourceRecursive(assetUrl, dispatcher, {resourceType: "asset", asset}, siteConfig));
217
217
  }
218
218
  }
@@ -281,7 +281,10 @@ var SiteGenerator = class {
281
281
  const assetReferences = metadata?.asset?.metadata?.assetReferences || [];
282
282
  const dispatchRequests = [];
283
283
  for (const ref of assetReferences) {
284
- dispatchRequests.push(this.dispatchResourceRecursive(ref.override?.uri || ref.url, dispatcher, {resourceType: "asset", asset: metadata?.asset}, siteConfig));
284
+ const refUrl = ref.override?.uri || ref.url;
285
+ dispatchRequests.push(this.dispatchResourceRecursive(refUrl, dispatcher, {resourceType: "asset", asset: metadata?.asset}, siteConfig).catch((err) => {
286
+ import_shared_utils.logger.warn(`Failed to fetch asset refrence => ${refUrl} from ${url}`, err);
287
+ }));
285
288
  }
286
289
  return Promise.all(dispatchRequests);
287
290
  }
@@ -317,7 +320,7 @@ var SiteGenerator = class {
317
320
  if (assetSrcDir && import_fs_extra.default.existsSync(assetSrcDir)) {
318
321
  import_fs_extra.default.copySync(assetSrcDir, assetOutputDir);
319
322
  } else {
320
- throw new Error("Could not find assets to copy at path: " + assetSrcDir);
323
+ console.warn("[WARN] Could not find assets to copy at path: " + assetSrcDir);
321
324
  }
322
325
  } catch (e) {
323
326
  console.error("Error occurred processing asset config: " + JSON.stringify(asset));
@@ -3,6 +3,7 @@ import { DiagnosticsError } from '@lwrjs/diagnostics';
3
3
  import { LwrViewHandler } from '@lwrjs/view-registry';
4
4
  import { isSupportedEnvironment } from './utils.js';
5
5
  import { decodeViewPath, getClientBootstrapConfigurationRoutes, extractRequestParams, } from '@lwrjs/shared-utils';
6
+ import { getClientRoutes } from '@lwrjs/router';
6
7
  export default function uiMiddleware(app, context) {
7
8
  const { viewRegistry, moduleRegistry, runtimeEnvironment: defaultRuntimeEnvironment } = context;
8
9
  const { environment: environmentConfig, routes, errorRoutes } = context.appConfig;
@@ -135,18 +136,30 @@ export default function uiMiddleware(app, context) {
135
136
  });
136
137
  }
137
138
  else {
138
- // vanity urls
139
- app.get(route.path, async (req, res) => {
140
- await sendViewResponse(req, res, route);
141
- });
142
- // canonical URL
143
- app.get([
144
- `/:apiVersion/application/:format/l/:locale/ai/:appId${route.path}`,
145
- `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId${route.path}`,
146
- `/:apiVersion/application/:format/ai/:appId${route.path}`,
147
- `/:apiVersion/application/:format/e/:environment/ai/:appId${route.path}`,
148
- ], async (req, res) => {
149
- await sendViewResponse(req, res, route);
139
+ // Get the client-side routes
140
+ const serverPath = route.path;
141
+ const paths = [serverPath];
142
+ const subRoutes = route.subRoutes ? getClientRoutes(route.subRoutes) : undefined;
143
+ if (subRoutes) {
144
+ // Concatenate each client uri to the server route.path, creating the full list of composite paths
145
+ const prefix = serverPath === '/' ? '' : serverPath;
146
+ subRoutes.routes.forEach((r) => paths.push(`${prefix}${r.uri}`));
147
+ }
148
+ // Register the server route.path and each composite client path, to enable full page refreshes of client pages
149
+ paths.forEach((path) => {
150
+ // vanity urls
151
+ app.get(path, async (req, res) => {
152
+ await sendViewResponse(req, res, route);
153
+ });
154
+ // canonical URL
155
+ app.get([
156
+ `/:apiVersion/application/:format/l/:locale/ai/:appId${path}`,
157
+ `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId${path}`,
158
+ `/:apiVersion/application/:format/ai/:appId${path}`,
159
+ `/:apiVersion/application/:format/e/:environment/ai/:appId${path}`,
160
+ ], async (req, res) => {
161
+ await sendViewResponse(req, res, route);
162
+ });
150
163
  });
151
164
  }
152
165
  });
@@ -1,5 +1,5 @@
1
1
  import { performance } from 'perf_hooks';
2
- import { getSpecifier, getFeatureFlags, hashContent, getModuleUriPrefix, getMappingUriPrefix, } from '@lwrjs/shared-utils';
2
+ import { getSpecifier, getFeatureFlags, hashContent, isSelfUrl, getModuleUriPrefix, getMappingUriPrefix, logger, } from '@lwrjs/shared-utils';
3
3
  import { join, dirname, extname } from 'path';
4
4
  import fs from 'fs-extra';
5
5
  import { writeResponse } from './utils/stream.js';
@@ -306,8 +306,8 @@ export default class SiteGenerator {
306
306
  const assets = viewDefinition.viewRecord.assetReferences || [];
307
307
  for (const asset of assets) {
308
308
  const assetUrl = asset.override?.uri || asset.url;
309
- // skip empty asset urls / data urls (i.e. <img src="" /> <img src="data:image/png;base64, iVBORw0..." />)
310
- if (assetUrl && !assetUrl.startsWith('data:')) {
309
+ // skip self referential asset urls / data urls (i.e. <img src="" /> <img src="data:image/png;base64, iVBORw0..." />)
310
+ if (assetUrl && !isSelfUrl(assetUrl)) {
311
311
  dispatchRequests.push(this.dispatchResourceRecursive(assetUrl, dispatcher, { resourceType: 'asset', asset }, siteConfig));
312
312
  }
313
313
  }
@@ -402,7 +402,11 @@ export default class SiteGenerator {
402
402
  const assetReferences = metadata?.asset?.metadata?.assetReferences || [];
403
403
  const dispatchRequests = [];
404
404
  for (const ref of assetReferences) {
405
- dispatchRequests.push(this.dispatchResourceRecursive(ref.override?.uri || ref.url, dispatcher, { resourceType: 'asset', asset: metadata?.asset }, siteConfig));
405
+ const refUrl = ref.override?.uri || ref.url;
406
+ dispatchRequests.push(this.dispatchResourceRecursive(refUrl, dispatcher, { resourceType: 'asset', asset: metadata?.asset }, siteConfig).catch((err) => {
407
+ // Warn the user that the we failed to fetch a referenced asset
408
+ logger.warn(`Failed to fetch asset refrence => ${refUrl} from ${url}`, err);
409
+ }));
406
410
  }
407
411
  return Promise.all(dispatchRequests);
408
412
  }
@@ -459,7 +463,7 @@ export default class SiteGenerator {
459
463
  fs.copySync(assetSrcDir, assetOutputDir);
460
464
  }
461
465
  else {
462
- throw new Error('Could not find assets to copy at path: ' + assetSrcDir);
466
+ console.warn('[WARN] Could not find assets to copy at path: ' + assetSrcDir);
463
467
  }
464
468
  }
465
469
  catch (e) {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.8.0-alpha.12",
7
+ "version": "0.8.0-alpha.13",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -32,32 +32,32 @@
32
32
  "package.cjs"
33
33
  ],
34
34
  "dependencies": {
35
- "@lwrjs/app-service": "0.8.0-alpha.12",
36
- "@lwrjs/asset-registry": "0.8.0-alpha.12",
37
- "@lwrjs/asset-transformer": "0.8.0-alpha.12",
38
- "@lwrjs/base-template-engine": "0.8.0-alpha.12",
39
- "@lwrjs/base-view-provider": "0.8.0-alpha.12",
40
- "@lwrjs/base-view-transformer": "0.8.0-alpha.12",
41
- "@lwrjs/client-modules": "0.8.0-alpha.12",
42
- "@lwrjs/compiler": "0.8.0-alpha.12",
43
- "@lwrjs/config": "0.8.0-alpha.12",
44
- "@lwrjs/diagnostics": "0.8.0-alpha.12",
45
- "@lwrjs/fs-asset-provider": "0.8.0-alpha.12",
46
- "@lwrjs/html-view-provider": "0.8.0-alpha.12",
47
- "@lwrjs/loader": "0.8.0-alpha.12",
48
- "@lwrjs/lwc-module-provider": "0.8.0-alpha.12",
49
- "@lwrjs/lwc-ssr": "0.8.0-alpha.12",
50
- "@lwrjs/markdown-view-provider": "0.8.0-alpha.12",
51
- "@lwrjs/module-bundler": "0.8.0-alpha.12",
52
- "@lwrjs/module-registry": "0.8.0-alpha.12",
53
- "@lwrjs/npm-module-provider": "0.8.0-alpha.12",
54
- "@lwrjs/nunjucks-view-provider": "0.8.0-alpha.12",
55
- "@lwrjs/o11y": "0.8.0-alpha.12",
56
- "@lwrjs/resource-registry": "0.8.0-alpha.12",
57
- "@lwrjs/router": "0.8.0-alpha.12",
58
- "@lwrjs/server": "0.8.0-alpha.12",
59
- "@lwrjs/shared-utils": "0.8.0-alpha.12",
60
- "@lwrjs/view-registry": "0.8.0-alpha.12",
35
+ "@lwrjs/app-service": "0.8.0-alpha.13",
36
+ "@lwrjs/asset-registry": "0.8.0-alpha.13",
37
+ "@lwrjs/asset-transformer": "0.8.0-alpha.13",
38
+ "@lwrjs/base-template-engine": "0.8.0-alpha.13",
39
+ "@lwrjs/base-view-provider": "0.8.0-alpha.13",
40
+ "@lwrjs/base-view-transformer": "0.8.0-alpha.13",
41
+ "@lwrjs/client-modules": "0.8.0-alpha.13",
42
+ "@lwrjs/compiler": "0.8.0-alpha.13",
43
+ "@lwrjs/config": "0.8.0-alpha.13",
44
+ "@lwrjs/diagnostics": "0.8.0-alpha.13",
45
+ "@lwrjs/fs-asset-provider": "0.8.0-alpha.13",
46
+ "@lwrjs/html-view-provider": "0.8.0-alpha.13",
47
+ "@lwrjs/loader": "0.8.0-alpha.13",
48
+ "@lwrjs/lwc-module-provider": "0.8.0-alpha.13",
49
+ "@lwrjs/lwc-ssr": "0.8.0-alpha.13",
50
+ "@lwrjs/markdown-view-provider": "0.8.0-alpha.13",
51
+ "@lwrjs/module-bundler": "0.8.0-alpha.13",
52
+ "@lwrjs/module-registry": "0.8.0-alpha.13",
53
+ "@lwrjs/npm-module-provider": "0.8.0-alpha.13",
54
+ "@lwrjs/nunjucks-view-provider": "0.8.0-alpha.13",
55
+ "@lwrjs/o11y": "0.8.0-alpha.13",
56
+ "@lwrjs/resource-registry": "0.8.0-alpha.13",
57
+ "@lwrjs/router": "0.8.0-alpha.13",
58
+ "@lwrjs/server": "0.8.0-alpha.13",
59
+ "@lwrjs/shared-utils": "0.8.0-alpha.13",
60
+ "@lwrjs/view-registry": "0.8.0-alpha.13",
61
61
  "fs-extra": "^10.1.0",
62
62
  "ms": "^2.1.3",
63
63
  "path-to-regexp": "^6.2.0",
@@ -65,7 +65,7 @@
65
65
  "ws": "^8.8.1"
66
66
  },
67
67
  "devDependencies": {
68
- "@lwrjs/types": "0.8.0-alpha.12",
68
+ "@lwrjs/types": "0.8.0-alpha.13",
69
69
  "@types/ws": "^8.5.3"
70
70
  },
71
71
  "peerDependencies": {
@@ -74,5 +74,5 @@
74
74
  "engines": {
75
75
  "node": ">=14.15.4 <19"
76
76
  },
77
- "gitHead": "eef0342738457f04590e760a0b501e4d78d93416"
77
+ "gitHead": "cc4bc856f34d2ec15df550503dd7463fa31b30e5"
78
78
  }