@hubspot/cms-dev-server 0.14.13 → 0.14.15
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/internalSsr.js +3 -1
- package/dist/run.js +65 -19
- package/dist/storybook-main/main.js +3 -1
- package/package.json +4 -3
package/dist/internalSsr.js
CHANGED
|
@@ -668,10 +668,12 @@ async function renderComponentOnServer(Component, props, pageUrl, environmentCon
|
|
|
668
668
|
}
|
|
669
669
|
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, contextOptions, debugName, renderOptions) {
|
|
670
670
|
const supplementalFieldValues = contextOptions ? contextOptions.supplementalFieldValues : void 0;
|
|
671
|
+
const messagesForBrowser = contextOptions ? contextOptions.messagesForBrowser : void 0;
|
|
671
672
|
const renderContext = cmsComponents.createServerRenderContextV2 ? cmsComponents.createServerRenderContextV2(pageUrl, {
|
|
672
673
|
environmentConfig,
|
|
673
674
|
entryPointBasePath,
|
|
674
|
-
supplementalFieldValues
|
|
675
|
+
supplementalFieldValues,
|
|
676
|
+
messagesForBrowser
|
|
675
677
|
}) : cmsComponents.createServerRenderContext(pageUrl, environmentConfig);
|
|
676
678
|
let html = await renderStreamToPromise(
|
|
677
679
|
/* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
package/dist/run.js
CHANGED
|
@@ -628,10 +628,12 @@ var renderStreamToPromise = async (reactElements, options) => {
|
|
|
628
628
|
};
|
|
629
629
|
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, contextOptions, debugName, renderOptions) {
|
|
630
630
|
const supplementalFieldValues = contextOptions ? contextOptions.supplementalFieldValues : void 0;
|
|
631
|
+
const messagesForBrowser = contextOptions ? contextOptions.messagesForBrowser : void 0;
|
|
631
632
|
const renderContext = cmsComponents.createServerRenderContextV2 ? cmsComponents.createServerRenderContextV2(pageUrl, {
|
|
632
633
|
environmentConfig,
|
|
633
634
|
entryPointBasePath,
|
|
634
|
-
supplementalFieldValues
|
|
635
|
+
supplementalFieldValues,
|
|
636
|
+
messagesForBrowser
|
|
635
637
|
}) : cmsComponents.createServerRenderContext(pageUrl, environmentConfig);
|
|
636
638
|
let html = await renderStreamToPromise(
|
|
637
639
|
/* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
|
@@ -1029,7 +1031,7 @@ function trackUsage(action) {
|
|
|
1029
1031
|
eventName: EVENT_NAME,
|
|
1030
1032
|
action,
|
|
1031
1033
|
nodeVersion: getNodeVersionData(),
|
|
1032
|
-
version: "0.14.
|
|
1034
|
+
version: "0.14.15",
|
|
1033
1035
|
os: getPlatform()
|
|
1034
1036
|
};
|
|
1035
1037
|
const uri = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -1320,6 +1322,7 @@ async function renderModule(viteServer, requestedModulePath, moduleProps, pageUr
|
|
|
1320
1322
|
environmentConfig.getGates(),
|
|
1321
1323
|
"CMS:JSRenderer:GetServerSideProps"
|
|
1322
1324
|
);
|
|
1325
|
+
const messagesForBrowser = [];
|
|
1323
1326
|
let serverSideProps;
|
|
1324
1327
|
let componentModule;
|
|
1325
1328
|
let dataQueryResult;
|
|
@@ -1369,16 +1372,27 @@ async function renderModule(viteServer, requestedModulePath, moduleProps, pageUr
|
|
|
1369
1372
|
pageUrl
|
|
1370
1373
|
);
|
|
1371
1374
|
if (dataQueryResult.errors && dataQueryResult.errors.length) {
|
|
1375
|
+
const errorString = `GraphQL query for ${requestedModulePath} had errors.`;
|
|
1376
|
+
messagesForBrowser.push({
|
|
1377
|
+
level: "error",
|
|
1378
|
+
parameters: [errorString]
|
|
1379
|
+
});
|
|
1372
1380
|
dataQueryResult.errors.forEach((graphQLError) => {
|
|
1373
1381
|
console.error(graphQLError);
|
|
1382
|
+
messagesForBrowser.push({
|
|
1383
|
+
level: "error",
|
|
1384
|
+
parameters: [graphQLError.message, graphQLError]
|
|
1385
|
+
});
|
|
1374
1386
|
});
|
|
1375
|
-
console.error("Your GraphQL query resulted in the above errors");
|
|
1376
1387
|
}
|
|
1377
1388
|
} catch (error) {
|
|
1389
|
+
const errorString = `Failed to execute query for ${requestedModulePath}.`;
|
|
1390
|
+
console.error(errorString);
|
|
1378
1391
|
console.error(error.message);
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1392
|
+
messagesForBrowser.push({
|
|
1393
|
+
level: "error",
|
|
1394
|
+
parameters: [errorString, error.message]
|
|
1395
|
+
});
|
|
1382
1396
|
}
|
|
1383
1397
|
}
|
|
1384
1398
|
const namespacedModuleProps = namespaceModulePropsShape({
|
|
@@ -1399,9 +1413,20 @@ async function renderModule(viteServer, requestedModulePath, moduleProps, pageUr
|
|
|
1399
1413
|
if (serverSideProps.constructor !== {}.constructor) {
|
|
1400
1414
|
throw new Error("getServerSideProps must return an object");
|
|
1401
1415
|
}
|
|
1402
|
-
} catch (
|
|
1403
|
-
|
|
1404
|
-
console.
|
|
1416
|
+
} catch (error) {
|
|
1417
|
+
const errorString = `Error resolving server side props ${requestedModulePath}`;
|
|
1418
|
+
console.log(errorString);
|
|
1419
|
+
console.error(error);
|
|
1420
|
+
messagesForBrowser.push(
|
|
1421
|
+
{
|
|
1422
|
+
level: "error",
|
|
1423
|
+
parameters: [errorString]
|
|
1424
|
+
},
|
|
1425
|
+
{
|
|
1426
|
+
level: "error",
|
|
1427
|
+
parameters: [error.message]
|
|
1428
|
+
}
|
|
1429
|
+
);
|
|
1405
1430
|
}
|
|
1406
1431
|
}
|
|
1407
1432
|
return renderComponentWithCSS_default(
|
|
@@ -1411,7 +1436,7 @@ async function renderModule(viteServer, requestedModulePath, moduleProps, pageUr
|
|
|
1411
1436
|
{ ...namespacedModuleProps, serverSideProps },
|
|
1412
1437
|
pageUrl,
|
|
1413
1438
|
basePath,
|
|
1414
|
-
{ supplementalFieldValues },
|
|
1439
|
+
{ supplementalFieldValues, messagesForBrowser },
|
|
1415
1440
|
environmentConfig,
|
|
1416
1441
|
renderOptions
|
|
1417
1442
|
).then(applyFieldsValidationToRenderContext);
|
|
@@ -1631,6 +1656,7 @@ import { get as hsGet3 } from "@hubspot/cli-lib/http.js";
|
|
|
1631
1656
|
// src/lib/proxyHelpers.ts
|
|
1632
1657
|
import fs2 from "fs";
|
|
1633
1658
|
import { resolve as resolve2 } from "path";
|
|
1659
|
+
import { unescape } from "html-escaper";
|
|
1634
1660
|
var localJsRenderStartString = '<!-- proxy local render of "';
|
|
1635
1661
|
var localJsRenderEndString = "end proxy local render -->";
|
|
1636
1662
|
function isRecord(value) {
|
|
@@ -1669,7 +1695,12 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
1669
1695
|
if (endOffset >= startOffset && endOffset < nextCommentEndOffset) {
|
|
1670
1696
|
const jsonString = body.substring(pathEndOffset + 1, endOffset).trim();
|
|
1671
1697
|
try {
|
|
1672
|
-
|
|
1698
|
+
let json;
|
|
1699
|
+
try {
|
|
1700
|
+
json = JSON.parse(unescape(jsonString));
|
|
1701
|
+
} catch (e) {
|
|
1702
|
+
json = JSON.parse(jsonString);
|
|
1703
|
+
}
|
|
1673
1704
|
if (!isRecord(json.request)) {
|
|
1674
1705
|
console.error(
|
|
1675
1706
|
`Invalid JSON inside <!-- proxy local render .. --> string (missing request key)`
|
|
@@ -1866,7 +1897,7 @@ function resolvePlaceholderPath(placeholderPath, projectName, projectComponent)
|
|
|
1866
1897
|
}
|
|
1867
1898
|
return placeholderPath;
|
|
1868
1899
|
}
|
|
1869
|
-
var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, projectName, environmentConfig, __jsRenderingGates) => {
|
|
1900
|
+
var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, projectName, environmentConfig, __jsRenderingGates, cookieHeader) => {
|
|
1870
1901
|
const url3 = new URL(urlToProxy);
|
|
1871
1902
|
const renderPreviewLocally = url3.searchParams.has("renderPreviewLocally");
|
|
1872
1903
|
let proxiedQueryParams = {};
|
|
@@ -1889,7 +1920,7 @@ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, pro
|
|
|
1889
1920
|
...proxiedQueryParams,
|
|
1890
1921
|
hs_preview: `${previewKey}-${contentId}`,
|
|
1891
1922
|
hsLocalProxyProject: localProxyProject,
|
|
1892
|
-
localProxySchemaVersion: "
|
|
1923
|
+
localProxySchemaVersion: "2"
|
|
1893
1924
|
};
|
|
1894
1925
|
if (renderPreviewLocally) {
|
|
1895
1926
|
proxiedQueryParams.hsDebugOverridePublicHost = url3.host;
|
|
@@ -1908,7 +1939,10 @@ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, pro
|
|
|
1908
1939
|
uri: pathname,
|
|
1909
1940
|
query: proxiedQueryParams,
|
|
1910
1941
|
json: false,
|
|
1911
|
-
useQuerystring: true
|
|
1942
|
+
useQuerystring: true,
|
|
1943
|
+
headers: {
|
|
1944
|
+
COOKIE: cookieHeader
|
|
1945
|
+
}
|
|
1912
1946
|
});
|
|
1913
1947
|
return result.catch((error) => {
|
|
1914
1948
|
if (error.statusCode >= 400 && error.statusCode < 500 && !!error.response.body) {
|
|
@@ -2028,7 +2062,7 @@ function renderComponentForPlaceholderModule(viteServer, resolvedPath, localModu
|
|
|
2028
2062
|
}
|
|
2029
2063
|
);
|
|
2030
2064
|
}
|
|
2031
|
-
async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2, viteServer, projectName, projectComponentPath, jsRenderingGates, urlToProxy, fullOriginalUrl) {
|
|
2065
|
+
async function proxySpecificPage(request2, response, portalId, hublet, contentId, webRoot2, viteServer, projectName, projectComponentPath, jsRenderingGates, urlToProxy, fullOriginalUrl) {
|
|
2032
2066
|
let accountId;
|
|
2033
2067
|
let proxyEnv;
|
|
2034
2068
|
const prettyPrint = isDebugUrlString3(urlToProxy);
|
|
@@ -2067,7 +2101,8 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
|
|
|
2067
2101
|
contentId,
|
|
2068
2102
|
projectName,
|
|
2069
2103
|
environmentConfig,
|
|
2070
|
-
jsRenderingGates
|
|
2104
|
+
jsRenderingGates,
|
|
2105
|
+
request2.get("COOKIE")
|
|
2071
2106
|
);
|
|
2072
2107
|
const { sortIslandRootsByPriority } = await viteServer.ssrLoadModule(
|
|
2073
2108
|
"@hubspot/cms-components"
|
|
@@ -2232,6 +2267,7 @@ async function proxyPageRouteHandler(request2, response, next) {
|
|
|
2232
2267
|
request2.app.locals.authedPortalId
|
|
2233
2268
|
);
|
|
2234
2269
|
await proxySpecificPage(
|
|
2270
|
+
request2,
|
|
2235
2271
|
response,
|
|
2236
2272
|
portalId,
|
|
2237
2273
|
hublet,
|
|
@@ -2384,6 +2420,7 @@ async function proxyPathPageRouteHandler(request2, response, next) {
|
|
|
2384
2420
|
request2.app.locals.authedPortalId
|
|
2385
2421
|
);
|
|
2386
2422
|
await proxySpecificPage(
|
|
2423
|
+
request2,
|
|
2387
2424
|
response,
|
|
2388
2425
|
portalId,
|
|
2389
2426
|
hublet,
|
|
@@ -2513,17 +2550,26 @@ async function modulePreviewRouteHandler(request2, response) {
|
|
|
2513
2550
|
const queryParams = new URLSearchParams({
|
|
2514
2551
|
portalId: `${authedPortalId}`,
|
|
2515
2552
|
hsLocalProxy: `${true}`,
|
|
2516
|
-
localProxySchemaVersion: "
|
|
2553
|
+
localProxySchemaVersion: "2"
|
|
2517
2554
|
});
|
|
2518
|
-
|
|
2555
|
+
const currentHubApiDomainOverride = process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
2556
|
+
process.env.HUBAPI_DOMAIN_OVERRIDE = `api.hubspot${authedEnv === "qa" ? "qa" : ""}`;
|
|
2557
|
+
const templatePreviewPromise = hsPost(authedPortalId, {
|
|
2519
2558
|
uri: `/api/cos-rendering/v1/public/_hcms/preview/template/multiform?${queryParams}`,
|
|
2520
2559
|
headers: {
|
|
2521
2560
|
["content-type"]: "application/x-www-form-urlencoded",
|
|
2522
2561
|
["Accept"]: "text/html",
|
|
2523
|
-
referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com
|
|
2562
|
+
referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
|
|
2563
|
+
cookie: request2.get("COOKIE")
|
|
2524
2564
|
},
|
|
2525
2565
|
body: `module=${encodeURIComponent(JSON.stringify(localModule))}`
|
|
2526
2566
|
});
|
|
2567
|
+
if (currentHubApiDomainOverride) {
|
|
2568
|
+
process.env.HUBAPI_DOMAIN_OVERRIDE = currentHubApiDomainOverride;
|
|
2569
|
+
} else {
|
|
2570
|
+
delete process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
2571
|
+
}
|
|
2572
|
+
templatePreview = await templatePreviewPromise;
|
|
2527
2573
|
} catch (e) {
|
|
2528
2574
|
return response.status(500).end(`Error fetching module preview for (${moduleName}).
|
|
2529
2575
|
|
|
@@ -602,10 +602,12 @@ async function renderComponentOnServer(Component, props, pageUrl, environmentCon
|
|
|
602
602
|
}
|
|
603
603
|
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, contextOptions, debugName, renderOptions) {
|
|
604
604
|
const supplementalFieldValues = contextOptions ? contextOptions.supplementalFieldValues : void 0;
|
|
605
|
+
const messagesForBrowser = contextOptions ? contextOptions.messagesForBrowser : void 0;
|
|
605
606
|
const renderContext = cmsComponents.createServerRenderContextV2 ? cmsComponents.createServerRenderContextV2(pageUrl, {
|
|
606
607
|
environmentConfig,
|
|
607
608
|
entryPointBasePath,
|
|
608
|
-
supplementalFieldValues
|
|
609
|
+
supplementalFieldValues,
|
|
610
|
+
messagesForBrowser
|
|
609
611
|
}) : cmsComponents.createServerRenderContext(pageUrl, environmentConfig);
|
|
610
612
|
let html = await renderStreamToPromise(
|
|
611
613
|
/* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.15",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@hubspot/cli-lib": "^3.0.12",
|
|
29
|
-
"@hubspot/cms-components": "^0.14.
|
|
29
|
+
"@hubspot/cms-components": "^0.14.15",
|
|
30
30
|
"@inquirer/select": "^2.0.0",
|
|
31
31
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
32
32
|
"@storybook/addon-actions": "7.0.7",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"cors": "^2.8.5",
|
|
45
45
|
"debug": "^4.3.4",
|
|
46
46
|
"express": "^4.17.3",
|
|
47
|
+
"html-escaper": "^3.0.3",
|
|
47
48
|
"http-proxy-middleware": "^2.0.6",
|
|
48
49
|
"node-fetch": "^3.3.0",
|
|
49
50
|
"react": "^18.1.0",
|
|
@@ -107,5 +108,5 @@
|
|
|
107
108
|
"publishConfig": {
|
|
108
109
|
"access": "public"
|
|
109
110
|
},
|
|
110
|
-
"gitHead": "
|
|
111
|
+
"gitHead": "30a7d77696a0cd7264245d09901f35dbd2b2411f"
|
|
111
112
|
}
|