@lwrjs/core 0.15.0-alpha.12 → 0.15.0-alpha.14

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.
@@ -45,7 +45,7 @@ function requestProcessorMiddleware(app, context) {
45
45
  }
46
46
  }
47
47
  requestClass = req.headers[MRT_REQUEST_CLASS_KEY];
48
- requestDepth = (0, import_shared_utils.parseRequestDepthHeader)(req.headers);
48
+ requestDepth = (0, import_shared_utils.parseRequestDepth)(req.headers, req.query);
49
49
  const forwarded = req.headers["forwarded"];
50
50
  const host = req.headers["host"];
51
51
  const forwardedProto = req.headers["x-forwarded-proto"];
@@ -57,7 +57,7 @@ function requestProcessorMiddleware(app, context) {
57
57
  });
58
58
  }
59
59
  }
60
- if (requestDepth && requestDepth > 0) {
60
+ if (requestDepth && requestDepth > 1) {
61
61
  import_diagnostics.logger.error({
62
62
  label: "request-processor-middleware",
63
63
  message: `Lambda SSR request cycle detected: ${req.originalUrl}`
@@ -115,11 +115,19 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
115
115
  if (traceId?.length) {
116
116
  res.setHeader("x-trace-id", traceId);
117
117
  }
118
- let status;
118
+ let status = resolvedRoute.status || viewResponse.status || 200;
119
+ const redirect = viewResponse.metadata?.viewDefinition?.redirect;
119
120
  if (viewResponse.status === 301 || viewResponse.status === 302) {
120
121
  status = viewResponse.status;
121
- } else {
122
- status = resolvedRoute.status || viewResponse.status || 200;
122
+ } else if (redirect) {
123
+ if ((0, import_shared_utils.isURL)(redirect.location) || redirect.location.startsWith("/")) {
124
+ status = redirect.status || 302;
125
+ res.set({
126
+ Location: addRedirectQueryParam(redirect.location, (0, import_shared_utils.parseRequestDepth)(req.headers, req.query))
127
+ });
128
+ } else {
129
+ import_diagnostics.logger.warn(`[view-middleware] Redirect failed because the URL is invalid: "${redirect.location}"`);
130
+ }
123
131
  }
124
132
  res.status(status);
125
133
  res.send(viewResponse.body);
@@ -225,3 +233,9 @@ function addDefaultLocaleRedirects(defaultLocale, defaultLocalePaths, app) {
225
233
  return res.sendStatus(301);
226
234
  });
227
235
  }
236
+ function addRedirectQueryParam(redirectUrl, depth) {
237
+ const fakeOrigin = "http://parse.com";
238
+ const url = (0, import_shared_utils.isURL)(redirectUrl) ? new URL(redirectUrl) : new URL(`${fakeOrigin}${redirectUrl}`);
239
+ url.searchParams.set(import_shared_utils.REQUEST_DEPTH_KEY, String(depth + 1));
240
+ return url.toString().replace(fakeOrigin, "");
241
+ }
@@ -232,12 +232,12 @@ var SiteGenerator = class {
232
232
  addBundleToSiteMetadata(bundleDefinition, url, siteConfig) {
233
233
  if (siteConfig.siteMetadata) {
234
234
  const locale = siteConfig.locale;
235
- const specifier = (0, import_site_metadata.getSiteBundleId)(bundleDefinition, locale, siteConfig.i18n);
236
- const imports = bundleDefinition.bundleRecord.imports?.map((moduleRef) => (0, import_site_metadata.getSiteBundleId)(moduleRef, locale, siteConfig.i18n)) || [];
237
- const dynamicImports = bundleDefinition.bundleRecord.dynamicImports?.map((moduleRef) => (0, import_site_metadata.getSiteBundleId)(moduleRef, locale, siteConfig.i18n));
235
+ const specifier = (0, import_site_metadata.getSiteBundleId)(bundleDefinition, locale, false, siteConfig.i18n);
236
+ const imports = bundleDefinition.bundleRecord.imports?.map((moduleRef) => (0, import_site_metadata.getSiteBundleId)(moduleRef, locale, false, siteConfig.i18n)) || [];
237
+ const dynamicImports = bundleDefinition.bundleRecord.dynamicImports?.map((moduleRef) => (0, import_site_metadata.getSiteBundleId)(moduleRef, locale, false, siteConfig.i18n));
238
238
  const includedModules = bundleDefinition.bundleRecord.includedModules?.map((moduleRef) => {
239
239
  const moduleId = (0, import_shared_utils.explodeSpecifier)(moduleRef);
240
- return (0, import_site_metadata.getSiteBundleId)(moduleId, locale, siteConfig.i18n);
240
+ return (0, import_site_metadata.getSiteBundleId)(moduleId, locale, false, siteConfig.i18n);
241
241
  }) || [];
242
242
  const version = bundleDefinition.version === import_shared_utils.VERSION_NOT_PROVIDED ? void 0 : bundleDefinition.version;
243
243
  const bundleMetadata = {
@@ -7,7 +7,7 @@
7
7
  *
8
8
  */
9
9
  import { logger } from '@lwrjs/diagnostics';
10
- import { REQUEST_DEPTH_HEADER, isLambdaEnv, parseRequestDepthHeader } from '@lwrjs/shared-utils';
10
+ import { REQUEST_DEPTH_HEADER, isLambdaEnv, parseRequestDepth } from '@lwrjs/shared-utils';
11
11
  const MRT_REQUEST_CLASS = 'X-Mobify-Request-Class';
12
12
  const MRT_REQUEST_CLASS_KEY = MRT_REQUEST_CLASS.toLowerCase();
13
13
  export function requestProcessorMiddleware(app, context) {
@@ -27,7 +27,7 @@ export function requestProcessorMiddleware(app, context) {
27
27
  }
28
28
  }
29
29
  requestClass = req.headers[MRT_REQUEST_CLASS_KEY];
30
- requestDepth = parseRequestDepthHeader(req.headers);
30
+ requestDepth = parseRequestDepth(req.headers, req.query);
31
31
  const forwarded = req.headers['forwarded'];
32
32
  const host = req.headers['host'];
33
33
  const forwardedProto = req.headers['x-forwarded-proto'];
@@ -40,8 +40,7 @@ export function requestProcessorMiddleware(app, context) {
40
40
  });
41
41
  }
42
42
  }
43
- // TODO Clean up once we have a long term solution
44
- if (requestDepth && requestDepth > 0) {
43
+ if (requestDepth && requestDepth > 1) {
45
44
  logger.error({
46
45
  label: 'request-processor-middleware',
47
46
  message: `Lambda SSR request cycle detected: ${req.originalUrl}`,
@@ -1,6 +1,6 @@
1
1
  import { descriptions, logger } from '@lwrjs/diagnostics';
2
2
  import { getClientRoutes } from '@lwrjs/router';
3
- import { decodeViewPath, extractRequestParams, getClientBootstrapConfigurationRoutes, shortestTtl, } from '@lwrjs/shared-utils';
3
+ import { decodeViewPath, extractRequestParams, getClientBootstrapConfigurationRoutes, isURL, parseRequestDepth, REQUEST_DEPTH_KEY, shortestTtl, } from '@lwrjs/shared-utils';
4
4
  import { RequestHandlerSpan, getTracer } from '@lwrjs/instrumentation';
5
5
  import { handleErrors } from './utils/error-handling.js';
6
6
  import { LwrViewHandler } from '@lwrjs/view-registry';
@@ -94,12 +94,22 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
94
94
  if (traceId?.length) {
95
95
  res.setHeader('x-trace-id', traceId);
96
96
  }
97
- let status;
97
+ let status = resolvedRoute.status || viewResponse.status || 200;
98
+ const redirect = viewResponse.metadata?.viewDefinition?.redirect;
98
99
  if (viewResponse.status === 301 || viewResponse.status === 302) {
100
+ // route handle redirect status takes precedence
99
101
  status = viewResponse.status;
100
102
  }
101
- else {
102
- status = resolvedRoute.status || viewResponse.status || 200;
103
+ else if (redirect) {
104
+ if (isURL(redirect.location) || redirect.location.startsWith('/')) {
105
+ status = redirect.status || 302;
106
+ res.set({
107
+ Location: addRedirectQueryParam(redirect.location, parseRequestDepth(req.headers, req.query)),
108
+ });
109
+ }
110
+ else {
111
+ logger.warn(`[view-middleware] Redirect failed because the URL is invalid: "${redirect.location}"`);
112
+ }
103
113
  }
104
114
  res.status(status);
105
115
  res.send(viewResponse.body);
@@ -229,4 +239,12 @@ function addDefaultLocaleRedirects(defaultLocale, defaultLocalePaths, app) {
229
239
  return res.sendStatus(301);
230
240
  });
231
241
  }
242
+ function addRedirectQueryParam(redirectUrl, depth) {
243
+ // add a request depth query param to the URL
244
+ // the depth header cannot be used since headers cannot be added to a redirect
245
+ const fakeOrigin = 'http://parse.com';
246
+ const url = isURL(redirectUrl) ? new URL(redirectUrl) : new URL(`${fakeOrigin}${redirectUrl}`);
247
+ url.searchParams.set(REQUEST_DEPTH_KEY, String(depth + 1));
248
+ return url.toString().replace(fakeOrigin, '');
249
+ }
232
250
  //# sourceMappingURL=view-middleware.js.map
@@ -299,12 +299,12 @@ export default class SiteGenerator {
299
299
  addBundleToSiteMetadata(bundleDefinition, url, siteConfig) {
300
300
  if (siteConfig.siteMetadata) {
301
301
  const locale = siteConfig.locale;
302
- const specifier = getSiteBundleId(bundleDefinition, locale, siteConfig.i18n);
303
- const imports = bundleDefinition.bundleRecord.imports?.map((moduleRef) => getSiteBundleId(moduleRef, locale, siteConfig.i18n)) || [];
304
- const dynamicImports = bundleDefinition.bundleRecord.dynamicImports?.map((moduleRef) => getSiteBundleId(moduleRef, locale, siteConfig.i18n));
302
+ const specifier = getSiteBundleId(bundleDefinition, locale, false, siteConfig.i18n);
303
+ const imports = bundleDefinition.bundleRecord.imports?.map((moduleRef) => getSiteBundleId(moduleRef, locale, false, siteConfig.i18n)) || [];
304
+ const dynamicImports = bundleDefinition.bundleRecord.dynamicImports?.map((moduleRef) => getSiteBundleId(moduleRef, locale, false, siteConfig.i18n));
305
305
  const includedModules = bundleDefinition.bundleRecord.includedModules?.map((moduleRef) => {
306
306
  const moduleId = explodeSpecifier(moduleRef);
307
- return getSiteBundleId(moduleId, locale, siteConfig.i18n);
307
+ return getSiteBundleId(moduleId, locale, false, siteConfig.i18n);
308
308
  }) || [];
309
309
  const version = bundleDefinition.version === VERSION_NOT_PROVIDED ? undefined : bundleDefinition.version;
310
310
  const bundleMetadata = {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.15.0-alpha.12",
7
+ "version": "0.15.0-alpha.14",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -43,34 +43,34 @@
43
43
  "build": "tsc -b"
44
44
  },
45
45
  "dependencies": {
46
- "@lwrjs/app-service": "0.15.0-alpha.12",
47
- "@lwrjs/asset-registry": "0.15.0-alpha.12",
48
- "@lwrjs/asset-transformer": "0.15.0-alpha.12",
49
- "@lwrjs/base-view-provider": "0.15.0-alpha.12",
50
- "@lwrjs/base-view-transformer": "0.15.0-alpha.12",
51
- "@lwrjs/client-modules": "0.15.0-alpha.12",
52
- "@lwrjs/config": "0.15.0-alpha.12",
53
- "@lwrjs/diagnostics": "0.15.0-alpha.12",
54
- "@lwrjs/esbuild": "0.15.0-alpha.12",
55
- "@lwrjs/fs-asset-provider": "0.15.0-alpha.12",
56
- "@lwrjs/fs-watch": "0.15.0-alpha.12",
57
- "@lwrjs/html-view-provider": "0.15.0-alpha.12",
58
- "@lwrjs/instrumentation": "0.15.0-alpha.12",
59
- "@lwrjs/loader": "0.15.0-alpha.12",
60
- "@lwrjs/lwc-module-provider": "0.15.0-alpha.12",
61
- "@lwrjs/lwc-ssr": "0.15.0-alpha.12",
62
- "@lwrjs/markdown-view-provider": "0.15.0-alpha.12",
63
- "@lwrjs/module-bundler": "0.15.0-alpha.12",
64
- "@lwrjs/module-registry": "0.15.0-alpha.12",
65
- "@lwrjs/npm-module-provider": "0.15.0-alpha.12",
66
- "@lwrjs/nunjucks-view-provider": "0.15.0-alpha.12",
67
- "@lwrjs/o11y": "0.15.0-alpha.12",
68
- "@lwrjs/resource-registry": "0.15.0-alpha.12",
69
- "@lwrjs/router": "0.15.0-alpha.12",
70
- "@lwrjs/server": "0.15.0-alpha.12",
71
- "@lwrjs/shared-utils": "0.15.0-alpha.12",
72
- "@lwrjs/static": "0.15.0-alpha.12",
73
- "@lwrjs/view-registry": "0.15.0-alpha.12",
46
+ "@lwrjs/app-service": "0.15.0-alpha.14",
47
+ "@lwrjs/asset-registry": "0.15.0-alpha.14",
48
+ "@lwrjs/asset-transformer": "0.15.0-alpha.14",
49
+ "@lwrjs/base-view-provider": "0.15.0-alpha.14",
50
+ "@lwrjs/base-view-transformer": "0.15.0-alpha.14",
51
+ "@lwrjs/client-modules": "0.15.0-alpha.14",
52
+ "@lwrjs/config": "0.15.0-alpha.14",
53
+ "@lwrjs/diagnostics": "0.15.0-alpha.14",
54
+ "@lwrjs/esbuild": "0.15.0-alpha.14",
55
+ "@lwrjs/fs-asset-provider": "0.15.0-alpha.14",
56
+ "@lwrjs/fs-watch": "0.15.0-alpha.14",
57
+ "@lwrjs/html-view-provider": "0.15.0-alpha.14",
58
+ "@lwrjs/instrumentation": "0.15.0-alpha.14",
59
+ "@lwrjs/loader": "0.15.0-alpha.14",
60
+ "@lwrjs/lwc-module-provider": "0.15.0-alpha.14",
61
+ "@lwrjs/lwc-ssr": "0.15.0-alpha.14",
62
+ "@lwrjs/markdown-view-provider": "0.15.0-alpha.14",
63
+ "@lwrjs/module-bundler": "0.15.0-alpha.14",
64
+ "@lwrjs/module-registry": "0.15.0-alpha.14",
65
+ "@lwrjs/npm-module-provider": "0.15.0-alpha.14",
66
+ "@lwrjs/nunjucks-view-provider": "0.15.0-alpha.14",
67
+ "@lwrjs/o11y": "0.15.0-alpha.14",
68
+ "@lwrjs/resource-registry": "0.15.0-alpha.14",
69
+ "@lwrjs/router": "0.15.0-alpha.14",
70
+ "@lwrjs/server": "0.15.0-alpha.14",
71
+ "@lwrjs/shared-utils": "0.15.0-alpha.14",
72
+ "@lwrjs/static": "0.15.0-alpha.14",
73
+ "@lwrjs/view-registry": "0.15.0-alpha.14",
74
74
  "chokidar": "^3.6.0",
75
75
  "esbuild": "^0.9.7",
76
76
  "fs-extra": "^11.2.0",
@@ -80,7 +80,7 @@
80
80
  "ws": "^8.18.0"
81
81
  },
82
82
  "devDependencies": {
83
- "@lwrjs/types": "0.15.0-alpha.12",
83
+ "@lwrjs/types": "0.15.0-alpha.14",
84
84
  "@types/ws": "^8.5.12",
85
85
  "memfs": "^4.9.3"
86
86
  },
@@ -93,5 +93,5 @@
93
93
  "volta": {
94
94
  "extends": "../../../package.json"
95
95
  },
96
- "gitHead": "24d0d4a163fcfbaa5e0a005aafd7cf77f314a2ab"
96
+ "gitHead": "c34e441a349c30ed3b52459c64e92d8036013036"
97
97
  }