@things-factory/notification 6.2.177 → 6.2.178
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/client/actions/notification-fcm.ts +3 -3
- package/dist-client/actions/notification-fcm.js.map +1 -1
- package/dist-client/bootstrap.js.map +1 -1
- package/dist-client/pages/notification/notification-list-page.js.map +1 -1
- package/dist-client/pages/notification-rule/notification-rule-importer.js.map +1 -1
- package/dist-client/pages/notification-rule/notification-rule-list-page.js.map +1 -1
- package/dist-client/reducers/notification.js.map +1 -1
- package/dist-client/route.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-client/viewparts/notification-badge.js.map +1 -1
- package/dist-client/viewparts/notification-item.js.map +1 -1
- package/dist-client/viewparts/notification-list.js.map +1 -1
- package/dist-client/viewparts/notification-sender.js.map +1 -1
- package/dist-client/viewparts/notification-setting-let.js.map +1 -1
- package/dist-server/controllers/fcm.d.ts +34 -0
- package/dist-server/controllers/fcm.js +5 -6
- package/dist-server/controllers/fcm.js.map +1 -1
- package/dist-server/controllers/index.d.ts +1 -0
- package/dist-server/index.d.ts +4 -0
- package/dist-server/middlewares/index.d.ts +1 -0
- package/dist-server/middlewares/index.js +1 -2
- package/dist-server/middlewares/index.js.map +1 -1
- package/dist-server/middlewares/notification-middleware.d.ts +1 -0
- package/dist-server/middlewares/notification-middleware.js +1 -2
- package/dist-server/middlewares/notification-middleware.js.map +1 -1
- package/dist-server/routers/notification-router.d.ts +1 -0
- package/dist-server/routes.d.ts +1 -0
- package/dist-server/service/index.d.ts +13 -0
- package/dist-server/service/notification/directive-notification.d.ts +3 -0
- package/dist-server/service/notification/directive-notification.js.map +1 -1
- package/dist-server/service/notification/index.d.ts +12 -0
- package/dist-server/service/notification/notification-mutation.d.ts +9 -0
- package/dist-server/service/notification/notification-mutation.js +2 -2
- package/dist-server/service/notification/notification-mutation.js.map +1 -1
- package/dist-server/service/notification/notification-query.d.ts +13 -0
- package/dist-server/service/notification/notification-query.js +2 -2
- package/dist-server/service/notification/notification-query.js.map +1 -1
- package/dist-server/service/notification/notification-subscription.d.ts +6 -0
- package/dist-server/service/notification/notification-subscription.js +2 -2
- package/dist-server/service/notification/notification-subscription.js.map +1 -1
- package/dist-server/service/notification/notification-type.d.ts +21 -0
- package/dist-server/service/notification/notification-type.js +6 -6
- package/dist-server/service/notification/notification-type.js.map +1 -1
- package/dist-server/service/notification/notification.d.ts +28 -0
- package/dist-server/service/notification/notification.js +3 -3
- package/dist-server/service/notification/notification.js.map +1 -1
- package/dist-server/service/notification-rule/event-subscriber.d.ts +7 -0
- package/dist-server/service/notification-rule/event-subscriber.js +2 -2
- package/dist-server/service/notification-rule/event-subscriber.js.map +1 -1
- package/dist-server/service/notification-rule/index.d.ts +7 -0
- package/dist-server/service/notification-rule/notification-rule-history.d.ts +28 -0
- package/dist-server/service/notification-rule/notification-rule-history.js +2 -2
- package/dist-server/service/notification-rule/notification-rule-history.js.map +1 -1
- package/dist-server/service/notification-rule/notification-rule-mutation.d.ts +10 -0
- package/dist-server/service/notification-rule/notification-rule-mutation.js +2 -2
- package/dist-server/service/notification-rule/notification-rule-mutation.js.map +1 -1
- package/dist-server/service/notification-rule/notification-rule-query.d.ts +12 -0
- package/dist-server/service/notification-rule/notification-rule-query.js +2 -2
- package/dist-server/service/notification-rule/notification-rule-query.js.map +1 -1
- package/dist-server/service/notification-rule/notification-rule-type.d.ts +27 -0
- package/dist-server/service/notification-rule/notification-rule-type.js +6 -6
- package/dist-server/service/notification-rule/notification-rule-type.js.map +1 -1
- package/dist-server/service/notification-rule/notification-rule.d.ts +34 -0
- package/dist-server/service/notification-rule/notification-rule.js +7 -8
- package/dist-server/service/notification-rule/notification-rule.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-badge.js","sourceRoot":"","sources":["../../client/viewparts/notification-badge.ts"],"names":[],"mappings":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,YAAY,CAAC,KAAK;QAChB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,YAAY,CAAC,KAAK,CAAA;IACvC,CAAC;;AAhDM,wBAAM,GAAG;IACd,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmCF;CACF,AArCY,CAqCZ;AAE2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;gDAAe;AAxC/B,iBAAiB;IAD7B,aAAa,CAAC,oBAAoB,CAAC;GACvB,iBAAiB,CAkD7B","sourcesContent":["import { LitElement, html, css } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { connect } from 'pwa-helpers/connect-mixin.js'\nimport { store } from '@operato/shell'\n\n@customElement('notification-badge')\nexport class NotificationBadge extends connect(store)(LitElement) {\n static styles = [\n css`\n :host {\n font-size: 2em;\n margin: 0 5px 0 0;\n --badge-size: 14px;\n }\n\n mwc-icon {\n display: block;\n }\n\n [data-badge] {\n position: relative;\n }\n\n [data-badge]::after {\n content: attr(data-badge);\n position: absolute;\n top: 0px;\n right: -6px;\n font-family: var(--theme-font);\n font-size: 0.4em;\n background: var(--paper-deep-orange-a400);\n color: var(--theme-white-color);\n width: var(--badge-size);\n height: var(--badge-size);\n text-align: center;\n line-height: var(--badge-size);\n border-radius: 50%;\n box-shadow: var(--box-shadow);\n }\n\n [data-badge='0']::after {\n display: none;\n }\n `\n ]\n\n @property({ type: Number }) badge?: number\n\n render() {\n var badge = this.badge || 0\n return html` <mwc-icon data-badge=${badge} class=\"badge\">notifications_none</mwc-icon> `\n }\n\n stateChanged(state) {\n this.badge = state.notification.badge\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-item.js","sourceRoot":"","sources":["../../client/viewparts/notification-item.ts"],"names":[],"mappings":";AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE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IAAI,EAAE,MAAM,EAAE,CAAC;;gDAAgB;AAC3C;IAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;gDAAiD;AAC5E;IAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;gDAAiB;AA9HlC,gBAAgB;IAD5B,aAAa,CAAC,mBAAmB,CAAC;GACtB,gBAAgB,CAgN5B;SAhNY,gBAAgB","sourcesContent":["import gql from 'graphql-tag'\nimport { LitElement, html, css } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport '@material/mwc-icon'\nimport { client } from '@operato/graphql'\n\nfunction isOriginSameAsLocation(url) {\n function defaultPort(protocol) {\n return { 'http:': 80, 'https:': 443 }[protocol]\n }\n\n function portOf(location) {\n return location.port || defaultPort(location.protocol || pageLocation.protocol)\n }\n\n try {\n var pageLocation = window.location\n var urlparts = new URL(url, pageLocation.href)\n\n return !!(\n urlparts.protocol &&\n urlparts.protocol == pageLocation.protocol &&\n urlparts.host &&\n urlparts.host == pageLocation.host &&\n urlparts.host &&\n portOf(urlparts) == portOf(pageLocation)\n )\n } catch (err) {\n console.warn(err, url)\n }\n}\n\n@customElement('notification-item')\nexport class NotificationItem extends LitElement {\n static styles = [\n css`\n :host {\n position: relative;\n background-color: var(--theme-white-color);\n padding: var(--padding-default);\n border-left: 0 solid transparent;\n border-bottom: var(--border-dark-color) !important;\n transition: border-left 300ms ease-in-out, padding-left 300ms ease-in-out;\n color: var(--scondary-color);\n\n --type-dot-size: 9px;\n }\n\n :host([newbie]) {\n background-color: var(--paper-light-green-50);\n }\n\n :host(:hover) {\n padding-left: 0.5rem;\n border-left: 0.5rem solid var(--status-info-color);\n }\n\n [titler] {\n white-space: normal;\n overflow: hidden;\n text-overflow: ellipsis;\n font-size: var(--fontsize-large);\n font-weight: bold;\n color: var(--secondary-color);\n }\n\n [titler] span {\n display: inline-block;\n width: var(--type-dot-size);\n height: var(--type-dot-size);\n border-radius: 50%;\n margin-right: var(--margin-narrow);\n }\n [titler] * {\n vertical-align: middle;\n }\n\n [close] {\n position: absolute;\n top: 13px;\n right: 0;\n font-size: var(--fontsize-large);\n opacity: 0.5;\n cursor: pointer;\n }\n [close]:hover {\n opacity: 1;\n }\n [detail] {\n padding: var(--padding-narrow) var(--padding-default);\n border-radius: var(--border-radius);\n font-size: 0.85em;\n }\n span.more {\n margin-left: 16px;\n float: right;\n padding: 0px var(--padding-narrow) 2px var(--padding-narrow);\n border-radius: var(--border-radius);\n font-size: 0.8em;\n color: var(--theme-white-color);\n --mdc-icon-size: 14px;\n }\n span.more * {\n vertical-align: middle;\n }\n\n :host([type='ERROR']) span {\n background-color: var(--status-danger-color);\n }\n :host([type='ERROR']) {\n border-color: var(--status-danger-color);\n }\n :host([type='ERROR']) [detail] {\n border: 1px solid rgba(241, 53, 63, 0.5);\n background-color: rgba(241, 53, 63, 0.1);\n }\n :host([type='WARN']) span {\n background-color: var(--status-warning-color);\n }\n :host([type='WARN']) {\n border-color: var(--status-warning-color);\n }\n :host([type='SUCCESS']) span {\n background-color: var(--status-success-color);\n }\n :host([type='SUCCESS']) {\n border-color: var(--status-success-color);\n }\n :host([type='INFO']) span,\n :host span {\n background-color: var(--status-info-color);\n }\n :host([type='INFO']) {\n border-color: var(--status-info-color);\n }\n\n img {\n display: block;\n max-width: 100%;\n margin: auto;\n }\n\n [message] {\n font-size: var(--fontsize-default);\n color: var(--secondary-color);\n }\n\n [timestamp] {\n white-space: nowrap;\n font-size: var(--fontsize-small);\n color: var(--secondary-text-color);\n }\n `\n ]\n\n @property({ type: String, reflect: true }) type?: string\n @property({ type: Object }) notification: any\n @property({ type: String }) target?: string\n @property({ type: Object }) detail?: { message: string; [key: string]: any }\n @property({ type: Boolean }) newbie?: boolean\n\n render() {\n const { title, url, image, timestamp, body } = this.notification\n const target = this.target\n const detail = this.detail\n const type = this.type\n\n return html`\n <div titler>\n <span></span>\n ${url\n ? target\n ? html`<a href=${url} target=${target}>${title}</a>`\n : html`<a href=${url}>${title}</a>`\n : title}\n </div>\n <mwc-icon close @click=${e => this.dispatchEvent(new CustomEvent('close'))}>close</mwc-icon>\n\n ${image\n ? url\n ? target\n ? html`<a href=${url} target=${target}><img src=${image} /></a>`\n : html`<a href=${url}><img src=${image} /></a>`\n : html`<img src=${image} />`\n : html``}\n <div message>${body}</div>\n ${type == 'ERROR'\n ? html`<div\n @click=${() => {\n this.decipherErrorCode()\n }}\n >\n <span class=\"more\"><mwc-icon>expand_circle_down</mwc-icon> more</span>\n </div>`\n : html``}\n ${detail ? html`<div detail>${detail.message}</div>` : html``}\n\n <div timestamp>${new Date(Number(timestamp)).toLocaleString()}</div>\n `\n }\n\n updated(changed) {\n if (!this.notification?.confirmed) {\n this.setAttribute('newbie', '')\n } else {\n this.removeAttribute('newbie')\n }\n\n const url = this.notification?.url\n this.target = url && !isOriginSameAsLocation(url) && '_blank'\n }\n\n async decipherErrorCode() {\n if (this.type != 'ERROR' || !this.notification) {\n return\n }\n\n const { title, body } = this.notification\n var code = `${title}`\n if (body) {\n code += `: ${body}`\n }\n\n const response = await client.query({\n query: gql`\n query ($input: CodeDecipherInput!) {\n decipherErrorCode(input: $input) {\n message\n }\n }\n `,\n variables: {\n input: {\n code,\n system: ''\n }\n }\n })\n\n this.detail = response.data.decipherErrorCode\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"notification-item.js","sourceRoot":"","sources":["../../client/viewparts/notification-item.ts"],"names":[],"mappings":";AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,oBAAoB,CAAA;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,SAAS,sBAAsB,CAAC,GAAG;IACjC,SAAS,WAAW,CAAC,QAAQ;QAC3B,OAAO,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OAAO,EAAE,CAAC;;gDAAiB;AA9HlC,gBAAgB;IAD5B,aAAa,CAAC,mBAAmB,CAAC;GACtB,gBAAgB,CAgN5B","sourcesContent":["import gql from 'graphql-tag'\nimport { LitElement, html, css } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport '@material/mwc-icon'\nimport { client } from '@operato/graphql'\n\nfunction isOriginSameAsLocation(url) {\n function defaultPort(protocol) {\n return { 'http:': 80, 'https:': 443 }[protocol]\n }\n\n function portOf(location) {\n return location.port || defaultPort(location.protocol || pageLocation.protocol)\n }\n\n try {\n var pageLocation = window.location\n var urlparts = new URL(url, pageLocation.href)\n\n return !!(\n urlparts.protocol &&\n urlparts.protocol == pageLocation.protocol &&\n urlparts.host &&\n urlparts.host == pageLocation.host &&\n urlparts.host &&\n portOf(urlparts) == portOf(pageLocation)\n )\n } catch (err) {\n console.warn(err, url)\n }\n}\n\n@customElement('notification-item')\nexport class NotificationItem extends LitElement {\n static styles = [\n css`\n :host {\n position: relative;\n background-color: var(--theme-white-color);\n padding: var(--padding-default);\n border-left: 0 solid transparent;\n border-bottom: var(--border-dark-color) !important;\n transition: border-left 300ms ease-in-out, padding-left 300ms ease-in-out;\n color: var(--scondary-color);\n\n --type-dot-size: 9px;\n }\n\n :host([newbie]) {\n background-color: var(--paper-light-green-50);\n }\n\n :host(:hover) {\n padding-left: 0.5rem;\n border-left: 0.5rem solid var(--status-info-color);\n }\n\n [titler] {\n white-space: normal;\n overflow: hidden;\n text-overflow: ellipsis;\n font-size: var(--fontsize-large);\n font-weight: bold;\n color: var(--secondary-color);\n }\n\n [titler] span {\n display: inline-block;\n width: var(--type-dot-size);\n height: var(--type-dot-size);\n border-radius: 50%;\n margin-right: var(--margin-narrow);\n }\n [titler] * {\n vertical-align: middle;\n }\n\n [close] {\n position: absolute;\n top: 13px;\n right: 0;\n font-size: var(--fontsize-large);\n opacity: 0.5;\n cursor: pointer;\n }\n [close]:hover {\n opacity: 1;\n }\n [detail] {\n padding: var(--padding-narrow) var(--padding-default);\n border-radius: var(--border-radius);\n font-size: 0.85em;\n }\n span.more {\n margin-left: 16px;\n float: right;\n padding: 0px var(--padding-narrow) 2px var(--padding-narrow);\n border-radius: var(--border-radius);\n font-size: 0.8em;\n color: var(--theme-white-color);\n --mdc-icon-size: 14px;\n }\n span.more * {\n vertical-align: middle;\n }\n\n :host([type='ERROR']) span {\n background-color: var(--status-danger-color);\n }\n :host([type='ERROR']) {\n border-color: var(--status-danger-color);\n }\n :host([type='ERROR']) [detail] {\n border: 1px solid rgba(241, 53, 63, 0.5);\n background-color: rgba(241, 53, 63, 0.1);\n }\n :host([type='WARN']) span {\n background-color: var(--status-warning-color);\n }\n :host([type='WARN']) {\n border-color: var(--status-warning-color);\n }\n :host([type='SUCCESS']) span {\n background-color: var(--status-success-color);\n }\n :host([type='SUCCESS']) {\n border-color: var(--status-success-color);\n }\n :host([type='INFO']) span,\n :host span {\n background-color: var(--status-info-color);\n }\n :host([type='INFO']) {\n border-color: var(--status-info-color);\n }\n\n img {\n display: block;\n max-width: 100%;\n margin: auto;\n }\n\n [message] {\n font-size: var(--fontsize-default);\n color: var(--secondary-color);\n }\n\n [timestamp] {\n white-space: nowrap;\n font-size: var(--fontsize-small);\n color: var(--secondary-text-color);\n }\n `\n ]\n\n @property({ type: String, reflect: true }) type?: string\n @property({ type: Object }) notification: any\n @property({ type: String }) target?: string\n @property({ type: Object }) detail?: { message: string; [key: string]: any }\n @property({ type: Boolean }) newbie?: boolean\n\n render() {\n const { title, url, image, timestamp, body } = this.notification\n const target = this.target\n const detail = this.detail\n const type = this.type\n\n return html`\n <div titler>\n <span></span>\n ${url\n ? target\n ? html`<a href=${url} target=${target}>${title}</a>`\n : html`<a href=${url}>${title}</a>`\n : title}\n </div>\n <mwc-icon close @click=${e => this.dispatchEvent(new CustomEvent('close'))}>close</mwc-icon>\n\n ${image\n ? url\n ? target\n ? html`<a href=${url} target=${target}><img src=${image} /></a>`\n : html`<a href=${url}><img src=${image} /></a>`\n : html`<img src=${image} />`\n : html``}\n <div message>${body}</div>\n ${type == 'ERROR'\n ? html`<div\n @click=${() => {\n this.decipherErrorCode()\n }}\n >\n <span class=\"more\"><mwc-icon>expand_circle_down</mwc-icon> more</span>\n </div>`\n : html``}\n ${detail ? html`<div detail>${detail.message}</div>` : html``}\n\n <div timestamp>${new Date(Number(timestamp)).toLocaleString()}</div>\n `\n }\n\n updated(changed) {\n if (!this.notification?.confirmed) {\n this.setAttribute('newbie', '')\n } else {\n this.removeAttribute('newbie')\n }\n\n const url = this.notification?.url\n this.target = url && !isOriginSameAsLocation(url) && '_blank'\n }\n\n async decipherErrorCode() {\n if (this.type != 'ERROR' || !this.notification) {\n return\n }\n\n const { title, body } = this.notification\n var code = `${title}`\n if (body) {\n code += `: ${body}`\n }\n\n const response = await client.query({\n query: gql`\n query ($input: CodeDecipherInput!) {\n decipherErrorCode(input: $input) {\n message\n }\n }\n `,\n variables: {\n input: {\n code,\n system: ''\n }\n }\n })\n\n this.detail = response.data.decipherErrorCode\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-list.js","sourceRoot":"","sources":["../../client/viewparts/notification-list.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAEjE,OAAO,oBAAoB,CAAA;AAC3B,OAAO,qBAAqB,CAAA;AAGrB,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,OAAO,CAAC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QAAQ,EAAC,EAAE;YAC/B,MAAM,OAAO,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,CAAA;YAEhD,QAAQ,CAAC;gBACP,IAAI,EAAE,mBAAmB;gBACzB,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC;aACtB,CAAC,CAAA;QACJ,CAAC,CAAQ,CAAC,CAAA;IACZ,CAAC;;AA7JM,uBAAM,GAAG;IACd,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4DF;CACF,AA9DY,CA8DZ;AAE0B;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;iDAAoB;AAjEnC,gBAAgB;IAD5B,aAAa,CAAC,mBAAmB,CAAC;GACtB,gBAAgB,CA+J5B","sourcesContent":["import { LitElement, html, css } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport { connect } from 'pwa-helpers'\nimport { store, notificationStore } from '@operato/shell'\nimport { i18next, localize } from '@operato/i18n'\nimport { UPDATE_NOTIFICATION } from '../actions/notification-fcm'\n\nimport '@material/mwc-icon'\nimport './notification-item'\n\n@customElement('notification-list')\nexport class NotificationList extends connect(store)(localize(i18next)(LitElement)) {\n static styles = [\n css`\n :host {\n display: block;\n background-color: var(--theme-white-color);\n box-shadow: var(--box-shadow);\n margin-right: var(--margin-wide);\n padding: var(--padding-default);\n max-height: 100%;\n overflow-x: hidden;\n overflow-y: auto;\n }\n :host::before {\n content: '';\n width: 0px;\n height: 0px;\n border-left: 7px solid transparent;\n border-right: 7px solid transparent;\n border-bottom: 7px solid var(--theme-white-color);\n position: absolute;\n margin-top: -7px;\n right: 50px;\n }\n\n [notifications-wrap] {\n display: flex;\n flex-direction: column;\n justify-content: flex-start;\n }\n [notifications-wrap] div {\n align-items: stretch;\n border-bottom: 1px solid var(--primary-color);\n }\n [notifications-wrap] strong {\n color: var(--primary-color);\n text-transform: capitalize;\n line-height: 2;\n }\n [notifications-wrap] mwc-button {\n float: right;\n --mdc-button-horizontal-padding: var(--padding-narrow);\n --mdc-typography-button-font-size: 0.75em;\n }\n [no-notifications] {\n margin: 0;\n padding: var(--padding-wide);\n text-align: center;\n font-size: var(--fontsize-default);\n font-weight: bold;\n color: var(--secondary-color);\n }\n div mwc-icon {\n display: block;\n opacity: 0.3;\n }\n @media screen and (max-width: 480px) {\n :host {\n height: 100%;\n width: 100vw;\n }\n }\n `\n ]\n\n @property({ type: Array }) history: any[] = []\n\n render() {\n var history = this.history.reverse()\n\n return history.length > 0\n ? html`\n <div notifications-wrap>\n <div>\n <strong>${i18next.t('label.notification list')}</strong>\n <mwc-button\n outlined\n dense\n label=${String(i18next.t('label.clear all'))}\n icon=\"delete_outline\"\n @click=${e => this.onclearall()}\n ></mwc-button>\n </div>\n ${history.map(\n notification => html`\n <notification-item\n @close=${e => {\n this.onClose(notification)\n }}\n .type=${notification.type}\n .notification=${notification}\n ></notification-item>\n `\n )}\n </div>\n `\n : html`\n <div no-notifications @click=${e => window.history.back()}>\n <mwc-icon>notifications_off</mwc-icon>${i18next.t('text.no notification available')}\n </div>\n `\n }\n\n onClose(notification) {\n const { id } = notification\n\n store.dispatch((async dispatch => {\n if (notification) {\n await notificationStore.delete(id)\n }\n\n const history = await notificationStore.getAll()\n\n dispatch({\n type: UPDATE_NOTIFICATION,\n history: [...history]\n })\n }) as any)\n }\n\n onclearall() {\n store.dispatch((async dispatch => {\n await notificationStore.clear()\n const history = await notificationStore.getAll()\n\n dispatch({\n type: UPDATE_NOTIFICATION,\n history: [...history]\n })\n }) as any)\n }\n\n stateChanged(state) {\n this.history = state.notification.history\n }\n\n async disconnectedCallback() {\n super.disconnectedCallback()\n\n await Promise.all(\n this.history\n .filter(notification => !notification.confirmed)\n .map(async notification => {\n return await notificationStore.put({\n ...notification,\n confirmed: true\n })\n })\n )\n\n store.dispatch((async dispatch => {\n const history = await notificationStore.getAll()\n\n dispatch({\n type: UPDATE_NOTIFICATION,\n history: [...history]\n })\n }) as any)\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-sender.js","sourceRoot":"","sources":["../../client/viewparts/notification-sender.ts"],"names":[],"mappings":";AAAA,OAAO,yBAAyB,CAAA;AAChC,OAAO,sBAAsB,CAAA;AAC7B,OAAO,wBAAwB,CAAA;AAC/B,OAAO,0BAA0B,CAAA;AAEjC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAY,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAA;AAC5D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAG9D,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;IA2CnE,MAAM;;QACJ,OAAO,IAAI,CAAA;;;;;;qBAMM,OAAO,CAAC,CAAC,CAAC,iBAAiB,CAAC;0BACvB,MAAA,IAAI,CAAC,UAAU,0CAAE,KAAK;;;;;;;qBAO3B,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC;;;;;;;;qBAQxB,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC;;;yDAGY,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC;yDACtB,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC;;;;;;;kDAO9B,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE;;;;qDAIf,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE;;;;;KAKnE,CAAA;IACH,CAAC;IAED,MAAM;QACJ,MAAM,CAAC,SAAS,EAAE,KAAK,EAAE,IA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AC,CAAC,CAAC,YAAY,CAAA;QAE1G,aAAa,CAAC;YACZ,SAAS;YACT,KAAK;YACL,IAAI;YACJ,KAAK;YACL,IAAI;YACJ,GAAG;SACJ,CAAC,CAAA;IACJ,CAAC;IAED,OAAO;QACL,CAAC;QAAA,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,GAAG,CACjD,GAAG,CAAC,EAAE,CAAC,CAAE,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,UAAU,GAAG,IAAI,CAAU,CAAC,KAAK,GAAG,EAAE,CAAC,CAC/E,CACA;QAAC,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,mBAAmB,CAAU,CAAC,OAAO,GAAG,KAAK,CAAA;IAC/E,CAAC;;AA7GM,yBAAM,GAAG;IACd,eAAe;IACf,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAqCF;CACF,AAxCY,CAwCZ;AAzCU,kBAAkB;IAD9B,aAAa,CAAC,qBAAqB,CAAC;GACxB,kBAAkB,CA+G9B","sourcesContent":["import '@material/mwc-formfield'\nimport '@material/mwc-button'\nimport '@material/mwc-checkbox'\nimport '@operato/i18n/ox-i18n.js'\n\nimport { css, html, LitElement } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport { auth } from '@things-factory/auth-base/dist-client'\nimport { i18next, localize } from '@operato/i18n'\nimport { ScrollbarStyles } from '@operato/styles'\n\nimport { notify as webpushNotify } from '../actions/notification-fcm'\n\n@customElement('notification-sender')\nexport class NotificationSender extends localize(i18next)(LitElement) {\n static styles = [\n ScrollbarStyles,\n css`\n :host {\n display: flex;\n background-color: var(--main-section-background-color);\n padding: var(--padding-wide);\n }\n\n form {\n flex: 1;\n display: flex;\n flex-direction: column;\n }\n [content] > * {\n margin: var(--margin-default);\n }\n\n [content] {\n flex: 1;\n flex-direction: column;\n display: flex;\n overflow: auto;\n }\n\n [buttons] {\n margin-top: auto;\n display: flex;\n flex-direction: row-reverse;\n }\n mwc-button {\n margin-left: var(--padding-default);\n }\n\n @media screen and (max-width: 480px) {\n :host {\n padding: var(--padding-default);\n }\n }\n `\n ]\n\n render() {\n return html`\n <form>\n <div content>\n <mwc-textfield\n type=\"text\"\n name=\"receivers\"\n .label=${i18next.t('field.receivers')}\n placeholder=${auth.credential?.email}\n required\n icon=\"account_circle\"\n ></mwc-textfield>\n <mwc-textfield\n type=\"text\"\n name=\"title\"\n .label=${i18next.t('field.title')}\n required\n icon=\"notifications_none\"\n ></mwc-textfield>\n\n <mwc-textfield\n type=\"text\"\n name=\"image\"\n .label=${i18next.t('field.image')}\n icon=\"insert_photo\"\n ></mwc-textfield>\n <mwc-textfield type=\"text\" name=\"url\" .label=${i18next.t('field.url')} icon=\"link\"></mwc-textfield>\n <mwc-textarea type=\"text\" name=\"body\" .label=${i18next.t('field.body')} required rows=\"5\"></mwc-textarea>\n <mwc-formfield label=\"In-App Message\">\n <mwc-checkbox name=\"inappmsg\"></mwc-checkbox>\n </mwc-formfield>\n </div>\n\n <div buttons>\n <mwc-button raised icon=\"send\" @click=${e => this.ontest()}>\n <ox-i18n msgid=\"button.notification-send\"> </ox-i18n>\n </mwc-button>\n\n <mwc-button type=\"reset\" outlined @click=${e => this.onReset()}>\n <ox-i18n msgid=\"button.reset\"> </ox-i18n>\n </mwc-button>\n </div>\n </form>\n `\n }\n\n ontest() {\n const [receivers, title, body, image, url] = ['receivers', 'title', 'body', 'image', 'url'].map(\n key => (this.renderRoot.querySelector(`[name=\"${key}\"]`)! as any).value\n )\n const mode = (this.renderRoot.querySelector(`[name=\"inappmsg\"]`)! as any).checked ? 'inapp' : 'background'\n\n webpushNotify({\n receivers,\n title,\n body,\n image,\n mode,\n url\n })\n }\n\n onReset() {\n ;['receivers', 'title', 'body', 'image', 'url'].map(\n key => ((this.renderRoot.querySelector(`[name=\"${key}\"]`)! as any).value = '')\n )\n ;(this.renderRoot.querySelector(`[name=\"inappmsg\"]`)! as any).checked = false\n }\n}\n"]}
|
|
@@ -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,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,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;IAkDvE,MAAM;QACJ,MAAM,SAAS,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAA;QAElC,OAAO,IAAI,CAAA;;;;UAIL,SAAS;YACT,CAAC,CAAC,IAAI,CAAA;;iCAEiB,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC;0DACpB,CAAC,CAAC,IAAI,CAAC,YAAY,WAAW,CAAC,CAAC,EAAE,CAC9E,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;;4CAES,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,WAAW,CAAC,CAAC,EAAE,CAC1F,IAAI,CAAC,MAAM,EAAE;;;;;wFAMf,IAAI,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,CAAC;GAC7B,sBAAsB,CA2LlC","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"]}
|
|
@@ -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.
|
|
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;AAEv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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;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":";;AA2BA,8BAOC;AAQD,4CASC;AAED,4BA2BC;AAED,gCAqBC;AAED,wBAsEC;;AA/KD,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,EAAE,SAAS,EAAE,GAAG,GAAG,IAAI,EAAE,CAAA;AAC1D,MAAM,EAAE,SAAS,EAAE,GAAG,QAAQ,IAAI,EAAE,CAAA;AAEpC,IAAI,SAAS,CAAA;AAEb,IAAI,cAAc,EAAE,CAAC;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAA,mBAAa,EAAC;YACxB,UAAU,EAAE,IAAA,UAAI,EAAC,cAAc,CAAC;SACjC,CAAC,CAAA;QAEF,SAAS,GAAG,IAAA,wBAAY,EAAC,GAAG,CAAC,CAAA;IAC/B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,YAAM,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAA;QACpD,YAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACnB,CAAC;AACH,CAAC;AAED,SAAgB,SAAS;IACvB,OAAO,SAAS;QACd,CAAC,CAAC;YACE,SAAS;YACT,cAAc,EAAE,SAAS;SAC1B;QACH,CAAC,CAAC,EAAE,CAAA;AACR,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,gBAAgB,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE;IAC3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AAE,kBAAkB;YAClC,aAAa,EAAE,OAAO,SAAS,EAAE;YACjC,UAAU,EAAE,SAAS,CAAC,iBAAiB;SACxC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;KAC3B,CAAC,CAAA;IAEF,IAAI,QAAQ,CAAC,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 @@
|
|
|
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 =
|
|
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":"
|
|
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 =
|
|
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":"
|
|
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,E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'\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
|
+
};
|
|
@@ -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,qBAAqB,GAAG,MAAA,IAAA,oBAAY,EAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,0CAAG,CAAC,CAAC,CAAA;QAC/E,IAAI,qBAAqB,EAAE;
|
|
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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C,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","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,KACR,OAAO,EAAE,IAAI,IACb,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC;IAIK,AAAN,KAAK,CAAC,0BAA0B,CACe,OAA4B,EAClE,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,IAAI,OAAO,GAAG,EAAE,CAAA;QAChB,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,CAAA;QACzF,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,CAAA;QACzF,MAAM,gBAAgB,GAAG,EAAE,CAAC,aAAa,CAAC,2BAAY,CAAC,CAAA;QAEvD,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;
|
|
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,C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E,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;+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')),
|
|
@@ -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;AACnH,yDAAgD;AAChD,iDAA6C;AAC7C,2DAAsD;AAG/C,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAEtB,AAAN,KAAK,CAAC,YAAY,CAAY,EAAU,EAAS,OAAwB;QACvE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEhC,OAAO,MAAM,IAAA,qBAAa,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A0B;QAC5C,OAAO,YAAY,CAAC,OAAO,IAAI,CAAC,MAAM,IAAA,qBAAa,EAAC,gBAAI,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;IACpG,CAAC;IAGK,AAAN,KAAK,CAAC,MAAM,CAAS,YAA0B;QAC7C,OAAO,YAAY,CAAC,QAAQ,IAAI,CAAC,MAAM,IAAA,qBAAa,EAAC,cAAM,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;IACxG,CAAC;IAGK,AAAN,KAAK,CAAC,OAAO,CAAS,YAA0B;QAC9C,OAAO,YAAY,CAAC,SAAS,IAAI,CAAC,MAAM,IAAA,qBAAa,EAAC,gBAAI,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;IACxG,CAAC;IAGK,AAAN,KAAK,CAAC,OAAO,CAAS,YAA0B;QAC9C,OAAO,YAAY,CAAC,SAAS,IAAI,CAAC,MAAM,IAAA,qBAAa,EAAC,gBAAI,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;IACxG,CAAC;CACF,CAAA;
|
|
1
|
+
{"version":3,"file":"notification-query.js","sourceRoot":"","sources":["../../../server/service/notification/notification-query.ts"],"names":[],"mappings":";;;;AAAA,+CAA8F;AAC9F,iDAAmH;AACnH,yDAAgD;AAChD,iDAA6C;AAC7C,2DAAsD;AAG/C,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAEtB,AAAN,KAAK,CAAC,YAAY,CAAY,EAAU,EAAS,OAAwB;QACvE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEhC,OAAO,MAAM,IAAA,qBAAa,EAAC,2BAAY,CAAC,CAAC,OAAO,CAAC;YAC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AAjB,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;4BA7DU,iBAAiB;IAD7B,IAAA,uBAAQ,EAAC,2BAAY,CAAC;GACV,iBAAiB,CA8D7B","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"]}
|