@sap/cds-messaging
Advanced tools
Comparing version 1.2.1 to 1.5.0
@@ -9,2 +9,20 @@ # Changelog | ||
## Version 1.5.0 - 2019-12-10 | ||
### Fixed | ||
- Receiving chunks can be an array with more than one item | ||
## Version 1.4.0 - 2019-11-19 | ||
### Removed | ||
- The `namespace` property of a services does not need to be set anymore | ||
## Version 1.3.0 - 2019-10-29 | ||
### Removed | ||
- `npm-shrinkwrap.json` | ||
## Version 1.2.1 - 2019-10-16 | ||
@@ -11,0 +29,0 @@ |
@@ -191,3 +191,8 @@ const FeatureNotSupportedError = require('../utils/FeatureNotSupported') | ||
if (options.kind === 'enterprise-messaging') { | ||
if (!connectionOptions || !connectionOptions.credentials.management || !connectionOptions.credentials.messaging) { | ||
if ( | ||
!connectionOptions || | ||
!connectionOptions.credentials || | ||
!connectionOptions.credentials.management || | ||
!connectionOptions.credentials.messaging | ||
) { | ||
throw new Error('No messaging credentials found: You need to bind your app to a message broker.') | ||
@@ -197,2 +202,3 @@ } | ||
const enterpriseMessagingOptions = { | ||
namespace: connectionOptions.credentials.namespace, | ||
amqp: connectionOptions.credentials.messaging.filter(entry => entry.protocol.includes('amqp10ws'))[0], | ||
@@ -199,0 +205,0 @@ management: connectionOptions.credentials.management[0] |
@@ -37,3 +37,3 @@ const { resolve } = require('../utils/thenable') | ||
try { | ||
payload = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(raw.payload.chunks[0]))) | ||
payload = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(Buffer.concat(raw.payload.chunks)))) | ||
} catch (err) { | ||
@@ -40,0 +40,0 @@ return raw.done() |
@@ -28,3 +28,3 @@ const dataHandler = require('./dataHandler') | ||
function _getSource ({ queueEnd, appName, appID, ownNamespace }) { | ||
function _deriveSource ({ queueEnd, appName, appID, ownNamespace }) { | ||
const shrunkAppID = appID.substring(0, 4) | ||
@@ -57,6 +57,3 @@ return ownNamespace | ||
msgOptions.namespace || | ||
(msgOptions.credentials && msgOptions.credentials.namespace) || | ||
'CAP' | ||
// TODO: Get the own namespace from API (not yet developed) | ||
const ownNamespace = namespaceOfService | ||
(msgOptions.credentials && msgOptions.credentials.namespace) | ||
const vcapApplication = process.env.VCAP_APPLICATION && JSON.parse(process.env.VCAP_APPLICATION) | ||
@@ -66,7 +63,5 @@ const appName = (vcapApplication && vcapApplication.application_name.replace(INVALID_SYMBOLS, '')) || 'unknownApp' | ||
const shrunkService = _shrinkService(service) | ||
const prefix = (msgOptions.credentials && msgOptions.credentials.prefix) || `${namespaceOfService}/${shrunkService}` | ||
const prefix = msgOptions.credentials && msgOptions.credentials.prefix | ||
const queueEnd = (msgOptions.credentials && msgOptions.credentials.prefix) || shrunkService | ||
const source = | ||
(msgOptions.credentials && msgOptions.credentials.queue && `queue:${msgOptions.credentials.queue}`) || | ||
_getSource({ queueEnd, appName, appID, ownNamespace }) | ||
const customSource = msgOptions.credentials && msgOptions.credentials.queue && `queue:${msgOptions.credentials.queue}` | ||
@@ -79,3 +74,4 @@ const options = { | ||
shrunkService, | ||
source, | ||
customSource, | ||
queueEnd, | ||
namespaceOfService, | ||
@@ -100,2 +96,6 @@ prefix, | ||
function _getPrefixForTopic (options, client) { | ||
return options.prefix || `${options.namespaceOfService || client._options.namespace}/${options.shrunkService}` | ||
} | ||
function _addSubscription (onHandler, options) { | ||
@@ -105,4 +105,5 @@ _pendingOperations(this) | ||
this.acquire({}, 'messaging').then(client => { | ||
const queueName = _getQueueName(options.source) | ||
const topic = _getTopicFromOnHandler(onHandler, options.prefix) | ||
const source = _getSource(client, options) | ||
const queueName = _getQueueNameFromSource(source) | ||
const topic = _getTopicFromOnHandler(onHandler, _getPrefixForTopic(options, client)) | ||
if (client._options.kind === 'enterprise-messaging') { | ||
@@ -127,6 +128,16 @@ _pendingOperations(client) | ||
function _getSource (client, options) { | ||
const ownNamespace = client._options.namespace | ||
return ( | ||
options.customSource || | ||
_deriveSource({ queueEnd: options.queueEnd, appName: options.appName, appID: options.appID, ownNamespace }) | ||
) | ||
} | ||
function _createQueueAndAddSubscription (normalizedHandler, options) { | ||
return this.acquire({}, 'messaging').then(client => { | ||
const queueName = _getQueueName(options.source) | ||
const topic = _getTopicFromOnHandler(normalizedHandler, options.prefix) | ||
const source = _getSource(client, options) | ||
const queueName = _getQueueNameFromSource(source) | ||
const prefixForTopic = _getPrefixForTopic(options, client) | ||
const topic = _getTopicFromOnHandler(normalizedHandler, prefixForTopic) | ||
if (client._options.kind === 'enterprise-messaging') { | ||
@@ -142,3 +153,3 @@ client._pendingOperations = _pendingOperations(client) | ||
} | ||
client.on(dataHandler(options.onHandlers, options.errHandlers, options.prefix), null, options.source) | ||
client.on(dataHandler(options.onHandlers, options.errHandlers, prefixForTopic), null, source) | ||
this.release(client) | ||
@@ -178,3 +189,3 @@ }) | ||
function _getQueueName (source) { | ||
function _getQueueNameFromSource (source) { | ||
return source.replace('queue:', '') | ||
@@ -219,3 +230,7 @@ } | ||
try { | ||
this.deleteQueue(_getQueueName(this.messagingOptions.source)) | ||
const client = await this.acquire({}, 'messaging') | ||
const source = _getSource(client, this.messagingOptions) | ||
client.disconnect() | ||
this.release(client) | ||
await this.deleteQueue(_getQueueNameFromSource(source)) | ||
} catch (err) {} | ||
@@ -232,5 +247,4 @@ } | ||
this.acquire({}, 'messaging').then(client => { | ||
const namespace = options.namespaceOfService | ||
const namespace = options.namespaceOfService || client._options.namespace | ||
const shrunkService = options.shrunkService | ||
const [target, msg] = _getTargetAndMessage(payload, namespace, shrunkService, entity, event, header) | ||
@@ -268,3 +282,3 @@ client.emit(msg, target) | ||
return new Promise((resolve, reject) => { | ||
const { | ||
let { | ||
oa2: { clientid, clientsecret, tokenendpoint } | ||
@@ -271,0 +285,0 @@ } = management |
@@ -1,1 +0,1 @@ | ||
{"bundleDependencies":false,"dependencies":{},"deprecated":false,"description":"","engines":{"node":">= 8.9.0"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"{lib,test}/**/*.js":["prettier-standard","standard --fix","git add"]},"main":"lib/index.js","name":"@sap/cds-messaging","version":"1.2.1","license":"SEE LICENSE IN developer-license-3.1.txt"} | ||
{"bundleDependencies":false,"dependencies":{},"deprecated":false,"description":"","engines":{"node":">= 8.9.0"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"{lib,test}/**/*.js":["prettier-standard","standard --fix","git add"]},"main":"lib/index.js","name":"@sap/cds-messaging","version":"1.5.0","license":"SEE LICENSE IN developer-license-3.1.txt"} |
Sorry, the diff of this file is not supported yet
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
53704
1026