@lwrjs/shared-utils 0.17.2-alpha.1 → 0.17.2-alpha.11
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/env.cjs +14 -6
- package/build/cjs/fs.cjs +1 -3
- package/build/cjs/graph.cjs +1 -3
- package/build/cjs/identity.cjs +1 -1
- package/build/cjs/urls.cjs +5 -1
- package/build/es/env.d.ts +6 -2
- package/build/es/env.js +11 -5
- package/build/es/fs.js +2 -4
- package/build/es/graph.js +2 -4
- package/build/es/identity.d.ts +1 -0
- package/build/es/identity.js +1 -1
- package/build/es/urls.d.ts +1 -0
- package/build/es/urls.js +9 -0
- package/package.json +4 -4
package/build/cjs/env.cjs
CHANGED
|
@@ -8,8 +8,12 @@ var __export = (target, all) => {
|
|
|
8
8
|
// packages/@lwrjs/shared-utils/src/env.ts
|
|
9
9
|
__markAsModule(exports);
|
|
10
10
|
__export(exports, {
|
|
11
|
+
B3_TRACE_ID: () => B3_TRACE_ID,
|
|
12
|
+
CORRELATION_ID: () => CORRELATION_ID,
|
|
13
|
+
MRT_REQUEST_CLASS: () => MRT_REQUEST_CLASS,
|
|
11
14
|
REQUEST_DEPTH_HEADER: () => REQUEST_DEPTH_HEADER,
|
|
12
|
-
|
|
15
|
+
ROUTE_CORE_HEADER: () => ROUTE_CORE_HEADER,
|
|
16
|
+
TRUE_CLIENT_IP: () => TRUE_CLIENT_IP,
|
|
13
17
|
buildEnvironmentContext: () => buildEnvironmentContext,
|
|
14
18
|
getFeatureFlags: () => getFeatureFlags,
|
|
15
19
|
isLambdaEnv: () => isLambdaEnv,
|
|
@@ -64,11 +68,15 @@ function buildEnvironmentContext(runtimeParams) {
|
|
|
64
68
|
uiBasePath
|
|
65
69
|
};
|
|
66
70
|
}
|
|
67
|
-
var
|
|
68
|
-
var
|
|
71
|
+
var TRUE_CLIENT_IP = "true-client-ip";
|
|
72
|
+
var B3_TRACE_ID = "x-b3-traceid";
|
|
73
|
+
var CORRELATION_ID = "x-correlation-id";
|
|
74
|
+
var MRT_REQUEST_CLASS = "x-mobify-request-class";
|
|
75
|
+
var ROUTE_CORE_HEADER = "x-sfdc-route-core";
|
|
76
|
+
var REQUEST_DEPTH_HEADER = "x-sfdc-request-depth";
|
|
69
77
|
function parseRequestDepth(headers = {}, query = {}) {
|
|
70
78
|
let maxDepth = 0;
|
|
71
|
-
const value = headers && headers[
|
|
79
|
+
const value = headers && headers[REQUEST_DEPTH_HEADER];
|
|
72
80
|
if (value) {
|
|
73
81
|
if (Array.isArray(value)) {
|
|
74
82
|
for (const depth of value) {
|
|
@@ -86,8 +94,8 @@ function parseRequestDepth(headers = {}, query = {}) {
|
|
|
86
94
|
}
|
|
87
95
|
}
|
|
88
96
|
}
|
|
89
|
-
if (query[
|
|
90
|
-
const queryValue = parseInt(query[
|
|
97
|
+
if (query[REQUEST_DEPTH_HEADER]) {
|
|
98
|
+
const queryValue = parseInt(query[REQUEST_DEPTH_HEADER], 10);
|
|
91
99
|
if (!isNaN(queryValue) && queryValue > maxDepth) {
|
|
92
100
|
maxDepth = queryValue;
|
|
93
101
|
}
|
package/build/cjs/fs.cjs
CHANGED
|
@@ -168,9 +168,7 @@ function normalizeResourcePath(rawPath, {rootDir, assets, contentDir, layoutsDir
|
|
|
168
168
|
return rawPath.replace(RESOURCE_DIR_REGEX, function(fullMatch, m1, m2) {
|
|
169
169
|
const alias = assetsMap[m1] || assetsMap[m2];
|
|
170
170
|
if (!alias && !allowUnresolvedAlias) {
|
|
171
|
-
throw
|
|
172
|
-
description: import_diagnostics.descriptions.UNRESOLVABLE.DIR_ALIAS(fullMatch)
|
|
173
|
-
}, import_diagnostics.LwrUnresolvableError);
|
|
171
|
+
throw new import_diagnostics.LwrUnresolvableError(import_diagnostics.descriptions.UNRESOLVABLE.DIR_ALIAS(fullMatch), "asset");
|
|
174
172
|
}
|
|
175
173
|
return alias;
|
|
176
174
|
});
|
package/build/cjs/graph.cjs
CHANGED
|
@@ -112,9 +112,7 @@ async function getModuleGraphs(specifier, options, moduleRegistry, defRegistry,
|
|
|
112
112
|
};
|
|
113
113
|
const moduleDef = isBundler(defRegistry) ? await defRegistry.getModuleBundle(versionedModuleId, runtimeEnvironment, runtimeParams) : await defRegistry.getModule(versionedModuleId, runtimeParams);
|
|
114
114
|
if (!moduleDef) {
|
|
115
|
-
throw
|
|
116
|
-
description: import_diagnostics.descriptions.UNRESOLVABLE.MODULE_ENTRY(versionedModuleId.specifier)
|
|
117
|
-
}, import_diagnostics.LwrUnresolvableError);
|
|
115
|
+
throw new import_diagnostics.LwrUnresolvableError(import_diagnostics.descriptions.UNRESOLVABLE.MODULE_ENTRY(versionedModuleId.specifier), "module");
|
|
118
116
|
}
|
|
119
117
|
const flattened = [];
|
|
120
118
|
await traverse(moduleDef, depth, flattened, 0, acc, defRegistry, runtimeEnvironment, runtimeParams);
|
package/build/cjs/identity.cjs
CHANGED
|
@@ -95,7 +95,7 @@ function explodeSpecifier(rawSpecifier) {
|
|
|
95
95
|
const name = rawName ? [rawName, ...remaining].join("/") : rawNamespace;
|
|
96
96
|
return {
|
|
97
97
|
specifier: importee,
|
|
98
|
-
namespace,
|
|
98
|
+
namespace: namespace || "",
|
|
99
99
|
name,
|
|
100
100
|
version: version ? normalizeVersionFromUri(version) : version
|
|
101
101
|
};
|
package/build/cjs/urls.cjs
CHANGED
|
@@ -33,7 +33,8 @@ __export(exports, {
|
|
|
33
33
|
getViewUri: () => getViewUri,
|
|
34
34
|
isModuleOrBundleUrl: () => isModuleOrBundleUrl,
|
|
35
35
|
isURL: () => isURL,
|
|
36
|
-
removeClientBootstrapConfigurationSuffix: () => removeClientBootstrapConfigurationSuffix
|
|
36
|
+
removeClientBootstrapConfigurationSuffix: () => removeClientBootstrapConfigurationSuffix,
|
|
37
|
+
toHostname: () => toHostname
|
|
37
38
|
});
|
|
38
39
|
var import_path_to_regexp = __toModule(require("path-to-regexp"));
|
|
39
40
|
var import_path = __toModule(require("path"));
|
|
@@ -138,3 +139,6 @@ function crossEnvFileURL(url) {
|
|
|
138
139
|
}
|
|
139
140
|
return url;
|
|
140
141
|
}
|
|
142
|
+
function toHostname(url) {
|
|
143
|
+
return url.replace(/^https?:\/\//, "").replace(/:(\d+)(?=[/.]|$)/, "");
|
|
144
|
+
}
|
package/build/es/env.d.ts
CHANGED
|
@@ -16,7 +16,11 @@ export declare function isLocalDev(): boolean;
|
|
|
16
16
|
* Create a serializable context for user-land exposed environment variables
|
|
17
17
|
*/
|
|
18
18
|
export declare function buildEnvironmentContext(runtimeParams: RuntimeParams): EnvironmentContext;
|
|
19
|
-
export declare const
|
|
20
|
-
export declare const
|
|
19
|
+
export declare const TRUE_CLIENT_IP = "true-client-ip";
|
|
20
|
+
export declare const B3_TRACE_ID = "x-b3-traceid";
|
|
21
|
+
export declare const CORRELATION_ID = "x-correlation-id";
|
|
22
|
+
export declare const MRT_REQUEST_CLASS = "x-mobify-request-class";
|
|
23
|
+
export declare const ROUTE_CORE_HEADER = "x-sfdc-route-core";
|
|
24
|
+
export declare const REQUEST_DEPTH_HEADER = "x-sfdc-request-depth";
|
|
21
25
|
export declare function parseRequestDepth(headers?: Headers, query?: Record<string, string>): number;
|
|
22
26
|
//# sourceMappingURL=env.d.ts.map
|
package/build/es/env.js
CHANGED
|
@@ -89,11 +89,17 @@ export function buildEnvironmentContext(runtimeParams) {
|
|
|
89
89
|
uiBasePath,
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
|
-
|
|
93
|
-
export const
|
|
92
|
+
// headers used by LWR-Node and LWR@MRT
|
|
93
|
+
export const TRUE_CLIENT_IP = 'true-client-ip'; // public IP of the original request source, eg: 13.123.12.3
|
|
94
|
+
export const B3_TRACE_ID = 'x-b3-traceid'; // trace ID shared across service boundaries for a page request, eg: 463ac35c9f6413ad48485a3953bb6124
|
|
95
|
+
export const CORRELATION_ID = 'x-correlation-id'; // shared correlation ID for the request
|
|
96
|
+
export const MRT_REQUEST_CLASS = 'x-mobify-request-class'; // contains the site base path, eg: basePath=/mysite
|
|
97
|
+
export const ROUTE_CORE_HEADER = 'x-sfdc-route-core'; // helps route requests to Core efficiently, value: true
|
|
98
|
+
export const REQUEST_DEPTH_HEADER = 'x-sfdc-request-depth'; // tracks the request depth to prevent cycles to the LWR server, eg: 2
|
|
99
|
+
// standard headers: Forwarded (eg: host=dev.testing.com;proto=https), Host (eg: darrell.sandbox.my.site.com), Cookie (holds the SID for auth'ed requests)
|
|
94
100
|
export function parseRequestDepth(headers = {}, query = {}) {
|
|
95
101
|
let maxDepth = 0;
|
|
96
|
-
const value = headers && headers[
|
|
102
|
+
const value = headers && headers[REQUEST_DEPTH_HEADER];
|
|
97
103
|
if (value) {
|
|
98
104
|
if (Array.isArray(value)) {
|
|
99
105
|
for (const depth of value) {
|
|
@@ -112,8 +118,8 @@ export function parseRequestDepth(headers = {}, query = {}) {
|
|
|
112
118
|
}
|
|
113
119
|
}
|
|
114
120
|
}
|
|
115
|
-
if (query[
|
|
116
|
-
const queryValue = parseInt(query[
|
|
121
|
+
if (query[REQUEST_DEPTH_HEADER]) {
|
|
122
|
+
const queryValue = parseInt(query[REQUEST_DEPTH_HEADER], 10);
|
|
117
123
|
if (!isNaN(queryValue) && queryValue > maxDepth) {
|
|
118
124
|
maxDepth = queryValue;
|
|
119
125
|
}
|
package/build/es/fs.js
CHANGED
|
@@ -3,7 +3,7 @@ import pathLib from 'path';
|
|
|
3
3
|
import url from 'url';
|
|
4
4
|
import crypto from 'crypto';
|
|
5
5
|
import { slugify } from './identity.js';
|
|
6
|
-
import { LwrUnresolvableError,
|
|
6
|
+
import { LwrUnresolvableError, descriptions } from '@lwrjs/diagnostics';
|
|
7
7
|
import { lookup } from 'mime-types';
|
|
8
8
|
import { Readable } from 'stream';
|
|
9
9
|
import { logger } from '@lwrjs/diagnostics';
|
|
@@ -185,9 +185,7 @@ export function normalizeResourcePath(rawPath, { rootDir, assets, contentDir, la
|
|
|
185
185
|
return rawPath.replace(RESOURCE_DIR_REGEX, function (fullMatch, m1, m2) {
|
|
186
186
|
const alias = assetsMap[m1] || assetsMap[m2];
|
|
187
187
|
if (!alias && !allowUnresolvedAlias) {
|
|
188
|
-
throw
|
|
189
|
-
description: descriptions.UNRESOLVABLE.DIR_ALIAS(fullMatch),
|
|
190
|
-
}, LwrUnresolvableError);
|
|
188
|
+
throw new LwrUnresolvableError(descriptions.UNRESOLVABLE.DIR_ALIAS(fullMatch), 'asset');
|
|
191
189
|
}
|
|
192
190
|
return alias;
|
|
193
191
|
});
|
package/build/es/graph.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getSpecifier, getVersionedModuleId, isBundleDefinition } from './identity.js';
|
|
2
|
-
import { LwrUnresolvableError,
|
|
2
|
+
import { LwrUnresolvableError, descriptions } from '@lwrjs/diagnostics';
|
|
3
3
|
import { ModuleNameType } from './import-metadata.js';
|
|
4
4
|
export var GraphDepth;
|
|
5
5
|
(function (GraphDepth) {
|
|
@@ -117,9 +117,7 @@ options, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visited
|
|
|
117
117
|
? await defRegistry.getModuleBundle(versionedModuleId, runtimeEnvironment, runtimeParams)
|
|
118
118
|
: await defRegistry.getModule(versionedModuleId, runtimeParams);
|
|
119
119
|
if (!moduleDef) {
|
|
120
|
-
throw
|
|
121
|
-
description: descriptions.UNRESOLVABLE.MODULE_ENTRY(versionedModuleId.specifier),
|
|
122
|
-
}, LwrUnresolvableError);
|
|
120
|
+
throw new LwrUnresolvableError(descriptions.UNRESOLVABLE.MODULE_ENTRY(versionedModuleId.specifier), 'module');
|
|
123
121
|
}
|
|
124
122
|
const flattened = [];
|
|
125
123
|
await traverse(moduleDef, depth, flattened, 0, acc, defRegistry, runtimeEnvironment, runtimeParams);
|
package/build/es/identity.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export declare function prettyModuleUriSuffix(specifier: string): string;
|
|
|
43
43
|
*/
|
|
44
44
|
interface PartialModuleId extends AbstractModuleId {
|
|
45
45
|
name: string;
|
|
46
|
+
namespace: string;
|
|
46
47
|
}
|
|
47
48
|
export declare function explodeSpecifier(rawSpecifier: string): PartialModuleId;
|
|
48
49
|
export declare function explodeSpecifiers(rawSpecifiers: string): PartialModuleId[];
|
package/build/es/identity.js
CHANGED
package/build/es/urls.d.ts
CHANGED
|
@@ -38,4 +38,5 @@ export declare function getViewUri(routePath: string, basePath: string, locale:
|
|
|
38
38
|
*/
|
|
39
39
|
export declare function isURL(uri: string): boolean;
|
|
40
40
|
export declare function crossEnvFileURL(url: string): string;
|
|
41
|
+
export declare function toHostname(url: string): string;
|
|
41
42
|
//# sourceMappingURL=urls.d.ts.map
|
package/build/es/urls.js
CHANGED
|
@@ -139,4 +139,13 @@ export function crossEnvFileURL(url) {
|
|
|
139
139
|
}
|
|
140
140
|
return url;
|
|
141
141
|
}
|
|
142
|
+
// Remove the protocol and port from a URL to create a hostname
|
|
143
|
+
// eg: url = https://developer.mozilla.org:4097/en-US/docs/Web/API/URL/hostname
|
|
144
|
+
// protocol = https
|
|
145
|
+
// port = 4097
|
|
146
|
+
// host = developer.mozilla.org:4097
|
|
147
|
+
// hostname = developer.mozilla.org
|
|
148
|
+
export function toHostname(url) {
|
|
149
|
+
return url.replace(/^https?:\/\//, '').replace(/:(\d+)(?=[/.]|$)/, '');
|
|
150
|
+
}
|
|
142
151
|
//# sourceMappingURL=urls.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.17.2-alpha.
|
|
7
|
+
"version": "0.17.2-alpha.11",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"build/**/*.d.ts"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@lwrjs/diagnostics": "0.17.2-alpha.
|
|
40
|
+
"@lwrjs/diagnostics": "0.17.2-alpha.11",
|
|
41
41
|
"es-module-lexer": "^1.5.4",
|
|
42
42
|
"fast-json-stable-stringify": "^2.1.0",
|
|
43
43
|
"magic-string": "^0.30.9",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"slugify": "^1.4.5"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@lwrjs/types": "0.17.2-alpha.
|
|
53
|
+
"@lwrjs/types": "0.17.2-alpha.11",
|
|
54
54
|
"@types/mime-types": "2.1.4",
|
|
55
55
|
"@types/path-to-regexp": "^1.7.0",
|
|
56
56
|
"memfs": "^4.13.0"
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">=18.0.0"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "72217912e6c17e617413044743892582be5599a0"
|
|
62
62
|
}
|