@sap-ux/project-integrity 0.0.2
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/LICENSE +201 -0
- package/README.md +23 -0
- package/dist/fiori-project/index.d.ts +42 -0
- package/dist/fiori-project/index.js +111 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +18 -0
- package/dist/integrity/check.d.ts +10 -0
- package/dist/integrity/check.js +92 -0
- package/dist/integrity/hash.d.ts +16 -0
- package/dist/integrity/hash.js +60 -0
- package/dist/integrity/index.d.ts +2 -0
- package/dist/integrity/index.js +11 -0
- package/dist/integrity/persistence.d.ts +18 -0
- package/dist/integrity/persistence.js +78 -0
- package/dist/integrity/project.d.ts +50 -0
- package/dist/integrity/project.js +124 -0
- package/dist/types.d.ts +69 -0
- package/dist/types.js +3 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @sap-ux/project-integrity
|
|
2
|
+
|
|
3
|
+
Library that offers functions to detect modifications to a set of files within a project. It also allows to pass addition key -> string values that are stored together with integrity data and can also be checked.
|
|
4
|
+
For specific Fiori project, this module contains convenience functions that take care of building up the file and additional string content list, consumer need just to pass a valid Fiori project root.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
Npm
|
|
8
|
+
`npm install --save @sap-ux/project-integrity`
|
|
9
|
+
|
|
10
|
+
Yarn
|
|
11
|
+
`yarn add @sap-ux/project-integrity`
|
|
12
|
+
|
|
13
|
+
Pnpm
|
|
14
|
+
`pnpm add @sap-ux/project-integrity`
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
See usage in `test/` folder.
|
|
18
|
+
|
|
19
|
+
## Keywords
|
|
20
|
+
* SAP Fiori tools
|
|
21
|
+
* SAP Fiori elements
|
|
22
|
+
* SAP Fiori freestyle
|
|
23
|
+
* Project integrity
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { CheckIntegrityResult } from '../types';
|
|
2
|
+
export declare const fioriIntegrityDataPath: string;
|
|
3
|
+
/**
|
|
4
|
+
* Initialize a Fiori project for integrity protection.
|
|
5
|
+
*
|
|
6
|
+
* @param projectRoot - root folder of the project
|
|
7
|
+
*/
|
|
8
|
+
export declare function initFioriProject(projectRoot: string): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Check the integrity of a Fiori project.
|
|
11
|
+
*
|
|
12
|
+
* @param projectRoot - root folder of the project
|
|
13
|
+
* @returns - results of the check
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkFioriProjectIntegrity(projectRoot: string): Promise<CheckIntegrityResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Updates the integrity data of a Fiori project.
|
|
18
|
+
*
|
|
19
|
+
* @param projectRoot - root folder of the project
|
|
20
|
+
*/
|
|
21
|
+
export declare function updateFioriProjectIntegrity(projectRoot: string): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Return whether integrity is enabled for a Fiori project.
|
|
24
|
+
*
|
|
25
|
+
* @param projectRoot - root folder of the project
|
|
26
|
+
* @returns true if integrity is enabled, false otherwise
|
|
27
|
+
*/
|
|
28
|
+
export declare function isFioriProjectIntegrityEnabled(projectRoot: string): Promise<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* Enable integrity protection for a Fiori project. The Fiori project must be initialized first.
|
|
31
|
+
* After initialization, Fiori project integrity is enabled by default.
|
|
32
|
+
*
|
|
33
|
+
* @param projectRoot - root folder of the project
|
|
34
|
+
*/
|
|
35
|
+
export declare function enableFioriProjectIntegrity(projectRoot: string): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Disable integrity protection for a Fiori project. The Fiori project must be initialized first.
|
|
38
|
+
*
|
|
39
|
+
* @param projectRoot - root folder of the project
|
|
40
|
+
*/
|
|
41
|
+
export declare function disableFioriProjectIntegrity(projectRoot: string): Promise<void>;
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fioriIntegrityDataPath = void 0;
|
|
4
|
+
exports.initFioriProject = initFioriProject;
|
|
5
|
+
exports.checkFioriProjectIntegrity = checkFioriProjectIntegrity;
|
|
6
|
+
exports.updateFioriProjectIntegrity = updateFioriProjectIntegrity;
|
|
7
|
+
exports.isFioriProjectIntegrityEnabled = isFioriProjectIntegrityEnabled;
|
|
8
|
+
exports.enableFioriProjectIntegrity = enableFioriProjectIntegrity;
|
|
9
|
+
exports.disableFioriProjectIntegrity = disableFioriProjectIntegrity;
|
|
10
|
+
const fs_1 = require("fs");
|
|
11
|
+
const path_1 = require("path");
|
|
12
|
+
const project_access_1 = require("@sap-ux/project-access");
|
|
13
|
+
const integrity_1 = require("../integrity");
|
|
14
|
+
exports.fioriIntegrityDataPath = (0, path_1.join)('.fiori-ai/ai-integrity.json');
|
|
15
|
+
/**
|
|
16
|
+
* Get the list of files to protect the integrity of.
|
|
17
|
+
*
|
|
18
|
+
* @param projectRoot - root folder of the project
|
|
19
|
+
* @returns - list of file paths
|
|
20
|
+
*/
|
|
21
|
+
async function getFileList(projectRoot) {
|
|
22
|
+
const fileList = [];
|
|
23
|
+
const schemaCds = (0, path_1.join)(projectRoot, 'db/schema.cds');
|
|
24
|
+
if ((0, fs_1.existsSync)(schemaCds)) {
|
|
25
|
+
fileList.push(schemaCds);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
throw new Error(`File ${schemaCds} does not exist.`);
|
|
29
|
+
}
|
|
30
|
+
const servicesCds = (0, path_1.join)(projectRoot, 'srv/service.cds');
|
|
31
|
+
if ((0, fs_1.existsSync)(servicesCds)) {
|
|
32
|
+
fileList.push(servicesCds);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new Error(`File ${servicesCds} does not exist.`);
|
|
36
|
+
}
|
|
37
|
+
return fileList;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns additional string content, like the CAP environment.
|
|
41
|
+
* This content will be stored in the integrity data.
|
|
42
|
+
*
|
|
43
|
+
* @param projectRoot - root folder of the project
|
|
44
|
+
* @returns - additional content to store in the integrity data
|
|
45
|
+
*/
|
|
46
|
+
async function getAdditionalStringContent(projectRoot) {
|
|
47
|
+
const capCustomPaths = await (0, project_access_1.getCapCustomPaths)(projectRoot);
|
|
48
|
+
return { capPaths: JSON.stringify(capCustomPaths) };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Initialize a Fiori project for integrity protection.
|
|
52
|
+
*
|
|
53
|
+
* @param projectRoot - root folder of the project
|
|
54
|
+
*/
|
|
55
|
+
async function initFioriProject(projectRoot) {
|
|
56
|
+
const integrityFilePath = (0, path_1.join)(projectRoot, exports.fioriIntegrityDataPath);
|
|
57
|
+
const fileList = await getFileList(projectRoot);
|
|
58
|
+
const additionalStringContent = await getAdditionalStringContent(projectRoot);
|
|
59
|
+
await (0, integrity_1.initProject)({ integrityFilePath, fileList, additionalStringContent });
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Check the integrity of a Fiori project.
|
|
63
|
+
*
|
|
64
|
+
* @param projectRoot - root folder of the project
|
|
65
|
+
* @returns - results of the check
|
|
66
|
+
*/
|
|
67
|
+
async function checkFioriProjectIntegrity(projectRoot) {
|
|
68
|
+
const integrityFilePath = (0, path_1.join)(projectRoot, exports.fioriIntegrityDataPath);
|
|
69
|
+
const additionalStringContent = await getAdditionalStringContent(projectRoot);
|
|
70
|
+
return (0, integrity_1.checkProjectIntegrity)(integrityFilePath, additionalStringContent);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Updates the integrity data of a Fiori project.
|
|
74
|
+
*
|
|
75
|
+
* @param projectRoot - root folder of the project
|
|
76
|
+
*/
|
|
77
|
+
async function updateFioriProjectIntegrity(projectRoot) {
|
|
78
|
+
const integrityFilePath = (0, path_1.join)(projectRoot, exports.fioriIntegrityDataPath);
|
|
79
|
+
const additionalStringContent = await getAdditionalStringContent(projectRoot);
|
|
80
|
+
await (0, integrity_1.updateProjectIntegrity)(integrityFilePath, additionalStringContent);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Return whether integrity is enabled for a Fiori project.
|
|
84
|
+
*
|
|
85
|
+
* @param projectRoot - root folder of the project
|
|
86
|
+
* @returns true if integrity is enabled, false otherwise
|
|
87
|
+
*/
|
|
88
|
+
async function isFioriProjectIntegrityEnabled(projectRoot) {
|
|
89
|
+
const integrityFilePath = (0, path_1.join)(projectRoot, exports.fioriIntegrityDataPath);
|
|
90
|
+
return (0, integrity_1.isProjectIntegrityEnabled)(integrityFilePath);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Enable integrity protection for a Fiori project. The Fiori project must be initialized first.
|
|
94
|
+
* After initialization, Fiori project integrity is enabled by default.
|
|
95
|
+
*
|
|
96
|
+
* @param projectRoot - root folder of the project
|
|
97
|
+
*/
|
|
98
|
+
async function enableFioriProjectIntegrity(projectRoot) {
|
|
99
|
+
const integrityFilePath = (0, path_1.join)(projectRoot, exports.fioriIntegrityDataPath);
|
|
100
|
+
await (0, integrity_1.enableProjectIntegrity)(integrityFilePath);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Disable integrity protection for a Fiori project. The Fiori project must be initialized first.
|
|
104
|
+
*
|
|
105
|
+
* @param projectRoot - root folder of the project
|
|
106
|
+
*/
|
|
107
|
+
async function disableFioriProjectIntegrity(projectRoot) {
|
|
108
|
+
const integrityFilePath = (0, path_1.join)(projectRoot, exports.fioriIntegrityDataPath);
|
|
109
|
+
await (0, integrity_1.disableProjectIntegrity)(integrityFilePath);
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { checkProjectIntegrity, disableProjectIntegrity, enableProjectIntegrity, initProject, isProjectIntegrityEnabled, updateProjectIntegrity } from './integrity';
|
|
2
|
+
export { checkFioriProjectIntegrity, disableFioriProjectIntegrity, enableFioriProjectIntegrity, initFioriProject, isFioriProjectIntegrityEnabled, updateFioriProjectIntegrity } from './fiori-project';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateFioriProjectIntegrity = exports.isFioriProjectIntegrityEnabled = exports.initFioriProject = exports.enableFioriProjectIntegrity = exports.disableFioriProjectIntegrity = exports.checkFioriProjectIntegrity = exports.updateProjectIntegrity = exports.isProjectIntegrityEnabled = exports.initProject = exports.enableProjectIntegrity = exports.disableProjectIntegrity = exports.checkProjectIntegrity = void 0;
|
|
4
|
+
var integrity_1 = require("./integrity");
|
|
5
|
+
Object.defineProperty(exports, "checkProjectIntegrity", { enumerable: true, get: function () { return integrity_1.checkProjectIntegrity; } });
|
|
6
|
+
Object.defineProperty(exports, "disableProjectIntegrity", { enumerable: true, get: function () { return integrity_1.disableProjectIntegrity; } });
|
|
7
|
+
Object.defineProperty(exports, "enableProjectIntegrity", { enumerable: true, get: function () { return integrity_1.enableProjectIntegrity; } });
|
|
8
|
+
Object.defineProperty(exports, "initProject", { enumerable: true, get: function () { return integrity_1.initProject; } });
|
|
9
|
+
Object.defineProperty(exports, "isProjectIntegrityEnabled", { enumerable: true, get: function () { return integrity_1.isProjectIntegrityEnabled; } });
|
|
10
|
+
Object.defineProperty(exports, "updateProjectIntegrity", { enumerable: true, get: function () { return integrity_1.updateProjectIntegrity; } });
|
|
11
|
+
var fiori_project_1 = require("./fiori-project");
|
|
12
|
+
Object.defineProperty(exports, "checkFioriProjectIntegrity", { enumerable: true, get: function () { return fiori_project_1.checkFioriProjectIntegrity; } });
|
|
13
|
+
Object.defineProperty(exports, "disableFioriProjectIntegrity", { enumerable: true, get: function () { return fiori_project_1.disableFioriProjectIntegrity; } });
|
|
14
|
+
Object.defineProperty(exports, "enableFioriProjectIntegrity", { enumerable: true, get: function () { return fiori_project_1.enableFioriProjectIntegrity; } });
|
|
15
|
+
Object.defineProperty(exports, "initFioriProject", { enumerable: true, get: function () { return fiori_project_1.initFioriProject; } });
|
|
16
|
+
Object.defineProperty(exports, "isFioriProjectIntegrityEnabled", { enumerable: true, get: function () { return fiori_project_1.isFioriProjectIntegrityEnabled; } });
|
|
17
|
+
Object.defineProperty(exports, "updateFioriProjectIntegrity", { enumerable: true, get: function () { return fiori_project_1.updateFioriProjectIntegrity; } });
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CheckIntegrityResult, Content, Integrity } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Check existing integrity data.
|
|
4
|
+
*
|
|
5
|
+
* @param integrityData - integrity data
|
|
6
|
+
* @param [additionalStringContent] - optional additional new string content
|
|
7
|
+
* @returns - results of the check
|
|
8
|
+
*/
|
|
9
|
+
export declare function checkIntegrity(integrityData: Integrity, additionalStringContent?: Content): Promise<CheckIntegrityResult>;
|
|
10
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkIntegrity = checkIntegrity;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const hash_1 = require("./hash");
|
|
6
|
+
/**
|
|
7
|
+
* Check existing integrity data.
|
|
8
|
+
*
|
|
9
|
+
* @param integrityData - integrity data
|
|
10
|
+
* @param [additionalStringContent] - optional additional new string content
|
|
11
|
+
* @returns - results of the check
|
|
12
|
+
*/
|
|
13
|
+
async function checkIntegrity(integrityData, additionalStringContent) {
|
|
14
|
+
return {
|
|
15
|
+
files: await checkFileIntegrity(integrityData.fileIntegrity),
|
|
16
|
+
additionalStringContent: checkContentIntegrity(integrityData.contentIntegrity, additionalStringContent)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Check an array of file hashes against the current state of the files.
|
|
21
|
+
*
|
|
22
|
+
* @param fileIntegrity - array of file integrity data
|
|
23
|
+
* @returns - results of the check
|
|
24
|
+
*/
|
|
25
|
+
async function checkFileIntegrity(fileIntegrity) {
|
|
26
|
+
const differentFiles = [];
|
|
27
|
+
const equalFiles = [];
|
|
28
|
+
const checkFiles = [];
|
|
29
|
+
for (const integrity of fileIntegrity) {
|
|
30
|
+
if (!(0, fs_1.existsSync)(integrity.filePath)) {
|
|
31
|
+
differentFiles.push({ filePath: integrity.filePath, oldContent: integrity.content, newContent: '' });
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
checkFiles.push(integrity);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const newFileIntegrityArray = await (0, hash_1.getFileIntegrity)(checkFiles.map((fileIntegrity) => fileIntegrity.filePath));
|
|
38
|
+
for (const newFileIntegrity of newFileIntegrityArray) {
|
|
39
|
+
const oldFileIntegrity = checkFiles.find((fileHash) => fileHash.filePath === newFileIntegrity.filePath);
|
|
40
|
+
if (oldFileIntegrity && oldFileIntegrity.hash === newFileIntegrity.hash) {
|
|
41
|
+
equalFiles.push(oldFileIntegrity.filePath);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
differentFiles.push({
|
|
45
|
+
filePath: newFileIntegrity.filePath,
|
|
46
|
+
oldContent: oldFileIntegrity?.content,
|
|
47
|
+
newContent: newFileIntegrity.content
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return { differentFiles, equalFiles };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Check old content integrity against new key->string values.
|
|
55
|
+
*
|
|
56
|
+
* @param contentIntegrity - existing content integrity from integrity data
|
|
57
|
+
* @param additionalStringContent - new additional key->string values
|
|
58
|
+
* @returns - result of the check
|
|
59
|
+
*/
|
|
60
|
+
function checkContentIntegrity(contentIntegrity, additionalStringContent) {
|
|
61
|
+
const oldContentIntegrityArray = structuredClone(contentIntegrity);
|
|
62
|
+
const differentContent = [];
|
|
63
|
+
const equalContent = [];
|
|
64
|
+
const newContentIntegrityArray = (0, hash_1.getContentIntegrity)(additionalStringContent);
|
|
65
|
+
for (const newContentIntegrity of newContentIntegrityArray) {
|
|
66
|
+
const index = oldContentIntegrityArray.findIndex((content) => content.contentKey === newContentIntegrity.contentKey);
|
|
67
|
+
let foundOldContentIntegrity;
|
|
68
|
+
if (index > -1) {
|
|
69
|
+
foundOldContentIntegrity = oldContentIntegrityArray[index];
|
|
70
|
+
oldContentIntegrityArray.splice(index, 1);
|
|
71
|
+
}
|
|
72
|
+
if (foundOldContentIntegrity?.hash === newContentIntegrity.hash) {
|
|
73
|
+
equalContent.push(newContentIntegrity.contentKey);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
differentContent.push({
|
|
77
|
+
key: newContentIntegrity.contentKey,
|
|
78
|
+
newContent: newContentIntegrity.content,
|
|
79
|
+
oldContent: foundOldContentIntegrity?.content
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
for (const missingContent of oldContentIntegrityArray) {
|
|
84
|
+
differentContent.push({
|
|
85
|
+
key: missingContent.contentKey,
|
|
86
|
+
newContent: undefined,
|
|
87
|
+
oldContent: missingContent.content
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return { differentContent, equalContent };
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Content, ContentIntegrity, FileIntegrity } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Returns integrity data for a list of given files.
|
|
4
|
+
*
|
|
5
|
+
* @param files - list of files to
|
|
6
|
+
* @returns - promise that resolves to an array of FileHash objects
|
|
7
|
+
*/
|
|
8
|
+
export declare function getFileIntegrity(files: string[]): Promise<FileIntegrity[]>;
|
|
9
|
+
/**
|
|
10
|
+
* Returns content integrity data for a map of key/value (string).
|
|
11
|
+
*
|
|
12
|
+
* @param additionalStringContent - key value map of additional content to write as integrity data
|
|
13
|
+
* @returns - array of
|
|
14
|
+
*/
|
|
15
|
+
export declare function getContentIntegrity(additionalStringContent?: Content): ContentIntegrity[];
|
|
16
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFileIntegrity = getFileIntegrity;
|
|
4
|
+
exports.getContentIntegrity = getContentIntegrity;
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
/**
|
|
8
|
+
* Create a md5 hash for a given file.
|
|
9
|
+
*
|
|
10
|
+
* @param filePath - path to file
|
|
11
|
+
* @returns - promise that resolves to a FileHash object
|
|
12
|
+
*/
|
|
13
|
+
async function computeFileIntegrityData(filePath) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
let content = '';
|
|
16
|
+
const hash = (0, crypto_1.createHash)('md5');
|
|
17
|
+
const fileStream = (0, fs_1.createReadStream)(filePath);
|
|
18
|
+
fileStream.on('data', (chunk) => {
|
|
19
|
+
content += chunk.toString();
|
|
20
|
+
hash.update(chunk);
|
|
21
|
+
});
|
|
22
|
+
fileStream.on('end', () => resolve({ filePath, hash: hash.digest('hex'), content }));
|
|
23
|
+
fileStream.on('error', (err) => reject(err));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Returns integrity data for a list of given files.
|
|
28
|
+
*
|
|
29
|
+
* @param files - list of files to
|
|
30
|
+
* @returns - promise that resolves to an array of FileHash objects
|
|
31
|
+
*/
|
|
32
|
+
async function getFileIntegrity(files) {
|
|
33
|
+
const nonExistingFiles = files.filter((file) => !(0, fs_1.existsSync)(file));
|
|
34
|
+
if (nonExistingFiles.length > 0) {
|
|
35
|
+
throw new Error(`The following files do not exist: ${nonExistingFiles.join(', ')}`);
|
|
36
|
+
}
|
|
37
|
+
const promises = files.map(computeFileIntegrityData);
|
|
38
|
+
return await Promise.all(promises);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns content integrity data for a map of key/value (string).
|
|
42
|
+
*
|
|
43
|
+
* @param additionalStringContent - key value map of additional content to write as integrity data
|
|
44
|
+
* @returns - array of
|
|
45
|
+
*/
|
|
46
|
+
function getContentIntegrity(additionalStringContent) {
|
|
47
|
+
const contentIntegrity = [];
|
|
48
|
+
if (additionalStringContent) {
|
|
49
|
+
for (const contentKey in additionalStringContent) {
|
|
50
|
+
const content = additionalStringContent[contentKey];
|
|
51
|
+
contentIntegrity.push({
|
|
52
|
+
contentKey,
|
|
53
|
+
hash: (0, crypto_1.createHash)('md5').update(content).digest('hex'),
|
|
54
|
+
content
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return contentIntegrity;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateProjectIntegrity = exports.isProjectIntegrityEnabled = exports.initProject = exports.enableProjectIntegrity = exports.disableProjectIntegrity = exports.checkProjectIntegrity = void 0;
|
|
4
|
+
var project_1 = require("./project");
|
|
5
|
+
Object.defineProperty(exports, "checkProjectIntegrity", { enumerable: true, get: function () { return project_1.checkProjectIntegrity; } });
|
|
6
|
+
Object.defineProperty(exports, "disableProjectIntegrity", { enumerable: true, get: function () { return project_1.disableProjectIntegrity; } });
|
|
7
|
+
Object.defineProperty(exports, "enableProjectIntegrity", { enumerable: true, get: function () { return project_1.enableProjectIntegrity; } });
|
|
8
|
+
Object.defineProperty(exports, "initProject", { enumerable: true, get: function () { return project_1.initProject; } });
|
|
9
|
+
Object.defineProperty(exports, "isProjectIntegrityEnabled", { enumerable: true, get: function () { return project_1.isProjectIntegrityEnabled; } });
|
|
10
|
+
Object.defineProperty(exports, "updateProjectIntegrity", { enumerable: true, get: function () { return project_1.updateProjectIntegrity; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Integrity } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Read hashes from a previously stored hash file.
|
|
4
|
+
* Throws an error if the file does not exist.
|
|
5
|
+
*
|
|
6
|
+
* @param integrityFilePath - path to the integrity file
|
|
7
|
+
* @returns - integrity data
|
|
8
|
+
*/
|
|
9
|
+
export declare function readIntegrityData(integrityFilePath: string): Promise<Integrity>;
|
|
10
|
+
/**
|
|
11
|
+
* Write file integrity information to file. When storing, use relative paths to the hash file
|
|
12
|
+
* so the project as whole can be moved without breaking integrity.
|
|
13
|
+
*
|
|
14
|
+
* @param integrityFilePath - path to the integrity file
|
|
15
|
+
* @param content - content to write to the integrity file
|
|
16
|
+
*/
|
|
17
|
+
export declare function writeIntegrityData(integrityFilePath: string, content: Integrity): Promise<void>;
|
|
18
|
+
//# sourceMappingURL=persistence.d.ts.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readIntegrityData = readIntegrityData;
|
|
4
|
+
exports.writeIntegrityData = writeIntegrityData;
|
|
5
|
+
const promises_1 = require("fs/promises");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const lz_string_1 = require("lz-string");
|
|
9
|
+
/**
|
|
10
|
+
* Read hashes from a previously stored hash file.
|
|
11
|
+
* Throws an error if the file does not exist.
|
|
12
|
+
*
|
|
13
|
+
* @param integrityFilePath - path to the integrity file
|
|
14
|
+
* @returns - integrity data
|
|
15
|
+
*/
|
|
16
|
+
async function readIntegrityData(integrityFilePath) {
|
|
17
|
+
if (!(0, fs_1.existsSync)(integrityFilePath)) {
|
|
18
|
+
throw new Error(`Integrity file not found at ${integrityFilePath}`);
|
|
19
|
+
}
|
|
20
|
+
const content = JSON.parse(await (0, promises_1.readFile)(integrityFilePath, { encoding: 'utf-8' }));
|
|
21
|
+
const integrityDir = (0, path_1.dirname)(integrityFilePath);
|
|
22
|
+
for (const fileIntegrity of content.fileIntegrity) {
|
|
23
|
+
fileIntegrity.filePath = (0, path_1.join)(integrityDir, fileIntegrity.filePath);
|
|
24
|
+
getifyContent(fileIntegrity);
|
|
25
|
+
}
|
|
26
|
+
for (const contentIntegrity of content.contentIntegrity) {
|
|
27
|
+
getifyContent(contentIntegrity);
|
|
28
|
+
}
|
|
29
|
+
return content;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Write file integrity information to file. When storing, use relative paths to the hash file
|
|
33
|
+
* so the project as whole can be moved without breaking integrity.
|
|
34
|
+
*
|
|
35
|
+
* @param integrityFilePath - path to the integrity file
|
|
36
|
+
* @param content - content to write to the integrity file
|
|
37
|
+
*/
|
|
38
|
+
async function writeIntegrityData(integrityFilePath, content) {
|
|
39
|
+
const integrityDir = (0, path_1.dirname)(integrityFilePath);
|
|
40
|
+
if (!(0, fs_1.existsSync)(integrityDir)) {
|
|
41
|
+
await (0, promises_1.mkdir)(integrityDir, { recursive: true });
|
|
42
|
+
}
|
|
43
|
+
for (const fileIntegrity of content.fileIntegrity) {
|
|
44
|
+
fileIntegrity.filePath = (0, path_1.relative)(integrityDir, fileIntegrity.filePath);
|
|
45
|
+
if (typeof fileIntegrity.content === 'string') {
|
|
46
|
+
fileIntegrity.content = (0, lz_string_1.compressToBase64)(fileIntegrity.content);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
for (const contentIntegrity of content.contentIntegrity) {
|
|
50
|
+
if (typeof contentIntegrity.content === 'string') {
|
|
51
|
+
contentIntegrity.content = (0, lz_string_1.compressToBase64)(contentIntegrity.content);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
await (0, promises_1.writeFile)(integrityFilePath, JSON.stringify(content), { encoding: 'utf-8' });
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Wrap content with getter to decompress on first access. Do nothing if the content does not exist.
|
|
58
|
+
*
|
|
59
|
+
* @param integrityObject - file or content integrity data with compressed content
|
|
60
|
+
*/
|
|
61
|
+
function getifyContent(integrityObject) {
|
|
62
|
+
if (typeof integrityObject?.content === 'string') {
|
|
63
|
+
const compressedContent = integrityObject.content;
|
|
64
|
+
let content;
|
|
65
|
+
Object.defineProperty(integrityObject, 'content', {
|
|
66
|
+
get: () => {
|
|
67
|
+
if (!content) {
|
|
68
|
+
content = (0, lz_string_1.decompressFromBase64)(compressedContent);
|
|
69
|
+
}
|
|
70
|
+
return content;
|
|
71
|
+
},
|
|
72
|
+
set: () => {
|
|
73
|
+
// Read-only property, ignore content changes
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=persistence.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { CheckIntegrityResult, Content, ProjectSettings } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Initialize a project by creating hashes for all selected files in the project. There is an option to add
|
|
4
|
+
* additional key->string content to the integrity data.
|
|
5
|
+
*
|
|
6
|
+
* @param settings - settings for the project
|
|
7
|
+
* @param settings.integrityFilePath - path to file where integrity data will be stored
|
|
8
|
+
* @param settings.fileList - list of file paths for files to create integrity data for
|
|
9
|
+
* @param [settings.additionalStringContent] - optional key/string map to add to integrity data
|
|
10
|
+
*/
|
|
11
|
+
export declare function initProject(settings: ProjectSettings): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Check the integrity of a project by comparing the stored integrity data with the current state
|
|
14
|
+
* of the files and additional key->string. Throws an error if the project is not initialized,
|
|
15
|
+
* which means no integrity data found at 'integrityFilePath'.
|
|
16
|
+
*
|
|
17
|
+
* @param integrityFilePath - path to file where integrity data is stored
|
|
18
|
+
* @param [additionalStringContent] - optional key/string map to add to integrity data
|
|
19
|
+
* @returns - results of the check
|
|
20
|
+
*/
|
|
21
|
+
export declare function checkProjectIntegrity(integrityFilePath: string, additionalStringContent?: Content): Promise<CheckIntegrityResult>;
|
|
22
|
+
/**
|
|
23
|
+
* Updates the integrity data of a project. Throws an error if a file or string content is missing
|
|
24
|
+
* or new.
|
|
25
|
+
*
|
|
26
|
+
* @param integrityFilePath - path to file where integrity data is stored
|
|
27
|
+
* @param additionalStringContent - optional key/string map to add to integrity data
|
|
28
|
+
*/
|
|
29
|
+
export declare function updateProjectIntegrity(integrityFilePath: string, additionalStringContent?: Content): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Return whether integrity is enabled for a project.
|
|
32
|
+
*
|
|
33
|
+
* @param integrityFilePath - path to file where integrity data is stored
|
|
34
|
+
* @returns - true if integrity is enabled, false otherwise
|
|
35
|
+
*/
|
|
36
|
+
export declare function isProjectIntegrityEnabled(integrityFilePath: string): Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Enable integrity for a project. The project has to be initialized before enabling integrity. After initialization,
|
|
39
|
+
* the project integrity is enabled by default.
|
|
40
|
+
*
|
|
41
|
+
* @param integrityFilePath - path to file where integrity data is stored
|
|
42
|
+
*/
|
|
43
|
+
export declare function enableProjectIntegrity(integrityFilePath: string): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Disable integrity for a project. The project has to be initialized before disabling integrity.
|
|
46
|
+
*
|
|
47
|
+
* @param integrityFilePath - path to file where integrity data is stored
|
|
48
|
+
*/
|
|
49
|
+
export declare function disableProjectIntegrity(integrityFilePath: string): Promise<void>;
|
|
50
|
+
//# sourceMappingURL=project.d.ts.map
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initProject = initProject;
|
|
4
|
+
exports.checkProjectIntegrity = checkProjectIntegrity;
|
|
5
|
+
exports.updateProjectIntegrity = updateProjectIntegrity;
|
|
6
|
+
exports.isProjectIntegrityEnabled = isProjectIntegrityEnabled;
|
|
7
|
+
exports.enableProjectIntegrity = enableProjectIntegrity;
|
|
8
|
+
exports.disableProjectIntegrity = disableProjectIntegrity;
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const hash_1 = require("./hash");
|
|
11
|
+
const persistence_1 = require("./persistence");
|
|
12
|
+
const check_1 = require("./check");
|
|
13
|
+
/**
|
|
14
|
+
* Function to ensure correct sorting of strings.
|
|
15
|
+
*
|
|
16
|
+
* @param a - first value to compare
|
|
17
|
+
* @param b - second value to compare
|
|
18
|
+
* @returns - 1 if a is greater than b, -1 if a is less than b, 0 if a is equal to b
|
|
19
|
+
*/
|
|
20
|
+
const sortLocal = (a, b) => a.localeCompare(b);
|
|
21
|
+
/**
|
|
22
|
+
* Initialize a project by creating hashes for all selected files in the project. There is an option to add
|
|
23
|
+
* additional key->string content to the integrity data.
|
|
24
|
+
*
|
|
25
|
+
* @param settings - settings for the project
|
|
26
|
+
* @param settings.integrityFilePath - path to file where integrity data will be stored
|
|
27
|
+
* @param settings.fileList - list of file paths for files to create integrity data for
|
|
28
|
+
* @param [settings.additionalStringContent] - optional key/string map to add to integrity data
|
|
29
|
+
*/
|
|
30
|
+
async function initProject(settings) {
|
|
31
|
+
const enabled = true;
|
|
32
|
+
const fileIntegrity = await (0, hash_1.getFileIntegrity)(settings.fileList);
|
|
33
|
+
const contentIntegrity = await (0, hash_1.getContentIntegrity)(settings.additionalStringContent);
|
|
34
|
+
await (0, persistence_1.writeIntegrityData)(settings.integrityFilePath, { enabled, fileIntegrity, contentIntegrity });
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Check the integrity of a project by comparing the stored integrity data with the current state
|
|
38
|
+
* of the files and additional key->string. Throws an error if the project is not initialized,
|
|
39
|
+
* which means no integrity data found at 'integrityFilePath'.
|
|
40
|
+
*
|
|
41
|
+
* @param integrityFilePath - path to file where integrity data is stored
|
|
42
|
+
* @param [additionalStringContent] - optional key/string map to add to integrity data
|
|
43
|
+
* @returns - results of the check
|
|
44
|
+
*/
|
|
45
|
+
async function checkProjectIntegrity(integrityFilePath, additionalStringContent) {
|
|
46
|
+
const integrityData = await (0, persistence_1.readIntegrityData)(integrityFilePath);
|
|
47
|
+
if (!integrityData.enabled) {
|
|
48
|
+
throw new Error(`Integrity is disabled for the project with integrity data ${integrityFilePath}`);
|
|
49
|
+
}
|
|
50
|
+
const checkResult = (0, check_1.checkIntegrity)(integrityData, additionalStringContent);
|
|
51
|
+
return checkResult;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Updates the integrity data of a project. Throws an error if a file or string content is missing
|
|
55
|
+
* or new.
|
|
56
|
+
*
|
|
57
|
+
* @param integrityFilePath - path to file where integrity data is stored
|
|
58
|
+
* @param additionalStringContent - optional key/string map to add to integrity data
|
|
59
|
+
*/
|
|
60
|
+
async function updateProjectIntegrity(integrityFilePath, additionalStringContent) {
|
|
61
|
+
if (!(0, fs_1.existsSync)(integrityFilePath)) {
|
|
62
|
+
throw new Error(`Integrity data not found at ${integrityFilePath}`);
|
|
63
|
+
}
|
|
64
|
+
const integrityData = await (0, persistence_1.readIntegrityData)(integrityFilePath);
|
|
65
|
+
if (!integrityData.enabled) {
|
|
66
|
+
throw new Error(`Integrity is disabled for the project with integrity data ${integrityFilePath}`);
|
|
67
|
+
}
|
|
68
|
+
const existingContentKeys = integrityData.contentIntegrity.map((content) => content.contentKey).sort(sortLocal);
|
|
69
|
+
const newContentKeys = Object.keys(additionalStringContent ?? {}).sort(sortLocal);
|
|
70
|
+
if (existingContentKeys.length !== newContentKeys.length ||
|
|
71
|
+
!existingContentKeys.every((key, index) => key === newContentKeys[index])) {
|
|
72
|
+
throw new Error(`There is a mismatch of additional content keys.
|
|
73
|
+
Stored content keys: ${existingContentKeys.join(', ')}
|
|
74
|
+
New content keys: ${newContentKeys.join(', ')}`);
|
|
75
|
+
}
|
|
76
|
+
const fileIntegrity = await (0, hash_1.getFileIntegrity)(integrityData.fileIntegrity.map((file) => file.filePath));
|
|
77
|
+
const contentIntegrity = (0, hash_1.getContentIntegrity)(additionalStringContent);
|
|
78
|
+
await (0, persistence_1.writeIntegrityData)(integrityFilePath, { enabled: integrityData.enabled, fileIntegrity, contentIntegrity });
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Return whether integrity is enabled for a project.
|
|
82
|
+
*
|
|
83
|
+
* @param integrityFilePath - path to file where integrity data is stored
|
|
84
|
+
* @returns - true if integrity is enabled, false otherwise
|
|
85
|
+
*/
|
|
86
|
+
async function isProjectIntegrityEnabled(integrityFilePath) {
|
|
87
|
+
if (!(0, fs_1.existsSync)(integrityFilePath)) {
|
|
88
|
+
throw new Error(`Integrity data not found at ${integrityFilePath}`);
|
|
89
|
+
}
|
|
90
|
+
const { enabled } = await (0, persistence_1.readIntegrityData)(integrityFilePath);
|
|
91
|
+
return enabled;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Enable integrity for a project. The project has to be initialized before enabling integrity. After initialization,
|
|
95
|
+
* the project integrity is enabled by default.
|
|
96
|
+
*
|
|
97
|
+
* @param integrityFilePath - path to file where integrity data is stored
|
|
98
|
+
*/
|
|
99
|
+
async function enableProjectIntegrity(integrityFilePath) {
|
|
100
|
+
if (!(0, fs_1.existsSync)(integrityFilePath)) {
|
|
101
|
+
throw new Error(`Integrity data not found at ${integrityFilePath}`);
|
|
102
|
+
}
|
|
103
|
+
const integrityData = await (0, persistence_1.readIntegrityData)(integrityFilePath);
|
|
104
|
+
if (!integrityData.enabled) {
|
|
105
|
+
integrityData.enabled = true;
|
|
106
|
+
await (0, persistence_1.writeIntegrityData)(integrityFilePath, integrityData);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Disable integrity for a project. The project has to be initialized before disabling integrity.
|
|
111
|
+
*
|
|
112
|
+
* @param integrityFilePath - path to file where integrity data is stored
|
|
113
|
+
*/
|
|
114
|
+
async function disableProjectIntegrity(integrityFilePath) {
|
|
115
|
+
if (!(0, fs_1.existsSync)(integrityFilePath)) {
|
|
116
|
+
throw new Error(`Integrity data not found at ${integrityFilePath}`);
|
|
117
|
+
}
|
|
118
|
+
const integrityData = await (0, persistence_1.readIntegrityData)(integrityFilePath);
|
|
119
|
+
if (integrityData.enabled) {
|
|
120
|
+
integrityData.enabled = false;
|
|
121
|
+
await (0, persistence_1.writeIntegrityData)(integrityFilePath, integrityData);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=project.js.map
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project settings when initializing project integrity.
|
|
3
|
+
*/
|
|
4
|
+
export interface ProjectSettings {
|
|
5
|
+
/**
|
|
6
|
+
* Path to the file where integrity data, like hash values, are stored
|
|
7
|
+
*/
|
|
8
|
+
integrityFilePath: string;
|
|
9
|
+
/**
|
|
10
|
+
* List of files to create a hash value for
|
|
11
|
+
*/
|
|
12
|
+
fileList: string[];
|
|
13
|
+
/**
|
|
14
|
+
* List of content (key->string) to create a hash value for
|
|
15
|
+
*/
|
|
16
|
+
additionalStringContent?: Content;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Integrity data for a project, stored as JSON in integrity file.
|
|
20
|
+
*/
|
|
21
|
+
export interface Integrity {
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
fileIntegrity: FileIntegrity[];
|
|
24
|
+
contentIntegrity: ContentIntegrity[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Integrity data for a file.
|
|
28
|
+
*/
|
|
29
|
+
export interface FileIntegrity {
|
|
30
|
+
filePath: string;
|
|
31
|
+
hash: string;
|
|
32
|
+
content?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Integrity data for a content (key->string).
|
|
36
|
+
*/
|
|
37
|
+
export interface ContentIntegrity {
|
|
38
|
+
contentKey: string;
|
|
39
|
+
hash: string;
|
|
40
|
+
content?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Content (key->string) to store in integrity data.
|
|
44
|
+
*/
|
|
45
|
+
export interface Content {
|
|
46
|
+
[contentKey: string]: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Result of a project integrity check.
|
|
50
|
+
*/
|
|
51
|
+
export interface CheckIntegrityResult {
|
|
52
|
+
files: {
|
|
53
|
+
differentFiles: {
|
|
54
|
+
filePath: string;
|
|
55
|
+
oldContent?: string;
|
|
56
|
+
newContent?: string;
|
|
57
|
+
}[];
|
|
58
|
+
equalFiles: string[];
|
|
59
|
+
};
|
|
60
|
+
additionalStringContent: {
|
|
61
|
+
differentContent: {
|
|
62
|
+
key: string;
|
|
63
|
+
oldContent?: string;
|
|
64
|
+
newContent?: string;
|
|
65
|
+
}[];
|
|
66
|
+
equalContent: string[];
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sap-ux/project-integrity",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Library to check the integrity of projects",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/SAP/open-ux-tools.git",
|
|
8
|
+
"directory": "packages/project-integrity"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aproject-integrity"
|
|
12
|
+
},
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"private": false,
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"!dist/*.map",
|
|
20
|
+
"!dist/**/*.map"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=18.x"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"lz-string": "1.5.0",
|
|
27
|
+
"@sap-ux/project-access": "1.28.10"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc --build",
|
|
31
|
+
"clean": "rimraf --glob dist coverage *.tsbuildinfo",
|
|
32
|
+
"format": "prettier --write '**/*.{js,json,ts,yaml,yml}' --ignore-path ../../.prettierignore",
|
|
33
|
+
"lint": "eslint . --ext .ts",
|
|
34
|
+
"lint:fix": "eslint . --ext .ts --fix",
|
|
35
|
+
"test": "jest --ci --forceExit --detectOpenHandles --colors",
|
|
36
|
+
"watch": "tsc --watch"
|
|
37
|
+
}
|
|
38
|
+
}
|