@hubspot/cms-dev-server 0.4.17 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ModulesList.js +14 -0
- package/dist/components/PartialsList.js +13 -0
- package/dist/createDevServer.js +162 -0
- package/dist/createViteDevServer.js +51 -0
- package/dist/fsevents-72LCIACT.node +0 -0
- package/dist/index.js +2 -2
- package/dist/internalSsr.js +20 -6
- package/dist/lib/cli.js +27 -0
- package/dist/lib/debug.js +2 -0
- package/dist/lib/errors.js +22 -0
- package/dist/lib/fullOriginalUrlFromRequest.js +3 -0
- package/dist/lib/httpsRedirectingServer.js +48 -0
- package/dist/lib/moduleGraph.js +11 -0
- package/dist/lib/proxyHelpers.js +70 -0
- package/dist/lib/proxyHelpers.test.js +136 -0
- package/dist/lib/renderComponentWithCSS.js +26 -0
- package/dist/lib/renderHelpers.js +45 -0
- package/dist/lib/renderModule.js +56 -0
- package/dist/lib/renderPartial.js +15 -0
- package/dist/lib/templates.js +55 -0
- package/dist/proxyPage/constants.js +1 -0
- package/dist/proxyPage/fetchContentMetadata.js +59 -0
- package/dist/proxyPage/fetchDomains.js +29 -0
- package/dist/proxyPage/fetchPreviewInfo.js +37 -0
- package/dist/proxyPage/proxyPage.js +174 -0
- package/dist/proxyPage/renderLocalError.js +27 -0
- package/dist/proxyPage/utils.js +38 -0
- package/dist/routes/createDevServerRoutes.js +43 -0
- package/dist/routes/homeRouteHandler.js +12 -0
- package/dist/routes/linksToAllModulesRouteHandler.js +10 -0
- package/dist/routes/linksToAllPartialsRouteHandler.js +10 -0
- package/dist/routes/module.js +41 -0
- package/dist/routes/partial.js +30 -0
- package/dist/routes/proxyPageResourceRedirect.js +22 -0
- package/dist/routes/proxyPageRouteHandler.js +40 -0
- package/dist/routes/proxyPathPageResourceRedirect.js +36 -0
- package/dist/routes/proxyPathPageRouteHandler.js +43 -0
- package/dist/run.js +157 -50
- package/dist/shadowDevServer/createShadowDevServerRoutes.js +63 -0
- package/dist/shadowDevServer/startShadowDevServer.js +31 -0
- package/dist/storybook/getFieldsArgTypes.js +54 -0
- package/dist/storybook/getFieldsArgTypes.test.js +91 -0
- package/dist/storybook/getNestedFieldObjectForArgs.js +22 -0
- package/dist/storybook/getNestedFieldObjectForArgs.test.js +40 -0
- package/dist/storybook/index.js +1 -1
- package/dist/storybook/main.js +21 -7
- package/dist/storybook/moduleStory.js +61 -0
- package/dist/storybook/preview.js +9 -0
- package/dist/storybook/types.js +1 -0
- package/package.json +3 -3
package/dist/run.js
CHANGED
|
@@ -60,7 +60,7 @@ import { createRequire } from "module";
|
|
|
60
60
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
61
61
|
import stream from "stream";
|
|
62
62
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
63
|
-
import {
|
|
63
|
+
import { createServerRenderContextV2, ServerRenderContext } from "@hubspot/cms-components";
|
|
64
64
|
import { createHash } from "crypto";
|
|
65
65
|
import { existsSync, readdirSync, lstatSync } from "fs";
|
|
66
66
|
import { join } from "path/posix";
|
|
@@ -148,6 +148,12 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
|
|
|
148
148
|
)}${writeSharedStateToJsGlobal(islands, perServerRequestData, indent)}`;
|
|
149
149
|
};
|
|
150
150
|
var require2 = createRequire(import.meta.url);
|
|
151
|
+
var ENABLED_FEATURES_GATE_MAP = {
|
|
152
|
+
"cms:jsr:sharedDeps": "CMS:JSRenderer:SharedDeps",
|
|
153
|
+
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
154
|
+
"cms:jsr:localProxySchemaVersion1": "CMS:JSRenderer:LocalProxySchemaVersion1",
|
|
155
|
+
"cms:jsr:graphqQLQueryBuild": "CMS:JSRenderer:GraphQLQueryBuild"
|
|
156
|
+
};
|
|
151
157
|
function isUngatedFor(gates, gate) {
|
|
152
158
|
return gates.includes(gate);
|
|
153
159
|
}
|
|
@@ -190,7 +196,7 @@ function resolveIslandPlugin(gates) {
|
|
|
190
196
|
}
|
|
191
197
|
};
|
|
192
198
|
}
|
|
193
|
-
var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: `island-${renderableIsland.index}-`,\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
199
|
+
var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: `island-${renderableIsland.index}-`,\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
194
200
|
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
195
201
|
function clientIslandEntryPlugin() {
|
|
196
202
|
return {
|
|
@@ -283,8 +289,11 @@ ${consoleLines.join("\n")}
|
|
|
283
289
|
${groupEnd}</script>
|
|
284
290
|
`;
|
|
285
291
|
};
|
|
286
|
-
async function renderOnServer(elements, pageUrl, environmentConfig, debugName, renderOptions) {
|
|
287
|
-
const renderContext =
|
|
292
|
+
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, debugName, renderOptions) {
|
|
293
|
+
const renderContext = createServerRenderContextV2(pageUrl, {
|
|
294
|
+
environmentConfig,
|
|
295
|
+
entryPointBasePath
|
|
296
|
+
});
|
|
288
297
|
let html = await renderStreamToPromise(
|
|
289
298
|
/* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
|
290
299
|
renderOptions
|
|
@@ -383,13 +392,16 @@ function findAllPartialsInRoot(webRoot2) {
|
|
|
383
392
|
);
|
|
384
393
|
return { partialNames, partialSubpaths };
|
|
385
394
|
}
|
|
386
|
-
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl) {
|
|
395
|
+
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath) {
|
|
387
396
|
const globals = [
|
|
388
397
|
`window.__hsEnvConfig = ${JSON.stringify(environmentConfig.toJSON())};`
|
|
389
398
|
];
|
|
390
399
|
if (hsServerPageUrl) {
|
|
391
400
|
globals.push(`window.__hsServerPageUrl = '${hsServerPageUrl}';`);
|
|
392
401
|
}
|
|
402
|
+
if (hsBasePath) {
|
|
403
|
+
globals.push(`window.__hsBasePath = '${hsBasePath}';`);
|
|
404
|
+
}
|
|
393
405
|
return `
|
|
394
406
|
<script type="text/javascript">
|
|
395
407
|
${globals.join("\n ")}
|
|
@@ -429,16 +441,6 @@ function renderFieldsToJson(fields) {
|
|
|
429
441
|
return moduleJson;
|
|
430
442
|
}
|
|
431
443
|
|
|
432
|
-
// src/lib/moduleGraph.ts
|
|
433
|
-
var findFullPathInModuleGraph = (modulePathNoExtension, moduleGraph) => {
|
|
434
|
-
for (const extension of COMPONENT_EXTENSIONS) {
|
|
435
|
-
const pathToTry = `${modulePathNoExtension}${extension}`;
|
|
436
|
-
if (moduleGraph.fileToModulesMap.has(pathToTry)) {
|
|
437
|
-
return pathToTry;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
};
|
|
441
|
-
|
|
442
444
|
// src/lib/packagePath.ts
|
|
443
445
|
import path2 from "path";
|
|
444
446
|
import url from "url";
|
|
@@ -456,10 +458,18 @@ function packagePath(metaUrl, projectPath) {
|
|
|
456
458
|
);
|
|
457
459
|
}
|
|
458
460
|
|
|
459
|
-
// src/lib/
|
|
460
|
-
|
|
461
|
-
const
|
|
462
|
-
|
|
461
|
+
// src/lib/moduleGraph.ts
|
|
462
|
+
var findFullPathInModuleGraph = (modulePathNoExtension, moduleGraph) => {
|
|
463
|
+
for (const extension of COMPONENT_EXTENSIONS) {
|
|
464
|
+
const pathToTry = `${modulePathNoExtension}${extension}`;
|
|
465
|
+
if (moduleGraph.fileToModulesMap.has(pathToTry)) {
|
|
466
|
+
return pathToTry;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
// src/lib/pathHelpers.ts
|
|
472
|
+
var getComponentPaths = (viteServer, componentPath) => {
|
|
463
473
|
let componentPathWithExtension;
|
|
464
474
|
let componentPathNoExtension;
|
|
465
475
|
if (hasComponentExtension(componentPath)) {
|
|
@@ -468,13 +478,6 @@ async function renderComponentWithCSS(viteServer, componentPath, Component, prop
|
|
|
468
478
|
} else {
|
|
469
479
|
componentPathNoExtension = componentPath;
|
|
470
480
|
}
|
|
471
|
-
const { html, renderContext } = await renderComponentOnServer(
|
|
472
|
-
Component,
|
|
473
|
-
props,
|
|
474
|
-
pageUrl,
|
|
475
|
-
environmentConfig,
|
|
476
|
-
renderOptions
|
|
477
|
-
);
|
|
478
481
|
if (!componentPathWithExtension) {
|
|
479
482
|
componentPathWithExtension = findFullPathInModuleGraph(
|
|
480
483
|
componentPathNoExtension,
|
|
@@ -486,6 +489,34 @@ async function renderComponentWithCSS(viteServer, componentPath, Component, prop
|
|
|
486
489
|
);
|
|
487
490
|
}
|
|
488
491
|
}
|
|
492
|
+
return [componentPathNoExtension, componentPathWithExtension];
|
|
493
|
+
};
|
|
494
|
+
var getEntryPointBasePath = (componentPath) => {
|
|
495
|
+
if (componentPath.includes(ENTRY_POINTS_PATH)) {
|
|
496
|
+
return `partial/${componentPath.split(ENTRY_POINTS_PATH)[1]}`;
|
|
497
|
+
}
|
|
498
|
+
if (componentPath.includes(MODULE_FOLDER_PATH)) {
|
|
499
|
+
return `module/${componentPath.split(MODULE_FOLDER_PATH)[1]}`;
|
|
500
|
+
}
|
|
501
|
+
throw new Error("Unknown entry point path type");
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
// src/lib/renderComponentWithCSS.ts
|
|
505
|
+
async function renderComponentWithCSS(viteServer, componentPath, Component, props, pageUrl, entryPointBasePath, environmentConfig, renderOptions) {
|
|
506
|
+
const internalSsrPath = packagePath(import.meta.url, "internalSsr");
|
|
507
|
+
const { renderComponentOnServer, collectCssInDev } = await viteServer.ssrLoadModule(internalSsrPath);
|
|
508
|
+
const [, componentPathWithExtension] = getComponentPaths(
|
|
509
|
+
viteServer,
|
|
510
|
+
componentPath
|
|
511
|
+
);
|
|
512
|
+
const { html, renderContext } = await renderComponentOnServer(
|
|
513
|
+
Component,
|
|
514
|
+
props,
|
|
515
|
+
pageUrl,
|
|
516
|
+
environmentConfig,
|
|
517
|
+
entryPointBasePath,
|
|
518
|
+
renderOptions
|
|
519
|
+
);
|
|
489
520
|
const cssNeeded = collectCssInDev(componentPathWithExtension, viteServer);
|
|
490
521
|
return { html, cssNeeded, renderContext };
|
|
491
522
|
}
|
|
@@ -532,17 +563,15 @@ var logPartialInfo = (partialPath, props) => {
|
|
|
532
563
|
console.groupEnd();
|
|
533
564
|
};
|
|
534
565
|
|
|
535
|
-
// src/lib/constants.ts
|
|
536
|
-
var Gates = {
|
|
537
|
-
GET_SERVER_SIDE_PROPS: "CMS:JSRenderer:GetServerSideProps"
|
|
538
|
-
};
|
|
539
|
-
|
|
540
566
|
// src/lib/renderPartial.ts
|
|
541
|
-
async function renderPartial(viteServer, partialPath, props, pageUrl, environmentConfig, renderOptions) {
|
|
567
|
+
async function renderPartial(viteServer, partialPath, props, pageUrl, basePath, environmentConfig, renderOptions) {
|
|
542
568
|
logPartialInfo(partialPath, props);
|
|
543
569
|
let serverSideProps;
|
|
544
570
|
const componentModule = await viteServer.ssrLoadModule(partialPath);
|
|
545
|
-
const ungatedForServerSideProps =
|
|
571
|
+
const ungatedForServerSideProps = isUngatedFor(
|
|
572
|
+
environmentConfig.getGates(),
|
|
573
|
+
"CMS:JSRenderer:GetServerSideProps"
|
|
574
|
+
);
|
|
546
575
|
if (!componentModule) {
|
|
547
576
|
throw new Error(`Couldn't find partial: ${partialPath}`);
|
|
548
577
|
}
|
|
@@ -553,7 +582,7 @@ async function renderPartial(viteServer, partialPath, props, pageUrl, environmen
|
|
|
553
582
|
if (ungatedForServerSideProps && componentModule.getServerSidePropsUnstable) {
|
|
554
583
|
try {
|
|
555
584
|
serverSideProps = await componentModule.getServerSidePropsUnstable(props);
|
|
556
|
-
if (serverSideProps.constructor !==
|
|
585
|
+
if (serverSideProps.constructor !== {}.constructor) {
|
|
557
586
|
throw new Error("getServerSidePropsUnstable must return an object");
|
|
558
587
|
}
|
|
559
588
|
} catch (e) {
|
|
@@ -567,6 +596,7 @@ async function renderPartial(viteServer, partialPath, props, pageUrl, environmen
|
|
|
567
596
|
Component,
|
|
568
597
|
{ ...props, ...serverSideProps },
|
|
569
598
|
pageUrl,
|
|
599
|
+
basePath,
|
|
570
600
|
environmentConfig,
|
|
571
601
|
renderOptions
|
|
572
602
|
);
|
|
@@ -628,7 +658,8 @@ var createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url3, tit
|
|
|
628
658
|
if (renderContext.islands.length) {
|
|
629
659
|
const globalScriptBlock = getServerGlobalsToInject(
|
|
630
660
|
renderContext.environmentConfig,
|
|
631
|
-
renderContext.pageUrl
|
|
661
|
+
renderContext.pageUrl,
|
|
662
|
+
renderContext.entryPointBasePath
|
|
632
663
|
);
|
|
633
664
|
htmlTemplate = await createIslandHtmlTemplate(
|
|
634
665
|
baseTemplatePath,
|
|
@@ -707,6 +738,7 @@ var partialRouteHandler = async (request2, response) => {
|
|
|
707
738
|
partialName
|
|
708
739
|
].join("/")
|
|
709
740
|
);
|
|
741
|
+
const basePath = getEntryPointBasePath(partialPath);
|
|
710
742
|
const environmentConfig = buildStaticEnvConfig(
|
|
711
743
|
authedPortalId,
|
|
712
744
|
authedHublet,
|
|
@@ -724,6 +756,7 @@ var partialRouteHandler = async (request2, response) => {
|
|
|
724
756
|
partialPath,
|
|
725
757
|
{},
|
|
726
758
|
fullOriginalUrlFromRequest(request2),
|
|
759
|
+
basePath,
|
|
727
760
|
environmentConfig,
|
|
728
761
|
{
|
|
729
762
|
identifierPrefix: getEntryPointHash(entrypointPath)
|
|
@@ -778,7 +811,8 @@ var linksToAllPartialRouteHandler = async (request2, response) => {
|
|
|
778
811
|
const { html: responseHtml } = await renderOnServer(
|
|
779
812
|
/* @__PURE__ */ jsx4(PartialsList, { webRoot: webRoot2, partialNames }),
|
|
780
813
|
null,
|
|
781
|
-
null
|
|
814
|
+
null,
|
|
815
|
+
""
|
|
782
816
|
);
|
|
783
817
|
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
784
818
|
};
|
|
@@ -814,7 +848,8 @@ var linksToAllModuleRouteHandler = async (request2, response) => {
|
|
|
814
848
|
const { html: responseHtml } = await renderOnServer(
|
|
815
849
|
/* @__PURE__ */ jsx6(ModulesList_default, { webRoot: webRoot2, moduleNames }),
|
|
816
850
|
null,
|
|
817
|
-
null
|
|
851
|
+
null,
|
|
852
|
+
""
|
|
818
853
|
);
|
|
819
854
|
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
820
855
|
};
|
|
@@ -840,9 +875,12 @@ var lookForModuleInFolder = async (modulePath, viteServer) => {
|
|
|
840
875
|
}
|
|
841
876
|
return [componentModule, insideFolderPath];
|
|
842
877
|
};
|
|
843
|
-
async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}, pageUrl, environmentConfig, renderOptions) {
|
|
878
|
+
async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}, pageUrl, basePath, environmentConfig, renderOptions) {
|
|
844
879
|
console.log("Rendering module", requestedModulePath);
|
|
845
|
-
const ungatedForServerSideProps =
|
|
880
|
+
const ungatedForServerSideProps = isUngatedFor(
|
|
881
|
+
environmentConfig.getGates(),
|
|
882
|
+
"CMS:JSRenderer:GetServerSideProps"
|
|
883
|
+
);
|
|
846
884
|
let serverSideProps;
|
|
847
885
|
let componentModule;
|
|
848
886
|
let foundPath;
|
|
@@ -876,6 +914,9 @@ async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}
|
|
|
876
914
|
if (ungatedForServerSideProps && componentModule.getServerSidePropsUnstable) {
|
|
877
915
|
try {
|
|
878
916
|
serverSideProps = await componentModule.getServerSidePropsUnstable(props);
|
|
917
|
+
if (serverSideProps.constructor !== {}.constructor) {
|
|
918
|
+
throw new Error("getServerSidePropsUnstable must return an object");
|
|
919
|
+
}
|
|
879
920
|
} catch (e) {
|
|
880
921
|
console.log("Error resolving server side props");
|
|
881
922
|
console.error(e);
|
|
@@ -887,6 +928,7 @@ async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}
|
|
|
887
928
|
Component,
|
|
888
929
|
{ ...props, ...serverSideProps },
|
|
889
930
|
pageUrl,
|
|
931
|
+
basePath,
|
|
890
932
|
environmentConfig,
|
|
891
933
|
renderOptions
|
|
892
934
|
);
|
|
@@ -941,6 +983,7 @@ var moduleRouteHandler = async (request2, response) => {
|
|
|
941
983
|
);
|
|
942
984
|
}
|
|
943
985
|
}
|
|
986
|
+
const basePath = getEntryPointBasePath(modulePath);
|
|
944
987
|
const environmentConfig = buildStaticEnvConfig2(
|
|
945
988
|
authedPortalId,
|
|
946
989
|
authedHublet,
|
|
@@ -958,6 +1001,7 @@ var moduleRouteHandler = async (request2, response) => {
|
|
|
958
1001
|
modulePath,
|
|
959
1002
|
fieldOverrides,
|
|
960
1003
|
fullOriginalUrlFromRequest(request2),
|
|
1004
|
+
basePath,
|
|
961
1005
|
environmentConfig,
|
|
962
1006
|
{
|
|
963
1007
|
identifierPrefix: getEntryPointHash(entrypointPath)
|
|
@@ -1262,6 +1306,16 @@ import {
|
|
|
1262
1306
|
import {
|
|
1263
1307
|
mergeServerRequestData_internal
|
|
1264
1308
|
} from "@hubspot/cms-components";
|
|
1309
|
+
var getEntryPointBasePathFromProxyRequest = (request2) => {
|
|
1310
|
+
if (!request2) {
|
|
1311
|
+
return "";
|
|
1312
|
+
}
|
|
1313
|
+
const { path: requestPath, pathParamDict } = request2;
|
|
1314
|
+
if (!pathParamDict || !pathParamDict.dynamic_slug) {
|
|
1315
|
+
return requestPath;
|
|
1316
|
+
}
|
|
1317
|
+
return requestPath.replace(pathParamDict.dynamic_slug, "");
|
|
1318
|
+
};
|
|
1265
1319
|
var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, projectName, jsRenderingGates) => {
|
|
1266
1320
|
const url3 = new URL(urlToProxy);
|
|
1267
1321
|
console.log(`Proxying request to ${url3.href}`, {
|
|
@@ -1303,7 +1357,7 @@ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, pro
|
|
|
1303
1357
|
}
|
|
1304
1358
|
});
|
|
1305
1359
|
};
|
|
1306
|
-
var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder, webRoot2, viteServer, pageUrl, environmentConfig, hsProjectJsonProjectName, webRootProjectComponent) => {
|
|
1360
|
+
var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder, webRoot2, viteServer, pageUrl, basePath, environmentConfig, hsProjectJsonProjectName, webRootProjectComponent) => {
|
|
1307
1361
|
const proxySchemaVersion = isUngatedFor(
|
|
1308
1362
|
environmentConfig.getGates(),
|
|
1309
1363
|
"CMS:JSRenderer:LocalProxySchemaVersion1"
|
|
@@ -1344,6 +1398,7 @@ var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder,
|
|
|
1344
1398
|
resolvedPath,
|
|
1345
1399
|
localRenderPlaceholderProps,
|
|
1346
1400
|
pageUrl,
|
|
1401
|
+
basePath,
|
|
1347
1402
|
environmentConfig,
|
|
1348
1403
|
{
|
|
1349
1404
|
identifierPrefix: getEntryPointHashWithIndexSuffix(
|
|
@@ -1358,6 +1413,7 @@ var renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder,
|
|
|
1358
1413
|
resolvedPath,
|
|
1359
1414
|
localRenderPlaceholderProps,
|
|
1360
1415
|
pageUrl,
|
|
1416
|
+
basePath,
|
|
1361
1417
|
environmentConfig,
|
|
1362
1418
|
{
|
|
1363
1419
|
identifierPrefix: getEntryPointHashWithIndexSuffix(
|
|
@@ -1417,6 +1473,7 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
|
|
|
1417
1473
|
let numJsRenderFailures = 0;
|
|
1418
1474
|
let islands = [];
|
|
1419
1475
|
let mergedPerRequestState = /* @__PURE__ */ new Map();
|
|
1476
|
+
let basePath;
|
|
1420
1477
|
const renderPromisesByChunkIndex = new Array(
|
|
1421
1478
|
numPlaceholders
|
|
1422
1479
|
);
|
|
@@ -1429,12 +1486,21 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
|
|
|
1429
1486
|
offsetSoFar,
|
|
1430
1487
|
localRenderPlaceholder.startOffset
|
|
1431
1488
|
);
|
|
1489
|
+
if (basePath === void 0 && isUngatedFor(
|
|
1490
|
+
environmentConfig.getGates(),
|
|
1491
|
+
"CMS:JSRenderer:LocalProxySchemaVersion1"
|
|
1492
|
+
)) {
|
|
1493
|
+
basePath = getEntryPointBasePathFromProxyRequest(
|
|
1494
|
+
localRenderPlaceholder.json.request
|
|
1495
|
+
);
|
|
1496
|
+
}
|
|
1432
1497
|
const renderPromise = renderComponentForPlaceholder(
|
|
1433
1498
|
indexForThisRender,
|
|
1434
1499
|
localRenderPlaceholder,
|
|
1435
1500
|
webRoot2,
|
|
1436
1501
|
viteServer,
|
|
1437
1502
|
fullOriginalUrl,
|
|
1503
|
+
basePath,
|
|
1438
1504
|
environmentConfig,
|
|
1439
1505
|
projectName,
|
|
1440
1506
|
projectComponentPath
|
|
@@ -1478,7 +1544,7 @@ ${html}`;
|
|
|
1478
1544
|
response.write(foobar);
|
|
1479
1545
|
}
|
|
1480
1546
|
response.write(
|
|
1481
|
-
getServerGlobalsToInject(environmentConfig, fullOriginalUrl)
|
|
1547
|
+
getServerGlobalsToInject(environmentConfig, fullOriginalUrl, basePath)
|
|
1482
1548
|
);
|
|
1483
1549
|
if (islands.length > 0) {
|
|
1484
1550
|
const sortedIslandRoots = sortIslandRootsByPriority(islands);
|
|
@@ -1593,7 +1659,8 @@ var homeRouteHandler = async (request2, response) => {
|
|
|
1593
1659
|
/* @__PURE__ */ jsx7(ModulesList_default, { webRoot: webRoot2, moduleNames })
|
|
1594
1660
|
] }),
|
|
1595
1661
|
null,
|
|
1596
|
-
null
|
|
1662
|
+
null,
|
|
1663
|
+
""
|
|
1597
1664
|
);
|
|
1598
1665
|
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
1599
1666
|
};
|
|
@@ -1635,7 +1702,8 @@ async function proxyPathPageRouteHandler(request2, response, next) {
|
|
|
1635
1702
|
] })
|
|
1636
1703
|
] }),
|
|
1637
1704
|
null,
|
|
1638
|
-
null
|
|
1705
|
+
null,
|
|
1706
|
+
""
|
|
1639
1707
|
);
|
|
1640
1708
|
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
1641
1709
|
return;
|
|
@@ -1736,8 +1804,10 @@ var createDevServerRoutes = async (viteServer, storybookPort) => {
|
|
|
1736
1804
|
devServerApp.get("/proxy", proxyPathPageRouteHandler);
|
|
1737
1805
|
devServerApp.get("/partials/", linksToAllPartialsRouteHandler_default);
|
|
1738
1806
|
devServerApp.get("/partial/:partial", partial_default);
|
|
1807
|
+
devServerApp.get("/partial/:partial/*", partial_default);
|
|
1739
1808
|
devServerApp.get("/modules/", linksToAllModulesRouteHandler_default);
|
|
1740
1809
|
devServerApp.get("/module/:moduleName", module_default);
|
|
1810
|
+
devServerApp.get("/module/:moduleName/*", module_default);
|
|
1741
1811
|
devServerApp.get("/", homeRouteHandler_default);
|
|
1742
1812
|
devServerApp.get("/*", proxyPathPageResourceRedirect);
|
|
1743
1813
|
devServerApp.get("/*", proxyPageResourceRedirect);
|
|
@@ -1954,10 +2024,42 @@ function createHttpsRedirectingServer(opts, handler) {
|
|
|
1954
2024
|
return { server, innerHTTPServer, innerHTTPSServer };
|
|
1955
2025
|
}
|
|
1956
2026
|
|
|
2027
|
+
// src/lib/getJSRenderingGates.ts
|
|
2028
|
+
import unAuth from "@hubspot/cli-lib/api/localDevAuth/unauthenticated.js";
|
|
2029
|
+
|
|
2030
|
+
// src/lib/gates.ts
|
|
2031
|
+
function getGatesFromEnv() {
|
|
2032
|
+
const gates = process.env.GATES ? process.env.GATES.split(",") : [];
|
|
2033
|
+
return gates;
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
// src/lib/getJSRenderingGates.ts
|
|
2037
|
+
var mapEnabledFeaturesToGates = (enabledFeatures) => {
|
|
2038
|
+
return Object.keys(enabledFeatures).reduce((gates, enabledFeature) => {
|
|
2039
|
+
if (enabledFeatures[enabledFeature]) {
|
|
2040
|
+
gates.push(ENABLED_FEATURES_GATE_MAP[enabledFeature]);
|
|
2041
|
+
}
|
|
2042
|
+
return gates;
|
|
2043
|
+
}, []);
|
|
2044
|
+
};
|
|
2045
|
+
async function getJsRenderingGates(portalId, env, personalAccessKey) {
|
|
2046
|
+
const { enabledFeatures = {} } = await unAuth.fetchAccessToken(
|
|
2047
|
+
personalAccessKey,
|
|
2048
|
+
env,
|
|
2049
|
+
portalId
|
|
2050
|
+
);
|
|
2051
|
+
const envGates = getGatesFromEnv();
|
|
2052
|
+
const gates = mapEnabledFeaturesToGates(enabledFeatures);
|
|
2053
|
+
const mergedGates = [...envGates, ...gates];
|
|
2054
|
+
process.env.GATES = mergedGates.join(",");
|
|
2055
|
+
return mergedGates;
|
|
2056
|
+
}
|
|
2057
|
+
|
|
1957
2058
|
// src/createDevServer.ts
|
|
1958
2059
|
import {
|
|
1959
2060
|
getEnv as getEnv2,
|
|
1960
2061
|
getAccountId as getAccountId3,
|
|
2062
|
+
getAccountConfig,
|
|
1961
2063
|
loadConfig,
|
|
1962
2064
|
validateConfig
|
|
1963
2065
|
} from "@hubspot/cli-lib/lib/config.js";
|
|
@@ -2014,12 +2116,6 @@ async function fetchWebsiteDomainNames(portalId) {
|
|
|
2014
2116
|
return domainNames;
|
|
2015
2117
|
}
|
|
2016
2118
|
|
|
2017
|
-
// src/lib/gates.ts
|
|
2018
|
-
function getGatesFromEnv() {
|
|
2019
|
-
const gates = process.env.GATES ? process.env.GATES.split(",") : [];
|
|
2020
|
-
return gates;
|
|
2021
|
-
}
|
|
2022
|
-
|
|
2023
2119
|
// src/createDevServer.ts
|
|
2024
2120
|
var BASE_PATH = "/";
|
|
2025
2121
|
var PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3e3;
|
|
@@ -2031,6 +2127,7 @@ async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2
|
|
|
2031
2127
|
);
|
|
2032
2128
|
let authedPortalId = null;
|
|
2033
2129
|
let authedEnv = null;
|
|
2130
|
+
let jsRenderingGates = [];
|
|
2034
2131
|
if (hubspotCliConfigPathOption2 && hubspotCliAccountNameOption2) {
|
|
2035
2132
|
console.log(
|
|
2036
2133
|
`Loading HS auth (account = ${hubspotCliAccountNameOption2}) configuration at: ${hubspotCliConfigPathOption2}`
|
|
@@ -2062,7 +2159,17 @@ If needed you can refer to another config file with --config.
|
|
|
2062
2159
|
Local proxy functionality will not work without setting up authentication.`
|
|
2063
2160
|
);
|
|
2064
2161
|
}
|
|
2065
|
-
|
|
2162
|
+
try {
|
|
2163
|
+
const { personalAccessKey } = getAccountConfig(authedPortalId);
|
|
2164
|
+
jsRenderingGates = await getJsRenderingGates(
|
|
2165
|
+
authedPortalId,
|
|
2166
|
+
authedEnv,
|
|
2167
|
+
personalAccessKey
|
|
2168
|
+
);
|
|
2169
|
+
} catch (e) {
|
|
2170
|
+
console.error(e);
|
|
2171
|
+
console.warn("Unable to fetch gating information");
|
|
2172
|
+
}
|
|
2066
2173
|
let domainsToProxy = [];
|
|
2067
2174
|
if (sslEnabledOption2 && authedPortalId) {
|
|
2068
2175
|
try {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/* hs-eslint ignored failing-rules */
|
|
2
|
+
/* eslint-disable require-await */
|
|
3
|
+
import { Router } from 'express';
|
|
4
|
+
import { getAccountId } from '@hubspot/cli-lib/lib/config.js';
|
|
5
|
+
import cors from 'cors';
|
|
6
|
+
import { findLocalRenderPlaceholders } from '../lib/proxyHelpers.js';
|
|
7
|
+
import { makeProxyPreviewRequest } from '../proxyPage/proxyPage.js';
|
|
8
|
+
import fetchPreviewInfo from '../proxyPage/fetchPreviewInfo.js';
|
|
9
|
+
function getShadowDevServerCheckHandler(devServerPort) {
|
|
10
|
+
return async function shadowDevServerCheckHandler(request, response) {
|
|
11
|
+
const { query } = request;
|
|
12
|
+
if (query) {
|
|
13
|
+
const { hostName, pathName, protocol, contentId, portalId: portalIdString, } = query;
|
|
14
|
+
const pageUrl = `${protocol}//${hostName}${pathName}`;
|
|
15
|
+
const portalId = parseInt(portalIdString, 10);
|
|
16
|
+
let accountId;
|
|
17
|
+
let hasJSBuildingBlocks = false;
|
|
18
|
+
let localProxyUrl;
|
|
19
|
+
try {
|
|
20
|
+
accountId = getAccountId(portalId);
|
|
21
|
+
if (accountId === null) {
|
|
22
|
+
throw new Error();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
response
|
|
27
|
+
.status(500)
|
|
28
|
+
.end(`Unable to find account for hubid = ${portalId}. Please check your hubspot.config.yaml`);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const previewInfo = await fetchPreviewInfo(accountId, portalId, contentId);
|
|
33
|
+
const { previewKey } = previewInfo;
|
|
34
|
+
const pageHtml = await makeProxyPreviewRequest(accountId, pageUrl, previewKey, contentId);
|
|
35
|
+
const localRenderPlaceholders = findLocalRenderPlaceholders(pageHtml);
|
|
36
|
+
if (localRenderPlaceholders.length) {
|
|
37
|
+
hasJSBuildingBlocks = true;
|
|
38
|
+
localProxyUrl = `http://${hostName}.hslocal.net:${devServerPort}${pathName}`;
|
|
39
|
+
}
|
|
40
|
+
response
|
|
41
|
+
.status(200)
|
|
42
|
+
.set({ 'Content-Type': 'application/json' })
|
|
43
|
+
.json({ hasJSBuildingBlocks, localProxyUrl });
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
response
|
|
47
|
+
.status(500)
|
|
48
|
+
.end(`Failed proxy render of page id = ${contentId} hub id = ${portalId}\n\n${error.stack}`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
response
|
|
54
|
+
.status(500)
|
|
55
|
+
.end(`Missing pageUrl param, cannot check for proxied page without a pageUrl`);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export default async function createShadowDevServerRoutes(devServerPort) {
|
|
60
|
+
const shadowDevServerRoutes = Router();
|
|
61
|
+
shadowDevServerRoutes.get('/check-if-local-dev-server', cors(), getShadowDevServerCheckHandler(devServerPort));
|
|
62
|
+
return shadowDevServerRoutes;
|
|
63
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import net from 'net';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import createShadowDevServerRoutes from './createShadowDevServerRoutes.js';
|
|
4
|
+
const testNetServer = net.createServer();
|
|
5
|
+
export default async function startShadowDevServer(devServerPort, shadowPort) {
|
|
6
|
+
const portIsTaken = await new Promise((res, rej) => {
|
|
7
|
+
console.log(`Starting proxy link server on port ${shadowPort}`);
|
|
8
|
+
testNetServer.once('error', err => {
|
|
9
|
+
if (err['code'] === 'EADDRINUSE') {
|
|
10
|
+
console.error(`Port ${shadowPort} is in use. HubSpot is unable to automatically create proxy links in the Sprocket Menu`);
|
|
11
|
+
res(true);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
rej(err);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
testNetServer.once('listening', () => {
|
|
18
|
+
testNetServer.close();
|
|
19
|
+
});
|
|
20
|
+
testNetServer.once('close', () => {
|
|
21
|
+
res(false);
|
|
22
|
+
});
|
|
23
|
+
testNetServer.listen(shadowPort);
|
|
24
|
+
});
|
|
25
|
+
if (portIsTaken) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const shadowDevServer = express();
|
|
29
|
+
shadowDevServer.listen(shadowPort);
|
|
30
|
+
shadowDevServer.use('/', await createShadowDevServerRoutes(devServerPort));
|
|
31
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export default function getFieldsArgTypes(fieldsJson, currentPathSegments = []) {
|
|
2
|
+
let resultArgTypes = {};
|
|
3
|
+
for (const field of fieldsJson) {
|
|
4
|
+
// storybook doesn't support nested controls, so emulate our nested
|
|
5
|
+
// structure with group1.group2.field structure
|
|
6
|
+
const fullFieldName = [...currentPathSegments, field.name].join('.');
|
|
7
|
+
// should this definition of fieldType => argType live next to fields in cms-components?
|
|
8
|
+
switch (field.type) {
|
|
9
|
+
case 'group': {
|
|
10
|
+
if (!field.children) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
const groupResult = getFieldsArgTypes(field.children, [
|
|
14
|
+
...currentPathSegments,
|
|
15
|
+
field.name,
|
|
16
|
+
]);
|
|
17
|
+
resultArgTypes = {
|
|
18
|
+
...resultArgTypes,
|
|
19
|
+
...groupResult,
|
|
20
|
+
};
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
case 'boolean': {
|
|
24
|
+
resultArgTypes[fullFieldName] = {
|
|
25
|
+
control: 'boolean',
|
|
26
|
+
defaultValue: field.default,
|
|
27
|
+
};
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
case 'text': {
|
|
31
|
+
resultArgTypes[fullFieldName] = {
|
|
32
|
+
control: 'text',
|
|
33
|
+
defaultValue: field.default,
|
|
34
|
+
};
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case 'number': {
|
|
38
|
+
resultArgTypes[fullFieldName] = {
|
|
39
|
+
control: 'number',
|
|
40
|
+
defaultValue: field.default,
|
|
41
|
+
};
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
default: {
|
|
45
|
+
resultArgTypes[fullFieldName] = {
|
|
46
|
+
control: 'object',
|
|
47
|
+
defaultValue: field.default,
|
|
48
|
+
};
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return resultArgTypes;
|
|
54
|
+
}
|