@sap-ux/project-integrity 0.2.18 → 0.2.20
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.
|
@@ -8,13 +8,13 @@ exports.isFioriProjectIntegrityEnabled = isFioriProjectIntegrityEnabled;
|
|
|
8
8
|
exports.enableFioriProjectIntegrity = enableFioriProjectIntegrity;
|
|
9
9
|
exports.disableFioriProjectIntegrity = disableFioriProjectIntegrity;
|
|
10
10
|
exports.isFioriProjectIntegrityInitialized = isFioriProjectIntegrityInitialized;
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const node_fs_1 = require("node:fs");
|
|
12
|
+
const node_path_1 = require("node:path");
|
|
13
13
|
const project_access_1 = require("@sap-ux/project-access");
|
|
14
14
|
const integrity_1 = require("../integrity");
|
|
15
15
|
const hash_1 = require("../integrity/hash");
|
|
16
16
|
const persistence_1 = require("../integrity/persistence");
|
|
17
|
-
exports.fioriIntegrityDataPath = (0,
|
|
17
|
+
exports.fioriIntegrityDataPath = (0, node_path_1.join)('.fiori-ai/ai-integrity.json');
|
|
18
18
|
/**
|
|
19
19
|
* Get the list of files to protect the integrity of.
|
|
20
20
|
*
|
|
@@ -23,15 +23,15 @@ exports.fioriIntegrityDataPath = (0, path_1.join)('.fiori-ai/ai-integrity.json')
|
|
|
23
23
|
*/
|
|
24
24
|
async function getFileList(projectRoot) {
|
|
25
25
|
const fileList = [];
|
|
26
|
-
const schemaCds = (0,
|
|
27
|
-
if ((0,
|
|
26
|
+
const schemaCds = (0, node_path_1.join)(projectRoot, 'db/schema.cds');
|
|
27
|
+
if ((0, node_fs_1.existsSync)(schemaCds)) {
|
|
28
28
|
fileList.push(schemaCds);
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
31
|
throw new Error(`File ${schemaCds} does not exist.`);
|
|
32
32
|
}
|
|
33
|
-
const servicesCds = (0,
|
|
34
|
-
if ((0,
|
|
33
|
+
const servicesCds = (0, node_path_1.join)(projectRoot, 'srv/service.cds');
|
|
34
|
+
if ((0, node_fs_1.existsSync)(servicesCds)) {
|
|
35
35
|
fileList.push(servicesCds);
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
@@ -50,7 +50,7 @@ async function getFileList(projectRoot) {
|
|
|
50
50
|
* including the namespace and structured clone of the definitions.
|
|
51
51
|
*/
|
|
52
52
|
async function getCsnContent(projectRoot) {
|
|
53
|
-
const modelFiles = { srv: (0,
|
|
53
|
+
const modelFiles = { srv: (0, node_path_1.join)('srv', 'service.cds'), db: (0, node_path_1.join)('db', 'schema.cds') };
|
|
54
54
|
const pathSelection = new Set(Object.keys(modelFiles));
|
|
55
55
|
const result = await (0, project_access_1.getCapModelAndServices)({ projectRoot, pathSelection });
|
|
56
56
|
const csn = result.model;
|
|
@@ -75,7 +75,7 @@ async function getAdditionalStringContent(projectRoot) {
|
|
|
75
75
|
* @param projectRoot - root folder of the project
|
|
76
76
|
*/
|
|
77
77
|
async function initFioriProject(projectRoot) {
|
|
78
|
-
const integrityFilePath = (0,
|
|
78
|
+
const integrityFilePath = (0, node_path_1.join)(projectRoot, exports.fioriIntegrityDataPath);
|
|
79
79
|
const fileList = await getFileList(projectRoot);
|
|
80
80
|
const additionalStringContent = await getAdditionalStringContent(projectRoot);
|
|
81
81
|
await (0, integrity_1.initProject)({ integrityFilePath, fileList, additionalStringContent });
|
|
@@ -87,7 +87,7 @@ async function initFioriProject(projectRoot) {
|
|
|
87
87
|
* @returns - results of the check
|
|
88
88
|
*/
|
|
89
89
|
async function checkFioriProjectIntegrity(projectRoot) {
|
|
90
|
-
const integrityFilePath = (0,
|
|
90
|
+
const integrityFilePath = (0, node_path_1.join)(projectRoot, exports.fioriIntegrityDataPath);
|
|
91
91
|
const additionalStringContent = await getAdditionalStringContent(projectRoot);
|
|
92
92
|
const checkResult = await (0, integrity_1.checkProjectIntegrity)(integrityFilePath, additionalStringContent);
|
|
93
93
|
const integrityData = await (0, persistence_1.readIntegrityData)(integrityFilePath);
|
|
@@ -141,7 +141,7 @@ async function checkFioriProjectIntegrity(projectRoot) {
|
|
|
141
141
|
* @param projectRoot - root folder of the project
|
|
142
142
|
*/
|
|
143
143
|
async function updateFioriProjectIntegrity(projectRoot) {
|
|
144
|
-
const integrityFilePath = (0,
|
|
144
|
+
const integrityFilePath = (0, node_path_1.join)(projectRoot, exports.fioriIntegrityDataPath);
|
|
145
145
|
const additionalStringContent = await getAdditionalStringContent(projectRoot);
|
|
146
146
|
await (0, integrity_1.updateProjectIntegrity)(integrityFilePath, additionalStringContent);
|
|
147
147
|
}
|
|
@@ -152,7 +152,7 @@ async function updateFioriProjectIntegrity(projectRoot) {
|
|
|
152
152
|
* @returns true if integrity is enabled, false otherwise
|
|
153
153
|
*/
|
|
154
154
|
async function isFioriProjectIntegrityEnabled(projectRoot) {
|
|
155
|
-
const integrityFilePath = (0,
|
|
155
|
+
const integrityFilePath = (0, node_path_1.join)(projectRoot, exports.fioriIntegrityDataPath);
|
|
156
156
|
return (0, integrity_1.isProjectIntegrityEnabled)(integrityFilePath);
|
|
157
157
|
}
|
|
158
158
|
/**
|
|
@@ -162,7 +162,7 @@ async function isFioriProjectIntegrityEnabled(projectRoot) {
|
|
|
162
162
|
* @param projectRoot - root folder of the project
|
|
163
163
|
*/
|
|
164
164
|
async function enableFioriProjectIntegrity(projectRoot) {
|
|
165
|
-
const integrityFilePath = (0,
|
|
165
|
+
const integrityFilePath = (0, node_path_1.join)(projectRoot, exports.fioriIntegrityDataPath);
|
|
166
166
|
await (0, integrity_1.enableProjectIntegrity)(integrityFilePath);
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
@@ -171,7 +171,7 @@ async function enableFioriProjectIntegrity(projectRoot) {
|
|
|
171
171
|
* @param projectRoot - root folder of the project
|
|
172
172
|
*/
|
|
173
173
|
async function disableFioriProjectIntegrity(projectRoot) {
|
|
174
|
-
const integrityFilePath = (0,
|
|
174
|
+
const integrityFilePath = (0, node_path_1.join)(projectRoot, exports.fioriIntegrityDataPath);
|
|
175
175
|
await (0, integrity_1.disableProjectIntegrity)(integrityFilePath);
|
|
176
176
|
}
|
|
177
177
|
/**
|
|
@@ -182,6 +182,6 @@ async function disableFioriProjectIntegrity(projectRoot) {
|
|
|
182
182
|
* @returns - true if the Fiori project integrity is initialized, false otherwise
|
|
183
183
|
*/
|
|
184
184
|
function isFioriProjectIntegrityInitialized(projectRoot) {
|
|
185
|
-
return (0,
|
|
185
|
+
return (0, node_fs_1.existsSync)((0, node_path_1.join)(projectRoot, exports.fioriIntegrityDataPath));
|
|
186
186
|
}
|
|
187
187
|
//# sourceMappingURL=index.js.map
|
package/dist/integrity/check.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkIntegrity = checkIntegrity;
|
|
4
|
-
const
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
5
|
const hash_1 = require("./hash");
|
|
6
6
|
/**
|
|
7
7
|
* Check existing integrity data.
|
|
@@ -27,7 +27,7 @@ async function checkFileIntegrity(fileIntegrity) {
|
|
|
27
27
|
const equalFiles = [];
|
|
28
28
|
const checkFiles = [];
|
|
29
29
|
for (const integrity of fileIntegrity) {
|
|
30
|
-
if (!(0,
|
|
30
|
+
if (!(0, node_fs_1.existsSync)(integrity.filePath)) {
|
|
31
31
|
differentFiles.push({ filePath: integrity.filePath, oldContent: integrity.content, newContent: '' });
|
|
32
32
|
}
|
|
33
33
|
else {
|
package/dist/integrity/hash.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFileIntegrity = getFileIntegrity;
|
|
4
4
|
exports.getContentIntegrity = getContentIntegrity;
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const node_crypto_1 = require("node:crypto");
|
|
7
7
|
/**
|
|
8
8
|
* Create a md5 hash for a given file.
|
|
9
9
|
*
|
|
@@ -13,8 +13,8 @@ const crypto_1 = require("crypto");
|
|
|
13
13
|
async function computeFileIntegrityData(filePath) {
|
|
14
14
|
return new Promise((resolve, reject) => {
|
|
15
15
|
let content = '';
|
|
16
|
-
const hash = (0,
|
|
17
|
-
const fileStream = (0,
|
|
16
|
+
const hash = (0, node_crypto_1.createHash)('md5');
|
|
17
|
+
const fileStream = (0, node_fs_1.createReadStream)(filePath);
|
|
18
18
|
fileStream.on('data', (chunk) => {
|
|
19
19
|
content += chunk.toString();
|
|
20
20
|
hash.update(new Uint8Array(chunk));
|
|
@@ -30,7 +30,7 @@ async function computeFileIntegrityData(filePath) {
|
|
|
30
30
|
* @returns - promise that resolves to an array of FileHash objects
|
|
31
31
|
*/
|
|
32
32
|
async function getFileIntegrity(files) {
|
|
33
|
-
const nonExistingFiles = files.filter((file) => !(0,
|
|
33
|
+
const nonExistingFiles = files.filter((file) => !(0, node_fs_1.existsSync)(file));
|
|
34
34
|
if (nonExistingFiles.length > 0) {
|
|
35
35
|
throw new Error(`The following files do not exist: ${nonExistingFiles.join(', ')}`);
|
|
36
36
|
}
|
|
@@ -50,7 +50,7 @@ function getContentIntegrity(additionalStringContent) {
|
|
|
50
50
|
const content = additionalStringContent[contentKey];
|
|
51
51
|
contentIntegrity.push({
|
|
52
52
|
contentKey,
|
|
53
|
-
hash: (0,
|
|
53
|
+
hash: (0, node_crypto_1.createHash)('md5').update(content).digest('hex'),
|
|
54
54
|
content
|
|
55
55
|
});
|
|
56
56
|
}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.readIntegrityData = readIntegrityData;
|
|
4
4
|
exports.writeIntegrityData = writeIntegrityData;
|
|
5
5
|
const promises_1 = require("fs/promises");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
8
|
const lz_string_1 = require("lz-string");
|
|
9
9
|
/**
|
|
10
10
|
* Read hashes from a previously stored hash file.
|
|
@@ -14,13 +14,13 @@ const lz_string_1 = require("lz-string");
|
|
|
14
14
|
* @returns - integrity data
|
|
15
15
|
*/
|
|
16
16
|
async function readIntegrityData(integrityFilePath) {
|
|
17
|
-
if (!(0,
|
|
17
|
+
if (!(0, node_fs_1.existsSync)(integrityFilePath)) {
|
|
18
18
|
throw new Error(`Integrity file not found at ${integrityFilePath}`);
|
|
19
19
|
}
|
|
20
20
|
const content = JSON.parse(await (0, promises_1.readFile)(integrityFilePath, { encoding: 'utf-8' }));
|
|
21
|
-
const integrityDir = (0,
|
|
21
|
+
const integrityDir = (0, node_path_1.dirname)(integrityFilePath);
|
|
22
22
|
for (const fileIntegrity of content.fileIntegrity) {
|
|
23
|
-
fileIntegrity.filePath = (0,
|
|
23
|
+
fileIntegrity.filePath = (0, node_path_1.join)(integrityDir, fileIntegrity.filePath);
|
|
24
24
|
getifyContent(fileIntegrity);
|
|
25
25
|
}
|
|
26
26
|
for (const contentIntegrity of content.contentIntegrity) {
|
|
@@ -37,12 +37,12 @@ async function readIntegrityData(integrityFilePath) {
|
|
|
37
37
|
*/
|
|
38
38
|
async function writeIntegrityData(integrityFilePath, content) {
|
|
39
39
|
const clonedContent = structuredClone(content); // clone to ensure integrity data has no getters
|
|
40
|
-
const integrityDir = (0,
|
|
41
|
-
if (!(0,
|
|
40
|
+
const integrityDir = (0, node_path_1.dirname)(integrityFilePath);
|
|
41
|
+
if (!(0, node_fs_1.existsSync)(integrityDir)) {
|
|
42
42
|
await (0, promises_1.mkdir)(integrityDir, { recursive: true });
|
|
43
43
|
}
|
|
44
44
|
for (const fileIntegrity of clonedContent.fileIntegrity) {
|
|
45
|
-
fileIntegrity.filePath = (0,
|
|
45
|
+
fileIntegrity.filePath = (0, node_path_1.relative)(integrityDir, fileIntegrity.filePath);
|
|
46
46
|
if (typeof fileIntegrity.content === 'string') {
|
|
47
47
|
fileIntegrity.content = (0, lz_string_1.compressToBase64)(fileIntegrity.content);
|
|
48
48
|
}
|
|
@@ -6,7 +6,7 @@ exports.updateProjectIntegrity = updateProjectIntegrity;
|
|
|
6
6
|
exports.isProjectIntegrityEnabled = isProjectIntegrityEnabled;
|
|
7
7
|
exports.enableProjectIntegrity = enableProjectIntegrity;
|
|
8
8
|
exports.disableProjectIntegrity = disableProjectIntegrity;
|
|
9
|
-
const
|
|
9
|
+
const node_fs_1 = require("node:fs");
|
|
10
10
|
const hash_1 = require("./hash");
|
|
11
11
|
const persistence_1 = require("./persistence");
|
|
12
12
|
const check_1 = require("./check");
|
|
@@ -58,7 +58,7 @@ async function checkProjectIntegrity(integrityFilePath, additionalStringContent)
|
|
|
58
58
|
* @param additionalStringContent - optional key/string map to add to integrity data
|
|
59
59
|
*/
|
|
60
60
|
async function updateProjectIntegrity(integrityFilePath, additionalStringContent) {
|
|
61
|
-
if (!(0,
|
|
61
|
+
if (!(0, node_fs_1.existsSync)(integrityFilePath)) {
|
|
62
62
|
throw new Error(`Integrity data not found at ${integrityFilePath}`);
|
|
63
63
|
}
|
|
64
64
|
const integrityData = await (0, persistence_1.readIntegrityData)(integrityFilePath);
|
|
@@ -84,7 +84,7 @@ New content keys: ${newContentKeys.join(', ')}`);
|
|
|
84
84
|
* @returns - true if integrity is enabled, false otherwise
|
|
85
85
|
*/
|
|
86
86
|
async function isProjectIntegrityEnabled(integrityFilePath) {
|
|
87
|
-
if (!(0,
|
|
87
|
+
if (!(0, node_fs_1.existsSync)(integrityFilePath)) {
|
|
88
88
|
throw new Error(`Integrity data not found at ${integrityFilePath}`);
|
|
89
89
|
}
|
|
90
90
|
const { enabled } = await (0, persistence_1.readIntegrityData)(integrityFilePath);
|
|
@@ -97,7 +97,7 @@ async function isProjectIntegrityEnabled(integrityFilePath) {
|
|
|
97
97
|
* @param integrityFilePath - path to file where integrity data is stored
|
|
98
98
|
*/
|
|
99
99
|
async function enableProjectIntegrity(integrityFilePath) {
|
|
100
|
-
if (!(0,
|
|
100
|
+
if (!(0, node_fs_1.existsSync)(integrityFilePath)) {
|
|
101
101
|
throw new Error(`Integrity data not found at ${integrityFilePath}`);
|
|
102
102
|
}
|
|
103
103
|
const integrityData = await (0, persistence_1.readIntegrityData)(integrityFilePath);
|
|
@@ -112,7 +112,7 @@ async function enableProjectIntegrity(integrityFilePath) {
|
|
|
112
112
|
* @param integrityFilePath - path to file where integrity data is stored
|
|
113
113
|
*/
|
|
114
114
|
async function disableProjectIntegrity(integrityFilePath) {
|
|
115
|
-
if (!(0,
|
|
115
|
+
if (!(0, node_fs_1.existsSync)(integrityFilePath)) {
|
|
116
116
|
throw new Error(`Integrity data not found at ${integrityFilePath}`);
|
|
117
117
|
}
|
|
118
118
|
const integrityData = await (0, persistence_1.readIntegrityData)(integrityFilePath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-ux/project-integrity",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.20",
|
|
4
4
|
"description": "Library to check the integrity of projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"lz-string": "1.5.0",
|
|
27
|
-
"@sap-ux/project-access": "1.32.
|
|
27
|
+
"@sap-ux/project-access": "1.32.3"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "tsc --build",
|