@things-factory/notification 7.0.0-alpha.9 → 7.0.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.
Files changed (96) hide show
  1. package/client/actions/notification-fcm.ts +1 -1
  2. package/client/bootstrap.ts +2 -1
  3. package/client/pages/notification/notification-list-page.ts +6 -5
  4. package/client/pages/notification-rule/notification-rule-importer.ts +5 -12
  5. package/client/pages/notification-rule/notification-rule-list-page.ts +6 -5
  6. package/client/viewparts/notification-badge.ts +15 -19
  7. package/client/viewparts/notification-item.ts +20 -17
  8. package/client/viewparts/notification-list.ts +23 -23
  9. package/client/viewparts/notification-sender.ts +53 -37
  10. package/client/viewparts/notification-setting-let.ts +44 -27
  11. package/dist-client/actions/notification-fcm.js.map +1 -1
  12. package/dist-client/bootstrap.js +1 -1
  13. package/dist-client/bootstrap.js.map +1 -1
  14. package/dist-client/pages/notification/notification-list-page.js +6 -5
  15. package/dist-client/pages/notification/notification-list-page.js.map +1 -1
  16. package/dist-client/pages/notification-rule/notification-rule-importer.d.ts +1 -0
  17. package/dist-client/pages/notification-rule/notification-rule-importer.js +5 -12
  18. package/dist-client/pages/notification-rule/notification-rule-importer.js.map +1 -1
  19. package/dist-client/pages/notification-rule/notification-rule-list-page.js +6 -5
  20. package/dist-client/pages/notification-rule/notification-rule-list-page.js.map +1 -1
  21. package/dist-client/reducers/notification.js.map +1 -1
  22. package/dist-client/route.js.map +1 -1
  23. package/dist-client/tsconfig.tsbuildinfo +1 -1
  24. package/dist-client/viewparts/notification-badge.d.ts +1 -0
  25. package/dist-client/viewparts/notification-badge.js +14 -19
  26. package/dist-client/viewparts/notification-badge.js.map +1 -1
  27. package/dist-client/viewparts/notification-item.d.ts +1 -1
  28. package/dist-client/viewparts/notification-item.js +19 -17
  29. package/dist-client/viewparts/notification-item.js.map +1 -1
  30. package/dist-client/viewparts/notification-list.d.ts +3 -2
  31. package/dist-client/viewparts/notification-list.js +20 -22
  32. package/dist-client/viewparts/notification-list.js.map +1 -1
  33. package/dist-client/viewparts/notification-sender.d.ts +3 -3
  34. package/dist-client/viewparts/notification-sender.js +51 -36
  35. package/dist-client/viewparts/notification-sender.js.map +1 -1
  36. package/dist-client/viewparts/notification-setting-let.d.ts +3 -4
  37. package/dist-client/viewparts/notification-setting-let.js +44 -22
  38. package/dist-client/viewparts/notification-setting-let.js.map +1 -1
  39. package/dist-server/controllers/fcm.d.ts +34 -0
  40. package/dist-server/controllers/fcm.js +5 -6
  41. package/dist-server/controllers/fcm.js.map +1 -1
  42. package/dist-server/controllers/index.d.ts +1 -0
  43. package/dist-server/index.d.ts +4 -0
  44. package/dist-server/middlewares/index.d.ts +1 -0
  45. package/dist-server/middlewares/index.js +1 -2
  46. package/dist-server/middlewares/index.js.map +1 -1
  47. package/dist-server/middlewares/notification-middleware.d.ts +1 -0
  48. package/dist-server/middlewares/notification-middleware.js +1 -2
  49. package/dist-server/middlewares/notification-middleware.js.map +1 -1
  50. package/dist-server/routers/notification-router.d.ts +1 -0
  51. package/dist-server/routes.d.ts +1 -0
  52. package/dist-server/service/index.d.ts +13 -0
  53. package/dist-server/service/notification/directive-notification.d.ts +3 -0
  54. package/dist-server/service/notification/directive-notification.js.map +1 -1
  55. package/dist-server/service/notification/index.d.ts +12 -0
  56. package/dist-server/service/notification/notification-mutation.d.ts +9 -0
  57. package/dist-server/service/notification/notification-mutation.js +2 -2
  58. package/dist-server/service/notification/notification-mutation.js.map +1 -1
  59. package/dist-server/service/notification/notification-query.d.ts +13 -0
  60. package/dist-server/service/notification/notification-query.js +4 -4
  61. package/dist-server/service/notification/notification-query.js.map +1 -1
  62. package/dist-server/service/notification/notification-subscription.d.ts +6 -0
  63. package/dist-server/service/notification/notification-subscription.js +2 -2
  64. package/dist-server/service/notification/notification-subscription.js.map +1 -1
  65. package/dist-server/service/notification/notification-type.d.ts +21 -0
  66. package/dist-server/service/notification/notification-type.js +6 -6
  67. package/dist-server/service/notification/notification-type.js.map +1 -1
  68. package/dist-server/service/notification/notification.d.ts +28 -0
  69. package/dist-server/service/notification/notification.js +4 -4
  70. package/dist-server/service/notification/notification.js.map +1 -1
  71. package/dist-server/service/notification-rule/event-subscriber.d.ts +7 -0
  72. package/dist-server/service/notification-rule/event-subscriber.js +2 -2
  73. package/dist-server/service/notification-rule/event-subscriber.js.map +1 -1
  74. package/dist-server/service/notification-rule/index.d.ts +7 -0
  75. package/dist-server/service/notification-rule/notification-rule-history.d.ts +28 -0
  76. package/dist-server/service/notification-rule/notification-rule-history.js +5 -5
  77. package/dist-server/service/notification-rule/notification-rule-history.js.map +1 -1
  78. package/dist-server/service/notification-rule/notification-rule-mutation.d.ts +10 -0
  79. package/dist-server/service/notification-rule/notification-rule-mutation.js +2 -2
  80. package/dist-server/service/notification-rule/notification-rule-mutation.js.map +1 -1
  81. package/dist-server/service/notification-rule/notification-rule-query.d.ts +12 -0
  82. package/dist-server/service/notification-rule/notification-rule-query.js +3 -3
  83. package/dist-server/service/notification-rule/notification-rule-query.js.map +1 -1
  84. package/dist-server/service/notification-rule/notification-rule-type.d.ts +27 -0
  85. package/dist-server/service/notification-rule/notification-rule-type.js +6 -6
  86. package/dist-server/service/notification-rule/notification-rule-type.js.map +1 -1
  87. package/dist-server/service/notification-rule/notification-rule.d.ts +34 -0
  88. package/dist-server/service/notification-rule/notification-rule.js +8 -9
  89. package/dist-server/service/notification-rule/notification-rule.js.map +1 -1
  90. package/dist-server/tsconfig.tsbuildinfo +1 -1
  91. package/package.json +10 -12
  92. package/server/service/notification/notification-query.ts +8 -2
  93. package/server/service/notification/notification.ts +1 -1
  94. package/server/service/notification-rule/notification-rule-history.ts +5 -5
  95. package/server/service/notification-rule/notification-rule-query.ts +4 -1
  96. package/server/service/notification-rule/notification-rule.ts +1 -1
@@ -1,10 +1,9 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
+ import '@material/web/icon/icon.js';
3
+ import '@material/web/switch/switch.js';
4
+ import '@operato/i18n/ox-i18n.js';
2
5
  import '@things-factory/setting-base';
3
6
  import './notification-sender';
4
- import '@material/mwc-formfield';
5
- import '@material/mwc-switch';
6
- import '@material/mwc-button';
7
- import '@operato/i18n/ox-i18n.js';
8
7
  import Clipboard from 'clipboard';
9
8
  import { css, html, LitElement } from 'lit';
10
9
  import { customElement, property } from 'lit/decorators.js';
