gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchf7-hookseee0b513|||PR ident#34 part: test-hook classes replaced by name/element/attribute selectors (tests adjusted), the shared lead/message/notice looks are statics in styles.hlmref7-hooks/lib/mail.hl

3.7 KB

  1. // lib/mail.hl — THE MAILER. One hl:smtp Mailer, configured from `.env` beside project.hl
  2. // (SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD, SMTP_FROM; the real environment
  3. // outranks the file). A send is non-blocking: the SMTP conversation runs on the
  4. // mailer's thread and its outcome arrives on the event loop (logged below).
  5. //
  6. // IDENT_MAIL_SINK names a file that receives the mail INSTEAD of the SMTP server: one
  7. // line `<address> <code>` is APPENDED per code (invitations: `<sink>.invites`, notification mails: `<sink>.mail`). The dev server and the gate use it, so
  8. // no real mail is sent until SMTP is configured for mail.byrod.in (see README).
  9. //
  10. // Handlers belong to instances: project.hl constructs this file once (`mail = new Mail()`).
  11. import { Mailer } from 'hl:smtp'
  12. import { envString } from './util.hl'
  13. import { writeFile, readFile, exists } from 'hl:fs'
  14. static NL = '
  15. '
  16. // An unconfigured dev setup gets the placeholder host 127.0.0.1 (the Mailer must exist:
  17. // `mailer.deliver()` and the `on mailer.…` handlers below); with the sink set nothing is ever
  18. // sent through it. SMTP_FROM's default is a real sender, not a placeholder — kept (mission 035).
  19. static smtpHost = envString('SMTP_HOST', null)
  20. static mailer = new Mailer(smtpHost != null ? smtpHost : '127.0.0.1', toNumber(envString('SMTP_PORT', '587')), {
  21. user = envString('SMTP_USER', null)
  22. pass = envString('SMTP_PASSWORD', null)
  23. sender = envString('SMTP_FROM', '[email protected]')
  24. })
  25. static sink = envString('IDENT_MAIL_SINK', null)
  26. static sendCode = (email, code) => {
  27. if (sink != null) {
  28. before = exists(sink) ? readFile(sink) : ''
  29. writeFile(sink, before + email + ' ' + code + NL)
  30. return 0
  31. }
  32. if (smtpHost == null) {
  33. console.warn('mail: NOT SENT to ' + email + ' — neither IDENT_MAIL_SINK nor SMTP_HOST is set')
  34. return 0
  35. }
  36. return mailer.send({
  37. to = email
  38. subject = 'Your ident login code: ' + code
  39. text = 'Hi,
  40. your one-time login code for worldapi is ' + code + '
  41. It is valid for 10 minutes and works once. If you did not ask for it, ignore this mail.
  42. '
  43. })
  44. }
  45. // AN INVITATION MAIL (ident#22). With the sink set, the line `<address> <link>` goes to
  46. // `<sink>.invites` (a second file: the code reader of the gates keeps its own format).
  47. static sendInvite = (email, link, appName, project, role, days) => {
  48. if (sink != null) {
  49. f = sink + '.invites'
  50. before = exists(f) ? readFile(f) : ''
  51. writeFile(f, before + email + ' ' + link + NL)
  52. return 0
  53. }
  54. if (smtpHost == null) {
  55. console.warn('mail: invitation NOT SENT to ' + email + ' — neither IDENT_MAIL_SINK nor SMTP_HOST is set')
  56. return 0
  57. }
  58. return mailer.send({
  59. to = email
  60. subject = 'You are invited to ' + project + ' (' + appName + ')'
  61. text = 'Hi,
  62. you are invited to ' + project + ' in ' + appName + ' (role: ' + role + ').
  63. Open this link to join with ident:
  64. ' + link + '
  65. The link works for ' + days + ' days. If you were not expecting it, ignore this mail.
  66. '
  67. })
  68. }
  69. // A NOTIFICATION MAIL (ident#7, lib/delivery.hl: the daily mail at 17:00 and urgent ones at once). With the sink set,
  70. // one JSON line `{ to, subject, text }` per mail goes to `<sink>.mail` (the gates read it; never real mail).
  71. static sendNotificationMail = (email, subject, text) => {
  72. if (sink != null) {
  73. f = sink + '.mail'
  74. before = exists(f) ? readFile(f) : ''
  75. writeFile(f, before + JSON.stringify({ to = email subject = subject text = text }) + NL)
  76. return 0
  77. }
  78. if (smtpHost == null) {
  79. console.warn('mail: notification mail NOT SENT to ' + email + ' — neither IDENT_MAIL_SINK nor SMTP_HOST is set')
  80. return 0
  81. }
  82. return mailer.send({ to = email subject = subject text = text })
  83. }
  84. mailer.deliver()
  85. on mailer.sent(r) { console.log('mail: sent', r.id, r.to, r.message) }
  86. on mailer.failed(r) { console.warn('mail: FAILED', r.id, r.to, r.stage, r.code, r.message) }

Branches

Latest commits

  • eee0b513|||PR ident#34 part: test-hook classes replaced by name/element/attribute selectors (tests adjusted), the shared lead/message/notice looks are statics in styles.hlmre
  • ccd6d0c4ident#34: browser gate: rowButton finds the row's button by namemre
  • 24dd414eident#34: the shared lead, message and notice looks are statics in components/styles.hl, imported by the components (lib/looks.hl gone)mre
  • 03ed26c7ident#34: access.hl: the remaining lead classes droppedmre
  • 1d066c42ident#34: access.hl drops its unstyled lead class (the shared lead rule would otherwise mute it)mre
  • 1e1dd7b4ident#34: the access page keeps its lead class string (the page has no ident-card, so its lead line was never muted; a shared rule would change the look)mre
  • 89ac6553ident#34: the lead, message and notice lines are named with Style.pLead / pMessage / pNotice (shared bodies in lib/looks.hl) instead of class stringsmre
  • e84be3deident#34: browser gate lists the Edit/Delete buttons by namemre
  • fb7111faident#34: access page: unstyled test-hook classes (idrow, never, who, whoname, appname, neverrevoke) dropped; the tests use element/name selectorsmre
  • 9f2ad803ident#34: notification switches: push/email by name=..., locked by aria-disabled, the switch look is the role=switch button (no switch/push/email/locked classes)mre
  • e0f0ddaaident#34: inbox: the Mark read/unread button is styled as the button of its note-foot, the icon is found as the row's img (no toggle/icon classes)mre
  • 16b49756ident#34: unused row classes (choice, usedrow, kind, shortid) droppedmre
  • f9d6fb38ident#34: apps and identity rows: the Edit/New secret/Delete buttons carry name=..., the API key is found by its element; unused row classes (app, identity, shortid) droppedmre
  • b323265aMerge branch 'f5-styles' into mainIdent
  • 9ced53c3|||PR ident#33 ident#35 every component's styles live in its own Style block; styles.hl keeps the page-wide rest; the account bar is phone first (min-width: 60rem block); the avatar preview is hidden with the hidden attribute (ident#34 in part)mre
  • f28333e4ident#33 ident#35: styles.hl keeps only the accent, the page column and the shared patterns; the account bar is written phone first (base rule + one min-width: 60rem block) instead of a max-width overridemre
  • 5b4541fcident#33: the selector sign-in frame's rules move into embed.hl's Stylemre
  • 00235f21ident#33: the per-app notification switches move into appsettings.hl's Stylemre
  • 2249945cident#33: the inbox and connection list rules move into inbox.hl's Stylemre
  • f2d9f79fident#33: the apps list and the secret box move into apps.hl's Stylemre