@hubspot/cms-dev-server 0.15.8 → 0.15.10
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/index.js +0 -2
- package/dist/internalSsr.js +2 -268
- package/dist/run.js +359 -354
- package/dist/storybook/index.js +1 -3
- package/dist/storybook-main/main.js +3 -269
- package/package.json +10 -10
package/dist/run.js
CHANGED
|
@@ -412,9 +412,6 @@ import stream from "stream";
|
|
|
412
412
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
413
413
|
import * as cmsComponents from "@hubspot/cms-components";
|
|
414
414
|
import { ServerRenderContext } from "@hubspot/cms-components";
|
|
415
|
-
import { writeFileSync } from "fs";
|
|
416
|
-
import ts from "typescript";
|
|
417
|
-
import React, { isValidElement, cloneElement } from "react";
|
|
418
415
|
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
419
416
|
var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
|
|
420
417
|
const islandsArrayToSerialize = tweakedIslandsArray.map(
|
|
@@ -658,358 +655,99 @@ async function renderOnServer(elements, renderContext = bootStrapRenderContext()
|
|
|
658
655
|
}
|
|
659
656
|
return { html, renderContext };
|
|
660
657
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
backgroundimage: "BackgroundImageFieldType",
|
|
665
|
-
blog: "BlogFieldType",
|
|
666
|
-
boolean: "BooleanFieldType",
|
|
667
|
-
border: "BorderFieldType",
|
|
668
|
-
choice: "ChoiceFieldType",
|
|
669
|
-
color: "ColorFieldType",
|
|
670
|
-
crmobject: "CrmObjectFieldType",
|
|
671
|
-
cta: "CtaFieldType",
|
|
672
|
-
date: "DateFieldType",
|
|
673
|
-
datetime: "DateTimeFieldType",
|
|
674
|
-
email: "EmailFieldType",
|
|
675
|
-
embed: "EmbedFieldType",
|
|
676
|
-
file: "FileFieldType",
|
|
677
|
-
followupemail: "FollowUpEmailFieldType",
|
|
678
|
-
font: "FontFieldType",
|
|
679
|
-
form: "FormFieldType",
|
|
680
|
-
gradient: "GradientFieldType",
|
|
681
|
-
group: "GroupFieldType",
|
|
682
|
-
html: "HtmlFieldType",
|
|
683
|
-
hubdbrow: "HubDbRowFieldType",
|
|
684
|
-
hubdbtable: "HubDbTableFieldType",
|
|
685
|
-
hubl: "HublFieldType",
|
|
686
|
-
icon: "IconFieldType",
|
|
687
|
-
image: "ImageFieldType",
|
|
688
|
-
link: "LinkFieldType",
|
|
689
|
-
logo: "LogoFieldType",
|
|
690
|
-
meeting: "MeetingFieldType",
|
|
691
|
-
menu: "MenuFieldType",
|
|
692
|
-
number: "NumberFieldType",
|
|
693
|
-
page: "PageFieldType",
|
|
694
|
-
payment: "PaymentFieldType",
|
|
695
|
-
podcast: "PodcastFieldType",
|
|
696
|
-
richtext: "RichTextFieldType",
|
|
697
|
-
salesforcecampaign: "SfdcCamapaignFieldType",
|
|
698
|
-
simplemenu: "SimpleMenuFieldType",
|
|
699
|
-
spacing: "SpacingFieldType",
|
|
700
|
-
survey: "SurveyFieldType",
|
|
701
|
-
tag: "TagFieldType",
|
|
702
|
-
textalignment: "TextAlignmentFieldType",
|
|
703
|
-
text: "TextFieldType",
|
|
704
|
-
url: "UrlFieldType",
|
|
705
|
-
video: "VideoFieldType",
|
|
706
|
-
workflow: "WorkflowFieldType"
|
|
707
|
-
};
|
|
708
|
-
var getChildrenAsArray = (element) => React.Children.toArray(element.props.children);
|
|
709
|
-
function getFieldEntries(fields) {
|
|
710
|
-
if (isValidElement(fields)) {
|
|
711
|
-
const fieldsJSX = getChildrenAsArray(fields);
|
|
712
|
-
return getReactFieldEntries(fieldsJSX);
|
|
713
|
-
} else if (Array.isArray(fields)) {
|
|
714
|
-
return getJSONFieldEntries(fields);
|
|
658
|
+
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
|
|
659
|
+
if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
|
|
660
|
+
prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
|
|
715
661
|
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
662
|
+
const serializedJson = jsonStringifyAndEscapeForInlineJS(
|
|
663
|
+
environmentConfig.toJSON(),
|
|
664
|
+
{ baseIndent: 6, prettyPrint }
|
|
665
|
+
);
|
|
666
|
+
const globals = [`window.__hsEnvConfig = ${serializedJson};`];
|
|
667
|
+
if (hsServerPageUrl) {
|
|
668
|
+
globals.push(
|
|
669
|
+
`window.__hsServerPageUrl = ${jsonStringifyAndEscapeForInlineJS(
|
|
670
|
+
hsServerPageUrl
|
|
671
|
+
)};`
|
|
672
|
+
);
|
|
725
673
|
}
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
if (!Array.isArray(fields)) {
|
|
731
|
-
return;
|
|
674
|
+
if (hsBasePath) {
|
|
675
|
+
globals.push(
|
|
676
|
+
`window.__hsBasePath = ${jsonStringifyAndEscapeForInlineJS(hsBasePath)};`
|
|
677
|
+
);
|
|
732
678
|
}
|
|
733
|
-
|
|
734
|
-
const
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
children: []
|
|
747
|
-
};
|
|
748
|
-
if (fieldType === "GroupFieldType") {
|
|
749
|
-
const childrenArray = getChildrenAsArray(field);
|
|
750
|
-
const children = getReactFieldEntries(childrenArray);
|
|
751
|
-
return {
|
|
752
|
-
...entry,
|
|
753
|
-
children
|
|
754
|
-
};
|
|
755
|
-
}
|
|
756
|
-
return entry;
|
|
757
|
-
}).filter((entry) => entry !== void 0);
|
|
758
|
-
}
|
|
759
|
-
function getJSONFieldEntries(fields) {
|
|
760
|
-
if (!Array.isArray(fields)) {
|
|
761
|
-
return;
|
|
679
|
+
if (!environmentConfig.getIsDeployed() && (criticalDevErrors == null ? void 0 : criticalDevErrors.length)) {
|
|
680
|
+
const firstCriticalDevError = criticalDevErrors[0];
|
|
681
|
+
globals.push(`
|
|
682
|
+
customElements.whenDefined('vite-error-overlay').then(() => {
|
|
683
|
+
const ErrorOverlay = customElements.get('vite-error-overlay');
|
|
684
|
+
const error = new Error(${jsonStringifyAndEscapeForInlineJS(
|
|
685
|
+
firstCriticalDevError.message
|
|
686
|
+
)});
|
|
687
|
+
const overlay = new ErrorOverlay(error);
|
|
688
|
+
|
|
689
|
+
document.body.appendChild(overlay);
|
|
690
|
+
})
|
|
691
|
+
`);
|
|
762
692
|
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
const entry = {
|
|
770
|
-
type: fieldType,
|
|
771
|
-
name,
|
|
772
|
-
isRepeater: "occurrence" in field,
|
|
773
|
-
hasDefault: !!field.default,
|
|
774
|
-
children: []
|
|
775
|
-
};
|
|
776
|
-
if (fieldType === "GroupFieldType" && "children" in field) {
|
|
777
|
-
const children = getJSONFieldEntries(field.children);
|
|
778
|
-
return { ...entry, children };
|
|
779
|
-
}
|
|
780
|
-
return entry;
|
|
781
|
-
}).filter((entry) => entry !== void 0);
|
|
693
|
+
const nonceAttr = includeNonces && cmsComponents.SCRIPT_NONCE_PLACEHOLDER ? ` nonce="${cmsComponents.SCRIPT_NONCE_PLACEHOLDER}"` : "";
|
|
694
|
+
return `
|
|
695
|
+
<script type="text/javascript"${nonceAttr}>
|
|
696
|
+
${globals.join("\n ")}
|
|
697
|
+
</script>
|
|
698
|
+
`;
|
|
782
699
|
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
var
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
700
|
+
|
|
701
|
+
// src/lib/moduleGraph.ts
|
|
702
|
+
var findFullPathInModuleGraph = (modulePathNoExtension, moduleGraph) => {
|
|
703
|
+
for (const extension of COMPONENT_EXTENSIONS) {
|
|
704
|
+
const pathToTry = `${modulePathNoExtension}${extension}`;
|
|
705
|
+
if (moduleGraph.fileToModulesMap.has(pathToTry)) {
|
|
706
|
+
return pathToTry;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
// src/lib/pathHelpers.ts
|
|
712
|
+
var getComponentPaths = (viteServer, componentPath) => {
|
|
713
|
+
let componentPathWithExtension;
|
|
714
|
+
let componentPathNoExtension;
|
|
715
|
+
if (hasComponentExtension(componentPath)) {
|
|
716
|
+
componentPathWithExtension = componentPath;
|
|
717
|
+
componentPathNoExtension = removeComponentExtension(componentPath);
|
|
718
|
+
} else {
|
|
719
|
+
componentPathNoExtension = componentPath;
|
|
720
|
+
}
|
|
721
|
+
if (!componentPathWithExtension) {
|
|
722
|
+
componentPathWithExtension = findFullPathInModuleGraph(
|
|
723
|
+
componentPathNoExtension,
|
|
724
|
+
viteServer.moduleGraph
|
|
803
725
|
);
|
|
804
|
-
if (!
|
|
805
|
-
|
|
726
|
+
if (!componentPathWithExtension) {
|
|
727
|
+
throw new Error(
|
|
728
|
+
`Couldn't find full path to component: ${componentPathNoExtension}`
|
|
729
|
+
);
|
|
806
730
|
}
|
|
807
|
-
finalType = field.isRepeater ? ts.factory.createTypeReferenceNode("Array", [
|
|
808
|
-
ts.factory.createTypeReferenceNode("Record", [
|
|
809
|
-
repeaterName,
|
|
810
|
-
typeLiteral
|
|
811
|
-
])
|
|
812
|
-
]) : ts.factory.createTypeReferenceNode(OVERRIDE_TYPE, [
|
|
813
|
-
finalType,
|
|
814
|
-
typeLiteral
|
|
815
|
-
]);
|
|
816
731
|
}
|
|
817
|
-
return
|
|
732
|
+
return [componentPathNoExtension, componentPathWithExtension];
|
|
818
733
|
};
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
);
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
const imports = ["DefaultValues"];
|
|
837
|
-
const types = fields.map((field) => {
|
|
838
|
-
if (field.children) {
|
|
839
|
-
const childrenResult = getFieldTypes(field.children);
|
|
840
|
-
imports.push(...childrenResult.imports);
|
|
841
|
-
if (childrenResult.types.length) {
|
|
842
|
-
const subType = ts.factory.createTypeLiteralNode(childrenResult.types);
|
|
843
|
-
const childrenPropertySignature = createPropertySignature(
|
|
844
|
-
"children",
|
|
845
|
-
subType
|
|
846
|
-
);
|
|
847
|
-
const { type: type2, imports: newImports2 } = buildTypeFromField(
|
|
848
|
-
field,
|
|
849
|
-
field.isRepeater ? subType : childrenPropertySignature
|
|
850
|
-
);
|
|
851
|
-
imports.push(...newImports2);
|
|
852
|
-
return type2;
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
const { type, imports: newImports } = buildTypeFromField(field);
|
|
856
|
-
imports.push(...newImports);
|
|
857
|
-
return type;
|
|
858
|
-
});
|
|
859
|
-
return { types, imports: Array.from(new Set(imports)) };
|
|
860
|
-
}
|
|
861
|
-
function constructFinalType(fields, typeName) {
|
|
862
|
-
const { types, imports } = getFieldTypes(fields);
|
|
863
|
-
const importDeclaration = getImportDeclaration(
|
|
864
|
-
imports,
|
|
865
|
-
CMS_COMPONENTS_FIELD_TYPES
|
|
866
|
-
);
|
|
867
|
-
const baseType = ts.factory.createTypeAliasDeclaration(
|
|
868
|
-
[],
|
|
869
|
-
[],
|
|
870
|
-
"",
|
|
871
|
-
void 0,
|
|
872
|
-
ts.factory.createTypeLiteralNode(types)
|
|
873
|
-
);
|
|
874
|
-
const wrappedType = ts.factory.createTypeReferenceNode(DEFAULT_VALUES_TYPE, [
|
|
875
|
-
baseType.type
|
|
876
|
-
]);
|
|
877
|
-
const finalType = ts.factory.createTypeAliasDeclaration(
|
|
878
|
-
[],
|
|
879
|
-
[],
|
|
880
|
-
typeName,
|
|
881
|
-
void 0,
|
|
882
|
-
wrappedType
|
|
883
|
-
);
|
|
884
|
-
const defaultExport = ts.factory.createExportDefault(
|
|
885
|
-
ts.factory.createIdentifier(typeName)
|
|
886
|
-
);
|
|
887
|
-
return [importDeclaration, finalType, defaultExport];
|
|
888
|
-
}
|
|
889
|
-
function writeFieldsType(fields, fileName, typeName) {
|
|
890
|
-
const entries = getFieldEntries(fields);
|
|
891
|
-
if (!entries) {
|
|
892
|
-
return false;
|
|
893
|
-
}
|
|
894
|
-
try {
|
|
895
|
-
const file = ts.createSourceFile(
|
|
896
|
-
fileName,
|
|
897
|
-
"",
|
|
898
|
-
ts.ScriptTarget.ESNext,
|
|
899
|
-
false,
|
|
900
|
-
ts.ScriptKind.TS
|
|
901
|
-
);
|
|
902
|
-
const printer = ts.createPrinter();
|
|
903
|
-
const nodes = constructFinalType(entries, typeName);
|
|
904
|
-
const comments = [
|
|
905
|
-
AUTO_GEN_COMMENT,
|
|
906
|
-
"Removing the above comment will disable type generation for this module",
|
|
907
|
-
"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"
|
|
908
|
-
].map((comment) => `// ${comment}`);
|
|
909
|
-
const typeResult = nodes.map(
|
|
910
|
-
(node) => printer.printNode(ts.EmitHint.Unspecified, node, file)
|
|
911
|
-
);
|
|
912
|
-
const result = [...comments, ...typeResult].join("\n");
|
|
913
|
-
writeFileSync(fileName, result);
|
|
914
|
-
return true;
|
|
915
|
-
} catch (e) {
|
|
916
|
-
console.error(e);
|
|
917
|
-
return false;
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
|
|
921
|
-
if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
|
|
922
|
-
prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
|
|
923
|
-
}
|
|
924
|
-
const serializedJson = jsonStringifyAndEscapeForInlineJS(
|
|
925
|
-
environmentConfig.toJSON(),
|
|
926
|
-
{ baseIndent: 6, prettyPrint }
|
|
927
|
-
);
|
|
928
|
-
const globals = [`window.__hsEnvConfig = ${serializedJson};`];
|
|
929
|
-
if (hsServerPageUrl) {
|
|
930
|
-
globals.push(
|
|
931
|
-
`window.__hsServerPageUrl = ${jsonStringifyAndEscapeForInlineJS(
|
|
932
|
-
hsServerPageUrl
|
|
933
|
-
)};`
|
|
934
|
-
);
|
|
935
|
-
}
|
|
936
|
-
if (hsBasePath) {
|
|
937
|
-
globals.push(
|
|
938
|
-
`window.__hsBasePath = ${jsonStringifyAndEscapeForInlineJS(hsBasePath)};`
|
|
939
|
-
);
|
|
940
|
-
}
|
|
941
|
-
if (!environmentConfig.getIsDeployed() && (criticalDevErrors == null ? void 0 : criticalDevErrors.length)) {
|
|
942
|
-
const firstCriticalDevError = criticalDevErrors[0];
|
|
943
|
-
globals.push(`
|
|
944
|
-
customElements.whenDefined('vite-error-overlay').then(() => {
|
|
945
|
-
const ErrorOverlay = customElements.get('vite-error-overlay');
|
|
946
|
-
const error = new Error(${jsonStringifyAndEscapeForInlineJS(
|
|
947
|
-
firstCriticalDevError.message
|
|
948
|
-
)});
|
|
949
|
-
const overlay = new ErrorOverlay(error);
|
|
950
|
-
|
|
951
|
-
document.body.appendChild(overlay);
|
|
952
|
-
})
|
|
953
|
-
`);
|
|
954
|
-
}
|
|
955
|
-
const nonceAttr = includeNonces && cmsComponents.SCRIPT_NONCE_PLACEHOLDER ? ` nonce="${cmsComponents.SCRIPT_NONCE_PLACEHOLDER}"` : "";
|
|
956
|
-
return `
|
|
957
|
-
<script type="text/javascript"${nonceAttr}>
|
|
958
|
-
${globals.join("\n ")}
|
|
959
|
-
</script>
|
|
960
|
-
`;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
// src/lib/moduleGraph.ts
|
|
964
|
-
var findFullPathInModuleGraph = (modulePathNoExtension, moduleGraph) => {
|
|
965
|
-
for (const extension of COMPONENT_EXTENSIONS) {
|
|
966
|
-
const pathToTry = `${modulePathNoExtension}${extension}`;
|
|
967
|
-
if (moduleGraph.fileToModulesMap.has(pathToTry)) {
|
|
968
|
-
return pathToTry;
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
};
|
|
972
|
-
|
|
973
|
-
// src/lib/pathHelpers.ts
|
|
974
|
-
var getComponentPaths = (viteServer, componentPath) => {
|
|
975
|
-
let componentPathWithExtension;
|
|
976
|
-
let componentPathNoExtension;
|
|
977
|
-
if (hasComponentExtension(componentPath)) {
|
|
978
|
-
componentPathWithExtension = componentPath;
|
|
979
|
-
componentPathNoExtension = removeComponentExtension(componentPath);
|
|
980
|
-
} else {
|
|
981
|
-
componentPathNoExtension = componentPath;
|
|
982
|
-
}
|
|
983
|
-
if (!componentPathWithExtension) {
|
|
984
|
-
componentPathWithExtension = findFullPathInModuleGraph(
|
|
985
|
-
componentPathNoExtension,
|
|
986
|
-
viteServer.moduleGraph
|
|
987
|
-
);
|
|
988
|
-
if (!componentPathWithExtension) {
|
|
989
|
-
throw new Error(
|
|
990
|
-
`Couldn't find full path to component: ${componentPathNoExtension}`
|
|
991
|
-
);
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
return [componentPathNoExtension, componentPathWithExtension];
|
|
995
|
-
};
|
|
996
|
-
var getEntryPointBasePath = (componentPath) => {
|
|
997
|
-
if (componentPath.includes(ENTRY_POINTS_PATH)) {
|
|
998
|
-
return `partial/${componentPath.split(ENTRY_POINTS_PATH)[1]}`;
|
|
999
|
-
}
|
|
1000
|
-
if (componentPath.includes(MODULE_FOLDER_PATH)) {
|
|
1001
|
-
return `module/${componentPath.split(MODULE_FOLDER_PATH)[1]}`;
|
|
1002
|
-
}
|
|
1003
|
-
throw new Error("Unknown entry point path type");
|
|
1004
|
-
};
|
|
1005
|
-
|
|
1006
|
-
// src/lib/renderComponentWithCSS.ts
|
|
1007
|
-
async function renderComponentWithCSS(viteServer, componentPath, Component, propsAndExtraDeps, pageUrl, entryPointBasePath, contextOptions, environmentConfig, renderOptions, getServerSideProps, modifyHtmlCallback) {
|
|
1008
|
-
const internalSsrPath = packagePath(import.meta.url, "internalSsr");
|
|
1009
|
-
const { renderComponentOnServer, collectCssInDev: collectCssInDev2 } = await viteServer.ssrLoadModule(internalSsrPath);
|
|
1010
|
-
const [, componentPathWithExtension] = getComponentPaths(
|
|
1011
|
-
viteServer,
|
|
1012
|
-
componentPath
|
|
734
|
+
var getEntryPointBasePath = (componentPath) => {
|
|
735
|
+
if (componentPath.includes(ENTRY_POINTS_PATH)) {
|
|
736
|
+
return `partial/${componentPath.split(ENTRY_POINTS_PATH)[1]}`;
|
|
737
|
+
}
|
|
738
|
+
if (componentPath.includes(MODULE_FOLDER_PATH)) {
|
|
739
|
+
return `module/${componentPath.split(MODULE_FOLDER_PATH)[1]}`;
|
|
740
|
+
}
|
|
741
|
+
throw new Error("Unknown entry point path type");
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
// src/lib/renderComponentWithCSS.ts
|
|
745
|
+
async function renderComponentWithCSS(viteServer, componentPath, Component, propsAndExtraDeps, pageUrl, entryPointBasePath, contextOptions, environmentConfig, renderOptions, getServerSideProps, modifyHtmlCallback) {
|
|
746
|
+
const internalSsrPath = packagePath(import.meta.url, "internalSsr");
|
|
747
|
+
const { renderComponentOnServer, collectCssInDev: collectCssInDev2 } = await viteServer.ssrLoadModule(internalSsrPath);
|
|
748
|
+
const [, componentPathWithExtension] = getComponentPaths(
|
|
749
|
+
viteServer,
|
|
750
|
+
componentPath
|
|
1013
751
|
);
|
|
1014
752
|
const renderResult = await renderComponentOnServer(
|
|
1015
753
|
Component,
|
|
@@ -1309,7 +1047,7 @@ function trackUsage(action) {
|
|
|
1309
1047
|
eventName: EVENT_NAME,
|
|
1310
1048
|
action,
|
|
1311
1049
|
nodeVersion: getNodeVersionData(),
|
|
1312
|
-
version: "0.15.
|
|
1050
|
+
version: "0.15.10",
|
|
1313
1051
|
os: getPlatform()
|
|
1314
1052
|
};
|
|
1315
1053
|
const uri = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -2748,7 +2486,7 @@ function proxyPathPageResourceRedirect(req, res, next) {
|
|
|
2748
2486
|
// src/routes/proxyServerlessHandler.ts
|
|
2749
2487
|
import fetch2 from "node-fetch";
|
|
2750
2488
|
var localDomains = ["localhost", "hslocal.net"];
|
|
2751
|
-
function
|
|
2489
|
+
function proxyServerlessRequest(req, res, next) {
|
|
2752
2490
|
const { method, headers } = req;
|
|
2753
2491
|
let refererUrl;
|
|
2754
2492
|
let domainToProxy;
|
|
@@ -3004,8 +2742,8 @@ var createDevServerRoutes = async (viteServer, storybookPort) => {
|
|
|
3004
2742
|
devServerApp.get("/modules/", linksToAllModulesRouteHandler_default);
|
|
3005
2743
|
devServerApp.get("/module/:moduleName", module_default);
|
|
3006
2744
|
devServerApp.get("/module/:moduleName/*", module_default);
|
|
3007
|
-
devServerApp.all("/hs/serverless/*",
|
|
3008
|
-
devServerApp.all("/_hcms/api/*",
|
|
2745
|
+
devServerApp.all("/hs/serverless/*", proxyServerlessRequest);
|
|
2746
|
+
devServerApp.all("/_hcms/api/*", proxyServerlessRequest);
|
|
3009
2747
|
devServerApp.get("/", homeRouteHandler_default);
|
|
3010
2748
|
devServerApp.get("/*", proxyPathPageResourceRedirect);
|
|
3011
2749
|
devServerApp.get("/*", proxyPageResourceRedirect);
|
|
@@ -3452,6 +3190,270 @@ async function validateHSPlatform(projectConfigPath, portalId) {
|
|
|
3452
3190
|
// src/createDevServer.ts
|
|
3453
3191
|
import { get as hsGet6 } from "@hubspot/cli-lib/http.js";
|
|
3454
3192
|
|
|
3193
|
+
// ../cms-js-internal/dist/buildFieldsTypes.js
|
|
3194
|
+
import { writeFileSync } from "fs";
|
|
3195
|
+
import ts from "typescript";
|
|
3196
|
+
import React, { isValidElement } from "react";
|
|
3197
|
+
var fieldTypeNameByType = {
|
|
3198
|
+
alignment: "AlignmentFieldType",
|
|
3199
|
+
audioplayer: "AudioFieldType",
|
|
3200
|
+
backgroundimage: "BackgroundImageFieldType",
|
|
3201
|
+
blog: "BlogFieldType",
|
|
3202
|
+
boolean: "BooleanFieldType",
|
|
3203
|
+
border: "BorderFieldType",
|
|
3204
|
+
choice: "ChoiceFieldType",
|
|
3205
|
+
color: "ColorFieldType",
|
|
3206
|
+
crmobject: "CrmObjectFieldType",
|
|
3207
|
+
cta: "CtaFieldType",
|
|
3208
|
+
date: "DateFieldType",
|
|
3209
|
+
datetime: "DateTimeFieldType",
|
|
3210
|
+
email: "EmailFieldType",
|
|
3211
|
+
embed: "EmbedFieldType",
|
|
3212
|
+
file: "FileFieldType",
|
|
3213
|
+
followupemail: "FollowUpEmailFieldType",
|
|
3214
|
+
font: "FontFieldType",
|
|
3215
|
+
form: "FormFieldType",
|
|
3216
|
+
gradient: "GradientFieldType",
|
|
3217
|
+
group: "GroupFieldType",
|
|
3218
|
+
html: "HtmlFieldType",
|
|
3219
|
+
hubdbrow: "HubDbRowFieldType",
|
|
3220
|
+
hubdbtable: "HubDbTableFieldType",
|
|
3221
|
+
hubl: "HublFieldType",
|
|
3222
|
+
icon: "IconFieldType",
|
|
3223
|
+
image: "ImageFieldType",
|
|
3224
|
+
link: "LinkFieldType",
|
|
3225
|
+
logo: "LogoFieldType",
|
|
3226
|
+
meeting: "MeetingFieldType",
|
|
3227
|
+
menu: "MenuFieldType",
|
|
3228
|
+
number: "NumberFieldType",
|
|
3229
|
+
page: "PageFieldType",
|
|
3230
|
+
payment: "PaymentFieldType",
|
|
3231
|
+
podcast: "PodcastFieldType",
|
|
3232
|
+
richtext: "RichTextFieldType",
|
|
3233
|
+
salesforcecampaign: "SfdcCamapaignFieldType",
|
|
3234
|
+
simplemenu: "SimpleMenuFieldType",
|
|
3235
|
+
spacing: "SpacingFieldType",
|
|
3236
|
+
survey: "SurveyFieldType",
|
|
3237
|
+
tag: "TagFieldType",
|
|
3238
|
+
textalignment: "TextAlignmentFieldType",
|
|
3239
|
+
text: "TextFieldType",
|
|
3240
|
+
url: "UrlFieldType",
|
|
3241
|
+
video: "VideoFieldType",
|
|
3242
|
+
workflow: "WorkflowFieldType"
|
|
3243
|
+
};
|
|
3244
|
+
var getChildrenAsArray = (element) => React.Children.toArray(element.props.children);
|
|
3245
|
+
function getFieldEntries(fields) {
|
|
3246
|
+
if (isValidElement(fields)) {
|
|
3247
|
+
const fieldsJSX = getChildrenAsArray(fields);
|
|
3248
|
+
return getReactFieldEntries(fieldsJSX);
|
|
3249
|
+
} else if (Array.isArray(fields)) {
|
|
3250
|
+
return getJSONFieldEntries(fields);
|
|
3251
|
+
}
|
|
3252
|
+
return void 0;
|
|
3253
|
+
}
|
|
3254
|
+
var getJSXFieldType = (fieldFunctionName) => {
|
|
3255
|
+
switch (fieldFunctionName) {
|
|
3256
|
+
case "RepeatedFieldGroup":
|
|
3257
|
+
case "FieldGroup":
|
|
3258
|
+
return "GroupFieldType";
|
|
3259
|
+
default:
|
|
3260
|
+
return `${fieldFunctionName}Type`;
|
|
3261
|
+
}
|
|
3262
|
+
};
|
|
3263
|
+
var getElementName = (element) => typeof element.type === "string" ? element.type : element.type.name || null;
|
|
3264
|
+
function getReactFieldEntries(fields) {
|
|
3265
|
+
const validTypeNames = Object.values(fieldTypeNameByType);
|
|
3266
|
+
if (!Array.isArray(fields)) {
|
|
3267
|
+
return;
|
|
3268
|
+
}
|
|
3269
|
+
return fields.filter((field) => field.props && field.props.name).map((field) => {
|
|
3270
|
+
const elName = getElementName(field);
|
|
3271
|
+
const fieldType = getJSXFieldType(getElementName(field));
|
|
3272
|
+
if (!validTypeNames.includes(fieldType)) {
|
|
3273
|
+
return void 0;
|
|
3274
|
+
}
|
|
3275
|
+
const { name, default: hasDefault } = field.props;
|
|
3276
|
+
const isRepeater = elName === "RepeatedFieldGroup";
|
|
3277
|
+
const entry = {
|
|
3278
|
+
type: fieldType,
|
|
3279
|
+
name,
|
|
3280
|
+
hasDefault: !!hasDefault,
|
|
3281
|
+
isRepeater,
|
|
3282
|
+
children: []
|
|
3283
|
+
};
|
|
3284
|
+
if (fieldType === "GroupFieldType") {
|
|
3285
|
+
const childrenArray = getChildrenAsArray(field);
|
|
3286
|
+
const children = getReactFieldEntries(childrenArray);
|
|
3287
|
+
return {
|
|
3288
|
+
...entry,
|
|
3289
|
+
children
|
|
3290
|
+
};
|
|
3291
|
+
}
|
|
3292
|
+
return entry;
|
|
3293
|
+
}).filter((entry) => entry !== void 0);
|
|
3294
|
+
}
|
|
3295
|
+
function getJSONFieldEntries(fields) {
|
|
3296
|
+
if (!Array.isArray(fields)) {
|
|
3297
|
+
return;
|
|
3298
|
+
}
|
|
3299
|
+
return fields.filter((field) => field.name && field.type).map((field) => {
|
|
3300
|
+
const { name, type } = field;
|
|
3301
|
+
const fieldType = fieldTypeNameByType[type];
|
|
3302
|
+
if (!fieldType) {
|
|
3303
|
+
return void 0;
|
|
3304
|
+
}
|
|
3305
|
+
const entry = {
|
|
3306
|
+
type: fieldType,
|
|
3307
|
+
name,
|
|
3308
|
+
isRepeater: "occurrence" in field,
|
|
3309
|
+
hasDefault: !!field.default,
|
|
3310
|
+
children: []
|
|
3311
|
+
};
|
|
3312
|
+
if (fieldType === "GroupFieldType" && "children" in field) {
|
|
3313
|
+
const children = getJSONFieldEntries(field.children);
|
|
3314
|
+
return { ...entry, children };
|
|
3315
|
+
}
|
|
3316
|
+
return entry;
|
|
3317
|
+
}).filter((entry) => entry !== void 0);
|
|
3318
|
+
}
|
|
3319
|
+
var OVERRIDE_TYPE = "Override";
|
|
3320
|
+
var REQUIRED_TYPE = "Required";
|
|
3321
|
+
var REPEATED_VAR = "_repeater";
|
|
3322
|
+
var DEFAULT_VALUES_TYPE = "DefaultValues";
|
|
3323
|
+
var CMS_COMPONENTS = "@hubspot/cms-components";
|
|
3324
|
+
var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
3325
|
+
var AUTO_GEN_COMMENT = "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.";
|
|
3326
|
+
var createPropertySignature = (identifier, type) => ts.factory.createPropertySignature([], identifier, void 0, type);
|
|
3327
|
+
var buildTypeFromField = (field, additionalNode) => {
|
|
3328
|
+
const imports = [field.type];
|
|
3329
|
+
const identifier = ts.factory.createIdentifier(field.name);
|
|
3330
|
+
const baseType = ts.factory.createTypeReferenceNode(field.type);
|
|
3331
|
+
const requiredType = ts.factory.createTypeReferenceNode(REQUIRED_TYPE, [
|
|
3332
|
+
baseType
|
|
3333
|
+
]);
|
|
3334
|
+
let finalType = field.hasDefault ? requiredType : baseType;
|
|
3335
|
+
if (additionalNode) {
|
|
3336
|
+
const typeLiteral = ts.isTypeLiteralNode(additionalNode) ? additionalNode : ts.factory.createTypeLiteralNode([additionalNode]);
|
|
3337
|
+
const repeaterName = ts.factory.createLiteralTypeNode(
|
|
3338
|
+
ts.factory.createStringLiteral(REPEATED_VAR)
|
|
3339
|
+
);
|
|
3340
|
+
if (!field.isRepeater) {
|
|
3341
|
+
imports.push(OVERRIDE_TYPE);
|
|
3342
|
+
}
|
|
3343
|
+
finalType = field.isRepeater ? ts.factory.createTypeReferenceNode("Array", [
|
|
3344
|
+
ts.factory.createTypeReferenceNode("Record", [
|
|
3345
|
+
repeaterName,
|
|
3346
|
+
typeLiteral
|
|
3347
|
+
])
|
|
3348
|
+
]) : ts.factory.createTypeReferenceNode(OVERRIDE_TYPE, [
|
|
3349
|
+
finalType,
|
|
3350
|
+
typeLiteral
|
|
3351
|
+
]);
|
|
3352
|
+
}
|
|
3353
|
+
return { type: createPropertySignature(identifier, finalType), imports };
|
|
3354
|
+
};
|
|
3355
|
+
function getImportDeclaration(imports, moduleSpecifier) {
|
|
3356
|
+
const importSpecifiers = Array.from(imports).map(
|
|
3357
|
+
(importName) => ts.factory.createImportSpecifier(
|
|
3358
|
+
true,
|
|
3359
|
+
void 0,
|
|
3360
|
+
ts.factory.createIdentifier(importName)
|
|
3361
|
+
)
|
|
3362
|
+
);
|
|
3363
|
+
const namedImports = ts.factory.createNamedImports(importSpecifiers);
|
|
3364
|
+
return ts.factory.createImportDeclaration(
|
|
3365
|
+
[],
|
|
3366
|
+
[],
|
|
3367
|
+
ts.factory.createImportClause(false, void 0, namedImports),
|
|
3368
|
+
ts.factory.createStringLiteral(moduleSpecifier)
|
|
3369
|
+
);
|
|
3370
|
+
}
|
|
3371
|
+
function getFieldTypes(fields) {
|
|
3372
|
+
const imports = ["DefaultValues"];
|
|
3373
|
+
const types = fields.map((field) => {
|
|
3374
|
+
if (field.children) {
|
|
3375
|
+
const childrenResult = getFieldTypes(field.children);
|
|
3376
|
+
imports.push(...childrenResult.imports);
|
|
3377
|
+
if (childrenResult.types.length) {
|
|
3378
|
+
const subType = ts.factory.createTypeLiteralNode(childrenResult.types);
|
|
3379
|
+
const childrenPropertySignature = createPropertySignature(
|
|
3380
|
+
"children",
|
|
3381
|
+
subType
|
|
3382
|
+
);
|
|
3383
|
+
const { type: type2, imports: newImports2 } = buildTypeFromField(
|
|
3384
|
+
field,
|
|
3385
|
+
field.isRepeater ? subType : childrenPropertySignature
|
|
3386
|
+
);
|
|
3387
|
+
imports.push(...newImports2);
|
|
3388
|
+
return type2;
|
|
3389
|
+
}
|
|
3390
|
+
}
|
|
3391
|
+
const { type, imports: newImports } = buildTypeFromField(field);
|
|
3392
|
+
imports.push(...newImports);
|
|
3393
|
+
return type;
|
|
3394
|
+
});
|
|
3395
|
+
return { types, imports: Array.from(new Set(imports)) };
|
|
3396
|
+
}
|
|
3397
|
+
function constructFinalType(fields, typeName) {
|
|
3398
|
+
const { types, imports } = getFieldTypes(fields);
|
|
3399
|
+
const importDeclaration = getImportDeclaration(
|
|
3400
|
+
imports,
|
|
3401
|
+
CMS_COMPONENTS_FIELD_TYPES
|
|
3402
|
+
);
|
|
3403
|
+
const baseType = ts.factory.createTypeAliasDeclaration(
|
|
3404
|
+
[],
|
|
3405
|
+
[],
|
|
3406
|
+
"",
|
|
3407
|
+
void 0,
|
|
3408
|
+
ts.factory.createTypeLiteralNode(types)
|
|
3409
|
+
);
|
|
3410
|
+
const wrappedType = ts.factory.createTypeReferenceNode(DEFAULT_VALUES_TYPE, [
|
|
3411
|
+
baseType.type
|
|
3412
|
+
]);
|
|
3413
|
+
const finalType = ts.factory.createTypeAliasDeclaration(
|
|
3414
|
+
[],
|
|
3415
|
+
[],
|
|
3416
|
+
typeName,
|
|
3417
|
+
void 0,
|
|
3418
|
+
wrappedType
|
|
3419
|
+
);
|
|
3420
|
+
const defaultExport = ts.factory.createExportDefault(
|
|
3421
|
+
ts.factory.createIdentifier(typeName)
|
|
3422
|
+
);
|
|
3423
|
+
return [importDeclaration, finalType, defaultExport];
|
|
3424
|
+
}
|
|
3425
|
+
function writeFieldsType(fields, fileName, typeName) {
|
|
3426
|
+
const entries = getFieldEntries(fields);
|
|
3427
|
+
if (!entries) {
|
|
3428
|
+
return false;
|
|
3429
|
+
}
|
|
3430
|
+
try {
|
|
3431
|
+
const file = ts.createSourceFile(
|
|
3432
|
+
fileName,
|
|
3433
|
+
"",
|
|
3434
|
+
ts.ScriptTarget.ESNext,
|
|
3435
|
+
false,
|
|
3436
|
+
ts.ScriptKind.TS
|
|
3437
|
+
);
|
|
3438
|
+
const printer = ts.createPrinter();
|
|
3439
|
+
const nodes = constructFinalType(entries, typeName);
|
|
3440
|
+
const comments = [
|
|
3441
|
+
AUTO_GEN_COMMENT,
|
|
3442
|
+
"Removing the above comment will disable type generation for this module",
|
|
3443
|
+
"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"
|
|
3444
|
+
].map((comment) => `// ${comment}`);
|
|
3445
|
+
const typeResult = nodes.map(
|
|
3446
|
+
(node) => printer.printNode(ts.EmitHint.Unspecified, node, file)
|
|
3447
|
+
);
|
|
3448
|
+
const result = [...comments, ...typeResult].join("\n");
|
|
3449
|
+
writeFileSync(fileName, result);
|
|
3450
|
+
return true;
|
|
3451
|
+
} catch (e) {
|
|
3452
|
+
console.error(e);
|
|
3453
|
+
return false;
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
|
|
3455
3457
|
// src/lib/watchFieldsUpdates.ts
|
|
3456
3458
|
import fs4 from "fs";
|
|
3457
3459
|
import path8 from "path";
|
|
@@ -3648,7 +3650,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
3648
3650
|
setTrackingInfo(authedPortalId, authedEnv);
|
|
3649
3651
|
sendTrackingRequest("start-dev-server");
|
|
3650
3652
|
let domainsToProxy = [];
|
|
3651
|
-
if (
|
|
3653
|
+
if (authedPortalId) {
|
|
3652
3654
|
try {
|
|
3653
3655
|
const portalDomains = await fetchWebsiteDomainNames(authedPortalId);
|
|
3654
3656
|
domainsToProxy = (process.env.DOMAINS_TO_PROXY || "").split(",").filter((d) => !!d);
|
|
@@ -3657,9 +3659,12 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
3657
3659
|
if (e instanceof MissingScopeError) {
|
|
3658
3660
|
logMissingScopeWarning(e);
|
|
3659
3661
|
} else {
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3662
|
+
const failedDomainFetchMessages = [
|
|
3663
|
+
"Failed to fetch the portal's domains, as a result:",
|
|
3664
|
+
"- HTTPS proxying won't work with them.",
|
|
3665
|
+
"- Proxying to serverless functions won't work."
|
|
3666
|
+
].map((msg) => wrapMessageInColor("yellow", msg)).join("\n");
|
|
3667
|
+
console.warn(failedDomainFetchMessages);
|
|
3663
3668
|
}
|
|
3664
3669
|
}
|
|
3665
3670
|
}
|