@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.
@@ -1,7 +1,7 @@
1
1
  // src/storybook/moduleStory.tsx
2
2
  import { useEffect } from "react";
3
3
 
4
- // ../cms-js-internal/dist/types-Dvw_fW6p.js
4
+ // ../cms-js-internal/dist/types-C8bPIEz4.js
5
5
  function namespaceModulePropsShape(props) {
6
6
  const {
7
7
  dataQueryResult,
@@ -8,7 +8,7 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
 
11
- // ../cms-js-internal/dist/types-Dvw_fW6p.js
11
+ // ../cms-js-internal/dist/types-C8bPIEz4.js
12
12
  import path from "path";
13
13
  import { createHash } from "crypto";
14
14
  import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
@@ -392,8 +392,8 @@ function isStylesheetAsset(staticAsset) {
392
392
  return staticAsset.type === "stylesheet";
393
393
  }
394
394
  var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, TEMPLATE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, badInlineJsChars, inlineJsEscapeChars, viteRoot, viteCommand, clientRenderIsland, virtualClientRenderIslandModuleId, scriptTagToLogServerMessages, getComponentExtension, hasComponentExtension, isStorybookStory, removeComponentExtension, COMBINED_REACT_BASE_PATH, ISLAND_RUNTIME_CONFIG_BASE_PATH, removeIndexFromPath, removeIndexOrTrailingJsFromPath, HEALTHCHECKS_ENABLED_DEFAULT, HEALTHCHECKS_STRICT_DEFAULT, BUILD_INFO_PATH, GATES, ENABLED_FEATURES_GATE_MAP, findAllComponentsIn;
395
- var init_types_Dvw_fW6p = __esm({
396
- "../cms-js-internal/dist/types-Dvw_fW6p.js"() {
395
+ var init_types_C8bPIEz4 = __esm({
396
+ "../cms-js-internal/dist/types-C8bPIEz4.js"() {
397
397
  COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
398
398
  ENTRY_POINTS_PATH = "components/partials/";
399
399
  MODULE_FOLDER_PATH = "components/modules/";
@@ -512,12 +512,10 @@ ${groupEnd}</script>
512
512
  GATES = [
513
513
  "CMS:JSRenderer:RemoveMockClientEntryPlugin",
514
514
  "CMS:JSRenderer:AnalyzeCmsModules",
515
- "CMS:JSRenderer:StripNullBytes",
516
- "PortalsAccessIdentity:DesignManager:UrlSigning"
515
+ "CMS:JSRenderer:StripNullBytes"
517
516
  ];
518
517
  ENABLED_FEATURES_GATE_MAP = {
519
- "cms:jsr:analyzeCmsModules": "CMS:JSRenderer:AnalyzeCmsModules",
520
- "PortalsAccessIdentity:DesignManager:UrlSigning": "PortalsAccessIdentity:DesignManager:UrlSigning"
518
+ "cms:jsr:analyzeCmsModules": "CMS:JSRenderer:AnalyzeCmsModules"
521
519
  };
522
520
  findAllComponentsIn = (webRoot2, componentsFolder) => {
523
521
  const fullComponentsFolderPath = join(webRoot2, componentsFolder);
@@ -1184,8 +1182,8 @@ function GlobalPartialSlot(props) {
1184
1182
  var setProperty, getProperty, hasProperty, serializeIslandDataForInlineScript, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, traverse, CMS_MODULE_COMPONENT_NAME, DND_AREA_COMPONENT_NAME, PLUGIN_NAME, promiseForNewWritableStream, renderStreamToPromise, createServerRenderContextV22, createServerRenderContext2, renderServerSidePropsWithAsyncLocalStoreContext, bootStrapRenderContext;
1185
1183
  var init_dist = __esm({
1186
1184
  "../cms-js-internal/dist/index.js"() {
1187
- init_types_Dvw_fW6p();
1188
- init_types_Dvw_fW6p();
1185
+ init_types_C8bPIEz4();
1186
+ init_types_C8bPIEz4();
1189
1187
  ({ setProperty, getProperty, hasProperty } = dotProp);
1190
1188
  serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
1191
1189
  const islandsArrayToSerialize = tweakedIslandsArray.map(
@@ -3,11 +3,14 @@
3
3
  // src/validateFields.ts
4
4
  import path3 from "path";
5
5
  import fs3 from "fs/promises";
6
- import { createServer as createViteServer, normalizePath as normalizePath2 } from "vite";
6
+ import {
7
+ createServer as createViteServer,
8
+ normalizePath as normalizePath2
9
+ } from "vite";
7
10
  import { createRequire } from "module";
8
11
  import { default as react } from "@vitejs/plugin-react";
9
12
 
10
- // ../cms-js-internal/dist/types-Dvw_fW6p.js
13
+ // ../cms-js-internal/dist/types-C8bPIEz4.js
11
14
  import path from "path";
12
15
  import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
13
16
  import { join } from "path/posix";
@@ -341,6 +344,7 @@ function getFieldEntries(fields) {
341
344
  // Choices are pair [value, label] but only the value is printed to the page, so flatten it.
342
345
  "choices" in field ? field.choices.map(([value, label]) => value) : void 0
343
346
  ),
347
+ multiple: field.type === "choice" ? field.multiple === true : void 0,
344
348
  children: []
345
349
  };
346
350
  if (fieldType === "GroupFieldType" && "children" in field) {
@@ -378,7 +382,8 @@ var buildTypeFromField = (field, additionalNode) => {
378
382
  ]);
379
383
  let finalType = field.isRequired ? requiredType : baseType;
380
384
  if (field.choices) {
381
- finalType = createUnionTypeFromArray(field.choices);
385
+ const choiceType = createUnionTypeFromArray(field.choices);
386
+ finalType = field.multiple ? ts.factory.createTypeReferenceNode("Array", [choiceType]) : choiceType;
382
387
  }
383
388
  if (field.isRequired) {
384
389
  imports.push(REQUIRED_TYPE);
@@ -630,39 +635,34 @@ async function extractAndValidateFields(fieldsJson, metaJson, modulePath) {
630
635
  ]
631
636
  };
632
637
  }
633
- async function validateSingleModule(modulePath, absoluteRoot, viteServer) {
638
+ async function generateSingleModule(modulePath, absoluteRoot, viteServer) {
634
639
  const absoluteModulePath = path3.resolve(absoluteRoot, modulePath);
635
- const moduleDir = path3.basename(modulePath);
636
640
  let files;
637
641
  try {
638
642
  files = await fs3.readdir(absoluteModulePath);
639
643
  } catch {
640
644
  return {
641
645
  fieldsJsonPath: "",
642
- fieldsTypePath: "",
643
646
  fieldErrors: [
644
647
  {
645
648
  severity: "FATAL",
646
649
  errorType: "MODULE_NOT_FOUND",
647
650
  message: `Module directory does not exist: ${modulePath}`
648
651
  }
649
- ],
650
- metaErrors: []
652
+ ]
651
653
  };
652
654
  }
653
655
  const indexFile = files.find((f) => f.startsWith("index."));
654
656
  if (!indexFile) {
655
657
  return {
656
658
  fieldsJsonPath: "",
657
- fieldsTypePath: "",
658
659
  fieldErrors: [
659
660
  {
660
661
  severity: "FATAL",
661
662
  errorType: "NO_INDEX_FILE",
662
663
  message: `No index file found in ${modulePath}`
663
664
  }
664
- ],
665
- metaErrors: []
665
+ ]
666
666
  };
667
667
  }
668
668
  const jsonResult = await generateAndWriteFieldsJson(
@@ -671,27 +671,36 @@ async function validateSingleModule(modulePath, absoluteRoot, viteServer) {
671
671
  viteServer
672
672
  );
673
673
  if ("severity" in jsonResult) {
674
- return {
675
- fieldsJsonPath: "",
676
- fieldsTypePath: "",
677
- fieldErrors: [jsonResult],
678
- metaErrors: []
679
- };
674
+ return { fieldsJsonPath: "", fieldErrors: [jsonResult] };
680
675
  }
676
+ return {
677
+ fieldsJsonPath: jsonResult.fieldsJsonPath,
678
+ fieldErrors: [],
679
+ fieldsJson: jsonResult.fieldsJson,
680
+ indexFile
681
+ };
682
+ }
683
+ async function validateSingleModule(modulePath, absoluteRoot, viteServer) {
684
+ const { fieldsJsonPath, fieldErrors, fieldsJson, indexFile } = await generateSingleModule(modulePath, absoluteRoot, viteServer);
685
+ if (!fieldsJson || !indexFile) {
686
+ return { fieldsJsonPath, fieldsTypePath: "", fieldErrors, metaErrors: [] };
687
+ }
688
+ const absoluteModulePath = path3.resolve(absoluteRoot, modulePath);
681
689
  const typeResult = await generateAndWriteFieldsType(
682
690
  absoluteModulePath,
683
691
  modulePath,
684
- moduleDir,
685
- jsonResult.fieldsJson
692
+ path3.basename(modulePath),
693
+ fieldsJson
686
694
  );
687
695
  if ("severity" in typeResult) {
688
696
  return {
689
- fieldsJsonPath: jsonResult.fieldsJsonPath,
697
+ fieldsJsonPath,
690
698
  fieldsTypePath: "",
691
699
  fieldErrors: [typeResult],
692
700
  metaErrors: []
693
701
  };
694
702
  }
703
+ const { fieldsTypePath } = typeResult;
695
704
  let mod;
696
705
  try {
697
706
  mod = await viteServer.ssrLoadModule(
@@ -699,8 +708,8 @@ async function validateSingleModule(modulePath, absoluteRoot, viteServer) {
699
708
  );
700
709
  } catch {
701
710
  return {
702
- fieldsJsonPath: jsonResult.fieldsJsonPath,
703
- fieldsTypePath: typeResult.fieldsTypePath,
711
+ fieldsJsonPath,
712
+ fieldsTypePath,
704
713
  fieldErrors: [
705
714
  {
706
715
  severity: "FATAL",
@@ -711,20 +720,21 @@ async function validateSingleModule(modulePath, absoluteRoot, viteServer) {
711
720
  metaErrors: []
712
721
  };
713
722
  }
714
- const { fieldErrors, metaErrors } = await extractAndValidateFields(
715
- jsonResult.fieldsJson,
723
+ const validation = await extractAndValidateFields(
724
+ fieldsJson,
716
725
  mod.meta,
717
726
  modulePath
718
727
  );
719
- return {
720
- fieldsJsonPath: jsonResult.fieldsJsonPath,
721
- fieldsTypePath: typeResult.fieldsTypePath,
722
- fieldErrors,
723
- metaErrors
724
- };
728
+ return { fieldsJsonPath, fieldsTypePath, ...validation };
725
729
  }
726
- async function validateModuleFields(projectRoot, moduleName) {
730
+ async function forEachModule(projectRoot, moduleName, run) {
727
731
  const absoluteRoot = normalizePath2(path3.resolve(process.cwd(), projectRoot));
732
+ const moduleNames = moduleName ? [moduleName] : findAllModulesInRoot(absoluteRoot).moduleNames;
733
+ if (moduleNames.length === 0) {
734
+ throw new Error(
735
+ `No modules found in ${path3.join(absoluteRoot, "components/modules")}`
736
+ );
737
+ }
728
738
  const require2 = createRequire(import.meta.url);
729
739
  const viteServer = await createViteServer({
730
740
  configFile: false,
@@ -756,53 +766,41 @@ async function validateModuleFields(projectRoot, moduleName) {
756
766
  ]
757
767
  });
758
768
  try {
759
- if (moduleName) {
760
- return [
761
- await validateSingleModule(
762
- `components/modules/${moduleName}`,
763
- absoluteRoot,
764
- viteServer
765
- )
766
- ];
767
- }
768
- const { moduleNames } = findAllModulesInRoot(absoluteRoot);
769
- const modulePaths = moduleNames.map(
770
- (name) => `components/modules/${name}`
771
- );
772
769
  return await Promise.all(
773
- modulePaths.map(
774
- (mp) => validateSingleModule(mp, absoluteRoot, viteServer)
770
+ moduleNames.map(
771
+ (name) => run(`components/modules/${name}`, absoluteRoot, viteServer)
775
772
  )
776
773
  );
777
774
  } finally {
778
775
  await viteServer.close();
779
776
  }
780
777
  }
781
-
782
- // src/validateFieldsCli.ts
783
- function parseCommandArgs() {
778
+ function validateModuleFields(projectRoot, moduleName) {
779
+ return forEachModule(projectRoot, moduleName, validateSingleModule);
780
+ }
781
+ async function runModuleFieldsCli(commandName, command) {
784
782
  const projectPath = process.argv[2];
785
783
  const moduleIdx = process.argv.indexOf("--module");
786
784
  const moduleName = moduleIdx !== -1 ? process.argv[moduleIdx + 1] : void 0;
787
785
  if (!projectPath) {
788
- console.error("Usage: validate-fields <path> [--module <name>]");
789
- process.exit(1);
786
+ console.error(`Usage: ${commandName} <path> [--module <name>]`);
787
+ process.exitCode = 1;
788
+ return;
790
789
  }
791
- return { projectPath, moduleName };
792
- }
793
- (async () => {
794
790
  try {
795
- const { projectPath, moduleName } = parseCommandArgs();
796
- const results = await validateModuleFields(projectPath, moduleName);
791
+ const results = await command(projectPath, moduleName);
797
792
  console.log(JSON.stringify(results, null, 2));
798
793
  const hasErrors = results.some(
799
- (r) => r.fieldErrors.length > 0 || r.metaErrors.length > 0
794
+ (r) => r.fieldErrors.length > 0 || (r.metaErrors ?? []).length > 0
800
795
  );
801
796
  process.exitCode = hasErrors ? 1 : 0;
802
797
  } catch (error) {
803
798
  console.error("An error occurred:", error);
804
799
  process.exitCode = 1;
805
800
  }
806
- })().catch((error) => {
801
+ }
802
+
803
+ // src/validateFieldsCli.ts
804
+ runModuleFieldsCli("validate-fields", validateModuleFields).catch((error) => {
807
805
  throw error;
808
806
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "1.2.80",
3
+ "version": "1.2.83",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "engines": {
@@ -29,7 +29,7 @@
29
29
  "@babel/parser": "^7.25.3",
30
30
  "@babel/traverse": "^7.25.3",
31
31
  "@babel/types": "^7.25.2",
32
- "@hubspot/cms-components": "^1.2.80",
32
+ "@hubspot/cms-components": "^1.2.83",
33
33
  "@hubspot/local-dev-lib": "5.10.1",
34
34
  "@inquirer/select": "^2.0.0",
35
35
  "@originjs/vite-plugin-commonjs": "^1.0.3",
@@ -111,6 +111,7 @@
111
111
  "bin": {
112
112
  "hs-cms-dev-server": "./dist/run.js",
113
113
  "jsx-module-fields-to-fields-json": "./dist/generateJsonFromJsx.js",
114
+ "generate-fields": "./dist/generateFieldsCli.js",
114
115
  "validate-fields": "./dist/validateFieldsCli.js"
115
116
  },
116
117
  "files": [
@@ -1,8 +1,7 @@
1
- import { Gate } from '@hubspot/cms-js-internal';
2
1
  export declare const DEFAULT_SECTION_VARIANT = "section1";
3
2
  export declare function signGetUrl(authedPortalId: number, unsignedUrl: string): Promise<string>;
4
- export declare function signedGet(authedPortalId: number, unsignedUrl: string, headers: Record<string, string>, gates: Gate[]): Promise<string>;
5
- export declare function renderRemoteModulePreview(modulePath: string, authedPortalId: any, authedEnv: any, cookieValue: any, gates: Gate[]): Promise<{
3
+ export declare function signedGet(authedPortalId: number, unsignedUrl: string, headers: Record<string, string>): Promise<string>;
4
+ export declare function renderRemoteModulePreview(modulePath: string, authedPortalId: any, authedEnv: any, cookieValue: any): Promise<{
6
5
  html: string;
7
6
  cssNeeded: string;
8
7
  }>;
@@ -0,0 +1,3 @@
1
+ import { Request, Response } from 'express';
2
+ declare const moduleValidateFieldsRouteHandler: (request: Request, response: Response) => Promise<Response<any, Record<string, any>>>;
3
+ export default moduleValidateFieldsRouteHandler;
@@ -0,0 +1,39 @@
1
+ import { type ViteDevServer } from 'vite';
2
+ declare type ModuleFieldError = {
3
+ severity: string;
4
+ errorType: string;
5
+ message: string;
6
+ fieldPath?: string;
7
+ };
8
+ declare type GenerateFieldsOutput = {
9
+ fieldsJsonPath: string;
10
+ fieldErrors: ModuleFieldError[];
11
+ };
12
+ declare type ValidateFieldsOutput = GenerateFieldsOutput & {
13
+ fieldsTypePath: string;
14
+ metaErrors: ModuleFieldError[];
15
+ };
16
+ /**
17
+ * Writes a module's `fields.json`, regenerates its `fields.type.ts` when that
18
+ * file has the auto-generated comment, then validates its fields and meta with
19
+ * HubSpot.
20
+ */
21
+ export declare function validateSingleModule(modulePath: string, absoluteRoot: string, viteServer: ViteDevServer): Promise<ValidateFieldsOutput>;
22
+ /** `validate-fields`: generates each module's fields files and validates them with HubSpot. */
23
+ export declare function validateModuleFields(projectRoot: string, moduleName?: string): Promise<ValidateFieldsOutput[]>;
24
+ /**
25
+ * `generate-fields`: writes each module's `fields.json`, without validating
26
+ * it. Each result includes the written JSON as `fieldsJson` (`null` when
27
+ * generation failed).
28
+ */
29
+ export declare function generateModuleFields(projectRoot: string, moduleName?: string): Promise<Array<GenerateFieldsOutput & {
30
+ fieldsJson: any[] | null;
31
+ }>>;
32
+ /**
33
+ * Runs `command` from a CLI: `<command> <path> [--module <name>]`. Prints the
34
+ * results as JSON and exits with 1 when any module has errors.
35
+ */
36
+ export declare function runModuleFieldsCli(commandName: string, command: (projectRoot: string, moduleName?: string) => Promise<Array<GenerateFieldsOutput & {
37
+ metaErrors?: ModuleFieldError[];
38
+ }>>): Promise<void>;
39
+ export {};
@@ -1,8 +0,0 @@
1
- export declare function debugAuthContext(
2
- authedPortalId: number,
3
- cookieValue: string
4
- ): Promise<void>;
5
- export declare function compareUrls(
6
- originalUrl: string,
7
- signedUrl: string
8
- ): void;
@@ -1,2 +0,0 @@
1
- export declare function getLocalComponentsPath(): string;
2
- export declare function shouldUseLocalComponents(): boolean;
@@ -1,18 +0,0 @@
1
- import { ViteDevServer } from 'vite';
2
- /**
3
- * Processes HTML to find remote assets and replace with Vite-managed URLs
4
- */
5
- export declare function processRemoteAssets(
6
- html: string,
7
- viteServer: ViteDevServer
8
- ): Promise<string>;
9
- /**
10
- * Vite plugin to handle remote assets
11
- */
12
- export declare function remoteAssetsPlugin(): {
13
- name: string;
14
- apply: 'serve';
15
- configResolved(config: any): void;
16
- resolveId(id: string): string;
17
- load(id: string): Promise<string>;
18
- };
@@ -1,2 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- export declare function hubspotStaticAssetsPlugin(): Plugin;
@@ -1,10 +0,0 @@
1
- import { ViteDevServer, Plugin } from 'vite';
2
- /**
3
- * Create a self-contained plugin with proper caching
4
- */
5
- export declare function remoteAssetsPlugin(): Plugin & {
6
- processRemoteAssets: (
7
- html: string,
8
- viteServer: ViteDevServer
9
- ) => Promise<string>;
10
- };
@@ -1,6 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- /**
3
- * Plugin that provides URL signing capabilities
4
- * Uses internal signing mechanisms when available, with fallback for public environments
5
- */
6
- export default function requestSigningPlugin(): Plugin;
@@ -1,13 +0,0 @@
1
- import { Request, Response, NextFunction } from 'express';
2
- export declare function handleGetModulePages(
3
- req: Request,
4
- res: Response,
5
- next: NextFunction
6
- ): Promise<Response<any, Record<string, any>>>;
7
- export declare function handleOpenFile(
8
- req: Request,
9
- res: Response,
10
- next: NextFunction
11
- ): Response<any, Record<string, any>>;
12
- export declare function createAppServerRoutes(): import('express-serve-static-core').Router;
13
- export default createAppServerRoutes;
@@ -1,7 +0,0 @@
1
- import { Request, Response } from 'express';
2
- declare const homeRouteHandler: (
3
- request: Request,
4
- response: Response,
5
- next: Function
6
- ) => Promise<void>;
7
- export default homeRouteHandler;