@hubspot/cms-dev-server 0.11.2 → 0.11.3

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/run.js CHANGED
@@ -869,7 +869,7 @@ function trackUsage(action) {
869
869
  eventName: EVENT_NAME,
870
870
  action,
871
871
  nodeVersion: getNodeVersionData(),
872
- version: "0.11.2",
872
+ version: "0.11.3",
873
873
  os: getPlatform()
874
874
  };
875
875
  const uri = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -1268,7 +1268,7 @@ var moduleRouteHandler = async (request2, response) => {
1268
1268
  } = await renderModule_default(
1269
1269
  viteServer,
1270
1270
  modulePath,
1271
- { fieldValues: fieldOverrides },
1271
+ { fieldValues: fieldOverrides, hublParameters: {} },
1272
1272
  fullOriginalUrlFromRequest(request2),
1273
1273
  basePath,
1274
1274
  environmentConfig,
@@ -1413,6 +1413,9 @@ import fs from "fs";
1413
1413
  import { resolve as resolve2 } from "path";
1414
1414
  var localJsRenderStartString = '<!-- proxy local render of "';
1415
1415
  var localJsRenderEndString = "end proxy local render -->";
1416
+ function isRecord(value) {
1417
+ return typeof value === "object" && value !== null;
1418
+ }
1416
1419
  var findLocalRenderPlaceholders = (body) => {
1417
1420
  let offsetSoFar = 0;
1418
1421
  const result = [];
@@ -1447,12 +1450,22 @@ var findLocalRenderPlaceholders = (body) => {
1447
1450
  const jsonString = body.substring(pathEndOffset + 1, endOffset).trim();
1448
1451
  try {
1449
1452
  const json = JSON.parse(jsonString);
1450
- result.push({
1451
- startOffset,
1452
- endOffset: endOffset + localJsRenderEndString.length,
1453
- path: path8,
1454
- json
1455
- });
1453
+ if (!isRecord(json.request)) {
1454
+ console.error(
1455
+ `Invalid JSON inside <!-- proxy local render .. --> string (missing request key)`
1456
+ );
1457
+ } else if (!isRecord(json.props)) {
1458
+ console.error(
1459
+ `Invalid JSON inside <!-- proxy local render .. --> string (missing props key)`
1460
+ );
1461
+ } else {
1462
+ result.push({
1463
+ startOffset,
1464
+ endOffset: endOffset + localJsRenderEndString.length,
1465
+ path: path8,
1466
+ json
1467
+ });
1468
+ }
1456
1469
  offsetSoFar = endOffset + localJsRenderEndString.length;
1457
1470
  } catch (e) {
1458
1471
  console.error(
@@ -1668,13 +1681,18 @@ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, pro
1668
1681
  }
1669
1682
  });
1670
1683
  };
1684
+ function isRecord2(value) {
1685
+ return typeof value === "object" && value !== null;
1686
+ }
1687
+ function isModulePlaceholder(value) {
1688
+ return isRecord2(value) && isRecord2(value.json) && isRecord2(value.json.props) && isRecord2(value.json.props.fieldValues) && isRecord2(value.json.props.hublParameters);
1689
+ }
1671
1690
  var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder, webRoot2, viteServer, pageUrl, basePath, environmentConfig, hsProjectJsonProjectName, webRootProjectComponent) => {
1672
1691
  const placeholderPath = resolvePlaceholderPath(
1673
1692
  localRenderPlaceholder.path,
1674
1693
  hsProjectJsonProjectName,
1675
1694
  webRootProjectComponent
1676
1695
  );
1677
- const localRenderPlaceholderProps = localRenderPlaceholder.json.props;
1678
1696
  const [
1679
1697
  __projectIdentifier,
1680
1698
  projectFolder,
@@ -1706,39 +1724,72 @@ var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder,
1706
1724
  if (placeholderPath.startsWith("/fake/path/to/")) {
1707
1725
  return fakeRenderJsComponent(indexForThisRender);
1708
1726
  } else if (partialPath === ENTRY_POINTS_PATH) {
1709
- return renderPartial_default(
1727
+ return renderComponentForPlaceholderPartial(
1710
1728
  viteServer,
1711
1729
  resolvedPath,
1712
- localRenderPlaceholderProps,
1730
+ localRenderPlaceholder,
1713
1731
  pageUrl,
1714
1732
  basePath,
1715
1733
  environmentConfig,
1716
- {
1717
- identifierPrefix: getEntryPointHashWithIndexSuffix(
1718
- entryPointPath,
1719
- indexForThisRender
1720
- )
1721
- }
1734
+ entryPointPath,
1735
+ indexForThisRender
1722
1736
  );
1723
1737
  } else if (partialPath === MODULE_FOLDER_PATH) {
1724
- return renderModule_default(
1725
- viteServer,
1726
- resolvedPath,
1727
- localRenderPlaceholderProps,
1728
- pageUrl,
1729
- basePath,
1730
- environmentConfig,
1731
- {
1732
- identifierPrefix: getEntryPointHashWithIndexSuffix(
1733
- entryPointPath,
1734
- indexForThisRender
1735
- )
1736
- }
1737
- );
1738
+ if (!isModulePlaceholder(localRenderPlaceholder)) {
1739
+ console.error(
1740
+ `Skipping local module render of ${componentFileName} <!-- proxy local render .. --> is missing necessary module prop keys (fieldValues? hublParameters?) `
1741
+ );
1742
+ } else {
1743
+ const localModuleRenderPlaceholder = {
1744
+ ...localRenderPlaceholder
1745
+ };
1746
+ return renderComponentForPlaceholderModule(
1747
+ viteServer,
1748
+ resolvedPath,
1749
+ localModuleRenderPlaceholder,
1750
+ pageUrl,
1751
+ basePath,
1752
+ environmentConfig,
1753
+ entryPointPath,
1754
+ indexForThisRender
1755
+ );
1756
+ }
1738
1757
  } else {
1739
1758
  throw new Error(`Unimplemented render of ${placeholderPath}.`);
1740
1759
  }
1741
1760
  };
1761
+ function renderComponentForPlaceholderPartial(viteServer, resolvedPath, localRenderPlaceholderProps, pageUrl, basePath, environmentConfig, entryPointPath, indexForThisRender) {
1762
+ return renderPartial_default(
1763
+ viteServer,
1764
+ resolvedPath,
1765
+ localRenderPlaceholderProps,
1766
+ pageUrl,
1767
+ basePath,
1768
+ environmentConfig,
1769
+ {
1770
+ identifierPrefix: getEntryPointHashWithIndexSuffix(
1771
+ entryPointPath,
1772
+ indexForThisRender
1773
+ )
1774
+ }
1775
+ );
1776
+ }
1777
+ function renderComponentForPlaceholderModule(viteServer, resolvedPath, localModuleRenderPlaceholder, pageUrl, basePath, environmentConfig, entryPointPath, indexForThisRender) {
1778
+ return renderModule_default(
1779
+ viteServer,
1780
+ resolvedPath,
1781
+ localModuleRenderPlaceholder.json.props,
1782
+ pageUrl,
1783
+ basePath,
1784
+ environmentConfig,
1785
+ {
1786
+ identifierPrefix: getEntryPointHashWithIndexSuffix(
1787
+ entryPointPath,
1788
+ indexForThisRender
1789
+ )
1790
+ }
1791
+ );
1792
+ }
1742
1793
  async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2, viteServer, projectName, projectComponentPath, jsRenderingGates, urlToProxy, fullOriginalUrl) {
1743
1794
  let accountId;
1744
1795
  let proxyEnv;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "0.11.2",
3
+ "version": "0.11.3",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "engines": {
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@hubspot/cli-lib": "^3.0.12",
28
- "@hubspot/cms-components": "^0.11.2",
28
+ "@hubspot/cms-components": "^0.11.3",
29
29
  "@originjs/vite-plugin-commonjs": "^1.0.3",
30
30
  "@storybook/addon-actions": "7.0.7",
31
31
  "@storybook/addon-essentials": "7.0.7",
@@ -101,5 +101,5 @@
101
101
  "publishConfig": {
102
102
  "access": "public"
103
103
  },
104
- "gitHead": "5fda95284c0941e0beff0ec91c048d270fc41eda"
104
+ "gitHead": "6f4927af2307a5bf997cfe130a87900b8b055916"
105
105
  }
@@ -1,11 +1,5 @@
1
1
  import React from 'react';
2
+ import { ModuleProps } from '@hubspot/cms-components';
2
3
  import { Args, ModuleStory } from './types.js';
3
- declare type ModuleProps = {
4
- fieldValues: any;
5
- dataQueryResult?: any;
6
- hublParameters?: any;
7
- serverSideProps?: any;
8
- };
9
4
  export declare function moduleStory(ModuleComponent: (moduleProps: ModuleProps) => React.ReactElement<any, any> | null, fields: JSX.Element, storyArgs: Args): ModuleStory;
10
5
  export declare function moduleStoryWithIsland(moduleName: string, fields: JSX.Element, storyArgs: Args): ModuleStory;
11
- export {};