@cap-js-community/event-queue
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -6,7 +6,7 @@ "use strict"; | ||
const eventQueue = require("./src"); | ||
const COMPONENT_NAME = "/eventQueue/plugin"; | ||
if (cds.env.eventQueue && cds.env.eventQueue.plugin) { | ||
cds.on("serving", async () => { | ||
await eventQueue.initialize(); | ||
}); | ||
const eventQueueConfig = cds.env.eventQueue; | ||
if (!(cds.build.register || (!eventQueueConfig?.config && !eventQueueConfig?.configFilePath))) { | ||
eventQueue.initialize().catch((err) => cds.log(COMPONENT_NAME).error(err)); | ||
} |
{ | ||
"name": "@cap-js-community/event-queue", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "An event queue that enables secure transactional processing of asynchronous events, featuring instant event processing with Redis Pub/Sub and load distribution across all application instances.", | ||
@@ -50,7 +50,7 @@ "main": "src/index.js", | ||
"devDependencies": { | ||
"@sap/cds": "7.5.2", | ||
"@sap/cds-dk": "7.5.1", | ||
"@sap/cds": "^7.5.3", | ||
"@sap/cds-dk": "^7.5.1", | ||
"eslint": "8.56.0", | ||
"eslint-config-prettier": "9.1.0", | ||
"eslint-plugin-jest": "27.6.2", | ||
"eslint-plugin-jest": "27.6.3", | ||
"eslint-plugin-node": "11.1.0", | ||
@@ -57,0 +57,0 @@ "express": "4.18.2", |
@@ -58,2 +58,3 @@ "use strict"; | ||
#useAsCAPOutbox; | ||
#userId; | ||
static #instance; | ||
@@ -457,2 +458,10 @@ constructor() { | ||
set userId(value) { | ||
this.#userId = value; | ||
} | ||
get userId() { | ||
return this.#userId; | ||
} | ||
get isMultiTenancy() { | ||
@@ -459,0 +468,0 @@ return !!cds.requires.multitenancy; |
@@ -5,3 +5,2 @@ "use strict"; | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
@@ -41,2 +40,3 @@ const cds = require("@sap/cds"); | ||
["useAsCAPOutbox", false], | ||
["userId", null], | ||
]; | ||
@@ -57,2 +57,3 @@ | ||
useAsCAPOutbox, | ||
userId, | ||
} = {}) => { | ||
@@ -80,3 +81,4 @@ // TODO: initialize check: | ||
thresholdLoggingEventProcessing, | ||
useAsCAPOutbox | ||
useAsCAPOutbox, | ||
userId | ||
); | ||
@@ -88,8 +90,10 @@ | ||
const dbService = await cds.connect.to("db"); | ||
await (cds.model ? Promise.resolve() : new Promise((resolve) => cds.on("serving", resolve))); | ||
!config.skipCsnCheck && (await csnCheck()); | ||
if (config.processEventsAfterPublish) { | ||
dbHandler.registerEventQueueDbHandler(dbService); | ||
cds.on("connect", (service) => { | ||
if (service.name === "db ") { | ||
dbHandler.registerEventQueueDbHandler(service); | ||
} | ||
}); | ||
} | ||
!config.skipCsnCheck && (await csnCheck()); | ||
@@ -158,22 +162,26 @@ monkeyPatchCAPOutbox(); | ||
const csnCheck = async () => { | ||
const eventCsn = cds.model.definitions[config.tableNameEventQueue]; | ||
if (!eventCsn) { | ||
throw EventQueueError.missingTableInCsn(config.tableNameEventQueue); | ||
} | ||
cds.on("loaded", async (csn) => { | ||
if (csn.namespace === "cds.xt") { | ||
return; | ||
} | ||
const eventCsn = csn.definitions[config.tableNameEventQueue]; | ||
if (!eventCsn) { | ||
throw EventQueueError.missingTableInCsn(config.tableNameEventQueue); | ||
} | ||
const lockCsn = cds.model.definitions[config.tableNameEventLock]; | ||
if (!lockCsn) { | ||
throw EventQueueError.missingTableInCsn(config.tableNameEventLock); | ||
} | ||
const lockCsn = csn.definitions[config.tableNameEventLock]; | ||
if (!lockCsn) { | ||
throw EventQueueError.missingTableInCsn(config.tableNameEventLock); | ||
} | ||
if (config.tableNameEventQueue === BASE_TABLES.EVENT && config.tableNameEventLock === BASE_TABLES.LOCK) { | ||
return; // no need to check base tables | ||
} | ||
if (config.tableNameEventQueue === BASE_TABLES.EVENT && config.tableNameEventLock === BASE_TABLES.LOCK) { | ||
return; // no need to check base tables | ||
} | ||
const csn = await cds.load(path.join(__dirname, "..", "db")); | ||
const baseEvent = csn.definitions["sap.eventqueue.Event"]; | ||
const baseLock = csn.definitions["sap.eventqueue.Lock"]; | ||
const baseEvent = csn.definitions["sap.eventqueue.Event"]; | ||
const baseLock = csn.definitions["sap.eventqueue.Lock"]; | ||
checkCustomTable(baseEvent, eventCsn); | ||
checkCustomTable(baseLock, lockCsn); | ||
checkCustomTable(baseEvent, eventCsn); | ||
checkCustomTable(baseLock, lockCsn); | ||
}); | ||
}; | ||
@@ -180,0 +188,0 @@ |
@@ -41,4 +41,6 @@ "use strict"; | ||
const subdomain = await getSubdomainForTenantId(tenantId); | ||
const user = new cds.User.Privileged(config.userId); | ||
const tenantContext = { | ||
tenant: tenantId, | ||
user, | ||
// NOTE: we need this because of logging otherwise logs would not contain the subdomain | ||
@@ -94,5 +96,7 @@ http: { req: { authInfo: { getSubdomain: () => subdomain } } }, | ||
const subdomain = await getSubdomainForTenantId(tenantId); | ||
const user = new cds.User.Privileged(config.userId); | ||
context = { | ||
// NOTE: we need this because of logging otherwise logs would not contain the subdomain | ||
tenant: tenantId, | ||
user, | ||
http: { req: { authInfo: { getSubdomain: () => subdomain } } }, | ||
@@ -99,0 +103,0 @@ }; |
@@ -5,2 +5,4 @@ "use strict"; | ||
const cds = require("@sap/cds"); | ||
const eventQueueConfig = require("./config"); | ||
@@ -15,2 +17,3 @@ const { processEventQueue } = require("./processEventQueue"); | ||
const { hashStringTo32Bit } = require("./shared/common"); | ||
const config = require("./config"); | ||
@@ -112,4 +115,6 @@ const COMPONENT_NAME = "/eventQueue/runner"; | ||
const subdomain = await getSubdomainForTenantId(tenantId); | ||
const user = new cds.User.Privileged(config.userId); | ||
const tenantContext = { | ||
tenant: tenantId, | ||
user, | ||
// NOTE: we need this because of logging otherwise logs would not contain the subdomain | ||
@@ -146,4 +151,6 @@ http: { req: { authInfo: { getSubdomain: () => subdomain } } }, | ||
const subdomain = await getSubdomainForTenantId(tenantId); | ||
const user = new cds.User.Privileged(config.userId); | ||
const tenantContext = { | ||
tenant: tenantId, | ||
user, | ||
// NOTE: we need this because of logging otherwise logs would not contain the subdomain | ||
@@ -150,0 +157,0 @@ http: { req: { authInfo: { getSubdomain: () => subdomain } } }, |
@@ -27,2 +27,3 @@ "use strict"; | ||
try { | ||
const user = new cds.User.Privileged(config.userId); | ||
if (cds.db.kind === "hana") { | ||
@@ -34,3 +35,3 @@ await cds.tx( | ||
locale: context.locale, | ||
user: context.user, | ||
user, | ||
headers: context.headers, | ||
@@ -53,3 +54,3 @@ http: context.http, | ||
locale: context.locale, | ||
user: context.user, | ||
user, | ||
headers: context.headers, | ||
@@ -61,2 +62,3 @@ http: context.http, | ||
} else { | ||
contextTx.context.user = user; | ||
await fn(contextTx, ...parameters); | ||
@@ -63,0 +65,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
150800
3656