@hubspot/cms-dev-server 1.2.80 → 1.2.83
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/generateFieldsCli.js +438 -0
- package/dist/generateJsonFromJsx.js +1 -1
- package/dist/index.js +1114 -922
- package/dist/internalSsr.js +3 -5
- package/dist/island-runtime.js +22 -6
- package/dist/run.js +990 -798
- package/dist/storybook/index.js +1 -1
- package/dist/storybook-main/main.js +7 -9
- package/dist/validateFieldsCli.js +56 -58
- package/package.json +3 -2
- package/types/lib/renderModulePreview.d.ts +2 -3
- package/types/routes/moduleValidateFields.d.ts +3 -0
- package/types/validateFields.d.ts +39 -0
- package/types/lib/debugAuth.d.ts +0 -8
- package/types/lib/localComponentsLoader.d.ts +0 -2
- package/types/lib/viteAssetHandler.d.ts +0 -18
- package/types/plugins/hubspotStaticAssetPlugin.d.ts +0 -2
- package/types/plugins/remoteAssetsPlugin.d.ts +0 -10
- package/types/plugins/requestSigningPlugin.d.ts +0 -6
- package/types/routes/createAppServerRoutes.d.ts +0 -13
- package/types/routes/homeRouteHandler.d.ts +0 -7
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createServer as createViteServer } from "vite";
|
|
|
3
3
|
import { createRequire } from "module";
|
|
4
4
|
import { default as react } from "@vitejs/plugin-react";
|
|
5
5
|
|
|
6
|
-
// ../cms-js-internal/dist/types-
|
|
6
|
+
// ../cms-js-internal/dist/types-C8bPIEz4.js
|
|
7
7
|
import path from "path";
|
|
8
8
|
import { createHash } from "crypto";
|
|
9
9
|
import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
@@ -262,12 +262,8 @@ function isLocalUiDisabled(config) {
|
|
|
262
262
|
return false;
|
|
263
263
|
}
|
|
264
264
|
var ENABLED_FEATURES_GATE_MAP = {
|
|
265
|
-
"cms:jsr:analyzeCmsModules": "CMS:JSRenderer:AnalyzeCmsModules"
|
|
266
|
-
"PortalsAccessIdentity:DesignManager:UrlSigning": "PortalsAccessIdentity:DesignManager:UrlSigning"
|
|
265
|
+
"cms:jsr:analyzeCmsModules": "CMS:JSRenderer:AnalyzeCmsModules"
|
|
267
266
|
};
|
|
268
|
-
function isUngatedFor(gates, gate) {
|
|
269
|
-
return gates.includes(gate);
|
|
270
|
-
}
|
|
271
267
|
var findAllComponentsIn = (webRoot, componentsFolder) => {
|
|
272
268
|
const fullComponentsFolderPath = join(webRoot, componentsFolder);
|
|
273
269
|
const componentsByName = {};
|
|
@@ -686,8 +682,8 @@ function convertEntryPointIslandPathsToRelative(config, entryPointsCmsModuleMap)
|
|
|
686
682
|
);
|
|
687
683
|
return Object.fromEntries(relativeEntries);
|
|
688
684
|
}
|
|
689
|
-
function toRelativePath(config,
|
|
690
|
-
return
|
|
685
|
+
function toRelativePath(config, path20) {
|
|
686
|
+
return path20.replace(`${config.root}/`, "");
|
|
691
687
|
}
|
|
692
688
|
function shouldAnalyzeModule(config, moduleInfo, code) {
|
|
693
689
|
const [fileId, __] = moduleInfo.id.split("?");
|
|
@@ -730,11 +726,11 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
|
|
|
730
726
|
let moduleComponentLocalImportName = CMS_MODULE_COMPONENT_NAME;
|
|
731
727
|
let dndAreaComponentLocalImportName = DND_AREA_COMPONENT_NAME;
|
|
732
728
|
traverse(sourceAst, {
|
|
733
|
-
ImportDeclaration(
|
|
734
|
-
if (t.isStringLiteral(
|
|
729
|
+
ImportDeclaration(path20) {
|
|
730
|
+
if (t.isStringLiteral(path20.node.source, {
|
|
735
731
|
value: "@hubspot/cms-components"
|
|
736
732
|
})) {
|
|
737
|
-
for (const specifier of
|
|
733
|
+
for (const specifier of path20.node.specifiers) {
|
|
738
734
|
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
|
|
739
735
|
name: CMS_MODULE_COMPONENT_NAME
|
|
740
736
|
})) {
|
|
@@ -748,14 +744,14 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
|
|
|
748
744
|
}
|
|
749
745
|
}
|
|
750
746
|
},
|
|
751
|
-
JSXOpeningElement(
|
|
752
|
-
if (t.isJSXIdentifier(
|
|
747
|
+
JSXOpeningElement(path20) {
|
|
748
|
+
if (t.isJSXIdentifier(path20.node.name, {
|
|
753
749
|
name: moduleComponentLocalImportName
|
|
754
750
|
})) {
|
|
755
751
|
let cmsModuleName;
|
|
756
752
|
let cmsModulePath;
|
|
757
753
|
let cmsModuleLabel;
|
|
758
|
-
for (const prop of
|
|
754
|
+
for (const prop of path20.node.attributes) {
|
|
759
755
|
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
760
756
|
cmsModuleName = prop.value.value;
|
|
761
757
|
continue;
|
|
@@ -790,11 +786,11 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
|
|
|
790
786
|
}
|
|
791
787
|
contentDescriptors.modules[cmsModuleProps.name] = cmsModuleProps;
|
|
792
788
|
}
|
|
793
|
-
if (t.isJSXIdentifier(
|
|
789
|
+
if (t.isJSXIdentifier(path20.node.name, {
|
|
794
790
|
name: dndAreaComponentLocalImportName
|
|
795
791
|
})) {
|
|
796
792
|
let dndAreaName;
|
|
797
|
-
for (const prop of
|
|
793
|
+
for (const prop of path20.node.attributes) {
|
|
798
794
|
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
799
795
|
dndAreaName = prop.value.value;
|
|
800
796
|
continue;
|
|
@@ -1241,8 +1237,8 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
1241
1237
|
var createViteDevServer_default = createViteDevServer;
|
|
1242
1238
|
|
|
1243
1239
|
// src/createDevServer.ts
|
|
1244
|
-
import
|
|
1245
|
-
import
|
|
1240
|
+
import path19 from "path";
|
|
1241
|
+
import fs11 from "fs";
|
|
1246
1242
|
import url2 from "url";
|
|
1247
1243
|
import express2 from "express";
|
|
1248
1244
|
import http3 from "http";
|
|
@@ -1663,7 +1659,7 @@ function trackUsage(action) {
|
|
|
1663
1659
|
eventName: EVENT_NAME,
|
|
1664
1660
|
action,
|
|
1665
1661
|
nodeVersion: getNodeVersionData(),
|
|
1666
|
-
version: "1.2.
|
|
1662
|
+
version: "1.2.83",
|
|
1667
1663
|
os: getPlatform()
|
|
1668
1664
|
};
|
|
1669
1665
|
const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -1737,12 +1733,12 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
1737
1733
|
);
|
|
1738
1734
|
offsetSoFar = nearestNewlineOrQuoteAfterBlockOpen;
|
|
1739
1735
|
if (pathEndOffset >= 0 && pathEndOffset < nextNewlineOffset) {
|
|
1740
|
-
const
|
|
1736
|
+
const path20 = body.substring(
|
|
1741
1737
|
startOffset + localJsRenderStartString.length,
|
|
1742
1738
|
pathEndOffset
|
|
1743
1739
|
);
|
|
1744
1740
|
offsetSoFar = pathEndOffset + 1;
|
|
1745
|
-
if (startOffset >= 0 &&
|
|
1741
|
+
if (startOffset >= 0 && path20) {
|
|
1746
1742
|
const nextCommentEndOffset = body.indexOf("-->", pathEndOffset);
|
|
1747
1743
|
const endOffset = body.indexOf(localJsRenderEndString, pathEndOffset);
|
|
1748
1744
|
offsetSoFar = Math.min(nextCommentEndOffset, endOffset);
|
|
@@ -1767,7 +1763,7 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
1767
1763
|
result.push({
|
|
1768
1764
|
startOffset,
|
|
1769
1765
|
endOffset: endOffset + localJsRenderEndString.length,
|
|
1770
|
-
path:
|
|
1766
|
+
path: path20,
|
|
1771
1767
|
json
|
|
1772
1768
|
});
|
|
1773
1769
|
}
|
|
@@ -2166,9 +2162,9 @@ var customColors = [
|
|
|
2166
2162
|
];
|
|
2167
2163
|
var Converter = new AnsiToHtmlConverter({ colors: customColors });
|
|
2168
2164
|
var darkErrorStyles = `background-color: #222; color: #ccc; padding: 0.5em; font-family: ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', 'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace;`;
|
|
2169
|
-
var renderLocalError_default = (
|
|
2165
|
+
var renderLocalError_default = (path20, error) => {
|
|
2170
2166
|
const stackWithColorClasses = Converter.toHtml(error.stack);
|
|
2171
|
-
return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${
|
|
2167
|
+
return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${path20}<br/><br/><code><pre>${stackWithColorClasses}</pre></code></div>`;
|
|
2172
2168
|
};
|
|
2173
2169
|
|
|
2174
2170
|
// src/proxyPage/fetchPreviewInfo.ts
|
|
@@ -3191,7 +3187,6 @@ function getWebDefaultStylesCss(metaUrl) {
|
|
|
3191
3187
|
}
|
|
3192
3188
|
return _webDefaultStylesCss;
|
|
3193
3189
|
}
|
|
3194
|
-
var URL_SIGNING_GATE = "PortalsAccessIdentity:DesignManager:UrlSigning";
|
|
3195
3190
|
async function signGetUrl(authedPortalId, unsignedUrl) {
|
|
3196
3191
|
const urlWithPortalId = new URL(unsignedUrl);
|
|
3197
3192
|
urlWithPortalId.searchParams.set("portalId", `${authedPortalId}`);
|
|
@@ -3208,14 +3203,7 @@ async function signGetUrl(authedPortalId, unsignedUrl) {
|
|
|
3208
3203
|
});
|
|
3209
3204
|
return response.data.signedUrl;
|
|
3210
3205
|
}
|
|
3211
|
-
async function signedGet(authedPortalId, unsignedUrl, headers
|
|
3212
|
-
if (!isUngatedFor(gates, URL_SIGNING_GATE)) {
|
|
3213
|
-
const { data } = await hsCliHttp7.get(authedPortalId, {
|
|
3214
|
-
url: unsignedUrl,
|
|
3215
|
-
headers
|
|
3216
|
-
});
|
|
3217
|
-
return data;
|
|
3218
|
-
}
|
|
3206
|
+
async function signedGet(authedPortalId, unsignedUrl, headers) {
|
|
3219
3207
|
const signedUrl = await signGetUrl(authedPortalId, unsignedUrl);
|
|
3220
3208
|
const accountConfig = getConfigAccountIfExists4(authedPortalId);
|
|
3221
3209
|
const authHeaders = {};
|
|
@@ -3242,7 +3230,7 @@ async function signedGet(authedPortalId, unsignedUrl, headers, gates) {
|
|
|
3242
3230
|
}
|
|
3243
3231
|
return await response.text();
|
|
3244
3232
|
}
|
|
3245
|
-
async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv, cookieValue
|
|
3233
|
+
async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv, cookieValue) {
|
|
3246
3234
|
const moduleInfoQueryParams = new URLSearchParams({
|
|
3247
3235
|
portalId: `${authedPortalId}`
|
|
3248
3236
|
});
|
|
@@ -3266,34 +3254,13 @@ async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv,
|
|
|
3266
3254
|
buffer_theme: `${true}`
|
|
3267
3255
|
});
|
|
3268
3256
|
const cosRenderingUrl = `https://api.hubspot${authedEnv === "qa" ? "qa" : ""}.com/api/cos-rendering/v1/public/_hcms/preview/template/multi?${queryParams}`;
|
|
3269
|
-
const
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
modulePreviewHtml = await signedGet(
|
|
3277
|
-
authedPortalId,
|
|
3278
|
-
cosRenderingUrl,
|
|
3279
|
-
{
|
|
3280
|
-
["content-type"]: "application/x-www-form-urlencoded",
|
|
3281
|
-
["Accept"]: "text/html",
|
|
3282
|
-
referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
|
|
3283
|
-
cookie: cookieValue,
|
|
3284
|
-
"User-Agent": "HubSpot CMS Dev Server"
|
|
3285
|
-
},
|
|
3286
|
-
gates
|
|
3287
|
-
);
|
|
3288
|
-
} finally {
|
|
3289
|
-
if (needsDomainOverride) {
|
|
3290
|
-
if (previousHubApiDomainOverride) {
|
|
3291
|
-
process.env.HUBAPI_DOMAIN_OVERRIDE = previousHubApiDomainOverride;
|
|
3292
|
-
} else {
|
|
3293
|
-
delete process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
3294
|
-
}
|
|
3295
|
-
}
|
|
3296
|
-
}
|
|
3257
|
+
const modulePreviewHtml = await signedGet(authedPortalId, cosRenderingUrl, {
|
|
3258
|
+
["content-type"]: "application/x-www-form-urlencoded",
|
|
3259
|
+
["Accept"]: "text/html",
|
|
3260
|
+
referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
|
|
3261
|
+
cookie: cookieValue,
|
|
3262
|
+
"User-Agent": "HubSpot CMS Dev Server"
|
|
3263
|
+
});
|
|
3297
3264
|
const previewDoc = parseHtml(modulePreviewHtml);
|
|
3298
3265
|
const modulePreviewContent = extractModuleOuterHtml(previewDoc);
|
|
3299
3266
|
const allStyleContent = extractStyleText(previewDoc);
|
|
@@ -3534,8 +3501,7 @@ var partialRouteHandler = async (request, response) => {
|
|
|
3534
3501
|
remoteModule.path,
|
|
3535
3502
|
authedPortalId,
|
|
3536
3503
|
authedEnv,
|
|
3537
|
-
request.get("COOKIE")
|
|
3538
|
-
jsRenderingGates
|
|
3504
|
+
request.get("COOKIE")
|
|
3539
3505
|
).then((result) => ({
|
|
3540
3506
|
remoteModule,
|
|
3541
3507
|
result
|
|
@@ -3859,142 +3825,724 @@ var moduleFieldsJsonRouteHandler = async (request, response) => {
|
|
|
3859
3825
|
};
|
|
3860
3826
|
var moduleFieldsJson_default = moduleFieldsJsonRouteHandler;
|
|
3861
3827
|
|
|
3862
|
-
// src/
|
|
3863
|
-
import
|
|
3864
|
-
import
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3828
|
+
// src/routes/moduleValidateFields.ts
|
|
3829
|
+
import path12 from "path";
|
|
3830
|
+
import fs6 from "fs/promises";
|
|
3831
|
+
|
|
3832
|
+
// src/validateFields.ts
|
|
3833
|
+
import path11 from "path";
|
|
3834
|
+
import fs5 from "fs/promises";
|
|
3835
|
+
|
|
3836
|
+
// ../cms-js-internal/dist/buildFieldsTypes.js
|
|
3837
|
+
import { writeFileSync } from "fs";
|
|
3838
|
+
import ts from "typescript";
|
|
3839
|
+
var fieldTypeNameByType = {
|
|
3840
|
+
alignment: "AlignmentFieldType",
|
|
3841
|
+
audioplayer: "AudioFieldType",
|
|
3842
|
+
backgroundimage: "BackgroundImageFieldType",
|
|
3843
|
+
blog: "BlogFieldType",
|
|
3844
|
+
boolean: "BooleanFieldType",
|
|
3845
|
+
border: "BorderFieldType",
|
|
3846
|
+
choice: "ChoiceFieldType",
|
|
3847
|
+
color: "ColorFieldType",
|
|
3848
|
+
crmobject: "CrmObjectFieldType",
|
|
3849
|
+
cta: "CtaFieldType",
|
|
3850
|
+
date: "DateFieldType",
|
|
3851
|
+
datetime: "DateTimeFieldType",
|
|
3852
|
+
email: "EmailFieldType",
|
|
3853
|
+
embed: "EmbedFieldType",
|
|
3854
|
+
file: "FileFieldType",
|
|
3855
|
+
followupemail: "FollowUpEmailFieldType",
|
|
3856
|
+
font: "FontFieldType",
|
|
3857
|
+
form: "FormFieldType",
|
|
3858
|
+
gradient: "GradientFieldType",
|
|
3859
|
+
group: "GroupFieldType",
|
|
3860
|
+
html: "HtmlFieldType",
|
|
3861
|
+
hubdbrow: "HubDbRowFieldType",
|
|
3862
|
+
hubdbtable: "HubDbTableFieldType",
|
|
3863
|
+
hubl: "HublFieldType",
|
|
3864
|
+
icon: "IconFieldType",
|
|
3865
|
+
image: "ImageFieldType",
|
|
3866
|
+
link: "LinkFieldType",
|
|
3867
|
+
logo: "LogoFieldType",
|
|
3868
|
+
meeting: "MeetingFieldType",
|
|
3869
|
+
menu: "MenuFieldType",
|
|
3870
|
+
number: "NumberFieldType",
|
|
3871
|
+
page: "PageFieldType",
|
|
3872
|
+
payment: "PaymentFieldType",
|
|
3873
|
+
podcast: "PodcastFieldType",
|
|
3874
|
+
richtext: "RichTextFieldType",
|
|
3875
|
+
salesforcecampaign: "SfdcCamapaignFieldType",
|
|
3876
|
+
simplemenu: "SimpleMenuFieldType",
|
|
3877
|
+
spacing: "SpacingFieldType",
|
|
3878
|
+
survey: "SurveyFieldType",
|
|
3879
|
+
tag: "TagFieldType",
|
|
3880
|
+
textalignment: "TextAlignmentFieldType",
|
|
3881
|
+
text: "TextFieldType",
|
|
3882
|
+
url: "UrlFieldType",
|
|
3883
|
+
variantselection: "VariantSelectionFieldType",
|
|
3884
|
+
videoplayer: "VideoFieldType",
|
|
3885
|
+
workflow: "WorkflowFieldType"
|
|
3886
|
+
};
|
|
3887
|
+
function getFieldEntries(fields) {
|
|
3888
|
+
if (!Array.isArray(fields)) {
|
|
3889
|
+
return void 0;
|
|
3871
3890
|
}
|
|
3872
|
-
return
|
|
3873
|
-
const
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
method: "HEAD",
|
|
3878
|
-
headers: {
|
|
3879
|
-
// Keep this user agent, so we don't get 403s from the request
|
|
3880
|
-
["User-Agent"]: "cms-dev-server"
|
|
3881
|
-
}
|
|
3882
|
-
},
|
|
3883
|
-
async (res) => {
|
|
3884
|
-
let portalIdHeader;
|
|
3885
|
-
let contentId;
|
|
3886
|
-
const isContentMembershipRedirect = Boolean(
|
|
3887
|
-
res.headers["x-hs-content-membership-redirect"]
|
|
3888
|
-
);
|
|
3889
|
-
if (isContentMembershipRedirect) {
|
|
3890
|
-
debug("Content Membership Redirect", res.headers);
|
|
3891
|
-
portalIdHeader = res.headers["x-hs-portal-id"];
|
|
3892
|
-
contentId = res.headers["x-hs-content-id"];
|
|
3893
|
-
if (portalIdHeader && contentId) {
|
|
3894
|
-
return resolve2({
|
|
3895
|
-
portalIdHeader,
|
|
3896
|
-
contentId,
|
|
3897
|
-
res
|
|
3898
|
-
});
|
|
3899
|
-
}
|
|
3900
|
-
}
|
|
3901
|
-
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
3902
|
-
console.log(`Redirecting to ${res.headers.location} (from ${url3})`);
|
|
3903
|
-
return resolve2(
|
|
3904
|
-
requestPage(
|
|
3905
|
-
res.headers.location,
|
|
3906
|
-
redirects + 1,
|
|
3907
|
-
originalUrl ?? url3
|
|
3908
|
-
)
|
|
3909
|
-
);
|
|
3910
|
-
}
|
|
3911
|
-
portalIdHeader = res.headers["x-hs-hub-id"];
|
|
3912
|
-
contentId = res.headers["x-hs-content-id"];
|
|
3913
|
-
return resolve2({
|
|
3914
|
-
res,
|
|
3915
|
-
portalIdHeader,
|
|
3916
|
-
contentId
|
|
3917
|
-
});
|
|
3918
|
-
}
|
|
3919
|
-
).on("error", (err) => {
|
|
3920
|
-
console.error(err);
|
|
3921
|
-
reject(err);
|
|
3922
|
-
}).end();
|
|
3923
|
-
});
|
|
3924
|
-
}
|
|
3925
|
-
async function fetchContentMetadata(url3, portalId) {
|
|
3926
|
-
const { portalIdHeader, contentId, res } = await requestPage(url3);
|
|
3927
|
-
if (Array.isArray(portalIdHeader) || Array.isArray(contentId)) {
|
|
3928
|
-
throw new Error(
|
|
3929
|
-
`There were multiple hub ID or content ID headers in the HEAD request to ${url3}`
|
|
3930
|
-
);
|
|
3931
|
-
} else {
|
|
3932
|
-
const portalIdFromResponse = parseInt(portalIdHeader, 10);
|
|
3933
|
-
const pageAccount = await getConfigAccountIfExists5(portalIdFromResponse);
|
|
3934
|
-
if (!pageAccount) {
|
|
3935
|
-
throw new Error(
|
|
3936
|
-
`No CLI auth for portal ${portalIdFromResponse} found, please run \`hs auth\``
|
|
3937
|
-
);
|
|
3891
|
+
return fields.filter((field) => field.name && field.type).map((field) => {
|
|
3892
|
+
const { name, type } = field;
|
|
3893
|
+
const fieldType = fieldTypeNameByType[type];
|
|
3894
|
+
if (!fieldType) {
|
|
3895
|
+
return void 0;
|
|
3938
3896
|
}
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3897
|
+
const entry = {
|
|
3898
|
+
type: fieldType,
|
|
3899
|
+
name,
|
|
3900
|
+
isRepeater: "occurrence" in field,
|
|
3901
|
+
isRequired: !!field.required,
|
|
3902
|
+
choices: (
|
|
3903
|
+
// Choices are pair [value, label] but only the value is printed to the page, so flatten it.
|
|
3904
|
+
"choices" in field ? field.choices.map(([value, label]) => value) : void 0
|
|
3905
|
+
),
|
|
3906
|
+
multiple: field.type === "choice" ? field.multiple === true : void 0,
|
|
3907
|
+
children: []
|
|
3908
|
+
};
|
|
3909
|
+
if (fieldType === "GroupFieldType" && "children" in field) {
|
|
3910
|
+
const children = getFieldEntries(field.children);
|
|
3911
|
+
return { ...entry, children };
|
|
3951
3912
|
}
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
}
|
|
3913
|
+
return entry;
|
|
3914
|
+
}).filter((entry) => entry !== void 0);
|
|
3955
3915
|
}
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3916
|
+
var INVALID_IMPORTS = ["ChoiceFieldType", "GroupFieldType"];
|
|
3917
|
+
var FIELD_GROUP_TYPE = "FieldGroupWithChildren";
|
|
3918
|
+
var REPEATER_GROUP_TYPE = "RepeaterGroup";
|
|
3919
|
+
var REQUIRED_TYPE = "RequiredField";
|
|
3920
|
+
var DEFAULT_VALUES_TYPE = "DefaultValues";
|
|
3921
|
+
var CMS_COMPONENTS = "@hubspot/cms-components";
|
|
3922
|
+
var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
3923
|
+
var AUTO_GEN_COMMENT = "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.";
|
|
3924
|
+
var createPropertySignature = (identifier, type, hasQuestionToken = false) => ts.factory.createPropertySignature(
|
|
3925
|
+
[],
|
|
3926
|
+
identifier,
|
|
3927
|
+
hasQuestionToken ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) : void 0,
|
|
3928
|
+
type
|
|
3929
|
+
);
|
|
3930
|
+
var createUnionTypeFromArray = (values) => ts.factory.createUnionTypeNode(
|
|
3931
|
+
values.map(
|
|
3932
|
+
(value) => ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(value))
|
|
3933
|
+
)
|
|
3934
|
+
);
|
|
3935
|
+
var buildTypeFromField = (field, additionalNode) => {
|
|
3936
|
+
const imports = [field.type];
|
|
3937
|
+
const identifier = ts.factory.createIdentifier(field.name);
|
|
3938
|
+
const baseType = ts.factory.createTypeReferenceNode(field.type);
|
|
3939
|
+
const requiredType = ts.factory.createTypeReferenceNode(REQUIRED_TYPE, [
|
|
3940
|
+
baseType
|
|
3941
|
+
]);
|
|
3942
|
+
let finalType = field.isRequired ? requiredType : baseType;
|
|
3943
|
+
if (field.choices) {
|
|
3944
|
+
const choiceType = createUnionTypeFromArray(field.choices);
|
|
3945
|
+
finalType = field.multiple ? ts.factory.createTypeReferenceNode("Array", [choiceType]) : choiceType;
|
|
3969
3946
|
}
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
const urlToProxy = `http://${domainToProxy}${request.originalUrl}`;
|
|
3973
|
-
if (!domainToProxy) {
|
|
3974
|
-
if (VALID_PROXY_DOMAIN_SUFFIXES.includes(request.hostname)) {
|
|
3975
|
-
const message = `Can't make a proxy request, you need to prepend the real page's domain to '${request.hostname}' (i.e. your.page.com.${request.hostname})`;
|
|
3976
|
-
consoleWarn(message);
|
|
3977
|
-
return response.status(400).send(message);
|
|
3978
|
-
} else {
|
|
3979
|
-
const message = `Can't make a proxy request, the domain '${request.hostname}' is not a valid proxy-able domain`;
|
|
3980
|
-
consoleWarn(message);
|
|
3981
|
-
return response.status(400).send(message);
|
|
3982
|
-
}
|
|
3947
|
+
if (field.isRequired) {
|
|
3948
|
+
imports.push(REQUIRED_TYPE);
|
|
3983
3949
|
}
|
|
3984
|
-
|
|
3985
|
-
const
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
);
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3950
|
+
if (additionalNode) {
|
|
3951
|
+
const typeLiteral = ts.isTypeLiteralNode(additionalNode) ? additionalNode : ts.factory.createTypeLiteralNode([additionalNode]);
|
|
3952
|
+
const genericType = field.isRepeater ? REPEATER_GROUP_TYPE : FIELD_GROUP_TYPE;
|
|
3953
|
+
imports.push(genericType);
|
|
3954
|
+
finalType = ts.factory.createTypeReferenceNode(genericType, [typeLiteral]);
|
|
3955
|
+
}
|
|
3956
|
+
return {
|
|
3957
|
+
type: createPropertySignature(
|
|
3958
|
+
identifier,
|
|
3959
|
+
finalType,
|
|
3960
|
+
!field.isRequired && !additionalNode
|
|
3961
|
+
),
|
|
3962
|
+
imports
|
|
3963
|
+
};
|
|
3964
|
+
};
|
|
3965
|
+
var filterUnusedImports = (imports, type) => {
|
|
3966
|
+
const usedImports = /* @__PURE__ */ new Set();
|
|
3967
|
+
const visit = (node) => {
|
|
3968
|
+
if (ts.isTypeReferenceNode(node)) {
|
|
3969
|
+
const typeName = node.typeName;
|
|
3970
|
+
if ("escapedText" in typeName) {
|
|
3971
|
+
usedImports.add(typeName.escapedText.toString());
|
|
3972
|
+
}
|
|
3973
|
+
}
|
|
3974
|
+
ts.forEachChild(node, visit);
|
|
3975
|
+
};
|
|
3976
|
+
visit(type);
|
|
3977
|
+
return imports.filter((name) => usedImports.has(name));
|
|
3978
|
+
};
|
|
3979
|
+
function getImportDeclaration(imports, moduleSpecifier) {
|
|
3980
|
+
const importSpecifiers = Array.from(imports).map(
|
|
3981
|
+
(importName) => ts.factory.createImportSpecifier(
|
|
3982
|
+
true,
|
|
3983
|
+
void 0,
|
|
3984
|
+
ts.factory.createIdentifier(importName)
|
|
3985
|
+
)
|
|
3986
|
+
);
|
|
3987
|
+
const namedImports = ts.factory.createNamedImports(importSpecifiers);
|
|
3988
|
+
return ts.factory.createImportDeclaration(
|
|
3989
|
+
[],
|
|
3990
|
+
[],
|
|
3991
|
+
ts.factory.createImportClause(false, void 0, namedImports),
|
|
3992
|
+
ts.factory.createStringLiteral(moduleSpecifier)
|
|
3993
|
+
);
|
|
3994
|
+
}
|
|
3995
|
+
function getFieldTypes(fields) {
|
|
3996
|
+
const imports = [];
|
|
3997
|
+
const types = fields.map((field) => {
|
|
3998
|
+
if (field.children) {
|
|
3999
|
+
const childrenResult = getFieldTypes(field.children);
|
|
4000
|
+
imports.push(...childrenResult.imports);
|
|
4001
|
+
if (childrenResult.types.length || field.type === "GroupFieldType") {
|
|
4002
|
+
const subType = ts.factory.createTypeLiteralNode(childrenResult.types);
|
|
4003
|
+
const { type: type2, imports: newImports2 } = buildTypeFromField(
|
|
4004
|
+
field,
|
|
4005
|
+
subType
|
|
4006
|
+
);
|
|
4007
|
+
imports.push(...newImports2);
|
|
4008
|
+
return type2;
|
|
4009
|
+
}
|
|
4010
|
+
}
|
|
4011
|
+
const { type, imports: newImports } = buildTypeFromField(field);
|
|
4012
|
+
imports.push(...newImports);
|
|
4013
|
+
return type;
|
|
4014
|
+
});
|
|
4015
|
+
const validImports = Array.from(
|
|
4016
|
+
new Set(imports.filter((name) => !INVALID_IMPORTS.includes(name)))
|
|
4017
|
+
);
|
|
4018
|
+
return { types, imports: validImports };
|
|
4019
|
+
}
|
|
4020
|
+
function constructFinalType(fields, typeName) {
|
|
4021
|
+
const { types, imports } = getFieldTypes(fields);
|
|
4022
|
+
const baseType = ts.factory.createTypeAliasDeclaration(
|
|
4023
|
+
[],
|
|
4024
|
+
[],
|
|
4025
|
+
"",
|
|
4026
|
+
void 0,
|
|
4027
|
+
ts.factory.createTypeLiteralNode(types)
|
|
4028
|
+
);
|
|
4029
|
+
const wrappedType = ts.factory.createTypeReferenceNode(DEFAULT_VALUES_TYPE, [
|
|
4030
|
+
baseType.type
|
|
4031
|
+
]);
|
|
4032
|
+
const finalType = ts.factory.createTypeAliasDeclaration(
|
|
4033
|
+
[],
|
|
4034
|
+
[],
|
|
4035
|
+
typeName,
|
|
4036
|
+
void 0,
|
|
4037
|
+
wrappedType
|
|
4038
|
+
);
|
|
4039
|
+
const filteredImports = filterUnusedImports(imports, finalType);
|
|
4040
|
+
const importDeclaration = getImportDeclaration(
|
|
4041
|
+
[...filteredImports, DEFAULT_VALUES_TYPE],
|
|
4042
|
+
CMS_COMPONENTS_FIELD_TYPES
|
|
4043
|
+
);
|
|
4044
|
+
const defaultExport = ts.factory.createExportDefault(
|
|
4045
|
+
ts.factory.createIdentifier(typeName)
|
|
4046
|
+
);
|
|
4047
|
+
return [importDeclaration, finalType, defaultExport];
|
|
4048
|
+
}
|
|
4049
|
+
function writeFieldsType(fields, fileName, typeName) {
|
|
4050
|
+
const entries = getFieldEntries(fields);
|
|
4051
|
+
if (!entries) {
|
|
4052
|
+
return false;
|
|
4053
|
+
}
|
|
4054
|
+
try {
|
|
4055
|
+
const file = ts.createSourceFile(
|
|
4056
|
+
fileName,
|
|
4057
|
+
"",
|
|
4058
|
+
ts.ScriptTarget.ESNext,
|
|
4059
|
+
false,
|
|
4060
|
+
ts.ScriptKind.TS
|
|
4061
|
+
);
|
|
4062
|
+
const printer = ts.createPrinter();
|
|
4063
|
+
const nodes = constructFinalType(entries, typeName);
|
|
4064
|
+
const comments = [
|
|
4065
|
+
AUTO_GEN_COMMENT,
|
|
4066
|
+
"Removing the above comment will disable type generation for this module",
|
|
4067
|
+
"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"
|
|
4068
|
+
].map((comment) => `// ${comment}`);
|
|
4069
|
+
const typeResult = nodes.map(
|
|
4070
|
+
(node) => printer.printNode(ts.EmitHint.Unspecified, node, file)
|
|
4071
|
+
);
|
|
4072
|
+
const result = [...comments, ...typeResult].join("\n");
|
|
4073
|
+
writeFileSync(fileName, result);
|
|
4074
|
+
return true;
|
|
4075
|
+
} catch (e) {
|
|
4076
|
+
console.error(e);
|
|
4077
|
+
return false;
|
|
4078
|
+
}
|
|
4079
|
+
}
|
|
4080
|
+
|
|
4081
|
+
// src/lib/watchFieldsUpdates.ts
|
|
4082
|
+
import fs4 from "fs";
|
|
4083
|
+
import path10 from "path";
|
|
4084
|
+
import readline from "readline";
|
|
4085
|
+
var lastSerializedFieldsCache = {};
|
|
4086
|
+
var formatAsTypeName = (str) => {
|
|
4087
|
+
const typeName = `${str.replace(/[^a-zA-Z0-9_$]/g, "_")}FieldsType`;
|
|
4088
|
+
const validFirstChar = /^[A-Za-z_$]/.test(str.charAt(0));
|
|
4089
|
+
return validFirstChar ? typeName : `_${typeName}`;
|
|
4090
|
+
};
|
|
4091
|
+
var isInModulesFolder = (filePath, projectRoot) => {
|
|
4092
|
+
const getEntryPathFromId = (id) => {
|
|
4093
|
+
return id.startsWith(projectRoot) ? id.replace(`${projectRoot}${path10.sep}`, "") : "";
|
|
4094
|
+
};
|
|
4095
|
+
const currentModuleId = path10.normalize(filePath);
|
|
4096
|
+
const moduleEntryPath = getEntryPathFromId(currentModuleId);
|
|
4097
|
+
const subFolderTokens = moduleEntryPath.split(path10.sep);
|
|
4098
|
+
return {
|
|
4099
|
+
inModuleFolder: subFolderTokens[0] === "components" && subFolderTokens[1] === "modules",
|
|
4100
|
+
isRootModuleFile: subFolderTokens.length === 3
|
|
4101
|
+
};
|
|
4102
|
+
};
|
|
4103
|
+
var fileContainsAutoGenComment = async (filePath) => {
|
|
4104
|
+
if (!fs4.existsSync(filePath))
|
|
4105
|
+
return true;
|
|
4106
|
+
const stream2 = fs4.createReadStream(filePath);
|
|
4107
|
+
const reader = readline.createInterface({ input: stream2 });
|
|
4108
|
+
const firstLine = await new Promise(
|
|
4109
|
+
(resolve2) => reader.once("line", (line) => resolve2(line.trim()))
|
|
4110
|
+
);
|
|
4111
|
+
reader.close();
|
|
4112
|
+
stream2.close();
|
|
4113
|
+
return firstLine && firstLine === `// ${AUTO_GEN_COMMENT}`;
|
|
4114
|
+
};
|
|
4115
|
+
var getIndexFile = (filePath, projectRoot) => {
|
|
4116
|
+
const { inModuleFolder, isRootModuleFile } = isInModulesFolder(
|
|
4117
|
+
filePath,
|
|
4118
|
+
projectRoot
|
|
4119
|
+
);
|
|
4120
|
+
if (!inModuleFolder)
|
|
4121
|
+
return void 0;
|
|
4122
|
+
if (isRootModuleFile)
|
|
4123
|
+
return { indexFilePath: filePath, isRootModuleFile };
|
|
4124
|
+
const dir = path10.dirname(filePath);
|
|
4125
|
+
const files = fs4.readdirSync(dir);
|
|
4126
|
+
const indexFileName = files.find((file) => file.startsWith("index."));
|
|
4127
|
+
return indexFileName ? { indexFilePath: path10.join(dir, indexFileName), isRootModuleFile } : void 0;
|
|
4128
|
+
};
|
|
4129
|
+
var getIndexFileFields = async (indexFilePath, indexFileName, viteServer) => {
|
|
4130
|
+
let indexFile;
|
|
4131
|
+
let renderFieldsToJson;
|
|
4132
|
+
try {
|
|
4133
|
+
indexFile = await viteServer.ssrLoadModule(indexFilePath);
|
|
4134
|
+
const internalSsrPath = packagePath(import.meta.url, "internalSsr");
|
|
4135
|
+
({ renderFieldsToJson } = await viteServer.ssrLoadModule(internalSsrPath));
|
|
4136
|
+
} catch (e) {
|
|
4137
|
+
return void 0;
|
|
4138
|
+
}
|
|
4139
|
+
if (!indexFile.fields)
|
|
4140
|
+
return void 0;
|
|
4141
|
+
const fields = indexFile.fields;
|
|
4142
|
+
const renderedFieldsJson = renderFieldsToJson(fields, indexFileName);
|
|
4143
|
+
const isValidFields = Array.isArray(renderedFieldsJson);
|
|
4144
|
+
return isValidFields ? renderedFieldsJson : void 0;
|
|
4145
|
+
};
|
|
4146
|
+
var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
|
|
4147
|
+
const indexInfo = getIndexFile(filePath, projectRoot);
|
|
4148
|
+
if (!indexInfo)
|
|
4149
|
+
return;
|
|
4150
|
+
const { indexFilePath, isRootModuleFile } = indexInfo;
|
|
4151
|
+
const indexFileName = path10.parse(indexFilePath).name;
|
|
4152
|
+
const isTypeFile = filePath.endsWith(".types.ts");
|
|
4153
|
+
if (isTypeFile)
|
|
4154
|
+
return;
|
|
4155
|
+
const fields = await getIndexFileFields(
|
|
4156
|
+
indexFilePath,
|
|
4157
|
+
indexFileName,
|
|
4158
|
+
viteServer
|
|
4159
|
+
);
|
|
4160
|
+
if (fields) {
|
|
4161
|
+
const typeFileName = isRootModuleFile ? `${indexFileName}.fields.types.ts` : "fields.type.ts";
|
|
4162
|
+
const typeFilePath = path10.join(path10.dirname(filePath), typeFileName);
|
|
4163
|
+
const lastSerializedFields = lastSerializedFieldsCache[typeFilePath];
|
|
4164
|
+
const serializedFields = JSON.stringify(fields);
|
|
4165
|
+
if (lastSerializedFields === serializedFields)
|
|
4166
|
+
return;
|
|
4167
|
+
const hasAutoGenComment = await fileContainsAutoGenComment(typeFilePath);
|
|
4168
|
+
if (!hasAutoGenComment)
|
|
4169
|
+
return;
|
|
4170
|
+
const moduleFolderName = path10.basename(path10.dirname(filePath));
|
|
4171
|
+
const outputTypeName = formatAsTypeName(moduleFolderName);
|
|
4172
|
+
const didSucceed = writeFieldsType(fields, typeFilePath, outputTypeName);
|
|
4173
|
+
if (didSucceed) {
|
|
4174
|
+
lastSerializedFieldsCache[typeFilePath] = serializedFields;
|
|
4175
|
+
}
|
|
4176
|
+
const pathToLog = isRootModuleFile ? `${moduleFolderName}/${indexFileName}` : moduleFolderName;
|
|
4177
|
+
const successMsg = `Successfully generated types for ${pathToLog}`;
|
|
4178
|
+
const errorMsg = `Failed to generate types for ${pathToLog}`;
|
|
4179
|
+
const message = didSucceed ? successMsg : errorMsg;
|
|
4180
|
+
console.log(wrapMessageInColor(didSucceed ? "green" : "red", message));
|
|
4181
|
+
}
|
|
4182
|
+
};
|
|
4183
|
+
var startFieldsTypeGenWatcher = (viteServer, projectRoot) => {
|
|
4184
|
+
const { moduleSubpaths } = findAllModulesInRoot(projectRoot);
|
|
4185
|
+
moduleSubpaths.forEach((modulePath) => {
|
|
4186
|
+
const resolvedPath = path10.resolve(projectRoot, modulePath);
|
|
4187
|
+
maybeUpdateFields(resolvedPath, viteServer, projectRoot);
|
|
4188
|
+
});
|
|
4189
|
+
const watchCallback = (filePath) => maybeUpdateFields(filePath, viteServer, projectRoot);
|
|
4190
|
+
viteServer.watcher.on("add", watchCallback).on("change", watchCallback);
|
|
4191
|
+
};
|
|
4192
|
+
|
|
4193
|
+
// src/validateFields.ts
|
|
4194
|
+
import { http as hsCliHttp8 } from "@hubspot/local-dev-lib/http";
|
|
4195
|
+
import { getConfigDefaultAccount } from "@hubspot/local-dev-lib/config";
|
|
4196
|
+
var EDITOR_VERSION_V2 = "2.0";
|
|
4197
|
+
async function generateAndWriteFieldsJson(absoluteModulePath, modulePath, viteServer) {
|
|
4198
|
+
let fieldsJson;
|
|
4199
|
+
try {
|
|
4200
|
+
fieldsJson = await renderModuleFieldsJson_default(viteServer, absoluteModulePath);
|
|
4201
|
+
} catch {
|
|
4202
|
+
return {
|
|
4203
|
+
severity: "FATAL",
|
|
4204
|
+
errorType: "MODULE_BUILD_ERROR",
|
|
4205
|
+
message: `Failed to SSR-load module at ${modulePath}`
|
|
4206
|
+
};
|
|
4207
|
+
}
|
|
4208
|
+
if (!Array.isArray(fieldsJson)) {
|
|
4209
|
+
return {
|
|
4210
|
+
severity: "FATAL",
|
|
4211
|
+
errorType: "INVALID_FIELDS",
|
|
4212
|
+
message: `renderModuleFieldsJson returned non-array for ${modulePath}`
|
|
4213
|
+
};
|
|
4214
|
+
}
|
|
4215
|
+
const fieldsJsonPath = path11.join(absoluteModulePath, "fields.json");
|
|
4216
|
+
await fs5.writeFile(fieldsJsonPath, JSON.stringify(fieldsJson, null, 2));
|
|
4217
|
+
return { fieldsJson, fieldsJsonPath };
|
|
4218
|
+
}
|
|
4219
|
+
async function generateAndWriteFieldsType(absoluteModulePath, modulePath, moduleDir, fieldsJson) {
|
|
4220
|
+
const fieldsTypePath = path11.join(absoluteModulePath, "fields.type.ts");
|
|
4221
|
+
const hasAutoGenComment = await fileContainsAutoGenComment(fieldsTypePath);
|
|
4222
|
+
if (hasAutoGenComment) {
|
|
4223
|
+
const typeName = formatAsTypeName(moduleDir);
|
|
4224
|
+
const didSucceed = writeFieldsType(fieldsJson, fieldsTypePath, typeName);
|
|
4225
|
+
if (!didSucceed) {
|
|
4226
|
+
return {
|
|
4227
|
+
severity: "FATAL",
|
|
4228
|
+
errorType: "TYPE_GEN_ERROR",
|
|
4229
|
+
message: `Failed to generate fields.type.ts for ${modulePath}`
|
|
4230
|
+
};
|
|
4231
|
+
}
|
|
4232
|
+
}
|
|
4233
|
+
return { fieldsTypePath };
|
|
4234
|
+
}
|
|
4235
|
+
async function extractAndValidateFields(fieldsJson, metaJson, modulePath) {
|
|
4236
|
+
if (!metaJson) {
|
|
4237
|
+
return {
|
|
4238
|
+
fieldErrors: [],
|
|
4239
|
+
metaErrors: [
|
|
4240
|
+
{
|
|
4241
|
+
severity: "FATAL",
|
|
4242
|
+
errorType: "MISSING_META",
|
|
4243
|
+
message: `Module does not have a named meta export: ${modulePath}`
|
|
4244
|
+
}
|
|
4245
|
+
]
|
|
4246
|
+
};
|
|
4247
|
+
}
|
|
4248
|
+
const portalId = getConfigDefaultAccount().accountId;
|
|
4249
|
+
const [fieldsResult, metaResult] = await Promise.allSettled([
|
|
4250
|
+
hsCliHttp8.post(portalId, {
|
|
4251
|
+
url: `${VALIDATE_FIELDS_ENDPOINT}?editorVersion=${metaJson.editor_version ?? EDITOR_VERSION_V2}`,
|
|
4252
|
+
data: fieldsJson
|
|
4253
|
+
}),
|
|
4254
|
+
hsCliHttp8.post(portalId, {
|
|
4255
|
+
url: VALIDATE_META_ENDPOINT,
|
|
4256
|
+
data: metaJson
|
|
4257
|
+
})
|
|
4258
|
+
]);
|
|
4259
|
+
const mapErrors = (entities) => entities.filter((e) => e.severity === "FATAL").map((e) => ({
|
|
4260
|
+
severity: e.severity,
|
|
4261
|
+
errorType: e.errorType,
|
|
4262
|
+
message: e.message,
|
|
4263
|
+
fieldPath: e.errorTokens.path[0]
|
|
4264
|
+
}));
|
|
4265
|
+
return {
|
|
4266
|
+
fieldErrors: fieldsResult.status === "fulfilled" ? mapErrors(fieldsResult.value.data) : [
|
|
4267
|
+
{
|
|
4268
|
+
severity: "FATAL",
|
|
4269
|
+
errorType: "API_UNREACHABLE",
|
|
4270
|
+
message: `Field validation API error: ${fieldsResult.reason}`
|
|
4271
|
+
}
|
|
4272
|
+
],
|
|
4273
|
+
metaErrors: metaResult.status === "fulfilled" ? mapErrors(metaResult.value.data) : [
|
|
4274
|
+
{
|
|
4275
|
+
severity: "FATAL",
|
|
4276
|
+
errorType: "API_UNREACHABLE",
|
|
4277
|
+
message: `Meta validation API error: ${metaResult.reason}`
|
|
4278
|
+
}
|
|
4279
|
+
]
|
|
4280
|
+
};
|
|
4281
|
+
}
|
|
4282
|
+
async function generateSingleModule(modulePath, absoluteRoot, viteServer) {
|
|
4283
|
+
const absoluteModulePath = path11.resolve(absoluteRoot, modulePath);
|
|
4284
|
+
let files;
|
|
4285
|
+
try {
|
|
4286
|
+
files = await fs5.readdir(absoluteModulePath);
|
|
4287
|
+
} catch {
|
|
4288
|
+
return {
|
|
4289
|
+
fieldsJsonPath: "",
|
|
4290
|
+
fieldErrors: [
|
|
4291
|
+
{
|
|
4292
|
+
severity: "FATAL",
|
|
4293
|
+
errorType: "MODULE_NOT_FOUND",
|
|
4294
|
+
message: `Module directory does not exist: ${modulePath}`
|
|
4295
|
+
}
|
|
4296
|
+
]
|
|
4297
|
+
};
|
|
4298
|
+
}
|
|
4299
|
+
const indexFile = files.find((f) => f.startsWith("index."));
|
|
4300
|
+
if (!indexFile) {
|
|
4301
|
+
return {
|
|
4302
|
+
fieldsJsonPath: "",
|
|
4303
|
+
fieldErrors: [
|
|
4304
|
+
{
|
|
4305
|
+
severity: "FATAL",
|
|
4306
|
+
errorType: "NO_INDEX_FILE",
|
|
4307
|
+
message: `No index file found in ${modulePath}`
|
|
4308
|
+
}
|
|
4309
|
+
]
|
|
4310
|
+
};
|
|
4311
|
+
}
|
|
4312
|
+
const jsonResult = await generateAndWriteFieldsJson(
|
|
4313
|
+
absoluteModulePath,
|
|
4314
|
+
modulePath,
|
|
4315
|
+
viteServer
|
|
4316
|
+
);
|
|
4317
|
+
if ("severity" in jsonResult) {
|
|
4318
|
+
return { fieldsJsonPath: "", fieldErrors: [jsonResult] };
|
|
4319
|
+
}
|
|
4320
|
+
return {
|
|
4321
|
+
fieldsJsonPath: jsonResult.fieldsJsonPath,
|
|
4322
|
+
fieldErrors: [],
|
|
4323
|
+
fieldsJson: jsonResult.fieldsJson,
|
|
4324
|
+
indexFile
|
|
4325
|
+
};
|
|
4326
|
+
}
|
|
4327
|
+
async function validateSingleModule(modulePath, absoluteRoot, viteServer) {
|
|
4328
|
+
const { fieldsJsonPath, fieldErrors, fieldsJson, indexFile } = await generateSingleModule(modulePath, absoluteRoot, viteServer);
|
|
4329
|
+
if (!fieldsJson || !indexFile) {
|
|
4330
|
+
return { fieldsJsonPath, fieldsTypePath: "", fieldErrors, metaErrors: [] };
|
|
4331
|
+
}
|
|
4332
|
+
const absoluteModulePath = path11.resolve(absoluteRoot, modulePath);
|
|
4333
|
+
const typeResult = await generateAndWriteFieldsType(
|
|
4334
|
+
absoluteModulePath,
|
|
4335
|
+
modulePath,
|
|
4336
|
+
path11.basename(modulePath),
|
|
4337
|
+
fieldsJson
|
|
4338
|
+
);
|
|
4339
|
+
if ("severity" in typeResult) {
|
|
4340
|
+
return {
|
|
4341
|
+
fieldsJsonPath,
|
|
4342
|
+
fieldsTypePath: "",
|
|
4343
|
+
fieldErrors: [typeResult],
|
|
4344
|
+
metaErrors: []
|
|
4345
|
+
};
|
|
4346
|
+
}
|
|
4347
|
+
const { fieldsTypePath } = typeResult;
|
|
4348
|
+
let mod;
|
|
4349
|
+
try {
|
|
4350
|
+
mod = await viteServer.ssrLoadModule(
|
|
4351
|
+
path11.join(absoluteModulePath, indexFile)
|
|
4352
|
+
);
|
|
4353
|
+
} catch {
|
|
4354
|
+
return {
|
|
4355
|
+
fieldsJsonPath,
|
|
4356
|
+
fieldsTypePath,
|
|
4357
|
+
fieldErrors: [
|
|
4358
|
+
{
|
|
4359
|
+
severity: "FATAL",
|
|
4360
|
+
errorType: "MODULE_BUILD_ERROR",
|
|
4361
|
+
message: `Failed to SSR-load module for meta extraction: ${modulePath}`
|
|
4362
|
+
}
|
|
4363
|
+
],
|
|
4364
|
+
metaErrors: []
|
|
4365
|
+
};
|
|
4366
|
+
}
|
|
4367
|
+
const validation = await extractAndValidateFields(
|
|
4368
|
+
fieldsJson,
|
|
4369
|
+
mod.meta,
|
|
4370
|
+
modulePath
|
|
4371
|
+
);
|
|
4372
|
+
return { fieldsJsonPath, fieldsTypePath, ...validation };
|
|
4373
|
+
}
|
|
4374
|
+
|
|
4375
|
+
// src/routes/moduleValidateFields.ts
|
|
4376
|
+
var invalidateModuleFiles = async (viteServer, absoluteModulePath) => {
|
|
4377
|
+
const files = await fs6.readdir(absoluteModulePath).catch(() => []);
|
|
4378
|
+
files.forEach(
|
|
4379
|
+
(file) => {
|
|
4380
|
+
var _a;
|
|
4381
|
+
return (_a = viteServer.moduleGraph.getModulesByFile(path12.join(absoluteModulePath, file))) == null ? void 0 : _a.forEach((mod) => viteServer.moduleGraph.invalidateModule(mod));
|
|
4382
|
+
}
|
|
4383
|
+
);
|
|
4384
|
+
};
|
|
4385
|
+
var moduleValidateFieldsRouteHandler = async (request, response) => {
|
|
4386
|
+
try {
|
|
4387
|
+
const { webRoot, viteServer } = request.app.locals;
|
|
4388
|
+
const { moduleName } = request.params;
|
|
4389
|
+
const modulesRoot = path12.resolve(webRoot, "components/modules");
|
|
4390
|
+
const absoluteModulePath = path12.resolve(modulesRoot, moduleName);
|
|
4391
|
+
if (!absoluteModulePath.startsWith(modulesRoot + path12.sep) || path12.dirname(absoluteModulePath) !== modulesRoot) {
|
|
4392
|
+
return response.status(400).json({ error: "Invalid module name" });
|
|
4393
|
+
}
|
|
4394
|
+
await invalidateModuleFiles(viteServer, absoluteModulePath);
|
|
4395
|
+
const result = await validateSingleModule(
|
|
4396
|
+
absoluteModulePath,
|
|
4397
|
+
webRoot,
|
|
4398
|
+
viteServer
|
|
4399
|
+
);
|
|
4400
|
+
return response.status(200).json([result]);
|
|
4401
|
+
} catch (error) {
|
|
4402
|
+
console.error("Error validating module fields:", error);
|
|
4403
|
+
return response.status(500).json({
|
|
4404
|
+
error: "Failed to validate module fields"
|
|
4405
|
+
});
|
|
4406
|
+
}
|
|
4407
|
+
};
|
|
4408
|
+
var moduleValidateFields_default = moduleValidateFieldsRouteHandler;
|
|
4409
|
+
|
|
4410
|
+
// src/proxyPage/fetchContentMetadata.ts
|
|
4411
|
+
import http from "http";
|
|
4412
|
+
import https from "https";
|
|
4413
|
+
import { getConfigAccountIfExists as getConfigAccountIfExists5 } from "@hubspot/local-dev-lib/config";
|
|
4414
|
+
async function requestPage(url3, redirects = 0, originalUrl) {
|
|
4415
|
+
if (redirects > 5) {
|
|
4416
|
+
throw new Error(
|
|
4417
|
+
`Hit too many redirects to HEAD requests for ${originalUrl}`
|
|
4418
|
+
);
|
|
4419
|
+
}
|
|
4420
|
+
return new Promise((resolve2, reject) => {
|
|
4421
|
+
const protocolAPI = url3.startsWith("https://") ? https : http;
|
|
4422
|
+
protocolAPI.request(
|
|
4423
|
+
url3,
|
|
4424
|
+
{
|
|
4425
|
+
method: "HEAD",
|
|
4426
|
+
headers: {
|
|
4427
|
+
// Keep this user agent, so we don't get 403s from the request
|
|
4428
|
+
["User-Agent"]: "cms-dev-server"
|
|
4429
|
+
}
|
|
4430
|
+
},
|
|
4431
|
+
async (res) => {
|
|
4432
|
+
let portalIdHeader;
|
|
4433
|
+
let contentId;
|
|
4434
|
+
const isContentMembershipRedirect = Boolean(
|
|
4435
|
+
res.headers["x-hs-content-membership-redirect"]
|
|
4436
|
+
);
|
|
4437
|
+
if (isContentMembershipRedirect) {
|
|
4438
|
+
debug("Content Membership Redirect", res.headers);
|
|
4439
|
+
portalIdHeader = res.headers["x-hs-portal-id"];
|
|
4440
|
+
contentId = res.headers["x-hs-content-id"];
|
|
4441
|
+
if (portalIdHeader && contentId) {
|
|
4442
|
+
return resolve2({
|
|
4443
|
+
portalIdHeader,
|
|
4444
|
+
contentId,
|
|
4445
|
+
res
|
|
4446
|
+
});
|
|
4447
|
+
}
|
|
4448
|
+
}
|
|
4449
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
4450
|
+
console.log(`Redirecting to ${res.headers.location} (from ${url3})`);
|
|
4451
|
+
return resolve2(
|
|
4452
|
+
requestPage(
|
|
4453
|
+
res.headers.location,
|
|
4454
|
+
redirects + 1,
|
|
4455
|
+
originalUrl ?? url3
|
|
4456
|
+
)
|
|
4457
|
+
);
|
|
4458
|
+
}
|
|
4459
|
+
portalIdHeader = res.headers["x-hs-hub-id"];
|
|
4460
|
+
contentId = res.headers["x-hs-content-id"];
|
|
4461
|
+
return resolve2({
|
|
4462
|
+
res,
|
|
4463
|
+
portalIdHeader,
|
|
4464
|
+
contentId
|
|
4465
|
+
});
|
|
4466
|
+
}
|
|
4467
|
+
).on("error", (err) => {
|
|
4468
|
+
console.error(err);
|
|
4469
|
+
reject(err);
|
|
4470
|
+
}).end();
|
|
4471
|
+
});
|
|
4472
|
+
}
|
|
4473
|
+
async function fetchContentMetadata(url3, portalId) {
|
|
4474
|
+
const { portalIdHeader, contentId, res } = await requestPage(url3);
|
|
4475
|
+
if (Array.isArray(portalIdHeader) || Array.isArray(contentId)) {
|
|
4476
|
+
throw new Error(
|
|
4477
|
+
`There were multiple hub ID or content ID headers in the HEAD request to ${url3}`
|
|
4478
|
+
);
|
|
4479
|
+
} else {
|
|
4480
|
+
const portalIdFromResponse = parseInt(portalIdHeader, 10);
|
|
4481
|
+
const pageAccount = await getConfigAccountIfExists5(portalIdFromResponse);
|
|
4482
|
+
if (!pageAccount) {
|
|
4483
|
+
throw new Error(
|
|
4484
|
+
`No CLI auth for portal ${portalIdFromResponse} found, please run \`hs auth\``
|
|
4485
|
+
);
|
|
4486
|
+
}
|
|
4487
|
+
if (res.statusCode !== 200 && !(portalIdFromResponse && pageAccount && contentId)) {
|
|
4488
|
+
throw new Error(
|
|
4489
|
+
`${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.` : ""}`
|
|
4490
|
+
);
|
|
4491
|
+
} else if (!portalId || !contentId) {
|
|
4492
|
+
throw new Error(
|
|
4493
|
+
`Missing hub ID or content ID headers on HEAD request to ${url3}`
|
|
4494
|
+
);
|
|
4495
|
+
} else if (isNaN(portalId)) {
|
|
4496
|
+
throw new Error(
|
|
4497
|
+
`Hub ID from the HEAD request is not a number: '${portalId}' (${url3})`
|
|
4498
|
+
);
|
|
4499
|
+
}
|
|
4500
|
+
const hublet = "na1";
|
|
4501
|
+
return { portalId, contentId, hublet };
|
|
4502
|
+
}
|
|
4503
|
+
}
|
|
4504
|
+
|
|
4505
|
+
// src/routes/proxyPageRouteHandler.ts
|
|
4506
|
+
async function proxyPageRouteHandler(request, response, next) {
|
|
4507
|
+
sendTrackingRequest("view-proxy-page-route");
|
|
4508
|
+
const {
|
|
4509
|
+
viteServer,
|
|
4510
|
+
webRoot,
|
|
4511
|
+
projectName,
|
|
4512
|
+
projectComponentPath,
|
|
4513
|
+
jsRenderingGates
|
|
4514
|
+
} = request.app.locals;
|
|
4515
|
+
if (!request.accepts().includes("text/html")) {
|
|
4516
|
+
return response.sendStatus(404);
|
|
4517
|
+
}
|
|
4518
|
+
const fullOriginalUrl = fullOriginalUrlFromRequest(request);
|
|
4519
|
+
const domainToProxy = getSubDomainFromValidLocalDomain(request.hostname);
|
|
4520
|
+
const urlToProxy = `http://${domainToProxy}${request.originalUrl}`;
|
|
4521
|
+
if (!domainToProxy) {
|
|
4522
|
+
if (VALID_PROXY_DOMAIN_SUFFIXES.includes(request.hostname)) {
|
|
4523
|
+
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})`;
|
|
4524
|
+
consoleWarn(message);
|
|
4525
|
+
return response.status(400).send(message);
|
|
4526
|
+
} else {
|
|
4527
|
+
const message = `Can't make a proxy request, the domain '${request.hostname}' is not a valid proxy-able domain`;
|
|
4528
|
+
consoleWarn(message);
|
|
4529
|
+
return response.status(400).send(message);
|
|
4530
|
+
}
|
|
4531
|
+
}
|
|
4532
|
+
try {
|
|
4533
|
+
const { portalId, contentId, hublet } = await fetchContentMetadata(
|
|
4534
|
+
urlToProxy,
|
|
4535
|
+
request.app.locals.authedPortalId
|
|
4536
|
+
);
|
|
4537
|
+
await proxySpecificPage(
|
|
4538
|
+
request,
|
|
4539
|
+
response,
|
|
4540
|
+
portalId,
|
|
4541
|
+
hublet,
|
|
4542
|
+
contentId,
|
|
4543
|
+
webRoot,
|
|
4544
|
+
viteServer,
|
|
4545
|
+
projectName,
|
|
3998
4546
|
projectComponentPath,
|
|
3999
4547
|
jsRenderingGates,
|
|
4000
4548
|
urlToProxy,
|
|
@@ -4060,31 +4608,31 @@ function HubLModulesList({ modules }) {
|
|
|
4060
4608
|
}
|
|
4061
4609
|
|
|
4062
4610
|
// src/api/designmanager.ts
|
|
4063
|
-
import { http as
|
|
4611
|
+
import { http as hsCliHttp9 } from "@hubspot/local-dev-lib/http";
|
|
4064
4612
|
var DESIGN_MANAGER_API_PATH = "designmanager/v1";
|
|
4065
4613
|
async function fetchHubLModules(accountId, previewToken, limit = 250) {
|
|
4066
|
-
return (await
|
|
4614
|
+
return (await hsCliHttp9.get(accountId, {
|
|
4067
4615
|
url: `${DESIGN_MANAGER_API_PATH}/modules/local-preview?previewToken=${previewToken}&limit=${limit}`
|
|
4068
4616
|
})).data;
|
|
4069
4617
|
}
|
|
4070
4618
|
async function fetchPreviewTemplates(accountId, previewToken, limit = 250) {
|
|
4071
|
-
return (await
|
|
4619
|
+
return (await hsCliHttp9.get(accountId, {
|
|
4072
4620
|
url: `${DESIGN_MANAGER_API_PATH}/templates/local-preview?previewToken=${previewToken}&limit=${limit}`
|
|
4073
4621
|
})).data;
|
|
4074
4622
|
}
|
|
4075
|
-
async function fetchModuleByPath(accountId,
|
|
4076
|
-
return (await
|
|
4077
|
-
url: `${DESIGN_MANAGER_API_PATH}/modules/by-path/${
|
|
4623
|
+
async function fetchModuleByPath(accountId, path20) {
|
|
4624
|
+
return (await hsCliHttp9.get(accountId, {
|
|
4625
|
+
url: `${DESIGN_MANAGER_API_PATH}/modules/by-path/${path20}?portalId=${accountId}`
|
|
4078
4626
|
})).data;
|
|
4079
4627
|
}
|
|
4080
|
-
async function fetchTemplateByPath(accountId,
|
|
4081
|
-
return (await
|
|
4082
|
-
url: `${DESIGN_MANAGER_API_PATH}/templates/by-path/${
|
|
4628
|
+
async function fetchTemplateByPath(accountId, path20) {
|
|
4629
|
+
return (await hsCliHttp9.get(accountId, {
|
|
4630
|
+
url: `${DESIGN_MANAGER_API_PATH}/templates/by-path/${path20}?portalId=${accountId}`
|
|
4083
4631
|
})).data;
|
|
4084
4632
|
}
|
|
4085
|
-
async function fetchModulePageDependencies(accountId,
|
|
4086
|
-
const url3 = `${DESIGN_MANAGER_API_PATH}/modules/list-pages?modulePath=${
|
|
4087
|
-
return (await
|
|
4633
|
+
async function fetchModulePageDependencies(accountId, path20) {
|
|
4634
|
+
const url3 = `${DESIGN_MANAGER_API_PATH}/modules/list-pages?modulePath=${path20}`;
|
|
4635
|
+
return (await hsCliHttp9.get(accountId, { url: url3 })).data;
|
|
4088
4636
|
}
|
|
4089
4637
|
|
|
4090
4638
|
// src/components/HubLTemplatesList.tsx
|
|
@@ -4319,7 +4867,7 @@ function proxyServerlessRequest(req, res, next) {
|
|
|
4319
4867
|
}
|
|
4320
4868
|
|
|
4321
4869
|
// src/routes/modulePreviewRouteHandler.ts
|
|
4322
|
-
import
|
|
4870
|
+
import path13 from "path";
|
|
4323
4871
|
import { normalizePath as normalizePath8 } from "vite";
|
|
4324
4872
|
async function modulePreviewRouteHandler(request, response) {
|
|
4325
4873
|
sendTrackingRequest("view-module-preview-route");
|
|
@@ -4336,7 +4884,7 @@ async function modulePreviewRouteHandler(request, response) {
|
|
|
4336
4884
|
} = request.app.locals;
|
|
4337
4885
|
const moduleName = request.params.moduleName;
|
|
4338
4886
|
const modulePath = normalizePath8(
|
|
4339
|
-
|
|
4887
|
+
path13.resolve(webRoot, "components/modules/", moduleName)
|
|
4340
4888
|
);
|
|
4341
4889
|
const PREVIEWER_APP_PARAM = "hsPreviewerApp";
|
|
4342
4890
|
let fieldOverrides = {};
|
|
@@ -4437,7 +4985,7 @@ var modulePreviewRouteHandler_default = modulePreviewRouteHandler;
|
|
|
4437
4985
|
// src/routes/hublModuleRouteHandler.ts
|
|
4438
4986
|
var hublModuleRouteHandler = async (request, response) => {
|
|
4439
4987
|
sendTrackingRequest("view-hubl-module-route");
|
|
4440
|
-
const { authedPortalId, localPreviewToken, projectName
|
|
4988
|
+
const { authedPortalId, localPreviewToken, projectName } = request.app.locals;
|
|
4441
4989
|
const { modulePath } = request.params;
|
|
4442
4990
|
if (!modulePath) {
|
|
4443
4991
|
response.status(200).set({ "Content-Type": "text/html" }).end(buildModuleIndex());
|
|
@@ -4465,7 +5013,7 @@ var hublModuleRouteHandler = async (request, response) => {
|
|
|
4465
5013
|
};
|
|
4466
5014
|
const previewUrl = getPreviewUrl(request, params);
|
|
4467
5015
|
try {
|
|
4468
|
-
const result = await signedGet(authedPortalId, previewUrl, {}
|
|
5016
|
+
const result = await signedGet(authedPortalId, previewUrl, {});
|
|
4469
5017
|
const html = addRefreshScript(result);
|
|
4470
5018
|
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
4471
5019
|
} catch (err) {
|
|
@@ -4540,12 +5088,7 @@ var templateRouteHandler = async (request, response) => {
|
|
|
4540
5088
|
const previewUrl = getPreviewUrl(request, params);
|
|
4541
5089
|
const fullOriginalUrl = `${request.protocol}://${request.get("host")}${request.originalUrl}`;
|
|
4542
5090
|
try {
|
|
4543
|
-
const result = await signedGet(
|
|
4544
|
-
authedPortalId,
|
|
4545
|
-
previewUrl,
|
|
4546
|
-
{},
|
|
4547
|
-
jsRenderingGates
|
|
4548
|
-
);
|
|
5091
|
+
const result = await signedGet(authedPortalId, previewUrl, {});
|
|
4549
5092
|
const pageHtml = addRefreshScript(result);
|
|
4550
5093
|
const finalHtml = pageHtml.replace(
|
|
4551
5094
|
HUBSPOT_PREVIEW_BASE_TAG_REGEX,
|
|
@@ -4599,15 +5142,15 @@ function getOpenCommand() {
|
|
|
4599
5142
|
}
|
|
4600
5143
|
}
|
|
4601
5144
|
async function handleGetModulePages(req, res, next) {
|
|
4602
|
-
const { path:
|
|
4603
|
-
if (!
|
|
5145
|
+
const { path: path20, portalId } = req.query;
|
|
5146
|
+
if (!path20 || !portalId) {
|
|
4604
5147
|
return res.status(400).json({ error: "Missing required parameters" });
|
|
4605
5148
|
}
|
|
4606
5149
|
try {
|
|
4607
5150
|
sendTrackingRequest("handle-module-dependencies");
|
|
4608
5151
|
const data = await fetchModulePageDependencies(
|
|
4609
5152
|
Number(portalId),
|
|
4610
|
-
|
|
5153
|
+
path20
|
|
4611
5154
|
);
|
|
4612
5155
|
res.json(data);
|
|
4613
5156
|
} catch (err) {
|
|
@@ -4615,14 +5158,14 @@ async function handleGetModulePages(req, res, next) {
|
|
|
4615
5158
|
}
|
|
4616
5159
|
}
|
|
4617
5160
|
function handleOpenFile(req, res, next) {
|
|
4618
|
-
const { path:
|
|
4619
|
-
if (!
|
|
5161
|
+
const { path: path20 } = req.query;
|
|
5162
|
+
if (!path20) {
|
|
4620
5163
|
return res.status(400).json({ error: "Missing required parameters" });
|
|
4621
5164
|
}
|
|
4622
5165
|
try {
|
|
4623
5166
|
sendTrackingRequest("handle-open-file");
|
|
4624
5167
|
const command = getOpenCommand();
|
|
4625
|
-
spawn(command, [
|
|
5168
|
+
spawn(command, [path20], { detached: true }).unref();
|
|
4626
5169
|
res.sendStatus(200);
|
|
4627
5170
|
} catch (err) {
|
|
4628
5171
|
next(err);
|
|
@@ -4637,25 +5180,25 @@ function createAppServerAPIRoutes() {
|
|
|
4637
5180
|
var createAppServerAPIRoutes_default = createAppServerAPIRoutes;
|
|
4638
5181
|
|
|
4639
5182
|
// src/routes/appServerRouteHandler.ts
|
|
4640
|
-
import
|
|
4641
|
-
import
|
|
5183
|
+
import fs8 from "node:fs/promises";
|
|
5184
|
+
import path15 from "path";
|
|
4642
5185
|
import { pathToFileURL } from "url";
|
|
4643
5186
|
|
|
4644
5187
|
// src/lib/getDevServerUIData.ts
|
|
4645
|
-
import
|
|
5188
|
+
import path14 from "path";
|
|
4646
5189
|
import { normalizePath as normalizePath9 } from "vite";
|
|
4647
5190
|
|
|
4648
5191
|
// src/api/project.ts
|
|
4649
|
-
import { http as
|
|
5192
|
+
import { http as hsCliHttp10 } from "@hubspot/local-dev-lib/http";
|
|
4650
5193
|
var DEVELOPER_PROJECTS_API_PATH = "/developer/projects/v1";
|
|
4651
5194
|
async function fetchProjectByName(accountId, projectName) {
|
|
4652
|
-
return (await
|
|
5195
|
+
return (await hsCliHttp10.get(accountId, {
|
|
4653
5196
|
url: `${DEVELOPER_PROJECTS_API_PATH}/by-name/${projectName}`
|
|
4654
5197
|
})).data;
|
|
4655
5198
|
}
|
|
4656
5199
|
|
|
4657
5200
|
// src/lib/getDevServerUIData.ts
|
|
4658
|
-
import
|
|
5201
|
+
import fs7 from "node:fs";
|
|
4659
5202
|
var templateTypeMap = {
|
|
4660
5203
|
// Standard templates
|
|
4661
5204
|
4: "Page",
|
|
@@ -4681,7 +5224,7 @@ function mapReactModules(modules, themeWebRoot, appViteServer) {
|
|
|
4681
5224
|
return Promise.all(
|
|
4682
5225
|
modules.moduleNames.map(async (name, index) => {
|
|
4683
5226
|
const modulePath = normalizePath9(
|
|
4684
|
-
|
|
5227
|
+
path14.resolve(themeWebRoot, "components/modules/", name)
|
|
4685
5228
|
);
|
|
4686
5229
|
const fieldsJson = await renderModuleFieldsJson_default(
|
|
4687
5230
|
appViteServer,
|
|
@@ -4727,9 +5270,9 @@ function normalizeTemplatesData(templates, projectName) {
|
|
|
4727
5270
|
});
|
|
4728
5271
|
}
|
|
4729
5272
|
function detectPackageManager(projectRoot) {
|
|
4730
|
-
if (
|
|
5273
|
+
if (fs7.existsSync(path14.join(projectRoot, "yarn.lock")))
|
|
4731
5274
|
return "yarn";
|
|
4732
|
-
if (
|
|
5275
|
+
if (fs7.existsSync(path14.join(projectRoot, "pnpm-lock.yaml")))
|
|
4733
5276
|
return "pnpm";
|
|
4734
5277
|
return "npm";
|
|
4735
5278
|
}
|
|
@@ -4813,10 +5356,10 @@ var appServerRouteHandler = async (req, res, __next) => {
|
|
|
4813
5356
|
const { appWebRoot, appViteServer } = appLocals;
|
|
4814
5357
|
const initialProps = await getDevServerUIData(appLocals);
|
|
4815
5358
|
const url3 = req.originalUrl.replace("/", "");
|
|
4816
|
-
const templatePath =
|
|
4817
|
-
const serverEntryPath = isProd ?
|
|
5359
|
+
const templatePath = path15.join(appWebRoot, "index.html");
|
|
5360
|
+
const serverEntryPath = isProd ? path15.join(appWebRoot, "server/serverEntry.js") : path15.join(appWebRoot, "serverEntry.tsx");
|
|
4818
5361
|
let render;
|
|
4819
|
-
let template = await
|
|
5362
|
+
let template = await fs8.readFile(path15.join(templatePath), "utf-8");
|
|
4820
5363
|
if (isProd) {
|
|
4821
5364
|
const { render: ssrRender } = await import(pathToFileURL(serverEntryPath).href);
|
|
4822
5365
|
render = ssrRender;
|
|
@@ -4847,7 +5390,7 @@ var appServerRouteHandler = async (req, res, __next) => {
|
|
|
4847
5390
|
var appServerRouteHandler_default = appServerRouteHandler;
|
|
4848
5391
|
|
|
4849
5392
|
// src/routes/createDevServerRoutes.ts
|
|
4850
|
-
import
|
|
5393
|
+
import path16 from "path";
|
|
4851
5394
|
var isProd2 = true;
|
|
4852
5395
|
var STORYBOOK_DOMAINS = VALID_PROXY_DOMAIN_SUFFIXES.map(
|
|
4853
5396
|
(domain) => `storybook.${domain}`
|
|
@@ -4874,7 +5417,7 @@ var createDevServerRoutes = async (viteServer, appLocals, storybookPort) => {
|
|
|
4874
5417
|
}
|
|
4875
5418
|
devServerApp.use(urlencoded());
|
|
4876
5419
|
if (isProd2) {
|
|
4877
|
-
const distAssetsPath =
|
|
5420
|
+
const distAssetsPath = path16.join(appWebRoot, "assets");
|
|
4878
5421
|
devServerApp.use("/assets", expressStatic(distAssetsPath));
|
|
4879
5422
|
} else if (appViteServer) {
|
|
4880
5423
|
devServerApp.use("/local", appViteServer.middlewares);
|
|
@@ -4898,6 +5441,10 @@ var createDevServerRoutes = async (viteServer, appLocals, storybookPort) => {
|
|
|
4898
5441
|
moduleFieldsJson_default
|
|
4899
5442
|
);
|
|
4900
5443
|
devServerApp.get("/module/:moduleName/*", module_default);
|
|
5444
|
+
devServerApp.post(
|
|
5445
|
+
"/preview/module/:moduleName/validate-fields",
|
|
5446
|
+
moduleValidateFields_default
|
|
5447
|
+
);
|
|
4901
5448
|
devServerApp.post("/preview/module/:moduleName", modulePreviewRouteHandler_default);
|
|
4902
5449
|
devServerApp.get("/hublmodule/:modulePath(*)", hublModuleRouteHandler);
|
|
4903
5450
|
devServerApp.get("/template/:templatePath(*)", templateRouteHandler);
|
|
@@ -5122,719 +5669,364 @@ function createHttpsRedirectingServer(opts, handler) {
|
|
|
5122
5669
|
return { server, innerHTTPServer, innerHTTPSServer };
|
|
5123
5670
|
}
|
|
5124
5671
|
|
|
5125
|
-
// src/lib/getJSRenderingGates.ts
|
|
5126
|
-
import { getAccessToken } from "@hubspot/local-dev-lib/personalAccessKey";
|
|
5127
|
-
|
|
5128
|
-
// src/lib/gates.ts
|
|
5129
|
-
function getGatesFromEnv() {
|
|
5130
|
-
const gates = process.env.GATES ? process.env.GATES.split(",") : [];
|
|
5131
|
-
return gates;
|
|
5132
|
-
}
|
|
5133
|
-
|
|
5134
|
-
// src/lib/getJSRenderingGates.ts
|
|
5135
|
-
var mapEnabledFeaturesToGates = (enabledFeatures) => {
|
|
5136
|
-
return Object.keys(enabledFeatures).reduce((gates, enabledFeature) => {
|
|
5137
|
-
if (enabledFeatures[enabledFeature]) {
|
|
5138
|
-
gates.push(ENABLED_FEATURES_GATE_MAP[enabledFeature]);
|
|
5139
|
-
}
|
|
5140
|
-
return gates;
|
|
5141
|
-
}, []);
|
|
5142
|
-
};
|
|
5143
|
-
async function getJsRenderingGates(portalId, env2, personalAccessKey) {
|
|
5144
|
-
const { enabledFeatures } = await getAccessToken(personalAccessKey, env2, portalId);
|
|
5145
|
-
const envGates = getGatesFromEnv();
|
|
5146
|
-
const gates = mapEnabledFeaturesToGates(enabledFeatures);
|
|
5147
|
-
const mergedGates = [...envGates, ...gates];
|
|
5148
|
-
process.env.GATES = mergedGates.join(",");
|
|
5149
|
-
return mergedGates;
|
|
5150
|
-
}
|
|
5151
|
-
|
|
5152
|
-
// src/lib/hsmetaUtils.ts
|
|
5153
|
-
import path14 from "path";
|
|
5154
|
-
import fs6 from "fs";
|
|
5155
|
-
var HSMETA_FILENAMES = [
|
|
5156
|
-
"theme-hsmeta.json",
|
|
5157
|
-
"cms-assets-hsmeta.json"
|
|
5158
|
-
];
|
|
5159
|
-
function getSubdirectories(dirPath) {
|
|
5160
|
-
try {
|
|
5161
|
-
return fs6.readdirSync(dirPath, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
5162
|
-
} catch {
|
|
5163
|
-
return [];
|
|
5164
|
-
}
|
|
5165
|
-
}
|
|
5166
|
-
function hsmetaCandidatePaths(srcPath) {
|
|
5167
|
-
const subdirs = getSubdirectories(srcPath);
|
|
5168
|
-
return subdirs.flatMap(
|
|
5169
|
-
(subdir) => HSMETA_FILENAMES.map((filename) => path14.join(srcPath, subdir, filename))
|
|
5170
|
-
);
|
|
5171
|
-
}
|
|
5172
|
-
function tryParseUid(hsmetaPath) {
|
|
5173
|
-
try {
|
|
5174
|
-
const hsmeta = JSON.parse(fs6.readFileSync(hsmetaPath, "utf8"));
|
|
5175
|
-
return hsmeta.uid ?? null;
|
|
5176
|
-
} catch (parseErr) {
|
|
5177
|
-
console.warn(`Could not parse ${hsmetaPath}:`, parseErr.message);
|
|
5178
|
-
return null;
|
|
5179
|
-
}
|
|
5180
|
-
}
|
|
5181
|
-
function findHsmetaUid(projectDir, srcDir) {
|
|
5182
|
-
const srcPath = path14.join(projectDir, srcDir);
|
|
5183
|
-
for (const candidatePath of hsmetaCandidatePaths(srcPath)) {
|
|
5184
|
-
if (!fs6.existsSync(candidatePath))
|
|
5185
|
-
continue;
|
|
5186
|
-
const uid = tryParseUid(candidatePath);
|
|
5187
|
-
if (uid)
|
|
5188
|
-
return uid;
|
|
5189
|
-
}
|
|
5190
|
-
return null;
|
|
5191
|
-
}
|
|
5192
|
-
|
|
5193
|
-
// src/lib/cliUtils.ts
|
|
5194
|
-
import process2 from "process";
|
|
5195
|
-
import os from "os";
|
|
5196
|
-
import tty from "tty";
|
|
5197
|
-
var COMPONENT_TYPES = Object.freeze({
|
|
5198
|
-
privateApp: "private-app",
|
|
5199
|
-
publicApp: "public-app",
|
|
5200
|
-
hublTheme: "hubl-theme"
|
|
5201
|
-
});
|
|
5202
|
-
var CONFIG_FILES = {
|
|
5203
|
-
[COMPONENT_TYPES.privateApp]: "app.json",
|
|
5204
|
-
[COMPONENT_TYPES.publicApp]: "public-app.json",
|
|
5205
|
-
[COMPONENT_TYPES.hublTheme]: "theme.json"
|
|
5206
|
-
};
|
|
5207
|
-
function hasNewDirectoryStructure(platformVersion) {
|
|
5208
|
-
return parseFloat(platformVersion) >= 2025.2;
|
|
5209
|
-
}
|
|
5210
|
-
var { env } = process2;
|
|
5211
|
-
function translateLevel(level) {
|
|
5212
|
-
if (level === 0) {
|
|
5213
|
-
return {
|
|
5214
|
-
level,
|
|
5215
|
-
hasBasic: false,
|
|
5216
|
-
has256: false,
|
|
5217
|
-
has16m: false
|
|
5218
|
-
};
|
|
5219
|
-
}
|
|
5220
|
-
return {
|
|
5221
|
-
level,
|
|
5222
|
-
hasBasic: true,
|
|
5223
|
-
has256: level >= 2,
|
|
5224
|
-
has16m: level >= 3
|
|
5225
|
-
};
|
|
5226
|
-
}
|
|
5227
|
-
function _supportsColor(haveStream, { streamIsTTY } = {}) {
|
|
5228
|
-
if (haveStream && !streamIsTTY) {
|
|
5229
|
-
return 0;
|
|
5230
|
-
}
|
|
5231
|
-
const min = 0;
|
|
5232
|
-
if (env.TERM === "dumb") {
|
|
5233
|
-
return min;
|
|
5234
|
-
}
|
|
5235
|
-
if (hasFlag("noColor")) {
|
|
5236
|
-
return 0;
|
|
5237
|
-
}
|
|
5238
|
-
if (process2.platform === "win32") {
|
|
5239
|
-
const osRelease = os.release().split(".");
|
|
5240
|
-
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
5241
|
-
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
5242
|
-
}
|
|
5243
|
-
return 1;
|
|
5244
|
-
}
|
|
5245
|
-
if ("CI" in env) {
|
|
5246
|
-
if ([
|
|
5247
|
-
"TRAVIS",
|
|
5248
|
-
"CIRCLECI",
|
|
5249
|
-
"APPVEYOR",
|
|
5250
|
-
"GITLAB_CI",
|
|
5251
|
-
"GITHUB_ACTIONS",
|
|
5252
|
-
"BUILDKITE",
|
|
5253
|
-
"DRONE"
|
|
5254
|
-
].some((sign) => sign in env) || env.CI_NAME === "codeship") {
|
|
5255
|
-
return 1;
|
|
5256
|
-
}
|
|
5257
|
-
return min;
|
|
5258
|
-
}
|
|
5259
|
-
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
|
|
5260
|
-
return 1;
|
|
5261
|
-
}
|
|
5262
|
-
if (env.COLORTERM === "truecolor") {
|
|
5263
|
-
return 3;
|
|
5264
|
-
}
|
|
5265
|
-
if ("TERM_PROGRAM" in env) {
|
|
5266
|
-
const version = Number.parseInt(
|
|
5267
|
-
(env.TERM_PROGRAM_VERSION || "").split(".")[0],
|
|
5268
|
-
10
|
|
5269
|
-
);
|
|
5270
|
-
switch (env.TERM_PROGRAM) {
|
|
5271
|
-
case "iTerm.app":
|
|
5272
|
-
return version >= 3 ? 3 : 2;
|
|
5273
|
-
case "Apple_Terminal":
|
|
5274
|
-
return 2;
|
|
5275
|
-
}
|
|
5276
|
-
}
|
|
5277
|
-
if (/-256(color)?$/i.test(env.TERM)) {
|
|
5278
|
-
return 2;
|
|
5279
|
-
}
|
|
5280
|
-
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
5281
|
-
return 1;
|
|
5282
|
-
}
|
|
5283
|
-
if ("COLORTERM" in env) {
|
|
5284
|
-
return 1;
|
|
5285
|
-
}
|
|
5286
|
-
return min;
|
|
5287
|
-
}
|
|
5288
|
-
function createSupportsColor(stream2, options = {}) {
|
|
5289
|
-
const level = _supportsColor(stream2, {
|
|
5290
|
-
streamIsTTY: stream2 && stream2.isTTY,
|
|
5291
|
-
...options
|
|
5292
|
-
});
|
|
5293
|
-
return translateLevel(level);
|
|
5294
|
-
}
|
|
5295
|
-
var supportsColor = {
|
|
5296
|
-
createSupportsColor,
|
|
5297
|
-
stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
|
|
5298
|
-
stderr: createSupportsColor({ isTTY: tty.isatty(2) })
|
|
5299
|
-
};
|
|
5300
|
-
function hasFlag(flag, argv = process2.argv) {
|
|
5301
|
-
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
5302
|
-
const position = argv.indexOf(prefix + flag);
|
|
5303
|
-
const terminatorPosition = argv.indexOf("--");
|
|
5304
|
-
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
5305
|
-
}
|
|
5306
|
-
|
|
5307
|
-
// src/createDevServer.ts
|
|
5308
|
-
import {
|
|
5309
|
-
getConfigAccountIfExists as getConfigAccountIfExists7,
|
|
5310
|
-
getConfigDefaultAccountIfExists,
|
|
5311
|
-
validateConfig
|
|
5312
|
-
} from "@hubspot/local-dev-lib/config";
|
|
5313
|
-
import { fetchSecrets } from "@hubspot/local-dev-lib/api/secrets";
|
|
5314
|
-
import { PERSONAL_ACCESS_KEY_AUTH_METHOD } from "@hubspot/local-dev-lib/constants/auth";
|
|
5672
|
+
// src/lib/getJSRenderingGates.ts
|
|
5673
|
+
import { getAccessToken } from "@hubspot/local-dev-lib/personalAccessKey";
|
|
5315
5674
|
|
|
5316
|
-
// src/
|
|
5317
|
-
|
|
5675
|
+
// src/lib/gates.ts
|
|
5676
|
+
function getGatesFromEnv() {
|
|
5677
|
+
const gates = process.env.GATES ? process.env.GATES.split(",") : [];
|
|
5678
|
+
return gates;
|
|
5679
|
+
}
|
|
5318
5680
|
|
|
5319
|
-
// src/lib/
|
|
5320
|
-
var
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
var NOT_PUBLIC_USE_ERROR = `The scope needed for this API call isn't available for public use`;
|
|
5325
|
-
var MissingScopeError = class extends Error {
|
|
5326
|
-
constructor(error) {
|
|
5327
|
-
let messageEnd = "";
|
|
5328
|
-
if (error.error.message.match(OAUTH_ERROR_REGEX)) {
|
|
5329
|
-
messageEnd = error.error.message;
|
|
5681
|
+
// src/lib/getJSRenderingGates.ts
|
|
5682
|
+
var mapEnabledFeaturesToGates = (enabledFeatures) => {
|
|
5683
|
+
return Object.keys(enabledFeatures).reduce((gates, enabledFeature) => {
|
|
5684
|
+
if (enabledFeatures[enabledFeature]) {
|
|
5685
|
+
gates.push(ENABLED_FEATURES_GATE_MAP[enabledFeature]);
|
|
5330
5686
|
}
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
Object.setPrototypeOf(this, MissingScopeError.prototype);
|
|
5334
|
-
}
|
|
5687
|
+
return gates;
|
|
5688
|
+
}, []);
|
|
5335
5689
|
};
|
|
5336
|
-
function
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
if (error && error.statusCode && error.error) {
|
|
5344
|
-
const { statusCode, error: errorDetails } = error;
|
|
5345
|
-
if ((errorDetails == null ? void 0 : errorDetails.category) === "MISSING_SCOPES") {
|
|
5346
|
-
console.log(
|
|
5347
|
-
"\nMissing scopes for secrets.",
|
|
5348
|
-
"\nSecrets require Serverless functions which are scoped to Enterprise portals.\n"
|
|
5349
|
-
);
|
|
5350
|
-
} else {
|
|
5351
|
-
console.error(`Error ${statusCode}: ${errorDetails.message}`);
|
|
5352
|
-
if (errorDetails.correlationId) {
|
|
5353
|
-
console.error(`Correlation ID: ${errorDetails.correlationId}`);
|
|
5354
|
-
}
|
|
5355
|
-
if (errorDetails.category) {
|
|
5356
|
-
console.error(`Category: ${errorDetails.category}`);
|
|
5357
|
-
}
|
|
5358
|
-
if (errorDetails.links) {
|
|
5359
|
-
if (errorDetails.links.support) {
|
|
5360
|
-
console.error(`Support URL: ${errorDetails.links.support}`);
|
|
5361
|
-
}
|
|
5362
|
-
if (errorDetails.links.forum) {
|
|
5363
|
-
console.error(`Forum URL: ${errorDetails.links.forum}`);
|
|
5364
|
-
}
|
|
5365
|
-
}
|
|
5366
|
-
}
|
|
5367
|
-
} else {
|
|
5368
|
-
console.error("Unexpected error structure:", error);
|
|
5369
|
-
}
|
|
5690
|
+
async function getJsRenderingGates(portalId, env2, personalAccessKey) {
|
|
5691
|
+
const { enabledFeatures } = await getAccessToken(personalAccessKey, env2, portalId);
|
|
5692
|
+
const envGates = getGatesFromEnv();
|
|
5693
|
+
const gates = mapEnabledFeaturesToGates(enabledFeatures);
|
|
5694
|
+
const mergedGates = [...envGates, ...gates];
|
|
5695
|
+
process.env.GATES = mergedGates.join(",");
|
|
5696
|
+
return mergedGates;
|
|
5370
5697
|
}
|
|
5371
5698
|
|
|
5372
|
-
// src/
|
|
5373
|
-
|
|
5699
|
+
// src/lib/hsmetaUtils.ts
|
|
5700
|
+
import path17 from "path";
|
|
5701
|
+
import fs9 from "fs";
|
|
5702
|
+
var HSMETA_FILENAMES = [
|
|
5703
|
+
"theme-hsmeta.json",
|
|
5704
|
+
"cms-assets-hsmeta.json"
|
|
5705
|
+
];
|
|
5706
|
+
function getSubdirectories(dirPath) {
|
|
5374
5707
|
try {
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
responseType: "json"
|
|
5379
|
-
})).data;
|
|
5380
|
-
return result.results;
|
|
5381
|
-
} catch (error) {
|
|
5382
|
-
if (isMissingScopeError(error)) {
|
|
5383
|
-
throw new MissingScopeError(error);
|
|
5384
|
-
}
|
|
5385
|
-
throw error;
|
|
5708
|
+
return fs9.readdirSync(dirPath, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
5709
|
+
} catch {
|
|
5710
|
+
return [];
|
|
5386
5711
|
}
|
|
5387
5712
|
}
|
|
5388
|
-
|
|
5389
|
-
const
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
});
|
|
5393
|
-
const domainNames = filteredDomains.map((r) => r.domain);
|
|
5394
|
-
return domainNames;
|
|
5395
|
-
}
|
|
5396
|
-
|
|
5397
|
-
// src/lib/validateHSPlatform.ts
|
|
5398
|
-
import path15 from "path";
|
|
5399
|
-
import fs7 from "fs";
|
|
5400
|
-
import { http as hsCliHttp11 } from "@hubspot/local-dev-lib/http";
|
|
5401
|
-
var HSPROJECT_JSON = "hsproject.json";
|
|
5402
|
-
function checkFileExists(filePath) {
|
|
5403
|
-
return fs7.existsSync(filePath) && fs7.statSync(filePath).isFile();
|
|
5404
|
-
}
|
|
5405
|
-
function findHSProjectJson(startPath) {
|
|
5406
|
-
let currentDir = startPath;
|
|
5407
|
-
let dirLevel = 0;
|
|
5408
|
-
const maxDirLevel = 4;
|
|
5409
|
-
while (path15.dirname(currentDir) !== currentDir && dirLevel < maxDirLevel) {
|
|
5410
|
-
const filePath = path15.join(currentDir, HSPROJECT_JSON);
|
|
5411
|
-
if (checkFileExists(filePath)) {
|
|
5412
|
-
return filePath;
|
|
5413
|
-
}
|
|
5414
|
-
currentDir = path15.dirname(currentDir);
|
|
5415
|
-
dirLevel++;
|
|
5416
|
-
}
|
|
5417
|
-
console.log(
|
|
5418
|
-
`'${HSPROJECT_JSON}' not found in any parent of dev server target`
|
|
5713
|
+
function hsmetaCandidatePaths(srcPath) {
|
|
5714
|
+
const subdirs = getSubdirectories(srcPath);
|
|
5715
|
+
return subdirs.flatMap(
|
|
5716
|
+
(subdir) => HSMETA_FILENAMES.map((filename) => path17.join(srcPath, subdir, filename))
|
|
5419
5717
|
);
|
|
5420
|
-
return null;
|
|
5421
5718
|
}
|
|
5422
|
-
|
|
5423
|
-
if (projectConfigPath === null) {
|
|
5424
|
-
console.log(
|
|
5425
|
-
`Unable to find local ${HSPROJECT_JSON}, skipping platform version validation.`
|
|
5426
|
-
);
|
|
5427
|
-
return false;
|
|
5428
|
-
}
|
|
5429
|
-
const hsProjectJSONContents = fs7.readFileSync(projectConfigPath, "utf8");
|
|
5430
|
-
const hsProjectJSONData = JSON.parse(hsProjectJSONContents);
|
|
5431
|
-
const { platformVersion } = hsProjectJSONData;
|
|
5432
|
-
let platformVersionResult;
|
|
5719
|
+
function tryParseUid(hsmetaPath) {
|
|
5433
5720
|
try {
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
})
|
|
5438
|
-
|
|
5439
|
-
console.error(e.message);
|
|
5440
|
-
console.log(
|
|
5441
|
-
"Unable to find active platform versions, skipping platform version validation."
|
|
5442
|
-
);
|
|
5443
|
-
return false;
|
|
5721
|
+
const hsmeta = JSON.parse(fs9.readFileSync(hsmetaPath, "utf8"));
|
|
5722
|
+
return hsmeta.uid ?? null;
|
|
5723
|
+
} catch (parseErr) {
|
|
5724
|
+
console.warn(`Could not parse ${hsmetaPath}:`, parseErr.message);
|
|
5725
|
+
return null;
|
|
5444
5726
|
}
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
})
|
|
5455
|
-
)
|
|
5456
|
-
});
|
|
5457
|
-
hsProjectJSONData.platformVersion = answer;
|
|
5458
|
-
try {
|
|
5459
|
-
fs7.writeFileSync(
|
|
5460
|
-
projectConfigPath,
|
|
5461
|
-
JSON.stringify(hsProjectJSONData, void 0, 2),
|
|
5462
|
-
"utf8"
|
|
5463
|
-
);
|
|
5464
|
-
return true;
|
|
5465
|
-
} catch (e) {
|
|
5466
|
-
console.error(
|
|
5467
|
-
`unable to write updated valid platform version, please make sure platformVersion in "${HSPROJECT_JSON}" is one of ${platformVersionResult.activePlatformVersions}`
|
|
5468
|
-
);
|
|
5469
|
-
return false;
|
|
5470
|
-
}
|
|
5471
|
-
};
|
|
5472
|
-
if (deferSelection) {
|
|
5473
|
-
deferSelection(promptAndWrite);
|
|
5474
|
-
return false;
|
|
5475
|
-
}
|
|
5476
|
-
return promptAndWrite();
|
|
5727
|
+
}
|
|
5728
|
+
function findHsmetaUid(projectDir, srcDir) {
|
|
5729
|
+
const srcPath = path17.join(projectDir, srcDir);
|
|
5730
|
+
for (const candidatePath of hsmetaCandidatePaths(srcPath)) {
|
|
5731
|
+
if (!fs9.existsSync(candidatePath))
|
|
5732
|
+
continue;
|
|
5733
|
+
const uid = tryParseUid(candidatePath);
|
|
5734
|
+
if (uid)
|
|
5735
|
+
return uid;
|
|
5477
5736
|
}
|
|
5478
|
-
return
|
|
5737
|
+
return null;
|
|
5479
5738
|
}
|
|
5480
5739
|
|
|
5481
|
-
// src/
|
|
5482
|
-
import
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
choice: "ChoiceFieldType",
|
|
5495
|
-
color: "ColorFieldType",
|
|
5496
|
-
crmobject: "CrmObjectFieldType",
|
|
5497
|
-
cta: "CtaFieldType",
|
|
5498
|
-
date: "DateFieldType",
|
|
5499
|
-
datetime: "DateTimeFieldType",
|
|
5500
|
-
email: "EmailFieldType",
|
|
5501
|
-
embed: "EmbedFieldType",
|
|
5502
|
-
file: "FileFieldType",
|
|
5503
|
-
followupemail: "FollowUpEmailFieldType",
|
|
5504
|
-
font: "FontFieldType",
|
|
5505
|
-
form: "FormFieldType",
|
|
5506
|
-
gradient: "GradientFieldType",
|
|
5507
|
-
group: "GroupFieldType",
|
|
5508
|
-
html: "HtmlFieldType",
|
|
5509
|
-
hubdbrow: "HubDbRowFieldType",
|
|
5510
|
-
hubdbtable: "HubDbTableFieldType",
|
|
5511
|
-
hubl: "HublFieldType",
|
|
5512
|
-
icon: "IconFieldType",
|
|
5513
|
-
image: "ImageFieldType",
|
|
5514
|
-
link: "LinkFieldType",
|
|
5515
|
-
logo: "LogoFieldType",
|
|
5516
|
-
meeting: "MeetingFieldType",
|
|
5517
|
-
menu: "MenuFieldType",
|
|
5518
|
-
number: "NumberFieldType",
|
|
5519
|
-
page: "PageFieldType",
|
|
5520
|
-
payment: "PaymentFieldType",
|
|
5521
|
-
podcast: "PodcastFieldType",
|
|
5522
|
-
richtext: "RichTextFieldType",
|
|
5523
|
-
salesforcecampaign: "SfdcCamapaignFieldType",
|
|
5524
|
-
simplemenu: "SimpleMenuFieldType",
|
|
5525
|
-
spacing: "SpacingFieldType",
|
|
5526
|
-
survey: "SurveyFieldType",
|
|
5527
|
-
tag: "TagFieldType",
|
|
5528
|
-
textalignment: "TextAlignmentFieldType",
|
|
5529
|
-
text: "TextFieldType",
|
|
5530
|
-
url: "UrlFieldType",
|
|
5531
|
-
variantselection: "VariantSelectionFieldType",
|
|
5532
|
-
videoplayer: "VideoFieldType",
|
|
5533
|
-
workflow: "WorkflowFieldType"
|
|
5740
|
+
// src/lib/cliUtils.ts
|
|
5741
|
+
import process2 from "process";
|
|
5742
|
+
import os from "os";
|
|
5743
|
+
import tty from "tty";
|
|
5744
|
+
var COMPONENT_TYPES = Object.freeze({
|
|
5745
|
+
privateApp: "private-app",
|
|
5746
|
+
publicApp: "public-app",
|
|
5747
|
+
hublTheme: "hubl-theme"
|
|
5748
|
+
});
|
|
5749
|
+
var CONFIG_FILES = {
|
|
5750
|
+
[COMPONENT_TYPES.privateApp]: "app.json",
|
|
5751
|
+
[COMPONENT_TYPES.publicApp]: "public-app.json",
|
|
5752
|
+
[COMPONENT_TYPES.hublTheme]: "theme.json"
|
|
5534
5753
|
};
|
|
5535
|
-
function
|
|
5536
|
-
|
|
5537
|
-
|
|
5754
|
+
function hasNewDirectoryStructure(platformVersion) {
|
|
5755
|
+
return parseFloat(platformVersion) >= 2025.2;
|
|
5756
|
+
}
|
|
5757
|
+
var { env } = process2;
|
|
5758
|
+
function translateLevel(level) {
|
|
5759
|
+
if (level === 0) {
|
|
5760
|
+
return {
|
|
5761
|
+
level,
|
|
5762
|
+
hasBasic: false,
|
|
5763
|
+
has256: false,
|
|
5764
|
+
has16m: false
|
|
5765
|
+
};
|
|
5538
5766
|
}
|
|
5539
|
-
return
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5767
|
+
return {
|
|
5768
|
+
level,
|
|
5769
|
+
hasBasic: true,
|
|
5770
|
+
has256: level >= 2,
|
|
5771
|
+
has16m: level >= 3
|
|
5772
|
+
};
|
|
5773
|
+
}
|
|
5774
|
+
function _supportsColor(haveStream, { streamIsTTY } = {}) {
|
|
5775
|
+
if (haveStream && !streamIsTTY) {
|
|
5776
|
+
return 0;
|
|
5777
|
+
}
|
|
5778
|
+
const min = 0;
|
|
5779
|
+
if (env.TERM === "dumb") {
|
|
5780
|
+
return min;
|
|
5781
|
+
}
|
|
5782
|
+
if (hasFlag("noColor")) {
|
|
5783
|
+
return 0;
|
|
5784
|
+
}
|
|
5785
|
+
if (process2.platform === "win32") {
|
|
5786
|
+
const osRelease = os.release().split(".");
|
|
5787
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
5788
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
5544
5789
|
}
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
return { ...entry, children };
|
|
5790
|
+
return 1;
|
|
5791
|
+
}
|
|
5792
|
+
if ("CI" in env) {
|
|
5793
|
+
if ([
|
|
5794
|
+
"TRAVIS",
|
|
5795
|
+
"CIRCLECI",
|
|
5796
|
+
"APPVEYOR",
|
|
5797
|
+
"GITLAB_CI",
|
|
5798
|
+
"GITHUB_ACTIONS",
|
|
5799
|
+
"BUILDKITE",
|
|
5800
|
+
"DRONE"
|
|
5801
|
+
].some((sign) => sign in env) || env.CI_NAME === "codeship") {
|
|
5802
|
+
return 1;
|
|
5559
5803
|
}
|
|
5560
|
-
return
|
|
5561
|
-
}).filter((entry) => entry !== void 0);
|
|
5562
|
-
}
|
|
5563
|
-
var INVALID_IMPORTS = ["ChoiceFieldType", "GroupFieldType"];
|
|
5564
|
-
var FIELD_GROUP_TYPE = "FieldGroupWithChildren";
|
|
5565
|
-
var REPEATER_GROUP_TYPE = "RepeaterGroup";
|
|
5566
|
-
var REQUIRED_TYPE = "RequiredField";
|
|
5567
|
-
var DEFAULT_VALUES_TYPE = "DefaultValues";
|
|
5568
|
-
var CMS_COMPONENTS = "@hubspot/cms-components";
|
|
5569
|
-
var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
5570
|
-
var AUTO_GEN_COMMENT = "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.";
|
|
5571
|
-
var createPropertySignature = (identifier, type, hasQuestionToken = false) => ts.factory.createPropertySignature(
|
|
5572
|
-
[],
|
|
5573
|
-
identifier,
|
|
5574
|
-
hasQuestionToken ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) : void 0,
|
|
5575
|
-
type
|
|
5576
|
-
);
|
|
5577
|
-
var createUnionTypeFromArray = (values) => ts.factory.createUnionTypeNode(
|
|
5578
|
-
values.map(
|
|
5579
|
-
(value) => ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(value))
|
|
5580
|
-
)
|
|
5581
|
-
);
|
|
5582
|
-
var buildTypeFromField = (field, additionalNode) => {
|
|
5583
|
-
const imports = [field.type];
|
|
5584
|
-
const identifier = ts.factory.createIdentifier(field.name);
|
|
5585
|
-
const baseType = ts.factory.createTypeReferenceNode(field.type);
|
|
5586
|
-
const requiredType = ts.factory.createTypeReferenceNode(REQUIRED_TYPE, [
|
|
5587
|
-
baseType
|
|
5588
|
-
]);
|
|
5589
|
-
let finalType = field.isRequired ? requiredType : baseType;
|
|
5590
|
-
if (field.choices) {
|
|
5591
|
-
finalType = createUnionTypeFromArray(field.choices);
|
|
5804
|
+
return min;
|
|
5592
5805
|
}
|
|
5593
|
-
if (
|
|
5594
|
-
|
|
5806
|
+
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
|
|
5807
|
+
return 1;
|
|
5595
5808
|
}
|
|
5596
|
-
if (
|
|
5597
|
-
|
|
5598
|
-
const genericType = field.isRepeater ? REPEATER_GROUP_TYPE : FIELD_GROUP_TYPE;
|
|
5599
|
-
imports.push(genericType);
|
|
5600
|
-
finalType = ts.factory.createTypeReferenceNode(genericType, [typeLiteral]);
|
|
5809
|
+
if (env.COLORTERM === "truecolor") {
|
|
5810
|
+
return 3;
|
|
5601
5811
|
}
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
)
|
|
5608
|
-
|
|
5609
|
-
|
|
5812
|
+
if ("TERM_PROGRAM" in env) {
|
|
5813
|
+
const version = Number.parseInt(
|
|
5814
|
+
(env.TERM_PROGRAM_VERSION || "").split(".")[0],
|
|
5815
|
+
10
|
|
5816
|
+
);
|
|
5817
|
+
switch (env.TERM_PROGRAM) {
|
|
5818
|
+
case "iTerm.app":
|
|
5819
|
+
return version >= 3 ? 3 : 2;
|
|
5820
|
+
case "Apple_Terminal":
|
|
5821
|
+
return 2;
|
|
5822
|
+
}
|
|
5823
|
+
}
|
|
5824
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
5825
|
+
return 2;
|
|
5826
|
+
}
|
|
5827
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
5828
|
+
return 1;
|
|
5829
|
+
}
|
|
5830
|
+
if ("COLORTERM" in env) {
|
|
5831
|
+
return 1;
|
|
5832
|
+
}
|
|
5833
|
+
return min;
|
|
5834
|
+
}
|
|
5835
|
+
function createSupportsColor(stream2, options = {}) {
|
|
5836
|
+
const level = _supportsColor(stream2, {
|
|
5837
|
+
streamIsTTY: stream2 && stream2.isTTY,
|
|
5838
|
+
...options
|
|
5839
|
+
});
|
|
5840
|
+
return translateLevel(level);
|
|
5841
|
+
}
|
|
5842
|
+
var supportsColor = {
|
|
5843
|
+
createSupportsColor,
|
|
5844
|
+
stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
|
|
5845
|
+
stderr: createSupportsColor({ isTTY: tty.isatty(2) })
|
|
5610
5846
|
};
|
|
5611
|
-
|
|
5612
|
-
const
|
|
5613
|
-
const
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5847
|
+
function hasFlag(flag, argv = process2.argv) {
|
|
5848
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
5849
|
+
const position = argv.indexOf(prefix + flag);
|
|
5850
|
+
const terminatorPosition = argv.indexOf("--");
|
|
5851
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
5852
|
+
}
|
|
5853
|
+
|
|
5854
|
+
// src/createDevServer.ts
|
|
5855
|
+
import {
|
|
5856
|
+
getConfigAccountIfExists as getConfigAccountIfExists7,
|
|
5857
|
+
getConfigDefaultAccountIfExists,
|
|
5858
|
+
validateConfig
|
|
5859
|
+
} from "@hubspot/local-dev-lib/config";
|
|
5860
|
+
import { fetchSecrets } from "@hubspot/local-dev-lib/api/secrets";
|
|
5861
|
+
import { PERSONAL_ACCESS_KEY_AUTH_METHOD } from "@hubspot/local-dev-lib/constants/auth";
|
|
5862
|
+
|
|
5863
|
+
// src/proxyPage/fetchDomains.ts
|
|
5864
|
+
import { http as hsCliHttp11 } from "@hubspot/local-dev-lib/http";
|
|
5865
|
+
|
|
5866
|
+
// src/lib/errors.ts
|
|
5867
|
+
var MISSING_SCOPE_ERROR_PREFIX = `Your personal access key is missing required scopes fetch domains.
|
|
5868
|
+
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
|
|
5869
|
+
`;
|
|
5870
|
+
var OAUTH_ERROR_REGEX = /^This oauth-token \([\w]+\) does not have proper permissions!/;
|
|
5871
|
+
var NOT_PUBLIC_USE_ERROR = `The scope needed for this API call isn't available for public use`;
|
|
5872
|
+
var MissingScopeError = class extends Error {
|
|
5873
|
+
constructor(error) {
|
|
5874
|
+
let messageEnd = "";
|
|
5875
|
+
if (error.error.message.match(OAUTH_ERROR_REGEX)) {
|
|
5876
|
+
messageEnd = error.error.message;
|
|
5619
5877
|
}
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5878
|
+
super(`${MISSING_SCOPE_ERROR_PREFIX}
|
|
5879
|
+
${messageEnd}`);
|
|
5880
|
+
Object.setPrototypeOf(this, MissingScopeError.prototype);
|
|
5881
|
+
}
|
|
5624
5882
|
};
|
|
5625
|
-
function
|
|
5626
|
-
|
|
5627
|
-
(importName) => ts.factory.createImportSpecifier(
|
|
5628
|
-
true,
|
|
5629
|
-
void 0,
|
|
5630
|
-
ts.factory.createIdentifier(importName)
|
|
5631
|
-
)
|
|
5632
|
-
);
|
|
5633
|
-
const namedImports = ts.factory.createNamedImports(importSpecifiers);
|
|
5634
|
-
return ts.factory.createImportDeclaration(
|
|
5635
|
-
[],
|
|
5636
|
-
[],
|
|
5637
|
-
ts.factory.createImportClause(false, void 0, namedImports),
|
|
5638
|
-
ts.factory.createStringLiteral(moduleSpecifier)
|
|
5639
|
-
);
|
|
5883
|
+
function logMissingScopeWarning(error) {
|
|
5884
|
+
console.warn(error.message);
|
|
5640
5885
|
}
|
|
5641
|
-
function
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5886
|
+
function isMissingScopeError(error) {
|
|
5887
|
+
return error.statusCode === 403 && (error.error.message.match(OAUTH_ERROR_REGEX) || error.error.message.startsWith(NOT_PUBLIC_USE_ERROR));
|
|
5888
|
+
}
|
|
5889
|
+
function handleSecretsError(error) {
|
|
5890
|
+
if (error && error.statusCode && error.error) {
|
|
5891
|
+
const { statusCode, error: errorDetails } = error;
|
|
5892
|
+
if ((errorDetails == null ? void 0 : errorDetails.category) === "MISSING_SCOPES") {
|
|
5893
|
+
console.log(
|
|
5894
|
+
"\nMissing scopes for secrets.",
|
|
5895
|
+
"\nSecrets require Serverless functions which are scoped to Enterprise portals.\n"
|
|
5896
|
+
);
|
|
5897
|
+
} else {
|
|
5898
|
+
console.error(`Error ${statusCode}: ${errorDetails.message}`);
|
|
5899
|
+
if (errorDetails.correlationId) {
|
|
5900
|
+
console.error(`Correlation ID: ${errorDetails.correlationId}`);
|
|
5901
|
+
}
|
|
5902
|
+
if (errorDetails.category) {
|
|
5903
|
+
console.error(`Category: ${errorDetails.category}`);
|
|
5904
|
+
}
|
|
5905
|
+
if (errorDetails.links) {
|
|
5906
|
+
if (errorDetails.links.support) {
|
|
5907
|
+
console.error(`Support URL: ${errorDetails.links.support}`);
|
|
5908
|
+
}
|
|
5909
|
+
if (errorDetails.links.forum) {
|
|
5910
|
+
console.error(`Forum URL: ${errorDetails.links.forum}`);
|
|
5911
|
+
}
|
|
5655
5912
|
}
|
|
5656
5913
|
}
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5914
|
+
} else {
|
|
5915
|
+
console.error("Unexpected error structure:", error);
|
|
5916
|
+
}
|
|
5917
|
+
}
|
|
5918
|
+
|
|
5919
|
+
// src/proxyPage/fetchDomains.ts
|
|
5920
|
+
async function fetchDomains(portalId) {
|
|
5921
|
+
try {
|
|
5922
|
+
const result = (await hsCliHttp11.get(portalId, {
|
|
5923
|
+
url: `/cms/v3/domains`,
|
|
5924
|
+
params: { portalId },
|
|
5925
|
+
responseType: "json"
|
|
5926
|
+
})).data;
|
|
5927
|
+
return result.results;
|
|
5928
|
+
} catch (error) {
|
|
5929
|
+
if (isMissingScopeError(error)) {
|
|
5930
|
+
throw new MissingScopeError(error);
|
|
5931
|
+
}
|
|
5932
|
+
throw error;
|
|
5933
|
+
}
|
|
5934
|
+
}
|
|
5935
|
+
async function fetchWebsiteDomainNames(portalId) {
|
|
5936
|
+
const domains = await fetchDomains(portalId);
|
|
5937
|
+
const filteredDomains = domains.filter((domain) => {
|
|
5938
|
+
return domain.isUsedForBlogPost || domain.isUsedForSitePage || domain.isUsedForLandingPage;
|
|
5660
5939
|
});
|
|
5661
|
-
const
|
|
5662
|
-
|
|
5663
|
-
);
|
|
5664
|
-
return { types, imports: validImports };
|
|
5940
|
+
const domainNames = filteredDomains.map((r) => r.domain);
|
|
5941
|
+
return domainNames;
|
|
5665
5942
|
}
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
);
|
|
5675
|
-
const wrappedType = ts.factory.createTypeReferenceNode(DEFAULT_VALUES_TYPE, [
|
|
5676
|
-
baseType.type
|
|
5677
|
-
]);
|
|
5678
|
-
const finalType = ts.factory.createTypeAliasDeclaration(
|
|
5679
|
-
[],
|
|
5680
|
-
[],
|
|
5681
|
-
typeName,
|
|
5682
|
-
void 0,
|
|
5683
|
-
wrappedType
|
|
5684
|
-
);
|
|
5685
|
-
const filteredImports = filterUnusedImports(imports, finalType);
|
|
5686
|
-
const importDeclaration = getImportDeclaration(
|
|
5687
|
-
[...filteredImports, DEFAULT_VALUES_TYPE],
|
|
5688
|
-
CMS_COMPONENTS_FIELD_TYPES
|
|
5689
|
-
);
|
|
5690
|
-
const defaultExport = ts.factory.createExportDefault(
|
|
5691
|
-
ts.factory.createIdentifier(typeName)
|
|
5692
|
-
);
|
|
5693
|
-
return [importDeclaration, finalType, defaultExport];
|
|
5943
|
+
|
|
5944
|
+
// src/lib/validateHSPlatform.ts
|
|
5945
|
+
import path18 from "path";
|
|
5946
|
+
import fs10 from "fs";
|
|
5947
|
+
import { http as hsCliHttp12 } from "@hubspot/local-dev-lib/http";
|
|
5948
|
+
var HSPROJECT_JSON = "hsproject.json";
|
|
5949
|
+
function checkFileExists(filePath) {
|
|
5950
|
+
return fs10.existsSync(filePath) && fs10.statSync(filePath).isFile();
|
|
5694
5951
|
}
|
|
5695
|
-
function
|
|
5696
|
-
|
|
5697
|
-
|
|
5698
|
-
|
|
5952
|
+
function findHSProjectJson(startPath) {
|
|
5953
|
+
let currentDir = startPath;
|
|
5954
|
+
let dirLevel = 0;
|
|
5955
|
+
const maxDirLevel = 4;
|
|
5956
|
+
while (path18.dirname(currentDir) !== currentDir && dirLevel < maxDirLevel) {
|
|
5957
|
+
const filePath = path18.join(currentDir, HSPROJECT_JSON);
|
|
5958
|
+
if (checkFileExists(filePath)) {
|
|
5959
|
+
return filePath;
|
|
5960
|
+
}
|
|
5961
|
+
currentDir = path18.dirname(currentDir);
|
|
5962
|
+
dirLevel++;
|
|
5699
5963
|
}
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
const nodes = constructFinalType(entries, typeName);
|
|
5710
|
-
const comments = [
|
|
5711
|
-
AUTO_GEN_COMMENT,
|
|
5712
|
-
"Removing the above comment will disable type generation for this module",
|
|
5713
|
-
"This file was created by @hubspot/cms-dev-server, for more information see https://github.hubspot.com/cms-react/reference/js-modules.html#module-fields"
|
|
5714
|
-
].map((comment) => `// ${comment}`);
|
|
5715
|
-
const typeResult = nodes.map(
|
|
5716
|
-
(node) => printer.printNode(ts.EmitHint.Unspecified, node, file)
|
|
5964
|
+
console.log(
|
|
5965
|
+
`'${HSPROJECT_JSON}' not found in any parent of dev server target`
|
|
5966
|
+
);
|
|
5967
|
+
return null;
|
|
5968
|
+
}
|
|
5969
|
+
async function validateHSPlatform(projectConfigPath, portalId, deferSelection) {
|
|
5970
|
+
if (projectConfigPath === null) {
|
|
5971
|
+
console.log(
|
|
5972
|
+
`Unable to find local ${HSPROJECT_JSON}, skipping platform version validation.`
|
|
5717
5973
|
);
|
|
5718
|
-
const result = [...comments, ...typeResult].join("\n");
|
|
5719
|
-
writeFileSync(fileName, result);
|
|
5720
|
-
return true;
|
|
5721
|
-
} catch (e) {
|
|
5722
|
-
console.error(e);
|
|
5723
5974
|
return false;
|
|
5724
5975
|
}
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
import path16 from "path";
|
|
5730
|
-
import readline from "readline";
|
|
5731
|
-
var lastSerializedFieldsCache = {};
|
|
5732
|
-
var formatAsTypeName = (str) => {
|
|
5733
|
-
const typeName = `${str.replace(/[^a-zA-Z0-9_$]/g, "_")}FieldsType`;
|
|
5734
|
-
const validFirstChar = /^[A-Za-z_$]/.test(str.charAt(0));
|
|
5735
|
-
return validFirstChar ? typeName : `_${typeName}`;
|
|
5736
|
-
};
|
|
5737
|
-
var isInModulesFolder = (filePath, projectRoot) => {
|
|
5738
|
-
const getEntryPathFromId = (id) => {
|
|
5739
|
-
return id.startsWith(projectRoot) ? id.replace(`${projectRoot}${path16.sep}`, "") : "";
|
|
5740
|
-
};
|
|
5741
|
-
const currentModuleId = path16.normalize(filePath);
|
|
5742
|
-
const moduleEntryPath = getEntryPathFromId(currentModuleId);
|
|
5743
|
-
const subFolderTokens = moduleEntryPath.split(path16.sep);
|
|
5744
|
-
return {
|
|
5745
|
-
inModuleFolder: subFolderTokens[0] === "components" && subFolderTokens[1] === "modules",
|
|
5746
|
-
isRootModuleFile: subFolderTokens.length === 3
|
|
5747
|
-
};
|
|
5748
|
-
};
|
|
5749
|
-
var fileContainsAutoGenComment = async (filePath) => {
|
|
5750
|
-
if (!fs8.existsSync(filePath))
|
|
5751
|
-
return true;
|
|
5752
|
-
const stream2 = fs8.createReadStream(filePath);
|
|
5753
|
-
const reader = readline.createInterface({ input: stream2 });
|
|
5754
|
-
const firstLine = await new Promise(
|
|
5755
|
-
(resolve2) => reader.once("line", (line) => resolve2(line.trim()))
|
|
5756
|
-
);
|
|
5757
|
-
reader.close();
|
|
5758
|
-
stream2.close();
|
|
5759
|
-
return firstLine && firstLine === `// ${AUTO_GEN_COMMENT}`;
|
|
5760
|
-
};
|
|
5761
|
-
var getIndexFile = (filePath, projectRoot) => {
|
|
5762
|
-
const { inModuleFolder, isRootModuleFile } = isInModulesFolder(
|
|
5763
|
-
filePath,
|
|
5764
|
-
projectRoot
|
|
5765
|
-
);
|
|
5766
|
-
if (!inModuleFolder)
|
|
5767
|
-
return void 0;
|
|
5768
|
-
if (isRootModuleFile)
|
|
5769
|
-
return { indexFilePath: filePath, isRootModuleFile };
|
|
5770
|
-
const dir = path16.dirname(filePath);
|
|
5771
|
-
const files = fs8.readdirSync(dir);
|
|
5772
|
-
const indexFileName = files.find((file) => file.startsWith("index."));
|
|
5773
|
-
return indexFileName ? { indexFilePath: path16.join(dir, indexFileName), isRootModuleFile } : void 0;
|
|
5774
|
-
};
|
|
5775
|
-
var getIndexFileFields = async (indexFilePath, indexFileName, viteServer) => {
|
|
5776
|
-
let indexFile;
|
|
5777
|
-
let renderFieldsToJson;
|
|
5976
|
+
const hsProjectJSONContents = fs10.readFileSync(projectConfigPath, "utf8");
|
|
5977
|
+
const hsProjectJSONData = JSON.parse(hsProjectJSONContents);
|
|
5978
|
+
const { platformVersion } = hsProjectJSONData;
|
|
5979
|
+
let platformVersionResult;
|
|
5778
5980
|
try {
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5981
|
+
platformVersionResult = (await hsCliHttp12.get(portalId, {
|
|
5982
|
+
url: `developer/projects/v1/platformVersion`,
|
|
5983
|
+
responseType: "json"
|
|
5984
|
+
})).data;
|
|
5782
5985
|
} catch (e) {
|
|
5783
|
-
|
|
5986
|
+
console.error(e.message);
|
|
5987
|
+
console.log(
|
|
5988
|
+
"Unable to find active platform versions, skipping platform version validation."
|
|
5989
|
+
);
|
|
5990
|
+
return false;
|
|
5784
5991
|
}
|
|
5785
|
-
if (!
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
|
|
5815
|
-
return;
|
|
5816
|
-
const moduleFolderName = path16.basename(path16.dirname(filePath));
|
|
5817
|
-
const outputTypeName = formatAsTypeName(moduleFolderName);
|
|
5818
|
-
const didSucceed = writeFieldsType(fields, typeFilePath, outputTypeName);
|
|
5819
|
-
if (didSucceed) {
|
|
5820
|
-
lastSerializedFieldsCache[typeFilePath] = serializedFields;
|
|
5992
|
+
if (platformVersion === void 0 || !platformVersionResult.activePlatformVersions.includes(platformVersion)) {
|
|
5993
|
+
const promptAndWrite = async () => {
|
|
5994
|
+
const { default: select } = await import("@inquirer/select");
|
|
5995
|
+
const answer = await select({
|
|
5996
|
+
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',
|
|
5997
|
+
choices: platformVersionResult.activePlatformVersions.map(
|
|
5998
|
+
(versionNumber) => ({
|
|
5999
|
+
name: versionNumber,
|
|
6000
|
+
value: versionNumber
|
|
6001
|
+
})
|
|
6002
|
+
)
|
|
6003
|
+
});
|
|
6004
|
+
hsProjectJSONData.platformVersion = answer;
|
|
6005
|
+
try {
|
|
6006
|
+
fs10.writeFileSync(
|
|
6007
|
+
projectConfigPath,
|
|
6008
|
+
JSON.stringify(hsProjectJSONData, void 0, 2),
|
|
6009
|
+
"utf8"
|
|
6010
|
+
);
|
|
6011
|
+
return true;
|
|
6012
|
+
} catch (e) {
|
|
6013
|
+
console.error(
|
|
6014
|
+
`unable to write updated valid platform version, please make sure platformVersion in "${HSPROJECT_JSON}" is one of ${platformVersionResult.activePlatformVersions}`
|
|
6015
|
+
);
|
|
6016
|
+
return false;
|
|
6017
|
+
}
|
|
6018
|
+
};
|
|
6019
|
+
if (deferSelection) {
|
|
6020
|
+
deferSelection(promptAndWrite);
|
|
6021
|
+
return false;
|
|
5821
6022
|
}
|
|
5822
|
-
|
|
5823
|
-
const successMsg = `Successfully generated types for ${pathToLog}`;
|
|
5824
|
-
const errorMsg = `Failed to generate types for ${pathToLog}`;
|
|
5825
|
-
const message = didSucceed ? successMsg : errorMsg;
|
|
5826
|
-
console.log(wrapMessageInColor(didSucceed ? "green" : "red", message));
|
|
6023
|
+
return promptAndWrite();
|
|
5827
6024
|
}
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
|
|
5831
|
-
|
|
5832
|
-
|
|
5833
|
-
maybeUpdateFields(resolvedPath, viteServer, projectRoot);
|
|
5834
|
-
});
|
|
5835
|
-
const watchCallback = (filePath) => maybeUpdateFields(filePath, viteServer, projectRoot);
|
|
5836
|
-
viteServer.watcher.on("add", watchCallback).on("change", watchCallback);
|
|
5837
|
-
};
|
|
6025
|
+
return true;
|
|
6026
|
+
}
|
|
6027
|
+
|
|
6028
|
+
// src/createDevServer.ts
|
|
6029
|
+
import { http as hsCliHttp13 } from "@hubspot/local-dev-lib/http";
|
|
5838
6030
|
|
|
5839
6031
|
// src/lib/configHelpers.ts
|
|
5840
6032
|
function getSecretNamesFromConfig(config) {
|
|
@@ -5861,8 +6053,8 @@ function getWebRootProjectComponentFolder(absoluteWebRoot, projectConfigPath) {
|
|
|
5861
6053
|
return themeFolderName;
|
|
5862
6054
|
}
|
|
5863
6055
|
try {
|
|
5864
|
-
const projectDir =
|
|
5865
|
-
const configContent =
|
|
6056
|
+
const projectDir = path19.dirname(projectConfigPath);
|
|
6057
|
+
const configContent = fs11.readFileSync(projectConfigPath, "utf8");
|
|
5866
6058
|
const projectConfig = JSON.parse(configContent);
|
|
5867
6059
|
if (hasNewDirectoryStructure(projectConfig.platformVersion)) {
|
|
5868
6060
|
const srcDir = projectConfig.srcDir || "src";
|
|
@@ -5932,7 +6124,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
5932
6124
|
}
|
|
5933
6125
|
setTrackingInfo(authedPortalId, authedEnv);
|
|
5934
6126
|
sendTrackingRequest("start-dev-server");
|
|
5935
|
-
const absoluteWebRoot = normalizePath10(
|
|
6127
|
+
const absoluteWebRoot = normalizePath10(path19.resolve(process.cwd(), webRoot));
|
|
5936
6128
|
const projectConfigPath = findHSProjectJson(absoluteWebRoot);
|
|
5937
6129
|
const webRootProjectComponentFolder = getWebRootProjectComponentFolder(
|
|
5938
6130
|
absoluteWebRoot,
|
|
@@ -6004,7 +6196,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
6004
6196
|
});
|
|
6005
6197
|
bootTasks.push(async () => {
|
|
6006
6198
|
try {
|
|
6007
|
-
const accountInformation = (await
|
|
6199
|
+
const accountInformation = (await hsCliHttp13.get(portalId, {
|
|
6008
6200
|
url: "/account-info/v3/details"
|
|
6009
6201
|
})).data;
|
|
6010
6202
|
authedHublet = accountInformation.dataHostingLocation;
|
|
@@ -6046,7 +6238,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
6046
6238
|
secretNames
|
|
6047
6239
|
);
|
|
6048
6240
|
if (fieldGenEnabledOption) {
|
|
6049
|
-
const normalizedAbsoluteWebRoot =
|
|
6241
|
+
const normalizedAbsoluteWebRoot = path19.normalize(absoluteWebRoot);
|
|
6050
6242
|
startFieldsTypeGenWatcher(viteServer, normalizedAbsoluteWebRoot);
|
|
6051
6243
|
}
|
|
6052
6244
|
const viteHTTPSConfig = viteServer.config.server.https;
|
|
@@ -6072,10 +6264,10 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
6072
6264
|
expressServer.locals.sslEnabled = sslEnabledOption;
|
|
6073
6265
|
expressServer.locals.fullHeightPreview = fullHeightPreview;
|
|
6074
6266
|
expressServer.use(bodyParser.json());
|
|
6075
|
-
const __dirname =
|
|
6076
|
-
let appWebRoot = normalizePath10(
|
|
6267
|
+
const __dirname = path19.dirname(url2.fileURLToPath(new URL(import.meta.url)));
|
|
6268
|
+
let appWebRoot = normalizePath10(path19.resolve(__dirname, "../app"));
|
|
6077
6269
|
if (true) {
|
|
6078
|
-
appWebRoot =
|
|
6270
|
+
appWebRoot = path19.join(__dirname, "app");
|
|
6079
6271
|
}
|
|
6080
6272
|
const skipUiServer = isLocalUiDisabled(cmsAssetConfig);
|
|
6081
6273
|
const appViteServer = skipUiServer ? null : await createAppServer_default(appWebRoot, PORT, sslEnabledOption);
|
|
@@ -6143,17 +6335,17 @@ HubSpot CMS dev server running at ${protocol}://hslocal.net:${PORT}${extraServer
|
|
|
6143
6335
|
`;
|
|
6144
6336
|
console.log(startMessage);
|
|
6145
6337
|
if (storybook) {
|
|
6146
|
-
const packageRoot =
|
|
6147
|
-
const configPath =
|
|
6338
|
+
const packageRoot = path19.dirname(url2.fileURLToPath(import.meta.url));
|
|
6339
|
+
const configPath = path19.resolve(packageRoot, "./storybook-main");
|
|
6148
6340
|
sendTrackingRequest("start-storybook");
|
|
6149
6341
|
let storybookBin;
|
|
6150
6342
|
try {
|
|
6151
6343
|
const sbPackagePath = await import.meta.resolve("storybook/package.json");
|
|
6152
|
-
const sbPackageDir =
|
|
6344
|
+
const sbPackageDir = path19.dirname(url2.fileURLToPath(sbPackagePath));
|
|
6153
6345
|
const packageJson = JSON.parse(
|
|
6154
|
-
|
|
6346
|
+
fs11.readFileSync(path19.join(sbPackageDir, "package.json"), "utf-8")
|
|
6155
6347
|
);
|
|
6156
|
-
storybookBin =
|
|
6348
|
+
storybookBin = path19.join(
|
|
6157
6349
|
sbPackageDir,
|
|
6158
6350
|
packageJson.bin.storybook || packageJson.bin
|
|
6159
6351
|
);
|
|
@@ -6190,7 +6382,7 @@ HubSpot CMS dev server running at ${protocol}://hslocal.net:${PORT}${extraServer
|
|
|
6190
6382
|
portalId: authedPortalId.toString(),
|
|
6191
6383
|
hsEnv: authedEnv,
|
|
6192
6384
|
hublet: authedHublet,
|
|
6193
|
-
WEB_ROOT:
|
|
6385
|
+
WEB_ROOT: path19.join(webRoot, "components")
|
|
6194
6386
|
},
|
|
6195
6387
|
stdio: "inherit"
|
|
6196
6388
|
}
|