@hubspot/project-parsing-lib 0.10.3-beta.0 → 0.11.0-beta.0

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.
Files changed (50) hide show
  1. package/package.json +48 -11
  2. package/src/exports/constants.d.ts +1 -0
  3. package/src/exports/constants.js +1 -0
  4. package/src/exports/migrate.d.ts +1 -0
  5. package/src/exports/migrate.js +1 -0
  6. package/src/exports/profiles.d.ts +3 -0
  7. package/src/exports/profiles.js +2 -0
  8. package/src/exports/projects.d.ts +3 -0
  9. package/src/exports/projects.js +2 -0
  10. package/src/exports/schema.d.ts +2 -0
  11. package/src/exports/schema.js +1 -0
  12. package/src/exports/themes.d.ts +2 -0
  13. package/src/exports/themes.js +1 -0
  14. package/src/exports/transform.d.ts +2 -0
  15. package/src/exports/transform.js +1 -0
  16. package/src/exports/translate.d.ts +3 -0
  17. package/src/exports/translate.js +2 -0
  18. package/src/exports/uid.d.ts +1 -0
  19. package/src/exports/uid.js +1 -0
  20. package/src/lang/copy.d.ts +1 -1
  21. package/src/lang/copy.js +21 -31
  22. package/src/lib/constants.d.ts +38 -38
  23. package/src/lib/constants.js +120 -153
  24. package/src/lib/errors.d.ts +2 -2
  25. package/src/lib/errors.js +19 -29
  26. package/src/lib/files.d.ts +1 -1
  27. package/src/lib/files.js +36 -47
  28. package/src/lib/localDev.d.ts +1 -1
  29. package/src/lib/localDev.js +8 -16
  30. package/src/lib/migrate.js +34 -40
  31. package/src/lib/migrateThemes.d.ts +3 -4
  32. package/src/lib/migrateThemes.js +31 -38
  33. package/src/lib/profiles.d.ts +1 -1
  34. package/src/lib/profiles.js +12 -20
  35. package/src/lib/project.js +11 -17
  36. package/src/lib/schemas.d.ts +2 -2
  37. package/src/lib/schemas.js +8 -11
  38. package/src/lib/transform.d.ts +1 -1
  39. package/src/lib/transform.js +50 -64
  40. package/src/lib/translate.d.ts +3 -0
  41. package/src/lib/translate.js +52 -0
  42. package/src/lib/types.d.ts +1 -1
  43. package/src/lib/types.js +1 -2
  44. package/src/lib/uid.js +9 -14
  45. package/src/lib/utils.d.ts +1 -1
  46. package/src/lib/utils.js +7 -14
  47. package/src/lib/validation.d.ts +3 -3
  48. package/src/lib/validation.js +46 -46
  49. package/src/index.d.ts +0 -19
  50. package/src/index.js +0 -94
@@ -1,244 +1,211 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.allowedTopLevelFields = exports.ProfileVariableTypes = exports.allowedSubComponentDirectories = exports.allowedComponentDirectories = exports.ProjectStructure = exports.allowedCmsAssetSubComponentDirs = exports.allowedThemeSubComponentsDirs = exports.allowedAppSubComponentsDirs = exports.packageLockJson = exports.packageJson = exports.hsProjectJsonFilename = exports.profileFilePrefix = exports.metafileExtension = exports.internalTypeToUserFacing = exports.userFacingToInternalType = exports.Components = exports.AutoGeneratedComponentTypes = exports.AppFunctionsPackageKey = exports.WorkflowActionsKey = exports.WebhooksJournalKey = exports.WebhooksKey = exports.VideoConferencingKey = exports.TelemetryKey = exports.SettingsKey = exports.MediaBridgeKey = exports.MCPRegistryKey = exports.MarketingEventsKey = exports.SCIMKey = exports.CardsKey = exports.CallingKey = exports.AppObjectAssociationKey = exports.AppObjectKey = exports.PagesKey = exports.AppFunctionsKey = exports.AppEventsKey = exports.CmsAssetsKey = exports.ThemeKey = exports.AppKey = void 0;
37
1
  // Top Level Component types
38
- const path = __importStar(require("path"));
2
+ import * as path from 'path';
39
3
  // Component types
40
- exports.AppKey = 'app';
41
- exports.ThemeKey = 'theme';
42
- exports.CmsAssetsKey = 'cms-assets';
4
+ export const APP_KEY = 'app';
5
+ export const THEME_KEY = 'theme';
6
+ export const CMS_ASSETS_KEY = 'cms-assets';
43
7
  // Sub-Component types
