@hubspot/cms-dev-server 1.2.79 → 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 +15 -9
- package/dist/index.js +2074 -1877
- package/dist/internalSsr.js +3 -5
- package/dist/island-runtime.js +22 -6
- package/dist/run.js +1001 -804
- 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/createViteDevServer.d.ts +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;
|
|
@@ -1138,18 +1134,25 @@ import { join as join2 } from "path";
|
|
|
1138
1134
|
function getPackageJson(packagePath2) {
|
|
1139
1135
|
return JSON.parse(readFileSync2(join2(packagePath2, "package.json")).toString());
|
|
1140
1136
|
}
|
|
1141
|
-
function
|
|
1142
|
-
const packageJson = getPackageJson(packagePath2);
|
|
1143
|
-
return packageJson.dependencies ? Object.keys(packageJson.dependencies) : [];
|
|
1144
|
-
}
|
|
1145
|
-
function getDepsForPackageIfExists(packagePath2) {
|
|
1137
|
+
function getAllDepsForPackageIfExists(packagePath2) {
|
|
1146
1138
|
try {
|
|
1147
|
-
|
|
1139
|
+
const packageJson = getPackageJson(packagePath2);
|
|
1140
|
+
return [
|
|
1141
|
+
.../* @__PURE__ */ new Set([
|
|
1142
|
+
...Object.keys(packageJson.dependencies ?? {}),
|
|
1143
|
+
...Object.keys(packageJson.peerDependencies ?? {})
|
|
1144
|
+
])
|
|
1145
|
+
];
|
|
1148
1146
|
} catch (e) {
|
|
1149
1147
|
console.warn("No package.json at ", packagePath2);
|
|
1150
1148
|
return [];
|
|
1151
1149
|
}
|
|
1152
1150
|
}
|
|
1151
|
+
function hasCmsComponentsDependency(packagePath2) {
|
|
1152
|
+
return getAllDepsForPackageIfExists(packagePath2).includes(
|
|
1153
|
+
"@hubspot/cms-components"
|
|
1154
|
+
);
|
|
1155
|
+
}
|
|
1153
1156
|
async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = [], jsRenderingGates, secretNames, logLevel) {
|
|
1154
1157
|
const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
|
|
1155
1158
|
`${proxyDomain}.localhost`,
|
|
@@ -1161,8 +1164,7 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
1161
1164
|
`);
|
|
1162
1165
|
}
|
|
1163
1166
|
const origin = process.env.VITE_ORIGIN ?? (sslEnabled ? `https://hslocal.net:${port}` : `http://hslocal.net:${port}`);
|
|
1164
|
-
const
|
|
1165
|
-
const isProjectWithReact = consumerDeps.includes("@hubspot/cms-components") || process.env.TRANSLATE_ASSET;
|
|
1167
|
+
const isProjectWithReact = hasCmsComponentsDependency(webRoot) || process.env.TRANSLATE_ASSET;
|
|
1166
1168
|
const componentsShimPlugin = isProjectWithReact ? null : cmsComponentsShimPlugin();
|
|
1167
1169
|
const ssrAndOptimizeDep = isProjectWithReact ? {
|
|
1168
1170
|
ssr: {
|
|
@@ -1235,8 +1237,8 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
1235
1237
|
var createViteDevServer_default = createViteDevServer;
|
|
1236
1238
|
|
|
1237
1239
|
// src/createDevServer.ts
|
|
1238
|
-
import
|
|
1239
|
-
import
|
|
1240
|
+
import path19 from "path";
|
|
1241
|
+
import fs11 from "fs";
|
|
1240
1242
|
import url2 from "url";
|
|
1241
1243
|
import express2 from "express";
|
|
1242
1244
|
import http3 from "http";
|
|
@@ -1657,7 +1659,7 @@ function trackUsage(action) {
|
|
|
1657
1659
|
eventName: EVENT_NAME,
|
|
1658
1660
|
action,
|
|
1659
1661
|
nodeVersion: getNodeVersionData(),
|
|
1660
|
-
version: "1.2.
|
|
1662
|
+
version: "1.2.82",
|
|
1661
1663
|
os: getPlatform()
|
|
1662
1664
|
};
|
|
1663
1665
|
const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -1731,12 +1733,12 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
1731
1733
|
);
|
|
1732
1734
|
offsetSoFar = nearestNewlineOrQuoteAfterBlockOpen;
|
|
1733
1735
|
if (pathEndOffset >= 0 && pathEndOffset < nextNewlineOffset) {
|
|
1734
|
-
const
|
|
1736
|
+
const path20 = body.substring(
|
|
1735
1737
|
startOffset + localJsRenderStartString.length,
|
|
1736
1738
|
pathEndOffset
|
|
1737
1739
|
);
|
|
1738
1740
|
offsetSoFar = pathEndOffset + 1;
|
|
1739
|
-
if (startOffset >= 0 &&
|
|
1741
|
+
if (startOffset >= 0 && path20) {
|
|
1740
1742
|
const nextCommentEndOffset = body.indexOf("-->", pathEndOffset);
|
|
1741
1743
|
const endOffset = body.indexOf(localJsRenderEndString, pathEndOffset);
|
|
1742
1744
|
offsetSoFar = Math.min(nextCommentEndOffset, endOffset);
|
|
@@ -1761,7 +1763,7 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
1761
1763
|
result.push({
|
|
1762
1764
|
startOffset,
|
|
1763
1765
|
endOffset: endOffset + localJsRenderEndString.length,
|
|
1764
|
-
path:
|
|
1766
|
+
path: path20,
|
|
1765
1767
|
json
|
|
1766
1768
|
});
|
|
1767
1769
|
}
|
|
@@ -2160,9 +2162,9 @@ var customColors = [
|
|
|
2160
2162
|
];
|
|
2161
2163
|
var Converter = new AnsiToHtmlConverter({ colors: customColors });
|
|
2162
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;`;
|
|
2163
|
-
var renderLocalError_default = (
|
|
2165
|
+
var renderLocalError_default = (path20, error) => {
|
|
2164
2166
|
const stackWithColorClasses = Converter.toHtml(error.stack);
|
|
2165
|
-
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>`;
|
|
2166
2168
|
};
|
|
2167
2169
|
|
|
2168
2170
|
// src/proxyPage/fetchPreviewInfo.ts
|
|
@@ -3185,7 +3187,6 @@ function getWebDefaultStylesCss(metaUrl) {
|
|
|
3185
3187
|
}
|
|
3186
3188
|
return _webDefaultStylesCss;
|
|
3187
3189
|
}
|
|
3188
|
-
var URL_SIGNING_GATE = "PortalsAccessIdentity:DesignManager:UrlSigning";
|
|
3189
3190
|
async function signGetUrl(authedPortalId, unsignedUrl) {
|
|
3190
3191
|
const urlWithPortalId = new URL(unsignedUrl);
|
|
3191
3192
|
urlWithPortalId.searchParams.set("portalId", `${authedPortalId}`);
|
|
@@ -3202,14 +3203,7 @@ async function signGetUrl(authedPortalId, unsignedUrl) {
|
|
|
3202
3203
|
});
|
|
3203
3204
|
return response.data.signedUrl;
|
|
3204
3205
|
}
|
|
3205
|
-
async function signedGet(authedPortalId, unsignedUrl, headers
|
|
3206
|
-
if (!isUngatedFor(gates, URL_SIGNING_GATE)) {
|
|
3207
|
-
const { data } = await hsCliHttp7.get(authedPortalId, {
|
|
3208
|
-
url: unsignedUrl,
|
|
3209
|
-
headers
|
|
3210
|
-
});
|
|
3211
|
-
return data;
|
|
3212
|
-
}
|
|
3206
|
+
async function signedGet(authedPortalId, unsignedUrl, headers) {
|
|
3213
3207
|
const signedUrl = await signGetUrl(authedPortalId, unsignedUrl);
|
|
3214
3208
|
const accountConfig = getConfigAccountIfExists4(authedPortalId);
|
|
3215
3209
|
const authHeaders = {};
|
|
@@ -3236,7 +3230,7 @@ async function signedGet(authedPortalId, unsignedUrl, headers, gates) {
|
|
|
3236
3230
|
}
|
|
3237
3231
|
return await response.text();
|
|
3238
3232
|
}
|
|
3239
|
-
async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv, cookieValue
|
|
3233
|
+
async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv, cookieValue) {
|
|
3240
3234
|
const moduleInfoQueryParams = new URLSearchParams({
|
|
3241
3235
|
portalId: `${authedPortalId}`
|
|
3242
3236
|
});
|
|
@@ -3260,34 +3254,13 @@ async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv,
|
|
|
3260
3254
|
buffer_theme: `${true}`
|
|
3261
3255
|
});
|
|
3262
3256
|
const cosRenderingUrl = `https://api.hubspot${authedEnv === "qa" ? "qa" : ""}.com/api/cos-rendering/v1/public/_hcms/preview/template/multi?${queryParams}`;
|
|
3263
|
-
const
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
modulePreviewHtml = await signedGet(
|
|
3271
|
-
authedPortalId,
|
|
3272
|
-
cosRenderingUrl,
|
|
3273
|
-
{
|
|
3274
|
-
["content-type"]: "application/x-www-form-urlencoded",
|
|
3275
|
-
["Accept"]: "text/html",
|
|
3276
|
-
referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
|
|
3277
|
-
cookie: cookieValue,
|
|
3278
|
-
"User-Agent": "HubSpot CMS Dev Server"
|
|
3279
|
-
},
|
|
3280
|
-
gates
|
|
3281
|
-
);
|
|
3282
|
-
} finally {
|
|
3283
|
-
if (needsDomainOverride) {
|
|
3284
|
-
if (previousHubApiDomainOverride) {
|
|
3285
|
-
process.env.HUBAPI_DOMAIN_OVERRIDE = previousHubApiDomainOverride;
|
|
3286
|
-
} else {
|
|
3287
|
-
delete process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
3288
|
-
}
|
|
3289
|
-
}
|
|
3290
|
-
}
|
|
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
|
+
});
|
|
3291
3264
|
const previewDoc = parseHtml(modulePreviewHtml);
|
|
3292
3265
|
const modulePreviewContent = extractModuleOuterHtml(previewDoc);
|
|
3293
3266
|
const allStyleContent = extractStyleText(previewDoc);
|
|
@@ -3528,8 +3501,7 @@ var partialRouteHandler = async (request, response) => {
|
|
|
3528
3501
|
remoteModule.path,
|
|
3529
3502
|
authedPortalId,
|
|
3530
3503
|
authedEnv,
|
|
3531
|
-
request.get("COOKIE")
|
|
3532
|
-
jsRenderingGates
|
|
3504
|
+
request.get("COOKIE")
|
|
3533
3505
|
).then((result) => ({
|
|
3534
3506
|
remoteModule,
|
|
3535
3507
|
result
|
|
@@ -3853,294 +3825,685 @@ var moduleFieldsJsonRouteHandler = async (request, response) => {
|
|
|
3853
3825
|
};
|
|
3854
3826
|
var moduleFieldsJson_default = moduleFieldsJsonRouteHandler;
|
|
3855
3827
|
|
|
3856
|
-
// src/
|
|
3857
|
-
import
|
|
3858
|
-
import
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
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;
|
|
3865
3890
|
}
|
|
3866
|
-
return
|
|
3867
|
-
const
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
method: "HEAD",
|
|
3872
|
-
headers: {
|
|
3873
|
-
// Keep this user agent, so we don't get 403s from the request
|
|
3874
|
-
["User-Agent"]: "cms-dev-server"
|
|
3875
|
-
}
|
|
3876
|
-
},
|
|
3877
|
-
async (res) => {
|
|
3878
|
-
let portalIdHeader;
|
|
3879
|
-
let contentId;
|
|
3880
|
-
const isContentMembershipRedirect = Boolean(
|
|
3881
|
-
res.headers["x-hs-content-membership-redirect"]
|
|
3882
|
-
);
|
|
3883
|
-
if (isContentMembershipRedirect) {
|
|
3884
|
-
debug("Content Membership Redirect", res.headers);
|
|
3885
|
-
portalIdHeader = res.headers["x-hs-portal-id"];
|
|
3886
|
-
contentId = res.headers["x-hs-content-id"];
|
|
3887
|
-
if (portalIdHeader && contentId) {
|
|
3888
|
-
return resolve2({
|
|
3889
|
-
portalIdHeader,
|
|
3890
|
-
contentId,
|
|
3891
|
-
res
|
|
3892
|
-
});
|
|
3893
|
-
}
|
|
3894
|
-
}
|
|
3895
|
-
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
3896
|
-
console.log(`Redirecting to ${res.headers.location} (from ${url3})`);
|
|
3897
|
-
return resolve2(
|
|
3898
|
-
requestPage(
|
|
3899
|
-
res.headers.location,
|
|
3900
|
-
redirects + 1,
|
|
3901
|
-
originalUrl ?? url3
|
|
3902
|
-
)
|
|
3903
|
-
);
|
|
3904
|
-
}
|
|
3905
|
-
portalIdHeader = res.headers["x-hs-hub-id"];
|
|
3906
|
-
contentId = res.headers["x-hs-content-id"];
|
|
3907
|
-
return resolve2({
|
|
3908
|
-
res,
|
|
3909
|
-
portalIdHeader,
|
|
3910
|
-
contentId
|
|
3911
|
-
});
|
|
3912
|
-
}
|
|
3913
|
-
).on("error", (err) => {
|
|
3914
|
-
console.error(err);
|
|
3915
|
-
reject(err);
|
|
3916
|
-
}).end();
|
|
3917
|
-
});
|
|
3918
|
-
}
|
|
3919
|
-
async function fetchContentMetadata(url3, portalId) {
|
|
3920
|
-
const { portalIdHeader, contentId, res } = await requestPage(url3);
|
|
3921
|
-
if (Array.isArray(portalIdHeader) || Array.isArray(contentId)) {
|
|
3922
|
-
throw new Error(
|
|
3923
|
-
`There were multiple hub ID or content ID headers in the HEAD request to ${url3}`
|
|
3924
|
-
);
|
|
3925
|
-
} else {
|
|
3926
|
-
const portalIdFromResponse = parseInt(portalIdHeader, 10);
|
|
3927
|
-
const pageAccount = await getConfigAccountIfExists5(portalIdFromResponse);
|
|
3928
|
-
if (!pageAccount) {
|
|
3929
|
-
throw new Error(
|
|
3930
|
-
`No CLI auth for portal ${portalIdFromResponse} found, please run \`hs auth\``
|
|
3931
|
-
);
|
|
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;
|
|
3932
3896
|
}
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
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 };
|
|
3945
3911
|
}
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
}
|
|
3912
|
+
return entry;
|
|
3913
|
+
}).filter((entry) => entry !== void 0);
|
|
3949
3914
|
}
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
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);
|
|
3963
3944
|
}
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
const urlToProxy = `http://${domainToProxy}${request.originalUrl}`;
|
|
3967
|
-
if (!domainToProxy) {
|
|
3968
|
-
if (VALID_PROXY_DOMAIN_SUFFIXES.includes(request.hostname)) {
|
|
3969
|
-
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})`;
|
|
3970
|
-
consoleWarn(message);
|
|
3971
|
-
return response.status(400).send(message);
|
|
3972
|
-
} else {
|
|
3973
|
-
const message = `Can't make a proxy request, the domain '${request.hostname}' is not a valid proxy-able domain`;
|
|
3974
|
-
consoleWarn(message);
|
|
3975
|
-
return response.status(400).send(message);
|
|
3976
|
-
}
|
|
3945
|
+
if (field.isRequired) {
|
|
3946
|
+
imports.push(REQUIRED_TYPE);
|
|
3977
3947
|
}
|
|
3978
|
-
|
|
3979
|
-
const
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
);
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
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
|
|
3996
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;
|
|
3997
4073
|
} catch (e) {
|
|
3998
|
-
|
|
4074
|
+
console.error(e);
|
|
4075
|
+
return false;
|
|
3999
4076
|
}
|
|
4000
4077
|
}
|
|
4001
4078
|
|
|
4002
|
-
// src/
|
|
4003
|
-
import
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
var
|
|
4007
|
-
var
|
|
4008
|
-
|
|
4009
|
-
const
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
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;
|
|
4013
4136
|
}
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
const
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
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;
|
|
4041
4173
|
}
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
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));
|
|
4047
4179
|
}
|
|
4048
|
-
}
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
}
|
|
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
|
+
};
|
|
4055
4190
|
|
|
4056
|
-
// src/
|
|
4191
|
+
// src/validateFields.ts
|
|
4057
4192
|
import { http as hsCliHttp8 } from "@hubspot/local-dev-lib/http";
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
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
|
-
|
|
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 };
|
|
4091
4232
|
}
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
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
|
+
};
|
|
4095
4279
|
}
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
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
|
+
};
|
|
4104
4299
|
}
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
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
|
|
4118
4319
|
);
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
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
|
|
4122
4333
|
);
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
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
|
+
}
|
|
4135
4382
|
);
|
|
4136
|
-
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
4137
4383
|
};
|
|
4138
|
-
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
|
+
}
|
|
4139
4503
|
|
|
4140
|
-
// src/routes/
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
sendTrackingRequest("view-proxy-path-route");
|
|
4504
|
+
// src/routes/proxyPageRouteHandler.ts
|
|
4505
|
+
async function proxyPageRouteHandler(request, response, next) {
|
|
4506
|
+
sendTrackingRequest("view-proxy-page-route");
|
|
4144
4507
|
const {
|
|
4145
4508
|
viteServer,
|
|
4146
4509
|
webRoot,
|
|
@@ -4151,45 +4514,23 @@ async function proxyPathPageRouteHandler(request, response, next) {
|
|
|
4151
4514
|
if (!request.accepts().includes("text/html")) {
|
|
4152
4515
|
return response.sendStatus(404);
|
|
4153
4516
|
}
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
}
|
|
4168
|
-
),
|
|
4169
|
-
/* @__PURE__ */ jsx9("button", { style: { display: "block" }, children: "Proxy" })
|
|
4170
|
-
] })
|
|
4171
|
-
] })
|
|
4172
|
-
);
|
|
4173
|
-
response.status(200).set({ "Content-Type": "text/html" }).end(responseHtml);
|
|
4174
|
-
return;
|
|
4175
|
-
}
|
|
4176
|
-
let proxyPageUrl;
|
|
4177
|
-
try {
|
|
4178
|
-
proxyPageUrl = new URL(request.query.page);
|
|
4179
|
-
} catch (e) {
|
|
4180
|
-
const message = "Please provide a valid page query parameter, e.g., http://localhost:3000/proxy?page=https://yourdomain.com/path";
|
|
4181
|
-
consoleWarn(message);
|
|
4182
|
-
response.status(400).send(message);
|
|
4183
|
-
return;
|
|
4184
|
-
}
|
|
4185
|
-
if (proxyPageUrl.searchParams.has("hs_preview")) {
|
|
4186
|
-
const message = `Can't make a proxy request, you cannot proxy URLs that include internal query params like hs_preview`;
|
|
4187
|
-
consoleWarn(message);
|
|
4188
|
-
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
|
+
}
|
|
4189
4530
|
}
|
|
4190
4531
|
try {
|
|
4191
4532
|
const { portalId, contentId, hublet } = await fetchContentMetadata(
|
|
4192
|
-
|
|
4533
|
+
urlToProxy,
|
|
4193
4534
|
request.app.locals.authedPortalId
|
|
4194
4535
|
);
|
|
4195
4536
|
await proxySpecificPage(
|
|
@@ -4197,1638 +4538,1494 @@ async function proxyPathPageRouteHandler(request, response, next) {
|
|
|
4197
4538
|
response,
|
|
4198
4539
|
portalId,
|
|
4199
4540
|
hublet,
|
|
4200
|
-
contentId,
|
|
4201
|
-
webRoot,
|
|
4202
|
-
viteServer,
|
|
4203
|
-
projectName,
|
|
4204
|
-
projectComponentPath,
|
|
4205
|
-
jsRenderingGates,
|
|
4206
|
-
proxyPageUrl.href,
|
|
4207
|
-
proxyPageUrl.href
|
|
4208
|
-
);
|
|
4209
|
-
} catch (e) {
|
|
4210
|
-
next(e);
|
|
4211
|
-
}
|
|
4212
|
-
}
|
|
4213
|
-
|
|
4214
|
-
// src/routes/proxyPathPageResourceRedirect.ts
|
|
4215
|
-
import fetch3 from "node-fetch";
|
|
4216
|
-
var HCMS_PATH2 = "/_hcms/";
|
|
4217
|
-
var HS_FS_PATH2 = "/hs-fs/";
|
|
4218
|
-
var HUB_FS_PATH2 = "/hubfs/";
|
|
4219
|
-
var isInternalCMSRoute2 = (req) => req.path.startsWith(HCMS_PATH2) || req.path.startsWith(HS_FS_PATH2) || req.path.startsWith(HUB_FS_PATH2);
|
|
4220
|
-
function proxyPathPageResourceRedirect(req, res, next) {
|
|
4221
|
-
const isAHtmlRequest = req.accepts().includes("text/html");
|
|
4222
|
-
let proxyPageUrl;
|
|
4223
|
-
let refererUrl;
|
|
4224
|
-
try {
|
|
4225
|
-
refererUrl = new URL(req.headers.referer);
|
|
4226
|
-
proxyPageUrl = new URL(
|
|
4227
|
-
new URL(req.headers.referer).searchParams.get("page")
|
|
4228
|
-
);
|
|
4229
|
-
} catch (e) {
|
|
4230
|
-
next();
|
|
4231
|
-
return;
|
|
4232
|
-
}
|
|
4233
|
-
if (!refererUrl.pathname.startsWith("/proxy")) {
|
|
4234
|
-
next();
|
|
4235
|
-
return;
|
|
4236
|
-
}
|
|
4237
|
-
if (isAHtmlRequest && !isInternalCMSRoute2(req)) {
|
|
4238
|
-
const encodedPageUrl = encodeURIComponent(
|
|
4239
|
-
`${proxyPageUrl.origin}${req.url}`
|
|
4240
|
-
);
|
|
4241
|
-
res.redirect(`/proxy?page=${encodedPageUrl}`);
|
|
4242
|
-
return;
|
|
4243
|
-
}
|
|
4244
|
-
const urlToProxy = `https://${proxyPageUrl.host}${req.url}`;
|
|
4245
|
-
fetch3(urlToProxy).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
|
|
4246
|
-
}
|
|
4247
|
-
|
|
4248
|
-
// src/routes/proxyServerlessHandler.ts
|
|
4249
|
-
import fetch4 from "node-fetch";
|
|
4250
|
-
var localDomains = ["localhost", "hslocal.net"];
|
|
4251
|
-
function proxyServerlessRequest(req, res, next) {
|
|
4252
|
-
const { method, headers } = req;
|
|
4253
|
-
let refererUrl;
|
|
4254
|
-
let domainToProxy;
|
|
4255
|
-
let body;
|
|
4256
|
-
if (!req.headers.referer) {
|
|
4257
|
-
console.log("unable to proxy serverless request, no referer header found");
|
|
4258
|
-
next();
|
|
4259
|
-
return;
|
|
4260
|
-
}
|
|
4261
|
-
try {
|
|
4262
|
-
refererUrl = new URL(req.headers.referer);
|
|
4263
|
-
const referrerDomain = refererUrl.hostname;
|
|
4264
|
-
if (localDomains.includes(referrerDomain)) {
|
|
4265
|
-
domainToProxy = req.app.locals.domainsToProxy[0];
|
|
4266
|
-
} else {
|
|
4267
|
-
domainToProxy = referrerDomain.replace(/\.localhost|\.hslocal\.net/, "");
|
|
4268
|
-
}
|
|
4269
|
-
} catch (e) {
|
|
4270
|
-
console.log("Error parsing referer URL:", e);
|
|
4271
|
-
next();
|
|
4272
|
-
}
|
|
4273
|
-
if (!domainToProxy) {
|
|
4274
|
-
console.log("No domain to proxy for serverless request, skipping...");
|
|
4275
|
-
next();
|
|
4276
|
-
return;
|
|
4277
|
-
}
|
|
4278
|
-
const urlToProxy = `${refererUrl.protocol}//${domainToProxy}${req.url}`;
|
|
4279
|
-
const contentType = headers["content-type"];
|
|
4280
|
-
const cookie = headers.cookie;
|
|
4281
|
-
if (req.body) {
|
|
4282
|
-
body = JSON.stringify(req.body);
|
|
4283
|
-
}
|
|
4284
|
-
const headersToPass = {
|
|
4285
|
-
...contentType ? { "Content-Type": contentType } : {},
|
|
4286
|
-
...cookie ? { COOKIE: cookie } : {}
|
|
4287
|
-
};
|
|
4288
|
-
const proxyLogArgs = [
|
|
4289
|
-
`attempting to proxy a ${method} serverless request to domain:`,
|
|
4290
|
-
domainToProxy,
|
|
4291
|
-
"for resource:",
|
|
4292
|
-
req.url
|
|
4293
|
-
];
|
|
4294
|
-
if (body) {
|
|
4295
|
-
proxyLogArgs.push("with body:", body);
|
|
4296
|
-
}
|
|
4297
|
-
console.log(...proxyLogArgs);
|
|
4298
|
-
switch (method) {
|
|
4299
|
-
case "POST":
|
|
4300
|
-
case "DELETE":
|
|
4301
|
-
case "PUT":
|
|
4302
|
-
fetch4(urlToProxy, {
|
|
4303
|
-
method,
|
|
4304
|
-
body,
|
|
4305
|
-
headers: headersToPass
|
|
4306
|
-
}).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
|
|
4307
|
-
break;
|
|
4308
|
-
default:
|
|
4309
|
-
fetch4(urlToProxy, {
|
|
4310
|
-
headers: headersToPass
|
|
4311
|
-
}).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
|
|
4312
|
-
}
|
|
4313
|
-
}
|
|
4314
|
-
|
|
4315
|
-
// src/routes/modulePreviewRouteHandler.ts
|
|
4316
|
-
import path10 from "path";
|
|
4317
|
-
import { normalizePath as normalizePath8 } from "vite";
|
|
4318
|
-
async function modulePreviewRouteHandler(request, response) {
|
|
4319
|
-
sendTrackingRequest("view-module-preview-route");
|
|
4320
|
-
const {
|
|
4321
|
-
authedPortalId,
|
|
4322
|
-
authedEnv,
|
|
4323
|
-
authedHublet,
|
|
4324
|
-
webRoot,
|
|
4325
|
-
viteServer,
|
|
4326
|
-
jsRenderingGates,
|
|
4327
|
-
projectName,
|
|
4328
|
-
projectComponentPath,
|
|
4329
|
-
fullHeightPreview
|
|
4330
|
-
} = request.app.locals;
|
|
4331
|
-
const moduleName = request.params.moduleName;
|
|
4332
|
-
const modulePath = normalizePath8(
|
|
4333
|
-
path10.resolve(webRoot, "components/modules/", moduleName)
|
|
4334
|
-
);
|
|
4335
|
-
const PREVIEWER_APP_PARAM = "hsPreviewerApp";
|
|
4336
|
-
let fieldOverrides = {};
|
|
4337
|
-
if (request.method === "POST" && request.body) {
|
|
4338
|
-
if (request.query[PREVIEWER_APP_PARAM] === "module" && request.body.module_data) {
|
|
4339
|
-
fieldOverrides = request.body.module_data;
|
|
4340
|
-
} else {
|
|
4341
|
-
fieldOverrides = request.body;
|
|
4342
|
-
}
|
|
4343
|
-
try {
|
|
4344
|
-
if (typeof fieldOverrides === "string") {
|
|
4345
|
-
const parsedFieldOverrides = JSON.parse(fieldOverrides);
|
|
4346
|
-
if (parsedFieldOverrides && typeof parsedFieldOverrides === "object" && !Array.isArray(parsedFieldOverrides)) {
|
|
4347
|
-
fieldOverrides = parsedFieldOverrides;
|
|
4348
|
-
} else {
|
|
4349
|
-
throw new Error("Parsed field overrides must be an object");
|
|
4350
|
-
}
|
|
4351
|
-
}
|
|
4352
|
-
} catch (e) {
|
|
4353
|
-
console.error(
|
|
4354
|
-
`Error parsing field for module "${moduleName}": ${e.message}`,
|
|
4355
|
-
"\nReceived value:",
|
|
4356
|
-
fieldOverrides
|
|
4357
|
-
);
|
|
4358
|
-
}
|
|
4359
|
-
} else if (request.query.fields) {
|
|
4360
|
-
try {
|
|
4361
|
-
if (typeof request.query.fields === "string") {
|
|
4362
|
-
fieldOverrides = JSON.parse(
|
|
4363
|
-
decodeURIComponent(request.query.fields.replace(/\+/g, "%20"))
|
|
4364
|
-
);
|
|
4365
|
-
}
|
|
4366
|
-
} catch (e) {
|
|
4367
|
-
console.error(
|
|
4368
|
-
`Error parsing field param for module ${moduleName}: ${request.query.fields}`
|
|
4369
|
-
);
|
|
4370
|
-
}
|
|
4371
|
-
}
|
|
4372
|
-
try {
|
|
4373
|
-
const {
|
|
4374
|
-
html: renderedHtml,
|
|
4375
|
-
cssNeeded,
|
|
4376
|
-
renderContext,
|
|
4377
|
-
inlineAssets,
|
|
4378
|
-
globalStylesCss,
|
|
4379
|
-
sectionVariant
|
|
4380
|
-
} = await renderLocalProjectModulePreview(
|
|
4381
|
-
moduleName,
|
|
4382
|
-
authedPortalId,
|
|
4383
|
-
authedEnv,
|
|
4384
|
-
authedHublet,
|
|
4541
|
+
contentId,
|
|
4385
4542
|
webRoot,
|
|
4386
4543
|
viteServer,
|
|
4387
|
-
jsRenderingGates,
|
|
4388
4544
|
projectName,
|
|
4389
4545
|
projectComponentPath,
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
);
|
|
4394
|
-
const baseTemplatePath = packagePath(
|
|
4395
|
-
import.meta.url,
|
|
4396
|
-
"html/baseTemplate.html"
|
|
4397
|
-
);
|
|
4398
|
-
const htmlShell = await createHtmlShellDependingOnRenderContext(
|
|
4399
|
-
baseTemplatePath,
|
|
4400
|
-
request.originalUrl,
|
|
4401
|
-
`Module: ${modulePath}`,
|
|
4402
|
-
renderContext,
|
|
4403
|
-
viteServer,
|
|
4404
|
-
jsRenderingGates
|
|
4405
|
-
);
|
|
4406
|
-
const fullHeightCss = fullHeightPreview ? `<style>html,body{height:100%;width:100%;margin:0}#root{height:100%;width:100%}</style>` : "";
|
|
4407
|
-
const bodyHtml = sectionVariant ? `<div data-section-variant="${sectionVariant}">${renderedHtml}</div>` : renderedHtml;
|
|
4408
|
-
const html = addScriptInjectionBootstrapper(
|
|
4409
|
-
htmlShell.replace(
|
|
4410
|
-
"<!--headend-->",
|
|
4411
|
-
[
|
|
4412
|
-
globalStylesCss,
|
|
4413
|
-
fullHeightCss,
|
|
4414
|
-
cssNeeded,
|
|
4415
|
-
...inlineAssets.map((inlineAsset) => inlineAsset.html)
|
|
4416
|
-
].join("\n")
|
|
4417
|
-
).replace(`<!--ssr-outlet-->`, bodyHtml),
|
|
4418
|
-
request.query
|
|
4546
|
+
jsRenderingGates,
|
|
4547
|
+
urlToProxy,
|
|
4548
|
+
fullOriginalUrl
|
|
4419
4549
|
);
|
|
4420
|
-
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
4421
4550
|
} catch (e) {
|
|
4422
|
-
|
|
4423
|
-
viteServer.ssrFixStacktrace(e);
|
|
4424
|
-
return response.status(500).end(`Error rendering module (${moduleName})
|
|
4425
|
-
|
|
4426
|
-
${e.stack}`);
|
|
4551
|
+
next(e);
|
|
4427
4552
|
}
|
|
4428
4553
|
}
|
|
4429
|
-
var modulePreviewRouteHandler_default = modulePreviewRouteHandler;
|
|
4430
4554
|
|
|
4431
|
-
// src/routes/
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
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();
|
|
4438
4565
|
return;
|
|
4439
4566
|
}
|
|
4440
|
-
const
|
|
4441
|
-
const
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
}
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
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));
|
|
4449
4600
|
}
|
|
4450
|
-
|
|
4451
|
-
|
|
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();
|
|
4452
4656
|
return;
|
|
4453
4657
|
}
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
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);
|
|
4469
4690
|
};
|
|
4470
|
-
var
|
|
4471
|
-
<div>
|
|
4472
|
-
<h2>Module</h2>
|
|
4473
|
-
<p>ERROR</p>
|
|
4474
|
-
</div>
|
|
4475
|
-
`);
|
|
4476
|
-
var buildModuleIndex = () => buildHTMLResponse(`
|
|
4477
|
-
<div>
|
|
4478
|
-
<h2>Module</h2>
|
|
4479
|
-
<p>Please provide a module path in the request</p>
|
|
4480
|
-
</div>
|
|
4481
|
-
`);
|
|
4691
|
+
var legacyRouteHandler_default = legacyRouteHandler;
|
|
4482
4692
|
|
|
4483
|
-
// src/routes/
|
|
4484
|
-
import {
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
var templateRouteHandler = async (request, response) => {
|
|
4488
|
-
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");
|
|
4489
4697
|
const {
|
|
4490
|
-
authedPortalId,
|
|
4491
|
-
localPreviewToken,
|
|
4492
|
-
projectName,
|
|
4493
4698
|
viteServer,
|
|
4494
4699
|
webRoot,
|
|
4700
|
+
projectName,
|
|
4495
4701
|
projectComponentPath,
|
|
4496
4702
|
jsRenderingGates
|
|
4497
4703
|
} = request.app.locals;
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
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);
|
|
4508
4727
|
return;
|
|
4509
4728
|
}
|
|
4510
|
-
|
|
4511
|
-
let templateInfo;
|
|
4729
|
+
let proxyPageUrl;
|
|
4512
4730
|
try {
|
|
4513
|
-
|
|
4514
|
-
} catch (
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
);
|
|
4518
|
-
}
|
|
4519
|
-
if (!templateInfo || !("previewKey" in templateInfo)) {
|
|
4520
|
-
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);
|
|
4521
4736
|
return;
|
|
4522
4737
|
}
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
hsLocalProxyProject: localProxyProject,
|
|
4529
|
-
localProxySchemaVersion: "2",
|
|
4530
|
-
hsLoginVerifyDisabled: `${true}`,
|
|
4531
|
-
hsCacheBuster: Date.now().toString(),
|
|
4532
|
-
...request.query
|
|
4533
|
-
};
|
|
4534
|
-
const previewUrl = getPreviewUrl(request, params);
|
|
4535
|
-
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
|
+
}
|
|
4536
4743
|
try {
|
|
4537
|
-
const
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
{},
|
|
4541
|
-
jsRenderingGates
|
|
4542
|
-
);
|
|
4543
|
-
const pageHtml = addRefreshScript(result);
|
|
4544
|
-
const finalHtml = pageHtml.replace(
|
|
4545
|
-
HUBSPOT_PREVIEW_BASE_TAG_REGEX,
|
|
4546
|
-
'<base href="/" />'
|
|
4744
|
+
const { portalId, contentId, hublet } = await fetchContentMetadata(
|
|
4745
|
+
proxyPageUrl.href,
|
|
4746
|
+
request.app.locals.authedPortalId
|
|
4547
4747
|
);
|
|
4548
|
-
|
|
4748
|
+
await proxySpecificPage(
|
|
4749
|
+
request,
|
|
4549
4750
|
response,
|
|
4550
|
-
|
|
4751
|
+
portalId,
|
|
4752
|
+
hublet,
|
|
4753
|
+
contentId,
|
|
4551
4754
|
webRoot,
|
|
4552
|
-
fullOriginalUrl,
|
|
4553
|
-
environmentConfig,
|
|
4554
4755
|
viteServer,
|
|
4555
4756
|
projectName,
|
|
4556
4757
|
projectComponentPath,
|
|
4557
4758
|
jsRenderingGates,
|
|
4558
|
-
|
|
4759
|
+
proxyPageUrl.href,
|
|
4760
|
+
proxyPageUrl.href
|
|
4559
4761
|
);
|
|
4560
|
-
} catch (
|
|
4561
|
-
|
|
4562
|
-
response.status(500).set({ "Content-Type": "text/html" }).end(buildErrorIndex2());
|
|
4762
|
+
} catch (e) {
|
|
4763
|
+
next(e);
|
|
4563
4764
|
}
|
|
4564
|
-
};
|
|
4565
|
-
function buildErrorIndex2() {
|
|
4566
|
-
return buildHTMLResponse(`
|
|
4567
|
-
<div>
|
|
4568
|
-
<h2>Error</h2>
|
|
4569
|
-
<p>Failed to fetch template data.</p>
|
|
4570
|
-
</div>
|
|
4571
|
-
`);
|
|
4572
|
-
}
|
|
4573
|
-
function buildTemplateIndex() {
|
|
4574
|
-
return buildHTMLResponse(`
|
|
4575
|
-
<div>
|
|
4576
|
-
<h2>Template</h2>
|
|
4577
|
-
<p>Please provide a template path in the request</p>
|
|
4578
|
-
</div>
|
|
4579
|
-
`);
|
|
4580
4765
|
}
|
|
4581
4766
|
|
|
4582
|
-
// src/routes/
|
|
4583
|
-
import
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
return "xdg-open";
|
|
4593
|
-
}
|
|
4594
|
-
}
|
|
4595
|
-
async function handleGetModulePages(req, res, next) {
|
|
4596
|
-
const { path: path18, portalId } = req.query;
|
|
4597
|
-
if (!path18 || !portalId) {
|
|
4598
|
-
return res.status(400).json({ error: "Missing required parameters" });
|
|
4599
|
-
}
|
|
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;
|
|
4600
4777
|
try {
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
path18
|
|
4778
|
+
refererUrl = new URL(req.headers.referer);
|
|
4779
|
+
proxyPageUrl = new URL(
|
|
4780
|
+
new URL(req.headers.referer).searchParams.get("page")
|
|
4605
4781
|
);
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
}
|
|
4610
|
-
}
|
|
4611
|
-
function handleOpenFile(req, res, next) {
|
|
4612
|
-
const { path: path18 } = req.query;
|
|
4613
|
-
if (!path18) {
|
|
4614
|
-
return res.status(400).json({ error: "Missing required parameters" });
|
|
4615
|
-
}
|
|
4616
|
-
try {
|
|
4617
|
-
sendTrackingRequest("handle-open-file");
|
|
4618
|
-
const command = getOpenCommand();
|
|
4619
|
-
spawn(command, [path18], { detached: true }).unref();
|
|
4620
|
-
res.sendStatus(200);
|
|
4621
|
-
} catch (err) {
|
|
4622
|
-
next(err);
|
|
4623
|
-
}
|
|
4624
|
-
}
|
|
4625
|
-
function createAppServerAPIRoutes() {
|
|
4626
|
-
const router = Router();
|
|
4627
|
-
router.get("/module-pages", handleGetModulePages);
|
|
4628
|
-
router.get("/open-file", handleOpenFile);
|
|
4629
|
-
return router;
|
|
4630
|
-
}
|
|
4631
|
-
var createAppServerAPIRoutes_default = createAppServerAPIRoutes;
|
|
4632
|
-
|
|
4633
|
-
// src/routes/appServerRouteHandler.ts
|
|
4634
|
-
import fs5 from "node:fs/promises";
|
|
4635
|
-
import path12 from "path";
|
|
4636
|
-
import { pathToFileURL } from "url";
|
|
4637
|
-
|
|
4638
|
-
// src/lib/getDevServerUIData.ts
|
|
4639
|
-
import path11 from "path";
|
|
4640
|
-
import { normalizePath as normalizePath9 } from "vite";
|
|
4641
|
-
|
|
4642
|
-
// src/api/project.ts
|
|
4643
|
-
import { http as hsCliHttp9 } from "@hubspot/local-dev-lib/http";
|
|
4644
|
-
var DEVELOPER_PROJECTS_API_PATH = "/developer/projects/v1";
|
|
4645
|
-
async function fetchProjectByName(accountId, projectName) {
|
|
4646
|
-
return (await hsCliHttp9.get(accountId, {
|
|
4647
|
-
url: `${DEVELOPER_PROJECTS_API_PATH}/by-name/${projectName}`
|
|
4648
|
-
})).data;
|
|
4649
|
-
}
|
|
4650
|
-
|
|
4651
|
-
// src/lib/getDevServerUIData.ts
|
|
4652
|
-
import fs4 from "node:fs";
|
|
4653
|
-
var templateTypeMap = {
|
|
4654
|
-
// Standard templates
|
|
4655
|
-
4: "Page",
|
|
4656
|
-
2: "Email",
|
|
4657
|
-
42: "Blog Listing",
|
|
4658
|
-
41: "Blog Post",
|
|
4659
|
-
6: "Blog (Deprecated)",
|
|
4660
|
-
// Global partials
|
|
4661
|
-
38: "Global Partial",
|
|
4662
|
-
18: "Global Group",
|
|
4663
|
-
// System templates
|
|
4664
|
-
11: "Error Page",
|
|
4665
|
-
19: "Password Prompt",
|
|
4666
|
-
29: "Membership Login",
|
|
4667
|
-
30: "Membership Register",
|
|
4668
|
-
31: "Membership Reset",
|
|
4669
|
-
32: "Membership Reset Request",
|
|
4670
|
-
12: "Subscription Preferences",
|
|
4671
|
-
14: "Backup Unsubscribe",
|
|
4672
|
-
27: "Search Results"
|
|
4673
|
-
};
|
|
4674
|
-
function mapReactModules(modules, themeWebRoot, appViteServer) {
|
|
4675
|
-
return Promise.all(
|
|
4676
|
-
modules.moduleNames.map(async (name, index) => {
|
|
4677
|
-
const modulePath = normalizePath9(
|
|
4678
|
-
path11.resolve(themeWebRoot, "components/modules/", name)
|
|
4679
|
-
);
|
|
4680
|
-
const fieldsJson = await renderModuleFieldsJson_default(
|
|
4681
|
-
appViteServer,
|
|
4682
|
-
modulePath
|
|
4683
|
-
);
|
|
4684
|
-
return {
|
|
4685
|
-
name,
|
|
4686
|
-
type: "react" /* REACT */,
|
|
4687
|
-
subPath: modules.moduleSubpaths[index],
|
|
4688
|
-
nameWithExtension: modules.moduleNamesWithExtension[index],
|
|
4689
|
-
extension: modules.moduleExtensions[index],
|
|
4690
|
-
fieldsJson
|
|
4691
|
-
};
|
|
4692
|
-
})
|
|
4693
|
-
);
|
|
4694
|
-
}
|
|
4695
|
-
function normalizeHubLModules(modules, projectName) {
|
|
4696
|
-
return modules.map((module) => {
|
|
4697
|
-
const subPath = projectName ? `${module.path.split("/@projects/")[1] || module.path}` : removePreviewPrefix(module.path);
|
|
4698
|
-
return {
|
|
4699
|
-
name: module.name,
|
|
4700
|
-
type: "hubl" /* HUBL */,
|
|
4701
|
-
subPath,
|
|
4702
|
-
nameWithExtension: module.filename,
|
|
4703
|
-
fieldsJson: module.fields
|
|
4704
|
-
};
|
|
4705
|
-
});
|
|
4706
|
-
}
|
|
4707
|
-
function normalizePartialsData(partialData) {
|
|
4708
|
-
return partialData.partialNames.map((name, index) => ({
|
|
4709
|
-
name,
|
|
4710
|
-
subPath: partialData.partialSubpaths[index]
|
|
4711
|
-
}));
|
|
4712
|
-
}
|
|
4713
|
-
function normalizeTemplatesData(templates, projectName) {
|
|
4714
|
-
return templates.filter((template) => template.templateType in templateTypeMap).map((template) => {
|
|
4715
|
-
const subPath = projectName ? `@projects/${template.path.split("/@projects/")[1] || template.path}` : removePreviewPrefix(template.path);
|
|
4716
|
-
return {
|
|
4717
|
-
name: template.displayName || template.label,
|
|
4718
|
-
subPath,
|
|
4719
|
-
templateTypeLabel: templateTypeMap[template.templateType]
|
|
4720
|
-
};
|
|
4721
|
-
});
|
|
4722
|
-
}
|
|
4723
|
-
function detectPackageManager(projectRoot) {
|
|
4724
|
-
if (fs4.existsSync(path11.join(projectRoot, "yarn.lock")))
|
|
4725
|
-
return "yarn";
|
|
4726
|
-
if (fs4.existsSync(path11.join(projectRoot, "pnpm-lock.yaml")))
|
|
4727
|
-
return "pnpm";
|
|
4728
|
-
return "npm";
|
|
4729
|
-
}
|
|
4730
|
-
async function getDevServerUIData(appLocals) {
|
|
4731
|
-
const {
|
|
4732
|
-
themeWebRoot,
|
|
4733
|
-
authedEnv,
|
|
4734
|
-
authedPortalId,
|
|
4735
|
-
projectName,
|
|
4736
|
-
localPreviewToken,
|
|
4737
|
-
webRootProjectComponentFolder,
|
|
4738
|
-
sslEnabled,
|
|
4739
|
-
fieldBuilderEnabled,
|
|
4740
|
-
appViteServer
|
|
4741
|
-
} = appLocals;
|
|
4742
|
-
const modulesData = findAllModulesInRoot(themeWebRoot);
|
|
4743
|
-
const partialsData = findAllPartialsInRoot(themeWebRoot);
|
|
4744
|
-
let packageJson = { scripts: {} };
|
|
4745
|
-
let packageManager = "";
|
|
4746
|
-
let cliCommands = [];
|
|
4747
|
-
let reactModules = [];
|
|
4748
|
-
if (projectName) {
|
|
4749
|
-
packageJson = getPackageJson(themeWebRoot);
|
|
4750
|
-
packageManager = detectPackageManager(themeWebRoot);
|
|
4751
|
-
const runCommand = packageManager === "yarn" ? "yarn" : `${packageManager} run`;
|
|
4752
|
-
cliCommands = projectName ? Object.entries((packageJson == null ? void 0 : packageJson.scripts) || {}).map(
|
|
4753
|
-
([scriptName, description]) => ({
|
|
4754
|
-
scriptName,
|
|
4755
|
-
description,
|
|
4756
|
-
runCommand: `${runCommand} ${scriptName}`
|
|
4757
|
-
})
|
|
4758
|
-
) : [];
|
|
4759
|
-
reactModules = projectName && appViteServer ? await mapReactModules(modulesData, themeWebRoot, appViteServer) : [];
|
|
4782
|
+
} catch (e) {
|
|
4783
|
+
next();
|
|
4784
|
+
return;
|
|
4760
4785
|
}
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
if (
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
fetchHubLModules(authedPortalId, localPreviewToken),
|
|
4769
|
-
fetchPreviewTemplates(authedPortalId, localPreviewToken),
|
|
4770
|
-
projectName ? fetchProjectByName(authedPortalId, projectName) : Promise.resolve(null)
|
|
4771
|
-
];
|
|
4772
|
-
[hubLModuleData, hubLTemplateData, projectData] = await Promise.all(dataFetchingPromises);
|
|
4773
|
-
} catch (e) {
|
|
4774
|
-
console.warn("Error fetching data:", e);
|
|
4775
|
-
}
|
|
4776
|
-
normalizedHubLModules = normalizeHubLModules(
|
|
4777
|
-
(hubLModuleData == null ? void 0 : hubLModuleData.objects) || [],
|
|
4778
|
-
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}`
|
|
4779
4793
|
);
|
|
4794
|
+
res.redirect(`/proxy?page=${encodedPageUrl}`);
|
|
4795
|
+
return;
|
|
4780
4796
|
}
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
authedEnv,
|
|
4784
|
-
projectName,
|
|
4785
|
-
modulesData: reactModules,
|
|
4786
|
-
partialsData: normalizePartialsData(partialsData),
|
|
4787
|
-
hubLModules: normalizedHubLModules || [],
|
|
4788
|
-
hubLTemplates: normalizeTemplatesData(
|
|
4789
|
-
(hubLTemplateData == null ? void 0 : hubLTemplateData.objects) || [],
|
|
4790
|
-
projectName
|
|
4791
|
-
),
|
|
4792
|
-
themeWebRoot,
|
|
4793
|
-
webRootProjectComponentFolder,
|
|
4794
|
-
cliCommands,
|
|
4795
|
-
sslEnabled,
|
|
4796
|
-
projectData,
|
|
4797
|
-
fieldBuilderEnabled
|
|
4798
|
-
};
|
|
4797
|
+
const urlToProxy = `https://${proxyPageUrl.host}${req.url}`;
|
|
4798
|
+
fetch3(urlToProxy).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
|
|
4799
4799
|
}
|
|
4800
4800
|
|
|
4801
|
-
// src/routes/
|
|
4802
|
-
|
|
4803
|
-
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
|
+
}
|
|
4804
4814
|
try {
|
|
4805
|
-
|
|
4806
|
-
const
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
const url3 = req.originalUrl.replace("/", "");
|
|
4810
|
-
const templatePath = path12.join(appWebRoot, "index.html");
|
|
4811
|
-
const serverEntryPath = isProd ? path12.join(appWebRoot, "server/serverEntry.js") : path12.join(appWebRoot, "serverEntry.tsx");
|
|
4812
|
-
let render;
|
|
4813
|
-
let template = await fs5.readFile(path12.join(templatePath), "utf-8");
|
|
4814
|
-
if (isProd) {
|
|
4815
|
-
const { render: ssrRender } = await import(pathToFileURL(serverEntryPath).href);
|
|
4816
|
-
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];
|
|
4817
4819
|
} else {
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
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"))
|
|
4821
4917
|
);
|
|
4822
4918
|
}
|
|
4823
|
-
|
|
4824
|
-
|
|
4919
|
+
} catch (e) {
|
|
4920
|
+
console.error(
|
|
4921
|
+
`Error parsing field param for module ${moduleName}: ${request.query.fields}`
|
|
4922
|
+
);
|
|
4825
4923
|
}
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
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
|
|
4832
4946
|
);
|
|
4833
|
-
|
|
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);
|
|
4834
4974
|
} catch (e) {
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
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));
|
|
4839
5021
|
}
|
|
4840
5022
|
};
|
|
4841
|
-
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
|
+
`);
|
|
4842
5035
|
|
|
4843
|
-
// src/routes/
|
|
4844
|
-
import
|
|
4845
|
-
|
|
4846
|
-
var
|
|
4847
|
-
|
|
4848
|
-
);
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
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}`
|
|
4867
5070
|
);
|
|
4868
5071
|
}
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
devServerApp.use("/assets", expressStatic(distAssetsPath));
|
|
4873
|
-
} else if (appViteServer) {
|
|
4874
|
-
devServerApp.use("/local", appViteServer.middlewares);
|
|
5072
|
+
if (!templateInfo || !("previewKey" in templateInfo)) {
|
|
5073
|
+
response.status(500).set({ "Content-Type": "text/html" }).end(buildErrorIndex2());
|
|
5074
|
+
return;
|
|
4875
5075
|
}
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
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());
|
|
4880
5111
|
}
|
|
4881
|
-
devServerApp.get("/legacy", legacyRouteHandler_default);
|
|
4882
|
-
devServerApp.get("/proxy", proxyPathPageRouteHandler);
|
|
4883
|
-
devServerApp.get("/partials/", linksToAllPartialsRouteHandler_default);
|
|
4884
|
-
devServerApp.get("/partial/:partial", partial_default);
|
|
4885
|
-
devServerApp.get("/partial/:partial/*", partial_default);
|
|
4886
|
-
devServerApp.get("/remote-fs-dirty", remoteFsDirtyHandler);
|
|
4887
|
-
devServerApp.get("/preview/module/:moduleName", modulePreviewRouteHandler_default);
|
|
4888
|
-
devServerApp.get("/modules/", linksToAllModulesRouteHandler_default);
|
|
4889
|
-
devServerApp.get("/module/:moduleName", module_default);
|
|
4890
|
-
devServerApp.get(
|
|
4891
|
-
"/preview/module/:moduleName/fields.json",
|
|
4892
|
-
moduleFieldsJson_default
|
|
4893
|
-
);
|
|
4894
|
-
devServerApp.get("/module/:moduleName/*", module_default);
|
|
4895
|
-
devServerApp.post("/preview/module/:moduleName", modulePreviewRouteHandler_default);
|
|
4896
|
-
devServerApp.get("/hublmodule/:modulePath(*)", hublModuleRouteHandler);
|
|
4897
|
-
devServerApp.get("/template/:templatePath(*)", templateRouteHandler);
|
|
4898
|
-
devServerApp.all("/hs/serverless/*", proxyServerlessRequest);
|
|
4899
|
-
devServerApp.all("/_hcms/api/*", proxyServerlessRequest);
|
|
4900
|
-
devServerApp.get("/*", proxyPathPageResourceRedirect);
|
|
4901
|
-
devServerApp.get("/*", proxyPageResourceRedirect);
|
|
4902
|
-
devServerApp.post("/*", proxyPageResourceRedirect);
|
|
4903
|
-
devServerApp.delete("/*", proxyPageResourceRedirect);
|
|
4904
|
-
devServerApp.head("/*", proxyPageResourceRedirect);
|
|
4905
|
-
devServerApp.put("/*", proxyPageResourceRedirect);
|
|
4906
|
-
devServerApp.options("/*", proxyPageResourceRedirect);
|
|
4907
|
-
devServerApp.get("/*", proxyPageRouteHandler);
|
|
4908
|
-
return devServerApp;
|
|
4909
5112
|
};
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
import { Router as Router3 } from "express";
|
|
4918
|
-
import { getConfigAccountIfExists as getConfigAccountIfExists6 } from "@hubspot/local-dev-lib/config";
|
|
4919
|
-
import cors2 from "cors";
|
|
4920
|
-
function getShadowDevServerCheckHandler(devServerPort, themePath) {
|
|
4921
|
-
return async function shadowDevServerCheckHandler(request, response) {
|
|
4922
|
-
const { query } = request;
|
|
4923
|
-
if (query) {
|
|
4924
|
-
const {
|
|
4925
|
-
hostName,
|
|
4926
|
-
pathName,
|
|
4927
|
-
contentId,
|
|
4928
|
-
portalId: portalIdString
|
|
4929
|
-
} = query;
|
|
4930
|
-
const portalId = parseInt(portalIdString, 10);
|
|
4931
|
-
let account;
|
|
4932
|
-
let isTemplateFromDevTheme = false;
|
|
4933
|
-
let localProxyUrl;
|
|
4934
|
-
try {
|
|
4935
|
-
account = getConfigAccountIfExists6(portalId);
|
|
4936
|
-
if (!account) {
|
|
4937
|
-
throw new Error();
|
|
4938
|
-
}
|
|
4939
|
-
} catch (e) {
|
|
4940
|
-
response.status(500).end(
|
|
4941
|
-
`Unable to find account for hubid = ${portalId}. Please check your hubspot.config.yaml`
|
|
4942
|
-
);
|
|
4943
|
-
return;
|
|
4944
|
-
}
|
|
4945
|
-
try {
|
|
4946
|
-
const { templatePath } = await fetchPreviewInfo_default(
|
|
4947
|
-
account.accountId,
|
|
4948
|
-
portalId,
|
|
4949
|
-
contentId
|
|
4950
|
-
);
|
|
4951
|
-
if (templatePath.startsWith(themePath)) {
|
|
4952
|
-
isTemplateFromDevTheme = true;
|
|
4953
|
-
localProxyUrl = `http://${hostName}.hslocal.net:${devServerPort}${pathName}`;
|
|
4954
|
-
}
|
|
4955
|
-
response.status(200).set({ "Content-Type": "application/json" }).json({
|
|
4956
|
-
isTemplateFromDevTheme,
|
|
4957
|
-
localProxyUrl
|
|
4958
|
-
});
|
|
4959
|
-
} catch (error) {
|
|
4960
|
-
response.status(500).end(
|
|
4961
|
-
`Failed proxy render of page id = ${contentId} hub id = ${portalId}
|
|
4962
|
-
|
|
4963
|
-
${error.stack}`
|
|
4964
|
-
);
|
|
4965
|
-
return;
|
|
4966
|
-
}
|
|
4967
|
-
} else {
|
|
4968
|
-
response.status(500).end(
|
|
4969
|
-
`Missing pageUrl param, cannot check for proxied page without a pageUrl`
|
|
4970
|
-
);
|
|
4971
|
-
}
|
|
4972
|
-
};
|
|
5113
|
+
function buildErrorIndex2() {
|
|
5114
|
+
return buildHTMLResponse(`
|
|
5115
|
+
<div>
|
|
5116
|
+
<h2>Error</h2>
|
|
5117
|
+
<p>Failed to fetch template data.</p>
|
|
5118
|
+
</div>
|
|
5119
|
+
`);
|
|
4973
5120
|
}
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
);
|
|
4981
|
-
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
|
+
`);
|
|
4982
5128
|
}
|
|
4983
5129
|
|
|
4984
|
-
// src/
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
} else {
|
|
4996
|
-
rej(err);
|
|
4997
|
-
}
|
|
4998
|
-
});
|
|
4999
|
-
testNetServer.once("listening", () => {
|
|
5000
|
-
testNetServer.close();
|
|
5001
|
-
});
|
|
5002
|
-
testNetServer.once("close", () => {
|
|
5003
|
-
res(false);
|
|
5004
|
-
});
|
|
5005
|
-
testNetServer.listen(shadowPort, host);
|
|
5006
|
-
});
|
|
5007
|
-
if (portIsTaken) {
|
|
5008
|
-
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";
|
|
5009
5141
|
}
|
|
5010
|
-
const shadowDevServer = express();
|
|
5011
|
-
shadowDevServer.listen(shadowPort, host);
|
|
5012
|
-
shadowDevServer.use(
|
|
5013
|
-
"/",
|
|
5014
|
-
await createShadowDevServerRoutes(devServerPort, themePath)
|
|
5015
|
-
);
|
|
5016
5142
|
}
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
}
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
origin,
|
|
5033
|
-
hmr: {
|
|
5034
|
-
protocol: sslEnabled ? "wss" : "ws",
|
|
5035
|
-
port: port + 1
|
|
5036
|
-
}
|
|
5037
|
-
},
|
|
5038
|
-
appType: "custom",
|
|
5039
|
-
root: appWebRoot,
|
|
5040
|
-
base: isProd3 ? void 0 : "/local",
|
|
5041
|
-
ssr: {
|
|
5042
|
-
noExternal: "@hubspot/cms-components"
|
|
5043
|
-
},
|
|
5044
|
-
resolve: {
|
|
5045
|
-
conditions: ["server"],
|
|
5046
|
-
dedupe: ["react", "react-dom", "@hubspot/cms-components", "styled-jsx"],
|
|
5047
|
-
alias: {
|
|
5048
|
-
"@": appWebRoot
|
|
5049
|
-
}
|
|
5050
|
-
},
|
|
5051
|
-
optimizeDeps: {
|
|
5052
|
-
include: ["react", "react-dom", "react-dom/client"]
|
|
5053
|
-
},
|
|
5054
|
-
plugins: [
|
|
5055
|
-
(() => {
|
|
5056
|
-
const require2 = createRequire2(import.meta.url);
|
|
5057
|
-
return react2({
|
|
5058
|
-
babel: {
|
|
5059
|
-
plugins: [
|
|
5060
|
-
require2.resolve("babel-plugin-styled-components"),
|
|
5061
|
-
require2.resolve("styled-jsx/babel"),
|
|
5062
|
-
require2.resolve("babel-plugin-macros")
|
|
5063
|
-
]
|
|
5064
|
-
}
|
|
5065
|
-
});
|
|
5066
|
-
})(),
|
|
5067
|
-
clientIslandEntryPlugin(),
|
|
5068
|
-
resolveIslandPlugin(),
|
|
5069
|
-
sslEnabled ? mkcert2() : null
|
|
5070
|
-
],
|
|
5071
|
-
css: {
|
|
5072
|
-
postcss: appWebRoot
|
|
5073
|
-
},
|
|
5074
|
-
envDir: appWebRoot,
|
|
5075
|
-
envPrefix: "HS_"
|
|
5076
|
-
};
|
|
5077
|
-
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
|
+
}
|
|
5078
5158
|
}
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
}
|
|
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
|
+
}
|
|
5090
5172
|
}
|
|
5091
|
-
function
|
|
5092
|
-
const
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
socket.pause();
|
|
5097
|
-
const byte = buffer[0];
|
|
5098
|
-
let protocol;
|
|
5099
|
-
if (byte === 22) {
|
|
5100
|
-
protocol = "https";
|
|
5101
|
-
} else if (32 < byte && byte < 127) {
|
|
5102
|
-
protocol = "http";
|
|
5103
|
-
} else {
|
|
5104
|
-
throw new Error(
|
|
5105
|
-
"Unknown issue with incoming data, unknown if http or https"
|
|
5106
|
-
);
|
|
5107
|
-
}
|
|
5108
|
-
const proxy = protocol === "http" ? innerHTTPServer : innerHTTPSServer;
|
|
5109
|
-
if (proxy) {
|
|
5110
|
-
socket.unshift(buffer);
|
|
5111
|
-
proxy.emit("connection", socket);
|
|
5112
|
-
}
|
|
5113
|
-
process.nextTick(() => socket.resume());
|
|
5114
|
-
});
|
|
5115
|
-
});
|
|
5116
|
-
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;
|
|
5117
5178
|
}
|
|
5179
|
+
var createAppServerAPIRoutes_default = createAppServerAPIRoutes;
|
|
5118
5180
|
|
|
5119
|
-
// src/
|
|
5120
|
-
import
|
|
5181
|
+
// src/routes/appServerRouteHandler.ts
|
|
5182
|
+
import fs8 from "node:fs/promises";
|
|
5183
|
+
import path15 from "path";
|
|
5184
|
+
import { pathToFileURL } from "url";
|
|
5121
5185
|
|
|
5122
|
-
// src/lib/
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
return gates;
|
|
5126
|
-
}
|
|
5186
|
+
// src/lib/getDevServerUIData.ts
|
|
5187
|
+
import path14 from "path";
|
|
5188
|
+
import { normalizePath as normalizePath9 } from "vite";
|
|
5127
5189
|
|
|
5128
|
-
// src/
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
}
|
|
5134
|
-
|
|
5135
|
-
}, []);
|
|
5136
|
-
};
|
|
5137
|
-
async function getJsRenderingGates(portalId, env2, personalAccessKey) {
|
|
5138
|
-
const { enabledFeatures } = await getAccessToken(personalAccessKey, env2, portalId);
|
|
5139
|
-
const envGates = getGatesFromEnv();
|
|
5140
|
-
const gates = mapEnabledFeaturesToGates(enabledFeatures);
|
|
5141
|
-
const mergedGates = [...envGates, ...gates];
|
|
5142
|
-
process.env.GATES = mergedGates.join(",");
|
|
5143
|
-
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;
|
|
5144
5197
|
}
|
|
5145
5198
|
|
|
5146
|
-
// src/lib/
|
|
5147
|
-
import
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
"
|
|
5151
|
-
"
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
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
|
+
})
|
|
5164
5241
|
);
|
|
5165
5242
|
}
|
|
5166
|
-
function
|
|
5167
|
-
|
|
5168
|
-
const
|
|
5169
|
-
return
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
for (const candidatePath of hsmetaCandidatePaths(srcPath)) {
|
|
5178
|
-
if (!fs6.existsSync(candidatePath))
|
|
5179
|
-
continue;
|
|
5180
|
-
const uid = tryParseUid(candidatePath);
|
|
5181
|
-
if (uid)
|
|
5182
|
-
return uid;
|
|
5183
|
-
}
|
|
5184
|
-
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
|
+
});
|
|
5185
5254
|
}
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
var COMPONENT_TYPES = Object.freeze({
|
|
5192
|
-
privateApp: "private-app",
|
|
5193
|
-
publicApp: "public-app",
|
|
5194
|
-
hublTheme: "hubl-theme"
|
|
5195
|
-
});
|
|
5196
|
-
var CONFIG_FILES = {
|
|
5197
|
-
[COMPONENT_TYPES.privateApp]: "app.json",
|
|
5198
|
-
[COMPONENT_TYPES.publicApp]: "public-app.json",
|
|
5199
|
-
[COMPONENT_TYPES.hublTheme]: "theme.json"
|
|
5200
|
-
};
|
|
5201
|
-
function hasNewDirectoryStructure(platformVersion) {
|
|
5202
|
-
return parseFloat(platformVersion) >= 2025.2;
|
|
5255
|
+
function normalizePartialsData(partialData) {
|
|
5256
|
+
return partialData.partialNames.map((name, index) => ({
|
|
5257
|
+
name,
|
|
5258
|
+
subPath: partialData.partialSubpaths[index]
|
|
5259
|
+
}));
|
|
5203
5260
|
}
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
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);
|
|
5207
5264
|
return {
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
has16m: false
|
|
5265
|
+
name: template.displayName || template.label,
|
|
5266
|
+
subPath,
|
|
5267
|
+
templateTypeLabel: templateTypeMap[template.templateType]
|
|
5212
5268
|
};
|
|
5213
|
-
}
|
|
5214
|
-
return {
|
|
5215
|
-
level,
|
|
5216
|
-
hasBasic: true,
|
|
5217
|
-
has256: level >= 2,
|
|
5218
|
-
has16m: level >= 3
|
|
5219
|
-
};
|
|
5269
|
+
});
|
|
5220
5270
|
}
|
|
5221
|
-
function
|
|
5222
|
-
if (
|
|
5223
|
-
return
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
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) : [];
|
|
5231
5308
|
}
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
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);
|
|
5236
5323
|
}
|
|
5237
|
-
|
|
5324
|
+
normalizedHubLModules = normalizeHubLModules(
|
|
5325
|
+
(hubLModuleData == null ? void 0 : hubLModuleData.objects) || [],
|
|
5326
|
+
projectName
|
|
5327
|
+
);
|
|
5238
5328
|
}
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
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;
|
|
5250
5373
|
}
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
return 3;
|
|
5258
|
-
}
|
|
5259
|
-
if ("TERM_PROGRAM" in env) {
|
|
5260
|
-
const version = Number.parseInt(
|
|
5261
|
-
(env.TERM_PROGRAM_VERSION || "").split(".")[0],
|
|
5262
|
-
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>` ?? ""
|
|
5263
5380
|
);
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
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);
|
|
5270
5387
|
}
|
|
5271
|
-
|
|
5272
|
-
|
|
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
|
+
);
|
|
5273
5416
|
}
|
|
5274
|
-
|
|
5275
|
-
|
|
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);
|
|
5276
5423
|
}
|
|
5277
|
-
|
|
5278
|
-
|
|
5424
|
+
devServerApp.use(viteServer.middlewares);
|
|
5425
|
+
devServerApp.use("/api", createAppServerAPIRoutes_default());
|
|
5426
|
+
if (appViteServer) {
|
|
5427
|
+
devServerApp.get("/", appServerRouteHandler_default);
|
|
5279
5428
|
}
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
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;
|
|
5293
5461
|
};
|
|
5294
|
-
|
|
5295
|
-
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
5296
|
-
const position = argv.indexOf(prefix + flag);
|
|
5297
|
-
const terminatorPosition = argv.indexOf("--");
|
|
5298
|
-
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
5299
|
-
}
|
|
5462
|
+
var createDevServerRoutes_default = createDevServerRoutes;
|
|
5300
5463
|
|
|
5301
|
-
// src/
|
|
5302
|
-
import
|
|
5303
|
-
|
|
5304
|
-
getConfigDefaultAccountIfExists,
|
|
5305
|
-
validateConfig
|
|
5306
|
-
} from "@hubspot/local-dev-lib/config";
|
|
5307
|
-
import { fetchSecrets } from "@hubspot/local-dev-lib/api/secrets";
|
|
5308
|
-
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";
|
|
5309
5467
|
|
|
5310
|
-
// src/
|
|
5311
|
-
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}
|
|
5312
5514
|
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
let messageEnd = "";
|
|
5322
|
-
if (error.error.message.match(OAUTH_ERROR_REGEX)) {
|
|
5323
|
-
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
|
+
);
|
|
5324
5523
|
}
|
|
5325
|
-
|
|
5326
|
-
${messageEnd}`);
|
|
5327
|
-
Object.setPrototypeOf(this, MissingScopeError.prototype);
|
|
5328
|
-
}
|
|
5329
|
-
};
|
|
5330
|
-
function logMissingScopeWarning(error) {
|
|
5331
|
-
console.warn(error.message);
|
|
5524
|
+
};
|
|
5332
5525
|
}
|
|
5333
|
-
function
|
|
5334
|
-
|
|
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;
|
|
5335
5534
|
}
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
)
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
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);
|
|
5348
5549
|
}
|
|
5349
|
-
|
|
5350
|
-
|
|
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
|
|
5351
5588
|
}
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
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
|
|
5359
5601
|
}
|
|
5360
|
-
}
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
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);
|
|
5364
5630
|
}
|
|
5631
|
+
var createAppServer_default = createAppServer;
|
|
5365
5632
|
|
|
5366
|
-
// src/
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
} catch (error) {
|
|
5376
|
-
if (isMissingScopeError(error)) {
|
|
5377
|
-
throw new MissingScopeError(error);
|
|
5378
|
-
}
|
|
5379
|
-
throw error;
|
|
5380
|
-
}
|
|
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();
|
|
5381
5642
|
}
|
|
5382
|
-
|
|
5383
|
-
const
|
|
5384
|
-
const
|
|
5385
|
-
|
|
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
|
+
});
|
|
5386
5667
|
});
|
|
5387
|
-
|
|
5388
|
-
return domainNames;
|
|
5668
|
+
return { server, innerHTTPServer, innerHTTPSServer };
|
|
5389
5669
|
}
|
|
5390
5670
|
|
|
5391
|
-
// src/lib/
|
|
5392
|
-
import
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
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;
|
|
5398
5678
|
}
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
if (checkFileExists(filePath)) {
|
|
5406
|
-
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]);
|
|
5407
5685
|
}
|
|
5408
|
-
|
|
5409
|
-
|
|
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 [];
|
|
5410
5710
|
}
|
|
5411
|
-
|
|
5412
|
-
|
|
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))
|
|
5413
5716
|
);
|
|
5414
|
-
return null;
|
|
5415
5717
|
}
|
|
5416
|
-
|
|
5417
|
-
if (projectConfigPath === null) {
|
|
5418
|
-
console.log(
|
|
5419
|
-
`Unable to find local ${HSPROJECT_JSON}, skipping platform version validation.`
|
|
5420
|
-
);
|
|
5421
|
-
return false;
|
|
5422
|
-
}
|
|
5423
|
-
const hsProjectJSONContents = fs7.readFileSync(projectConfigPath, "utf8");
|
|
5424
|
-
const hsProjectJSONData = JSON.parse(hsProjectJSONContents);
|
|
5425
|
-
const { platformVersion } = hsProjectJSONData;
|
|
5426
|
-
let platformVersionResult;
|
|
5718
|
+
function tryParseUid(hsmetaPath) {
|
|
5427
5719
|
try {
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
})
|
|
5432
|
-
|
|
5433
|
-
console.error(e.message);
|
|
5434
|
-
console.log(
|
|
5435
|
-
"Unable to find active platform versions, skipping platform version validation."
|
|
5436
|
-
);
|
|
5437
|
-
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;
|
|
5438
5725
|
}
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
})
|
|
5449
|
-
)
|
|
5450
|
-
});
|
|
5451
|
-
hsProjectJSONData.platformVersion = answer;
|
|
5452
|
-
try {
|
|
5453
|
-
fs7.writeFileSync(
|
|
5454
|
-
projectConfigPath,
|
|
5455
|
-
JSON.stringify(hsProjectJSONData, void 0, 2),
|
|
5456
|
-
"utf8"
|
|
5457
|
-
);
|
|
5458
|
-
return true;
|
|
5459
|
-
} catch (e) {
|
|
5460
|
-
console.error(
|
|
5461
|
-
`unable to write updated valid platform version, please make sure platformVersion in "${HSPROJECT_JSON}" is one of ${platformVersionResult.activePlatformVersions}`
|
|
5462
|
-
);
|
|
5463
|
-
return false;
|
|
5464
|
-
}
|
|
5465
|
-
};
|
|
5466
|
-
if (deferSelection) {
|
|
5467
|
-
deferSelection(promptAndWrite);
|
|
5468
|
-
return false;
|
|
5469
|
-
}
|
|
5470
|
-
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;
|
|
5471
5735
|
}
|
|
5472
|
-
return
|
|
5736
|
+
return null;
|
|
5473
5737
|
}
|
|
5474
5738
|
|
|
5475
|
-
// src/
|
|
5476
|
-
import
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
choice: "ChoiceFieldType",
|
|
5489
|
-
color: "ColorFieldType",
|
|
5490
|
-
crmobject: "CrmObjectFieldType",
|
|
5491
|
-
cta: "CtaFieldType",
|
|
5492
|
-
date: "DateFieldType",
|
|
5493
|
-
datetime: "DateTimeFieldType",
|
|
5494
|
-
email: "EmailFieldType",
|
|
5495
|
-
embed: "EmbedFieldType",
|
|
5496
|
-
file: "FileFieldType",
|
|
5497
|
-
followupemail: "FollowUpEmailFieldType",
|
|
5498
|
-
font: "FontFieldType",
|
|
5499
|
-
form: "FormFieldType",
|
|
5500
|
-
gradient: "GradientFieldType",
|
|
5501
|
-
group: "GroupFieldType",
|
|
5502
|
-
html: "HtmlFieldType",
|
|
5503
|
-
hubdbrow: "HubDbRowFieldType",
|
|
5504
|
-
hubdbtable: "HubDbTableFieldType",
|
|
5505
|
-
hubl: "HublFieldType",
|
|
5506
|
-
icon: "IconFieldType",
|
|
5507
|
-
image: "ImageFieldType",
|
|
5508
|
-
link: "LinkFieldType",
|
|
5509
|
-
logo: "LogoFieldType",
|
|
5510
|
-
meeting: "MeetingFieldType",
|
|
5511
|
-
menu: "MenuFieldType",
|
|
5512
|
-
number: "NumberFieldType",
|
|
5513
|
-
page: "PageFieldType",
|
|
5514
|
-
payment: "PaymentFieldType",
|
|
5515
|
-
podcast: "PodcastFieldType",
|
|
5516
|
-
richtext: "RichTextFieldType",
|
|
5517
|
-
salesforcecampaign: "SfdcCamapaignFieldType",
|
|
5518
|
-
simplemenu: "SimpleMenuFieldType",
|
|
5519
|
-
spacing: "SpacingFieldType",
|
|
5520
|
-
survey: "SurveyFieldType",
|
|
5521
|
-
tag: "TagFieldType",
|
|
5522
|
-
textalignment: "TextAlignmentFieldType",
|
|
5523
|
-
text: "TextFieldType",
|
|
5524
|
-
url: "UrlFieldType",
|
|
5525
|
-
variantselection: "VariantSelectionFieldType",
|
|
5526
|
-
videoplayer: "VideoFieldType",
|
|
5527
|
-
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"
|
|
5528
5752
|
};
|
|
5529
|
-
function
|
|
5530
|
-
|
|
5531
|
-
|
|
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
|
+
};
|
|
5532
5765
|
}
|
|
5533
|
-
return
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
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;
|
|
5538
5788
|
}
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
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;
|
|
5553
5802
|
}
|
|
5554
|
-
return
|
|
5555
|
-
}).filter((entry) => entry !== void 0);
|
|
5556
|
-
}
|
|
5557
|
-
var INVALID_IMPORTS = ["ChoiceFieldType", "GroupFieldType"];
|
|
5558
|
-
var FIELD_GROUP_TYPE = "FieldGroupWithChildren";
|
|
5559
|
-
var REPEATER_GROUP_TYPE = "RepeaterGroup";
|
|
5560
|
-
var REQUIRED_TYPE = "RequiredField";
|
|
5561
|
-
var DEFAULT_VALUES_TYPE = "DefaultValues";
|
|
5562
|
-
var CMS_COMPONENTS = "@hubspot/cms-components";
|
|
5563
|
-
var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
5564
|
-
var AUTO_GEN_COMMENT = "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.";
|
|
5565
|
-
var createPropertySignature = (identifier, type, hasQuestionToken = false) => ts.factory.createPropertySignature(
|
|
5566
|
-
[],
|
|
5567
|
-
identifier,
|
|
5568
|
-
hasQuestionToken ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) : void 0,
|
|
5569
|
-
type
|
|
5570
|
-
);
|
|
5571
|
-
var createUnionTypeFromArray = (values) => ts.factory.createUnionTypeNode(
|
|
5572
|
-
values.map(
|
|
5573
|
-
(value) => ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(value))
|
|
5574
|
-
)
|
|
5575
|
-
);
|
|
5576
|
-
var buildTypeFromField = (field, additionalNode) => {
|
|
5577
|
-
const imports = [field.type];
|
|
5578
|
-
const identifier = ts.factory.createIdentifier(field.name);
|
|
5579
|
-
const baseType = ts.factory.createTypeReferenceNode(field.type);
|
|
5580
|
-
const requiredType = ts.factory.createTypeReferenceNode(REQUIRED_TYPE, [
|
|
5581
|
-
baseType
|
|
5582
|
-
]);
|
|
5583
|
-
let finalType = field.isRequired ? requiredType : baseType;
|
|
5584
|
-
if (field.choices) {
|
|
5585
|
-
finalType = createUnionTypeFromArray(field.choices);
|
|
5803
|
+
return min;
|
|
5586
5804
|
}
|
|
5587
|
-
if (
|
|
5588
|
-
|
|
5805
|
+
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
|
|
5806
|
+
return 1;
|
|
5589
5807
|
}
|
|
5590
|
-
if (
|
|
5591
|
-
|
|
5592
|
-
const genericType = field.isRepeater ? REPEATER_GROUP_TYPE : FIELD_GROUP_TYPE;
|
|
5593
|
-
imports.push(genericType);
|
|
5594
|
-
finalType = ts.factory.createTypeReferenceNode(genericType, [typeLiteral]);
|
|
5808
|
+
if (env.COLORTERM === "truecolor") {
|
|
5809
|
+
return 3;
|
|
5595
5810
|
}
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
)
|
|
5602
|
-
|
|
5603
|
-
|
|
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) })
|
|
5604
5845
|
};
|
|
5605
|
-
|
|
5606
|
-
const
|
|
5607
|
-
const
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
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;
|
|
5613
5876
|
}
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5877
|
+
super(`${MISSING_SCOPE_ERROR_PREFIX}
|
|
5878
|
+
${messageEnd}`);
|
|
5879
|
+
Object.setPrototypeOf(this, MissingScopeError.prototype);
|
|
5880
|
+
}
|
|
5618
5881
|
};
|
|
5619
|
-
function
|
|
5620
|
-
|
|
5621
|
-
(importName) => ts.factory.createImportSpecifier(
|
|
5622
|
-
true,
|
|
5623
|
-
void 0,
|
|
5624
|
-
ts.factory.createIdentifier(importName)
|
|
5625
|
-
)
|
|
5626
|
-
);
|
|
5627
|
-
const namedImports = ts.factory.createNamedImports(importSpecifiers);
|
|
5628
|
-
return ts.factory.createImportDeclaration(
|
|
5629
|
-
[],
|
|
5630
|
-
[],
|
|
5631
|
-
ts.factory.createImportClause(false, void 0, namedImports),
|
|
5632
|
-
ts.factory.createStringLiteral(moduleSpecifier)
|
|
5633
|
-
);
|
|
5882
|
+
function logMissingScopeWarning(error) {
|
|
5883
|
+
console.warn(error.message);
|
|
5634
5884
|
}
|
|
5635
|
-
function
|
|
5636
|
-
|
|
5637
|
-
|
|
5638
|
-
|
|
5639
|
-
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
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
|
+
}
|
|
5649
5911
|
}
|
|
5650
5912
|
}
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
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;
|
|
5654
5938
|
});
|
|
5655
|
-
const
|
|
5656
|
-
|
|
5657
|
-
);
|
|
5658
|
-
return { types, imports: validImports };
|
|
5939
|
+
const domainNames = filteredDomains.map((r) => r.domain);
|
|
5940
|
+
return domainNames;
|
|
5659
5941
|
}
|
|
5660
|
-
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
);
|
|
5669
|
-
const wrappedType = ts.factory.createTypeReferenceNode(DEFAULT_VALUES_TYPE, [
|
|
5670
|
-
baseType.type
|
|
5671
|
-
]);
|
|
5672
|
-
const finalType = ts.factory.createTypeAliasDeclaration(
|
|
5673
|
-
[],
|
|
5674
|
-
[],
|
|
5675
|
-
typeName,
|
|
5676
|
-
void 0,
|
|
5677
|
-
wrappedType
|
|
5678
|
-
);
|
|
5679
|
-
const filteredImports = filterUnusedImports(imports, finalType);
|
|
5680
|
-
const importDeclaration = getImportDeclaration(
|
|
5681
|
-
[...filteredImports, DEFAULT_VALUES_TYPE],
|
|
5682
|
-
CMS_COMPONENTS_FIELD_TYPES
|
|
5683
|
-
);
|
|
5684
|
-
const defaultExport = ts.factory.createExportDefault(
|
|
5685
|
-
ts.factory.createIdentifier(typeName)
|
|
5686
|
-
);
|
|
5687
|
-
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();
|
|
5688
5950
|
}
|
|
5689
|
-
function
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
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++;
|
|
5693
5962
|
}
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
|
|
5697
|
-
|
|
5698
|
-
|
|
5699
|
-
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
const nodes = constructFinalType(entries, typeName);
|
|
5704
|
-
const comments = [
|
|
5705
|
-
AUTO_GEN_COMMENT,
|
|
5706
|
-
"Removing the above comment will disable type generation for this module",
|
|
5707
|
-
"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"
|
|
5708
|
-
].map((comment) => `// ${comment}`);
|
|
5709
|
-
const typeResult = nodes.map(
|
|
5710
|
-
(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.`
|
|
5711
5972
|
);
|
|
5712
|
-
const result = [...comments, ...typeResult].join("\n");
|
|
5713
|
-
writeFileSync(fileName, result);
|
|
5714
|
-
return true;
|
|
5715
|
-
} catch (e) {
|
|
5716
|
-
console.error(e);
|
|
5717
5973
|
return false;
|
|
5718
5974
|
}
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
5723
|
-
import path16 from "path";
|
|
5724
|
-
import readline from "readline";
|
|
5725
|
-
var lastSerializedFieldsCache = {};
|
|
5726
|
-
var formatAsTypeName = (str) => {
|
|
5727
|
-
const typeName = `${str.replace(/[^a-zA-Z0-9_$]/g, "_")}FieldsType`;
|
|
5728
|
-
const validFirstChar = /^[A-Za-z_$]/.test(str.charAt(0));
|
|
5729
|
-
return validFirstChar ? typeName : `_${typeName}`;
|
|
5730
|
-
};
|
|
5731
|
-
var isInModulesFolder = (filePath, projectRoot) => {
|
|
5732
|
-
const getEntryPathFromId = (id) => {
|
|
5733
|
-
return id.startsWith(projectRoot) ? id.replace(`${projectRoot}${path16.sep}`, "") : "";
|
|
5734
|
-
};
|
|
5735
|
-
const currentModuleId = path16.normalize(filePath);
|
|
5736
|
-
const moduleEntryPath = getEntryPathFromId(currentModuleId);
|
|
5737
|
-
const subFolderTokens = moduleEntryPath.split(path16.sep);
|
|
5738
|
-
return {
|
|
5739
|
-
inModuleFolder: subFolderTokens[0] === "components" && subFolderTokens[1] === "modules",
|
|
5740
|
-
isRootModuleFile: subFolderTokens.length === 3
|
|
5741
|
-
};
|
|
5742
|
-
};
|
|
5743
|
-
var fileContainsAutoGenComment = async (filePath) => {
|
|
5744
|
-
if (!fs8.existsSync(filePath))
|
|
5745
|
-
return true;
|
|
5746
|
-
const stream2 = fs8.createReadStream(filePath);
|
|
5747
|
-
const reader = readline.createInterface({ input: stream2 });
|
|
5748
|
-
const firstLine = await new Promise(
|
|
5749
|
-
(resolve2) => reader.once("line", (line) => resolve2(line.trim()))
|
|
5750
|
-
);
|
|
5751
|
-
reader.close();
|
|
5752
|
-
stream2.close();
|
|
5753
|
-
return firstLine && firstLine === `// ${AUTO_GEN_COMMENT}`;
|
|
5754
|
-
};
|
|
5755
|
-
var getIndexFile = (filePath, projectRoot) => {
|
|
5756
|
-
const { inModuleFolder, isRootModuleFile } = isInModulesFolder(
|
|
5757
|
-
filePath,
|
|
5758
|
-
projectRoot
|
|
5759
|
-
);
|
|
5760
|
-
if (!inModuleFolder)
|
|
5761
|
-
return void 0;
|
|
5762
|
-
if (isRootModuleFile)
|
|
5763
|
-
return { indexFilePath: filePath, isRootModuleFile };
|
|
5764
|
-
const dir = path16.dirname(filePath);
|
|
5765
|
-
const files = fs8.readdirSync(dir);
|
|
5766
|
-
const indexFileName = files.find((file) => file.startsWith("index."));
|
|
5767
|
-
return indexFileName ? { indexFilePath: path16.join(dir, indexFileName), isRootModuleFile } : void 0;
|
|
5768
|
-
};
|
|
5769
|
-
var getIndexFileFields = async (indexFilePath, indexFileName, viteServer) => {
|
|
5770
|
-
let indexFile;
|
|
5771
|
-
let renderFieldsToJson;
|
|
5975
|
+
const hsProjectJSONContents = fs10.readFileSync(projectConfigPath, "utf8");
|
|
5976
|
+
const hsProjectJSONData = JSON.parse(hsProjectJSONContents);
|
|
5977
|
+
const { platformVersion } = hsProjectJSONData;
|
|
5978
|
+
let platformVersionResult;
|
|
5772
5979
|
try {
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5980
|
+
platformVersionResult = (await hsCliHttp12.get(portalId, {
|
|
5981
|
+
url: `developer/projects/v1/platformVersion`,
|
|
5982
|
+
responseType: "json"
|
|
5983
|
+
})).data;
|
|
5776
5984
|
} catch (e) {
|
|
5777
|
-
|
|
5985
|
+
console.error(e.message);
|
|
5986
|
+
console.log(
|
|
5987
|
+
"Unable to find active platform versions, skipping platform version validation."
|
|
5988
|
+
);
|
|
5989
|
+
return false;
|
|
5778
5990
|
}
|
|
5779
|
-
if (!
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
return;
|
|
5810
|
-
const moduleFolderName = path16.basename(path16.dirname(filePath));
|
|
5811
|
-
const outputTypeName = formatAsTypeName(moduleFolderName);
|
|
5812
|
-
const didSucceed = writeFieldsType(fields, typeFilePath, outputTypeName);
|
|
5813
|
-
if (didSucceed) {
|
|
5814
|
-
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;
|
|
5815
6021
|
}
|
|
5816
|
-
|
|
5817
|
-
const successMsg = `Successfully generated types for ${pathToLog}`;
|
|
5818
|
-
const errorMsg = `Failed to generate types for ${pathToLog}`;
|
|
5819
|
-
const message = didSucceed ? successMsg : errorMsg;
|
|
5820
|
-
console.log(wrapMessageInColor(didSucceed ? "green" : "red", message));
|
|
6022
|
+
return promptAndWrite();
|
|
5821
6023
|
}
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
maybeUpdateFields(resolvedPath, viteServer, projectRoot);
|
|
5828
|
-
});
|
|
5829
|
-
const watchCallback = (filePath) => maybeUpdateFields(filePath, viteServer, projectRoot);
|
|
5830
|
-
viteServer.watcher.on("add", watchCallback).on("change", watchCallback);
|
|
5831
|
-
};
|
|
6024
|
+
return true;
|
|
6025
|
+
}
|
|
6026
|
+
|
|
6027
|
+
// src/createDevServer.ts
|
|
6028
|
+
import { http as hsCliHttp13 } from "@hubspot/local-dev-lib/http";
|
|
5832
6029
|
|
|
5833
6030
|
// src/lib/configHelpers.ts
|
|
5834
6031
|
function getSecretNamesFromConfig(config) {
|
|
@@ -5855,8 +6052,8 @@ function getWebRootProjectComponentFolder(absoluteWebRoot, projectConfigPath) {
|
|
|
5855
6052
|
return themeFolderName;
|
|
5856
6053
|
}
|
|
5857
6054
|
try {
|
|
5858
|
-
const projectDir =
|
|
5859
|
-
const configContent =
|
|
6055
|
+
const projectDir = path19.dirname(projectConfigPath);
|
|
6056
|
+
const configContent = fs11.readFileSync(projectConfigPath, "utf8");
|
|
5860
6057
|
const projectConfig = JSON.parse(configContent);
|
|
5861
6058
|
if (hasNewDirectoryStructure(projectConfig.platformVersion)) {
|
|
5862
6059
|
const srcDir = projectConfig.srcDir || "src";
|
|
@@ -5926,7 +6123,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
5926
6123
|
}
|
|
5927
6124
|
setTrackingInfo(authedPortalId, authedEnv);
|
|
5928
6125
|
sendTrackingRequest("start-dev-server");
|
|
5929
|
-
const absoluteWebRoot = normalizePath10(
|
|
6126
|
+
const absoluteWebRoot = normalizePath10(path19.resolve(process.cwd(), webRoot));
|
|
5930
6127
|
const projectConfigPath = findHSProjectJson(absoluteWebRoot);
|
|
5931
6128
|
const webRootProjectComponentFolder = getWebRootProjectComponentFolder(
|
|
5932
6129
|
absoluteWebRoot,
|
|
@@ -5998,7 +6195,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
5998
6195
|
});
|
|
5999
6196
|
bootTasks.push(async () => {
|
|
6000
6197
|
try {
|
|
6001
|
-
const accountInformation = (await
|
|
6198
|
+
const accountInformation = (await hsCliHttp13.get(portalId, {
|
|
6002
6199
|
url: "/account-info/v3/details"
|
|
6003
6200
|
})).data;
|
|
6004
6201
|
authedHublet = accountInformation.dataHostingLocation;
|
|
@@ -6040,7 +6237,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
6040
6237
|
secretNames
|
|
6041
6238
|
);
|
|
6042
6239
|
if (fieldGenEnabledOption) {
|
|
6043
|
-
const normalizedAbsoluteWebRoot =
|
|
6240
|
+
const normalizedAbsoluteWebRoot = path19.normalize(absoluteWebRoot);
|
|
6044
6241
|
startFieldsTypeGenWatcher(viteServer, normalizedAbsoluteWebRoot);
|
|
6045
6242
|
}
|
|
6046
6243
|
const viteHTTPSConfig = viteServer.config.server.https;
|
|
@@ -6066,10 +6263,10 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
6066
6263
|
expressServer.locals.sslEnabled = sslEnabledOption;
|
|
6067
6264
|
expressServer.locals.fullHeightPreview = fullHeightPreview;
|
|
6068
6265
|
expressServer.use(bodyParser.json());
|
|
6069
|
-
const __dirname =
|
|
6070
|
-
let appWebRoot = normalizePath10(
|
|
6266
|
+
const __dirname = path19.dirname(url2.fileURLToPath(new URL(import.meta.url)));
|
|
6267
|
+
let appWebRoot = normalizePath10(path19.resolve(__dirname, "../app"));
|
|
6071
6268
|
if (true) {
|
|
6072
|
-
appWebRoot =
|
|
6269
|
+
appWebRoot = path19.join(__dirname, "app");
|
|
6073
6270
|
}
|
|
6074
6271
|
const skipUiServer = isLocalUiDisabled(cmsAssetConfig);
|
|
6075
6272
|
const appViteServer = skipUiServer ? null : await createAppServer_default(appWebRoot, PORT, sslEnabledOption);
|
|
@@ -6137,17 +6334,17 @@ HubSpot CMS dev server running at ${protocol}://hslocal.net:${PORT}${extraServer
|
|
|
6137
6334
|
`;
|
|
6138
6335
|
console.log(startMessage);
|
|
6139
6336
|
if (storybook) {
|
|
6140
|
-
const packageRoot =
|
|
6141
|
-
const configPath =
|
|
6337
|
+
const packageRoot = path19.dirname(url2.fileURLToPath(import.meta.url));
|
|
6338
|
+
const configPath = path19.resolve(packageRoot, "./storybook-main");
|
|
6142
6339
|
sendTrackingRequest("start-storybook");
|
|
6143
6340
|
let storybookBin;
|
|
6144
6341
|
try {
|
|
6145
6342
|
const sbPackagePath = await import.meta.resolve("storybook/package.json");
|
|
6146
|
-
const sbPackageDir =
|
|
6343
|
+
const sbPackageDir = path19.dirname(url2.fileURLToPath(sbPackagePath));
|
|
6147
6344
|
const packageJson = JSON.parse(
|
|
6148
|
-
|
|
6345
|
+
fs11.readFileSync(path19.join(sbPackageDir, "package.json"), "utf-8")
|
|
6149
6346
|
);
|
|
6150
|
-
storybookBin =
|
|
6347
|
+
storybookBin = path19.join(
|
|
6151
6348
|
sbPackageDir,
|
|
6152
6349
|
packageJson.bin.storybook || packageJson.bin
|
|
6153
6350
|
);
|
|
@@ -6184,7 +6381,7 @@ HubSpot CMS dev server running at ${protocol}://hslocal.net:${PORT}${extraServer
|
|
|
6184
6381
|
portalId: authedPortalId.toString(),
|
|
6185
6382
|
hsEnv: authedEnv,
|
|
6186
6383
|
hublet: authedHublet,
|
|
6187
|
-
WEB_ROOT:
|
|
6384
|
+
WEB_ROOT: path19.join(webRoot, "components")
|
|
6188
6385
|
},
|
|
6189
6386
|
stdio: "inherit"
|
|
6190
6387
|
}
|