@hubspot/cms-dev-server 0.16.10 → 0.16.12
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/generateJsonFromJsx.js +4 -4
- package/dist/generateJsonFromJsx.js.map +7 -0
- package/dist/index.js +4 -4
- package/dist/index.js.map +7 -0
- package/dist/internalSsr.js +6 -5
- package/dist/internalSsr.js.map +7 -0
- package/dist/island-runtime.js.map +7 -0
- package/dist/run.js +1137 -988
- package/dist/run.js.map +7 -0
- package/dist/storybook/index.js.map +7 -0
- package/dist/storybook-main/main.js +6 -5
- package/dist/storybook-main/main.js.map +7 -0
- package/dist/storybook-main/preview.js.map +7 -0
- package/package.json +4 -3
- package/types/island-runtime.d.ts +2 -0
package/dist/run.js
CHANGED
|
@@ -80,13 +80,13 @@ function getDevServerCommandLineOptions(argv) {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
// src/createDevServer.ts
|
|
83
|
-
import
|
|
83
|
+
import path10 from "path";
|
|
84
84
|
import url2 from "url";
|
|
85
85
|
import express2 from "express";
|
|
86
86
|
import http3 from "http";
|
|
87
87
|
import bodyParser from "body-parser";
|
|
88
88
|
import { spawn } from "child_process";
|
|
89
|
-
import { normalizePath as
|
|
89
|
+
import { normalizePath as normalizePath7 } from "vite";
|
|
90
90
|
import { Transform } from "stream";
|
|
91
91
|
|
|
92
92
|
// src/routes/createDevServerRoutes.ts
|
|
@@ -94,8 +94,8 @@ import { Router } from "express";
|
|
|
94
94
|
import { createProxyMiddleware } from "http-proxy-middleware";
|
|
95
95
|
|
|
96
96
|
// src/routes/partial.ts
|
|
97
|
-
import
|
|
98
|
-
import { normalizePath as
|
|
97
|
+
import path5 from "path";
|
|
98
|
+
import { normalizePath as normalizePath4 } from "vite";
|
|
99
99
|
|
|
100
100
|
// src/lib/fullOriginalUrlFromRequest.ts
|
|
101
101
|
function fullOriginalUrlFromRequest(request2) {
|
|
@@ -300,7 +300,8 @@ function getCMSAssetConfig(webRoot2) {
|
|
|
300
300
|
}
|
|
301
301
|
var ENABLED_FEATURES_GATE_MAP = {
|
|
302
302
|
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
303
|
-
"cms:jsr:RemoveCjsPlugin": "CMS:JSRenderer:RemoveCjsPlugin"
|
|
303
|
+
"cms:jsr:RemoveCjsPlugin": "CMS:JSRenderer:RemoveCjsPlugin",
|
|
304
|
+
"cms:jsr:analyzeCmsModules": "CMS:JSRenderer:AnalyzeCmsModules"
|
|
304
305
|
};
|
|
305
306
|
function isUngatedFor(gates, gate) {
|
|
306
307
|
return gates.includes(gate);
|
|
@@ -601,7 +602,7 @@ function noncePlaceholderPlugin() {
|
|
|
601
602
|
};
|
|
602
603
|
}
|
|
603
604
|
var traverse = _traverse.default;
|
|
604
|
-
var CMS_MODULE_COMPONENT_NAME = "
|
|
605
|
+
var CMS_MODULE_COMPONENT_NAME = "Module";
|
|
605
606
|
function findCmsModules(cmsModules = {}) {
|
|
606
607
|
let config;
|
|
607
608
|
return {
|
|
@@ -621,32 +622,32 @@ function findCmsModules(cmsModules = {}) {
|
|
|
621
622
|
sourceType: "module",
|
|
622
623
|
plugins: ["jsx", "typescript"]
|
|
623
624
|
});
|
|
624
|
-
let
|
|
625
|
+
let moduleLocalImportName = CMS_MODULE_COMPONENT_NAME;
|
|
625
626
|
const pluginError = this.error.bind(this);
|
|
626
627
|
traverse(sourceAst, {
|
|
627
|
-
ImportDeclaration(
|
|
628
|
-
if (!t.isStringLiteral(
|
|
628
|
+
ImportDeclaration(path11) {
|
|
629
|
+
if (!t.isStringLiteral(path11.node.source, {
|
|
629
630
|
value: "@hubspot/cms-components"
|
|
630
631
|
})) {
|
|
631
632
|
return null;
|
|
632
633
|
}
|
|
633
|
-
for (const specifier of
|
|
634
|
+
for (const specifier of path11.node.specifiers) {
|
|
634
635
|
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
|
|
635
636
|
name: CMS_MODULE_COMPONENT_NAME
|
|
636
637
|
})) {
|
|
637
|
-
|
|
638
|
+
moduleLocalImportName = specifier.local.name;
|
|
638
639
|
}
|
|
639
640
|
}
|
|
640
641
|
},
|
|
641
|
-
JSXOpeningElement(
|
|
642
|
-
if (!t.isJSXIdentifier(
|
|
643
|
-
name:
|
|
644
|
-
}) ||
|
|
642
|
+
JSXOpeningElement(path11) {
|
|
643
|
+
if (!t.isJSXIdentifier(path11.node.name, {
|
|
644
|
+
name: moduleLocalImportName
|
|
645
|
+
}) || path11.node.attributes.length !== 2) {
|
|
645
646
|
return null;
|
|
646
647
|
}
|
|
647
648
|
let cmsModuleName;
|
|
648
649
|
let cmsModulePath;
|
|
649
|
-
for (const prop of
|
|
650
|
+
for (const prop of path11.node.attributes) {
|
|
650
651
|
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
651
652
|
cmsModuleName = prop.value.value;
|
|
652
653
|
continue;
|
|
@@ -1193,7 +1194,7 @@ var getIslandRuntimeAndGlobalToInject = async (sortedIslandRoots, perServerReque
|
|
|
1193
1194
|
};
|
|
1194
1195
|
|
|
1195
1196
|
// src/routes/partial.ts
|
|
1196
|
-
import { buildStaticEnvConfig } from "@hubspot/cms-components";
|
|
1197
|
+
import { buildStaticEnvConfig as buildStaticEnvConfig3 } from "@hubspot/cms-components";
|
|
1197
1198
|
|
|
1198
1199
|
// src/lib/trackUsage.ts
|
|
1199
1200
|
import localDevHttpImport from "@hubspot/local-dev-lib/http";
|
|
@@ -1232,7 +1233,7 @@ function trackUsage(action) {
|
|
|
1232
1233
|
eventName: EVENT_NAME,
|
|
1233
1234
|
action,
|
|
1234
1235
|
nodeVersion: getNodeVersionData(),
|
|
1235
|
-
version: "0.16.
|
|
1236
|
+
version: "0.16.12",
|
|
1236
1237
|
os: getPlatform()
|
|
1237
1238
|
};
|
|
1238
1239
|
const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -1270,162 +1271,113 @@ function sendTrackingRequest(action) {
|
|
|
1270
1271
|
});
|
|
1271
1272
|
}
|
|
1272
1273
|
|
|
1273
|
-
// src/
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
authedPortalId,
|
|
1278
|
-
authedEnv,
|
|
1279
|
-
authedHublet,
|
|
1280
|
-
webRoot: webRoot2,
|
|
1281
|
-
viteServer,
|
|
1282
|
-
jsRenderingGates,
|
|
1283
|
-
projectName,
|
|
1284
|
-
projectComponentPath
|
|
1285
|
-
} = request2.app.locals;
|
|
1286
|
-
const partialName = request2.params.partial;
|
|
1287
|
-
const baseTemplatePath = packagePath(
|
|
1288
|
-
import.meta.url,
|
|
1289
|
-
"html/baseTemplate.html"
|
|
1290
|
-
);
|
|
1291
|
-
const partialPath = normalizePath2(
|
|
1292
|
-
path3.resolve(webRoot2, "components/partials/", partialName)
|
|
1293
|
-
);
|
|
1294
|
-
const entrypointPath = normalizePath2(
|
|
1295
|
-
[
|
|
1296
|
-
"@projects",
|
|
1297
|
-
projectName,
|
|
1298
|
-
projectComponentPath,
|
|
1299
|
-
"components/modules/",
|
|
1300
|
-
partialName
|
|
1301
|
-
].join("/")
|
|
1302
|
-
);
|
|
1303
|
-
const basePath = getEntryPointBasePath(partialPath);
|
|
1304
|
-
const environmentConfig = buildStaticEnvConfig(
|
|
1305
|
-
authedPortalId,
|
|
1306
|
-
authedHublet,
|
|
1307
|
-
authedEnv,
|
|
1308
|
-
false,
|
|
1309
|
-
jsRenderingGates
|
|
1310
|
-
);
|
|
1311
|
-
try {
|
|
1312
|
-
const {
|
|
1313
|
-
html: renderedHtml,
|
|
1314
|
-
cssNeeded,
|
|
1315
|
-
renderContext,
|
|
1316
|
-
inlineAssets
|
|
1317
|
-
} = await renderPartial_default(
|
|
1318
|
-
viteServer,
|
|
1319
|
-
partialPath,
|
|
1320
|
-
{},
|
|
1321
|
-
fullOriginalUrlFromRequest(request2),
|
|
1322
|
-
basePath,
|
|
1323
|
-
environmentConfig,
|
|
1324
|
-
{
|
|
1325
|
-
identifierPrefix: getEntryPointHash(entrypointPath)
|
|
1326
|
-
}
|
|
1327
|
-
);
|
|
1328
|
-
const htmlShell = await createHtmlShellDependingOnRenderContext(
|
|
1329
|
-
baseTemplatePath,
|
|
1330
|
-
request2.originalUrl,
|
|
1331
|
-
`Partial: ${partialPath}`,
|
|
1332
|
-
renderContext,
|
|
1333
|
-
viteServer,
|
|
1334
|
-
jsRenderingGates
|
|
1335
|
-
);
|
|
1336
|
-
const html = htmlShell.replace(
|
|
1337
|
-
"<!--headend-->",
|
|
1338
|
-
[
|
|
1339
|
-
cssNeeded,
|
|
1340
|
-
...inlineAssets.map((inlineAsset) => inlineAsset.html)
|
|
1341
|
-
].join("\n")
|
|
1342
|
-
).replace(`<!--ssr-outlet-->`, renderedHtml);
|
|
1343
|
-
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
1344
|
-
} catch (e) {
|
|
1345
|
-
console.error(e);
|
|
1346
|
-
viteServer.ssrFixStacktrace(e);
|
|
1347
|
-
response.status(500).end(`Error rendering partial (${partialName})
|
|
1274
|
+
// src/lib/renderModulePreview.ts
|
|
1275
|
+
import { buildStaticEnvConfig as buildStaticEnvConfig2 } from "@hubspot/cms-components";
|
|
1276
|
+
import path4 from "path";
|
|
1277
|
+
import { normalizePath as normalizePath3 } from "vite";
|
|
1348
1278
|
|
|
1349
|
-
|
|
1279
|
+
// src/lib/proxyHelpers.ts
|
|
1280
|
+
import fs2 from "fs";
|
|
1281
|
+
import { resolve as resolve2 } from "path";
|
|
1282
|
+
import { unescape } from "html-escaper";
|
|
1283
|
+
var localJsRenderStartString = '<!-- proxy local render of "';
|
|
1284
|
+
var localJsRenderEndString = "end proxy local render -->";
|
|
1285
|
+
function isRecord(value) {
|
|
1286
|
+
return typeof value === "object" && value !== null;
|
|
1287
|
+
}
|
|
1288
|
+
var findLocalRenderPlaceholders = (body) => {
|
|
1289
|
+
let offsetSoFar = 0;
|
|
1290
|
+
const result = [];
|
|
1291
|
+
while (offsetSoFar < body.length && offsetSoFar !== -1) {
|
|
1292
|
+
const startOffset = body.indexOf(localJsRenderStartString, offsetSoFar);
|
|
1293
|
+
offsetSoFar = startOffset;
|
|
1294
|
+
if (startOffset >= 0) {
|
|
1295
|
+
const nextNewlineOffset = body.indexOf(
|
|
1296
|
+
"\n",
|
|
1297
|
+
startOffset + localJsRenderStartString.length
|
|
1298
|
+
);
|
|
1299
|
+
const pathEndOffset = body.indexOf(
|
|
1300
|
+
'"',
|
|
1301
|
+
startOffset + localJsRenderStartString.length
|
|
1302
|
+
);
|
|
1303
|
+
const nearestNewlineOrQuoteAfterBlockOpen = Math.min(
|
|
1304
|
+
nextNewlineOffset,
|
|
1305
|
+
pathEndOffset
|
|
1306
|
+
);
|
|
1307
|
+
offsetSoFar = nearestNewlineOrQuoteAfterBlockOpen;
|
|
1308
|
+
if (pathEndOffset >= 0 && pathEndOffset < nextNewlineOffset) {
|
|
1309
|
+
const path11 = body.substring(
|
|
1310
|
+
startOffset + localJsRenderStartString.length,
|
|
1311
|
+
pathEndOffset
|
|
1312
|
+
);
|
|
1313
|
+
offsetSoFar = pathEndOffset + 1;
|
|
1314
|
+
if (startOffset >= 0 && path11) {
|
|
1315
|
+
const nextCommentEndOffset = body.indexOf("-->", pathEndOffset);
|
|
1316
|
+
const endOffset = body.indexOf(localJsRenderEndString, pathEndOffset);
|
|
1317
|
+
offsetSoFar = Math.min(nextCommentEndOffset, endOffset);
|
|
1318
|
+
if (endOffset >= startOffset && endOffset < nextCommentEndOffset) {
|
|
1319
|
+
const jsonString = body.substring(pathEndOffset + 1, endOffset).trim();
|
|
1320
|
+
try {
|
|
1321
|
+
let json;
|
|
1322
|
+
try {
|
|
1323
|
+
json = JSON.parse(unescape(jsonString));
|
|
1324
|
+
} catch (e) {
|
|
1325
|
+
json = JSON.parse(jsonString);
|
|
1326
|
+
}
|
|
1327
|
+
if (!isRecord(json.request)) {
|
|
1328
|
+
console.error(
|
|
1329
|
+
`Invalid JSON inside <!-- proxy local render .. --> string (missing request key)`
|
|
1330
|
+
);
|
|
1331
|
+
} else if (!isRecord(json.props)) {
|
|
1332
|
+
console.error(
|
|
1333
|
+
`Invalid JSON inside <!-- proxy local render .. --> string (missing props key)`
|
|
1334
|
+
);
|
|
1335
|
+
} else {
|
|
1336
|
+
result.push({
|
|
1337
|
+
startOffset,
|
|
1338
|
+
endOffset: endOffset + localJsRenderEndString.length,
|
|
1339
|
+
path: path11,
|
|
1340
|
+
json
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
offsetSoFar = endOffset + localJsRenderEndString.length;
|
|
1344
|
+
} catch (e) {
|
|
1345
|
+
console.error(
|
|
1346
|
+
`Invalid JSON inside <!-- proxy local render .. --> string (around offset ${pathEndOffset})`
|
|
1347
|
+
);
|
|
1348
|
+
offsetSoFar = endOffset;
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1350
1354
|
}
|
|
1355
|
+
return result;
|
|
1351
1356
|
};
|
|
1352
|
-
var
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
"components/partials"
|
|
1362
|
-
] })
|
|
1363
|
-
] });
|
|
1364
|
-
}
|
|
1365
|
-
function PartialLinkInLI({ partialName }) {
|
|
1366
|
-
return /* @__PURE__ */ jsx2("li", { children: /* @__PURE__ */ jsx2("a", { href: `/partial/${partialName}`, children: partialName }) });
|
|
1367
|
-
}
|
|
1368
|
-
function PartialsList({ webRoot: webRoot2, partialNames }) {
|
|
1369
|
-
if (partialNames.length === 0) {
|
|
1370
|
-
return /* @__PURE__ */ jsx2(EmptyPartialsList, { webRoot: webRoot2 });
|
|
1357
|
+
var getHSProjectConfig = (hsProjectConfigPath) => {
|
|
1358
|
+
try {
|
|
1359
|
+
return JSON.parse(fs2.readFileSync(hsProjectConfigPath, "utf8"));
|
|
1360
|
+
} catch (e) {
|
|
1361
|
+
console.warn(
|
|
1362
|
+
`Missing hsproject.json file (${resolve2(hsProjectConfigPath)}): `,
|
|
1363
|
+
e.message
|
|
1364
|
+
);
|
|
1365
|
+
return null;
|
|
1371
1366
|
}
|
|
1372
|
-
return /* @__PURE__ */ jsx2("ul", { children: partialNames.map((partialName) => /* @__PURE__ */ jsx2(PartialLinkInLI, { partialName }, partialName)) });
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
|
-
// src/routes/linksToAllPartialsRouteHandler.tsx
|
|
1376
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
1377
|
-
var linksToAllPartialRouteHandler = async (request2, response) => {
|
|
1378
|
-
const { webRoot: webRoot2 } = request2.app.locals;
|
|
1379
|
-
const { partialNames } = findAllPartialsInRoot(webRoot2);
|
|
1380
|
-
const { html: responseHtml } = await renderOnServer(
|
|
1381
|
-
/* @__PURE__ */ jsx3(PartialsList, { webRoot: webRoot2, partialNames })
|
|
1382
|
-
);
|
|
1383
|
-
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
1384
1367
|
};
|
|
1385
|
-
var
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
function EmptyModulesList({ webRoot: webRoot2 }) {
|
|
1390
|
-
return /* @__PURE__ */ jsxs2("p", { children: [
|
|
1391
|
-
"No modules in ",
|
|
1392
|
-
/* @__PURE__ */ jsxs2("code", { children: [
|
|
1393
|
-
webRoot2,
|
|
1394
|
-
"components/modules"
|
|
1395
|
-
] })
|
|
1396
|
-
] });
|
|
1397
|
-
}
|
|
1398
|
-
function ModuleLinkInLI({ moduleName }) {
|
|
1399
|
-
return /* @__PURE__ */ jsxs2("li", { children: [
|
|
1400
|
-
/* @__PURE__ */ jsx4("a", { href: `/preview/module/${moduleName}`, children: moduleName }),
|
|
1401
|
-
" / ",
|
|
1402
|
-
/* @__PURE__ */ jsx4("a", { href: `/module/${moduleName}`, children: "Local Version" })
|
|
1403
|
-
] });
|
|
1404
|
-
}
|
|
1405
|
-
function ModulesList({ webRoot: webRoot2, moduleNames }) {
|
|
1406
|
-
if (moduleNames.length === 0) {
|
|
1407
|
-
return /* @__PURE__ */ jsx4(EmptyModulesList, { webRoot: webRoot2 });
|
|
1368
|
+
var getProjectNameFromHSConfig = (hsProjectConfigPath) => {
|
|
1369
|
+
const hsProjectConfig = getHSProjectConfig(hsProjectConfigPath);
|
|
1370
|
+
if (hsProjectConfig) {
|
|
1371
|
+
return hsProjectConfig.name;
|
|
1408
1372
|
}
|
|
1409
|
-
|
|
1410
|
-
}
|
|
1411
|
-
var ModulesList_default = ModulesList;
|
|
1412
|
-
|
|
1413
|
-
// src/routes/linksToAllModulesRouteHandler.tsx
|
|
1414
|
-
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
1415
|
-
var linksToAllModuleRouteHandler = async (request2, response) => {
|
|
1416
|
-
const { webRoot: webRoot2 } = request2.app.locals;
|
|
1417
|
-
const { moduleNames } = findAllModulesInRoot(webRoot2);
|
|
1418
|
-
const { html: responseHtml } = await renderOnServer(
|
|
1419
|
-
/* @__PURE__ */ jsx5(ModulesList_default, { webRoot: webRoot2, moduleNames })
|
|
1420
|
-
);
|
|
1421
|
-
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
1373
|
+
throw new Error("hsproject.json file not found");
|
|
1422
1374
|
};
|
|
1423
|
-
var linksToAllModulesRouteHandler_default = linksToAllModuleRouteHandler;
|
|
1424
1375
|
|
|
1425
|
-
// src/
|
|
1426
|
-
import
|
|
1427
|
-
import
|
|
1428
|
-
import {
|
|
1376
|
+
// src/proxyPage/proxyPage.ts
|
|
1377
|
+
import path3 from "path";
|
|
1378
|
+
import { normalizePath as normalizePath2 } from "vite";
|
|
1379
|
+
import { getAccountId, getEnv } from "@hubspot/local-dev-lib/config";
|
|
1380
|
+
import localDevHttpImport5 from "@hubspot/local-dev-lib/http";
|
|
1429
1381
|
|
|
1430
1382
|
// src/lib/renderModule.ts
|
|
1431
1383
|
import { join as joinPosix2 } from "path/posix";
|
|
@@ -1640,392 +1592,95 @@ function getFieldValuesForModule(fieldsJSON, fieldOverrides = {}) {
|
|
|
1640
1592
|
}
|
|
1641
1593
|
var renderModule_default = renderModule;
|
|
1642
1594
|
|
|
1643
|
-
// src/
|
|
1644
|
-
|
|
1645
|
-
sendTrackingRequest("view-module-route");
|
|
1646
|
-
const {
|
|
1647
|
-
authedPortalId,
|
|
1648
|
-
authedEnv,
|
|
1649
|
-
authedHublet,
|
|
1650
|
-
webRoot: webRoot2,
|
|
1651
|
-
viteServer,
|
|
1652
|
-
jsRenderingGates,
|
|
1653
|
-
projectName,
|
|
1654
|
-
projectComponentPath
|
|
1655
|
-
} = request2.app.locals;
|
|
1656
|
-
const moduleName = request2.params.moduleName;
|
|
1657
|
-
const baseTemplatePath = packagePath(
|
|
1658
|
-
import.meta.url,
|
|
1659
|
-
"html/baseTemplate.html"
|
|
1660
|
-
);
|
|
1661
|
-
const modulePath = normalizePath3(
|
|
1662
|
-
path4.resolve(webRoot2, "components/modules/", moduleName)
|
|
1663
|
-
);
|
|
1664
|
-
const entrypointPath = normalizePath3(
|
|
1665
|
-
[
|
|
1666
|
-
"@projects",
|
|
1667
|
-
projectName,
|
|
1668
|
-
projectComponentPath,
|
|
1669
|
-
"components/modules/",
|
|
1670
|
-
moduleName
|
|
1671
|
-
].join("/")
|
|
1672
|
-
);
|
|
1673
|
-
let fieldOverrides = null;
|
|
1674
|
-
if (request2.query.fields) {
|
|
1675
|
-
try {
|
|
1676
|
-
if (typeof request2.query.fields === "string") {
|
|
1677
|
-
fieldOverrides = JSON.parse(
|
|
1678
|
-
decodeURIComponent(request2.query.fields.replace(/\+/g, "%20"))
|
|
1679
|
-
);
|
|
1680
|
-
}
|
|
1681
|
-
} catch (e) {
|
|
1682
|
-
console.error(
|
|
1683
|
-
`Error parsing field param for module ${moduleName}: ${request2.query.fields}`
|
|
1684
|
-
);
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
const basePath = getEntryPointBasePath(modulePath);
|
|
1688
|
-
const environmentConfig = buildStaticEnvConfig2(
|
|
1689
|
-
authedPortalId,
|
|
1690
|
-
authedHublet,
|
|
1691
|
-
authedEnv,
|
|
1692
|
-
false,
|
|
1693
|
-
jsRenderingGates
|
|
1694
|
-
);
|
|
1695
|
-
try {
|
|
1696
|
-
const {
|
|
1697
|
-
html: renderedHtml,
|
|
1698
|
-
cssNeeded,
|
|
1699
|
-
renderContext,
|
|
1700
|
-
inlineAssets
|
|
1701
|
-
} = await renderModule_default(
|
|
1702
|
-
viteServer,
|
|
1703
|
-
modulePath,
|
|
1704
|
-
{
|
|
1705
|
-
fieldValues: fieldOverrides,
|
|
1706
|
-
hublParameters: {},
|
|
1707
|
-
moduleName: `local-${moduleName}`
|
|
1708
|
-
},
|
|
1709
|
-
fullOriginalUrlFromRequest(request2),
|
|
1710
|
-
basePath,
|
|
1711
|
-
environmentConfig,
|
|
1712
|
-
{
|
|
1713
|
-
identifierPrefix: getEntryPointHash(entrypointPath)
|
|
1714
|
-
}
|
|
1715
|
-
);
|
|
1716
|
-
const htmlShell = await createHtmlShellDependingOnRenderContext(
|
|
1717
|
-
baseTemplatePath,
|
|
1718
|
-
request2.originalUrl,
|
|
1719
|
-
`Module: ${modulePath}`,
|
|
1720
|
-
renderContext,
|
|
1721
|
-
viteServer,
|
|
1722
|
-
jsRenderingGates
|
|
1723
|
-
);
|
|
1724
|
-
const html = htmlShell.replace(
|
|
1725
|
-
"<!--headend-->",
|
|
1726
|
-
[
|
|
1727
|
-
cssNeeded,
|
|
1728
|
-
...inlineAssets.map((inlineAsset) => inlineAsset.html)
|
|
1729
|
-
].join("\n")
|
|
1730
|
-
).replace(`<!--ssr-outlet-->`, renderedHtml);
|
|
1731
|
-
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
1732
|
-
} catch (e) {
|
|
1733
|
-
console.error(e);
|
|
1734
|
-
viteServer.ssrFixStacktrace(e);
|
|
1735
|
-
response.status(500).end(`Error rendering module (${moduleName})
|
|
1595
|
+
// src/proxyPage/utils.ts
|
|
1596
|
+
import { createEmptyServerRenderContext } from "@hubspot/cms-components";
|
|
1736
1597
|
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
};
|
|
1740
|
-
var module_default = moduleRouteHandler;
|
|
1598
|
+
// src/proxyPage/constants.ts
|
|
1599
|
+
var VALID_PROXY_DOMAIN_SUFFIXES = ["localhost", "hslocal.net"];
|
|
1741
1600
|
|
|
1742
|
-
// src/proxyPage/
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
throw new Error(
|
|
1749
|
-
`Hit too many redirects to HEAD requests for ${originalUrl}`
|
|
1750
|
-
);
|
|
1601
|
+
// src/proxyPage/utils.ts
|
|
1602
|
+
var getSubDomainFromValidLocalDomain = (hostname) => {
|
|
1603
|
+
for (const validProxyDomainSuffix of VALID_PROXY_DOMAIN_SUFFIXES) {
|
|
1604
|
+
if (hostname.endsWith(`.${validProxyDomainSuffix}`)) {
|
|
1605
|
+
return hostname.slice(0, -1 * validProxyDomainSuffix.length - 1);
|
|
1606
|
+
}
|
|
1751
1607
|
}
|
|
1608
|
+
return void 0;
|
|
1609
|
+
};
|
|
1610
|
+
var randomStringWithLotsOf = (char, maxLength) => {
|
|
1611
|
+
return new Array(Math.floor(Math.random() * maxLength)).fill(char).join("");
|
|
1612
|
+
};
|
|
1613
|
+
var fakeRenderJsComponent = (indexForThisRender) => {
|
|
1752
1614
|
return new Promise((resolve3, reject) => {
|
|
1753
|
-
const
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
const isContentMembershipRedirect = Boolean(
|
|
1767
|
-
res.headers["x-hs-content-membership-redirect"]
|
|
1768
|
-
);
|
|
1769
|
-
if (isContentMembershipRedirect) {
|
|
1770
|
-
debug("Content Membership Redirect", res.headers);
|
|
1771
|
-
portalIdHeader = res.headers["x-hs-portal-id"];
|
|
1772
|
-
contentId = res.headers["x-hs-content-id"];
|
|
1773
|
-
if (portalIdHeader && contentId) {
|
|
1774
|
-
return resolve3({
|
|
1775
|
-
portalIdHeader,
|
|
1776
|
-
contentId,
|
|
1777
|
-
res
|
|
1778
|
-
});
|
|
1779
|
-
}
|
|
1780
|
-
}
|
|
1781
|
-
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
1782
|
-
console.log(`Redirecting to ${res.headers.location} (from ${url3})`);
|
|
1783
|
-
return resolve3(
|
|
1784
|
-
requestPage(
|
|
1785
|
-
res.headers.location,
|
|
1786
|
-
redirects + 1,
|
|
1787
|
-
originalUrl ?? url3
|
|
1788
|
-
)
|
|
1789
|
-
);
|
|
1790
|
-
}
|
|
1791
|
-
portalIdHeader = res.headers["x-hs-hub-id"];
|
|
1792
|
-
contentId = res.headers["x-hs-content-id"];
|
|
1793
|
-
return resolve3({
|
|
1794
|
-
res,
|
|
1795
|
-
portalIdHeader,
|
|
1796
|
-
contentId
|
|
1615
|
+
const randomTimeout = Math.floor(Math.random() * 200) + indexForThisRender * 1e3;
|
|
1616
|
+
setTimeout(() => {
|
|
1617
|
+
try {
|
|
1618
|
+
const fakeJsRenderedOutput = `<div data-js-rendered>JS render #${indexForThisRender + 1} (${randomTimeout}ms delay) ${randomStringWithLotsOf(
|
|
1619
|
+
"?",
|
|
1620
|
+
100
|
|
1621
|
+
)}</div>
|
|
1622
|
+
`;
|
|
1623
|
+
resolve3({
|
|
1624
|
+
html: fakeJsRenderedOutput,
|
|
1625
|
+
cssNeeded: "",
|
|
1626
|
+
renderContext: createEmptyServerRenderContext(),
|
|
1627
|
+
inlineAssets: []
|
|
1797
1628
|
});
|
|
1629
|
+
} catch (e) {
|
|
1630
|
+
console.log("Error with JS render...");
|
|
1631
|
+
console.error(e);
|
|
1632
|
+
reject();
|
|
1798
1633
|
}
|
|
1799
|
-
|
|
1800
|
-
console.error(err);
|
|
1801
|
-
reject(err);
|
|
1802
|
-
}).end();
|
|
1634
|
+
}, randomTimeout);
|
|
1803
1635
|
});
|
|
1804
|
-
}
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1636
|
+
};
|
|
1637
|
+
var consoleWarn = (message) => {
|
|
1638
|
+
console.warn("\x1B[33m%s\x1B[0m", "WARNING:", message);
|
|
1639
|
+
};
|
|
1640
|
+
|
|
1641
|
+
// src/proxyPage/renderLocalError.ts
|
|
1642
|
+
import AnsiToHtmlConverter from "ansi-to-html";
|
|
1643
|
+
var customColors = [
|
|
1644
|
+
// Normal colors
|
|
1645
|
+
"#000",
|
|
1646
|
+
// black
|
|
1647
|
+
"#ec392c",
|
|
1648
|
+
// red
|
|
1649
|
+
"#b3e439",
|
|
1650
|
+
// green
|
|
1651
|
+
"#fea525",
|
|
1652
|
+
// yellow
|
|
1653
|
+
"#76dff3",
|
|
1654
|
+
// blue
|
|
1655
|
+
"#fd4285",
|
|
1656
|
+
// magenta
|
|
1657
|
+
"#cfa3ff",
|
|
1658
|
+
// cyan
|
|
1659
|
+
"#f4f4f4",
|
|
1660
|
+
// White
|
|
1661
|
+
// Bright colors (mostly identical to ^)
|
|
1662
|
+
"#646464",
|
|
1663
|
+
"#ec392c",
|
|
1664
|
+
"#fea525",
|
|
1665
|
+
"#76dff3",
|
|
1666
|
+
"#fd4285",
|
|
1667
|
+
"#cfa3ff",
|
|
1668
|
+
"#f4f4f4"
|
|
1669
|
+
];
|
|
1670
|
+
var Converter = new AnsiToHtmlConverter({ colors: customColors });
|
|
1671
|
+
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;`;
|
|
1672
|
+
var renderLocalError_default = (path11, error) => {
|
|
1673
|
+
const stackWithColorClasses = Converter.toHtml(error.stack);
|
|
1674
|
+
return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${path11}<br/><br/><code><pre>${stackWithColorClasses}</pre></code></div>`;
|
|
1675
|
+
};
|
|
1676
|
+
|
|
1677
|
+
// src/proxyPage/fetchPreviewInfo.ts
|
|
1678
|
+
import localDevHttpImport4 from "@hubspot/local-dev-lib/http";
|
|
1679
|
+
var { default: hsCliHttp4 } = localDevHttpImport4;
|
|
1680
|
+
var fetchPreviewInfo_default = async (accountId, portalId, contentId) => {
|
|
1681
|
+
if (!contentId) {
|
|
1808
1682
|
throw new Error(
|
|
1809
|
-
`
|
|
1810
|
-
);
|
|
1811
|
-
} else {
|
|
1812
|
-
const portalIdFromResponse = parseInt(portalIdHeader, 10);
|
|
1813
|
-
const pageAccount = await getAccountId(portalIdFromResponse);
|
|
1814
|
-
if (!pageAccount) {
|
|
1815
|
-
throw new Error(
|
|
1816
|
-
`No CLI auth for portal ${portalIdFromResponse} found, please run \`hs auth\``
|
|
1817
|
-
);
|
|
1818
|
-
}
|
|
1819
|
-
if (res.statusCode !== 200 && !(portalIdFromResponse && pageAccount && contentId)) {
|
|
1820
|
-
throw new Error(
|
|
1821
|
-
`${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.` : ""}`
|
|
1822
|
-
);
|
|
1823
|
-
} else if (!portalId || !contentId) {
|
|
1824
|
-
throw new Error(
|
|
1825
|
-
`Missing hub ID or content ID headers on HEAD request to ${url3}`
|
|
1826
|
-
);
|
|
1827
|
-
} else if (isNaN(portalId)) {
|
|
1828
|
-
throw new Error(
|
|
1829
|
-
`Hub ID from the HEAD request is not a number: '${portalId}' (${url3})`
|
|
1830
|
-
);
|
|
1831
|
-
}
|
|
1832
|
-
const hublet = "na1";
|
|
1833
|
-
return { portalId, contentId, hublet };
|
|
1834
|
-
}
|
|
1835
|
-
}
|
|
1836
|
-
|
|
1837
|
-
// src/proxyPage/proxyPage.ts
|
|
1838
|
-
import path5 from "path";
|
|
1839
|
-
import { normalizePath as normalizePath4 } from "vite";
|
|
1840
|
-
import { getAccountId as getAccountId2, getEnv } from "@hubspot/local-dev-lib/config";
|
|
1841
|
-
import localDevHttpImport5 from "@hubspot/local-dev-lib/http";
|
|
1842
|
-
|
|
1843
|
-
// src/lib/proxyHelpers.ts
|
|
1844
|
-
import fs2 from "fs";
|
|
1845
|
-
import { resolve as resolve2 } from "path";
|
|
1846
|
-
import { unescape } from "html-escaper";
|
|
1847
|
-
var localJsRenderStartString = '<!-- proxy local render of "';
|
|
1848
|
-
var localJsRenderEndString = "end proxy local render -->";
|
|
1849
|
-
function isRecord(value) {
|
|
1850
|
-
return typeof value === "object" && value !== null;
|
|
1851
|
-
}
|
|
1852
|
-
var findLocalRenderPlaceholders = (body) => {
|
|
1853
|
-
let offsetSoFar = 0;
|
|
1854
|
-
const result = [];
|
|
1855
|
-
while (offsetSoFar < body.length && offsetSoFar !== -1) {
|
|
1856
|
-
const startOffset = body.indexOf(localJsRenderStartString, offsetSoFar);
|
|
1857
|
-
offsetSoFar = startOffset;
|
|
1858
|
-
if (startOffset >= 0) {
|
|
1859
|
-
const nextNewlineOffset = body.indexOf(
|
|
1860
|
-
"\n",
|
|
1861
|
-
startOffset + localJsRenderStartString.length
|
|
1862
|
-
);
|
|
1863
|
-
const pathEndOffset = body.indexOf(
|
|
1864
|
-
'"',
|
|
1865
|
-
startOffset + localJsRenderStartString.length
|
|
1866
|
-
);
|
|
1867
|
-
const nearestNewlineOrQuoteAfterBlockOpen = Math.min(
|
|
1868
|
-
nextNewlineOffset,
|
|
1869
|
-
pathEndOffset
|
|
1870
|
-
);
|
|
1871
|
-
offsetSoFar = nearestNewlineOrQuoteAfterBlockOpen;
|
|
1872
|
-
if (pathEndOffset >= 0 && pathEndOffset < nextNewlineOffset) {
|
|
1873
|
-
const path10 = body.substring(
|
|
1874
|
-
startOffset + localJsRenderStartString.length,
|
|
1875
|
-
pathEndOffset
|
|
1876
|
-
);
|
|
1877
|
-
offsetSoFar = pathEndOffset + 1;
|
|
1878
|
-
if (startOffset >= 0 && path10) {
|
|
1879
|
-
const nextCommentEndOffset = body.indexOf("-->", pathEndOffset);
|
|
1880
|
-
const endOffset = body.indexOf(localJsRenderEndString, pathEndOffset);
|
|
1881
|
-
offsetSoFar = Math.min(nextCommentEndOffset, endOffset);
|
|
1882
|
-
if (endOffset >= startOffset && endOffset < nextCommentEndOffset) {
|
|
1883
|
-
const jsonString = body.substring(pathEndOffset + 1, endOffset).trim();
|
|
1884
|
-
try {
|
|
1885
|
-
let json;
|
|
1886
|
-
try {
|
|
1887
|
-
json = JSON.parse(unescape(jsonString));
|
|
1888
|
-
} catch (e) {
|
|
1889
|
-
json = JSON.parse(jsonString);
|
|
1890
|
-
}
|
|
1891
|
-
if (!isRecord(json.request)) {
|
|
1892
|
-
console.error(
|
|
1893
|
-
`Invalid JSON inside <!-- proxy local render .. --> string (missing request key)`
|
|
1894
|
-
);
|
|
1895
|
-
} else if (!isRecord(json.props)) {
|
|
1896
|
-
console.error(
|
|
1897
|
-
`Invalid JSON inside <!-- proxy local render .. --> string (missing props key)`
|
|
1898
|
-
);
|
|
1899
|
-
} else {
|
|
1900
|
-
result.push({
|
|
1901
|
-
startOffset,
|
|
1902
|
-
endOffset: endOffset + localJsRenderEndString.length,
|
|
1903
|
-
path: path10,
|
|
1904
|
-
json
|
|
1905
|
-
});
|
|
1906
|
-
}
|
|
1907
|
-
offsetSoFar = endOffset + localJsRenderEndString.length;
|
|
1908
|
-
} catch (e) {
|
|
1909
|
-
console.error(
|
|
1910
|
-
`Invalid JSON inside <!-- proxy local render .. --> string (around offset ${pathEndOffset})`
|
|
1911
|
-
);
|
|
1912
|
-
offsetSoFar = endOffset;
|
|
1913
|
-
}
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
}
|
|
1918
|
-
}
|
|
1919
|
-
return result;
|
|
1920
|
-
};
|
|
1921
|
-
var getHSProjectConfig = (hsProjectConfigPath) => {
|
|
1922
|
-
try {
|
|
1923
|
-
return JSON.parse(fs2.readFileSync(hsProjectConfigPath, "utf8"));
|
|
1924
|
-
} catch (e) {
|
|
1925
|
-
console.warn(
|
|
1926
|
-
`Missing hsproject.json file (${resolve2(hsProjectConfigPath)}): `,
|
|
1927
|
-
e.message
|
|
1928
|
-
);
|
|
1929
|
-
return null;
|
|
1930
|
-
}
|
|
1931
|
-
};
|
|
1932
|
-
var getProjectNameFromHSConfig = (hsProjectConfigPath) => {
|
|
1933
|
-
const hsProjectConfig = getHSProjectConfig(hsProjectConfigPath);
|
|
1934
|
-
if (hsProjectConfig) {
|
|
1935
|
-
return hsProjectConfig.name;
|
|
1936
|
-
}
|
|
1937
|
-
throw new Error("hsproject.json file not found");
|
|
1938
|
-
};
|
|
1939
|
-
|
|
1940
|
-
// src/proxyPage/utils.ts
|
|
1941
|
-
import { createEmptyServerRenderContext } from "@hubspot/cms-components";
|
|
1942
|
-
|
|
1943
|
-
// src/proxyPage/constants.ts
|
|
1944
|
-
var VALID_PROXY_DOMAIN_SUFFIXES = ["localhost", "hslocal.net"];
|
|
1945
|
-
|
|
1946
|
-
// src/proxyPage/utils.ts
|
|
1947
|
-
var getSubDomainFromValidLocalDomain = (hostname) => {
|
|
1948
|
-
for (const validProxyDomainSuffix of VALID_PROXY_DOMAIN_SUFFIXES) {
|
|
1949
|
-
if (hostname.endsWith(`.${validProxyDomainSuffix}`)) {
|
|
1950
|
-
return hostname.slice(0, -1 * validProxyDomainSuffix.length - 1);
|
|
1951
|
-
}
|
|
1952
|
-
}
|
|
1953
|
-
return void 0;
|
|
1954
|
-
};
|
|
1955
|
-
var randomStringWithLotsOf = (char, maxLength) => {
|
|
1956
|
-
return new Array(Math.floor(Math.random() * maxLength)).fill(char).join("");
|
|
1957
|
-
};
|
|
1958
|
-
var fakeRenderJsComponent = (indexForThisRender) => {
|
|
1959
|
-
return new Promise((resolve3, reject) => {
|
|
1960
|
-
const randomTimeout = Math.floor(Math.random() * 200) + indexForThisRender * 1e3;
|
|
1961
|
-
setTimeout(() => {
|
|
1962
|
-
try {
|
|
1963
|
-
const fakeJsRenderedOutput = `<div data-js-rendered>JS render #${indexForThisRender + 1} (${randomTimeout}ms delay) ${randomStringWithLotsOf(
|
|
1964
|
-
"?",
|
|
1965
|
-
100
|
|
1966
|
-
)}</div>
|
|
1967
|
-
`;
|
|
1968
|
-
resolve3({
|
|
1969
|
-
html: fakeJsRenderedOutput,
|
|
1970
|
-
cssNeeded: "",
|
|
1971
|
-
renderContext: createEmptyServerRenderContext(),
|
|
1972
|
-
inlineAssets: []
|
|
1973
|
-
});
|
|
1974
|
-
} catch (e) {
|
|
1975
|
-
console.log("Error with JS render...");
|
|
1976
|
-
console.error(e);
|
|
1977
|
-
reject();
|
|
1978
|
-
}
|
|
1979
|
-
}, randomTimeout);
|
|
1980
|
-
});
|
|
1981
|
-
};
|
|
1982
|
-
var consoleWarn = (message) => {
|
|
1983
|
-
console.warn("\x1B[33m%s\x1B[0m", "WARNING:", message);
|
|
1984
|
-
};
|
|
1985
|
-
|
|
1986
|
-
// src/proxyPage/renderLocalError.ts
|
|
1987
|
-
import AnsiToHtmlConverter from "ansi-to-html";
|
|
1988
|
-
var customColors = [
|
|
1989
|
-
// Normal colors
|
|
1990
|
-
"#000",
|
|
1991
|
-
// black
|
|
1992
|
-
"#ec392c",
|
|
1993
|
-
// red
|
|
1994
|
-
"#b3e439",
|
|
1995
|
-
// green
|
|
1996
|
-
"#fea525",
|
|
1997
|
-
// yellow
|
|
1998
|
-
"#76dff3",
|
|
1999
|
-
// blue
|
|
2000
|
-
"#fd4285",
|
|
2001
|
-
// magenta
|
|
2002
|
-
"#cfa3ff",
|
|
2003
|
-
// cyan
|
|
2004
|
-
"#f4f4f4",
|
|
2005
|
-
// White
|
|
2006
|
-
// Bright colors (mostly identical to ^)
|
|
2007
|
-
"#646464",
|
|
2008
|
-
"#ec392c",
|
|
2009
|
-
"#fea525",
|
|
2010
|
-
"#76dff3",
|
|
2011
|
-
"#fd4285",
|
|
2012
|
-
"#cfa3ff",
|
|
2013
|
-
"#f4f4f4"
|
|
2014
|
-
];
|
|
2015
|
-
var Converter = new AnsiToHtmlConverter({ colors: customColors });
|
|
2016
|
-
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;`;
|
|
2017
|
-
var renderLocalError_default = (path10, error) => {
|
|
2018
|
-
const stackWithColorClasses = Converter.toHtml(error.stack);
|
|
2019
|
-
return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${path10}<br/><br/><code><pre>${stackWithColorClasses}</pre></code></div>`;
|
|
2020
|
-
};
|
|
2021
|
-
|
|
2022
|
-
// src/proxyPage/fetchPreviewInfo.ts
|
|
2023
|
-
import localDevHttpImport4 from "@hubspot/local-dev-lib/http";
|
|
2024
|
-
var { default: hsCliHttp4 } = localDevHttpImport4;
|
|
2025
|
-
var fetchPreviewInfo_default = async (accountId, portalId, contentId) => {
|
|
2026
|
-
if (!contentId) {
|
|
2027
|
-
throw new Error(
|
|
2028
|
-
`Invalid contentId when attempting to fetch preview info: ${contentId}`
|
|
1683
|
+
`Invalid contentId when attempting to fetch preview info: ${contentId}`
|
|
2029
1684
|
);
|
|
2030
1685
|
}
|
|
2031
1686
|
try {
|
|
@@ -2059,372 +1714,958 @@ ${error.error.message}`);
|
|
|
2059
1714
|
}
|
|
2060
1715
|
throw error;
|
|
2061
1716
|
}
|
|
2062
|
-
}
|
|
2063
|
-
};
|
|
1717
|
+
}
|
|
1718
|
+
};
|
|
1719
|
+
|
|
1720
|
+
// src/proxyPage/proxyPage.ts
|
|
1721
|
+
import {
|
|
1722
|
+
buildStaticEnvConfig,
|
|
1723
|
+
isDebugUrlString as isDebugUrlString3,
|
|
1724
|
+
mergeServerRequestData_internal
|
|
1725
|
+
} from "@hubspot/cms-components";
|
|
1726
|
+
var { default: hsCliHttp5 } = localDevHttpImport5;
|
|
1727
|
+
var getEntryPointBasePathFromProxyRequest = (request2) => {
|
|
1728
|
+
if (!request2) {
|
|
1729
|
+
return "";
|
|
1730
|
+
}
|
|
1731
|
+
const { path: requestPath, pathParamDict } = request2;
|
|
1732
|
+
if (!pathParamDict || !pathParamDict.dynamic_slug) {
|
|
1733
|
+
return requestPath;
|
|
1734
|
+
}
|
|
1735
|
+
return requestPath.replace(pathParamDict.dynamic_slug, "");
|
|
1736
|
+
};
|
|
1737
|
+
function resolvePlaceholderPath(placeholderPath, projectName, projectComponent) {
|
|
1738
|
+
if (!process.env.DEFAULT_MODULE_PATH_REWRITE) {
|
|
1739
|
+
return placeholderPath;
|
|
1740
|
+
}
|
|
1741
|
+
const mappedPlaceholderPath = `@projects/${projectName}/${projectComponent}/components/modules/${process.env.DEFAULT_MODULE_PATH_REWRITE.split(":")[1]}`;
|
|
1742
|
+
if (placeholderPath.startsWith(`@default-modules/${projectName}/`) && placeholderPath.endsWith(
|
|
1743
|
+
process.env.DEFAULT_MODULE_PATH_REWRITE.split(":")[0]
|
|
1744
|
+
)) {
|
|
1745
|
+
return mappedPlaceholderPath;
|
|
1746
|
+
}
|
|
1747
|
+
return placeholderPath;
|
|
1748
|
+
}
|
|
1749
|
+
var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, projectName, environmentConfig, __jsRenderingGates, cookieHeader) => {
|
|
1750
|
+
const url3 = new URL(urlToProxy);
|
|
1751
|
+
const renderPreviewLocally = url3.searchParams.has("renderPreviewLocally");
|
|
1752
|
+
let proxiedQueryParams = {};
|
|
1753
|
+
let baseURL = url3.origin;
|
|
1754
|
+
let pathname = url3.pathname;
|
|
1755
|
+
const PARAMS_TO_IGNORE = ["renderPreviewLocally"];
|
|
1756
|
+
const queryKeys = Array.from(url3.searchParams.keys()).filter(
|
|
1757
|
+
(queryKey) => !PARAMS_TO_IGNORE.includes(queryKey)
|
|
1758
|
+
);
|
|
1759
|
+
for (const queryKey of queryKeys) {
|
|
1760
|
+
const values = url3.searchParams.getAll(queryKey);
|
|
1761
|
+
if (values.length > 1) {
|
|
1762
|
+
proxiedQueryParams[queryKey] = values;
|
|
1763
|
+
} else {
|
|
1764
|
+
proxiedQueryParams[queryKey] = values[0];
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
const localProxyProject = process.env.DEFAULT_MODULE_PATH_REWRITE ? `@default-modules/${projectName}` : `@projects/${projectName}`;
|
|
1768
|
+
proxiedQueryParams = {
|
|
1769
|
+
...proxiedQueryParams,
|
|
1770
|
+
hs_preview: `${previewKey}-${contentId}`,
|
|
1771
|
+
hsLocalProxyProject: localProxyProject,
|
|
1772
|
+
localProxySchemaVersion: "2",
|
|
1773
|
+
hsLoginVerifyDisabled: `${true}`
|
|
1774
|
+
};
|
|
1775
|
+
if (renderPreviewLocally) {
|
|
1776
|
+
proxiedQueryParams.hsDebugOverridePublicHost = url3.host;
|
|
1777
|
+
baseURL = `http://local.hubspot${environmentConfig.getInternalHSEnv() === "qa" ? "qa" : ""}.com`;
|
|
1778
|
+
pathname = `/cos-rendering/v1/public${url3.pathname}`;
|
|
1779
|
+
}
|
|
1780
|
+
console.log(
|
|
1781
|
+
`Proxying request to ${baseURL}${pathname}?${new URLSearchParams({
|
|
1782
|
+
...proxiedQueryParams,
|
|
1783
|
+
previewKey,
|
|
1784
|
+
contentId
|
|
1785
|
+
}).toString()}`
|
|
1786
|
+
);
|
|
1787
|
+
const result = hsCliHttp5.get(accountId, {
|
|
1788
|
+
baseURL,
|
|
1789
|
+
url: pathname,
|
|
1790
|
+
params: proxiedQueryParams,
|
|
1791
|
+
responseType: "text",
|
|
1792
|
+
headers: {
|
|
1793
|
+
COOKIE: cookieHeader
|
|
1794
|
+
}
|
|
1795
|
+
});
|
|
1796
|
+
return result.catch((error) => {
|
|
1797
|
+
if (error.status >= 400 && error.status < 500 && !!error.response.data) {
|
|
1798
|
+
return error.response.data;
|
|
1799
|
+
} else {
|
|
1800
|
+
throw error;
|
|
1801
|
+
}
|
|
1802
|
+
});
|
|
1803
|
+
};
|
|
1804
|
+
function isRecord2(value) {
|
|
1805
|
+
return typeof value === "object" && value !== null;
|
|
1806
|
+
}
|
|
1807
|
+
function isModulePlaceholder(value) {
|
|
1808
|
+
return isRecord2(value) && isRecord2(value.json) && isRecord2(value.json.props) && isRecord2(value.json.props.fieldValues) && isRecord2(value.json.props.hublParameters);
|
|
1809
|
+
}
|
|
1810
|
+
var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder, webRoot2, viteServer, pageUrl, basePath, environmentConfig, hsProjectJsonProjectName, webRootProjectComponent) => {
|
|
1811
|
+
const placeholderPath = resolvePlaceholderPath(
|
|
1812
|
+
localRenderPlaceholder.path,
|
|
1813
|
+
hsProjectJsonProjectName,
|
|
1814
|
+
webRootProjectComponent
|
|
1815
|
+
);
|
|
1816
|
+
const localRenderPlaceholderProps = localRenderPlaceholder.json.props;
|
|
1817
|
+
const [
|
|
1818
|
+
__projectIdentifier,
|
|
1819
|
+
projectFolder,
|
|
1820
|
+
projectComponentFolder,
|
|
1821
|
+
componentFolder,
|
|
1822
|
+
componentTypeFolder,
|
|
1823
|
+
componentFileName
|
|
1824
|
+
] = placeholderPath.split("/");
|
|
1825
|
+
const partialPath = `${componentFolder}/${componentTypeFolder}/`;
|
|
1826
|
+
if (projectFolder !== hsProjectJsonProjectName) {
|
|
1827
|
+
throw new Error(
|
|
1828
|
+
`Unable to render component located outside of the project folder "${hsProjectJsonProjectName}". Components should be nested within the project folder. Check that the specified path is correct: ${placeholderPath}.`
|
|
1829
|
+
);
|
|
1830
|
+
} else if (projectComponentFolder !== webRootProjectComponent) {
|
|
1831
|
+
throw new Error(
|
|
1832
|
+
`The specified component folder "${projectComponentFolder}" does not match the webroot project component folder "${webRootProjectComponent}/${projectComponentFolder}" specified to the cms-dev-server. Components must be located within the webroot project folder. Check that the specified path is correct: ${placeholderPath}.`
|
|
1833
|
+
);
|
|
1834
|
+
}
|
|
1835
|
+
const resolvedPath = normalizePath2(
|
|
1836
|
+
path3.resolve(webRoot2, partialPath, componentFileName)
|
|
1837
|
+
);
|
|
1838
|
+
const entryPointPath = [
|
|
1839
|
+
"@projects",
|
|
1840
|
+
webRootProjectComponent,
|
|
1841
|
+
projectComponentFolder,
|
|
1842
|
+
partialPath,
|
|
1843
|
+
componentFileName
|
|
1844
|
+
].join("/");
|
|
1845
|
+
if (placeholderPath.startsWith("/fake/path/to/")) {
|
|
1846
|
+
return fakeRenderJsComponent(indexForThisRender);
|
|
1847
|
+
} else if (partialPath === ENTRY_POINTS_PATH) {
|
|
1848
|
+
return renderComponentForPlaceholderPartial(
|
|
1849
|
+
viteServer,
|
|
1850
|
+
resolvedPath,
|
|
1851
|
+
localRenderPlaceholderProps,
|
|
1852
|
+
pageUrl,
|
|
1853
|
+
basePath,
|
|
1854
|
+
environmentConfig,
|
|
1855
|
+
entryPointPath,
|
|
1856
|
+
indexForThisRender
|
|
1857
|
+
);
|
|
1858
|
+
} else if (partialPath === MODULE_FOLDER_PATH) {
|
|
1859
|
+
if (!isModulePlaceholder(localRenderPlaceholder)) {
|
|
1860
|
+
console.error(
|
|
1861
|
+
`Skipping local module render of ${componentFileName} <!-- proxy local render .. --> is missing necessary module prop keys (fieldValues? hublParameters?) `
|
|
1862
|
+
);
|
|
1863
|
+
} else {
|
|
1864
|
+
const localModuleRenderPlaceholder = {
|
|
1865
|
+
...localRenderPlaceholder
|
|
1866
|
+
};
|
|
1867
|
+
return renderComponentForPlaceholderModule(
|
|
1868
|
+
viteServer,
|
|
1869
|
+
resolvedPath,
|
|
1870
|
+
localModuleRenderPlaceholder,
|
|
1871
|
+
pageUrl,
|
|
1872
|
+
basePath,
|
|
1873
|
+
environmentConfig,
|
|
1874
|
+
entryPointPath,
|
|
1875
|
+
indexForThisRender
|
|
1876
|
+
);
|
|
1877
|
+
}
|
|
1878
|
+
} else {
|
|
1879
|
+
throw new Error(`Unimplemented render of ${placeholderPath}.`);
|
|
1880
|
+
}
|
|
1881
|
+
};
|
|
1882
|
+
function renderComponentForPlaceholderPartial(viteServer, resolvedPath, localRenderPlaceholderProps, pageUrl, basePath, environmentConfig, entryPointPath, indexForThisRender) {
|
|
1883
|
+
return renderPartial_default(
|
|
1884
|
+
viteServer,
|
|
1885
|
+
resolvedPath,
|
|
1886
|
+
localRenderPlaceholderProps,
|
|
1887
|
+
pageUrl,
|
|
1888
|
+
basePath,
|
|
1889
|
+
environmentConfig,
|
|
1890
|
+
{
|
|
1891
|
+
identifierPrefix: getEntryPointHashWithIndexSuffix(
|
|
1892
|
+
entryPointPath,
|
|
1893
|
+
indexForThisRender
|
|
1894
|
+
)
|
|
1895
|
+
}
|
|
1896
|
+
);
|
|
1897
|
+
}
|
|
1898
|
+
function renderComponentForPlaceholderModule(viteServer, resolvedPath, localModuleRenderPlaceholder, pageUrl, basePath, environmentConfig, entryPointPath, indexForThisRender) {
|
|
1899
|
+
return renderModule_default(
|
|
1900
|
+
viteServer,
|
|
1901
|
+
resolvedPath,
|
|
1902
|
+
localModuleRenderPlaceholder.json.props,
|
|
1903
|
+
pageUrl,
|
|
1904
|
+
basePath,
|
|
1905
|
+
environmentConfig,
|
|
1906
|
+
{
|
|
1907
|
+
identifierPrefix: getEntryPointHashWithIndexSuffix(
|
|
1908
|
+
entryPointPath,
|
|
1909
|
+
indexForThisRender
|
|
1910
|
+
)
|
|
1911
|
+
}
|
|
1912
|
+
);
|
|
1913
|
+
}
|
|
1914
|
+
async function proxySpecificPage(request2, response, portalId, hublet, contentId, webRoot2, viteServer, projectName, projectComponentPath, jsRenderingGates, urlToProxy, fullOriginalUrl) {
|
|
1915
|
+
let accountId;
|
|
1916
|
+
let proxyEnv;
|
|
1917
|
+
const prettyPrint = isDebugUrlString3(urlToProxy);
|
|
1918
|
+
try {
|
|
1919
|
+
accountId = getAccountId(portalId);
|
|
1920
|
+
if (accountId === null) {
|
|
1921
|
+
throw new Error();
|
|
1922
|
+
}
|
|
1923
|
+
proxyEnv = getEnv(accountId);
|
|
1924
|
+
} catch (e) {
|
|
1925
|
+
response.status(500).end(
|
|
1926
|
+
`Unable to find account for hubid = ${portalId}. Please check your hubspot.config.yaml`
|
|
1927
|
+
);
|
|
1928
|
+
return;
|
|
1929
|
+
}
|
|
1930
|
+
if (!accountId) {
|
|
1931
|
+
response.status(500).end(
|
|
1932
|
+
`Unable to find account for hubid = ${portalId}. Please check your hubspot.config.yaml`
|
|
1933
|
+
);
|
|
1934
|
+
return;
|
|
1935
|
+
}
|
|
1936
|
+
try {
|
|
1937
|
+
const previewInfo = await fetchPreviewInfo_default(accountId, portalId, contentId);
|
|
1938
|
+
const { previewKey } = previewInfo;
|
|
1939
|
+
const environmentConfig = buildStaticEnvConfig(
|
|
1940
|
+
portalId,
|
|
1941
|
+
hublet,
|
|
1942
|
+
proxyEnv,
|
|
1943
|
+
false,
|
|
1944
|
+
jsRenderingGates
|
|
1945
|
+
);
|
|
1946
|
+
const pageHtml = await makeProxyPreviewRequest(
|
|
1947
|
+
accountId,
|
|
1948
|
+
urlToProxy,
|
|
1949
|
+
previewKey,
|
|
1950
|
+
contentId,
|
|
1951
|
+
projectName,
|
|
1952
|
+
environmentConfig,
|
|
1953
|
+
jsRenderingGates,
|
|
1954
|
+
request2.get("COOKIE")
|
|
1955
|
+
);
|
|
1956
|
+
const { sortIslandRootsByPriority } = await viteServer.ssrLoadModule(
|
|
1957
|
+
"@hubspot/cms-components"
|
|
1958
|
+
);
|
|
1959
|
+
const localRenderPlaceholders = findLocalRenderPlaceholders(pageHtml);
|
|
1960
|
+
const numPlaceholders = localRenderPlaceholders.length;
|
|
1961
|
+
let numJsRenderFailures = 0;
|
|
1962
|
+
let islands = [];
|
|
1963
|
+
let mergedPerRequestState = /* @__PURE__ */ new Map();
|
|
1964
|
+
let basePath;
|
|
1965
|
+
const criticalDevErrors = [];
|
|
1966
|
+
const renderPromisesByChunkIndex = new Array(
|
|
1967
|
+
numPlaceholders
|
|
1968
|
+
);
|
|
1969
|
+
if (localRenderPlaceholders.length > 0) {
|
|
1970
|
+
let offsetSoFar = 0;
|
|
1971
|
+
const pageChunks = new Array(numPlaceholders + 1);
|
|
1972
|
+
for (let indexForThisRender = 0; indexForThisRender < numPlaceholders; indexForThisRender++) {
|
|
1973
|
+
const localRenderPlaceholder = localRenderPlaceholders[indexForThisRender];
|
|
1974
|
+
pageChunks[indexForThisRender] = pageHtml.slice(
|
|
1975
|
+
offsetSoFar,
|
|
1976
|
+
localRenderPlaceholder.startOffset
|
|
1977
|
+
);
|
|
1978
|
+
if (basePath === void 0) {
|
|
1979
|
+
basePath = getEntryPointBasePathFromProxyRequest(
|
|
1980
|
+
localRenderPlaceholder.json.request
|
|
1981
|
+
);
|
|
1982
|
+
}
|
|
1983
|
+
const renderPromise = renderComponentForPlaceholder(
|
|
1984
|
+
indexForThisRender,
|
|
1985
|
+
localRenderPlaceholder,
|
|
1986
|
+
webRoot2,
|
|
1987
|
+
viteServer,
|
|
1988
|
+
fullOriginalUrl,
|
|
1989
|
+
basePath,
|
|
1990
|
+
environmentConfig,
|
|
1991
|
+
projectName,
|
|
1992
|
+
projectComponentPath
|
|
1993
|
+
);
|
|
1994
|
+
renderPromisesByChunkIndex[indexForThisRender] = renderPromise.then((promiseResult) => {
|
|
1995
|
+
var _a;
|
|
1996
|
+
let { html, cssNeeded, inlineAssets, renderContext } = promiseResult;
|
|
1997
|
+
console.log(
|
|
1998
|
+
`Finished render of ${localRenderPlaceholder.path} (i = ${indexForThisRender})`
|
|
1999
|
+
);
|
|
2000
|
+
if ((_a = renderContext.criticalDevErrors) == null ? void 0 : _a.length) {
|
|
2001
|
+
criticalDevErrors.push(...renderContext.criticalDevErrors);
|
|
2002
|
+
}
|
|
2003
|
+
if (renderContext.islands.length > 0) {
|
|
2004
|
+
islands = islands.concat(renderContext.islands);
|
|
2005
|
+
}
|
|
2006
|
+
mergedPerRequestState = mergeServerRequestData_internal(
|
|
2007
|
+
mergedPerRequestState,
|
|
2008
|
+
renderContext.perServerRequestData
|
|
2009
|
+
);
|
|
2010
|
+
let result = html;
|
|
2011
|
+
if (inlineAssets) {
|
|
2012
|
+
result = `${inlineAssets.map((inlineAsset) => inlineAsset.html).join("\n")}
|
|
2013
|
+
${result}`;
|
|
2014
|
+
}
|
|
2015
|
+
if (cssNeeded) {
|
|
2016
|
+
result = `${cssNeeded}
|
|
2017
|
+
${result}`;
|
|
2018
|
+
}
|
|
2019
|
+
return result;
|
|
2020
|
+
}).catch((e) => {
|
|
2021
|
+
numJsRenderFailures += 1;
|
|
2022
|
+
console.log(
|
|
2023
|
+
"Attempted to render",
|
|
2024
|
+
localRenderPlaceholder.path,
|
|
2025
|
+
"with props",
|
|
2026
|
+
localRenderPlaceholder.json
|
|
2027
|
+
);
|
|
2028
|
+
console.error(e);
|
|
2029
|
+
return renderLocalError_default(localRenderPlaceholder.path, e);
|
|
2030
|
+
});
|
|
2031
|
+
offsetSoFar = localRenderPlaceholder.endOffset;
|
|
2032
|
+
}
|
|
2033
|
+
pageChunks[localRenderPlaceholders.length] = pageHtml.slice(offsetSoFar);
|
|
2034
|
+
response.writeHead(200);
|
|
2035
|
+
for (let i = 0; i < localRenderPlaceholders.length; i++) {
|
|
2036
|
+
const chunk = pageChunks[i];
|
|
2037
|
+
response.write(chunk);
|
|
2038
|
+
const foobar = await renderPromisesByChunkIndex[i];
|
|
2039
|
+
response.write(foobar);
|
|
2040
|
+
}
|
|
2041
|
+
response.write(
|
|
2042
|
+
getServerGlobalsToInject(
|
|
2043
|
+
environmentConfig,
|
|
2044
|
+
fullOriginalUrl,
|
|
2045
|
+
basePath,
|
|
2046
|
+
void 0,
|
|
2047
|
+
criticalDevErrors
|
|
2048
|
+
)
|
|
2049
|
+
);
|
|
2050
|
+
if (criticalDevErrors.length) {
|
|
2051
|
+
response.write(
|
|
2052
|
+
scriptTagToLogServerMessages(
|
|
2053
|
+
criticalDevErrorsToServerMessages_default(criticalDevErrors),
|
|
2054
|
+
"@hubspot/cms-dev-server messages"
|
|
2055
|
+
)
|
|
2056
|
+
);
|
|
2057
|
+
}
|
|
2058
|
+
if (islands.length > 0) {
|
|
2059
|
+
const sortedIslandRoots = sortIslandRootsByPriority(islands);
|
|
2060
|
+
const islandRuntimeAndGlobalScriptHtml = await getIslandRuntimeAndGlobalToInject(
|
|
2061
|
+
sortedIslandRoots,
|
|
2062
|
+
mergedPerRequestState,
|
|
2063
|
+
viteServer,
|
|
2064
|
+
jsRenderingGates,
|
|
2065
|
+
prettyPrint
|
|
2066
|
+
);
|
|
2067
|
+
response.write(islandRuntimeAndGlobalScriptHtml);
|
|
2068
|
+
}
|
|
2069
|
+
response.write(pageChunks[pageChunks.length - 1]);
|
|
2070
|
+
response.end();
|
|
2071
|
+
} else {
|
|
2072
|
+
response.writeHead(200);
|
|
2073
|
+
response.write(pageHtml);
|
|
2074
|
+
response.end();
|
|
2075
|
+
}
|
|
2076
|
+
} catch (error) {
|
|
2077
|
+
response.status(500).end(
|
|
2078
|
+
`Failed proxy render of page id = ${contentId} hub id = ${portalId}
|
|
2064
2079
|
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
isDebugUrlString as isDebugUrlString3,
|
|
2069
|
-
mergeServerRequestData_internal
|
|
2070
|
-
} from "@hubspot/cms-components";
|
|
2071
|
-
var { default: hsCliHttp5 } = localDevHttpImport5;
|
|
2072
|
-
var getEntryPointBasePathFromProxyRequest = (request2) => {
|
|
2073
|
-
if (!request2) {
|
|
2074
|
-
return "";
|
|
2075
|
-
}
|
|
2076
|
-
const { path: requestPath, pathParamDict } = request2;
|
|
2077
|
-
if (!pathParamDict || !pathParamDict.dynamic_slug) {
|
|
2078
|
-
return requestPath;
|
|
2079
|
-
}
|
|
2080
|
-
return requestPath.replace(pathParamDict.dynamic_slug, "");
|
|
2081
|
-
};
|
|
2082
|
-
function resolvePlaceholderPath(placeholderPath, projectName, projectComponent) {
|
|
2083
|
-
if (!process.env.DEFAULT_MODULE_PATH_REWRITE) {
|
|
2084
|
-
return placeholderPath;
|
|
2085
|
-
}
|
|
2086
|
-
const mappedPlaceholderPath = `@projects/${projectName}/${projectComponent}/components/modules/${process.env.DEFAULT_MODULE_PATH_REWRITE.split(":")[1]}`;
|
|
2087
|
-
if (placeholderPath.startsWith(`@default-modules/${projectName}/`) && placeholderPath.endsWith(
|
|
2088
|
-
process.env.DEFAULT_MODULE_PATH_REWRITE.split(":")[0]
|
|
2089
|
-
)) {
|
|
2090
|
-
return mappedPlaceholderPath;
|
|
2080
|
+
${error.stack}`
|
|
2081
|
+
);
|
|
2082
|
+
return;
|
|
2091
2083
|
}
|
|
2092
|
-
return placeholderPath;
|
|
2093
2084
|
}
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
const
|
|
2102
|
-
|
|
2103
|
-
);
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
} else {
|
|
2109
|
-
proxiedQueryParams[queryKey] = values[0];
|
|
2110
|
-
}
|
|
2111
|
-
}
|
|
2112
|
-
const localProxyProject = process.env.DEFAULT_MODULE_PATH_REWRITE ? `@default-modules/${projectName}` : `@projects/${projectName}`;
|
|
2113
|
-
proxiedQueryParams = {
|
|
2114
|
-
...proxiedQueryParams,
|
|
2115
|
-
hs_preview: `${previewKey}-${contentId}`,
|
|
2116
|
-
hsLocalProxyProject: localProxyProject,
|
|
2117
|
-
localProxySchemaVersion: "2",
|
|
2118
|
-
hsLoginVerifyDisabled: `${true}`
|
|
2119
|
-
};
|
|
2120
|
-
if (renderPreviewLocally) {
|
|
2121
|
-
proxiedQueryParams.hsDebugOverridePublicHost = url3.host;
|
|
2122
|
-
baseURL = `http://local.hubspot${environmentConfig.getInternalHSEnv() === "qa" ? "qa" : ""}.com`;
|
|
2123
|
-
pathname = `/cos-rendering/v1/public${url3.pathname}`;
|
|
2124
|
-
}
|
|
2125
|
-
console.log(
|
|
2126
|
-
`Proxying request to ${baseURL}${pathname}?${new URLSearchParams({
|
|
2127
|
-
...proxiedQueryParams,
|
|
2128
|
-
previewKey,
|
|
2129
|
-
contentId
|
|
2130
|
-
}).toString()}`
|
|
2131
|
-
);
|
|
2132
|
-
const result = hsCliHttp5.get(accountId, {
|
|
2133
|
-
baseURL,
|
|
2134
|
-
url: pathname,
|
|
2135
|
-
params: proxiedQueryParams,
|
|
2136
|
-
responseType: "text",
|
|
2085
|
+
|
|
2086
|
+
// src/lib/renderModulePreview.ts
|
|
2087
|
+
import localDevHttpImport6 from "@hubspot/local-dev-lib/http";
|
|
2088
|
+
import jsdom from "jsdom";
|
|
2089
|
+
var { JSDOM } = jsdom;
|
|
2090
|
+
var { default: hsCliHttp6 } = localDevHttpImport6;
|
|
2091
|
+
async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv, cookieValue) {
|
|
2092
|
+
const moduleInfoQueryParams = new URLSearchParams({
|
|
2093
|
+
portalId: `${authedPortalId}`
|
|
2094
|
+
});
|
|
2095
|
+
const moduleInfo = await hsCliHttp6.get(authedPortalId, {
|
|
2096
|
+
url: `/api/designmanager/v1/modules/by-path/${encodeURIComponent(
|
|
2097
|
+
modulePath
|
|
2098
|
+
)}?${moduleInfoQueryParams}`,
|
|
2137
2099
|
headers: {
|
|
2138
|
-
|
|
2100
|
+
["Accept"]: "application/json",
|
|
2101
|
+
referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
|
|
2102
|
+
cookie: cookieValue,
|
|
2103
|
+
"User-Agent": "HubSpot CMS Dev Server"
|
|
2139
2104
|
}
|
|
2140
2105
|
});
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2106
|
+
const currentHubApiDomainOverride = process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
2107
|
+
process.env.HUBAPI_DOMAIN_OVERRIDE = `api.hubspot`;
|
|
2108
|
+
const queryParams = new URLSearchParams({
|
|
2109
|
+
portalId: `${authedPortalId}`,
|
|
2110
|
+
hsLocalProxy: `${true}`,
|
|
2111
|
+
localProxySchemaVersion: "2",
|
|
2112
|
+
hsLoginVerifyDisabled: `${true}`,
|
|
2113
|
+
module_id: moduleInfo.moduleId
|
|
2114
|
+
});
|
|
2115
|
+
const modulePreviewHtml = await hsCliHttp6.get(authedPortalId, {
|
|
2116
|
+
url: `/api/cos-rendering/v1/public/_hcms/preview/template/multi?${queryParams}`,
|
|
2117
|
+
headers: {
|
|
2118
|
+
["content-type"]: "application/x-www-form-urlencoded",
|
|
2119
|
+
["Accept"]: "text/html",
|
|
2120
|
+
referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
|
|
2121
|
+
cookie: cookieValue,
|
|
2122
|
+
"User-Agent": "HubSpot CMS Dev Server"
|
|
2146
2123
|
}
|
|
2147
2124
|
});
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2125
|
+
if (currentHubApiDomainOverride) {
|
|
2126
|
+
process.env.HUBAPI_DOMAIN_OVERRIDE = currentHubApiDomainOverride;
|
|
2127
|
+
} else {
|
|
2128
|
+
delete process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
2129
|
+
}
|
|
2130
|
+
const dom = new JSDOM(modulePreviewHtml);
|
|
2131
|
+
const modulePreviewContent = dom.window.document.querySelector(
|
|
2132
|
+
'div[data-hs-cos-type="module"]'
|
|
2133
|
+
).outerHTML;
|
|
2134
|
+
const cssNeeded = Array.from(dom.window.document.querySelectorAll("style")).map((element) => element.outerHTML).join("");
|
|
2135
|
+
return { html: modulePreviewContent, cssNeeded };
|
|
2154
2136
|
}
|
|
2155
|
-
|
|
2156
|
-
const
|
|
2157
|
-
|
|
2158
|
-
hsProjectJsonProjectName,
|
|
2159
|
-
webRootProjectComponent
|
|
2137
|
+
async function renderLocalProjectModulePreview(moduleName, authedPortalId, authedEnv, authedHublet, webRoot2, viteServer, jsRenderingGates, projectName, projectComponentPath, fullOriginalUrl, cookieValue) {
|
|
2138
|
+
const modulePath = normalizePath3(
|
|
2139
|
+
path4.resolve(webRoot2, "components/modules/", moduleName)
|
|
2160
2140
|
);
|
|
2161
|
-
const
|
|
2162
|
-
const
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
if (
|
|
2141
|
+
const basePath = `preview/${getEntryPointBasePath(modulePath)}`;
|
|
2142
|
+
const environmentConfig = buildStaticEnvConfig2(
|
|
2143
|
+
authedPortalId,
|
|
2144
|
+
authedHublet,
|
|
2145
|
+
authedEnv,
|
|
2146
|
+
false,
|
|
2147
|
+
jsRenderingGates
|
|
2148
|
+
);
|
|
2149
|
+
let componentModule;
|
|
2150
|
+
let foundPath;
|
|
2151
|
+
if (!hasComponentExtension(modulePath)) {
|
|
2152
|
+
[componentModule, foundPath] = await lookForModuleInFolder2(
|
|
2153
|
+
modulePath,
|
|
2154
|
+
viteServer
|
|
2155
|
+
);
|
|
2156
|
+
}
|
|
2157
|
+
if (!componentModule) {
|
|
2158
|
+
componentModule = await viteServer.ssrLoadModule(modulePath);
|
|
2159
|
+
foundPath = componentModule ? modulePath : void 0;
|
|
2160
|
+
}
|
|
2161
|
+
if (!componentModule) {
|
|
2162
|
+
throw new Error(`Couldn't find module: ${modulePath}`);
|
|
2163
|
+
}
|
|
2164
|
+
const Component = componentModule.Component;
|
|
2165
|
+
const fields = componentModule.fields;
|
|
2166
|
+
const meta = componentModule.meta;
|
|
2167
|
+
const hublDataTemplate = componentModule.hublDataTemplate;
|
|
2168
|
+
if (!Component) {
|
|
2172
2169
|
throw new Error(
|
|
2173
|
-
`
|
|
2170
|
+
`Module does not have a named Component export: ${foundPath}`
|
|
2174
2171
|
);
|
|
2175
|
-
} else if (
|
|
2172
|
+
} else if (!fields) {
|
|
2173
|
+
throw new Error(`Module does not have a named fields export: ${foundPath}`);
|
|
2174
|
+
} else if (!meta) {
|
|
2175
|
+
throw new Error(`Module does not have a named meta export: ${foundPath}`);
|
|
2176
|
+
}
|
|
2177
|
+
const internalSsrPath = packagePath(import.meta.url, "internalSsr");
|
|
2178
|
+
const { renderFieldsToJson } = await viteServer.ssrLoadModule(internalSsrPath);
|
|
2179
|
+
const localFieldsJson = renderFieldsToJson(fields, modulePath);
|
|
2180
|
+
const localModule = {
|
|
2181
|
+
isJsModule: true,
|
|
2182
|
+
schemaVersion: 2,
|
|
2183
|
+
fields: localFieldsJson,
|
|
2184
|
+
id: 1,
|
|
2185
|
+
path: `@projects/${projectName}/${projectComponentPath}/components/modules/${moduleName}`,
|
|
2186
|
+
hublDataTemplate
|
|
2187
|
+
};
|
|
2188
|
+
const queryParams = new URLSearchParams({
|
|
2189
|
+
portalId: `${authedPortalId}`,
|
|
2190
|
+
hsLocalProxy: `${true}`,
|
|
2191
|
+
localProxySchemaVersion: "2",
|
|
2192
|
+
hsLoginVerifyDisabled: `${true}`
|
|
2193
|
+
});
|
|
2194
|
+
const currentHubApiDomainOverride = process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
2195
|
+
process.env.HUBAPI_DOMAIN_OVERRIDE = `api.hubspot`;
|
|
2196
|
+
const templatePreview = await hsCliHttp6.post(authedPortalId, {
|
|
2197
|
+
url: `/api/cos-rendering/v1/public/_hcms/preview/template/multiform?${queryParams}`,
|
|
2198
|
+
headers: {
|
|
2199
|
+
["content-type"]: "application/x-www-form-urlencoded",
|
|
2200
|
+
["Accept"]: "text/html",
|
|
2201
|
+
referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
|
|
2202
|
+
cookie: cookieValue,
|
|
2203
|
+
"User-Agent": "HubSpot CMS Dev Server"
|
|
2204
|
+
},
|
|
2205
|
+
data: `module=${encodeURIComponent(JSON.stringify(localModule))}`
|
|
2206
|
+
});
|
|
2207
|
+
if (currentHubApiDomainOverride) {
|
|
2208
|
+
process.env.HUBAPI_DOMAIN_OVERRIDE = currentHubApiDomainOverride;
|
|
2209
|
+
} else {
|
|
2210
|
+
delete process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
2211
|
+
}
|
|
2212
|
+
const localRenderPlaceholders = findLocalRenderPlaceholders(templatePreview);
|
|
2213
|
+
if (localRenderPlaceholders.length !== 1) {
|
|
2176
2214
|
throw new Error(
|
|
2177
|
-
`
|
|
2215
|
+
`Error previewing module (${moduleName}), exception in module preview HTML
|
|
2216
|
+
|
|
2217
|
+
`
|
|
2178
2218
|
);
|
|
2179
2219
|
}
|
|
2180
|
-
|
|
2181
|
-
|
|
2220
|
+
return await renderComponentForPlaceholder(
|
|
2221
|
+
0,
|
|
2222
|
+
localRenderPlaceholders[0],
|
|
2223
|
+
webRoot2,
|
|
2224
|
+
viteServer,
|
|
2225
|
+
fullOriginalUrl,
|
|
2226
|
+
basePath,
|
|
2227
|
+
environmentConfig,
|
|
2228
|
+
projectName,
|
|
2229
|
+
projectComponentPath
|
|
2182
2230
|
);
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2231
|
+
}
|
|
2232
|
+
|
|
2233
|
+
// src/routes/partial.ts
|
|
2234
|
+
import { join as joinPosix3 } from "path/posix";
|
|
2235
|
+
var partialRouteHandler = async (request2, response) => {
|
|
2236
|
+
sendTrackingRequest("view-partial-route");
|
|
2237
|
+
const {
|
|
2238
|
+
authedPortalId,
|
|
2239
|
+
authedEnv,
|
|
2240
|
+
authedHublet,
|
|
2241
|
+
webRoot: webRoot2,
|
|
2242
|
+
viteServer,
|
|
2243
|
+
jsRenderingGates,
|
|
2244
|
+
projectName,
|
|
2245
|
+
projectComponentPath
|
|
2246
|
+
} = request2.app.locals;
|
|
2247
|
+
const partialName = request2.params.partial;
|
|
2248
|
+
const baseTemplatePath = packagePath(
|
|
2249
|
+
import.meta.url,
|
|
2250
|
+
"html/baseTemplate.html"
|
|
2251
|
+
);
|
|
2252
|
+
const partialPath = normalizePath4(
|
|
2253
|
+
path5.resolve(webRoot2, "components/partials/", partialName)
|
|
2254
|
+
);
|
|
2255
|
+
const entrypointPath = normalizePath4(
|
|
2256
|
+
[
|
|
2257
|
+
"@projects",
|
|
2258
|
+
projectName,
|
|
2259
|
+
projectComponentPath,
|
|
2260
|
+
"components/modules/",
|
|
2261
|
+
partialName
|
|
2262
|
+
].join("/")
|
|
2263
|
+
);
|
|
2264
|
+
const basePath = getEntryPointBasePath(partialPath);
|
|
2265
|
+
const environmentConfig = buildStaticEnvConfig3(
|
|
2266
|
+
authedPortalId,
|
|
2267
|
+
authedHublet,
|
|
2268
|
+
authedEnv,
|
|
2269
|
+
false,
|
|
2270
|
+
jsRenderingGates
|
|
2271
|
+
);
|
|
2272
|
+
try {
|
|
2273
|
+
const {
|
|
2274
|
+
html: renderedHtml,
|
|
2275
|
+
cssNeeded,
|
|
2276
|
+
renderContext,
|
|
2277
|
+
inlineAssets
|
|
2278
|
+
} = await renderPartial_default(
|
|
2194
2279
|
viteServer,
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2280
|
+
partialPath,
|
|
2281
|
+
{},
|
|
2282
|
+
fullOriginalUrlFromRequest(request2),
|
|
2198
2283
|
basePath,
|
|
2199
2284
|
environmentConfig,
|
|
2200
|
-
|
|
2201
|
-
|
|
2285
|
+
{
|
|
2286
|
+
identifierPrefix: getEntryPointHash(entrypointPath)
|
|
2287
|
+
}
|
|
2202
2288
|
);
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2289
|
+
let resolvedCss = cssNeeded;
|
|
2290
|
+
let resolvedInlineAssets = inlineAssets;
|
|
2291
|
+
let partialHtml = renderedHtml;
|
|
2292
|
+
if (jsRenderingGates.includes("CMS:JSRenderer:AnalyzeCmsModules")) {
|
|
2293
|
+
const moduleNode = await viteServer.moduleGraph.getModuleByUrl(
|
|
2294
|
+
hasComponentExtension(partialPath) ? partialPath : joinPosix3(partialPath, "index")
|
|
2207
2295
|
);
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
entryPointPath,
|
|
2220
|
-
indexForThisRender
|
|
2296
|
+
if (!moduleNode) {
|
|
2297
|
+
throw new Error(`Error: could not find partial: ${partialPath}`);
|
|
2298
|
+
}
|
|
2299
|
+
const moduleInfo = viteServer.pluginContainer.getModuleInfo(
|
|
2300
|
+
moduleNode.id
|
|
2301
|
+
);
|
|
2302
|
+
const cmsModules = moduleInfo.meta.findCmsModules ?? {};
|
|
2303
|
+
const localProjectModules = Object.values(cmsModules).filter(
|
|
2304
|
+
(moduleDescriptor) => moduleDescriptor.path.startsWith(
|
|
2305
|
+
`@projects/${projectName}/${projectComponentPath}/components/modules/`
|
|
2306
|
+
)
|
|
2221
2307
|
);
|
|
2308
|
+
const remoteModules = Object.values(cmsModules).filter(
|
|
2309
|
+
(moduleDescriptor) => !moduleDescriptor.path.startsWith(
|
|
2310
|
+
`@projects/${projectName}/${projectComponentPath}/components/modules/`
|
|
2311
|
+
)
|
|
2312
|
+
);
|
|
2313
|
+
const remoteModulePreviewPromises = [];
|
|
2314
|
+
const localProjectModulePreviewPromises = [];
|
|
2315
|
+
for (const remoteModule of remoteModules) {
|
|
2316
|
+
const modulePlaceholder = createModulePlaceholder(remoteModule.name);
|
|
2317
|
+
if (!renderedHtml.includes(modulePlaceholder))
|
|
2318
|
+
continue;
|
|
2319
|
+
remoteModulePreviewPromises.push(
|
|
2320
|
+
renderRemoteModulePreview(
|
|
2321
|
+
remoteModule.path,
|
|
2322
|
+
authedPortalId,
|
|
2323
|
+
authedEnv,
|
|
2324
|
+
request2.get("COOKIE")
|
|
2325
|
+
).then((result) => ({
|
|
2326
|
+
remoteModule,
|
|
2327
|
+
result
|
|
2328
|
+
}))
|
|
2329
|
+
);
|
|
2330
|
+
}
|
|
2331
|
+
for (const localProjectModule of localProjectModules) {
|
|
2332
|
+
const modulePlaceholder = createModulePlaceholder(
|
|
2333
|
+
localProjectModule.name
|
|
2334
|
+
);
|
|
2335
|
+
if (!renderedHtml.includes(modulePlaceholder))
|
|
2336
|
+
continue;
|
|
2337
|
+
localProjectModulePreviewPromises.push(
|
|
2338
|
+
renderLocalProjectModulePreview(
|
|
2339
|
+
path5.basename(localProjectModule.path),
|
|
2340
|
+
authedPortalId,
|
|
2341
|
+
authedEnv,
|
|
2342
|
+
authedHublet,
|
|
2343
|
+
webRoot2,
|
|
2344
|
+
viteServer,
|
|
2345
|
+
jsRenderingGates,
|
|
2346
|
+
projectName,
|
|
2347
|
+
projectComponentPath,
|
|
2348
|
+
fullOriginalUrlFromRequest(request2),
|
|
2349
|
+
request2.get("COOKIE")
|
|
2350
|
+
).then((result) => ({
|
|
2351
|
+
localProjectModule,
|
|
2352
|
+
result
|
|
2353
|
+
}))
|
|
2354
|
+
);
|
|
2355
|
+
}
|
|
2356
|
+
const [remoteModuleResults, localProjectModuleResults] = await Promise.all([
|
|
2357
|
+
Promise.all(remoteModulePreviewPromises),
|
|
2358
|
+
Promise.all(localProjectModulePreviewPromises)
|
|
2359
|
+
]);
|
|
2360
|
+
for (const { remoteModule, result } of remoteModuleResults) {
|
|
2361
|
+
const modulePlaceholder = createModulePlaceholder(remoteModule.name);
|
|
2362
|
+
partialHtml = partialHtml.replace(modulePlaceholder, result.html);
|
|
2363
|
+
resolvedCss = resolvedCss.concat(result.cssNeeded);
|
|
2364
|
+
}
|
|
2365
|
+
for (const { localProjectModule, result } of localProjectModuleResults) {
|
|
2366
|
+
const modulePlaceholder = createModulePlaceholder(
|
|
2367
|
+
localProjectModule.name
|
|
2368
|
+
);
|
|
2369
|
+
renderContext.islands.push(...result.renderContext.islands);
|
|
2370
|
+
resolvedCss = resolvedCss.concat(result.cssNeeded);
|
|
2371
|
+
resolvedInlineAssets = resolvedInlineAssets.concat(result.inlineAssets);
|
|
2372
|
+
partialHtml = partialHtml.replace(modulePlaceholder, result.html);
|
|
2373
|
+
}
|
|
2222
2374
|
}
|
|
2223
|
-
|
|
2224
|
-
|
|
2375
|
+
const htmlShell = await createHtmlShellDependingOnRenderContext(
|
|
2376
|
+
baseTemplatePath,
|
|
2377
|
+
request2.originalUrl,
|
|
2378
|
+
`Partial: ${partialPath}`,
|
|
2379
|
+
renderContext,
|
|
2380
|
+
viteServer,
|
|
2381
|
+
jsRenderingGates
|
|
2382
|
+
);
|
|
2383
|
+
const html = htmlShell.replace(
|
|
2384
|
+
"<!--headend-->",
|
|
2385
|
+
[
|
|
2386
|
+
resolvedCss,
|
|
2387
|
+
...resolvedInlineAssets.map((inlineAsset) => inlineAsset.html)
|
|
2388
|
+
].join("\n")
|
|
2389
|
+
).replace(`<!--ssr-outlet-->`, partialHtml);
|
|
2390
|
+
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
2391
|
+
} catch (e) {
|
|
2392
|
+
console.error(e);
|
|
2393
|
+
viteServer.ssrFixStacktrace(e);
|
|
2394
|
+
response.status(500).end(`Error rendering partial (${partialName})
|
|
2395
|
+
|
|
2396
|
+
${e.stack}`);
|
|
2225
2397
|
}
|
|
2226
2398
|
};
|
|
2227
|
-
function
|
|
2228
|
-
return
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
}
|
|
2399
|
+
function createModulePlaceholder(moduleName) {
|
|
2400
|
+
return `<!-- hs-module-placeholder-${moduleName} -->`;
|
|
2401
|
+
}
|
|
2402
|
+
var partial_default = partialRouteHandler;
|
|
2403
|
+
|
|
2404
|
+
// src/components/PartialsList.tsx
|
|
2405
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
2406
|
+
function EmptyPartialsList({ webRoot: webRoot2 }) {
|
|
2407
|
+
return /* @__PURE__ */ jsxs("p", { children: [
|
|
2408
|
+
"No partials in ",
|
|
2409
|
+
/* @__PURE__ */ jsxs("code", { children: [
|
|
2410
|
+
webRoot2,
|
|
2411
|
+
"components/partials"
|
|
2412
|
+
] })
|
|
2413
|
+
] });
|
|
2414
|
+
}
|
|
2415
|
+
function PartialLinkInLI({ partialName }) {
|
|
2416
|
+
return /* @__PURE__ */ jsx2("li", { children: /* @__PURE__ */ jsx2("a", { href: `/partial/${partialName}`, children: partialName }) });
|
|
2417
|
+
}
|
|
2418
|
+
function PartialsList({ webRoot: webRoot2, partialNames }) {
|
|
2419
|
+
if (partialNames.length === 0) {
|
|
2420
|
+
return /* @__PURE__ */ jsx2(EmptyPartialsList, { webRoot: webRoot2 });
|
|
2421
|
+
}
|
|
2422
|
+
return /* @__PURE__ */ jsx2("ul", { children: partialNames.map((partialName) => /* @__PURE__ */ jsx2(PartialLinkInLI, { partialName }, partialName)) });
|
|
2423
|
+
}
|
|
2424
|
+
|
|
2425
|
+
// src/routes/linksToAllPartialsRouteHandler.tsx
|
|
2426
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
2427
|
+
var linksToAllPartialRouteHandler = async (request2, response) => {
|
|
2428
|
+
const { webRoot: webRoot2 } = request2.app.locals;
|
|
2429
|
+
const { partialNames } = findAllPartialsInRoot(webRoot2);
|
|
2430
|
+
const { html: responseHtml } = await renderOnServer(
|
|
2431
|
+
/* @__PURE__ */ jsx3(PartialsList, { webRoot: webRoot2, partialNames })
|
|
2241
2432
|
);
|
|
2433
|
+
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
2434
|
+
};
|
|
2435
|
+
var linksToAllPartialsRouteHandler_default = linksToAllPartialRouteHandler;
|
|
2436
|
+
|
|
2437
|
+
// src/components/ModulesList.tsx
|
|
2438
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
2439
|
+
function EmptyModulesList({ webRoot: webRoot2 }) {
|
|
2440
|
+
return /* @__PURE__ */ jsxs2("p", { children: [
|
|
2441
|
+
"No modules in ",
|
|
2442
|
+
/* @__PURE__ */ jsxs2("code", { children: [
|
|
2443
|
+
webRoot2,
|
|
2444
|
+
"components/modules"
|
|
2445
|
+
] })
|
|
2446
|
+
] });
|
|
2242
2447
|
}
|
|
2243
|
-
function
|
|
2244
|
-
return
|
|
2448
|
+
function ModuleLinkInLI({ moduleName }) {
|
|
2449
|
+
return /* @__PURE__ */ jsxs2("li", { children: [
|
|
2450
|
+
/* @__PURE__ */ jsx4("a", { href: `/preview/module/${moduleName}`, children: moduleName }),
|
|
2451
|
+
" / ",
|
|
2452
|
+
/* @__PURE__ */ jsx4("a", { href: `/module/${moduleName}`, children: "Local Version" })
|
|
2453
|
+
] });
|
|
2454
|
+
}
|
|
2455
|
+
function ModulesList({ webRoot: webRoot2, moduleNames }) {
|
|
2456
|
+
if (moduleNames.length === 0) {
|
|
2457
|
+
return /* @__PURE__ */ jsx4(EmptyModulesList, { webRoot: webRoot2 });
|
|
2458
|
+
}
|
|
2459
|
+
return /* @__PURE__ */ jsx4("ul", { children: moduleNames.map((moduleName) => /* @__PURE__ */ jsx4(ModuleLinkInLI, { moduleName }, moduleName)) });
|
|
2460
|
+
}
|
|
2461
|
+
var ModulesList_default = ModulesList;
|
|
2462
|
+
|
|
2463
|
+
// src/routes/linksToAllModulesRouteHandler.tsx
|
|
2464
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
2465
|
+
var linksToAllModuleRouteHandler = async (request2, response) => {
|
|
2466
|
+
const { webRoot: webRoot2 } = request2.app.locals;
|
|
2467
|
+
const { moduleNames } = findAllModulesInRoot(webRoot2);
|
|
2468
|
+
const { html: responseHtml } = await renderOnServer(
|
|
2469
|
+
/* @__PURE__ */ jsx5(ModulesList_default, { webRoot: webRoot2, moduleNames })
|
|
2470
|
+
);
|
|
2471
|
+
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
2472
|
+
};
|
|
2473
|
+
var linksToAllModulesRouteHandler_default = linksToAllModuleRouteHandler;
|
|
2474
|
+
|
|
2475
|
+
// src/routes/module.ts
|
|
2476
|
+
import { buildStaticEnvConfig as buildStaticEnvConfig4 } from "@hubspot/cms-components";
|
|
2477
|
+
import path6 from "path";
|
|
2478
|
+
import { normalizePath as normalizePath5 } from "vite";
|
|
2479
|
+
var moduleRouteHandler = async (request2, response) => {
|
|
2480
|
+
sendTrackingRequest("view-module-route");
|
|
2481
|
+
const {
|
|
2482
|
+
authedPortalId,
|
|
2483
|
+
authedEnv,
|
|
2484
|
+
authedHublet,
|
|
2485
|
+
webRoot: webRoot2,
|
|
2245
2486
|
viteServer,
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
indexForThisRender
|
|
2255
|
-
)
|
|
2256
|
-
}
|
|
2487
|
+
jsRenderingGates,
|
|
2488
|
+
projectName,
|
|
2489
|
+
projectComponentPath
|
|
2490
|
+
} = request2.app.locals;
|
|
2491
|
+
const moduleName = request2.params.moduleName;
|
|
2492
|
+
const baseTemplatePath = packagePath(
|
|
2493
|
+
import.meta.url,
|
|
2494
|
+
"html/baseTemplate.html"
|
|
2257
2495
|
);
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2496
|
+
const modulePath = normalizePath5(
|
|
2497
|
+
path6.resolve(webRoot2, "components/modules/", moduleName)
|
|
2498
|
+
);
|
|
2499
|
+
const entrypointPath = normalizePath5(
|
|
2500
|
+
[
|
|
2501
|
+
"@projects",
|
|
2502
|
+
projectName,
|
|
2503
|
+
projectComponentPath,
|
|
2504
|
+
"components/modules/",
|
|
2505
|
+
moduleName
|
|
2506
|
+
].join("/")
|
|
2507
|
+
);
|
|
2508
|
+
let fieldOverrides = null;
|
|
2509
|
+
if (request2.query.fields) {
|
|
2510
|
+
try {
|
|
2511
|
+
if (typeof request2.query.fields === "string") {
|
|
2512
|
+
fieldOverrides = JSON.parse(
|
|
2513
|
+
decodeURIComponent(request2.query.fields.replace(/\+/g, "%20"))
|
|
2514
|
+
);
|
|
2515
|
+
}
|
|
2516
|
+
} catch (e) {
|
|
2517
|
+
console.error(
|
|
2518
|
+
`Error parsing field param for module ${moduleName}: ${request2.query.fields}`
|
|
2519
|
+
);
|
|
2267
2520
|
}
|
|
2268
|
-
proxyEnv = getEnv(accountId);
|
|
2269
|
-
} catch (e) {
|
|
2270
|
-
response.status(500).end(
|
|
2271
|
-
`Unable to find account for hubid = ${portalId}. Please check your hubspot.config.yaml`
|
|
2272
|
-
);
|
|
2273
|
-
return;
|
|
2274
|
-
}
|
|
2275
|
-
if (!accountId) {
|
|
2276
|
-
response.status(500).end(
|
|
2277
|
-
`Unable to find account for hubid = ${portalId}. Please check your hubspot.config.yaml`
|
|
2278
|
-
);
|
|
2279
|
-
return;
|
|
2280
2521
|
}
|
|
2522
|
+
const basePath = getEntryPointBasePath(modulePath);
|
|
2523
|
+
const environmentConfig = buildStaticEnvConfig4(
|
|
2524
|
+
authedPortalId,
|
|
2525
|
+
authedHublet,
|
|
2526
|
+
authedEnv,
|
|
2527
|
+
false,
|
|
2528
|
+
jsRenderingGates
|
|
2529
|
+
);
|
|
2281
2530
|
try {
|
|
2282
|
-
const
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2531
|
+
const {
|
|
2532
|
+
html: renderedHtml,
|
|
2533
|
+
cssNeeded,
|
|
2534
|
+
renderContext,
|
|
2535
|
+
inlineAssets
|
|
2536
|
+
} = await renderModule_default(
|
|
2537
|
+
viteServer,
|
|
2538
|
+
modulePath,
|
|
2539
|
+
{
|
|
2540
|
+
fieldValues: fieldOverrides,
|
|
2541
|
+
hublParameters: {},
|
|
2542
|
+
moduleName: `local-${moduleName}`
|
|
2543
|
+
},
|
|
2544
|
+
fullOriginalUrlFromRequest(request2),
|
|
2545
|
+
basePath,
|
|
2297
2546
|
environmentConfig,
|
|
2298
|
-
|
|
2299
|
-
|
|
2547
|
+
{
|
|
2548
|
+
identifierPrefix: getEntryPointHash(entrypointPath)
|
|
2549
|
+
}
|
|
2300
2550
|
);
|
|
2301
|
-
const
|
|
2302
|
-
|
|
2551
|
+
const htmlShell = await createHtmlShellDependingOnRenderContext(
|
|
2552
|
+
baseTemplatePath,
|
|
2553
|
+
request2.originalUrl,
|
|
2554
|
+
`Module: ${modulePath}`,
|
|
2555
|
+
renderContext,
|
|
2556
|
+
viteServer,
|
|
2557
|
+
jsRenderingGates
|
|
2303
2558
|
);
|
|
2304
|
-
const
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2559
|
+
const html = htmlShell.replace(
|
|
2560
|
+
"<!--headend-->",
|
|
2561
|
+
[
|
|
2562
|
+
cssNeeded,
|
|
2563
|
+
...inlineAssets.map((inlineAsset) => inlineAsset.html)
|
|
2564
|
+
].join("\n")
|
|
2565
|
+
).replace(`<!--ssr-outlet-->`, renderedHtml);
|
|
2566
|
+
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
2567
|
+
} catch (e) {
|
|
2568
|
+
console.error(e);
|
|
2569
|
+
viteServer.ssrFixStacktrace(e);
|
|
2570
|
+
response.status(500).end(`Error rendering module (${moduleName})
|
|
2571
|
+
|
|
2572
|
+
${e.stack}`);
|
|
2573
|
+
}
|
|
2574
|
+
};
|
|
2575
|
+
var module_default = moduleRouteHandler;
|
|
2576
|
+
|
|
2577
|
+
// src/proxyPage/fetchContentMetadata.ts
|
|
2578
|
+
import http from "http";
|
|
2579
|
+
import https from "https";
|
|
2580
|
+
import { getAccountId as getAccountId2 } from "@hubspot/local-dev-lib/config";
|
|
2581
|
+
async function requestPage(url3, redirects = 0, originalUrl) {
|
|
2582
|
+
if (redirects > 5) {
|
|
2583
|
+
throw new Error(
|
|
2584
|
+
`Hit too many redirects to HEAD requests for ${originalUrl}`
|
|
2313
2585
|
);
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
basePath = getEntryPointBasePathFromProxyRequest(
|
|
2325
|
-
localRenderPlaceholder.json.request
|
|
2326
|
-
);
|
|
2586
|
+
}
|
|
2587
|
+
return new Promise((resolve3, reject) => {
|
|
2588
|
+
const protocolAPI = url3.startsWith("https://") ? https : http;
|
|
2589
|
+
protocolAPI.request(
|
|
2590
|
+
url3,
|
|
2591
|
+
{
|
|
2592
|
+
method: "HEAD",
|
|
2593
|
+
headers: {
|
|
2594
|
+
// Keep this user agent, so we don't get 403s from the request
|
|
2595
|
+
["User-Agent"]: "cms-dev-server"
|
|
2327
2596
|
}
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
basePath,
|
|
2335
|
-
environmentConfig,
|
|
2336
|
-
projectName,
|
|
2337
|
-
projectComponentPath
|
|
2597
|
+
},
|
|
2598
|
+
async (res) => {
|
|
2599
|
+
let portalIdHeader;
|
|
2600
|
+
let contentId;
|
|
2601
|
+
const isContentMembershipRedirect = Boolean(
|
|
2602
|
+
res.headers["x-hs-content-membership-redirect"]
|
|
2338
2603
|
);
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
islands = islands.concat(renderContext.islands);
|
|
2350
|
-
}
|
|
2351
|
-
mergedPerRequestState = mergeServerRequestData_internal(
|
|
2352
|
-
mergedPerRequestState,
|
|
2353
|
-
renderContext.perServerRequestData
|
|
2354
|
-
);
|
|
2355
|
-
let result = html;
|
|
2356
|
-
if (inlineAssets) {
|
|
2357
|
-
result = `${inlineAssets.map((inlineAsset) => inlineAsset.html).join("\n")}
|
|
2358
|
-
${result}`;
|
|
2359
|
-
}
|
|
2360
|
-
if (cssNeeded) {
|
|
2361
|
-
result = `${cssNeeded}
|
|
2362
|
-
${result}`;
|
|
2604
|
+
if (isContentMembershipRedirect) {
|
|
2605
|
+
debug("Content Membership Redirect", res.headers);
|
|
2606
|
+
portalIdHeader = res.headers["x-hs-portal-id"];
|
|
2607
|
+
contentId = res.headers["x-hs-content-id"];
|
|
2608
|
+
if (portalIdHeader && contentId) {
|
|
2609
|
+
return resolve3({
|
|
2610
|
+
portalIdHeader,
|
|
2611
|
+
contentId,
|
|
2612
|
+
res
|
|
2613
|
+
});
|
|
2363
2614
|
}
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2615
|
+
}
|
|
2616
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
2617
|
+
console.log(`Redirecting to ${res.headers.location} (from ${url3})`);
|
|
2618
|
+
return resolve3(
|
|
2619
|
+
requestPage(
|
|
2620
|
+
res.headers.location,
|
|
2621
|
+
redirects + 1,
|
|
2622
|
+
originalUrl ?? url3
|
|
2623
|
+
)
|
|
2372
2624
|
);
|
|
2373
|
-
|
|
2374
|
-
|
|
2625
|
+
}
|
|
2626
|
+
portalIdHeader = res.headers["x-hs-hub-id"];
|
|
2627
|
+
contentId = res.headers["x-hs-content-id"];
|
|
2628
|
+
return resolve3({
|
|
2629
|
+
res,
|
|
2630
|
+
portalIdHeader,
|
|
2631
|
+
contentId
|
|
2375
2632
|
});
|
|
2376
|
-
offsetSoFar = localRenderPlaceholder.endOffset;
|
|
2377
|
-
}
|
|
2378
|
-
pageChunks[localRenderPlaceholders.length] = pageHtml.slice(offsetSoFar);
|
|
2379
|
-
response.writeHead(200);
|
|
2380
|
-
for (let i = 0; i < localRenderPlaceholders.length; i++) {
|
|
2381
|
-
const chunk = pageChunks[i];
|
|
2382
|
-
response.write(chunk);
|
|
2383
|
-
const foobar = await renderPromisesByChunkIndex[i];
|
|
2384
|
-
response.write(foobar);
|
|
2385
2633
|
}
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2634
|
+
).on("error", (err) => {
|
|
2635
|
+
console.error(err);
|
|
2636
|
+
reject(err);
|
|
2637
|
+
}).end();
|
|
2638
|
+
});
|
|
2639
|
+
}
|
|
2640
|
+
async function fetchContentMetadata(url3, portalId) {
|
|
2641
|
+
const { portalIdHeader, contentId, res } = await requestPage(url3);
|
|
2642
|
+
if (Array.isArray(portalIdHeader) || Array.isArray(contentId)) {
|
|
2643
|
+
throw new Error(
|
|
2644
|
+
`There were multiple hub ID or content ID headers in the HEAD request to ${url3}`
|
|
2645
|
+
);
|
|
2646
|
+
} else {
|
|
2647
|
+
const portalIdFromResponse = parseInt(portalIdHeader, 10);
|
|
2648
|
+
const pageAccount = await getAccountId2(portalIdFromResponse);
|
|
2649
|
+
if (!pageAccount) {
|
|
2650
|
+
throw new Error(
|
|
2651
|
+
`No CLI auth for portal ${portalIdFromResponse} found, please run \`hs auth\``
|
|
2394
2652
|
);
|
|
2395
|
-
if (criticalDevErrors.length) {
|
|
2396
|
-
response.write(
|
|
2397
|
-
scriptTagToLogServerMessages(
|
|
2398
|
-
criticalDevErrorsToServerMessages_default(criticalDevErrors),
|
|
2399
|
-
"@hubspot/cms-dev-server messages"
|
|
2400
|
-
)
|
|
2401
|
-
);
|
|
2402
|
-
}
|
|
2403
|
-
if (islands.length > 0) {
|
|
2404
|
-
const sortedIslandRoots = sortIslandRootsByPriority(islands);
|
|
2405
|
-
const islandRuntimeAndGlobalScriptHtml = await getIslandRuntimeAndGlobalToInject(
|
|
2406
|
-
sortedIslandRoots,
|
|
2407
|
-
mergedPerRequestState,
|
|
2408
|
-
viteServer,
|
|
2409
|
-
jsRenderingGates,
|
|
2410
|
-
prettyPrint
|
|
2411
|
-
);
|
|
2412
|
-
response.write(islandRuntimeAndGlobalScriptHtml);
|
|
2413
|
-
}
|
|
2414
|
-
response.write(pageChunks[pageChunks.length - 1]);
|
|
2415
|
-
response.end();
|
|
2416
|
-
} else {
|
|
2417
|
-
response.writeHead(200);
|
|
2418
|
-
response.write(pageHtml);
|
|
2419
|
-
response.end();
|
|
2420
2653
|
}
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2654
|
+
if (res.statusCode !== 200 && !(portalIdFromResponse && pageAccount && contentId)) {
|
|
2655
|
+
throw new Error(
|
|
2656
|
+
`${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.` : ""}`
|
|
2657
|
+
);
|
|
2658
|
+
} else if (!portalId || !contentId) {
|
|
2659
|
+
throw new Error(
|
|
2660
|
+
`Missing hub ID or content ID headers on HEAD request to ${url3}`
|
|
2661
|
+
);
|
|
2662
|
+
} else if (isNaN(portalId)) {
|
|
2663
|
+
throw new Error(
|
|
2664
|
+
`Hub ID from the HEAD request is not a number: '${portalId}' (${url3})`
|
|
2665
|
+
);
|
|
2666
|
+
}
|
|
2667
|
+
const hublet = "na1";
|
|
2668
|
+
return { portalId, contentId, hublet };
|
|
2428
2669
|
}
|
|
2429
2670
|
}
|
|
2430
2671
|
|
|
@@ -2728,11 +2969,8 @@ function proxyServerlessRequest(req, res, next) {
|
|
|
2728
2969
|
}
|
|
2729
2970
|
|
|
2730
2971
|
// src/routes/modulePreviewRouteHandler.ts
|
|
2731
|
-
import
|
|
2732
|
-
import
|
|
2733
|
-
import { normalizePath as normalizePath5 } from "vite";
|
|
2734
|
-
import localDevHttpImport6 from "@hubspot/local-dev-lib/http";
|
|
2735
|
-
var { default: hsCliHttp6 } = localDevHttpImport6;
|
|
2972
|
+
import path7 from "path";
|
|
2973
|
+
import { normalizePath as normalizePath6 } from "vite";
|
|
2736
2974
|
async function modulePreviewRouteHandler(request2, response) {
|
|
2737
2975
|
sendTrackingRequest("view-module-preview-route");
|
|
2738
2976
|
const {
|
|
@@ -2746,116 +2984,27 @@ async function modulePreviewRouteHandler(request2, response) {
|
|
|
2746
2984
|
projectComponentPath
|
|
2747
2985
|
} = request2.app.locals;
|
|
2748
2986
|
const moduleName = request2.params.moduleName;
|
|
2749
|
-
const modulePath =
|
|
2750
|
-
|
|
2751
|
-
);
|
|
2752
|
-
const basePath = `preview/${getEntryPointBasePath(modulePath)}`;
|
|
2753
|
-
const environmentConfig = buildStaticEnvConfig4(
|
|
2754
|
-
authedPortalId,
|
|
2755
|
-
authedHublet,
|
|
2756
|
-
authedEnv,
|
|
2757
|
-
false,
|
|
2758
|
-
jsRenderingGates
|
|
2987
|
+
const modulePath = normalizePath6(
|
|
2988
|
+
path7.resolve(webRoot2, "components/modules/", moduleName)
|
|
2759
2989
|
);
|
|
2760
|
-
let templatePreview;
|
|
2761
|
-
try {
|
|
2762
|
-
let componentModule;
|
|
2763
|
-
let foundPath;
|
|
2764
|
-
if (!hasComponentExtension(modulePath)) {
|
|
2765
|
-
[componentModule, foundPath] = await lookForModuleInFolder2(
|
|
2766
|
-
modulePath,
|
|
2767
|
-
viteServer
|
|
2768
|
-
);
|
|
2769
|
-
}
|
|
2770
|
-
if (!componentModule) {
|
|
2771
|
-
componentModule = await viteServer.ssrLoadModule(modulePath);
|
|
2772
|
-
foundPath = componentModule ? modulePath : void 0;
|
|
2773
|
-
}
|
|
2774
|
-
if (!componentModule) {
|
|
2775
|
-
throw new Error(`Couldn't find module: ${modulePath}`);
|
|
2776
|
-
}
|
|
2777
|
-
const Component = componentModule.Component;
|
|
2778
|
-
const fields = componentModule.fields;
|
|
2779
|
-
const meta = componentModule.meta;
|
|
2780
|
-
const hublDataTemplate = componentModule.hublDataTemplate;
|
|
2781
|
-
if (!Component) {
|
|
2782
|
-
throw new Error(
|
|
2783
|
-
`Module does not have a named Component export: ${foundPath}`
|
|
2784
|
-
);
|
|
2785
|
-
} else if (!fields) {
|
|
2786
|
-
throw new Error(
|
|
2787
|
-
`Module does not have a named fields export: ${foundPath}`
|
|
2788
|
-
);
|
|
2789
|
-
} else if (!meta) {
|
|
2790
|
-
throw new Error(`Module does not have a named meta export: ${foundPath}`);
|
|
2791
|
-
}
|
|
2792
|
-
const internalSsrPath = packagePath(import.meta.url, "internalSsr");
|
|
2793
|
-
const { renderFieldsToJson } = await viteServer.ssrLoadModule(internalSsrPath);
|
|
2794
|
-
const localFieldsJson = renderFieldsToJson(fields, modulePath);
|
|
2795
|
-
const localModule = {
|
|
2796
|
-
isJsModule: true,
|
|
2797
|
-
schemaVersion: 2,
|
|
2798
|
-
fields: localFieldsJson,
|
|
2799
|
-
id: 1,
|
|
2800
|
-
path: `@projects/${projectName}/${projectComponentPath}/components/modules/${moduleName}`,
|
|
2801
|
-
hublDataTemplate
|
|
2802
|
-
};
|
|
2803
|
-
const queryParams = new URLSearchParams({
|
|
2804
|
-
portalId: `${authedPortalId}`,
|
|
2805
|
-
hsLocalProxy: `${true}`,
|
|
2806
|
-
localProxySchemaVersion: "2",
|
|
2807
|
-
hsLoginVerifyDisabled: `${true}`
|
|
2808
|
-
});
|
|
2809
|
-
const currentHubApiDomainOverride = process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
2810
|
-
process.env.HUBAPI_DOMAIN_OVERRIDE = `api.hubspot`;
|
|
2811
|
-
const templatePreviewPromise = hsCliHttp6.post(authedPortalId, {
|
|
2812
|
-
url: `/api/cos-rendering/v1/public/_hcms/preview/template/multiform?${queryParams}`,
|
|
2813
|
-
headers: {
|
|
2814
|
-
["content-type"]: "application/x-www-form-urlencoded",
|
|
2815
|
-
["Accept"]: "text/html",
|
|
2816
|
-
referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
|
|
2817
|
-
cookie: request2.get("COOKIE"),
|
|
2818
|
-
"User-Agent": "HubSpot CMS Dev Server"
|
|
2819
|
-
},
|
|
2820
|
-
data: `module=${encodeURIComponent(JSON.stringify(localModule))}`
|
|
2821
|
-
});
|
|
2822
|
-
if (currentHubApiDomainOverride) {
|
|
2823
|
-
process.env.HUBAPI_DOMAIN_OVERRIDE = currentHubApiDomainOverride;
|
|
2824
|
-
} else {
|
|
2825
|
-
delete process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
2826
|
-
}
|
|
2827
|
-
templatePreview = await templatePreviewPromise;
|
|
2828
|
-
} catch (e) {
|
|
2829
|
-
return response.status(500).end(`Error fetching module preview for (${moduleName}).
|
|
2830
|
-
|
|
2831
|
-
${e}.
|
|
2832
|
-
|
|
2833
|
-
`);
|
|
2834
|
-
}
|
|
2835
2990
|
try {
|
|
2836
|
-
const localRenderPlaceholders = findLocalRenderPlaceholders(templatePreview);
|
|
2837
|
-
if (localRenderPlaceholders.length !== 1) {
|
|
2838
|
-
return response.status(500).end(
|
|
2839
|
-
`Error previewing module (${moduleName}), exception in module preview HTML
|
|
2840
|
-
|
|
2841
|
-
`
|
|
2842
|
-
);
|
|
2843
|
-
}
|
|
2844
2991
|
const {
|
|
2845
2992
|
html: renderedHtml,
|
|
2846
2993
|
cssNeeded,
|
|
2847
2994
|
renderContext,
|
|
2848
2995
|
inlineAssets
|
|
2849
|
-
} = await
|
|
2850
|
-
|
|
2851
|
-
|
|
2996
|
+
} = await renderLocalProjectModulePreview(
|
|
2997
|
+
moduleName,
|
|
2998
|
+
authedPortalId,
|
|
2999
|
+
authedEnv,
|
|
3000
|
+
authedHublet,
|
|
2852
3001
|
webRoot2,
|
|
2853
3002
|
viteServer,
|
|
2854
|
-
|
|
2855
|
-
basePath,
|
|
2856
|
-
environmentConfig,
|
|
3003
|
+
jsRenderingGates,
|
|
2857
3004
|
projectName,
|
|
2858
|
-
projectComponentPath
|
|
3005
|
+
projectComponentPath,
|
|
3006
|
+
fullOriginalUrlFromRequest(request2),
|
|
3007
|
+
request2.get("COOKIE")
|
|
2859
3008
|
);
|
|
2860
3009
|
const baseTemplatePath = packagePath(
|
|
2861
3010
|
import.meta.url,
|
|
@@ -3321,7 +3470,7 @@ async function fetchWebsiteDomainNames(portalId) {
|
|
|
3321
3470
|
}
|
|
3322
3471
|
|
|
3323
3472
|
// src/lib/validateHSPlatform.ts
|
|
3324
|
-
import
|
|
3473
|
+
import path8 from "path";
|
|
3325
3474
|
import fs3 from "fs";
|
|
3326
3475
|
import select from "@inquirer/select";
|
|
3327
3476
|
import localDevHttpImport8 from "@hubspot/local-dev-lib/http";
|
|
@@ -3334,12 +3483,12 @@ function findHSProjectJson(startPath) {
|
|
|
3334
3483
|
let currentDir = startPath;
|
|
3335
3484
|
let dirLevel = 0;
|
|
3336
3485
|
const maxDirLevel = 4;
|
|
3337
|
-
while (
|
|
3338
|
-
const filePath =
|
|
3486
|
+
while (path8.dirname(currentDir) !== currentDir && dirLevel < maxDirLevel) {
|
|
3487
|
+
const filePath = path8.join(currentDir, HSPROJECT_JSON);
|
|
3339
3488
|
if (checkFileExists(filePath)) {
|
|
3340
3489
|
return filePath;
|
|
3341
3490
|
}
|
|
3342
|
-
currentDir =
|
|
3491
|
+
currentDir = path8.dirname(currentDir);
|
|
3343
3492
|
dirLevel++;
|
|
3344
3493
|
}
|
|
3345
3494
|
console.log(
|
|
@@ -3645,7 +3794,7 @@ function writeFieldsType(fields, fileName, typeName) {
|
|
|
3645
3794
|
|
|
3646
3795
|
// src/lib/watchFieldsUpdates.ts
|
|
3647
3796
|
import fs4 from "fs";
|
|
3648
|
-
import
|
|
3797
|
+
import path9 from "path";
|
|
3649
3798
|
import readline from "readline";
|
|
3650
3799
|
var lastSerializedFieldsCache = {};
|
|
3651
3800
|
var formatAsTypeName = (str) => {
|
|
@@ -3657,9 +3806,9 @@ var isInModulesFolder = (filePath, projectRoot) => {
|
|
|
3657
3806
|
const getEntryPathFromId = (id) => {
|
|
3658
3807
|
return id.startsWith(projectRoot) ? id.replace(`${projectRoot}/`, "") : "";
|
|
3659
3808
|
};
|
|
3660
|
-
const currentModuleId =
|
|
3809
|
+
const currentModuleId = path9.normalize(filePath);
|
|
3661
3810
|
const moduleEntryPath = getEntryPathFromId(currentModuleId);
|
|
3662
|
-
const subFolderTokens = moduleEntryPath.split(
|
|
3811
|
+
const subFolderTokens = moduleEntryPath.split(path9.sep);
|
|
3663
3812
|
return {
|
|
3664
3813
|
inModuleFolder: subFolderTokens[0] === "components" && subFolderTokens[1] === "modules",
|
|
3665
3814
|
isRootModuleFile: subFolderTokens.length === 3
|
|
@@ -3686,10 +3835,10 @@ var getIndexFile = (filePath, projectRoot) => {
|
|
|
3686
3835
|
return void 0;
|
|
3687
3836
|
if (isRootModuleFile)
|
|
3688
3837
|
return { indexFilePath: filePath, isRootModuleFile };
|
|
3689
|
-
const dir =
|
|
3838
|
+
const dir = path9.dirname(filePath);
|
|
3690
3839
|
const files = fs4.readdirSync(dir);
|
|
3691
3840
|
const indexFileName = files.find((file) => file.startsWith("index."));
|
|
3692
|
-
return indexFileName ? { indexFilePath:
|
|
3841
|
+
return indexFileName ? { indexFilePath: path9.join(dir, indexFileName), isRootModuleFile } : void 0;
|
|
3693
3842
|
};
|
|
3694
3843
|
var getIndexFileFields = async (indexFilePath, indexFileName, viteServer) => {
|
|
3695
3844
|
let indexFile;
|
|
@@ -3713,7 +3862,7 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
|
|
|
3713
3862
|
if (!indexInfo)
|
|
3714
3863
|
return;
|
|
3715
3864
|
const { indexFilePath, isRootModuleFile } = indexInfo;
|
|
3716
|
-
const indexFileName =
|
|
3865
|
+
const indexFileName = path9.parse(indexFilePath).name;
|
|
3717
3866
|
const isTypeFile = filePath.endsWith(".types.ts");
|
|
3718
3867
|
if (isTypeFile)
|
|
3719
3868
|
return;
|
|
@@ -3724,7 +3873,7 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
|
|
|
3724
3873
|
);
|
|
3725
3874
|
if (fields) {
|
|
3726
3875
|
const typeFileName = isRootModuleFile ? `${indexFileName}.fields.types.ts` : "fields.type.ts";
|
|
3727
|
-
const typeFilePath =
|
|
3876
|
+
const typeFilePath = path9.join(path9.dirname(filePath), typeFileName);
|
|
3728
3877
|
const lastSerializedFields = lastSerializedFieldsCache[typeFilePath];
|
|
3729
3878
|
const serializedFields = JSON.stringify(fields);
|
|
3730
3879
|
if (lastSerializedFields === serializedFields)
|
|
@@ -3732,7 +3881,7 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
|
|
|
3732
3881
|
const hasAutoGenComment = await fileContainsAutoGenComment(typeFilePath);
|
|
3733
3882
|
if (!hasAutoGenComment)
|
|
3734
3883
|
return;
|
|
3735
|
-
const moduleFolderName =
|
|
3884
|
+
const moduleFolderName = path9.basename(path9.dirname(filePath));
|
|
3736
3885
|
const outputTypeName = formatAsTypeName(moduleFolderName);
|
|
3737
3886
|
const didSucceed = writeFieldsType(fields, typeFilePath, outputTypeName);
|
|
3738
3887
|
if (didSucceed) {
|
|
@@ -3748,7 +3897,7 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
|
|
|
3748
3897
|
var startFieldsTypeGenWatcher = (viteServer, projectRoot) => {
|
|
3749
3898
|
const { moduleSubpaths } = findAllModulesInRoot(projectRoot);
|
|
3750
3899
|
moduleSubpaths.forEach((modulePath) => {
|
|
3751
|
-
const resolvedPath =
|
|
3900
|
+
const resolvedPath = path9.resolve(projectRoot, modulePath);
|
|
3752
3901
|
maybeUpdateFields(resolvedPath, viteServer, projectRoot);
|
|
3753
3902
|
});
|
|
3754
3903
|
const watchCallback = (filePath) => maybeUpdateFields(filePath, viteServer, projectRoot);
|
|
@@ -3881,7 +4030,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
3881
4030
|
} catch (e) {
|
|
3882
4031
|
authedHublet = "na1";
|
|
3883
4032
|
}
|
|
3884
|
-
const absoluteWebRoot =
|
|
4033
|
+
const absoluteWebRoot = normalizePath7(path10.resolve(process.cwd(), webRoot2));
|
|
3885
4034
|
const [__webRootProjectFolder, webRootProjectComponentFolder] = absoluteWebRoot.replace(/\/$/, "").split("/").slice(-2);
|
|
3886
4035
|
const projectConfigPath = findHSProjectJson(absoluteWebRoot);
|
|
3887
4036
|
if (authedPortalId) {
|
|
@@ -3958,8 +4107,8 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
|
|
|
3958
4107
|
`
|
|
3959
4108
|
);
|
|
3960
4109
|
if (storybook2) {
|
|
3961
|
-
const packageRoot =
|
|
3962
|
-
const configPath =
|
|
4110
|
+
const packageRoot = path10.dirname(url2.fileURLToPath(import.meta.url));
|
|
4111
|
+
const configPath = path10.resolve(packageRoot, "./storybook-main");
|
|
3963
4112
|
sendTrackingRequest("start-storybook");
|
|
3964
4113
|
const storybookProcess = spawn(
|
|
3965
4114
|
"sb",
|
|
@@ -3979,7 +4128,7 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
|
|
|
3979
4128
|
portalId: authedPortalId.toString(),
|
|
3980
4129
|
hsEnv: authedEnv,
|
|
3981
4130
|
hublet: authedHublet,
|
|
3982
|
-
WEB_ROOT:
|
|
4131
|
+
WEB_ROOT: path10.join(webRoot2, "components")
|
|
3983
4132
|
}
|
|
3984
4133
|
}
|
|
3985
4134
|
);
|