@cap-js/audit-logging 0.8.0 → 0.8.1

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,13 @@ 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.8.1 - 2024-09-13
8
+
9
+ ### Fixed
10
+
11
+ - Support for @sap/cds^8.2
12
+ - Reduce clutter in error raised for outbound requests
13
+
7
14
  ## Version 0.8.0 - 2024-05-24
8
15
 
9
16
  ### Added
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Welcome to @cap-js/audit-logging
2
+
2
3
  [![REUSE status](https://api.reuse.software/badge/github.com/cap-js/audit-logging)](https://api.reuse.software/info/github.com/cap-js/audit-logging)
3
4
 
4
5
  `@cap-js/audit-logging` is a 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.
@@ -19,18 +20,22 @@ cd incidents-app
19
20
  npm i
20
21
  ```
21
22
 
23
+
22
24
  ## Setup
25
+
23
26
  To enable audit logging, simply add this self-configuring plugin package to your project:
24
27
 
25
28
  ```sh
26
29
  npm add @cap-js/audit-logging
27
30
  ```
28
31
 
32
+
29
33
  ## Annotate Personal Data
34
+
30
35
  Identify entities and elements (potentially) holding personal data using `@PersonalData` annotations. Create a `db/data-privacy.cds` file and add the following:
31
36
 
32
37
  ```cds
33
- using { sap.capire.incidents as my } from '../db/extensions';
38
+ using { sap.capire.incidents as my } from './schema';
34
39
 
35
40
  annotate my.Customers with @PersonalData : {
36
41
  DataSubjectRole : 'Customer',
@@ -69,6 +74,7 @@ Learn more about the annotations in capire:
69
74
 
70
75
 
71
76
  ## Test-Drive Locally
77
+
72
78
  You've prepared everything to log personal data-related events. Let's see that in action.
73
79
 
74
80
  Start the server as usual:
@@ -78,36 +84,36 @@ cds watch
78
84
 
79
85
  Send an update request that changes personal data:
80
86
  ```http
81
- PATCH http://localhost:4004/admin/Customers(8e2f2640-6866-4dcf-8f4d-3027aa831cad) HTTP/1.1
87
+ PATCH http://localhost:4004/odata/v4/admin/Customers('1004155')
82
88
  Authorization: Basic alice:in-wonderland
83
89
  Content-Type: application/json
84
90
 
85
91
  {
86
- "firstName": "Johnny",
87
- "lastName": "Doey"
92
+ "firstName": "Danny",
93
+ "lastName": "Joules"
88
94
  }
89
95
  ```
90
96
 
91
97
  See the audit logs in the server's console output:
92
98
  ```sh
93
- {
99
+ [audit-log] - PersonalDataModified: {
94
100
  data_subject: {
95
- type: 'AdminService.Customers',
96
- id: { ID: '8e2f2640-6866-4dcf-8f4d-3027aa831cad' },
101
+ id: { ID: '1004155' },
97
102
  role: 'Customer',
103
+ type: 'AdminService.Customers'
98
104
  },
99
105
  object: {
100
106
  type: 'AdminService.Customers',
101
- id: { ID: '8e2f2640-6866-4dcf-8f4d-3027aa831cad' }
107
+ id: { ID: '1004155' }
102
108
  },
103
109
  attributes: [
104
- { name: 'firstName', old: 'John', new: 'Johnny' },
105
- { name: 'lastName', old: 'Doe', new: 'Doey' }
110
+ { name: 'firstName', old: 'Daniel', new: 'Danny' },
111
+ { name: 'lastName', old: 'Watts', new: 'Joules' }
106
112
  ],
107
- user: 'alice',
113
+ uuid: '71fa93d9-c993-405f-ba1b-a9ef42668199',
108
114
  tenant: 't1',
109
- uuid: '1391A703E2CBE52E817269EC7527368C',
110
- time: '2023-02-26T08:13:48.287Z'
115
+ user: 'alice',
116
+ time: 2023-02-26T08:13:48.287Z
111
117
  }
112
118
  ```
113
119
 
@@ -120,14 +126,17 @@ The end-to-end out-of-the-box functionality provided by this plugin requires a p
120
126
 
121
127
  [_Learn more about custom audit logging._](https://cap.cloud.sap/docs/guides/data-privacy/audit-logging#custom-audit-logging)
122
128
 
129
+
123
130
  ## Support, Feedback, Contributing
124
131
 
125
132
  This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/cap-js/audit-logging/issues). Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
126
133
 
134
+
127
135
  ## Code of Conduct
128
136
 
129
137
  We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its [Code of Conduct](CODE_OF_CONDUCT.md) at all times.
130
138
 
139
+
131
140
  ## Licensing
132
141
 
133
142
  Copyright 2023 SAP SE or an SAP affiliate company and contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/cap-js/audit-logging).
package/lib/access.js CHANGED
@@ -2,7 +2,6 @@ const cds = require('@sap/cds')
2
2
 
3
3
  // REVISIT: don't require internal stuff
4
4
  const getTemplate = require('@sap/cds/libx/_runtime/common/utils/template')
5
- const templateProcessor = require('@sap/cds/libx/_runtime/common/utils/templateProcessor')
6
5
 
7
6
  const {
8
7
  getRootEntity,
@@ -56,8 +55,16 @@ const auditAccess = async function (data, req) {
56
55
  if (!template.elements.size) return
57
56
 
58
57
  const accessLogs = {}
59
- const _data = Array.isArray(data) ? data : [data]
60
- _data.forEach(row => templateProcessor({ processFn: _processorFnAccess(accessLogs, this.model, req), row, template }))
58
+ const processFn = _processorFnAccess(accessLogs, this.model, req)
59
+ // cds internal templating mechanism api changed in 8.2.0 -> polyfill
60
+ if (!template.process) {
61
+ module.exports._templateProcessor ??= require('@sap/cds/libx/_runtime/common/utils/templateProcessor')
62
+ template.process = (data, processFn) => {
63
+ const _data = Array.isArray(data) ? data : [data]
64
+ _data.forEach(row => module.exports._templateProcessor({ processFn, row, template }))
65
+ }
66
+ }
67
+ template.process(data, processFn)
61
68
 
62
69
  for (const each of Object.keys(accessLogs)) if (!accessLogs[each].attributes.length) delete accessLogs[each]
63
70
  if (!Object.keys(accessLogs).length) return
@@ -2,7 +2,6 @@ const cds = require('@sap/cds')
2
2
 
3
3
  // REVISIT: don't require internal stuff
4
4
  const getTemplate = require('@sap/cds/libx/_runtime/common/utils/template')
5
- const templateProcessor = require('@sap/cds/libx/_runtime/common/utils/templateProcessor')
6
5
 
7
6
  const {
8
7
  getMapKeyForCurrentRequest,
@@ -166,7 +165,14 @@ const _getDataModificationLogs = (req, tx, diff, beforeWrite) => {
166
165
 
167
166
  const modificationLogs = {}
168
167
  const processFn = _processorFnModification(modificationLogs, tx.model, req, beforeWrite)
169
- templateProcessor({ processFn, row: diff, template })
168
+ // cds internal templating mechanism api changed in 8.2.0 -> polyfill
169
+ if (!template.process) {
170
+ module.exports._templateProcessor ??= require('@sap/cds/libx/_runtime/common/utils/templateProcessor')
171
+ template.process = (data, processFn) => {
172
+ module.exports._templateProcessor({ processFn, row: data, template })
173
+ }
174
+ }
175
+ template.process(diff, processFn)
170
176
 
171
177
  return modificationLogs
172
178
  }
package/lib/utils.js CHANGED
@@ -1,3 +1,5 @@
1
+ const cds = require('@sap/cds')
2
+
1
3
  const WRITE = { CREATE: 1, UPDATE: 1, DELETE: 1 }
2
4
 
3
5
  const $hasPersonalData = Symbol('@cap-js/audit-logging:hasPersonalData')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/audit-logging",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
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)",
@@ -16,16 +16,16 @@
16
16
  "lint": "npx eslint .",
17
17
  "test": "npm run test-new-db && npm run test-old-db",
18
18
  "test-new-db": "CDS_ENV='better-sqlite' npx jest --silent",
19
- "test-old-db": "npx jest --silent"
19
+ "test-old-db": "CDS_ENV='legacy-sqlite' npx jest --silent"
20
20
  },
21
21
  "peerDependencies": {
22
- "@sap/cds": ">=7 || ^8.0.0-beta"
22
+ "@sap/cds": ">=7"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@cap-js/audit-logging": "file:.",
26
26
  "@cap-js/sqlite": "^1",
27
27
  "axios": "^1",
28
- "eslint": "^8",
28
+ "eslint": "^9",
29
29
  "express": "^4",
30
30
  "jest": "^29",
31
31
  "sqlite3": "^5.1.6"
@@ -5,6 +5,7 @@ module.exports = class AuditLog2Console extends AuditLogService {
5
5
  this.on('*', function (req) {
6
6
  const { event, data } = req
7
7
 
8
+ // eslint-disable-next-line no-console
8
9
  console.log(`[audit-log] - ${event}:`, data)
9
10
  })
10
11
 
package/srv/log2restv2.js CHANGED
@@ -154,12 +154,16 @@ async function _post(url, data, options) {
154
154
  const chunks = []
155
155
  res.on('data', chunk => chunks.push(chunk))
156
156
  res.on('end', () => {
157
+ const { statusCode, statusMessage } = res
157
158
  let body = Buffer.concat(chunks).toString()
158
159
  if (res.headers['content-type']?.match(/json/)) body = JSON.parse(body)
159
160
  if (res.statusCode >= 400) {
160
- const err = new Error(res.statusMessage)
161
- err.response = res
162
- err.body = body
161
+ // prettier-ignore
162
+ const err = new Error(`Request failed with${statusMessage ? `: ${statusCode} - ${statusMessage}` : ` status ${statusCode}`}`)
163
+ err.request = { method: options.method, url, headers: options.headers, body: data }
164
+ if (err.request.headers.authorization)
165
+ err.request.headers.authorization = err.request.headers.authorization.split(' ')[0] + ' ***'
166
+ err.response = { statusCode, statusMessage, headers: res.headers, body }
163
167
  reject(err)
164
168
  } else {
165
169
  resolve(body)