@things-factory/notification 6.1.195 → 6.2.0
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.
- package/dist-server/middlewares/notification-middleware.js +3 -1
- package/dist-server/middlewares/notification-middleware.js.map +1 -1
- package/dist-server/routes.js +8 -1
- package/dist-server/routes.js.map +1 -1
- package/dist-server/service/notification/notification-subscription.js +1 -1
- package/dist-server/service/notification/notification-subscription.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/server/middlewares/notification-middleware.ts +3 -0
- package/server/routes.ts +8 -1
- package/server/service/notification/notification-subscription.ts +1 -1
|
@@ -6,7 +6,7 @@ const env_1 = require("@things-factory/env");
|
|
|
6
6
|
const fcm_1 = require("../controllers/fcm");
|
|
7
7
|
const debug = require('debug')('things-factory:notification:notification-middleware');
|
|
8
8
|
function notifier(context) {
|
|
9
|
-
return async function ({ receivers, privileges, tokens, topic, subject = 'info', title, body, image, url, actions, timestamp = Date.now(), mode = 'background' }) {
|
|
9
|
+
return async function ({ receivers, privileges, tokens, topic, type, subject = 'info', title, body, image, url, actions, timestamp = Date.now(), mode = 'background' }) {
|
|
10
10
|
const { domain, user } = context.state;
|
|
11
11
|
try {
|
|
12
12
|
if (mode === 'background') {
|
|
@@ -19,6 +19,7 @@ function notifier(context) {
|
|
|
19
19
|
title,
|
|
20
20
|
body,
|
|
21
21
|
data: {
|
|
22
|
+
type,
|
|
22
23
|
url,
|
|
23
24
|
timestamp: String(timestamp)
|
|
24
25
|
},
|
|
@@ -33,6 +34,7 @@ function notifier(context) {
|
|
|
33
34
|
notification: {
|
|
34
35
|
domain,
|
|
35
36
|
subject,
|
|
37
|
+
type,
|
|
36
38
|
title,
|
|
37
39
|
body,
|
|
38
40
|
image,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-middleware.js","sourceRoot":"","sources":["../../server/middlewares/notification-middleware.ts"],"names":[],"mappings":";;;AA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,OAAO,CAAC,CAAA;KACzC;IAED,MAAM,IAAI,EAAE,CAAA;AACd,CAAC;AAND,wDAMC","sourcesContent":["import { pubsub } from '@things-factory/shell'\nimport { logger } from '@things-factory/env'\n\nimport { notify } from '../controllers/fcm'\n\nconst debug = require('debug')('things-factory:notification:notification-middleware')\n\nfunction notifier(context) {\n return async function ({\n receivers,\n privileges,\n tokens,\n topic,\n subject = 'info',\n title,\n body,\n image,\n url,\n actions,\n timestamp = Date.now(),\n mode = 'background'\n }) {\n const { domain, user } = context.state\n\n try {\n if (mode === 'background') {\n /* for send webpush notification message */\n\n await notify({\n receivers,\n privileges,\n tokens,\n topic,\n title,\n body,\n data: {\n url,\n timestamp: String(timestamp)\n },\n image,\n actions\n })\n } else {\n /* for send publish notification to clients */\n // TODO CONFIRM data format\n await pubsub.publish('notification', {\n notification: {\n domain,\n subject,\n title,\n body,\n image,\n url,\n timestamp\n }\n })\n }\n } catch (err) {\n logger.error(err)\n }\n }\n}\n\nexport async function notificationMiddleware(context: any, next: any) {\n if (!context.state.notify) {\n context.state.notify = notifier(context)\n }\n\n await next()\n}\n"]}
|
|
1
|
+
{"version":3,"file":"notification-middleware.js","sourceRoot":"","sources":["../../server/middlewares/notification-middleware.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAC9C,6CAA4C;AAE5C,4CAA2C;AAE3C,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,qDAAqD,CAAC,CAAA;AAErF,SAAS,QAAQ,CAAC,OAAO;IACvB,OAAO,KAAK,WAAW,EACrB,SAAS,EACT,UAAU,EACV,MAAM,EACN,KAAK,EACL,IAAI,EACJ,OAAO,GAAG,MAAM,EAChB,KAAK,EACL,IAAI,EACJ,KAAK,EACL,GAAG,EACH,OAAO,EACP,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,EACtB,IAAI,GAAG,YAAY,EACpB;QACC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEtC,IAAI;YACF,IAAI,IAAI,KAAK,YAAY,EAAE;gBACzB,2CAA2C;gBAE3C,MAAM,IAAA,YAAM,EAAC;oBACX,SAAS;oBACT,UAAU;oBACV,MAAM;oBACN,KAAK;oBACL,KAAK;oBACL,IAAI;oBACJ,IAAI,EAAE;wBACJ,IAAI;wBACJ,GAAG;wBACH,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC;qBAC7B;oBACD,KAAK;oBACL,OAAO;iBACR,CAAC,CAAA;aACH;iBAAM;gBACL,8CAA8C;gBAC9C,2BAA2B;gBAC3B,MAAM,cAAM,CAAC,OAAO,CAAC,cAAc,EAAE;oBACnC,YAAY,EAAE;wBACZ,MAAM;wBACN,OAAO;wBACP,IAAI;wBACJ,KAAK;wBACL,IAAI;wBACJ,KAAK;wBACL,GAAG;wBACH,SAAS;qBACV;iBACF,CAAC,CAAA;aACH;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,YAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;SAClB;IACH,CAAC,CAAA;AACH,CAAC;AAEM,KAAK,UAAU,sBAAsB,CAAC,OAAY,EAAE,IAAS;IAClE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE;QACzB,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;KACzC;IAED,MAAM,IAAI,EAAE,CAAA;AACd,CAAC;AAND,wDAMC","sourcesContent":["import { pubsub } from '@things-factory/shell'\nimport { logger } from '@things-factory/env'\n\nimport { notify } from '../controllers/fcm'\n\nconst debug = require('debug')('things-factory:notification:notification-middleware')\n\nfunction notifier(context) {\n return async function ({\n receivers,\n privileges,\n tokens,\n topic,\n type,\n subject = 'info',\n title,\n body,\n image,\n url,\n actions,\n timestamp = Date.now(),\n mode = 'background'\n }) {\n const { domain, user } = context.state\n\n try {\n if (mode === 'background') {\n /* for send webpush notification message */\n\n await notify({\n receivers,\n privileges,\n tokens,\n topic,\n title,\n body,\n data: {\n type,\n url,\n timestamp: String(timestamp)\n },\n image,\n actions\n })\n } else {\n /* for send publish notification to clients */\n // TODO CONFIRM data format\n await pubsub.publish('notification', {\n notification: {\n domain,\n subject,\n type,\n title,\n body,\n image,\n url,\n timestamp\n }\n })\n }\n } catch (err) {\n logger.error(err)\n }\n }\n}\n\nexport async function notificationMiddleware(context: any, next: any) {\n if (!context.state.notify) {\n context.state.notify = notifier(context)\n }\n\n await next()\n}\n"]}
|
package/dist-server/routes.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const env_1 = require("@things-factory/env");
|
|
3
4
|
const notification_router_1 = require("./routers/notification-router");
|
|
5
|
+
const isPathBaseDomain = !env_1.config.get('subdomain') && !env_1.config.get('useVirtualHostBasedDomain');
|
|
4
6
|
process.on('bootstrap-module-global-public-route', (app, globalPublicRouter) => { });
|
|
5
7
|
process.on('bootstrap-module-global-private-route', (app, globalPrivateRouter) => { });
|
|
6
8
|
process.on('bootstrap-module-domain-public-route', (app, domainPublicRouter) => { });
|
|
7
9
|
process.on('bootstrap-module-domain-private-route', (app, domainPrivateRouter) => {
|
|
8
|
-
|
|
10
|
+
if (isPathBaseDomain) {
|
|
11
|
+
domainPrivateRouter.use('/domain/:domain', notification_router_1.notificationRouter.routes(), notification_router_1.notificationRouter.allowedMethods());
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
domainPrivateRouter.use('', notification_router_1.notificationRouter.routes(), notification_router_1.notificationRouter.allowedMethods());
|
|
15
|
+
}
|
|
9
16
|
});
|
|
10
17
|
//# sourceMappingURL=routes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":";;AAAA,uEAAkE;AAElE,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,kBAA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CAAA;KAC7G;SAAM;QACL,mBAAmB,CAAC,GAAG,CAAC,EAAE,EAAE,wCAAkB,CAAC,MAAM,EAAE,EAAE,wCAAkB,CAAC,cAAc,EAAE,CAAC,CAAA;KAC9F;AACH,CAAC,CAAC,CAAA","sourcesContent":["import { config } from '@things-factory/env'\nimport { notificationRouter } from './routers/notification-router'\n\nconst isPathBaseDomain = !config.get('subdomain') && !config.get('useVirtualHostBasedDomain')\n\nprocess.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {})\n\nprocess.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRouter) => {})\n\nprocess.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {})\n\nprocess.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {\n if (isPathBaseDomain) {\n domainPrivateRouter.use('/domain/:domain', notificationRouter.routes(), notificationRouter.allowedMethods())\n } else {\n domainPrivateRouter.use('', notificationRouter.routes(), notificationRouter.allowedMethods())\n }\n})\n"]}
|
|
@@ -7,7 +7,7 @@ const type_graphql_1 = require("type-graphql");
|
|
|
7
7
|
const shell_1 = require("@things-factory/shell");
|
|
8
8
|
const notification_1 = require("./notification");
|
|
9
9
|
let NotificationSubscription = class NotificationSubscription {
|
|
10
|
-
notification(payload,
|
|
10
|
+
notification(payload, subjects) {
|
|
11
11
|
return payload.notification;
|
|
12
12
|
}
|
|
13
13
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-subscription.js","sourceRoot":"","sources":["../../../server/service/notification/notification-subscription.ts"],"names":[],"mappings":";;;;AAAA,iEAAkD;AAClD,+CAA+E;AAE/E,iDAA0D;AAE1D,iDAA6C;AAGtC,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IA6BnC,YAAY,CACF,OAAuC,EACQ,
|
|
1
|
+
{"version":3,"file":"notification-subscription.js","sourceRoot":"","sources":["../../../server/service/notification/notification-subscription.ts"],"names":[],"mappings":";;;;AAAA,iEAAkD;AAClD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I,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;;;4CACrD,2BAAY;4DAEd;AAlCU,wBAAwB;IADpC,IAAA,uBAAQ,EAAC,2BAAY,CAAC;GACV,wBAAwB,CAmCpC;AAnCY,4DAAwB","sourcesContent":["import { withFilter } from 'graphql-subscriptions'\nimport { Arg, Resolver, FieldResolver, Root, Subscription } from 'type-graphql'\n\nimport { pubsub, ScalarDate } from '@things-factory/shell'\n\nimport { Notification } from './notification'\n\n@Resolver(Notification)\nexport class NotificationSubscription {\n @Subscription({\n subscribe: withFilter(\n () => pubsub.asyncIterator('notification'),\n (payload, variables, context, info) => {\n /* normally, subscription context doesn't have domain */\n const { domain, user } = context.state\n\n const { subjects = [] } = variables\n const {\n notification: { subject, domain: pdomain }\n } = payload\n\n const subdomain = pdomain?.subdomain\n\n if (subdomain) {\n if (domain?.subdomain) {\n if (subdomain !== domain.subdomain) {\n return false\n }\n } else if (!user.domains.find(d => d.subdomain === subdomain)) {\n return false\n }\n }\n\n return !subject || subjects.indexOf(subject) !== -1\n }\n )\n })\n notification(\n @Root() payload: { notification: Notification },\n @Arg('subjects', type => [String], { nullable: true }) subjects: string[]\n ): Notification {\n return payload.notification\n }\n}\n"]}
|