@lwrjs/shared-utils 0.7.0-alpha.9 → 0.7.2
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.
- package/build/cjs/identity.cjs +12 -0
- package/build/cjs/urls.cjs +9 -1
- package/build/es/identity.js +12 -0
- package/build/es/urls.d.ts +1 -0
- package/build/es/urls.js +11 -1
- package/package.json +5 -5
package/build/cjs/identity.cjs
CHANGED
|
@@ -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,
|
package/build/cjs/urls.cjs
CHANGED
|
@@ -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;
|
package/build/es/identity.js
CHANGED
|
@@ -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,
|
package/build/es/urls.d.ts
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
7
|
+
"version": "0.7.2",
|
|
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.
|
|
48
|
-
"@lwrjs/types": "0.7.
|
|
47
|
+
"@lwrjs/diagnostics": "0.7.2",
|
|
48
|
+
"@lwrjs/types": "0.7.2",
|
|
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 <
|
|
53
|
+
"node": ">=14.15.4 <19"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "1467a95aa5dcf6901e1122f6025ffd4f22237a3f"
|
|
56
56
|
}
|