@hubspot/cms-dev-server 0.6.8 → 0.7.0

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.
Binary file
@@ -184,14 +184,12 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
184
184
  var GATES = [
185
185
  "CMS:JSRenderer:SharedDeps",
186
186
  "CMS:JSRenderer:GetServerSideProps",
187
- "CMS:JSRenderer:LocalProxySchemaVersion1",
188
187
  "CMS:JSRenderer:GraphQLQueryBuild",
189
188
  "CMS:JSRenderer:SeparateIslandRenderOption"
190
189
  ];
191
190
  var ENABLED_FEATURES_GATE_MAP = {
192
191
  "cms:jsr:sharedDeps": "CMS:JSRenderer:SharedDeps",
193
192
  "cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
194
- "cms:jsr:localProxySchemaVersion1": "CMS:JSRenderer:LocalProxySchemaVersion1",
195
193
  "cms:jsr:graphqQLQueryBuild": "CMS:JSRenderer:GraphQLQueryBuild",
196
194
  "cms:jsr:separateIslandRenderOption": "CMS:JSRenderer:SeparateIslandRenderOption"
197
195
  };
@@ -338,7 +336,7 @@ var scriptTagToLogServerMessages = (messagesForBrowser, groupLabel) => {
338
336
  }
339
337
  let groupStart = "";
340
338
  let groupEnd = "";
