@hubspot/cms-dev-server 1.2.80 → 1.2.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generateJsonFromJsx.js +1 -1
- package/dist/index.js +2060 -1869
- package/dist/internalSsr.js +3 -5
- package/dist/island-runtime.js +22 -6
- package/dist/run.js +987 -796
- package/dist/storybook/index.js +1 -1
- package/dist/storybook-main/main.js +7 -9
- package/dist/validateFieldsCli.js +1 -1
- package/package.json +2 -2
- package/types/lib/renderModulePreview.d.ts +2 -3
- package/types/routes/moduleValidateFields.d.ts +3 -0
- package/types/validateFields.d.ts +16 -0
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createServer as createViteServer } from "vite";
|
|
|
3
3
|
import { createRequire } from "module";
|
|
4
4
|
import { default as react } from "@vitejs/plugin-react";
|
|
5
5
|
|
|
6
|
-
// ../cms-js-internal/dist/types-
|
|
6
|
+
// ../cms-js-internal/dist/types-C8bPIEz4.js
|
|
7
7
|
import path from "path";
|
|
8
8
|
import { createHash } from "crypto";
|
|
9
9
|
import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
@@ -262,12 +262,8 @@ function isLocalUiDisabled(config) {
|
|
|
262
262
|
return false;
|
|
263
263
|
}
|
|
264
264
|
var ENABLED_FEATURES_GATE_MAP = {
|
|
265
|
-
"cms:jsr:analyzeCmsModules": "CMS:JSRenderer:AnalyzeCmsModules"
|
|
266
|
-
"PortalsAccessIdentity:DesignManager:UrlSigning": "PortalsAccessIdentity:DesignManager:UrlSigning"
|
|
265
|
+
"cms:jsr:analyzeCmsModules": "CMS:JSRenderer:AnalyzeCmsModules"
|
|
267
266
|
};
|
|
268
|
-
function isUngatedFor(gates, gate) {
|
|
269
|
-
return gates.includes(gate);
|
|
270
|
-
}
|
|
271
267
|
var findAllComponentsIn = (webRoot, componentsFolder) => {
|
|
272
268
|
const fullComponentsFolderPath = join(webRoot, componentsFolder);
|
|
273
269
|
const componentsByName = {};
|
|
@@ -686,8 +682,8 @@ function convertEntryPointIslandPathsToRelative(config, entryPointsCmsModuleMap)
|
|
|
686
682
|
);
|
|
687
683
|
return Object.fromEntries(relativeEntries);
|
|
688
684
|
}
|
|
689
|
-
function toRelativePath(config,
|
|
690
|
-
return
|
|
685
|
+
function toRelativePath(config, path20) {
|
|
686
|
+
return path20.replace(`${config.root}/`, "");
|
|
691
687
|
}
|
|
692
688
|
function shouldAnalyzeModule(config, moduleInfo, code) {
|
|
693
689
|
const [fileId, __] = moduleInfo.id.split("?");
|
|
@@ -730,11 +726,11 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
|
|
|
730
726
|
let moduleComponentLocalImportName = CMS_MODULE_COMPONENT_NAME;
|
|
731
727
|
let dndAreaComponentLocalImportName = DND_AREA_COMPONENT_NAME;
|
|
732
728
|
traverse(sourceAst, {
|
|
733
|
-
ImportDeclaration(
|
|
734
|
-
if (t.isStringLiteral(
|
|
729
|
+
ImportDeclaration(path20) {
|
|
730
|
+
if (t.isStringLiteral(path20.node.source, {
|
|
735
731
|
value: "@hubspot/cms-components"
|
|
736
732
|
})) {
|
|
737
|
-
for (const specifier of
|
|
733
|
+
for (const specifier of path20.node.specifiers) {
|
|
738
734
|
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
|
|
739
735
|
name: CMS_MODULE_COMPONENT_NAME
|
|
740
736
|
})) {
|
|
@@ -748,14 +744,14 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
|
|
|
748
744
|
}
|
|
749
745
|
}
|
|
750
746
|
},
|
|
751
|
-
JSXOpeningElement(
|
|
752
|
-
if (t.isJSXIdentifier(
|
|
747
|
+
JSXOpeningElement(path20) {
|
|
748
|
+
if (t.isJSXIdentifier(path20.node.name, {
|
|
753
749
|
name: moduleComponentLocalImportName
|
|
754
750
|
})) {
|
|
755
751
|
let cmsModuleName;
|
|
756
752
|
let cmsModulePath;
|
|
757
753
|
let cmsModuleLabel;
|
|
758
|
-
for (const prop of
|
|
754
|
+
for (const prop of path20.node.attributes) {
|
|
759
755
|
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
760
756
|
cmsModuleName = prop.value.value;
|
|
761
757
|
continue;
|
|
@@ -790,11 +786,11 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
|
|
|
790
786
|
}
|
|
791
787
|
contentDescriptors.modules[cmsModuleProps.name] = cmsModuleProps;
|
|
792
788
|
}
|
|
793
|
-
if (t.isJSXIdentifier(
|
|
789
|
+
if (t.isJSXIdentifier(path20.node.name, {
|
|
794
790
|
name: dndAreaComponentLocalImportName
|
|
795
791
|
})) {
|
|
796
792
|
let dndAreaName;
|
|
797
|
-
for (const prop of
|
|
793
|
+
for (const prop of path20.node.attributes) {
|
|
798
794
|
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
799
795
|
dndAreaName = prop.value.value;
|
|
800
796
|
continue;
|
|
@@ -1241,8 +1237,8 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
1241
1237
|
var createViteDevServer_default = createViteDevServer;
|
|
1242
1238
|
|
|
1243
1239
|
// src/createDevServer.ts
|
|
1244
|
-
import
|
|
1245
|
-
import
|
|
1240
|
+
import path19 from "path";
|
|
1241
|
+
import fs11 from "fs";
|
|
1246
1242
|
import url2 from "url";
|
|
1247
1243
|
import express2 from "express";
|
|
1248
1244
|
import http3 from "http";
|
|
@@ -1663,7 +1659,7 @@ function trackUsage(action) {
|
|
|
1663
1659
|
eventName: EVENT_NAME,
|
|
1664
1660
|
action,
|
|
1665
1661
|
nodeVersion: getNodeVersionData(),
|
|
1666
|
-
version: "1.2.
|
|
1662
|
+
version: "1.2.82",
|
|
1667
1663
|
os: getPlatform()
|
|
1668
1664
|
};
|
|
1669
1665
|
const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -1737,12 +1733,12 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
1737
1733
|
);
|
|
1738
1734
|
offsetSoFar = nearestNewlineOrQuoteAfterBlockOpen;
|
|
1739
1735
|
if (pathEndOffset >= 0 && pathEndOffset < nextNewlineOffset) {
|
|
1740
|
-
const
|
|
1736
|
+
const path20 = body.substring(
|
|
1741
1737
|
startOffset + localJsRenderStartString.length,
|
|
1742
1738
|
pathEndOffset
|
|
1743
1739
|
);
|
|
1744
1740
|
offsetSoFar = pathEndOffset + 1;
|
|
1745
|
-
if (startOffset >= 0 &&
|
|
1741
|
+
if (startOffset >= 0 && path20) {
|
|
1746
1742
|
const nextCommentEndOffset = body.indexOf("-->", pathEndOffset);
|
|
1747
1743
|
const endOffset = body.indexOf(localJsRenderEndString, pathEndOffset);
|
|
1748
1744
|
offsetSoFar = Math.min(nextCommentEndOffset, endOffset);
|
|
@@ -1767,7 +1763,7 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
1767
1763
|
result.push({
|
|
1768
1764
|
startOffset,
|
|
1769
1765
|
endOffset: endOffset + localJsRenderEndString.length,
|
|
1770
|
-
path:
|
|
1766
|
+
path: path20,
|
|
1771
1767
|
json
|
|
1772
1768
|
});
|
|
1773
1769
|
}
|
|
@@ -2166,9 +2162,9 @@ var customColors = [
|
|
|
2166
2162
|
];
|
|
2167
2163
|
var Converter = new AnsiToHtmlConverter({ colors: customColors });
|
|
2168
2164
|
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;`;
|
|
2169
|
-
var renderLocalError_default = (
|
|
2165
|
+
var renderLocalError_default = (path20, error) => {
|
|
2170
2166
|
const stackWithColorClasses = Converter.toHtml(error.stack);
|
|
2171
|
-
return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${
|
|
2167
|
+
return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${path20}<br/><br/><code><pre>${stackWithColorClasses}</pre></code></div>`;
|
|
2172
2168
|
};
|
|
2173
2169
|
|
|
2174
2170
|
// src/proxyPage/fetchPreviewInfo.ts
|
|
@@ -3191,7 +3187,6 @@ function getWebDefaultStylesCss(metaUrl) {
|
|
|
3191
3187
|
}
|
|
3192
3188
|
return _webDefaultStylesCss;
|
|
3193
3189
|
}
|
|
3194
|
-
var URL_SIGNING_GATE = "PortalsAccessIdentity:DesignManager:UrlSigning";
|
|
3195
3190
|
async function signGetUrl(authedPortalId, unsignedUrl) {
|
|
3196
3191
|
const urlWithPortalId = new URL(unsignedUrl);
|
|
3197
3192
|
urlWithPortalId.searchParams.set("portalId", `${authedPortalId}`);
|
|
@@ -3208,14 +3203,7 @@ async function signGetUrl(authedPortalId, unsignedUrl) {
|
|
|
3208
3203
|
});
|
|
3209
3204
|
return response.data.signedUrl;
|
|
3210
3205
|
}
|
|
3211
|
-
async function signedGet(authedPortalId, unsignedUrl, headers
|
|
3212
|
-
if (!isUngatedFor(gates, URL_SIGNING_GATE)) {
|
|
3213
|
-
const { data } = await hsCliHttp7.get(authedPortalId, {
|
|
3214
|
-
url: unsignedUrl,
|
|
3215
|
-
headers
|
|
3216
|
-
});
|
|
3217
|
-
return data;
|
|
3218
|
-
}
|
|
3206
|
+
async function signedGet(authedPortalId, unsignedUrl, headers) {
|
|
3219
3207
|
const signedUrl = await signGetUrl(authedPortalId, unsignedUrl);
|
|
3220
3208
|
const accountConfig = getConfigAccountIfExists4(authedPortalId);
|
|
3221
3209
|
const authHeaders = {};
|
|
@@ -3242,7 +3230,7 @@ async function signedGet(authedPortalId, unsignedUrl, headers, gates) {
|
|
|
3242
3230
|
}
|
|
3243
3231
|
return await response.text();
|
|
3244
3232
|
}
|
|
3245
|
-
async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv, cookieValue
|
|
3233
|
+
async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv, cookieValue) {
|
|
3246
3234
|
const moduleInfoQueryParams = new URLSearchParams({
|
|
3247
3235
|
portalId: `${authedPortalId}`
|
|
3248
3236
|
});
|
|
@@ -3266,34 +3254,13 @@ async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv,
|
|
|
3266
3254
|
buffer_theme: `${true}`
|
|
3267
3255
|
});
|
|
3268
3256
|
const cosRenderingUrl = `https://api.hubspot${authedEnv === "qa" ? "qa" : ""}.com/api/cos-rendering/v1/public/_hcms/preview/template/multi?${queryParams}`;
|
|
3269
|
-
const
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
modulePreviewHtml = await signedGet(
|
|
3277
|
-
authedPortalId,
|
|
3278
|
-
cosRenderingUrl,
|
|
3279
|
-
{
|
|
3280
|
-
["content-type"]: "application/x-www-form-urlencoded",
|
|
3281
|
-
["Accept"]: "text/html",
|
|
3282
|
-
referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
|
|
3283
|
-
cookie: cookieValue,
|
|
3284
|
-
"User-Agent": "HubSpot CMS Dev Server"
|
|
3285
|
-
},
|
|
3286
|
-
gates
|
|
3287
|
-
);
|
|
3288
|
-
} finally {
|
|
3289
|
-
if (needsDomainOverride) {
|
|
3290
|
-
if (previousHubApiDomainOverride) {
|
|
3291
|
-
process.env.HUBAPI_DOMAIN_OVERRIDE = previousHubApiDomainOverride;
|
|
3292
|
-
} else {
|
|
3293
|
-
delete process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
3294
|
-
}
|
|
3295
|
-
}
|
|
3296
|
-
}
|
|
3257
|
+
const modulePreviewHtml = await signedGet(authedPortalId, cosRenderingUrl, {
|
|
3258
|
+
["content-type"]: "application/x-www-form-urlencoded",
|
|
3259
|
+
["Accept"]: "text/html",
|
|
3260
|
+
referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
|
|
3261
|
+
cookie: cookieValue,
|
|
3262
|
+
"User-Agent": "HubSpot CMS Dev Server"
|
|
3263
|
+
});
|
|
3297
3264
|
const previewDoc = parseHtml(modulePreviewHtml);
|
|
3298
3265
|
const modulePreviewContent = extractModuleOuterHtml(previewDoc);
|
|
3299
3266
|
const allStyleContent = extractStyleText(previewDoc);
|
|
@@ -3534,8 +3501,7 @@ var partialRouteHandler = async (request, response) => {
|
|
|
3534
3501
|
remoteModule.path,
|
|
3535
3502
|
authedPortalId,
|
|
3536
3503
|
authedEnv,
|
|
3537
|
-
request.get("COOKIE")
|
|
3538
|
-
jsRenderingGates
|
|
3504
|
+
request.get("COOKIE")
|
|
3539
3505
|
).then((result) => ({
|
|
3540
3506
|
remoteModule,
|
|
3541
3507
|
result
|
|
@@ -3859,294 +3825,685 @@ var moduleFieldsJsonRouteHandler = async (request, response) => {
|
|
|
3859
3825
|
};
|
|
3860
3826
|
var moduleFieldsJson_default = moduleFieldsJsonRouteHandler;
|
|
3861
3827
|
|
|
3862
|
-
// src/
|
|
3863
|
-
import
|
|
3864
|
-
import
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3828
|
+
// src/routes/moduleValidateFields.ts
|
|
3829
|
+
import path12 from "path";
|
|
3830
|
+
import fs6 from "fs/promises";
|
|
3831
|
+
|
|
3832
|
+
// src/validateFields.ts
|
|
3833
|
+
import path11 from "path";
|
|
3834
|
+
import fs5 from "fs/promises";
|
|
3835
|
+
|
|
3836
|
+
// ../cms-js-internal/dist/buildFieldsTypes.js
|
|
3837
|
+
import { writeFileSync } from "fs";
|
|
3838
|
+
import ts from "typescript";
|
|
3839
|
+
var fieldTypeNameByType = {
|
|
3840
|
+
alignment: "AlignmentFieldType",
|
|
3841
|
+
audioplayer: "AudioFieldType",
|
|
3842
|
+
backgroundimage: "BackgroundImageFieldType",
|
|
3843
|
+
blog: "BlogFieldType",
|
|
3844
|
+
boolean: "BooleanFieldType",
|
|
3845
|
+
border: "BorderFieldType",
|
|
3846
|
+
choice: "ChoiceFieldType",
|
|
3847
|
+
color: "ColorFieldType",
|
|
3848
|
+
crmobject: "CrmObjectFieldType",
|
|
3849
|
+
cta: "CtaFieldType",
|
|
3850
|
+
date: "DateFieldType",
|
|
3851
|
+
datetime: "DateTimeFieldType",
|
|
3852
|
+
email: "EmailFieldType",
|
|
3853
|
+
embed: "EmbedFieldType",
|
|
3854
|
+
file: "FileFieldType",
|
|
3855
|
+
followupemail: "FollowUpEmailFieldType",
|
|
3856
|
+
font: "FontFieldType",
|
|
3857
|
+
form: "FormFieldType",
|
|
3858
|
+
gradient: "GradientFieldType",
|
|
3859
|
+
group: "GroupFieldType",
|
|
3860
|
+
html: "HtmlFieldType",
|
|
3861
|
+
hubdbrow: "HubDbRowFieldType",
|
|
3862
|
+
hubdbtable: "HubDbTableFieldType",
|
|
3863
|
+
hubl: "HublFieldType",
|
|
3864
|
+
icon: "IconFieldType",
|
|
3865
|
+
image: "ImageFieldType",
|
|
3866
|
+
link: "LinkFieldType",
|
|
3867
|
+
logo: "LogoFieldType",
|
|
3868
|
+
meeting: "MeetingFieldType",
|
|
3869
|
+
menu: "MenuFieldType",
|
|
3870
|
+
number: "NumberFieldType",
|
|
3871
|
+
page: "PageFieldType",
|
|
3872
|
+
payment: "PaymentFieldType",
|
|
3873
|
+
podcast: "PodcastFieldType",
|
|
3874
|
+
richtext: "RichTextFieldType",
|
|
3875
|
+
salesforcecampaign: "SfdcCamapaignFieldType",
|
|
3876
|
+
simplemenu: "SimpleMenuFieldType",
|
|
3877
|
+
spacing: "SpacingFieldType",
|
|
3878
|
+
survey: "SurveyFieldType",
|
|
3879
|
+
tag: "TagFieldType",
|
|
3880
|
+
textalignment: "TextAlignmentFieldType",
|
|
3881
|
+
text: "TextFieldType",
|
|
3882
|
+
url: "UrlFieldType",
|
|
3883
|
+
variantselection: "VariantSelectionFieldType",
|
|
3884
|
+
videoplayer: "VideoFieldType",
|
|
3885
|
+
workflow: "WorkflowFieldType"
|
|
3886
|
+
};
|
|
3887
|
+
function getFieldEntries(fields) {
|
|
3888
|
+
if (!Array.isArray(fields)) {
|
|
3889
|
+
return void 0;
|
|
3871
3890
|
}
|
|
3872
|
-
return
|
|
3873
|
-
const
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
method: "HEAD",
|
|
3878
|
-
headers: {
|
|
3879
|
-
// Keep this user agent, so we don't get 403s from the request
|
|
3880
|
-
["User-Agent"]: "cms-dev-server"
|
|
3881
|
-
}
|
|
3882
|
-
},
|
|
3883
|
-
async (res) => {
|
|
3884
|
-
let portalIdHeader;
|
|
3885
|
-
let contentId;
|
|
3886
|
-
const isContentMembershipRedirect = Boolean(
|
|
3887
|
-
res.headers["x-hs-content-membership-redirect"]
|
|
3888
|
-
);
|
|
3889
|
-
if (isContentMembershipRedirect) {
|
|
3890
|
-
debug("Content Membership Redirect", res.headers);
|
|
3891
|
-
portalIdHeader = res.headers["x-hs-portal-id"];
|
|
3892
|
-
contentId = res.headers["x-hs-content-id"];
|
|
3893
|
-
if (portalIdHeader && contentId) {
|
|
3894
|
-
return resolve2({
|
|
3895
|
-
portalIdHeader,
|
|
3896
|
-
contentId,
|
|
3897
|
-
res
|
|
3898
|
-
});
|
|
3899
|
-
}
|
|
3900
|
-
}
|
|
3901
|
-
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
3902
|
-
console.log(`Redirecting to ${res.headers.location} (from ${url3})`);
|
|
3903
|
-
return resolve2(
|
|
3904
|
-
requestPage(
|
|
3905
|
-
res.headers.location,
|
|
3906
|
-
redirects + 1,
|
|
3907
|
-
originalUrl ?? url3
|
|
3908
|
-
)
|
|
3909
|
-
);
|
|
3910
|
-
}
|
|
3911
|
-
portalIdHeader = res.headers["x-hs-hub-id"];
|
|
3912
|
-
contentId = res.headers["x-hs-content-id"];
|
|
3913
|
-
return resolve2({
|
|
3914
|
-
res,
|
|
3915
|
-
portalIdHeader,
|
|
3916
|
-
contentId
|
|
3917
|
-
});
|
|
3918
|
-
}
|
|
3919
|
-
).on("error", (err) => {
|
|
3920
|
-
console.error(err);
|
|
3921
|
-
reject(err);
|
|
3922
|
-
}).end();
|
|
3923
|
-
});
|
|
3924
|
-
}
|
|
3925
|
-
async function fetchContentMetadata(url3, portalId) {
|
|
3926
|
-
const { portalIdHeader, contentId, res } = await requestPage(url3);
|
|
3927
|
-
if (Array.isArray(portalIdHeader) || Array.isArray(contentId)) {
|
|
3928
|
-
throw new Error(
|
|
3929
|
-
`There were multiple hub ID or content ID headers in the HEAD request to ${url3}`
|
|
3930
|
-
);
|
|
3931
|
-
} else {
|
|
3932
|
-
const portalIdFromResponse = parseInt(portalIdHeader, 10);
|
|
3933
|
-
const pageAccount = await getConfigAccountIfExists5(portalIdFromResponse);
|
|
3934
|
-
if (!pageAccount) {
|
|
3935
|
-
throw new Error(
|
|
3936
|
-
`No CLI auth for portal ${portalIdFromResponse} found, please run \`hs auth\``
|
|
3937
|
-
);
|
|
3891
|
+
return fields.filter((field) => field.name && field.type).map((field) => {
|
|
3892
|
+
const { name, type } = field;
|
|
3893
|
+
const fieldType = fieldTypeNameByType[type];
|
|
3894
|
+
if (!fieldType) {
|
|
3895
|
+
return void 0;
|
|
3938
3896
|
}
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3897
|
+
const entry = {
|
|
3898
|
+
type: fieldType,
|
|
3899
|
+
name,
|
|
3900
|
+
isRepeater: "occurrence" in field,
|
|
3901
|
+
isRequired: !!field.required,
|
|
3902
|
+
choices: (
|
|
3903
|
+
// Choices are pair [value, label] but only the value is printed to the page, so flatten it.
|
|
3904
|
+
"choices" in field ? field.choices.map(([value, label]) => value) : void 0
|
|
3905
|
+
),
|
|
3906
|
+
children: []
|
|
3907
|
+
};
|
|
3908
|
+
if (fieldType === "GroupFieldType" && "children" in field) {
|
|
3909
|
+
const children = getFieldEntries(field.children);
|
|
3910
|
+
return { ...entry, children };
|
|
3951
3911
|
}
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
}
|
|
3912
|
+
return entry;
|
|
3913
|
+
}).filter((entry) => entry !== void 0);
|
|
3955
3914
|
}
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3915
|
+
var INVALID_IMPORTS = ["ChoiceFieldType", "GroupFieldType"];
|
|
3916
|
+
var FIELD_GROUP_TYPE = "FieldGroupWithChildren";
|
|
3917
|
+
var REPEATER_GROUP_TYPE = "RepeaterGroup";
|
|
3918
|
+
var REQUIRED_TYPE = "RequiredField";
|
|
3919
|
+
var DEFAULT_VALUES_TYPE = "DefaultValues";
|
|
3920
|
+
var CMS_COMPONENTS = "@hubspot/cms-components";
|
|
3921
|
+
var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
3922
|
+
var AUTO_GEN_COMMENT = "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.";
|
|
3923
|
+
var createPropertySignature = (identifier, type, hasQuestionToken = false) => ts.factory.createPropertySignature(
|
|
3924
|
+
[],
|
|
3925
|
+
identifier,
|
|
3926
|
+
hasQuestionToken ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) : void 0,
|
|
3927
|
+
type
|
|
3928
|
+
);
|
|
3929
|
+
var createUnionTypeFromArray = (values) => ts.factory.createUnionTypeNode(
|
|
3930
|
+
values.map(
|
|
3931
|
+
(value) => ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(value))
|
|
3932
|
+
)
|
|
3933
|
+
);
|
|
3934
|
+
var buildTypeFromField = (field, additionalNode) => {
|
|
3935
|
+
const imports = [field.type];
|
|
3936
|
+
const identifier = ts.factory.createIdentifier(field.name);
|
|
3937
|
+
const baseType = ts.factory.createTypeReferenceNode(field.type);
|
|
3938
|
+
const requiredType = ts.factory.createTypeReferenceNode(REQUIRED_TYPE, [
|
|
3939
|
+
baseType
|
|
3940
|
+
]);
|
|
3941
|
+
let finalType = field.isRequired ? requiredType : baseType;
|
|
3942
|
+
if (field.choices) {
|
|
3943
|
+
finalType = createUnionTypeFromArray(field.choices);
|
|
3969
3944
|
}
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
const urlToProxy = `http://${domainToProxy}${request.originalUrl}`;
|
|
3973
|
-
if (!domainToProxy) {
|
|
3974
|
-
if (VALID_PROXY_DOMAIN_SUFFIXES.includes(request.hostname)) {
|
|
3975
|
-
const message = `Can't make a proxy request, you need to prepend the real page's domain to '${request.hostname}' (i.e. your.page.com.${request.hostname})`;
|
|
3976
|
-
consoleWarn(message);
|
|
3977
|
-
return response.status(400).send(message);
|
|
3978
|
-
} else {
|
|
3979
|
-
const message = `Can't make a proxy request, the domain '${request.hostname}' is not a valid proxy-able domain`;
|
|
3980
|
-
consoleWarn(message);
|
|
3981
|
-
return response.status(400).send(message);
|
|
3982
|
-
}
|
|
3945
|
+
if (field.isRequired) {
|
|
3946
|
+
imports.push(REQUIRED_TYPE);
|
|
3983
3947
|
}
|
|
3984
|
-
|
|
3985
|
-
const
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
);
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
3948
|
+
if (additionalNode) {
|
|
3949
|
+
const typeLiteral = ts.isTypeLiteralNode(additionalNode) ? additionalNode : ts.factory.createTypeLiteralNode([additionalNode]);
|
|
3950
|
+
const genericType = field.isRepeater ? REPEATER_GROUP_TYPE : FIELD_GROUP_TYPE;
|
|
3951
|
+
imports.push(genericType);
|
|
3952
|
+
finalType = ts.factory.createTypeReferenceNode(genericType, [typeLiteral]);
|
|
3953
|
+
}
|
|
3954
|
+
return {
|
|
3955
|
+
type: createPropertySignature(
|
|
3956
|
+
identifier,
|
|
3957
|
+
finalType,
|
|
3958
|
+
!field.isRequired && !additionalNode
|
|
3959
|
+
),
|
|
3960
|
+
imports
|
|
3961
|
+
};
|
|
3962
|
+
};
|
|
3963
|
+
var filterUnusedImports = (imports, type) => {
|
|
3964
|
+
const usedImports = /* @__PURE__ */ new Set();
|
|
3965
|
+
const visit = (node) => {
|
|
3966
|
+
if (ts.isTypeReferenceNode(node)) {
|
|
3967
|
+
const typeName = node.typeName;
|
|
3968
|
+
if ("escapedText" in typeName) {
|
|
3969
|
+
usedImports.add(typeName.escapedText.toString());
|
|
3970
|
+
}
|
|
3971
|
+
}
|
|
3972
|
+
ts.forEachChild(node, visit);
|
|
3973
|
+
};
|
|
3974
|
+
visit(type);
|
|
3975
|
+
return imports.filter((name) => usedImports.has(name));
|
|
3976
|
+
};
|
|
3977
|
+
function getImportDeclaration(imports, moduleSpecifier) {
|
|
3978
|
+
const importSpecifiers = Array.from(imports).map(
|
|
3979
|
+
(importName) => ts.factory.createImportSpecifier(
|
|
3980
|
+
true,
|
|
3981
|
+
void 0,
|
|
3982
|
+
ts.factory.createIdentifier(importName)
|
|
3983
|
+
)
|
|
3984
|
+
);
|
|
3985
|
+
const namedImports = ts.factory.createNamedImports(importSpecifiers);
|
|
3986
|
+
return ts.factory.createImportDeclaration(
|
|
3987
|
+
[],
|
|
3988
|
+
[],
|
|
3989
|
+
ts.factory.createImportClause(false, void 0, namedImports),
|
|
3990
|
+
ts.factory.createStringLiteral(moduleSpecifier)
|
|
3991
|
+
);
|
|
3992
|
+
}
|
|
3993
|
+
function getFieldTypes(fields) {
|
|
3994
|
+
const imports = [];
|
|
3995
|
+
const types = fields.map((field) => {
|
|
3996
|
+
if (field.children) {
|
|
3997
|
+
const childrenResult = getFieldTypes(field.children);
|
|
3998
|
+
imports.push(...childrenResult.imports);
|
|
3999
|
+
if (childrenResult.types.length || field.type === "GroupFieldType") {
|
|
4000
|
+
const subType = ts.factory.createTypeLiteralNode(childrenResult.types);
|
|
4001
|
+
const { type: type2, imports: newImports2 } = buildTypeFromField(
|
|
4002
|
+
field,
|
|
4003
|
+
subType
|
|
4004
|
+
);
|
|
4005
|
+
imports.push(...newImports2);
|
|
4006
|
+
return type2;
|
|
4007
|
+
}
|
|
4008
|
+
}
|
|
4009
|
+
const { type, imports: newImports } = buildTypeFromField(field);
|
|
4010
|
+
imports.push(...newImports);
|
|
4011
|
+
return type;
|
|
4012
|
+
});
|
|
4013
|
+
const validImports = Array.from(
|
|
4014
|
+
new Set(imports.filter((name) => !INVALID_IMPORTS.includes(name)))
|
|
4015
|
+
);
|
|
4016
|
+
return { types, imports: validImports };
|
|
4017
|
+
}
|
|
4018
|
+
function constructFinalType(fields, typeName) {
|
|
4019
|
+
const { types, imports } = getFieldTypes(fields);
|
|
4020
|
+
const baseType = ts.factory.createTypeAliasDeclaration(
|
|
4021
|
+
[],
|
|
4022
|
+
[],
|
|
4023
|
+
"",
|
|
4024
|
+
void 0,
|
|
4025
|
+
ts.factory.createTypeLiteralNode(types)
|
|
4026
|
+
);
|
|
4027
|
+
const wrappedType = ts.factory.createTypeReferenceNode(DEFAULT_VALUES_TYPE, [
|
|
4028
|
+
baseType.type
|
|
4029
|
+
]);
|
|
4030
|
+
const finalType = ts.factory.createTypeAliasDeclaration(
|
|
4031
|
+
[],
|
|
4032
|
+
[],
|
|
4033
|
+
typeName,
|
|
4034
|
+
void 0,
|
|
4035
|
+
wrappedType
|
|
4036
|
+
);
|
|
4037
|
+
const filteredImports = filterUnusedImports(imports, finalType);
|
|
4038
|
+
const importDeclaration = getImportDeclaration(
|
|
4039
|
+
[...filteredImports, DEFAULT_VALUES_TYPE],
|
|
4040
|
+
CMS_COMPONENTS_FIELD_TYPES
|
|
4041
|
+
);
|
|
4042
|
+
const defaultExport = ts.factory.createExportDefault(
|
|
4043
|
+
ts.factory.createIdentifier(typeName)
|
|
4044
|
+
);
|
|
4045
|
+
return [importDeclaration, finalType, defaultExport];
|
|
4046
|
+
}
|
|
4047
|
+
function writeFieldsType(fields, fileName, typeName) {
|
|
4048
|
+
const entries = getFieldEntries(fields);
|
|
4049
|
+
if (!entries) {
|
|
4050
|
+
return false;
|
|
4051
|
+
}
|
|
4052
|
+
try {
|
|
4053
|
+
const file = ts.createSourceFile(
|
|
4054
|
+
fileName,
|
|
4055
|
+
"",
|
|
4056
|
+
ts.ScriptTarget.ESNext,
|
|
4057
|
+
false,
|
|
4058
|
+
ts.ScriptKind.TS
|
|
4002
4059
|
);
|
|
4060
|
+
const printer = ts.createPrinter();
|
|
4061
|
+
const nodes = constructFinalType(entries, typeName);
|
|
4062
|
+
const comments = [
|
|
4063
|
+
AUTO_GEN_COMMENT,
|
|
4064
|
+
"Removing the above comment will disable type generation for this module",
|
|
4065
|
+
"This file was created by @hubspot/cms-dev-server, for more information see https://github.hubspot.com/cms-react/reference/js-modules.html#module-fields"
|
|
4066
|
+
].map((comment) => `// ${comment}`);
|
|
4067
|
+
const typeResult = nodes.map(
|
|
4068
|
+
(node) => printer.printNode(ts.EmitHint.Unspecified, node, file)
|
|
4069
|
+
);
|
|
4070
|
+
const result = [...comments, ...typeResult].join("\n");
|
|
4071
|
+
writeFileSync(fileName, result);
|
|
4072
|
+
return true;
|
|
4003
4073
|
} catch (e) {
|
|
4004
|
-
|
|
4074
|
+
console.error(e);
|
|
4075
|
+
return false;
|
|
4005
4076
|
}
|
|
4006
4077
|
}
|
|
4007
4078
|
|
|
4008
|
-
// src/
|
|
4009
|
-
import
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
var
|
|
4013
|
-
var
|
|
4014
|
-
|
|
4015
|
-
const
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4079
|
+
// src/lib/watchFieldsUpdates.ts
|
|
4080
|
+
import fs4 from "fs";
|
|
4081
|
+
import path10 from "path";
|
|
4082
|
+
import readline from "readline";
|
|
4083
|
+
var lastSerializedFieldsCache = {};
|
|
4084
|
+
var formatAsTypeName = (str) => {
|
|
4085
|
+
const typeName = `${str.replace(/[^a-zA-Z0-9_$]/g, "_")}FieldsType`;
|
|
4086
|
+
const validFirstChar = /^[A-Za-z_$]/.test(str.charAt(0));
|
|
4087
|
+
return validFirstChar ? typeName : `_${typeName}`;
|
|
4088
|
+
};
|
|
4089
|
+
var isInModulesFolder = (filePath, projectRoot) => {
|
|
4090
|
+
const getEntryPathFromId = (id) => {
|
|
4091
|
+
return id.startsWith(projectRoot) ? id.replace(`${projectRoot}${path10.sep}`, "") : "";
|
|
4092
|
+
};
|
|
4093
|
+
const currentModuleId = path10.normalize(filePath);
|
|
4094
|
+
const moduleEntryPath = getEntryPathFromId(currentModuleId);
|
|
4095
|
+
const subFolderTokens = moduleEntryPath.split(path10.sep);
|
|
4096
|
+
return {
|
|
4097
|
+
inModuleFolder: subFolderTokens[0] === "components" && subFolderTokens[1] === "modules",
|
|
4098
|
+
isRootModuleFile: subFolderTokens.length === 3
|
|
4099
|
+
};
|
|
4100
|
+
};
|
|
4101
|
+
var fileContainsAutoGenComment = async (filePath) => {
|
|
4102
|
+
if (!fs4.existsSync(filePath))
|
|
4103
|
+
return true;
|
|
4104
|
+
const stream2 = fs4.createReadStream(filePath);
|
|
4105
|
+
const reader = readline.createInterface({ input: stream2 });
|
|
4106
|
+
const firstLine = await new Promise(
|
|
4107
|
+
(resolve2) => reader.once("line", (line) => resolve2(line.trim()))
|
|
4108
|
+
);
|
|
4109
|
+
reader.close();
|
|
4110
|
+
stream2.close();
|
|
4111
|
+
return firstLine && firstLine === `// ${AUTO_GEN_COMMENT}`;
|
|
4112
|
+
};
|
|
4113
|
+
var getIndexFile = (filePath, projectRoot) => {
|
|
4114
|
+
const { inModuleFolder, isRootModuleFile } = isInModulesFolder(
|
|
4115
|
+
filePath,
|
|
4116
|
+
projectRoot
|
|
4117
|
+
);
|
|
4118
|
+
if (!inModuleFolder)
|
|
4119
|
+
return void 0;
|
|
4120
|
+
if (isRootModuleFile)
|
|
4121
|
+
return { indexFilePath: filePath, isRootModuleFile };
|
|
4122
|
+
const dir = path10.dirname(filePath);
|
|
4123
|
+
const files = fs4.readdirSync(dir);
|
|
4124
|
+
const indexFileName = files.find((file) => file.startsWith("index."));
|
|
4125
|
+
return indexFileName ? { indexFilePath: path10.join(dir, indexFileName), isRootModuleFile } : void 0;
|
|
4126
|
+
};
|
|
4127
|
+
var getIndexFileFields = async (indexFilePath, indexFileName, viteServer) => {
|
|
4128
|
+
let indexFile;
|
|
4129
|
+
let renderFieldsToJson;
|
|
4130
|
+
try {
|
|
4131
|
+
indexFile = await viteServer.ssrLoadModule(indexFilePath);
|
|
4132
|
+
const internalSsrPath = packagePath(import.meta.url, "internalSsr");
|
|
4133
|
+
({ renderFieldsToJson } = await viteServer.ssrLoadModule(internalSsrPath));
|
|
4134
|
+
} catch (e) {
|
|
4135
|
+
return void 0;
|
|
4019
4136
|
}
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
const
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4137
|
+
if (!indexFile.fields)
|
|
4138
|
+
return void 0;
|
|
4139
|
+
const fields = indexFile.fields;
|
|
4140
|
+
const renderedFieldsJson = renderFieldsToJson(fields, indexFileName);
|
|
4141
|
+
const isValidFields = Array.isArray(renderedFieldsJson);
|
|
4142
|
+
return isValidFields ? renderedFieldsJson : void 0;
|
|
4143
|
+
};
|
|
4144
|
+
var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
|
|
4145
|
+
const indexInfo = getIndexFile(filePath, projectRoot);
|
|
4146
|
+
if (!indexInfo)
|
|
4147
|
+
return;
|
|
4148
|
+
const { indexFilePath, isRootModuleFile } = indexInfo;
|
|
4149
|
+
const indexFileName = path10.parse(indexFilePath).name;
|
|
4150
|
+
const isTypeFile = filePath.endsWith(".types.ts");
|
|
4151
|
+
if (isTypeFile)
|
|
4152
|
+
return;
|
|
4153
|
+
const fields = await getIndexFileFields(
|
|
4154
|
+
indexFilePath,
|
|
4155
|
+
indexFileName,
|
|
4156
|
+
viteServer
|
|
4157
|
+
);
|
|
4158
|
+
if (fields) {
|
|
4159
|
+
const typeFileName = isRootModuleFile ? `${indexFileName}.fields.types.ts` : "fields.type.ts";
|
|
4160
|
+
const typeFilePath = path10.join(path10.dirname(filePath), typeFileName);
|
|
4161
|
+
const lastSerializedFields = lastSerializedFieldsCache[typeFilePath];
|
|
4162
|
+
const serializedFields = JSON.stringify(fields);
|
|
4163
|
+
if (lastSerializedFields === serializedFields)
|
|
4164
|
+
return;
|
|
4165
|
+
const hasAutoGenComment = await fileContainsAutoGenComment(typeFilePath);
|
|
4166
|
+
if (!hasAutoGenComment)
|
|
4167
|
+
return;
|
|
4168
|
+
const moduleFolderName = path10.basename(path10.dirname(filePath));
|
|
4169
|
+
const outputTypeName = formatAsTypeName(moduleFolderName);
|
|
4170
|
+
const didSucceed = writeFieldsType(fields, typeFilePath, outputTypeName);
|
|
4171
|
+
if (didSucceed) {
|
|
4172
|
+
lastSerializedFieldsCache[typeFilePath] = serializedFields;
|
|
4047
4173
|
}
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4174
|
+
const pathToLog = isRootModuleFile ? `${moduleFolderName}/${indexFileName}` : moduleFolderName;
|
|
4175
|
+
const successMsg = `Successfully generated types for ${pathToLog}`;
|
|
4176
|
+
const errorMsg = `Failed to generate types for ${pathToLog}`;
|
|
4177
|
+
const message = didSucceed ? successMsg : errorMsg;
|
|
4178
|
+
console.log(wrapMessageInColor(didSucceed ? "green" : "red", message));
|
|
4053
4179
|
}
|
|
4054
|
-
}
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
}
|
|
4180
|
+
};
|
|
4181
|
+
var startFieldsTypeGenWatcher = (viteServer, projectRoot) => {
|
|
4182
|
+
const { moduleSubpaths } = findAllModulesInRoot(projectRoot);
|
|
4183
|
+
moduleSubpaths.forEach((modulePath) => {
|
|
4184
|
+
const resolvedPath = path10.resolve(projectRoot, modulePath);
|
|
4185
|
+
maybeUpdateFields(resolvedPath, viteServer, projectRoot);
|
|
4186
|
+
});
|
|
4187
|
+
const watchCallback = (filePath) => maybeUpdateFields(filePath, viteServer, projectRoot);
|
|
4188
|
+
viteServer.watcher.on("add", watchCallback).on("change", watchCallback);
|
|
4189
|
+
};
|
|
4061
4190
|
|
|
4062
|
-
// src/
|
|
4191
|
+
// src/validateFields.ts
|
|
4063
4192
|
import { http as hsCliHttp8 } from "@hubspot/local-dev-lib/http";
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
}
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
}
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4193
|
+
import { getConfigDefaultAccount } from "@hubspot/local-dev-lib/config";
|
|
4194
|
+
var EDITOR_VERSION_V2 = "2.0";
|
|
4195
|
+
async function generateAndWriteFieldsJson(absoluteModulePath, modulePath, viteServer) {
|
|
4196
|
+
let fieldsJson;
|
|
4197
|
+
try {
|
|
4198
|
+
fieldsJson = await renderModuleFieldsJson_default(viteServer, absoluteModulePath);
|
|
4199
|
+
} catch {
|
|
4200
|
+
return {
|
|
4201
|
+
severity: "FATAL",
|
|
4202
|
+
errorType: "MODULE_BUILD_ERROR",
|
|
4203
|
+
message: `Failed to SSR-load module at ${modulePath}`
|
|
4204
|
+
};
|
|
4205
|
+
}
|
|
4206
|
+
if (!Array.isArray(fieldsJson)) {
|
|
4207
|
+
return {
|
|
4208
|
+
severity: "FATAL",
|
|
4209
|
+
errorType: "INVALID_FIELDS",
|
|
4210
|
+
message: `renderModuleFieldsJson returned non-array for ${modulePath}`
|
|
4211
|
+
};
|
|
4212
|
+
}
|
|
4213
|
+
const fieldsJsonPath = path11.join(absoluteModulePath, "fields.json");
|
|
4214
|
+
await fs5.writeFile(fieldsJsonPath, JSON.stringify(fieldsJson, null, 2));
|
|
4215
|
+
return { fieldsJson, fieldsJsonPath };
|
|
4216
|
+
}
|
|
4217
|
+
async function generateAndWriteFieldsType(absoluteModulePath, modulePath, moduleDir, fieldsJson) {
|
|
4218
|
+
const fieldsTypePath = path11.join(absoluteModulePath, "fields.type.ts");
|
|
4219
|
+
const hasAutoGenComment = await fileContainsAutoGenComment(fieldsTypePath);
|
|
4220
|
+
if (hasAutoGenComment) {
|
|
4221
|
+
const typeName = formatAsTypeName(moduleDir);
|
|
4222
|
+
const didSucceed = writeFieldsType(fieldsJson, fieldsTypePath, typeName);
|
|
4223
|
+
if (!didSucceed) {
|
|
4224
|
+
return {
|
|
4225
|
+
severity: "FATAL",
|
|
4226
|
+
errorType: "TYPE_GEN_ERROR",
|
|
4227
|
+
message: `Failed to generate fields.type.ts for ${modulePath}`
|
|
4228
|
+
};
|
|
4229
|
+
}
|
|
4230
|
+
}
|
|
4231
|
+
return { fieldsTypePath };
|
|
4097
4232
|
}
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4233
|
+
async function extractAndValidateFields(fieldsJson, metaJson, modulePath) {
|
|
4234
|
+
if (!metaJson) {
|
|
4235
|
+
return {
|
|
4236
|
+
fieldErrors: [],
|
|
4237
|
+
metaErrors: [
|
|
4238
|
+
{
|
|
4239
|
+
severity: "FATAL",
|
|
4240
|
+
errorType: "MISSING_META",
|
|
4241
|
+
message: `Module does not have a named meta export: ${modulePath}`
|
|
4242
|
+
}
|
|
4243
|
+
]
|
|
4244
|
+
};
|
|
4245
|
+
}
|
|
4246
|
+
const portalId = getConfigDefaultAccount().accountId;
|
|
4247
|
+
const [fieldsResult, metaResult] = await Promise.allSettled([
|
|
4248
|
+
hsCliHttp8.post(portalId, {
|
|
4249
|
+
url: `${VALIDATE_FIELDS_ENDPOINT}?editorVersion=${metaJson.editor_version ?? EDITOR_VERSION_V2}`,
|
|
4250
|
+
data: fieldsJson
|
|
4251
|
+
}),
|
|
4252
|
+
hsCliHttp8.post(portalId, {
|
|
4253
|
+
url: VALIDATE_META_ENDPOINT,
|
|
4254
|
+
data: metaJson
|
|
4255
|
+
})
|
|
4256
|
+
]);
|
|
4257
|
+
const mapErrors = (entities) => entities.filter((e) => e.severity === "FATAL").map((e) => ({
|
|
4258
|
+
severity: e.severity,
|
|
4259
|
+
errorType: e.errorType,
|
|
4260
|
+
message: e.message,
|
|
4261
|
+
fieldPath: e.errorTokens.path[0]
|
|
4262
|
+
}));
|
|
4263
|
+
return {
|
|
4264
|
+
fieldErrors: fieldsResult.status === "fulfilled" ? mapErrors(fieldsResult.value.data) : [
|
|
4265
|
+
{
|
|
4266
|
+
severity: "FATAL",
|
|
4267
|
+
errorType: "API_UNREACHABLE",
|
|
4268
|
+
message: `Field validation API error: ${fieldsResult.reason}`
|
|
4269
|
+
}
|
|
4270
|
+
],
|
|
4271
|
+
metaErrors: metaResult.status === "fulfilled" ? mapErrors(metaResult.value.data) : [
|
|
4272
|
+
{
|
|
4273
|
+
severity: "FATAL",
|
|
4274
|
+
errorType: "API_UNREACHABLE",
|
|
4275
|
+
message: `Meta validation API error: ${metaResult.reason}`
|
|
4276
|
+
}
|
|
4277
|
+
]
|
|
4278
|
+
};
|
|
4101
4279
|
}
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
return
|
|
4280
|
+
async function validateSingleModule(modulePath, absoluteRoot, viteServer) {
|
|
4281
|
+
const absoluteModulePath = path11.resolve(absoluteRoot, modulePath);
|
|
4282
|
+
const moduleDir = path11.basename(modulePath);
|
|
4283
|
+
let files;
|
|
4284
|
+
try {
|
|
4285
|
+
files = await fs5.readdir(absoluteModulePath);
|
|
4286
|
+
} catch {
|
|
4287
|
+
return {
|
|
4288
|
+
fieldsJsonPath: "",
|
|
4289
|
+
fieldsTypePath: "",
|
|
4290
|
+
fieldErrors: [
|
|
4291
|
+
{
|
|
4292
|
+
severity: "FATAL",
|
|
4293
|
+
errorType: "MODULE_NOT_FOUND",
|
|
4294
|
+
message: `Module directory does not exist: ${modulePath}`
|
|
4295
|
+
}
|
|
4296
|
+
],
|
|
4297
|
+
metaErrors: []
|
|
4298
|
+
};
|
|
4110
4299
|
}
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4300
|
+
const indexFile = files.find((f) => f.startsWith("index."));
|
|
4301
|
+
if (!indexFile) {
|
|
4302
|
+
return {
|
|
4303
|
+
fieldsJsonPath: "",
|
|
4304
|
+
fieldsTypePath: "",
|
|
4305
|
+
fieldErrors: [
|
|
4306
|
+
{
|
|
4307
|
+
severity: "FATAL",
|
|
4308
|
+
errorType: "NO_INDEX_FILE",
|
|
4309
|
+
message: `No index file found in ${modulePath}`
|
|
4310
|
+
}
|
|
4311
|
+
],
|
|
4312
|
+
metaErrors: []
|
|
4313
|
+
};
|
|
4314
|
+
}
|
|
4315
|
+
const jsonResult = await generateAndWriteFieldsJson(
|
|
4316
|
+
absoluteModulePath,
|
|
4317
|
+
modulePath,
|
|
4318
|
+
viteServer
|
|
4124
4319
|
);
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4320
|
+
if ("severity" in jsonResult) {
|
|
4321
|
+
return {
|
|
4322
|
+
fieldsJsonPath: "",
|
|
4323
|
+
fieldsTypePath: "",
|
|
4324
|
+
fieldErrors: [jsonResult],
|
|
4325
|
+
metaErrors: []
|
|
4326
|
+
};
|
|
4327
|
+
}
|
|
4328
|
+
const typeResult = await generateAndWriteFieldsType(
|
|
4329
|
+
absoluteModulePath,
|
|
4330
|
+
modulePath,
|
|
4331
|
+
moduleDir,
|
|
4332
|
+
jsonResult.fieldsJson
|
|
4128
4333
|
);
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4334
|
+
if ("severity" in typeResult) {
|
|
4335
|
+
return {
|
|
4336
|
+
fieldsJsonPath: jsonResult.fieldsJsonPath,
|
|
4337
|
+
fieldsTypePath: "",
|
|
4338
|
+
fieldErrors: [typeResult],
|
|
4339
|
+
metaErrors: []
|
|
4340
|
+
};
|
|
4341
|
+
}
|
|
4342
|
+
let mod;
|
|
4343
|
+
try {
|
|
4344
|
+
mod = await viteServer.ssrLoadModule(
|
|
4345
|
+
path11.join(absoluteModulePath, indexFile)
|
|
4346
|
+
);
|
|
4347
|
+
} catch {
|
|
4348
|
+
return {
|
|
4349
|
+
fieldsJsonPath: jsonResult.fieldsJsonPath,
|
|
4350
|
+
fieldsTypePath: typeResult.fieldsTypePath,
|
|
4351
|
+
fieldErrors: [
|
|
4352
|
+
{
|
|
4353
|
+
severity: "FATAL",
|
|
4354
|
+
errorType: "MODULE_BUILD_ERROR",
|
|
4355
|
+
message: `Failed to SSR-load module for meta extraction: ${modulePath}`
|
|
4356
|
+
}
|
|
4357
|
+
],
|
|
4358
|
+
metaErrors: []
|
|
4359
|
+
};
|
|
4360
|
+
}
|
|
4361
|
+
const { fieldErrors, metaErrors } = await extractAndValidateFields(
|
|
4362
|
+
jsonResult.fieldsJson,
|
|
4363
|
+
mod.meta,
|
|
4364
|
+
modulePath
|
|
4365
|
+
);
|
|
4366
|
+
return {
|
|
4367
|
+
fieldsJsonPath: jsonResult.fieldsJsonPath,
|
|
4368
|
+
fieldsTypePath: typeResult.fieldsTypePath,
|
|
4369
|
+
fieldErrors,
|
|
4370
|
+
metaErrors
|
|
4371
|
+
};
|
|
4372
|
+
}
|
|
4373
|
+
|
|
4374
|
+
// src/routes/moduleValidateFields.ts
|
|
4375
|
+
var invalidateModuleFiles = async (viteServer, absoluteModulePath) => {
|
|
4376
|
+
const files = await fs6.readdir(absoluteModulePath).catch(() => []);
|
|
4377
|
+
files.forEach(
|
|
4378
|
+
(file) => {
|
|
4379
|
+
var _a;
|
|
4380
|
+
return (_a = viteServer.moduleGraph.getModulesByFile(path12.join(absoluteModulePath, file))) == null ? void 0 : _a.forEach((mod) => viteServer.moduleGraph.invalidateModule(mod));
|
|
4381
|
+
}
|
|
4141
4382
|
);
|
|
4142
|
-
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
4143
4383
|
};
|
|
4144
|
-
var
|
|
4384
|
+
var moduleValidateFieldsRouteHandler = async (request, response) => {
|
|
4385
|
+
try {
|
|
4386
|
+
const { webRoot, viteServer } = request.app.locals;
|
|
4387
|
+
const { moduleName } = request.params;
|
|
4388
|
+
const modulesRoot = path12.resolve(webRoot, "components/modules");
|
|
4389
|
+
const absoluteModulePath = path12.resolve(modulesRoot, moduleName);
|
|
4390
|
+
if (!absoluteModulePath.startsWith(modulesRoot + path12.sep) || path12.dirname(absoluteModulePath) !== modulesRoot) {
|
|
4391
|
+
return response.status(400).json({ error: "Invalid module name" });
|
|
4392
|
+
}
|
|
4393
|
+
await invalidateModuleFiles(viteServer, absoluteModulePath);
|
|
4394
|
+
const result = await validateSingleModule(
|
|
4395
|
+
absoluteModulePath,
|
|
4396
|
+
webRoot,
|
|
4397
|
+
viteServer
|
|
4398
|
+
);
|
|
4399
|
+
return response.status(200).json([result]);
|
|
4400
|
+
} catch (error) {
|
|
4401
|
+
console.error("Error validating module fields:", error);
|
|
4402
|
+
return response.status(500).json({
|
|
4403
|
+
error: "Failed to validate module fields"
|
|
4404
|
+
});
|
|
4405
|
+
}
|
|
4406
|
+
};
|
|
4407
|
+
var moduleValidateFields_default = moduleValidateFieldsRouteHandler;
|
|
4408
|
+
|
|
4409
|
+
// src/proxyPage/fetchContentMetadata.ts
|
|
4410
|
+
import http from "http";
|
|
4411
|
+
import https from "https";
|
|
4412
|
+
import { getConfigAccountIfExists as getConfigAccountIfExists5 } from "@hubspot/local-dev-lib/config";
|
|
4413
|
+
async function requestPage(url3, redirects = 0, originalUrl) {
|
|
4414
|
+
if (redirects > 5) {
|
|
4415
|
+
throw new Error(
|
|
4416
|
+
`Hit too many redirects to HEAD requests for ${originalUrl}`
|
|
4417
|
+
);
|
|
4418
|
+
}
|
|
4419
|
+
return new Promise((resolve2, reject) => {
|
|
4420
|
+
const protocolAPI = url3.startsWith("https://") ? https : http;
|
|
4421
|
+
protocolAPI.request(
|
|
4422
|
+
url3,
|
|
4423
|
+
{
|
|
4424
|
+
method: "HEAD",
|
|
4425
|
+
headers: {
|
|
4426
|
+
// Keep this user agent, so we don't get 403s from the request
|
|
4427
|
+
["User-Agent"]: "cms-dev-server"
|
|
4428
|
+
}
|
|
4429
|
+
},
|
|
4430
|
+
async (res) => {
|
|
4431
|
+
let portalIdHeader;
|
|
4432
|
+
let contentId;
|
|
4433
|
+
const isContentMembershipRedirect = Boolean(
|
|
4434
|
+
res.headers["x-hs-content-membership-redirect"]
|
|
4435
|
+
);
|
|
4436
|
+
if (isContentMembershipRedirect) {
|
|
4437
|
+
debug("Content Membership Redirect", res.headers);
|
|
4438
|
+
portalIdHeader = res.headers["x-hs-portal-id"];
|
|
4439
|
+
contentId = res.headers["x-hs-content-id"];
|
|
4440
|
+
if (portalIdHeader && contentId) {
|
|
4441
|
+
return resolve2({
|
|
4442
|
+
portalIdHeader,
|
|
4443
|
+
contentId,
|
|
4444
|
+
res
|
|
4445
|
+
});
|
|
4446
|
+
}
|
|
4447
|
+
}
|
|
4448
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
4449
|
+
console.log(`Redirecting to ${res.headers.location} (from ${url3})`);
|
|
4450
|
+
return resolve2(
|
|
4451
|
+
requestPage(
|
|
4452
|
+
res.headers.location,
|
|
4453
|
+
redirects + 1,
|
|
4454
|
+
originalUrl ?? url3
|
|
4455
|
+
)
|
|
4456
|
+
);
|
|
4457
|
+
}
|
|
4458
|
+
portalIdHeader = res.headers["x-hs-hub-id"];
|
|
4459
|
+
contentId = res.headers["x-hs-content-id"];
|
|
4460
|
+
return resolve2({
|
|
4461
|
+
res,
|
|
4462
|
+
portalIdHeader,
|
|
4463
|
+
contentId
|
|
4464
|
+
});
|
|
4465
|
+
}
|
|
4466
|
+
).on("error", (err) => {
|
|
4467
|
+
console.error(err);
|
|
4468
|
+
reject(err);
|
|
4469
|
+
}).end();
|
|
4470
|
+
});
|
|
4471
|
+
}
|
|
4472
|
+
async function fetchContentMetadata(url3, portalId) {
|
|
4473
|
+
const { portalIdHeader, contentId, res } = await requestPage(url3);
|
|
4474
|
+
if (Array.isArray(portalIdHeader) || Array.isArray(contentId)) {
|
|
4475
|
+
throw new Error(
|
|
4476
|
+
`There were multiple hub ID or content ID headers in the HEAD request to ${url3}`
|
|
4477
|
+
);
|
|
4478
|
+
} else {
|
|
4479
|
+
const portalIdFromResponse = parseInt(portalIdHeader, 10);
|
|
4480
|
+
const pageAccount = await getConfigAccountIfExists5(portalIdFromResponse);
|
|
4481
|
+
if (!pageAccount) {
|
|
4482
|
+
throw new Error(
|
|
4483
|
+
`No CLI auth for portal ${portalIdFromResponse} found, please run \`hs auth\``
|
|
4484
|
+
);
|
|
4485
|
+
}
|
|
4486
|
+
if (res.statusCode !== 200 && !(portalIdFromResponse && pageAccount && contentId)) {
|
|
4487
|
+
throw new Error(
|
|
4488
|
+
`${res.statusCode} ${res.statusMessage} - Unable to obtain HEAD information from ${url3}. ${res.statusCode === 429 && res.headers["retry-after"] ? `Retry after ${res.headers["retry-after"]} seconds.` : ""}`
|
|
4489
|
+
);
|
|
4490
|
+
} else if (!portalId || !contentId) {
|
|
4491
|
+
throw new Error(
|
|
4492
|
+
`Missing hub ID or content ID headers on HEAD request to ${url3}`
|
|
4493
|
+
);
|
|
4494
|
+
} else if (isNaN(portalId)) {
|
|
4495
|
+
throw new Error(
|
|
4496
|
+
`Hub ID from the HEAD request is not a number: '${portalId}' (${url3})`
|
|
4497
|
+
);
|
|
4498
|
+
}
|
|
4499
|
+
const hublet = "na1";
|
|
4500
|
+
return { portalId, contentId, hublet };
|
|
4501
|
+
}
|
|
4502
|
+
}
|
|
4145
4503
|
|
|
4146
|
-
// src/routes/
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
sendTrackingRequest("view-proxy-path-route");
|
|
4504
|
+
// src/routes/proxyPageRouteHandler.ts
|
|
4505
|
+
async function proxyPageRouteHandler(request, response, next) {
|
|
4506
|
+
sendTrackingRequest("view-proxy-page-route");
|
|
4150
4507
|
const {
|
|
4151
4508
|
viteServer,
|
|
4152
4509
|
webRoot,
|
|
@@ -4157,45 +4514,23 @@ async function proxyPathPageRouteHandler(request, response, next) {
|
|
|
4157
4514
|
if (!request.accepts().includes("text/html")) {
|
|
4158
4515
|
return response.sendStatus(404);
|
|
4159
4516
|
}
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
}
|
|
4174
|
-
),
|
|
4175
|
-
/* @__PURE__ */ jsx9("button", { style: { display: "block" }, children: "Proxy" })
|
|
4176
|
-
] })
|
|
4177
|
-
] })
|
|
4178
|
-
);
|
|
4179
|
-
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
4180
|
-
return;
|
|
4181
|
-
}
|
|
4182
|
-
let proxyPageUrl;
|
|
4183
|
-
try {
|
|
4184
|
-
proxyPageUrl = new URL(request.query.page);
|
|
4185
|
-
} catch (e) {
|
|
4186
|
-
const message = "Please provide a valid page query parameter, e.g., http://localhost:3000/proxy?page=https://yourdomain.com/path";
|
|
4187
|
-
consoleWarn(message);
|
|
4188
|
-
response.status(400).send(message);
|
|
4189
|
-
return;
|
|
4190
|
-
}
|
|
4191
|
-
if (proxyPageUrl.searchParams.has("hs_preview")) {
|
|
4192
|
-
const message = `Can't make a proxy request, you cannot proxy URLs that include internal query params like hs_preview`;
|
|
4193
|
-
consoleWarn(message);
|
|
4194
|
-
return response.status(400).send(message);
|
|
4517
|
+
const fullOriginalUrl = fullOriginalUrlFromRequest(request);
|
|
4518
|
+
const domainToProxy = getSubDomainFromValidLocalDomain(request.hostname);
|
|
4519
|
+
const urlToProxy = `http://${domainToProxy}${request.originalUrl}`;
|
|
4520
|
+
if (!domainToProxy) {
|
|
4521
|
+
if (VALID_PROXY_DOMAIN_SUFFIXES.includes(request.hostname)) {
|
|
4522
|
+
const message = `Can't make a proxy request, you need to prepend the real page's domain to '${request.hostname}' (i.e. your.page.com.${request.hostname})`;
|
|
4523
|
+
consoleWarn(message);
|
|
4524
|
+
return response.status(400).send(message);
|
|
4525
|
+
} else {
|
|
4526
|
+
const message = `Can't make a proxy request, the domain '${request.hostname}' is not a valid proxy-able domain`;
|
|
4527
|
+
consoleWarn(message);
|
|
4528
|
+
return response.status(400).send(message);
|
|
4529
|
+
}
|
|
4195
4530
|
}
|
|
4196
4531
|
try {
|
|
4197
4532
|
const { portalId, contentId, hublet } = await fetchContentMetadata(
|
|
4198
|
-
|
|
4533
|
+
urlToProxy,
|
|
4199
4534
|
request.app.locals.authedPortalId
|
|
4200
4535
|
);
|
|
4201
4536
|
await proxySpecificPage(
|
|
@@ -4203,1638 +4538,1494 @@ async function proxyPathPageRouteHandler(request, response, next) {
|
|
|
4203
4538
|
response,
|
|
4204
4539
|
portalId,
|
|
4205
4540
|
hublet,
|
|
4206
|
-
contentId,
|
|
4207
|
-
webRoot,
|
|
4208
|
-
viteServer,
|
|
4209
|
-
projectName,
|
|
4210
|
-
projectComponentPath,
|
|
4211
|
-
jsRenderingGates,
|
|
4212
|
-
proxyPageUrl.href,
|
|
4213
|
-
proxyPageUrl.href
|
|
4214
|
-
);
|
|
4215
|
-
} catch (e) {
|
|
4216
|
-
next(e);
|
|
4217
|
-
}
|
|
4218
|
-
}
|
|
4219
|
-
|
|
4220
|
-
// src/routes/proxyPathPageResourceRedirect.ts
|
|
4221
|
-
import fetch3 from "node-fetch";
|
|
4222
|
-
var HCMS_PATH2 = "/_hcms/";
|
|
4223
|
-
var HS_FS_PATH2 = "/hs-fs/";
|
|
4224
|
-
var HUB_FS_PATH2 = "/hubfs/";
|
|
4225
|
-
var isInternalCMSRoute2 = (req) => req.path.startsWith(HCMS_PATH2) || req.path.startsWith(HS_FS_PATH2) || req.path.startsWith(HUB_FS_PATH2);
|
|
4226
|
-
function proxyPathPageResourceRedirect(req, res, next) {
|
|
4227
|
-
const isAHtmlRequest = req.accepts().includes("text/html");
|
|
4228
|
-
let proxyPageUrl;
|
|
4229
|
-
let refererUrl;
|
|
4230
|
-
try {
|
|
4231
|
-
refererUrl = new URL(req.headers.referer);
|
|
4232
|
-
proxyPageUrl = new URL(
|
|
4233
|
-
new URL(req.headers.referer).searchParams.get("page")
|
|
4234
|
-
);
|
|
4235
|
-
} catch (e) {
|
|
4236
|
-
next();
|
|
4237
|
-
return;
|
|
4238
|
-
}
|
|
4239
|
-
if (!refererUrl.pathname.startsWith("/proxy")) {
|
|
4240
|
-
next();
|
|
4241
|
-
return;
|
|
4242
|
-
}
|
|
4243
|
-
if (isAHtmlRequest && !isInternalCMSRoute2(req)) {
|
|
4244
|
-
const encodedPageUrl = encodeURIComponent(
|
|
4245
|
-
`${proxyPageUrl.origin}${req.url}`
|
|
4246
|
-
);
|
|
4247
|
-
res.redirect(`/proxy?page=${encodedPageUrl}`);
|
|
4248
|
-
return;
|
|
4249
|
-
}
|
|
4250
|
-
const urlToProxy = `https://${proxyPageUrl.host}${req.url}`;
|
|
4251
|
-
fetch3(urlToProxy).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
|
|
4252
|
-
}
|
|
4253
|
-
|
|
4254
|
-
// src/routes/proxyServerlessHandler.ts
|
|
4255
|
-
import fetch4 from "node-fetch";
|
|
4256
|
-
var localDomains = ["localhost", "hslocal.net"];
|
|
4257
|
-
function proxyServerlessRequest(req, res, next) {
|
|
4258
|
-
const { method, headers } = req;
|
|
4259
|
-
let refererUrl;
|
|
4260
|
-
let domainToProxy;
|
|
4261
|
-
let body;
|
|
4262
|
-
if (!req.headers.referer) {
|
|
4263
|
-
console.log("unable to proxy serverless request, no referer header found");
|
|
4264
|
-
next();
|
|
4265
|
-
return;
|
|
4266
|
-
}
|
|
4267
|
-
try {
|
|
4268
|
-
refererUrl = new URL(req.headers.referer);
|
|
4269
|
-
const referrerDomain = refererUrl.hostname;
|
|
4270
|
-
if (localDomains.includes(referrerDomain)) {
|
|
4271
|
-
domainToProxy = req.app.locals.domainsToProxy[0];
|
|
4272
|
-
} else {
|
|
4273
|
-
domainToProxy = referrerDomain.replace(/\.localhost|\.hslocal\.net/, "");
|
|
4274
|
-
}
|
|
4275
|
-
} catch (e) {
|
|
4276
|
-
console.log("Error parsing referer URL:", e);
|
|
4277
|
-
next();
|
|
4278
|
-
}
|
|
4279
|
-
if (!domainToProxy) {
|
|
4280
|
-
console.log("No domain to proxy for serverless request, skipping...");
|
|
4281
|
-
next();
|
|
4282
|
-
return;
|
|
4283
|
-
}
|
|
4284
|
-
const urlToProxy = `${refererUrl.protocol}//${domainToProxy}${req.url}`;
|
|
4285
|
-
const contentType = headers["content-type"];
|
|
4286
|
-
const cookie = headers.cookie;
|
|
4287
|
-
if (req.body) {
|
|
4288
|
-
body = JSON.stringify(req.body);
|
|
4289
|
-
}
|
|
4290
|
-
const headersToPass = {
|
|
4291
|
-
...contentType ? { "Content-Type": contentType } : {},
|
|
4292
|
-
...cookie ? { COOKIE: cookie } : {}
|
|
4293
|
-
};
|
|
4294
|
-
const proxyLogArgs = [
|
|
4295
|
-
`attempting to proxy a ${method} serverless request to domain:`,
|
|
4296
|
-
domainToProxy,
|
|
4297
|
-
"for resource:",
|
|
4298
|
-
req.url
|
|
4299
|
-
];
|
|
4300
|
-
if (body) {
|
|
4301
|
-
proxyLogArgs.push("with body:", body);
|
|
4302
|
-
}
|
|
4303
|
-
console.log(...proxyLogArgs);
|
|
4304
|
-
switch (method) {
|
|
4305
|
-
case "POST":
|
|
4306
|
-
case "DELETE":
|
|
4307
|
-
case "PUT":
|
|
4308
|
-
fetch4(urlToProxy, {
|
|
4309
|
-
method,
|
|
4310
|
-
body,
|
|
4311
|
-
headers: headersToPass
|
|
4312
|
-
}).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
|
|
4313
|
-
break;
|
|
4314
|
-
default:
|
|
4315
|
-
fetch4(urlToProxy, {
|
|
4316
|
-
headers: headersToPass
|
|
4317
|
-
}).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
|
|
4318
|
-
}
|
|
4319
|
-
}
|
|
4320
|
-
|
|
4321
|
-
// src/routes/modulePreviewRouteHandler.ts
|
|
4322
|
-
import path10 from "path";
|
|
4323
|
-
import { normalizePath as normalizePath8 } from "vite";
|
|
4324
|
-
async function modulePreviewRouteHandler(request, response) {
|
|
4325
|
-
sendTrackingRequest("view-module-preview-route");
|
|
4326
|
-
const {
|
|
4327
|
-
authedPortalId,
|
|
4328
|
-
authedEnv,
|
|
4329
|
-
authedHublet,
|
|
4330
|
-
webRoot,
|
|
4331
|
-
viteServer,
|
|
4332
|
-
jsRenderingGates,
|
|
4333
|
-
projectName,
|
|
4334
|
-
projectComponentPath,
|
|
4335
|
-
fullHeightPreview
|
|
4336
|
-
} = request.app.locals;
|
|
4337
|
-
const moduleName = request.params.moduleName;
|
|
4338
|
-
const modulePath = normalizePath8(
|
|
4339
|
-
path10.resolve(webRoot, "components/modules/", moduleName)
|
|
4340
|
-
);
|
|
4341
|
-
const PREVIEWER_APP_PARAM = "hsPreviewerApp";
|
|
4342
|
-
let fieldOverrides = {};
|
|
4343
|
-
if (request.method === "POST" && request.body) {
|
|
4344
|
-
if (request.query[PREVIEWER_APP_PARAM] === "module" && request.body.module_data) {
|
|
4345
|
-
fieldOverrides = request.body.module_data;
|
|
4346
|
-
} else {
|
|
4347
|
-
fieldOverrides = request.body;
|
|
4348
|
-
}
|
|
4349
|
-
try {
|
|
4350
|
-
if (typeof fieldOverrides === "string") {
|
|
4351
|
-
const parsedFieldOverrides = JSON.parse(fieldOverrides);
|
|
4352
|
-
if (parsedFieldOverrides && typeof parsedFieldOverrides === "object" && !Array.isArray(parsedFieldOverrides)) {
|
|
4353
|
-
fieldOverrides = parsedFieldOverrides;
|
|
4354
|
-
} else {
|
|
4355
|
-
throw new Error("Parsed field overrides must be an object");
|
|
4356
|
-
}
|
|
4357
|
-
}
|
|
4358
|
-
} catch (e) {
|
|
4359
|
-
console.error(
|
|
4360
|
-
`Error parsing field for module "${moduleName}": ${e.message}`,
|
|
4361
|
-
"\nReceived value:",
|
|
4362
|
-
fieldOverrides
|
|
4363
|
-
);
|
|
4364
|
-
}
|
|
4365
|
-
} else if (request.query.fields) {
|
|
4366
|
-
try {
|
|
4367
|
-
if (typeof request.query.fields === "string") {
|
|
4368
|
-
fieldOverrides = JSON.parse(
|
|
4369
|
-
decodeURIComponent(request.query.fields.replace(/\+/g, "%20"))
|
|
4370
|
-
);
|
|
4371
|
-
}
|
|
4372
|
-
} catch (e) {
|
|
4373
|
-
console.error(
|
|
4374
|
-
`Error parsing field param for module ${moduleName}: ${request.query.fields}`
|
|
4375
|
-
);
|
|
4376
|
-
}
|
|
4377
|
-
}
|
|
4378
|
-
try {
|
|
4379
|
-
const {
|
|
4380
|
-
html: renderedHtml,
|
|
4381
|
-
cssNeeded,
|
|
4382
|
-
renderContext,
|
|
4383
|
-
inlineAssets,
|
|
4384
|
-
globalStylesCss,
|
|
4385
|
-
sectionVariant
|
|
4386
|
-
} = await renderLocalProjectModulePreview(
|
|
4387
|
-
moduleName,
|
|
4388
|
-
authedPortalId,
|
|
4389
|
-
authedEnv,
|
|
4390
|
-
authedHublet,
|
|
4541
|
+
contentId,
|
|
4391
4542
|
webRoot,
|
|
4392
4543
|
viteServer,
|
|
4393
|
-
jsRenderingGates,
|
|
4394
4544
|
projectName,
|
|
4395
4545
|
projectComponentPath,
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
);
|
|
4400
|
-
const baseTemplatePath = packagePath(
|
|
4401
|
-
import.meta.url,
|
|
4402
|
-
"html/baseTemplate.html"
|
|
4403
|
-
);
|
|
4404
|
-
const htmlShell = await createHtmlShellDependingOnRenderContext(
|
|
4405
|
-
baseTemplatePath,
|
|
4406
|
-
request.originalUrl,
|
|
4407
|
-
`Module: ${modulePath}`,
|
|
4408
|
-
renderContext,
|
|
4409
|
-
viteServer,
|
|
4410
|
-
jsRenderingGates
|
|
4411
|
-
);
|
|
4412
|
-
const fullHeightCss = fullHeightPreview ? `<style>html,body{height:100%;width:100%;margin:0}#root{height:100%;width:100%}</style>` : "";
|
|
4413
|
-
const bodyHtml = sectionVariant ? `<div data-section-variant="${sectionVariant}">${renderedHtml}</div>` : renderedHtml;
|
|
4414
|
-
const html = addScriptInjectionBootstrapper(
|
|
4415
|
-
htmlShell.replace(
|
|
4416
|
-
"<!--headend-->",
|
|
4417
|
-
[
|
|
4418
|
-
globalStylesCss,
|
|
4419
|
-
fullHeightCss,
|
|
4420
|
-
cssNeeded,
|
|
4421
|
-
...inlineAssets.map((inlineAsset) => inlineAsset.html)
|
|
4422
|
-
].join("\n")
|
|
4423
|
-
).replace(`<!--ssr-outlet-->`, bodyHtml),
|
|
4424
|
-
request.query
|
|
4546
|
+
jsRenderingGates,
|
|
4547
|
+
urlToProxy,
|
|
4548
|
+
fullOriginalUrl
|
|
4425
4549
|
);
|
|
4426
|
-
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
4427
4550
|
} catch (e) {
|
|
4428
|
-
|
|
4429
|
-
viteServer.ssrFixStacktrace(e);
|
|
4430
|
-
return response.status(500).end(`Error rendering module (${moduleName})
|
|
4431
|
-
|
|
4432
|
-
${e.stack}`);
|
|
4551
|
+
next(e);
|
|
4433
4552
|
}
|
|
4434
4553
|
}
|
|
4435
|
-
var modulePreviewRouteHandler_default = modulePreviewRouteHandler;
|
|
4436
4554
|
|
|
4437
|
-
// src/routes/
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4555
|
+
// src/routes/proxyPageResourceRedirect.ts
|
|
4556
|
+
import fetch2 from "node-fetch";
|
|
4557
|
+
var HCMS_PATH = "/_hcms/";
|
|
4558
|
+
var HS_FS_PATH = "/hs-fs/";
|
|
4559
|
+
var HUB_FS_PATH = "/hubfs/";
|
|
4560
|
+
var isInternalCMSRoute = (req) => req.path.startsWith(HCMS_PATH) || req.path.startsWith(HS_FS_PATH) || req.path.startsWith(HUB_FS_PATH);
|
|
4561
|
+
function proxyPageResourceRedirect(req, res, next) {
|
|
4562
|
+
const isAHtmlRequest = req.accepts().includes("text/html");
|
|
4563
|
+
if (isAHtmlRequest && !isInternalCMSRoute(req) || VALID_PROXY_DOMAIN_SUFFIXES.includes(req.hostname)) {
|
|
4564
|
+
next();
|
|
4444
4565
|
return;
|
|
4445
4566
|
}
|
|
4446
|
-
const
|
|
4447
|
-
const
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
}
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4567
|
+
const domainToProxy = getSubDomainFromValidLocalDomain(req.hostname);
|
|
4568
|
+
const pathToProxy = req.originalUrl;
|
|
4569
|
+
const urlToProxy = `https://${domainToProxy}${pathToProxy}`;
|
|
4570
|
+
if (req.method === "GET") {
|
|
4571
|
+
fetch2(urlToProxy).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
|
|
4572
|
+
} else {
|
|
4573
|
+
const contentType = req.headers["content-type"];
|
|
4574
|
+
const isSendingJSON = contentType && /\bjson\b/.test(req.headers["content-type"].toString());
|
|
4575
|
+
const headerEntries = Object.entries(req.headers).filter(([header]) => {
|
|
4576
|
+
if (
|
|
4577
|
+
// Need to reset these headers for https (and recompression/encoding?) to work properly
|
|
4578
|
+
["host", "origin", "connection", "content-length"].includes(
|
|
4579
|
+
header.toLowerCase()
|
|
4580
|
+
) || header.startsWith("sec-")
|
|
4581
|
+
) {
|
|
4582
|
+
return false;
|
|
4583
|
+
}
|
|
4584
|
+
return true;
|
|
4585
|
+
});
|
|
4586
|
+
const headersToPass = Object.fromEntries(headerEntries);
|
|
4587
|
+
let body = void 0;
|
|
4588
|
+
if (req.body) {
|
|
4589
|
+
if (isSendingJSON) {
|
|
4590
|
+
body = JSON.stringify(req.body);
|
|
4591
|
+
} else {
|
|
4592
|
+
body = req.body.toString();
|
|
4593
|
+
}
|
|
4594
|
+
}
|
|
4595
|
+
fetch2(urlToProxy, {
|
|
4596
|
+
method: req.method,
|
|
4597
|
+
headers: headersToPass,
|
|
4598
|
+
body
|
|
4599
|
+
}).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
|
|
4455
4600
|
}
|
|
4456
|
-
|
|
4457
|
-
|
|
4601
|
+
}
|
|
4602
|
+
|
|
4603
|
+
// src/components/HubLModulesList.tsx
|
|
4604
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
4605
|
+
function HubLModulesList({ modules }) {
|
|
4606
|
+
return modules.length === 0 ? /* @__PURE__ */ jsx6("p", { children: "No modules found." }) : /* @__PURE__ */ jsx6("ul", { children: modules.map((module) => /* @__PURE__ */ jsx6("li", { children: /* @__PURE__ */ jsx6("a", { href: `/hublmodule/${removePreviewPrefix(module.path)}`, children: removePreviewPrefix(module.path) }) }, module.moduleId)) });
|
|
4607
|
+
}
|
|
4608
|
+
|
|
4609
|
+
// src/api/designmanager.ts
|
|
4610
|
+
import { http as hsCliHttp9 } from "@hubspot/local-dev-lib/http";
|
|
4611
|
+
var DESIGN_MANAGER_API_PATH = "designmanager/v1";
|
|
4612
|
+
async function fetchHubLModules(accountId, previewToken, limit = 250) {
|
|
4613
|
+
return (await hsCliHttp9.get(accountId, {
|
|
4614
|
+
url: `${DESIGN_MANAGER_API_PATH}/modules/local-preview?previewToken=${previewToken}&limit=${limit}`
|
|
4615
|
+
})).data;
|
|
4616
|
+
}
|
|
4617
|
+
async function fetchPreviewTemplates(accountId, previewToken, limit = 250) {
|
|
4618
|
+
return (await hsCliHttp9.get(accountId, {
|
|
4619
|
+
url: `${DESIGN_MANAGER_API_PATH}/templates/local-preview?previewToken=${previewToken}&limit=${limit}`
|
|
4620
|
+
})).data;
|
|
4621
|
+
}
|
|
4622
|
+
async function fetchModuleByPath(accountId, path20) {
|
|
4623
|
+
return (await hsCliHttp9.get(accountId, {
|
|
4624
|
+
url: `${DESIGN_MANAGER_API_PATH}/modules/by-path/${path20}?portalId=${accountId}`
|
|
4625
|
+
})).data;
|
|
4626
|
+
}
|
|
4627
|
+
async function fetchTemplateByPath(accountId, path20) {
|
|
4628
|
+
return (await hsCliHttp9.get(accountId, {
|
|
4629
|
+
url: `${DESIGN_MANAGER_API_PATH}/templates/by-path/${path20}?portalId=${accountId}`
|
|
4630
|
+
})).data;
|
|
4631
|
+
}
|
|
4632
|
+
async function fetchModulePageDependencies(accountId, path20) {
|
|
4633
|
+
const url3 = `${DESIGN_MANAGER_API_PATH}/modules/list-pages?modulePath=${path20}`;
|
|
4634
|
+
return (await hsCliHttp9.get(accountId, { url: url3 })).data;
|
|
4635
|
+
}
|
|
4636
|
+
|
|
4637
|
+
// src/components/HubLTemplatesList.tsx
|
|
4638
|
+
import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
4639
|
+
function HubLTemplatesList({ templates }) {
|
|
4640
|
+
return templates.length === 0 ? /* @__PURE__ */ jsxs3("p", { children: [
|
|
4641
|
+
"No templates found ",
|
|
4642
|
+
JSON.stringify(templates)
|
|
4643
|
+
] }) : /* @__PURE__ */ jsx7("ul", { children: templates.filter((t2) => isCodedFile(t2.filename)).map((template) => /* @__PURE__ */ jsx7("li", { children: /* @__PURE__ */ jsx7("a", { href: `/template/${removePreviewPrefix(template.path)}`, children: removePreviewPrefix(template.path) }) }, template.previewKey)) });
|
|
4644
|
+
}
|
|
4645
|
+
var TEMPLATE_EXTENSION_REGEX = new RegExp(/(?<!module)\.html$/);
|
|
4646
|
+
function isCodedFile(filePath) {
|
|
4647
|
+
return TEMPLATE_EXTENSION_REGEX.test(filePath);
|
|
4648
|
+
}
|
|
4649
|
+
|
|
4650
|
+
// src/routes/legacyRouteHandler.tsx
|
|
4651
|
+
import { Fragment, jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
4652
|
+
var legacyRouteHandler = async (request, response, next) => {
|
|
4653
|
+
const domainToProxy = getSubDomainFromValidLocalDomain(request.hostname);
|
|
4654
|
+
if (domainToProxy) {
|
|
4655
|
+
next();
|
|
4458
4656
|
return;
|
|
4459
4657
|
}
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4658
|
+
sendTrackingRequest("view-legacy-home-route");
|
|
4659
|
+
const {
|
|
4660
|
+
authedPortalId,
|
|
4661
|
+
webRoot,
|
|
4662
|
+
storybookEnabled,
|
|
4663
|
+
devServerPort,
|
|
4664
|
+
localPreviewToken
|
|
4665
|
+
} = request.app.locals;
|
|
4666
|
+
const { partialNames } = findAllPartialsInRoot(webRoot);
|
|
4667
|
+
const { moduleNames } = findAllModulesInRoot(webRoot);
|
|
4668
|
+
const hublModuleData = await fetchHubLModules(
|
|
4669
|
+
authedPortalId,
|
|
4670
|
+
localPreviewToken
|
|
4671
|
+
);
|
|
4672
|
+
const hublTemplateData = await fetchPreviewTemplates(
|
|
4673
|
+
authedPortalId,
|
|
4674
|
+
localPreviewToken
|
|
4675
|
+
);
|
|
4676
|
+
const { html: responseHtml } = await renderOnServer(
|
|
4677
|
+
/* @__PURE__ */ jsxs4(Fragment, { children: [
|
|
4678
|
+
storybookEnabled ? /* @__PURE__ */ jsx8("h2", { children: /* @__PURE__ */ jsx8("a", { href: `//storybook.${request.hostname}:${devServerPort}`, children: "Storybook" }) }) : null,
|
|
4679
|
+
/* @__PURE__ */ jsx8("h2", { children: "Partials" }),
|
|
4680
|
+
/* @__PURE__ */ jsx8(PartialsList, { webRoot, partialNames }),
|
|
4681
|
+
/* @__PURE__ */ jsx8("h2", { children: "React modules" }),
|
|
4682
|
+
/* @__PURE__ */ jsx8(ModulesList_default, { webRoot, moduleNames }),
|
|
4683
|
+
/* @__PURE__ */ jsx8("h2", { children: "HubL modules" }),
|
|
4684
|
+
/* @__PURE__ */ jsx8(HubLModulesList, { modules: hublModuleData.objects }),
|
|
4685
|
+
/* @__PURE__ */ jsx8("h2", { children: "HubL templates" }),
|
|
4686
|
+
/* @__PURE__ */ jsx8(HubLTemplatesList, { templates: hublTemplateData.objects })
|
|
4687
|
+
] })
|
|
4688
|
+
);
|
|
4689
|
+
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
4475
4690
|
};
|
|
4476
|
-
var
|
|
4477
|
-
<div>
|
|
4478
|
-
<h2>Module</h2>
|
|
4479
|
-
<p>ERROR</p>
|
|
4480
|
-
</div>
|
|
4481
|
-
`);
|
|
4482
|
-
var buildModuleIndex = () => buildHTMLResponse(`
|
|
4483
|
-
<div>
|
|
4484
|
-
<h2>Module</h2>
|
|
4485
|
-
<p>Please provide a module path in the request</p>
|
|
4486
|
-
</div>
|
|
4487
|
-
`);
|
|
4691
|
+
var legacyRouteHandler_default = legacyRouteHandler;
|
|
4488
4692
|
|
|
4489
|
-
// src/routes/
|
|
4490
|
-
import {
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
var templateRouteHandler = async (request, response) => {
|
|
4494
|
-
sendTrackingRequest("view-template-route");
|
|
4693
|
+
// src/routes/proxyPathPageRouteHandler.tsx
|
|
4694
|
+
import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
4695
|
+
async function proxyPathPageRouteHandler(request, response, next) {
|
|
4696
|
+
sendTrackingRequest("view-proxy-path-route");
|
|
4495
4697
|
const {
|
|
4496
|
-
authedPortalId,
|
|
4497
|
-
localPreviewToken,
|
|
4498
|
-
projectName,
|
|
4499
4698
|
viteServer,
|
|
4500
4699
|
webRoot,
|
|
4700
|
+
projectName,
|
|
4501
4701
|
projectComponentPath,
|
|
4502
4702
|
jsRenderingGates
|
|
4503
4703
|
} = request.app.locals;
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4704
|
+
if (!request.accepts().includes("text/html")) {
|
|
4705
|
+
return response.sendStatus(404);
|
|
4706
|
+
}
|
|
4707
|
+
if (!request.query.page) {
|
|
4708
|
+
const { html: responseHtml } = await renderOnServer(
|
|
4709
|
+
/* @__PURE__ */ jsxs5("div", { children: [
|
|
4710
|
+
/* @__PURE__ */ jsx9("h2", { children: "Local Proxy" }),
|
|
4711
|
+
/* @__PURE__ */ jsxs5("form", { action: "/proxy", children: [
|
|
4712
|
+
/* @__PURE__ */ jsx9("label", { htmlFor: "page", style: { display: "block" }, children: "Page URL" }),
|
|
4713
|
+
/* @__PURE__ */ jsx9(
|
|
4714
|
+
"input",
|
|
4715
|
+
{
|
|
4716
|
+
style: { width: "300px" },
|
|
4717
|
+
name: "page",
|
|
4718
|
+
type: "text",
|
|
4719
|
+
placeholder: "https://somecmspage.com/path"
|
|
4720
|
+
}
|
|
4721
|
+
),
|
|
4722
|
+
/* @__PURE__ */ jsx9("button", { style: { display: "block" }, children: "Proxy" })
|
|
4723
|
+
] })
|
|
4724
|
+
] })
|
|
4725
|
+
);
|
|
4726
|
+
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
4514
4727
|
return;
|
|
4515
4728
|
}
|
|
4516
|
-
|
|
4517
|
-
let templateInfo;
|
|
4729
|
+
let proxyPageUrl;
|
|
4518
4730
|
try {
|
|
4519
|
-
|
|
4520
|
-
} catch (
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
);
|
|
4524
|
-
}
|
|
4525
|
-
if (!templateInfo || !("previewKey" in templateInfo)) {
|
|
4526
|
-
response.status(500).set({ "Content-Type": "text/html" }).end(buildErrorIndex2());
|
|
4731
|
+
proxyPageUrl = new URL(request.query.page);
|
|
4732
|
+
} catch (e) {
|
|
4733
|
+
const message = "Please provide a valid page query parameter, e.g., http://localhost:3000/proxy?page=https://yourdomain.com/path";
|
|
4734
|
+
consoleWarn(message);
|
|
4735
|
+
response.status(400).send(message);
|
|
4527
4736
|
return;
|
|
4528
4737
|
}
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
hsLocalProxyProject: localProxyProject,
|
|
4535
|
-
localProxySchemaVersion: "2",
|
|
4536
|
-
hsLoginVerifyDisabled: `${true}`,
|
|
4537
|
-
hsCacheBuster: Date.now().toString(),
|
|
4538
|
-
...request.query
|
|
4539
|
-
};
|
|
4540
|
-
const previewUrl = getPreviewUrl(request, params);
|
|
4541
|
-
const fullOriginalUrl = `${request.protocol}://${request.get("host")}${request.originalUrl}`;
|
|
4738
|
+
if (proxyPageUrl.searchParams.has("hs_preview")) {
|
|
4739
|
+
const message = `Can't make a proxy request, you cannot proxy URLs that include internal query params like hs_preview`;
|
|
4740
|
+
consoleWarn(message);
|
|
4741
|
+
return response.status(400).send(message);
|
|
4742
|
+
}
|
|
4542
4743
|
try {
|
|
4543
|
-
const
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
{},
|
|
4547
|
-
jsRenderingGates
|
|
4548
|
-
);
|
|
4549
|
-
const pageHtml = addRefreshScript(result);
|
|
4550
|
-
const finalHtml = pageHtml.replace(
|
|
4551
|
-
HUBSPOT_PREVIEW_BASE_TAG_REGEX,
|
|
4552
|
-
'<base href="/" />'
|
|
4744
|
+
const { portalId, contentId, hublet } = await fetchContentMetadata(
|
|
4745
|
+
proxyPageUrl.href,
|
|
4746
|
+
request.app.locals.authedPortalId
|
|
4553
4747
|
);
|
|
4554
|
-
|
|
4748
|
+
await proxySpecificPage(
|
|
4749
|
+
request,
|
|
4555
4750
|
response,
|
|
4556
|
-
|
|
4751
|
+
portalId,
|
|
4752
|
+
hublet,
|
|
4753
|
+
contentId,
|
|
4557
4754
|
webRoot,
|
|
4558
|
-
fullOriginalUrl,
|
|
4559
|
-
environmentConfig,
|
|
4560
4755
|
viteServer,
|
|
4561
4756
|
projectName,
|
|
4562
4757
|
projectComponentPath,
|
|
4563
4758
|
jsRenderingGates,
|
|
4564
|
-
|
|
4759
|
+
proxyPageUrl.href,
|
|
4760
|
+
proxyPageUrl.href
|
|
4565
4761
|
);
|
|
4566
|
-
} catch (
|
|
4567
|
-
|
|
4568
|
-
response.status(500).set({ "Content-Type": "text/html" }).end(buildErrorIndex2());
|
|
4762
|
+
} catch (e) {
|
|
4763
|
+
next(e);
|
|
4569
4764
|
}
|
|
4570
|
-
};
|
|
4571
|
-
function buildErrorIndex2() {
|
|
4572
|
-
return buildHTMLResponse(`
|
|
4573
|
-
<div>
|
|
4574
|
-
<h2>Error</h2>
|
|
4575
|
-
<p>Failed to fetch template data.</p>
|
|
4576
|
-
</div>
|
|
4577
|
-
`);
|
|
4578
|
-
}
|
|
4579
|
-
function buildTemplateIndex() {
|
|
4580
|
-
return buildHTMLResponse(`
|
|
4581
|
-
<div>
|
|
4582
|
-
<h2>Template</h2>
|
|
4583
|
-
<p>Please provide a template path in the request</p>
|
|
4584
|
-
</div>
|
|
4585
|
-
`);
|
|
4586
4765
|
}
|
|
4587
4766
|
|
|
4588
|
-
// src/routes/
|
|
4589
|
-
import
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
return "xdg-open";
|
|
4599
|
-
}
|
|
4600
|
-
}
|
|
4601
|
-
async function handleGetModulePages(req, res, next) {
|
|
4602
|
-
const { path: path18, portalId } = req.query;
|
|
4603
|
-
if (!path18 || !portalId) {
|
|
4604
|
-
return res.status(400).json({ error: "Missing required parameters" });
|
|
4605
|
-
}
|
|
4767
|
+
// src/routes/proxyPathPageResourceRedirect.ts
|
|
4768
|
+
import fetch3 from "node-fetch";
|
|
4769
|
+
var HCMS_PATH2 = "/_hcms/";
|
|
4770
|
+
var HS_FS_PATH2 = "/hs-fs/";
|
|
4771
|
+
var HUB_FS_PATH2 = "/hubfs/";
|
|
4772
|
+
var isInternalCMSRoute2 = (req) => req.path.startsWith(HCMS_PATH2) || req.path.startsWith(HS_FS_PATH2) || req.path.startsWith(HUB_FS_PATH2);
|
|
4773
|
+
function proxyPathPageResourceRedirect(req, res, next) {
|
|
4774
|
+
const isAHtmlRequest = req.accepts().includes("text/html");
|
|
4775
|
+
let proxyPageUrl;
|
|
4776
|
+
let refererUrl;
|
|
4606
4777
|
try {
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
path18
|
|
4778
|
+
refererUrl = new URL(req.headers.referer);
|
|
4779
|
+
proxyPageUrl = new URL(
|
|
4780
|
+
new URL(req.headers.referer).searchParams.get("page")
|
|
4611
4781
|
);
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
}
|
|
4616
|
-
}
|
|
4617
|
-
function handleOpenFile(req, res, next) {
|
|
4618
|
-
const { path: path18 } = req.query;
|
|
4619
|
-
if (!path18) {
|
|
4620
|
-
return res.status(400).json({ error: "Missing required parameters" });
|
|
4621
|
-
}
|
|
4622
|
-
try {
|
|
4623
|
-
sendTrackingRequest("handle-open-file");
|
|
4624
|
-
const command = getOpenCommand();
|
|
4625
|
-
spawn(command, [path18], { detached: true }).unref();
|
|
4626
|
-
res.sendStatus(200);
|
|
4627
|
-
} catch (err) {
|
|
4628
|
-
next(err);
|
|
4629
|
-
}
|
|
4630
|
-
}
|
|
4631
|
-
function createAppServerAPIRoutes() {
|
|
4632
|
-
const router = Router();
|
|
4633
|
-
router.get("/module-pages", handleGetModulePages);
|
|
4634
|
-
router.get("/open-file", handleOpenFile);
|
|
4635
|
-
return router;
|
|
4636
|
-
}
|
|
4637
|
-
var createAppServerAPIRoutes_default = createAppServerAPIRoutes;
|
|
4638
|
-
|
|
4639
|
-
// src/routes/appServerRouteHandler.ts
|
|
4640
|
-
import fs5 from "node:fs/promises";
|
|
4641
|
-
import path12 from "path";
|
|
4642
|
-
import { pathToFileURL } from "url";
|
|
4643
|
-
|
|
4644
|
-
// src/lib/getDevServerUIData.ts
|
|
4645
|
-
import path11 from "path";
|
|
4646
|
-
import { normalizePath as normalizePath9 } from "vite";
|
|
4647
|
-
|
|
4648
|
-
// src/api/project.ts
|
|
4649
|
-
import { http as hsCliHttp9 } from "@hubspot/local-dev-lib/http";
|
|
4650
|
-
var DEVELOPER_PROJECTS_API_PATH = "/developer/projects/v1";
|
|
4651
|
-
async function fetchProjectByName(accountId, projectName) {
|
|
4652
|
-
return (await hsCliHttp9.get(accountId, {
|
|
4653
|
-
url: `${DEVELOPER_PROJECTS_API_PATH}/by-name/${projectName}`
|
|
4654
|
-
})).data;
|
|
4655
|
-
}
|
|
4656
|
-
|
|
4657
|
-
// src/lib/getDevServerUIData.ts
|
|
4658
|
-
import fs4 from "node:fs";
|
|
4659
|
-
var templateTypeMap = {
|
|
4660
|
-
// Standard templates
|
|
4661
|
-
4: "Page",
|
|
4662
|
-
2: "Email",
|
|
4663
|
-
42: "Blog Listing",
|
|
4664
|
-
41: "Blog Post",
|
|
4665
|
-
6: "Blog (Deprecated)",
|
|
4666
|
-
// Global partials
|
|
4667
|
-
38: "Global Partial",
|
|
4668
|
-
18: "Global Group",
|
|
4669
|
-
// System templates
|
|
4670
|
-
11: "Error Page",
|
|
4671
|
-
19: "Password Prompt",
|
|
4672
|
-
29: "Membership Login",
|
|
4673
|
-
30: "Membership Register",
|
|
4674
|
-
31: "Membership Reset",
|
|
4675
|
-
32: "Membership Reset Request",
|
|
4676
|
-
12: "Subscription Preferences",
|
|
4677
|
-
14: "Backup Unsubscribe",
|
|
4678
|
-
27: "Search Results"
|
|
4679
|
-
};
|
|
4680
|
-
function mapReactModules(modules, themeWebRoot, appViteServer) {
|
|
4681
|
-
return Promise.all(
|
|
4682
|
-
modules.moduleNames.map(async (name, index) => {
|
|
4683
|
-
const modulePath = normalizePath9(
|
|
4684
|
-
path11.resolve(themeWebRoot, "components/modules/", name)
|
|
4685
|
-
);
|
|
4686
|
-
const fieldsJson = await renderModuleFieldsJson_default(
|
|
4687
|
-
appViteServer,
|
|
4688
|
-
modulePath
|
|
4689
|
-
);
|
|
4690
|
-
return {
|
|
4691
|
-
name,
|
|
4692
|
-
type: "react" /* REACT */,
|
|
4693
|
-
subPath: modules.moduleSubpaths[index],
|
|
4694
|
-
nameWithExtension: modules.moduleNamesWithExtension[index],
|
|
4695
|
-
extension: modules.moduleExtensions[index],
|
|
4696
|
-
fieldsJson
|
|
4697
|
-
};
|
|
4698
|
-
})
|
|
4699
|
-
);
|
|
4700
|
-
}
|
|
4701
|
-
function normalizeHubLModules(modules, projectName) {
|
|
4702
|
-
return modules.map((module) => {
|
|
4703
|
-
const subPath = projectName ? `${module.path.split("/@projects/")[1] || module.path}` : removePreviewPrefix(module.path);
|
|
4704
|
-
return {
|
|
4705
|
-
name: module.name,
|
|
4706
|
-
type: "hubl" /* HUBL */,
|
|
4707
|
-
subPath,
|
|
4708
|
-
nameWithExtension: module.filename,
|
|
4709
|
-
fieldsJson: module.fields
|
|
4710
|
-
};
|
|
4711
|
-
});
|
|
4712
|
-
}
|
|
4713
|
-
function normalizePartialsData(partialData) {
|
|
4714
|
-
return partialData.partialNames.map((name, index) => ({
|
|
4715
|
-
name,
|
|
4716
|
-
subPath: partialData.partialSubpaths[index]
|
|
4717
|
-
}));
|
|
4718
|
-
}
|
|
4719
|
-
function normalizeTemplatesData(templates, projectName) {
|
|
4720
|
-
return templates.filter((template) => template.templateType in templateTypeMap).map((template) => {
|
|
4721
|
-
const subPath = projectName ? `@projects/${template.path.split("/@projects/")[1] || template.path}` : removePreviewPrefix(template.path);
|
|
4722
|
-
return {
|
|
4723
|
-
name: template.displayName || template.label,
|
|
4724
|
-
subPath,
|
|
4725
|
-
templateTypeLabel: templateTypeMap[template.templateType]
|
|
4726
|
-
};
|
|
4727
|
-
});
|
|
4728
|
-
}
|
|
4729
|
-
function detectPackageManager(projectRoot) {
|
|
4730
|
-
if (fs4.existsSync(path11.join(projectRoot, "yarn.lock")))
|
|
4731
|
-
return "yarn";
|
|
4732
|
-
if (fs4.existsSync(path11.join(projectRoot, "pnpm-lock.yaml")))
|
|
4733
|
-
return "pnpm";
|
|
4734
|
-
return "npm";
|
|
4735
|
-
}
|
|
4736
|
-
async function getDevServerUIData(appLocals) {
|
|
4737
|
-
const {
|
|
4738
|
-
themeWebRoot,
|
|
4739
|
-
authedEnv,
|
|
4740
|
-
authedPortalId,
|
|
4741
|
-
projectName,
|
|
4742
|
-
localPreviewToken,
|
|
4743
|
-
webRootProjectComponentFolder,
|
|
4744
|
-
sslEnabled,
|
|
4745
|
-
fieldBuilderEnabled,
|
|
4746
|
-
appViteServer
|
|
4747
|
-
} = appLocals;
|
|
4748
|
-
const modulesData = findAllModulesInRoot(themeWebRoot);
|
|
4749
|
-
const partialsData = findAllPartialsInRoot(themeWebRoot);
|
|
4750
|
-
let packageJson = { scripts: {} };
|
|
4751
|
-
let packageManager = "";
|
|
4752
|
-
let cliCommands = [];
|
|
4753
|
-
let reactModules = [];
|
|
4754
|
-
if (projectName) {
|
|
4755
|
-
packageJson = getPackageJson(themeWebRoot);
|
|
4756
|
-
packageManager = detectPackageManager(themeWebRoot);
|
|
4757
|
-
const runCommand = packageManager === "yarn" ? "yarn" : `${packageManager} run`;
|
|
4758
|
-
cliCommands = projectName ? Object.entries((packageJson == null ? void 0 : packageJson.scripts) || {}).map(
|
|
4759
|
-
([scriptName, description]) => ({
|
|
4760
|
-
scriptName,
|
|
4761
|
-
description,
|
|
4762
|
-
runCommand: `${runCommand} ${scriptName}`
|
|
4763
|
-
})
|
|
4764
|
-
) : [];
|
|
4765
|
-
reactModules = projectName && appViteServer ? await mapReactModules(modulesData, themeWebRoot, appViteServer) : [];
|
|
4782
|
+
} catch (e) {
|
|
4783
|
+
next();
|
|
4784
|
+
return;
|
|
4766
4785
|
}
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
if (
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
fetchHubLModules(authedPortalId, localPreviewToken),
|
|
4775
|
-
fetchPreviewTemplates(authedPortalId, localPreviewToken),
|
|
4776
|
-
projectName ? fetchProjectByName(authedPortalId, projectName) : Promise.resolve(null)
|
|
4777
|
-
];
|
|
4778
|
-
[hubLModuleData, hubLTemplateData, projectData] = await Promise.all(dataFetchingPromises);
|
|
4779
|
-
} catch (e) {
|
|
4780
|
-
console.warn("Error fetching data:", e);
|
|
4781
|
-
}
|
|
4782
|
-
normalizedHubLModules = normalizeHubLModules(
|
|
4783
|
-
(hubLModuleData == null ? void 0 : hubLModuleData.objects) || [],
|
|
4784
|
-
projectName
|
|
4786
|
+
if (!refererUrl.pathname.startsWith("/proxy")) {
|
|
4787
|
+
next();
|
|
4788
|
+
return;
|
|
4789
|
+
}
|
|
4790
|
+
if (isAHtmlRequest && !isInternalCMSRoute2(req)) {
|
|
4791
|
+
const encodedPageUrl = encodeURIComponent(
|
|
4792
|
+
`${proxyPageUrl.origin}${req.url}`
|
|
4785
4793
|
);
|
|
4794
|
+
res.redirect(`/proxy?page=${encodedPageUrl}`);
|
|
4795
|
+
return;
|
|
4786
4796
|
}
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
authedEnv,
|
|
4790
|
-
projectName,
|
|
4791
|
-
modulesData: reactModules,
|
|
4792
|
-
partialsData: normalizePartialsData(partialsData),
|
|
4793
|
-
hubLModules: normalizedHubLModules || [],
|
|
4794
|
-
hubLTemplates: normalizeTemplatesData(
|
|
4795
|
-
(hubLTemplateData == null ? void 0 : hubLTemplateData.objects) || [],
|
|
4796
|
-
projectName
|
|
4797
|
-
),
|
|
4798
|
-
themeWebRoot,
|
|
4799
|
-
webRootProjectComponentFolder,
|
|
4800
|
-
cliCommands,
|
|
4801
|
-
sslEnabled,
|
|
4802
|
-
projectData,
|
|
4803
|
-
fieldBuilderEnabled
|
|
4804
|
-
};
|
|
4797
|
+
const urlToProxy = `https://${proxyPageUrl.host}${req.url}`;
|
|
4798
|
+
fetch3(urlToProxy).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
|
|
4805
4799
|
}
|
|
4806
4800
|
|
|
4807
|
-
// src/routes/
|
|
4808
|
-
|
|
4809
|
-
var
|
|
4801
|
+
// src/routes/proxyServerlessHandler.ts
|
|
4802
|
+
import fetch4 from "node-fetch";
|
|
4803
|
+
var localDomains = ["localhost", "hslocal.net"];
|
|
4804
|
+
function proxyServerlessRequest(req, res, next) {
|
|
4805
|
+
const { method, headers } = req;
|
|
4806
|
+
let refererUrl;
|
|
4807
|
+
let domainToProxy;
|
|
4808
|
+
let body;
|
|
4809
|
+
if (!req.headers.referer) {
|
|
4810
|
+
console.log("unable to proxy serverless request, no referer header found");
|
|
4811
|
+
next();
|
|
4812
|
+
return;
|
|
4813
|
+
}
|
|
4810
4814
|
try {
|
|
4811
|
-
|
|
4812
|
-
const
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
const url3 = req.originalUrl.replace("/", "");
|
|
4816
|
-
const templatePath = path12.join(appWebRoot, "index.html");
|
|
4817
|
-
const serverEntryPath = isProd ? path12.join(appWebRoot, "server/serverEntry.js") : path12.join(appWebRoot, "serverEntry.tsx");
|
|
4818
|
-
let render;
|
|
4819
|
-
let template = await fs5.readFile(path12.join(templatePath), "utf-8");
|
|
4820
|
-
if (isProd) {
|
|
4821
|
-
const { render: ssrRender } = await import(pathToFileURL(serverEntryPath).href);
|
|
4822
|
-
render = ssrRender;
|
|
4815
|
+
refererUrl = new URL(req.headers.referer);
|
|
4816
|
+
const referrerDomain = refererUrl.hostname;
|
|
4817
|
+
if (localDomains.includes(referrerDomain)) {
|
|
4818
|
+
domainToProxy = req.app.locals.domainsToProxy[0];
|
|
4823
4819
|
} else {
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4820
|
+
domainToProxy = referrerDomain.replace(/\.localhost|\.hslocal\.net/, "");
|
|
4821
|
+
}
|
|
4822
|
+
} catch (e) {
|
|
4823
|
+
console.log("Error parsing referer URL:", e);
|
|
4824
|
+
next();
|
|
4825
|
+
}
|
|
4826
|
+
if (!domainToProxy) {
|
|
4827
|
+
console.log("No domain to proxy for serverless request, skipping...");
|
|
4828
|
+
next();
|
|
4829
|
+
return;
|
|
4830
|
+
}
|
|
4831
|
+
const urlToProxy = `${refererUrl.protocol}//${domainToProxy}${req.url}`;
|
|
4832
|
+
const contentType = headers["content-type"];
|
|
4833
|
+
const cookie = headers.cookie;
|
|
4834
|
+
if (req.body) {
|
|
4835
|
+
body = JSON.stringify(req.body);
|
|
4836
|
+
}
|
|
4837
|
+
const headersToPass = {
|
|
4838
|
+
...contentType ? { "Content-Type": contentType } : {},
|
|
4839
|
+
...cookie ? { COOKIE: cookie } : {}
|
|
4840
|
+
};
|
|
4841
|
+
const proxyLogArgs = [
|
|
4842
|
+
`attempting to proxy a ${method} serverless request to domain:`,
|
|
4843
|
+
domainToProxy,
|
|
4844
|
+
"for resource:",
|
|
4845
|
+
req.url
|
|
4846
|
+
];
|
|
4847
|
+
if (body) {
|
|
4848
|
+
proxyLogArgs.push("with body:", body);
|
|
4849
|
+
}
|
|
4850
|
+
console.log(...proxyLogArgs);
|
|
4851
|
+
switch (method) {
|
|
4852
|
+
case "POST":
|
|
4853
|
+
case "DELETE":
|
|
4854
|
+
case "PUT":
|
|
4855
|
+
fetch4(urlToProxy, {
|
|
4856
|
+
method,
|
|
4857
|
+
body,
|
|
4858
|
+
headers: headersToPass
|
|
4859
|
+
}).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
|
|
4860
|
+
break;
|
|
4861
|
+
default:
|
|
4862
|
+
fetch4(urlToProxy, {
|
|
4863
|
+
headers: headersToPass
|
|
4864
|
+
}).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
|
|
4865
|
+
}
|
|
4866
|
+
}
|
|
4867
|
+
|
|
4868
|
+
// src/routes/modulePreviewRouteHandler.ts
|
|
4869
|
+
import path13 from "path";
|
|
4870
|
+
import { normalizePath as normalizePath8 } from "vite";
|
|
4871
|
+
async function modulePreviewRouteHandler(request, response) {
|
|
4872
|
+
sendTrackingRequest("view-module-preview-route");
|
|
4873
|
+
const {
|
|
4874
|
+
authedPortalId,
|
|
4875
|
+
authedEnv,
|
|
4876
|
+
authedHublet,
|
|
4877
|
+
webRoot,
|
|
4878
|
+
viteServer,
|
|
4879
|
+
jsRenderingGates,
|
|
4880
|
+
projectName,
|
|
4881
|
+
projectComponentPath,
|
|
4882
|
+
fullHeightPreview
|
|
4883
|
+
} = request.app.locals;
|
|
4884
|
+
const moduleName = request.params.moduleName;
|
|
4885
|
+
const modulePath = normalizePath8(
|
|
4886
|
+
path13.resolve(webRoot, "components/modules/", moduleName)
|
|
4887
|
+
);
|
|
4888
|
+
const PREVIEWER_APP_PARAM = "hsPreviewerApp";
|
|
4889
|
+
let fieldOverrides = {};
|
|
4890
|
+
if (request.method === "POST" && request.body) {
|
|
4891
|
+
if (request.query[PREVIEWER_APP_PARAM] === "module" && request.body.module_data) {
|
|
4892
|
+
fieldOverrides = request.body.module_data;
|
|
4893
|
+
} else {
|
|
4894
|
+
fieldOverrides = request.body;
|
|
4895
|
+
}
|
|
4896
|
+
try {
|
|
4897
|
+
if (typeof fieldOverrides === "string") {
|
|
4898
|
+
const parsedFieldOverrides = JSON.parse(fieldOverrides);
|
|
4899
|
+
if (parsedFieldOverrides && typeof parsedFieldOverrides === "object" && !Array.isArray(parsedFieldOverrides)) {
|
|
4900
|
+
fieldOverrides = parsedFieldOverrides;
|
|
4901
|
+
} else {
|
|
4902
|
+
throw new Error("Parsed field overrides must be an object");
|
|
4903
|
+
}
|
|
4904
|
+
}
|
|
4905
|
+
} catch (e) {
|
|
4906
|
+
console.error(
|
|
4907
|
+
`Error parsing field for module "${moduleName}": ${e.message}`,
|
|
4908
|
+
"\nReceived value:",
|
|
4909
|
+
fieldOverrides
|
|
4910
|
+
);
|
|
4911
|
+
}
|
|
4912
|
+
} else if (request.query.fields) {
|
|
4913
|
+
try {
|
|
4914
|
+
if (typeof request.query.fields === "string") {
|
|
4915
|
+
fieldOverrides = JSON.parse(
|
|
4916
|
+
decodeURIComponent(request.query.fields.replace(/\+/g, "%20"))
|
|
4827
4917
|
);
|
|
4828
4918
|
}
|
|
4829
|
-
|
|
4830
|
-
|
|
4919
|
+
} catch (e) {
|
|
4920
|
+
console.error(
|
|
4921
|
+
`Error parsing field param for module ${moduleName}: ${request.query.fields}`
|
|
4922
|
+
);
|
|
4831
4923
|
}
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4924
|
+
}
|
|
4925
|
+
try {
|
|
4926
|
+
const {
|
|
4927
|
+
html: renderedHtml,
|
|
4928
|
+
cssNeeded,
|
|
4929
|
+
renderContext,
|
|
4930
|
+
inlineAssets,
|
|
4931
|
+
globalStylesCss,
|
|
4932
|
+
sectionVariant
|
|
4933
|
+
} = await renderLocalProjectModulePreview(
|
|
4934
|
+
moduleName,
|
|
4935
|
+
authedPortalId,
|
|
4936
|
+
authedEnv,
|
|
4937
|
+
authedHublet,
|
|
4938
|
+
webRoot,
|
|
4939
|
+
viteServer,
|
|
4940
|
+
jsRenderingGates,
|
|
4941
|
+
projectName,
|
|
4942
|
+
projectComponentPath,
|
|
4943
|
+
fullOriginalUrlFromRequest(request),
|
|
4944
|
+
request.get("COOKIE"),
|
|
4945
|
+
fieldOverrides
|
|
4838
4946
|
);
|
|
4839
|
-
|
|
4947
|
+
const baseTemplatePath = packagePath(
|
|
4948
|
+
import.meta.url,
|
|
4949
|
+
"html/baseTemplate.html"
|
|
4950
|
+
);
|
|
4951
|
+
const htmlShell = await createHtmlShellDependingOnRenderContext(
|
|
4952
|
+
baseTemplatePath,
|
|
4953
|
+
request.originalUrl,
|
|
4954
|
+
`Module: ${modulePath}`,
|
|
4955
|
+
renderContext,
|
|
4956
|
+
viteServer,
|
|
4957
|
+
jsRenderingGates
|
|
4958
|
+
);
|
|
4959
|
+
const fullHeightCss = fullHeightPreview ? `<style>html,body{height:100%;width:100%;margin:0}#root{height:100%;width:100%}</style>` : "";
|
|
4960
|
+
const bodyHtml = sectionVariant ? `<div data-section-variant="${sectionVariant}">${renderedHtml}</div>` : renderedHtml;
|
|
4961
|
+
const html = addScriptInjectionBootstrapper(
|
|
4962
|
+
htmlShell.replace(
|
|
4963
|
+
"<!--headend-->",
|
|
4964
|
+
[
|
|
4965
|
+
globalStylesCss,
|
|
4966
|
+
fullHeightCss,
|
|
4967
|
+
cssNeeded,
|
|
4968
|
+
...inlineAssets.map((inlineAsset) => inlineAsset.html)
|
|
4969
|
+
].join("\n")
|
|
4970
|
+
).replace(`<!--ssr-outlet-->`, bodyHtml),
|
|
4971
|
+
request.query
|
|
4972
|
+
);
|
|
4973
|
+
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
4840
4974
|
} catch (e) {
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4975
|
+
console.error(e);
|
|
4976
|
+
viteServer.ssrFixStacktrace(e);
|
|
4977
|
+
return response.status(500).end(`Error rendering module (${moduleName})
|
|
4978
|
+
|
|
4979
|
+
${e.stack}`);
|
|
4980
|
+
}
|
|
4981
|
+
}
|
|
4982
|
+
var modulePreviewRouteHandler_default = modulePreviewRouteHandler;
|
|
4983
|
+
|
|
4984
|
+
// src/routes/hublModuleRouteHandler.ts
|
|
4985
|
+
var hublModuleRouteHandler = async (request, response) => {
|
|
4986
|
+
sendTrackingRequest("view-hubl-module-route");
|
|
4987
|
+
const { authedPortalId, localPreviewToken, projectName } = request.app.locals;
|
|
4988
|
+
const { modulePath } = request.params;
|
|
4989
|
+
if (!modulePath) {
|
|
4990
|
+
response.status(200).set({ "Content-Type": "text/html" }).end(buildModuleIndex());
|
|
4991
|
+
return;
|
|
4992
|
+
}
|
|
4993
|
+
const projectPrefix = projectName ? "@projects/" : "";
|
|
4994
|
+
const calculatedPath = `@preview/${localPreviewToken}/${projectPrefix}${modulePath}.module`;
|
|
4995
|
+
let customWidgetInfo;
|
|
4996
|
+
try {
|
|
4997
|
+
customWidgetInfo = await fetchModuleByPath(authedPortalId, calculatedPath);
|
|
4998
|
+
} catch (err) {
|
|
4999
|
+
console.error(`Failed to fetch module data for ${calculatedPath}: ${err}`);
|
|
5000
|
+
response.status(500).set({ "Content-Type": "text/html" }).end(buildErrorIndex(err));
|
|
5001
|
+
return;
|
|
5002
|
+
}
|
|
5003
|
+
if (!customWidgetInfo || !("moduleId" in customWidgetInfo)) {
|
|
5004
|
+
response.status(500).set({ "Content-Type": "text/html" }).end(buildErrorIndex(null));
|
|
5005
|
+
return;
|
|
5006
|
+
}
|
|
5007
|
+
const params = {
|
|
5008
|
+
module_id: customWidgetInfo.moduleId,
|
|
5009
|
+
hs_preview_key: customWidgetInfo.previewKey,
|
|
5010
|
+
updated: Date.now(),
|
|
5011
|
+
...request.query
|
|
5012
|
+
};
|
|
5013
|
+
const previewUrl = getPreviewUrl(request, params);
|
|
5014
|
+
try {
|
|
5015
|
+
const result = await signedGet(authedPortalId, previewUrl, {});
|
|
5016
|
+
const html = addRefreshScript(result);
|
|
5017
|
+
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
5018
|
+
} catch (err) {
|
|
5019
|
+
console.log(err);
|
|
5020
|
+
response.status(500).set({ "Content-Type": "text/html" }).end(buildErrorIndex(err));
|
|
4845
5021
|
}
|
|
4846
5022
|
};
|
|
4847
|
-
var
|
|
5023
|
+
var buildErrorIndex = (err) => buildHTMLResponse(`
|
|
5024
|
+
<div>
|
|
5025
|
+
<h2>Module</h2>
|
|
5026
|
+
<p>ERROR</p>
|
|
5027
|
+
</div>
|
|
5028
|
+
`);
|
|
5029
|
+
var buildModuleIndex = () => buildHTMLResponse(`
|
|
5030
|
+
<div>
|
|
5031
|
+
<h2>Module</h2>
|
|
5032
|
+
<p>Please provide a module path in the request</p>
|
|
5033
|
+
</div>
|
|
5034
|
+
`);
|
|
4848
5035
|
|
|
4849
|
-
// src/routes/
|
|
4850
|
-
import
|
|
4851
|
-
|
|
4852
|
-
var
|
|
4853
|
-
|
|
4854
|
-
);
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
5036
|
+
// src/routes/hublTemplateRouteHandler.ts
|
|
5037
|
+
import { buildStaticEnvConfig as buildStaticEnvConfig5 } from "@hubspot/cms-components";
|
|
5038
|
+
import { getConfigAccountEnvironment } from "@hubspot/local-dev-lib/config";
|
|
5039
|
+
var HUBSPOT_PREVIEW_BASE_TAG_REGEX = /<base\s+[^>]*href=["'][^"']*(?:hubspotpreview(?:qa)?)[^"']*["'][^>]*>/i;
|
|
5040
|
+
var templateRouteHandler = async (request, response) => {
|
|
5041
|
+
sendTrackingRequest("view-template-route");
|
|
5042
|
+
const {
|
|
5043
|
+
authedPortalId,
|
|
5044
|
+
localPreviewToken,
|
|
5045
|
+
projectName,
|
|
5046
|
+
viteServer,
|
|
5047
|
+
webRoot,
|
|
5048
|
+
projectComponentPath,
|
|
5049
|
+
jsRenderingGates
|
|
5050
|
+
} = request.app.locals;
|
|
5051
|
+
const environmentConfig = buildStaticEnvConfig5(
|
|
5052
|
+
authedPortalId,
|
|
5053
|
+
"na1",
|
|
5054
|
+
getConfigAccountEnvironment(authedPortalId),
|
|
5055
|
+
false,
|
|
5056
|
+
jsRenderingGates
|
|
5057
|
+
);
|
|
5058
|
+
const { templatePath } = request.params;
|
|
5059
|
+
if (!templatePath) {
|
|
5060
|
+
response.status(200).set({ "Content-Type": "text/html" }).end(buildTemplateIndex());
|
|
5061
|
+
return;
|
|
5062
|
+
}
|
|
5063
|
+
const calculatedPath = `@preview/${localPreviewToken}/${templatePath}`;
|
|
5064
|
+
let templateInfo;
|
|
5065
|
+
try {
|
|
5066
|
+
templateInfo = await fetchTemplateByPath(authedPortalId, calculatedPath);
|
|
5067
|
+
} catch (err) {
|
|
5068
|
+
console.error(
|
|
5069
|
+
`Failed to fetch template data for ${calculatedPath}: ${err}`
|
|
4873
5070
|
);
|
|
4874
5071
|
}
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
devServerApp.use("/assets", expressStatic(distAssetsPath));
|
|
4879
|
-
} else if (appViteServer) {
|
|
4880
|
-
devServerApp.use("/local", appViteServer.middlewares);
|
|
5072
|
+
if (!templateInfo || !("previewKey" in templateInfo)) {
|
|
5073
|
+
response.status(500).set({ "Content-Type": "text/html" }).end(buildErrorIndex2());
|
|
5074
|
+
return;
|
|
4881
5075
|
}
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
5076
|
+
const localProxyProject = process.env.DEFAULT_MODULE_PATH_REWRITE ? `@default-modules/${projectName}` : `@projects/${projectName}`;
|
|
5077
|
+
const params = {
|
|
5078
|
+
template_file_path: calculatedPath,
|
|
5079
|
+
hs_preview_key: templateInfo.previewKey,
|
|
5080
|
+
localPreviewToken,
|
|
5081
|
+
hsLocalProxyProject: localProxyProject,
|
|
5082
|
+
localProxySchemaVersion: "2",
|
|
5083
|
+
hsLoginVerifyDisabled: `${true}`,
|
|
5084
|
+
hsCacheBuster: Date.now().toString(),
|
|
5085
|
+
...request.query
|
|
5086
|
+
};
|
|
5087
|
+
const previewUrl = getPreviewUrl(request, params);
|
|
5088
|
+
const fullOriginalUrl = `${request.protocol}://${request.get("host")}${request.originalUrl}`;
|
|
5089
|
+
try {
|
|
5090
|
+
const result = await signedGet(authedPortalId, previewUrl, {});
|
|
5091
|
+
const pageHtml = addRefreshScript(result);
|
|
5092
|
+
const finalHtml = pageHtml.replace(
|
|
5093
|
+
HUBSPOT_PREVIEW_BASE_TAG_REGEX,
|
|
5094
|
+
'<base href="/" />'
|
|
5095
|
+
);
|
|
5096
|
+
infillReactModulesAndWriteResponse(
|
|
5097
|
+
response,
|
|
5098
|
+
finalHtml,
|
|
5099
|
+
webRoot,
|
|
5100
|
+
fullOriginalUrl,
|
|
5101
|
+
environmentConfig,
|
|
5102
|
+
viteServer,
|
|
5103
|
+
projectName,
|
|
5104
|
+
projectComponentPath,
|
|
5105
|
+
jsRenderingGates,
|
|
5106
|
+
false
|
|
5107
|
+
);
|
|
5108
|
+
} catch (err) {
|
|
5109
|
+
console.error("Template route error:", err);
|
|
5110
|
+
response.status(500).set({ "Content-Type": "text/html" }).end(buildErrorIndex2());
|
|
4886
5111
|
}
|
|
4887
|
-
devServerApp.get("/legacy", legacyRouteHandler_default);
|
|
4888
|
-
devServerApp.get("/proxy", proxyPathPageRouteHandler);
|
|
4889
|
-
devServerApp.get("/partials/", linksToAllPartialsRouteHandler_default);
|
|
4890
|
-
devServerApp.get("/partial/:partial", partial_default);
|
|
4891
|
-
devServerApp.get("/partial/:partial/*", partial_default);
|
|
4892
|
-
devServerApp.get("/remote-fs-dirty", remoteFsDirtyHandler);
|
|
4893
|
-
devServerApp.get("/preview/module/:moduleName", modulePreviewRouteHandler_default);
|
|
4894
|
-
devServerApp.get("/modules/", linksToAllModulesRouteHandler_default);
|
|
4895
|
-
devServerApp.get("/module/:moduleName", module_default);
|
|
4896
|
-
devServerApp.get(
|
|
4897
|
-
"/preview/module/:moduleName/fields.json",
|
|
4898
|
-
moduleFieldsJson_default
|
|
4899
|
-
);
|
|
4900
|
-
devServerApp.get("/module/:moduleName/*", module_default);
|
|
4901
|
-
devServerApp.post("/preview/module/:moduleName", modulePreviewRouteHandler_default);
|
|
4902
|
-
devServerApp.get("/hublmodule/:modulePath(*)", hublModuleRouteHandler);
|
|
4903
|
-
devServerApp.get("/template/:templatePath(*)", templateRouteHandler);
|
|
4904
|
-
devServerApp.all("/hs/serverless/*", proxyServerlessRequest);
|
|
4905
|
-
devServerApp.all("/_hcms/api/*", proxyServerlessRequest);
|
|
4906
|
-
devServerApp.get("/*", proxyPathPageResourceRedirect);
|
|
4907
|
-
devServerApp.get("/*", proxyPageResourceRedirect);
|
|
4908
|
-
devServerApp.post("/*", proxyPageResourceRedirect);
|
|
4909
|
-
devServerApp.delete("/*", proxyPageResourceRedirect);
|
|
4910
|
-
devServerApp.head("/*", proxyPageResourceRedirect);
|
|
4911
|
-
devServerApp.put("/*", proxyPageResourceRedirect);
|
|
4912
|
-
devServerApp.options("/*", proxyPageResourceRedirect);
|
|
4913
|
-
devServerApp.get("/*", proxyPageRouteHandler);
|
|
4914
|
-
return devServerApp;
|
|
4915
5112
|
};
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
import { Router as Router3 } from "express";
|
|
4924
|
-
import { getConfigAccountIfExists as getConfigAccountIfExists6 } from "@hubspot/local-dev-lib/config";
|
|
4925
|
-
import cors2 from "cors";
|
|
4926
|
-
function getShadowDevServerCheckHandler(devServerPort, themePath) {
|
|
4927
|
-
return async function shadowDevServerCheckHandler(request, response) {
|
|
4928
|
-
const { query } = request;
|
|
4929
|
-
if (query) {
|
|
4930
|
-
const {
|
|
4931
|
-
hostName,
|
|
4932
|
-
pathName,
|
|
4933
|
-
contentId,
|
|
4934
|
-
portalId: portalIdString
|
|
4935
|
-
} = query;
|
|
4936
|
-
const portalId = parseInt(portalIdString, 10);
|
|
4937
|
-
let account;
|
|
4938
|
-
let isTemplateFromDevTheme = false;
|
|
4939
|
-
let localProxyUrl;
|
|
4940
|
-
try {
|
|
4941
|
-
account = getConfigAccountIfExists6(portalId);
|
|
4942
|
-
if (!account) {
|
|
4943
|
-
throw new Error();
|
|
4944
|
-
}
|
|
4945
|
-
} catch (e) {
|
|
4946
|
-
response.status(500).end(
|
|
4947
|
-
`Unable to find account for hubid = ${portalId}. Please check your hubspot.config.yaml`
|
|
4948
|
-
);
|
|
4949
|
-
return;
|
|
4950
|
-
}
|
|
4951
|
-
try {
|
|
4952
|
-
const { templatePath } = await fetchPreviewInfo_default(
|
|
4953
|
-
account.accountId,
|
|
4954
|
-
portalId,
|
|
4955
|
-
contentId
|
|
4956
|
-
);
|
|
4957
|
-
if (templatePath.startsWith(themePath)) {
|
|
4958
|
-
isTemplateFromDevTheme = true;
|
|
4959
|
-
localProxyUrl = `http://${hostName}.hslocal.net:${devServerPort}${pathName}`;
|
|
4960
|
-
}
|
|
4961
|
-
response.status(200).set({ "Content-Type": "application/json" }).json({
|
|
4962
|
-
isTemplateFromDevTheme,
|
|
4963
|
-
localProxyUrl
|
|
4964
|
-
});
|
|
4965
|
-
} catch (error) {
|
|
4966
|
-
response.status(500).end(
|
|
4967
|
-
`Failed proxy render of page id = ${contentId} hub id = ${portalId}
|
|
4968
|
-
|
|
4969
|
-
${error.stack}`
|
|
4970
|
-
);
|
|
4971
|
-
return;
|
|
4972
|
-
}
|
|
4973
|
-
} else {
|
|
4974
|
-
response.status(500).end(
|
|
4975
|
-
`Missing pageUrl param, cannot check for proxied page without a pageUrl`
|
|
4976
|
-
);
|
|
4977
|
-
}
|
|
4978
|
-
};
|
|
5113
|
+
function buildErrorIndex2() {
|
|
5114
|
+
return buildHTMLResponse(`
|
|
5115
|
+
<div>
|
|
5116
|
+
<h2>Error</h2>
|
|
5117
|
+
<p>Failed to fetch template data.</p>
|
|
5118
|
+
</div>
|
|
5119
|
+
`);
|
|
4979
5120
|
}
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
);
|
|
4987
|
-
return shadowDevServerRoutes;
|
|
5121
|
+
function buildTemplateIndex() {
|
|
5122
|
+
return buildHTMLResponse(`
|
|
5123
|
+
<div>
|
|
5124
|
+
<h2>Template</h2>
|
|
5125
|
+
<p>Please provide a template path in the request</p>
|
|
5126
|
+
</div>
|
|
5127
|
+
`);
|
|
4988
5128
|
}
|
|
4989
5129
|
|
|
4990
|
-
// src/
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
} else {
|
|
5002
|
-
rej(err);
|
|
5003
|
-
}
|
|
5004
|
-
});
|
|
5005
|
-
testNetServer.once("listening", () => {
|
|
5006
|
-
testNetServer.close();
|
|
5007
|
-
});
|
|
5008
|
-
testNetServer.once("close", () => {
|
|
5009
|
-
res(false);
|
|
5010
|
-
});
|
|
5011
|
-
testNetServer.listen(shadowPort, host);
|
|
5012
|
-
});
|
|
5013
|
-
if (portIsTaken) {
|
|
5014
|
-
return;
|
|
5130
|
+
// src/routes/createAppServerAPIRoutes.ts
|
|
5131
|
+
import { Router } from "express";
|
|
5132
|
+
import { spawn } from "child_process";
|
|
5133
|
+
function getOpenCommand() {
|
|
5134
|
+
switch (process.platform) {
|
|
5135
|
+
case "darwin":
|
|
5136
|
+
return "open";
|
|
5137
|
+
case "win32":
|
|
5138
|
+
return "start";
|
|
5139
|
+
default:
|
|
5140
|
+
return "xdg-open";
|
|
5015
5141
|
}
|
|
5016
|
-
const shadowDevServer = express();
|
|
5017
|
-
shadowDevServer.listen(shadowPort, host);
|
|
5018
|
-
shadowDevServer.use(
|
|
5019
|
-
"/",
|
|
5020
|
-
await createShadowDevServerRoutes(devServerPort, themePath)
|
|
5021
|
-
);
|
|
5022
5142
|
}
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
}
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
origin,
|
|
5039
|
-
hmr: {
|
|
5040
|
-
protocol: sslEnabled ? "wss" : "ws",
|
|
5041
|
-
port: port + 1
|
|
5042
|
-
}
|
|
5043
|
-
},
|
|
5044
|
-
appType: "custom",
|
|
5045
|
-
root: appWebRoot,
|
|
5046
|
-
base: isProd3 ? void 0 : "/local",
|
|
5047
|
-
ssr: {
|
|
5048
|
-
noExternal: "@hubspot/cms-components"
|
|
5049
|
-
},
|
|
5050
|
-
resolve: {
|
|
5051
|
-
conditions: ["server"],
|
|
5052
|
-
dedupe: ["react", "react-dom", "@hubspot/cms-components", "styled-jsx"],
|
|
5053
|
-
alias: {
|
|
5054
|
-
"@": appWebRoot
|
|
5055
|
-
}
|
|
5056
|
-
},
|
|
5057
|
-
optimizeDeps: {
|
|
5058
|
-
include: ["react", "react-dom", "react-dom/client"]
|
|
5059
|
-
},
|
|
5060
|
-
plugins: [
|
|
5061
|
-
(() => {
|
|
5062
|
-
const require2 = createRequire2(import.meta.url);
|
|
5063
|
-
return react2({
|
|
5064
|
-
babel: {
|
|
5065
|
-
plugins: [
|
|
5066
|
-
require2.resolve("babel-plugin-styled-components"),
|
|
5067
|
-
require2.resolve("styled-jsx/babel"),
|
|
5068
|
-
require2.resolve("babel-plugin-macros")
|
|
5069
|
-
]
|
|
5070
|
-
}
|
|
5071
|
-
});
|
|
5072
|
-
})(),
|
|
5073
|
-
clientIslandEntryPlugin(),
|
|
5074
|
-
resolveIslandPlugin(),
|
|
5075
|
-
sslEnabled ? mkcert2() : null
|
|
5076
|
-
],
|
|
5077
|
-
css: {
|
|
5078
|
-
postcss: appWebRoot
|
|
5079
|
-
},
|
|
5080
|
-
envDir: appWebRoot,
|
|
5081
|
-
envPrefix: "HS_"
|
|
5082
|
-
};
|
|
5083
|
-
return createViteServer2(viteConfig);
|
|
5143
|
+
async function handleGetModulePages(req, res, next) {
|
|
5144
|
+
const { path: path20, portalId } = req.query;
|
|
5145
|
+
if (!path20 || !portalId) {
|
|
5146
|
+
return res.status(400).json({ error: "Missing required parameters" });
|
|
5147
|
+
}
|
|
5148
|
+
try {
|
|
5149
|
+
sendTrackingRequest("handle-module-dependencies");
|
|
5150
|
+
const data = await fetchModulePageDependencies(
|
|
5151
|
+
Number(portalId),
|
|
5152
|
+
path20
|
|
5153
|
+
);
|
|
5154
|
+
res.json(data);
|
|
5155
|
+
} catch (err) {
|
|
5156
|
+
next(err);
|
|
5157
|
+
}
|
|
5084
5158
|
}
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
}
|
|
5159
|
+
function handleOpenFile(req, res, next) {
|
|
5160
|
+
const { path: path20 } = req.query;
|
|
5161
|
+
if (!path20) {
|
|
5162
|
+
return res.status(400).json({ error: "Missing required parameters" });
|
|
5163
|
+
}
|
|
5164
|
+
try {
|
|
5165
|
+
sendTrackingRequest("handle-open-file");
|
|
5166
|
+
const command = getOpenCommand();
|
|
5167
|
+
spawn(command, [path20], { detached: true }).unref();
|
|
5168
|
+
res.sendStatus(200);
|
|
5169
|
+
} catch (err) {
|
|
5170
|
+
next(err);
|
|
5171
|
+
}
|
|
5096
5172
|
}
|
|
5097
|
-
function
|
|
5098
|
-
const
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
socket.pause();
|
|
5103
|
-
const byte = buffer[0];
|
|
5104
|
-
let protocol;
|
|
5105
|
-
if (byte === 22) {
|
|
5106
|
-
protocol = "https";
|
|
5107
|
-
} else if (32 < byte && byte < 127) {
|
|
5108
|
-
protocol = "http";
|
|
5109
|
-
} else {
|
|
5110
|
-
throw new Error(
|
|
5111
|
-
"Unknown issue with incoming data, unknown if http or https"
|
|
5112
|
-
);
|
|
5113
|
-
}
|
|
5114
|
-
const proxy = protocol === "http" ? innerHTTPServer : innerHTTPSServer;
|
|
5115
|
-
if (proxy) {
|
|
5116
|
-
socket.unshift(buffer);
|
|
5117
|
-
proxy.emit("connection", socket);
|
|
5118
|
-
}
|
|
5119
|
-
process.nextTick(() => socket.resume());
|
|
5120
|
-
});
|
|
5121
|
-
});
|
|
5122
|
-
return { server, innerHTTPServer, innerHTTPSServer };
|
|
5173
|
+
function createAppServerAPIRoutes() {
|
|
5174
|
+
const router = Router();
|
|
5175
|
+
router.get("/module-pages", handleGetModulePages);
|
|
5176
|
+
router.get("/open-file", handleOpenFile);
|
|
5177
|
+
return router;
|
|
5123
5178
|
}
|
|
5179
|
+
var createAppServerAPIRoutes_default = createAppServerAPIRoutes;
|
|
5124
5180
|
|
|
5125
|
-
// src/
|
|
5126
|
-
import
|
|
5181
|
+
// src/routes/appServerRouteHandler.ts
|
|
5182
|
+
import fs8 from "node:fs/promises";
|
|
5183
|
+
import path15 from "path";
|
|
5184
|
+
import { pathToFileURL } from "url";
|
|
5127
5185
|
|
|
5128
|
-
// src/lib/
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
return gates;
|
|
5132
|
-
}
|
|
5186
|
+
// src/lib/getDevServerUIData.ts
|
|
5187
|
+
import path14 from "path";
|
|
5188
|
+
import { normalizePath as normalizePath9 } from "vite";
|
|
5133
5189
|
|
|
5134
|
-
// src/
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
}
|
|
5140
|
-
|
|
5141
|
-
}, []);
|
|
5142
|
-
};
|
|
5143
|
-
async function getJsRenderingGates(portalId, env2, personalAccessKey) {
|
|
5144
|
-
const { enabledFeatures } = await getAccessToken(personalAccessKey, env2, portalId);
|
|
5145
|
-
const envGates = getGatesFromEnv();
|
|
5146
|
-
const gates = mapEnabledFeaturesToGates(enabledFeatures);
|
|
5147
|
-
const mergedGates = [...envGates, ...gates];
|
|
5148
|
-
process.env.GATES = mergedGates.join(",");
|
|
5149
|
-
return mergedGates;
|
|
5190
|
+
// src/api/project.ts
|
|
5191
|
+
import { http as hsCliHttp10 } from "@hubspot/local-dev-lib/http";
|
|
5192
|
+
var DEVELOPER_PROJECTS_API_PATH = "/developer/projects/v1";
|
|
5193
|
+
async function fetchProjectByName(accountId, projectName) {
|
|
5194
|
+
return (await hsCliHttp10.get(accountId, {
|
|
5195
|
+
url: `${DEVELOPER_PROJECTS_API_PATH}/by-name/${projectName}`
|
|
5196
|
+
})).data;
|
|
5150
5197
|
}
|
|
5151
5198
|
|
|
5152
|
-
// src/lib/
|
|
5153
|
-
import
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
"
|
|
5157
|
-
"
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5199
|
+
// src/lib/getDevServerUIData.ts
|
|
5200
|
+
import fs7 from "node:fs";
|
|
5201
|
+
var templateTypeMap = {
|
|
5202
|
+
// Standard templates
|
|
5203
|
+
4: "Page",
|
|
5204
|
+
2: "Email",
|
|
5205
|
+
42: "Blog Listing",
|
|
5206
|
+
41: "Blog Post",
|
|
5207
|
+
6: "Blog (Deprecated)",
|
|
5208
|
+
// Global partials
|
|
5209
|
+
38: "Global Partial",
|
|
5210
|
+
18: "Global Group",
|
|
5211
|
+
// System templates
|
|
5212
|
+
11: "Error Page",
|
|
5213
|
+
19: "Password Prompt",
|
|
5214
|
+
29: "Membership Login",
|
|
5215
|
+
30: "Membership Register",
|
|
5216
|
+
31: "Membership Reset",
|
|
5217
|
+
32: "Membership Reset Request",
|
|
5218
|
+
12: "Subscription Preferences",
|
|
5219
|
+
14: "Backup Unsubscribe",
|
|
5220
|
+
27: "Search Results"
|
|
5221
|
+
};
|
|
5222
|
+
function mapReactModules(modules, themeWebRoot, appViteServer) {
|
|
5223
|
+
return Promise.all(
|
|
5224
|
+
modules.moduleNames.map(async (name, index) => {
|
|
5225
|
+
const modulePath = normalizePath9(
|
|
5226
|
+
path14.resolve(themeWebRoot, "components/modules/", name)
|
|
5227
|
+
);
|
|
5228
|
+
const fieldsJson = await renderModuleFieldsJson_default(
|
|
5229
|
+
appViteServer,
|
|
5230
|
+
modulePath
|
|
5231
|
+
);
|
|
5232
|
+
return {
|
|
5233
|
+
name,
|
|
5234
|
+
type: "react" /* REACT */,
|
|
5235
|
+
subPath: modules.moduleSubpaths[index],
|
|
5236
|
+
nameWithExtension: modules.moduleNamesWithExtension[index],
|
|
5237
|
+
extension: modules.moduleExtensions[index],
|
|
5238
|
+
fieldsJson
|
|
5239
|
+
};
|
|
5240
|
+
})
|
|
5170
5241
|
);
|
|
5171
5242
|
}
|
|
5172
|
-
function
|
|
5173
|
-
|
|
5174
|
-
const
|
|
5175
|
-
return
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
for (const candidatePath of hsmetaCandidatePaths(srcPath)) {
|
|
5184
|
-
if (!fs6.existsSync(candidatePath))
|
|
5185
|
-
continue;
|
|
5186
|
-
const uid = tryParseUid(candidatePath);
|
|
5187
|
-
if (uid)
|
|
5188
|
-
return uid;
|
|
5189
|
-
}
|
|
5190
|
-
return null;
|
|
5243
|
+
function normalizeHubLModules(modules, projectName) {
|
|
5244
|
+
return modules.map((module) => {
|
|
5245
|
+
const subPath = projectName ? `${module.path.split("/@projects/")[1] || module.path}` : removePreviewPrefix(module.path);
|
|
5246
|
+
return {
|
|
5247
|
+
name: module.name,
|
|
5248
|
+
type: "hubl" /* HUBL */,
|
|
5249
|
+
subPath,
|
|
5250
|
+
nameWithExtension: module.filename,
|
|
5251
|
+
fieldsJson: module.fields
|
|
5252
|
+
};
|
|
5253
|
+
});
|
|
5191
5254
|
}
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
var COMPONENT_TYPES = Object.freeze({
|
|
5198
|
-
privateApp: "private-app",
|
|
5199
|
-
publicApp: "public-app",
|
|
5200
|
-
hublTheme: "hubl-theme"
|
|
5201
|
-
});
|
|
5202
|
-
var CONFIG_FILES = {
|
|
5203
|
-
[COMPONENT_TYPES.privateApp]: "app.json",
|
|
5204
|
-
[COMPONENT_TYPES.publicApp]: "public-app.json",
|
|
5205
|
-
[COMPONENT_TYPES.hublTheme]: "theme.json"
|
|
5206
|
-
};
|
|
5207
|
-
function hasNewDirectoryStructure(platformVersion) {
|
|
5208
|
-
return parseFloat(platformVersion) >= 2025.2;
|
|
5255
|
+
function normalizePartialsData(partialData) {
|
|
5256
|
+
return partialData.partialNames.map((name, index) => ({
|
|
5257
|
+
name,
|
|
5258
|
+
subPath: partialData.partialSubpaths[index]
|
|
5259
|
+
}));
|
|
5209
5260
|
}
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
|
|
5261
|
+
function normalizeTemplatesData(templates, projectName) {
|
|
5262
|
+
return templates.filter((template) => template.templateType in templateTypeMap).map((template) => {
|
|
5263
|
+
const subPath = projectName ? `@projects/${template.path.split("/@projects/")[1] || template.path}` : removePreviewPrefix(template.path);
|
|
5213
5264
|
return {
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
has16m: false
|
|
5265
|
+
name: template.displayName || template.label,
|
|
5266
|
+
subPath,
|
|
5267
|
+
templateTypeLabel: templateTypeMap[template.templateType]
|
|
5218
5268
|
};
|
|
5219
|
-
}
|
|
5220
|
-
return {
|
|
5221
|
-
level,
|
|
5222
|
-
hasBasic: true,
|
|
5223
|
-
has256: level >= 2,
|
|
5224
|
-
has16m: level >= 3
|
|
5225
|
-
};
|
|
5269
|
+
});
|
|
5226
5270
|
}
|
|
5227
|
-
function
|
|
5228
|
-
if (
|
|
5229
|
-
return
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5271
|
+
function detectPackageManager(projectRoot) {
|
|
5272
|
+
if (fs7.existsSync(path14.join(projectRoot, "yarn.lock")))
|
|
5273
|
+
return "yarn";
|
|
5274
|
+
if (fs7.existsSync(path14.join(projectRoot, "pnpm-lock.yaml")))
|
|
5275
|
+
return "pnpm";
|
|
5276
|
+
return "npm";
|
|
5277
|
+
}
|
|
5278
|
+
async function getDevServerUIData(appLocals) {
|
|
5279
|
+
const {
|
|
5280
|
+
themeWebRoot,
|
|
5281
|
+
authedEnv,
|
|
5282
|
+
authedPortalId,
|
|
5283
|
+
projectName,
|
|
5284
|
+
localPreviewToken,
|
|
5285
|
+
webRootProjectComponentFolder,
|
|
5286
|
+
sslEnabled,
|
|
5287
|
+
fieldBuilderEnabled,
|
|
5288
|
+
appViteServer
|
|
5289
|
+
} = appLocals;
|
|
5290
|
+
const modulesData = findAllModulesInRoot(themeWebRoot);
|
|
5291
|
+
const partialsData = findAllPartialsInRoot(themeWebRoot);
|
|
5292
|
+
let packageJson = { scripts: {} };
|
|
5293
|
+
let packageManager = "";
|
|
5294
|
+
let cliCommands = [];
|
|
5295
|
+
let reactModules = [];
|
|
5296
|
+
if (projectName) {
|
|
5297
|
+
packageJson = getPackageJson(themeWebRoot);
|
|
5298
|
+
packageManager = detectPackageManager(themeWebRoot);
|
|
5299
|
+
const runCommand = packageManager === "yarn" ? "yarn" : `${packageManager} run`;
|
|
5300
|
+
cliCommands = projectName ? Object.entries((packageJson == null ? void 0 : packageJson.scripts) || {}).map(
|
|
5301
|
+
([scriptName, description]) => ({
|
|
5302
|
+
scriptName,
|
|
5303
|
+
description,
|
|
5304
|
+
runCommand: `${runCommand} ${scriptName}`
|
|
5305
|
+
})
|
|
5306
|
+
) : [];
|
|
5307
|
+
reactModules = projectName && appViteServer ? await mapReactModules(modulesData, themeWebRoot, appViteServer) : [];
|
|
5237
5308
|
}
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5309
|
+
let hubLModuleData = { objects: [] };
|
|
5310
|
+
let hubLTemplateData = { objects: [] };
|
|
5311
|
+
let projectData = null;
|
|
5312
|
+
let normalizedHubLModules = [];
|
|
5313
|
+
if (authedPortalId) {
|
|
5314
|
+
try {
|
|
5315
|
+
const dataFetchingPromises = [
|
|
5316
|
+
fetchHubLModules(authedPortalId, localPreviewToken),
|
|
5317
|
+
fetchPreviewTemplates(authedPortalId, localPreviewToken),
|
|
5318
|
+
projectName ? fetchProjectByName(authedPortalId, projectName) : Promise.resolve(null)
|
|
5319
|
+
];
|
|
5320
|
+
[hubLModuleData, hubLTemplateData, projectData] = await Promise.all(dataFetchingPromises);
|
|
5321
|
+
} catch (e) {
|
|
5322
|
+
console.warn("Error fetching data:", e);
|
|
5242
5323
|
}
|
|
5243
|
-
|
|
5324
|
+
normalizedHubLModules = normalizeHubLModules(
|
|
5325
|
+
(hubLModuleData == null ? void 0 : hubLModuleData.objects) || [],
|
|
5326
|
+
projectName
|
|
5327
|
+
);
|
|
5244
5328
|
}
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5329
|
+
return {
|
|
5330
|
+
authedPortalId,
|
|
5331
|
+
authedEnv,
|
|
5332
|
+
projectName,
|
|
5333
|
+
modulesData: reactModules,
|
|
5334
|
+
partialsData: normalizePartialsData(partialsData),
|
|
5335
|
+
hubLModules: normalizedHubLModules || [],
|
|
5336
|
+
hubLTemplates: normalizeTemplatesData(
|
|
5337
|
+
(hubLTemplateData == null ? void 0 : hubLTemplateData.objects) || [],
|
|
5338
|
+
projectName
|
|
5339
|
+
),
|
|
5340
|
+
themeWebRoot,
|
|
5341
|
+
webRootProjectComponentFolder,
|
|
5342
|
+
cliCommands,
|
|
5343
|
+
sslEnabled,
|
|
5344
|
+
projectData,
|
|
5345
|
+
fieldBuilderEnabled
|
|
5346
|
+
};
|
|
5347
|
+
}
|
|
5348
|
+
|
|
5349
|
+
// src/routes/appServerRouteHandler.ts
|
|
5350
|
+
var isProd = true;
|
|
5351
|
+
var appServerRouteHandler = async (req, res, __next) => {
|
|
5352
|
+
try {
|
|
5353
|
+
sendTrackingRequest("view-index-route");
|
|
5354
|
+
const appLocals = req.app.locals.appLocals;
|
|
5355
|
+
const { appWebRoot, appViteServer } = appLocals;
|
|
5356
|
+
const initialProps = await getDevServerUIData(appLocals);
|
|
5357
|
+
const url3 = req.originalUrl.replace("/", "");
|
|
5358
|
+
const templatePath = path15.join(appWebRoot, "index.html");
|
|
5359
|
+
const serverEntryPath = isProd ? path15.join(appWebRoot, "server/serverEntry.js") : path15.join(appWebRoot, "serverEntry.tsx");
|
|
5360
|
+
let render;
|
|
5361
|
+
let template = await fs8.readFile(path15.join(templatePath), "utf-8");
|
|
5362
|
+
if (isProd) {
|
|
5363
|
+
const { render: ssrRender } = await import(pathToFileURL(serverEntryPath).href);
|
|
5364
|
+
render = ssrRender;
|
|
5365
|
+
} else {
|
|
5366
|
+
if (!appViteServer) {
|
|
5367
|
+
throw new Error(
|
|
5368
|
+
"appViteServer is required to render the dev server UI in development"
|
|
5369
|
+
);
|
|
5370
|
+
}
|
|
5371
|
+
template = await appViteServer.transformIndexHtml(url3, template);
|
|
5372
|
+
render = (await appViteServer.ssrLoadModule(serverEntryPath)).render;
|
|
5256
5373
|
}
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
return 3;
|
|
5264
|
-
}
|
|
5265
|
-
if ("TERM_PROGRAM" in env) {
|
|
5266
|
-
const version = Number.parseInt(
|
|
5267
|
-
(env.TERM_PROGRAM_VERSION || "").split(".")[0],
|
|
5268
|
-
10
|
|
5374
|
+
const rendered = await render(initialProps);
|
|
5375
|
+
const html = template.replace(`<!--app-head-->`, rendered.head ?? "").replace(`<!--app-html-->`, rendered.html ?? "").replace(
|
|
5376
|
+
`<!--app-script-->`,
|
|
5377
|
+
`<script>window.__hsInitialProps = ${JSON.stringify(
|
|
5378
|
+
initialProps
|
|
5379
|
+
)};</script>` ?? ""
|
|
5269
5380
|
);
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5381
|
+
res.status(200).set({ "Content-Type": "text/html" }).send(html);
|
|
5382
|
+
} catch (e) {
|
|
5383
|
+
const { appViteServer } = req.app.locals.appLocals;
|
|
5384
|
+
appViteServer == null ? void 0 : appViteServer.ssrFixStacktrace(e);
|
|
5385
|
+
console.log(e.stack);
|
|
5386
|
+
res.status(500).end(e.stack);
|
|
5276
5387
|
}
|
|
5277
|
-
|
|
5278
|
-
|
|
5388
|
+
};
|
|
5389
|
+
var appServerRouteHandler_default = appServerRouteHandler;
|
|
5390
|
+
|
|
5391
|
+
// src/routes/createDevServerRoutes.ts
|
|
5392
|
+
import path16 from "path";
|
|
5393
|
+
var isProd2 = true;
|
|
5394
|
+
var STORYBOOK_DOMAINS = VALID_PROXY_DOMAIN_SUFFIXES.map(
|
|
5395
|
+
(domain) => `storybook.${domain}`
|
|
5396
|
+
);
|
|
5397
|
+
var createDevServerRoutes = async (viteServer, appLocals, storybookPort) => {
|
|
5398
|
+
const devServerApp = Router2();
|
|
5399
|
+
const { appViteServer, appWebRoot } = appLocals || {};
|
|
5400
|
+
devServerApp.use((request, response, next) => {
|
|
5401
|
+
const { method, url: url3, hostname } = request;
|
|
5402
|
+
debug(`${method}:${hostname}${url3}`);
|
|
5403
|
+
next();
|
|
5404
|
+
});
|
|
5405
|
+
devServerApp.use(cors());
|
|
5406
|
+
if (storybookPort) {
|
|
5407
|
+
devServerApp.use(
|
|
5408
|
+
createProxyMiddleware2(
|
|
5409
|
+
(__pathname, req) => STORYBOOK_DOMAINS.includes(req.hostname),
|
|
5410
|
+
{
|
|
5411
|
+
logLevel: "warn",
|
|
5412
|
+
target: `http://localhost:${storybookPort}`
|
|
5413
|
+
}
|
|
5414
|
+
)
|
|
5415
|
+
);
|
|
5279
5416
|
}
|
|
5280
|
-
|
|
5281
|
-
|
|
5417
|
+
devServerApp.use(urlencoded());
|
|
5418
|
+
if (isProd2) {
|
|
5419
|
+
const distAssetsPath = path16.join(appWebRoot, "assets");
|
|
5420
|
+
devServerApp.use("/assets", expressStatic(distAssetsPath));
|
|
5421
|
+
} else if (appViteServer) {
|
|
5422
|
+
devServerApp.use("/local", appViteServer.middlewares);
|
|
5282
5423
|
}
|
|
5283
|
-
|
|
5284
|
-
|
|
5424
|
+
devServerApp.use(viteServer.middlewares);
|
|
5425
|
+
devServerApp.use("/api", createAppServerAPIRoutes_default());
|
|
5426
|
+
if (appViteServer) {
|
|
5427
|
+
devServerApp.get("/", appServerRouteHandler_default);
|
|
5285
5428
|
}
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5429
|
+
devServerApp.get("/legacy", legacyRouteHandler_default);
|
|
5430
|
+
devServerApp.get("/proxy", proxyPathPageRouteHandler);
|
|
5431
|
+
devServerApp.get("/partials/", linksToAllPartialsRouteHandler_default);
|
|
5432
|
+
devServerApp.get("/partial/:partial", partial_default);
|
|
5433
|
+
devServerApp.get("/partial/:partial/*", partial_default);
|
|
5434
|
+
devServerApp.get("/remote-fs-dirty", remoteFsDirtyHandler);
|
|
5435
|
+
devServerApp.get("/preview/module/:moduleName", modulePreviewRouteHandler_default);
|
|
5436
|
+
devServerApp.get("/modules/", linksToAllModulesRouteHandler_default);
|
|
5437
|
+
devServerApp.get("/module/:moduleName", module_default);
|
|
5438
|
+
devServerApp.get(
|
|
5439
|
+
"/preview/module/:moduleName/fields.json",
|
|
5440
|
+
moduleFieldsJson_default
|
|
5441
|
+
);
|
|
5442
|
+
devServerApp.get("/module/:moduleName/*", module_default);
|
|
5443
|
+
devServerApp.post(
|
|
5444
|
+
"/preview/module/:moduleName/validate-fields",
|
|
5445
|
+
moduleValidateFields_default
|
|
5446
|
+
);
|
|
5447
|
+
devServerApp.post("/preview/module/:moduleName", modulePreviewRouteHandler_default);
|
|
5448
|
+
devServerApp.get("/hublmodule/:modulePath(*)", hublModuleRouteHandler);
|
|
5449
|
+
devServerApp.get("/template/:templatePath(*)", templateRouteHandler);
|
|
5450
|
+
devServerApp.all("/hs/serverless/*", proxyServerlessRequest);
|
|
5451
|
+
devServerApp.all("/_hcms/api/*", proxyServerlessRequest);
|
|
5452
|
+
devServerApp.get("/*", proxyPathPageResourceRedirect);
|
|
5453
|
+
devServerApp.get("/*", proxyPageResourceRedirect);
|
|
5454
|
+
devServerApp.post("/*", proxyPageResourceRedirect);
|
|
5455
|
+
devServerApp.delete("/*", proxyPageResourceRedirect);
|
|
5456
|
+
devServerApp.head("/*", proxyPageResourceRedirect);
|
|
5457
|
+
devServerApp.put("/*", proxyPageResourceRedirect);
|
|
5458
|
+
devServerApp.options("/*", proxyPageResourceRedirect);
|
|
5459
|
+
devServerApp.get("/*", proxyPageRouteHandler);
|
|
5460
|
+
return devServerApp;
|
|
5299
5461
|
};
|
|
5300
|
-
|
|
5301
|
-
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
5302
|
-
const position = argv.indexOf(prefix + flag);
|
|
5303
|
-
const terminatorPosition = argv.indexOf("--");
|
|
5304
|
-
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
5305
|
-
}
|
|
5462
|
+
var createDevServerRoutes_default = createDevServerRoutes;
|
|
5306
5463
|
|
|
5307
|
-
// src/
|
|
5308
|
-
import
|
|
5309
|
-
|
|
5310
|
-
getConfigDefaultAccountIfExists,
|
|
5311
|
-
validateConfig
|
|
5312
|
-
} from "@hubspot/local-dev-lib/config";
|
|
5313
|
-
import { fetchSecrets } from "@hubspot/local-dev-lib/api/secrets";
|
|
5314
|
-
import { PERSONAL_ACCESS_KEY_AUTH_METHOD } from "@hubspot/local-dev-lib/constants/auth";
|
|
5464
|
+
// src/shadowDevServer/startShadowDevServer.ts
|
|
5465
|
+
import net from "net";
|
|
5466
|
+
import express from "express";
|
|
5315
5467
|
|
|
5316
|
-
// src/
|
|
5317
|
-
import {
|
|
5468
|
+
// src/shadowDevServer/createShadowDevServerRoutes.ts
|
|
5469
|
+
import { Router as Router3 } from "express";
|
|
5470
|
+
import { getConfigAccountIfExists as getConfigAccountIfExists6 } from "@hubspot/local-dev-lib/config";
|
|
5471
|
+
import cors2 from "cors";
|
|
5472
|
+
function getShadowDevServerCheckHandler(devServerPort, themePath) {
|
|
5473
|
+
return async function shadowDevServerCheckHandler(request, response) {
|
|
5474
|
+
const { query } = request;
|
|
5475
|
+
if (query) {
|
|
5476
|
+
const {
|
|
5477
|
+
hostName,
|
|
5478
|
+
pathName,
|
|
5479
|
+
contentId,
|
|
5480
|
+
portalId: portalIdString
|
|
5481
|
+
} = query;
|
|
5482
|
+
const portalId = parseInt(portalIdString, 10);
|
|
5483
|
+
let account;
|
|
5484
|
+
let isTemplateFromDevTheme = false;
|
|
5485
|
+
let localProxyUrl;
|
|
5486
|
+
try {
|
|
5487
|
+
account = getConfigAccountIfExists6(portalId);
|
|
5488
|
+
if (!account) {
|
|
5489
|
+
throw new Error();
|
|
5490
|
+
}
|
|
5491
|
+
} catch (e) {
|
|
5492
|
+
response.status(500).end(
|
|
5493
|
+
`Unable to find account for hubid = ${portalId}. Please check your hubspot.config.yaml`
|
|
5494
|
+
);
|
|
5495
|
+
return;
|
|
5496
|
+
}
|
|
5497
|
+
try {
|
|
5498
|
+
const { templatePath } = await fetchPreviewInfo_default(
|
|
5499
|
+
account.accountId,
|
|
5500
|
+
portalId,
|
|
5501
|
+
contentId
|
|
5502
|
+
);
|
|
5503
|
+
if (templatePath.startsWith(themePath)) {
|
|
5504
|
+
isTemplateFromDevTheme = true;
|
|
5505
|
+
localProxyUrl = `http://${hostName}.hslocal.net:${devServerPort}${pathName}`;
|
|
5506
|
+
}
|
|
5507
|
+
response.status(200).set({ "Content-Type": "application/json" }).json({
|
|
5508
|
+
isTemplateFromDevTheme,
|
|
5509
|
+
localProxyUrl
|
|
5510
|
+
});
|
|
5511
|
+
} catch (error) {
|
|
5512
|
+
response.status(500).end(
|
|
5513
|
+
`Failed proxy render of page id = ${contentId} hub id = ${portalId}
|
|
5318
5514
|
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
let messageEnd = "";
|
|
5328
|
-
if (error.error.message.match(OAUTH_ERROR_REGEX)) {
|
|
5329
|
-
messageEnd = error.error.message;
|
|
5515
|
+
${error.stack}`
|
|
5516
|
+
);
|
|
5517
|
+
return;
|
|
5518
|
+
}
|
|
5519
|
+
} else {
|
|
5520
|
+
response.status(500).end(
|
|
5521
|
+
`Missing pageUrl param, cannot check for proxied page without a pageUrl`
|
|
5522
|
+
);
|
|
5330
5523
|
}
|
|
5331
|
-
|
|
5332
|
-
${messageEnd}`);
|
|
5333
|
-
Object.setPrototypeOf(this, MissingScopeError.prototype);
|
|
5334
|
-
}
|
|
5335
|
-
};
|
|
5336
|
-
function logMissingScopeWarning(error) {
|
|
5337
|
-
console.warn(error.message);
|
|
5524
|
+
};
|
|
5338
5525
|
}
|
|
5339
|
-
function
|
|
5340
|
-
|
|
5526
|
+
async function createShadowDevServerRoutes(devServerPort, themePath) {
|
|
5527
|
+
const shadowDevServerRoutes = Router3();
|
|
5528
|
+
shadowDevServerRoutes.get(
|
|
5529
|
+
"/check-if-local-dev-server",
|
|
5530
|
+
cors2(),
|
|
5531
|
+
getShadowDevServerCheckHandler(devServerPort, themePath)
|
|
5532
|
+
);
|
|
5533
|
+
return shadowDevServerRoutes;
|
|
5341
5534
|
}
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
)
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5535
|
+
|
|
5536
|
+
// src/shadowDevServer/startShadowDevServer.ts
|
|
5537
|
+
var testNetServer = net.createServer();
|
|
5538
|
+
async function startShadowDevServer(devServerPort, shadowPort, themePath, host) {
|
|
5539
|
+
const portIsTaken = await new Promise((res, rej) => {
|
|
5540
|
+
console.log(`Starting proxy link server on port ${shadowPort}`);
|
|
5541
|
+
testNetServer.once("error", (err) => {
|
|
5542
|
+
if (err["code"] === "EADDRINUSE") {
|
|
5543
|
+
console.error(
|
|
5544
|
+
`Port ${shadowPort} is in use. HubSpot is unable to automatically create proxy links in the Sprocket Menu`
|
|
5545
|
+
);
|
|
5546
|
+
res(true);
|
|
5547
|
+
} else {
|
|
5548
|
+
rej(err);
|
|
5354
5549
|
}
|
|
5355
|
-
|
|
5356
|
-
|
|
5550
|
+
});
|
|
5551
|
+
testNetServer.once("listening", () => {
|
|
5552
|
+
testNetServer.close();
|
|
5553
|
+
});
|
|
5554
|
+
testNetServer.once("close", () => {
|
|
5555
|
+
res(false);
|
|
5556
|
+
});
|
|
5557
|
+
testNetServer.listen(shadowPort, host);
|
|
5558
|
+
});
|
|
5559
|
+
if (portIsTaken) {
|
|
5560
|
+
return;
|
|
5561
|
+
}
|
|
5562
|
+
const shadowDevServer = express();
|
|
5563
|
+
shadowDevServer.listen(shadowPort, host);
|
|
5564
|
+
shadowDevServer.use(
|
|
5565
|
+
"/",
|
|
5566
|
+
await createShadowDevServerRoutes(devServerPort, themePath)
|
|
5567
|
+
);
|
|
5568
|
+
}
|
|
5569
|
+
|
|
5570
|
+
// src/createAppServer.ts
|
|
5571
|
+
import {
|
|
5572
|
+
createServer as createViteServer2
|
|
5573
|
+
} from "vite";
|
|
5574
|
+
import { createRequire as createRequire2 } from "module";
|
|
5575
|
+
import { default as react2 } from "@vitejs/plugin-react";
|
|
5576
|
+
import { default as mkcert2 } from "vite-plugin-mkcert";
|
|
5577
|
+
var isProd3 = true;
|
|
5578
|
+
async function createAppServer(appWebRoot, port, sslEnabled) {
|
|
5579
|
+
const origin = process.env.VITE_ORIGIN ?? (sslEnabled ? `https://hslocal.net:${port}` : `http://hslocal.net:${port}`);
|
|
5580
|
+
const viteConfig = {
|
|
5581
|
+
server: {
|
|
5582
|
+
middlewareMode: true,
|
|
5583
|
+
host: "hslocal.net",
|
|
5584
|
+
origin,
|
|
5585
|
+
hmr: {
|
|
5586
|
+
protocol: sslEnabled ? "wss" : "ws",
|
|
5587
|
+
port: port + 1
|
|
5357
5588
|
}
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5589
|
+
},
|
|
5590
|
+
appType: "custom",
|
|
5591
|
+
root: appWebRoot,
|
|
5592
|
+
base: isProd3 ? void 0 : "/local",
|
|
5593
|
+
ssr: {
|
|
5594
|
+
noExternal: "@hubspot/cms-components"
|
|
5595
|
+
},
|
|
5596
|
+
resolve: {
|
|
5597
|
+
conditions: ["server"],
|
|
5598
|
+
dedupe: ["react", "react-dom", "@hubspot/cms-components", "styled-jsx"],
|
|
5599
|
+
alias: {
|
|
5600
|
+
"@": appWebRoot
|
|
5365
5601
|
}
|
|
5366
|
-
}
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5602
|
+
},
|
|
5603
|
+
optimizeDeps: {
|
|
5604
|
+
include: ["react", "react-dom", "react-dom/client"]
|
|
5605
|
+
},
|
|
5606
|
+
plugins: [
|
|
5607
|
+
(() => {
|
|
5608
|
+
const require2 = createRequire2(import.meta.url);
|
|
5609
|
+
return react2({
|
|
5610
|
+
babel: {
|
|
5611
|
+
plugins: [
|
|
5612
|
+
require2.resolve("babel-plugin-styled-components"),
|
|
5613
|
+
require2.resolve("styled-jsx/babel"),
|
|
5614
|
+
require2.resolve("babel-plugin-macros")
|
|
5615
|
+
]
|
|
5616
|
+
}
|
|
5617
|
+
});
|
|
5618
|
+
})(),
|
|
5619
|
+
clientIslandEntryPlugin(),
|
|
5620
|
+
resolveIslandPlugin(),
|
|
5621
|
+
sslEnabled ? mkcert2() : null
|
|
5622
|
+
],
|
|
5623
|
+
css: {
|
|
5624
|
+
postcss: appWebRoot
|
|
5625
|
+
},
|
|
5626
|
+
envDir: appWebRoot,
|
|
5627
|
+
envPrefix: "HS_"
|
|
5628
|
+
};
|
|
5629
|
+
return createViteServer2(viteConfig);
|
|
5370
5630
|
}
|
|
5631
|
+
var createAppServer_default = createAppServer;
|
|
5371
5632
|
|
|
5372
|
-
// src/
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
} catch (error) {
|
|
5382
|
-
if (isMissingScopeError(error)) {
|
|
5383
|
-
throw new MissingScopeError(error);
|
|
5384
|
-
}
|
|
5385
|
-
throw error;
|
|
5386
|
-
}
|
|
5633
|
+
// src/lib/httpsRedirectingServer.ts
|
|
5634
|
+
import net2 from "net";
|
|
5635
|
+
import http2 from "http";
|
|
5636
|
+
import https2 from "https";
|
|
5637
|
+
function requireHTTPS(message, response) {
|
|
5638
|
+
const newLocation = `https://${message.headers.host}${message.url}`;
|
|
5639
|
+
response.writeHead(302, {
|
|
5640
|
+
Location: newLocation
|
|
5641
|
+
}).end();
|
|
5387
5642
|
}
|
|
5388
|
-
|
|
5389
|
-
const
|
|
5390
|
-
const
|
|
5391
|
-
|
|
5643
|
+
function createHttpsRedirectingServer(opts, handler) {
|
|
5644
|
+
const innerHTTPServer = http2.createServer(requireHTTPS);
|
|
5645
|
+
const innerHTTPSServer = https2.createServer(opts, handler);
|
|
5646
|
+
const server = net2.createServer((socket) => {
|
|
5647
|
+
socket.once("data", (buffer) => {
|
|
5648
|
+
socket.pause();
|
|
5649
|
+
const byte = buffer[0];
|
|
5650
|
+
let protocol;
|
|
5651
|
+
if (byte === 22) {
|
|
5652
|
+
protocol = "https";
|
|
5653
|
+
} else if (32 < byte && byte < 127) {
|
|
5654
|
+
protocol = "http";
|
|
5655
|
+
} else {
|
|
5656
|
+
throw new Error(
|
|
5657
|
+
"Unknown issue with incoming data, unknown if http or https"
|
|
5658
|
+
);
|
|
5659
|
+
}
|
|
5660
|
+
const proxy = protocol === "http" ? innerHTTPServer : innerHTTPSServer;
|
|
5661
|
+
if (proxy) {
|
|
5662
|
+
socket.unshift(buffer);
|
|
5663
|
+
proxy.emit("connection", socket);
|
|
5664
|
+
}
|
|
5665
|
+
process.nextTick(() => socket.resume());
|
|
5666
|
+
});
|
|
5392
5667
|
});
|
|
5393
|
-
|
|
5394
|
-
return domainNames;
|
|
5668
|
+
return { server, innerHTTPServer, innerHTTPSServer };
|
|
5395
5669
|
}
|
|
5396
5670
|
|
|
5397
|
-
// src/lib/
|
|
5398
|
-
import
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
return
|
|
5671
|
+
// src/lib/getJSRenderingGates.ts
|
|
5672
|
+
import { getAccessToken } from "@hubspot/local-dev-lib/personalAccessKey";
|
|
5673
|
+
|
|
5674
|
+
// src/lib/gates.ts
|
|
5675
|
+
function getGatesFromEnv() {
|
|
5676
|
+
const gates = process.env.GATES ? process.env.GATES.split(",") : [];
|
|
5677
|
+
return gates;
|
|
5404
5678
|
}
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
|
|
5408
|
-
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
if (checkFileExists(filePath)) {
|
|
5412
|
-
return filePath;
|
|
5679
|
+
|
|
5680
|
+
// src/lib/getJSRenderingGates.ts
|
|
5681
|
+
var mapEnabledFeaturesToGates = (enabledFeatures) => {
|
|
5682
|
+
return Object.keys(enabledFeatures).reduce((gates, enabledFeature) => {
|
|
5683
|
+
if (enabledFeatures[enabledFeature]) {
|
|
5684
|
+
gates.push(ENABLED_FEATURES_GATE_MAP[enabledFeature]);
|
|
5413
5685
|
}
|
|
5414
|
-
|
|
5415
|
-
|
|
5686
|
+
return gates;
|
|
5687
|
+
}, []);
|
|
5688
|
+
};
|
|
5689
|
+
async function getJsRenderingGates(portalId, env2, personalAccessKey) {
|
|
5690
|
+
const { enabledFeatures } = await getAccessToken(personalAccessKey, env2, portalId);
|
|
5691
|
+
const envGates = getGatesFromEnv();
|
|
5692
|
+
const gates = mapEnabledFeaturesToGates(enabledFeatures);
|
|
5693
|
+
const mergedGates = [...envGates, ...gates];
|
|
5694
|
+
process.env.GATES = mergedGates.join(",");
|
|
5695
|
+
return mergedGates;
|
|
5696
|
+
}
|
|
5697
|
+
|
|
5698
|
+
// src/lib/hsmetaUtils.ts
|
|
5699
|
+
import path17 from "path";
|
|
5700
|
+
import fs9 from "fs";
|
|
5701
|
+
var HSMETA_FILENAMES = [
|
|
5702
|
+
"theme-hsmeta.json",
|
|
5703
|
+
"cms-assets-hsmeta.json"
|
|
5704
|
+
];
|
|
5705
|
+
function getSubdirectories(dirPath) {
|
|
5706
|
+
try {
|
|
5707
|
+
return fs9.readdirSync(dirPath, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
5708
|
+
} catch {
|
|
5709
|
+
return [];
|
|
5416
5710
|
}
|
|
5417
|
-
|
|
5418
|
-
|
|
5711
|
+
}
|
|
5712
|
+
function hsmetaCandidatePaths(srcPath) {
|
|
5713
|
+
const subdirs = getSubdirectories(srcPath);
|
|
5714
|
+
return subdirs.flatMap(
|
|
5715
|
+
(subdir) => HSMETA_FILENAMES.map((filename) => path17.join(srcPath, subdir, filename))
|
|
5419
5716
|
);
|
|
5420
|
-
return null;
|
|
5421
5717
|
}
|
|
5422
|
-
|
|
5423
|
-
if (projectConfigPath === null) {
|
|
5424
|
-
console.log(
|
|
5425
|
-
`Unable to find local ${HSPROJECT_JSON}, skipping platform version validation.`
|
|
5426
|
-
);
|
|
5427
|
-
return false;
|
|
5428
|
-
}
|
|
5429
|
-
const hsProjectJSONContents = fs7.readFileSync(projectConfigPath, "utf8");
|
|
5430
|
-
const hsProjectJSONData = JSON.parse(hsProjectJSONContents);
|
|
5431
|
-
const { platformVersion } = hsProjectJSONData;
|
|
5432
|
-
let platformVersionResult;
|
|
5718
|
+
function tryParseUid(hsmetaPath) {
|
|
5433
5719
|
try {
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
})
|
|
5438
|
-
|
|
5439
|
-
console.error(e.message);
|
|
5440
|
-
console.log(
|
|
5441
|
-
"Unable to find active platform versions, skipping platform version validation."
|
|
5442
|
-
);
|
|
5443
|
-
return false;
|
|
5720
|
+
const hsmeta = JSON.parse(fs9.readFileSync(hsmetaPath, "utf8"));
|
|
5721
|
+
return hsmeta.uid ?? null;
|
|
5722
|
+
} catch (parseErr) {
|
|
5723
|
+
console.warn(`Could not parse ${hsmetaPath}:`, parseErr.message);
|
|
5724
|
+
return null;
|
|
5444
5725
|
}
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
})
|
|
5455
|
-
)
|
|
5456
|
-
});
|
|
5457
|
-
hsProjectJSONData.platformVersion = answer;
|
|
5458
|
-
try {
|
|
5459
|
-
fs7.writeFileSync(
|
|
5460
|
-
projectConfigPath,
|
|
5461
|
-
JSON.stringify(hsProjectJSONData, void 0, 2),
|
|
5462
|
-
"utf8"
|
|
5463
|
-
);
|
|
5464
|
-
return true;
|
|
5465
|
-
} catch (e) {
|
|
5466
|
-
console.error(
|
|
5467
|
-
`unable to write updated valid platform version, please make sure platformVersion in "${HSPROJECT_JSON}" is one of ${platformVersionResult.activePlatformVersions}`
|
|
5468
|
-
);
|
|
5469
|
-
return false;
|
|
5470
|
-
}
|
|
5471
|
-
};
|
|
5472
|
-
if (deferSelection) {
|
|
5473
|
-
deferSelection(promptAndWrite);
|
|
5474
|
-
return false;
|
|
5475
|
-
}
|
|
5476
|
-
return promptAndWrite();
|
|
5726
|
+
}
|
|
5727
|
+
function findHsmetaUid(projectDir, srcDir) {
|
|
5728
|
+
const srcPath = path17.join(projectDir, srcDir);
|
|
5729
|
+
for (const candidatePath of hsmetaCandidatePaths(srcPath)) {
|
|
5730
|
+
if (!fs9.existsSync(candidatePath))
|
|
5731
|
+
continue;
|
|
5732
|
+
const uid = tryParseUid(candidatePath);
|
|
5733
|
+
if (uid)
|
|
5734
|
+
return uid;
|
|
5477
5735
|
}
|
|
5478
|
-
return
|
|
5736
|
+
return null;
|
|
5479
5737
|
}
|
|
5480
5738
|
|
|
5481
|
-
// src/
|
|
5482
|
-
import
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
choice: "ChoiceFieldType",
|
|
5495
|
-
color: "ColorFieldType",
|
|
5496
|
-
crmobject: "CrmObjectFieldType",
|
|
5497
|
-
cta: "CtaFieldType",
|
|
5498
|
-
date: "DateFieldType",
|
|
5499
|
-
datetime: "DateTimeFieldType",
|
|
5500
|
-
email: "EmailFieldType",
|
|
5501
|
-
embed: "EmbedFieldType",
|
|
5502
|
-
file: "FileFieldType",
|
|
5503
|
-
followupemail: "FollowUpEmailFieldType",
|
|
5504
|
-
font: "FontFieldType",
|
|
5505
|
-
form: "FormFieldType",
|
|
5506
|
-
gradient: "GradientFieldType",
|
|
5507
|
-
group: "GroupFieldType",
|
|
5508
|
-
html: "HtmlFieldType",
|
|
5509
|
-
hubdbrow: "HubDbRowFieldType",
|
|
5510
|
-
hubdbtable: "HubDbTableFieldType",
|
|
5511
|
-
hubl: "HublFieldType",
|
|
5512
|
-
icon: "IconFieldType",
|
|
5513
|
-
image: "ImageFieldType",
|
|
5514
|
-
link: "LinkFieldType",
|
|
5515
|
-
logo: "LogoFieldType",
|
|
5516
|
-
meeting: "MeetingFieldType",
|
|
5517
|
-
menu: "MenuFieldType",
|
|
5518
|
-
number: "NumberFieldType",
|
|
5519
|
-
page: "PageFieldType",
|
|
5520
|
-
payment: "PaymentFieldType",
|
|
5521
|
-
podcast: "PodcastFieldType",
|
|
5522
|
-
richtext: "RichTextFieldType",
|
|
5523
|
-
salesforcecampaign: "SfdcCamapaignFieldType",
|
|
5524
|
-
simplemenu: "SimpleMenuFieldType",
|
|
5525
|
-
spacing: "SpacingFieldType",
|
|
5526
|
-
survey: "SurveyFieldType",
|
|
5527
|
-
tag: "TagFieldType",
|
|
5528
|
-
textalignment: "TextAlignmentFieldType",
|
|
5529
|
-
text: "TextFieldType",
|
|
5530
|
-
url: "UrlFieldType",
|
|
5531
|
-
variantselection: "VariantSelectionFieldType",
|
|
5532
|
-
videoplayer: "VideoFieldType",
|
|
5533
|
-
workflow: "WorkflowFieldType"
|
|
5739
|
+
// src/lib/cliUtils.ts
|
|
5740
|
+
import process2 from "process";
|
|
5741
|
+
import os from "os";
|
|
5742
|
+
import tty from "tty";
|
|
5743
|
+
var COMPONENT_TYPES = Object.freeze({
|
|
5744
|
+
privateApp: "private-app",
|
|
5745
|
+
publicApp: "public-app",
|
|
5746
|
+
hublTheme: "hubl-theme"
|
|
5747
|
+
});
|
|
5748
|
+
var CONFIG_FILES = {
|
|
5749
|
+
[COMPONENT_TYPES.privateApp]: "app.json",
|
|
5750
|
+
[COMPONENT_TYPES.publicApp]: "public-app.json",
|
|
5751
|
+
[COMPONENT_TYPES.hublTheme]: "theme.json"
|
|
5534
5752
|
};
|
|
5535
|
-
function
|
|
5536
|
-
|
|
5537
|
-
|
|
5753
|
+
function hasNewDirectoryStructure(platformVersion) {
|
|
5754
|
+
return parseFloat(platformVersion) >= 2025.2;
|
|
5755
|
+
}
|
|
5756
|
+
var { env } = process2;
|
|
5757
|
+
function translateLevel(level) {
|
|
5758
|
+
if (level === 0) {
|
|
5759
|
+
return {
|
|
5760
|
+
level,
|
|
5761
|
+
hasBasic: false,
|
|
5762
|
+
has256: false,
|
|
5763
|
+
has16m: false
|
|
5764
|
+
};
|
|
5538
5765
|
}
|
|
5539
|
-
return
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5766
|
+
return {
|
|
5767
|
+
level,
|
|
5768
|
+
hasBasic: true,
|
|
5769
|
+
has256: level >= 2,
|
|
5770
|
+
has16m: level >= 3
|
|
5771
|
+
};
|
|
5772
|
+
}
|
|
5773
|
+
function _supportsColor(haveStream, { streamIsTTY } = {}) {
|
|
5774
|
+
if (haveStream && !streamIsTTY) {
|
|
5775
|
+
return 0;
|
|
5776
|
+
}
|
|
5777
|
+
const min = 0;
|
|
5778
|
+
if (env.TERM === "dumb") {
|
|
5779
|
+
return min;
|
|
5780
|
+
}
|
|
5781
|
+
if (hasFlag("noColor")) {
|
|
5782
|
+
return 0;
|
|
5783
|
+
}
|
|
5784
|
+
if (process2.platform === "win32") {
|
|
5785
|
+
const osRelease = os.release().split(".");
|
|
5786
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
5787
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
5544
5788
|
}
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
return { ...entry, children };
|
|
5789
|
+
return 1;
|
|
5790
|
+
}
|
|
5791
|
+
if ("CI" in env) {
|
|
5792
|
+
if ([
|
|
5793
|
+
"TRAVIS",
|
|
5794
|
+
"CIRCLECI",
|
|
5795
|
+
"APPVEYOR",
|
|
5796
|
+
"GITLAB_CI",
|
|
5797
|
+
"GITHUB_ACTIONS",
|
|
5798
|
+
"BUILDKITE",
|
|
5799
|
+
"DRONE"
|
|
5800
|
+
].some((sign) => sign in env) || env.CI_NAME === "codeship") {
|
|
5801
|
+
return 1;
|
|
5559
5802
|
}
|
|
5560
|
-
return
|
|
5561
|
-
}).filter((entry) => entry !== void 0);
|
|
5562
|
-
}
|
|
5563
|
-
var INVALID_IMPORTS = ["ChoiceFieldType", "GroupFieldType"];
|
|
5564
|
-
var FIELD_GROUP_TYPE = "FieldGroupWithChildren";
|
|
5565
|
-
var REPEATER_GROUP_TYPE = "RepeaterGroup";
|
|
5566
|
-
var REQUIRED_TYPE = "RequiredField";
|
|
5567
|
-
var DEFAULT_VALUES_TYPE = "DefaultValues";
|
|
5568
|
-
var CMS_COMPONENTS = "@hubspot/cms-components";
|
|
5569
|
-
var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
5570
|
-
var AUTO_GEN_COMMENT = "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.";
|
|
5571
|
-
var createPropertySignature = (identifier, type, hasQuestionToken = false) => ts.factory.createPropertySignature(
|
|
5572
|
-
[],
|
|
5573
|
-
identifier,
|
|
5574
|
-
hasQuestionToken ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) : void 0,
|
|
5575
|
-
type
|
|
5576
|
-
);
|
|
5577
|
-
var createUnionTypeFromArray = (values) => ts.factory.createUnionTypeNode(
|
|
5578
|
-
values.map(
|
|
5579
|
-
(value) => ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(value))
|
|
5580
|
-
)
|
|
5581
|
-
);
|
|
5582
|
-
var buildTypeFromField = (field, additionalNode) => {
|
|
5583
|
-
const imports = [field.type];
|
|
5584
|
-
const identifier = ts.factory.createIdentifier(field.name);
|
|
5585
|
-
const baseType = ts.factory.createTypeReferenceNode(field.type);
|
|
5586
|
-
const requiredType = ts.factory.createTypeReferenceNode(REQUIRED_TYPE, [
|
|
5587
|
-
baseType
|
|
5588
|
-
]);
|
|
5589
|
-
let finalType = field.isRequired ? requiredType : baseType;
|
|
5590
|
-
if (field.choices) {
|
|
5591
|
-
finalType = createUnionTypeFromArray(field.choices);
|
|
5803
|
+
return min;
|
|
5592
5804
|
}
|
|
5593
|
-
if (
|
|
5594
|
-
|
|
5805
|
+
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
|
|
5806
|
+
return 1;
|
|
5595
5807
|
}
|
|
5596
|
-
if (
|
|
5597
|
-
|
|
5598
|
-
const genericType = field.isRepeater ? REPEATER_GROUP_TYPE : FIELD_GROUP_TYPE;
|
|
5599
|
-
imports.push(genericType);
|
|
5600
|
-
finalType = ts.factory.createTypeReferenceNode(genericType, [typeLiteral]);
|
|
5808
|
+
if (env.COLORTERM === "truecolor") {
|
|
5809
|
+
return 3;
|
|
5601
5810
|
}
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
)
|
|
5608
|
-
|
|
5609
|
-
|
|
5811
|
+
if ("TERM_PROGRAM" in env) {
|
|
5812
|
+
const version = Number.parseInt(
|
|
5813
|
+
(env.TERM_PROGRAM_VERSION || "").split(".")[0],
|
|
5814
|
+
10
|
|
5815
|
+
);
|
|
5816
|
+
switch (env.TERM_PROGRAM) {
|
|
5817
|
+
case "iTerm.app":
|
|
5818
|
+
return version >= 3 ? 3 : 2;
|
|
5819
|
+
case "Apple_Terminal":
|
|
5820
|
+
return 2;
|
|
5821
|
+
}
|
|
5822
|
+
}
|
|
5823
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
5824
|
+
return 2;
|
|
5825
|
+
}
|
|
5826
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
5827
|
+
return 1;
|
|
5828
|
+
}
|
|
5829
|
+
if ("COLORTERM" in env) {
|
|
5830
|
+
return 1;
|
|
5831
|
+
}
|
|
5832
|
+
return min;
|
|
5833
|
+
}
|
|
5834
|
+
function createSupportsColor(stream2, options = {}) {
|
|
5835
|
+
const level = _supportsColor(stream2, {
|
|
5836
|
+
streamIsTTY: stream2 && stream2.isTTY,
|
|
5837
|
+
...options
|
|
5838
|
+
});
|
|
5839
|
+
return translateLevel(level);
|
|
5840
|
+
}
|
|
5841
|
+
var supportsColor = {
|
|
5842
|
+
createSupportsColor,
|
|
5843
|
+
stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
|
|
5844
|
+
stderr: createSupportsColor({ isTTY: tty.isatty(2) })
|
|
5610
5845
|
};
|
|
5611
|
-
|
|
5612
|
-
const
|
|
5613
|
-
const
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5846
|
+
function hasFlag(flag, argv = process2.argv) {
|
|
5847
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
5848
|
+
const position = argv.indexOf(prefix + flag);
|
|
5849
|
+
const terminatorPosition = argv.indexOf("--");
|
|
5850
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
5851
|
+
}
|
|
5852
|
+
|
|
5853
|
+
// src/createDevServer.ts
|
|
5854
|
+
import {
|
|
5855
|
+
getConfigAccountIfExists as getConfigAccountIfExists7,
|
|
5856
|
+
getConfigDefaultAccountIfExists,
|
|
5857
|
+
validateConfig
|
|
5858
|
+
} from "@hubspot/local-dev-lib/config";
|
|
5859
|
+
import { fetchSecrets } from "@hubspot/local-dev-lib/api/secrets";
|
|
5860
|
+
import { PERSONAL_ACCESS_KEY_AUTH_METHOD } from "@hubspot/local-dev-lib/constants/auth";
|
|
5861
|
+
|
|
5862
|
+
// src/proxyPage/fetchDomains.ts
|
|
5863
|
+
import { http as hsCliHttp11 } from "@hubspot/local-dev-lib/http";
|
|
5864
|
+
|
|
5865
|
+
// src/lib/errors.ts
|
|
5866
|
+
var MISSING_SCOPE_ERROR_PREFIX = `Your personal access key is missing required scopes fetch domains.
|
|
5867
|
+
You may need to re-generate a new personal access key with the required scopes and re-run \`hs-auth\`, or you may not have this functionality enabled in your account
|
|
5868
|
+
`;
|
|
5869
|
+
var OAUTH_ERROR_REGEX = /^This oauth-token \([\w]+\) does not have proper permissions!/;
|
|
5870
|
+
var NOT_PUBLIC_USE_ERROR = `The scope needed for this API call isn't available for public use`;
|
|
5871
|
+
var MissingScopeError = class extends Error {
|
|
5872
|
+
constructor(error) {
|
|
5873
|
+
let messageEnd = "";
|
|
5874
|
+
if (error.error.message.match(OAUTH_ERROR_REGEX)) {
|
|
5875
|
+
messageEnd = error.error.message;
|
|
5619
5876
|
}
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5877
|
+
super(`${MISSING_SCOPE_ERROR_PREFIX}
|
|
5878
|
+
${messageEnd}`);
|
|
5879
|
+
Object.setPrototypeOf(this, MissingScopeError.prototype);
|
|
5880
|
+
}
|
|
5624
5881
|
};
|
|
5625
|
-
function
|
|
5626
|
-
|
|
5627
|
-
(importName) => ts.factory.createImportSpecifier(
|
|
5628
|
-
true,
|
|
5629
|
-
void 0,
|
|
5630
|
-
ts.factory.createIdentifier(importName)
|
|
5631
|
-
)
|
|
5632
|
-
);
|
|
5633
|
-
const namedImports = ts.factory.createNamedImports(importSpecifiers);
|
|
5634
|
-
return ts.factory.createImportDeclaration(
|
|
5635
|
-
[],
|
|
5636
|
-
[],
|
|
5637
|
-
ts.factory.createImportClause(false, void 0, namedImports),
|
|
5638
|
-
ts.factory.createStringLiteral(moduleSpecifier)
|
|
5639
|
-
);
|
|
5882
|
+
function logMissingScopeWarning(error) {
|
|
5883
|
+
console.warn(error.message);
|
|
5640
5884
|
}
|
|
5641
|
-
function
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5885
|
+
function isMissingScopeError(error) {
|
|
5886
|
+
return error.statusCode === 403 && (error.error.message.match(OAUTH_ERROR_REGEX) || error.error.message.startsWith(NOT_PUBLIC_USE_ERROR));
|
|
5887
|
+
}
|
|
5888
|
+
function handleSecretsError(error) {
|
|
5889
|
+
if (error && error.statusCode && error.error) {
|
|
5890
|
+
const { statusCode, error: errorDetails } = error;
|
|
5891
|
+
if ((errorDetails == null ? void 0 : errorDetails.category) === "MISSING_SCOPES") {
|
|
5892
|
+
console.log(
|
|
5893
|
+
"\nMissing scopes for secrets.",
|
|
5894
|
+
"\nSecrets require Serverless functions which are scoped to Enterprise portals.\n"
|
|
5895
|
+
);
|
|
5896
|
+
} else {
|
|
5897
|
+
console.error(`Error ${statusCode}: ${errorDetails.message}`);
|
|
5898
|
+
if (errorDetails.correlationId) {
|
|
5899
|
+
console.error(`Correlation ID: ${errorDetails.correlationId}`);
|
|
5900
|
+
}
|
|
5901
|
+
if (errorDetails.category) {
|
|
5902
|
+
console.error(`Category: ${errorDetails.category}`);
|
|
5903
|
+
}
|
|
5904
|
+
if (errorDetails.links) {
|
|
5905
|
+
if (errorDetails.links.support) {
|
|
5906
|
+
console.error(`Support URL: ${errorDetails.links.support}`);
|
|
5907
|
+
}
|
|
5908
|
+
if (errorDetails.links.forum) {
|
|
5909
|
+
console.error(`Forum URL: ${errorDetails.links.forum}`);
|
|
5910
|
+
}
|
|
5655
5911
|
}
|
|
5656
5912
|
}
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5913
|
+
} else {
|
|
5914
|
+
console.error("Unexpected error structure:", error);
|
|
5915
|
+
}
|
|
5916
|
+
}
|
|
5917
|
+
|
|
5918
|
+
// src/proxyPage/fetchDomains.ts
|
|
5919
|
+
async function fetchDomains(portalId) {
|
|
5920
|
+
try {
|
|
5921
|
+
const result = (await hsCliHttp11.get(portalId, {
|
|
5922
|
+
url: `/cms/v3/domains`,
|
|
5923
|
+
params: { portalId },
|
|
5924
|
+
responseType: "json"
|
|
5925
|
+
})).data;
|
|
5926
|
+
return result.results;
|
|
5927
|
+
} catch (error) {
|
|
5928
|
+
if (isMissingScopeError(error)) {
|
|
5929
|
+
throw new MissingScopeError(error);
|
|
5930
|
+
}
|
|
5931
|
+
throw error;
|
|
5932
|
+
}
|
|
5933
|
+
}
|
|
5934
|
+
async function fetchWebsiteDomainNames(portalId) {
|
|
5935
|
+
const domains = await fetchDomains(portalId);
|
|
5936
|
+
const filteredDomains = domains.filter((domain) => {
|
|
5937
|
+
return domain.isUsedForBlogPost || domain.isUsedForSitePage || domain.isUsedForLandingPage;
|
|
5660
5938
|
});
|
|
5661
|
-
const
|
|
5662
|
-
|
|
5663
|
-
);
|
|
5664
|
-
return { types, imports: validImports };
|
|
5939
|
+
const domainNames = filteredDomains.map((r) => r.domain);
|
|
5940
|
+
return domainNames;
|
|
5665
5941
|
}
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
);
|
|
5675
|
-
const wrappedType = ts.factory.createTypeReferenceNode(DEFAULT_VALUES_TYPE, [
|
|
5676
|
-
baseType.type
|
|
5677
|
-
]);
|
|
5678
|
-
const finalType = ts.factory.createTypeAliasDeclaration(
|
|
5679
|
-
[],
|
|
5680
|
-
[],
|
|
5681
|
-
typeName,
|
|
5682
|
-
void 0,
|
|
5683
|
-
wrappedType
|
|
5684
|
-
);
|
|
5685
|
-
const filteredImports = filterUnusedImports(imports, finalType);
|
|
5686
|
-
const importDeclaration = getImportDeclaration(
|
|
5687
|
-
[...filteredImports, DEFAULT_VALUES_TYPE],
|
|
5688
|
-
CMS_COMPONENTS_FIELD_TYPES
|
|
5689
|
-
);
|
|
5690
|
-
const defaultExport = ts.factory.createExportDefault(
|
|
5691
|
-
ts.factory.createIdentifier(typeName)
|
|
5692
|
-
);
|
|
5693
|
-
return [importDeclaration, finalType, defaultExport];
|
|
5942
|
+
|
|
5943
|
+
// src/lib/validateHSPlatform.ts
|
|
5944
|
+
import path18 from "path";
|
|
5945
|
+
import fs10 from "fs";
|
|
5946
|
+
import { http as hsCliHttp12 } from "@hubspot/local-dev-lib/http";
|
|
5947
|
+
var HSPROJECT_JSON = "hsproject.json";
|
|
5948
|
+
function checkFileExists(filePath) {
|
|
5949
|
+
return fs10.existsSync(filePath) && fs10.statSync(filePath).isFile();
|
|
5694
5950
|
}
|
|
5695
|
-
function
|
|
5696
|
-
|
|
5697
|
-
|
|
5698
|
-
|
|
5951
|
+
function findHSProjectJson(startPath) {
|
|
5952
|
+
let currentDir = startPath;
|
|
5953
|
+
let dirLevel = 0;
|
|
5954
|
+
const maxDirLevel = 4;
|
|
5955
|
+
while (path18.dirname(currentDir) !== currentDir && dirLevel < maxDirLevel) {
|
|
5956
|
+
const filePath = path18.join(currentDir, HSPROJECT_JSON);
|
|
5957
|
+
if (checkFileExists(filePath)) {
|
|
5958
|
+
return filePath;
|
|
5959
|
+
}
|
|
5960
|
+
currentDir = path18.dirname(currentDir);
|
|
5961
|
+
dirLevel++;
|
|
5699
5962
|
}
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
const nodes = constructFinalType(entries, typeName);
|
|
5710
|
-
const comments = [
|
|
5711
|
-
AUTO_GEN_COMMENT,
|
|
5712
|
-
"Removing the above comment will disable type generation for this module",
|
|
5713
|
-
"This file was created by @hubspot/cms-dev-server, for more information see https://github.hubspot.com/cms-react/reference/js-modules.html#module-fields"
|
|
5714
|
-
].map((comment) => `// ${comment}`);
|
|
5715
|
-
const typeResult = nodes.map(
|
|
5716
|
-
(node) => printer.printNode(ts.EmitHint.Unspecified, node, file)
|
|
5963
|
+
console.log(
|
|
5964
|
+
`'${HSPROJECT_JSON}' not found in any parent of dev server target`
|
|
5965
|
+
);
|
|
5966
|
+
return null;
|
|
5967
|
+
}
|
|
5968
|
+
async function validateHSPlatform(projectConfigPath, portalId, deferSelection) {
|
|
5969
|
+
if (projectConfigPath === null) {
|
|
5970
|
+
console.log(
|
|
5971
|
+
`Unable to find local ${HSPROJECT_JSON}, skipping platform version validation.`
|
|
5717
5972
|
);
|
|
5718
|
-
const result = [...comments, ...typeResult].join("\n");
|
|
5719
|
-
writeFileSync(fileName, result);
|
|
5720
|
-
return true;
|
|
5721
|
-
} catch (e) {
|
|
5722
|
-
console.error(e);
|
|
5723
5973
|
return false;
|
|
5724
5974
|
}
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
import path16 from "path";
|
|
5730
|
-
import readline from "readline";
|
|
5731
|
-
var lastSerializedFieldsCache = {};
|
|
5732
|
-
var formatAsTypeName = (str) => {
|
|
5733
|
-
const typeName = `${str.replace(/[^a-zA-Z0-9_$]/g, "_")}FieldsType`;
|
|
5734
|
-
const validFirstChar = /^[A-Za-z_$]/.test(str.charAt(0));
|
|
5735
|
-
return validFirstChar ? typeName : `_${typeName}`;
|
|
5736
|
-
};
|
|
5737
|
-
var isInModulesFolder = (filePath, projectRoot) => {
|
|
5738
|
-
const getEntryPathFromId = (id) => {
|
|
5739
|
-
return id.startsWith(projectRoot) ? id.replace(`${projectRoot}${path16.sep}`, "") : "";
|
|
5740
|
-
};
|
|
5741
|
-
const currentModuleId = path16.normalize(filePath);
|
|
5742
|
-
const moduleEntryPath = getEntryPathFromId(currentModuleId);
|
|
5743
|
-
const subFolderTokens = moduleEntryPath.split(path16.sep);
|
|
5744
|
-
return {
|
|
5745
|
-
inModuleFolder: subFolderTokens[0] === "components" && subFolderTokens[1] === "modules",
|
|
5746
|
-
isRootModuleFile: subFolderTokens.length === 3
|
|
5747
|
-
};
|
|
5748
|
-
};
|
|
5749
|
-
var fileContainsAutoGenComment = async (filePath) => {
|
|
5750
|
-
if (!fs8.existsSync(filePath))
|
|
5751
|
-
return true;
|
|
5752
|
-
const stream2 = fs8.createReadStream(filePath);
|
|
5753
|
-
const reader = readline.createInterface({ input: stream2 });
|
|
5754
|
-
const firstLine = await new Promise(
|
|
5755
|
-
(resolve2) => reader.once("line", (line) => resolve2(line.trim()))
|
|
5756
|
-
);
|
|
5757
|
-
reader.close();
|
|
5758
|
-
stream2.close();
|
|
5759
|
-
return firstLine && firstLine === `// ${AUTO_GEN_COMMENT}`;
|
|
5760
|
-
};
|
|
5761
|
-
var getIndexFile = (filePath, projectRoot) => {
|
|
5762
|
-
const { inModuleFolder, isRootModuleFile } = isInModulesFolder(
|
|
5763
|
-
filePath,
|
|
5764
|
-
projectRoot
|
|
5765
|
-
);
|
|
5766
|
-
if (!inModuleFolder)
|
|
5767
|
-
return void 0;
|
|
5768
|
-
if (isRootModuleFile)
|
|
5769
|
-
return { indexFilePath: filePath, isRootModuleFile };
|
|
5770
|
-
const dir = path16.dirname(filePath);
|
|
5771
|
-
const files = fs8.readdirSync(dir);
|
|
5772
|
-
const indexFileName = files.find((file) => file.startsWith("index."));
|
|
5773
|
-
return indexFileName ? { indexFilePath: path16.join(dir, indexFileName), isRootModuleFile } : void 0;
|
|
5774
|
-
};
|
|
5775
|
-
var getIndexFileFields = async (indexFilePath, indexFileName, viteServer) => {
|
|
5776
|
-
let indexFile;
|
|
5777
|
-
let renderFieldsToJson;
|
|
5975
|
+
const hsProjectJSONContents = fs10.readFileSync(projectConfigPath, "utf8");
|
|
5976
|
+
const hsProjectJSONData = JSON.parse(hsProjectJSONContents);
|
|
5977
|
+
const { platformVersion } = hsProjectJSONData;
|
|
5978
|
+
let platformVersionResult;
|
|
5778
5979
|
try {
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5980
|
+
platformVersionResult = (await hsCliHttp12.get(portalId, {
|
|
5981
|
+
url: `developer/projects/v1/platformVersion`,
|
|
5982
|
+
responseType: "json"
|
|
5983
|
+
})).data;
|
|
5782
5984
|
} catch (e) {
|
|
5783
|
-
|
|
5985
|
+
console.error(e.message);
|
|
5986
|
+
console.log(
|
|
5987
|
+
"Unable to find active platform versions, skipping platform version validation."
|
|
5988
|
+
);
|
|
5989
|
+
return false;
|
|
5784
5990
|
}
|
|
5785
|
-
if (!
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
|
|
5815
|
-
return;
|
|
5816
|
-
const moduleFolderName = path16.basename(path16.dirname(filePath));
|
|
5817
|
-
const outputTypeName = formatAsTypeName(moduleFolderName);
|
|
5818
|
-
const didSucceed = writeFieldsType(fields, typeFilePath, outputTypeName);
|
|
5819
|
-
if (didSucceed) {
|
|
5820
|
-
lastSerializedFieldsCache[typeFilePath] = serializedFields;
|
|
5991
|
+
if (platformVersion === void 0 || !platformVersionResult.activePlatformVersions.includes(platformVersion)) {
|
|
5992
|
+
const promptAndWrite = async () => {
|
|
5993
|
+
const { default: select } = await import("@inquirer/select");
|
|
5994
|
+
const answer = await select({
|
|
5995
|
+
message: 'Your local "hsproject.json" does not have a valid platform version, please select a valid platform version. You can read more about Platform Versioning here https://developers.hubspot.com/docs/platform/platform-versioning',
|
|
5996
|
+
choices: platformVersionResult.activePlatformVersions.map(
|
|
5997
|
+
(versionNumber) => ({
|
|
5998
|
+
name: versionNumber,
|
|
5999
|
+
value: versionNumber
|
|
6000
|
+
})
|
|
6001
|
+
)
|
|
6002
|
+
});
|
|
6003
|
+
hsProjectJSONData.platformVersion = answer;
|
|
6004
|
+
try {
|
|
6005
|
+
fs10.writeFileSync(
|
|
6006
|
+
projectConfigPath,
|
|
6007
|
+
JSON.stringify(hsProjectJSONData, void 0, 2),
|
|
6008
|
+
"utf8"
|
|
6009
|
+
);
|
|
6010
|
+
return true;
|
|
6011
|
+
} catch (e) {
|
|
6012
|
+
console.error(
|
|
6013
|
+
`unable to write updated valid platform version, please make sure platformVersion in "${HSPROJECT_JSON}" is one of ${platformVersionResult.activePlatformVersions}`
|
|
6014
|
+
);
|
|
6015
|
+
return false;
|
|
6016
|
+
}
|
|
6017
|
+
};
|
|
6018
|
+
if (deferSelection) {
|
|
6019
|
+
deferSelection(promptAndWrite);
|
|
6020
|
+
return false;
|
|
5821
6021
|
}
|
|
5822
|
-
|
|
5823
|
-
const successMsg = `Successfully generated types for ${pathToLog}`;
|
|
5824
|
-
const errorMsg = `Failed to generate types for ${pathToLog}`;
|
|
5825
|
-
const message = didSucceed ? successMsg : errorMsg;
|
|
5826
|
-
console.log(wrapMessageInColor(didSucceed ? "green" : "red", message));
|
|
6022
|
+
return promptAndWrite();
|
|
5827
6023
|
}
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
|
|
5831
|
-
|
|
5832
|
-
|
|
5833
|
-
maybeUpdateFields(resolvedPath, viteServer, projectRoot);
|
|
5834
|
-
});
|
|
5835
|
-
const watchCallback = (filePath) => maybeUpdateFields(filePath, viteServer, projectRoot);
|
|
5836
|
-
viteServer.watcher.on("add", watchCallback).on("change", watchCallback);
|
|
5837
|
-
};
|
|
6024
|
+
return true;
|
|
6025
|
+
}
|
|
6026
|
+
|
|
6027
|
+
// src/createDevServer.ts
|
|
6028
|
+
import { http as hsCliHttp13 } from "@hubspot/local-dev-lib/http";
|
|
5838
6029
|
|
|
5839
6030
|
// src/lib/configHelpers.ts
|
|
5840
6031
|
function getSecretNamesFromConfig(config) {
|
|
@@ -5861,8 +6052,8 @@ function getWebRootProjectComponentFolder(absoluteWebRoot, projectConfigPath) {
|
|
|
5861
6052
|
return themeFolderName;
|
|
5862
6053
|
}
|
|
5863
6054
|
try {
|
|
5864
|
-
const projectDir =
|
|
5865
|
-
const configContent =
|
|
6055
|
+
const projectDir = path19.dirname(projectConfigPath);
|
|
6056
|
+
const configContent = fs11.readFileSync(projectConfigPath, "utf8");
|
|
5866
6057
|
const projectConfig = JSON.parse(configContent);
|
|
5867
6058
|
if (hasNewDirectoryStructure(projectConfig.platformVersion)) {
|
|
5868
6059
|
const srcDir = projectConfig.srcDir || "src";
|
|
@@ -5932,7 +6123,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
5932
6123
|
}
|
|
5933
6124
|
setTrackingInfo(authedPortalId, authedEnv);
|
|
5934
6125
|
sendTrackingRequest("start-dev-server");
|
|
5935
|
-
const absoluteWebRoot = normalizePath10(
|
|
6126
|
+
const absoluteWebRoot = normalizePath10(path19.resolve(process.cwd(), webRoot));
|
|
5936
6127
|
const projectConfigPath = findHSProjectJson(absoluteWebRoot);
|
|
5937
6128
|
const webRootProjectComponentFolder = getWebRootProjectComponentFolder(
|
|
5938
6129
|
absoluteWebRoot,
|
|
@@ -6004,7 +6195,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
6004
6195
|
});
|
|
6005
6196
|
bootTasks.push(async () => {
|
|
6006
6197
|
try {
|
|
6007
|
-
const accountInformation = (await
|
|
6198
|
+
const accountInformation = (await hsCliHttp13.get(portalId, {
|
|
6008
6199
|
url: "/account-info/v3/details"
|
|
6009
6200
|
})).data;
|
|
6010
6201
|
authedHublet = accountInformation.dataHostingLocation;
|
|
@@ -6046,7 +6237,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
6046
6237
|
secretNames
|
|
6047
6238
|
);
|
|
6048
6239
|
if (fieldGenEnabledOption) {
|
|
6049
|
-
const normalizedAbsoluteWebRoot =
|
|
6240
|
+
const normalizedAbsoluteWebRoot = path19.normalize(absoluteWebRoot);
|
|
6050
6241
|
startFieldsTypeGenWatcher(viteServer, normalizedAbsoluteWebRoot);
|
|
6051
6242
|
}
|
|
6052
6243
|
const viteHTTPSConfig = viteServer.config.server.https;
|
|
@@ -6072,10 +6263,10 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
6072
6263
|
expressServer.locals.sslEnabled = sslEnabledOption;
|
|
6073
6264
|
expressServer.locals.fullHeightPreview = fullHeightPreview;
|
|
6074
6265
|
expressServer.use(bodyParser.json());
|
|
6075
|
-
const __dirname =
|
|
6076
|
-
let appWebRoot = normalizePath10(
|
|
6266
|
+
const __dirname = path19.dirname(url2.fileURLToPath(new URL(import.meta.url)));
|
|
6267
|
+
let appWebRoot = normalizePath10(path19.resolve(__dirname, "../app"));
|
|
6077
6268
|
if (true) {
|
|
6078
|
-
appWebRoot =
|
|
6269
|
+
appWebRoot = path19.join(__dirname, "app");
|
|
6079
6270
|
}
|
|
6080
6271
|
const skipUiServer = isLocalUiDisabled(cmsAssetConfig);
|
|
6081
6272
|
const appViteServer = skipUiServer ? null : await createAppServer_default(appWebRoot, PORT, sslEnabledOption);
|
|
@@ -6143,17 +6334,17 @@ HubSpot CMS dev server running at ${protocol}://hslocal.net:${PORT}${extraServer
|
|
|
6143
6334
|
`;
|
|
6144
6335
|
console.log(startMessage);
|
|
6145
6336
|
if (storybook) {
|
|
6146
|
-
const packageRoot =
|
|
6147
|
-
const configPath =
|
|
6337
|
+
const packageRoot = path19.dirname(url2.fileURLToPath(import.meta.url));
|
|
6338
|
+
const configPath = path19.resolve(packageRoot, "./storybook-main");
|
|
6148
6339
|
sendTrackingRequest("start-storybook");
|
|
6149
6340
|
let storybookBin;
|
|
6150
6341
|
try {
|
|
6151
6342
|
const sbPackagePath = await import.meta.resolve("storybook/package.json");
|
|
6152
|
-
const sbPackageDir =
|
|
6343
|
+
const sbPackageDir = path19.dirname(url2.fileURLToPath(sbPackagePath));
|
|
6153
6344
|
const packageJson = JSON.parse(
|
|
6154
|
-
|
|
6345
|
+
fs11.readFileSync(path19.join(sbPackageDir, "package.json"), "utf-8")
|
|
6155
6346
|
);
|
|
6156
|
-
storybookBin =
|
|
6347
|
+
storybookBin = path19.join(
|
|
6157
6348
|
sbPackageDir,
|
|
6158
6349
|
packageJson.bin.storybook || packageJson.bin
|
|
6159
6350
|
);
|
|
@@ -6190,7 +6381,7 @@ HubSpot CMS dev server running at ${protocol}://hslocal.net:${PORT}${extraServer
|
|
|
6190
6381
|
portalId: authedPortalId.toString(),
|
|
6191
6382
|
hsEnv: authedEnv,
|
|
6192
6383
|
hublet: authedHublet,
|
|
6193
|
-
WEB_ROOT:
|
|
6384
|
+
WEB_ROOT: path19.join(webRoot, "components")
|
|
6194
6385
|
},
|
|
6195
6386
|
stdio: "inherit"
|
|
6196
6387
|
}
|