@lwrjs/core 0.5.10 → 0.5.11-236-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.
@@ -30,13 +30,14 @@ var import_ms = __toModule(require("ms"));
30
30
  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
+ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
33
34
  function uiMiddleware(app, context) {
34
35
  const {viewRegistry, moduleRegistry, runtimeEnvironment: defaultRuntimeEnvironment} = context;
35
36
  const {environment: environmentConfig, routes, errorRoutes} = context.appConfig;
36
37
  const route404 = errorRoutes.find((r) => r.status === 404);
37
38
  const route500 = errorRoutes.find((r) => r.status === 500);
38
39
  const viewHandler = new import_view_registry.LwrViewHandler({viewRegistry, moduleRegistry}, context.appConfig);
39
- async function sendResponse(req, res, route, defaultStatus = 200) {
40
+ async function sendViewResponse(req, res, route, defaultStatus = 200) {
40
41
  if (!req.validateJsonRequest()) {
41
42
  res.status(400).send({error: "Accept header and json query parameter are incompatible"});
42
43
  return;
@@ -81,23 +82,27 @@ function uiMiddleware(app, context) {
81
82
  console.error(error);
82
83
  }
83
84
  if (route500 && defaultStatus !== 500) {
84
- await sendResponse(req, res, route500, 500);
85
+ await sendViewResponse(req, res, route500, 500);
85
86
  } else {
86
87
  res.status(500).send(`500 - Error retrieving view for route "${route.id}"`);
87
88
  }
88
89
  }
89
90
  }
90
- async function sendConfigurationResponse(req, res, route, defaultStatus = 200) {
91
+ async function sendConfigurationResponse(req, res, defaultStatus = 200) {
91
92
  const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(defaultRuntimeEnvironment);
92
- const {originalUrl, path} = req;
93
- const {apiVersion, format, appId, locale} = req.params;
94
- const rootCfgPath = `/${apiVersion}/application/${format}/l/${locale}/ai/${appId}/configuration/ci`;
95
- const url = originalUrl.replace(rootCfgPath, "");
96
- const requestPath = path.replace(rootCfgPath, "");
93
+ const {appId, encodedViewPath} = req.params;
94
+ const route = routes.find((route2) => route2.id === appId);
95
+ if (!route) {
96
+ res.status(404).send({error: `LWR configuration for "${appId} is not available"`});
97
+ return;
98
+ }
97
99
  try {
100
+ const url = decodeURIComponent(encodedViewPath);
101
+ const requestPath = route.path;
102
+ const params = (0, import_shared_utils.extractRequestParams)(requestPath, url, req.params);
98
103
  const viewRequest = {
99
104
  url,
100
- params: req.params,
105
+ params,
101
106
  query: req.query,
102
107
  requestPath
103
108
  };
@@ -126,7 +131,7 @@ function uiMiddleware(app, context) {
126
131
  console.error(error);
127
132
  }
128
133
  if (route500 && defaultStatus !== 500) {
129
- await sendResponse(req, res, route500, 500);
134
+ await sendViewResponse(req, res, route500, 500);
130
135
  } else {
131
136
  res.status(500).send(`500 - Error retrieving route "${route.id}"`);
132
137
  }
@@ -135,30 +140,30 @@ function uiMiddleware(app, context) {
135
140
  routes.forEach((route) => {
136
141
  if (route.method === "post") {
137
142
  app.post(route.path, async (req, res) => {
138
- await sendResponse(req, res, route);
143
+ await sendViewResponse(req, res, route);
139
144
  });
140
145
  } else {
141
146
  app.get(route.path, async (req, res) => {
142
- await sendResponse(req, res, route);
147
+ await sendViewResponse(req, res, route);
143
148
  });
144
149
  app.get([
145
150
  `/:apiVersion/application/:format/l/:locale/ai/:appId${route.path}`,
146
- `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId${route.path}`
151
+ `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId${route.path}`,
152
+ `/:apiVersion/application/:format/ai/:appId${route.path}`,
153
+ `/:apiVersion/application/:format/e/:environment/ai/:appId${route.path}`
147
154
  ], async (req, res) => {
148
- await sendResponse(req, res, route);
149
- });
150
- app.get([
151
- `/:apiVersion/application/:format/l/:locale/ai/:appId/configuration/ci${route.path}`,
152
- `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId/configuration/ci${route.path}`
153
- ], async (req, res) => {
154
- await sendConfigurationResponse(req, res, route);
155
+ await sendViewResponse(req, res, route);
155
156
  });
156
157
  }
157
158
  });
159
+ const clientBootstrapConfigurationRoutes = (0, import_shared_utils.getClientBootstrapConfigurationRoutes)();
160
+ app.get(clientBootstrapConfigurationRoutes, async (req, res) => {
161
+ await sendConfigurationResponse(req, res);
162
+ });
158
163
  app.initRoutes();
159
164
  app.use(async (req, res) => {
160
165
  if (route404) {
161
- await sendResponse(req, res, route404, 404);
166
+ await sendViewResponse(req, res, route404, 404);
162
167
  } else {
163
168
  res.status(404).send("404 - This page does not exist");
164
169
  }
@@ -2,13 +2,14 @@ import ms from 'ms';
2
2
  import { DiagnosticsError } from '@lwrjs/diagnostics';
3
3
  import { LwrViewHandler } from '@lwrjs/view-registry';
4
4
  import { isSupportedEnvironment } from './utils.js';
5
+ import { getClientBootstrapConfigurationRoutes, extractRequestParams } from '@lwrjs/shared-utils';
5
6
  export default function uiMiddleware(app, context) {
6
7
  const { viewRegistry, moduleRegistry, runtimeEnvironment: defaultRuntimeEnvironment } = context;
7
8
  const { environment: environmentConfig, routes, errorRoutes } = context.appConfig;
8
9
  const route404 = errorRoutes.find((r) => r.status === 404);
9
10
  const route500 = errorRoutes.find((r) => r.status === 500);
10
11
  const viewHandler = new LwrViewHandler({ viewRegistry, moduleRegistry }, context.appConfig);
11
- async function sendResponse(req, res, route, defaultStatus = 200) {
12
+ async function sendViewResponse(req, res, route, defaultStatus = 200) {
12
13
  if (!req.validateJsonRequest()) {
13
14
  res.status(400).send({ error: 'Accept header and json query parameter are incompatible' });
14
15
  return;
@@ -58,25 +59,31 @@ export default function uiMiddleware(app, context) {
58
59
  console.error(error);
59
60
  }
60
61
  if (route500 && defaultStatus !== 500) {
61
- await sendResponse(req, res, route500, 500);
62
+ await sendViewResponse(req, res, route500, 500);
62
63
  }
63
64
  else {
64
65
  res.status(500).send(`500 - Error retrieving view for route "${route.id}"`);
65
66
  }
66
67
  }
67
68
  }
68
- async function sendConfigurationResponse(req, res, route, defaultStatus = 200) {
69
+ async function sendConfigurationResponse(req, res, defaultStatus = 200) {
69
70
  const { runtimeEnvironment, runtimeParams } = req.getRuntimeContext(defaultRuntimeEnvironment);
70
- const { originalUrl, path } = req;
71
- const { apiVersion, format, appId, locale } = req.params;
72
- const rootCfgPath = `/${apiVersion}/application/${format}/l/${locale}/ai/${appId}/configuration/ci`;
73
- const url = originalUrl.replace(rootCfgPath, '');
74
- const requestPath = path.replace(rootCfgPath, '');
71
+ const { appId, encodedViewPath } = req.params;
72
+ // Match the route id
73
+ const route = routes.find((route) => route.id === appId);
74
+ if (!route) {
75
+ res.status(404).send({ error: `LWR configuration for "${appId} is not available"` });
76
+ return;
77
+ }
75
78
  try {
79
+ // decode the resolved view path and extract any params.
80
+ const url = decodeURIComponent(encodedViewPath);
81
+ const requestPath = route.path;
82
+ const params = extractRequestParams(requestPath, url, req.params);
76
83
  // HTML document
77
84
  const viewRequest = {
78
85
  url,
79
- params: req.params,
86
+ params,
80
87
  query: req.query,
81
88
  requestPath,
82
89
  };
@@ -108,7 +115,7 @@ export default function uiMiddleware(app, context) {
108
115
  console.error(error);
109
116
  }
110
117
  if (route500 && defaultStatus !== 500) {
111
- await sendResponse(req, res, route500, 500);
118
+ await sendViewResponse(req, res, route500, 500);
112
119
  }
113
120
  else {
114
121
  res.status(500).send(`500 - Error retrieving route "${route.id}"`);
@@ -120,29 +127,29 @@ export default function uiMiddleware(app, context) {
120
127
  // Seems like we only support get or post
121
128
  if (route.method === 'post') {
122
129
  app.post(route.path, async (req, res) => {
123
- await sendResponse(req, res, route);
130
+ await sendViewResponse(req, res, route);
124
131
  });
125
132
  }
126
133
  else {
127
134
  // vanity urls
128
135
  app.get(route.path, async (req, res) => {
129
- await sendResponse(req, res, route);
136
+ await sendViewResponse(req, res, route);
130
137
  });
131
138
  // canonical URL
132
139
  app.get([
133
140
  `/:apiVersion/application/:format/l/:locale/ai/:appId${route.path}`,
134
141
  `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId${route.path}`,
142
+ `/:apiVersion/application/:format/ai/:appId${route.path}`,
143
+ `/:apiVersion/application/:format/e/:environment/ai/:appId${route.path}`,
135
144
  ], async (req, res) => {
136
- await sendResponse(req, res, route);
137
- });
138
- app.get([
139
- `/:apiVersion/application/:format/l/:locale/ai/:appId/configuration/ci${route.path}`,
140
- `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId/configuration/ci${route.path}`,
141
- ], async (req, res) => {
142
- await sendConfigurationResponse(req, res, route);
145
+ await sendViewResponse(req, res, route);
143
146
  });
144
147
  }
145
148
  });
149
+ const clientBootstrapConfigurationRoutes = getClientBootstrapConfigurationRoutes();
150
+ app.get(clientBootstrapConfigurationRoutes, async (req, res) => {
151
+ await sendConfigurationResponse(req, res);
152
+ });
146
153
  // TODO nrkruk - This needs to be more generalized and visible at the top level of our middleware code.
147
154
  // This is the only time we call initRoutes() - which adds all the routing middleware that has been declared previously
148
155
  // to the app (get()/post()/all()). Any routing middleware declared after this point will not be initialized
@@ -152,7 +159,7 @@ export default function uiMiddleware(app, context) {
152
159
  // -- Default 404 route -------------------------------------------------------------
153
160
  app.use(async (req, res) => {
154
161
  if (route404) {
155
- await sendResponse(req, res, route404, 404);
162
+ await sendViewResponse(req, res, route404, 404);
156
163
  }
157
164
  else {
158
165
  res.status(404).send('404 - This page does not exist');
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.5.10",
7
+ "version": "0.5.11-236-1",
8
8
  "homepage": "https://lwr.dev/",
9
9
  "repository": {
10
10
  "type": "git",
@@ -33,27 +33,27 @@
33
33
  "package.cjs"
34
34
  ],
35
35
  "dependencies": {
36
- "@lwrjs/app-service": "0.5.10",
37
- "@lwrjs/asset-registry": "0.5.10",
38
- "@lwrjs/base-template-engine": "0.5.10",
39
- "@lwrjs/base-view-provider": "0.5.10",
40
- "@lwrjs/client-modules": "0.5.10",
41
- "@lwrjs/compiler": "0.5.10",
42
- "@lwrjs/diagnostics": "0.5.10",
43
- "@lwrjs/fs-asset-provider": "0.5.10",
44
- "@lwrjs/html-view-provider": "0.5.10",
45
- "@lwrjs/loader": "0.5.10",
46
- "@lwrjs/lwc-module-provider": "0.5.10",
47
- "@lwrjs/markdown-view-provider": "0.5.10",
48
- "@lwrjs/module-bundler": "0.5.10",
49
- "@lwrjs/module-registry": "0.5.10",
50
- "@lwrjs/npm-module-provider": "0.5.10",
51
- "@lwrjs/nunjucks-view-provider": "0.5.10",
52
- "@lwrjs/resource-registry": "0.5.10",
53
- "@lwrjs/router": "0.5.10",
54
- "@lwrjs/server": "0.5.10",
55
- "@lwrjs/shared-utils": "0.5.10",
56
- "@lwrjs/view-registry": "0.5.10",
36
+ "@lwrjs/app-service": "0.5.11-236-1",
37
+ "@lwrjs/asset-registry": "0.5.11-236-1",
38
+ "@lwrjs/base-template-engine": "0.5.11-236-1",
39
+ "@lwrjs/base-view-provider": "0.5.11-236-1",
40
+ "@lwrjs/client-modules": "0.5.11-236-1",
41
+ "@lwrjs/compiler": "0.5.11-236-1",
42
+ "@lwrjs/diagnostics": "0.5.11-236-1",
43
+ "@lwrjs/fs-asset-provider": "0.5.11-236-1",
44
+ "@lwrjs/html-view-provider": "0.5.11-236-1",
45
+ "@lwrjs/loader": "0.5.11-236-1",
46
+ "@lwrjs/lwc-module-provider": "0.5.11-236-1",
47
+ "@lwrjs/markdown-view-provider": "0.5.11-236-1",
48
+ "@lwrjs/module-bundler": "0.5.11-236-1",
49
+ "@lwrjs/module-registry": "0.5.11-236-1",
50
+ "@lwrjs/npm-module-provider": "0.5.11-236-1",
51
+ "@lwrjs/nunjucks-view-provider": "0.5.11-236-1",
52
+ "@lwrjs/resource-registry": "0.5.11-236-1",
53
+ "@lwrjs/router": "0.5.11-236-1",
54
+ "@lwrjs/server": "0.5.11-236-1",
55
+ "@lwrjs/shared-utils": "0.5.11-236-1",
56
+ "@lwrjs/view-registry": "0.5.11-236-1",
57
57
  "dompurify": "^2.3.0",
58
58
  "fs-extra": "^10.0.0",
59
59
  "jsdom": "^16.7.0",
@@ -63,13 +63,12 @@
63
63
  "qs": "^6.9.4"
64
64
  },
65
65
  "devDependencies": {
66
- "@lwrjs/types": "0.5.10"
66
+ "@lwrjs/types": "0.5.11-236-1"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "lwc": ">= 1.x <= 2.x"
70
70
  },
71
71
  "engines": {
72
72
  "node": ">=14.15.4 <17"
73
- },
74
- "gitHead": "5de44fdfc0bb47f7ed19aa167beef07ce553b261"
73
+ }
75
74
  }
package/LICENSE DELETED
@@ -1,10 +0,0 @@
1
- MIT LICENSE
2
-
3
- Copyright (c) 2020, Salesforce.com, Inc.
4
- All rights reserved.
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
-
8
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
-
10
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.