@hubspot/cms-dev-server 0.14.2 → 0.14.4

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/dist/index.js CHANGED
@@ -3,7 +3,9 @@ import { createServer as createViteServer } from "vite";
3
3
  import { default as react } from "@vitejs/plugin-react";
4
4
 
5
5
  // ../cms-js-internal/dist/index.js
6
+ import * as dotProp from "dot-prop";
6
7
  import path from "path";
8
+ var { setProperty, getProperty, hasProperty } = dotProp;
7
9
  var viteRoot;
8
10
  var viteCommand;
9
11
  function resolveIslandPlugin(islandsSet) {
@@ -42,6 +44,28 @@ function resolveIslandPlugin(islandsSet) {
42
44
  }
43
45
  };
44
46
  }
47
+ function noncePlaceholderPlugin() {
48
+ const HS_DEPLOYED = process.env.AWS_EXECUTION_ENV != null || process.env.HS_DEPLOYED === "true";
49
+ return {
50
+ name: "hs-nonce-placeholder",
51
+ enforce: "post",
52
+ apply() {
53
+ return HS_DEPLOYED;
54
+ },
55
+ transformIndexHtml(html) {
56
+ const regex = /<(style|script|link) (.*)>/gi;
57
+ const replacer = (_, p1, p2) => {
58
+ if (p1 === "style" || p1 === "script" || // if link, only nonce for stylesheet
59
+ p1 === "link" && p2.includes('rel="stylesheet"')) {
60
+ const noncePlaceholderValue = p1 === "script" ? "hs-random-nonce" : "hs-random-style-nonce";
61
+ p2 = `nonce="${noncePlaceholderValue}" ${p2}`;
62
+ }
63
+ return `<${p1} ${p2}>`;
64
+ };
65
+ return html.replace(regex, replacer);
66
+ }
67
+ };
68
+ }
45
69
  var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || (id => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\n } = renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\n }\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n {innerComponent}\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
46
70
  var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
47
71
  function clientIslandEntryPlugin() {
@@ -152,7 +176,8 @@ Custom origin: ${process.env.VITE_ORIGIN}
152
176
  clientIslandEntryPlugin(),
153
177
  resolveIslandPlugin(),
154
178
  jsRenderingGates.includes("CMS:JSRenderer:RemoveCjsPlugin") ? null : viteCommonjs(),
155
- devSecretsPlugin(secretNames)
179
+ devSecretsPlugin(secretNames),
180
+ noncePlaceholderPlugin()
156
181
  ],
