@lwrjs/core 0.15.0-alpha.44 → 0.15.0-alpha.46

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.
@@ -26,6 +26,7 @@ __markAsModule(exports);
26
26
  __export(exports, {
27
27
  assetMiddleware: () => assetMiddleware
28
28
  });
29
+ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
29
30
  var import_path = __toModule(require("path"));
30
31
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
31
32
  var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
@@ -81,6 +82,12 @@ function createAssetMiddleware(context) {
81
82
  res.setHeader("Cache-control", "public, max-age=12895706, immutable");
82
83
  } else if (runtimeEnvironment.immutableAssets) {
83
84
  res.setHeader("Cache-control", "public, max-age=60");
85
+ const extraAssetHeaders = parseHeaderStringToObject((0, import_shared_utils.getFeatureFlags)().EXPERIMENTAL_ASSET_HEADERS);
86
+ if (extraAssetHeaders) {
87
+ for (const [key, value] of Object.entries(extraAssetHeaders)) {
88
+ res.setHeader(key, value);
89
+ }
90
+ }
84
91
  }
85
92
  res.status(200).stream(asset.stream());
86
93
  } catch (error) {
@@ -111,3 +118,8 @@ function sendRedirect(res, assetUri) {
111
118
  });
112
119
  res.sendStatus(302);
113
120
  }
121
+ function parseHeaderStringToObject(assetHeadersString) {
122
+ if (typeof assetHeadersString === "string") {
123
+ return Object.fromEntries(assetHeadersString.split(";").filter(Boolean).map((e) => e.split(":").map((s) => s.trim())).filter((pair) => pair.length === 2 && pair[0]));
124
+ }
125
+ }
@@ -136,17 +136,21 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
136
136
  }
137
137
  }
138
138
  let status = resolvedRoute.status || viewResponse.status || 200;
139
- const redirect = viewResponse.metadata?.viewDefinition?.redirect;
139
+ const viewDefinitionStatus = viewResponse.metadata?.viewDefinition?.status;
140
140
  if (viewResponse.status === 301 || viewResponse.status === 302) {
141
141
  status = viewResponse.status;
142
- } else if (redirect) {
143
- if ((0, import_shared_utils.isURL)(redirect.location) || redirect.location.startsWith("/")) {
144
- status = redirect.status || 302;
142
+ } else if (viewDefinitionStatus && viewDefinitionStatus.code) {
143
+ const origStatus = status;
144
+ const {code, location} = viewDefinitionStatus;
145
+ const isRedirect = code === 301 || code == 302;
146
+ status = code;
147
+ if (isRedirect && location && (0, import_shared_utils.isURL)(location) || location?.startsWith("/")) {
145
148
  res.set({
146
- Location: addRedirectQueryParam(redirect.location, (0, import_shared_utils.parseRequestDepth)(req.headers, req.query))
149
+ location: addRedirectQueryParam(location, (0, import_shared_utils.parseRequestDepth)(req.headers, req.query))
147
150
  });
148
151
  } else {
149
- import_diagnostics.logger.warn(`[view-middleware] Redirect failed because the URL is invalid: "${redirect.location}"`);
152
+ status = origStatus;
153
+ import_diagnostics.logger.warn(`[view-middleware] Ignoring invalid location header: "${location}"`);
150
154
  }
151
155
  }
152
156
  res.status(status);
@@ -1,3 +1,4 @@
1
+ import { getFeatureFlags } from '@lwrjs/shared-utils';
1
2
  import path from 'path';
2
3
  import { DiagnosticsError } from '@lwrjs/diagnostics';
3
4
  import { RequestHandlerSpan, getTracer } from '@lwrjs/instrumentation';
@@ -63,6 +64,12 @@ function createAssetMiddleware(context) {
63
64
  }
64
65
  else if (runtimeEnvironment.immutableAssets) {
65
66
  res.setHeader('Cache-control', 'public, max-age=60');
67
+ const extraAssetHeaders = parseHeaderStringToObject(getFeatureFlags().EXPERIMENTAL_ASSET_HEADERS);
68
+ if (extraAssetHeaders) {
69
+ for (const [key, value] of Object.entries(extraAssetHeaders)) {
70
+ res.setHeader(key, value);
71
+ }
72
+ }
66
73
  }
67
74
  res.status(200).stream(asset.stream());
68
75
  }
