@hubspot/cms-dev-server 0.4.17 → 0.4.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/internalSsr.js +7 -0
- package/dist/run.js +62 -15
- package/dist/storybook/main.js +8 -1
- package/package.json +3 -3
package/dist/internalSsr.js
CHANGED
|
@@ -159,6 +159,12 @@ var GATES = [
|
|
|
159
159
|
"CMS:JSRenderer:LocalProxySchemaVersion1",
|
|
160
160
|
"CMS:JSRenderer:GraphQLQueryBuild"
|
|
161
161
|
];
|
|
162
|
+
var ENABLED_FEATURES_GATE_MAP = {
|
|
163
|
+
"cms:jsr:sharedDeps": "CMS:JSRenderer:SharedDeps",
|
|
164
|
+
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
165
|
+
"cms:jsr:localProxySchemaVersion1": "CMS:JSRenderer:LocalProxySchemaVersion1",
|
|
166
|
+
"cms:jsr:graphqQLQueryBuild": "CMS:JSRenderer:GraphQLQueryBuild"
|
|
167
|
+
};
|
|
162
168
|
function isUngatedFor(gates, gate) {
|
|
163
169
|
return gates.includes(gate);
|
|
164
170
|
}
|
|
@@ -478,6 +484,7 @@ function renderFieldsToJson(fields) {
|
|
|
478
484
|
export {
|
|
479
485
|
COMPONENT_EXTENSIONS,
|
|
480
486
|
CSS_LANGS_RE,
|
|
487
|
+
ENABLED_FEATURES_GATE_MAP,
|
|
481
488
|
ENTRY_POINTS_PATH,
|
|
482
489
|
GATES,
|
|
483
490
|
MODULE_FOLDER_PATH,
|
package/dist/run.js
CHANGED
|
@@ -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
|
}
|
|
@@ -532,17 +538,15 @@ var logPartialInfo = (partialPath, props) => {
|
|
|
532
538
|
console.groupEnd();
|
|
533
539
|
};
|
|
534
540
|
|
|
535
|
-
// src/lib/constants.ts
|
|
536
|
-
var Gates = {
|
|
537
|
-
GET_SERVER_SIDE_PROPS: "CMS:JSRenderer:GetServerSideProps"
|
|
538
|
-
};
|
|
539
|
-
|
|
540
541
|
// src/lib/renderPartial.ts
|
|
541
542
|
async function renderPartial(viteServer, partialPath, props, pageUrl, environmentConfig, renderOptions) {
|
|
542
543
|
logPartialInfo(partialPath, props);
|
|
543
544
|
let serverSideProps;
|
|
544
545
|
const componentModule = await viteServer.ssrLoadModule(partialPath);
|
|
545
|
-
const ungatedForServerSideProps =
|
|
546
|
+
const ungatedForServerSideProps = isUngatedFor(
|
|
547
|
+
environmentConfig.getGates(),
|
|
548
|
+
"CMS:JSRenderer:GetServerSideProps"
|
|
549
|
+
);
|
|
546
550
|
if (!componentModule) {
|
|
547
551
|
throw new Error(`Couldn't find partial: ${partialPath}`);
|
|
548
552
|
}
|
|
@@ -553,7 +557,7 @@ async function renderPartial(viteServer, partialPath, props, pageUrl, environmen
|
|
|
553
557
|
if (ungatedForServerSideProps && componentModule.getServerSidePropsUnstable) {
|
|
554
558
|
try {
|
|
555
559
|
serverSideProps = await componentModule.getServerSidePropsUnstable(props);
|
|
556
|
-
if (serverSideProps.constructor !==
|
|
560
|
+
if (serverSideProps.constructor !== {}.constructor) {
|
|
557
561
|
throw new Error("getServerSidePropsUnstable must return an object");
|
|
558
562
|
}
|
|
559
563
|
} catch (e) {
|
|
@@ -842,7 +846,10 @@ var lookForModuleInFolder = async (modulePath, viteServer) => {
|
|
|
842
846
|
};
|
|
843
847
|
async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}, pageUrl, environmentConfig, renderOptions) {
|
|
844
848
|
console.log("Rendering module", requestedModulePath);
|
|
845
|
-
const ungatedForServerSideProps =
|
|
849
|
+
const ungatedForServerSideProps = isUngatedFor(
|
|
850
|
+
environmentConfig.getGates(),
|
|
851
|
+
"CMS:JSRenderer:GetServerSideProps"
|
|
852
|
+
);
|
|
846
853
|
let serverSideProps;
|
|
847
854
|
let componentModule;
|
|
848
855
|
let foundPath;
|
|
@@ -876,6 +883,9 @@ async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}
|
|
|
876
883
|
if (ungatedForServerSideProps && componentModule.getServerSidePropsUnstable) {
|
|
877
884
|
try {
|
|
878
885
|
serverSideProps = await componentModule.getServerSidePropsUnstable(props);
|
|
886
|
+
if (serverSideProps.constructor !== {}.constructor) {
|
|
887
|
+
throw new Error("getServerSidePropsUnstable must return an object");
|
|
888
|
+
}
|
|
879
889
|
} catch (e) {
|
|
880
890
|
console.log("Error resolving server side props");
|
|
881
891
|
console.error(e);
|
|
@@ -1954,10 +1964,42 @@ function createHttpsRedirectingServer(opts, handler) {
|
|
|
1954
1964
|
return { server, innerHTTPServer, innerHTTPSServer };
|
|
1955
1965
|
}
|
|
1956
1966
|
|
|
1967
|
+
// src/lib/getJSRenderingGates.ts
|
|
1968
|
+
import unAuth from "@hubspot/cli-lib/api/localDevAuth/unauthenticated.js";
|
|
1969
|
+
|
|
1970
|
+
// src/lib/gates.ts
|
|
1971
|
+
function getGatesFromEnv() {
|
|
1972
|
+
const gates = process.env.GATES ? process.env.GATES.split(",") : [];
|
|
1973
|
+
return gates;
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1976
|
+
// src/lib/getJSRenderingGates.ts
|
|
1977
|
+
var mapEnabledFeaturesToGates = (enabledFeatures) => {
|
|
1978
|
+
return Object.keys(enabledFeatures).reduce((gates, enabledFeature) => {
|
|
1979
|
+
if (enabledFeatures[enabledFeature]) {
|
|
1980
|
+
gates.push(ENABLED_FEATURES_GATE_MAP[enabledFeature]);
|
|
1981
|
+
}
|
|
1982
|
+
return gates;
|
|
1983
|
+
}, []);
|
|
1984
|
+
};
|
|
1985
|
+
async function getJsRenderingGates(portalId, env, personalAccessKey) {
|
|
1986
|
+
const { enabledFeatures = {} } = await unAuth.fetchAccessToken(
|
|
1987
|
+
personalAccessKey,
|
|
1988
|
+
env,
|
|
1989
|
+
portalId
|
|
1990
|
+
);
|
|
1991
|
+
const envGates = getGatesFromEnv();
|
|
1992
|
+
const gates = mapEnabledFeaturesToGates(enabledFeatures);
|
|
1993
|
+
const mergedGates = [...envGates, ...gates];
|
|
1994
|
+
process.env.GATES = mergedGates.join(",");
|
|
1995
|
+
return mergedGates;
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1957
1998
|
// src/createDevServer.ts
|
|
1958
1999
|
import {
|
|
1959
2000
|
getEnv as getEnv2,
|
|
1960
2001
|
getAccountId as getAccountId3,
|
|
2002
|
+
getAccountConfig,
|
|
1961
2003
|
loadConfig,
|
|
1962
2004
|
validateConfig
|
|
1963
2005
|
} from "@hubspot/cli-lib/lib/config.js";
|
|
@@ -2014,12 +2056,6 @@ async function fetchWebsiteDomainNames(portalId) {
|
|
|
2014
2056
|
return domainNames;
|
|
2015
2057
|
}
|
|
2016
2058
|
|
|
2017
|
-
// src/lib/gates.ts
|
|
2018
|
-
function getGatesFromEnv() {
|
|
2019
|
-
const gates = process.env.GATES ? process.env.GATES.split(",") : [];
|
|
2020
|
-
return gates;
|
|
2021
|
-
}
|
|
2022
|
-
|
|
2023
2059
|
// src/createDevServer.ts
|
|
2024
2060
|
var BASE_PATH = "/";
|
|
2025
2061
|
var PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3e3;
|
|
@@ -2031,6 +2067,7 @@ async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2
|
|
|
2031
2067
|
);
|
|
2032
2068
|
let authedPortalId = null;
|
|
2033
2069
|
let authedEnv = null;
|
|
2070
|
+
let jsRenderingGates = [];
|
|
2034
2071
|
if (hubspotCliConfigPathOption2 && hubspotCliAccountNameOption2) {
|
|
2035
2072
|
console.log(
|
|
2036
2073
|
`Loading HS auth (account = ${hubspotCliAccountNameOption2}) configuration at: ${hubspotCliConfigPathOption2}`
|
|
@@ -2062,7 +2099,17 @@ If needed you can refer to another config file with --config.
|
|
|
2062
2099
|
Local proxy functionality will not work without setting up authentication.`
|
|
2063
2100
|
);
|
|
2064
2101
|
}
|
|
2065
|
-
|
|
2102
|
+
try {
|
|
2103
|
+
const { personalAccessKey } = getAccountConfig(authedPortalId);
|
|
2104
|
+
jsRenderingGates = await getJsRenderingGates(
|
|
2105
|
+
authedPortalId,
|
|
2106
|
+
authedEnv,
|
|
2107
|
+
personalAccessKey
|
|
2108
|
+
);
|
|
2109
|
+
} catch (e) {
|
|
2110
|
+
console.error(e);
|
|
2111
|
+
console.warn("Unable to fetch gating information");
|
|
2112
|
+
}
|
|
2066
2113
|
let domainsToProxy = [];
|
|
2067
2114
|
if (sslEnabledOption2 && authedPortalId) {
|
|
2068
2115
|
try {
|
package/dist/storybook/main.js
CHANGED
|
@@ -13,6 +13,7 @@ var dist_exports = {};
|
|
|
13
13
|
__export(dist_exports, {
|
|
14
14
|
COMPONENT_EXTENSIONS: () => COMPONENT_EXTENSIONS,
|
|
15
15
|
CSS_LANGS_RE: () => CSS_LANGS_RE,
|
|
16
|
+
ENABLED_FEATURES_GATE_MAP: () => ENABLED_FEATURES_GATE_MAP,
|
|
16
17
|
ENTRY_POINTS_PATH: () => ENTRY_POINTS_PATH,
|
|
17
18
|
GATES: () => GATES,
|
|
18
19
|
MODULE_FOLDER_PATH: () => MODULE_FOLDER_PATH,
|
|
@@ -287,7 +288,7 @@ function renderFieldsToJson(fields) {
|
|
|
287
288
|
);
|
|
288
289
|
return moduleJson;
|
|
289
290
|
}
|
|
290
|
-
var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, serializeIslandDataToJSON, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, require2, GATES, BUILD_INFO_PATH, viteRoot, viteCommand, clientRenderIsland, virtualClientRenderIslandModuleId, jsx2, promiseForNewWritableStream, renderStreamToPromise, scriptTagToLogServerMessages, getComponentExtension, hasComponentExtension, isStorybookStory, removeComponentExtension, COMBINED_REACT_BASE_PATH, ISLAND_RUNTIME_CONFIG_BASE_PATH, findAllComponentsIn;
|
|
291
|
+
var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, serializeIslandDataToJSON, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, require2, GATES, ENABLED_FEATURES_GATE_MAP, BUILD_INFO_PATH, viteRoot, viteCommand, clientRenderIsland, virtualClientRenderIslandModuleId, jsx2, promiseForNewWritableStream, renderStreamToPromise, scriptTagToLogServerMessages, getComponentExtension, hasComponentExtension, isStorybookStory, removeComponentExtension, COMBINED_REACT_BASE_PATH, ISLAND_RUNTIME_CONFIG_BASE_PATH, findAllComponentsIn;
|
|
291
292
|
var init_dist = __esm({
|
|
292
293
|
"../cms-js-internal/dist/index.js"() {
|
|
293
294
|
COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
|
|
@@ -403,6 +404,12 @@ ${indentString}`);
|
|
|
403
404
|
"CMS:JSRenderer:LocalProxySchemaVersion1",
|
|
404
405
|
"CMS:JSRenderer:GraphQLQueryBuild"
|
|
405
406
|
];
|
|
407
|
+
ENABLED_FEATURES_GATE_MAP = {
|
|
408
|
+
"cms:jsr:sharedDeps": "CMS:JSRenderer:SharedDeps",
|
|
409
|
+
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
410
|
+
"cms:jsr:localProxySchemaVersion1": "CMS:JSRenderer:LocalProxySchemaVersion1",
|
|
411
|
+
"cms:jsr:graphqQLQueryBuild": "CMS:JSRenderer:GraphQLQueryBuild"
|
|
412
|
+
};
|
|
406
413
|
BUILD_INFO_PATH = "/build-info.json";
|
|
407
414
|
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";
|
|
408
415
|
virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.18",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@hubspot/cli-lib": "^3.0.12",
|
|
27
|
-
"@hubspot/cms-components": "^0.4.
|
|
27
|
+
"@hubspot/cms-components": "^0.4.18",
|
|
28
28
|
"@storybook/addon-actions": "^7.0.0-beta.19",
|
|
29
29
|
"@storybook/addon-essentials": "^7.0.0-beta.19",
|
|
30
30
|
"@storybook/addon-interactions": "^7.0.0-beta.19",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
"publishConfig": {
|
|
96
96
|
"access": "public"
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "82893df718a2aae330cce8df35e00f27cb49adf1"
|
|
99
99
|
}
|