@things-factory/integration-notification 10.1.106 → 10.1.107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const typeorm_1 = require("typeorm");
|
|
4
|
-
const auth_base_1 = require("@things-factory/auth-base");
|
|
5
3
|
const integration_base_1 = require("@things-factory/integration-base");
|
|
6
4
|
const notification_1 = require("@things-factory/notification");
|
|
7
5
|
const shell_1 = require("@things-factory/shell");
|
|
@@ -10,15 +8,13 @@ async function Notification(step, { logger, domain, user, data, variables }) {
|
|
|
10
8
|
if (!receivers || !title || !body) {
|
|
11
9
|
throw Error(`receivers, title and body should be defined: receivers - '${receivers}', title - '${title}', body - '${body}'`);
|
|
12
10
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
receivers =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return receiver && receiver.id;
|
|
21
|
-
}))).filter(receiver => !!receiver);
|
|
11
|
+
/* members of this domain only - an e-mail of another tenant reaches nobody */
|
|
12
|
+
const named = (0, notification_1.splitEmails)(receivers);
|
|
13
|
+
receivers = await (0, notification_1.domainMemberIdsByEmail)(domain, named);
|
|
14
|
+
if (receivers.length === 0) {
|
|
15
|
+
/* an empty list would publish to the whole domain */
|
|
16
|
+
throw Error(`none of the receivers is a member of this domain: '${named.join(', ')}'`);
|
|
17
|
+
}
|
|
22
18
|
try {
|
|
23
19
|
body = (0, integration_base_1.evaluateTemplate)(body, { domain, user, data, variables, console });
|
|
24
20
|
}
|
|
@@ -29,7 +25,6 @@ async function Notification(step, { logger, domain, user, data, variables }) {
|
|
|
29
25
|
if (push) {
|
|
30
26
|
await (0, notification_1.notify)({
|
|
31
27
|
receivers,
|
|
32
|
-
privileges: undefined,
|
|
33
28
|
tokens: undefined,
|
|
34
29
|
topic: undefined,
|
|
35
30
|
title,
|
|
@@ -46,6 +41,7 @@ async function Notification(step, { logger, domain, user, data, variables }) {
|
|
|
46
41
|
await shell_1.pubsub.publish('notification', {
|
|
47
42
|
notification: {
|
|
48
43
|
domain,
|
|
44
|
+
receivers,
|
|
49
45
|
type,
|
|
50
46
|
subject: type || 'info',
|
|
51
47
|
title,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification.js","sourceRoot":"","sources":["../../../server/engine/task/notification.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"notification.js","sourceRoot":"","sources":["../../../server/engine/task/notification.ts"],"names":[],"mappings":";;AAAA,uEAAiF;AACjF,+DAA0F;AAC1F,iDAA8C;AAE9C,KAAK,UAAU,YAAY,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE;IACzE,IAAI,EACF,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,GAAG,KAAK,EAAE,EAC1E,GAAG,IAAI,CAAA;IAER,IAAI,CAAC,SAAS,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;QAClC,MAAM,KAAK,CACT,6DAA6D,SAAS,eAAe,KAAK,cAAc,IAAI,GAAG,CAChH,CAAA;IACH,CAAC;IAED,8EAA8E;IAC9E,MAAM,KAAK,GAAG,IAAA,0BAAW,EAAC,SAAS,CAAC,CAAA;IACpC,SAAS,GAAG,MAAM,IAAA,qCAAsB,EAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IACvD,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,qDAAqD;QACrD,MAAM,KAAK,CAAC,sDAAsD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACxF,CAAC;IAED,IAAI,CAAC;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AK,EAAE,OAAO;KACf;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,OAAO;KACf;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,KAAK;QACX,KAAK,EAAE,KAAK;KACb;IACD;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,cAAc;QACrB,QAAQ,EAAE;YACR,QAAQ,EAAE,MAAM;YAChB,eAAe,EAAE,IAAI;SACtB;QACD,MAAM,EAAE;YACN,IAAI,EAAE,GAAG;SACV;KACF;IACD;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,mBAAmB;KAC3B;CACF,CAAA;AAED,YAAY,CAAC,aAAa,GAAG,IAAI,CAAA;AACjC,YAAY,CAAC,IAAI,GAAG,+BAA+B,CAAA;AAEnD,+BAAY,CAAC,mBAAmB,CAAC,cAAc,EAAE,YAAY,CAAC,CAAA","sourcesContent":["import { TaskRegistry, evaluateTemplate } from '@things-factory/integration-base'\nimport { domainMemberIdsByEmail, notify, splitEmails } from '@things-factory/notification'\nimport { pubsub } from '@things-factory/shell'\n\nasync function Notification(step, { logger, domain, user, data, variables }) {\n var {\n params: { level: type, receivers, title, image, url, body, push = false }\n } = step\n\n if (!receivers || !title || !body) {\n throw Error(\n `receivers, title and body should be defined: receivers - '${receivers}', title - '${title}', body - '${body}'`\n )\n }\n\n /* members of this domain only - an e-mail of another tenant reaches nobody */\n const named = splitEmails(receivers)\n receivers = await domainMemberIdsByEmail(domain, named)\n if (receivers.length === 0) {\n /* an empty list would publish to the whole domain */\n throw Error(`none of the receivers is a member of this domain: '${named.join(', ')}'`)\n }\n\n try {\n body = evaluateTemplate(body, { domain, user, data, variables, console })\n } catch (err) {\n throw new Error(`Failed to evaluate body: ${err.message}`)\n }\n const timestamp = String(Date.now())\n\n if (push) {\n await notify({\n receivers,\n tokens: undefined,\n topic: undefined,\n title,\n body,\n data: {\n url,\n timestamp\n },\n image,\n actions: undefined\n })\n } else {\n await pubsub.publish('notification', {\n notification: {\n domain,\n receivers,\n type,\n subject: type || 'info',\n title,\n body,\n image,\n url,\n timestamp\n }\n })\n }\n\n return {\n data: true\n }\n}\n\nNotification.parameterSpec = [\n {\n type: 'select',\n name: 'level',\n label: 'level',\n property: {\n options: ['', 'info', 'warn', 'error']\n }\n },\n {\n type: 'string',\n name: 'receivers',\n label: 'receivers'\n },\n {\n type: 'string',\n name: 'title',\n label: 'title'\n },\n {\n type: 'string',\n name: 'image',\n label: 'image'\n },\n {\n type: 'string',\n name: 'url',\n label: 'url'\n },\n {\n type: 'textarea',\n name: 'body',\n label: 'message-body',\n property: {\n language: 'text',\n showLineNumbers: true\n },\n styles: {\n flex: '1'\n }\n },\n {\n type: 'checkbox',\n name: 'push',\n label: 'push-notification'\n }\n]\n\nNotification.connectorFree = true\nNotification.help = 'integration/task/notification'\n\nTaskRegistry.registerTaskHandler('notification', Notification)\n"]}
|