Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for cds 7.5.0 #77

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Version 0.6.0 - tbd

### Added

- Support for @sap/cds^7.5

## Version 0.5.2 - 2023-12-08

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cap-js/audit-logging",
"version": "0.5.2",
"version": "0.6.0",
"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.",
"repository": "cap-js/audit-logging",
"author": "SAP SE (https://www.sap.com)",
Expand Down
7 changes: 3 additions & 4 deletions srv/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const Base = cds.outboxed ? cds.Service : require('@sap/cds/libx/_runtime/messag

module.exports = class AuditLogService extends Base {
async init() {
const outboxed = this.immediate instanceof cds.Service

// add common audit log entry fields
this.before('*', req => {
const { tenant, user, timestamp } = cds.context
Expand All @@ -22,8 +20,9 @@ module.exports = class AuditLogService extends Base {
this.log = this.emit
// NOTE: logSync is not a public API!
this.logSync = (...args) => {
if (outboxed) return this.immediate.send(...args)
return this.send(...args)
if (cds.unboxed) return cds.unboxed(this).send(...args) //> cds >= 7.5
if (this.immediate instanceof cds.Service) return this.immediate.send(...args) //> cds ~ 7.4
return this.send(...args) //> cds <= 7.3
}
}
}
5 changes: 2 additions & 3 deletions test/api/srv/api-service.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
module.exports = async function () {
const audit = await cds.connect.to('audit-log')
const outboxed = audit.immediate instanceof cds.Service

this.on('testEmit', async function () {
await audit.emit('foo', { bar: 'baz' })
})

this.on('testSend', async function () {
if (outboxed) await audit.immediate.send('foo', { bar: 'baz' })
else await audit.send('foo', { bar: 'baz' })
// only works with cds^7.5, but we don't execute the tests with prior cds versions
await cds.unboxed(audit).send('foo', { bar: 'baz' })
})

this.on('testLog', async function () {
Expand Down
Loading