@lwrjs/shared-utils 0.17.2-alpha.15 → 0.17.2-alpha.16
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 +10 -7
- package/build/cjs/serialize.cjs +52 -0
- package/build/es/env.js +11 -7
- package/build/es/serialize.d.ts +13 -1
- package/build/es/serialize.js +66 -0
- package/package.json +4 -4
package/build/cjs/env.cjs
CHANGED
|
@@ -35,6 +35,7 @@ function getFeatureFlags() {
|
|
|
35
35
|
EXPERIMENTAL_UNVERSIONED_ALIASES: parseBooleanFlag("EXPERIMENTAL_UNVERSIONED_ALIASES"),
|
|
36
36
|
LEGACY_LOADER: parseBooleanFlag("LEGACY_LOADER"),
|
|
37
37
|
LWR_TRACING: parseTracingFlag(),
|
|
38
|
+
DISABLE_B3_TRACING: parseBooleanFlag("DISABLE_B3_TRACING"),
|
|
38
39
|
MAX_VIEW_CACHE_TTL: parseStringFlag("MAX_VIEW_CACHE_TTL"),
|
|
39
40
|
REEVALUATE_MODULES: parseBooleanFlag("REEVALUATE_MODULES"),
|
|
40
41
|
SSR_COMPILER_ENABLED: parseBooleanFlag("SSR_COMPILER_ENABLED"),
|
|
@@ -115,13 +116,15 @@ function getTraceHeaders(runtimeParams, span) {
|
|
|
115
116
|
headers[TRUE_CLIENT_IP] = runtimeParams.trueClientIP;
|
|
116
117
|
if (runtimeParams.correlationID)
|
|
117
118
|
headers[CORRELATION_ID] = runtimeParams.correlationID;
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
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;
|
|
121
128
|
}
|
|
122
|
-
if (span?.spanId)
|
|
123
|
-
headers[B3_SPAN_ID] = span.spanId;
|
|
124
|
-
if (span?.parentSpanId)
|
|
125
|
-
headers[B3_PARENT_ID] = span.parentSpanId;
|
|
126
129
|
return headers;
|
|
127
130
|
}
|
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/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.
|
|
@@ -135,14 +137,16 @@ export function getTraceHeaders(runtimeParams, span) {
|
|
|
135
137
|
headers[TRUE_CLIENT_IP] = runtimeParams.trueClientIP;
|
|
136
138
|
if (runtimeParams.correlationID)
|
|
137
139
|
headers[CORRELATION_ID] = runtimeParams.correlationID;
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
|
|
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;
|
|
141
149
|
}
|
|
142
|
-
if (span?.spanId)
|
|
143
|
-
headers[B3_SPAN_ID] = span.spanId;
|
|
144
|
-
if (span?.parentSpanId)
|
|
145
|
-
headers[B3_PARENT_ID] = span.parentSpanId;
|
|
146
150
|
return headers;
|
|
147
151
|
}
|
|
148
152
|
//# sourceMappingURL=env.js.map
|
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/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.16",
|
|
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.16",
|
|
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.16",
|
|
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": ">=20.0.0"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "5a6b24c265145652f9dda60d1d2cb405148c71f3"
|
|
62
62
|
}
|