341
- if (groupLabel !== null) {
339
+ if (groupLabel !== void 0 && groupLabel !== null) {
342
340
  groupStart = `
343
341
  console.group(${JSON.stringify(groupLabel)});`;
344
342
  groupEnd = ` console.groupEnd()
package/dist/run.js CHANGED
@@ -180,7 +180,6 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
180
180
  var ENABLED_FEATURES_GATE_MAP = {
181
181
  "cms:jsr:sharedDeps": "CMS:JSRenderer:SharedDeps",
182
182
  "cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
183
- "cms:jsr:localProxySchemaVersion1": "CMS:JSRenderer:LocalProxySchemaVersion1",
184
183
  "cms:jsr:graphqQLQueryBuild": "CMS:JSRenderer:GraphQLQueryBuild",
185
184
  "cms:jsr:separateIslandRenderOption": "CMS:JSRenderer:SeparateIslandRenderOption"
186
185
  };
@@ -314,7 +313,7 @@ var scriptTagToLogServerMessages = (messagesForBrowser, groupLabel) => {
314
313
  }
315
314
  let groupStart = "";
316
315
  let groupEnd = "";
317
- if (groupLabel !== null) {
316
+ if (groupLabel !== void 0 && groupLabel !== null) {
318
317
  groupStart = `
319
318
  console.group(${JSON.stringify(groupLabel)});`;
320
319
  groupEnd = ` console.groupEnd()
@@ -1144,7 +1143,30 @@ var module_default = moduleRouteHandler;
1144
1143
  // src/proxyPage/fetchContentMetadata.ts
1145
1144
  import http from "http";
1146
1145
  import https from "https";
1147
- async function fetchContentMetadata(url3, redirects = 0, originalUrl) {
1146
+ import { get as hsGet } from "@hubspot/cli-lib/http.js";
1147
+ import { getAccountId } from "@hubspot/cli-lib/lib/config.js";
1148
+ async function requestContentPreview(url3, portalId) {
1149
+ const urlObject = new URL(url3);
1150
+ const proxiedQueryParams = {};
1151
+ for (const queryKey of urlObject.searchParams.keys()) {
1152
+ const values = urlObject.searchParams.getAll(queryKey);
1153
+ if (values.length > 1) {
1154
+ proxiedQueryParams[queryKey] = values;
1155
+ } else {
1156
+ proxiedQueryParams[queryKey] = values[0];
1157
+ }
1158
+ }
1159
+ const accountId = getAccountId(portalId);
1160
+ const response = await hsGet(accountId, {
1161
+ baseUrl: urlObject.origin,
1162
+ uri: urlObject.pathname,
1163
+ query: proxiedQueryParams,
1164
+ json: false,
1165
+ resolveWithFullResponse: true
1166
+ });
1167
+ return response;
1168
+ }
1169
+ async function requestPage(url3, redirects = 0, originalUrl) {
1148
1170
  if (redirects > 5) {
1149
1171
  throw new Error(
1150
1172
  `Hit too many redirects to HEAD requests for ${originalUrl}`
@@ -1165,45 +1187,14 @@ async function fetchContentMetadata(url3, redirects = 0, originalUrl) {
1165
1187
  if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
1166
1188
  console.log(`Redirecting to ${res.headers.location} (from ${url3})`);
1167
1189
  return resolve3(
1168
- fetchContentMetadata(
1190
+ requestPage(
1169
1191
  res.headers.location,
1170
1192
  redirects + 1,
1171
1193
  originalUrl ?? url3
1172
1194
  )
1173
1195
  );
1174
1196
  }
1175
- const portalIdHeader = res.headers["x-hs-hub-id"];
1176
- const contentId = res.headers["x-hs-content-id"];
1177
- if (Array.isArray(portalIdHeader) || Array.isArray(contentId)) {
1178
- return reject(
1179
- new Error(
1180
- `There were multiple hub ID or content ID headers in the HEAD request to ${url3}`
1181
- )
1182
- );
1183
- } else {
1184
- const portalId = parseInt(portalIdHeader, 10);
1185
- if (res.statusCode !== 200) {
1186
- return reject(
1187
- new Error(
1188
- `${res.statusCode} ${res.statusMessage} - Unable to obtain HEAD information from ${url3}. ${res.statusCode === 429 && res.headers["retry-after"] ? `Retry after ${res.headers["retry-after"]} seconds.` : ""}`
1189
- )
1190
- );
1191
- } else if (!portalId || !contentId) {
1192
- return reject(
1193
- new Error(
1194
- `Missing hub ID or content ID headers on HEAD request to ${url3}`
1195
- )
1196
- );
1197
- } else if (isNaN(portalId)) {
1198
- return reject(
1199
- new Error(
1200
- `Hub ID from the HEAD request is not a number: '${portalId}' (${url3})`
1201
- )
1202
- );
1203
- }
1204
- const hublet = "na1";
1205
- return resolve3({ portalId, contentId, hublet });
1206
- }
1197
+ return resolve3(res);
1207
1198
  }
1208
1199
  ).on("error", (err) => {
1209
1200
  console.error(err);
@@ -1211,11 +1202,49 @@ async function fetchContentMetadata(url3, redirects = 0, originalUrl) {
1211
1202
  }).end();
1212
1203
  });
1213
1204
  }
1205
+ async function fetchContentMetadata(url3, portalId) {
1206
+ let res;
1207
+ if (url3.includes("hs_preview")) {
1208
+ res = await requestContentPreview(url3, portalId);
1209
+ } else {
1210
+ res = await requestPage(url3);
1211
+ }
1212
+ const portalIdHeader = res.headers["x-hs-hub-id"];
1213
+ const contentId = res.headers["x-hs-content-id"];
1214
+ if (Array.isArray(portalIdHeader) || Array.isArray(contentId)) {
1215
+ throw new Error(
1216
+ `There were multiple hub ID or content ID headers in the HEAD request to ${url3}`
1217
+ );
1218
+ } else {
1219
+ const portalIdFromResponse = parseInt(portalIdHeader, 10);
1220
+ const pageAccount = await getAccountId(portalIdFromResponse);
1221
+ if (!pageAccount) {
1222
+ throw new Error(
1223
+ `No CLI auth for portal ${portalIdFromResponse} found, please run \`hs auth\``
1224
+ );
1225
+ }
1226
+ if (res.statusCode !== 200) {
1227
+ throw new Error(
1228
+ `${res.statusCode} ${res.statusMessage} - Unable to obtain HEAD information from ${url3}. ${res.statusCode === 429 && res.headers["retry-after"] ? `Retry after ${res.headers["retry-after"]} seconds.` : ""}`
1229
+ );
1230
+ } else if (!portalId || !contentId) {
1231
+ throw new Error(
1232
+ `Missing hub ID or content ID headers on HEAD request to ${url3}`
1233
+ );
1234
+ } else if (isNaN(portalId)) {
1235
+ throw new Error(
1236
+ `Hub ID from the HEAD request is not a number: '${portalId}' (${url3})`
1237
+ );
1238
+ }
1239
+ const hublet = "na1";
1240
+ return { portalId, contentId, hublet };
1241
+ }
1242
+ }
1214
1243
 
1215
1244
  // src/proxyPage/proxyPage.ts
1216
1245
  import path5 from "path";
1217
- import { getAccountId, getEnv } from "@hubspot/cli-lib/lib/config.js";
1218
- import { get as hsGet2 } from "@hubspot/cli-lib/http.js";
1246
+ import { getAccountId as getAccountId2, getEnv } from "@hubspot/cli-lib/lib/config.js";
1247
+ import { get as hsGet3 } from "@hubspot/cli-lib/http.js";
1219
1248
 
1220
1249
  // src/lib/proxyHelpers.ts
1221
1250
  import fs from "fs";
@@ -1372,7 +1401,7 @@ var renderLocalError_default = (path7, error) => {
1372
1401
  };
1373
1402
 
1374
1403
  // src/proxyPage/fetchPreviewInfo.ts
1375
- import { get as hsGet } from "@hubspot/cli-lib/http.js";
1404
+ import { get as hsGet2 } from "@hubspot/cli-lib/http.js";
1376
1405
  var fetchPreviewInfo_default = async (accountId, portalId, contentId) => {
1377
1406
  if (!contentId) {
1378
1407
  throw new Error(
@@ -1380,7 +1409,7 @@ var fetchPreviewInfo_default = async (accountId, portalId, contentId) => {
1380
1409
  );
1381
1410
  }
1382
1411
  try {
1383
- const content = await hsGet(accountId, {
1412
+ const content = await hsGet2(accountId, {
1384
1413
  uri: `/content/api/v4/contents/${contentId}`,
1385
1414
  query: { portalId },
1386
1415
  json: true
@@ -1428,16 +1457,12 @@ var getEntryPointBasePathFromProxyRequest = (request2) => {
1428
1457
  }
1429
1458
  return requestPath.replace(pathParamDict.dynamic_slug, "");
1430
1459
  };
1431
- var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, projectName, jsRenderingGates) => {
1460
+ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, projectName, __jsRenderingGates) => {
1432
1461
  const url3 = new URL(urlToProxy);
1433
1462
  console.log(`Proxying request to ${url3.href}`, {
1434
1463
  previewKey,
1435
1464
  contentId
1436
1465
  });
1437
- const proxySchemaVersion = isUngatedFor(
1438
- jsRenderingGates,
1439
- "CMS:JSRenderer:LocalProxySchemaVersion1"
1440
- ) ? 1 : 0;
1441
1466
  let proxiedQueryParams = {};
1442
1467
  for (const queryKey of url3.searchParams.keys()) {
1443
1468
  const values = url3.searchParams.getAll(queryKey);
@@ -1452,9 +1477,9 @@ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, pro
1452
1477
  hs_preview: `${previewKey}-${contentId}`,
1453
1478
  hsLocalProxy: true,
1454
1479
  hsLocalProxyProject: `@projects/${projectName}`,
1455
- localProxySchemaVersion: proxySchemaVersion
1480
+ localProxySchemaVersion: 1
1456
1481
  };
1457
- const result = hsGet2(accountId, {
1482
+ const result = hsGet3(accountId, {
1458
1483
  baseUrl: url3.origin,
1459
1484
  uri: url3.pathname,
1460
1485
  query: proxiedQueryParams,
@@ -1470,12 +1495,8 @@ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, pro
1470
1495
  });
1471
1496
  };
1472
1497
  var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder, webRoot2, viteServer, pageUrl, basePath, environmentConfig, hsProjectJsonProjectName, webRootProjectComponent) => {
1473
- const proxySchemaVersion = isUngatedFor(
1474
- environmentConfig.getGates(),
1475
- "CMS:JSRenderer:LocalProxySchemaVersion1"
1476
- ) ? 1 : 0;
1477
1498
  const { path: placeholderPath } = localRenderPlaceholder;
1478
- const localRenderPlaceholderProps = proxySchemaVersion === 1 ? localRenderPlaceholder.json.props : localRenderPlaceholder.json;
1499
+ const localRenderPlaceholderProps = localRenderPlaceholder.json.props;
1479
1500
  const [
1480
1501
  __projectIdentifier,
1481
1502
  projectFolder,
@@ -1523,7 +1544,7 @@ var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder,
1523
1544
  return renderModule_default(
1524
1545
  viteServer,
1525
1546
  resolvedPath,
1526
- localRenderPlaceholderProps,
1547
+ localRenderPlaceholderProps.fieldValues,
1527
1548
  pageUrl,
1528
1549
  basePath,
1529
1550
  environmentConfig,
@@ -1542,7 +1563,7 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
1542
1563
  let accountId;
1543
1564
  let proxyEnv;
1544
1565
  try {
1545
- accountId = getAccountId(portalId);
1566
+ accountId = getAccountId2(portalId);
1546
1567
  if (accountId === null) {
1547
1568
  throw new Error();
1548
1569
  }
@@ -1598,10 +1619,7 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
1598
1619
  offsetSoFar,
1599
1620
  localRenderPlaceholder.startOffset
1600
1621
  );
1601
- if (basePath === void 0 && isUngatedFor(
1602
- environmentConfig.getGates(),
1603
- "CMS:JSRenderer:LocalProxySchemaVersion1"
1604
- )) {
1622
+ if (basePath === void 0) {
1605
1623
  basePath = getEntryPointBasePathFromProxyRequest(
1606
1624
  localRenderPlaceholder.json.request
1607
1625
  );
@@ -1711,14 +1729,10 @@ async function proxyPageRouteHandler(request2, response, next) {
1711
1729
  return response.status(400).send(message);
1712
1730
  }
1713
1731
  }
1714
- if (request2.query.hs_preview) {
1715
- const message = `Can't make a proxy request, you cannot proxy URLs that include internal query params like hs_preview`;
1716
- consoleWarn(message);
1717
- return response.status(400).send(message);
1718
- }
1719
1732
  try {
1720
1733
  const { portalId, contentId, hublet } = await fetchContentMetadata(
1721
- urlToProxy
1734
+ urlToProxy,
1735
+ request2.app.locals.authedPortalId
1722
1736
  );
1723
1737
  await proxySpecificPage(
1724
1738
  response,
@@ -1866,7 +1880,8 @@ async function proxyPathPageRouteHandler(request2, response, next) {
1866
1880
  }
1867
1881
  try {
1868
1882
  const { portalId, contentId, hublet } = await fetchContentMetadata(
1869
- proxyPageUrl.href
1883
+ proxyPageUrl.href,
1884
+ request2.app.locals.portalId
1870
1885
  );
1871
1886
  await proxySpecificPage(
1872
1887
  response,
@@ -1969,7 +1984,7 @@ import express from "express";
1969
1984
 
1970
1985
  // src/shadowDevServer/createShadowDevServerRoutes.ts
1971
1986
  import { Router as Router2 } from "express";
1972
- import { getAccountId as getAccountId2 } from "@hubspot/cli-lib/lib/config.js";
1987
+ import { getAccountId as getAccountId3 } from "@hubspot/cli-lib/lib/config.js";
1973
1988
  import cors from "cors";
1974
1989
  function getShadowDevServerCheckHandler(devServerPort, projectName, gates) {
1975
1990
  return async function shadowDevServerCheckHandler(request2, response) {
@@ -1988,7 +2003,7 @@ function getShadowDevServerCheckHandler(devServerPort, projectName, gates) {
1988
2003
  let hasJSBuildingBlocks = false;
1989
2004
  let localProxyUrl;
1990
2005
  try {
1991
- accountId = getAccountId2(portalId);
2006
+ accountId = getAccountId3(portalId);
1992
2007
  if (accountId === null) {
1993
2008
  throw new Error();
1994
2009
  }
@@ -2210,14 +2225,14 @@ async function getJsRenderingGates(portalId, env, personalAccessKey) {
2210
2225
  // src/createDevServer.ts
2211
2226
  import {
2212
2227
  getEnv as getEnv2,
2213
- getAccountId as getAccountId3,
2228
+ getAccountId as getAccountId4,
2214
2229
  getAccountConfig,
2215
2230
  loadConfig,
2216
2231
  validateConfig
2217
2232
  } from "@hubspot/cli-lib/lib/config.js";
2218
2233
 
2219
2234
  // src/proxyPage/fetchDomains.ts
2220
- import { get as hsGet3 } from "@hubspot/cli-lib/http.js";
2235
+ import { get as hsGet4 } from "@hubspot/cli-lib/http.js";
2221
2236
 
2222
2237
  // src/lib/errors.ts
2223
2238
  var MISSING_SCOPE_ERROR_PREFIX = `Your personal access key is missing required scopes fetch domains.
@@ -2246,7 +2261,7 @@ function isMissingScopeError(error) {
2246
2261
  // src/proxyPage/fetchDomains.ts
2247
2262
  async function fetchDomains(portalId) {
2248
2263
  try {
2249
- const result = await hsGet3(portalId, {
2264
+ const result = await hsGet4(portalId, {
2250
2265
  uri: `/cms/v3/domains`,
2251
2266
  query: { portalId },
2252
2267
  json: true
@@ -2313,7 +2328,7 @@ async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2
2313
2328
  }
2314
2329
  loadConfig(hubspotCliConfigPathOption2 || null, { useEnv: false });
2315
2330
  if (validateConfig()) {
2316
- authedPortalId = getAccountId3(hubspotCliAccountNameOption2);
2331
+ authedPortalId = getAccountId4(hubspotCliAccountNameOption2);
2317
2332
  authedEnv = getEnv2(hubspotCliAccountNameOption2);
2318
2333
  personalAccessKey = getAccountConfig(authedPortalId) && getAccountConfig(authedPortalId).personalAccessKey;
2319
2334
  if (!authedPortalId && hubspotCliAccountNameOption2) {
@@ -5,6 +5,27 @@ import { renderToStaticMarkup as renderToStaticMarkup2 } from "react-dom/server"
5
5
  // ../cms-js-internal/dist/index.js
6
6
  import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
7
7
  import { cloneElement } from "react";
8
+ function namespaceModulePropsShape(props) {
9
+ const {
10
+ dataQueryResult,
11
+ hublParameters,
12
+ fieldValues: passedFieldValues
13
+ } = props;
14
+ const oldPropsShape = { ...props };
15
+ if (oldPropsShape.dataQueryResult) {
16
+ delete oldPropsShape.dataQueryResult;
17
+ }
18
+ if (oldPropsShape.hublParameters) {
19
+ delete oldPropsShape.hublParameters;
20
+ }
21
+ const fieldValues = passedFieldValues || oldPropsShape;
22
+ return {
23
+ ...fieldValues,
24
+ dataQueryResult,
25
+ fieldValues,
26
+ hublParameters
27
+ };
28
+ }
8
29
  function renderFieldsToJson(fields) {
9
30
  let moduleJson;
10
31
  const outputCallback = (callbackJson) => {
@@ -135,7 +156,8 @@ function moduleStory(ModuleComponent, fields, storyArgs) {
135
156
  return {
136
157
  render: (_args) => {
137
158
  const fieldValues = getNestedFieldObjectForArgs(_args);
138
- return /* @__PURE__ */ jsx(ModuleComponent, { ...fieldValues });
159
+ const props = namespaceModulePropsShape({ fieldValues });
160
+ return /* @__PURE__ */ jsx(ModuleComponent, { ...props });
139
161
  },
140
162
  argTypes,
141
163
  args
@@ -458,14 +458,12 @@ ${indentString}`);
458
458
  GATES = [
459
459
  "CMS:JSRenderer:SharedDeps",
460
460
  "CMS:JSRenderer:GetServerSideProps",
461
- "CMS:JSRenderer:LocalProxySchemaVersion1",
462
461
  "CMS:JSRenderer:GraphQLQueryBuild",
463
462
  "CMS:JSRenderer:SeparateIslandRenderOption"
464
463
  ];
465
464
  ENABLED_FEATURES_GATE_MAP = {
466
465
  "cms:jsr:sharedDeps": "CMS:JSRenderer:SharedDeps",
467
466
  "cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
468
- "cms:jsr:localProxySchemaVersion1": "CMS:JSRenderer:LocalProxySchemaVersion1",
469
467
  "cms:jsr:graphqQLQueryBuild": "CMS:JSRenderer:GraphQLQueryBuild",
470
468
  "cms:jsr:separateIslandRenderOption": "CMS:JSRenderer:SeparateIslandRenderOption"
471
469
  };
@@ -527,7 +525,7 @@ ${indentString}`);
527
525
  }
528
526
  let groupStart = "";
529
527
  let groupEnd = "";
530
- if (groupLabel !== null) {
528
+ if (groupLabel !== void 0 && groupLabel !== null) {
531
529
  groupStart = `
532
530
  console.group(${JSON.stringify(groupLabel)});`;
533
531
  groupEnd = ` console.groupEnd()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "0.6.8",
3
+ "version": "0.7.0",
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.6.8",
28
+ "@hubspot/cms-components": "^0.7.0",
29
29
  "@storybook/addon-actions": "7.0.7",
30
30
  "@storybook/addon-essentials": "7.0.7",
31
31
  "@storybook/addon-interactions": "7.0.7",
@@ -97,5 +97,5 @@
97
97
  "publishConfig": {
98
98
  "access": "public"
99
99
  },
100
- "gitHead": "9ca0f79fc066dc1663f94ead2987e1e51b799351"
100
+ "gitHead": "2e6ce49ad4fbee93591ea9c0459b46e8211da987"
101
101
  }
@@ -1,8 +1,15 @@
1
1
  import React from 'react';
2
2
  import { Field } from '@hubspot/cms-components/fields';
3
3
  import { Args, ModuleStory } from './types.js';
4
+ declare type ModuleProps = {
5
+ fieldValues: any;
6
+ dataQueryResult?: any;
7
+ hublParameters?: any;
8
+ serverSideProps?: any;
9
+ };
4
10
  export declare function moduleFieldsToJson(fields: JSX.Element): Field[];
5
- export declare function moduleStory(ModuleComponent: React.ComponentType, fields: JSX.Element, storyArgs: Args): ModuleStory;
11
+ export declare function moduleStory(ModuleComponent: (moduleProps: ModuleProps) => React.ReactElement<any, any> | null, fields: JSX.Element, storyArgs: Args): ModuleStory;
6
12
  export declare function moduleStoryWithIsland(fields: JSX.Element, // was module component
7
13
  moduleName: string, // was fields jSX
8
14
  storyArgs: Args): ModuleStory;
15
+ export {};