@lwrjs/shared-utils 0.17.2-alpha.2 → 0.17.2-alpha.20
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 +40 -6
- package/build/cjs/identity.cjs +1 -1
- package/build/cjs/serialize.cjs +52 -0
- package/build/cjs/urls.cjs +5 -1
- package/build/es/env.d.ts +14 -2
- package/build/es/env.js +34 -5
- package/build/es/identity.d.ts +1 -0
- package/build/es/identity.js +1 -1
- package/build/es/serialize.d.ts +13 -1
- package/build/es/serialize.js +66 -0
- package/build/es/urls.d.ts +1 -0
- package/build/es/urls.js +9 -0
- package/package.json +5 -5
package/build/cjs/env.cjs
CHANGED
|
@@ -8,10 +8,18 @@ var __export = (target, all) => {
|
|
|
8
8
|
// packages/@lwrjs/shared-utils/src/env.ts
|
|
9
9
|
__markAsModule(exports);
|
|
10
10
|
__export(exports, {
|
|
11
|
+
B3_PARENT_ID: () => B3_PARENT_ID,
|
|
12
|
+
B3_SAMPLED: () => B3_SAMPLED,
|
|
13
|
+
B3_SPAN_ID: () => B3_SPAN_ID,
|
|
14
|
+
B3_TRACE_ID: () => B3_TRACE_ID,
|
|
15
|
+
CORRELATION_ID: () => CORRELATION_ID,
|
|
16
|
+
MRT_REQUEST_CLASS: () => MRT_REQUEST_CLASS,
|
|
11
17
|
REQUEST_DEPTH_HEADER: () => REQUEST_DEPTH_HEADER,
|
|
12
|
-
|
|
18
|
+
ROUTE_CORE_HEADER: () => ROUTE_CORE_HEADER,
|
|
19
|
+
TRUE_CLIENT_IP: () => TRUE_CLIENT_IP,
|
|
13
20
|
buildEnvironmentContext: () => buildEnvironmentContext,
|
|
14
21
|
getFeatureFlags: () => getFeatureFlags,
|
|
22
|
+
getTraceHeaders: () => getTraceHeaders,
|
|
15
23
|
isLambdaEnv: () => isLambdaEnv,
|
|
16
24
|
isLocalDev: () => isLocalDev,
|
|
17
25
|
parseRequestDepth: () => parseRequestDepth
|
|
@@ -27,6 +35,7 @@ function getFeatureFlags() {
|
|
|
27
35
|
EXPERIMENTAL_UNVERSIONED_ALIASES: parseBooleanFlag("EXPERIMENTAL_UNVERSIONED_ALIASES"),
|
|
28
36
|
LEGACY_LOADER: parseBooleanFlag("LEGACY_LOADER"),
|
|
29
37
|
LWR_TRACING: parseTracingFlag(),
|
|
38
|
+
DISABLE_B3_TRACING: parseBooleanFlag("DISABLE_B3_TRACING"),
|
|
30
39
|
MAX_VIEW_CACHE_TTL: parseStringFlag("MAX_VIEW_CACHE_TTL"),
|
|
31
40
|
REEVALUATE_MODULES: parseBooleanFlag("REEVALUATE_MODULES"),
|
|
32
41
|
SSR_COMPILER_ENABLED: parseBooleanFlag("SSR_COMPILER_ENABLED"),
|
|
@@ -64,11 +73,18 @@ function buildEnvironmentContext(runtimeParams) {
|
|
|
64
73
|
uiBasePath
|
|
65
74
|
};
|
|
66
75
|
}
|
|
67
|
-
var
|
|
68
|
-
var
|
|
76
|
+
var TRUE_CLIENT_IP = "true-client-ip";
|
|
77
|
+
var CORRELATION_ID = "x-correlation-id";
|
|
78
|
+
var B3_TRACE_ID = "x-b3-traceid";
|
|
79
|
+
var B3_SPAN_ID = "x-b3-spandid";
|
|
80
|
+
var B3_PARENT_ID = "x-b3-parentid";
|
|
81
|
+
var B3_SAMPLED = "x-b3-sampled";
|
|
82
|
+
var MRT_REQUEST_CLASS = "x-mobify-request-class";
|
|
83
|
+
var ROUTE_CORE_HEADER = "x-sfdc-route-core";
|
|
84
|
+
var REQUEST_DEPTH_HEADER = "x-sfdc-request-depth";
|
|
69
85
|
function parseRequestDepth(headers = {}, query = {}) {
|
|
70
86
|
let maxDepth = 0;
|
|
71
|
-
const value = headers && headers[
|
|
87
|
+
const value = headers && headers[REQUEST_DEPTH_HEADER];
|
|
72
88
|
if (value) {
|
|
73
89
|
if (Array.isArray(value)) {
|
|
74
90
|
for (const depth of value) {
|
|
@@ -86,11 +102,29 @@ function parseRequestDepth(headers = {}, query = {}) {
|
|
|
86
102
|
}
|
|
87
103
|
}
|
|
88
104
|
}
|
|
89
|
-
if (query[
|
|
90
|
-
const queryValue = parseInt(query[
|
|
105
|
+
if (query[REQUEST_DEPTH_HEADER]) {
|
|
106
|
+
const queryValue = parseInt(query[REQUEST_DEPTH_HEADER], 10);
|
|
91
107
|
if (!isNaN(queryValue) && queryValue > maxDepth) {
|
|
92
108
|
maxDepth = queryValue;
|
|
93
109
|
}
|
|
94
110
|
}
|
|
95
111
|
return maxDepth;
|
|
96
112
|
}
|
|
113
|
+
function getTraceHeaders(runtimeParams, span) {
|
|
114
|
+
const headers = {};
|
|
115
|
+
if (runtimeParams.trueClientIP)
|
|
116
|
+
headers[TRUE_CLIENT_IP] = runtimeParams.trueClientIP;
|
|
117
|
+
if (runtimeParams.correlationID)
|
|
118
|
+
headers[CORRELATION_ID] = runtimeParams.correlationID;
|
|
119
|
+
if (!getFeatureFlags().DISABLE_B3_TRACING) {
|
|
120
|
+
if (span?.traceId) {
|
|
121
|
+
headers[B3_TRACE_ID] = span.traceId;
|
|
122
|
+
headers[B3_SAMPLED] = parseTracingFlag() ? "1" : "0";
|
|
123
|
+
}
|
|
124
|
+
if (span?.spanId)
|
|
125
|
+
headers[B3_SPAN_ID] = span.spanId;
|
|
126
|
+
if (span?.parentSpanId)
|
|
127
|
+
headers[B3_PARENT_ID] = span.parentSpanId;
|
|
128
|
+
}
|
|
129
|
+
return headers;
|
|
130
|
+
}
|
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/serialize.cjs
CHANGED
|
@@ -24,11 +24,14 @@ var __toModule = (module2) => {
|
|
|
24
24
|
// packages/@lwrjs/shared-utils/src/serialize.ts
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
|
+
addHeadMarkup: () => addHeadMarkup,
|
|
28
|
+
createHeadMarkup: () => createHeadMarkup,
|
|
27
29
|
replaceStringFromLocation: () => replaceStringFromLocation,
|
|
28
30
|
serializeModuleToJson: () => serializeModuleToJson,
|
|
29
31
|
shortestTtl: () => shortestTtl
|
|
30
32
|
});
|
|
31
33
|
var import_ms = __toModule(require("ms"));
|
|
34
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
32
35
|
async function createJsonModule(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams) {
|
|
33
36
|
const {
|
|
34
37
|
ownHash,
|
|
@@ -84,3 +87,52 @@ function shortestTtl(newTtl, oldTtl, maxTtl) {
|
|
|
84
87
|
}
|
|
85
88
|
return shortest;
|
|
86
89
|
}
|
|
90
|
+
function createMetaTags(meta) {
|
|
91
|
+
return meta.reduce((metaStr, {name, content, httpEquiv}) => {
|
|
92
|
+
if (!name && !content && !httpEquiv)
|
|
93
|
+
return metaStr;
|
|
94
|
+
const nameStr = name ? ` name="${name}"` : "", httpEquivStr = httpEquiv ? ` http-equiv="${httpEquiv}"` : "", contentStr = content ? ` content="${content}"` : "";
|
|
95
|
+
return metaStr + `<meta${nameStr}${httpEquivStr}${contentStr}>
|
|
96
|
+
`;
|
|
97
|
+
}, "");
|
|
98
|
+
}
|
|
99
|
+
function createScriptTags(scripts) {
|
|
100
|
+
return scripts.reduce((scriptStr, {body}) => scriptStr + `<script type="application/ld+json">${body}</script>
|
|
101
|
+
`, "");
|
|
102
|
+
}
|
|
103
|
+
function createLinkTags(links) {
|
|
104
|
+
return links.reduce((linkStr, {href, rel, as, fetchpriority}) => {
|
|
105
|
+
const relStr = rel ? ` rel="${rel}"` : "", asStr = as ? ` as="${as}"` : "", fetchStr = fetchpriority ? ` fetchpriority="${fetchpriority}"` : "";
|
|
106
|
+
return linkStr + `<link href="${href}"${relStr}${asStr}${fetchStr}>
|
|
107
|
+
`;
|
|
108
|
+
}, "");
|
|
109
|
+
}
|
|
110
|
+
function createStyleTags(styles) {
|
|
111
|
+
return styles.reduce((styleStr, {body, id}) => {
|
|
112
|
+
const idStr = id ? ` id="${id}"` : "";
|
|
113
|
+
return styleStr + `<style type="text/css"${idStr}>${body}</style>
|
|
114
|
+
`;
|
|
115
|
+
}, "");
|
|
116
|
+
}
|
|
117
|
+
function createHeadMarkup(markup) {
|
|
118
|
+
let hasTitle = false;
|
|
119
|
+
return markup.reduce((str, {title, scripts = [], meta = [], links = [], styles = []} = {}) => {
|
|
120
|
+
if (title && !hasTitle) {
|
|
121
|
+
hasTitle = true;
|
|
122
|
+
str += `<title>${title}</title>
|
|
123
|
+
`;
|
|
124
|
+
}
|
|
125
|
+
return str + createMetaTags(meta) + createScriptTags(scripts) + createLinkTags(links) + createStyleTags(styles);
|
|
126
|
+
}, "");
|
|
127
|
+
}
|
|
128
|
+
function addHeadMarkup(markup, stringBuilder) {
|
|
129
|
+
const headMarkup = createHeadMarkup(markup);
|
|
130
|
+
if (headMarkup) {
|
|
131
|
+
const headIndex = stringBuilder.original.indexOf("</head>");
|
|
132
|
+
if (headIndex >= 0) {
|
|
133
|
+
stringBuilder.prependLeft(headIndex, headMarkup);
|
|
134
|
+
} else {
|
|
135
|
+
import_diagnostics.logger.error("Adding head markup failed. Could not find the </head> tag.");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
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,19 @@ 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 CORRELATION_ID = "x-correlation-id";
|
|
21
|
+
export declare const B3_TRACE_ID = "x-b3-traceid";
|
|
22
|
+
export declare const B3_SPAN_ID = "x-b3-spandid";
|
|
23
|
+
export declare const B3_PARENT_ID = "x-b3-parentid";
|
|
24
|
+
export declare const B3_SAMPLED = "x-b3-sampled";
|
|
25
|
+
export declare const MRT_REQUEST_CLASS = "x-mobify-request-class";
|
|
26
|
+
export declare const ROUTE_CORE_HEADER = "x-sfdc-route-core";
|
|
27
|
+
export declare const REQUEST_DEPTH_HEADER = "x-sfdc-request-depth";
|
|
21
28
|
export declare function parseRequestDepth(headers?: Headers, query?: Record<string, string>): number;
|
|
29
|
+
export declare function getTraceHeaders(runtimeParams: RuntimeParams, span?: {
|
|
30
|
+
traceId: string;
|
|
31
|
+
spanId: string;
|
|
32
|
+
parentSpanId?: string;
|
|
33
|
+
}): HeadersInit;
|
|
22
34
|
//# sourceMappingURL=env.d.ts.map
|
package/build/es/env.js
CHANGED
|
@@ -14,6 +14,8 @@ export function getFeatureFlags() {
|
|
|
14
14
|
LEGACY_LOADER: parseBooleanFlag('LEGACY_LOADER'),
|
|
15
15
|
// Enable metrics log level 'off', 'default' or 'verbose'
|
|
16
16
|
LWR_TRACING: parseTracingFlag(),
|
|
17
|
+
// Turn off distributed tracing (B3 headers, traceparent meta tag, MRT span exporting)
|
|
18
|
+
DISABLE_B3_TRACING: parseBooleanFlag('DISABLE_B3_TRACING'),
|
|
17
19
|
// Max size of ViewDefinition time to live
|
|
18
20
|
MAX_VIEW_CACHE_TTL: parseStringFlag('MAX_VIEW_CACHE_TTL'),
|
|
19
21
|
// Forces SSR to re-evaluate modules for every page render. By default, modules are evaluated only once.
|
|
@@ -89,11 +91,20 @@ export function buildEnvironmentContext(runtimeParams) {
|
|
|
89
91
|
uiBasePath,
|
|
90
92
|
};
|
|
91
93
|
}
|
|
92
|
-
|
|
93
|
-
export const
|
|
94
|
+
// headers used by LWR-Node and LWR@MRT
|
|
95
|
+
export const TRUE_CLIENT_IP = 'true-client-ip'; // public IP of the original request source, eg: 13.123.12.3
|
|
96
|
+
export const CORRELATION_ID = 'x-correlation-id'; // shared correlation ID for the request
|
|
97
|
+
export const B3_TRACE_ID = 'x-b3-traceid'; // trace ID shared across service boundaries for a page request, set to inbound B3 header || lwr.handle.view trace ID
|
|
98
|
+
export const B3_SPAN_ID = 'x-b3-spandid'; // span ID for a trace
|
|
99
|
+
export const B3_PARENT_ID = 'x-b3-parentid'; // parent span ID for a trace
|
|
100
|
+
export const B3_SAMPLED = 'x-b3-sampled'; // "0" = tracing is off, "1" = tracing is on
|
|
101
|
+
export const MRT_REQUEST_CLASS = 'x-mobify-request-class'; // contains the site base path, eg: basePath=/mysite
|
|
102
|
+
export const ROUTE_CORE_HEADER = 'x-sfdc-route-core'; // helps route requests to Core efficiently, value: true
|
|
103
|
+
export const REQUEST_DEPTH_HEADER = 'x-sfdc-request-depth'; // tracks the request depth to prevent cycles to the LWR server, eg: 2
|
|
104
|
+
// 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
105
|
export function parseRequestDepth(headers = {}, query = {}) {
|
|
95
106
|
let maxDepth = 0;
|
|
96
|
-
const value = headers && headers[
|
|
107
|
+
const value = headers && headers[REQUEST_DEPTH_HEADER];
|
|
97
108
|
if (value) {
|
|
98
109
|
if (Array.isArray(value)) {
|
|
99
110
|
for (const depth of value) {
|
|
@@ -112,12 +123,30 @@ export function parseRequestDepth(headers = {}, query = {}) {
|
|
|
112
123
|
}
|
|
113
124
|
}
|
|
114
125
|
}
|
|
115
|
-
if (query[
|
|
116
|
-
const queryValue = parseInt(query[
|
|
126
|
+
if (query[REQUEST_DEPTH_HEADER]) {
|
|
127
|
+
const queryValue = parseInt(query[REQUEST_DEPTH_HEADER], 10);
|
|
117
128
|
if (!isNaN(queryValue) && queryValue > maxDepth) {
|
|
118
129
|
maxDepth = queryValue;
|
|
119
130
|
}
|
|
120
131
|
}
|
|
121
132
|
return maxDepth;
|
|
122
133
|
}
|
|
134
|
+
export function getTraceHeaders(runtimeParams, span) {
|
|
135
|
+
const headers = {};
|
|
136
|
+
if (runtimeParams.trueClientIP)
|
|
137
|
+
headers[TRUE_CLIENT_IP] = runtimeParams.trueClientIP;
|
|
138
|
+
if (runtimeParams.correlationID)
|
|
139
|
+
headers[CORRELATION_ID] = runtimeParams.correlationID;
|
|
140
|
+
if (!getFeatureFlags().DISABLE_B3_TRACING) {
|
|
141
|
+
if (span?.traceId) {
|
|
142
|
+
headers[B3_TRACE_ID] = span.traceId;
|
|
143
|
+
headers[B3_SAMPLED] = parseTracingFlag() ? '1' : '0';
|
|
144
|
+
}
|
|
145
|
+
if (span?.spanId)
|
|
146
|
+
headers[B3_SPAN_ID] = span.spanId;
|
|
147
|
+
if (span?.parentSpanId)
|
|
148
|
+
headers[B3_PARENT_ID] = span.parentSpanId;
|
|
149
|
+
}
|
|
150
|
+
return headers;
|
|
151
|
+
}
|
|
123
152
|
//# sourceMappingURL=env.js.map
|
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/serialize.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LinkedModuleDefinition, ModuleJsonDefinition, ModuleRegistry, RuntimeParams } from '@lwrjs/types';
|
|
1
|
+
import type { HeadMarkup, LinkedModuleDefinition, LwrStringBuilder, ModuleJsonDefinition, ModuleRegistry, RuntimeParams } from '@lwrjs/types';
|
|
2
2
|
/**
|
|
3
3
|
* Take a Module Definition and return its JSON serialization
|
|
4
4
|
*
|
|
@@ -26,4 +26,16 @@ export declare function replaceStringFromLocation(src: string, { startOffset, en
|
|
|
26
26
|
* @returns - the shorter of the two TTLs IN SECONDS, undefined if both TTLs are missing
|
|
27
27
|
*/
|
|
28
28
|
export declare function shortestTtl(newTtl?: string | number, oldTtl?: string | number, maxTtl?: string | number): number | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Serialize head markup metadata into an HTML string
|
|
31
|
+
* @param markup An array of markup metadata objects
|
|
32
|
+
* @returns A string of HTML generated from markup metadata
|
|
33
|
+
*/
|
|
34
|
+
export declare function createHeadMarkup(markup: (HeadMarkup | undefined)[]): string;
|
|
35
|
+
/**
|
|
36
|
+
* Serialize HeadMarkup config into HTML, then add it to the <head> of a base doc
|
|
37
|
+
* @param markup An array of markup metadata objects
|
|
38
|
+
* @param stringBuilder The string builder for a base document
|
|
39
|
+
*/
|
|
40
|
+
export declare function addHeadMarkup(markup: (HeadMarkup | undefined)[], stringBuilder: LwrStringBuilder): void;
|
|
29
41
|
//# sourceMappingURL=serialize.d.ts.map
|
package/build/es/serialize.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ms from 'ms';
|
|
2
|
+
import { logger } from '@lwrjs/diagnostics';
|
|
2
3
|
// Given a Module Identifier, return a JSON entry
|
|
3
4
|
async function createJsonModule(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams) {
|
|
4
5
|
const { ownHash, moduleEntry: { version }, } = await moduleRegistry.getModule(moduleId, runtimeParams);
|
|
@@ -67,4 +68,69 @@ export function shortestTtl(newTtl, oldTtl, maxTtl) {
|
|
|
67
68
|
}
|
|
68
69
|
return shortest;
|
|
69
70
|
}
|
|
71
|
+
/** HEAD MARKUP UTILS */
|
|
72
|
+
function createMetaTags(meta) {
|
|
73
|
+
return meta.reduce((metaStr, { name, content, httpEquiv }) => {
|
|
74
|
+
if (!name && !content && !httpEquiv)
|
|
75
|
+
return metaStr; // do not create empty <meta> tags
|
|
76
|
+
const nameStr = name ? ` name="${name}"` : '', httpEquivStr = httpEquiv ? ` http-equiv="${httpEquiv}"` : '', contentStr = content ? ` content="${content}"` : '';
|
|
77
|
+
return metaStr + `<meta${nameStr}${httpEquivStr}${contentStr}>\n`;
|
|
78
|
+
}, '');
|
|
79
|
+
}
|
|
80
|
+
function createScriptTags(scripts) {
|
|
81
|
+
return scripts.reduce((scriptStr, { body }) => scriptStr + `<script type="application/ld+json">${body}</script>\n`, '');
|
|
82
|
+
}
|
|
83
|
+
function createLinkTags(links) {
|
|
84
|
+
return links.reduce((linkStr, { href, rel, as, fetchpriority }) => {
|
|
85
|
+
const relStr = rel ? ` rel="${rel}"` : '', asStr = as ? ` as="${as}"` : '', fetchStr = fetchpriority ? ` fetchpriority="${fetchpriority}"` : '';
|
|
86
|
+
return linkStr + `<link href="${href}"${relStr}${asStr}${fetchStr}>\n`;
|
|
87
|
+
}, '');
|
|
88
|
+
}
|
|
89
|
+
function createStyleTags(styles) {
|
|
90
|
+
return styles.reduce((styleStr, { body, id }) => {
|
|
91
|
+
const idStr = id ? ` id="${id}"` : '';
|
|
92
|
+
return styleStr + `<style type="text/css"${idStr}>${body}</style>\n`;
|
|
93
|
+
}, '');
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Serialize head markup metadata into an HTML string
|
|
97
|
+
* @param markup An array of markup metadata objects
|
|
98
|
+
* @returns A string of HTML generated from markup metadata
|
|
99
|
+
*/
|
|
100
|
+
export function createHeadMarkup(markup) {
|
|
101
|
+
// Loop through the <title>, <script>, <meta>, and <link> tag information
|
|
102
|
+
// Create an HTML string for each tag
|
|
103
|
+
let hasTitle = false;
|
|
104
|
+
return markup.reduce((str, { title, scripts = [], meta = [], links = [], styles = [] } = {}) => {
|
|
105
|
+
if (title && !hasTitle) {
|
|
106
|
+
// first <title> wins
|
|
107
|
+
hasTitle = true;
|
|
108
|
+
str += `<title>${title}</title>\n`;
|
|
109
|
+
}
|
|
110
|
+
return (str +
|
|
111
|
+
createMetaTags(meta) +
|
|
112
|
+
createScriptTags(scripts) +
|
|
113
|
+
createLinkTags(links) +
|
|
114
|
+
createStyleTags(styles));
|
|
115
|
+
}, '');
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Serialize HeadMarkup config into HTML, then add it to the <head> of a base doc
|
|
119
|
+
* @param markup An array of markup metadata objects
|
|
120
|
+
* @param stringBuilder The string builder for a base document
|
|
121
|
+
*/
|
|
122
|
+
export function addHeadMarkup(markup, stringBuilder) {
|
|
123
|
+
// Create HTML tags for each item in the SsrDataResponse.markup bag
|
|
124
|
+
const headMarkup = createHeadMarkup(markup);
|
|
125
|
+
if (headMarkup) {
|
|
126
|
+
// Add all the links to the <head> section of the base document
|
|
127
|
+
const headIndex = stringBuilder.original.indexOf('</head>');
|
|
128
|
+
if (headIndex >= 0) {
|
|
129
|
+
stringBuilder.prependLeft(headIndex, headMarkup);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
logger.error('Adding head markup failed. Could not find the </head> tag.');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
70
136
|
//# sourceMappingURL=serialize.js.map
|
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.20",
|
|
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.20",
|
|
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,13 +50,13 @@
|
|
|
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.20",
|
|
54
54
|
"@types/mime-types": "2.1.4",
|
|
55
55
|
"@types/path-to-regexp": "^1.7.0",
|
|
56
56
|
"memfs": "^4.13.0"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
|
-
"node": ">=
|
|
59
|
+
"node": ">=20.0.0"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "871213620dec8ff886be421339f1e90e86dbee96"
|
|
62
62
|
}
|