@cap-js/audit-logging 0.5.1 → 0.5.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/CHANGELOG.md +6 -0
- package/lib/modification.js +25 -13
- package/package.json +9 -3
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/).
|
|
6
6
|
|
|
7
|
+
## Version 0.5.2 - 2023-12-08
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Automatic personal data modification logging for deep data structures with renamings
|
|
12
|
+
|
|
7
13
|
## Version 0.5.1 - 2023-11-30
|
|
8
14
|
|
|
9
15
|
### Fixed
|
package/lib/modification.js
CHANGED
|
@@ -17,27 +17,39 @@ const {
|
|
|
17
17
|
|
|
18
18
|
let audit
|
|
19
19
|
|
|
20
|
-
const _applyTransitionRecursively = (transition, data, d) => {
|
|
20
|
+
const _applyTransitionRecursively = (transition, data, d, old = {}) => {
|
|
21
21
|
for (const [k, v] of transition.mapping) {
|
|
22
22
|
if (v.transition) {
|
|
23
|
-
|
|
23
|
+
const ok = v.ref?.[0] || k
|
|
24
|
+
if (!data[ok]) continue
|
|
25
|
+
if (Array.isArray(data[ok])) {
|
|
24
26
|
d[k] = []
|
|
25
|
-
for (let i = 0; i < data[
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
for (let i = 0; i < data[ok].length; i++) {
|
|
28
|
+
const _op = data[ok][i]._op || d._op
|
|
29
|
+
d[k].push(_op ? { _op } : {})
|
|
30
|
+
const _old = old[ok]?.[i] || data[ok][i]._old
|
|
31
|
+
if (_old) d[k][i]._old = _old
|
|
32
|
+
_applyTransitionRecursively(v.transition, data[ok][i], d[k][i], _old)
|
|
33
|
+
}
|
|
34
|
+
if (old[ok] && data[ok].length !== old[ok].length) {
|
|
35
|
+
for (const each of Object.values(old[ok]).filter(ele => !ele.__visited)) {
|
|
36
|
+
const i = d[k].push({ _op: 'delete' })
|
|
37
|
+
d[k][i - 1]._old = each
|
|
38
|
+
_applyTransitionRecursively(v.transition, each, d[k][i - 1], each)
|
|
39
|
+
}
|
|
29
40
|
}
|
|
30
41
|
} else {
|
|
31
|
-
d[k] = { _op: data[
|
|
32
|
-
|
|
33
|
-
|
|
42
|
+
d[k] = { _op: data[ok]._op || d._op }
|
|
43
|
+
const _old = old[ok] || data[ok]._old
|
|
44
|
+
if (_old) d[k]._old = _old
|
|
45
|
+
_applyTransitionRecursively(v.transition, data[ok], d[k], _old)
|
|
34
46
|
}
|
|
35
|
-
continue
|
|
36
47
|
} else if (v.ref) {
|
|
37
48
|
if (v.ref[0] in data) d[k] = data[v.ref[0]]
|
|
38
|
-
if (
|
|
49
|
+
if (v.ref[0] in old) d._old[k] = old[v.ref[0]]
|
|
39
50
|
}
|
|
40
51
|
}
|
|
52
|
+
if (Object.keys(old).length) old.__visited = true
|
|
41
53
|
}
|
|
42
54
|
|
|
43
55
|
// REVISIT: remove once old database impl is removed
|
|
@@ -47,9 +59,9 @@ const _getDataWithAppliedTransitions = (data, req) => {
|
|
|
47
59
|
// NOTE: there will only be transitions if old database impl is used
|
|
48
60
|
const transition = query._transitions?.find(t => t.queryTarget.name === req.target.name)
|
|
49
61
|
if (transition) {
|
|
50
|
-
d = { _op: data._op }
|
|
62
|
+
d = data._op ? { _op: data._op } : {}
|
|
51
63
|
if (data._old) d._old = {}
|
|
52
|
-
_applyTransitionRecursively(transition, data, d)
|
|
64
|
+
_applyTransitionRecursively(transition, data, d, data._old)
|
|
53
65
|
}
|
|
54
66
|
return d || data
|
|
55
67
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js/audit-logging",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
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)",
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
16
|
"lint": "npx eslint .",
|
|
17
|
-
"test": "
|
|
17
|
+
"test": "npm run test-new-db && npm run test-old-db",
|
|
18
|
+
"test-new-db": "CDS_ENV='better-sqlite' npx jest --silent",
|
|
19
|
+
"test-old-db": "npx jest --silent"
|
|
18
20
|
},
|
|
19
21
|
"peerDependencies": {
|
|
20
22
|
"@sap/cds": "^7"
|
|
@@ -25,10 +27,14 @@
|
|
|
25
27
|
"axios": "^1",
|
|
26
28
|
"eslint": "^8",
|
|
27
29
|
"express": "^4",
|
|
28
|
-
"jest": "^29"
|
|
30
|
+
"jest": "^29",
|
|
31
|
+
"sqlite3": "^5.1.6"
|
|
29
32
|
},
|
|
30
33
|
"cds": {
|
|
31
34
|
"requires": {
|
|
35
|
+
"[test]": {
|
|
36
|
+
"outbox": "persistent-outbox"
|
|
37
|
+
},
|
|
32
38
|
"audit-log": {
|
|
33
39
|
"handle": [
|
|
34
40
|
"READ",
|