@hubspot/cms-dev-server 0.14.2 → 0.14.3
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 +40 -6
- package/dist/run.js +186 -29
- package/dist/storybook/index.js +4 -2
- package/dist/storybook-main/main.js +40 -6
- package/package.json +5 -4
package/dist/internalSsr.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// ../cms-js-internal/dist/index.js
|
|
2
|
+
import { hasProperty, setProperty, getProperty } from "dot-prop";
|
|
2
3
|
import path from "path";
|
|
3
4
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
4
5
|
import stream from "stream";
|
|
@@ -96,7 +97,7 @@ function jsonStringifyAndEscapeForInlineJS(input, { baseIndent = 0, jsonIndent =
|
|
|
96
97
|
${indentString}`
|
|
97
98
|
);
|
|
98
99
|
}
|
|
99
|
-
var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, prettyPrint) => {
|
|
100
|
+
var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
|
|
100
101
|
const islandsArrayToSerialize = tweakedIslandsArray.map(
|
|
101
102
|
({
|
|
102
103
|
id,
|
|
@@ -108,6 +109,7 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, p
|
|
|
108
109
|
priority,
|
|
109
110
|
url,
|
|
110
111
|
sharedStateID,
|
|
112
|
+
supplementalFieldValues,
|
|
111
113
|
wrapperModuleId,
|
|
112
114
|
wrapperUrl
|
|
113
115
|
}) => {
|
|
@@ -130,6 +132,13 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, p
|
|
|
130
132
|
if (wrapperUrl) {
|
|
131
133
|
output.wrapperUrl = wrapperUrl;
|
|
132
134
|
}
|
|
135
|
+
const filteredSupplementalFieldValues = filterOutUnreadSupplementalFieldValues(
|
|
136
|
+
supplementalFieldValues,
|
|
137
|
+
perServerRequestData.get("supplementalFieldValuesRead")
|
|
138
|
+
);
|
|
139
|
+
if (filteredSupplementalFieldValues) {
|
|
140
|
+
output.supplementalFieldValues = filteredSupplementalFieldValues;
|
|
141
|
+
}
|
|
133
142
|
return output;
|
|
134
143
|
}
|
|
135
144
|
);
|
|
@@ -139,6 +148,25 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, p
|
|
|
139
148
|
prettyPrint
|
|
140
149
|
});
|
|
141
150
|
};
|
|
151
|
+
function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplementalFieldValuesRead) {
|
|
152
|
+
if (!supplementalFieldValues) {
|
|
153
|
+
return supplementalFieldValues;
|
|
154
|
+
}
|
|
155
|
+
if (!supplementalFieldValuesRead) {
|
|
156
|
+
return supplementalFieldValues;
|
|
157
|
+
}
|
|
158
|
+
const result = {};
|
|
159
|
+
Array.from(supplementalFieldValuesRead).forEach((fieldPath) => {
|
|
160
|
+
if (hasProperty(supplementalFieldValues, fieldPath)) {
|
|
161
|
+
setProperty(
|
|
162
|
+
result,
|
|
163
|
+
fieldPath,
|
|
164
|
+
getProperty(supplementalFieldValues, fieldPath)
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
142
170
|
var writeSharedStateToJsGlobal = (islands, perServerRequestData, indent = 0, prettyPrint) => {
|
|
143
171
|
const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x) => !!x);
|
|
144
172
|
if (sharedStateIDs.length > 0) {
|
|
@@ -216,6 +244,7 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
|
|
|
216
244
|
indent
|
|
217
245
|
)}window.__islands = ${serializeIslandDataForInlineScript(
|
|
218
246
|
islands,
|
|
247
|
+
perServerRequestData,
|
|
219
248
|
indent,
|
|
220
249
|
prettyPrint
|
|
221
250
|
)}${writeSharedStateToJsGlobal(
|
|
@@ -362,21 +391,24 @@ ${consoleLines.join("\n")}
|
|
|
362
391
|
${groupEnd}</script>
|
|
363
392
|
`;
|
|
364
393
|
};
|
|
365
|
-
async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, entryPointBasePath, renderOptions) {
|
|
394
|
+
async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, entryPointBasePath, contextOptions, renderOptions) {
|
|
366
395
|
const componentDebugName = Component.displayName || Component.name;
|
|
367
396
|
return renderOnServer(
|
|
368
397
|
/* @__PURE__ */ jsx2(Component, { ...props }),
|
|
369
398
|
pageUrl,
|
|
370
399
|
environmentConfig,
|
|
371
400
|
entryPointBasePath,
|
|
401
|
+
contextOptions,
|
|
372
402
|
componentDebugName,
|
|
373
403
|
renderOptions
|
|
374
404
|
);
|
|
375
405
|
}
|
|
376
|
-
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, debugName, renderOptions) {
|
|
406
|
+
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, contextOptions, debugName, renderOptions) {
|
|
407
|
+
const supplementalFieldValues = contextOptions ? contextOptions.supplementalFieldValues : void 0;
|
|
377
408
|
const renderContext = cmsComponents.createServerRenderContextV2 ? cmsComponents.createServerRenderContextV2(pageUrl, {
|
|
378
409
|
environmentConfig,
|
|
379
|
-
entryPointBasePath
|
|
410
|
+
entryPointBasePath,
|
|
411
|
+
supplementalFieldValues
|
|
380
412
|
}) : cmsComponents.createServerRenderContext(pageUrl, environmentConfig);
|
|
381
413
|
let html = await renderStreamToPromise(
|
|
382
414
|
/* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
|
@@ -564,7 +596,8 @@ function namespaceModulePropsShape(props) {
|
|
|
564
596
|
fieldValues: passedFieldValues,
|
|
565
597
|
hublData,
|
|
566
598
|
experimentalHublData,
|
|
567
|
-
moduleName
|
|
599
|
+
moduleName,
|
|
600
|
+
supplementalFieldValues
|
|
568
601
|
} = props;
|
|
569
602
|
const oldPropsShape = { ...props };
|
|
570
603
|
if (oldPropsShape.dataQueryResult) {
|
|
@@ -581,7 +614,8 @@ function namespaceModulePropsShape(props) {
|
|
|
581
614
|
hublParameters,
|
|
582
615
|
hublData,
|
|
583
616
|
experimentalHublData,
|
|
584
|
-
moduleName
|
|
617
|
+
moduleName,
|
|
618
|
+
supplementalFieldValues
|
|
585
619
|
};
|
|
586
620
|
}
|
|
587
621
|
function setIn(object, nestedKeysArray, value) {
|
package/dist/run.js
CHANGED
|
@@ -77,13 +77,13 @@ function getDevServerCommandLineOptions(argv) {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
// src/createDevServer.ts
|
|
80
|
-
import
|
|
80
|
+
import path8 from "path";
|
|
81
81
|
import url2 from "url";
|
|
82
82
|
import express2 from "express";
|
|
83
83
|
import http3 from "http";
|
|
84
84
|
import bodyParser from "body-parser";
|
|
85
85
|
import { spawn } from "child_process";
|
|
86
|
-
import { normalizePath as
|
|
86
|
+
import { normalizePath as normalizePath6 } from "vite";
|
|
87
87
|
import { Transform } from "stream";
|
|
88
88
|
|
|
89
89
|
// src/routes/createDevServerRoutes.ts
|
|
@@ -127,6 +127,7 @@ function packagePath(metaUrl, projectPath) {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
// ../cms-js-internal/dist/index.js
|
|
130
|
+
import { hasProperty, setProperty, getProperty } from "dot-prop";
|
|
130
131
|
import path2 from "path";
|
|
131
132
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
132
133
|
import stream from "stream";
|
|
@@ -162,7 +163,7 @@ function jsonStringifyAndEscapeForInlineJS(input, { baseIndent = 0, jsonIndent =
|
|
|
162
163
|
${indentString}`
|
|
163
164
|
);
|
|
164
165
|
}
|
|
165
|
-
var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, prettyPrint) => {
|
|
166
|
+
var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
|
|
166
167
|
const islandsArrayToSerialize = tweakedIslandsArray.map(
|
|
167
168
|
({
|
|
168
169
|
id,
|
|
@@ -174,6 +175,7 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, p
|
|
|
174
175
|
priority,
|
|
175
176
|
url: url3,
|
|
176
177
|
sharedStateID,
|
|
178
|
+
supplementalFieldValues,
|
|
177
179
|
wrapperModuleId,
|
|
178
180
|
wrapperUrl
|
|
179
181
|
}) => {
|
|
@@ -196,6 +198,13 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, p
|
|
|
196
198
|
if (wrapperUrl) {
|
|
197
199
|
output.wrapperUrl = wrapperUrl;
|
|
198
200
|
}
|
|
201
|
+
const filteredSupplementalFieldValues = filterOutUnreadSupplementalFieldValues(
|
|
202
|
+
supplementalFieldValues,
|
|
203
|
+
perServerRequestData.get("supplementalFieldValuesRead")
|
|
204
|
+
);
|
|
205
|
+
if (filteredSupplementalFieldValues) {
|
|
206
|
+
output.supplementalFieldValues = filteredSupplementalFieldValues;
|
|
207
|
+
}
|
|
199
208
|
return output;
|
|
200
209
|
}
|
|
201
210
|
);
|
|
@@ -205,6 +214,25 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, p
|
|
|
205
214
|
prettyPrint
|
|
206
215
|
});
|
|
207
216
|
};
|
|
217
|
+
function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplementalFieldValuesRead) {
|
|
218
|
+
if (!supplementalFieldValues) {
|
|
219
|
+
return supplementalFieldValues;
|
|
220
|
+
}
|
|
221
|
+
if (!supplementalFieldValuesRead) {
|
|
222
|
+
return supplementalFieldValues;
|
|
223
|
+
}
|
|
224
|
+
const result = {};
|
|
225
|
+
Array.from(supplementalFieldValuesRead).forEach((fieldPath) => {
|
|
226
|
+
if (hasProperty(supplementalFieldValues, fieldPath)) {
|
|
227
|
+
setProperty(
|
|
228
|
+
result,
|
|
229
|
+
fieldPath,
|
|
230
|
+
getProperty(supplementalFieldValues, fieldPath)
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
return result;
|
|
235
|
+
}
|
|
208
236
|
var writeSharedStateToJsGlobal = (islands, perServerRequestData, indent = 0, prettyPrint) => {
|
|
209
237
|
const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x) => !!x);
|
|
210
238
|
if (sharedStateIDs.length > 0) {
|
|
@@ -282,6 +310,7 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
|
|
|
282
310
|
indent
|
|
283
311
|
)}window.__islands = ${serializeIslandDataForInlineScript(
|
|
284
312
|
islands,
|
|
313
|
+
perServerRequestData,
|
|
285
314
|
indent,
|
|
286
315
|
prettyPrint
|
|
287
316
|
)}${writeSharedStateToJsGlobal(
|
|
@@ -428,10 +457,12 @@ ${consoleLines.join("\n")}
|
|
|
428
457
|
${groupEnd}</script>
|
|
429
458
|
`;
|
|
430
459
|
};
|
|
431
|
-
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, debugName, renderOptions) {
|
|
460
|
+
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, contextOptions, debugName, renderOptions) {
|
|
461
|
+
const supplementalFieldValues = contextOptions ? contextOptions.supplementalFieldValues : void 0;
|
|
432
462
|
const renderContext = cmsComponents.createServerRenderContextV2 ? cmsComponents.createServerRenderContextV2(pageUrl, {
|
|
433
463
|
environmentConfig,
|
|
434
|
-
entryPointBasePath
|
|
464
|
+
entryPointBasePath,
|
|
465
|
+
supplementalFieldValues
|
|
435
466
|
}) : cmsComponents.createServerRenderContext(pageUrl, environmentConfig);
|
|
436
467
|
let html = await renderStreamToPromise(
|
|
437
468
|
/* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
|
@@ -584,7 +615,8 @@ function namespaceModulePropsShape(props) {
|
|
|
584
615
|
fieldValues: passedFieldValues,
|
|
585
616
|
hublData,
|
|
586
617
|
experimentalHublData,
|
|
587
|
-
moduleName
|
|
618
|
+
moduleName,
|
|
619
|
+
supplementalFieldValues
|
|
588
620
|
} = props;
|
|
589
621
|
const oldPropsShape = { ...props };
|
|
590
622
|
if (oldPropsShape.dataQueryResult) {
|
|
@@ -601,7 +633,8 @@ function namespaceModulePropsShape(props) {
|
|
|
601
633
|
hublParameters,
|
|
602
634
|
hublData,
|
|
603
635
|
experimentalHublData,
|
|
604
|
-
moduleName
|
|
636
|
+
moduleName,
|
|
637
|
+
supplementalFieldValues
|
|
605
638
|
};
|
|
606
639
|
}
|
|
607
640
|
function setIn(object, nestedKeysArray, value) {
|
|
@@ -1590,12 +1623,12 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
1590
1623
|
);
|
|
1591
1624
|
offsetSoFar = nearestNewlineOrQuoteAfterBlockOpen;
|
|
1592
1625
|
if (pathEndOffset >= 0 && pathEndOffset < nextNewlineOffset) {
|
|
1593
|
-
const
|
|
1626
|
+
const path9 = body.substring(
|
|
1594
1627
|
startOffset + localJsRenderStartString.length,
|
|
1595
1628
|
pathEndOffset
|
|
1596
1629
|
);
|
|
1597
1630
|
offsetSoFar = pathEndOffset + 1;
|
|
1598
|
-
if (startOffset >= 0 &&
|
|
1631
|
+
if (startOffset >= 0 && path9) {
|
|
1599
1632
|
const nextCommentEndOffset = body.indexOf("-->", pathEndOffset);
|
|
1600
1633
|
const endOffset = body.indexOf(localJsRenderEndString, pathEndOffset);
|
|
1601
1634
|
offsetSoFar = Math.min(nextCommentEndOffset, endOffset);
|
|
@@ -1615,7 +1648,7 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
1615
1648
|
result.push({
|
|
1616
1649
|
startOffset,
|
|
1617
1650
|
endOffset: endOffset + localJsRenderEndString.length,
|
|
1618
|
-
path:
|
|
1651
|
+
path: path9,
|
|
1619
1652
|
json
|
|
1620
1653
|
});
|
|
1621
1654
|
}
|
|
@@ -1724,9 +1757,9 @@ var customColors = [
|
|
|
1724
1757
|
];
|
|
1725
1758
|
var Converter = new AnsiToHtmlConverter({ colors: customColors });
|
|
1726
1759
|
var darkErrorStyles = `background-color: #222; color: #ccc; padding: 0.5em; font-family: ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', 'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace;`;
|
|
1727
|
-
var renderLocalError_default = (
|
|
1760
|
+
var renderLocalError_default = (path9, error) => {
|
|
1728
1761
|
const stackWithColorClasses = Converter.toHtml(error.stack);
|
|
1729
|
-
return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${
|
|
1762
|
+
return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${path9}<br/><br/><code><pre>${stackWithColorClasses}</pre></code></div>`;
|
|
1730
1763
|
};
|
|
1731
1764
|
|
|
1732
1765
|
// src/proxyPage/fetchPreviewInfo.ts
|
|
@@ -2334,7 +2367,7 @@ async function proxyPathPageRouteHandler(request2, response, next) {
|
|
|
2334
2367
|
}
|
|
2335
2368
|
|
|
2336
2369
|
// src/routes/proxyPathPageResourceRedirect.ts
|
|
2337
|
-
import
|
|
2370
|
+
import fetch2 from "node-fetch";
|
|
2338
2371
|
var HCMS_PATH2 = "/_hcms/";
|
|
2339
2372
|
var HS_FS_PATH2 = "/hs-fs/";
|
|
2340
2373
|
var HUB_FS_PATH2 = "/hubfs/";
|
|
@@ -2364,9 +2397,132 @@ function proxyPathPageResourceRedirect(req, res, next) {
|
|
|
2364
2397
|
return;
|
|
2365
2398
|
}
|
|
2366
2399
|
const urlToProxy = `https://${proxyPageUrl.host}${req.url}`;
|
|
2367
|
-
|
|
2400
|
+
fetch2(urlToProxy).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
|
|
2368
2401
|
}
|
|
2369
2402
|
|
|
2403
|
+
// src/routes/modulePreviewRouteHandler.ts
|
|
2404
|
+
import { buildStaticEnvConfig as buildStaticEnvConfig4 } from "@hubspot/cms-components";
|
|
2405
|
+
import path6 from "path";
|
|
2406
|
+
import { normalizePath as normalizePath5 } from "vite";
|
|
2407
|
+
import { getAccountId as getAccountId3 } from "@hubspot/cli-lib/lib/config.js";
|
|
2408
|
+
import { get as hsGet4 } from "@hubspot/cli-lib/http.js";
|
|
2409
|
+
async function modulePreviewRouteHandler(request2, response) {
|
|
2410
|
+
sendTrackingRequest("view-module-preview-route");
|
|
2411
|
+
const {
|
|
2412
|
+
authedPortalId,
|
|
2413
|
+
authedEnv,
|
|
2414
|
+
authedHublet,
|
|
2415
|
+
webRoot: webRoot2,
|
|
2416
|
+
viteServer,
|
|
2417
|
+
jsRenderingGates,
|
|
2418
|
+
projectName,
|
|
2419
|
+
projectComponentPath
|
|
2420
|
+
} = request2.app.locals;
|
|
2421
|
+
const moduleName = request2.params.moduleName;
|
|
2422
|
+
const modulePath = normalizePath5(
|
|
2423
|
+
path6.resolve(webRoot2, "components/modules/", moduleName)
|
|
2424
|
+
);
|
|
2425
|
+
const basePath = getEntryPointBasePath(modulePath);
|
|
2426
|
+
const environmentConfig = buildStaticEnvConfig4(
|
|
2427
|
+
authedPortalId,
|
|
2428
|
+
authedHublet,
|
|
2429
|
+
authedEnv,
|
|
2430
|
+
false,
|
|
2431
|
+
jsRenderingGates
|
|
2432
|
+
);
|
|
2433
|
+
const baseUrl = `https://api.hubspot${authedEnv === "qa" ? "qa" : ""}${authedHublet === "eu1" ? "-eu1" : ""}.com/api`;
|
|
2434
|
+
const accountId = await getAccountId3(authedPortalId);
|
|
2435
|
+
let templatePreview;
|
|
2436
|
+
try {
|
|
2437
|
+
const moduleFetchResult = await hsGet4(accountId, {
|
|
2438
|
+
baseUrl,
|
|
2439
|
+
uri: `/designmanager/v1/modules/by-path/@projects/${projectName}/${projectComponentPath}/components/modules/${moduleName}`,
|
|
2440
|
+
query: {
|
|
2441
|
+
portalId: authedPortalId
|
|
2442
|
+
},
|
|
2443
|
+
json: true,
|
|
2444
|
+
useQuerystring: true
|
|
2445
|
+
});
|
|
2446
|
+
const queryParams = new URLSearchParams({
|
|
2447
|
+
portalId: `${authedPortalId}`,
|
|
2448
|
+
module_id: `${moduleFetchResult.moduleId}`,
|
|
2449
|
+
hsLocalProxy: `${true}`,
|
|
2450
|
+
hs_preview_key: `${moduleFetchResult.previewKey}`,
|
|
2451
|
+
localProxySchemaVersion: "1"
|
|
2452
|
+
});
|
|
2453
|
+
const templatePreviewResponse = await fetch(
|
|
2454
|
+
`${baseUrl}/cos-rendering/v1/public/_hcms/preview/template/multiform?${queryParams}`,
|
|
2455
|
+
{
|
|
2456
|
+
method: "POST",
|
|
2457
|
+
headers: {
|
|
2458
|
+
["content-type"]: "application/x-www-form-urlencoded",
|
|
2459
|
+
["Accept"]: "text/html",
|
|
2460
|
+
referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com`
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
);
|
|
2464
|
+
templatePreview = await templatePreviewResponse.text();
|
|
2465
|
+
} catch (e) {
|
|
2466
|
+
return response.status(500).end(
|
|
2467
|
+
`Error previewing module (${moduleName}). Ensure this module has been included in a successful project build.
|
|
2468
|
+
|
|
2469
|
+
`
|
|
2470
|
+
);
|
|
2471
|
+
}
|
|
2472
|
+
try {
|
|
2473
|
+
const localRenderPlaceholders = findLocalRenderPlaceholders(templatePreview);
|
|
2474
|
+
if (localRenderPlaceholders.length !== 1) {
|
|
2475
|
+
return response.status(500).end(
|
|
2476
|
+
`Error previewing module (${moduleName}), exception in module preview HTML
|
|
2477
|
+
|
|
2478
|
+
`
|
|
2479
|
+
);
|
|
2480
|
+
}
|
|
2481
|
+
const {
|
|
2482
|
+
html: renderedHtml,
|
|
2483
|
+
cssNeeded,
|
|
2484
|
+
renderContext,
|
|
2485
|
+
inlineAssets
|
|
2486
|
+
} = await renderComponentForPlaceholder(
|
|
2487
|
+
0,
|
|
2488
|
+
localRenderPlaceholders[0],
|
|
2489
|
+
webRoot2,
|
|
2490
|
+
viteServer,
|
|
2491
|
+
fullOriginalUrlFromRequest(request2),
|
|
2492
|
+
basePath,
|
|
2493
|
+
environmentConfig,
|
|
2494
|
+
projectName,
|
|
2495
|
+
projectComponentPath
|
|
2496
|
+
);
|
|
2497
|
+
const baseTemplatePath = packagePath(
|
|
2498
|
+
import.meta.url,
|
|
2499
|
+
"html/baseTemplate.html"
|
|
2500
|
+
);
|
|
2501
|
+
const htmlShell = await createHtmlShellDependingOnRenderContext(
|
|
2502
|
+
baseTemplatePath,
|
|
2503
|
+
request2.originalUrl,
|
|
2504
|
+
`Module: ${modulePath}`,
|
|
2505
|
+
renderContext,
|
|
2506
|
+
viteServer,
|
|
2507
|
+
jsRenderingGates
|
|
2508
|
+
);
|
|
2509
|
+
const html = htmlShell.replace(
|
|
2510
|
+
"<!--headend-->",
|
|
2511
|
+
[cssNeeded, ...inlineAssets.map((inlineAsset) => inlineAsset.html)].join(
|
|
2512
|
+
"\n"
|
|
2513
|
+
)
|
|
2514
|
+
).replace(`<!--ssr-outlet-->`, renderedHtml);
|
|
2515
|
+
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
2516
|
+
} catch (e) {
|
|
2517
|
+
console.error(e);
|
|
2518
|
+
viteServer.ssrFixStacktrace(e);
|
|
2519
|
+
return response.status(500).end(`Error rendering module (${moduleName})
|
|
2520
|
+
|
|
2521
|
+
${e.stack}`);
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
var modulePreviewRouteHandler_default = modulePreviewRouteHandler;
|
|
2525
|
+
|
|
2370
2526
|
// src/routes/createDevServerRoutes.ts
|
|
2371
2527
|
var STORYBOOK_DOMAINS = VALID_PROXY_DOMAIN_SUFFIXES.map(
|
|
2372
2528
|
(domain) => `storybook.${domain}`
|
|
@@ -2394,6 +2550,7 @@ var createDevServerRoutes = async (viteServer, storybookPort) => {
|
|
|
2394
2550
|
devServerApp.get("/partials/", linksToAllPartialsRouteHandler_default);
|
|
2395
2551
|
devServerApp.get("/partial/:partial", partial_default);
|
|
2396
2552
|
devServerApp.get("/partial/:partial/*", partial_default);
|
|
2553
|
+
devServerApp.get("/preview/module/:moduleName", modulePreviewRouteHandler_default);
|
|
2397
2554
|
devServerApp.get("/modules/", linksToAllModulesRouteHandler_default);
|
|
2398
2555
|
devServerApp.get("/module/:moduleName", module_default);
|
|
2399
2556
|
devServerApp.get("/module/:moduleName/*", module_default);
|
|
@@ -2416,9 +2573,9 @@ import express from "express";
|
|
|
2416
2573
|
|
|
2417
2574
|
// src/shadowDevServer/createShadowDevServerRoutes.ts
|
|
2418
2575
|
import { Router as Router2 } from "express";
|
|
2419
|
-
import { getAccountId as
|
|
2576
|
+
import { getAccountId as getAccountId4, getEnv as getEnv2 } from "@hubspot/cli-lib/lib/config.js";
|
|
2420
2577
|
import cors from "cors";
|
|
2421
|
-
import { buildStaticEnvConfig as
|
|
2578
|
+
import { buildStaticEnvConfig as buildStaticEnvConfig5 } from "@hubspot/cms-components";
|
|
2422
2579
|
function getShadowDevServerCheckHandler(devServerPort, projectName, gates) {
|
|
2423
2580
|
return async function shadowDevServerCheckHandler(request2, response) {
|
|
2424
2581
|
const { query } = request2;
|
|
@@ -2437,7 +2594,7 @@ function getShadowDevServerCheckHandler(devServerPort, projectName, gates) {
|
|
|
2437
2594
|
let hasJSBuildingBlocks = false;
|
|
2438
2595
|
let localProxyUrl;
|
|
2439
2596
|
try {
|
|
2440
|
-
accountId =
|
|
2597
|
+
accountId = getAccountId4(portalId);
|
|
2441
2598
|
if (accountId === null) {
|
|
2442
2599
|
throw new Error();
|
|
2443
2600
|
}
|
|
@@ -2455,7 +2612,7 @@ function getShadowDevServerCheckHandler(devServerPort, projectName, gates) {
|
|
|
2455
2612
|
contentId
|
|
2456
2613
|
);
|
|
2457
2614
|
const { previewKey } = previewInfo;
|
|
2458
|
-
const environmentConfig =
|
|
2615
|
+
const environmentConfig = buildStaticEnvConfig5(
|
|
2459
2616
|
portalId,
|
|
2460
2617
|
"na1",
|
|
2461
2618
|
// bad lazy TF (but does it really matter for this check)
|
|
@@ -2703,7 +2860,7 @@ async function getJsRenderingGates(portalId, env, personalAccessKey) {
|
|
|
2703
2860
|
// src/createDevServer.ts
|
|
2704
2861
|
import {
|
|
2705
2862
|
getEnv as getEnv3,
|
|
2706
|
-
getAccountId as
|
|
2863
|
+
getAccountId as getAccountId5,
|
|
2707
2864
|
getAccountConfig as getAccountConfig2,
|
|
2708
2865
|
loadConfig,
|
|
2709
2866
|
validateConfig
|
|
@@ -2711,7 +2868,7 @@ import {
|
|
|
2711
2868
|
import { fetchSecrets } from "@hubspot/cli-lib/api/secrets.js";
|
|
2712
2869
|
|
|
2713
2870
|
// src/proxyPage/fetchDomains.ts
|
|
2714
|
-
import { get as
|
|
2871
|
+
import { get as hsGet5 } from "@hubspot/cli-lib/http.js";
|
|
2715
2872
|
|
|
2716
2873
|
// src/lib/errors.ts
|
|
2717
2874
|
var MISSING_SCOPE_ERROR_PREFIX = `Your personal access key is missing required scopes fetch domains.
|
|
@@ -2740,7 +2897,7 @@ function isMissingScopeError(error) {
|
|
|
2740
2897
|
// src/proxyPage/fetchDomains.ts
|
|
2741
2898
|
async function fetchDomains(portalId) {
|
|
2742
2899
|
try {
|
|
2743
|
-
const result = await
|
|
2900
|
+
const result = await hsGet5(portalId, {
|
|
2744
2901
|
uri: `/cms/v3/domains`,
|
|
2745
2902
|
query: { portalId },
|
|
2746
2903
|
json: true
|
|
@@ -2764,9 +2921,9 @@ async function fetchWebsiteDomainNames(portalId) {
|
|
|
2764
2921
|
|
|
2765
2922
|
// src/lib/getCMSAssetConfig.ts
|
|
2766
2923
|
import fs2 from "fs";
|
|
2767
|
-
import
|
|
2924
|
+
import path7 from "path";
|
|
2768
2925
|
function getCMSAssetConfig(webRoot2) {
|
|
2769
|
-
const cmsAssetsPath =
|
|
2926
|
+
const cmsAssetsPath = path7.join(webRoot2, "cms-assets.json");
|
|
2770
2927
|
return JSON.parse(fs2.readFileSync(cmsAssetsPath).toString());
|
|
2771
2928
|
}
|
|
2772
2929
|
|
|
@@ -2805,7 +2962,7 @@ async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2
|
|
|
2805
2962
|
process.exit(1);
|
|
2806
2963
|
}
|
|
2807
2964
|
if (validateConfig()) {
|
|
2808
|
-
authedPortalId =
|
|
2965
|
+
authedPortalId = getAccountId5(hubspotCliAccountNameOption2);
|
|
2809
2966
|
authedEnv = getEnv3(hubspotCliAccountNameOption2);
|
|
2810
2967
|
personalAccessKey = getAccountConfig2(authedPortalId) && getAccountConfig2(authedPortalId).personalAccessKey;
|
|
2811
2968
|
if (!authedPortalId && hubspotCliAccountNameOption2) {
|
|
@@ -2874,7 +3031,7 @@ Local proxy functionality will not work without setting up authentication.`
|
|
|
2874
3031
|
}
|
|
2875
3032
|
}
|
|
2876
3033
|
const authedHublet = "na1";
|
|
2877
|
-
const absoluteWebRoot =
|
|
3034
|
+
const absoluteWebRoot = normalizePath6(path8.resolve(process.cwd(), webRoot2));
|
|
2878
3035
|
const [__webRootProjectFolder, webRootProjectComponentFolder] = absoluteWebRoot.replace(/\/$/, "").split("/").slice(-2);
|
|
2879
3036
|
const viteServer = await createViteDevServer_default(
|
|
2880
3037
|
absoluteWebRoot,
|
|
@@ -2888,7 +3045,7 @@ Local proxy functionality will not work without setting up authentication.`
|
|
|
2888
3045
|
const httpsKey = viteHTTPSConfig ? viteHTTPSConfig.key : null;
|
|
2889
3046
|
const httpsCert = viteHTTPSConfig ? viteHTTPSConfig.cert : null;
|
|
2890
3047
|
const projectName = getProjectNameFromHSConfig(
|
|
2891
|
-
|
|
3048
|
+
path8.join(webRoot2, "../hsproject.json")
|
|
2892
3049
|
);
|
|
2893
3050
|
const httpServers = [];
|
|
2894
3051
|
const expressServer = express2();
|
|
@@ -2945,8 +3102,8 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
|
|
|
2945
3102
|
`
|
|
2946
3103
|
);
|
|
2947
3104
|
if (storybook2) {
|
|
2948
|
-
const packageRoot =
|
|
2949
|
-
const configPath =
|
|
3105
|
+
const packageRoot = path8.dirname(url2.fileURLToPath(import.meta.url));
|
|
3106
|
+
const configPath = path8.resolve(packageRoot, "./storybook-main");
|
|
2950
3107
|
sendTrackingRequest("start-storybook");
|
|
2951
3108
|
const storybookProcess = spawn(
|
|
2952
3109
|
"sb",
|
|
@@ -2966,7 +3123,7 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
|
|
|
2966
3123
|
portalId: authedPortalId.toString(),
|
|
2967
3124
|
hsEnv: authedEnv,
|
|
2968
3125
|
hublet: authedHublet,
|
|
2969
|
-
WEB_ROOT:
|
|
3126
|
+
WEB_ROOT: path8.join(webRoot2, "components")
|
|
2970
3127
|
}
|
|
2971
3128
|
}
|
|
2972
3129
|
);
|
package/dist/storybook/index.js
CHANGED
|
@@ -11,7 +11,8 @@ function namespaceModulePropsShape(props) {
|
|
|
11
11
|
fieldValues: passedFieldValues,
|
|
12
12
|
hublData,
|
|
13
13
|
experimentalHublData,
|
|
14
|
-
moduleName
|
|
14
|
+
moduleName,
|
|
15
|
+
supplementalFieldValues
|
|
15
16
|
} = props;
|
|
16
17
|
const oldPropsShape = { ...props };
|
|
17
18
|
if (oldPropsShape.dataQueryResult) {
|
|
@@ -28,7 +29,8 @@ function namespaceModulePropsShape(props) {
|
|
|
28
29
|
hublParameters,
|
|
29
30
|
hublData,
|
|
30
31
|
experimentalHublData,
|
|
31
|
-
moduleName
|
|
32
|
+
moduleName,
|
|
33
|
+
supplementalFieldValues
|
|
32
34
|
};
|
|
33
35
|
}
|
|
34
36
|
function renderFieldsJSX(fieldsJSX) {
|
|
@@ -53,6 +53,7 @@ __export(dist_exports, {
|
|
|
53
53
|
ungatedAtBuildTimeFor: () => ungatedAtBuildTimeFor,
|
|
54
54
|
virtualClientRenderIslandModuleId: () => virtualClientRenderIslandModuleId
|
|
55
55
|
});
|
|
56
|
+
import { hasProperty, setProperty, getProperty } from "dot-prop";
|
|
56
57
|
import path from "path";
|
|
57
58
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
58
59
|
import stream from "stream";
|
|
@@ -100,6 +101,25 @@ function jsonStringifyAndEscapeForInlineJS(input, { baseIndent = 0, jsonIndent =
|
|
|
100
101
|
${indentString}`
|
|
101
102
|
);
|
|
102
103
|
}
|
|
104
|
+
function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplementalFieldValuesRead) {
|
|
105
|
+
if (!supplementalFieldValues) {
|
|
106
|
+
return supplementalFieldValues;
|
|
107
|
+
}
|
|
108
|
+
if (!supplementalFieldValuesRead) {
|
|
109
|
+
return supplementalFieldValues;
|
|
110
|
+
}
|
|
111
|
+
const result = {};
|
|
112
|
+
Array.from(supplementalFieldValuesRead).forEach((fieldPath) => {
|
|
113
|
+
if (hasProperty(supplementalFieldValues, fieldPath)) {
|
|
114
|
+
setProperty(
|
|
115
|
+
result,
|
|
116
|
+
fieldPath,
|
|
117
|
+
getProperty(supplementalFieldValues, fieldPath)
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
103
123
|
function getIslandUrls(roots, viteDevServer) {
|
|
104
124
|
return roots.map((island) => {
|
|
105
125
|
const islandModule = viteDevServer.moduleGraph.getModuleById(
|
|
@@ -210,21 +230,24 @@ function clientIslandEntryPlugin() {
|
|
|
210
230
|
}
|
|
211
231
|
};
|
|
212
232
|
}
|
|
213
|
-
async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, entryPointBasePath, renderOptions) {
|
|
233
|
+
async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, entryPointBasePath, contextOptions, renderOptions) {
|
|
214
234
|
const componentDebugName = Component.displayName || Component.name;
|
|
215
235
|
return renderOnServer(
|
|
216
236
|
/* @__PURE__ */ jsx2(Component, { ...props }),
|
|
217
237
|
pageUrl,
|
|
218
238
|
environmentConfig,
|
|
219
239
|
entryPointBasePath,
|
|
240
|
+
contextOptions,
|
|
220
241
|
componentDebugName,
|
|
221
242
|
renderOptions
|
|
222
243
|
);
|
|
223
244
|
}
|
|
224
|
-
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, debugName, renderOptions) {
|
|
245
|
+
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, contextOptions, debugName, renderOptions) {
|
|
246
|
+
const supplementalFieldValues = contextOptions ? contextOptions.supplementalFieldValues : void 0;
|
|
225
247
|
const renderContext = cmsComponents.createServerRenderContextV2 ? cmsComponents.createServerRenderContextV2(pageUrl, {
|
|
226
248
|
environmentConfig,
|
|
227
|
-
entryPointBasePath
|
|
249
|
+
entryPointBasePath,
|
|
250
|
+
supplementalFieldValues
|
|
228
251
|
}) : cmsComponents.createServerRenderContext(pageUrl, environmentConfig);
|
|
229
252
|
let html = await renderStreamToPromise(
|
|
230
253
|
/* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
|
@@ -344,7 +367,8 @@ function namespaceModulePropsShape(props) {
|
|
|
344
367
|
fieldValues: passedFieldValues,
|
|
345
368
|
hublData,
|
|
346
369
|
experimentalHublData,
|
|
347
|
-
moduleName
|
|
370
|
+
moduleName,
|
|
371
|
+
supplementalFieldValues
|
|
348
372
|
} = props;
|
|
349
373
|
const oldPropsShape = { ...props };
|
|
350
374
|
if (oldPropsShape.dataQueryResult) {
|
|
@@ -361,7 +385,8 @@ function namespaceModulePropsShape(props) {
|
|
|
361
385
|
hublParameters,
|
|
362
386
|
hublData,
|
|
363
387
|
experimentalHublData,
|
|
364
|
-
moduleName
|
|
388
|
+
moduleName,
|
|
389
|
+
supplementalFieldValues
|
|
365
390
|
};
|
|
366
391
|
}
|
|
367
392
|
function setIn(object, nestedKeysArray, value) {
|
|
@@ -473,7 +498,7 @@ var init_dist = __esm({
|
|
|
473
498
|
">": "\\u003E",
|
|
474
499
|
"/": "\\u002F"
|
|
475
500
|
};
|
|
476
|
-
serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, prettyPrint) => {
|
|
501
|
+
serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
|
|
477
502
|
const islandsArrayToSerialize = tweakedIslandsArray.map(
|
|
478
503
|
({
|
|
479
504
|
id,
|
|
@@ -485,6 +510,7 @@ var init_dist = __esm({
|
|
|
485
510
|
priority,
|
|
486
511
|
url,
|
|
487
512
|
sharedStateID,
|
|
513
|
+
supplementalFieldValues,
|
|
488
514
|
wrapperModuleId,
|
|
489
515
|
wrapperUrl
|
|
490
516
|
}) => {
|
|
@@ -507,6 +533,13 @@ var init_dist = __esm({
|
|
|
507
533
|
if (wrapperUrl) {
|
|
508
534
|
output.wrapperUrl = wrapperUrl;
|
|
509
535
|
}
|
|
536
|
+
const filteredSupplementalFieldValues = filterOutUnreadSupplementalFieldValues(
|
|
537
|
+
supplementalFieldValues,
|
|
538
|
+
perServerRequestData.get("supplementalFieldValuesRead")
|
|
539
|
+
);
|
|
540
|
+
if (filteredSupplementalFieldValues) {
|
|
541
|
+
output.supplementalFieldValues = filteredSupplementalFieldValues;
|
|
542
|
+
}
|
|
510
543
|
return output;
|
|
511
544
|
}
|
|
512
545
|
);
|
|
@@ -550,6 +583,7 @@ ${indentString}`);
|
|
|
550
583
|
indent
|
|
551
584
|
)}window.__islands = ${serializeIslandDataForInlineScript(
|
|
552
585
|
islands,
|
|
586
|
+
perServerRequestData,
|
|
553
587
|
indent,
|
|
554
588
|
prettyPrint
|
|
555
589
|
)}${writeSharedStateToJsGlobal(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"copy-html": "copyfiles -u 1 'src/html/**' 'dist'",
|
|
13
13
|
"build-types": "tsc --project tsconfig.types.json",
|
|
14
14
|
"clean": "tsc --build --clean",
|
|
15
|
-
"dev": "nodemon --exec 'yarn start'",
|
|
15
|
+
"dev": "nodemon --no-stdin --exec 'yarn start'",
|
|
16
16
|
"dev-inspect": "nodemon --exec 'yarn start-inspect'",
|
|
17
17
|
"es-watch": "esbuild --outfile=dist-esbuild/runWhenDeveloping.cjs --bundle --watch --platform=node --external:fsevents --external:vite --external:react-refresh runWhenDeveloping.ts",
|
|
18
18
|
"package": "npm run build && npm pack",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@hubspot/cli-lib": "^3.0.12",
|
|
29
|
-
"@hubspot/cms-components": "^0.14.
|
|
29
|
+
"@hubspot/cms-components": "^0.14.3",
|
|
30
|
+
"@inquirer/select": "^2.0.0",
|
|
30
31
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
31
32
|
"@storybook/addon-actions": "7.0.7",
|
|
32
33
|
"@storybook/addon-essentials": "7.0.7",
|
|
@@ -106,5 +107,5 @@
|
|
|
106
107
|
"publishConfig": {
|
|
107
108
|
"access": "public"
|
|
108
109
|
},
|
|
109
|
-
"gitHead": "
|
|
110
|
+
"gitHead": "0c0426830420f96794f6b5899b645d901fa6bdd4"
|
|
110
111
|
}
|