@cap-js/audit-logging 0.5.0 → 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 CHANGED
@@ -4,6 +4,18 @@ 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
+
13
+ ## Version 0.5.1 - 2023-11-30
14
+
15
+ ### Fixed
16
+
17
+ - Falsy early exit during bootstrapping in case a service does not contain personal data
18
+
7
19
  ## Version 0.5.0 - 2023-11-22
8
20
 
9
21
  ### Added
package/cds-plugin.js CHANGED
@@ -17,7 +17,7 @@ cds.on('served', services => {
17
17
 
18
18
  const relevantEntities = []
19
19
  for (const entity of service.entities) if (hasPersonalData(entity)) relevantEntities.push(entity)
20
- if (!relevantEntities.length) return
20
+ if (!relevantEntities.length) continue
21
21
 
22
22
  for (const entity of relevantEntities) {
23
23
  /*
@@ -17,6 +17,41 @@ const {
17
17
 
18
18
  let audit
19
19
 
20
+ const _applyTransitionRecursively = (transition, data, d, old = {}) => {
21
+ for (const [k, v] of transition.mapping) {
22
+ if (v.transition) {
23
+ const ok = v.ref?.[0] || k
24
+ if (!data[ok]) continue
25
+ if (Array.isArray(data[ok])) {
26
+ d[k] = []
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
+ }
40
+ }
41
+ } else {
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)
46
+ }
47
+ } else if (v.ref) {
48
+ if (v.ref[0] in data) d[k] = data[v.ref[0]]
49
+ if (v.ref[0] in old) d._old[k] = old[v.ref[0]]
50
+ }
51
+ }
52
+ if (Object.keys(old).length) old.__visited = true
53
+ }
54
+
20
55
  // REVISIT: remove once old database impl is removed
21
56
  const _getDataWithAppliedTransitions = (data, req) => {
22
57
  let d
@@ -24,12 +59,9 @@ const _getDataWithAppliedTransitions = (data, req) => {
24
59
  // NOTE: there will only be transitions if old database impl is used
25
60
  const transition = query._transitions?.find(t => t.queryTarget.name === req.target.name)
26
61
  if (transition) {
27
- d = { _op: data._op }
62
+ d = data._op ? { _op: data._op } : {}
28
63
  if (data._old) d._old = {}
29
- for (const [k, v] of transition.mapping) {
30
- if (v.ref[0] in data) d[k] = data[v.ref[0]]
31
- if (data._old && v.ref[0] in data._old) d._old[k] = data._old[v.ref[0]]
32
- }
64
+ _applyTransitionRecursively(transition, data, d, data._old)
33
65
  }
34
66
  return d || data
35
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/audit-logging",
3
- "version": "0.5.0",
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": "npx jest --silent"
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",