@lwrjs/view-registry 0.13.0-alpha.10 → 0.13.0-alpha.12
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/index.cjs +4 -2
- package/build/cjs/utils.cjs +11 -9
- package/build/es/index.js +5 -1
- package/build/es/utils.d.ts +2 -2
- package/build/es/utils.js +15 -11
- package/package.json +7 -7
package/build/cjs/index.cjs
CHANGED
|
@@ -161,7 +161,8 @@ var LwrViewRegistry = class {
|
|
|
161
161
|
freezeAssets,
|
|
162
162
|
locale: runtimeParams?.locale,
|
|
163
163
|
basePath: runtimeParams?.basePath,
|
|
164
|
-
debug: runtimeEnvironment.debug
|
|
164
|
+
debug: runtimeEnvironment.debug,
|
|
165
|
+
nonceEnabled: (0, import_shared_utils.getFeatureFlags)().ENABLE_NONCE
|
|
165
166
|
});
|
|
166
167
|
import_diagnostics.logger.debug(`[view-registry][hasViewDefinition] viewDefId=${viewDefId}`);
|
|
167
168
|
const viewParamKey = viewParamCacheKey ? (0, import_shared_utils.getCacheKeyFromJson)(viewParamCacheKey) : (0, import_shared_utils.getCacheKeyFromJson)(viewParams);
|
|
@@ -182,7 +183,8 @@ var LwrViewRegistry = class {
|
|
|
182
183
|
freezeAssets,
|
|
183
184
|
locale: runtimeParams?.locale,
|
|
184
185
|
basePath: runtimeParams?.basePath,
|
|
185
|
-
debug: runtimeEnvironment.debug
|
|
186
|
+
debug: runtimeEnvironment.debug,
|
|
187
|
+
nonceEnabled: (0, import_shared_utils.getFeatureFlags)().ENABLE_NONCE
|
|
186
188
|
});
|
|
187
189
|
import_diagnostics.logger.debug(`[view-registry][getViewDefinition] viewDefCacheKey=${viewDefCacheKey}`);
|
|
188
190
|
const viewParamKey = viewParamCacheKey ? (0, import_shared_utils.getCacheKeyFromJson)(viewParamCacheKey) : (0, import_shared_utils.getCacheKeyFromJson)(viewParams);
|
package/build/cjs/utils.cjs
CHANGED
|
@@ -52,7 +52,7 @@ function generateExternalScript(type = "application/javascript", src, async, def
|
|
|
52
52
|
} else if (async) {
|
|
53
53
|
scriptLoadOrder = " async";
|
|
54
54
|
}
|
|
55
|
-
const nonceAttr = nonce ? ` nonce="${nonce}"` : "";
|
|
55
|
+
const nonceAttr = (0, import_shared_utils.getFeatureFlags)().ENABLE_NONCE && nonce ? ` nonce="${nonce}"` : "";
|
|
56
56
|
return `<script type="${type}"${scriptLoadOrder}${nonceAttr} src="${src}"></script>`;
|
|
57
57
|
}
|
|
58
58
|
function generateLinkPreloadTag({href, type}) {
|
|
@@ -74,7 +74,7 @@ function generateExternalTag({type, src = "", async, defer, isPreload, nonce}) {
|
|
|
74
74
|
async function generateInlineTag({specifier, type, content, stream, nonce}) {
|
|
75
75
|
const typeStr = type === "text/css" ? "" : ` type="${type}"`;
|
|
76
76
|
const tag = type === "text/css" ? "style" : "script";
|
|
77
|
-
const nonceStr = nonce ? ` nonce="${nonce}"` : "";
|
|
77
|
+
const nonceStr = (0, import_shared_utils.getFeatureFlags)().ENABLE_NONCE && nonce && nonce ? ` nonce="${nonce}"` : "";
|
|
78
78
|
if (!content && !stream) {
|
|
79
79
|
throw new Error(`Invalid inline Resource Definition: must have either "content" or "stream": "${specifier}"`);
|
|
80
80
|
}
|
|
@@ -259,18 +259,20 @@ async function createJsonModule(specifier, moduleRegistry, environment, params)
|
|
|
259
259
|
};
|
|
260
260
|
}
|
|
261
261
|
function getViewNonce(viewParams) {
|
|
262
|
-
return viewParams?.page?.nonce;
|
|
262
|
+
return (0, import_shared_utils.getFeatureFlags)().ENABLE_NONCE ? viewParams?.page?.nonce : void 0;
|
|
263
263
|
}
|
|
264
264
|
function generateViewNonce(viewParams) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
viewParams.page
|
|
268
|
-
|
|
269
|
-
|
|
265
|
+
if ((0, import_shared_utils.getFeatureFlags)().ENABLE_NONCE) {
|
|
266
|
+
const nonce = import_crypto.default.randomBytes(16).toString("base64");
|
|
267
|
+
if (!viewParams.page) {
|
|
268
|
+
viewParams.page = {nonce};
|
|
269
|
+
} else {
|
|
270
|
+
viewParams.page.nonce = nonce;
|
|
271
|
+
}
|
|
270
272
|
}
|
|
271
273
|
}
|
|
272
274
|
function addExternalScriptNonce(def, nonce) {
|
|
273
|
-
if (!def.inline) {
|
|
275
|
+
if (nonce && (0, import_shared_utils.getFeatureFlags)().ENABLE_NONCE && !def.inline) {
|
|
274
276
|
def.nonce = nonce;
|
|
275
277
|
}
|
|
276
278
|
}
|
package/build/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InflightTasks, createStringBuilder, extractMetadataFromHtml, getCacheKeyFromJson, getSpecifier, isLocalDev, normalizeResourcePath, shortestTtl, } from '@lwrjs/shared-utils';
|
|
1
|
+
import { InflightTasks, createStringBuilder, extractMetadataFromHtml, getCacheKeyFromJson, getFeatureFlags, getSpecifier, isLocalDev, normalizeResourcePath, shortestTtl, } from '@lwrjs/shared-utils';
|
|
2
2
|
import { getTracer, ViewSpan } from '@lwrjs/instrumentation';
|
|
3
3
|
import { generateViewNonce, getViewNonce, normalizeRenderOptions, normalizeRenderedResult, reduceSourceAssetReferences, } from './utils.js';
|
|
4
4
|
import { linkLwrResources } from './linkers/link-lwr-resources.js';
|
|
@@ -150,6 +150,8 @@ export class LwrViewRegistry {
|
|
|
150
150
|
locale: runtimeParams?.locale,
|
|
151
151
|
basePath: runtimeParams?.basePath,
|
|
152
152
|
debug: runtimeEnvironment.debug,
|
|
153
|
+
// Add a variable on if the nonce is enabled
|
|
154
|
+
nonceEnabled: getFeatureFlags().ENABLE_NONCE,
|
|
153
155
|
});
|
|
154
156
|
logger.debug(`[view-registry][hasViewDefinition] viewDefId=${viewDefId}`);
|
|
155
157
|
// viewParams is an unbounded object and can be very large (17MB/view for developer.salesforce.com). Allowing consumers
|
|
@@ -177,6 +179,8 @@ export class LwrViewRegistry {
|
|
|
177
179
|
locale: runtimeParams?.locale,
|
|
178
180
|
basePath: runtimeParams?.basePath,
|
|
179
181
|
debug: runtimeEnvironment.debug,
|
|
182
|
+
// Add a variable on if the nonce is enabled
|
|
183
|
+
nonceEnabled: getFeatureFlags().ENABLE_NONCE,
|
|
180
184
|
});
|
|
181
185
|
logger.debug(`[view-registry][getViewDefinition] viewDefCacheKey=${viewDefCacheKey}`);
|
|
182
186
|
// viewParams is an unbounded object and can be very large (17MB/view for developer.salesforce.com). Allowing consumers
|
package/build/es/utils.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare function createJsonModule(specifier: string, moduleRegistry: Publ
|
|
|
13
13
|
/**
|
|
14
14
|
* Get the nonce set on the page context of the view params
|
|
15
15
|
*/
|
|
16
|
-
export declare function getViewNonce(viewParams: ViewParams): string;
|
|
16
|
+
export declare function getViewNonce(viewParams: ViewParams): string | undefined;
|
|
17
17
|
/**
|
|
18
18
|
* Generate a nonce in the page context of the view params
|
|
19
19
|
*/
|
|
@@ -21,5 +21,5 @@ export declare function generateViewNonce(viewParams: ViewParams): void;
|
|
|
21
21
|
/**
|
|
22
22
|
* Add a nonce to a script definition in view if it is external (not inline)
|
|
23
23
|
*/
|
|
24
|
-
export declare function addExternalScriptNonce(def: ResourceDefinition, nonce
|
|
24
|
+
export declare function addExternalScriptNonce(def: ResourceDefinition, nonce?: string): void;
|
|
25
25
|
//# sourceMappingURL=utils.d.ts.map
|
package/build/es/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { basename, extname } from 'path';
|
|
2
|
-
import { explodeSpecifier, getMappingUriPrefix, getSpecifier, getClientBootstrapConfigurationUri, mimeLookup, DEFAULT_TITLE, streamToString, } from '@lwrjs/shared-utils';
|
|
2
|
+
import { explodeSpecifier, getMappingUriPrefix, getSpecifier, getClientBootstrapConfigurationUri, mimeLookup, DEFAULT_TITLE, streamToString, getFeatureFlags, } from '@lwrjs/shared-utils';
|
|
3
3
|
import { AppResourceEnum, getAppSpecifier, ResourceIdentityTypes, } from '@lwrjs/app-service/identity';
|
|
4
4
|
import crypto from 'crypto';
|
|
5
5
|
function generateExternalStyle(src) {
|
|
@@ -13,7 +13,7 @@ function generateExternalScript(type = 'application/javascript', src, async, def
|
|
|
13
13
|
else if (async) {
|
|
14
14
|
scriptLoadOrder = ' async';
|
|
15
15
|
}
|
|
16
|
-
const nonceAttr = nonce ? ` nonce="${nonce}"` : '';
|
|
16
|
+
const nonceAttr = getFeatureFlags().ENABLE_NONCE && nonce ? ` nonce="${nonce}"` : '';
|
|
17
17
|
return `<script type="${type}"${scriptLoadOrder}${nonceAttr} src="${src}"></script>`;
|
|
18
18
|
}
|
|
19
19
|
function generateLinkPreloadTag({ href, type }) {
|
|
@@ -38,7 +38,7 @@ function generateExternalTag({ type, src = '', async, defer, isPreload, nonce })
|
|
|
38
38
|
async function generateInlineTag({ specifier, type, content, stream, nonce }) {
|
|
39
39
|
const typeStr = type === 'text/css' ? '' : ` type="${type}"`;
|
|
40
40
|
const tag = type === 'text/css' ? 'style' : 'script';
|
|
41
|
-
const nonceStr = nonce ? ` nonce="${nonce}"` : '';
|
|
41
|
+
const nonceStr = getFeatureFlags().ENABLE_NONCE && nonce && nonce ? ` nonce="${nonce}"` : '';
|
|
42
42
|
if (!content && !stream) {
|
|
43
43
|
throw new Error(`Invalid inline Resource Definition: must have either "content" or "stream": "${specifier}"`);
|
|
44
44
|
}
|
|
@@ -243,25 +243,29 @@ export async function createJsonModule(specifier, moduleRegistry, environment, p
|
|
|
243
243
|
* Get the nonce set on the page context of the view params
|
|
244
244
|
*/
|
|
245
245
|
export function getViewNonce(viewParams) {
|
|
246
|
-
return
|
|
246
|
+
return getFeatureFlags().ENABLE_NONCE
|
|
247
|
+
? viewParams?.page?.nonce
|
|
248
|
+
: undefined;
|
|
247
249
|
}
|
|
248
250
|
/**
|
|
249
251
|
* Generate a nonce in the page context of the view params
|
|
250
252
|
*/
|
|
251
253
|
export function generateViewNonce(viewParams) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
viewParams.page
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
254
|
+
if (getFeatureFlags().ENABLE_NONCE) {
|
|
255
|
+
const nonce = crypto.randomBytes(16).toString('base64');
|
|
256
|
+
if (!viewParams.page) {
|
|
257
|
+
viewParams.page = { nonce };
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
viewParams.page.nonce = nonce;
|
|
261
|
+
}
|
|
258
262
|
}
|
|
259
263
|
}
|
|
260
264
|
/**
|
|
261
265
|
* Add a nonce to a script definition in view if it is external (not inline)
|
|
262
266
|
*/
|
|
263
267
|
export function addExternalScriptNonce(def, nonce) {
|
|
264
|
-
if (!def.inline) {
|
|
268
|
+
if (nonce && getFeatureFlags().ENABLE_NONCE && !def.inline) {
|
|
265
269
|
def.nonce = nonce;
|
|
266
270
|
}
|
|
267
271
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.13.0-alpha.
|
|
7
|
+
"version": "0.13.0-alpha.12",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
"build/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@lwrjs/app-service": "0.13.0-alpha.
|
|
34
|
-
"@lwrjs/diagnostics": "0.13.0-alpha.
|
|
35
|
-
"@lwrjs/instrumentation": "0.13.0-alpha.
|
|
36
|
-
"@lwrjs/shared-utils": "0.13.0-alpha.
|
|
33
|
+
"@lwrjs/app-service": "0.13.0-alpha.12",
|
|
34
|
+
"@lwrjs/diagnostics": "0.13.0-alpha.12",
|
|
35
|
+
"@lwrjs/instrumentation": "0.13.0-alpha.12",
|
|
36
|
+
"@lwrjs/shared-utils": "0.13.0-alpha.12",
|
|
37
37
|
"lru-cache": "^10.2.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@lwrjs/types": "0.13.0-alpha.
|
|
40
|
+
"@lwrjs/types": "0.13.0-alpha.12"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=18.0.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "60e763c7829cfbcdf5ccd88bd5c2c1a31db4554d"
|
|
46
46
|
}
|