@protobase/server 0.124.2 → 0.125.0
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/better-auth/auth-settings.d.ts +56 -70
- package/dist/better-auth/auth-settings.js +6 -1
- package/dist/better-auth/create-auth.d.ts +59 -69
- package/dist/better-auth/create-auth.js +15 -11
- package/dist/better-auth/names/modules/index.d.ts +83 -0
- package/dist/better-auth/names/modules/mail-senders.js +130 -69
- package/dist/better-auth/staff-checks.js +1 -1
- package/dist/better-auth/store/steps/index.js +3 -1
- package/dist/better-auth/store/steps/legacy-versions.js +4 -0
- package/dist/better-auth/store/steps/mail-senders/004-sender-verifications.js +41 -0
- package/dist/create-admin.js +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -3
- package/dist/locale/en.js +1 -5
- package/dist/locale/nl.js +1 -5
- package/dist/package.js +1 -1
- package/dist/personal-mail/listed-mail-senders.d.ts +16 -0
- package/dist/personal-mail/listed-mail-senders.js +18 -6
- package/dist/personal-mail/mail-sender.d.ts +1 -0
- package/dist/personal-mail/mail-sender.js +1 -1
- package/dist/personal-mail/mail-senders-plugin.js +44 -46
- package/dist/personal-mail/personal-mailer.js +7 -2
- package/dist/personal-mail/sender-address-state.js +8 -5
- package/dist/personal-mail/sender-store.d.ts +2 -1
- package/dist/personal-mail/verifiers/report-endpoint.js +40 -0
- package/dist/personal-mail/verifiers/sender-address-verifier.d.ts +62 -0
- package/dist/personal-mail/verifiers/sender-verifications.d.ts +6 -0
- package/dist/personal-mail/verifiers/sender-verifications.js +28 -0
- package/dist/personal-mail/verifiers/start-verification.d.ts +4 -0
- package/dist/personal-mail/verifiers/start-verification.js +34 -0
- package/dist/personal-mail/verifiers/verification-outcome.js +49 -0
- package/dist/personal-mail/verifiers/verification-secret.js +8 -0
- package/dist/personal-mail/verifiers/verification-store.d.ts +17 -0
- package/dist/personal-mail/verifiers/verification-store.js +130 -0
- package/dist/personal-mail/verifiers/verification-sweep.js +45 -0
- package/dist/personal-mail/verifiers/verifier-list.js +26 -0
- package/dist/personal-mail/verifiers/verify-tools.js +30 -0
- package/dist/webhooks/attempt.js +1 -1
- package/dist/webhooks/table/webhooks-module.d.ts +2 -2
- package/dist/workflows/workflows-module.d.ts +2 -2
- package/package.json +6 -6
- package/dist/personal-mail/alias-checks.d.ts +0 -14
- package/dist/personal-mail/alias-checks.js +0 -29
- package/dist/personal-mail/mail-check-service.js +0 -41
- package/dist/personal-mail/mail-check-settings.js +0 -18
- package/dist/personal-mail/mail-check-signing.d.ts +0 -10
- package/dist/personal-mail/mail-check-signing.js +0 -13
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/personal-mail/verifiers/verifier-list.ts
|
|
2
|
+
const idPattern = /^[a-z][a-z0-9_.-]{0,63}$/;
|
|
3
|
+
/**
|
|
4
|
+
* The verifiers of one app, as its trusted code adds them with `add_verifier` while the app starts: each id once, in
|
|
5
|
+
* lowercase letters, digits, `_`, `.` and `-`, as verifications store it. Once `freeze` is called, as the app's auth is
|
|
6
|
+
* built, `add_verifier` refuses.
|
|
7
|
+
*/
|
|
8
|
+
const senderVerifierList = () => {
|
|
9
|
+
const verifiers = [];
|
|
10
|
+
let frozen = false;
|
|
11
|
+
const add_verifier = (verifier) => {
|
|
12
|
+
if (frozen) throw new Error(`add_verifier: "${verifier.id}" comes after the app started; add verifiers while it starts`);
|
|
13
|
+
if (!idPattern.test(verifier.id)) throw new Error(`add_verifier: the id "${verifier.id}" must be lowercase letters, digits, "_", "." or "-", starting with a letter, at most 64 characters`);
|
|
14
|
+
if (verifiers.some(({ id }) => id === verifier.id)) throw new Error(`add_verifier: two verifiers have the id "${verifier.id}"`);
|
|
15
|
+
verifiers.push(verifier);
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
add_verifier,
|
|
19
|
+
freeze: () => {
|
|
20
|
+
frozen = true;
|
|
21
|
+
return [...verifiers];
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { senderVerifierList };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as z$1 from "zod";
|
|
2
|
+
//#region src/personal-mail/verifiers/verify-tools.ts
|
|
3
|
+
const message = z$1.object({
|
|
4
|
+
to: z$1.email(),
|
|
5
|
+
subject: z$1.string().min(1).max(998),
|
|
6
|
+
text: z$1.string(),
|
|
7
|
+
html: z$1.string().optional()
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* The tools of one `verify` of the address record `senderId`: `send` goes through `mail`, its owner's mailbox, From that
|
|
11
|
+
* record, to one recipient, once. Only `to`, `subject`, `text` and `html` are read, so a From, a Sender, copies, header
|
|
12
|
+
* fields or attachments a verifier passes never reach the message.
|
|
13
|
+
*/
|
|
14
|
+
const verifyTools = (mail, senderId) => {
|
|
15
|
+
let sent = false;
|
|
16
|
+
return { send: async (given) => {
|
|
17
|
+
if (sent) throw new Error("A verification sends one test message; verify called tools.send again");
|
|
18
|
+
const { to, subject, text, html } = message.parse(given);
|
|
19
|
+
sent = true;
|
|
20
|
+
await mail.send({
|
|
21
|
+
sender_address_id: senderId,
|
|
22
|
+
to,
|
|
23
|
+
subject,
|
|
24
|
+
text,
|
|
25
|
+
...html !== void 0 && { html }
|
|
26
|
+
});
|
|
27
|
+
} };
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { verifyTools };
|
package/dist/webhooks/attempt.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { standardWebhookHeaders } from "./standard-webhooks.js";
|
|
2
1
|
import { AddressRefusedError, pinnedRequest } from "./table/pinned-request.js";
|
|
3
2
|
import { readLimited } from "./table/read-limited.js";
|
|
4
3
|
import { invokeFunction } from "../functions/define-function.js";
|
|
5
4
|
import { retryAfterMs } from "./retry-schedule.js";
|
|
5
|
+
import { standardWebhookHeaders } from "./standard-webhooks.js";
|
|
6
6
|
import { subscriberSession } from "./subscriber-view.js";
|
|
7
7
|
//#region src/webhooks/attempt.ts
|
|
8
8
|
/** How long a receiver has to answer. */
|
|
@@ -84,7 +84,7 @@ export declare const webhooksModule: (options?: WebhooksOptions) => {
|
|
|
84
84
|
readonly tenant_id: import("@protobase/schema").Field<string | null>;
|
|
85
85
|
readonly event_type: import("@protobase/schema").Field<string>;
|
|
86
86
|
readonly event_id: import("@protobase/schema").Field<string>;
|
|
87
|
-
readonly status: import("@protobase/schema").Field<"
|
|
87
|
+
readonly status: import("@protobase/schema").Field<"waiting" | "failed">;
|
|
88
88
|
readonly attempt: import("@protobase/schema").Field<number>;
|
|
89
89
|
readonly next_attempt: import("@protobase/schema").Field<string | null>;
|
|
90
90
|
readonly last_error: import("@protobase/schema").Field<string | null>;
|
|
@@ -97,7 +97,7 @@ export declare const webhooksModule: (options?: WebhooksOptions) => {
|
|
|
97
97
|
readonly tenant_id: import("@protobase/schema").Field<string | null>;
|
|
98
98
|
readonly event_type: import("@protobase/schema").Field<string>;
|
|
99
99
|
readonly event_id: import("@protobase/schema").Field<string>;
|
|
100
|
-
readonly status: import("@protobase/schema").Field<"
|
|
100
|
+
readonly status: import("@protobase/schema").Field<"waiting" | "failed">;
|
|
101
101
|
readonly attempt: import("@protobase/schema").Field<number>;
|
|
102
102
|
readonly next_attempt: import("@protobase/schema").Field<string | null>;
|
|
103
103
|
readonly last_error: import("@protobase/schema").Field<string | null>;
|
|
@@ -280,7 +280,7 @@ export declare const workflowsModule: (options?: Pick<WorkflowsOptions, "schema"
|
|
|
280
280
|
readonly version: import("@protobase/schema").Field<number | null>;
|
|
281
281
|
readonly input: import("@protobase/schema").Field<import("zod").JSONType>;
|
|
282
282
|
readonly key: import("@protobase/schema").Field<string | null>;
|
|
283
|
-
readonly status: import("@protobase/schema").Field<"
|
|
283
|
+
readonly status: import("@protobase/schema").Field<"waiting" | "failed" | "queued" | "running" | "succeeded">;
|
|
284
284
|
readonly output: import("@protobase/schema").Field<import("zod").JSONType>;
|
|
285
285
|
readonly error: import("@protobase/schema").Field<string | null>;
|
|
286
286
|
readonly cause: import("@protobase/schema").Field<string | null>;
|
|
@@ -306,7 +306,7 @@ export declare const workflowsModule: (options?: Pick<WorkflowsOptions, "schema"
|
|
|
306
306
|
readonly version: import("@protobase/schema").Field<number | null>;
|
|
307
307
|
readonly input: import("@protobase/schema").Field<import("zod").JSONType>;
|
|
308
308
|
readonly key: import("@protobase/schema").Field<string | null>;
|
|
309
|
-
readonly status: import("@protobase/schema").Field<"
|
|
309
|
+
readonly status: import("@protobase/schema").Field<"waiting" | "failed" | "queued" | "running" | "succeeded">;
|
|
310
310
|
readonly output: import("@protobase/schema").Field<import("zod").JSONType>;
|
|
311
311
|
readonly error: import("@protobase/schema").Field<string | null>;
|
|
312
312
|
readonly cause: import("@protobase/schema").Field<string | null>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.125.0",
|
|
4
4
|
"description": "The Protobase REST API as a Hono app, with Better Auth sign-in.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"@better-auth/sso": "^1.7.12",
|
|
45
45
|
"@livekit/protocol": "1.53.1",
|
|
46
46
|
"@modelcontextprotocol/server": "^2.3.1",
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/workflow-plugins": "0.
|
|
51
|
-
"@protobase/workflows": "0.
|
|
47
|
+
"@protobase/layout": "0.125.0",
|
|
48
|
+
"@protobase/query": "0.125.0",
|
|
49
|
+
"@protobase/schema": "0.125.0",
|
|
50
|
+
"@protobase/workflow-plugins": "0.125.0",
|
|
51
|
+
"@protobase/workflows": "0.125.0",
|
|
52
52
|
"@react-email/render": "^2.1.0",
|
|
53
53
|
"@react-pdf/primitives": "^4.4.0",
|
|
54
54
|
"@react-pdf/renderer": "^4.9.0",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import "./personal-mailer.js";
|
|
2
|
-
import { Locale } from "@protobase/schema/internal";
|
|
3
|
-
//#region src/personal-mail/alias-checks.d.ts
|
|
4
|
-
/** Where a check of a From address stands: its test message has not arrived yet, or arrived from that address, or from another. */
|
|
5
|
-
export type AliasCheckResult = {
|
|
6
|
-
status: 'waiting';
|
|
7
|
-
} | {
|
|
8
|
-
status: 'confirmed';
|
|
9
|
-
from: string;
|
|
10
|
-
} | {
|
|
11
|
-
status: 'mismatch';
|
|
12
|
-
from: string;
|
|
13
|
-
};
|
|
14
|
-
//#endregion
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { messages } from "../locale/messages.js";
|
|
2
|
-
//#region src/personal-mail/alias-checks.ts
|
|
3
|
-
const text = messages("personal-mail");
|
|
4
|
-
const aliasChecks = (service, mailOf) => ({
|
|
5
|
-
start: async (userId, { id, address }, locale) => {
|
|
6
|
-
const { token, address: to } = await service.issue();
|
|
7
|
-
const say = text(locale);
|
|
8
|
-
await mailOf(userId).send({
|
|
9
|
-
sender_address_id: id,
|
|
10
|
-
to,
|
|
11
|
-
subject: say("ALIAS_CHECK_SUBJECT", { address }),
|
|
12
|
-
text: say("ALIAS_CHECK_TEXT", { address })
|
|
13
|
-
});
|
|
14
|
-
return token;
|
|
15
|
-
},
|
|
16
|
-
result: async (token, address) => {
|
|
17
|
-
const from = await service.received(token);
|
|
18
|
-
if (from === void 0) return { status: "waiting" };
|
|
19
|
-
return from.toLowerCase() === address.toLowerCase() ? {
|
|
20
|
-
status: "confirmed",
|
|
21
|
-
from
|
|
22
|
-
} : {
|
|
23
|
-
status: "mismatch",
|
|
24
|
-
from
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
//#endregion
|
|
29
|
-
export { aliasChecks };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { mailCheckHeaders } from "./mail-check-signing.js";
|
|
2
|
-
import * as z$1 from "zod";
|
|
3
|
-
//#region src/personal-mail/mail-check-service.ts
|
|
4
|
-
/** The calls of the mail check service, under the URL the platform names. */
|
|
5
|
-
const mailCheckPaths = (url) => ({
|
|
6
|
-
issue: `${url}/alias-checks`,
|
|
7
|
-
result: `${url}/alias-checks/result`
|
|
8
|
-
});
|
|
9
|
-
const issued = z$1.object({
|
|
10
|
-
token: z$1.string().min(1),
|
|
11
|
-
address: z$1.email()
|
|
12
|
-
});
|
|
13
|
-
const result = z$1.union([z$1.object({ received: z$1.literal(false) }), z$1.object({
|
|
14
|
-
received: z$1.literal(true),
|
|
15
|
-
from: z$1.string().min(1)
|
|
16
|
-
})]);
|
|
17
|
-
const mailCheckService = ({ url, platformSecret }, fetcher = (...args) => fetch(...args)) => {
|
|
18
|
-
const paths = mailCheckPaths(url);
|
|
19
|
-
const call = async (path, payload) => {
|
|
20
|
-
const body = JSON.stringify(payload);
|
|
21
|
-
const response = await fetcher(path, {
|
|
22
|
-
method: "POST",
|
|
23
|
-
headers: {
|
|
24
|
-
...await mailCheckHeaders(platformSecret, crypto.randomUUID(), body),
|
|
25
|
-
"content-type": "application/json"
|
|
26
|
-
},
|
|
27
|
-
body
|
|
28
|
-
});
|
|
29
|
-
if (!response.ok) throw new Error(`The mail check service answered ${response.status} ${response.statusText} to ${path}`);
|
|
30
|
-
return response.json();
|
|
31
|
-
};
|
|
32
|
-
return {
|
|
33
|
-
issue: async () => issued.parse(await call(paths.issue, {})),
|
|
34
|
-
received: async (token) => {
|
|
35
|
-
const answer = result.parse(await call(paths.result, { token }));
|
|
36
|
-
return answer.received ? answer.from : void 0;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
//#endregion
|
|
41
|
-
export { mailCheckPaths, mailCheckService };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { checkedUrl } from "../checked-url.js";
|
|
2
|
-
//#region src/personal-mail/mail-check-settings.ts
|
|
3
|
-
const mailCheckVariable = "PROTOBASE_MAIL_CHECK_URL";
|
|
4
|
-
/**
|
|
5
|
-
* The mail check service the platform names in `PROTOBASE_MAIL_CHECK_URL`, with `PROTOBASE_SECRET` to sign the calls;
|
|
6
|
-
* without either, From addresses are not checked. A value that is no http(s) URL stops startup, naming the variable.
|
|
7
|
-
*/
|
|
8
|
-
const readMailCheckSettings = (env) => {
|
|
9
|
-
const url = env[mailCheckVariable]?.trim();
|
|
10
|
-
if (!url) return;
|
|
11
|
-
if (!env.PROTOBASE_SECRET) throw new Error(`${mailCheckVariable} signs its calls with the app's secret: set PROTOBASE_SECRET too`);
|
|
12
|
-
return {
|
|
13
|
-
url: checkedUrl(url, mailCheckVariable),
|
|
14
|
-
platformSecret: env.PROTOBASE_SECRET
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
//#endregion
|
|
18
|
-
export { mailCheckVariable, readMailCheckSettings };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
//#region src/personal-mail/mail-check-signing.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* The Standard Webhooks secret an app signs its calls to the mail check service with, derived from the platform
|
|
4
|
-
* secret (`PROTOBASE_SECRET`) by HKDF, so no other use of that secret signs one and the secret itself never travels.
|
|
5
|
-
* The service derives the same one from the app's secret and checks a call with `verifyStandardWebhook`.
|
|
6
|
-
*/
|
|
7
|
-
export declare const mailCheckSecret: (platformSecret: string) => string;
|
|
8
|
-
/** The headers that sign one call to the mail check service: `id`, unique per call, and the JSON `body`. */
|
|
9
|
-
export declare const mailCheckHeaders: (platformSecret: string, id: string, body: string, now?: () => number) => Promise<Record<string, string>>;
|
|
10
|
-
//#endregion
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { standardWebhookHeaders } from "../webhooks/standard-webhooks.js";
|
|
2
|
-
import { hkdfSync } from "node:crypto";
|
|
3
|
-
//#region src/personal-mail/mail-check-signing.ts
|
|
4
|
-
/**
|
|
5
|
-
* The Standard Webhooks secret an app signs its calls to the mail check service with, derived from the platform
|
|
6
|
-
* secret (`PROTOBASE_SECRET`) by HKDF, so no other use of that secret signs one and the secret itself never travels.
|
|
7
|
-
* The service derives the same one from the app's secret and checks a call with `verifyStandardWebhook`.
|
|
8
|
-
*/
|
|
9
|
-
const mailCheckSecret = (platformSecret) => `whsec_${Buffer.from(hkdfSync("sha256", platformSecret, /* @__PURE__ */ new Uint8Array(0), "protobase mail alias check", 32)).toString("base64")}`;
|
|
10
|
-
/** The headers that sign one call to the mail check service: `id`, unique per call, and the JSON `body`. */
|
|
11
|
-
const mailCheckHeaders = (platformSecret, id, body, now = Date.now) => standardWebhookHeaders(id, Math.floor(now() / 1e3), body, mailCheckSecret(platformSecret));
|
|
12
|
-
//#endregion
|
|
13
|
-
export { mailCheckHeaders, mailCheckSecret };
|