@hubspot/project-parsing-lib 0.23.1 → 0.23.2-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/lang/copy.d.ts +1 -0
- package/src/lang/copy.js +2 -1
- package/src/lib/migrate.js +6 -2
- package/src/lib/schemas.js +16 -5
- package/src/lib/validation.js +1 -1
package/package.json
CHANGED
package/src/lang/copy.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const errorMessages: {
|
|
|
4
4
|
failedToFetchSchemas: string;
|
|
5
5
|
failedToFetchSchemas403: string;
|
|
6
6
|
accountIdIsRequiredToFetchSchemas: string;
|
|
7
|
+
platformVersionNotAvailable: (platformVersion: string) => string;
|
|
7
8
|
};
|
|
8
9
|
project: {
|
|
9
10
|
mustHaveAppComponent: (componentType: string) => string;
|
package/src/lang/copy.js
CHANGED
|
@@ -5,6 +5,7 @@ export const errorMessages = {
|
|
|
5
5
|
failedToFetchSchemas: 'Failed to fetch component schemas',
|
|
6
6
|
failedToFetchSchemas403: 'Failed to fetch component schemas. Please verify that your personal access key provides access to developer projects.',
|
|
7
7
|
accountIdIsRequiredToFetchSchemas: 'Account id is required to fetch component schemas',
|
|
8
|
+
platformVersionNotAvailable: (platformVersion) => `Platform version '${platformVersion}' is not available. No component schemas are registered for it. Check the "platformVersion" field in hsproject.json.`,
|
|
8
9
|
},
|
|
9
10
|
project: {
|
|
10
11
|
mustHaveAppComponent: (componentType) => `This '${componentType}' component must be a child of the '${APP_KEY}' component. No *-hsmeta.json files were found with type '${APP_KEY}'`,
|
|
@@ -34,7 +35,7 @@ export const errorMessages = {
|
|
|
34
35
|
unsupportedType: (type) => `Unsupported type: ${mapToUserFacingType(type)}`,
|
|
35
36
|
errorWithField: (field, error) => `${field}: ${error || 'Unknown error'}`,
|
|
36
37
|
invalidJson: 'Invalid JSON',
|
|
37
|
-
permissionsNotSupported: (platformVersion) => `The "permissions" field is not supported on platform version "${platformVersion}". Upgrade to "
|
|
38
|
+
permissionsNotSupported: (platformVersion) => `The "permissions" field is not supported on platform version "${platformVersion}". Upgrade to "2027.03-beta" or later to use component-level permissions.`,
|
|
38
39
|
unexpectedToplevelFields: (unexpectedFields) => `Unexpected top-level properties found: ${unexpectedFields}`,
|
|
39
40
|
wrongDirectoryForComponent: (directory, componentType, componentMetadata, correctDir) => `The directory '${directory}' is incorrect for type '${componentType}'. ${componentMetadata.userFriendlyName} ${componentMetadata.userFriendlyTypePlural} should only be placed in the '${correctDir}' directory`,
|
|
40
41
|
},
|
package/src/lib/migrate.js
CHANGED
|
@@ -57,12 +57,16 @@ export async function migrate(inputDir, outputDir) {
|
|
|
57
57
|
// Write the hsmeta file to the output directory
|
|
58
58
|
fs.writeFileSync(hsmetaFilePath, JSON.stringify(component, null, 2));
|
|
59
59
|
});
|
|
60
|
-
|
|
60
|
+
// translate returns { intermediateRepresentation, skippedHsMetaFiles }.
|
|
61
|
+
// Only the intermediate representation belongs in OUTPUT_IR_FILE; the hsmeta
|
|
62
|
+
// files written above are generated into supported directories, so
|
|
63
|
+
// skippedHsMetaFiles is not expected to be populated here.
|
|
64
|
+
const translateResult = await translate({
|
|
61
65
|
projectSourceDir: sourceCodeOutputDir,
|
|
62
66
|
platformVersion: hsProjectJson.platformVersion,
|
|
63
67
|
}, { skipValidation: true });
|
|
64
68
|
// Write the IR file to the output directory
|
|
65
|
-
fs.writeFileSync(path.join(outputDir, OUTPUT_IR_FILE), JSON.stringify(
|
|
69
|
+
fs.writeFileSync(path.join(outputDir, OUTPUT_IR_FILE), JSON.stringify(translateResult.intermediateRepresentation, null, 2));
|
|
66
70
|
}
|
|
67
71
|
function ensureDirExists(dir) {
|
|
68
72
|
if (!fs.existsSync(dir)) {
|
package/src/lib/schemas.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { http } from '@hubspot/local-dev-lib/http';
|
|
2
|
+
import { isLegacyProject } from './platformVersion.js';
|
|
2
3
|
import { isHubSpotHttpError, isSpecifiedError, } from '@hubspot/local-dev-lib/errors/index';
|
|
3
4
|
import { errorMessages } from '../lang/copy.js';
|
|
4
|
-
|
|
5
|
-
if (!translationContext.accountId) {
|
|
6
|
-
throw new Error(errorMessages.api.accountIdIsRequiredToFetchSchemas);
|
|
7
|
-
}
|
|
5
|
+
async function fetchSchemas(accountId, platformVersion) {
|
|
8
6
|
try {
|
|
9
|
-
const { accountId, platformVersion } = translationContext;
|
|
10
7
|
const { data } = await http.get(accountId, {
|
|
11
8
|
url: `project-components-external/project-schemas/v3/${platformVersion}`,
|
|
12
9
|
});
|
|
@@ -22,3 +19,17 @@ export async function getIntermediateRepresentationSchema(translationContext) {
|
|
|
22
19
|
throw new Error(errorMessages.api.failedToFetchSchemas, { cause: e });
|
|
23
20
|
}
|
|
24
21
|
}
|
|
22
|
+
export async function getIntermediateRepresentationSchema(translationContext) {
|
|
23
|
+
if (!translationContext.accountId) {
|
|
24
|
+
throw new Error(errorMessages.api.accountIdIsRequiredToFetchSchemas);
|
|
25
|
+
}
|
|
26
|
+
const { accountId, platformVersion } = translationContext;
|
|
27
|
+
const schemas = await fetchSchemas(accountId, platformVersion);
|
|
28
|
+
// A platform version that is not open yet has no components registered against it, so this
|
|
29
|
+
// comes back empty and every component in the project would otherwise be reported as an
|
|
30
|
+
// unsupported type. Legacy versions predate components and legitimately register none.
|
|
31
|
+
if (!isLegacyProject(platformVersion) && Object.keys(schemas).length === 0) {
|
|
32
|
+
throw new Error(errorMessages.api.platformVersionNotAvailable(platformVersion));
|
|
33
|
+
}
|
|
34
|
+
return schemas;
|
|
35
|
+
}
|
package/src/lib/validation.js
CHANGED
|
@@ -49,7 +49,7 @@ function validateIntermediateRepresentationNode(schema, transformation, irNode,
|
|
|
49
49
|
shouldSkipValidation = true;
|
|
50
50
|
}
|
|
51
51
|
if (irNode.permissions &&
|
|
52
|
-
!meetsMinimumPlatformVersion(translationContext.platformVersion, PLATFORM_VERSIONS.
|
|
52
|
+
!meetsMinimumPlatformVersion(translationContext.platformVersion, PLATFORM_VERSIONS.v2027_03_BETA)) {
|
|
53
53
|
transformation.fileParseResult.errors.push(errorMessages.validation.permissionsNotSupported(translationContext.platformVersion));
|
|
54
54
|
}
|
|
55
55
|
if (!schema[irNode.componentType]) {
|