157
182
  css: {
158
183
  postcss: webRoot
@@ -1,4 +1,5 @@
1
1
  // ../cms-js-internal/dist/index.js
2
+ import * as dotProp from "dot-prop";
2
3
  import path from "path";
3
4
  import * as jsxRuntime from "react/jsx-runtime";
4
5
  import stream from "stream";
@@ -96,7 +97,8 @@ function jsonStringifyAndEscapeForInlineJS(input, { baseIndent = 0, jsonIndent =
96
97
  ${indentString}`
97
98
  );
98
99
  }
99
- var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, prettyPrint) => {
100
+ var { setProperty, getProperty, hasProperty } = dotProp;
101
+ var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
100
102
  const islandsArrayToSerialize = tweakedIslandsArray.map(
101
103
  ({
102
104
  id,
@@ -108,6 +110,7 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, p
108
110
  priority,
109
111
  url,
110
112
  sharedStateID,
113
+ supplementalFieldValues,
111
114
  wrapperModuleId,
112
115
  wrapperUrl
113
116
  }) => {
@@ -130,6 +133,13 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, p
130
133
  if (wrapperUrl) {
131
134
  output.wrapperUrl = wrapperUrl;
132
135
  }
136
+ const filteredSupplementalFieldValues = filterOutUnreadSupplementalFieldValues(
137
+ supplementalFieldValues,
138
+ perServerRequestData.get("supplementalFieldValuesRead")
139
+ );
140
+ if (filteredSupplementalFieldValues) {
141
+ output.supplementalFieldValues = filteredSupplementalFieldValues;
142
+ }
133
143
  return output;
134
144
  }
135
145
  );
@@ -139,6 +149,25 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, p
139
149
  prettyPrint
140
150
  });
141
151
  };
152
+ function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplementalFieldValuesRead) {
153
+ if (!supplementalFieldValues) {
154
+ return supplementalFieldValues;
155
+ }
156
+ if (!supplementalFieldValuesRead) {
157
+ return supplementalFieldValues;
158
+ }
159
+ const result = {};
160
+ Array.from(supplementalFieldValuesRead).forEach((fieldPath) => {
161
+ if (hasProperty(supplementalFieldValues, fieldPath)) {
162
+ setProperty(
163
+ result,
164
+ fieldPath,
165
+ getProperty(supplementalFieldValues, fieldPath)
166
+ );
167
+ }
168
+ });
169
+ return result;
170
+ }
142
171
  var writeSharedStateToJsGlobal = (islands, perServerRequestData, indent = 0, prettyPrint) => {
143
172
  const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x) => !!x);
144
173
  if (sharedStateIDs.length > 0) {
@@ -216,6 +245,7 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
216
245
  indent
217
246
  )}window.__islands = ${serializeIslandDataForInlineScript(
218
247
  islands,
248
+ perServerRequestData,
219
249
  indent,
220
250
  prettyPrint
221
251
  )}${writeSharedStateToJsGlobal(
@@ -263,6 +293,28 @@ function resolveIslandPlugin(islandsSet) {
263
293
  }
264
294
  };
265
295
  }
296
+ function noncePlaceholderPlugin() {
297
+ const HS_DEPLOYED = process.env.AWS_EXECUTION_ENV != null || process.env.HS_DEPLOYED === "true";
298
+ return {
299
+ name: "hs-nonce-placeholder",
300
+ enforce: "post",
301
+ apply() {
302
+ return HS_DEPLOYED;
303
+ },
304
+ transformIndexHtml(html) {
305
+ const regex = /<(style|script|link) (.*)>/gi;
306
+ const replacer = (_, p1, p2) => {
307
+ if (p1 === "style" || p1 === "script" || // if link, only nonce for stylesheet
308
+ p1 === "link" && p2.includes('rel="stylesheet"')) {
309
+ const noncePlaceholderValue = p1 === "script" ? "hs-random-nonce" : "hs-random-style-nonce";
310
+ p2 = `nonce="${noncePlaceholderValue}" ${p2}`;
311
+ }
312
+ return `<${p1} ${p2}>`;
313
+ };
314
+ return html.replace(regex, replacer);
315
+ }
316
+ };
317
+ }
266
318
  var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || (id => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\n } = renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\n }\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n {innerComponent}\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
267
319
  var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
268
320
  function clientIslandEntryPlugin() {
@@ -362,21 +414,24 @@ ${consoleLines.join("\n")}
362
414
  ${groupEnd}</script>
363
415
  `;
364
416
  };
365
- async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, entryPointBasePath, renderOptions) {
417
+ async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, entryPointBasePath, contextOptions, renderOptions) {
366
418
  const componentDebugName = Component.displayName || Component.name;
367
419
  return renderOnServer(
368
420
  /* @__PURE__ */ jsx2(Component, { ...props }),
369
421
  pageUrl,
370
422
  environmentConfig,
371
423
  entryPointBasePath,
424
+ contextOptions,
372
425
  componentDebugName,
373
426
  renderOptions
374
427
  );
375
428
  }
376
- async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, debugName, renderOptions) {
429
+ async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, contextOptions, debugName, renderOptions) {
430
+ const supplementalFieldValues = contextOptions ? contextOptions.supplementalFieldValues : void 0;
377
431
  const renderContext = cmsComponents.createServerRenderContextV2 ? cmsComponents.createServerRenderContextV2(pageUrl, {
378
432
  environmentConfig,
379
- entryPointBasePath
433
+ entryPointBasePath,
434
+ supplementalFieldValues
380
435
  }) : cmsComponents.createServerRenderContext(pageUrl, environmentConfig);
381
436
  let html = await renderStreamToPromise(
382
437
  /* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
@@ -516,7 +571,7 @@ function findAllPartialsInRoot(webRoot) {
516
571
  const partialSubpaths = Object.keys(allPartialComponents);
517
572
  return { partialNames, partialSubpaths };
518
573
  }
519
- function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors) {
574
+ function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
520
575
  if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
521
576
  prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
522
577
  }
@@ -551,8 +606,9 @@ function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath
551
606
  })
552
607
  `);
553
608
  }
609
+ const nonceAttr = includeNonces && cmsComponents.STYLE_NONCE_PLACEHOLDER ? ` nonce="${cmsComponents.STYLE_NONCE_PLACEHOLDER}"` : "";
554
610
  return `
555
- <script type="text/javascript">
611
+ <script type="text/javascript"${nonceAttr}>
556
612
  ${globals.join("\n ")}
557
613
  </script>
558
614
  `;
@@ -564,7 +620,8 @@ function namespaceModulePropsShape(props) {
564
620
  fieldValues: passedFieldValues,
565
621
  hublData,
566
622
  experimentalHublData,
567
- moduleName
623
+ moduleName,
624
+ supplementalFieldValues
568
625
  } = props;
569
626
  const oldPropsShape = { ...props };
570
627
  if (oldPropsShape.dataQueryResult) {
@@ -581,7 +638,8 @@ function namespaceModulePropsShape(props) {
581
638
  hublParameters,
582
639
  hublData,
583
640
  experimentalHublData,
584
- moduleName
641
+ moduleName,
642
+ supplementalFieldValues
585
643
  };
586
644
  }
587
645
  function setIn(object, nestedKeysArray, value) {
@@ -671,6 +729,7 @@ export {
671
729
  isUngatedFor,
672
730
  jsonStringifyAndEscapeForInlineJS,
673
731
  namespaceModulePropsShape,
732
+ noncePlaceholderPlugin,
674
733
  removeComponentExtension,
675
734
  renderComponentOnServer,
676
735
  renderFieldsToJson,
package/dist/run.js CHANGED
@@ -77,13 +77,13 @@ function getDevServerCommandLineOptions(argv) {
77
77
  }
78
78
 
79
79
  // src/createDevServer.ts
80
- import path7 from "path";
80
+ import path9 from "path";
81
81
  import url2 from "url";
82
82
  import express2 from "express";
83
83
  import http3 from "http";
84
84
  import bodyParser from "body-parser";
85
85
  import { spawn } from "child_process";
86
- import { normalizePath as normalizePath5 } from "vite";
86
+ import { normalizePath as normalizePath6 } from "vite";
87
87
  import { Transform } from "stream";
88
88
 
89
89
  // src/routes/createDevServerRoutes.ts
@@ -127,6 +127,7 @@ function packagePath(metaUrl, projectPath) {
127
127
  }
128
128
 
129
129
  // ../cms-js-internal/dist/index.js
130
+ import * as dotProp from "dot-prop";
130
131
  import path2 from "path";
131
132
  import * as jsxRuntime from "react/jsx-runtime";
132
133
  import stream from "stream";
@@ -162,7 +163,8 @@ function jsonStringifyAndEscapeForInlineJS(input, { baseIndent = 0, jsonIndent =
162
163
  ${indentString}`
163
164
  );
164
165
  }
165
- var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, prettyPrint) => {
166
+ var { setProperty, getProperty, hasProperty } = dotProp;
167
+ var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
166
168
  const islandsArrayToSerialize = tweakedIslandsArray.map(
167
169
  ({
168
170
  id,
@@ -174,6 +176,7 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, p
174
176
  priority,
175
177
  url: url3,
176
178
  sharedStateID,
179
+ supplementalFieldValues,
177
180
  wrapperModuleId,
178
181
  wrapperUrl
179
182
  }) => {
@@ -196,6 +199,13 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, p
196
199
  if (wrapperUrl) {
197
200
  output.wrapperUrl = wrapperUrl;
198
201
  }
202
+ const filteredSupplementalFieldValues = filterOutUnreadSupplementalFieldValues(
203
+ supplementalFieldValues,
204
+ perServerRequestData.get("supplementalFieldValuesRead")
205
+ );
206
+ if (filteredSupplementalFieldValues) {
207
+ output.supplementalFieldValues = filteredSupplementalFieldValues;
208
+ }
199
209
  return output;
200
210
  }
201
211
  );
@@ -205,6 +215,25 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, p
205
215
  prettyPrint
206
216
  });
207
217
  };
218
+ function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplementalFieldValuesRead) {
219
+ if (!supplementalFieldValues) {
220
+ return supplementalFieldValues;
221
+ }
222
+ if (!supplementalFieldValuesRead) {
223
+ return supplementalFieldValues;
224
+ }
225
+ const result = {};
226
+ Array.from(supplementalFieldValuesRead).forEach((fieldPath) => {
227
+ if (hasProperty(supplementalFieldValues, fieldPath)) {
228
+ setProperty(
229
+ result,
230
+ fieldPath,
231
+ getProperty(supplementalFieldValues, fieldPath)
232
+ );
233
+ }
234
+ });
235
+ return result;
236
+ }
208
237
  var writeSharedStateToJsGlobal = (islands, perServerRequestData, indent = 0, prettyPrint) => {
209
238
  const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x) => !!x);
210
239
  if (sharedStateIDs.length > 0) {
@@ -282,6 +311,7 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
282
311
  indent
283
312
  )}window.__islands = ${serializeIslandDataForInlineScript(
284
313
  islands,
314
+ perServerRequestData,
285
315
  indent,
286
316
  prettyPrint
287
317
  )}${writeSharedStateToJsGlobal(
@@ -329,6 +359,28 @@ function resolveIslandPlugin(islandsSet) {
329
359
  }
330
360
  };
331
361
  }
362
+ function noncePlaceholderPlugin() {
363
+ const HS_DEPLOYED = process.env.AWS_EXECUTION_ENV != null || process.env.HS_DEPLOYED === "true";
364
+ return {
365
+ name: "hs-nonce-placeholder",
366
+ enforce: "post",
367
+ apply() {
368
+ return HS_DEPLOYED;
369
+ },
370
+ transformIndexHtml(html) {
371
+ const regex = /<(style|script|link) (.*)>/gi;
372
+ const replacer = (_, p1, p2) => {
373
+ if (p1 === "style" || p1 === "script" || // if link, only nonce for stylesheet
374
+ p1 === "link" && p2.includes('rel="stylesheet"')) {
375
+ const noncePlaceholderValue = p1 === "script" ? "hs-random-nonce" : "hs-random-style-nonce";
376
+ p2 = `nonce="${noncePlaceholderValue}" ${p2}`;
377
+ }
378
+ return `<${p1} ${p2}>`;
379
+ };
380
+ return html.replace(regex, replacer);
381
+ }
382
+ };
383
+ }
332
384
  var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || (id => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\n } = renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\n }\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n {innerComponent}\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
333
385
  var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
334
386
  function clientIslandEntryPlugin() {
@@ -428,10 +480,12 @@ ${consoleLines.join("\n")}
428
480
  ${groupEnd}</script>
429
481
  `;
430
482
  };
431
- async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, debugName, renderOptions) {
483
+ async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, contextOptions, debugName, renderOptions) {
484
+ const supplementalFieldValues = contextOptions ? contextOptions.supplementalFieldValues : void 0;
432
485
  const renderContext = cmsComponents.createServerRenderContextV2 ? cmsComponents.createServerRenderContextV2(pageUrl, {
433
486
  environmentConfig,
434
- entryPointBasePath
487
+ entryPointBasePath,
488
+ supplementalFieldValues
435
489
  }) : cmsComponents.createServerRenderContext(pageUrl, environmentConfig);
436
490
  let html = await renderStreamToPromise(
437
491
  /* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
@@ -536,7 +590,7 @@ function findAllPartialsInRoot(webRoot2) {
536
590
  const partialSubpaths = Object.keys(allPartialComponents);
537
591
  return { partialNames, partialSubpaths };
538
592
  }
539
- function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors) {
593
+ function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
540
594
  if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
541
595
  prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
542
596
  }
@@ -571,8 +625,9 @@ function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath
571
625
  })
572
626
  `);
573
627
  }
628
+ const nonceAttr = includeNonces && cmsComponents.STYLE_NONCE_PLACEHOLDER ? ` nonce="${cmsComponents.STYLE_NONCE_PLACEHOLDER}"` : "";
574
629
  return `
575
- <script type="text/javascript">
630
+ <script type="text/javascript"${nonceAttr}>
576
631
  ${globals.join("\n ")}
577
632
  </script>
578
633
  `;
@@ -584,7 +639,8 @@ function namespaceModulePropsShape(props) {
584
639
  fieldValues: passedFieldValues,
585
640
  hublData,
586
641
  experimentalHublData,
587
- moduleName
642
+ moduleName,
643
+ supplementalFieldValues
588
644
  } = props;
589
645
  const oldPropsShape = { ...props };
590
646
  if (oldPropsShape.dataQueryResult) {
@@ -601,7 +657,8 @@ function namespaceModulePropsShape(props) {
601
657
  hublParameters,
602
658
  hublData,
603
659
  experimentalHublData,
604
- moduleName
660
+ moduleName,
661
+ supplementalFieldValues
605
662
  };
606
663
  }
607
664
  function setIn(object, nestedKeysArray, value) {
@@ -966,7 +1023,7 @@ function trackUsage(action) {
966
1023
  eventName: EVENT_NAME,
967
1024
  action,
968
1025
  nodeVersion: getNodeVersionData(),
969
- version: "0.14.2",
1026
+ version: "0.14.4",
970
1027
  os: getPlatform()
971
1028
  };
972
1029
  const uri = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -1590,12 +1647,12 @@ var findLocalRenderPlaceholders = (body) => {
1590
1647
  );
1591
1648
  offsetSoFar = nearestNewlineOrQuoteAfterBlockOpen;
1592
1649
  if (pathEndOffset >= 0 && pathEndOffset < nextNewlineOffset) {
1593
- const path8 = body.substring(
1650
+ const path10 = body.substring(
1594
1651
  startOffset + localJsRenderStartString.length,
1595
1652
  pathEndOffset
1596
1653
  );
1597
1654
  offsetSoFar = pathEndOffset + 1;
1598
- if (startOffset >= 0 && path8) {
1655
+ if (startOffset >= 0 && path10) {
1599
1656
  const nextCommentEndOffset = body.indexOf("-->", pathEndOffset);
1600
1657
  const endOffset = body.indexOf(localJsRenderEndString, pathEndOffset);
1601
1658
  offsetSoFar = Math.min(nextCommentEndOffset, endOffset);
@@ -1615,7 +1672,7 @@ var findLocalRenderPlaceholders = (body) => {
1615
1672
  result.push({
1616
1673
  startOffset,
1617
1674
  endOffset: endOffset + localJsRenderEndString.length,
1618
- path: path8,
1675
+ path: path10,
1619
1676
  json
1620
1677
  });
1621
1678
  }
@@ -1724,9 +1781,9 @@ var customColors = [
1724
1781
  ];
1725
1782
  var Converter = new AnsiToHtmlConverter({ colors: customColors });
1726
1783
  var darkErrorStyles = `background-color: #222; color: #ccc; padding: 0.5em; font-family: ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', 'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace;`;
1727
- var renderLocalError_default = (path8, error) => {
1784
+ var renderLocalError_default = (path10, error) => {
1728
1785
  const stackWithColorClasses = Converter.toHtml(error.stack);
1729
- return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${path8}<br/><br/><code><pre>${stackWithColorClasses}</pre></code></div>`;
1786
+ return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${path10}<br/><br/><code><pre>${stackWithColorClasses}</pre></code></div>`;
1730
1787
  };
1731
1788
 
1732
1789
  // src/proxyPage/fetchPreviewInfo.ts
@@ -2334,7 +2391,7 @@ async function proxyPathPageRouteHandler(request2, response, next) {
2334
2391
  }
2335
2392
 
2336
2393
  // src/routes/proxyPathPageResourceRedirect.ts
2337
- import fetch from "node-fetch";
2394
+ import fetch2 from "node-fetch";
2338
2395
  var HCMS_PATH2 = "/_hcms/";
2339
2396
  var HS_FS_PATH2 = "/hs-fs/";
2340
2397
  var HUB_FS_PATH2 = "/hubfs/";
@@ -2364,9 +2421,132 @@ function proxyPathPageResourceRedirect(req, res, next) {
2364
2421
  return;
2365
2422
  }
2366
2423
  const urlToProxy = `https://${proxyPageUrl.host}${req.url}`;
2367
- fetch(urlToProxy).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
2424
+ fetch2(urlToProxy).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
2368
2425
  }
2369
2426
 
2427
+ // src/routes/modulePreviewRouteHandler.ts
2428
+ import { buildStaticEnvConfig as buildStaticEnvConfig4 } from "@hubspot/cms-components";
2429
+ import path6 from "path";
2430
+ import { normalizePath as normalizePath5 } from "vite";
2431
+ import { getAccountId as getAccountId3 } from "@hubspot/cli-lib/lib/config.js";
2432
+ import { get as hsGet4 } from "@hubspot/cli-lib/http.js";
2433
+ async function modulePreviewRouteHandler(request2, response) {
2434
+ sendTrackingRequest("view-module-preview-route");
2435
+ const {
2436
+ authedPortalId,
2437
+ authedEnv,
2438
+ authedHublet,
2439
+ webRoot: webRoot2,
2440
+ viteServer,
2441
+ jsRenderingGates,
2442
+ projectName,
2443
+ projectComponentPath
2444
+ } = request2.app.locals;
2445
+ const moduleName = request2.params.moduleName;
2446
+ const modulePath = normalizePath5(
2447
+ path6.resolve(webRoot2, "components/modules/", moduleName)
2448
+ );
2449
+ const basePath = getEntryPointBasePath(modulePath);
2450
+ const environmentConfig = buildStaticEnvConfig4(
2451
+ authedPortalId,
2452
+ authedHublet,
2453
+ authedEnv,
2454
+ false,
2455
+ jsRenderingGates
2456
+ );
2457
+ const baseUrl = `https://api.hubspot${authedEnv === "qa" ? "qa" : ""}${authedHublet === "eu1" ? "-eu1" : ""}.com/api`;
2458
+ const accountId = await getAccountId3(authedPortalId);
2459
+ let templatePreview;
2460
+ try {
2461
+ const moduleFetchResult = await hsGet4(accountId, {
2462
+ baseUrl,
2463
+ uri: `/designmanager/v1/modules/by-path/@projects/${projectName}/${projectComponentPath}/components/modules/${moduleName}`,
2464
+ query: {
2465
+ portalId: authedPortalId
2466
+ },
2467
+ json: true,
2468
+ useQuerystring: true
2469
+ });
2470
+ const queryParams = new URLSearchParams({
2471
+ portalId: `${authedPortalId}`,
2472
+ module_id: `${moduleFetchResult.moduleId}`,
2473
+ hsLocalProxy: `${true}`,
2474
+ hs_preview_key: `${moduleFetchResult.previewKey}`,
2475
+ localProxySchemaVersion: "1"
2476
+ });
2477
+ const templatePreviewResponse = await fetch(
2478
+ `${baseUrl}/cos-rendering/v1/public/_hcms/preview/template/multiform?${queryParams}`,
2479
+ {
2480
+ method: "POST",
2481
+ headers: {
2482
+ ["content-type"]: "application/x-www-form-urlencoded",
2483
+ ["Accept"]: "text/html",
2484
+ referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com`
2485
+ }
2486
+ }
2487
+ );
2488
+ templatePreview = await templatePreviewResponse.text();
2489
+ } catch (e) {
2490
+ return response.status(500).end(
2491
+ `Error previewing module (${moduleName}). Ensure this module has been included in a successful project build.
2492
+
2493
+ `
2494
+ );
2495
+ }
2496
+ try {
2497
+ const localRenderPlaceholders = findLocalRenderPlaceholders(templatePreview);
2498
+ if (localRenderPlaceholders.length !== 1) {
2499
+ return response.status(500).end(
2500
+ `Error previewing module (${moduleName}), exception in module preview HTML
2501
+
2502
+ `
2503
+ );
2504
+ }
2505
+ const {
2506
+ html: renderedHtml,
2507
+ cssNeeded,
2508
+ renderContext,
2509
+ inlineAssets
2510
+ } = await renderComponentForPlaceholder(
2511
+ 0,
2512
+ localRenderPlaceholders[0],
2513
+ webRoot2,
2514
+ viteServer,
2515
+ fullOriginalUrlFromRequest(request2),
2516
+ basePath,
2517
+ environmentConfig,
2518
+ projectName,
2519
+ projectComponentPath
2520
+ );
2521
+ const baseTemplatePath = packagePath(
2522
+ import.meta.url,
2523
+ "html/baseTemplate.html"
2524
+ );
2525
+ const htmlShell = await createHtmlShellDependingOnRenderContext(
2526
+ baseTemplatePath,
2527
+ request2.originalUrl,
2528
+ `Module: ${modulePath}`,
2529
+ renderContext,
2530
+ viteServer,
2531
+ jsRenderingGates
2532
+ );
2533
+ const html = htmlShell.replace(
2534
+ "<!--headend-->",
2535
+ [cssNeeded, ...inlineAssets.map((inlineAsset) => inlineAsset.html)].join(
2536
+ "\n"
2537
+ )
2538
+ ).replace(`<!--ssr-outlet-->`, renderedHtml);
2539
+ response.status(200).set({ "Content-Type": "text/html" }).end(html);
2540
+ } catch (e) {
2541
+ console.error(e);
2542
+ viteServer.ssrFixStacktrace(e);
2543
+ return response.status(500).end(`Error rendering module (${moduleName})
2544
+
2545
+ ${e.stack}`);
2546
+ }
2547
+ }
2548
+ var modulePreviewRouteHandler_default = modulePreviewRouteHandler;
2549
+
2370
2550
  // src/routes/createDevServerRoutes.ts
2371
2551
  var STORYBOOK_DOMAINS = VALID_PROXY_DOMAIN_SUFFIXES.map(
2372
2552
  (domain) => `storybook.${domain}`
@@ -2394,6 +2574,7 @@ var createDevServerRoutes = async (viteServer, storybookPort) => {
2394
2574
  devServerApp.get("/partials/", linksToAllPartialsRouteHandler_default);
2395
2575
  devServerApp.get("/partial/:partial", partial_default);
2396
2576
  devServerApp.get("/partial/:partial/*", partial_default);
2577
+ devServerApp.get("/preview/module/:moduleName", modulePreviewRouteHandler_default);
2397
2578
  devServerApp.get("/modules/", linksToAllModulesRouteHandler_default);
2398
2579
  devServerApp.get("/module/:moduleName", module_default);
2399
2580
  devServerApp.get("/module/:moduleName/*", module_default);
@@ -2416,9 +2597,9 @@ import express from "express";
2416
2597
 
2417
2598
  // src/shadowDevServer/createShadowDevServerRoutes.ts
2418
2599
  import { Router as Router2 } from "express";
2419
- import { getAccountId as getAccountId3, getEnv as getEnv2 } from "@hubspot/cli-lib/lib/config.js";
2600
+ import { getAccountId as getAccountId4, getEnv as getEnv2 } from "@hubspot/cli-lib/lib/config.js";
2420
2601
  import cors from "cors";
2421
- import { buildStaticEnvConfig as buildStaticEnvConfig4 } from "@hubspot/cms-components";
2602
+ import { buildStaticEnvConfig as buildStaticEnvConfig5 } from "@hubspot/cms-components";
2422
2603
  function getShadowDevServerCheckHandler(devServerPort, projectName, gates) {
2423
2604
  return async function shadowDevServerCheckHandler(request2, response) {
2424
2605
  const { query } = request2;
@@ -2437,7 +2618,7 @@ function getShadowDevServerCheckHandler(devServerPort, projectName, gates) {
2437
2618
  let hasJSBuildingBlocks = false;
2438
2619
  let localProxyUrl;
2439
2620
  try {
2440
- accountId = getAccountId3(portalId);
2621
+ accountId = getAccountId4(portalId);
2441
2622
  if (accountId === null) {
2442
2623
  throw new Error();
2443
2624
  }
@@ -2455,7 +2636,7 @@ function getShadowDevServerCheckHandler(devServerPort, projectName, gates) {
2455
2636
  contentId
2456
2637
  );
2457
2638
  const { previewKey } = previewInfo;
2458
- const environmentConfig = buildStaticEnvConfig4(
2639
+ const environmentConfig = buildStaticEnvConfig5(
2459
2640
  portalId,
2460
2641
  "na1",
2461
2642
  // bad lazy TF (but does it really matter for this check)
@@ -2619,7 +2800,8 @@ Custom origin: ${process.env.VITE_ORIGIN}
2619
2800
  clientIslandEntryPlugin(),
2620
2801
  resolveIslandPlugin(),
2621
2802
  jsRenderingGates.includes("CMS:JSRenderer:RemoveCjsPlugin") ? null : viteCommonjs(),
2622
- devSecretsPlugin(secretNames)
2803
+ devSecretsPlugin(secretNames),
2804
+ noncePlaceholderPlugin()
2623
2805
  ],
2624
2806
  css: {
2625
2807
  postcss: webRoot2
@@ -2703,7 +2885,7 @@ async function getJsRenderingGates(portalId, env, personalAccessKey) {
2703
2885
  // src/createDevServer.ts
2704
2886
  import {
2705
2887
  getEnv as getEnv3,
2706
- getAccountId as getAccountId4,
2888
+ getAccountId as getAccountId5,
2707
2889
  getAccountConfig as getAccountConfig2,
2708
2890
  loadConfig,
2709
2891
  validateConfig
@@ -2711,7 +2893,7 @@ import {
2711
2893
  import { fetchSecrets } from "@hubspot/cli-lib/api/secrets.js";
2712
2894
 
2713
2895
  // src/proxyPage/fetchDomains.ts
2714
- import { get as hsGet4 } from "@hubspot/cli-lib/http.js";
2896
+ import { get as hsGet5 } from "@hubspot/cli-lib/http.js";
2715
2897
 
2716
2898
  // src/lib/errors.ts
2717
2899
  var MISSING_SCOPE_ERROR_PREFIX = `Your personal access key is missing required scopes fetch domains.
@@ -2740,7 +2922,7 @@ function isMissingScopeError(error) {
2740
2922
  // src/proxyPage/fetchDomains.ts
2741
2923
  async function fetchDomains(portalId) {
2742
2924
  try {
2743
- const result = await hsGet4(portalId, {
2925
+ const result = await hsGet5(portalId, {
2744
2926
  uri: `/cms/v3/domains`,
2745
2927
  query: { portalId },
2746
2928
  json: true
@@ -2764,12 +2946,90 @@ async function fetchWebsiteDomainNames(portalId) {
2764
2946
 
2765
2947
  // src/lib/getCMSAssetConfig.ts
2766
2948
  import fs2 from "fs";
2767
- import path6 from "path";
2949
+ import path7 from "path";
2768
2950
  function getCMSAssetConfig(webRoot2) {
2769
- const cmsAssetsPath = path6.join(webRoot2, "cms-assets.json");
2951
+ const cmsAssetsPath = path7.join(webRoot2, "cms-assets.json");
2770
2952
  return JSON.parse(fs2.readFileSync(cmsAssetsPath).toString());
2771
2953
  }
2772
2954
 
2955
+ // src/lib/validateHSPlatform.ts
2956
+ import path8 from "path";
2957
+ import fs3 from "fs";
2958
+ import select from "@inquirer/select";
2959
+ import { get as hsGet6 } from "@hubspot/cli-lib/http.js";
2960
+ var HSPROJECT_JSON = "hsproject.json";
2961
+ function checkFileExists(filePath) {
2962
+ return fs3.existsSync(filePath) && fs3.statSync(filePath).isFile();
2963
+ }
2964
+ function findHSProjectJson(startPath) {
2965
+ let currentDir = startPath;
2966
+ let dirLevel = 0;
2967
+ const maxDirLevel = 4;
2968
+ while (path8.dirname(currentDir) !== currentDir && dirLevel < maxDirLevel) {
2969
+ const filePath = path8.join(currentDir, HSPROJECT_JSON);
2970
+ if (checkFileExists(filePath)) {
2971
+ return filePath;
2972
+ }
2973
+ currentDir = path8.dirname(currentDir);
2974
+ dirLevel++;
2975
+ }
2976
+ console.log(
2977
+ `'${HSPROJECT_JSON}' not found in any parent of dev server target`
2978
+ );
2979
+ return null;
2980
+ }
2981
+ async function validateHSPlatform(webroot, portalId) {
2982
+ const foundHSProjectJsonPath = findHSProjectJson(webroot);
2983
+ if (foundHSProjectJsonPath === null) {
2984
+ console.log(
2985
+ `Unable to find local ${HSPROJECT_JSON}, skipping platform version validation.`
2986
+ );
2987
+ return false;
2988
+ }
2989
+ const hsProjectJSONContents = fs3.readFileSync(foundHSProjectJsonPath, "utf8");
2990
+ const hsProjectJSONData = JSON.parse(hsProjectJSONContents);
2991
+ const { platformVersion } = hsProjectJSONData;
2992
+ let platformVersionResult;
2993
+ try {
2994
+ platformVersionResult = await hsGet6(portalId, {
2995
+ uri: `developer/projects/v1/platformVersion`,
2996
+ json: true
2997
+ });
2998
+ } catch (e) {
2999
+ console.error(e.message);
3000
+ console.log(
3001
+ "Unable to find active platform versions, skipping platform version validation."
3002
+ );
3003
+ return false;
3004
+ }
3005
+ if (platformVersion === void 0 || !platformVersionResult.activePlatformVersions.includes(platformVersion)) {
3006
+ const answer = await select({
3007
+ message: 'Your local "hsproject.json" does not have a valid platform version, please select a valid platform version. You can read more about Platform Versioning here https://developers.hubspot.com/docs/platform/platform-versioning',
3008
+ choices: platformVersionResult.activePlatformVersions.map(
3009
+ (versionNumber) => ({
3010
+ name: versionNumber,
3011
+ value: versionNumber
3012
+ })
3013
+ )
3014
+ });
3015
+ hsProjectJSONData.platformVersion = answer;
3016
+ try {
3017
+ fs3.writeFileSync(
3018
+ foundHSProjectJsonPath,
3019
+ JSON.stringify(hsProjectJSONData, void 0, 2),
3020
+ "utf8"
3021
+ );
3022
+ return true;
3023
+ } catch (e) {
3024
+ console.error(
3025
+ `unable to write updated valid platform version, please make sure platformVersion in "${HSPROJECT_JSON}" is one of ${platformVersionResult.activePlatformVersions}`
3026
+ );
3027
+ return false;
3028
+ }
3029
+ }
3030
+ return true;
3031
+ }
3032
+
2773
3033
  // src/createDevServer.ts
2774
3034
  var BASE_PATH = "/";
2775
3035
  var PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3e3;
@@ -2805,7 +3065,7 @@ async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2
2805
3065
  process.exit(1);
2806
3066
  }
2807
3067
  if (validateConfig()) {
2808
- authedPortalId = getAccountId4(hubspotCliAccountNameOption2);
3068
+ authedPortalId = getAccountId5(hubspotCliAccountNameOption2);
2809
3069
  authedEnv = getEnv3(hubspotCliAccountNameOption2);
2810
3070
  personalAccessKey = getAccountConfig2(authedPortalId) && getAccountConfig2(authedPortalId).personalAccessKey;
2811
3071
  if (!authedPortalId && hubspotCliAccountNameOption2) {
@@ -2857,6 +3117,9 @@ Local proxy functionality will not work without setting up authentication.`
2857
3117
  }
2858
3118
  setTrackingInfo(authedPortalId, authedEnv);
2859
3119
  sendTrackingRequest("start-dev-server");
3120
+ if (authedPortalId) {
3121
+ await validateHSPlatform(webRoot2, authedPortalId);
3122
+ }
2860
3123
  let domainsToProxy = [];
2861
3124
  if (sslEnabledOption2 && authedPortalId) {
2862
3125
  try {
@@ -2874,7 +3137,7 @@ Local proxy functionality will not work without setting up authentication.`
2874
3137
  }
2875
3138
  }
2876
3139
  const authedHublet = "na1";
2877
- const absoluteWebRoot = normalizePath5(path7.resolve(process.cwd(), webRoot2));
3140
+ const absoluteWebRoot = normalizePath6(path9.resolve(process.cwd(), webRoot2));
2878
3141
  const [__webRootProjectFolder, webRootProjectComponentFolder] = absoluteWebRoot.replace(/\/$/, "").split("/").slice(-2);
2879
3142
  const viteServer = await createViteDevServer_default(
2880
3143
  absoluteWebRoot,
@@ -2888,7 +3151,7 @@ Local proxy functionality will not work without setting up authentication.`
2888
3151
  const httpsKey = viteHTTPSConfig ? viteHTTPSConfig.key : null;
2889
3152
  const httpsCert = viteHTTPSConfig ? viteHTTPSConfig.cert : null;
2890
3153
  const projectName = getProjectNameFromHSConfig(
2891
- path7.join(webRoot2, "../hsproject.json")
3154
+ path9.join(webRoot2, "../hsproject.json")
2892
3155
  );
2893
3156
  const httpServers = [];
2894
3157
  const expressServer = express2();
@@ -2945,8 +3208,8 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
2945
3208
  `
2946
3209
  );
2947
3210
  if (storybook2) {
2948
- const packageRoot = path7.dirname(url2.fileURLToPath(import.meta.url));
2949
- const configPath = path7.resolve(packageRoot, "./storybook-main");
3211
+ const packageRoot = path9.dirname(url2.fileURLToPath(import.meta.url));
3212
+ const configPath = path9.resolve(packageRoot, "./storybook-main");
2950
3213
  sendTrackingRequest("start-storybook");
2951
3214
  const storybookProcess = spawn(
2952
3215
  "sb",
@@ -2966,7 +3229,7 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
2966
3229
  portalId: authedPortalId.toString(),
2967
3230
  hsEnv: authedEnv,
2968
3231
  hublet: authedHublet,
2969
- WEB_ROOT: path7.join(webRoot2, "components")
3232
+ WEB_ROOT: path9.join(webRoot2, "components")
2970
3233
  }
2971
3234
  }
2972
3235
  );
@@ -2,8 +2,10 @@
2
2
  import { useEffect } from "react";
3
3
 
4
4
  // ../cms-js-internal/dist/index.js
5
+ import * as dotProp from "dot-prop";
5
6
  import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
6
7
  import { isValidElement, cloneElement } from "react";
8
+ var { setProperty, getProperty, hasProperty } = dotProp;
7
9
  function namespaceModulePropsShape(props) {
8
10
  const {
9
11
  dataQueryResult,
@@ -11,7 +13,8 @@ function namespaceModulePropsShape(props) {
11
13
  fieldValues: passedFieldValues,
12
14
  hublData,
13
15
  experimentalHublData,
14
- moduleName
16
+ moduleName,
17
+ supplementalFieldValues
15
18
  } = props;
16
19
  const oldPropsShape = { ...props };
17
20
  if (oldPropsShape.dataQueryResult) {
@@ -28,7 +31,8 @@ function namespaceModulePropsShape(props) {
28
31
  hublParameters,
29
32
  hublData,
30
33
  experimentalHublData,
31
- moduleName
34
+ moduleName,
35
+ supplementalFieldValues
32
36
  };
33
37
  }
34
38
  function renderFieldsJSX(fieldsJSX) {
@@ -41,6 +41,7 @@ __export(dist_exports, {
41
41
  isUngatedFor: () => isUngatedFor,
42
42
  jsonStringifyAndEscapeForInlineJS: () => jsonStringifyAndEscapeForInlineJS,
43
43
  namespaceModulePropsShape: () => namespaceModulePropsShape,
44
+ noncePlaceholderPlugin: () => noncePlaceholderPlugin,
44
45
  removeComponentExtension: () => removeComponentExtension,
45
46
  renderComponentOnServer: () => renderComponentOnServer,
46
47
  renderFieldsToJson: () => renderFieldsToJson,
@@ -53,6 +54,7 @@ __export(dist_exports, {
53
54
  ungatedAtBuildTimeFor: () => ungatedAtBuildTimeFor,
54
55
  virtualClientRenderIslandModuleId: () => virtualClientRenderIslandModuleId
55
56
  });
57
+ import * as dotProp from "dot-prop";
56
58
  import path from "path";
57
59
  import * as jsxRuntime from "react/jsx-runtime";
58
60
  import stream from "stream";
@@ -100,6 +102,25 @@ function jsonStringifyAndEscapeForInlineJS(input, { baseIndent = 0, jsonIndent =
100
102
  ${indentString}`
101
103
  );
102
104
  }
105
+ function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplementalFieldValuesRead) {
106
+ if (!supplementalFieldValues) {
107
+ return supplementalFieldValues;
108
+ }
109
+ if (!supplementalFieldValuesRead) {
110
+ return supplementalFieldValues;
111
+ }
112
+ const result = {};
113
+ Array.from(supplementalFieldValuesRead).forEach((fieldPath) => {
114
+ if (hasProperty(supplementalFieldValues, fieldPath)) {
115
+ setProperty(
116
+ result,
117
+ fieldPath,
118
+ getProperty(supplementalFieldValues, fieldPath)
119
+ );
120
+ }
121
+ });
122
+ return result;
123
+ }
103
124
  function getIslandUrls(roots, viteDevServer) {
104
125
  return roots.map((island) => {
105
126
  const islandModule = viteDevServer.moduleGraph.getModuleById(
@@ -179,6 +200,28 @@ function resolveIslandPlugin(islandsSet) {
179
200
  }
180
201
  };
181
202
  }
203
+ function noncePlaceholderPlugin() {
204
+ const HS_DEPLOYED = process.env.AWS_EXECUTION_ENV != null || process.env.HS_DEPLOYED === "true";
205
+ return {
206
+ name: "hs-nonce-placeholder",
207
+ enforce: "post",
208
+ apply() {
209
+ return HS_DEPLOYED;
210
+ },
211
+ transformIndexHtml(html) {
212
+ const regex = /<(style|script|link) (.*)>/gi;
213
+ const replacer = (_, p1, p2) => {
214
+ if (p1 === "style" || p1 === "script" || // if link, only nonce for stylesheet
215
+ p1 === "link" && p2.includes('rel="stylesheet"')) {
216
+ const noncePlaceholderValue = p1 === "script" ? "hs-random-nonce" : "hs-random-style-nonce";
217
+ p2 = `nonce="${noncePlaceholderValue}" ${p2}`;
218
+ }
219
+ return `<${p1} ${p2}>`;
220
+ };
221
+ return html.replace(regex, replacer);
222
+ }
223
+ };
224
+ }
182
225
  function clientIslandEntryPlugin() {
183
226
  return {
184
227
  enforce: "pre",
@@ -210,21 +253,24 @@ function clientIslandEntryPlugin() {
210
253
  }
211
254
  };
212
255
  }
213
- async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, entryPointBasePath, renderOptions) {
256
+ async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, entryPointBasePath, contextOptions, renderOptions) {
214
257
  const componentDebugName = Component.displayName || Component.name;
215
258
  return renderOnServer(
216
259
  /* @__PURE__ */ jsx2(Component, { ...props }),
217
260
  pageUrl,
218
261
  environmentConfig,
219
262
  entryPointBasePath,
263
+ contextOptions,
220
264
  componentDebugName,
221
265
  renderOptions
222
266
  );
223
267
  }
