@lwrjs/view-registry 0.13.0-alpha.11 → 0.13.0-alpha.13

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.
@@ -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);
@@ -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
- const nonce = import_crypto.default.randomBytes(16).toString("base64");
266
- if (!viewParams.page) {
267
- viewParams.page = {nonce};
268
- } else {
269
- viewParams.page.nonce = nonce;
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
  }
@@ -130,6 +130,8 @@ var LwrViewHandler = class {
130
130
  const paths = {rootDir, assets, contentDir, layoutsDir};
131
131
  const locale = runtimeParams.locale;
132
132
  const basePath = runtimeParams.basePath;
133
+ const assetBasePath = runtimeParams.assetBasePath;
134
+ const uiBasePath = runtimeParams.assetBasePath;
133
135
  const viewApi = this.getBoundApi(viewRequest, route, runtimeEnvironment, runtimeParams);
134
136
  const response = await (0, import_instrumentation.getTracer)().trace({
135
137
  name: import_instrumentation.ViewSpan.ExecuteRouteHandler,
@@ -139,7 +141,7 @@ var LwrViewHandler = class {
139
141
  }
140
142
  }, async () => {
141
143
  try {
142
- return await routeHandlerFn({...viewRequest, locale, basePath}, {route, viewApi, ...paths}, routeHandlerOptions);
144
+ return await routeHandlerFn({...viewRequest, locale, basePath, assetBasePath, uiBasePath}, {route, viewApi, ...paths}, routeHandlerOptions);
143
145
  } catch (err) {
144
146
  if (err instanceof import_diagnostics.DiagnosticsError) {
145
147
  throw err;
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
@@ -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: string): void;
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 viewParams?.page?.nonce;
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
- const nonce = crypto.randomBytes(16).toString('base64');
253
- if (!viewParams.page) {
254
- viewParams.page = { nonce };
255
- }
256
- else {
257
- viewParams.page.nonce = nonce;
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
  }
@@ -146,6 +146,8 @@ export class LwrViewHandler {
146
146
  const paths = { rootDir, assets, contentDir, layoutsDir };
147
147
  const locale = runtimeParams.locale;
148
148
  const basePath = runtimeParams.basePath;
149
+ const assetBasePath = runtimeParams.assetBasePath;
150
+ const uiBasePath = runtimeParams.assetBasePath;
149
151
  const viewApi = this.getBoundApi(viewRequest, route, runtimeEnvironment, runtimeParams);
150
152
  const response = await getTracer().trace({
151
153
  name: ViewSpan.ExecuteRouteHandler,
@@ -155,7 +157,7 @@ export class LwrViewHandler {
155
157
  },
156
158
  }, async () => {
157
159
  try {
158
- return await routeHandlerFn({ ...viewRequest, locale, basePath }, { route: route, viewApi, ...paths }, routeHandlerOptions);
160
+ return await routeHandlerFn({ ...viewRequest, locale, basePath, assetBasePath, uiBasePath }, { route: route, viewApi, ...paths }, routeHandlerOptions);
159
161
  }
160
162
  catch (err) {
161
163
  if (err instanceof DiagnosticsError) {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.13.0-alpha.11",
7
+ "version": "0.13.0-alpha.13",
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.11",
34
- "@lwrjs/diagnostics": "0.13.0-alpha.11",
35
- "@lwrjs/instrumentation": "0.13.0-alpha.11",
36
- "@lwrjs/shared-utils": "0.13.0-alpha.11",
33
+ "@lwrjs/app-service": "0.13.0-alpha.13",
34
+ "@lwrjs/diagnostics": "0.13.0-alpha.13",
35
+ "@lwrjs/instrumentation": "0.13.0-alpha.13",
36
+ "@lwrjs/shared-utils": "0.13.0-alpha.13",
37
37
  "lru-cache": "^10.2.2"
38
38
  },
39
39
  "devDependencies": {
40
- "@lwrjs/types": "0.13.0-alpha.11"
40
+ "@lwrjs/types": "0.13.0-alpha.13"
41
41
  },
42
42
  "engines": {
43
43
  "node": ">=18.0.0"
44
44
  },
45
- "gitHead": "59bd49a87178069c588b68eace0b092c00dd8bb6"
45
+ "gitHead": "7ef5235dbf1a8c5895fb8acdb212c50f715f0a03"
46
46
  }