@things-factory/notification 10.1.248 → 10.1.254
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/controllers/fcm.d.ts +6 -10
- package/dist-server/controllers/fcm.js +73 -122
- package/dist-server/controllers/fcm.js.map +1 -1
- package/dist-server/controllers/notice/deliver-notice.d.ts +2 -2
- package/dist-server/controllers/notice/deliver-notice.js +4 -4
- package/dist-server/controllers/notice/deliver-notice.js.map +1 -1
- package/dist-server/controllers/notice/index.d.ts +0 -2
- package/dist-server/controllers/notice/index.js +0 -2
- package/dist-server/controllers/notice/index.js.map +1 -1
- package/dist-server/controllers/notice/notice-channels.d.ts +2 -6
- package/dist-server/controllers/notice/notice-channels.js +2 -9
- package/dist-server/controllers/notice/notice-channels.js.map +1 -1
- package/dist-server/controllers/notice/send-notice.js +1 -2
- package/dist-server/controllers/notice/send-notice.js.map +1 -1
- package/dist-server/middlewares/notification-middleware.d.ts +1 -0
- package/dist-server/middlewares/notification-middleware.js +11 -1
- package/dist-server/middlewares/notification-middleware.js.map +1 -1
- package/dist-server/service/index.d.ts +2 -1
- package/dist-server/service/index.js +4 -1
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/notification-token/index.d.ts +2 -0
- package/dist-server/service/notification-token/index.js +6 -0
- package/dist-server/service/notification-token/index.js.map +1 -0
- package/dist-server/service/notification-token/notification-token.d.ts +22 -0
- package/dist-server/service/notification-token/notification-token.js +64 -0
- package/dist-server/service/notification-token/notification-token.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/tests/notice-delivery.test.ts +1 -116
- package/tests/push-tokens.test.ts +190 -0
- package/dist-server/controllers/notice/app-brand.d.ts +0 -17
- package/dist-server/controllers/notice/app-brand.js +0 -61
- package/dist-server/controllers/notice/app-brand.js.map +0 -1
- package/dist-server/controllers/notice/notice-email.d.ts +0 -32
- package/dist-server/controllers/notice/notice-email.js +0 -153
- package/dist-server/controllers/notice/notice-email.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"notice-email.js","sourceRoot":"","sources":["../../../server/controllers/notice/notice-email.ts"],"names":[],"mappings":";;AAMA,gCAOC;AAWD,wCAcC;AAOD,oDAsBC;AAOD,0CAmGC;AA7KD,mCAA+B;AAE/B,iDAA0E;AAG1E,8FAA8F;AAC9F,SAAgB,UAAU,CAAC,KAAc;IACvC,OAAO,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AAC3B,CAAC;AAED,mFAAmF;AACnF,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAA;AAC9D,MAAM,OAAO,GAAG,0BAA0B,CAAA;AAE1C;;;;GAIG;AACH,SAAgB,cAAc,CAAC,IAA+B,EAAE,IAAa;IAC3E,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;IACrC,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAA;IAE1B,IAAI,GAAQ,CAAA;IACZ,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,IAAI,OAAO,CAAC,CAAA;IACrC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC;QAAE,OAAO,SAAS,CAAA;IACvD,IAAI,GAAG,CAAC,M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type AppBrand } from './app-brand.js'\nimport type { NoticeWords } from './notice-channels.js'\n\n/** Every value goes into the HTML through this - a subject like `<b>` or `A&B` stays text. */\nexport function escapeHtml(value: unknown): string {\n return String(value ?? '')\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''')\n}\n\n/** The schemes a link in a notice may take; anything else is shown as its text. */\nconst SAFE_PROTOCOLS = new Set(['http:', 'https:', 'mailto:'])\nconst NO_BASE = 'https://no-base.invalid/'\n\n/**\n * Where a link in a notice may go: http(s) and mailto as written, and an address of the app (no scheme) under `base`,\n * the domain's own address. With no base an app address has nowhere to go and is dropped, as is every other scheme -\n * `javascript:` in any spelling the URL parser reads as one.\n */\nexport function safeNoticeHref(href: string | null | undefined, base?: string): string | undefined {\n const raw = String(href ?? '').trim()\n if (!raw) return undefined\n\n let url: URL\n try {\n url = new URL(raw, base || NO_BASE)\n } catch {\n return undefined\n }\n\n if (!SAFE_PROTOCOLS.has(url.protocol)) return undefined\n if (url.origin === new URL(NO_BASE).origin) return undefined\n return url.href\n}\n\n/**\n * Markdown as mail HTML, rendered here on the server. Raw HTML in the text is shown as text, never as markup; a link or\n * an image becomes a link only to an address `safeNoticeHref` allows, and an image is not loaded - it is shown as a\n * link with its alt text, so a mail does not fetch from wherever its writer pointed.\n */\nexport function renderNoticeMarkdown(markdown: string, base?: string): string {\n const marked = new Marked({\n gfm: true,\n breaks: true,\n async: false,\n renderer: {\n html({ text }) {\n return escapeHtml(text)\n },\n link({ href, title, tokens }) {\n const label = this.parser.parseInline(tokens)\n const safe = safeNoticeHref(href, base)\n return safe ? `<a href=\"${escapeHtml(safe)}\"${title ? ` title=\"${escapeHtml(title)}\"` : ''}>${label}</a>` : label\n },\n image({ href, text }) {\n const safe = safeNoticeHref(href, base)\n return safe ? `<a href=\"${escapeHtml(safe)}\">${escapeHtml(text || safe)}</a>` : escapeHtml(text)\n }\n }\n })\n\n return marked.parse(String(markdown ?? '')) as string\n}\n\n/**\n * The notice mail (ADR-0164) - the head, band, button and foot of the auth mails, so a person knows the sender. The head\n * names the application that sends it with its tagline, and the band and button are in its brand colour (`appBrand`).\n * Without a link (a notice sent with no request to take the address from) the button gives way to the note.\n */\nexport function noticeEmailForm({\n lang,\n words,\n link,\n format = 'text',\n base,\n brand = DEFAULT_BRAND\n}: {\n lang: string\n words: NoticeWords\n link?: string\n /** How the body is written - an announcement's is Markdown. */\n format?: 'text' | 'markdown'\n /** The domain's address, under which an app address in a Markdown body is resolved. */\n base?: string\n /** The application sending it. */\n brand?: AppBrand\n}) {\n const color = escapeHtml(brand.color)\n const onColor = textColorOn(brand.color)\n /*\n * Laid out as tables, each colour on its cell as `bgcolor` as well as in its style: mail programs drop a box's\n * margins and backgrounds, and one in dark mode repaints what it was not told is light - so the mail says it is light.\n */\n const action = link\n ? `<table role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"border-collapse:separate\">\n <tr>\n <td bgcolor=\"${color}\" style=\"background-color:${color};border-radius:7px;padding:8px 16px\">\n <a href=\"${escapeHtml(link)}\" style=\"color:${onColor};font-size:18px;font-weight:bold;text-decoration:none\"\n ><font color=\"${onColor}\">${escapeHtml(words.action)}</font></a\n >\n </td>\n </tr>\n </table>`\n : `<span style=\"color:#555555\">${escapeHtml(words.note)}</span>`\n\n return `\n <html lang=\"${escapeHtml(lang)}\">\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"color-scheme\" content=\"light\" />\n <meta name=\"supported-color-schemes\" content=\"light\" />\n <title>${escapeHtml(words.subject)}</title>\n <meta name=\"author\" content=\"hatiolab\" />\n <meta name=\"google\" content=\"notranslate\"/>\n <style>:root { color-scheme: light; supported-color-schemes: light; }</style>\n </head>\n\n <body style=\"margin:0;padding:0\" bgcolor=\"#f6f6f6\">\n <table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" bgcolor=\"#f6f6f6\" style=\"background-color:#f6f6f6;border-collapse:collapse\">\n <!--header begin-->\n <tr>\n <td bgcolor=\"#ffffff\" style=\"background-color:#ffffff;border-top:2px solid ${color};padding:10px 20px\">\n <table role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tr>\n <td style=\"font-size:20px;font-weight:bold;color:#1f2933;white-space:nowrap\">${escapeHtml(brand.name)}</td>${\n brand.tagline\n ? `\n <td style=\"padding-left:12px;font-size:13px;color:#6b7280\"> ${escapeHtml(brand.tagline)}</td>`\n : ''\n }\n </tr>\n </table>\n </td>\n </tr>\n <!--header end-->\n\n <!--title begin-->\n <tr>\n <td bgcolor=\"${color}\" style=\"background-color:${color};padding:14px 20px 12px 60px;color:${onColor};font-size:24px;font-weight:bold\"\n ><font color=\"${onColor}\">${escapeHtml(words.subject)}</font></td\n >\n </tr>\n <!--title end-->\n\n <!--body begin-->\n <tr>\n <td style=\"padding:10px 20px;line-height:1.5;font-size:16px;color:#1f2933\">${\n format === 'markdown' ? renderNoticeMarkdown(words.body, base) : `<div style=\"white-space:pre-line\">${escapeHtml(words.body)}</div>`\n }</td>\n </tr>\n <tr>\n <td style=\"padding:6px 20px 20px 20px;font-size:16px\">\n ${action}\n </td>\n </tr>\n <!--body end-->\n\n <!--footer begin-->\n <tr>\n <td bgcolor=\"#3d5874\" style=\"background-color:#3d5874;padding:8px 20px 6px 20px;font-size:12px;color:#efefef\"\n ><font color=\"#efefef\">© Hatio, Lab. Inc. All rights reserved.</font></td\n >\n </tr>\n <!--footer end-->\n </table>\n </body>\n </html>\n `\n}\n"]}
|