@columenlabs/lumen-people 0.1.67 → 0.1.69
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/email.js +13 -0
- package/dist/routes.js +6 -3
- package/package.json +2 -2
package/dist/email.js
CHANGED
|
@@ -30,6 +30,15 @@ async function call(c, path, init) {
|
|
|
30
30
|
return { res: null, ms: Date.now() - t0 };
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
+
/** A 3xx: the address leads to a sign-in page (Cloudflare Access, a login proxy), not the API. */
|
|
34
|
+
const redirected = (res) => {
|
|
35
|
+
let to = '';
|
|
36
|
+
try {
|
|
37
|
+
to = new URL(res.headers.get('location') ?? '').host;
|
|
38
|
+
}
|
|
39
|
+
catch { }
|
|
40
|
+
return `The address redirects${to ? ` to ${to}` : ''} (a sign-in page?), not to the email API`;
|
|
41
|
+
};
|
|
33
42
|
const refused = (status) => status === 401 || status === 403
|
|
34
43
|
? 'The server refused the API key'
|
|
35
44
|
: status === 400 || status === 422
|
|
@@ -52,6 +61,8 @@ export async function sendResend(c, msg) {
|
|
|
52
61
|
if (!res)
|
|
53
62
|
return { ok: false, detail: 'Could not reach the email server' };
|
|
54
63
|
await res.body?.cancel();
|
|
64
|
+
if (res.status >= 300 && res.status < 400)
|
|
65
|
+
return { ok: false, detail: redirected(res) };
|
|
55
66
|
return res.ok
|
|
56
67
|
? { ok: true, detail: `Emailed ${msg.to}` }
|
|
57
68
|
: { ok: false, detail: refused(res.status) };
|
|
@@ -65,6 +76,8 @@ async function reachAndKey(c, where) {
|
|
|
65
76
|
return [{ id: 'reach', ok: false, text: `Could not reach ${where}`, ms }];
|
|
66
77
|
await res.body?.cancel();
|
|
67
78
|
const reach = { id: 'reach', ok: true, text: `Reached ${where}`, ms };
|
|
79
|
+
if (res.status >= 300 && res.status < 400)
|
|
80
|
+
return [{ ...reach, ok: false, text: redirected(res) }];
|
|
68
81
|
if (res.status === 404 || res.status === 405)
|
|
69
82
|
return [{ ...reach, ok: false, text: `${where} has no email API at this address` }];
|
|
70
83
|
if (res.status === 401 || res.status === 403)
|
package/dist/routes.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* be same-origin JSON: a signed-in browser session is a cookie, so a foreign page's form or fetch
|
|
9
9
|
* is refused before it reaches a rule.
|
|
10
10
|
*/
|
|
11
|
-
import { levelLabel, levelOf, } from '@columenlabs/lumen-ui-types/people';
|
|
11
|
+
import { levelLabel, levelOf, normEmail, } from '@columenlabs/lumen-ui-types/people';
|
|
12
12
|
import { checkResend, emailView, resolveDraft, storedMailer, testResend, } from './email.js';
|
|
13
13
|
import { inviteTemplate } from './mailer.js';
|
|
14
14
|
const HEADERS = { 'content-type': 'application/json', 'cache-control': 'no-store' };
|
|
@@ -255,16 +255,19 @@ export function peopleRoutes(o) {
|
|
|
255
255
|
if (!r.ok)
|
|
256
256
|
return fail(r.error);
|
|
257
257
|
if (m === 'POST' && (parts[1] === 'check' || parts[1] === 'test') && parts.length === 2) {
|
|
258
|
+
const to = draft.testTo ? normEmail(draft.testTo) : actor.email;
|
|
259
|
+
if (!to)
|
|
260
|
+
return fail('Enter one email address to send the test to.');
|
|
258
261
|
const res = parts[1] === 'check'
|
|
259
262
|
? await checkResend(r.config, r.where)
|
|
260
|
-
: await testResend(r.config, r.where,
|
|
263
|
+
: await testResend(r.config, r.where, to, o.appName);
|
|
261
264
|
const t = { ...res, by: actor.email };
|
|
262
265
|
await email.store.putTest?.(req, t);
|
|
263
266
|
await people.log(via, {
|
|
264
267
|
kind: 'mail',
|
|
265
268
|
op: t.kind,
|
|
266
269
|
target: 'Email',
|
|
267
|
-
detail: `${t.kind === 'test' ?
|
|
270
|
+
detail: `${t.kind === 'test' ? `Test email to ${to}` : 'Connection check'} ${t.ok ? 'passed' : 'failed'} · ${r.where}`,
|
|
268
271
|
...(t.ok ? {} : { refused: t.steps.find((s) => s.ok === false)?.text ?? 'failed' }),
|
|
269
272
|
});
|
|
270
273
|
return json(t);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@columenlabs/lumen-people",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.69",
|
|
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.
|
|
55
|
+
"@columenlabs/lumen-ui-types": "0.1.69"
|
|
56
56
|
}
|
|
57
57
|
}
|