ident
All repositories: gitoria
3.7 KB
// lib/mail.hl — THE MAILER. One hl:smtp Mailer, configured from `.env` beside project.hl// (SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD, SMTP_FROM; the real environment// outranks the file). A send is non-blocking: the SMTP conversation runs on the// mailer's thread and its outcome arrives on the event loop (logged below).//// IDENT_MAIL_SINK names a file that receives the mail INSTEAD of the SMTP server: one// line `<address> <code>` is APPENDED per code (invitations: `<sink>.invites`, notification mails: `<sink>.mail`). The dev server and the gate use it, so// no real mail is sent until SMTP is configured for mail.byrod.in (see README).//// Handlers belong to instances: project.hl constructs this file once (`mail = new Mail()`).import { Mailer } from 'hl:smtp'import { envString } from './util.hl'import { writeFile, readFile, exists } from 'hl:fs'static NL = ''// An unconfigured dev setup gets the placeholder host 127.0.0.1 (the Mailer must exist:// `mailer.deliver()` and the `on mailer.…` handlers below); with the sink set nothing is ever// sent through it. SMTP_FROM's default is a real sender, not a placeholder — kept (mission 035).static smtpHost = envString('SMTP_HOST', null)static mailer = new Mailer(smtpHost != null ? smtpHost : '127.0.0.1', toNumber(envString('SMTP_PORT', '587')), {user = envString('SMTP_USER', null)pass = envString('SMTP_PASSWORD', null)sender = envString('SMTP_FROM', '[email protected]')})static sink = envString('IDENT_MAIL_SINK', null)static sendCode = (email, code) => {if (sink != null) {before = exists(sink) ? readFile(sink) : ''writeFile(sink, before + email + ' ' + code + NL)return 0}if (smtpHost == null) {console.warn('mail: NOT SENT to ' + email + ' — neither IDENT_MAIL_SINK nor SMTP_HOST is set')return 0}return mailer.send({to = emailsubject = 'Your ident login code: ' + codetext = 'Hi,your one-time login code for worldapi is ' + code + 'It is valid for 10 minutes and works once. If you did not ask for it, ignore this mail.'})}// AN INVITATION MAIL (ident#22). With the sink set, the line `<address> <link>` goes to// `<sink>.invites` (a second file: the code reader of the gates keeps its own format).static sendInvite = (email, link, appName, project, role, days) => {if (sink != null) {f = sink + '.invites'before = exists(f) ? readFile(f) : ''writeFile(f, before + email + ' ' + link + NL)return 0}if (smtpHost == null) {console.warn('mail: invitation NOT SENT to ' + email + ' — neither IDENT_MAIL_SINK nor SMTP_HOST is set')return 0}return mailer.send({to = emailsubject = 'You are invited to ' + project + ' (' + appName + ')'text = 'Hi,you are invited to ' + project + ' in ' + appName + ' (role: ' + role + ').Open this link to join with ident:' + link + 'The link works for ' + days + ' days. If you were not expecting it, ignore this mail.'})}// A NOTIFICATION MAIL (ident#7, lib/delivery.hl: the daily mail at 17:00 and urgent ones at once). With the sink set,// one JSON line `{ to, subject, text }` per mail goes to `<sink>.mail` (the gates read it; never real mail).static sendNotificationMail = (email, subject, text) => {if (sink != null) {f = sink + '.mail'before = exists(f) ? readFile(f) : ''writeFile(f, before + JSON.stringify({ to = email subject = subject text = text }) + NL)return 0}if (smtpHost == null) {console.warn('mail: notification mail NOT SENT to ' + email + ' — neither IDENT_MAIL_SINK nor SMTP_HOST is set')return 0}return mailer.send({ to = email subject = subject text = text })}mailer.deliver()on mailer.sent(r) { console.log('mail: sent', r.id, r.to, r.message) }on mailer.failed(r) { console.warn('mail: FAILED', r.id, r.to, r.stage, r.code, r.message) }
Branches
Latest commits
- ddc7d135Merge branch 'f7-hooks' into mainIdent
- 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