@things-factory/notification 6.1.195 → 6.2.1

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.
@@ -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":";;;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,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,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,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 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"]}
@@ -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, subject) {
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,OAAiB;QAExE,OAAO,OAAO,CAAC,YAAY,CAAA;IAC7B,CAAC;CACF,CAAA;AAlCC;IAAC,IAAA,2BAAY,EAAC;QACZ,SAAS,EAAE,IAAA,kCAAU,EACnB,GAAG,EAAE,CAAC,cAAM,CAAC,aAAa,CAAC,cAAc,CAAC,EAC1C,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;YACpC,wDAAwD;YACxD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;YAEtC,MAAM,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,SAAS,CAAA;YACnC,MAAM,EACJ,YAAY,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAC3C,GAAG,OAAO,CAAA;YAEX,MAAM,SAAS,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,CAAA;YAEpC,IAAI,SAAS,EAAE;gBACb,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,EAAE;oBACrB,IAAI,SAAS,KAAK,MAAM,CAAC,SAAS,EAAE;wBAClC,OAAO,KAAK,CAAA;qBACb;iBACF;qBAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,EAAE;oBAC7D,OAAO,KAAK,CAAA;iBACb;aACF;YAED,OAAO,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;QACrD,CAAC,CACF;KACF,CAAC;IAEC,mBAAA,IAAA,mBAAI,GAAE,CAAA;IACN,mBAAA,IAAA,kBAAG,EAAC,UAAU,EAAE,IAAI,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 }) subject: string[]\n ): Notification {\n return payload.notification\n }\n}\n"]}
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,QAAkB;QAEzE,OAAO,OAAO,CAAC,YAAY,CAAA;IAC7B,CAAC;CACF,CAAA;AAlCC;IAAC,IAAA,2B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cesContent":["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"]}