@jskit-ai/oidc-issuer-core 0.1.28 → 0.1.30
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/oidc-issuer-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.30",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -119,10 +119,10 @@
|
|
|
119
119
|
"oidc-provider": "9.12.2"
|
|
120
120
|
},
|
|
121
121
|
"devDependencies": {
|
|
122
|
-
"@jskit-ai/auth-provider-local-core": "0.2.
|
|
122
|
+
"@jskit-ai/auth-provider-local-core": "0.2.24"
|
|
123
123
|
},
|
|
124
124
|
"peerDependencies": {
|
|
125
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
126
|
-
"@jskit-ai/kernel": "0.2.
|
|
125
|
+
"@jskit-ai/database-runtime": "0.1.270",
|
|
126
|
+
"@jskit-ai/kernel": "0.2.21"
|
|
127
127
|
}
|
|
128
128
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"private": true,
|
|
3
3
|
"type": "module",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
6
|
-
"@jskit-ai/database-runtime-mysql": "0.1.
|
|
7
|
-
"@jskit-ai/oidc-issuer-core": "0.1.
|
|
5
|
+
"@jskit-ai/database-runtime": "0.1.270",
|
|
6
|
+
"@jskit-ai/database-runtime-mysql": "0.1.268",
|
|
7
|
+
"@jskit-ai/oidc-issuer-core": "0.1.30"
|
|
8
8
|
}
|
|
9
9
|
}
|
package/src/server/config.js
CHANGED
|
@@ -2,6 +2,7 @@ import { randomBytes } from "node:crypto";
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { isProductionEnv } from "@jskit-ai/kernel/server/runtime/runtimeMode";
|
|
5
|
+
import { sideEffectsAreLive } from "@jskit-ai/kernel/shared/support/sideEffects";
|
|
5
6
|
|
|
6
7
|
const LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
|
|
7
8
|
const MIN_SECRET_BYTES = 32;
|
|
@@ -112,7 +113,9 @@ function resolveMail(env, { isProduction }) {
|
|
|
112
113
|
return Object.freeze({
|
|
113
114
|
from,
|
|
114
115
|
resendApiKey,
|
|
115
|
-
smtpUrl
|
|
116
|
+
smtpUrl,
|
|
117
|
+
// A test copy (SIDE_EFFECTS is not live) logs each email instead of sending it, even with a sender configured.
|
|
118
|
+
live: sideEffectsAreLive(env)
|
|
116
119
|
});
|
|
117
120
|
}
|
|
118
121
|
|
package/src/server/hubRoutes.js
CHANGED
|
@@ -635,8 +635,9 @@ function registerAdminRoutes(app, hub, support) {
|
|
|
635
635
|
app.post("/hub/api/admin/setup/test-email", async (request) => {
|
|
636
636
|
const { account } = await requireOwner(request);
|
|
637
637
|
const locale = requestLocale(texts, request);
|
|
638
|
+
let delivery;
|
|
638
639
|
try {
|
|
639
|
-
await mailer.send({
|
|
640
|
+
delivery = await mailer.send({
|
|
640
641
|
to: account.email,
|
|
641
642
|
subject: texts.t(locale, "jskit.accounts.mail.test.subject"),
|
|
642
643
|
...composeMessage({
|
|
@@ -651,6 +652,10 @@ function registerAdminRoutes(app, hub, support) {
|
|
|
651
652
|
await settings.set("email-test", { ok: false, at: hub.now().toISOString() });
|
|
652
653
|
throw hubError(HUB_ERRORS.testEmailFailed, { reason: error.message });
|
|
653
654
|
}
|
|
655
|
+
// A test copy logged the email instead of sending it, which proves nothing about the sender.
|
|
656
|
+
if (delivery?.simulated) {
|
|
657
|
+
return { ok: true, simulated: true };
|
|
658
|
+
}
|
|
654
659
|
await settings.set("email-test", { ok: true, at: hub.now().toISOString() });
|
|
655
660
|
return { ok: true };
|
|
656
661
|
});
|
package/src/server/mailer.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { logSimulatedSideEffect } from "@jskit-ai/kernel/server/runtime/sideEffects";
|
|
1
2
|
import { escapeHtml } from "./http.js";
|
|
2
3
|
|
|
3
4
|
const RESEND_ENDPOINT = "https://api.resend.com/emails";
|
|
@@ -19,6 +20,8 @@ function composeMessage({ heading, body, actionLabel, actionUrl, footer }) {
|
|
|
19
20
|
* Sends the hub's emails with the owner's own sender: Resend when
|
|
20
21
|
* RESEND_API_KEY is set, otherwise SMTP_URL. Outside production, with neither
|
|
21
22
|
* set, messages are written to the log so the developer can follow the link.
|
|
23
|
+
* A test copy (SIDE_EFFECTS is not `live`) sends nothing: it logs each message,
|
|
24
|
+
* link included, and `send` answers `{ simulated: true }`.
|
|
22
25
|
* @param {object} dependencies
|
|
23
26
|
* @param {import("./types.js").HubConfig["mail"]} dependencies.mail
|
|
24
27
|
* @param {import("@jskit-ai/kernel/server/types").RuntimeLogger} dependencies.logger
|
|
@@ -47,11 +50,26 @@ function createMailer({ mail, logger, isProduction, fetchImpl }) {
|
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
52
|
|
|
53
|
+
/** @returns {Promise<{ simulated: boolean }>} */
|
|
50
54
|
async function send(message) {
|
|
51
|
-
if (mail.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
if (!mail.live) {
|
|
56
|
+
logSimulatedSideEffect(logger, {
|
|
57
|
+
kind: "email",
|
|
58
|
+
summary: `the accounts hub email "${message.subject}" to ${message.to}`,
|
|
59
|
+
details: { to: message.to, subject: message.subject, text: message.text }
|
|
60
|
+
});
|
|
61
|
+
return { simulated: true };
|
|
62
|
+
}
|
|
63
|
+
if (mail.from && mail.resendApiKey) {
|
|
64
|
+
await sendWithResend(message);
|
|
65
|
+
} else if (mail.from && mail.smtpUrl) {
|
|
66
|
+
await sendWithSmtp(message);
|
|
67
|
+
} else if (isProduction) {
|
|
68
|
+
throw new Error("The hub has no email sender.");
|
|
69
|
+
} else {
|
|
70
|
+
logger.info({ to: message.to, subject: message.subject }, `Accounts hub email (not sent: no sender configured)\n${message.text}`);
|
|
71
|
+
}
|
|
72
|
+
return { simulated: false };
|
|
55
73
|
}
|
|
56
74
|
|
|
57
75
|
return Object.freeze({
|