@hubspot/project-parsing-lib 0.10.2 → 0.10.3-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.
- package/package.json +1 -1
- package/src/index.d.ts +1 -1
- package/src/index.js +2 -1
- package/src/lib/profiles.d.ts +4 -0
- package/src/lib/profiles.js +30 -6
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare function translate(translationContext: TranslationContext, transl
|
|
|
4
4
|
export declare function translateForLocalDev(translationContext: TranslationContext, translationOptions?: TranslationOptionsLocalDev): Promise<IntermediateRepresentationLocalDev>;
|
|
5
5
|
export { isTranslationError } from './lib/errors';
|
|
6
6
|
export { IntermediateRepresentation, IntermediateRepresentationNode, IntermediateRepresentationLocalDev, IntermediateRepresentationNodeLocalDev, TranslationContext, };
|
|
7
|
-
export { getHsProfileFilename } from './lib/profiles';
|
|
7
|
+
export { getHsProfileFilename, validateProfileVariables } from './lib/profiles';
|
|
8
8
|
export { loadHsProfileFile, getAllHsProfiles, projectContainsHsMetaFiles, } from './lib/files';
|
|
9
9
|
export { migrate } from './lib/migrate';
|
|
10
10
|
export { validateUid, coerceToValidUid } from './lib/uid';
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getProjectThemeDetails = exports.migrateThemes = exports.getUnsupportedTypeError = exports.getFailedToFetchSchemasError = exports.getMissingRequiredFieldError = exports.getMissingAccountIdError = exports.getMissingConfigError = exports.getMissingTypeError = exports.getInvalidJsonError = exports.AjvErrorKeyword = exports.hsProjectJsonFilename = exports.metafileExtension = exports.createAjvInstance = exports.getIntermediateRepresentationSchema = exports.mapToInternalType = exports.mapToUserFriendlyName = exports.coerceToValidUid = exports.validateUid = exports.migrate = exports.projectContainsHsMetaFiles = exports.getAllHsProfiles = exports.loadHsProfileFile = exports.getHsProfileFilename = exports.isTranslationError = void 0;
|
|
3
|
+
exports.getProjectThemeDetails = exports.migrateThemes = exports.getUnsupportedTypeError = exports.getFailedToFetchSchemasError = exports.getMissingRequiredFieldError = exports.getMissingAccountIdError = exports.getMissingConfigError = exports.getMissingTypeError = exports.getInvalidJsonError = exports.AjvErrorKeyword = exports.hsProjectJsonFilename = exports.metafileExtension = exports.createAjvInstance = exports.getIntermediateRepresentationSchema = exports.mapToInternalType = exports.mapToUserFriendlyName = exports.coerceToValidUid = exports.validateUid = exports.migrate = exports.projectContainsHsMetaFiles = exports.getAllHsProfiles = exports.loadHsProfileFile = exports.validateProfileVariables = exports.getHsProfileFilename = exports.isTranslationError = void 0;
|
|
4
4
|
exports.translate = translate;
|
|
5
5
|
exports.translateForLocalDev = translateForLocalDev;
|
|
6
6
|
const files_1 = require("./lib/files");
|
|
@@ -59,6 +59,7 @@ var errors_1 = require("./lib/errors");
|
|
|
59
59
|
Object.defineProperty(exports, "isTranslationError", { enumerable: true, get: function () { return errors_1.isTranslationError; } });
|
|
60
60
|
var profiles_1 = require("./lib/profiles");
|
|
61
61
|
Object.defineProperty(exports, "getHsProfileFilename", { enumerable: true, get: function () { return profiles_1.getHsProfileFilename; } });
|
|
62
|
+
Object.defineProperty(exports, "validateProfileVariables", { enumerable: true, get: function () { return profiles_1.validateProfileVariables; } });
|
|
62
63
|
var files_2 = require("./lib/files");
|
|
63
64
|
Object.defineProperty(exports, "loadHsProfileFile", { enumerable: true, get: function () { return files_2.loadHsProfileFile; } });
|
|
64
65
|
Object.defineProperty(exports, "getAllHsProfiles", { enumerable: true, get: function () { return files_2.getAllHsProfiles; } });
|
package/src/lib/profiles.d.ts
CHANGED
|
@@ -3,4 +3,8 @@ export declare function getIsProfileFile(filename: string): boolean;
|
|
|
3
3
|
export declare function getHsProfileFilename(profileName: string): string;
|
|
4
4
|
export declare function getHsProfileName(profileFilename: string): string;
|
|
5
5
|
export declare function getHsProfileVariables(hsProfileContents: HsProfileFile): HSProfileVariables;
|
|
6
|
+
export declare function validateProfileVariables(profileVariables: HSProfileVariables, filename: string): {
|
|
7
|
+
success: boolean;
|
|
8
|
+
errors: string[];
|
|
9
|
+
};
|
|
6
10
|
export declare function applyHsProfileVariables(fileParseResults: FileParseResult[], hsProfileContents: HsProfileFile): FileParseResult[];
|
package/src/lib/profiles.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.getIsProfileFile = getIsProfileFile;
|
|
|
4
4
|
exports.getHsProfileFilename = getHsProfileFilename;
|
|
5
5
|
exports.getHsProfileName = getHsProfileName;
|
|
6
6
|
exports.getHsProfileVariables = getHsProfileVariables;
|
|
7
|
+
exports.validateProfileVariables = validateProfileVariables;
|
|
7
8
|
exports.applyHsProfileVariables = applyHsProfileVariables;
|
|
8
9
|
const constants_1 = require("./constants");
|
|
9
10
|
const copy_1 = require("../lang/copy");
|
|
@@ -25,15 +26,38 @@ function getHsProfileVariables(hsProfileContents) {
|
|
|
25
26
|
!Array.isArray(hsProfileContents.variables);
|
|
26
27
|
return profileVariablesAreValid ? hsProfileContents.variables : {};
|
|
27
28
|
}
|
|
29
|
+
function validateProfileVariables(profileVariables, filename) {
|
|
30
|
+
const errors = [];
|
|
31
|
+
Object.entries(profileVariables).forEach(([key, value]) => {
|
|
32
|
+
try {
|
|
33
|
+
validateProfileVariable(typeof value, key, filename);
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
if (e instanceof Error) {
|
|
37
|
+
errors.push(e.message);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
errors.push(`${e}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
success: errors.length === 0,
|
|
46
|
+
errors,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function validateProfileVariable(profileVariableType, key, file) {
|
|
50
|
+
if (profileVariableType === 'undefined') {
|
|
51
|
+
throw new Error(copy_1.errorMessages.profile.missingValue(key, file));
|
|
52
|
+
}
|
|
53
|
+
if (!['string', 'number', 'boolean'].includes(profileVariableType)) {
|
|
54
|
+
throw new Error(copy_1.errorMessages.profile.invalidValue(key));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
28
57
|
function interpolate(file, template, profileVariables) {
|
|
29
58
|
return template.replace(profileInsertRegex, (__match, key) => {
|
|
30
59
|
const profileVariableType = typeof profileVariables[key];
|
|
31
|
-
|
|
32
|
-
throw new Error(copy_1.errorMessages.profile.missingValue(key, file));
|
|
33
|
-
}
|
|
34
|
-
if (!['string', 'number', 'boolean'].includes(profileVariableType)) {
|
|
35
|
-
throw new Error(copy_1.errorMessages.profile.invalidValue(key));
|
|
36
|
-
}
|
|
60
|
+
validateProfileVariable(profileVariableType, key, file);
|
|
37
61
|
return String(profileVariables[key]);
|
|
38
62
|
});
|
|
39
63
|
}
|