@hubspot/project-parsing-lib 0.2.2-beta.0 → 0.2.2-experimental.1
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 +128 -22
- 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 +12 -1
- package/src/lang/copy.js +33 -32
- package/src/lib/constants.d.ts +56 -29
- package/src/lib/constants.js +180 -126
- package/src/lib/errors.d.ts +3 -3
- package/src/lib/errors.js +25 -33
- package/src/lib/files.d.ts +3 -3
- package/src/lib/files.js +46 -42
- 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 +4 -0
- package/src/lib/platformVersion.js +30 -0
- package/src/lib/profiles.d.ts +6 -1
- package/src/lib/profiles.js +95 -40
- package/src/lib/project.js +22 -17
- 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 +109 -59
- package/src/lib/translate.d.ts +3 -0
- package/src/lib/translate.js +62 -0
- package/src/lib/types.d.ts +37 -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 +66 -53
- package/src/lib/workspaces.d.ts +113 -0
- package/src/lib/workspaces.js +403 -0
- package/src/index.d.ts +0 -18
- package/src/index.js +0 -87
package/src/lib/constants.js
CHANGED
|
@@ -1,191 +1,245 @@
|
|
|
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.SCIMKey = 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
|
-
|
|
55
|
-
|
|
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';
|
|
37
|
+
export const BREEZE_TOOL_KEY = 'breeze-tool';
|
|
56
38
|
// Auto-generated component types
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
39
|
+
export const APP_FUNCTIONS_PACKAGE_KEY = 'serverless-package';
|
|
40
|
+
export const AUTO_GENERATED_COMPONENT_TYPES = [APP_FUNCTIONS_PACKAGE_KEY];
|
|
41
|
+
const TOP_LEVEL_COMPONENT_FIELDS = {
|
|
60
42
|
isToplevel: true,
|
|
61
43
|
userFriendlyType: 'component',
|
|
62
44
|
userFriendlyTypePlural: 'components',
|
|
63
45
|
};
|
|
64
|
-
const
|
|
46
|
+
const SUB_COMPONENT_FIELDS = {
|
|
65
47
|
isToplevel: false,
|
|
66
48
|
userFriendlyType: 'feature',
|
|
67
49
|
userFriendlyTypePlural: 'features',
|
|
68
50
|
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
51
|
+
const PAGE_COMPONENT = {
|
|
52
|
+
dir: 'pages',
|
|
53
|
+
parentComponent: APP_KEY,
|
|
54
|
+
...SUB_COMPONENT_FIELDS,
|
|
55
|
+
userFriendlyName: 'Page',
|
|
56
|
+
singularComponent: true,
|
|
57
|
+
};
|
|
58
|
+
// Breeze components share a `breeze/` group directory so future breeze features
|
|
59
|
+
// (e.g. breeze/skills, breeze/subagents) can sit alongside breeze/tools.
|
|
60
|
+
const BREEZE_COMPONENT_DIR = 'breeze';
|
|
61
|
+
export const Components = {
|
|
62
|
+
[APP_KEY]: {
|
|
63
|
+
dir: APP_KEY,
|
|
72
64
|
userFriendlyName: 'App',
|
|
73
|
-
...
|
|
65
|
+
...TOP_LEVEL_COMPONENT_FIELDS,
|
|
74
66
|
singularComponent: true,
|
|
75
67
|
},
|
|
76
|
-
[
|
|
68
|
+
[APP_OBJECT_KEY]: {
|
|
77
69
|
dir: 'app-objects',
|
|
78
|
-
parentComponent:
|
|
79
|
-
...
|
|
70
|
+
parentComponent: APP_KEY,
|
|
71
|
+
...SUB_COMPONENT_FIELDS,
|
|
80
72
|
userFriendlyName: 'App Object',
|
|
81
73
|
},
|
|
82
|
-
[
|
|
74
|
+
[APP_OBJECT_ASSOCIATION_KEY]: {
|
|
83
75
|
dir: 'app-object-associations',
|
|
84
|
-
parentComponent:
|
|
85
|
-
...
|
|
76
|
+
parentComponent: APP_KEY,
|
|
77
|
+
...SUB_COMPONENT_FIELDS,
|
|
86
78
|
userFriendlyName: 'App Object Association',
|
|
87
79
|
},
|
|
88
|
-
[
|
|
89
|
-
|
|
80
|
+
[PAGE_KEY]: PAGE_COMPONENT,
|
|
81
|
+
[PAGES_KEY]: PAGE_COMPONENT,
|
|
82
|
+
[THEME_KEY]: {
|
|
83
|
+
dir: THEME_KEY,
|
|
90
84
|
userFriendlyName: 'Theme',
|
|
91
|
-
...
|
|
85
|
+
...TOP_LEVEL_COMPONENT_FIELDS,
|
|
86
|
+
},
|
|
87
|
+
[CMS_ASSETS_KEY]: {
|
|
88
|
+
dir: CMS_ASSETS_KEY,
|
|
89
|
+
userFriendlyName: 'CMS Asset',
|
|
90
|
+
...TOP_LEVEL_COMPONENT_FIELDS,
|
|
92
91
|
},
|
|
93
|
-
[
|
|
94
|
-
dir:
|
|
95
|
-
parentComponent:
|
|
92
|
+
[CALLING_KEY]: {
|
|
93
|
+
dir: CALLING_KEY,
|
|
94
|
+
parentComponent: APP_KEY,
|
|
96
95
|
userFriendlyName: 'Calling',
|
|
97
|
-
...
|
|
96
|
+
...SUB_COMPONENT_FIELDS,
|
|
98
97
|
singularComponent: true,
|
|
99
98
|
},
|
|
100
|
-
[
|
|
99
|
+
[CARDS_KEY]: {
|
|
101
100
|
dir: 'cards',
|
|
102
|
-
parentComponent:
|
|
101
|
+
parentComponent: APP_KEY,
|
|
103
102
|
userFriendlyName: 'Card',
|
|
104
|
-
...
|
|
103
|
+
...SUB_COMPONENT_FIELDS,
|
|
105
104
|
},
|
|
106
|
-
[
|
|
105
|
+
[APP_FUNCTIONS_KEY]: {
|
|
107
106
|
dir: 'functions',
|
|
108
|
-
parentComponent:
|
|
107
|
+
parentComponent: APP_KEY,
|
|
109
108
|
userFriendlyName: 'App Function',
|
|
110
|
-
...
|
|
109
|
+
...SUB_COMPONENT_FIELDS,
|
|
111
110
|
},
|
|
112
|
-
[
|
|
113
|
-
dir:
|
|
114
|
-
parentComponent:
|
|
111
|
+
[SCIM_KEY]: {
|
|
112
|
+
dir: SCIM_KEY,
|
|
113
|
+
parentComponent: APP_KEY,
|
|
115
114
|
userFriendlyName: 'SCIM',
|
|
116
115
|
singularComponent: true,
|
|
117
|
-
...
|
|
116
|
+
...SUB_COMPONENT_FIELDS,
|
|
118
117
|
},
|
|
119
|
-
[
|
|
118
|
+
[SETTINGS_KEY]: {
|
|
120
119
|
dir: 'settings',
|
|
121
|
-
parentComponent:
|
|
120
|
+
parentComponent: APP_KEY,
|
|
122
121
|
userFriendlyName: 'Settings Extension',
|
|
123
|
-
...
|
|
122
|
+
...SUB_COMPONENT_FIELDS,
|
|
124
123
|
singularComponent: true,
|
|
125
124
|
},
|
|
126
|
-
[
|
|
125
|
+
[MARKETING_EVENTS_KEY]: {
|
|
127
126
|
dir: 'marketing-events',
|
|
128
|
-
parentComponent:
|
|
127
|
+
parentComponent: APP_KEY,
|
|
129
128
|
userFriendlyName: 'Marketing Event',
|
|
130
|
-
...
|
|
129
|
+
...SUB_COMPONENT_FIELDS,
|
|
131
130
|
},
|
|
132
|
-
|
|
133
|
-
dir:
|
|
134
|
-
parentComponent:
|
|
131
|
+
[MEDIA_BRIDGE_KEY]: {
|
|
132
|
+
dir: MEDIA_BRIDGE_KEY,
|
|
133
|
+
parentComponent: APP_KEY,
|
|
135
134
|
userFriendlyName: 'Media Bridge',
|
|
136
|
-
...
|
|
135
|
+
...SUB_COMPONENT_FIELDS,
|
|
137
136
|
},
|
|
138
|
-
[
|
|
139
|
-
dir: '
|
|
140
|
-
parentComponent:
|
|
141
|
-
userFriendlyName: '
|
|
142
|
-
...
|
|
137
|
+
[APP_EVENTS_KEY]: {
|
|
138
|
+
dir: 'app-events',
|
|
139
|
+
parentComponent: APP_KEY,
|
|
140
|
+
userFriendlyName: 'App Event',
|
|
141
|
+
...SUB_COMPONENT_FIELDS,
|
|
143
142
|
},
|
|
144
|
-
[
|
|
145
|
-
dir:
|
|
146
|
-
parentComponent:
|
|
143
|
+
[VIDEO_CONFERENCING_KEY]: {
|
|
144
|
+
dir: VIDEO_CONFERENCING_KEY,
|
|
145
|
+
parentComponent: APP_KEY,
|
|
147
146
|
userFriendlyName: 'Video Conferencing',
|
|
148
|
-
...
|
|
147
|
+
...SUB_COMPONENT_FIELDS,
|
|
149
148
|
},
|
|
150
|
-
[
|
|
151
|
-
dir:
|
|
152
|
-
parentComponent:
|
|
149
|
+
[WEBHOOKS_KEY]: {
|
|
150
|
+
dir: WEBHOOKS_KEY,
|
|
151
|
+
parentComponent: APP_KEY,
|
|
153
152
|
userFriendlyName: 'Webhooks',
|
|
154
|
-
...
|
|
153
|
+
...SUB_COMPONENT_FIELDS,
|
|
155
154
|
singularComponent: true,
|
|
156
155
|
},
|
|
157
|
-
[
|
|
156
|
+
[WEBHOOKS_JOURNAL_KEY]: {
|
|
157
|
+
dir: WEBHOOKS_JOURNAL_KEY,
|
|
158
|
+
parentComponent: APP_KEY,
|
|
159
|
+
userFriendlyName: 'Webhooks Journal',
|
|
160
|
+
...SUB_COMPONENT_FIELDS,
|
|
161
|
+
singularComponent: true,
|
|
162
|
+
},
|
|
163
|
+
[WORKFLOW_ACTIONS_KEY]: {
|
|
158
164
|
dir: 'workflow-actions',
|
|
159
|
-
parentComponent:
|
|
165
|
+
parentComponent: APP_KEY,
|
|
160
166
|
userFriendlyName: 'Workflow Action',
|
|
161
|
-
...
|
|
167
|
+
...SUB_COMPONENT_FIELDS,
|
|
168
|
+
},
|
|
169
|
+
[ACTIONS_KEY]: {
|
|
170
|
+
dir: 'actions',
|
|
171
|
+
parentComponent: APP_KEY,
|
|
172
|
+
userFriendlyName: 'Action',
|
|
173
|
+
...SUB_COMPONENT_FIELDS,
|
|
174
|
+
},
|
|
175
|
+
[TELEMETRY_KEY]: {
|
|
176
|
+
dir: TELEMETRY_KEY,
|
|
177
|
+
parentComponent: APP_KEY,
|
|
178
|
+
userFriendlyName: 'Telemetry',
|
|
179
|
+
singularComponent: true,
|
|
180
|
+
...SUB_COMPONENT_FIELDS,
|
|
181
|
+
},
|
|
182
|
+
[MCP_SERVER_KEY]: {
|
|
183
|
+
dir: MCP_SERVER_KEY,
|
|
184
|
+
parentComponent: APP_KEY,
|
|
185
|
+
userFriendlyName: 'MCP Server',
|
|
186
|
+
singularComponent: true,
|
|
187
|
+
...SUB_COMPONENT_FIELDS,
|
|
188
|
+
},
|
|
189
|
+
[BREEZE_TOOL_KEY]: {
|
|
190
|
+
dir: `${BREEZE_COMPONENT_DIR}/tools`,
|
|
191
|
+
parentComponent: APP_KEY,
|
|
192
|
+
userFriendlyName: 'Breeze Tool',
|
|
193
|
+
...SUB_COMPONENT_FIELDS,
|
|
162
194
|
},
|
|
163
195
|
};
|
|
164
|
-
|
|
165
|
-
[
|
|
166
|
-
[
|
|
196
|
+
export const USER_FACING_TO_INTERNAL_TYPE = {
|
|
197
|
+
[APP_KEY]: 'APPLICATION',
|
|
198
|
+
[SCIM_KEY]: 'SCIM_INTEGRATION',
|
|
199
|
+
[TELEMETRY_KEY]: 'TELEMETRY_CONFIG',
|
|
200
|
+
[CMS_ASSETS_KEY]: 'REACT_THEME',
|
|
201
|
+
[PAGES_KEY]: 'PAGE',
|
|
167
202
|
};
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
203
|
+
export const INTERNAL_TYPE_TO_USER_FACING = Object.fromEntries(Object.entries(USER_FACING_TO_INTERNAL_TYPE).map(([key, value]) => [
|
|
204
|
+
value,
|
|
205
|
+
key,
|
|
206
|
+
]));
|
|
207
|
+
export const METAFILE_EXTENSION = '-hsmeta.json';
|
|
208
|
+
export const PROFILE_FILE_PREFIX = 'hsprofile';
|
|
209
|
+
export const HS_PROJECT_JSON_FILENAME = 'hsproject.json';
|
|
210
|
+
export const PACKAGE_JSON = 'package.json';
|
|
211
|
+
export const PACKAGE_LOCK_JSON = 'package-lock.json';
|
|
174
212
|
function getSubComponentDirsForParentType(parentComponent) {
|
|
175
|
-
return Object.values(
|
|
213
|
+
return Object.values(Components).reduce((acc, item) => {
|
|
176
214
|
if (item.parentComponent === parentComponent) {
|
|
177
215
|
acc.push(item.dir);
|
|
178
216
|
}
|
|
179
217
|
return acc;
|
|
180
218
|
}, []);
|
|
181
219
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
[
|
|
220
|
+
export const ALLOWED_APP_SUB_COMPONENTS_DIRS = getSubComponentDirsForParentType(APP_KEY);
|
|
221
|
+
export const ALLOWED_THEME_SUB_COMPONENTS_DIRS = getSubComponentDirsForParentType(THEME_KEY);
|
|
222
|
+
export const ALLOWED_CMS_ASSET_SUB_COMPONENT_DIRS = getSubComponentDirsForParentType(CMS_ASSETS_KEY);
|
|
223
|
+
export const PROJECT_STRUCTURE = {
|
|
224
|
+
[APP_KEY]: ALLOWED_APP_SUB_COMPONENTS_DIRS,
|
|
225
|
+
[THEME_KEY]: ALLOWED_THEME_SUB_COMPONENTS_DIRS,
|
|
226
|
+
[CMS_ASSETS_KEY]: ALLOWED_CMS_ASSET_SUB_COMPONENT_DIRS,
|
|
187
227
|
};
|
|
188
|
-
|
|
189
|
-
|
|
228
|
+
export const ALLOWED_COMPONENT_DIRECTORIES = Object.keys(PROJECT_STRUCTURE);
|
|
229
|
+
export const ALLOWED_SUB_COMPONENT_DIRECTORIES = Object.entries(PROJECT_STRUCTURE)
|
|
190
230
|
.map(([key, value]) => value.map((value) => path.join(key, value)))
|
|
191
231
|
.flat();
|
|
232
|
+
// Profile variable types
|
|
233
|
+
export const PROFILE_VARIABLE_TYPES = {
|
|
234
|
+
PROFILE_INT: 'PROFILE_INT',
|
|
235
|
+
PROFILE_LONG: 'PROFILE_LONG',
|
|
236
|
+
PROFILE_STRING: 'PROFILE_STRING',
|
|
237
|
+
PROFILE_BOOLEAN: 'PROFILE_BOOLEAN',
|
|
238
|
+
};
|
|
239
|
+
export const ALLOWED_TOP_LEVEL_FIELDS = new Set([
|
|
240
|
+
'uid',
|
|
241
|
+
'type',
|
|
242
|
+
'config',
|
|
243
|
+
'dependencies',
|
|
244
|
+
'permissions',
|
|
245
|
+
]);
|
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,5 @@
|
|
|
1
|
-
import { FileParseResult, TranslationContext, HsProfileFile } from './types';
|
|
2
|
-
type MetaFileLocation = {
|
|
1
|
+
import { FileParseResult, TranslationContext, HsProfileFile } from './types.js';
|
|
2
|
+
export type MetaFileLocation = {
|
|
3
3
|
file: string;
|
|
4
4
|
parentDirectory?: string;
|
|
5
5
|
};
|
|
@@ -10,4 +10,4 @@ export declare function locateHsMetaFiles(projectSourceDir: string, options?: {
|
|
|
10
10
|
silent: boolean;
|
|
11
11
|
}): Promise<MetaFileLocation[]>;
|
|
12
12
|
export declare function projectContainsHsMetaFiles(projectSourceDir: string): Promise<boolean>;
|
|
13
|
-
export
|
|
13
|
+
export declare function convertPathToPosixPath(filepath: string): string;
|