@protobase/server 0.15.5 → 0.16.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.
Files changed (41) hide show
  1. package/dist/app-name.js +9 -0
  2. package/dist/better-auth/auth-mail/account-exists-email.d.ts +1 -0
  3. package/dist/better-auth/auth-mail/account-exists-email.js +31 -0
  4. package/dist/better-auth/auth-mail/auth-email-layout.js +90 -0
  5. package/dist/better-auth/auth-mail/auth-emails.d.ts +7 -0
  6. package/dist/better-auth/auth-mail/auth-emails.js +8 -0
  7. package/dist/better-auth/auth-mail/invitation-email.d.ts +1 -0
  8. package/dist/better-auth/auth-mail/invitation-email.js +38 -0
  9. package/dist/better-auth/auth-mail/mailing-app.js +11 -0
  10. package/dist/better-auth/auth-mail/reset-password-email.d.ts +1 -0
  11. package/dist/better-auth/auth-mail/reset-password-email.js +35 -0
  12. package/dist/better-auth/auth-mail/send-auth-email.d.ts +1 -0
  13. package/dist/better-auth/auth-mail/send-auth-email.js +15 -0
  14. package/dist/better-auth/auth-mail/sign-in-code-email.d.ts +1 -0
  15. package/dist/better-auth/auth-mail/sign-in-code-email.js +32 -0
  16. package/dist/better-auth/auth-mail/sign-up-code-email.d.ts +1 -0
  17. package/dist/better-auth/auth-mail/sign-up-code-email.js +32 -0
  18. package/dist/better-auth/auth-mail/staff-sign-in-email.d.ts +1 -0
  19. package/dist/better-auth/auth-mail/staff-sign-in-email.js +39 -0
  20. package/dist/better-auth/auth-mail/two-factor-code-email.d.ts +1 -0
  21. package/dist/better-auth/auth-mail/two-factor-code-email.js +32 -0
  22. package/dist/better-auth/create-auth.d.ts +43 -181
  23. package/dist/better-auth/create-auth.js +24 -11
  24. package/dist/better-auth/organizations/organization-plugin.js +8 -8
  25. package/dist/better-auth/password-reset.js +8 -21
  26. package/dist/better-auth/sign-in-mail.js +14 -55
  27. package/dist/better-auth/sign-up/sign-up-code.js +2 -1
  28. package/dist/better-auth/sign-up/sign-up-plugin.d.ts +2 -0
  29. package/dist/better-auth/sign-up/sign-up-plugin.js +37 -22
  30. package/dist/better-auth/sign-up/sign-up-ticket.js +34 -0
  31. package/dist/better-auth/staff-plugin.js +2 -2
  32. package/dist/better-auth/staff-sign-in-endpoints.js +5 -6
  33. package/dist/check-views.js +5 -0
  34. package/dist/index.d.ts +1 -1
  35. package/dist/mail/platform-mailer.js +10 -3
  36. package/dist/mail/smtp-mailer.js +6 -2
  37. package/dist/view-access.js +6 -1
  38. package/dist/view-map.js +12 -2
  39. package/package.json +5 -4
  40. package/dist/better-auth/organizations/invitation-mail.js +0 -17
  41. package/dist/better-auth/sign-up/sign-up-mail.js +0 -29