44
- exports.AppEventsKey = 'app-event';
45
- exports.AppFunctionsKey = 'app-function';
46
- exports.PagesKey = 'page';
47
- exports.AppObjectKey = 'app-object';
48
- exports.AppObjectAssociationKey = 'app-object-association';
49
- exports.CallingKey = 'calling';
50
- exports.CardsKey = 'card';
51
- exports.SCIMKey = 'scim';
52
- exports.MarketingEventsKey = 'marketing-event';
53
- exports.MCPRegistryKey = 'mcp-registry';
54
- exports.MediaBridgeKey = 'media-bridge';
55
- exports.SettingsKey = 'settings';
56
- exports.TelemetryKey = 'telemetry';
57
- exports.VideoConferencingKey = 'video-conferencing';
58
- exports.WebhooksKey = 'webhooks';
59
- exports.WebhooksJournalKey = 'webhooks-journal';
60
- exports.WorkflowActionsKey = 'workflow-action';
8
+ export const APP_EVENTS_KEY = 'app-event';
9
+ export const APP_FUNCTIONS_KEY = 'app-function';
10
+ export const PAGES_KEY = 'page';
11
+ export const APP_OBJECT_KEY = 'app-object';
12
+ export const APP_OBJECT_ASSOCIATION_KEY = 'app-object-association';
13
+ export const CALLING_KEY = 'calling';
14
+ export const CARDS_KEY = 'card';
15
+ export const SCIM_KEY = 'scim';
16
+ export const MARKETING_EVENTS_KEY = 'marketing-event';
17
+ export const MCP_REGISTRY_KEY = 'mcp-registry';
18
+ export const MEDIA_BRIDGE_KEY = 'media-bridge';
19
+ export const SETTINGS_KEY = 'settings';
20
+ export const TELEMETRY_KEY = 'telemetry';
21
+ export const VIDEO_CONFERENCING_KEY = 'video-conferencing';
22
+ export const WEBHOOKS_KEY = 'webhooks';
23
+ export const WEBHOOKS_JOURNAL_KEY = 'webhooks-journal';
24
+ export const WORKFLOW_ACTIONS_KEY = 'workflow-action';
61
25
  // Auto-generated component types
