@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/run.js
CHANGED
|
@@ -842,8 +842,8 @@ async function buildThemePreviewOptions(webRoot2, isUsingLocalWorkspace = false)
|
|
|
842
842
|
}
|
|
843
843
|
|
|
844
844
|
// src/createDevServer.ts
|
|
845
|
-
import
|
|
846
|
-
import
|
|
845
|
+
import path20 from "path";
|
|
846
|
+
import fs12 from "fs";
|
|
847
847
|
import url2 from "url";
|
|
848
848
|
import express2 from "express";
|
|
849
849
|
import http3 from "http";
|
|
@@ -896,7 +896,7 @@ function packagePath(metaUrl, projectPath) {
|
|
|
896
896
|
);
|
|
897
897
|
}
|
|
898
898
|
|
|
899
|
-
// ../cms-js-internal/dist/types-
|
|
899
|
+
// ../cms-js-internal/dist/types-C8bPIEz4.js
|
|
900
900
|
import path4 from "path";
|
|
901
901
|
import { createHash } from "crypto";
|
|
902
902
|
import fs3, { readFileSync, existsSync as existsSync2, readdirSync, lstatSync } from "fs";
|
|
@@ -1155,12 +1155,8 @@ function isLocalUiDisabled(config) {
|
|
|
1155
1155
|
return false;
|
|
1156
1156
|
}
|
|
1157
1157
|
var ENABLED_FEATURES_GATE_MAP = {
|
|
1158
|
-
"cms:jsr:analyzeCmsModules": "CMS:JSRenderer:AnalyzeCmsModules"
|
|
1159
|
-
"PortalsAccessIdentity:DesignManager:UrlSigning": "PortalsAccessIdentity:DesignManager:UrlSigning"
|
|
1158
|
+
"cms:jsr:analyzeCmsModules": "CMS:JSRenderer:AnalyzeCmsModules"
|
|
1160
1159
|
};
|
|
1161
|
-
function isUngatedFor(gates, gate) {
|
|
1162
|
-
return gates.includes(gate);
|
|
1163
|
-
}
|
|
1164
1160
|
var findAllComponentsIn = (webRoot2, componentsFolder) => {
|
|
1165
1161
|
const fullComponentsFolderPath = join2(webRoot2, componentsFolder);
|
|
1166
1162
|
const componentsByName = {};
|
|
@@ -1579,8 +1575,8 @@ function convertEntryPointIslandPathsToRelative(config, entryPointsCmsModuleMap)
|
|
|
1579
1575
|
);
|
|
1580
1576
|
return Object.fromEntries(relativeEntries);
|
|
1581
1577
|
}
|
|
1582
|
-
function toRelativePath(config,
|
|
1583
|
-
return
|
|
1578
|
+
function toRelativePath(config, path21) {
|
|
1579
|
+
return path21.replace(`${config.root}/`, "");
|
|
1584
1580
|
}
|
|
1585
1581
|
function shouldAnalyzeModule(config, moduleInfo, code) {
|
|
1586
1582
|
const [fileId, __] = moduleInfo.id.split("?");
|
|
@@ -1623,11 +1619,11 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
|
|
|
1623
1619
|
let moduleComponentLocalImportName = CMS_MODULE_COMPONENT_NAME;
|
|
1624
1620
|
let dndAreaComponentLocalImportName = DND_AREA_COMPONENT_NAME;
|
|
1625
1621
|
traverse(sourceAst, {
|
|
1626
|
-
ImportDeclaration(
|
|
1627
|
-
if (t.isStringLiteral(
|
|
1622
|
+
ImportDeclaration(path21) {
|
|
1623
|
+
if (t.isStringLiteral(path21.node.source, {
|
|
1628
1624
|
value: "@hubspot/cms-components"
|
|
1629
1625
|
})) {
|
|
1630
|
-
for (const specifier of
|
|
1626
|
+
for (const specifier of path21.node.specifiers) {
|
|
1631
1627
|
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, {
|
|
1632
1628
|
name: CMS_MODULE_COMPONENT_NAME
|
|
1633
1629
|
})) {
|
|
@@ -1641,14 +1637,14 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
|
|
|
1641
1637
|
}
|
|
1642
1638
|
}
|
|
1643
1639
|
},
|
|
1644
|
-
JSXOpeningElement(
|
|
1645
|
-
if (t.isJSXIdentifier(
|
|
1640
|
+
JSXOpeningElement(path21) {
|
|
1641
|
+
if (t.isJSXIdentifier(path21.node.name, {
|
|
1646
1642
|
name: moduleComponentLocalImportName
|
|
1647
1643
|
})) {
|
|
1648
1644
|
let cmsModuleName;
|
|
1649
1645
|
let cmsModulePath;
|
|
1650
1646
|
let cmsModuleLabel;
|
|
1651
|
-
for (const prop of
|
|
1647
|
+
for (const prop of path21.node.attributes) {
|
|
1652
1648
|
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
1653
1649
|
cmsModuleName = prop.value.value;
|
|
1654
1650
|
continue;
|
|
@@ -1683,11 +1679,11 @@ function analyzeSourceCodeUsages(ctx, moduleInfo, config, code) {
|
|
|
1683
1679
|
}
|
|
1684
1680
|
contentDescriptors.modules[cmsModuleProps.name] = cmsModuleProps;
|
|
1685
1681
|
}
|
|
1686
|
-
if (t.isJSXIdentifier(
|
|
1682
|
+
if (t.isJSXIdentifier(path21.node.name, {
|
|
1687
1683
|
name: dndAreaComponentLocalImportName
|
|
1688
1684
|
})) {
|
|
1689
1685
|
let dndAreaName;
|
|
1690
|
-
for (const prop of
|
|
1686
|
+
for (const prop of path21.node.attributes) {
|
|
1691
1687
|
if (t.isJSXAttribute(prop) && t.isJSXIdentifier(prop.name, { name: "name" }) && t.isStringLiteral(prop.value)) {
|
|
1692
1688
|
dndAreaName = prop.value.value;
|
|
1693
1689
|
continue;
|
|
@@ -2262,7 +2258,7 @@ function trackUsage(action) {
|
|
|
2262
2258
|
eventName: EVENT_NAME,
|
|
2263
2259
|
action,
|
|
2264
2260
|
nodeVersion: getNodeVersionData(),
|
|
2265
|
-
version: "1.2.
|
|
2261
|
+
version: "1.2.83",
|
|
2266
2262
|
os: getPlatform()
|
|
2267
2263
|
};
|
|
2268
2264
|
const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -2336,12 +2332,12 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
2336
2332
|
);
|
|
2337
2333
|
offsetSoFar = nearestNewlineOrQuoteAfterBlockOpen;
|
|
2338
2334
|
if (pathEndOffset >= 0 && pathEndOffset < nextNewlineOffset) {
|
|
2339
|
-
const
|
|
2335
|
+
const path21 = body.substring(
|
|
2340
2336
|
startOffset + localJsRenderStartString.length,
|
|
2341
2337
|
pathEndOffset
|
|
2342
2338
|
);
|
|
2343
2339
|
offsetSoFar = pathEndOffset + 1;
|
|
2344
|
-
if (startOffset >= 0 &&
|
|
2340
|
+
if (startOffset >= 0 && path21) {
|
|
2345
2341
|
const nextCommentEndOffset = body.indexOf("-->", pathEndOffset);
|
|
2346
2342
|
const endOffset = body.indexOf(localJsRenderEndString, pathEndOffset);
|
|
2347
2343
|
offsetSoFar = Math.min(nextCommentEndOffset, endOffset);
|
|
@@ -2366,7 +2362,7 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
2366
2362
|
result.push({
|
|
2367
2363
|
startOffset,
|
|
2368
2364
|
endOffset: endOffset + localJsRenderEndString.length,
|
|
2369
|
-
path:
|
|
2365
|
+
path: path21,
|
|
2370
2366
|
json
|
|
2371
2367
|
});
|
|
2372
2368
|
}
|
|
@@ -2765,9 +2761,9 @@ var customColors = [
|
|
|
2765
2761
|
];
|
|
2766
2762
|
var Converter = new AnsiToHtmlConverter({ colors: customColors });
|
|
2767
2763
|
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;`;
|
|
2768
|
-
var renderLocalError_default = (
|
|
2764
|
+
var renderLocalError_default = (path21, error) => {
|
|
2769
2765
|
const stackWithColorClasses = Converter.toHtml(error.stack);
|
|
2770
|
-
return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${
|
|
2766
|
+
return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${path21}<br/><br/><code><pre>${stackWithColorClasses}</pre></code></div>`;
|
|
2771
2767
|
};
|
|
2772
2768
|
|
|
2773
2769
|
// src/proxyPage/fetchPreviewInfo.ts
|
|
@@ -3790,7 +3786,6 @@ function getWebDefaultStylesCss(metaUrl) {
|
|
|
3790
3786
|
}
|
|
3791
3787
|
return _webDefaultStylesCss;
|
|
3792
3788
|
}
|
|
3793
|
-
var URL_SIGNING_GATE = "PortalsAccessIdentity:DesignManager:UrlSigning";
|
|
3794
3789
|
async function signGetUrl(authedPortalId, unsignedUrl) {
|
|
3795
3790
|
const urlWithPortalId = new URL(unsignedUrl);
|
|
3796
3791
|
urlWithPortalId.searchParams.set("portalId", `${authedPortalId}`);
|
|
@@ -3807,14 +3802,7 @@ async function signGetUrl(authedPortalId, unsignedUrl) {
|
|
|
3807
3802
|
});
|
|
3808
3803
|
return response.data.signedUrl;
|
|
3809
3804
|
}
|
|
3810
|
-
async function signedGet(authedPortalId, unsignedUrl, headers
|
|
3811
|
-
if (!isUngatedFor(gates, URL_SIGNING_GATE)) {
|
|
3812
|
-
const { data } = await hsCliHttp7.get(authedPortalId, {
|
|
3813
|
-
url: unsignedUrl,
|
|
3814
|
-
headers
|
|
3815
|
-
});
|
|
3816
|
-
return data;
|
|
3817
|
-
}
|
|
3805
|
+
async function signedGet(authedPortalId, unsignedUrl, headers) {
|
|
3818
3806
|
const signedUrl = await signGetUrl(authedPortalId, unsignedUrl);
|
|
3819
3807
|
const accountConfig = getConfigAccountIfExists5(authedPortalId);
|
|
3820
3808
|
const authHeaders = {};
|
|
@@ -3841,7 +3829,7 @@ async function signedGet(authedPortalId, unsignedUrl, headers, gates) {
|
|
|
3841
3829
|
}
|
|
3842
3830
|
return await response.text();
|
|
3843
3831
|
}
|
|
3844
|
-
async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv, cookieValue
|
|
3832
|
+
async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv, cookieValue) {
|
|
3845
3833
|
const moduleInfoQueryParams = new URLSearchParams({
|
|
3846
3834
|
portalId: `${authedPortalId}`
|
|
3847
3835
|
});
|
|
@@ -3865,34 +3853,13 @@ async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv,
|
|
|
3865
3853
|
buffer_theme: `${true}`
|
|
3866
3854
|
});
|
|
3867
3855
|
const cosRenderingUrl = `https://api.hubspot${authedEnv === "qa" ? "qa" : ""}.com/api/cos-rendering/v1/public/_hcms/preview/template/multi?${queryParams}`;
|
|
3868
|
-
const
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
modulePreviewHtml = await signedGet(
|
|
3876
|
-
authedPortalId,
|
|
3877
|
-
cosRenderingUrl,
|
|
3878
|
-
{
|
|
3879
|
-
["content-type"]: "application/x-www-form-urlencoded",
|
|
3880
|
-
["Accept"]: "text/html",
|
|
3881
|
-
referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
|
|
3882
|
-
cookie: cookieValue,
|
|
3883
|
-
"User-Agent": "HubSpot CMS Dev Server"
|
|
3884
|
-
},
|
|
3885
|
-
gates
|
|
3886
|
-
);
|
|
3887
|
-
} finally {
|
|
3888
|
-
if (needsDomainOverride) {
|
|
3889
|
-
if (previousHubApiDomainOverride) {
|
|
3890
|
-
process.env.HUBAPI_DOMAIN_OVERRIDE = previousHubApiDomainOverride;
|
|
3891
|
-
} else {
|
|
3892
|
-
delete process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
3893
|
-
}
|
|
3894
|
-
}
|
|
3895
|
-
}
|
|
3856
|
+
const modulePreviewHtml = await signedGet(authedPortalId, cosRenderingUrl, {
|
|
3857
|
+
["content-type"]: "application/x-www-form-urlencoded",
|
|
3858
|
+
["Accept"]: "text/html",
|
|
3859
|
+
referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
|
|
3860
|
+
cookie: cookieValue,
|
|
3861
|
+
"User-Agent": "HubSpot CMS Dev Server"
|
|
3862
|
+
});
|
|
3896
3863
|
const previewDoc = parseHtml(modulePreviewHtml);
|
|
3897
3864
|
const modulePreviewContent = extractModuleOuterHtml(previewDoc);
|
|
3898
3865
|
const allStyleContent = extractStyleText(previewDoc);
|
|
@@ -4133,8 +4100,7 @@ var partialRouteHandler = async (request, response) => {
|
|
|
4133
4100
|
remoteModule.path,
|
|
4134
4101
|
authedPortalId,
|
|
4135
4102
|
authedEnv,
|
|
4136
|
-
request.get("COOKIE")
|
|
4137
|
-
jsRenderingGates
|
|
4103
|
+
request.get("COOKIE")
|
|
4138
4104
|
).then((result) => ({
|
|
4139
4105
|
remoteModule,
|
|
4140
4106
|
result
|
|
@@ -4458,143 +4424,725 @@ var moduleFieldsJsonRouteHandler = async (request, response) => {
|
|
|
4458
4424
|
};
|
|
4459
4425
|
var moduleFieldsJson_default = moduleFieldsJsonRouteHandler;
|
|
4460
4426
|
|
|
4461
|
-
// src/
|
|
4462
|
-
import
|
|
4463
|
-
import
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4427
|
+
// src/routes/moduleValidateFields.ts
|
|
4428
|
+
import path14 from "path";
|
|
4429
|
+
import fs8 from "fs/promises";
|
|
4430
|
+
|
|
4431
|
+
// src/validateFields.ts
|
|
4432
|
+
import path13 from "path";
|
|
4433
|
+
import fs7 from "fs/promises";
|
|
4434
|
+
|
|
4435
|
+
// ../cms-js-internal/dist/buildFieldsTypes.js
|
|
4436
|
+
import { writeFileSync } from "fs";
|
|
4437
|
+
import ts from "typescript";
|
|
4438
|
+
var fieldTypeNameByType = {
|
|
4439
|
+
alignment: "AlignmentFieldType",
|
|
4440
|
+
audioplayer: "AudioFieldType",
|
|
4441
|
+
backgroundimage: "BackgroundImageFieldType",
|
|
4442
|
+
blog: "BlogFieldType",
|
|
4443
|
+
boolean: "BooleanFieldType",
|
|
4444
|
+
border: "BorderFieldType",
|
|
4445
|
+
choice: "ChoiceFieldType",
|
|
4446
|
+
color: "ColorFieldType",
|
|
4447
|
+
crmobject: "CrmObjectFieldType",
|
|
4448
|
+
cta: "CtaFieldType",
|
|
4449
|
+
date: "DateFieldType",
|
|
4450
|
+
datetime: "DateTimeFieldType",
|
|
4451
|
+
email: "EmailFieldType",
|
|
4452
|
+
embed: "EmbedFieldType",
|
|
4453
|
+
file: "FileFieldType",
|
|
4454
|
+
followupemail: "FollowUpEmailFieldType",
|
|
4455
|
+
font: "FontFieldType",
|
|
4456
|
+
form: "FormFieldType",
|
|
4457
|
+
gradient: "GradientFieldType",
|
|
4458
|
+
group: "GroupFieldType",
|
|
4459
|
+
html: "HtmlFieldType",
|
|
4460
|
+
hubdbrow: "HubDbRowFieldType",
|
|
4461
|
+
hubdbtable: "HubDbTableFieldType",
|
|
4462
|
+
hubl: "HublFieldType",
|
|
4463
|
+
icon: "IconFieldType",
|
|
4464
|
+
image: "ImageFieldType",
|
|
4465
|
+
link: "LinkFieldType",
|
|
4466
|
+
logo: "LogoFieldType",
|
|
4467
|
+
meeting: "MeetingFieldType",
|
|
4468
|
+
menu: "MenuFieldType",
|
|
4469
|
+
number: "NumberFieldType",
|
|
4470
|
+
page: "PageFieldType",
|
|
4471
|
+
payment: "PaymentFieldType",
|
|
4472
|
+
podcast: "PodcastFieldType",
|
|
4473
|
+
richtext: "RichTextFieldType",
|
|
4474
|
+
salesforcecampaign: "SfdcCamapaignFieldType",
|
|
4475
|
+
simplemenu: "SimpleMenuFieldType",
|
|
4476
|
+
spacing: "SpacingFieldType",
|
|
4477
|
+
survey: "SurveyFieldType",
|
|
4478
|
+
tag: "TagFieldType",
|
|
4479
|
+
textalignment: "TextAlignmentFieldType",
|
|
4480
|
+
text: "TextFieldType",
|
|
4481
|
+
url: "UrlFieldType",
|
|
4482
|
+
variantselection: "VariantSelectionFieldType",
|
|
4483
|
+
videoplayer: "VideoFieldType",
|
|
4484
|
+
workflow: "WorkflowFieldType"
|
|
4485
|
+
};
|
|
4486
|
+
function getFieldEntries(fields) {
|
|
4487
|
+
if (!Array.isArray(fields)) {
|
|
4488
|
+
return void 0;
|
|
4470
4489
|
}
|
|
4471
|
-
return
|
|
4472
|
-
const
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
method: "HEAD",
|
|
4477
|
-
headers: {
|
|
4478
|
-
// Keep this user agent, so we don't get 403s from the request
|
|
4479
|
-
["User-Agent"]: "cms-dev-server"
|
|
4480
|
-
}
|
|
4481
|
-
},
|
|
4482
|
-
async (res) => {
|
|
4483
|
-
let portalIdHeader;
|
|
4484
|
-
let contentId;
|
|
4485
|
-
const isContentMembershipRedirect = Boolean(
|
|
4486
|
-
res.headers["x-hs-content-membership-redirect"]
|
|
4487
|
-
);
|
|
4488
|
-
if (isContentMembershipRedirect) {
|
|
4489
|
-
debug("Content Membership Redirect", res.headers);
|
|
4490
|
-
portalIdHeader = res.headers["x-hs-portal-id"];
|
|
4491
|
-
contentId = res.headers["x-hs-content-id"];
|
|
4492
|
-
if (portalIdHeader && contentId) {
|
|
4493
|
-
return resolve3({
|
|
4494
|
-
portalIdHeader,
|
|
4495
|
-
contentId,
|
|
4496
|
-
res
|
|
4497
|
-
});
|
|
4498
|
-
}
|
|
4499
|
-
}
|
|
4500
|
-
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
4501
|
-
console.log(`Redirecting to ${res.headers.location} (from ${url3})`);
|
|
4502
|
-
return resolve3(
|
|
4503
|
-
requestPage(
|
|
4504
|
-
res.headers.location,
|
|
4505
|
-
redirects + 1,
|
|
4506
|
-
originalUrl ?? url3
|
|
4507
|
-
)
|
|
4508
|
-
);
|
|
4509
|
-
}
|
|
4510
|
-
portalIdHeader = res.headers["x-hs-hub-id"];
|
|
4511
|
-
contentId = res.headers["x-hs-content-id"];
|
|
4512
|
-
return resolve3({
|
|
4513
|
-
res,
|
|
4514
|
-
portalIdHeader,
|
|
4515
|
-
contentId
|
|
4516
|
-
});
|
|
4517
|
-
}
|
|
4518
|
-
).on("error", (err) => {
|
|
4519
|
-
console.error(err);
|
|
4520
|
-
reject(err);
|
|
4521
|
-
}).end();
|
|
4522
|
-
});
|
|
4523
|
-
}
|
|
4524
|
-
async function fetchContentMetadata(url3, portalId) {
|
|
4525
|
-
const { portalIdHeader, contentId, res } = await requestPage(url3);
|
|
4526
|
-
if (Array.isArray(portalIdHeader) || Array.isArray(contentId)) {
|
|
4527
|
-
throw new Error(
|
|
4528
|
-
`There were multiple hub ID or content ID headers in the HEAD request to ${url3}`
|
|
4529
|
-
);
|
|
4530
|
-
} else {
|
|
4531
|
-
const portalIdFromResponse = parseInt(portalIdHeader, 10);
|
|
4532
|
-
const pageAccount = await getConfigAccountIfExists6(portalIdFromResponse);
|
|
4533
|
-
if (!pageAccount) {
|
|
4534
|
-
throw new Error(
|
|
4535
|
-
`No CLI auth for portal ${portalIdFromResponse} found, please run \`hs auth\``
|
|
4536
|
-
);
|
|
4490
|
+
return fields.filter((field) => field.name && field.type).map((field) => {
|
|
4491
|
+
const { name, type } = field;
|
|
4492
|
+
const fieldType = fieldTypeNameByType[type];
|
|
4493
|
+
if (!fieldType) {
|
|
4494
|
+
return void 0;
|
|
4537
4495
|
}
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4496
|
+
const entry = {
|
|
4497
|
+
type: fieldType,
|
|
4498
|
+
name,
|
|
4499
|
+
isRepeater: "occurrence" in field,
|
|
4500
|
+
isRequired: !!field.required,
|
|
4501
|
+
choices: (
|
|
4502
|
+
// Choices are pair [value, label] but only the value is printed to the page, so flatten it.
|
|
4503
|
+
"choices" in field ? field.choices.map(([value, label]) => value) : void 0
|
|
4504
|
+
),
|
|
4505
|
+
multiple: field.type === "choice" ? field.multiple === true : void 0,
|
|
4506
|
+
children: []
|
|
4507
|
+
};
|
|
4508
|
+
if (fieldType === "GroupFieldType" && "children" in field) {
|
|
4509
|
+
const children = getFieldEntries(field.children);
|
|
4510
|
+
return { ...entry, children };
|
|
4550
4511
|
}
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
}
|
|
4512
|
+
return entry;
|
|
4513
|
+
}).filter((entry) => entry !== void 0);
|
|
4554
4514
|
}
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4515
|
+
var INVALID_IMPORTS = ["ChoiceFieldType", "GroupFieldType"];
|
|
4516
|
+
var FIELD_GROUP_TYPE = "FieldGroupWithChildren";
|
|
4517
|
+
var REPEATER_GROUP_TYPE = "RepeaterGroup";
|
|
4518
|
+
var REQUIRED_TYPE = "RequiredField";
|
|
4519
|
+
var DEFAULT_VALUES_TYPE = "DefaultValues";
|
|
4520
|
+
var CMS_COMPONENTS = "@hubspot/cms-components";
|
|
4521
|
+
var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
4522
|
+
var AUTO_GEN_COMMENT = "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.";
|
|
4523
|
+
var createPropertySignature = (identifier, type, hasQuestionToken = false) => ts.factory.createPropertySignature(
|
|
4524
|
+
[],
|
|
4525
|
+
identifier,
|
|
4526
|
+
hasQuestionToken ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) : void 0,
|
|
4527
|
+
type
|
|
4528
|
+
);
|
|
4529
|
+
var createUnionTypeFromArray = (values) => ts.factory.createUnionTypeNode(
|
|
4530
|
+
values.map(
|
|
4531
|
+
(value) => ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(value))
|
|
4532
|
+
)
|
|
4533
|
+
);
|
|
4534
|
+
var buildTypeFromField = (field, additionalNode) => {
|
|
4535
|
+
const imports = [field.type];
|
|
4536
|
+
const identifier = ts.factory.createIdentifier(field.name);
|
|
4537
|
+
const baseType = ts.factory.createTypeReferenceNode(field.type);
|
|
4538
|
+
const requiredType = ts.factory.createTypeReferenceNode(REQUIRED_TYPE, [
|
|
4539
|
+
baseType
|
|
4540
|
+
]);
|
|
4541
|
+
let finalType = field.isRequired ? requiredType : baseType;
|
|
4542
|
+
if (field.choices) {
|
|
4543
|
+
const choiceType = createUnionTypeFromArray(field.choices);
|
|
4544
|
+
finalType = field.multiple ? ts.factory.createTypeReferenceNode("Array", [choiceType]) : choiceType;
|
|
4568
4545
|
}
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
const urlToProxy = `http://${domainToProxy}${request.originalUrl}`;
|
|
4572
|
-
if (!domainToProxy) {
|
|
4573
|
-
if (VALID_PROXY_DOMAIN_SUFFIXES.includes(request.hostname)) {
|
|
4574
|
-
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})`;
|
|
4575
|
-
consoleWarn(message);
|
|
4576
|
-
return response.status(400).send(message);
|
|
4577
|
-
} else {
|
|
4578
|
-
const message = `Can't make a proxy request, the domain '${request.hostname}' is not a valid proxy-able domain`;
|
|
4579
|
-
consoleWarn(message);
|
|
4580
|
-
return response.status(400).send(message);
|
|
4581
|
-
}
|
|
4546
|
+
if (field.isRequired) {
|
|
4547
|
+
imports.push(REQUIRED_TYPE);
|
|
4582
4548
|
}
|
|
4583
|
-
|
|
4584
|
-
const
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
);
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4549
|
+
if (additionalNode) {
|
|
4550
|
+
const typeLiteral = ts.isTypeLiteralNode(additionalNode) ? additionalNode : ts.factory.createTypeLiteralNode([additionalNode]);
|
|
4551
|
+
const genericType = field.isRepeater ? REPEATER_GROUP_TYPE : FIELD_GROUP_TYPE;
|
|
4552
|
+
imports.push(genericType);
|
|
4553
|
+
finalType = ts.factory.createTypeReferenceNode(genericType, [typeLiteral]);
|
|
4554
|
+
}
|
|
4555
|
+
return {
|
|
4556
|
+
type: createPropertySignature(
|
|
4557
|
+
identifier,
|
|
4558
|
+
finalType,
|
|
4559
|
+
!field.isRequired && !additionalNode
|
|
4560
|
+
),
|
|
4561
|
+
imports
|
|
4562
|
+
};
|
|
4563
|
+
};
|
|
4564
|
+
var filterUnusedImports = (imports, type) => {
|
|
4565
|
+
const usedImports = /* @__PURE__ */ new Set();
|
|
4566
|
+
const visit = (node) => {
|
|
4567
|
+
if (ts.isTypeReferenceNode(node)) {
|
|
4568
|
+
const typeName = node.typeName;
|
|
4569
|
+
if ("escapedText" in typeName) {
|
|
4570
|
+
usedImports.add(typeName.escapedText.toString());
|
|
4571
|
+
}
|
|
4572
|
+
}
|
|
4573
|
+
ts.forEachChild(node, visit);
|
|
4574
|
+
};
|
|
4575
|
+
visit(type);
|
|
4576
|
+
return imports.filter((name) => usedImports.has(name));
|
|
4577
|
+
};
|
|
4578
|
+
function getImportDeclaration(imports, moduleSpecifier) {
|
|
4579
|
+
const importSpecifiers = Array.from(imports).map(
|
|
4580
|
+
(importName) => ts.factory.createImportSpecifier(
|
|
4581
|
+
true,
|
|
4582
|
+
void 0,
|
|
4583
|
+
ts.factory.createIdentifier(importName)
|
|
4584
|
+
)
|
|
4585
|
+
);
|
|
4586
|
+
const namedImports = ts.factory.createNamedImports(importSpecifiers);
|
|
4587
|
+
return ts.factory.createImportDeclaration(
|
|
4588
|
+
[],
|
|
4589
|
+
[],
|
|
4590
|
+
ts.factory.createImportClause(false, void 0, namedImports),
|
|
4591
|
+
ts.factory.createStringLiteral(moduleSpecifier)
|
|
4592
|
+
);
|
|
4593
|
+
}
|
|
4594
|
+
function getFieldTypes(fields) {
|
|
4595
|
+
const imports = [];
|
|
4596
|
+
const types = fields.map((field) => {
|
|
4597
|
+
if (field.children) {
|
|
4598
|
+
const childrenResult = getFieldTypes(field.children);
|
|
4599
|
+
imports.push(...childrenResult.imports);
|
|
4600
|
+
if (childrenResult.types.length || field.type === "GroupFieldType") {
|
|
4601
|
+
const subType = ts.factory.createTypeLiteralNode(childrenResult.types);
|
|
4602
|
+
const { type: type2, imports: newImports2 } = buildTypeFromField(
|
|
4603
|
+
field,
|
|
4604
|
+
subType
|
|
4605
|
+
);
|
|
4606
|
+
imports.push(...newImports2);
|
|
4607
|
+
return type2;
|
|
4608
|
+
}
|
|
4609
|
+
}
|
|
4610
|
+
const { type, imports: newImports } = buildTypeFromField(field);
|
|
4611
|
+
imports.push(...newImports);
|
|
4612
|
+
return type;
|
|
4613
|
+
});
|
|
4614
|
+
const validImports = Array.from(
|
|
4615
|
+
new Set(imports.filter((name) => !INVALID_IMPORTS.includes(name)))
|
|
4616
|
+
);
|
|
4617
|
+
return { types, imports: validImports };
|
|
4618
|
+
}
|
|
4619
|
+
function constructFinalType(fields, typeName) {
|
|
4620
|
+
const { types, imports } = getFieldTypes(fields);
|
|
4621
|
+
const baseType = ts.factory.createTypeAliasDeclaration(
|
|
4622
|
+
[],
|
|
4623
|
+
[],
|
|
4624
|
+
"",
|
|
4625
|
+
void 0,
|
|
4626
|
+
ts.factory.createTypeLiteralNode(types)
|
|
4627
|
+
);
|
|
4628
|
+
const wrappedType = ts.factory.createTypeReferenceNode(DEFAULT_VALUES_TYPE, [
|
|
4629
|
+
baseType.type
|
|
4630
|
+
]);
|
|
4631
|
+
const finalType = ts.factory.createTypeAliasDeclaration(
|
|
4632
|
+
[],
|
|
4633
|
+
[],
|
|
4634
|
+
typeName,
|
|
4635
|
+
void 0,
|
|
4636
|
+
wrappedType
|
|
4637
|
+
);
|
|
4638
|
+
const filteredImports = filterUnusedImports(imports, finalType);
|
|
4639
|
+
const importDeclaration = getImportDeclaration(
|
|
4640
|
+
[...filteredImports, DEFAULT_VALUES_TYPE],
|
|
4641
|
+
CMS_COMPONENTS_FIELD_TYPES
|
|
4642
|
+
);
|
|
4643
|
+
const defaultExport = ts.factory.createExportDefault(
|
|
4644
|
+
ts.factory.createIdentifier(typeName)
|
|
4645
|
+
);
|
|
4646
|
+
return [importDeclaration, finalType, defaultExport];
|
|
4647
|
+
}
|
|
4648
|
+
function writeFieldsType(fields, fileName, typeName) {
|
|
4649
|
+
const entries = getFieldEntries(fields);
|
|
4650
|
+
if (!entries) {
|
|
4651
|
+
return false;
|
|
4652
|
+
}
|
|
4653
|
+
try {
|
|
4654
|
+
const file = ts.createSourceFile(
|
|
4655
|
+
fileName,
|
|
4656
|
+
"",
|
|
4657
|
+
ts.ScriptTarget.ESNext,
|
|
4658
|
+
false,
|
|
4659
|
+
ts.ScriptKind.TS
|
|
4660
|
+
);
|
|
4661
|
+
const printer = ts.createPrinter();
|
|
4662
|
+
const nodes = constructFinalType(entries, typeName);
|
|
4663
|
+
const comments = [
|
|
4664
|
+
AUTO_GEN_COMMENT,
|
|
4665
|
+
"Removing the above comment will disable type generation for this module",
|
|
4666
|
+
"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"
|
|
4667
|
+
].map((comment) => `// ${comment}`);
|
|
4668
|
+
const typeResult = nodes.map(
|
|
4669
|
+
(node) => printer.printNode(ts.EmitHint.Unspecified, node, file)
|
|
4670
|
+
);
|
|
4671
|
+
const result = [...comments, ...typeResult].join("\n");
|
|
4672
|
+
writeFileSync(fileName, result);
|
|
4673
|
+
return true;
|
|
4674
|
+
} catch (e) {
|
|
4675
|
+
console.error(e);
|
|
4676
|
+
return false;
|
|
4677
|
+
}
|
|
4678
|
+
}
|
|
4679
|
+
|
|
4680
|
+
// src/lib/watchFieldsUpdates.ts
|
|
4681
|
+
import fs6 from "fs";
|
|
4682
|
+
import path12 from "path";
|
|
4683
|
+
import readline from "readline";
|
|
4684
|
+
var lastSerializedFieldsCache = {};
|
|
4685
|
+
var formatAsTypeName = (str) => {
|
|
4686
|
+
const typeName = `${str.replace(/[^a-zA-Z0-9_$]/g, "_")}FieldsType`;
|
|
4687
|
+
const validFirstChar = /^[A-Za-z_$]/.test(str.charAt(0));
|
|
4688
|
+
return validFirstChar ? typeName : `_${typeName}`;
|
|
4689
|
+
};
|
|
4690
|
+
var isInModulesFolder = (filePath, projectRoot) => {
|
|
4691
|
+
const getEntryPathFromId = (id) => {
|
|
4692
|
+
return id.startsWith(projectRoot) ? id.replace(`${projectRoot}${path12.sep}`, "") : "";
|
|
4693
|
+
};
|
|
4694
|
+
const currentModuleId = path12.normalize(filePath);
|
|
4695
|
+
const moduleEntryPath = getEntryPathFromId(currentModuleId);
|
|
4696
|
+
const subFolderTokens = moduleEntryPath.split(path12.sep);
|
|
4697
|
+
return {
|
|
4698
|
+
inModuleFolder: subFolderTokens[0] === "components" && subFolderTokens[1] === "modules",
|
|
4699
|
+
isRootModuleFile: subFolderTokens.length === 3
|
|
4700
|
+
};
|
|
4701
|
+
};
|
|
4702
|
+
var fileContainsAutoGenComment = async (filePath) => {
|
|
4703
|
+
if (!fs6.existsSync(filePath))
|
|
4704
|
+
return true;
|
|
4705
|
+
const stream2 = fs6.createReadStream(filePath);
|
|
4706
|
+
const reader = readline.createInterface({ input: stream2 });
|
|
4707
|
+
const firstLine = await new Promise(
|
|
4708
|
+
(resolve3) => reader.once("line", (line) => resolve3(line.trim()))
|
|
4709
|
+
);
|
|
4710
|
+
reader.close();
|
|
4711
|
+
stream2.close();
|
|
4712
|
+
return firstLine && firstLine === `// ${AUTO_GEN_COMMENT}`;
|
|
4713
|
+
};
|
|
4714
|
+
var getIndexFile = (filePath, projectRoot) => {
|
|
4715
|
+
const { inModuleFolder, isRootModuleFile } = isInModulesFolder(
|
|
4716
|
+
filePath,
|
|
4717
|
+
projectRoot
|
|
4718
|
+
);
|
|
4719
|
+
if (!inModuleFolder)
|
|
4720
|
+
return void 0;
|
|
4721
|
+
if (isRootModuleFile)
|
|
4722
|
+
return { indexFilePath: filePath, isRootModuleFile };
|
|
4723
|
+
const dir = path12.dirname(filePath);
|
|
4724
|
+
const files = fs6.readdirSync(dir);
|
|
4725
|
+
const indexFileName = files.find((file) => file.startsWith("index."));
|
|
4726
|
+
return indexFileName ? { indexFilePath: path12.join(dir, indexFileName), isRootModuleFile } : void 0;
|
|
4727
|
+
};
|
|
4728
|
+
var getIndexFileFields = async (indexFilePath, indexFileName, viteServer) => {
|
|
4729
|
+
let indexFile;
|
|
4730
|
+
let renderFieldsToJson;
|
|
4731
|
+
try {
|
|
4732
|
+
indexFile = await viteServer.ssrLoadModule(indexFilePath);
|
|
4733
|
+
const internalSsrPath = packagePath(import.meta.url, "internalSsr");
|
|
4734
|
+
({ renderFieldsToJson } = await viteServer.ssrLoadModule(internalSsrPath));
|
|
4735
|
+
} catch (e) {
|
|
4736
|
+
return void 0;
|
|
4737
|
+
}
|
|
4738
|
+
if (!indexFile.fields)
|
|
4739
|
+
return void 0;
|
|
4740
|
+
const fields = indexFile.fields;
|
|
4741
|
+
const renderedFieldsJson = renderFieldsToJson(fields, indexFileName);
|
|
4742
|
+
const isValidFields = Array.isArray(renderedFieldsJson);
|
|
4743
|
+
return isValidFields ? renderedFieldsJson : void 0;
|
|
4744
|
+
};
|
|
4745
|
+
var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
|
|
4746
|
+
const indexInfo = getIndexFile(filePath, projectRoot);
|
|
4747
|
+
if (!indexInfo)
|
|
4748
|
+
return;
|
|
4749
|
+
const { indexFilePath, isRootModuleFile } = indexInfo;
|
|
4750
|
+
const indexFileName = path12.parse(indexFilePath).name;
|
|
4751
|
+
const isTypeFile = filePath.endsWith(".types.ts");
|
|
4752
|
+
if (isTypeFile)
|
|
4753
|
+
return;
|
|
4754
|
+
const fields = await getIndexFileFields(
|
|
4755
|
+
indexFilePath,
|
|
4756
|
+
indexFileName,
|
|
4757
|
+
viteServer
|
|
4758
|
+
);
|
|
4759
|
+
if (fields) {
|
|
4760
|
+
const typeFileName = isRootModuleFile ? `${indexFileName}.fields.types.ts` : "fields.type.ts";
|
|
4761
|
+
const typeFilePath = path12.join(path12.dirname(filePath), typeFileName);
|
|
4762
|
+
const lastSerializedFields = lastSerializedFieldsCache[typeFilePath];
|
|
4763
|
+
const serializedFields = JSON.stringify(fields);
|
|
4764
|
+
if (lastSerializedFields === serializedFields)
|
|
4765
|
+
return;
|
|
4766
|
+
const hasAutoGenComment = await fileContainsAutoGenComment(typeFilePath);
|
|
4767
|
+
if (!hasAutoGenComment)
|
|
4768
|
+
return;
|
|
4769
|
+
const moduleFolderName = path12.basename(path12.dirname(filePath));
|
|
4770
|
+
const outputTypeName = formatAsTypeName(moduleFolderName);
|
|
4771
|
+
const didSucceed = writeFieldsType(fields, typeFilePath, outputTypeName);
|
|
4772
|
+
if (didSucceed) {
|
|
4773
|
+
lastSerializedFieldsCache[typeFilePath] = serializedFields;
|
|
4774
|
+
}
|
|
4775
|
+
const pathToLog = isRootModuleFile ? `${moduleFolderName}/${indexFileName}` : moduleFolderName;
|
|
4776
|
+
const successMsg = `Successfully generated types for ${pathToLog}`;
|
|
4777
|
+
const errorMsg = `Failed to generate types for ${pathToLog}`;
|
|
4778
|
+
const message = didSucceed ? successMsg : errorMsg;
|
|
4779
|
+
console.log(wrapMessageInColor(didSucceed ? "green" : "red", message));
|
|
4780
|
+
}
|
|
4781
|
+
};
|
|
4782
|
+
var startFieldsTypeGenWatcher = (viteServer, projectRoot) => {
|
|
4783
|
+
const { moduleSubpaths } = findAllModulesInRoot(projectRoot);
|
|
4784
|
+
moduleSubpaths.forEach((modulePath) => {
|
|
4785
|
+
const resolvedPath = path12.resolve(projectRoot, modulePath);
|
|
4786
|
+
maybeUpdateFields(resolvedPath, viteServer, projectRoot);
|
|
4787
|
+
});
|
|
4788
|
+
const watchCallback = (filePath) => maybeUpdateFields(filePath, viteServer, projectRoot);
|
|
4789
|
+
viteServer.watcher.on("add", watchCallback).on("change", watchCallback);
|
|
4790
|
+
};
|
|
4791
|
+
|
|
4792
|
+
// src/validateFields.ts
|
|
4793
|
+
import { http as hsCliHttp8 } from "@hubspot/local-dev-lib/http";
|
|
4794
|
+
import { getConfigDefaultAccount } from "@hubspot/local-dev-lib/config";
|
|
4795
|
+
var EDITOR_VERSION_V2 = "2.0";
|
|
4796
|
+
async function generateAndWriteFieldsJson(absoluteModulePath, modulePath, viteServer) {
|
|
4797
|
+
let fieldsJson;
|
|
4798
|
+
try {
|
|
4799
|
+
fieldsJson = await renderModuleFieldsJson_default(viteServer, absoluteModulePath);
|
|
4800
|
+
} catch {
|
|
4801
|
+
return {
|
|
4802
|
+
severity: "FATAL",
|
|
4803
|
+
errorType: "MODULE_BUILD_ERROR",
|
|
4804
|
+
message: `Failed to SSR-load module at ${modulePath}`
|
|
4805
|
+
};
|
|
4806
|
+
}
|
|
4807
|
+
if (!Array.isArray(fieldsJson)) {
|
|
4808
|
+
return {
|
|
4809
|
+
severity: "FATAL",
|
|
4810
|
+
errorType: "INVALID_FIELDS",
|
|
4811
|
+
message: `renderModuleFieldsJson returned non-array for ${modulePath}`
|
|
4812
|
+
};
|
|
4813
|
+
}
|
|
4814
|
+
const fieldsJsonPath = path13.join(absoluteModulePath, "fields.json");
|
|
4815
|
+
await fs7.writeFile(fieldsJsonPath, JSON.stringify(fieldsJson, null, 2));
|
|
4816
|
+
return { fieldsJson, fieldsJsonPath };
|
|
4817
|
+
}
|
|
4818
|
+
async function generateAndWriteFieldsType(absoluteModulePath, modulePath, moduleDir, fieldsJson) {
|
|
4819
|
+
const fieldsTypePath = path13.join(absoluteModulePath, "fields.type.ts");
|
|
4820
|
+
const hasAutoGenComment = await fileContainsAutoGenComment(fieldsTypePath);
|
|
4821
|
+
if (hasAutoGenComment) {
|
|
4822
|
+
const typeName = formatAsTypeName(moduleDir);
|
|
4823
|
+
const didSucceed = writeFieldsType(fieldsJson, fieldsTypePath, typeName);
|
|
4824
|
+
if (!didSucceed) {
|
|
4825
|
+
return {
|
|
4826
|
+
severity: "FATAL",
|
|
4827
|
+
errorType: "TYPE_GEN_ERROR",
|
|
4828
|
+
message: `Failed to generate fields.type.ts for ${modulePath}`
|
|
4829
|
+
};
|
|
4830
|
+
}
|
|
4831
|
+
}
|
|
4832
|
+
return { fieldsTypePath };
|
|
4833
|
+
}
|
|
4834
|
+
async function extractAndValidateFields(fieldsJson, metaJson, modulePath) {
|
|
4835
|
+
if (!metaJson) {
|
|
4836
|
+
return {
|
|
4837
|
+
fieldErrors: [],
|
|
4838
|
+
metaErrors: [
|
|
4839
|
+
{
|
|
4840
|
+
severity: "FATAL",
|
|
4841
|
+
errorType: "MISSING_META",
|
|
4842
|
+
message: `Module does not have a named meta export: ${modulePath}`
|
|
4843
|
+
}
|
|
4844
|
+
]
|
|
4845
|
+
};
|
|
4846
|
+
}
|
|
4847
|
+
const portalId = getConfigDefaultAccount().accountId;
|
|
4848
|
+
const [fieldsResult, metaResult] = await Promise.allSettled([
|
|
4849
|
+
hsCliHttp8.post(portalId, {
|
|
4850
|
+
url: `${VALIDATE_FIELDS_ENDPOINT}?editorVersion=${metaJson.editor_version ?? EDITOR_VERSION_V2}`,
|
|
4851
|
+
data: fieldsJson
|
|
4852
|
+
}),
|
|
4853
|
+
hsCliHttp8.post(portalId, {
|
|
4854
|
+
url: VALIDATE_META_ENDPOINT,
|
|
4855
|
+
data: metaJson
|
|
4856
|
+
})
|
|
4857
|
+
]);
|
|
4858
|
+
const mapErrors = (entities) => entities.filter((e) => e.severity === "FATAL").map((e) => ({
|
|
4859
|
+
severity: e.severity,
|
|
4860
|
+
errorType: e.errorType,
|
|
4861
|
+
message: e.message,
|
|
4862
|
+
fieldPath: e.errorTokens.path[0]
|
|
4863
|
+
}));
|
|
4864
|
+
return {
|
|
4865
|
+
fieldErrors: fieldsResult.status === "fulfilled" ? mapErrors(fieldsResult.value.data) : [
|
|
4866
|
+
{
|
|
4867
|
+
severity: "FATAL",
|
|
4868
|
+
errorType: "API_UNREACHABLE",
|
|
4869
|
+
message: `Field validation API error: ${fieldsResult.reason}`
|
|
4870
|
+
}
|
|
4871
|
+
],
|
|
4872
|
+
metaErrors: metaResult.status === "fulfilled" ? mapErrors(metaResult.value.data) : [
|
|
4873
|
+
{
|
|
4874
|
+
severity: "FATAL",
|
|
4875
|
+
errorType: "API_UNREACHABLE",
|
|
4876
|
+
message: `Meta validation API error: ${metaResult.reason}`
|
|
4877
|
+
}
|
|
4878
|
+
]
|
|
4879
|
+
};
|
|
4880
|
+
}
|
|
4881
|
+
async function generateSingleModule(modulePath, absoluteRoot, viteServer) {
|
|
4882
|
+
const absoluteModulePath = path13.resolve(absoluteRoot, modulePath);
|
|
4883
|
+
let files;
|
|
4884
|
+
try {
|
|
4885
|
+
files = await fs7.readdir(absoluteModulePath);
|
|
4886
|
+
} catch {
|
|
4887
|
+
return {
|
|
4888
|
+
fieldsJsonPath: "",
|
|
4889
|
+
fieldErrors: [
|
|
4890
|
+
{
|
|
4891
|
+
severity: "FATAL",
|
|
4892
|
+
errorType: "MODULE_NOT_FOUND",
|
|
4893
|
+
message: `Module directory does not exist: ${modulePath}`
|
|
4894
|
+
}
|
|
4895
|
+
]
|
|
4896
|
+
};
|
|
4897
|
+
}
|
|
4898
|
+
const indexFile = files.find((f) => f.startsWith("index."));
|
|
4899
|
+
if (!indexFile) {
|
|
4900
|
+
return {
|
|
4901
|
+
fieldsJsonPath: "",
|
|
4902
|
+
fieldErrors: [
|
|
4903
|
+
{
|
|
4904
|
+
severity: "FATAL",
|
|
4905
|
+
errorType: "NO_INDEX_FILE",
|
|
4906
|
+
message: `No index file found in ${modulePath}`
|
|
4907
|
+
}
|
|
4908
|
+
]
|
|
4909
|
+
};
|
|
4910
|
+
}
|
|
4911
|
+
const jsonResult = await generateAndWriteFieldsJson(
|
|
4912
|
+
absoluteModulePath,
|
|
4913
|
+
modulePath,
|
|
4914
|
+
viteServer
|
|
4915
|
+
);
|
|
4916
|
+
if ("severity" in jsonResult) {
|
|
4917
|
+
return { fieldsJsonPath: "", fieldErrors: [jsonResult] };
|
|
4918
|
+
}
|
|
4919
|
+
return {
|
|
4920
|
+
fieldsJsonPath: jsonResult.fieldsJsonPath,
|
|
4921
|
+
fieldErrors: [],
|
|
4922
|
+
fieldsJson: jsonResult.fieldsJson,
|
|
4923
|
+
indexFile
|
|
4924
|
+
};
|
|
4925
|
+
}
|
|
4926
|
+
async function validateSingleModule(modulePath, absoluteRoot, viteServer) {
|
|
4927
|
+
const { fieldsJsonPath, fieldErrors, fieldsJson, indexFile } = await generateSingleModule(modulePath, absoluteRoot, viteServer);
|
|
4928
|
+
if (!fieldsJson || !indexFile) {
|
|
4929
|
+
return { fieldsJsonPath, fieldsTypePath: "", fieldErrors, metaErrors: [] };
|
|
4930
|
+
}
|
|
4931
|
+
const absoluteModulePath = path13.resolve(absoluteRoot, modulePath);
|
|
4932
|
+
const typeResult = await generateAndWriteFieldsType(
|
|
4933
|
+
absoluteModulePath,
|
|
4934
|
+
modulePath,
|
|
4935
|
+
path13.basename(modulePath),
|
|
4936
|
+
fieldsJson
|
|
4937
|
+
);
|
|
4938
|
+
if ("severity" in typeResult) {
|
|
4939
|
+
return {
|
|
4940
|
+
fieldsJsonPath,
|
|
4941
|
+
fieldsTypePath: "",
|
|
4942
|
+
fieldErrors: [typeResult],
|
|
4943
|
+
metaErrors: []
|
|
4944
|
+
};
|
|
4945
|
+
}
|
|
4946
|
+
const { fieldsTypePath } = typeResult;
|
|
4947
|
+
let mod;
|
|
4948
|
+
try {
|
|
4949
|
+
mod = await viteServer.ssrLoadModule(
|
|
4950
|
+
path13.join(absoluteModulePath, indexFile)
|
|
4951
|
+
);
|
|
4952
|
+
} catch {
|
|
4953
|
+
return {
|
|
4954
|
+
fieldsJsonPath,
|
|
4955
|
+
fieldsTypePath,
|
|
4956
|
+
fieldErrors: [
|
|
4957
|
+
{
|
|
4958
|
+
severity: "FATAL",
|
|
4959
|
+
errorType: "MODULE_BUILD_ERROR",
|
|
4960
|
+
message: `Failed to SSR-load module for meta extraction: ${modulePath}`
|
|
4961
|
+
}
|
|
4962
|
+
],
|
|
4963
|
+
metaErrors: []
|
|
4964
|
+
};
|
|
4965
|
+
}
|
|
4966
|
+
const validation = await extractAndValidateFields(
|
|
4967
|
+
fieldsJson,
|
|
4968
|
+
mod.meta,
|
|
4969
|
+
modulePath
|
|
4970
|
+
);
|
|
4971
|
+
return { fieldsJsonPath, fieldsTypePath, ...validation };
|
|
4972
|
+
}
|
|
4973
|
+
|
|
4974
|
+
// src/routes/moduleValidateFields.ts
|
|
4975
|
+
var invalidateModuleFiles = async (viteServer, absoluteModulePath) => {
|
|
4976
|
+
const files = await fs8.readdir(absoluteModulePath).catch(() => []);
|
|
4977
|
+
files.forEach(
|
|
4978
|
+
(file) => {
|
|
4979
|
+
var _a;
|
|
4980
|
+
return (_a = viteServer.moduleGraph.getModulesByFile(path14.join(absoluteModulePath, file))) == null ? void 0 : _a.forEach((mod) => viteServer.moduleGraph.invalidateModule(mod));
|
|
4981
|
+
}
|
|
4982
|
+
);
|
|
4983
|
+
};
|
|
4984
|
+
var moduleValidateFieldsRouteHandler = async (request, response) => {
|
|
4985
|
+
try {
|
|
4986
|
+
const { webRoot: webRoot2, viteServer } = request.app.locals;
|
|
4987
|
+
const { moduleName } = request.params;
|
|
4988
|
+
const modulesRoot = path14.resolve(webRoot2, "components/modules");
|
|
4989
|
+
const absoluteModulePath = path14.resolve(modulesRoot, moduleName);
|
|
4990
|
+
if (!absoluteModulePath.startsWith(modulesRoot + path14.sep) || path14.dirname(absoluteModulePath) !== modulesRoot) {
|
|
4991
|
+
return response.status(400).json({ error: "Invalid module name" });
|
|
4992
|
+
}
|
|
4993
|
+
await invalidateModuleFiles(viteServer, absoluteModulePath);
|
|
4994
|
+
const result = await validateSingleModule(
|
|
4995
|
+
absoluteModulePath,
|
|
4996
|
+
webRoot2,
|
|
4997
|
+
viteServer
|
|
4998
|
+
);
|
|
4999
|
+
return response.status(200).json([result]);
|
|
5000
|
+
} catch (error) {
|
|
5001
|
+
console.error("Error validating module fields:", error);
|
|
5002
|
+
return response.status(500).json({
|
|
5003
|
+
error: "Failed to validate module fields"
|
|
5004
|
+
});
|
|
5005
|
+
}
|
|
5006
|
+
};
|
|
5007
|
+
var moduleValidateFields_default = moduleValidateFieldsRouteHandler;
|
|
5008
|
+
|
|
5009
|
+
// src/proxyPage/fetchContentMetadata.ts
|
|
5010
|
+
import http from "http";
|
|
5011
|
+
import https from "https";
|
|
5012
|
+
import { getConfigAccountIfExists as getConfigAccountIfExists6 } from "@hubspot/local-dev-lib/config";
|
|
5013
|
+
async function requestPage(url3, redirects = 0, originalUrl) {
|
|
5014
|
+
if (redirects > 5) {
|
|
5015
|
+
throw new Error(
|
|
5016
|
+
`Hit too many redirects to HEAD requests for ${originalUrl}`
|
|
5017
|
+
);
|
|
5018
|
+
}
|
|
5019
|
+
return new Promise((resolve3, reject) => {
|
|
5020
|
+
const protocolAPI = url3.startsWith("https://") ? https : http;
|
|
5021
|
+
protocolAPI.request(
|
|
5022
|
+
url3,
|
|
5023
|
+
{
|
|
5024
|
+
method: "HEAD",
|
|
5025
|
+
headers: {
|
|
5026
|
+
// Keep this user agent, so we don't get 403s from the request
|
|
5027
|
+
["User-Agent"]: "cms-dev-server"
|
|
5028
|
+
}
|
|
5029
|
+
},
|
|
5030
|
+
async (res) => {
|
|
5031
|
+
let portalIdHeader;
|
|
5032
|
+
let contentId;
|
|
5033
|
+
const isContentMembershipRedirect = Boolean(
|
|
5034
|
+
res.headers["x-hs-content-membership-redirect"]
|
|
5035
|
+
);
|
|
5036
|
+
if (isContentMembershipRedirect) {
|
|
5037
|
+
debug("Content Membership Redirect", res.headers);
|
|
5038
|
+
portalIdHeader = res.headers["x-hs-portal-id"];
|
|
5039
|
+
contentId = res.headers["x-hs-content-id"];
|
|
5040
|
+
if (portalIdHeader && contentId) {
|
|
5041
|
+
return resolve3({
|
|
5042
|
+
portalIdHeader,
|
|
5043
|
+
contentId,
|
|
5044
|
+
res
|
|
5045
|
+
});
|
|
5046
|
+
}
|
|
5047
|
+
}
|
|
5048
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
5049
|
+
console.log(`Redirecting to ${res.headers.location} (from ${url3})`);
|
|
5050
|
+
return resolve3(
|
|
5051
|
+
requestPage(
|
|
5052
|
+
res.headers.location,
|
|
5053
|
+
redirects + 1,
|
|
5054
|
+
originalUrl ?? url3
|
|
5055
|
+
)
|
|
5056
|
+
);
|
|
5057
|
+
}
|
|
5058
|
+
portalIdHeader = res.headers["x-hs-hub-id"];
|
|
5059
|
+
contentId = res.headers["x-hs-content-id"];
|
|
5060
|
+
return resolve3({
|
|
5061
|
+
res,
|
|
5062
|
+
portalIdHeader,
|
|
5063
|
+
contentId
|
|
5064
|
+
});
|
|
5065
|
+
}
|
|
5066
|
+
).on("error", (err) => {
|
|
5067
|
+
console.error(err);
|
|
5068
|
+
reject(err);
|
|
5069
|
+
}).end();
|
|
5070
|
+
});
|
|
5071
|
+
}
|
|
5072
|
+
async function fetchContentMetadata(url3, portalId) {
|
|
5073
|
+
const { portalIdHeader, contentId, res } = await requestPage(url3);
|
|
5074
|
+
if (Array.isArray(portalIdHeader) || Array.isArray(contentId)) {
|
|
5075
|
+
throw new Error(
|
|
5076
|
+
`There were multiple hub ID or content ID headers in the HEAD request to ${url3}`
|
|
5077
|
+
);
|
|
5078
|
+
} else {
|
|
5079
|
+
const portalIdFromResponse = parseInt(portalIdHeader, 10);
|
|
5080
|
+
const pageAccount = await getConfigAccountIfExists6(portalIdFromResponse);
|
|
5081
|
+
if (!pageAccount) {
|
|
5082
|
+
throw new Error(
|
|
5083
|
+
`No CLI auth for portal ${portalIdFromResponse} found, please run \`hs auth\``
|
|
5084
|
+
);
|
|
5085
|
+
}
|
|
5086
|
+
if (res.statusCode !== 200 && !(portalIdFromResponse && pageAccount && contentId)) {
|
|
5087
|
+
throw new Error(
|
|
5088
|
+
`${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.` : ""}`
|
|
5089
|
+
);
|
|
5090
|
+
} else if (!portalId || !contentId) {
|
|
5091
|
+
throw new Error(
|
|
5092
|
+
`Missing hub ID or content ID headers on HEAD request to ${url3}`
|
|
5093
|
+
);
|
|
5094
|
+
} else if (isNaN(portalId)) {
|
|
5095
|
+
throw new Error(
|
|
5096
|
+
`Hub ID from the HEAD request is not a number: '${portalId}' (${url3})`
|
|
5097
|
+
);
|
|
5098
|
+
}
|
|
5099
|
+
const hublet = "na1";
|
|
5100
|
+
return { portalId, contentId, hublet };
|
|
5101
|
+
}
|
|
5102
|
+
}
|
|
5103
|
+
|
|
5104
|
+
// src/routes/proxyPageRouteHandler.ts
|
|
5105
|
+
async function proxyPageRouteHandler(request, response, next) {
|
|
5106
|
+
sendTrackingRequest("view-proxy-page-route");
|
|
5107
|
+
const {
|
|
5108
|
+
viteServer,
|
|
5109
|
+
webRoot: webRoot2,
|
|
5110
|
+
projectName,
|
|
5111
|
+
projectComponentPath,
|
|
5112
|
+
jsRenderingGates
|
|
5113
|
+
} = request.app.locals;
|
|
5114
|
+
if (!request.accepts().includes("text/html")) {
|
|
5115
|
+
return response.sendStatus(404);
|
|
5116
|
+
}
|
|
5117
|
+
const fullOriginalUrl = fullOriginalUrlFromRequest(request);
|
|
5118
|
+
const domainToProxy = getSubDomainFromValidLocalDomain(request.hostname);
|
|
5119
|
+
const urlToProxy = `http://${domainToProxy}${request.originalUrl}`;
|
|
5120
|
+
if (!domainToProxy) {
|
|
5121
|
+
if (VALID_PROXY_DOMAIN_SUFFIXES.includes(request.hostname)) {
|
|
5122
|
+
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})`;
|
|
5123
|
+
consoleWarn(message);
|
|
5124
|
+
return response.status(400).send(message);
|
|
5125
|
+
} else {
|
|
5126
|
+
const message = `Can't make a proxy request, the domain '${request.hostname}' is not a valid proxy-able domain`;
|
|
5127
|
+
consoleWarn(message);
|
|
5128
|
+
return response.status(400).send(message);
|
|
5129
|
+
}
|
|
5130
|
+
}
|
|
5131
|
+
try {
|
|
5132
|
+
const { portalId, contentId, hublet } = await fetchContentMetadata(
|
|
5133
|
+
urlToProxy,
|
|
5134
|
+
request.app.locals.authedPortalId
|
|
5135
|
+
);
|
|
5136
|
+
await proxySpecificPage(
|
|
5137
|
+
request,
|
|
5138
|
+
response,
|
|
5139
|
+
portalId,
|
|
5140
|
+
hublet,
|
|
5141
|
+
contentId,
|
|
5142
|
+
webRoot2,
|
|
5143
|
+
viteServer,
|
|
5144
|
+
projectName,
|
|
5145
|
+
projectComponentPath,
|
|
4598
5146
|
jsRenderingGates,
|
|
4599
5147
|
urlToProxy,
|
|
4600
5148
|
fullOriginalUrl
|
|
@@ -4659,31 +5207,31 @@ function HubLModulesList({ modules }) {
|
|
|
4659
5207
|
}
|
|
4660
5208
|
|
|
4661
5209
|
// src/api/designmanager.ts
|
|
4662
|
-
import { http as
|
|
5210
|
+
import { http as hsCliHttp9 } from "@hubspot/local-dev-lib/http";
|
|
4663
5211
|
var DESIGN_MANAGER_API_PATH = "designmanager/v1";
|
|
4664
5212
|
async function fetchHubLModules(accountId, previewToken, limit = 250) {
|
|
4665
|
-
return (await
|
|
5213
|
+
return (await hsCliHttp9.get(accountId, {
|
|
4666
5214
|
url: `${DESIGN_MANAGER_API_PATH}/modules/local-preview?previewToken=${previewToken}&limit=${limit}`
|
|
4667
5215
|
})).data;
|
|
4668
5216
|
}
|
|
4669
5217
|
async function fetchPreviewTemplates(accountId, previewToken, limit = 250) {
|
|
4670
|
-
return (await
|
|
5218
|
+
return (await hsCliHttp9.get(accountId, {
|
|
4671
5219
|
url: `${DESIGN_MANAGER_API_PATH}/templates/local-preview?previewToken=${previewToken}&limit=${limit}`
|
|
4672
5220
|
})).data;
|
|
4673
5221
|
}
|
|
4674
|
-
async function fetchModuleByPath(accountId,
|
|
4675
|
-
return (await
|
|
4676
|
-
url: `${DESIGN_MANAGER_API_PATH}/modules/by-path/${
|
|
5222
|
+
async function fetchModuleByPath(accountId, path21) {
|
|
5223
|
+
return (await hsCliHttp9.get(accountId, {
|
|
5224
|
+
url: `${DESIGN_MANAGER_API_PATH}/modules/by-path/${path21}?portalId=${accountId}`
|
|
4677
5225
|
})).data;
|
|
4678
5226
|
}
|
|
4679
|
-
async function fetchTemplateByPath(accountId,
|
|
4680
|
-
return (await
|
|
4681
|
-
url: `${DESIGN_MANAGER_API_PATH}/templates/by-path/${
|
|
5227
|
+
async function fetchTemplateByPath(accountId, path21) {
|
|
5228
|
+
return (await hsCliHttp9.get(accountId, {
|
|
5229
|
+
url: `${DESIGN_MANAGER_API_PATH}/templates/by-path/${path21}?portalId=${accountId}`
|
|
4682
5230
|
})).data;
|
|
4683
5231
|
}
|
|
4684
|
-
async function fetchModulePageDependencies(accountId,
|
|
4685
|
-
const url3 = `${DESIGN_MANAGER_API_PATH}/modules/list-pages?modulePath=${
|
|
4686
|
-
return (await
|
|
5232
|
+
async function fetchModulePageDependencies(accountId, path21) {
|
|
5233
|
+
const url3 = `${DESIGN_MANAGER_API_PATH}/modules/list-pages?modulePath=${path21}`;
|
|
5234
|
+
return (await hsCliHttp9.get(accountId, { url: url3 })).data;
|
|
4687
5235
|
}
|
|
4688
5236
|
|
|
4689
5237
|
// src/components/HubLTemplatesList.tsx
|
|
@@ -4918,7 +5466,7 @@ function proxyServerlessRequest(req, res, next) {
|
|
|
4918
5466
|
}
|
|
4919
5467
|
|
|
4920
5468
|
// src/routes/modulePreviewRouteHandler.ts
|
|
4921
|
-
import
|
|
5469
|
+
import path15 from "path";
|
|
4922
5470
|
import { normalizePath as normalizePath8 } from "vite";
|
|
4923
5471
|
async function modulePreviewRouteHandler(request, response) {
|
|
4924
5472
|
sendTrackingRequest("view-module-preview-route");
|
|
@@ -4935,7 +5483,7 @@ async function modulePreviewRouteHandler(request, response) {
|
|
|
4935
5483
|
} = request.app.locals;
|
|
4936
5484
|
const moduleName = request.params.moduleName;
|
|
4937
5485
|
const modulePath = normalizePath8(
|
|
4938
|
-
|
|
5486
|
+
path15.resolve(webRoot2, "components/modules/", moduleName)
|
|
4939
5487
|
);
|
|
4940
5488
|
const PREVIEWER_APP_PARAM = "hsPreviewerApp";
|
|
4941
5489
|
let fieldOverrides = {};
|
|
@@ -5036,7 +5584,7 @@ var modulePreviewRouteHandler_default = modulePreviewRouteHandler;
|
|
|
5036
5584
|
// src/routes/hublModuleRouteHandler.ts
|
|
5037
5585
|
var hublModuleRouteHandler = async (request, response) => {
|
|
5038
5586
|
sendTrackingRequest("view-hubl-module-route");
|
|
5039
|
-
const { authedPortalId, localPreviewToken, projectName
|
|
5587
|
+
const { authedPortalId, localPreviewToken, projectName } = request.app.locals;
|
|
5040
5588
|
const { modulePath } = request.params;
|
|
5041
5589
|
if (!modulePath) {
|
|
5042
5590
|
response.status(200).set({ "Content-Type": "text/html" }).end(buildModuleIndex());
|
|
@@ -5064,7 +5612,7 @@ var hublModuleRouteHandler = async (request, response) => {
|
|
|
5064
5612
|
};
|
|
5065
5613
|
const previewUrl = getPreviewUrl(request, params);
|
|
5066
5614
|
try {
|
|
5067
|
-
const result = await signedGet(authedPortalId, previewUrl, {}
|
|
5615
|
+
const result = await signedGet(authedPortalId, previewUrl, {});
|
|
5068
5616
|
const html = addRefreshScript(result);
|
|
5069
5617
|
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
5070
5618
|
} catch (err) {
|
|
@@ -5139,12 +5687,7 @@ var templateRouteHandler = async (request, response) => {
|
|
|
5139
5687
|
const previewUrl = getPreviewUrl(request, params);
|
|
5140
5688
|
const fullOriginalUrl = `${request.protocol}://${request.get("host")}${request.originalUrl}`;
|
|
5141
5689
|
try {
|
|
5142
|
-
const result = await signedGet(
|
|
5143
|
-
authedPortalId,
|
|
5144
|
-
previewUrl,
|
|
5145
|
-
{},
|
|
5146
|
-
jsRenderingGates
|
|
5147
|
-
);
|
|
5690
|
+
const result = await signedGet(authedPortalId, previewUrl, {});
|
|
5148
5691
|
const pageHtml = addRefreshScript(result);
|
|
5149
5692
|
const finalHtml = pageHtml.replace(
|
|
5150
5693
|
HUBSPOT_PREVIEW_BASE_TAG_REGEX,
|
|
@@ -5198,15 +5741,15 @@ function getOpenCommand() {
|
|
|
5198
5741
|
}
|
|
5199
5742
|
}
|
|
5200
5743
|
async function handleGetModulePages(req, res, next) {
|
|
5201
|
-
const { path:
|
|
5202
|
-
if (!
|
|
5744
|
+
const { path: path21, portalId } = req.query;
|
|
5745
|
+
if (!path21 || !portalId) {
|
|
5203
5746
|
return res.status(400).json({ error: "Missing required parameters" });
|
|
5204
5747
|
}
|
|
5205
5748
|
try {
|
|
5206
5749
|
sendTrackingRequest("handle-module-dependencies");
|
|
5207
5750
|
const data = await fetchModulePageDependencies(
|
|
5208
5751
|
Number(portalId),
|
|
5209
|
-
|
|
5752
|
+
path21
|
|
5210
5753
|
);
|
|
5211
5754
|
res.json(data);
|
|
5212
5755
|
} catch (err) {
|
|
@@ -5214,14 +5757,14 @@ async function handleGetModulePages(req, res, next) {
|
|
|
5214
5757
|
}
|
|
5215
5758
|
}
|
|
5216
5759
|
function handleOpenFile(req, res, next) {
|
|
5217
|
-
const { path:
|
|
5218
|
-
if (!
|
|
5760
|
+
const { path: path21 } = req.query;
|
|
5761
|
+
if (!path21) {
|
|
5219
5762
|
return res.status(400).json({ error: "Missing required parameters" });
|
|
5220
5763
|
}
|
|
5221
5764
|
try {
|
|
5222
5765
|
sendTrackingRequest("handle-open-file");
|
|
5223
5766
|
const command = getOpenCommand();
|
|
5224
|
-
spawn(command, [
|
|
5767
|
+
spawn(command, [path21], { detached: true }).unref();
|
|
5225
5768
|
res.sendStatus(200);
|
|
5226
5769
|
} catch (err) {
|
|
5227
5770
|
next(err);
|
|
@@ -5236,19 +5779,19 @@ function createAppServerAPIRoutes() {
|
|
|
5236
5779
|
var createAppServerAPIRoutes_default = createAppServerAPIRoutes;
|
|
5237
5780
|
|
|
5238
5781
|
// src/routes/appServerRouteHandler.ts
|
|
5239
|
-
import
|
|
5240
|
-
import
|
|
5782
|
+
import fs10 from "node:fs/promises";
|
|
5783
|
+
import path17 from "path";
|
|
5241
5784
|
import { pathToFileURL } from "url";
|
|
5242
5785
|
|
|
5243
5786
|
// src/lib/getDevServerUIData.ts
|
|
5244
|
-
import
|
|
5787
|
+
import path16 from "path";
|
|
5245
5788
|
import { normalizePath as normalizePath9 } from "vite";
|
|
5246
5789
|
|
|
5247
5790
|
// src/api/project.ts
|
|
5248
|
-
import { http as
|
|
5791
|
+
import { http as hsCliHttp10 } from "@hubspot/local-dev-lib/http";
|
|
5249
5792
|
var DEVELOPER_PROJECTS_API_PATH = "/developer/projects/v1";
|
|
5250
5793
|
async function fetchProjectByName(accountId, projectName) {
|
|
5251
|
-
return (await
|
|
5794
|
+
return (await hsCliHttp10.get(accountId, {
|
|
5252
5795
|
url: `${DEVELOPER_PROJECTS_API_PATH}/by-name/${projectName}`
|
|
5253
5796
|
})).data;
|
|
5254
5797
|
}
|
|
@@ -5479,7 +6022,7 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
5479
6022
|
var createViteDevServer_default = createViteDevServer;
|
|
5480
6023
|
|
|
5481
6024
|
// src/lib/getDevServerUIData.ts
|
|
5482
|
-
import
|
|
6025
|
+
import fs9 from "node:fs";
|
|
5483
6026
|
var templateTypeMap = {
|
|
5484
6027
|
// Standard templates
|
|
5485
6028
|
4: "Page",
|
|
@@ -5505,7 +6048,7 @@ function mapReactModules(modules, themeWebRoot, appViteServer) {
|
|
|
5505
6048
|
return Promise.all(
|
|
5506
6049
|
modules.moduleNames.map(async (name, index) => {
|
|
5507
6050
|
const modulePath = normalizePath9(
|
|
5508
|
-
|
|
6051
|
+
path16.resolve(themeWebRoot, "components/modules/", name)
|
|
5509
6052
|
);
|
|
5510
6053
|
const fieldsJson = await renderModuleFieldsJson_default(
|
|
5511
6054
|
appViteServer,
|
|
@@ -5551,9 +6094,9 @@ function normalizeTemplatesData(templates, projectName) {
|
|
|
5551
6094
|
});
|
|
5552
6095
|
}
|
|
5553
6096
|
function detectPackageManager(projectRoot) {
|
|
5554
|
-
if (
|
|
6097
|
+
if (fs9.existsSync(path16.join(projectRoot, "yarn.lock")))
|
|
5555
6098
|
return "yarn";
|
|
5556
|
-
if (
|
|
6099
|
+
if (fs9.existsSync(path16.join(projectRoot, "pnpm-lock.yaml")))
|
|
5557
6100
|
return "pnpm";
|
|
5558
6101
|
return "npm";
|
|
5559
6102
|
}
|
|
@@ -5637,10 +6180,10 @@ var appServerRouteHandler = async (req, res, __next) => {
|
|
|
5637
6180
|
const { appWebRoot, appViteServer } = appLocals;
|
|
5638
6181
|
const initialProps = await getDevServerUIData(appLocals);
|
|
5639
6182
|
const url3 = req.originalUrl.replace("/", "");
|
|
5640
|
-
const templatePath =
|
|
5641
|
-
const serverEntryPath = isProd ?
|
|
6183
|
+
const templatePath = path17.join(appWebRoot, "index.html");
|
|
6184
|
+
const serverEntryPath = isProd ? path17.join(appWebRoot, "server/serverEntry.js") : path17.join(appWebRoot, "serverEntry.tsx");
|
|
5642
6185
|
let render;
|
|
5643
|
-
let template = await
|
|
6186
|
+
let template = await fs10.readFile(path17.join(templatePath), "utf-8");
|
|
5644
6187
|
if (isProd) {
|
|
5645
6188
|
const { render: ssrRender } = await import(pathToFileURL(serverEntryPath).href);
|
|
5646
6189
|
render = ssrRender;
|
|
@@ -5671,7 +6214,7 @@ var appServerRouteHandler = async (req, res, __next) => {
|
|
|
5671
6214
|
var appServerRouteHandler_default = appServerRouteHandler;
|
|
5672
6215
|
|
|
5673
6216
|
// src/routes/createDevServerRoutes.ts
|
|
5674
|
-
import
|
|
6217
|
+
import path18 from "path";
|
|
5675
6218
|
var isProd2 = true;
|
|
5676
6219
|
var STORYBOOK_DOMAINS = VALID_PROXY_DOMAIN_SUFFIXES.map(
|
|
5677
6220
|
(domain2) => `storybook.${domain2}`
|
|
@@ -5698,7 +6241,7 @@ var createDevServerRoutes = async (viteServer, appLocals, storybookPort) => {
|
|
|
5698
6241
|
}
|
|
5699
6242
|
devServerApp.use(urlencoded());
|
|
5700
6243
|
if (isProd2) {
|
|
5701
|
-
const distAssetsPath =
|
|
6244
|
+
const distAssetsPath = path18.join(appWebRoot, "assets");
|
|
5702
6245
|
devServerApp.use("/assets", expressStatic(distAssetsPath));
|
|
5703
6246
|
} else if (appViteServer) {
|
|
5704
6247
|
devServerApp.use("/local", appViteServer.middlewares);
|
|
@@ -5722,6 +6265,10 @@ var createDevServerRoutes = async (viteServer, appLocals, storybookPort) => {
|
|
|
5722
6265
|
moduleFieldsJson_default
|
|
5723
6266
|
);
|
|
5724
6267
|
devServerApp.get("/module/:moduleName/*", module_default);
|
|
6268
|
+
devServerApp.post(
|
|
6269
|
+
"/preview/module/:moduleName/validate-fields",
|
|
6270
|
+
moduleValidateFields_default
|
|
6271
|
+
);
|
|
5725
6272
|
devServerApp.post("/preview/module/:moduleName", modulePreviewRouteHandler_default);
|
|
5726
6273
|
devServerApp.get("/hublmodule/:modulePath(*)", hublModuleRouteHandler);
|
|
5727
6274
|
devServerApp.get("/template/:templatePath(*)", templateRouteHandler);
|
|
@@ -5932,578 +6479,223 @@ function createHttpsRedirectingServer(opts, handler) {
|
|
|
5932
6479
|
protocol = "http";
|
|
5933
6480
|
} else {
|
|
5934
6481
|
throw new Error(
|
|
5935
|
-
"Unknown issue with incoming data, unknown if http or https"
|
|
5936
|
-
);
|
|
5937
|
-
}
|
|
5938
|
-
const proxy = protocol === "http" ? innerHTTPServer : innerHTTPSServer;
|
|
5939
|
-
if (proxy) {
|
|
5940
|
-
socket.unshift(buffer);
|
|
5941
|
-
proxy.emit("connection", socket);
|
|
5942
|
-
}
|
|
5943
|
-
process.nextTick(() => socket.resume());
|
|
5944
|
-
});
|
|
5945
|
-
});
|
|
5946
|
-
return { server, innerHTTPServer, innerHTTPSServer };
|
|
5947
|
-
}
|
|
5948
|
-
|
|
5949
|
-
// src/lib/getJSRenderingGates.ts
|
|
5950
|
-
import { getAccessToken } from "@hubspot/local-dev-lib/personalAccessKey";
|
|
5951
|
-
|
|
5952
|
-
// src/lib/gates.ts
|
|
5953
|
-
function getGatesFromEnv() {
|
|
5954
|
-
const gates = process.env.GATES ? process.env.GATES.split(",") : [];
|
|
5955
|
-
return gates;
|
|
5956
|
-
}
|
|
5957
|
-
|
|
5958
|
-
// src/lib/getJSRenderingGates.ts
|
|
5959
|
-
var mapEnabledFeaturesToGates = (enabledFeatures) => {
|
|
5960
|
-
return Object.keys(enabledFeatures).reduce((gates, enabledFeature) => {
|
|
5961
|
-
if (enabledFeatures[enabledFeature]) {
|
|
5962
|
-
gates.push(ENABLED_FEATURES_GATE_MAP[enabledFeature]);
|
|
5963
|
-
}
|
|
5964
|
-
return gates;
|
|
5965
|
-
}, []);
|
|
5966
|
-
};
|
|
5967
|
-
async function getJsRenderingGates(portalId, env2, personalAccessKey) {
|
|
5968
|
-
const { enabledFeatures } = await getAccessToken(personalAccessKey, env2, portalId);
|
|
5969
|
-
const envGates = getGatesFromEnv();
|
|
5970
|
-
const gates = mapEnabledFeaturesToGates(enabledFeatures);
|
|
5971
|
-
const mergedGates = [...envGates, ...gates];
|
|
5972
|
-
process.env.GATES = mergedGates.join(",");
|
|
5973
|
-
return mergedGates;
|
|
5974
|
-
}
|
|
5975
|
-
|
|
5976
|
-
// src/createDevServer.ts
|
|
5977
|
-
import {
|
|
5978
|
-
getConfigAccountIfExists as getConfigAccountIfExists8,
|
|
5979
|
-
getConfigDefaultAccountIfExists,
|
|
5980
|
-
validateConfig
|
|
5981
|
-
} from "@hubspot/local-dev-lib/config";
|
|
5982
|
-
import { fetchSecrets } from "@hubspot/local-dev-lib/api/secrets";
|
|
5983
|
-
import { PERSONAL_ACCESS_KEY_AUTH_METHOD } from "@hubspot/local-dev-lib/constants/auth";
|
|
5984
|
-
|
|
5985
|
-
// src/proxyPage/fetchDomains.ts
|
|
5986
|
-
import { http as hsCliHttp10 } from "@hubspot/local-dev-lib/http";
|
|
5987
|
-
|
|
5988
|
-
// src/lib/errors.ts
|
|
5989
|
-
var MISSING_SCOPE_ERROR_PREFIX = `Your personal access key is missing required scopes fetch domains.
|
|
5990
|
-
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
|
|
5991
|
-
`;
|
|
5992
|
-
var OAUTH_ERROR_REGEX = /^This oauth-token \([\w]+\) does not have proper permissions!/;
|
|
5993
|
-
var NOT_PUBLIC_USE_ERROR = `The scope needed for this API call isn't available for public use`;
|
|
5994
|
-
var MissingScopeError = class extends Error {
|
|
5995
|
-
constructor(error) {
|
|
5996
|
-
let messageEnd = "";
|
|
5997
|
-
if (error.error.message.match(OAUTH_ERROR_REGEX)) {
|
|
5998
|
-
messageEnd = error.error.message;
|
|
5999
|
-
}
|
|
6000
|
-
super(`${MISSING_SCOPE_ERROR_PREFIX}
|
|
6001
|
-
${messageEnd}`);
|
|
6002
|
-
Object.setPrototypeOf(this, MissingScopeError.prototype);
|
|
6003
|
-
}
|
|
6004
|
-
};
|
|
6005
|
-
function logMissingScopeWarning(error) {
|
|
6006
|
-
console.warn(error.message);
|
|
6007
|
-
}
|
|
6008
|
-
function isMissingScopeError2(error) {
|
|
6009
|
-
return error.statusCode === 403 && (error.error.message.match(OAUTH_ERROR_REGEX) || error.error.message.startsWith(NOT_PUBLIC_USE_ERROR));
|
|
6010
|
-
}
|
|
6011
|
-
function handleSecretsError(error) {
|
|
6012
|
-
if (error && error.statusCode && error.error) {
|
|
6013
|
-
const { statusCode, error: errorDetails } = error;
|
|
6014
|
-
if ((errorDetails == null ? void 0 : errorDetails.category) === "MISSING_SCOPES") {
|
|
6015
|
-
console.log(
|
|
6016
|
-
"\nMissing scopes for secrets.",
|
|
6017
|
-
"\nSecrets require Serverless functions which are scoped to Enterprise portals.\n"
|
|
6018
|
-
);
|
|
6019
|
-
} else {
|
|
6020
|
-
console.error(`Error ${statusCode}: ${errorDetails.message}`);
|
|
6021
|
-
if (errorDetails.correlationId) {
|
|
6022
|
-
console.error(`Correlation ID: ${errorDetails.correlationId}`);
|
|
6023
|
-
}
|
|
6024
|
-
if (errorDetails.category) {
|
|
6025
|
-
console.error(`Category: ${errorDetails.category}`);
|
|
6026
|
-
}
|
|
6027
|
-
if (errorDetails.links) {
|
|
6028
|
-
if (errorDetails.links.support) {
|
|
6029
|
-
console.error(`Support URL: ${errorDetails.links.support}`);
|
|
6030
|
-
}
|
|
6031
|
-
if (errorDetails.links.forum) {
|
|
6032
|
-
console.error(`Forum URL: ${errorDetails.links.forum}`);
|
|
6033
|
-
}
|
|
6034
|
-
}
|
|
6035
|
-
}
|
|
6036
|
-
} else {
|
|
6037
|
-
console.error("Unexpected error structure:", error);
|
|
6038
|
-
}
|
|
6039
|
-
}
|
|
6040
|
-
|
|
6041
|
-
// src/proxyPage/fetchDomains.ts
|
|
6042
|
-
async function fetchDomains(portalId) {
|
|
6043
|
-
try {
|
|
6044
|
-
const result = (await hsCliHttp10.get(portalId, {
|
|
6045
|
-
url: `/cms/v3/domains`,
|
|
6046
|
-
params: { portalId },
|
|
6047
|
-
responseType: "json"
|
|
6048
|
-
})).data;
|
|
6049
|
-
return result.results;
|
|
6050
|
-
} catch (error) {
|
|
6051
|
-
if (isMissingScopeError2(error)) {
|
|
6052
|
-
throw new MissingScopeError(error);
|
|
6053
|
-
}
|
|
6054
|
-
throw error;
|
|
6055
|
-
}
|
|
6056
|
-
}
|
|
6057
|
-
async function fetchWebsiteDomainNames(portalId) {
|
|
6058
|
-
const domains = await fetchDomains(portalId);
|
|
6059
|
-
const filteredDomains = domains.filter((domain2) => {
|
|
6060
|
-
return domain2.isUsedForBlogPost || domain2.isUsedForSitePage || domain2.isUsedForLandingPage;
|
|
6061
|
-
});
|
|
6062
|
-
const domainNames = filteredDomains.map((r) => r.domain);
|
|
6063
|
-
return domainNames;
|
|
6064
|
-
}
|
|
6065
|
-
|
|
6066
|
-
// src/lib/validateHSPlatform.ts
|
|
6067
|
-
import path16 from "path";
|
|
6068
|
-
import fs8 from "fs";
|
|
6069
|
-
import { http as hsCliHttp11 } from "@hubspot/local-dev-lib/http";
|
|
6070
|
-
var HSPROJECT_JSON = "hsproject.json";
|
|
6071
|
-
function checkFileExists(filePath) {
|
|
6072
|
-
return fs8.existsSync(filePath) && fs8.statSync(filePath).isFile();
|
|
6073
|
-
}
|
|
6074
|
-
function findHSProjectJson(startPath) {
|
|
6075
|
-
let currentDir = startPath;
|
|
6076
|
-
let dirLevel = 0;
|
|
6077
|
-
const maxDirLevel = 4;
|
|
6078
|
-
while (path16.dirname(currentDir) !== currentDir && dirLevel < maxDirLevel) {
|
|
6079
|
-
const filePath = path16.join(currentDir, HSPROJECT_JSON);
|
|
6080
|
-
if (checkFileExists(filePath)) {
|
|
6081
|
-
return filePath;
|
|
6082
|
-
}
|
|
6083
|
-
currentDir = path16.dirname(currentDir);
|
|
6084
|
-
dirLevel++;
|
|
6085
|
-
}
|
|
6086
|
-
console.log(
|
|
6087
|
-
`'${HSPROJECT_JSON}' not found in any parent of dev server target`
|
|
6088
|
-
);
|
|
6089
|
-
return null;
|
|
6090
|
-
}
|
|
6091
|
-
async function validateHSPlatform(projectConfigPath, portalId, deferSelection) {
|
|
6092
|
-
if (projectConfigPath === null) {
|
|
6093
|
-
console.log(
|
|
6094
|
-
`Unable to find local ${HSPROJECT_JSON}, skipping platform version validation.`
|
|
6095
|
-
);
|
|
6096
|
-
return false;
|
|
6097
|
-
}
|
|
6098
|
-
const hsProjectJSONContents = fs8.readFileSync(projectConfigPath, "utf8");
|
|
6099
|
-
const hsProjectJSONData = JSON.parse(hsProjectJSONContents);
|
|
6100
|
-
const { platformVersion } = hsProjectJSONData;
|
|
6101
|
-
let platformVersionResult;
|
|
6102
|
-
try {
|
|
6103
|
-
platformVersionResult = (await hsCliHttp11.get(portalId, {
|
|
6104
|
-
url: `developer/projects/v1/platformVersion`,
|
|
6105
|
-
responseType: "json"
|
|
6106
|
-
})).data;
|
|
6107
|
-
} catch (e) {
|
|
6108
|
-
console.error(e.message);
|
|
6109
|
-
console.log(
|
|
6110
|
-
"Unable to find active platform versions, skipping platform version validation."
|
|
6111
|
-
);
|
|
6112
|
-
return false;
|
|
6113
|
-
}
|
|
6114
|
-
if (platformVersion === void 0 || !platformVersionResult.activePlatformVersions.includes(platformVersion)) {
|
|
6115
|
-
const promptAndWrite = async () => {
|
|
6116
|
-
const { default: select } = await import("@inquirer/select");
|
|
6117
|
-
const answer = await select({
|
|
6118
|
-
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',
|
|
6119
|
-
choices: platformVersionResult.activePlatformVersions.map(
|
|
6120
|
-
(versionNumber) => ({
|
|
6121
|
-
name: versionNumber,
|
|
6122
|
-
value: versionNumber
|
|
6123
|
-
})
|
|
6124
|
-
)
|
|
6125
|
-
});
|
|
6126
|
-
hsProjectJSONData.platformVersion = answer;
|
|
6127
|
-
try {
|
|
6128
|
-
fs8.writeFileSync(
|
|
6129
|
-
projectConfigPath,
|
|
6130
|
-
JSON.stringify(hsProjectJSONData, void 0, 2),
|
|
6131
|
-
"utf8"
|
|
6132
|
-
);
|
|
6133
|
-
return true;
|
|
6134
|
-
} catch (e) {
|
|
6135
|
-
console.error(
|
|
6136
|
-
`unable to write updated valid platform version, please make sure platformVersion in "${HSPROJECT_JSON}" is one of ${platformVersionResult.activePlatformVersions}`
|
|
6482
|
+
"Unknown issue with incoming data, unknown if http or https"
|
|
6137
6483
|
);
|
|
6138
|
-
return false;
|
|
6139
6484
|
}
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6485
|
+
const proxy = protocol === "http" ? innerHTTPServer : innerHTTPSServer;
|
|
6486
|
+
if (proxy) {
|
|
6487
|
+
socket.unshift(buffer);
|
|
6488
|
+
proxy.emit("connection", socket);
|
|
6489
|
+
}
|
|
6490
|
+
process.nextTick(() => socket.resume());
|
|
6491
|
+
});
|
|
6492
|
+
});
|
|
6493
|
+
return { server, innerHTTPServer, innerHTTPSServer };
|
|
6494
|
+
}
|
|
6495
|
+
|
|
6496
|
+
// src/lib/getJSRenderingGates.ts
|
|
6497
|
+
import { getAccessToken } from "@hubspot/local-dev-lib/personalAccessKey";
|
|
6498
|
+
|
|
6499
|
+
// src/lib/gates.ts
|
|
6500
|
+
function getGatesFromEnv() {
|
|
6501
|
+
const gates = process.env.GATES ? process.env.GATES.split(",") : [];
|
|
6502
|
+
return gates;
|
|
6503
|
+
}
|
|
6504
|
+
|
|
6505
|
+
// src/lib/getJSRenderingGates.ts
|
|
6506
|
+
var mapEnabledFeaturesToGates = (enabledFeatures) => {
|
|
6507
|
+
return Object.keys(enabledFeatures).reduce((gates, enabledFeature) => {
|
|
6508
|
+
if (enabledFeatures[enabledFeature]) {
|
|
6509
|
+
gates.push(ENABLED_FEATURES_GATE_MAP[enabledFeature]);
|
|
6144
6510
|
}
|
|
6145
|
-
return
|
|
6146
|
-
}
|
|
6147
|
-
|
|
6511
|
+
return gates;
|
|
6512
|
+
}, []);
|
|
6513
|
+
};
|
|
6514
|
+
async function getJsRenderingGates(portalId, env2, personalAccessKey) {
|
|
6515
|
+
const { enabledFeatures } = await getAccessToken(personalAccessKey, env2, portalId);
|
|
6516
|
+
const envGates = getGatesFromEnv();
|
|
6517
|
+
const gates = mapEnabledFeaturesToGates(enabledFeatures);
|
|
6518
|
+
const mergedGates = [...envGates, ...gates];
|
|
6519
|
+
process.env.GATES = mergedGates.join(",");
|
|
6520
|
+
return mergedGates;
|
|
6148
6521
|
}
|
|
6149
6522
|
|
|
6150
6523
|
// src/createDevServer.ts
|
|
6151
|
-
import {
|
|
6524
|
+
import {
|
|
6525
|
+
getConfigAccountIfExists as getConfigAccountIfExists8,
|
|
6526
|
+
getConfigDefaultAccountIfExists,
|
|
6527
|
+
validateConfig
|
|
6528
|
+
} from "@hubspot/local-dev-lib/config";
|
|
6529
|
+
import { fetchSecrets } from "@hubspot/local-dev-lib/api/secrets";
|
|
6530
|
+
import { PERSONAL_ACCESS_KEY_AUTH_METHOD } from "@hubspot/local-dev-lib/constants/auth";
|
|
6152
6531
|
|
|
6153
|
-
//
|
|
6154
|
-
import {
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
date: "DateFieldType",
|
|
6168
|
-
datetime: "DateTimeFieldType",
|
|
6169
|
-
email: "EmailFieldType",
|
|
6170
|
-
embed: "EmbedFieldType",
|
|
6171
|
-
file: "FileFieldType",
|
|
6172
|
-
followupemail: "FollowUpEmailFieldType",
|
|
6173
|
-
font: "FontFieldType",
|
|
6174
|
-
form: "FormFieldType",
|
|
6175
|
-
gradient: "GradientFieldType",
|
|
6176
|
-
group: "GroupFieldType",
|
|
6177
|
-
html: "HtmlFieldType",
|
|
6178
|
-
hubdbrow: "HubDbRowFieldType",
|
|
6179
|
-
hubdbtable: "HubDbTableFieldType",
|
|
6180
|
-
hubl: "HublFieldType",
|
|
6181
|
-
icon: "IconFieldType",
|
|
6182
|
-
image: "ImageFieldType",
|
|
6183
|
-
link: "LinkFieldType",
|
|
6184
|
-
logo: "LogoFieldType",
|
|
6185
|
-
meeting: "MeetingFieldType",
|
|
6186
|
-
menu: "MenuFieldType",
|
|
6187
|
-
number: "NumberFieldType",
|
|
6188
|
-
page: "PageFieldType",
|
|
6189
|
-
payment: "PaymentFieldType",
|
|
6190
|
-
podcast: "PodcastFieldType",
|
|
6191
|
-
richtext: "RichTextFieldType",
|
|
6192
|
-
salesforcecampaign: "SfdcCamapaignFieldType",
|
|
6193
|
-
simplemenu: "SimpleMenuFieldType",
|
|
6194
|
-
spacing: "SpacingFieldType",
|
|
6195
|
-
survey: "SurveyFieldType",
|
|
6196
|
-
tag: "TagFieldType",
|
|
6197
|
-
textalignment: "TextAlignmentFieldType",
|
|
6198
|
-
text: "TextFieldType",
|
|
6199
|
-
url: "UrlFieldType",
|
|
6200
|
-
variantselection: "VariantSelectionFieldType",
|
|
6201
|
-
videoplayer: "VideoFieldType",
|
|
6202
|
-
workflow: "WorkflowFieldType"
|
|
6203
|
-
};
|
|
6204
|
-
function getFieldEntries(fields) {
|
|
6205
|
-
if (!Array.isArray(fields)) {
|
|
6206
|
-
return void 0;
|
|
6207
|
-
}
|
|
6208
|
-
return fields.filter((field) => field.name && field.type).map((field) => {
|
|
6209
|
-
const { name, type } = field;
|
|
6210
|
-
const fieldType = fieldTypeNameByType[type];
|
|
6211
|
-
if (!fieldType) {
|
|
6212
|
-
return void 0;
|
|
6213
|
-
}
|
|
6214
|
-
const entry = {
|
|
6215
|
-
type: fieldType,
|
|
6216
|
-
name,
|
|
6217
|
-
isRepeater: "occurrence" in field,
|
|
6218
|
-
isRequired: !!field.required,
|
|
6219
|
-
choices: (
|
|
6220
|
-
// Choices are pair [value, label] but only the value is printed to the page, so flatten it.
|
|
6221
|
-
"choices" in field ? field.choices.map(([value, label]) => value) : void 0
|
|
6222
|
-
),
|
|
6223
|
-
children: []
|
|
6224
|
-
};
|
|
6225
|
-
if (fieldType === "GroupFieldType" && "children" in field) {
|
|
6226
|
-
const children = getFieldEntries(field.children);
|
|
6227
|
-
return { ...entry, children };
|
|
6532
|
+
// src/proxyPage/fetchDomains.ts
|
|
6533
|
+
import { http as hsCliHttp11 } from "@hubspot/local-dev-lib/http";
|
|
6534
|
+
|
|
6535
|
+
// src/lib/errors.ts
|
|
6536
|
+
var MISSING_SCOPE_ERROR_PREFIX = `Your personal access key is missing required scopes fetch domains.
|
|
6537
|
+
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
|
|
6538
|
+
`;
|
|
6539
|
+
var OAUTH_ERROR_REGEX = /^This oauth-token \([\w]+\) does not have proper permissions!/;
|
|
6540
|
+
var NOT_PUBLIC_USE_ERROR = `The scope needed for this API call isn't available for public use`;
|
|
6541
|
+
var MissingScopeError = class extends Error {
|
|
6542
|
+
constructor(error) {
|
|
6543
|
+
let messageEnd = "";
|
|
6544
|
+
if (error.error.message.match(OAUTH_ERROR_REGEX)) {
|
|
6545
|
+
messageEnd = error.error.message;
|
|
6228
6546
|
}
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
var INVALID_IMPORTS = ["ChoiceFieldType", "GroupFieldType"];
|
|
6233
|
-
var FIELD_GROUP_TYPE = "FieldGroupWithChildren";
|
|
6234
|
-
var REPEATER_GROUP_TYPE = "RepeaterGroup";
|
|
6235
|
-
var REQUIRED_TYPE = "RequiredField";
|
|
6236
|
-
var DEFAULT_VALUES_TYPE = "DefaultValues";
|
|
6237
|
-
var CMS_COMPONENTS = "@hubspot/cms-components";
|
|
6238
|
-
var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
6239
|
-
var AUTO_GEN_COMMENT = "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.";
|
|
6240
|
-
var createPropertySignature = (identifier, type, hasQuestionToken = false) => ts.factory.createPropertySignature(
|
|
6241
|
-
[],
|
|
6242
|
-
identifier,
|
|
6243
|
-
hasQuestionToken ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) : void 0,
|
|
6244
|
-
type
|
|
6245
|
-
);
|
|
6246
|
-
var createUnionTypeFromArray = (values) => ts.factory.createUnionTypeNode(
|
|
6247
|
-
values.map(
|
|
6248
|
-
(value) => ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(value))
|
|
6249
|
-
)
|
|
6250
|
-
);
|
|
6251
|
-
var buildTypeFromField = (field, additionalNode) => {
|
|
6252
|
-
const imports = [field.type];
|
|
6253
|
-
const identifier = ts.factory.createIdentifier(field.name);
|
|
6254
|
-
const baseType = ts.factory.createTypeReferenceNode(field.type);
|
|
6255
|
-
const requiredType = ts.factory.createTypeReferenceNode(REQUIRED_TYPE, [
|
|
6256
|
-
baseType
|
|
6257
|
-
]);
|
|
6258
|
-
let finalType = field.isRequired ? requiredType : baseType;
|
|
6259
|
-
if (field.choices) {
|
|
6260
|
-
finalType = createUnionTypeFromArray(field.choices);
|
|
6261
|
-
}
|
|
6262
|
-
if (field.isRequired) {
|
|
6263
|
-
imports.push(REQUIRED_TYPE);
|
|
6264
|
-
}
|
|
6265
|
-
if (additionalNode) {
|
|
6266
|
-
const typeLiteral = ts.isTypeLiteralNode(additionalNode) ? additionalNode : ts.factory.createTypeLiteralNode([additionalNode]);
|
|
6267
|
-
const genericType = field.isRepeater ? REPEATER_GROUP_TYPE : FIELD_GROUP_TYPE;
|
|
6268
|
-
imports.push(genericType);
|
|
6269
|
-
finalType = ts.factory.createTypeReferenceNode(genericType, [typeLiteral]);
|
|
6547
|
+
super(`${MISSING_SCOPE_ERROR_PREFIX}
|
|
6548
|
+
${messageEnd}`);
|
|
6549
|
+
Object.setPrototypeOf(this, MissingScopeError.prototype);
|
|
6270
6550
|
}
|
|
6271
|
-
return {
|
|
6272
|
-
type: createPropertySignature(
|
|
6273
|
-
identifier,
|
|
6274
|
-
finalType,
|
|
6275
|
-
!field.isRequired && !additionalNode
|
|
6276
|
-
),
|
|
6277
|
-
imports
|
|
6278
|
-
};
|
|
6279
6551
|
};
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
const visit = (node) => {
|
|
6283
|
-
if (ts.isTypeReferenceNode(node)) {
|
|
6284
|
-
const typeName = node.typeName;
|
|
6285
|
-
if ("escapedText" in typeName) {
|
|
6286
|
-
usedImports.add(typeName.escapedText.toString());
|
|
6287
|
-
}
|
|
6288
|
-
}
|
|
6289
|
-
ts.forEachChild(node, visit);
|
|
6290
|
-
};
|
|
6291
|
-
visit(type);
|
|
6292
|
-
return imports.filter((name) => usedImports.has(name));
|
|
6293
|
-
};
|
|
6294
|
-
function getImportDeclaration(imports, moduleSpecifier) {
|
|
6295
|
-
const importSpecifiers = Array.from(imports).map(
|
|
6296
|
-
(importName) => ts.factory.createImportSpecifier(
|
|
6297
|
-
true,
|
|
6298
|
-
void 0,
|
|
6299
|
-
ts.factory.createIdentifier(importName)
|
|
6300
|
-
)
|
|
6301
|
-
);
|
|
6302
|
-
const namedImports = ts.factory.createNamedImports(importSpecifiers);
|
|
6303
|
-
return ts.factory.createImportDeclaration(
|
|
6304
|
-
[],
|
|
6305
|
-
[],
|
|
6306
|
-
ts.factory.createImportClause(false, void 0, namedImports),
|
|
6307
|
-
ts.factory.createStringLiteral(moduleSpecifier)
|
|
6308
|
-
);
|
|
6552
|
+
function logMissingScopeWarning(error) {
|
|
6553
|
+
console.warn(error.message);
|
|
6309
6554
|
}
|
|
6310
|
-
function
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
6555
|
+
function isMissingScopeError2(error) {
|
|
6556
|
+
return error.statusCode === 403 && (error.error.message.match(OAUTH_ERROR_REGEX) || error.error.message.startsWith(NOT_PUBLIC_USE_ERROR));
|
|
6557
|
+
}
|
|
6558
|
+
function handleSecretsError(error) {
|
|
6559
|
+
if (error && error.statusCode && error.error) {
|
|
6560
|
+
const { statusCode, error: errorDetails } = error;
|
|
6561
|
+
if ((errorDetails == null ? void 0 : errorDetails.category) === "MISSING_SCOPES") {
|
|
6562
|
+
console.log(
|
|
6563
|
+
"\nMissing scopes for secrets.",
|
|
6564
|
+
"\nSecrets require Serverless functions which are scoped to Enterprise portals.\n"
|
|
6565
|
+
);
|
|
6566
|
+
} else {
|
|
6567
|
+
console.error(`Error ${statusCode}: ${errorDetails.message}`);
|
|
6568
|
+
if (errorDetails.correlationId) {
|
|
6569
|
+
console.error(`Correlation ID: ${errorDetails.correlationId}`);
|
|
6570
|
+
}
|
|
6571
|
+
if (errorDetails.category) {
|
|
6572
|
+
console.error(`Category: ${errorDetails.category}`);
|
|
6573
|
+
}
|
|
6574
|
+
if (errorDetails.links) {
|
|
6575
|
+
if (errorDetails.links.support) {
|
|
6576
|
+
console.error(`Support URL: ${errorDetails.links.support}`);
|
|
6577
|
+
}
|
|
6578
|
+
if (errorDetails.links.forum) {
|
|
6579
|
+
console.error(`Forum URL: ${errorDetails.links.forum}`);
|
|
6580
|
+
}
|
|
6324
6581
|
}
|
|
6325
6582
|
}
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6583
|
+
} else {
|
|
6584
|
+
console.error("Unexpected error structure:", error);
|
|
6585
|
+
}
|
|
6586
|
+
}
|
|
6587
|
+
|
|
6588
|
+
// src/proxyPage/fetchDomains.ts
|
|
6589
|
+
async function fetchDomains(portalId) {
|
|
6590
|
+
try {
|
|
6591
|
+
const result = (await hsCliHttp11.get(portalId, {
|
|
6592
|
+
url: `/cms/v3/domains`,
|
|
6593
|
+
params: { portalId },
|
|
6594
|
+
responseType: "json"
|
|
6595
|
+
})).data;
|
|
6596
|
+
return result.results;
|
|
6597
|
+
} catch (error) {
|
|
6598
|
+
if (isMissingScopeError2(error)) {
|
|
6599
|
+
throw new MissingScopeError(error);
|
|
6600
|
+
}
|
|
6601
|
+
throw error;
|
|
6602
|
+
}
|
|
6603
|
+
}
|
|
6604
|
+
async function fetchWebsiteDomainNames(portalId) {
|
|
6605
|
+
const domains = await fetchDomains(portalId);
|
|
6606
|
+
const filteredDomains = domains.filter((domain2) => {
|
|
6607
|
+
return domain2.isUsedForBlogPost || domain2.isUsedForSitePage || domain2.isUsedForLandingPage;
|
|
6329
6608
|
});
|
|
6330
|
-
const
|
|
6331
|
-
|
|
6332
|
-
);
|
|
6333
|
-
return { types, imports: validImports };
|
|
6609
|
+
const domainNames = filteredDomains.map((r) => r.domain);
|
|
6610
|
+
return domainNames;
|
|
6334
6611
|
}
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
);
|
|
6344
|
-
const wrappedType = ts.factory.createTypeReferenceNode(DEFAULT_VALUES_TYPE, [
|
|
6345
|
-
baseType.type
|
|
6346
|
-
]);
|
|
6347
|
-
const finalType = ts.factory.createTypeAliasDeclaration(
|
|
6348
|
-
[],
|
|
6349
|
-
[],
|
|
6350
|
-
typeName,
|
|
6351
|
-
void 0,
|
|
6352
|
-
wrappedType
|
|
6353
|
-
);
|
|
6354
|
-
const filteredImports = filterUnusedImports(imports, finalType);
|
|
6355
|
-
const importDeclaration = getImportDeclaration(
|
|
6356
|
-
[...filteredImports, DEFAULT_VALUES_TYPE],
|
|
6357
|
-
CMS_COMPONENTS_FIELD_TYPES
|
|
6358
|
-
);
|
|
6359
|
-
const defaultExport = ts.factory.createExportDefault(
|
|
6360
|
-
ts.factory.createIdentifier(typeName)
|
|
6361
|
-
);
|
|
6362
|
-
return [importDeclaration, finalType, defaultExport];
|
|
6612
|
+
|
|
6613
|
+
// src/lib/validateHSPlatform.ts
|
|
6614
|
+
import path19 from "path";
|
|
6615
|
+
import fs11 from "fs";
|
|
6616
|
+
import { http as hsCliHttp12 } from "@hubspot/local-dev-lib/http";
|
|
6617
|
+
var HSPROJECT_JSON = "hsproject.json";
|
|
6618
|
+
function checkFileExists(filePath) {
|
|
6619
|
+
return fs11.existsSync(filePath) && fs11.statSync(filePath).isFile();
|
|
6363
6620
|
}
|
|
6364
|
-
function
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6621
|
+
function findHSProjectJson(startPath) {
|
|
6622
|
+
let currentDir = startPath;
|
|
6623
|
+
let dirLevel = 0;
|
|
6624
|
+
const maxDirLevel = 4;
|
|
6625
|
+
while (path19.dirname(currentDir) !== currentDir && dirLevel < maxDirLevel) {
|
|
6626
|
+
const filePath = path19.join(currentDir, HSPROJECT_JSON);
|
|
6627
|
+
if (checkFileExists(filePath)) {
|
|
6628
|
+
return filePath;
|
|
6629
|
+
}
|
|
6630
|
+
currentDir = path19.dirname(currentDir);
|
|
6631
|
+
dirLevel++;
|
|
6368
6632
|
}
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
const nodes = constructFinalType(entries, typeName);
|
|
6379
|
-
const comments = [
|
|
6380
|
-
AUTO_GEN_COMMENT,
|
|
6381
|
-
"Removing the above comment will disable type generation for this module",
|
|
6382
|
-
"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"
|
|
6383
|
-
].map((comment) => `// ${comment}`);
|
|
6384
|
-
const typeResult = nodes.map(
|
|
6385
|
-
(node) => printer.printNode(ts.EmitHint.Unspecified, node, file)
|
|
6633
|
+
console.log(
|
|
6634
|
+
`'${HSPROJECT_JSON}' not found in any parent of dev server target`
|
|
6635
|
+
);
|
|
6636
|
+
return null;
|
|
6637
|
+
}
|
|
6638
|
+
async function validateHSPlatform(projectConfigPath, portalId, deferSelection) {
|
|
6639
|
+
if (projectConfigPath === null) {
|
|
6640
|
+
console.log(
|
|
6641
|
+
`Unable to find local ${HSPROJECT_JSON}, skipping platform version validation.`
|
|
6386
6642
|
);
|
|
6387
|
-
const result = [...comments, ...typeResult].join("\n");
|
|
6388
|
-
writeFileSync(fileName, result);
|
|
6389
|
-
return true;
|
|
6390
|
-
} catch (e) {
|
|
6391
|
-
console.error(e);
|
|
6392
6643
|
return false;
|
|
6393
6644
|
}
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
import path17 from "path";
|
|
6399
|
-
import readline from "readline";
|
|
6400
|
-
var lastSerializedFieldsCache = {};
|
|
6401
|
-
var formatAsTypeName = (str) => {
|
|
6402
|
-
const typeName = `${str.replace(/[^a-zA-Z0-9_$]/g, "_")}FieldsType`;
|
|
6403
|
-
const validFirstChar = /^[A-Za-z_$]/.test(str.charAt(0));
|
|
6404
|
-
return validFirstChar ? typeName : `_${typeName}`;
|
|
6405
|
-
};
|
|
6406
|
-
var isInModulesFolder = (filePath, projectRoot) => {
|
|
6407
|
-
const getEntryPathFromId = (id) => {
|
|
6408
|
-
return id.startsWith(projectRoot) ? id.replace(`${projectRoot}${path17.sep}`, "") : "";
|
|
6409
|
-
};
|
|
6410
|
-
const currentModuleId = path17.normalize(filePath);
|
|
6411
|
-
const moduleEntryPath = getEntryPathFromId(currentModuleId);
|
|
6412
|
-
const subFolderTokens = moduleEntryPath.split(path17.sep);
|
|
6413
|
-
return {
|
|
6414
|
-
inModuleFolder: subFolderTokens[0] === "components" && subFolderTokens[1] === "modules",
|
|
6415
|
-
isRootModuleFile: subFolderTokens.length === 3
|
|
6416
|
-
};
|
|
6417
|
-
};
|
|
6418
|
-
var fileContainsAutoGenComment = async (filePath) => {
|
|
6419
|
-
if (!fs9.existsSync(filePath))
|
|
6420
|
-
return true;
|
|
6421
|
-
const stream2 = fs9.createReadStream(filePath);
|
|
6422
|
-
const reader = readline.createInterface({ input: stream2 });
|
|
6423
|
-
const firstLine = await new Promise(
|
|
6424
|
-
(resolve3) => reader.once("line", (line) => resolve3(line.trim()))
|
|
6425
|
-
);
|
|
6426
|
-
reader.close();
|
|
6427
|
-
stream2.close();
|
|
6428
|
-
return firstLine && firstLine === `// ${AUTO_GEN_COMMENT}`;
|
|
6429
|
-
};
|
|
6430
|
-
var getIndexFile = (filePath, projectRoot) => {
|
|
6431
|
-
const { inModuleFolder, isRootModuleFile } = isInModulesFolder(
|
|
6432
|
-
filePath,
|
|
6433
|
-
projectRoot
|
|
6434
|
-
);
|
|
6435
|
-
if (!inModuleFolder)
|
|
6436
|
-
return void 0;
|
|
6437
|
-
if (isRootModuleFile)
|
|
6438
|
-
return { indexFilePath: filePath, isRootModuleFile };
|
|
6439
|
-
const dir = path17.dirname(filePath);
|
|
6440
|
-
const files = fs9.readdirSync(dir);
|
|
6441
|
-
const indexFileName = files.find((file) => file.startsWith("index."));
|
|
6442
|
-
return indexFileName ? { indexFilePath: path17.join(dir, indexFileName), isRootModuleFile } : void 0;
|
|
6443
|
-
};
|
|
6444
|
-
var getIndexFileFields = async (indexFilePath, indexFileName, viteServer) => {
|
|
6445
|
-
let indexFile;
|
|
6446
|
-
let renderFieldsToJson;
|
|
6645
|
+
const hsProjectJSONContents = fs11.readFileSync(projectConfigPath, "utf8");
|
|
6646
|
+
const hsProjectJSONData = JSON.parse(hsProjectJSONContents);
|
|
6647
|
+
const { platformVersion } = hsProjectJSONData;
|
|
6648
|
+
let platformVersionResult;
|
|
6447
6649
|
try {
|
|
6448
|
-
|
|
6449
|
-
|
|
6450
|
-
|
|
6650
|
+
platformVersionResult = (await hsCliHttp12.get(portalId, {
|
|
6651
|
+
url: `developer/projects/v1/platformVersion`,
|
|
6652
|
+
responseType: "json"
|
|
6653
|
+
})).data;
|
|
6451
6654
|
} catch (e) {
|
|
6452
|
-
|
|
6655
|
+
console.error(e.message);
|
|
6656
|
+
console.log(
|
|
6657
|
+
"Unable to find active platform versions, skipping platform version validation."
|
|
6658
|
+
);
|
|
6659
|
+
return false;
|
|
6453
6660
|
}
|
|
6454
|
-
if (!
|
|
6455
|
-
|
|
6456
|
-
|
|
6457
|
-
|
|
6458
|
-
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
|
|
6466
|
-
|
|
6467
|
-
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
return;
|
|
6485
|
-
const moduleFolderName = path17.basename(path17.dirname(filePath));
|
|
6486
|
-
const outputTypeName = formatAsTypeName(moduleFolderName);
|
|
6487
|
-
const didSucceed = writeFieldsType(fields, typeFilePath, outputTypeName);
|
|
6488
|
-
if (didSucceed) {
|
|
6489
|
-
lastSerializedFieldsCache[typeFilePath] = serializedFields;
|
|
6661
|
+
if (platformVersion === void 0 || !platformVersionResult.activePlatformVersions.includes(platformVersion)) {
|
|
6662
|
+
const promptAndWrite = async () => {
|
|
6663
|
+
const { default: select } = await import("@inquirer/select");
|
|
6664
|
+
const answer = await select({
|
|
6665
|
+
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',
|
|
6666
|
+
choices: platformVersionResult.activePlatformVersions.map(
|
|
6667
|
+
(versionNumber) => ({
|
|
6668
|
+
name: versionNumber,
|
|
6669
|
+
value: versionNumber
|
|
6670
|
+
})
|
|
6671
|
+
)
|
|
6672
|
+
});
|
|
6673
|
+
hsProjectJSONData.platformVersion = answer;
|
|
6674
|
+
try {
|
|
6675
|
+
fs11.writeFileSync(
|
|
6676
|
+
projectConfigPath,
|
|
6677
|
+
JSON.stringify(hsProjectJSONData, void 0, 2),
|
|
6678
|
+
"utf8"
|
|
6679
|
+
);
|
|
6680
|
+
return true;
|
|
6681
|
+
} catch (e) {
|
|
6682
|
+
console.error(
|
|
6683
|
+
`unable to write updated valid platform version, please make sure platformVersion in "${HSPROJECT_JSON}" is one of ${platformVersionResult.activePlatformVersions}`
|
|
6684
|
+
);
|
|
6685
|
+
return false;
|
|
6686
|
+
}
|
|
6687
|
+
};
|
|
6688
|
+
if (deferSelection) {
|
|
6689
|
+
deferSelection(promptAndWrite);
|
|
6690
|
+
return false;
|
|
6490
6691
|
}
|
|
6491
|
-
|
|
6492
|
-
const successMsg = `Successfully generated types for ${pathToLog}`;
|
|
6493
|
-
const errorMsg = `Failed to generate types for ${pathToLog}`;
|
|
6494
|
-
const message = didSucceed ? successMsg : errorMsg;
|
|
6495
|
-
console.log(wrapMessageInColor(didSucceed ? "green" : "red", message));
|
|
6692
|
+
return promptAndWrite();
|
|
6496
6693
|
}
|
|
6497
|
-
|
|
6498
|
-
|
|
6499
|
-
|
|
6500
|
-
|
|
6501
|
-
|
|
6502
|
-
maybeUpdateFields(resolvedPath, viteServer, projectRoot);
|
|
6503
|
-
});
|
|
6504
|
-
const watchCallback = (filePath) => maybeUpdateFields(filePath, viteServer, projectRoot);
|
|
6505
|
-
viteServer.watcher.on("add", watchCallback).on("change", watchCallback);
|
|
6506
|
-
};
|
|
6694
|
+
return true;
|
|
6695
|
+
}
|
|
6696
|
+
|
|
6697
|
+
// src/createDevServer.ts
|
|
6698
|
+
import { http as hsCliHttp13 } from "@hubspot/local-dev-lib/http";
|
|
6507
6699
|
|
|
6508
6700
|
// src/lib/configHelpers.ts
|
|
6509
6701
|
function getSecretNamesFromConfig(config) {
|
|
@@ -6530,8 +6722,8 @@ function getWebRootProjectComponentFolder(absoluteWebRoot, projectConfigPath) {
|
|
|
6530
6722
|
return themeFolderName;
|
|
6531
6723
|
}
|
|
6532
6724
|
try {
|
|
6533
|
-
const projectDir =
|
|
6534
|
-
const configContent =
|
|
6725
|
+
const projectDir = path20.dirname(projectConfigPath);
|
|
6726
|
+
const configContent = fs12.readFileSync(projectConfigPath, "utf8");
|
|
6535
6727
|
const projectConfig = JSON.parse(configContent);
|
|
6536
6728
|
if (hasNewDirectoryStructure(projectConfig.platformVersion)) {
|
|
6537
6729
|
const srcDir = projectConfig.srcDir || "src";
|
|
@@ -6601,7 +6793,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
6601
6793
|
}
|
|
6602
6794
|
setTrackingInfo(authedPortalId, authedEnv);
|
|
6603
6795
|
sendTrackingRequest("start-dev-server");
|
|
6604
|
-
const absoluteWebRoot = normalizePath10(
|
|
6796
|
+
const absoluteWebRoot = normalizePath10(path20.resolve(process.cwd(), webRoot2));
|
|
6605
6797
|
const projectConfigPath = findHSProjectJson(absoluteWebRoot);
|
|
6606
6798
|
const webRootProjectComponentFolder = getWebRootProjectComponentFolder(
|
|
6607
6799
|
absoluteWebRoot,
|
|
@@ -6673,7 +6865,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
6673
6865
|
});
|
|
6674
6866
|
bootTasks.push(async () => {
|
|
6675
6867
|
try {
|
|
6676
|
-
const accountInformation = (await
|
|
6868
|
+
const accountInformation = (await hsCliHttp13.get(portalId, {
|
|
6677
6869
|
url: "/account-info/v3/details"
|
|
6678
6870
|
})).data;
|
|
6679
6871
|
authedHublet = accountInformation.dataHostingLocation;
|
|
@@ -6715,7 +6907,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
6715
6907
|
secretNames
|
|
6716
6908
|
);
|
|
6717
6909
|
if (fieldGenEnabledOption2) {
|
|
6718
|
-
const normalizedAbsoluteWebRoot =
|
|
6910
|
+
const normalizedAbsoluteWebRoot = path20.normalize(absoluteWebRoot);
|
|
6719
6911
|
startFieldsTypeGenWatcher(viteServer, normalizedAbsoluteWebRoot);
|
|
6720
6912
|
}
|
|
6721
6913
|
const viteHTTPSConfig = viteServer.config.server.https;
|
|
@@ -6741,10 +6933,10 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
6741
6933
|
expressServer.locals.sslEnabled = sslEnabledOption2;
|
|
6742
6934
|
expressServer.locals.fullHeightPreview = fullHeightPreview;
|
|
6743
6935
|
expressServer.use(bodyParser.json());
|
|
6744
|
-
const __dirname =
|
|
6745
|
-
let appWebRoot = normalizePath10(
|
|
6936
|
+
const __dirname = path20.dirname(url2.fileURLToPath(new URL(import.meta.url)));
|
|
6937
|
+
let appWebRoot = normalizePath10(path20.resolve(__dirname, "../app"));
|
|
6746
6938
|
if (true) {
|
|
6747
|
-
appWebRoot =
|
|
6939
|
+
appWebRoot = path20.join(__dirname, "app");
|
|
6748
6940
|
}
|
|
6749
6941
|
const skipUiServer = isLocalUiDisabled(cmsAssetConfig);
|
|
6750
6942
|
const appViteServer = skipUiServer ? null : await createAppServer_default(appWebRoot, PORT, sslEnabledOption2);
|
|
@@ -6812,17 +7004,17 @@ HubSpot CMS dev server running at ${protocol}://hslocal.net:${PORT}${extraServer
|
|
|
6812
7004
|
`;
|
|
6813
7005
|
console.log(startMessage);
|
|
6814
7006
|
if (storybook2) {
|
|
6815
|
-
const packageRoot =
|
|
6816
|
-
const configPath =
|
|
7007
|
+
const packageRoot = path20.dirname(url2.fileURLToPath(import.meta.url));
|
|
7008
|
+
const configPath = path20.resolve(packageRoot, "./storybook-main");
|
|
6817
7009
|
sendTrackingRequest("start-storybook");
|
|
6818
7010
|
let storybookBin;
|
|
6819
7011
|
try {
|
|
6820
7012
|
const sbPackagePath = await import.meta.resolve("storybook/package.json");
|
|
6821
|
-
const sbPackageDir =
|
|
7013
|
+
const sbPackageDir = path20.dirname(url2.fileURLToPath(sbPackagePath));
|
|
6822
7014
|
const packageJson = JSON.parse(
|
|
6823
|
-
|
|
7015
|
+
fs12.readFileSync(path20.join(sbPackageDir, "package.json"), "utf-8")
|
|
6824
7016
|
);
|
|
6825
|
-
storybookBin =
|
|
7017
|
+
storybookBin = path20.join(
|
|
6826
7018
|
sbPackageDir,
|
|
6827
7019
|
packageJson.bin.storybook || packageJson.bin
|
|
6828
7020
|
);
|
|
@@ -6859,7 +7051,7 @@ HubSpot CMS dev server running at ${protocol}://hslocal.net:${PORT}${extraServer
|
|
|
6859
7051
|
portalId: authedPortalId.toString(),
|
|
6860
7052
|
hsEnv: authedEnv,
|
|
6861
7053
|
hublet: authedHublet,
|
|
6862
|
-
WEB_ROOT:
|
|
7054
|
+
WEB_ROOT: path20.join(webRoot2, "components")
|
|
6863
7055
|
},
|
|
6864
7056
|
stdio: "inherit"
|
|
6865
7057
|
}
|