@@ -105,4 +112,14 @@ function sendRedirect(res, assetUri) {
105
112
  });
106
113
  res.sendStatus(302);
107
114
  }
115
+ function parseHeaderStringToObject(assetHeadersString) {
116
+ if (typeof assetHeadersString === 'string') {
117
+ // convert to cache sring header:value to object
118
+ return Object.fromEntries(assetHeadersString
119
+ .split(';')
120
+ .filter(Boolean)
121
+ .map((e) => e.split(':').map((s) => s.trim()))
122
+ .filter((pair) => pair.length === 2 && pair[0]));
123
+ }
124
+ }
108
125
  //# sourceMappingURL=asset-middleware.js.map
@@ -119,20 +119,25 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
119
119
  }
120
120
  }
121
121
  let status = resolvedRoute.status || viewResponse.status || 200;
122
- const redirect = viewResponse.metadata?.viewDefinition?.redirect;
122
+ const viewDefinitionStatus = viewResponse.metadata?.viewDefinition?.status;
123
123
  if (viewResponse.status === 301 || viewResponse.status === 302) {
124
124
  // route handle redirect status takes precedence
125
125
  status = viewResponse.status;
126
126
  }
127
- else if (redirect) {
128
- if (isURL(redirect.location) || redirect.location.startsWith('/')) {
129
- status = redirect.status || 302;
127
+ else if (viewDefinitionStatus && viewDefinitionStatus.code) {
128
+ const origStatus = status;
129
+ const { code, location } = viewDefinitionStatus;
130
+ const isRedirect = code === 301 || code == 302;
131
+ status = code;
132
+ if ((isRedirect && location && isURL(location)) || location?.startsWith('/')) {
130
133
  res.set({
131
- Location: addRedirectQueryParam(redirect.location, parseRequestDepth(req.headers, req.query)),
134
+ location: addRedirectQueryParam(location, parseRequestDepth(req.headers, req.query)),
132
135
  });
133
136
  }
134
137
  else {
135
- logger.warn(`[view-middleware] Redirect failed because the URL is invalid: "${redirect.location}"`);
138
+ // reset the status in the event of an ivalid location when redirecting
139
+ status = origStatus;
140
+ logger.warn(`[view-middleware] Ignoring invalid location header: "${location}"`);
136
141
  }
137
142
  }
138
143
  res.status(status);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.15.0-alpha.44",
7
+ "version": "0.15.0-alpha.46",
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.44",
47
- "@lwrjs/asset-registry": "0.15.0-alpha.44",
48
- "@lwrjs/asset-transformer": "0.15.0-alpha.44",
49
- "@lwrjs/base-view-provider": "0.15.0-alpha.44",
50
- "@lwrjs/base-view-transformer": "0.15.0-alpha.44",
51
- "@lwrjs/client-modules": "0.15.0-alpha.44",
52
- "@lwrjs/config": "0.15.0-alpha.44",
53
- "@lwrjs/diagnostics": "0.15.0-alpha.44",
54
- "@lwrjs/esbuild": "0.15.0-alpha.44",
55
- "@lwrjs/fs-asset-provider": "0.15.0-alpha.44",
56
- "@lwrjs/fs-watch": "0.15.0-alpha.44",
57
- "@lwrjs/html-view-provider": "0.15.0-alpha.44",
58
- "@lwrjs/instrumentation": "0.15.0-alpha.44",
59
- "@lwrjs/loader": "0.15.0-alpha.44",
60
- "@lwrjs/lwc-module-provider": "0.15.0-alpha.44",
61
- "@lwrjs/lwc-ssr": "0.15.0-alpha.44",
62
- "@lwrjs/markdown-view-provider": "0.15.0-alpha.44",
63
- "@lwrjs/module-bundler": "0.15.0-alpha.44",
64
- "@lwrjs/module-registry": "0.15.0-alpha.44",
65
- "@lwrjs/npm-module-provider": "0.15.0-alpha.44",
66
- "@lwrjs/nunjucks-view-provider": "0.15.0-alpha.44",
67
- "@lwrjs/o11y": "0.15.0-alpha.44",
68
- "@lwrjs/resource-registry": "0.15.0-alpha.44",
69
- "@lwrjs/router": "0.15.0-alpha.44",
70
- "@lwrjs/server": "0.15.0-alpha.44",
71
- "@lwrjs/shared-utils": "0.15.0-alpha.44",
72
- "@lwrjs/static": "0.15.0-alpha.44",
73
- "@lwrjs/view-registry": "0.15.0-alpha.44",
46
+ "@lwrjs/app-service": "0.15.0-alpha.46",
47
+ "@lwrjs/asset-registry": "0.15.0-alpha.46",
48
+ "@lwrjs/asset-transformer": "0.15.0-alpha.46",
49
+ "@lwrjs/base-view-provider": "0.15.0-alpha.46",
50
+ "@lwrjs/base-view-transformer": "0.15.0-alpha.46",
51
+ "@lwrjs/client-modules": "0.15.0-alpha.46",
52
+ "@lwrjs/config": "0.15.0-alpha.46",
53
+ "@lwrjs/diagnostics": "0.15.0-alpha.46",
54
+ "@lwrjs/esbuild": "0.15.0-alpha.46",
55
+ "@lwrjs/fs-asset-provider": "0.15.0-alpha.46",
56
+ "@lwrjs/fs-watch": "0.15.0-alpha.46",
57
+ "@lwrjs/html-view-provider": "0.15.0-alpha.46",
58
+ "@lwrjs/instrumentation": "0.15.0-alpha.46",
59
+ "@lwrjs/loader": "0.15.0-alpha.46",
60
+ "@lwrjs/lwc-module-provider": "0.15.0-alpha.46",
61
+ "@lwrjs/lwc-ssr": "0.15.0-alpha.46",
62
+ "@lwrjs/markdown-view-provider": "0.15.0-alpha.46",
63
+ "@lwrjs/module-bundler": "0.15.0-alpha.46",
64
+ "@lwrjs/module-registry": "0.15.0-alpha.46",
65
+ "@lwrjs/npm-module-provider": "0.15.0-alpha.46",
66
+ "@lwrjs/nunjucks-view-provider": "0.15.0-alpha.46",
67
+ "@lwrjs/o11y": "0.15.0-alpha.46",
68
+ "@lwrjs/resource-registry": "0.15.0-alpha.46",
69
+ "@lwrjs/router": "0.15.0-alpha.46",
70
+ "@lwrjs/server": "0.15.0-alpha.46",
71
+ "@lwrjs/shared-utils": "0.15.0-alpha.46",
72
+ "@lwrjs/static": "0.15.0-alpha.46",
73
+ "@lwrjs/view-registry": "0.15.0-alpha.46",
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.44",
83
+ "@lwrjs/types": "0.15.0-alpha.46",
84
84
  "@types/ws": "^8.5.12",
85
85
  "memfs": "^4.13.0"
86
86
  },
@@ -93,5 +93,5 @@
93
93
  "volta": {
94
94
  "extends": "../../../package.json"
95
95
  },
96
- "gitHead": "8ca58462a449ee5fe39c8a098d5bf6501533711a"
96
+ "gitHead": "366b77f76c34626c9449da0042766fc107cc6b8f"
97
97
  }