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