62
- exports.AppFunctionsPackageKey = 'serverless-package';
63
- exports.AutoGeneratedComponentTypes = [exports.AppFunctionsPackageKey];
64
- const TopLevelComponentFields = {
26
+ export const APP_FUNCTIONS_PACKAGE_KEY = 'serverless-package';
27
+ export const AUTO_GENERATED_COMPONENT_TYPES = [APP_FUNCTIONS_PACKAGE_KEY];
28
+ const TOP_LEVEL_COMPONENT_FIELDS = {
65
29
  isToplevel: true,
66
30
  userFriendlyType: 'component',
67
31
  userFriendlyTypePlural: 'components',
68
32
  };
69
- const SubComponentFields = {
33
+ const SUB_COMPONENT_FIELDS = {
70
34
  isToplevel: false,
71
35
  userFriendlyType: 'feature',
72
36
  userFriendlyTypePlural: 'features',
73
37
  };
74
- exports.Components = {
75
- [exports.AppKey]: {
76
- dir: exports.AppKey,
38
+ export const Components = {
39
+ [APP_KEY]: {
40
+ dir: APP_KEY,
77
41
  userFriendlyName: 'App',
78
- ...TopLevelComponentFields,
42
+ ...TOP_LEVEL_COMPONENT_FIELDS,
79
43
  singularComponent: true,
80
44
  },
81
- [exports.AppObjectKey]: {
45
+ [APP_OBJECT_KEY]: {
82
46
  dir: 'app-objects',
83
- parentComponent: exports.AppKey,
84
- ...SubComponentFields,
47
+ parentComponent: APP_KEY,
48
+ ...SUB_COMPONENT_FIELDS,
85
49
  userFriendlyName: 'App Object',
86
50
  },
87
- [exports.AppObjectAssociationKey]: {
51
+ [APP_OBJECT_ASSOCIATION_KEY]: {
88
52
  dir: 'app-object-associations',
89
- parentComponent: exports.AppKey,
90
- ...SubComponentFields,
53
+ parentComponent: APP_KEY,
54
+ ...SUB_COMPONENT_FIELDS,
91
55
  userFriendlyName: 'App Object Association',
92
56
  },
93
- [exports.PagesKey]: {
57
+ [PAGES_KEY]: {
94
58
  dir: 'pages',
95
- parentComponent: exports.AppKey,
96
- ...SubComponentFields,
59
+ parentComponent: APP_KEY,
60
+ ...SUB_COMPONENT_FIELDS,
97
61
  userFriendlyName: 'Page',
98
62
  singularComponent: true,
99
63
  },
100
- [exports.ThemeKey]: {
101
- dir: exports.ThemeKey,
64
+ [THEME_KEY]: {
65
+ dir: THEME_KEY,
102
66
  userFriendlyName: 'Theme',
103
- ...TopLevelComponentFields,
67
+ ...TOP_LEVEL_COMPONENT_FIELDS,
104
68
  },
105
- [exports.CmsAssetsKey]: {
106
- dir: exports.CmsAssetsKey,
69
+ [CMS_ASSETS_KEY]: {
70
+ dir: CMS_ASSETS_KEY,
107
71
  userFriendlyName: 'CMS Asset',
108
- ...TopLevelComponentFields,
72
+ ...TOP_LEVEL_COMPONENT_FIELDS,
109
73
  },
110
- [exports.CallingKey]: {
111
- dir: exports.CallingKey,
112
- parentComponent: exports.AppKey,
74
+ [CALLING_KEY]: {
75
+ dir: CALLING_KEY,
76
+ parentComponent: APP_KEY,
113
77
  userFriendlyName: 'Calling',
114
- ...SubComponentFields,
78
+ ...SUB_COMPONENT_FIELDS,
115
79
  singularComponent: true,
116
80
  },
117
- [exports.CardsKey]: {
81
+ [CARDS_KEY]: {
118
82
  dir: 'cards',
119
- parentComponent: exports.AppKey,
83
+ parentComponent: APP_KEY,
120
84
  userFriendlyName: 'Card',
121
- ...SubComponentFields,
85
+ ...SUB_COMPONENT_FIELDS,
122
86
  },
123
- [exports.AppFunctionsKey]: {
87
+ [APP_FUNCTIONS_KEY]: {
124
88
  dir: 'functions',
125
- parentComponent: exports.AppKey,
89
+ parentComponent: APP_KEY,
126
90
  userFriendlyName: 'App Function',
127
- ...SubComponentFields,
91
+ ...SUB_COMPONENT_FIELDS,
128
92
  },
129
- [exports.SCIMKey]: {
130
- dir: exports.SCIMKey,
131
- parentComponent: exports.AppKey,
93
+ [SCIM_KEY]: {
94
+ dir: SCIM_KEY,
95
+ parentComponent: APP_KEY,
132
96
  userFriendlyName: 'SCIM',
133
97
  singularComponent: true,
134
- ...SubComponentFields,
98
+ ...SUB_COMPONENT_FIELDS,
135
99
  },
136
- [exports.SettingsKey]: {
100
+ [SETTINGS_KEY]: {
137
101
  dir: 'settings',
138
- parentComponent: exports.AppKey,
102
+ parentComponent: APP_KEY,
139
103
  userFriendlyName: 'Settings Extension',
140
- ...SubComponentFields,
104
+ ...SUB_COMPONENT_FIELDS,
141
105
  singularComponent: true,
142
106
  },
143
- [exports.MarketingEventsKey]: {
107
+ [MARKETING_EVENTS_KEY]: {
144
108
  dir: 'marketing-events',
145
- parentComponent: exports.AppKey,
109
+ parentComponent: APP_KEY,
146
110
  userFriendlyName: 'Marketing Event',
147
- ...SubComponentFields,
111
+ ...SUB_COMPONENT_FIELDS,
148
112
  },
149
- MediaBridgeKey: {
150
- dir: exports.MediaBridgeKey,
151
- parentComponent: exports.AppKey,
113
+ [MEDIA_BRIDGE_KEY]: {
114
+ dir: MEDIA_BRIDGE_KEY,
115
+ parentComponent: APP_KEY,
152
116
  userFriendlyName: 'Media Bridge',
153
- ...SubComponentFields,
117
+ ...SUB_COMPONENT_FIELDS,
154
118
  },
155
- [exports.AppEventsKey]: {
119
+ [APP_EVENTS_KEY]: {
156
120
  dir: 'app-events',
157
- parentComponent: exports.AppKey,
121
+ parentComponent: APP_KEY,
158
122
  userFriendlyName: 'App Event',
159
- ...SubComponentFields,
123
+ ...SUB_COMPONENT_FIELDS,
160
124
  },
161
- [exports.VideoConferencingKey]: {
162
- dir: exports.VideoConferencingKey,
163
- parentComponent: exports.AppKey,
125
+ [VIDEO_CONFERENCING_KEY]: {
126
+ dir: VIDEO_CONFERENCING_KEY,
127
+ parentComponent: APP_KEY,
164
128
  userFriendlyName: 'Video Conferencing',
165
- ...SubComponentFields,
129
+ ...SUB_COMPONENT_FIELDS,
166
130
  },
167
- [exports.WebhooksKey]: {
168
- dir: exports.WebhooksKey,
169
- parentComponent: exports.AppKey,
131
+ [WEBHOOKS_KEY]: {
132
+ dir: WEBHOOKS_KEY,
133
+ parentComponent: APP_KEY,
170
134
  userFriendlyName: 'Webhooks',
171
- ...SubComponentFields,
135
+ ...SUB_COMPONENT_FIELDS,
172
136
  singularComponent: true,
173
137
  },
174
- [exports.WebhooksJournalKey]: {
175
- dir: exports.WebhooksJournalKey,
176
- parentComponent: exports.AppKey,
138
+ [WEBHOOKS_JOURNAL_KEY]: {
139
+ dir: WEBHOOKS_JOURNAL_KEY,
140
+ parentComponent: APP_KEY,
177
141
  userFriendlyName: 'Webhooks Journal',
178
- ...SubComponentFields,
142
+ ...SUB_COMPONENT_FIELDS,
179
143
  singularComponent: true,
180
144
  },
181
- [exports.WorkflowActionsKey]: {
145
+ [WORKFLOW_ACTIONS_KEY]: {
182
146
  dir: 'workflow-actions',
183
- parentComponent: exports.AppKey,
147
+ parentComponent: APP_KEY,
184
148
  userFriendlyName: 'Workflow Action',
185
- ...SubComponentFields,
149
+ ...SUB_COMPONENT_FIELDS,
186
150
  },
187
- [exports.TelemetryKey]: {
188
- dir: exports.TelemetryKey,
189
- parentComponent: exports.AppKey,
151
+ [TELEMETRY_KEY]: {
152
+ dir: TELEMETRY_KEY,
153
+ parentComponent: APP_KEY,
190
154
  userFriendlyName: 'Telemetry',
191
155
  singularComponent: true,
192
- ...SubComponentFields,
156
+ ...SUB_COMPONENT_FIELDS,
193
157
  },
194
- [exports.MCPRegistryKey]: {
195
- dir: exports.MCPRegistryKey,
196
- parentComponent: exports.AppKey,
158
+ [MCP_REGISTRY_KEY]: {
159
+ dir: MCP_REGISTRY_KEY,
160
+ parentComponent: APP_KEY,
197
161
  userFriendlyName: 'MCP Registry',
198
162
  singularComponent: true,
199
- ...SubComponentFields,
163
+ ...SUB_COMPONENT_FIELDS,
200
164
  },
201
165
  };
202
- exports.userFacingToInternalType = {
203
- [exports.AppKey]: 'APPLICATION',
204
- [exports.SCIMKey]: 'SCIM_INTEGRATION',
205
- [exports.TelemetryKey]: 'TELEMETRY_CONFIG',
206
- [exports.CmsAssetsKey]: 'REACT_THEME',
166
+ export const USER_FACING_TO_INTERNAL_TYPE = {
167
+ [APP_KEY]: 'APPLICATION',
168
+ [SCIM_KEY]: 'SCIM_INTEGRATION',
169
+ [TELEMETRY_KEY]: 'TELEMETRY_CONFIG',
170
+ [CMS_ASSETS_KEY]: 'REACT_THEME',
207
171
  };
208
- exports.internalTypeToUserFacing = Object.fromEntries(Object.entries(exports.userFacingToInternalType).map(([key, value]) => [value, key]));
209
- exports.metafileExtension = '-hsmeta.json';
210
- exports.profileFilePrefix = 'hsprofile';
211
- exports.hsProjectJsonFilename = 'hsproject.json';
212
- exports.packageJson = 'package.json';
213
- exports.packageLockJson = 'package-lock.json';
172
+ export const INTERNAL_TYPE_TO_USER_FACING = Object.fromEntries(Object.entries(USER_FACING_TO_INTERNAL_TYPE).map(([key, value]) => [
173
+ value,
174
+ key,
175
+ ]));
176
+ export const METAFILE_EXTENSION = '-hsmeta.json';
177
+ export const PROFILE_FILE_PREFIX = 'hsprofile';
178
+ export const HS_PROJECT_JSON_FILENAME = 'hsproject.json';
179
+ export const PACKAGE_JSON = 'package.json';
180
+ export const PACKAGE_LOCK_JSON = 'package-lock.json';
214
181
  function getSubComponentDirsForParentType(parentComponent) {
215
- return Object.values(exports.Components).reduce((acc, item) => {
182
+ return Object.values(Components).reduce((acc, item) => {
216
183
  if (item.parentComponent === parentComponent) {
217
184
  acc.push(item.dir);
218
185
  }
219
186
  return acc;
220
187
  }, []);
221
188
  }
222
- exports.allowedAppSubComponentsDirs = getSubComponentDirsForParentType(exports.AppKey);
223
- exports.allowedThemeSubComponentsDirs = getSubComponentDirsForParentType(exports.ThemeKey);
224
- exports.allowedCmsAssetSubComponentDirs = getSubComponentDirsForParentType(exports.CmsAssetsKey);
225
- exports.ProjectStructure = {
226
- [exports.AppKey]: exports.allowedAppSubComponentsDirs,
227
- [exports.ThemeKey]: exports.allowedThemeSubComponentsDirs,
228
- [exports.CmsAssetsKey]: exports.allowedCmsAssetSubComponentDirs,
189
+ export const ALLOWED_APP_SUB_COMPONENTS_DIRS = getSubComponentDirsForParentType(APP_KEY);
190
+ export const ALLOWED_THEME_SUB_COMPONENTS_DIRS = getSubComponentDirsForParentType(THEME_KEY);
191
+ export const ALLOWED_CMS_ASSET_SUB_COMPONENT_DIRS = getSubComponentDirsForParentType(CMS_ASSETS_KEY);
192
+ export const PROJECT_STRUCTURE = {
193
+ [APP_KEY]: ALLOWED_APP_SUB_COMPONENTS_DIRS,
194
+ [THEME_KEY]: ALLOWED_THEME_SUB_COMPONENTS_DIRS,
195
+ [CMS_ASSETS_KEY]: ALLOWED_CMS_ASSET_SUB_COMPONENT_DIRS,
229
196
  };
230
- exports.allowedComponentDirectories = Object.keys(exports.ProjectStructure);
231
- exports.allowedSubComponentDirectories = Object.entries(exports.ProjectStructure)
197
+ export const ALLOWED_COMPONENT_DIRECTORIES = Object.keys(PROJECT_STRUCTURE);
198
+ export const ALLOWED_SUB_COMPONENT_DIRECTORIES = Object.entries(PROJECT_STRUCTURE)
232
199
  .map(([key, value]) => value.map((value) => path.join(key, value)))
233
200
  .flat();
234
201
  // Profile variable types
235
- exports.ProfileVariableTypes = {
202
+ export const PROFILE_VARIABLE_TYPES = {
236
203
  PROFILE_INT: 'PROFILE_INT',
237
204
  PROFILE_LONG: 'PROFILE_LONG',
238
205
  PROFILE_STRING: 'PROFILE_STRING',
239
206
  PROFILE_BOOLEAN: 'PROFILE_BOOLEAN',
240
207
  };
241
- exports.allowedTopLevelFields = new Set([
208
+ export const ALLOWED_TOP_LEVEL_FIELDS = new Set([
242
209
  'uid',
243
210
  'type',
244
211
  'config',
@@ -1,5 +1,5 @@
1
- import { CompiledError, Transformation, TranslationContext } from './types';
2
- import { ErrorObject } from 'ajv/dist/2020';
1
+ import { CompiledError, Transformation, TranslationContext } from './types.js';
2
+ import type { ErrorObject } from 'ajv';
3
3
  export declare function isTranslationError(error: unknown): error is TranslationError;
4
4
  export declare function compileError(validatedTransformation: Transformation): CompiledError;
5
5
  export declare class TranslationError extends Error {
package/src/lib/errors.js CHANGED
@@ -1,26 +1,17 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AjvErrorKeyword = exports.TranslationError = void 0;
7
- exports.isTranslationError = isTranslationError;
8
- exports.compileError = compileError;
9
- exports.extractDotNotationValueFromTransformation = extractDotNotationValueFromTransformation;
10
- const copy_1 = require("../lang/copy");
11
- const path_1 = __importDefault(require("path"));
12
- const logger_1 = require("@hubspot/local-dev-lib/logger");
13
- function isTranslationError(error) {
1
+ import { errorMessages } from '../lang/copy.js';
2
+ import path from 'path';
3
+ import { logger } from '@hubspot/local-dev-lib/logger';
4
+ export function isTranslationError(error) {
14
5
  return error instanceof TranslationError;
15
6
  }
16
- function compileError(validatedTransformation) {
7
+ export function compileError(validatedTransformation) {
17
8
  const { fileParseResult } = validatedTransformation;
18
9
  const { errors } = fileParseResult;
19
10
  return {
20
11
  errors,
21
12
  };
22
13
  }
23
- class TranslationError extends Error {
14
+ export class TranslationError extends Error {
24
15
  errors = [];
25
16
  translationContext;
26
17
  constructor(message, transformations, errors, translationContext) {
@@ -35,16 +26,15 @@ class TranslationError extends Error {
35
26
  if (errors.length === 0) {
36
27
  return null;
37
28
  }
38
- const projectRoot = path_1.default.dirname(path_1.default.dirname(this.translationContext.projectSourceDir));
39
- const relativePath = path_1.default.relative(projectRoot, path_1.default.join(this.translationContext.projectSourceDir, file));
40
- return copy_1.errorMessages.validation.errorWithFileHeader(relativePath, errors);
29
+ const projectRoot = path.dirname(path.dirname(this.translationContext.projectSourceDir));
30
+ const relativePath = path.relative(projectRoot, path.join(this.translationContext.projectSourceDir, file));
31
+ return errorMessages.validation.errorWithFileHeader(relativePath, errors);
41
32
  });
42
33
  return `${this.message}:${listOfErrors
43
34
  .filter(error => error !== null)
44
35
  .join('')}`;
45
36
  }
46
37
  }
47
- exports.TranslationError = TranslationError;
48
38
  function generateDotNotationPath(error) {
49
39
  const { instancePath } = error;
50
40
  const errorPath = instancePath
@@ -104,7 +94,7 @@ function preprocessSpecialErrors(schemaErrors, transformation) {
104
94
  }
105
95
  function generateErrorMessage(error, transformation) {
106
96
  const errorPath = generateDotNotationPath(error);
107
- const errorMessage = copy_1.errorMessages.validation.errorWithField(errorPath, error.message);
97
+ const errorMessage = errorMessages.validation.errorWithField(errorPath, error.message);
108
98
  const params = Object.entries(error.params);
109
99
  if (params.length === 0) {
110
100
  return errorMessage;
@@ -113,12 +103,12 @@ function generateErrorMessage(error, transformation) {
113
103
  .filter(([_, value]) => value)
114
104
  .map(([key, value]) => `${key}: ${Array.isArray(value) ? value.join(', ') : value}`);
115
105
  if (isRequiredError(error)) {
116
- return copy_1.errorMessages.validation.missingRequiredField(`${errorPath}.${error.params.missingProperty}`);
106
+ return errorMessages.validation.missingRequiredField(`${errorPath}.${error.params.missingProperty}`);
117
107
  }
118
108
  else if (isTypeError(error)) {
119
109
  const dotNotationPath = generateDotNotationPath(error);
120
110
  const value = extractDotNotationValueFromTransformation(dotNotationPath, transformation);
121
- return copy_1.errorMessages.validation.errorWithField(value !== undefined
111
+ return errorMessages.validation.errorWithField(value !== undefined
122
112
  ? `Value (${value}) in ${dotNotationPath}`
123
113
  : dotNotationPath, error.message);
124
114
  }
@@ -142,7 +132,7 @@ function mergeEnumErrors(cur, next) {
142
132
  },
143
133
  };
144
134
  }
145
- function extractDotNotationValueFromTransformation(dotNotation, transformation) {
135
+ export function extractDotNotationValueFromTransformation(dotNotation, transformation) {
146
136
  try {
147
137
  const parts = dotNotation.split('.');
148
138
  if (!transformation?.fileParseResult?.content || parts.length === 0) {
@@ -169,22 +159,22 @@ function extractDotNotationValueFromTransformation(dotNotation, transformation)
169
159
  return value;
170
160
  }
171
161
  catch (e) {
172
- logger_1.logger.debug('Unable to parse dot notation path to located value', e);
162
+ logger.debug('Unable to parse dot notation path to located value', e);
173
163
  }
174
164
  }
175
165
  function isOneOfError(error) {
176
- return error.keyword === exports.AjvErrorKeyword.OneOf;
166
+ return error.keyword === AjvErrorKeyword.OneOf;
177
167
  }
178
168
  function isRequiredError(error) {
179
- return error.keyword === exports.AjvErrorKeyword.Required;
169
+ return error.keyword === AjvErrorKeyword.Required;
180
170
  }
181
171
  function isEnumError(error) {
182
- return error.keyword === exports.AjvErrorKeyword.Enum;
172
+ return error.keyword === AjvErrorKeyword.Enum;
183
173
  }
184
174
  function isTypeError(error) {
185
- return error.keyword === exports.AjvErrorKeyword.Type;
175
+ return error.keyword === AjvErrorKeyword.Type;
186
176
  }
187
- exports.AjvErrorKeyword = {
177
+ export const AjvErrorKeyword = {
188
178
  AdditionalItems: 'additionalItems',
189
179
  AdditionalProperties: 'additionalProperties',
190
180
  Dependencies: 'dependencies',
@@ -1,4 +1,4 @@
1
- import { FileParseResult, TranslationContext, HsProfileFile } from './types';
1
+ import { FileParseResult, TranslationContext, HsProfileFile } from './types.js';
2
2
  export type MetaFileLocation = {
3
3
  file: string;
4
4
  parentDirectory?: string;
package/src/lib/files.js CHANGED
@@ -1,69 +1,58 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.loadHsProfileFile = loadHsProfileFile;
7
- exports.getAllHsProfiles = getAllHsProfiles;
8
- exports.loadHsMetaFiles = loadHsMetaFiles;
9
- exports.locateHsMetaFiles = locateHsMetaFiles;
10
- exports.projectContainsHsMetaFiles = projectContainsHsMetaFiles;
11
- exports.convertPathToPosixPath = convertPathToPosixPath;
12
- const fs_1 = __importDefault(require("fs"));
13
- const path_1 = __importDefault(require("path"));
14
- const fs_2 = require("@hubspot/local-dev-lib/fs");
15
- const constants_1 = require("./constants");
16
- const copy_1 = require("../lang/copy");
17
- const logger_1 = require("@hubspot/local-dev-lib/logger");
18
- const profiles_1 = require("./profiles");
19
- function loadHsProfileFile(projectSourceDir, profile) {
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { walk } from '@hubspot/local-dev-lib/fs';
4
+ import { ALLOWED_COMPONENT_DIRECTORIES, ALLOWED_SUB_COMPONENT_DIRECTORIES, METAFILE_EXTENSION, ALLOWED_TOP_LEVEL_FIELDS, } from './constants.js';
5
+ import { errorMessages, logMessages } from '../lang/copy.js';
6
+ import { logger } from '@hubspot/local-dev-lib/logger';
7
+ import { getHsProfileFilename, getHsProfileName, getIsProfileFile, } from './profiles.js';
8
+ export function loadHsProfileFile(projectSourceDir, profile) {
20
9
  if (!profile) {
21
- throw new Error(copy_1.errorMessages.profile.noProfileSpecified);
10
+ throw new Error(errorMessages.profile.noProfileSpecified);
22
11
  }
23
- const profileFile = (0, profiles_1.getHsProfileFilename)(profile);
24
- const profileFilepath = path_1.default.join(projectSourceDir, profileFile);
12
+ const profileFile = getHsProfileFilename(profile);
13
+ const profileFilepath = path.join(projectSourceDir, profileFile);
25
14
  let hsProfile;
26
15
  try {
27
- hsProfile = JSON.parse(fs_1.default.readFileSync(profileFilepath, 'utf8'));
16
+ hsProfile = JSON.parse(fs.readFileSync(profileFilepath, 'utf8'));
28
17
  }
29
18
  catch (_e) {
30
- throw new Error(copy_1.errorMessages.profile.failedToLoadHsProfile(profileFile));
19
+ throw new Error(errorMessages.profile.failedToLoadHsProfile(profileFile));
31
20
  }
32
21
  return hsProfile;
33
22
  }
34
- function getAllHsProfiles(projectSourceDir) {
23
+ export function getAllHsProfiles(projectSourceDir) {
35
24
  return new Promise((resolve, _reject) => {
36
- fs_1.default.readdir(projectSourceDir, { recursive: false, withFileTypes: true }, (err, files) => {
25
+ fs.readdir(projectSourceDir, { recursive: false, withFileTypes: true }, (err, files) => {
37
26
  if (err) {
38
27
  return resolve([]);
39
28
  }
40
29
  return resolve(files
41
- .filter(file => file.isFile() && (0, profiles_1.getIsProfileFile)(file.name))
42
- .map(file => (0, profiles_1.getHsProfileName)(file.name)));
30
+ .filter(file => file.isFile() && getIsProfileFile(file.name))
31
+ .map(file => getHsProfileName(file.name)));
43
32
  });
44
33
  });
45
34
  }
46
- async function loadHsMetaFiles(translationContext) {
35
+ export async function loadHsMetaFiles(translationContext) {
47
36
  const metaFiles = await locateHsMetaFiles(translationContext.projectSourceDir);
48
37
  return parseHsMetaFiles(metaFiles, translationContext);
49
38
  }
50
- async function locateHsMetaFiles(projectSourceDir, options = { silent: false }) {
51
- return (await (0, fs_2.walk)(projectSourceDir, ['node_modules'])).reduce((metaFiles, file) => {
52
- if (!file.endsWith(constants_1.metafileExtension)) {
39
+ export async function locateHsMetaFiles(projectSourceDir, options = { silent: false }) {
40
+ return (await walk(projectSourceDir, ['node_modules'])).reduce((metaFiles, file) => {
41
+ if (!file.endsWith(METAFILE_EXTENSION)) {
53
42
  return metaFiles;
54
43
  }
55
- const pathRelativeToProjectSrcDir = path_1.default.relative(projectSourceDir, file);
56
- const { dir: metaFileDir } = path_1.default.parse(pathRelativeToProjectSrcDir);
57
- const parentDirectory = metaFileDir.split(path_1.default.sep)[0];
58
- if (constants_1.allowedComponentDirectories.includes(metaFileDir)) {
44
+ const pathRelativeToProjectSrcDir = path.relative(projectSourceDir, file);
45
+ const { dir: metaFileDir } = path.parse(pathRelativeToProjectSrcDir);
46
+ const parentDirectory = metaFileDir.split(path.sep)[0];
47
+ if (ALLOWED_COMPONENT_DIRECTORIES.includes(metaFileDir)) {
59
48
  metaFiles.push({ file });
60
49
  }
61
- else if (constants_1.allowedSubComponentDirectories.includes(metaFileDir)) {
50
+ else if (ALLOWED_SUB_COMPONENT_DIRECTORIES.includes(metaFileDir)) {
62
51
  metaFiles.push({ file, parentDirectory });
63
52
  }
64
53
  else {
65
54
  if (!options.silent) {
66
- logger_1.logger.warn(copy_1.logMessages.files.skippingPath(pathRelativeToProjectSrcDir));
55
+ logger.warn(logMessages.files.skippingPath(pathRelativeToProjectSrcDir));
67
56
  }
68
57
  }
69
58
  return metaFiles;
@@ -79,7 +68,7 @@ function loadFile(metaFileLocation, translationContext) {
79
68
  const { projectSourceDir } = translationContext;
80
69
  return new Promise(async (resolve) => {
81
70
  const { file, parentDirectory } = metaFileLocation;
82
- fs_1.default.readFile(file, 'utf-8', (err, content) => {
71
+ fs.readFile(file, 'utf-8', (err, content) => {
83
72
  if (err) {
84
73
  return resolve({
85
74
  file,
@@ -87,7 +76,7 @@ function loadFile(metaFileLocation, translationContext) {
87
76
  });
88
77
  }
89
78
  resolve({
90
- file: path_1.default.relative(projectSourceDir, file),
79
+ file: path.relative(projectSourceDir, file),
91
80
  content,
92
81
  parentDirectory,
93
82
  errors: [],
@@ -105,25 +94,25 @@ function parseFile(fileLoadResult) {
105
94
  parsedFileContents = JSON.parse(fileLoadResult.content);
106
95
  }
107
96
  catch (_e) {
108
- fileLoadResult.errors?.push(copy_1.errorMessages.validation.invalidJson);
97
+ fileLoadResult.errors?.push(errorMessages.validation.invalidJson);
109
98
  }
110
99
  // Validate top-level fields (only uid, type, and config are expected)
111
100
  if (parsedFileContents &&
112
101
  typeof parsedFileContents === 'object' &&
113
102
  !Array.isArray(parsedFileContents)) {
114
103
  const actualFields = Object.keys(parsedFileContents);
115
- const unexpectedFields = actualFields.filter(field => !constants_1.allowedTopLevelFields.has(field));
104
+ const unexpectedFields = actualFields.filter(field => !ALLOWED_TOP_LEVEL_FIELDS.has(field));
116
105
  if (unexpectedFields.length > 0) {
117
106
  const unexpectedFieldsList = unexpectedFields.join(', ');
118
- fileLoadResult.errors?.push(copy_1.errorMessages.validation.unexpectedToplevelFields(unexpectedFieldsList));
107
+ fileLoadResult.errors?.push(errorMessages.validation.unexpectedToplevelFields(unexpectedFieldsList));
119
108
  }
120
109
  }
121
110
  return { ...fileLoadResult, content: parsedFileContents };
122
111
  }
123
- async function projectContainsHsMetaFiles(projectSourceDir) {
124
- const hsMetaFiles = (await (0, fs_2.walk)(projectSourceDir, ['node_modules'])).filter(file => file.endsWith(constants_1.metafileExtension));
112
+ export async function projectContainsHsMetaFiles(projectSourceDir) {
113
+ const hsMetaFiles = (await walk(projectSourceDir, ['node_modules'])).filter(file => file.endsWith(METAFILE_EXTENSION));
125
114
  return hsMetaFiles.length > 0;
126
115
  }
127
- function convertPathToPosixPath(filepath) {
128
- return filepath.replaceAll(path_1.default.win32.sep, path_1.default.posix.sep);
116
+ export function convertPathToPosixPath(filepath) {
117
+ return filepath.replaceAll(path.win32.sep, path.posix.sep);
129
118
  }
@@ -1,4 +1,4 @@
1
- import { BEProfileVariables, HSProfileVariables, IntermediateRepresentationNode, IntermediateRepresentationNodeLocalDev, FileParseResult } from './types';
1
+ import { BEProfileVariables, HSProfileVariables, IntermediateRepresentationNode, IntermediateRepresentationNodeLocalDev, FileParseResult } from './types.js';
2
2
  export declare function getLocalDevProjectNodes(intermediateNodesIndexedByUid: Record<string, IntermediateRepresentationNode>, projectSourceDir: string, projectNodesAtLastUpload?: Record<string, IntermediateRepresentationNodeLocalDev>): Record<string, IntermediateRepresentationNodeLocalDev>;
3
3
  export declare function getRemovedNodesAndNodesWithErrors(intermediateNodesIndexedByUid: Record<string, IntermediateRepresentationNode>, projectNodesAtLastUpload: Record<string, IntermediateRepresentationNodeLocalDev>, parsingErrors: FileParseResult[]): Record<string, IntermediateRepresentationNodeLocalDev>;
4
4
  export declare function getLocalDevProfileData(profileVariables?: BEProfileVariables): HSProfileVariables;