@@ -20,19 +19,32 @@ let NotificationSettingLet = class NotificationSettingLet extends localize(i18ne
20
19
 
21
20
  ${supported
22
21
  ? html `
23
- <div slot="content" onoff>
24
- <mwc-formfield label=${String(i18next.t('label.allow push message'))}>
25
- <mwc-switch label="allow message" ?selected=${!!this.subscription} @click=${e => this.onClickSwitch(e)}></mwc-switch>
26
- </mwc-formfield>
27
- <mwc-button test outlined label=${String(i18next.t('button.push message test'))} @click=${e => this.ontest()}></mwc-button>
28
- </div>
29
-
30
- <div slot="content" info>
31
- <label for="subscription-token"><ox-i18n msgid="label.subscription token"></ox-i18n></label>
32
- <input id="subscription-token" type="text" name="subscription-token" .value=${this.subscription || ''} readonly />
33
- <mwc-button dense unelevated button-in-field clipboard-copy @click=${e => e.preventDefault()}><ox-i18n msgid="button.copy"></mwc-button>
34
- </div>
35
- `
22
+ <div slot="content" onoff>
23
+ <label>
24
+ <md-switch
25
+ label="allow message"
26
+ ?selected=${!!this.subscription}
27
+ @click=${e => this.onClickSwitch(e)}
28
+ ></md-switch>
29
+ ${String(i18next.t('label.allow push message'))}
30
+ </label>
31
+ <md-outlined-button test @click=${e => this.ontest()}
32
+ >${String(i18next.t('button.push message test'))}</md-outlined-button
33
+ >
34
+ </div>
35
+
36
+ <div slot="content" info>
37
+ <label for="subscription-token"><ox-i18n msgid="label.subscription token"></ox-i18n></label>
38
+ <input
39
+ id="subscription-token"
40
+ type="text"
41
+ name="subscription-token"
42
+ .value=${this.subscription || ''}
43
+ readonly
44
+ />
45
+ <md-icon button-in-field clipboard-copy @click=${e => e.preventDefault()}>content_copy</md-icon>
46
+ </div>
47
+ `
36
48
  : html ` <div slot="content">${i18next.t('text.push notification is not supported in your browser')}</div>`}
37
49
  </setting-let>
38
50
  `;
@@ -140,9 +152,9 @@ NotificationSettingLet.styles = [
140
152
  div[onoff] {
141
153
  display: flex;
142
154
  align-items: center;
143
- border-bottom: var(--border-dark-color);
144
- margin-bottom: var(--margin-default);
145
- padding-bottom: var(--padding-default);
155
+ border-bottom: var(--border-dim-color);
156
+ margin-bottom: var(--spacing-medium);
157
+ padding-bottom: var(--spacing-medium);
146
158
  }
147
159
 
148
160
  div[info] {
@@ -152,8 +164,12 @@ NotificationSettingLet.styles = [
152
164
  }
153
165
 
154
166
  label {
167
+ display: flex;
168
+ gap: 10px;
169
+ align-items: center;
170
+
155
171
  font: var(--label-font);
156
- color: var(--label-color);
172
+ color: var(--md-sys-color-on-surface);
157
173
  text-transform: var(--label-text-transform);
158
174
  }
159
175
 
@@ -162,7 +178,7 @@ NotificationSettingLet.styles = [
162
178
  }
163
179
 
164
180
  input {
165
- border: var(--border-dark-color);
181
+ border: var(--border-dim-color);
166
182
  border-radius: var(--border-radius);
167
183
  margin: var(--input-margin);
168
184
  padding: var(--input-padding);
@@ -172,9 +188,15 @@ NotificationSettingLet.styles = [
172
188
  }
173
189
 
174
190
  [button-in-field] {
191
+ --md-icon-size: 18px;
175
192
  position: absolute;
176
193
  top: 24px;
177
194
  right: 4px;
195
+ width: 30px;
196
+ padding: 2px;
197
+ border-radius: var(--border-radius, 5px);
198
+ color: var(--md-sys-color-on-secondary, #fff);
199
+ background-color: var(--md-sys-color-secondary, #394e64);
178
200
  }
179
201
  `
180
202
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"notification-setting-let.js","sourceRoot":"","sources":["../../client/viewparts/notification-setting-let.ts"],"names":[],"mappings":";AAAA,OAAO,8BAA8B,CAAA;AACrC,OAAO,uBAAuB,CAAA;AAC9B,OAAO,yBAAyB,CAAA;AAChC,OAAO,sBAAsB,CAAA;AAC7B,OAAO,sBAAsB,CAAA;AAC7B,OAAO,0BAA0B,CAAA;AAEjC,OAAO,SAAS,MA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AAI,CAAA,+CAA+C,EAAE;YAC7D,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,2BAA2B,CAAC;SAC9C,CAAC,CAAA;IACJ,CAAC;;AAzLM,6BAAM,GAAG;IACd,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAwCF;CACF,CAAA;AAED;IAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;4DAAmB;AAC9C;IAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;yDAAoB;AA9CrC,sBAAsB;IADlC,aAAa,CAAC,0BAA0B,CAAC;GAC7B,sBAAsB,CA2LlC;SA3LY,sBAAsB","sourcesContent":["import '@things-factory/setting-base'\nimport './notification-sender'\nimport '@material/mwc-formfield'\nimport '@material/mwc-switch'\nimport '@material/mwc-button'\nimport '@operato/i18n/ox-i18n.js'\n\nimport Clipboard from 'clipboard'\nimport { css, html, LitElement } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { notify, openPopup } from '@operato/layout'\nimport { i18next, localize } from '@operato/i18n'\n\nimport { getSubscriptionToken, isSupportingMessaging, subscribe, unsubscribe } from '../actions/notification-fcm'\n\n@customElement('notification-setting-let')\nexport class NotificationSettingLet extends localize(i18next)(LitElement) {\n static styles = [\n css`\n div[onoff] {\n display: flex;\n align-items: center;\n border-bottom: var(--border-dark-color);\n margin-bottom: var(--margin-default);\n padding-bottom: var(--padding-default);\n }\n\n div[info] {\n display: flex;\n flex-direction: column;\n position: relative;\n }\n\n label {\n font: var(--label-font);\n color: var(--label-color);\n text-transform: var(--label-text-transform);\n }\n\n [test] {\n margin-left: auto;\n }\n\n input {\n border: var(--border-dark-color);\n border-radius: var(--border-radius);\n margin: var(--input-margin);\n padding: var(--input-padding);\n font: var(--input-font);\n\n flex: 1;\n }\n\n [button-in-field] {\n position: absolute;\n top: 24px;\n right: 4px;\n }\n `\n ]\n\n @property({ type: Object }) subscription?: any\n @property({ type: Boolean }) supported?: boolean\n\n clipboard: any\n\n render() {\n const supported = !!this.supported\n\n return html`\n <setting-let>\n <ox-i18n slot=\"title\" msgid=\"title.notification subscription\"></ox-i18n>\n\n ${supported\n ? html`\n <div slot=\"content\" onoff>\n <mwc-formfield label=${String(i18next.t('label.allow push message'))}>\n <mwc-switch label=\"allow message\" ?selected=${!!this.subscription} @click=${e =>\n this.onClickSwitch(e)}></mwc-switch>\n </mwc-formfield>\n <mwc-button test outlined label=${String(i18next.t('button.push message test'))} @click=${e =>\n this.ontest()}></mwc-button>\n </div>\n \n <div slot=\"content\" info>\n <label for=\"subscription-token\"><ox-i18n msgid=\"label.subscription token\"></ox-i18n></label>\n <input id=\"subscription-token\" type=\"text\" name=\"subscription-token\" .value=${\n this.subscription || ''\n } readonly />\n <mwc-button dense unelevated button-in-field clipboard-copy @click=${e =>\n e.preventDefault()}><ox-i18n msgid=\"button.copy\"></mwc-button>\n </div>\n `\n : html` <div slot=\"content\">${i18next.t('text.push notification is not supported in your browser')}</div>`}\n </setting-let>\n `\n }\n\n updated(changes) {\n if (changes.has('supported') && this.supported) {\n const copybuttons = this.renderRoot.querySelectorAll('[clipboard-copy]')\n\n this.clipboard = new Clipboard(copybuttons, {\n target: trigger => trigger.parentElement!.querySelector('input')!\n })\n }\n }\n\n async connectedCallback() {\n super.connectedCallback()\n\n if (!('Notification' in window)) {\n return\n }\n\n this.supported = await isSupportingMessaging()\n this.subscription = await getSubscriptionToken()\n }\n\n async onClickSwitch(e) {\n const target = e.target\n const on = target.selected\n\n if (!('Notification' in window)) {\n notify({\n level: 'error',\n message: i18next.t('This browser does not support desktop notification')\n })\n\n return\n }\n\n try {\n if (Notification.permission !== 'granted') {\n const permission = await Notification.requestPermission()\n if (permission === 'denied') {\n notify({\n level: 'error',\n message: i18next.t('text.web push notification unblock guide')\n })\n }\n return\n }\n\n if (Notification.permission === 'granted') {\n if (on) {\n const subscription = await getSubscriptionToken()\n\n if (subscription) {\n this.subscription = subscription\n notify({\n level: 'info',\n message: i18next.t('text.notification subscribed already')\n })\n } else {\n this.subscription = await subscribe()\n\n this.subscription &&\n notify({\n level: 'info',\n message: i18next.t('text.notification subscribe started')\n })\n }\n } else {\n if (this.subscription) {\n await unsubscribe()\n\n this.subscription = await getSubscriptionToken()\n\n notify({\n level: 'info',\n message: i18next.t('text.notification unsubscribed')\n })\n } else {\n notify({\n level: 'info',\n message: i18next.t('text.notification unsubscribed already')\n })\n }\n }\n } else {\n notify({\n level: 'error',\n message: i18next.t('text.notification subscribing failed')\n })\n }\n } catch (err) {\n notify({\n level: 'error',\n message: String(err)\n })\n } finally {\n target.checked = !!this.subscription\n }\n }\n\n ontest() {\n openPopup(html` <notification-sender></notification-sender> `, {\n backdrop: true,\n size: 'large',\n title: i18next.t('title.notification-sender')\n })\n }\n}\n"]}
1
+ {"version":3,"file":"notification-setting-let.js","sourceRoot":"","sources":["../../client/viewparts/notification-setting-let.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AACnC,OAAO,gCAAgC,CAAA;AACvC,OAAO,0BAA0B,CAAA;AACjC,OAAO,8BAA8B,CAAA;AACrC,OAAO,uBAAuB,CAAA;AAE9B,OAAO,SAAS,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE3D,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAG1G,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,QAAQ,CA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAkDF;CACF,AApDY,CAoDZ;AAE2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;4DAAmB;AACjB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;yDAAoB;AAxDrC,sBAAsB;IADlC,aAAa,CAAC,0BAA0B,CAAC;GAC7B,sBAAsB,CA6MlC","sourcesContent":["import '@material/web/icon/icon.js'\nimport '@material/web/switch/switch.js'\nimport '@operato/i18n/ox-i18n.js'\nimport '@things-factory/setting-base'\nimport './notification-sender'\n\nimport Clipboard from 'clipboard'\nimport { css, html, LitElement } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { notify, openPopup } from '@operato/layout'\nimport { i18next, localize } from '@operato/i18n'\n\nimport { getSubscriptionToken, isSupportingMessaging, subscribe, unsubscribe } from '../actions/notification-fcm'\n\n@customElement('notification-setting-let')\nexport class NotificationSettingLet extends localize(i18next)(LitElement) {\n static styles = [\n css`\n div[onoff] {\n display: flex;\n align-items: center;\n border-bottom: var(--border-dim-color);\n margin-bottom: var(--spacing-medium);\n padding-bottom: var(--spacing-medium);\n }\n\n div[info] {\n display: flex;\n flex-direction: column;\n position: relative;\n }\n\n label {\n display: flex;\n gap: 10px;\n align-items: center;\n\n font: var(--label-font);\n color: var(--md-sys-color-on-surface);\n text-transform: var(--label-text-transform);\n }\n\n [test] {\n margin-left: auto;\n }\n\n input {\n border: var(--border-dim-color);\n border-radius: var(--border-radius);\n margin: var(--input-margin);\n padding: var(--input-padding);\n font: var(--input-font);\n\n flex: 1;\n }\n\n [button-in-field] {\n --md-icon-size: 18px;\n position: absolute;\n top: 24px;\n right: 4px;\n width: 30px;\n padding: 2px;\n border-radius: var(--border-radius, 5px);\n color: var(--md-sys-color-on-secondary, #fff);\n background-color: var(--md-sys-color-secondary, #394e64);\n }\n `\n ]\n\n @property({ type: Object }) subscription?: any\n @property({ type: Boolean }) supported?: boolean\n\n clipboard: any\n\n render() {\n const supported = !!this.supported\n\n return html`\n <setting-let>\n <ox-i18n slot=\"title\" msgid=\"title.notification subscription\"></ox-i18n>\n\n ${supported\n ? html`\n <div slot=\"content\" onoff>\n <label>\n <md-switch\n label=\"allow message\"\n ?selected=${!!this.subscription}\n @click=${e => this.onClickSwitch(e)}\n ></md-switch>\n ${String(i18next.t('label.allow push message'))}\n </label>\n <md-outlined-button test @click=${e => this.ontest()}\n >${String(i18next.t('button.push message test'))}</md-outlined-button\n >\n </div>\n\n <div slot=\"content\" info>\n <label for=\"subscription-token\"><ox-i18n msgid=\"label.subscription token\"></ox-i18n></label>\n <input\n id=\"subscription-token\"\n type=\"text\"\n name=\"subscription-token\"\n .value=${this.subscription || ''}\n readonly\n />\n <md-icon button-in-field clipboard-copy @click=${e => e.preventDefault()}>content_copy</md-icon>\n </div>\n `\n : html` <div slot=\"content\">${i18next.t('text.push notification is not supported in your browser')}</div>`}\n </setting-let>\n `\n }\n\n updated(changes) {\n if (changes.has('supported') && this.supported) {\n const copybuttons = this.renderRoot.querySelectorAll('[clipboard-copy]')\n\n this.clipboard = new Clipboard(copybuttons, {\n target: trigger => trigger.parentElement!.querySelector('input')!\n })\n }\n }\n\n async connectedCallback() {\n super.connectedCallback()\n\n if (!('Notification' in window)) {\n return\n }\n\n this.supported = await isSupportingMessaging()\n this.subscription = await getSubscriptionToken()\n }\n\n async onClickSwitch(e) {\n const target = e.target\n const on = target.selected\n\n if (!('Notification' in window)) {\n notify({\n level: 'error',\n message: i18next.t('This browser does not support desktop notification')\n })\n\n return\n }\n\n try {\n if (Notification.permission !== 'granted') {\n const permission = await Notification.requestPermission()\n if (permission === 'denied') {\n notify({\n level: 'error',\n message: i18next.t('text.web push notification unblock guide')\n })\n }\n return\n }\n\n if (Notification.permission === 'granted') {\n if (on) {\n const subscription = await getSubscriptionToken()\n\n if (subscription) {\n this.subscription = subscription\n notify({\n level: 'info',\n message: i18next.t('text.notification subscribed already')\n })\n } else {\n this.subscription = await subscribe()\n\n this.subscription &&\n notify({\n level: 'info',\n message: i18next.t('text.notification subscribe started')\n })\n }\n } else {\n if (this.subscription) {\n await unsubscribe()\n\n this.subscription = await getSubscriptionToken()\n\n notify({\n level: 'info',\n message: i18next.t('text.notification unsubscribed')\n })\n } else {\n notify({\n level: 'info',\n message: i18next.t('text.notification unsubscribed already')\n })\n }\n }\n } else {\n notify({\n level: 'error',\n message: i18next.t('text.notification subscribing failed')\n })\n }\n } catch (err) {\n notify({\n level: 'error',\n message: String(err)\n })\n } finally {\n target.checked = !!this.subscription\n }\n }\n\n ontest() {\n openPopup(html` <notification-sender></notification-sender> `, {\n backdrop: true,\n size: 'large',\n title: i18next.t('title.notification-sender')\n })\n }\n}\n"]}
@@ -0,0 +1,34 @@
1
+ export declare function getConfig(): {
2
+ appConfig: any;
3
+ vapidPublicKey: any;
4
+ } | {
5
+ appConfig?: undefined;
6
+ vapidPublicKey?: undefined;
7
+ };
8
+ /**
9
+ * sendNotification
10
+ *
11
+ * @param receiver user.id who will receive notification
12
+ * @param message message object to be sent
13
+ */
14
+ export declare function sendNotification({ receivers, message }: {
15
+ receivers: any;
16
+ message: any;
17
+ }): Promise<void>;
18
+ export declare function register(user: any, { subscription }: {
19
+ subscription: any;
20
+ }): Promise<boolean>;
21
+ export declare function unregister(user: any, { subscription }: {
22
+ subscription: any;
23
+ }): Promise<boolean>;
24
+ export declare function notify({ receivers, privileges, tokens, topic, title, body, data, image, actions }: {
25
+ receivers: any;
26
+ privileges: any;
27
+ tokens: any;
28
+ topic: any;
29
+ title: any;
30
+ body: any;
31
+ data: any;
32
+ image: any;
33
+ actions: any;
34
+ }): Promise<void>;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.notify = exports.unregister = exports.register = exports.sendNotification = exports.getConfig = void 0;
3
+ exports.getConfig = getConfig;
4
+ exports.sendNotification = sendNotification;
5
+ exports.register = register;
6
+ exports.unregister = unregister;
7
+ exports.notify = notify;
4
8
  const tslib_1 = require("tslib");
5
9
  const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
6
10
  const env_1 = require("@things-factory/env");
@@ -31,7 +35,6 @@ function getConfig() {
31
35
  }
32
36
  : {};
33
37
  }
34
- exports.getConfig = getConfig;
35
38
  /**
36
39
  * sendNotification
37
40
  *
@@ -44,7 +47,6 @@ async function sendNotification({ receivers, message }) {
44
47
  }
45
48
  notify(Object.assign({ receivers }, message));
46
49
  }
47
- exports.sendNotification = sendNotification;
48
50
  async function register(user, { subscription }) {
49
51
  if (!messaging || !subscription || !user) {
50
52
  return false;
@@ -72,7 +74,6 @@ async function register(user, { subscription }) {
72
74
  return;
73
75
  }
74
76
  }
75
- exports.register = register;
76
77
  async function unregister(user, { subscription }) {
77
78
  if (!messaging || !subscription || !user) {
78
79
  return false;
@@ -93,7 +94,6 @@ async function unregister(user, { subscription }) {
93
94
  return;
94
95
  }
95
96
  }
96
- exports.unregister = unregister;
97
97
  async function notify({ receivers, privileges, tokens, topic, title, body, data, image, actions }) {
98
98
  if (!messaging) {
99
99
  return;
@@ -161,7 +161,6 @@ async function notify({ receivers, privileges, tokens, topic, title, body, data,
161
161
  }
162
162
  }
163
163
  }
164
- exports.notify = notify;
165
164
  async function postDeviceGroup(body) {
166
165
  var response = await (0, node_fetch_1.default)('https://fcm.googleapis.com/fcm/notification', {
167
166
  method: 'POST',
@@ -1 +1 @@
1
- {"version":3,"file":"fcm.js","sourceRoot":"","sources":["../../server/controllers/fcm.ts"],"names":[],"mappings":";;;;AAAA,oEAA8B;AAE9B,6CAAoD;AAEpD,4CAAwD;AACxD,wDAAuD;AAEvD,MAAM,kBAAkB,GAAG,YAAM,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAA;AAC3D,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,kBAAkB,CAAA;AAC5C,MAAM,EAAE,cAAc,EAAE,SAAS,EA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AAE;QACf,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAClD,OAAO,gBAAgB,CAAA;KACxB;AACH,CAAC","sourcesContent":["import fetch from 'node-fetch'\n\nimport { config, logger } from '@things-factory/env'\n\nimport { initializeApp, cert } from 'firebase-admin/app'\nimport { getMessaging } from 'firebase-admin/messaging'\n\nconst notificationConfig = config.get('notification') || {}\nconst { fcm, vapidKey } = notificationConfig\nconst { serviceAccount, appConfig, serverKey } = fcm || {}\nconst { publicKey } = vapidKey || {}\n\nvar messaging\n\nif (serviceAccount) {\n try {\n const app = initializeApp({\n credential: cert(serviceAccount)\n })\n\n messaging = getMessaging(app)\n } catch (err) {\n logger.error('incorrect notification configuration')\n logger.error(err)\n }\n}\n\nexport function getConfig() {\n return messaging\n ? {\n appConfig,\n vapidPublicKey: publicKey\n }\n : {}\n}\n\n/**\n * sendNotification\n *\n * @param receiver user.id who will receive notification\n * @param message message object to be sent\n */\nexport async function sendNotification({ receivers, message }) {\n if (!messaging) {\n return\n }\n\n notify({\n receivers,\n ...message\n })\n}\n\nexport async function register(user, { subscription }) {\n if (!messaging || !subscription || !user) {\n return false\n }\n\n try {\n var notification_key = await getDeviceGroup(user.id)\n\n if (!notification_key) {\n await postDeviceGroup({\n operation: 'create',\n notification_key_name: user.id,\n registration_ids: [subscription]\n })\n } else {\n await postDeviceGroup({\n operation: 'add',\n notification_key_name: user.id,\n notification_key,\n registration_ids: [subscription]\n })\n }\n\n return true\n } catch (err) {\n return\n }\n}\n\nexport async function unregister(user, { subscription }) {\n if (!messaging || !subscription || !user) {\n return false\n }\n\n try {\n var notification_key = await getDeviceGroup(user.id)\n\n if (notification_key) {\n await postDeviceGroup({\n operation: 'remove',\n notification_key_name: user.id,\n notification_key,\n registration_ids: [subscription]\n })\n }\n\n return true\n } catch (err) {\n return\n }\n}\n\nexport async function notify({ receivers, privileges, tokens, topic, title, body, data, image, actions }) {\n if (!messaging) {\n return\n }\n\n // Caution: non-string attributes are not allowed in FCM payload validation\n var notification = {\n title: title || '',\n body: body || '',\n image: image || ''\n }\n\n if (tokens && tokens instanceof Array && tokens.length > 0) {\n if (tokens.length > 1) {\n const response = await messaging.sendMulticast({\n notification,\n data,\n tokens\n })\n\n if (response.failureCount > 0) {\n const failedTokens = []\n response.responses.forEach((resp, idx) => {\n if (!resp.success) {\n failedTokens.push(tokens[idx])\n }\n })\n logger.error('List of tokens that caused failures: ' + failedTokens)\n }\n } else {\n const token = tokens[0]\n\n try {\n const response = await messaging.send({\n notification,\n data,\n token\n })\n logger.log('Successfully sent message:', response)\n } catch (err) {\n logger.error('Error sending message:', err)\n }\n }\n }\n\n if (topic) {\n try {\n const response = await messaging.send({\n notification,\n data,\n topic\n })\n logger.log('Successfully sent message:', response)\n } catch (err) {\n logger.error('Error sending message:', err)\n }\n }\n\n if (receivers && receivers instanceof Array) {\n for (let receiver of receivers) {\n const notification_key = await getDeviceGroup(receiver)\n\n if (notification_key) {\n await messaging.sendToDeviceGroup(notification_key, {\n notification,\n data\n })\n }\n }\n }\n}\n\nasync function postDeviceGroup(body) {\n var response = await fetch('https://fcm.googleapis.com/fcm/notification', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `key=${serverKey}`,\n project_id: appConfig.messagingSenderId\n },\n body: JSON.stringify(body)\n })\n\n if (response.ok) {\n const { notification_key } = await response.json()\n return notification_key\n } else {\n console.error('postDeviceGroup-notok', response.status, await response.text())\n }\n}\n\nasync function getDeviceGroup(notificationKeyName) {\n const response = await fetch(\n `https://fcm.googleapis.com/fcm/notification?notification_key_name=${notificationKeyName}`,\n {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `key=${serverKey}`,\n project_id: appConfig.messagingSenderId\n }\n }\n )\n\n if (response.ok) {\n const { notification_key } = await response.json()\n return notification_key\n }\n}\n"]}
1
+ {"version":3,"file":"fcm.js","sourceRoot":"","sources":["../../server/controllers/fcm.ts"],"names":[],"mappings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C,EAAE,EAAE,CAAC;QAChB,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAClD,OAAO,gBAAgB,CAAA;IACzB,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IAChF,CAAC;AACH,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,mBAAmB;IAC/C,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAK,EAC1B,qEAAqE,mBAAmB,EAAE,EAC1F;QACE,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,OAAO,SAAS,EAAE;YACjC,UAAU,EAAE,SAAS,CAAC,iBAAiB;SACxC;KACF,CACF,CAAA;IAED,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAC;QAChB,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAClD,OAAO,gBAAgB,CAAA;IACzB,CAAC;AACH,CAAC","sourcesContent":["import fetch from 'node-fetch'\n\nimport { config, logger } from '@things-factory/env'\n\nimport { initializeApp, cert } from 'firebase-admin/app'\nimport { getMessaging } from 'firebase-admin/messaging'\n\nconst notificationConfig = config.get('notification') || {}\nconst { fcm, vapidKey } = notificationConfig\nconst { serviceAccount, appConfig, serverKey } = fcm || {}\nconst { publicKey } = vapidKey || {}\n\nvar messaging\n\nif (serviceAccount) {\n try {\n const app = initializeApp({\n credential: cert(serviceAccount)\n })\n\n messaging = getMessaging(app)\n } catch (err) {\n logger.error('incorrect notification configuration')\n logger.error(err)\n }\n}\n\nexport function getConfig() {\n return messaging\n ? {\n appConfig,\n vapidPublicKey: publicKey\n }\n : {}\n}\n\n/**\n * sendNotification\n *\n * @param receiver user.id who will receive notification\n * @param message message object to be sent\n */\nexport async function sendNotification({ receivers, message }) {\n if (!messaging) {\n return\n }\n\n notify({\n receivers,\n ...message\n })\n}\n\nexport async function register(user, { subscription }) {\n if (!messaging || !subscription || !user) {\n return false\n }\n\n try {\n var notification_key = await getDeviceGroup(user.id)\n\n if (!notification_key) {\n await postDeviceGroup({\n operation: 'create',\n notification_key_name: user.id,\n registration_ids: [subscription]\n })\n } else {\n await postDeviceGroup({\n operation: 'add',\n notification_key_name: user.id,\n notification_key,\n registration_ids: [subscription]\n })\n }\n\n return true\n } catch (err) {\n return\n }\n}\n\nexport async function unregister(user, { subscription }) {\n if (!messaging || !subscription || !user) {\n return false\n }\n\n try {\n var notification_key = await getDeviceGroup(user.id)\n\n if (notification_key) {\n await postDeviceGroup({\n operation: 'remove',\n notification_key_name: user.id,\n notification_key,\n registration_ids: [subscription]\n })\n }\n\n return true\n } catch (err) {\n return\n }\n}\n\nexport async function notify({ receivers, privileges, tokens, topic, title, body, data, image, actions }) {\n if (!messaging) {\n return\n }\n\n // Caution: non-string attributes are not allowed in FCM payload validation\n var notification = {\n title: title || '',\n body: body || '',\n image: image || ''\n }\n\n if (tokens && tokens instanceof Array && tokens.length > 0) {\n if (tokens.length > 1) {\n const response = await messaging.sendMulticast({\n notification,\n data,\n tokens\n })\n\n if (response.failureCount > 0) {\n const failedTokens = []\n response.responses.forEach((resp, idx) => {\n if (!resp.success) {\n failedTokens.push(tokens[idx])\n }\n })\n logger.error('List of tokens that caused failures: ' + failedTokens)\n }\n } else {\n const token = tokens[0]\n\n try {\n const response = await messaging.send({\n notification,\n data,\n token\n })\n logger.log('Successfully sent message:', response)\n } catch (err) {\n logger.error('Error sending message:', err)\n }\n }\n }\n\n if (topic) {\n try {\n const response = await messaging.send({\n notification,\n data,\n topic\n })\n logger.log('Successfully sent message:', response)\n } catch (err) {\n logger.error('Error sending message:', err)\n }\n }\n\n if (receivers && receivers instanceof Array) {\n for (let receiver of receivers) {\n const notification_key = await getDeviceGroup(receiver)\n\n if (notification_key) {\n await messaging.sendToDeviceGroup(notification_key, {\n notification,\n data\n })\n }\n }\n }\n}\n\nasync function postDeviceGroup(body) {\n var response = await fetch('https://fcm.googleapis.com/fcm/notification', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `key=${serverKey}`,\n project_id: appConfig.messagingSenderId\n },\n body: JSON.stringify(body)\n })\n\n if (response.ok) {\n const { notification_key } = await response.json()\n return notification_key\n } else {\n console.error('postDeviceGroup-notok', response.status, await response.text())\n }\n}\n\nasync function getDeviceGroup(notificationKeyName) {\n const response = await fetch(\n `https://fcm.googleapis.com/fcm/notification?notification_key_name=${notificationKeyName}`,\n {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `key=${serverKey}`,\n project_id: appConfig.messagingSenderId\n }\n }\n )\n\n if (response.ok) {\n const { notification_key } = await response.json()\n return notification_key\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export * from './fcm';
@@ -0,0 +1,4 @@
1
+ export * from './service';
2
+ export * from './middlewares';
3
+ export * from './controllers';
4
+ import './routes';
@@ -0,0 +1 @@
1
+ export declare function initMiddlewares(app: any): void;
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initMiddlewares = void 0;
3
+ exports.initMiddlewares = initMiddlewares;
4
4
  const notification_middleware_1 = require("./notification-middleware");
5
5
  function initMiddlewares(app) {
6
6
  app.use(notification_middleware_1.notificationMiddleware);
7
7
  }
8
- exports.initMiddlewares = initMiddlewares;
9
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/middlewares/index.ts"],"names":[],"mappings":";;;AAAA,uEAAkE;AAElE,SAAgB,eAAe,CAAC,GAAG;IACjC,GAAG,CAAC,GAAG,CAAC,gDAAsB,CAAC,CAAA;AACjC,CAAC;AAFD,0CAEC","sourcesContent":["import { notificationMiddleware } from './notification-middleware'\n\nexport function initMiddlewares(app) {\n app.use(notificationMiddleware)\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/middlewares/index.ts"],"names":[],"mappings":";;AAEA,0CAEC;AAJD,uEAAkE;AAElE,SAAgB,eAAe,CAAC,GAAG;IACjC,GAAG,CAAC,GAAG,CAAC,gDAAsB,CAAC,CAAA;AACjC,CAAC","sourcesContent":["import { notificationMiddleware } from './notification-middleware'\n\nexport function initMiddlewares(app) {\n app.use(notificationMiddleware)\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare function notificationMiddleware(context: any, next: any): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.notificationMiddleware = void 0;
3
+ exports.notificationMiddleware = notificationMiddleware;
4
4
  const shell_1 = require("@things-factory/shell");
5
5
  const env_1 = require("@things-factory/env");
6
6
  const fcm_1 = require("../controllers/fcm");
@@ -55,5 +55,4 @@ async function notificationMiddleware(context, next) {
55
55
  }
56
56
  await next();
57
57
  }
58
- exports.notificationMiddleware = notificationMiddleware;
59
58
  //# sourceMappingURL=notification-middleware.js.map
@@ -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,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"]}
1
+ {"version":3,"file":"notification-middleware.js","sourceRoot":"","sources":["../../server/middlewares/notification-middleware.ts"],"names":[],"mappings":";;AAkEA,wDAMC;AAxED,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,CAAC;YACH,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;gBAC1B,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;YACJ,CAAC;iBAAM,CAAC;gBACN,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;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,YAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACnB,CAAC;IACH,CAAC,CAAA;AACH,CAAC;AAEM,KAAK,UAAU,sBAAsB,CAAC,OAAY,EAAE,IAAS;IAClE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QAC1B,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1C,CAAC;IAED,MAAM,IAAI,EAAE,CAAA;AACd,CAAC","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"]}
@@ -0,0 +1 @@
1
+ export declare const notificationRouter: any;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ export * from './notification-rule/notification-rule';
2
+ export * from './notification/notification';
3
+ export declare const entities: (typeof import("./notification-rule/notification-rule").NotificationRule | typeof import("./notification/notification").Notification)[];
4
+ export declare const subscribers: typeof import("./notification-rule/event-subscriber").NotificationRuleHistoryEntitySubscriber[];
5
+ export declare const schema: {
6
+ typeDefs: {
7
+ notificationDirectiveTypeDefs: import("graphql").DocumentNode;
8
+ };
9
+ resolverClasses: (typeof import("./notification-rule/notification-rule-query").NotificationRuleQuery | typeof import("./notification-rule/notification-rule-mutation").NotificationRuleMutation | typeof import("./notification/notification-query").NotificationQuery | typeof import("./notification/notification-mutation").NotificationMutation | typeof import("./notification/notification-subscription").NotificationSubscription)[];
10
+ directives: {
11
+ notification: (schema: import("graphql").GraphQLSchema) => import("graphql").GraphQLSchema;
12
+ };
13
+ };
@@ -0,0 +1,3 @@
1
+ import { GraphQLSchema } from 'graphql';
2
+ export declare const notificationDirectiveTypeDefs: import("graphql").DocumentNode;
3
+ export declare const directiveNotification: (schema: GraphQLSchema) => GraphQLSchema;
@@ -1 +1 @@
1
- {"version":3,"file":"directive-notification.js","sourceRoot":"","sources":["../../../server/service/notification/directive-notification.ts"],"names":[],"mappings":";;;;AAAA,qCAA6D;AAC7D,sEAA6B;AAE7B,gDAA0E;AAE1E,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oDAAoD,CAAC,CAAA;AAEpF,MAAM,SAAS,GAAG,cAAc,CAAA;AAEnB,QAAA,6BAA6B,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;;CAY/C,CAAA;AACM,MAAM,qBAAqB,GAAG,CAAC,MAAqB,EAAE,EAAE,CAC7D,IAAA,iBAAS,EAAC,MAAM,EAAE;IAChB,CAAC,kBAAU,CAAC,YAAY,CAAC,EAAE,CAAC,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE;;QACtE,MAAM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,QAAA,qBAAqB,yBAgD9B","sourcesContent":["import { defaultFieldResolver, GraphQLSchema } from 'graphql'\nimport gql from 'graphql-tag'\n\nimport { getDirective, MapperKind, mapSchema } from '@graphql-tools/utils'\n\nconst debug = require('debug')('things-factory:notification:directive-notification')\n\nconst DIRECTIVE = 'notification'\n\nexport const notificationDirectiveTypeDefs = gql`\n directive @notification(\n receivers: String\n topic: String\n subject: String # info\n title: String\n body: String\n image: String\n url: String\n # timestamp = String(Date.now())\n mode: String # background\n ) on FIELD_DEFINITION\n`\nexport const directiveNotification = (schema: GraphQLSchema) =>\n mapSchema(schema, {\n [MapperKind.OBJECT_FIELD]: (fieldConfig, fieldName, typeName, schema) => {\n const notificationDirective = getDirective(schema, fieldConfig, DIRECTIVE)?.[0]\n if (notificationDirective) {\n const { resolve = defaultFieldResolver, args } = fieldConfig\n\n if (!args) {\n throw new Error(`Unexpected Error. args should be defined in @notification directive for field ${fieldName}.`)\n }\n\n const {\n receivers,\n topic,\n subject = 'info',\n title,\n body,\n image,\n url,\n mode = 'background'\n } = notificationDirective\n const timestamp = Date.now()\n\n fieldConfig.resolve = async function (source, args, context, info) {\n const result = await resolve.call(this, source, args, context, info)\n\n const { domain, user, notify } = context.state\n\n if (!notify) {\n debug('notify not set')\n } else {\n try {\n await notify({\n receivers: [user.id],\n notificationDirective,\n timestamp: new Date()\n })\n } catch (err) {\n debug(err)\n }\n }\n\n return result\n }\n\n return fieldConfig\n }\n }\n })\n"]}
1
+ {"version":3,"file":"directive-notification.js","sourceRoot":"","sources":["../../../server/service/notification/directive-notification.ts"],"names":[],"mappings":";;;;AAAA,qCAA6D;AAC7D,sEAA6B;AAE7B,gDAA0E;AAE1E,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oDAAoD,CAAC,CAAA;AAEpF,MAAM,SAAS,GAAG,cAAc,CAAA;AAEnB,QAAA,6BAA6B,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;;CAY/C,CAAA;AACM,MA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;4BACrB,SAAS,EAAE,IAAI,IAAI,EAAE;yBACtB,CAAC,CAAA;oBACJ,CAAC;oBAAC,OAAO,GAAG,EAAE,CAAC;wBACb,KAAK,CAAC,GAAG,CAAC,CAAA;oBACZ,CAAC;gBACH,CAAC;gBAED,OAAO,MAAM,CAAA;YACf,CAAC,CAAA;YAED,OAAO,WAAW,CAAA;QACpB,CAAC;IACH,CAAC;CACF,CAAC,CAAA;AAhDS,QAAA,qBAAqB,yBAgD9B","sourcesContent":["import { defaultFieldResolver, GraphQLSchema } from 'graphql'\nimport gql from 'graphql-tag'\n\nimport { getDirective, MapperKind, mapSchema } from '@graphql-tools/utils'\n\nconst debug = require('debug')('things-factory:notification:directive-notification')\n\nconst DIRECTIVE = 'notification'\n\nexport const notificationDirectiveTypeDefs = gql`\n directive @notification(\n receivers: String\n topic: String\n subject: String # info\n title: String\n body: String\n image: String\n url: String\n # timestamp = String(Date.now())\n mode: String # background\n ) on FIELD_DEFINITION\n`\nexport const directiveNotification = (schema: GraphQLSchema) =>\n mapSchema(schema, {\n [MapperKind.OBJECT_FIELD]: (fieldConfig, fieldName, typeName, schema) => {\n const notificationDirective = getDirective(schema, fieldConfig, DIRECTIVE)?.[0]\n if (notificationDirective) {\n const { resolve = defaultFieldResolver, args } = fieldConfig\n\n if (!args) {\n throw new Error(`Unexpected Error. args should be defined in @notification directive for field ${fieldName}.`)\n }\n\n const {\n receivers,\n topic,\n subject = 'info',\n title,\n body,\n image,\n url,\n mode = 'background'\n } = notificationDirective\n const timestamp = Date.now()\n\n fieldConfig.resolve = async function (source, args, context, info) {\n const result = await resolve.call(this, source, args, context, info)\n\n const { domain, user, notify } = context.state\n\n if (!notify) {\n debug('notify not set')\n } else {\n try {\n await notify({\n receivers: [user.id],\n notificationDirective,\n timestamp: new Date()\n })\n } catch (err) {\n debug(err)\n }\n }\n\n return result\n }\n\n return fieldConfig\n }\n }\n })\n"]}
@@ -0,0 +1,12 @@
1
+ import { Notification } from './notification';
2
+ import { NotificationQuery } from './notification-query';
3
+ import { NotificationMutation } from './notification-mutation';
4
+ import { NotificationSubscription } from './notification-subscription';
5
+ export declare const typeDefs: {
6
+ notificationDirectiveTypeDefs: import("graphql").DocumentNode;
7
+ };
8
+ export declare const entities: (typeof Notification)[];
9
+ export declare const resolvers: (typeof NotificationQuery | typeof NotificationMutation | typeof NotificationSubscription)[];
10
+ export declare const directives: {
11
+ notification: (schema: import("graphql").GraphQLSchema) => import("graphql").GraphQLSchema;
12
+ };
@@ -0,0 +1,9 @@
1
+ import { Notification } from './notification';
2
+ import { NewNotification, NotificationPatch } from './notification-type';
3
+ export declare class NotificationMutation {
4
+ createNotification(notification: NewNotification, context: ResolverContext): Promise<Notification>;
5
+ updateNotification(id: string, patch: NotificationPatch, context: ResolverContext): Promise<Notification>;
6
+ updateMultipleNotification(patches: NotificationPatch[], context: ResolverContext): Promise<Notification[]>;
7
+ deleteNotification(id: string, context: ResolverContext): Promise<boolean>;
8
+ deleteNotificationes(ids: string[], context: ResolverContext): Promise<boolean>;
9
+ }
@@ -57,6 +57,7 @@ let NotificationMutation = class NotificationMutation {
57
57
  return true;
58
58
  }
59
59
  };
60
+ exports.NotificationMutation = NotificationMutation;
60
61
  tslib_1.__decorate([
61
62
  (0, type_graphql_1.Directive)('@transaction'),
62
63
  (0, type_graphql_1.Mutation)(returns => notification_1.Notification, { description: 'To create new Notification' }),
@@ -103,8 +104,7 @@ tslib_1.__decorate([
103
104
  tslib_1.__metadata("design:paramtypes", [Array, Object]),
104
105
  tslib_1.__metadata("design:returntype", Promise)
105
106
  ], NotificationMutation.prototype, "deleteNotificationes", null);
106
- NotificationMutation = tslib_1.__decorate([
107
+ exports.NotificationMutation = NotificationMutation = tslib_1.__decorate([
107
108
  (0, type_graphql_1.Resolver)(notification_1.Notification)
108
109
  ], NotificationMutation);
109
- exports.NotificationMutation = NotificationMutation;
110
110
  //# sourceMappingURL=notification-mutation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"notification-mutation.js","source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AC,CAAA;IACZ,mBAAA,IAAA,kBAAG,GAAE,CAAA;;qDADe,qCAAiB;;8DAiBvC;AAIK;IAFL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,CAAC,2BAAY,CAAC,EAAE,EAAE,WAAW,EAAE,gDAAgD,EAAE,CAAC;IAEpG,mBAAA,IAAA,kBAAG,EAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,qCAAiB,CAAC,CAAC,CAAA;IAC3C,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;sEAwCP;AAIK;IAFL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,wBAAwB,EAAE,CAAC;IAC9C,mBAAA,IAAA,kBAAG,EAAC,IAAI,CAAC,CAAA;IAAc,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;8DAMrD;AAIK;IAFL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,mCAAmC,EAAE,CAAC;IAEhF,mBAAA,IAAA,kBAAG,EAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;gEAUP;AA9GU,oBAAoB;IADhC,IAAA,uBAAQ,EAAC,2BAAY,CAAC;GACV,oBAAoB,CA+GhC;AA/GY,oDAAoB","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { Notification } from './notification'\nimport { NewNotification, NotificationPatch } from './notification-type'\n\n@Resolver(Notification)\nexport class NotificationMutation {\n @Directive('@transaction')\n @Mutation(returns => Notification, { description: 'To create new Notification' })\n async createNotification(\n @Arg('notification') notification: NewNotification,\n @Ctx() context: ResolverContext\n ): Promise<Notification> {\n const { domain, user, tx } = context.state\n\n return await tx.getRepository(Notification).save({\n ...notification,\n domain,\n creator: user,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Mutation(returns => Notification, { description: 'To modify Notification information' })\n async updateNotification(\n @Arg('id') id: string,\n @Arg('patch') patch: NotificationPatch,\n @Ctx() context: ResolverContext\n ): Promise<Notification> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(Notification)\n const notification = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n const result = await repository.save({\n ...notification,\n ...patch,\n updater: user\n })\n\n return result\n }\n\n @Directive('@transaction')\n @Mutation(returns => [Notification], { description: \"To modify multiple Notificationes' information\" })\n async updateMultipleNotification(\n @Arg('patches', type => [NotificationPatch]) patches: NotificationPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Notification[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n const notificationRepo = tx.getRepository(Notification)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await notificationRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const updateRecord = _updateRecords[i]\n const notification = await notificationRepo.findOneBy({ id: updateRecord.id })\n\n const result = await notificationRepo.save({\n ...notification,\n ...updateRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete Notification' })\n async deleteNotification(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Notification).delete({ domain: { id: domain.id }, id })\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete multiple Notificationes' })\n async deleteNotificationes(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Notification).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n return true\n }\n}\n"]}
1
+ {"version":3,"file":"notification-mutation.js","sourceRoot":"","sources":["../../../server/service/notification/notification-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,iDAA6C;AAC7C,2DAAwE;AAGjE,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAGzB,AAAN,KAAK,CAAC,kBAAkB,CACD,YAA6B,EAC3C,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,OAAO,MAAM,EAAE,CAAC,aAAa,CAAC,2BAAY,CAAC,CAAC,IAAI,iCAC3C,YAAY,KACf,MAAM,EACN,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,IAAI,IACb,CAAA;IACJ,CAAC;IAIK,AAAN,KAAK,CAAC,kBAAkB,CACX,EAAU,EACP,KAAwB,EAC/B,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,2BAAY,CAAC,CAAA;QACjD,MAAM,YAAY,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;YAC5C,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE;SACzC,CAAC,CAAA;QAEF,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,+CAC/B,YAAY,GACZ,KAAK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AAC,CAAA;IAC5B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;gEAUP;+BA9GU,oBAAoB;IADhC,IAAA,uBAAQ,EAAC,2BAAY,CAAC;GACV,oBAAoB,CA+GhC","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { Notification } from './notification'\nimport { NewNotification, NotificationPatch } from './notification-type'\n\n@Resolver(Notification)\nexport class NotificationMutation {\n @Directive('@transaction')\n @Mutation(returns => Notification, { description: 'To create new Notification' })\n async createNotification(\n @Arg('notification') notification: NewNotification,\n @Ctx() context: ResolverContext\n ): Promise<Notification> {\n const { domain, user, tx } = context.state\n\n return await tx.getRepository(Notification).save({\n ...notification,\n domain,\n creator: user,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Mutation(returns => Notification, { description: 'To modify Notification information' })\n async updateNotification(\n @Arg('id') id: string,\n @Arg('patch') patch: NotificationPatch,\n @Ctx() context: ResolverContext\n ): Promise<Notification> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(Notification)\n const notification = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n const result = await repository.save({\n ...notification,\n ...patch,\n updater: user\n })\n\n return result\n }\n\n @Directive('@transaction')\n @Mutation(returns => [Notification], { description: \"To modify multiple Notificationes' information\" })\n async updateMultipleNotification(\n @Arg('patches', type => [NotificationPatch]) patches: NotificationPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Notification[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n const notificationRepo = tx.getRepository(Notification)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await notificationRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const updateRecord = _updateRecords[i]\n const notification = await notificationRepo.findOneBy({ id: updateRecord.id })\n\n const result = await notificationRepo.save({\n ...notification,\n ...updateRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete Notification' })\n async deleteNotification(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Notification).delete({ domain: { id: domain.id }, id })\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete multiple Notificationes' })\n async deleteNotificationes(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Notification).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n return true\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { Domain, ListParam } from '@things-factory/shell';
2
+ import { User } from '@things-factory/auth-base';
3
+ import { Notification } from './notification';
4
+ import { NotificationList } from './notification-type';
5
+ export declare class NotificationQuery {
6
+ notification(id: string, context: ResolverContext): Promise<Notification>;
7
+ notificationes(params: ListParam, context: ResolverContext): Promise<NotificationList>;
8
+ myNotifications(params: ListParam, context: ResolverContext): Promise<NotificationList>;
9
+ owner(notification: Notification): Promise<User>;
10
+ domain(notification: Notification): Promise<Domain>;
11
+ updater(notification: Notification): Promise<User>;
12
+ creator(notification: Notification): Promise<User>;
13
+ }
@@ -50,6 +50,7 @@ let NotificationQuery = class NotificationQuery {
50
50
  return notification.creatorId && (await (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: notification.creatorId }));
51
51
  }
52
52
  };
53
+ exports.NotificationQuery = NotificationQuery;
53
54
  tslib_1.__decorate([
54
55
  (0, type_graphql_1.Query)(returns => notification_1.Notification, { nullable: true, description: 'To fetch a Notification' }),
55
56
  tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
@@ -60,7 +61,7 @@ tslib_1.__decorate([
60
61
  ], NotificationQuery.prototype, "notification", null);
61
62
  tslib_1.__decorate([
62
63
  (0, type_graphql_1.Query)(returns => notification_type_1.NotificationList, { description: 'To fetch multiple Notificationes' }),
63
- tslib_1.__param(0, (0, type_graphql_1.Args)()),
64
+ tslib_1.__param(0, (0, type_graphql_1.Args)(type => shell_1.ListParam)),
64
65
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
65
66
  tslib_1.__metadata("design:type", Function),
66
67
  tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
@@ -68,7 +69,7 @@ tslib_1.__decorate([
68
69
  ], NotificationQuery.prototype, "notificationes", null);
69
70
  tslib_1.__decorate([
70
71
  (0, type_graphql_1.Query)(returns => notification_type_1.NotificationList, { description: 'To fetch my notifications' }),
71
- tslib_1.__param(0, (0, type_graphql_1.Args)()),
72
+ tslib_1.__param(0, (0, type_graphql_1.Args)(type => shell_1.ListParam)),
72
73
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
73
74
  tslib_1.__metadata("design:type", Function),
74
75
  tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
@@ -102,8 +103,7 @@ tslib_1.__decorate([
102
103
  tslib_1.__metadata("design:paramtypes", [notification_1.Notification]),
103
104
  tslib_1.__metadata("design:returntype", Promise)
104
105
  ], NotificationQuery.prototype, "creator", null);
105
- NotificationQuery = tslib_1.__decorate([
106
+ exports.NotificationQuery = NotificationQuery = tslib_1.__decorate([
106
107
  (0, type_graphql_1.Resolver)(notification_1.Notification)
107
108
  ], NotificationQuery);
108
- exports.NotificationQuery = NotificationQuery;
109
109
  //# sourceMappingURL=notification-query.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"notification-query.js","sourceRoot":"","sources":["../../../server/service/notification/notification-query.ts"],"names":[],"mappings":";;;;AAAA,+CAA8F;AAC9F,iDAAmH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EAAC,IAAI,CAAC,CAAA;IAAc,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;qDAM/C;AAGK;IADL,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,oCAAgB,EAAE,EAAE,WAAW,EAAE,kCAAkC,EAAE,CAAC;IAClE,mBAAA,IAAA,mBAAI,GAAE,CAAA;IAAqB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;6CAAjB,iBAAS;;uDAa7C;AAGK;IADL,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,oCAAgB,EAAE,EAAE,WAAW,EAAE,2BAA2B,EAAE,CAAC;IAC1D,mBAAA,IAAA,mBAAI,GAAE,CAAA;IAAqB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;6CAAjB,iBAAS;;wDAc9C;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,CAAC;IACf,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAe,2BAAY;;8CAE7C;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,CAAC;IAChB,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAe,2BAAY;;+CAE9C;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,CAAC;IACb,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAe,2BAAY;;gDAE/C;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,CAAC;IACb,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAe,2BAAY;;gDAE/C;AA7DU,iBAAiB;IAD7B,IAAA,uBAAQ,EAAC,2BAAY,CAAC;GACV,iBAAiB,CA8D7B;AA9DY,8CAAiB","sourcesContent":["import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'\nimport { Domain, getQueryBuilderFromListParams, getRepository, ListParam, ScalarDate } from '@things-factory/shell'\nimport { User } from '@things-factory/auth-base'\nimport { Notification } from './notification'\nimport { NotificationList } from './notification-type'\n\n@Resolver(Notification)\nexport class NotificationQuery {\n @Query(returns => Notification!, { nullable: true, description: 'To fetch a Notification' })\n async notification(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Notification> {\n const { domain } = context.state\n\n return await getRepository(Notification).findOne({\n where: { domain: { id: domain.id }, id }\n })\n }\n\n @Query(returns => NotificationList, { description: 'To fetch multiple Notificationes' })\n async notificationes(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<NotificationList> {\n const { domain } = context.state\n\n const queryBuilder = getQueryBuilderFromListParams({\n domain,\n params,\n repository: await getRepository(Notification),\n searchables: ['title', 'body']\n })\n\n const [items, total] = await queryBuilder.getManyAndCount()\n\n return { items, total }\n }\n\n @Query(returns => NotificationList, { description: 'To fetch my notifications' })\n async myNotifications(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<NotificationList> {\n const { domain, user } = context.state\n\n const queryBuilder = getQueryBuilderFromListParams({\n domain,\n params,\n alias: 'nb',\n repository: await getRepository(Notification),\n searchables: ['title', 'body']\n }).andWhere('nb.owner = :user', { user: user.id })\n\n const [items, total] = await queryBuilder.getManyAndCount()\n\n return { items, total }\n }\n\n @FieldResolver(type => User)\n async owner(@Root() notification: Notification): Promise<User> {\n return notification.ownerId && (await getRepository(User).findOneBy({ id: notification.ownerId }))\n }\n\n @FieldResolver(type => Domain)\n async domain(@Root() notification: Notification): Promise<Domain> {\n return notification.domainId && (await getRepository(Domain).findOneBy({ id: notification.domainId }))\n }\n\n @FieldResolver(type => User)\n async updater(@Root() notification: Notification): Promise<User> {\n return notification.updaterId && (await getRepository(User).findOneBy({ id: notification.updaterId }))\n }\n\n @FieldResolver(type => User)\n async creator(@Root() notification: Notification): Promise<User> {\n return notification.creatorId && (await getRepository(User).findOneBy({ id: notification.creatorId }))\n }\n}\n"]}
1
+ {"version":3,"file":"notification-query.js","sourceRoot":"","sources":["../../../server/service/notification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,CAoE7B","sourcesContent":["import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'\nimport { Domain, getQueryBuilderFromListParams, getRepository, ListParam, ScalarDate } from '@things-factory/shell'\nimport { User } from '@things-factory/auth-base'\nimport { Notification } from './notification'\nimport { NotificationList } from './notification-type'\n\n@Resolver(Notification)\nexport class NotificationQuery {\n @Query(returns => Notification!, { nullable: true, description: 'To fetch a Notification' })\n async notification(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Notification> {\n const { domain } = context.state\n\n return await getRepository(Notification).findOne({\n where: { domain: { id: domain.id }, id }\n })\n }\n\n @Query(returns => NotificationList, { description: 'To fetch multiple Notificationes' })\n async notificationes(\n @Args(type => ListParam) params: ListParam,\n @Ctx() context: ResolverContext\n ): Promise<NotificationList> {\n const { domain } = context.state\n\n const queryBuilder = getQueryBuilderFromListParams({\n domain,\n params,\n repository: await getRepository(Notification),\n searchables: ['title', 'body']\n })\n\n const [items, total] = await queryBuilder.getManyAndCount()\n\n return { items, total }\n }\n\n @Query(returns => NotificationList, { description: 'To fetch my notifications' })\n async myNotifications(\n @Args(type => ListParam) params: ListParam,\n @Ctx() context: ResolverContext\n ): Promise<NotificationList> {\n const { domain, user } = context.state\n\n const queryBuilder = getQueryBuilderFromListParams({\n domain,\n params,\n alias: 'nb',\n repository: await getRepository(Notification),\n searchables: ['title', 'body']\n }).andWhere('nb.owner = :user', { user: user.id })\n\n const [items, total] = await queryBuilder.getManyAndCount()\n\n return { items, total }\n }\n\n @FieldResolver(type => User)\n async owner(@Root() notification: Notification): Promise<User> {\n return notification.ownerId && (await getRepository(User).findOneBy({ id: notification.ownerId }))\n }\n\n @FieldResolver(type => Domain)\n async domain(@Root() notification: Notification): Promise<Domain> {\n return notification.domainId && (await getRepository(Domain).findOneBy({ id: notification.domainId }))\n }\n\n @FieldResolver(type => User)\n async updater(@Root() notification: Notification): Promise<User> {\n return notification.updaterId && (await getRepository(User).findOneBy({ id: notification.updaterId }))\n }\n\n @FieldResolver(type => User)\n async creator(@Root() notification: Notification): Promise<User> {\n return notification.creatorId && (await getRepository(User).findOneBy({ id: notification.creatorId }))\n }\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import { Notification } from './notification';
2
+ export declare class NotificationSubscription {
3
+ notification(payload: {
4
+ notification: Notification;
5
+ }, subjects: string[]): Notification;
6
+ }
@@ -11,6 +11,7 @@ let NotificationSubscription = class NotificationSubscription {
11
11
  return payload.notification;
12
12
  }
13
13
  };
14
+ exports.NotificationSubscription = NotificationSubscription;
14
15
  tslib_1.__decorate([
15
16
  (0, type_graphql_1.Subscription)({
16
17
  subscribe: ({ args, context, info }) => {
@@ -40,8 +41,7 @@ tslib_1.__decorate([
40
41
  tslib_1.__metadata("design:paramtypes", [Object, Array]),
41
42
  tslib_1.__metadata("design:returntype", notification_1.Notification)
42
43
  ], NotificationSubscription.prototype, "notification", null);
43
- NotificationSubscription = tslib_1.__decorate([
44
+ exports.NotificationSubscription = NotificationSubscription = tslib_1.__decorate([
44
45
  (0, type_graphql_1.Resolver)(notification_1.Notification)
45
46
  ], NotificationSubscription);
46
- exports.NotificationSubscription = NotificationSubscription;
47
47
  //# sourceMappingURL=notification-subscription.js.map