@columenlabs/lumen-people 0.1.84 → 0.1.86

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/email.js +20 -5
  2. package/package.json +2 -2
package/dist/email.js CHANGED
@@ -60,12 +60,27 @@ export async function sendResend(c, msg) {
60
60
  });
61
61
  if (!res)
62
62
  return { ok: false, detail: 'Could not reach the email server' };
63
- await res.body?.cancel();
64
- if (res.status >= 300 && res.status < 400)
63
+ if (res.ok) {
64
+ await res.body?.cancel();
65
+ return { ok: true, detail: `Emailed ${msg.to}` };
66
+ }
67
+ if (res.status >= 300 && res.status < 400) {
68
+ await res.body?.cancel();
65
69
  return { ok: false, detail: redirected(res) };
66
- return res.ok
67
- ? { ok: true, detail: `Emailed ${msg.to}` }
68
- : { ok: false, detail: refused(res.status) };
70
+ }
71
+ const why = await serverSays(res);
72
+ return { ok: false, detail: why ? `${refused(res.status)}: ${why}` : refused(res.status) };
73
+ }
74
+ /** The server's own reason in a Resend-style error body (`message` or `error`), short and on one line. */
75
+ async function serverSays(res) {
76
+ const body = (await res.json().catch(() => null));
77
+ const said = typeof body?.message === 'string'
78
+ ? body.message
79
+ : typeof body?.error === 'string'
80
+ ? body.error
81
+ : '';
82
+ const line = said.replace(/\s+/g, ' ').trim();
83
+ return line ? (line.length > 200 ? `${line.slice(0, 199)}…` : line) : null;
69
84
  }
70
85
  export const resendMailer = (c) => (msg) => sendResend(c, msg);
71
86
  /** Reached the server and key accepted, from one request that cannot send: an empty email to
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@columenlabs/lumen-people",
3
- "version": "0.1.84",
3
+ "version": "0.1.86",
4
4
  "description": "Lumen's people, access and invites on the server: the rules, a SQL store, single-use invite links, a pluggable mailer and the routes the People screens call.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -52,6 +52,6 @@
52
52
  "registry": "https://registry.npmjs.org/"
53
53
  },
54
54
  "dependencies": {
55
- "@columenlabs/lumen-ui-types": "0.1.84"
55
+ "@columenlabs/lumen-ui-types": "0.1.86"
56
56
  }
57
57
  }