@cap-js/audit-logging 1.2.1 → 1.3.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/README.md +2 -2
- package/lib/utils.js +16 -3
- package/package.json +7 -7
- package/srv/log2alsng.js +1 -1
- package/srv/log2restv2.js +2 -5
package/README.md
CHANGED
|
@@ -122,9 +122,9 @@ See the audit logs in the server's console output:
|
|
|
122
122
|
|
|
123
123
|
The end-to-end out-of-the-box functionality provided by this plugin requires a paid-for instance of the [SAP Audit Log service for customers](https://help.sap.com/docs/btp/sap-business-technology-platform/audit-log-write-api-for-customers?locale=en-US). However, it is possible to provide an own implementation that writes the audit logs to a custom store.
|
|
124
124
|
|
|
125
|
-
[_Learn more about using the SAP Audit Log service._](https://cap.cloud.sap/docs/guides/
|
|
125
|
+
[_Learn more about using the SAP Audit Log service._](https://cap.cloud.sap/docs/guides/security/dpp-audit-logging#use-sap-audit-log-service)
|
|
126
126
|
|
|
127
|
-
[_Learn more about custom audit logging._](https://cap.cloud.sap/docs/guides/
|
|
127
|
+
[_Learn more about custom audit logging._](https://cap.cloud.sap/docs/guides/security/dpp-audit-logging#custom-audit-logging)
|
|
128
128
|
|
|
129
129
|
## Support, Feedback, Contributing
|
|
130
130
|
|
package/lib/utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const cds = require("@sap/cds");
|
|
2
|
+
const LOG = cds.log("audit-log");
|
|
2
3
|
|
|
3
4
|
const { Relation, exposeRelation, relationHandler } = require("./_relation");
|
|
4
5
|
|
|
@@ -24,7 +25,7 @@ const hasPersonalData = (entity) => {
|
|
|
24
25
|
const hasPersonalData = !!Object.values(entity.elements).some(element =>
|
|
25
26
|
element['@PersonalData.IsPotentiallyPersonal'] ||
|
|
26
27
|
element['@PersonalData.IsPotentiallySensitive'] ||
|
|
27
|
-
(element['@PersonalData.FieldSemantics'] && element['@PersonalData.FieldSemantics'] === 'DataSubjectID'))
|
|
28
|
+
(element['@PersonalData.FieldSemantics'] && element['@PersonalData.FieldSemantics'] === 'DataSubjectID'));
|
|
28
29
|
entity.set($hasPersonalData, hasPersonalData);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
@@ -212,6 +213,10 @@ const _getDataSubjectUp = (root, model, entity, prev, next, result) => {
|
|
|
212
213
|
} else {
|
|
213
214
|
// dfs is a must here
|
|
214
215
|
result = _getDataSubjectUp(root, model, element.parent, me, next || me, result);
|
|
216
|
+
// If upward traversal dead-ends, try finding the DataSubject downward from the parent entity.
|
|
217
|
+
// This handles composition targets whose parent reaches a DataSubject via a sibling association
|
|
218
|
+
// (e.g., Attachments → up to Things → down via owner to Users).
|
|
219
|
+
if (!result) result = _getDataSubjectDown(root, element.parent, me, next || me);
|
|
215
220
|
}
|
|
216
221
|
}
|
|
217
222
|
return result;
|
|
@@ -246,9 +251,9 @@ const getDataSubject = (entity, model) => {
|
|
|
246
251
|
// be always below or always above 'DataSubject' entity in CSN tree
|
|
247
252
|
let dataSubjectInfo = _getDataSubjectUp(entity.name, model, entity);
|
|
248
253
|
if (!dataSubjectInfo) dataSubjectInfo = _getDataSubjectDown(entity.name, entity);
|
|
249
|
-
entity.set($dataSubject, dataSubjectInfo);
|
|
254
|
+
entity.set($dataSubject, dataSubjectInfo || false);
|
|
250
255
|
}
|
|
251
|
-
return entity.own($dataSubject);
|
|
256
|
+
return entity.own($dataSubject) || undefined;
|
|
252
257
|
};
|
|
253
258
|
|
|
254
259
|
const _getDataSubjectsMap = (req) => {
|
|
@@ -261,6 +266,14 @@ const _getDataSubjectsMap = (req) => {
|
|
|
261
266
|
|
|
262
267
|
const addDataSubjectForDetailsEntity = (row, log, req, entity, model) => {
|
|
263
268
|
const dataSubjectInfo = getDataSubject(entity, model);
|
|
269
|
+
if (!dataSubjectInfo) {
|
|
270
|
+
LOG.warn(
|
|
271
|
+
`No DataSubject entity reachable from '${entity.name}' annotated with @PersonalData.EntitySemantics: '${entity["@PersonalData.EntitySemantics"]}'. ` +
|
|
272
|
+
`Skipping data-subject enrichment for this entity. ` +
|
|
273
|
+
`Ensure a path to an entity annotated with @PersonalData.EntitySemantics: 'DataSubject' exists via associations.`
|
|
274
|
+
);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
264
277
|
const role = dataSubjectInfo.dataSubjectEntity["@PersonalData.DataSubjectRole"];
|
|
265
278
|
log.data_subject.role ??= role;
|
|
266
279
|
log.data_subject.type = dataSubjectInfo.dataSubjectEntity.name;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js/audit-logging",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "CDS plugin providing integration to the SAP Audit Log service as well as out-of-the-box personal data-related audit logging based on annotations.",
|
|
5
5
|
"repository": "cap-js/audit-logging",
|
|
6
6
|
"author": "SAP SE (https://www.sap.com)",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
"test": "npx jest --silent --testPathIgnorePatterns=integration"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"@sap/cds": ">=
|
|
21
|
+
"@sap/cds": ">=9"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@cap-js/audit-logging": "file:.",
|
|
25
|
-
"@cap-js/cds-test": "
|
|
26
|
-
"@cap-js/sqlite": "
|
|
27
|
-
"@sap/cds-lsp": "^
|
|
28
|
-
"@sap/cds-mtxs": "^
|
|
29
|
-
"express": "^
|
|
25
|
+
"@cap-js/cds-test": "^1",
|
|
26
|
+
"@cap-js/sqlite": "^3",
|
|
27
|
+
"@sap/cds-lsp": "^10",
|
|
28
|
+
"@sap/cds-mtxs": "^4",
|
|
29
|
+
"express": "^5",
|
|
30
30
|
"jest": "^30"
|
|
31
31
|
},
|
|
32
32
|
"cds": {
|
package/srv/log2alsng.js
CHANGED
|
@@ -195,7 +195,7 @@ module.exports = class AuditLog2ALSNG extends AuditLogService {
|
|
|
195
195
|
if (res.headers["content-type"]?.match(/json/)) body = JSON.parse(body);
|
|
196
196
|
if (res.statusCode >= 400) {
|
|
197
197
|
// prettier-ignore
|
|
198
|
-
const err = new Error(`Request failed with${statusMessage ? `: ${statusCode} - ${statusMessage}` : ` status ${statusCode}`}`)
|
|
198
|
+
const err = new Error(`Request failed with${statusMessage ? `: ${statusCode} - ${statusMessage}` : ` status ${statusCode}`}`);
|
|
199
199
|
err.request = { method: options.method, url, headers: options.headers, body: data };
|
|
200
200
|
if (err.request.headers.authorization)
|
|
201
201
|
err.request.headers.authorization =
|
package/srv/log2restv2.js
CHANGED
|
@@ -69,12 +69,9 @@ module.exports = class AuditLog2RESTv2 extends AuditLogService {
|
|
|
69
69
|
} else {
|
|
70
70
|
data.client_secret = uaa.clientsecret;
|
|
71
71
|
}
|
|
72
|
-
const
|
|
73
|
-
acc += (acc ? "&" : "") + cur + "=" + data[cur];
|
|
74
|
-
return acc;
|
|
75
|
-
}, "");
|
|
72
|
+
const encodedParams = new URLSearchParams(data).toString();
|
|
76
73
|
try {
|
|
77
|
-
const { access_token, expires_in } = await _post(url,
|
|
74
|
+
const { access_token, expires_in } = await _post(url, encodedParams, options);
|
|
78
75
|
tokens.set(tenant, access_token);
|
|
79
76
|
// remove token from cache 60 seconds before it expires
|
|
80
77
|
setTimeout(() => tokens.delete(tenant), (expires_in - 60) * 1000);
|