@@ -0,0 +1,9 @@
1
+ //#region src/app-name.ts
2
+ const appNameVariable = "PROTOBASE_APP_NAME";
3
+ /**
4
+ * The app's name the platform passes in `PROTOBASE_APP_NAME`, such as `Property Finder`; `undefined` when it is not
5
+ * set. Protobase names the app with it in sign-in prompts and in the mail it sends, unless the app names itself.
6
+ */
7
+ const readAppName = (env) => env["PROTOBASE_APP_NAME"]?.trim() || void 0;
8
+ //#endregion
9
+ export { appNameVariable, readAppName };
@@ -0,0 +1 @@
1
+ import "../../index.js";
@@ -0,0 +1,31 @@
1
+ import { defineEmail } from "../../mail/define-email.js";
2
+ import { AuthEmailLayout, EmailButton, EmailNote } from "./auth-email-layout.js";
3
+ import { signInPath } from "@protobase/schema";
4
+ import { Text } from "react-email";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ //#region src/better-auth/auth-mail/account-exists-email.tsx
7
+ const AccountExistsEmail = ({ app }) => /* @__PURE__ */ jsxs(AuthEmailLayout, {
8
+ app,
9
+ preview: `Sign in to ${app.name} with this address instead`,
10
+ heading: "You already have an account",
11
+ children: [
12
+ /* @__PURE__ */ jsxs(Text, { children: [
13
+ "Someone asked to create an account with ",
14
+ app.name,
15
+ " for this address. It has one already, so no new account was made."
16
+ ] }),
17
+ /* @__PURE__ */ jsxs(EmailButton, {
18
+ href: new URL(signInPath(), app.url).href,
19
+ children: ["Sign in to ", app.name]
20
+ }),
21
+ /* @__PURE__ */ jsx(EmailNote, { children: "If this was not you, ignore this email: your account stays as it is." })
22
+ ]
23
+ });
24
+ /** The email to an address that asked for a sign-up code while it has an account already: no code, a link to sign in instead. */
25
+ const accountExistsEmail = defineEmail({
26
+ name: "account-exists",
27
+ subject: ({ app }) => `You already have an account with ${app.name}`,
28
+ component: AccountExistsEmail
29
+ });
30
+ //#endregion
31
+ export { accountExistsEmail };
@@ -0,0 +1,90 @@
1
+ import { Body, Button, Container, Head, Heading, Hr, Html, Link, Preview, Text } from "react-email";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ //#region src/better-auth/auth-mail/auth-email-layout.tsx
4
+ const styles = {
5
+ body: {
6
+ backgroundColor: "#f4f4f5",
7
+ fontFamily: "Helvetica, Arial, sans-serif",
8
+ color: "#18181b"
9
+ },
10
+ container: {
11
+ backgroundColor: "#ffffff",
12
+ padding: "24px",
13
+ maxWidth: "480px"
14
+ },
15
+ heading: { fontSize: "20px" },
16
+ rule: { borderColor: "#e4e4e7" },
17
+ footer: {
18
+ color: "#71717a",
19
+ fontSize: "13px",
20
+ margin: "0"
21
+ },
22
+ footerLink: { color: "#71717a" },
23
+ note: {
24
+ color: "#71717a",
25
+ fontSize: "13px"
26
+ },
27
+ code: {
28
+ fontFamily: "Menlo, Consolas, monospace",
29
+ fontSize: "28px",
30
+ fontWeight: 600,
31
+ letterSpacing: "4px",
32
+ margin: "16px 0"
33
+ },
34
+ button: {
35
+ backgroundColor: "#0f766e",
36
+ color: "#ffffff",
37
+ padding: "12px 20px",
38
+ borderRadius: "6px",
39
+ fontWeight: 600
40
+ }
41
+ };
42
+ /** An auth email: its heading and body on a card, and a footer naming the app, linked to its home page. */
43
+ const AuthEmailLayout = ({ app, preview, heading, children }) => /* @__PURE__ */ jsxs(Html, {
44
+ lang: "en",
45
+ children: [
46
+ /* @__PURE__ */ jsx(Head, {}),
47
+ /* @__PURE__ */ jsx(Preview, { children: preview }),
48
+ /* @__PURE__ */ jsx(Body, {
49
+ style: styles.body,
50
+ children: /* @__PURE__ */ jsxs(Container, {
51
+ style: styles.container,
52
+ children: [
53
+ /* @__PURE__ */ jsx(Heading, {
54
+ as: "h1",
55
+ style: styles.heading,
56
+ children: heading
57
+ }),
58
+ children,
59
+ /* @__PURE__ */ jsx(Hr, { style: styles.rule }),
60
+ /* @__PURE__ */ jsx(Text, {
61
+ style: styles.footer,
62
+ children: /* @__PURE__ */ jsx(Link, {
63
+ href: app.url,
64
+ style: styles.footerLink,
65
+ children: app.name
66
+ })
67
+ })
68
+ ]
69
+ })
70
+ })
71
+ ]
72
+ });
73
+ /** A code to type in, on a line of its own in both parts. */
74
+ const EmailCode = ({ code }) => /* @__PURE__ */ jsx(Text, {
75
+ style: styles.code,
76
+ children: code
77
+ });
78
+ /** A remark below the message, such as what to do when the email was not expected. */
79
+ const EmailNote = ({ children }) => /* @__PURE__ */ jsx(Text, {
80
+ style: styles.note,
81
+ children
82
+ });
83
+ /** The email's one action, such as signing in: a button, and the label with the link in the plain-text part. */
84
+ const EmailButton = ({ href, children }) => /* @__PURE__ */ jsx(Button, {
85
+ href,
86
+ style: styles.button,
87
+ children
88
+ });
89
+ //#endregion
90
+ export { AuthEmailLayout, EmailButton, EmailCode, EmailNote };
@@ -0,0 +1,7 @@
1
+ import "./account-exists-email.js";
2
+ import "./invitation-email.js";
3
+ import "./reset-password-email.js";
4
+ import "./sign-in-code-email.js";
5
+ import "./sign-up-code-email.js";
6
+ import "./staff-sign-in-email.js";
7
+ import "./two-factor-code-email.js";
@@ -0,0 +1,8 @@
1
+ import { accountExistsEmail } from "./account-exists-email.js";
2
+ import { invitationEmail } from "./invitation-email.js";
3
+ import { resetPasswordEmail } from "./reset-password-email.js";
4
+ import { signInCodeEmail } from "./sign-in-code-email.js";
5
+ import { signUpCodeEmail } from "./sign-up-code-email.js";
6
+ import { staffSignInEmail } from "./staff-sign-in-email.js";
7
+ import { twoFactorCodeEmail } from "./two-factor-code-email.js";
8
+ export { accountExistsEmail, invitationEmail, resetPasswordEmail, signInCodeEmail, signUpCodeEmail, staffSignInEmail, twoFactorCodeEmail };
@@ -0,0 +1 @@
1
+ import "../../index.js";
@@ -0,0 +1,38 @@
1
+ import { defineEmail } from "../../mail/define-email.js";
2
+ import { AuthEmailLayout, EmailButton, EmailNote } from "./auth-email-layout.js";
3
+ import { Text } from "react-email";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ //#region src/better-auth/auth-mail/invitation-email.tsx
6
+ const InvitationEmail = ({ app, inviter, organization, url, expiresAt }) => /* @__PURE__ */ jsxs(AuthEmailLayout, {
7
+ app,
8
+ preview: `${inviter} invites you to join ${organization}`,
9
+ heading: `Join ${organization}`,
10
+ children: [
11
+ /* @__PURE__ */ jsxs(Text, { children: [
12
+ inviter,
13
+ " invites you to join ",
14
+ organization,
15
+ " on ",
16
+ app.name,
17
+ ". To accept, open this link:"
18
+ ] }),
19
+ /* @__PURE__ */ jsx(EmailButton, {
20
+ href: url,
21
+ children: "Accept the invitation"
22
+ }),
23
+ /* @__PURE__ */ jsxs(Text, { children: [
24
+ "The link works until ",
25
+ expiresAt.toUTCString(),
26
+ "."
27
+ ] }),
28
+ /* @__PURE__ */ jsx(EmailNote, { children: "If you do not want to join, ignore this email: nothing happens without you." })
29
+ ]
30
+ });
31
+ /** The invitation email: who invites whom to which organization, the link, and until when it works. */
32
+ const invitationEmail = defineEmail({
33
+ name: "invitation",
34
+ subject: ({ organization, app }) => `Join ${organization} on ${app.name}`,
35
+ component: InvitationEmail
36
+ });
37
+ //#endregion
38
+ export { invitationEmail };
@@ -0,0 +1,11 @@
1
+ //#region src/better-auth/auth-mail/mailing-app.ts
2
+ /**
3
+ * The app as an auth email names it: `appName`, and the home page on the origin of `requestURL`, a URL on the origin
4
+ * the request came to (such as Better Auth's `ctx.context.baseURL`), or on `baseURL`'s origin without one.
5
+ */
6
+ const mailingApp = ({ appName, baseURL }, requestURL) => ({
7
+ name: appName,
8
+ url: new URL("/", requestURL ?? baseURL).href
9
+ });
10
+ //#endregion
11
+ export { mailingApp };
@@ -0,0 +1 @@
1
+ import "../../index.js";
@@ -0,0 +1,35 @@
1
+ import { defineEmail } from "../../mail/define-email.js";
2
+ import { AuthEmailLayout, EmailButton, EmailNote } from "./auth-email-layout.js";
3
+ import { Text } from "react-email";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ //#region src/better-auth/auth-mail/reset-password-email.tsx
6
+ const ResetPasswordEmail = ({ app, url, lifetime }) => /* @__PURE__ */ jsxs(AuthEmailLayout, {
7
+ app,
8
+ preview: `Choose a new password for ${app.name}`,
9
+ heading: "Reset your password",
10
+ children: [
11
+ /* @__PURE__ */ jsxs(Text, { children: [
12
+ "Someone asked to reset the password of your account with ",
13
+ app.name,
14
+ ". To choose a new password, open this link:"
15
+ ] }),
16
+ /* @__PURE__ */ jsx(EmailButton, {
17
+ href: url,
18
+ children: "Choose a new password"
19
+ }),
20
+ /* @__PURE__ */ jsxs(Text, { children: [
21
+ "The link works for ",
22
+ lifetime,
23
+ ", once."
24
+ ] }),
25
+ /* @__PURE__ */ jsx(EmailNote, { children: "If you did not ask for this, ignore this email: your password stays as it is." })
26
+ ]
27
+ });
28
+ /** The reset email: the link, how long it works, and that it can be ignored. */
29
+ const resetPasswordEmail = defineEmail({
30
+ name: "reset-password",
31
+ subject: ({ app }) => `Reset your ${app.name} password`,
32
+ component: ResetPasswordEmail
33
+ });
34
+ //#endregion
35
+ export { resetPasswordEmail };
@@ -0,0 +1 @@
1
+ import "./auth-emails.js";
@@ -0,0 +1,15 @@
1
+ import { mailingApp } from "./mailing-app.js";
2
+ //#region src/better-auth/auth-mail/send-auth-email.ts
3
+ /**
4
+ * Renders the auth email `name` for `data`, with the app it comes from on the origin of `requestURL` (see `mailingApp`),
5
+ * and sends it to `to`. The templates, and React Email with them, are imported on the first auth email sent, so
6
+ * starting the server loads neither.
7
+ */
8
+ const sendAuthEmail = async (mail, name, to, data, requestURL) => {
9
+ await (await import("./auth-emails.js"))[name].send(to, {
10
+ ...data,
11
+ app: mailingApp(mail, requestURL)
12
+ }, mail.mailer);
13
+ };
14
+ //#endregion
15
+ export { sendAuthEmail };
@@ -0,0 +1 @@
1
+ import "../../index.js";
@@ -0,0 +1,32 @@
1
+ import { defineEmail } from "../../mail/define-email.js";
2
+ import { AuthEmailLayout, EmailCode, EmailNote } from "./auth-email-layout.js";
3
+ import { Text } from "react-email";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ //#region src/better-auth/auth-mail/sign-in-code-email.tsx
6
+ const SignInCodeEmail = ({ app, code, lifetime }) => /* @__PURE__ */ jsxs(AuthEmailLayout, {
7
+ app,
8
+ preview: `Your code to sign in to ${app.name}`,
9
+ heading: "Your sign-in code",
10
+ children: [
11
+ /* @__PURE__ */ jsxs(Text, { children: [
12
+ "Use this code to sign in to ",
13
+ app.name,
14
+ ":"
15
+ ] }),
16
+ /* @__PURE__ */ jsx(EmailCode, { code }),
17
+ /* @__PURE__ */ jsxs(Text, { children: [
18
+ "It works for ",
19
+ lifetime,
20
+ ", once."
21
+ ] }),
22
+ /* @__PURE__ */ jsx(EmailNote, { children: "If you did not try to sign in, ignore this email: nobody can sign in without the code." })
23
+ ]
24
+ });
25
+ /** The email with a code to sign in with instead of a password. */
26
+ const signInCodeEmail = defineEmail({
27
+ name: "sign-in-code",
28
+ subject: ({ app }) => `Your ${app.name} sign-in code`,
29
+ component: SignInCodeEmail
30
+ });
31
+ //#endregion
32
+ export { signInCodeEmail };
@@ -0,0 +1 @@
1
+ import "../../index.js";
@@ -0,0 +1,32 @@
1
+ import { defineEmail } from "../../mail/define-email.js";
2
+ import { AuthEmailLayout, EmailCode, EmailNote } from "./auth-email-layout.js";
3
+ import { Text } from "react-email";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ //#region src/better-auth/auth-mail/sign-up-code-email.tsx
6
+ const SignUpCodeEmail = ({ app, code, lifetime }) => /* @__PURE__ */ jsxs(AuthEmailLayout, {
7
+ app,
8
+ preview: `Your code to create an account with ${app.name}`,
9
+ heading: "Create your account",
10
+ children: [
11
+ /* @__PURE__ */ jsxs(Text, { children: [
12
+ "Use this code to create your account with ",
13
+ app.name,
14
+ ":"
15
+ ] }),
16
+ /* @__PURE__ */ jsx(EmailCode, { code }),
17
+ /* @__PURE__ */ jsxs(Text, { children: [
18
+ "It works for ",
19
+ lifetime,
20
+ ", once."
21
+ ] }),
22
+ /* @__PURE__ */ jsx(EmailNote, { children: "If you did not try to create an account, ignore this email: nobody can create one for your address without the code." })
23
+ ]
24
+ });
25
+ /** The email with the code that makes an account for the address. */
26
+ const signUpCodeEmail = defineEmail({
27
+ name: "sign-up-code",
28
+ subject: ({ app }) => `Your code to create an account with ${app.name}`,
29
+ component: SignUpCodeEmail
30
+ });
31
+ //#endregion
32
+ export { signUpCodeEmail };
@@ -0,0 +1 @@
1
+ import "../../index.js";
@@ -0,0 +1,39 @@
1
+ import { defineEmail } from "../../mail/define-email.js";
2
+ import { AuthEmailLayout, EmailNote } from "./auth-email-layout.js";
3
+ import { Text } from "react-email";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ //#region src/better-auth/auth-mail/staff-sign-in-email.tsx
6
+ const StaffSignInEmail = ({ app, staff, reason, expiresAt }) => /* @__PURE__ */ jsxs(AuthEmailLayout, {
7
+ app,
8
+ preview: `${staff} signed in as you to help`,
9
+ heading: "Staff signed in as you",
10
+ children: [
11
+ /* @__PURE__ */ jsxs(Text, { children: [
12
+ staff,
13
+ ", of the team that runs ",
14
+ app.name,
15
+ ", signed in as you to help. The reason they gave:"
16
+ ] }),
17
+ /* @__PURE__ */ jsx(Text, {
18
+ style: {
19
+ borderLeft: "3px solid #e4e4e7",
20
+ paddingLeft: "12px"
21
+ },
22
+ children: reason
23
+ }),
24
+ /* @__PURE__ */ jsxs(Text, { children: [
25
+ "Their session ends by ",
26
+ expiresAt.toUTCString(),
27
+ ". The app's admins see it in the app's log of staff sign-ins."
28
+ ] }),
29
+ /* @__PURE__ */ jsx(EmailNote, { children: "If you did not expect this, tell your admin." })
30
+ ]
31
+ });
32
+ /** The email to someone whose app lets staff sign in as people only when they are told: who, why, and until when. */
33
+ const staffSignInEmail = defineEmail({
34
+ name: "staff-sign-in",
35
+ subject: ({ app }) => `Staff signed in to ${app.name} as you`,
36
+ component: StaffSignInEmail
37
+ });
38
+ //#endregion
39
+ export { staffSignInEmail };
@@ -0,0 +1 @@
1
+ import "../../index.js";
@@ -0,0 +1,32 @@
1
+ import { defineEmail } from "../../mail/define-email.js";
2
+ import { AuthEmailLayout, EmailCode, EmailNote } from "./auth-email-layout.js";
3
+ import { Text } from "react-email";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ //#region src/better-auth/auth-mail/two-factor-code-email.tsx
6
+ const TwoFactorCodeEmail = ({ app, code, lifetime }) => /* @__PURE__ */ jsxs(AuthEmailLayout, {
7
+ app,
8
+ preview: `Your code to finish signing in to ${app.name}`,
9
+ heading: "Finish signing in",
10
+ children: [
11
+ /* @__PURE__ */ jsxs(Text, { children: [
12
+ "Use this code to finish signing in to ",
13
+ app.name,
14
+ ":"
15
+ ] }),
16
+ /* @__PURE__ */ jsx(EmailCode, { code }),
17
+ /* @__PURE__ */ jsxs(Text, { children: [
18
+ "It works for ",
19
+ lifetime,
20
+ ", once."
21
+ ] }),
22
+ /* @__PURE__ */ jsx(EmailNote, { children: "If you did not just sign in, someone else may know your password or have your sign-in code: change your password." })
23
+ ]
24
+ });
25
+ /** The email with the second step of a sign-in, for an account with two-factor authentication by email. */
26
+ const twoFactorCodeEmail = defineEmail({
27
+ name: "two-factor-code",
28
+ subject: ({ app }) => `Your ${app.name} verification code`,
29
+ component: TwoFactorCodeEmail
30
+ });
31
+ //#endregion
32
+ export { twoFactorCodeEmail };