diff --git a/lib/utils.js b/lib/utils.js index 8390937..a54103f 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -20,6 +20,10 @@ const messages = { EMPTY_OBJECT_FOR_NOTIFY: "Empty object is passed a single parameter to notify function.", NO_OBJECT_FOR_NOTIFY: "An object must be passed to notify function." }; +//See: https://help.sap.com/docs/build-work-zone-standard-edition/sap-build-work-zone-standard-edition/developing-cloud-foundry-applications-with-notifications +const supportedANSLanguages = {AF: 1, AR: 1, BG: 1, CA: 1, ZH: 1, ZF: 1, HR: 1, CS: 1, DA: 1, NL: 1, EN: 1, ET: 1, FI: 1, FR: 1, KM: 1, DE: 1, EL: 1, HE: 1, HU: 1, IS: 1, ID: 1, IT: 1, HI: 1, JA: 1, KO: 1, LV: 1, LT: 1, MS: 1, NO: 1, NB: 1, PL: 1, PT: 1, Z1: 1, RO: 1, RU: 1, SR: 1, SH: 1, SK: 1, VI: 1, SL: 1, ES: 1, SV: 1, TH: 1, TR: 1, UK: 1, IW: 1, IN: 1, ZH_HANS: 1, ZH_HANT: 1, ZH_CN: 1, ZH_TW: 1} + +const sanitizedLocale = () => cds.context?.locale && supportedANSLanguages[cds.context.locale] != undefined ? cds.context.locale : 'en' function validateNotificationTypes(notificationTypes) { for(let notificationType of notificationTypes){ @@ -141,14 +145,14 @@ function buildDefaultNotification( const properties = [ { Key: "title", - Language: "en", + Language: sanitizedLocale(), Value: title, Type: "String", IsSensitive: false, }, { Key: "description", - Language: "en", + Language: sanitizedLocale(), Value: description, Type: "String", IsSensitive: false, @@ -172,7 +176,7 @@ function buildCustomNotification(_) { Recipients: _.Recipients || _.recipients?.map(id => ({ RecipientId: id })), Priority: _.Priority || _.priority || "NEUTRAL", Properties: _.Properties || Object.entries(_.data).map(([k,v]) => ({ - Key:k, Value:v, Language: "en", Type: typeof v, // IsSensitive: false + Key:k, Value:v, Language: sanitizedLocale(), Type: typeof v, IsSensitive: true //Is sensitive so all data is encrypted and stored in DB in ANS })), // Low-level API properties diff --git a/package-lock.json b/package-lock.json index 4c833f9..3f18a66 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@cap-js/notifications", - "version": "0.1.0", + "version": "0.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@cap-js/notifications", - "version": "0.1.0", + "version": "0.2.0", "license": "SEE LICENSE IN LICENSE", "dependencies": { "@sap-cloud-sdk/connectivity": "^3.13.0",