224
- async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, debugName, renderOptions) {
268
+ async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, contextOptions, debugName, renderOptions) {
269
+ const supplementalFieldValues = contextOptions ? contextOptions.supplementalFieldValues : void 0;
225
270
  const renderContext = cmsComponents.createServerRenderContextV2 ? cmsComponents.createServerRenderContextV2(pageUrl, {
226
271
  environmentConfig,
227
- entryPointBasePath
272
+ entryPointBasePath,
273
+ supplementalFieldValues
228
274
  }) : cmsComponents.createServerRenderContext(pageUrl, environmentConfig);
229
275
  let html = await renderStreamToPromise(
230
276
  /* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
@@ -296,7 +342,7 @@ function findAllPartialsInRoot(webRoot2) {
296
342
  const partialSubpaths = Object.keys(allPartialComponents);
297
343
  return { partialNames, partialSubpaths };
298
344
  }
299
- function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors) {
345
+ function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
300
346
  if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
301
347
  prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
302
348
  }
@@ -331,8 +377,9 @@ function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath
331
377
  })
332
378
  `);
333
379
  }
380
+ const nonceAttr = includeNonces && cmsComponents.STYLE_NONCE_PLACEHOLDER ? ` nonce="${cmsComponents.STYLE_NONCE_PLACEHOLDER}"` : "";
334
381
  return `
335
- <script type="text/javascript">
382
+ <script type="text/javascript"${nonceAttr}>
336
383
  ${globals.join("\n ")}
337
384
  </script>
338
385
  `;
@@ -344,7 +391,8 @@ function namespaceModulePropsShape(props) {
344
391
  fieldValues: passedFieldValues,
345
392
  hublData,
346
393
  experimentalHublData,
347
- moduleName
394
+ moduleName,
395
+ supplementalFieldValues
348
396
  } = props;
349
397
  const oldPropsShape = { ...props };
350
398
  if (oldPropsShape.dataQueryResult) {
@@ -361,7 +409,8 @@ function namespaceModulePropsShape(props) {
361
409
  hublParameters,
362
410
  hublData,
363
411
  experimentalHublData,
364
- moduleName
412
+ moduleName,
413
+ supplementalFieldValues
365
414
  };
366
415
  }
367
416
  function setIn(object, nestedKeysArray, value) {
@@ -420,7 +469,7 @@ function renderFieldsToJson(fields, moduleName) {
420
469
  function isStylesheetAsset(staticAsset) {
421
470
  return staticAsset.type === "stylesheet";
422
471
  }
423
- var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, badInlineJsChars, inlineJsEscapeChars, serializeIslandDataForInlineScript, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, viteRoot, viteCommand, clientRenderIsland, virtualClientRenderIslandModuleId, jsx2, promiseForNewWritableStream, renderStreamToPromise, scriptTagToLogServerMessages, getComponentExtension, hasComponentExtension, isStorybookStory, removeComponentExtension, COMBINED_REACT_BASE_PATH, ISLAND_RUNTIME_CONFIG_BASE_PATH, GATES, ENABLED_FEATURES_GATE_MAP, BUILD_INFO_PATH, findAllComponentsIn;
472
+ var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, badInlineJsChars, inlineJsEscapeChars, setProperty, getProperty, hasProperty, serializeIslandDataForInlineScript, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, viteRoot, viteCommand, clientRenderIsland, virtualClientRenderIslandModuleId, jsx2, promiseForNewWritableStream, renderStreamToPromise, scriptTagToLogServerMessages, getComponentExtension, hasComponentExtension, isStorybookStory, removeComponentExtension, COMBINED_REACT_BASE_PATH, ISLAND_RUNTIME_CONFIG_BASE_PATH, GATES, ENABLED_FEATURES_GATE_MAP, BUILD_INFO_PATH, findAllComponentsIn;
424
473
  var init_dist = __esm({
425
474
  "../cms-js-internal/dist/index.js"() {
426
475
  COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
@@ -473,7 +522,8 @@ var init_dist = __esm({
473
522
  ">": "\\u003E",
474
523
  "/": "\\u002F"
475
524
  };
476
- serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, prettyPrint) => {
525
+ ({ setProperty, getProperty, hasProperty } = dotProp);
526
+ serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
477
527
  const islandsArrayToSerialize = tweakedIslandsArray.map(
478
528
  ({
479
529
  id,
@@ -485,6 +535,7 @@ var init_dist = __esm({
485
535
  priority,
486
536
  url,
487
537
  sharedStateID,
538
+ supplementalFieldValues,
488
539
  wrapperModuleId,
489
540
  wrapperUrl
490
541
  }) => {
@@ -507,6 +558,13 @@ var init_dist = __esm({
507
558
  if (wrapperUrl) {
508
559
  output.wrapperUrl = wrapperUrl;
509
560
  }
561
+ const filteredSupplementalFieldValues = filterOutUnreadSupplementalFieldValues(
562
+ supplementalFieldValues,
563
+ perServerRequestData.get("supplementalFieldValuesRead")
564
+ );
565
+ if (filteredSupplementalFieldValues) {
566
+ output.supplementalFieldValues = filteredSupplementalFieldValues;
567
+ }
510
568
  return output;
511
569
  }
512
570
  );
@@ -550,6 +608,7 @@ ${indentString}`);
550
608
  indent
551
609
  )}window.__islands = ${serializeIslandDataForInlineScript(
552
610
  islands,
611
+ perServerRequestData,
553
612
  indent,
554
613
  prettyPrint
555
614
  )}${writeSharedStateToJsGlobal(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "0.14.2",
3
+ "version": "0.14.4",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "engines": {
@@ -12,7 +12,7 @@
12
12
  "copy-html": "copyfiles -u 1 'src/html/**' 'dist'",
13
13
  "build-types": "tsc --project tsconfig.types.json",
14
14
  "clean": "tsc --build --clean",
15
- "dev": "nodemon --exec 'yarn start'",
15
+ "dev": "nodemon --no-stdin --exec 'yarn start'",
16
16
  "dev-inspect": "nodemon --exec 'yarn start-inspect'",
17
17
  "es-watch": "esbuild --outfile=dist-esbuild/runWhenDeveloping.cjs --bundle --watch --platform=node --external:fsevents --external:vite --external:react-refresh runWhenDeveloping.ts",
18
18
  "package": "npm run build && npm pack",
@@ -26,7 +26,8 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@hubspot/cli-lib": "^3.0.12",
29
- "@hubspot/cms-components": "^0.14.2",
29
+ "@hubspot/cms-components": "^0.14.4",
30
+ "@inquirer/select": "^2.0.0",
30
31
  "@originjs/vite-plugin-commonjs": "^1.0.3",
31
32
  "@storybook/addon-actions": "7.0.7",
32
33
  "@storybook/addon-essentials": "7.0.7",
@@ -106,5 +107,5 @@
106
107
  "publishConfig": {
107
108
  "access": "public"
108
109
  },
109
- "gitHead": "3cdf0bda841f30c17da5f55f6a52288572ba4967"
110
+ "gitHead": "9bfc94d44102ba7d992c58fb92ff26434cdeb085"
110
111
  }