@lwrjs/shared-utils 0.7.0-alpha.8 → 0.7.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.
@@ -62,7 +62,7 @@ async function extractMetadataFromHtml(htmlSource) {
62
62
  tagName,
63
63
  location: {startOffset, endOffset},
64
64
  props: attrs.length ? attrs.reduce((obj, {name, value}) => {
65
- obj[(0, import_identity.getPropFromAttrName)(name)] = value;
65
+ obj[(0, import_identity.getPropFromAttrName)(name)] = value === "" ? "true" : value;
66
66
  return obj;
67
67
  }, {}) : void 0
68
68
  };
@@ -212,8 +212,14 @@ function isExternalUrl(url) {
212
212
  function isBundleDefinition(definition) {
213
213
  return definition.bundleRecord !== void 0;
214
214
  }
215
+ function validateSpecifier(specifer) {
216
+ return specifer.indexOf("../") < 0;
217
+ }
215
218
  function getModuleIdentity(req) {
216
219
  const {specifier, signature = LATEST_SIGNATURE} = req.params;
220
+ if (validateSpecifier(specifier) === false) {
221
+ throw new Error("dot-dot-slash is not allowed for module specifier");
222
+ }
217
223
  const moduleId = explodeSpecifier(specifier);
218
224
  return {
219
225
  moduleId,
@@ -232,6 +238,9 @@ function getMappingIdentity(req) {
232
238
  }
233
239
  function getResourceIdentity(req) {
234
240
  const {specifier, signature = LATEST_SIGNATURE} = req.params;
241
+ if (validateSpecifier(specifier) === false) {
242
+ throw new Error("dot-dot-slash is not allowed for resource specifier");
243
+ }
235
244
  const resourceId = explodeSpecifier(specifier);
236
245
  return {
237
246
  resourceId,
@@ -241,6 +250,9 @@ function getResourceIdentity(req) {
241
250
  function getAssetIdentity(req) {
242
251
  const {signature = LATEST_SIGNATURE, assetType: type} = req.params;
243
252
  const [specifier] = req.originalUrl.split("?");
253
+ if (validateSpecifier(specifier) === false) {
254
+ throw new Error("dot-dot-slash is not allowed for asset specifier");
255
+ }
244
256
  return {
245
257
  assetId: {
246
258
  specifier,
@@ -24,6 +24,7 @@ var __toModule = (module2) => {
24
24
  // packages/@lwrjs/shared-utils/src/urls.ts
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
+ decodeViewPath: () => decodeViewPath,
27
28
  extractRequestParams: () => extractRequestParams,
28
29
  getClientBootstrapConfigurationRoutes: () => getClientBootstrapConfigurationRoutes,
29
30
  getClientBootstrapConfigurationUri: () => getClientBootstrapConfigurationUri,
@@ -34,11 +35,18 @@ var import_path_to_regexp = __toModule(require("path-to-regexp"));
34
35
  var CONFIG_SUFFIX = "/config.js";
35
36
  var SIGNATURE_SIGIL = "s";
36
37
  function getClientBootstrapConfigurationUri(routeInfo, runtimeEnvironment, runtimeParams, signature) {
37
- const encodeUrl = encodeURIComponent(routeInfo.url);
38
+ const encodeUrl = `-${encodeURIComponent(routeInfo.url)}-`;
38
39
  const configUrlPrefix = getClientBootstrapConfigurationUriPrefix(routeInfo, runtimeEnvironment, runtimeParams);
39
40
  const signatureSegment = signature ? `/${SIGNATURE_SIGIL}/${signature}` : "";
40
41
  return `${configUrlPrefix}/${encodeUrl}${signatureSegment}${CONFIG_SUFFIX}`;
41
42
  }
43
+ function decodeViewPath(encodedViewPath) {
44
+ let decodePath = decodeURIComponent(encodedViewPath);
45
+ if (encodedViewPath.startsWith("-") && encodedViewPath.endsWith("-")) {
46
+ decodePath = decodePath.substring(1, decodePath.length - 1);
47
+ }
48
+ return decodePath;
49
+ }
42
50
  function getClientBootstrapConfigurationUriPrefix(routeInfo, runtimeEnvironment, runtimeParams) {
43
51
  const {apiVersion, format, basePath} = runtimeEnvironment;
44
52
  const {id} = routeInfo;
@@ -39,9 +39,10 @@ export async function extractMetadataFromHtml(htmlSource) {
39
39
  location: { startOffset, endOffset },
40
40
  // transform attributes [{ name: 'some-attr', value: 'the value' }] into properties { someAttr: 'the value' }
41
41
  // leave props as undefined if there are no attributes
42
+ // set boolean attribute values to "true", or lwc will see them as falsy
42
43
  props: attrs.length
43
44
  ? attrs.reduce((obj, { name, value }) => {
44
- obj[getPropFromAttrName(name)] = value;
45
+ obj[getPropFromAttrName(name)] = value === '' ? 'true' : value;
45
46
  return obj;
46
47
  }, {})
47
48
  : undefined,
@@ -279,8 +279,14 @@ export function isExternalUrl(url) {
279
279
  export function isBundleDefinition(definition) {
280
280
  return definition.bundleRecord !== undefined;
281
281
  }
282
+ function validateSpecifier(specifer) {
283
+ return specifer.indexOf('../') < 0;
284
+ }
282
285
  export function getModuleIdentity(req) {
283
286
  const { specifier, signature = LATEST_SIGNATURE } = req.params;
287
+ if (validateSpecifier(specifier) === false) {
288
+ throw new Error('dot-dot-slash is not allowed for module specifier');
289
+ }
284
290
  const moduleId = explodeSpecifier(specifier);
285
291
  return {
286
292
  moduleId,
@@ -299,6 +305,9 @@ export function getMappingIdentity(req) {
299
305
  }
300
306
  export function getResourceIdentity(req) {
301
307
  const { specifier, signature = LATEST_SIGNATURE } = req.params;
308
+ if (validateSpecifier(specifier) === false) {
309
+ throw new Error('dot-dot-slash is not allowed for resource specifier');
310
+ }
302
311
  const resourceId = explodeSpecifier(specifier);
303
312
  return {
304
313
  resourceId,
@@ -308,6 +317,9 @@ export function getResourceIdentity(req) {
308
317
  export function getAssetIdentity(req) {
309
318
  const { signature = LATEST_SIGNATURE, assetType: type } = req.params;
310
319
  const [specifier] = req.originalUrl.split('?');
320
+ if (validateSpecifier(specifier) === false) {
321
+ throw new Error('dot-dot-slash is not allowed for asset specifier');
322
+ }
311
323
  return {
312
324
  assetId: {
313
325
  specifier,
@@ -3,6 +3,7 @@ export declare function getClientBootstrapConfigurationUri(routeInfo: {
3
3
  id: string;
4
4
  url: string;
5
5
  }, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, signature?: string): string;
6
+ export declare function decodeViewPath(encodedViewPath: string): string;
6
7
  export declare function getClientBootstrapConfigurationUriPrefix(routeInfo: {
7
8
  id: string;
8
9
  }, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): string;
package/build/es/urls.js CHANGED
@@ -2,11 +2,21 @@ import { pathToRegexp } from 'path-to-regexp';
2
2
  const CONFIG_SUFFIX = '/config.js';
3
3
  const SIGNATURE_SIGIL = 's';
4
4
  export function getClientBootstrapConfigurationUri(routeInfo, runtimeEnvironment, runtimeParams, signature) {
5
- const encodeUrl = encodeURIComponent(routeInfo.url);
5
+ // Add extra dashes around encoded path so when saved as static file leading and
6
+ // trailing slashes are preserved as file path.
7
+ const encodeUrl = `-${encodeURIComponent(routeInfo.url)}-`;
6
8
  const configUrlPrefix = getClientBootstrapConfigurationUriPrefix(routeInfo, runtimeEnvironment, runtimeParams);
7
9
  const signatureSegment = signature ? `/${SIGNATURE_SIGIL}/${signature}` : '';
8
10
  return `${configUrlPrefix}/${encodeUrl}${signatureSegment}${CONFIG_SUFFIX}`;
9
11
  }
12
+ export function decodeViewPath(encodedViewPath) {
13
+ let decodePath = decodeURIComponent(encodedViewPath);
14
+ // Remove surrounding dashes
15
+ if (encodedViewPath.startsWith('-') && encodedViewPath.endsWith('-')) {
16
+ decodePath = decodePath.substring(1, decodePath.length - 1);
17
+ }
18
+ return decodePath;
19
+ }
10
20
  export function getClientBootstrapConfigurationUriPrefix(routeInfo, runtimeEnvironment, runtimeParams) {
11
21
  const { apiVersion, format, basePath } = runtimeEnvironment;
12
22
  const { id } = routeInfo;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.7.0-alpha.8",
7
+ "version": "0.7.1",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -44,13 +44,13 @@
44
44
  "winston": "^3.7.2"
45
45
  },
46
46
  "devDependencies": {
47
- "@lwrjs/diagnostics": "0.7.0-alpha.8",
48
- "@lwrjs/types": "0.7.0-alpha.8",
47
+ "@lwrjs/diagnostics": "0.7.1",
48
+ "@lwrjs/types": "0.7.1",
49
49
  "@types/mime-types": "2.1.1",
50
50
  "@types/path-to-regexp": "^1.7.0"
51
51
  },
52
52
  "engines": {
53
- "node": ">=14.15.4 <17"
53
+ "node": ">=14.15.4 <19"
54
54
  },
55
- "gitHead": "fbe1daed908cf07eaf9fc8821f2ba2947f5d919f"
55
+ "gitHead": "3d4dd15182d1492e10a9aaf3055714d834e3df2e"
56
56
  }