Skip to content

Commit b09953b

Browse files
authored
Add authInfo to align with CDS (#378)
* add authInfo to align with CDS * upgrade cds * wip * wip
1 parent 8d141ae commit b09953b

File tree

17 files changed

+394
-245
lines changed

17 files changed

+394
-245
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## v1.11.0 - 2025-07-09
9+
10+
### Added
11+
12+
- Added `authInfo` to cds.User as CDS 9.3 deprecated `tokenInfo`.
13+
814
## v1.10.10 - 2025-07-09
915

1016
### Fixed

package-lock.json

Lines changed: 156 additions & 159 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@
4848
},
4949
"dependencies": {
5050
"@sap/xssec": "^4.6.0",
51-
"cron-parser": "^5.2.0",
51+
"cron-parser": "^5.3.1",
5252
"redis": "^4.7.0",
5353
"verror": "^1.10.1",
5454
"yaml": "^2.7.1"
5555
},
5656
"devDependencies": {
5757
"@cap-js/cds-test": "^0.4.0",
58-
"@cap-js/hana": "^2.1.0",
58+
"@cap-js/hana": "^2.2.0",
5959
"@cap-js/sqlite": "^2.0.1",
60-
"@sap/cds": "^9.1.0",
61-
"@sap/cds-dk": "^9.1.0",
60+
"@sap/cds": "^9.3.1",
61+
"@sap/cds-dk": "^9.3.1",
6262
"eslint": "^8.57.0",
6363
"eslint-config-prettier": "^9.1.0",
6464
"eslint-plugin-jest": "^28.6.0",

src/config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class Config {
114114
#redisNamespace;
115115
#publishEventBlockList;
116116
#crashOnRedisUnavailable;
117-
#tenantIdFilterTokenInfoCb;
117+
#tenantIdFilterAuthContextCb;
118118
#tenantIdFilterEventProcessingCb;
119119
#configEvents;
120120
#configPeriodicEvents;
@@ -770,12 +770,12 @@ class Config {
770770
this.#crashOnRedisUnavailable = value;
771771
}
772772

773-
get tenantIdFilterTokenInfo() {
774-
return this.#tenantIdFilterTokenInfoCb;
773+
get tenantIdFilterAuthContext() {
774+
return this.#tenantIdFilterAuthContextCb;
775775
}
776776

777-
set tenantIdFilterTokenInfo(value) {
778-
this.#tenantIdFilterTokenInfoCb = value;
777+
set tenantIdFilterAuthContext(value) {
778+
this.#tenantIdFilterAuthContextCb = value;
779779
}
780780

781781
get tenantIdFilterEventProcessing() {

src/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ module.exports = {
2222
},
2323
TenantIdCheckTypes: {
2424
eventProcessing: "eventProcessing",
25-
getTokenInfo: "getTokenInfo",
25+
getAuthContext: "getAuthContext",
2626
},
2727
};

src/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export declare type EventProcessingStatusType = (typeof EventProcessingStatus)[E
1414

1515
export declare const TenantIdCheckTypes: {
1616
eventProcessing: "eventProcessing";
17-
getTokenInfo: "getTokenInfo";
17+
getAuthContext: "getAuthContext";
1818
};
1919

2020
export declare const TransactionMode: {
@@ -215,8 +215,8 @@ declare class Config {
215215
get publishEventBlockList(): any;
216216
set crashOnRedisUnavailable(value: any);
217217
get crashOnRedisUnavailable(): any;
218-
set tenantIdFilterTokenInfo(value: any);
219-
get tenantIdFilterTokenInfo(): any;
218+
set tenantIdFilterAuthContext(value: any);
219+
get tenantIdFilterAuthContext(): any;
220220
set tenantIdFilterEventProcessing(value: any);
221221
get tenantIdFilterEventProcessing(): any;
222222
set runInterval(value: any);

src/outbox/EventQueueGenericOutboxHandler.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,11 @@ class EventQueueGenericOutboxHandler extends EventQueueBaseClass {
327327
}
328328

329329
async #setContextUser(context, userId, reg) {
330+
const authInfo = await common.getAuthContext(context.tenant);
330331
context.user = new cds.User.Privileged({
331332
id: userId,
332-
tokenInfo: await common.getTokenInfo(this.baseContext.tenant),
333+
authInfo,
334+
tokenInfo: authInfo?.token,
333335
});
334336
if (reg) {
335337
reg.user = context.user;

src/redis/redisPub.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ const _processLocalWithoutRedis = async (tenantId, events) => {
119119
let context = {};
120120
if (tenantId) {
121121
const user = await cds.tx({ tenant: tenantId }, async () => {
122-
return new cds.User.Privileged({ id: config.userId, tokenInfo: await common.getTokenInfo(tenantId) });
122+
const authInfo = await common.getAuthContext(tenantId);
123+
return new cds.User.Privileged({ id: config.userId, authInfo, tokenInfo: authInfo.token });
123124
});
124125
context = {
125126
tenant: tenantId,

src/redis/redisSub.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ const _messageHandlerProcessEvents = async (messageData) => {
7878
}
7979

8080
const user = await cds.tx({ tenant: tenantId }, async () => {
81-
return new cds.User.Privileged({ id: config.userId, tokenInfo: await common.getTokenInfo(tenantId) });
81+
const authInfo = await common.getAuthContext(tenantId);
82+
return new cds.User.Privileged({ id: config.userId, authInfo, tokenInfo: authInfo?.token });
8283
});
8384
const tenantContext = {
8485
tenant: tenantId,

src/runner/runner.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,11 @@ const _executeEventsAllTenantsRedis = async (tenantIds) => {
149149
tx.context,
150150
"get-openEvents-and-publish",
151151
async () => {
152+
const authInfo = await common.getAuthContext(tenantId);
152153
tx.context.user = new cds.User.Privileged({
153154
id: config.userId,
154-
tokenInfo: await common.getTokenInfo(tenantId),
155+
authInfo,
156+
tokenInfo: authInfo?.token,
155157
});
156158
const entries = await openEvents.getOpenQueueEntries(tx, false);
157159
logger.info("broadcasting events for run", {
@@ -187,10 +189,11 @@ const _executeEventsAllTenants = async (tenantIds, runId) => {
187189
try {
188190
events = await trace(
189191
{ id, tenant: tenantId },
190-
"fetch-openEvents-and-tokenInfo",
192+
"fetch-openEvents-and-authInfo",
191193
async () => {
192194
const user = await cds.tx({ tenant: tenantId }, async () => {
193-
return new cds.User.Privileged({ id: config.userId, tokenInfo: await common.getTokenInfo(tenantId) });
195+
const authInfo = await common.getAuthContext(tenantId);
196+
return new cds.User.Privileged({ id: config.userId, authInfo, tokenInfo: authInfo?.token });
194197
});
195198
tenantContext = {
196199
tenant: tenantId,
@@ -258,7 +261,8 @@ const _executePeriodicEventsAllTenants = async (tenantIds) => {
258261
for (const tenantId of tenantIds) {
259262
try {
260263
const user = await cds.tx({ tenant: tenantId }, async () => {
261-
return new cds.User.Privileged({ id: config.userId, tokenInfo: await common.getTokenInfo(tenantId) });
264+
const authInfo = await common.getAuthContext(tenantId);
265+
return new cds.User.Privileged({ id: config.userId, authInfo, tokenInfo: authInfo?.token });
262266
});
263267
const tenantContext = {
264268
tenant: tenantId,
@@ -289,7 +293,7 @@ const _singleTenantDb = async () => {
289293
const id = cds.utils.uuid();
290294
const events = await trace(
291295
{ id },
292-
"fetch-openEvents-and-tokenInfo",
296+
"fetch-openEvents-and-authInfo",
293297
async () => {
294298
return await cds.tx({}, async (tx) => {
295299
return await openEvents.getOpenQueueEntries(tx);
@@ -530,7 +534,7 @@ const _checkPeriodicEventsSingleTenant = async (context) => {
530534
try {
531535
logger.info("executing updating periodic events", {
532536
tenantId: context.tenant,
533-
subdomain: context.user?.tokenInfo?.extAttributes?.zdn,
537+
subdomain: context.user?.authInfo?.getSubdomain?.(),
534538
});
535539
await periodicEvents.checkAndInsertPeriodicEvents(context);
536540
} catch (err) {

0 commit comments

Comments
 (0)