@hubspot/cms-dev-server 0.3.2 → 0.3.4
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/createDevServer.js +18 -1
- package/dist/createViteDevServer.js +1 -1
- package/dist/lib/renderComponentWithCSS.js +2 -2
- package/dist/lib/renderModule.js +2 -2
- package/dist/lib/renderPartial.js +6 -3
- package/dist/lib/templates.js +23 -14
- package/dist/proxyPage/fetchContentMetadata.js +10 -4
- package/dist/proxyPage/proxyPage.js +12 -8
- package/dist/proxyPage/utils.js +2 -2
- package/dist/routes/createDevServerRoutes.js +4 -0
- package/dist/routes/homeRouteHandler.js +1 -1
- package/dist/routes/linksToAllModulesRouteHandler.js +1 -1
- package/dist/routes/linksToAllPartialsRouteHandler.js +1 -1
- package/dist/routes/module.js +4 -2
- package/dist/routes/partial.js +4 -2
- package/dist/routes/proxyPageRouteHandler.js +2 -2
- package/dist/routes/proxyPathPageResourceRedirect.js +36 -0
- package/dist/routes/proxyPathPageRouteHandler.js +43 -0
- package/dist/shadowDevServer/createShadowDevServerRoutes.js +58 -0
- package/dist/shadowDevServer/startShadowDevServer.js +32 -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 +29 -22
- package/dist/storybook/main.js +3 -0
- package/dist/storybook/moduleStory.js +4 -92
- package/dist/storybook/types.js +1 -0
- package/package.json +16 -10
- package/types/storybook/getFieldsArgTypes.d.ts +9 -0
- package/types/storybook/getNestedFieldObjectForArgs.d.ts +6 -0
- package/types/storybook/moduleStory.d.ts +0 -10
- package/types/storybook/types.d.ts +3 -0
package/dist/createDevServer.js
CHANGED
|
@@ -4,6 +4,7 @@ import express from 'express';
|
|
|
4
4
|
import { spawn } from 'child_process';
|
|
5
5
|
import { normalizePath } from 'vite';
|
|
6
6
|
import createDevServerRoutes from './routes/createDevServerRoutes.js';
|
|
7
|
+
import startShadowDevServer from './shadowDevServer/startShadowDevServer.js';
|
|
7
8
|
import { getProjectNameFromHSConfig } from './lib/proxyHelpers.js';
|
|
8
9
|
import createViteDevServer from './createViteDevServer.js';
|
|
9
10
|
import { debug } from './lib/debug.js';
|
|
@@ -43,6 +44,7 @@ If needed you can refer to another config file with --config.
|
|
|
43
44
|
|
|
44
45
|
Local proxy functionality will not work without setting up authentication.`);
|
|
45
46
|
}
|
|
47
|
+
const authedHublet = 'na1';
|
|
46
48
|
const absoluteWebRoot = normalizePath(path.resolve(process.cwd(), webRoot));
|
|
47
49
|
const [__webRootProjectFolder, webRootProjectComponentFolder] = absoluteWebRoot.replace(/\/$/, '').split('/').slice(-2);
|
|
48
50
|
const expressServer = express();
|
|
@@ -51,12 +53,16 @@ Local proxy functionality will not work without setting up authentication.`);
|
|
|
51
53
|
expressServer.locals.devServerPort = PORT;
|
|
52
54
|
expressServer.locals.webRoot = webRoot;
|
|
53
55
|
expressServer.locals.viteServer = viteServer;
|
|
56
|
+
expressServer.locals.authedPortalId = authedPortalId;
|
|
57
|
+
expressServer.locals.authedEnv = authedEnv;
|
|
58
|
+
expressServer.locals.authedHublet = authedHublet;
|
|
54
59
|
expressServer.locals.storybookEnabled = storybook;
|
|
55
60
|
expressServer.locals.storybookPort = STORYBOOK_PORT;
|
|
56
61
|
expressServer.locals.projectName = getProjectNameFromHSConfig(path.join(webRoot, '../hsproject.json'));
|
|
57
62
|
expressServer.locals.projectComponentPath = webRootProjectComponentFolder;
|
|
58
63
|
expressServer.use(BASE_PATH, await createDevServerRoutes(viteServer, storybook ? STORYBOOK_PORT : null));
|
|
59
|
-
expressServer.listen(PORT);
|
|
64
|
+
const httpServer = expressServer.listen(PORT);
|
|
65
|
+
startShadowDevServer(PORT);
|
|
60
66
|
let extraServerInfo = '';
|
|
61
67
|
if (authedPortalId) {
|
|
62
68
|
extraServerInfo += `, hubid=${authedPortalId}`;
|
|
@@ -92,5 +98,16 @@ HubSpot CMS dev server hosting: ${expressServer.locals.projectName}/${expressSer
|
|
|
92
98
|
}
|
|
93
99
|
storybookProcess.stderr.pipe(process.stderr);
|
|
94
100
|
}
|
|
101
|
+
// Return hook to shut down server gracefully
|
|
102
|
+
return {
|
|
103
|
+
close: () => {
|
|
104
|
+
const httpServerClosePromise = new Promise(resolve => {
|
|
105
|
+
httpServer.close(() => {
|
|
106
|
+
resolve(null);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
return Promise.allSettled([httpServerClosePromise, viteServer.close()]);
|
|
110
|
+
},
|
|
111
|
+
};
|
|
95
112
|
}
|
|
96
113
|
export default createDevServer;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createServer as createViteServer
|
|
1
|
+
import { createServer as createViteServer } from 'vite';
|
|
2
2
|
import { default as react } from '@vitejs/plugin-react';
|
|
3
3
|
import { resolveIslandPlugin } from '@hubspot/cms-js-internal';
|
|
4
4
|
const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { hasComponentExtension, removeComponentExtension, } from '@hubspot/cms-js-internal';
|
|
2
2
|
import { findFullPathInModuleGraph } from './moduleGraph.js';
|
|
3
|
-
async function renderComponentWithCSS(viteServer, componentPath, Component, props, pageUrl) {
|
|
3
|
+
async function renderComponentWithCSS(viteServer, componentPath, Component, props, pageUrl, environmentConfig) {
|
|
4
4
|
// Need to make sure rendering happens in Vite SSR context
|
|
5
5
|
const { renderComponentOnServer, collectCssInDev } = await viteServer.ssrLoadModule('@hubspot/cms-js-internal');
|
|
6
6
|
let componentPathWithExtension;
|
|
@@ -13,7 +13,7 @@ async function renderComponentWithCSS(viteServer, componentPath, Component, prop
|
|
|
13
13
|
else {
|
|
14
14
|
componentPathNoExtension = componentPath;
|
|
15
15
|
}
|
|
16
|
-
const { html, renderContext } = await renderComponentOnServer(Component, props, pageUrl);
|
|
16
|
+
const { html, renderContext } = await renderComponentOnServer(Component, props, pageUrl, environmentConfig);
|
|
17
17
|
if (!componentPathWithExtension) {
|
|
18
18
|
componentPathWithExtension = findFullPathInModuleGraph(componentPathNoExtension, viteServer.moduleGraph);
|
|
19
19
|
if (!componentPathWithExtension) {
|
package/dist/lib/renderModule.js
CHANGED
|
@@ -15,7 +15,7 @@ const lookForModuleInFolder = async (modulePath, viteServer) => {
|
|
|
15
15
|
}
|
|
16
16
|
return [componentModule, insideFolderPath];
|
|
17
17
|
};
|
|
18
|
-
async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}, pageUrl) {
|
|
18
|
+
async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}, pageUrl, environmentConfig) {
|
|
19
19
|
console.log('Rendering module', requestedModulePath);
|
|
20
20
|
let componentModule;
|
|
21
21
|
let foundPath;
|
|
@@ -44,7 +44,7 @@ async function renderModule(viteServer, requestedModulePath, fieldOverrides = {}
|
|
|
44
44
|
}
|
|
45
45
|
const fieldsJSON = renderFieldsToJson(fields);
|
|
46
46
|
const props = getPropsForModule(fieldsJSON, fieldOverrides);
|
|
47
|
-
return renderComponentWithCSS(viteServer, foundPath, Component, props, pageUrl);
|
|
47
|
+
return renderComponentWithCSS(viteServer, foundPath, Component, props, pageUrl, environmentConfig);
|
|
48
48
|
}
|
|
49
49
|
function getPropsForModule(fieldsJSON, fieldOverrides = {}) {
|
|
50
50
|
const props = {};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import renderComponentWithCSS from './renderComponentWithCSS.js';
|
|
2
2
|
import { logPartialInfo } from './renderHelpers.js';
|
|
3
|
-
async function renderPartial(viteServer, partialPath, props, pageUrl) {
|
|
3
|
+
async function renderPartial(viteServer, partialPath, props, pageUrl, environmentConfig) {
|
|
4
4
|
logPartialInfo(partialPath, props);
|
|
5
5
|
const componentModule = await viteServer.ssrLoadModule(partialPath);
|
|
6
|
-
const Component = componentModule.default;
|
|
7
6
|
if (!componentModule) {
|
|
8
7
|
throw new Error(`Couldn't find partial: ${partialPath}`);
|
|
9
8
|
}
|
|
10
|
-
|
|
9
|
+
const Component = componentModule.default;
|
|
10
|
+
if (!Component) {
|
|
11
|
+
throw new Error(`Couldn't find default export on partial: ${partialPath}`);
|
|
12
|
+
}
|
|
13
|
+
return renderComponentWithCSS(viteServer, partialPath, Component, props, pageUrl, environmentConfig);
|
|
11
14
|
}
|
|
12
15
|
export default renderPartial;
|
package/dist/lib/templates.js
CHANGED
|
@@ -3,20 +3,28 @@
|
|
|
3
3
|
import { promises as fsPromises } from 'fs';
|
|
4
4
|
import { createIslandsGlobalJsForClientInDev, getServerGlobalsToInject, } from '@hubspot/cms-js-internal';
|
|
5
5
|
const { readFile } = fsPromises;
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const generateIslandSetupScriptBlock = () => {
|
|
7
|
+
return `<script type="module">
|
|
8
|
+
import { initConfigSingletonFromJSON } from '@hubspot/cms-components/config';
|
|
9
|
+
initConfigSingletonFromJSON(window.__hsEnvConfig);
|
|
10
|
+
</script>
|
|
11
|
+
<script type="module">
|
|
12
|
+
import { setupIslandHydration } from '@hubspot/cms-components/island-runtime';
|
|
13
|
+
setupIslandHydration();
|
|
14
|
+
</script>
|
|
10
15
|
`;
|
|
11
|
-
|
|
16
|
+
};
|
|
17
|
+
const createdPlainHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock) => {
|
|
12
18
|
const htmlTemplateBase = await readFile(baseTemplatePath, 'utf-8');
|
|
13
|
-
return htmlTemplateBase.replace('<!--title-->', title)
|
|
19
|
+
return htmlTemplateBase.replace('<!--title-->', title).replace('<!--bodyend-->', `
|
|
20
|
+
${globalScriptBlock}
|
|
21
|
+
<!--bodyend-->`);
|
|
14
22
|
};
|
|
15
|
-
const createIslandHtmlTemplate = async (baseTemplatePath, title) => {
|
|
16
|
-
let htmlTemplate = await createdPlainHtmlTemplate(baseTemplatePath, title);
|
|
23
|
+
const createIslandHtmlTemplate = async (baseTemplatePath, title, globalScriptBlock) => {
|
|
24
|
+
let htmlTemplate = await createdPlainHtmlTemplate(baseTemplatePath, title, globalScriptBlock);
|
|
17
25
|
htmlTemplate = htmlTemplate.replace('<!--bodyend-->', `
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
${generateIslandSetupScriptBlock()}
|
|
27
|
+
<!-- ISLAND_RUNTIME_AND_SETUP_SCRIPT_BLOCK -->
|
|
20
28
|
<!--islandsglobal-->
|
|
21
29
|
`);
|
|
22
30
|
return htmlTemplate;
|
|
@@ -24,15 +32,16 @@ const createIslandHtmlTemplate = async (baseTemplatePath, title) => {
|
|
|
24
32
|
export const createHtmlShellDependingOnRenderContext = async (baseTemplatePath, url, title, renderContext, viteServer) => {
|
|
25
33
|
let htmlTemplate;
|
|
26
34
|
if (renderContext.islands.length) {
|
|
27
|
-
|
|
35
|
+
const globalScriptBlock = getServerGlobalsToInject(renderContext.environmentConfig, renderContext.pageUrl);
|
|
36
|
+
htmlTemplate = await createIslandHtmlTemplate(baseTemplatePath, title, globalScriptBlock);
|
|
28
37
|
htmlTemplate = htmlTemplate.replace('<!--islandsglobal-->', `<script>
|
|
29
38
|
${createIslandsGlobalJsForClientInDev(renderContext.islands, viteServer, 4)}
|
|
30
39
|
</script>
|
|
31
|
-
${getServerGlobalsToInject(renderContext.pageUrl)}
|
|
32
40
|
`);
|
|
33
41
|
}
|
|
34
42
|
else {
|
|
35
|
-
|
|
43
|
+
const globalScriptBlock = getServerGlobalsToInject(renderContext.environmentConfig);
|
|
44
|
+
htmlTemplate = await createdPlainHtmlTemplate(baseTemplatePath, title, globalScriptBlock);
|
|
36
45
|
}
|
|
37
46
|
return viteServer.transformIndexHtml(url, htmlTemplate);
|
|
38
47
|
};
|
|
@@ -40,7 +49,7 @@ export const getIslandRuntimeAndGlobalToInject = async (sortedIslandRoots, viteS
|
|
|
40
49
|
const serverDomainAndPort = `${devServerHost}:${devServerPort}`;
|
|
41
50
|
// Loading through vite so all of nested `@hubspot/cms-*` imports work
|
|
42
51
|
const { createIslandsGlobalJsForClientInDev } = await viteServer.ssrLoadModule('@hubspot/cms-js-internal');
|
|
43
|
-
let islandRuntimeScript = await viteServer.transformIndexHtml('/',
|
|
52
|
+
let islandRuntimeScript = await viteServer.transformIndexHtml('/', generateIslandSetupScriptBlock());
|
|
44
53
|
islandRuntimeScript = islandRuntimeScript.replace('import RefreshRuntime from "/@react-refresh"', `import RefreshRuntime from "http://${serverDomainAndPort}/@react-refresh"`);
|
|
45
54
|
return `${islandRuntimeScript}
|
|
46
55
|
<script>${createIslandsGlobalJsForClientInDev(sortedIslandRoots, viteServer, 4)}</script>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
2
|
import https from 'https';
|
|
3
|
-
export default async function
|
|
3
|
+
export default async function fetchContentMetadata(url, redirects = 0, originalUrl) {
|
|
4
4
|
if (redirects > 5) {
|
|
5
5
|
throw new Error(`Hit too many redirects to HEAD requests for ${originalUrl}`);
|
|
6
6
|
}
|
|
@@ -13,13 +13,13 @@ export default async function getContentMetadata(url, redirects = 0, originalUrl
|
|
|
13
13
|
// Keep this user agent, so we don't get 403s from the request
|
|
14
14
|
['User-Agent']: 'cms-dev-server',
|
|
15
15
|
},
|
|
16
|
-
}, res => {
|
|
16
|
+
}, async (res) => {
|
|
17
17
|
// Use a lib to better follow various redirects?
|
|
18
18
|
if (res.statusCode >= 300 &&
|
|
19
19
|
res.statusCode < 400 &&
|
|
20
20
|
res.headers.location) {
|
|
21
21
|
console.log(`Redirecting to ${res.headers.location} (from ${url})`);
|
|
22
|
-
return resolve(
|
|
22
|
+
return resolve(fetchContentMetadata(res.headers.location, redirects + 1, originalUrl ?? url));
|
|
23
23
|
}
|
|
24
24
|
const portalIdHeader = res.headers['x-hs-hub-id'];
|
|
25
25
|
const contentId = res.headers['x-hs-content-id'];
|
|
@@ -39,7 +39,13 @@ export default async function getContentMetadata(url, redirects = 0, originalUrl
|
|
|
39
39
|
else if (isNaN(portalId)) {
|
|
40
40
|
return reject(new Error(`Hub ID from the HEAD request is not a number: '${portalId}' (${url})`));
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
// TODO, the hubs-hublets/hublets/find/<portalId> API is internal auth only.🤔...
|
|
43
|
+
// Prior implementation of fetchHubletForPortalId that would work execept for an internal auth issue:
|
|
44
|
+
// https://git.hubteam.com/HubSpot/cms-js-platform/blob/ef6e8029df6c09fe30d65a80073606f41ca324a6/cms-dev-server/src/proxyPage/fetchHubletForPortalId.ts
|
|
45
|
+
//
|
|
46
|
+
// const hublet = await fetchHubletForPortalId(portalId);
|
|
47
|
+
const hublet = 'na1';
|
|
48
|
+
return resolve({ portalId, contentId, hublet });
|
|
43
49
|
}
|
|
44
50
|
})
|
|
45
51
|
.on('error', err => {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
3
|
/* eslint-disable no-loop-func */
|
|
4
4
|
import path from 'path';
|
|
5
|
-
import { getAccountId } from '@hubspot/cli-lib/lib/config.js';
|
|
5
|
+
import { getAccountId, getEnv } from '@hubspot/cli-lib/lib/config.js';
|
|
6
6
|
import { get as hsGet } from '@hubspot/cli-lib/http.js';
|
|
7
7
|
import { findLocalRenderPlaceholders, } from '../lib/proxyHelpers.js';
|
|
8
8
|
import renderPartial from '../lib/renderPartial.js';
|
|
@@ -12,7 +12,8 @@ import { ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, getServerGlobalsToInject, } from
|
|
|
12
12
|
import { fakeRenderJsComponent } from './utils.js';
|
|
13
13
|
import renderLocalError from './renderLocalError.js';
|
|
14
14
|
import fetchPreviewInfo from './fetchPreviewInfo.js';
|
|
15
|
-
|
|
15
|
+
import { buildStaticEnvConfig, } from '@hubspot/cms-components/config';
|
|
16
|
+
export const makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId) => {
|
|
16
17
|
const url = new URL(urlToProxy);
|
|
17
18
|
console.log(`Proxying request to ${url.href}`, {
|
|
18
19
|
previewKey,
|
|
@@ -52,7 +53,7 @@ const makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId) =
|
|
|
52
53
|
}
|
|
53
54
|
});
|
|
54
55
|
};
|
|
55
|
-
const renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder, webRoot, viteServer, pageUrl, hsProjectJsonProjectName, webRootProjectComponent) => {
|
|
56
|
+
const renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholder, webRoot, viteServer, pageUrl, environmentConfig, hsProjectJsonProjectName, webRootProjectComponent) => {
|
|
56
57
|
const { path: placeholderPath } = localRenderPlaceholder;
|
|
57
58
|
const [__projectIdentifier, projectFolder, projectComponentFolder, componentFolder, componentTypeFolder, componentFileName,] = placeholderPath.split('/');
|
|
58
59
|
const partialPath = `${componentFolder}/${componentTypeFolder}/`;
|
|
@@ -67,19 +68,21 @@ const renderComponentForPlaceholder = (indexForThisRender, localRenderPlaceholde
|
|
|
67
68
|
return fakeRenderJsComponent(indexForThisRender);
|
|
68
69
|
}
|
|
69
70
|
else if (partialPath === ENTRY_POINTS_PATH) {
|
|
70
|
-
return renderPartial(viteServer, resolvedPath, localRenderPlaceholder.json, pageUrl);
|
|
71
|
+
return renderPartial(viteServer, resolvedPath, localRenderPlaceholder.json, pageUrl, environmentConfig);
|
|
71
72
|
}
|
|
72
73
|
else if (partialPath === MODULE_FOLDER_PATH) {
|
|
73
|
-
return renderModule(viteServer, resolvedPath, localRenderPlaceholder.json, pageUrl);
|
|
74
|
+
return renderModule(viteServer, resolvedPath, localRenderPlaceholder.json, pageUrl, environmentConfig);
|
|
74
75
|
}
|
|
75
76
|
else {
|
|
76
77
|
throw new Error(`Unimplemented render of ${placeholderPath}.`);
|
|
77
78
|
}
|
|
78
79
|
};
|
|
79
|
-
export default async function proxySpecificPage(response, portalId, contentId, webRoot, viteServer, devServerHost, devServerPort, projectName, projectComponentPath, urlToProxy, fullOriginalUrl) {
|
|
80
|
+
export default async function proxySpecificPage(response, portalId, hublet, contentId, webRoot, viteServer, devServerHost, devServerPort, projectName, projectComponentPath, urlToProxy, fullOriginalUrl) {
|
|
80
81
|
let accountId;
|
|
82
|
+
let proxyEnv;
|
|
81
83
|
try {
|
|
82
84
|
accountId = getAccountId(portalId);
|
|
85
|
+
proxyEnv = getEnv(accountId);
|
|
83
86
|
}
|
|
84
87
|
catch (e) {
|
|
85
88
|
response
|
|
@@ -97,6 +100,7 @@ export default async function proxySpecificPage(response, portalId, contentId, w
|
|
|
97
100
|
const previewInfo = await fetchPreviewInfo(accountId, portalId, contentId);
|
|
98
101
|
const { previewKey } = previewInfo;
|
|
99
102
|
const pageHtml = await makeProxyPreviewRequest(accountId, urlToProxy, previewKey, contentId);
|
|
103
|
+
const environmentConfig = buildStaticEnvConfig(portalId, hublet, proxyEnv, false);
|
|
100
104
|
// Loading through vite so all of nested `@hubspot/cms-*` imports work
|
|
101
105
|
const { sortIslandRootsByPriority } = await viteServer.ssrLoadModule('@hubspot/cms-components');
|
|
102
106
|
const localRenderPlaceholders = findLocalRenderPlaceholders(pageHtml);
|
|
@@ -110,7 +114,7 @@ export default async function proxySpecificPage(response, portalId, contentId, w
|
|
|
110
114
|
for (let indexForThisRender = 0; indexForThisRender < numPlaceholders; indexForThisRender++) {
|
|
111
115
|
const localRenderPlaceholder = localRenderPlaceholders[indexForThisRender];
|
|
112
116
|
pageChunks[indexForThisRender] = pageHtml.slice(offsetSoFar, localRenderPlaceholder.startOffset);
|
|
113
|
-
const renderPromise = renderComponentForPlaceholder(indexForThisRender, localRenderPlaceholder, webRoot, viteServer, fullOriginalUrl, projectName, projectComponentPath);
|
|
117
|
+
const renderPromise = renderComponentForPlaceholder(indexForThisRender, localRenderPlaceholder, webRoot, viteServer, fullOriginalUrl, environmentConfig, projectName, projectComponentPath);
|
|
114
118
|
renderPromisesByChunkIndex[indexForThisRender] = renderPromise
|
|
115
119
|
.then(promiseResult => {
|
|
116
120
|
// eslint-disable-next-line prefer-const
|
|
@@ -141,7 +145,7 @@ export default async function proxySpecificPage(response, portalId, contentId, w
|
|
|
141
145
|
// console.log("JS rendered chunk", i, foobar);
|
|
142
146
|
response.write(foobar);
|
|
143
147
|
}
|
|
144
|
-
response.write(getServerGlobalsToInject(fullOriginalUrl));
|
|
148
|
+
response.write(getServerGlobalsToInject(environmentConfig, fullOriginalUrl));
|
|
145
149
|
if (islands.length > 0) {
|
|
146
150
|
const sortedIslandRoots = sortIslandRootsByPriority(islands);
|
|
147
151
|
const islandRuntimeAndGlobalScriptHtml = await getIslandRuntimeAndGlobalToInject(sortedIslandRoots, viteServer, devServerHost, devServerPort);
|
package/dist/proxyPage/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* hs-eslint ignored failing-rules */
|
|
2
2
|
/* eslint-disable prefer-promise-reject-errors */
|
|
3
|
-
import {
|
|
3
|
+
import { createEmptyServerRenderContext } from '@hubspot/cms-components';
|
|
4
4
|
import { VALID_PROXY_DOMAIN_SUFFIXES } from './constants.js';
|
|
5
5
|
export const getSubDomainFromValidLocalDomain = hostname => {
|
|
6
6
|
for (const validProxyDomainSuffix of VALID_PROXY_DOMAIN_SUFFIXES) {
|
|
@@ -22,7 +22,7 @@ export const fakeRenderJsComponent = (indexForThisRender) => {
|
|
|
22
22
|
resolve({
|
|
23
23
|
html: fakeJsRenderedOutput,
|
|
24
24
|
cssNeeded: '',
|
|
25
|
-
renderContext:
|
|
25
|
+
renderContext: createEmptyServerRenderContext(),
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
catch (e) {
|
|
@@ -9,6 +9,8 @@ import proxyPageResourceRedirect from './proxyPageResourceRedirect.js';
|
|
|
9
9
|
import homeRouteHandler from './homeRouteHandler.js';
|
|
10
10
|
import { debug } from '../lib/debug.js';
|
|
11
11
|
import { VALID_PROXY_DOMAIN_SUFFIXES } from '../proxyPage/constants.js';
|
|
12
|
+
import proxyPathPageRouteHandler from './proxyPathPageRouteHandler.js';
|
|
13
|
+
import proxyPathPageResourceRedirect from './proxyPathPageResourceRedirect.js';
|
|
12
14
|
const STORYBOOK_DOMAINS = VALID_PROXY_DOMAIN_SUFFIXES.map(domain => `storybook.${domain}`);
|
|
13
15
|
const createDevServerRoutes = async (viteServer, storybookPort) => {
|
|
14
16
|
const devServerApp = Router();
|
|
@@ -25,11 +27,13 @@ const createDevServerRoutes = async (viteServer, storybookPort) => {
|
|
|
25
27
|
}));
|
|
26
28
|
}
|
|
27
29
|
devServerApp.use(viteServer.middlewares);
|
|
30
|
+
devServerApp.get('/proxy', proxyPathPageRouteHandler);
|
|
28
31
|
devServerApp.get('/partials/', linksToAllPartialsRouteHandler);
|
|
29
32
|
devServerApp.get('/partial/:partial', partialRouteHandler);
|
|
30
33
|
devServerApp.get('/modules/', linksToAllModulesRouteHandler);
|
|
31
34
|
devServerApp.get('/module/:moduleName', moduleRouteHandler);
|
|
32
35
|
devServerApp.get('/', homeRouteHandler);
|
|
36
|
+
devServerApp.get('/*', proxyPathPageResourceRedirect);
|
|
33
37
|
devServerApp.get('/*', proxyPageResourceRedirect);
|
|
34
38
|
devServerApp.get('/*', proxyPageRouteHandler);
|
|
35
39
|
return devServerApp;
|
|
@@ -6,7 +6,7 @@ const homeRouteHandler = async (request, response) => {
|
|
|
6
6
|
const { webRoot, storybookEnabled, devServerPort } = request.app.locals;
|
|
7
7
|
const { partialNames } = findAllPartialsInRoot(webRoot);
|
|
8
8
|
const { moduleNames } = findAllModulesInRoot(webRoot);
|
|
9
|
-
const { html: responseHtml } = await renderOnServer(_jsxs(_Fragment, { children: [storybookEnabled ? (_jsx("h2", { children: _jsx("a", { href: `//storybook.${request.hostname}:${devServerPort}`, children: "Storybook" }) })) : null, _jsx("h2", { children: "Partials" }), _jsx(PartialsList, { webRoot: webRoot, partialNames: partialNames }), _jsx("h2", { children: "Modules" }), _jsx(ModulesList, { webRoot: webRoot, moduleNames: moduleNames })] }), null);
|
|
9
|
+
const { html: responseHtml } = await renderOnServer(_jsxs(_Fragment, { children: [storybookEnabled ? (_jsx("h2", { children: _jsx("a", { href: `//storybook.${request.hostname}:${devServerPort}`, children: "Storybook" }) })) : null, _jsx("h2", { children: "Partials" }), _jsx(PartialsList, { webRoot: webRoot, partialNames: partialNames }), _jsx("h2", { children: "Modules" }), _jsx(ModulesList, { webRoot: webRoot, moduleNames: moduleNames })] }), null, null);
|
|
10
10
|
response.status(200).set({ 'Content-Type': 'text/html' }).end(responseHtml);
|
|
11
11
|
};
|
|
12
12
|
export default homeRouteHandler;
|
|
@@ -4,7 +4,7 @@ import ModulesList from '../components/ModulesList.js';
|
|
|
4
4
|
const linksToAllModuleRouteHandler = async (request, response) => {
|
|
5
5
|
const { webRoot } = request.app.locals;
|
|
6
6
|
const { moduleNames } = findAllModulesInRoot(webRoot);
|
|
7
|
-
const { html: responseHtml } = await renderOnServer(_jsx(ModulesList, { webRoot: webRoot, moduleNames: moduleNames }), null);
|
|
7
|
+
const { html: responseHtml } = await renderOnServer(_jsx(ModulesList, { webRoot: webRoot, moduleNames: moduleNames }), null, null);
|
|
8
8
|
response.status(200).set({ 'Content-Type': 'text/html' }).end(responseHtml);
|
|
9
9
|
};
|
|
10
10
|
export default linksToAllModuleRouteHandler;
|
|
@@ -4,7 +4,7 @@ import PartialsList from '../components/PartialsList.js';
|
|
|
4
4
|
const linksToAllPartialRouteHandler = async (request, response) => {
|
|
5
5
|
const { webRoot } = request.app.locals;
|
|
6
6
|
const { partialNames } = findAllPartialsInRoot(webRoot);
|
|
7
|
-
const { html: responseHtml } = await renderOnServer(_jsx(PartialsList, { webRoot: webRoot, partialNames: partialNames }), null);
|
|
7
|
+
const { html: responseHtml } = await renderOnServer(_jsx(PartialsList, { webRoot: webRoot, partialNames: partialNames }), null, null);
|
|
8
8
|
response.status(200).set({ 'Content-Type': 'text/html' }).end(responseHtml);
|
|
9
9
|
};
|
|
10
10
|
export default linksToAllPartialRouteHandler;
|
package/dist/routes/module.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { buildStaticEnvConfig } from '@hubspot/cms-components/config';
|
|
1
2
|
import path from 'path';
|
|
2
3
|
import url from 'url';
|
|
3
4
|
import { normalizePath } from 'vite';
|
|
@@ -5,12 +6,13 @@ import fullOriginalUrlFromRequest from '../lib/fullOriginalUrlFromRequest.js';
|
|
|
5
6
|
import renderModule from '../lib/renderModule.js';
|
|
6
7
|
import { createHtmlShellDependingOnRenderContext } from '../lib/templates.js';
|
|
7
8
|
const moduleRouteHandler = async (request, response) => {
|
|
8
|
-
const { webRoot, viteServer } = request.app.locals;
|
|
9
|
+
const { authedPortalId, authedEnv, authedHublet, webRoot, viteServer } = request.app.locals;
|
|
9
10
|
const moduleName = request.params.moduleName;
|
|
10
11
|
const baseTemplatePath = path.join(path.dirname(url.fileURLToPath(import.meta.url)), '../html/baseTemplate.html');
|
|
11
12
|
const modulePath = normalizePath(path.resolve(webRoot, 'components/modules/', moduleName));
|
|
13
|
+
const environmentConfig = buildStaticEnvConfig(authedPortalId, authedHublet, authedEnv, false);
|
|
12
14
|
try {
|
|
13
|
-
const { html: renderedHtml, cssNeeded, renderContext, } = await renderModule(viteServer, modulePath, null, fullOriginalUrlFromRequest(request));
|
|
15
|
+
const { html: renderedHtml, cssNeeded, renderContext, } = await renderModule(viteServer, modulePath, null, fullOriginalUrlFromRequest(request), environmentConfig);
|
|
14
16
|
const htmlShell = await createHtmlShellDependingOnRenderContext(baseTemplatePath, request.originalUrl, `Module: ${modulePath}`, renderContext, viteServer);
|
|
15
17
|
const html = htmlShell
|
|
16
18
|
.replace('<!--headend-->', cssNeeded)
|
package/dist/routes/partial.js
CHANGED
|
@@ -4,13 +4,15 @@ import { normalizePath } from 'vite';
|
|
|
4
4
|
import fullOriginalUrlFromRequest from '../lib/fullOriginalUrlFromRequest.js';
|
|
5
5
|
import renderPartial from '../lib/renderPartial.js';
|
|
6
6
|
import { createHtmlShellDependingOnRenderContext } from '../lib/templates.js';
|
|
7
|
+
import { buildStaticEnvConfig } from '@hubspot/cms-components/config';
|
|
7
8
|
const partialRouteHandler = async (request, response) => {
|
|
8
|
-
const { webRoot, viteServer } = request.app.locals;
|
|
9
|
+
const { authedPortalId, authedEnv, authedHublet, webRoot, viteServer } = request.app.locals;
|
|
9
10
|
const partialName = request.params.partial;
|
|
10
11
|
const baseTemplatePath = path.join(path.dirname(url.fileURLToPath(import.meta.url)), '../html/baseTemplate.html');
|
|
11
12
|
const partialPath = normalizePath(path.resolve(webRoot, 'components/partials/', partialName));
|
|
13
|
+
const environmentConfig = buildStaticEnvConfig(authedPortalId, authedHublet, authedEnv, false);
|
|
12
14
|
try {
|
|
13
|
-
const { html: renderedHtml, cssNeeded, renderContext, } = await renderPartial(viteServer, partialPath, {}, fullOriginalUrlFromRequest(request));
|
|
15
|
+
const { html: renderedHtml, cssNeeded, renderContext, } = await renderPartial(viteServer, partialPath, {}, fullOriginalUrlFromRequest(request), environmentConfig);
|
|
14
16
|
const htmlShell = await createHtmlShellDependingOnRenderContext(baseTemplatePath, request.originalUrl, `Partial: ${partialPath}`, renderContext, viteServer);
|
|
15
17
|
const html = htmlShell
|
|
16
18
|
.replace('<!--headend-->', cssNeeded)
|
|
@@ -31,8 +31,8 @@ export default async function proxyPageRouteHandler(request, response, next) {
|
|
|
31
31
|
return response.status(400).send(message);
|
|
32
32
|
}
|
|
33
33
|
try {
|
|
34
|
-
const { portalId, contentId } = await fetchContentMetadata(urlToProxy);
|
|
35
|
-
await proxyPage(response, portalId, contentId, webRoot, viteServer, devServerHost, devServerPort, projectName, projectComponentPath, urlToProxy, fullOriginalUrl);
|
|
34
|
+
const { portalId, contentId, hublet } = await fetchContentMetadata(urlToProxy);
|
|
35
|
+
await proxyPage(response, portalId, hublet, contentId, webRoot, viteServer, devServerHost, devServerPort, projectName, projectComponentPath, urlToProxy, fullOriginalUrl);
|
|
36
36
|
}
|
|
37
37
|
catch (e) {
|
|
38
38
|
next(e);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
const HCMS_PATH = '/_hcms/';
|
|
3
|
+
const HS_FS_PATH = '/hs-fs/';
|
|
4
|
+
const HUB_FS_PATH = '/hubfs/';
|
|
5
|
+
// From(ish) https://git.hubteam.com/HubSpot/cloudflare-workers/blob/master/worker-lib/src/Constants.ts
|
|
6
|
+
const isInternalCMSRoute = (req) => req.path.startsWith(HCMS_PATH) ||
|
|
7
|
+
req.path.startsWith(HS_FS_PATH) ||
|
|
8
|
+
req.path.startsWith(HUB_FS_PATH);
|
|
9
|
+
export default function proxyPathPageResourceRedirect(req, res, next) {
|
|
10
|
+
const isAHtmlRequest = req.accepts().includes('text/html');
|
|
11
|
+
// only proxy when referer's path is /proxy && has page query param
|
|
12
|
+
let proxyPageUrl;
|
|
13
|
+
let refererUrl;
|
|
14
|
+
try {
|
|
15
|
+
refererUrl = new URL(req.headers.referer);
|
|
16
|
+
proxyPageUrl = new URL(new URL(req.headers.referer).searchParams.get('page'));
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
next();
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (!refererUrl.pathname.startsWith('/proxy')) {
|
|
23
|
+
next();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// handle anchor links, unless internal CMS route
|
|
27
|
+
if (isAHtmlRequest && !isInternalCMSRoute(req)) {
|
|
28
|
+
const encodedPageUrl = encodeURIComponent(`${proxyPageUrl.origin}${req.url}`);
|
|
29
|
+
res.redirect(`/proxy?page=${encodedPageUrl}`);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const urlToProxy = `https://${proxyPageUrl.host}${req.url}`;
|
|
33
|
+
fetch(urlToProxy)
|
|
34
|
+
.then(response => response.body.pipe(res))
|
|
35
|
+
.catch(err => console.log(err));
|
|
36
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/* hs-eslint ignored failing-rules */
|
|
3
|
+
/* eslint-disable consistent-return */
|
|
4
|
+
import { renderOnServer } from '@hubspot/cms-js-internal';
|
|
5
|
+
import fetchContentMetadata from '../proxyPage/fetchContentMetadata.js';
|
|
6
|
+
import proxyPage from '../proxyPage/proxyPage.js';
|
|
7
|
+
import { consoleWarn } from '../proxyPage/utils.js';
|
|
8
|
+
export default async function proxyPathPageRouteHandler(request, response, next) {
|
|
9
|
+
const { viteServer, webRoot, devServerHost, devServerPort, projectName, projectComponentPath, } = request.app.locals;
|
|
10
|
+
if (!request.accepts().includes('text/html')) {
|
|
11
|
+
return response.sendStatus(404);
|
|
12
|
+
}
|
|
13
|
+
// render proxy index page if not supplied with query param
|
|
14
|
+
if (!request.query.page) {
|
|
15
|
+
const { html: responseHtml } = await renderOnServer(_jsxs("div", { children: [_jsx("h2", { children: "Local Proxy" }), _jsxs("form", { action: "/proxy", children: [_jsx("label", { htmlFor: "page", style: { display: 'block' }, children: "Page URL" }), _jsx("input", { style: { width: '300px' }, name: "page", type: "text", placeholder: "https://somecmspage.com/path" }), _jsx("button", { style: { display: 'block' }, children: "Proxy" })] })] }), null, null);
|
|
16
|
+
response.status(200).set({ 'Content-Type': 'text/html' }).end(responseHtml);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// parse proxy page URL from query param
|
|
20
|
+
let proxyPageUrl;
|
|
21
|
+
try {
|
|
22
|
+
proxyPageUrl = new URL(request.query.page);
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
const message = 'Please provide a valid page query parameter, e.g., http://localhost:3000/proxy?page=https://yourdomain.com/path';
|
|
26
|
+
consoleWarn(message);
|
|
27
|
+
response.status(400).send(message);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// validate proxy page URL query params
|
|
31
|
+
if (proxyPageUrl.searchParams.has('hs_preview')) {
|
|
32
|
+
const message = `Can't make a proxy request, you cannot proxy URLs that include internal query params like hs_preview`;
|
|
33
|
+
consoleWarn(message);
|
|
34
|
+
return response.status(400).send(message);
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const { portalId, contentId, hublet } = await fetchContentMetadata(proxyPageUrl.href);
|
|
38
|
+
await proxyPage(response, portalId, hublet, contentId, webRoot, viteServer, devServerHost, devServerPort, projectName, projectComponentPath, proxyPageUrl.href, proxyPageUrl.href);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
next(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import { getAccountId } from '@hubspot/cli-lib/lib/config.js';
|
|
3
|
+
import cors from 'cors';
|
|
4
|
+
import { findLocalRenderPlaceholders } from '../lib/proxyHelpers.js';
|
|
5
|
+
import { makeProxyPreviewRequest } from '../proxyPage/proxyPage.js';
|
|
6
|
+
import fetchPreviewInfo from '../proxyPage/fetchPreviewInfo.js';
|
|
7
|
+
function getShadowDevServerCheckHandler(devServerPort) {
|
|
8
|
+
return async function shadowDevServerCheckHandler(request, response) {
|
|
9
|
+
const { query } = request;
|
|
10
|
+
if (query) {
|
|
11
|
+
const { hostName, pathName, protocol, contentId, portalId: portalIdString, } = query;
|
|
12
|
+
const pageUrl = `${protocol}//${hostName}${pathName}`;
|
|
13
|
+
const portalId = parseInt(portalIdString, 10);
|
|
14
|
+
let accountId;
|
|
15
|
+
let hasJSBuildingBlocks = false;
|
|
16
|
+
let localProxyUrl;
|
|
17
|
+
try {
|
|
18
|
+
accountId = getAccountId(portalId);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
response
|
|
22
|
+
.status(500)
|
|
23
|
+
.end(`Unable to find account for hubid = ${portalId}. Please check your hubspot.config.yaml`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const previewInfo = await fetchPreviewInfo(accountId, portalId, contentId);
|
|
28
|
+
const { previewKey } = previewInfo;
|
|
29
|
+
const pageHtml = await makeProxyPreviewRequest(accountId, pageUrl, previewKey, contentId);
|
|
30
|
+
const localRenderPlaceholders = findLocalRenderPlaceholders(pageHtml);
|
|
31
|
+
if (localRenderPlaceholders.length) {
|
|
32
|
+
hasJSBuildingBlocks = true;
|
|
33
|
+
localProxyUrl = `http://${hostName}.hslocal.net:${devServerPort}${pathName}`;
|
|
34
|
+
}
|
|
35
|
+
response
|
|
36
|
+
.status(200)
|
|
37
|
+
.set({ 'Content-Type': 'application/json' })
|
|
38
|
+
.json({ hasJSBuildingBlocks, localProxyUrl });
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
response
|
|
42
|
+
.status(500)
|
|
43
|
+
.end(`Failed proxy render of page id = ${contentId} hub id = ${portalId}\n\n${error.stack}`);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
response
|
|
49
|
+
.status(500)
|
|
50
|
+
.end(`Missing pageUrl param, cannot check for proxied page without a pageUrl`);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export default async function createShadowDevServerRoutes(devServerPort) {
|
|
55
|
+
const shadowDevServerRoutes = Router();
|
|
56
|
+
shadowDevServerRoutes.get('/check-if-local-dev-server', cors(), getShadowDevServerCheckHandler(devServerPort));
|
|
57
|
+
return shadowDevServerRoutes;
|
|
58
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import net from 'net';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import createShadowDevServerRoutes from './createShadowDevServerRoutes.js';
|
|
4
|
+
const SHADOW_PORT = 1442;
|
|
5
|
+
const testNetServer = net.createServer();
|
|
6
|
+
export default async function startShadowDevServer(devServerPort) {
|
|
7
|
+
const portIsTaken = await new Promise((res, rej) => {
|
|
8
|
+
console.log(`Starting proxy link server on port ${SHADOW_PORT}`);
|
|
9
|
+
testNetServer.once('error', err => {
|
|
10
|
+
if (err['code'] === 'EADDRINUSE') {
|
|
11
|
+
console.error(`Port ${SHADOW_PORT} is in use. HubSpot is unable to automatically create proxy links in the Sprocket Menu`);
|
|
12
|
+
res(true);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
rej(err);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
testNetServer.once('listening', () => {
|
|
19
|
+
testNetServer.close();
|
|
20
|
+
});
|
|
21
|
+
testNetServer.once('close', () => {
|
|
22
|
+
res(false);
|
|
23
|
+
});
|
|
24
|
+
testNetServer.listen(SHADOW_PORT);
|
|
25
|
+
});
|
|
26
|
+
if (portIsTaken) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const shadowDevServer = express();
|
|
30
|
+
shadowDevServer.listen(SHADOW_PORT);
|
|
31
|
+
shadowDevServer.use('/', await createShadowDevServerRoutes(devServerPort));
|
|
32
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { ModuleFields, BooleanField, TextField, FieldGroup, NumberField, ColorField, } from '@hubspot/cms-components/fields';
|
|
4
|
+
import { renderFieldsToJson } from '@hubspot/cms-js-internal';
|
|
5
|
+
import getFieldsArgTypes from './getFieldsArgTypes.js';
|
|
6
|
+
describe('getFieldsArgTypes', () => {
|
|
7
|
+
it('creates argType for boolean field', () => {
|
|
8
|
+
const fields = (_jsx(ModuleFields, { children: _jsx(BooleanField, { name: "testBooleanField", label: "field", default: false }) }));
|
|
9
|
+
const argTypes = getFieldsArgTypes(renderFieldsToJson(fields));
|
|
10
|
+
expect(argTypes).toStrictEqual({
|
|
11
|
+
testBooleanField: {
|
|
12
|
+
control: 'boolean',
|
|
13
|
+
defaultValue: false,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
it('creates text argType for text field', () => {
|
|
18
|
+
const fields = (_jsx(ModuleFields, { children: _jsx(TextField, { name: "testStringField", label: "field", default: 'test' }) }));
|
|
19
|
+
const argTypes = getFieldsArgTypes(renderFieldsToJson(fields));
|
|
20
|
+
expect(argTypes).toStrictEqual({
|
|
21
|
+
testStringField: {
|
|
22
|
+
control: 'text',
|
|
23
|
+
defaultValue: 'test',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
it('creates number argType for number field', () => {
|
|
28
|
+
const fields = (_jsx(ModuleFields, { children: _jsx(NumberField, { name: "testNumberField", label: "field", default: 123 }) }));
|
|
29
|
+
const argTypes = getFieldsArgTypes(renderFieldsToJson(fields));
|
|
30
|
+
expect(argTypes).toStrictEqual({
|
|
31
|
+
testNumberField: {
|
|
32
|
+
control: 'number',
|
|
33
|
+
defaultValue: 123,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
it('creates object argType for unknown field', () => {
|
|
38
|
+
const fields = (_jsx(ModuleFields, { children: _jsx(ColorField, { name: "testColorField", label: "field", default: {
|
|
39
|
+
color: '#fff',
|
|
40
|
+
} }) }));
|
|
41
|
+
const argTypes = getFieldsArgTypes(renderFieldsToJson(fields));
|
|
42
|
+
expect(argTypes).toStrictEqual({
|
|
43
|
+
testColorField: {
|
|
44
|
+
control: 'object',
|
|
45
|
+
defaultValue: {
|
|
46
|
+
color: '#fff',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
it('prefixes fields in a group with . separated group names', () => {
|
|
52
|
+
const fields = (_jsx(ModuleFields, { children: _jsxs(FieldGroup, { name: "mygroup", label: "field group", children: [_jsx(TextField, { name: "testStringField", label: "field", default: 'test' }), _jsx(BooleanField, { name: "testBooleanField", label: "field", default: false })] }) }));
|
|
53
|
+
const argTypes = getFieldsArgTypes(renderFieldsToJson(fields));
|
|
54
|
+
expect(argTypes).toStrictEqual({
|
|
55
|
+
'mygroup.testStringField': {
|
|
56
|
+
control: 'text',
|
|
57
|
+
defaultValue: 'test',
|
|
58
|
+
},
|
|
59
|
+
'mygroup.testBooleanField': {
|
|
60
|
+
control: 'boolean',
|
|
61
|
+
defaultValue: false,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
it('handles multiple nesting alongside top level values', () => {
|
|
66
|
+
const fields = (_jsxs(ModuleFields, { children: [_jsx(TextField, { name: "toplevel", label: "top level text field", default: "defaultvalue" }), _jsxs(FieldGroup, { name: "mygroup", label: "field group", children: [_jsx(TextField, { name: "testStringField", label: "field", default: 'test' }), _jsx(BooleanField, { name: "testBooleanField", label: "field", default: false }), _jsxs(FieldGroup, { name: "nestedgroup", label: "nested group", children: [_jsx(TextField, { name: "testStringField", label: "field", default: 'test' }), _jsx(BooleanField, { name: "testBooleanField", label: "field", default: false })] })] })] }));
|
|
67
|
+
const argTypes = getFieldsArgTypes(renderFieldsToJson(fields));
|
|
68
|
+
expect(argTypes).toStrictEqual({
|
|
69
|
+
toplevel: {
|
|
70
|
+
control: 'text',
|
|
71
|
+
defaultValue: 'defaultvalue',
|
|
72
|
+
},
|
|
73
|
+
'mygroup.testStringField': {
|
|
74
|
+
control: 'text',
|
|
75
|
+
defaultValue: 'test',
|
|
76
|
+
},
|
|
77
|
+
'mygroup.testBooleanField': {
|
|
78
|
+
control: 'boolean',
|
|
79
|
+
defaultValue: false,
|
|
80
|
+
},
|
|
81
|
+
'mygroup.nestedgroup.testStringField': {
|
|
82
|
+
control: 'text',
|
|
83
|
+
defaultValue: 'test',
|
|
84
|
+
},
|
|
85
|
+
'mygroup.nestedgroup.testBooleanField': {
|
|
86
|
+
control: 'boolean',
|
|
87
|
+
defaultValue: false,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// default values come through via `defaultValue` in the story's argTypes, we
|
|
2
|
+
// need to re-nest them to match the field structure
|
|
3
|
+
export default function getNestedFieldObjectForArgs(_args) {
|
|
4
|
+
const result = {};
|
|
5
|
+
for (const argPath in _args) {
|
|
6
|
+
if (Object.prototype.hasOwnProperty.call(_args, argPath)) {
|
|
7
|
+
const argPathSegments = argPath.split('.');
|
|
8
|
+
const nestedSegments = argPathSegments.slice(0, -1);
|
|
9
|
+
const fieldName = argPathSegments[argPathSegments.length - 1];
|
|
10
|
+
const fieldValue = _args[argPath];
|
|
11
|
+
let currentNest = result;
|
|
12
|
+
for (const segment of nestedSegments) {
|
|
13
|
+
if (!Object.prototype.hasOwnProperty.call(currentNest, segment)) {
|
|
14
|
+
currentNest[segment] = {};
|
|
15
|
+
}
|
|
16
|
+
currentNest = currentNest[segment];
|
|
17
|
+
}
|
|
18
|
+
currentNest[fieldName] = fieldValue;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import getNestedFieldObjectForArgs from './getNestedFieldObjectForArgs.js';
|
|
3
|
+
describe('getNestedFieldObjectForArgs', () => {
|
|
4
|
+
it('leaves top level args as is', () => {
|
|
5
|
+
const argMap = {
|
|
6
|
+
testField: 'testValue',
|
|
7
|
+
testField2: 'testValue',
|
|
8
|
+
};
|
|
9
|
+
const result = getNestedFieldObjectForArgs(argMap);
|
|
10
|
+
expect(result).toStrictEqual(argMap);
|
|
11
|
+
});
|
|
12
|
+
it('turns a . separated arg name into a nested field', () => {
|
|
13
|
+
const argMap = {
|
|
14
|
+
'group.testField': 'testValue',
|
|
15
|
+
topLevelField: 'testValue',
|
|
16
|
+
};
|
|
17
|
+
const result = getNestedFieldObjectForArgs(argMap);
|
|
18
|
+
expect(result).toStrictEqual({
|
|
19
|
+
group: {
|
|
20
|
+
testField: 'testValue',
|
|
21
|
+
},
|
|
22
|
+
topLevelField: 'testValue',
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
it('keeps nested fields with the same group prefix nested in the same object', () => {
|
|
26
|
+
const argMap = {
|
|
27
|
+
'group.testField': 'testValue',
|
|
28
|
+
'group.secondField': 'testValue',
|
|
29
|
+
topLevelField: 'testValue',
|
|
30
|
+
};
|
|
31
|
+
const result = getNestedFieldObjectForArgs(argMap);
|
|
32
|
+
expect(result).toStrictEqual({
|
|
33
|
+
group: {
|
|
34
|
+
testField: 'testValue',
|
|
35
|
+
secondField: 'testValue',
|
|
36
|
+
},
|
|
37
|
+
topLevelField: 'testValue',
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
package/dist/storybook/index.js
CHANGED
|
@@ -1,7 +1,26 @@
|
|
|
1
|
-
//
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
// ../cms-js-internal/dist/index.js
|
|
2
|
+
import { renderToPipeableStream } from "react-dom/server";
|
|
3
|
+
import {
|
|
4
|
+
ServerRenderContext,
|
|
5
|
+
createServerRenderContext
|
|
6
|
+
} from "@hubspot/cms-components";
|
|
4
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
import { cloneElement } from "react";
|
|
9
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
10
|
+
function renderFieldsToJson(fields) {
|
|
11
|
+
let moduleJson;
|
|
12
|
+
const outputCallback = (callbackJson) => {
|
|
13
|
+
moduleJson = callbackJson;
|
|
14
|
+
};
|
|
15
|
+
renderToStaticMarkup(
|
|
16
|
+
cloneElement(fields, {
|
|
17
|
+
outputCallback
|
|
18
|
+
})
|
|
19
|
+
);
|
|
20
|
+
return moduleJson;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/storybook/getFieldsArgTypes.ts
|
|
5
24
|
function getFieldsArgTypes(fieldsJson, currentPathSegments = []) {
|
|
6
25
|
let resultArgTypes = {};
|
|
7
26
|
for (const field of fieldsJson) {
|
|
@@ -53,6 +72,8 @@ function getFieldsArgTypes(fieldsJson, currentPathSegments = []) {
|
|
|
53
72
|
}
|
|
54
73
|
return resultArgTypes;
|
|
55
74
|
}
|
|
75
|
+
|
|
76
|
+
// src/storybook/getNestedFieldObjectForArgs.ts
|
|
56
77
|
function getNestedFieldObjectForArgs(_args) {
|
|
57
78
|
const result = {};
|
|
58
79
|
for (const argPath in _args) {
|
|
@@ -73,27 +94,15 @@ function getNestedFieldObjectForArgs(_args) {
|
|
|
73
94
|
}
|
|
74
95
|
return result;
|
|
75
96
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
moduleJson = callbackJson;
|
|
80
|
-
};
|
|
81
|
-
renderToStaticMarkup(
|
|
82
|
-
React.cloneElement(fields, {
|
|
83
|
-
outputCallback
|
|
84
|
-
})
|
|
85
|
-
);
|
|
86
|
-
if (!moduleJson) {
|
|
87
|
-
throw new Error("couldn't render module fields definition to fields.json");
|
|
88
|
-
}
|
|
89
|
-
return moduleJson;
|
|
90
|
-
}
|
|
97
|
+
|
|
98
|
+
// src/storybook/moduleStory.tsx
|
|
99
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
91
100
|
function moduleStory(ModuleComponent, fields) {
|
|
92
|
-
const moduleJson =
|
|
101
|
+
const moduleJson = renderFieldsToJson(fields);
|
|
93
102
|
const argTypes = getFieldsArgTypes(moduleJson);
|
|
94
103
|
const story = (_args) => {
|
|
95
104
|
const fieldValues = getNestedFieldObjectForArgs(_args);
|
|
96
|
-
return /* @__PURE__ */
|
|
105
|
+
return /* @__PURE__ */ jsx2(ModuleComponent, {
|
|
97
106
|
...fieldValues
|
|
98
107
|
});
|
|
99
108
|
};
|
|
@@ -103,7 +112,5 @@ function moduleStory(ModuleComponent, fields) {
|
|
|
103
112
|
return storyWithArgs;
|
|
104
113
|
}
|
|
105
114
|
export {
|
|
106
|
-
getNestedFieldObjectForArgs,
|
|
107
|
-
moduleFieldsToJson,
|
|
108
115
|
moduleStory
|
|
109
116
|
};
|
package/dist/storybook/main.js
CHANGED
|
@@ -1,97 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
let resultArgTypes = {};
|
|
6
|
-
for (const field of fieldsJson) {
|
|
7
|
-
// storybook doesn't support nested controls, so emulate our nested
|
|
8
|
-
// structure with group1.group2.field structure
|
|
9
|
-
const fullFieldName = [...currentPathSegments, field.name].join('.');
|
|
10
|
-
// should this definition of fieldType => argType live next to fields in cms-components?
|
|
11
|
-
switch (field.type) {
|
|
12
|
-
case 'group': {
|
|
13
|
-
if (!field.children) {
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
const groupResult = getFieldsArgTypes(field.children, [
|
|
17
|
-
...currentPathSegments,
|
|
18
|
-
field.name,
|
|
19
|
-
]);
|
|
20
|
-
resultArgTypes = {
|
|
21
|
-
...resultArgTypes,
|
|
22
|
-
...groupResult,
|
|
23
|
-
};
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
case 'boolean': {
|
|
27
|
-
resultArgTypes[fullFieldName] = {
|
|
28
|
-
control: 'boolean',
|
|
29
|
-
defaultValue: field.default,
|
|
30
|
-
};
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
case 'text': {
|
|
34
|
-
resultArgTypes[fullFieldName] = {
|
|
35
|
-
control: 'text',
|
|
36
|
-
defaultValue: field.default,
|
|
37
|
-
};
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
case 'number': {
|
|
41
|
-
resultArgTypes[fullFieldName] = {
|
|
42
|
-
control: 'number',
|
|
43
|
-
defaultValue: field.default,
|
|
44
|
-
};
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
default: {
|
|
48
|
-
resultArgTypes[fullFieldName] = {
|
|
49
|
-
control: 'object',
|
|
50
|
-
defaultValue: field.default,
|
|
51
|
-
};
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return resultArgTypes;
|
|
57
|
-
}
|
|
58
|
-
// default values come through via `defaultValue` in the story's argTypes, we
|
|
59
|
-
// need to re-nest them to match the field structure
|
|
60
|
-
export function getNestedFieldObjectForArgs(_args) {
|
|
61
|
-
const result = {};
|
|
62
|
-
for (const argPath in _args) {
|
|
63
|
-
if (Object.prototype.hasOwnProperty.call(_args, argPath)) {
|
|
64
|
-
const argPathSegments = argPath.split('.');
|
|
65
|
-
const nestedSegments = argPathSegments.slice(0, -1);
|
|
66
|
-
const fieldName = argPathSegments[argPathSegments.length - 1];
|
|
67
|
-
const fieldValue = _args[argPath];
|
|
68
|
-
let currentNest = result;
|
|
69
|
-
for (const segment of nestedSegments) {
|
|
70
|
-
if (!Object.prototype.hasOwnProperty.call(currentNest, segment)) {
|
|
71
|
-
currentNest[segment] = {};
|
|
72
|
-
}
|
|
73
|
-
currentNest = currentNest[segment];
|
|
74
|
-
}
|
|
75
|
-
currentNest[fieldName] = fieldValue;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return result;
|
|
79
|
-
}
|
|
80
|
-
export function moduleFieldsToJson(fields) {
|
|
81
|
-
let moduleJson;
|
|
82
|
-
const outputCallback = (callbackJson) => {
|
|
83
|
-
moduleJson = callbackJson;
|
|
84
|
-
};
|
|
85
|
-
renderToStaticMarkup(React.cloneElement(fields, {
|
|
86
|
-
outputCallback,
|
|
87
|
-
}));
|
|
88
|
-
if (!moduleJson) {
|
|
89
|
-
throw new Error("couldn't render module fields definition to fields.json");
|
|
90
|
-
}
|
|
91
|
-
return moduleJson;
|
|
92
|
-
}
|
|
2
|
+
import { renderFieldsToJson } from '@hubspot/cms-js-internal';
|
|
3
|
+
import getFieldsArgTypes from './getFieldsArgTypes.js';
|
|
4
|
+
import getNestedFieldObjectForArgs from './getNestedFieldObjectForArgs.js';
|
|
93
5
|
export function moduleStory(ModuleComponent, fields) {
|
|
94
|
-
const moduleJson =
|
|
6
|
+
const moduleJson = renderFieldsToJson(fields);
|
|
95
7
|
const argTypes = getFieldsArgTypes(moduleJson);
|
|
96
8
|
const story = (_args) => {
|
|
97
9
|
const fieldValues = getNestedFieldObjectForArgs(_args);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -8,21 +8,24 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc --build && yarn run copy-html && yarn build-types && node scripts/build.mjs",
|
|
11
|
+
"build:watch": "nodemon --exec 'yarn build'",
|
|
11
12
|
"copy-html": "copyfiles -u 1 'src/html/**' 'dist'",
|
|
12
13
|
"build-types": "tsc --project tsconfig.types.json",
|
|
13
14
|
"clean": "tsc --build --clean",
|
|
14
|
-
"dev": "nodemon --exec '
|
|
15
|
-
"dev-inspect": "nodemon --exec '
|
|
15
|
+
"dev": "nodemon --exec 'yarn start'",
|
|
16
|
+
"dev-inspect": "nodemon --exec 'yarn start-inspect'",
|
|
16
17
|
"es-watch": "esbuild --outfile=dist-esbuild/runWhenDeveloping.cjs --bundle --watch --platform=node --external:fsevents --external:vite --external:react-refresh runWhenDeveloping.ts",
|
|
17
18
|
"package": "npm run build && npm pack",
|
|
18
19
|
"prepare": "npm run build",
|
|
19
|
-
"runBuild": "node run.
|
|
20
|
-
"
|
|
20
|
+
"runBuild": "node dist/run.js",
|
|
21
|
+
"start": "ts-node-esm --transpileOnly runWhenDeveloping.ts",
|
|
22
|
+
"start-inspect": "node --loader ts-node/esm --inspect runWhenDeveloping.ts",
|
|
23
|
+
"test": "NODE_ENV=test vitest run"
|
|
21
24
|
},
|
|
22
25
|
"dependencies": {
|
|
23
26
|
"@hubspot/cli-lib": "^3.0.12",
|
|
24
|
-
"@hubspot/cms-components": "^0.3.
|
|
25
|
-
"@hubspot/cms-js-internal": "^0.3.
|
|
27
|
+
"@hubspot/cms-components": "^0.3.4",
|
|
28
|
+
"@hubspot/cms-js-internal": "^0.3.4",
|
|
26
29
|
"@storybook/addon-actions": "^7.0.0-beta.19",
|
|
27
30
|
"@storybook/addon-essentials": "^7.0.0-beta.19",
|
|
28
31
|
"@storybook/addon-interactions": "^7.0.0-beta.19",
|
|
@@ -33,6 +36,7 @@
|
|
|
33
36
|
"@storybook/testing-library": "^0.0.13",
|
|
34
37
|
"@vitejs/plugin-react": "^3.0.0",
|
|
35
38
|
"ansi-to-html": "0.7.x",
|
|
39
|
+
"cors": "^2.8.5",
|
|
36
40
|
"debug": "^4.3.4",
|
|
37
41
|
"express": "^4.17.3",
|
|
38
42
|
"http-proxy-middleware": "^2.0.6",
|
|
@@ -44,17 +48,19 @@
|
|
|
44
48
|
"vite-plugin-inspect": "^0.4.3"
|
|
45
49
|
},
|
|
46
50
|
"devDependencies": {
|
|
51
|
+
"@testing-library/dom": "^8.20.0",
|
|
47
52
|
"@types/express": "^4.17.13",
|
|
48
53
|
"@types/react": "^18.0.0",
|
|
49
54
|
"@types/react-dom": "^18.0.0",
|
|
50
55
|
"copyfiles": "^2.4.1",
|
|
56
|
+
"node-fetch": "^3.3.0",
|
|
51
57
|
"nodemon": "^2.0.15",
|
|
52
58
|
"ts-node": "^10.7.0",
|
|
53
59
|
"vitest": "0.25.8"
|
|
54
60
|
},
|
|
55
|
-
"main": "./dist/
|
|
61
|
+
"main": "./dist/createDevServer.js",
|
|
56
62
|
"exports": {
|
|
57
|
-
".": "./dist/
|
|
63
|
+
".": "./dist/createDevServer.js",
|
|
58
64
|
"./storybook": {
|
|
59
65
|
"types": "./types/storybook/index.d.ts",
|
|
60
66
|
"default": "./dist/storybook/index.js"
|
|
@@ -85,5 +91,5 @@
|
|
|
85
91
|
"publishConfig": {
|
|
86
92
|
"access": "public"
|
|
87
93
|
},
|
|
88
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "ca8cb386c6ffeea1474ef31811be525db2c69c97"
|
|
89
95
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Field } from '@hubspot/cms-components/fields';
|
|
2
|
+
declare type ArgTypes = {
|
|
3
|
+
[fieldPath: string]: {
|
|
4
|
+
control: string;
|
|
5
|
+
defaultValue: any;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export default function getFieldsArgTypes(fieldsJson: Field[], currentPathSegments?: string[]): ArgTypes;
|
|
9
|
+
export {};
|
|
@@ -1,12 +1,2 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Field } from '@hubspot/cms-components/fields';
|
|
3
|
-
declare type Args = {
|
|
4
|
-
[fieldPath: string]: any;
|
|
5
|
-
};
|
|
6
|
-
declare type FieldValues = {
|
|
7
|
-
[fieldNameOrGroupName: string]: FieldValues;
|
|
8
|
-
};
|
|
9
|
-
export declare function getNestedFieldObjectForArgs(_args: Args): FieldValues;
|
|
10
|
-
export declare function moduleFieldsToJson(fields: JSX.Element): Field[];
|
|
11
2
|
export declare function moduleStory(ModuleComponent: React.ComponentType, fields: JSX.Element): any;
|
|
12
|
-
export {};
|