@midsummer-ai/sdk 0.1.0-staging.3725 → 0.1.0-staging.3731

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 (47) hide show
  1. package/ai/contract.mjs +1 -1
  2. package/ai/index.d.mts +3 -2
  3. package/ai/index.mjs +1 -262
  4. package/ai/stand-in.mjs +1 -62
  5. package/ai-2Llbc56l.mjs +328 -0
  6. package/apps.d.mts +0 -15
  7. package/apps.mjs +19 -2
  8. package/auth/contract.d.mts +2 -2
  9. package/auth/contract.mjs +1 -1
  10. package/auth/index.d.mts +2 -2
  11. package/auth/index.mjs +1 -1
  12. package/auth/mail.mjs +2 -2
  13. package/auth/password.mjs +1 -1
  14. package/auth/react.d.mts +12 -3
  15. package/auth/react.mjs +75 -13
  16. package/auth/stand-in.d.mts +1 -1
  17. package/{auth-C9V1Xb0w.mjs → auth-BaGXVRYd.mjs} +46 -15
  18. package/billing/index.mjs +1 -1
  19. package/client-_Al5bpqX.mjs +877 -0
  20. package/{client-D3BZs3LA.d.mts → client-oAVg6vn_.d.mts} +64 -20
  21. package/client.mjs +1 -1
  22. package/contract.mjs +1 -1
  23. package/database/client.d.mts +2 -2
  24. package/database/client.mjs +2 -711
  25. package/database/react.d.mts +1 -1
  26. package/database/stand-in.mjs +1 -1
  27. package/email/client.mjs +1 -1
  28. package/email/contract.mjs +1 -1
  29. package/email/inbox.mjs +1 -1
  30. package/email/index.mjs +1 -1
  31. package/email/smtp.mjs +1 -1
  32. package/email/stand-in.mjs +1 -1
  33. package/{email-ynNo0HqT.mjs → email-DmWG_Ug-.mjs} +16 -2
  34. package/{engine-DDPJ2CET.mjs → engine-BmiPioJ2.mjs} +13 -2
  35. package/{here-1plIxb0D.mjs → here-BKjizr_N.mjs} +9 -1
  36. package/{index-DYSS7OGg.d.mts → index-C8Ti5raa.d.mts} +3 -3
  37. package/index.mjs +1 -1
  38. package/package.json +1 -1
  39. package/{qr-BR3Ld80n.mjs → qr-Br1sOBmT.mjs} +19 -1
  40. package/queues/index.mjs +1 -1
  41. package/s3.mjs +1 -1
  42. package/socket.mjs +1 -1
  43. package/{src-BKKy9km-.mjs → src-DgX-tCDn.mjs} +2 -2
  44. package/storage/files.d.mts +1 -1
  45. package/storage/files.mjs +2 -2
  46. package/{store-CLGBhEpO.d.mts → store-Bx4dOx66.d.mts} +1 -1
  47. package/vector/index.mjs +1 -1
package/apps.d.mts CHANGED
@@ -1,19 +1,4 @@
1
1
  //#region src/apps.d.ts
2
- /**
3
- * For an app teams install on Midsummer: check that an event or a runner job Midsummer posted is
4
- * genuine, and act in an installation with a token that is renewed before it ends.
5
- *
6
- * import { InstalledApp, verifyEvent } from "@midsummer-ai/sdk/apps"
7
- *
8
- * // In your events handler, with the body exactly as it arrived:
9
- * if (!(await verifyEvent(request.headers, body, process.env.MIDSUMMER_SIGNING_SECRET!))) return new Response(null, { status: 401 })
10
- * const event = JSON.parse(body) as AppEvent
11
- *
12
- * const app = new InstalledApp({ id: "oapp_…", secret: process.env.MIDSUMMER_APP_SECRET! })
13
- * await app.request(event.data.installation.id, "/v1/mr/acme/web/mr-12/checks/style", { method: "PUT", body: JSON.stringify({ candidateId, state: "running" }) })
14
- *
15
- * Events are signed as Standard Webhooks says, so any of its libraries checks them too.
16
- */
17
2
  /** What Midsummer posts to an app: its `type`, when, and `data` with the installation it is for. */
18
3
  interface AppEvent<Data extends Record<string, unknown> = Record<string, unknown>> {
19
4
  readonly type: string;
package/apps.mjs CHANGED
@@ -1,4 +1,21 @@
1
+ import { r as platformApi } from "./here-BKjizr_N.mjs";
1
2
  //#region src/apps.ts
3
+ /**
4
+ * For an app teams install on Midsummer: check that an event or a runner job Midsummer posted is
5
+ * genuine, and act in an installation with a token that is renewed before it ends.
6
+ *
7
+ * import { InstalledApp, verifyEvent } from "@midsummer-ai/sdk/apps"
8
+ *
9
+ * // In your events handler, with the body exactly as it arrived:
10
+ * if (!(await verifyEvent(request.headers, body, process.env.MIDSUMMER_SIGNING_SECRET!))) return new Response(null, { status: 401 })
11
+ * const event = JSON.parse(body) as AppEvent
12
+ *
13
+ * const app = new InstalledApp({ id: "oapp_…", secret: process.env.MIDSUMMER_APP_SECRET! })
14
+ * await app.request(event.data.installation.id, "/v1/mr/acme/web/mr-12/checks/style", { method: "PUT", body: JSON.stringify({ candidateId, state: "running" }) })
15
+ *
16
+ * Events are signed as Standard Webhooks says, so any of its libraries checks them too. Calls go to `origin`, or to
17
+ * `MIDSUMMER_API` when left out, else the API of the site this package was published for.
18
+ */
2
19
  /** How old a signed event may be, and how far ahead of the clock: five minutes, as Standard Webhooks says. */
3
20
  const TOLERANCE_SECONDS = 300;
4
21
  /**
@@ -36,7 +53,7 @@ var InstalledApp = class {
36
53
  constructor(options) {
37
54
  this.#id = options.id;
38
55
  this.#secret = options.secret;
39
- this.#origin = (options.origin ?? "https://api.midsummer.new").replace(/\/+$/, "");
56
+ this.#origin = (options.origin ?? platformApi()).replace(/\/+$/, "");
40
57
  this.#fetch = options.fetch ?? fetch;
41
58
  }
42
59
  /** An installation's token (`msinst_…`), from the one kept while it has over a minute left. Throws when Midsummer refuses the app's secret or the installation. */
@@ -73,7 +90,7 @@ var InstalledApp = class {
73
90
  }
74
91
  /** Trades the one-time code a manifest's app was made with for its id, secret and signing secret, shown this once. */
75
92
  static async fromManifestCode(code, options = {}) {
76
- const origin = (options.origin ?? "https://api.midsummer.new").replace(/\/+$/, "");
93
+ const origin = (options.origin ?? platformApi()).replace(/\/+$/, "");
77
94
  const response = await (options.fetch ?? fetch)(`${origin}/v1/apps/conversions/${encodeURIComponent(code)}`, { method: "POST" });
78
95
  if (!response.ok) throw new Error(`Midsummer refused the code: HTTP ${response.status} ${await response.text()}`);
79
96
  return await response.json();
@@ -1,6 +1,6 @@
1
- import { n as AuthStore } from "../store-CLGBhEpO.mjs";
1
+ import { n as AuthStore } from "../store-Bx4dOx66.mjs";
2
2
  import { SignInMail } from "./mail.mjs";
3
- import { a as Auth } from "../index-DYSS7OGg.mjs";
3
+ import { a as Auth } from "../index-C8Ti5raa.mjs";
4
4
  //#region src/auth/contract.d.ts
5
5
  interface AuthHarness {
6
6
  /** Sign-in over a store with no users, made with `scopes: CONTRACT_SCOPES`. */
package/auth/contract.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { c as LIMITS, l as LIMIT_WINDOW_MS, r as AuthError, u as SETTINGS_TTL_MS } from "../auth-C9V1Xb0w.mjs";
1
+ import { c as LIMITS, l as LIMIT_WINDOW_MS, r as AuthError, u as SETTINGS_TTL_MS } from "../auth-BaGXVRYd.mjs";
2
2
  import { IMPERSONATION_TOKEN_MS, startImpersonation } from "./impersonate.mjs";
3
3
  //#region src/auth/contract.ts
4
4
  /**
package/auth/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { n as AuthStore, r as databaseStore, t as AuthCall } from "../store-CLGBhEpO.mjs";
1
+ import { n as AuthStore, r as databaseStore, t as AuthCall } from "../store-Bx4dOx66.mjs";
2
2
  import { i as SignUpPolicy, n as CaptchaProvider, r as PublicSettings, t as AuthSettings } from "../settings-Dz3irtlu.mjs";
3
3
  import { SignInMail, SignInMailKind, checkSignInMail, signInWords } from "./mail.mjs";
4
- import { _ as AuthEvent, a as Auth, b as EventSend, c as AuthOptions, d as IMPERSONATION_S, f as SESSION_CACHE_S, g as createAuth, h as auth, i as AgentKey, l as AuthUser, m as SignedInAgent, n as AUTH_ROUTES, o as AuthError, p as SignedIn, r as AgentGrant, s as AuthErrorCode, t as AUTH_PATH, u as AuthUserRecord, v as AuthEventBatch, y as AuthEventType } from "../index-DYSS7OGg.mjs";
4
+ import { _ as AuthEvent, a as Auth, b as EventSend, c as AuthOptions, d as IMPERSONATION_S, f as SESSION_CACHE_S, g as createAuth, h as auth, i as AgentKey, l as AuthUser, m as SignedInAgent, n as AUTH_ROUTES, o as AuthError, p as SignedIn, r as AgentGrant, s as AuthErrorCode, t as AUTH_PATH, u as AuthUserRecord, v as AuthEventBatch, y as AuthEventType } from "../index-C8Ti5raa.mjs";
5
5
  import { i as authFiles } from "../files-B553U-d6.mjs";
6
6
  export { AUTH_PATH, AUTH_ROUTES, AgentGrant, AgentKey, Auth, type AuthCall, AuthError, AuthErrorCode, type AuthEvent, type AuthEventBatch, type AuthEventType, AuthOptions, type AuthSettings, type AuthStore, AuthUser, AuthUserRecord, type CaptchaProvider, type EventSend, IMPERSONATION_S, type PublicSettings, SESSION_CACHE_S, type SignInMail, type SignInMailKind, type SignUpPolicy, SignedIn, SignedInAgent, auth, authFiles, checkSignInMail, createAuth, databaseStore, signInWords };
package/auth/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as SESSION_CACHE_S, d as databaseStore, i as IMPERSONATION_S, n as AUTH_ROUTES, o as auth, r as AuthError, s as createAuth, t as AUTH_PATH } from "../auth-C9V1Xb0w.mjs";
1
+ import { a as SESSION_CACHE_S, d as databaseStore, i as IMPERSONATION_S, n as AUTH_ROUTES, o as auth, r as AuthError, s as createAuth, t as AUTH_PATH } from "../auth-BaGXVRYd.mjs";
2
2
  import { checkSignInMail, signInWords } from "./mail.mjs";
3
3
  import { n as authFiles } from "../files-DhPeWwcT.mjs";
4
4
  export { AUTH_PATH, AUTH_ROUTES, AuthError, IMPERSONATION_S, SESSION_CACHE_S, auth, authFiles, checkSignInMail, createAuth, databaseStore, signInWords };
package/auth/mail.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { r as processEnv, t as here } from "../here-1plIxb0D.mjs";
2
- import { l as email, t as EmailError } from "../email-ynNo0HqT.mjs";
1
+ import { i as processEnv, t as here } from "../here-BKjizr_N.mjs";
2
+ import { l as email, t as EmailError } from "../email-DmWG_Ug-.mjs";
3
3
  //#region src/auth/mail.ts
4
4
  /**
5
5
  * The mail sign-in sends: a code, a sign-in link, an email check, a password reset, an invitation or a sign-in from
package/auth/password.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as hashPassword$1, o as verifyPassword$1 } from "../engine-DDPJ2CET.mjs";
1
+ import { i as hashPassword$1, o as verifyPassword$1 } from "../engine-BmiPioJ2.mjs";
2
2
  import { isBcrypt as isBcrypt$1 } from "./import.mjs";
3
3
  //#region src/auth/password.ts
4
4
  /**
package/auth/react.d.mts CHANGED
@@ -12,11 +12,16 @@ interface AuthState {
12
12
  /** Reads who is signed in again. */
13
13
  refresh(): Promise<void>;
14
14
  }
15
- /** Gives the screens inside it the client and who is signed in; `baseURL` when the app's server is on another address. */
15
+ /**
16
+ * Gives the screens inside it the client and who is signed in; `baseURL` when the app's server is on another address.
17
+ * With `database`, the hooks of `@midsummer-ai/sdk/react` inside it (`useQuery`, `useMutation`) reach the app's
18
+ * database as whoever is signed in (`signedInDatabase`), and connect again as someone signs in or out.
19
+ */
16
20
  declare function AuthProvider(props: {
17
21
  readonly children?: ReactNode;
18
22
  readonly client?: AuthClient;
19
23
  readonly baseURL?: string;
24
+ readonly database?: boolean;
20
25
  }): import("react").FunctionComponentElement<import("react").ProviderProps<AuthState | null>>;
21
26
  /** Who is signed in, the client and the app's settings: inside an `AuthProvider`. */
22
27
  declare function useAuth(): AuthState;
@@ -29,8 +34,9 @@ declare function SignIn(props: {
29
34
  readonly title: string;
30
35
  readonly lead?: string;
31
36
  readonly wide?: boolean;
37
+ readonly appear?: boolean;
32
38
  readonly children?: ReactNode;
33
- }> | null;
39
+ }> | import("react").FunctionComponentElement<{}>;
34
40
  /** Sign-up with a name, an email and a password; under a waitlist, joining it; when the app wants emails confirmed, asking for that. */
35
41
  declare function SignUp(props: {
36
42
  readonly redirectTo?: string;
@@ -39,8 +45,9 @@ declare function SignUp(props: {
39
45
  readonly title: string;
40
46
  readonly lead?: string;
41
47
  readonly wide?: boolean;
48
+ readonly appear?: boolean;
42
49
  readonly children?: ReactNode;
43
- }> | null;
50
+ }> | import("react").FunctionComponentElement<{}>;
44
51
  /** The signed-in person's picture or initial, opening a menu: their account, and signing out. */
45
52
  declare function UserButton(props: {
46
53
  readonly accountUrl?: string;
@@ -63,6 +70,7 @@ declare function UserProfile(): import("react").FunctionComponentElement<{
63
70
  readonly title: string;
64
71
  readonly lead?: string;
65
72
  readonly wide?: boolean;
73
+ readonly appear?: boolean;
66
74
  readonly children?: ReactNode;
67
75
  }> | null;
68
76
  /** Which organization the person works in, or their personal account; and making a new one. */
@@ -80,6 +88,7 @@ declare function OrganizationProfile(props: {
80
88
  readonly title: string;
81
89
  readonly lead?: string;
82
90
  readonly wide?: boolean;
91
+ readonly appear?: boolean;
83
92
  readonly children?: ReactNode;
84
93
  }> | null;
85
94
  //#endregion
package/auth/react.mjs CHANGED
@@ -1,4 +1,6 @@
1
- import { a as WORDS, c as setupKeyOf, i as CAPTCHA_WIDGETS, o as ago, r as AUTH_CSS, s as deviceOf, t as qrPath } from "../qr-BR3Ld80n.mjs";
1
+ import { c as signedInDatabase, t as DATABASE_TOKEN_PATH } from "../client-_Al5bpqX.mjs";
2
+ import { DatabaseProvider } from "../database/react.mjs";
3
+ import { a as WORDS, c as deviceOf, i as CAPTCHA_WIDGETS, l as setupKeyOf, o as ago, r as AUTH_CSS, t as qrPath } from "../qr-Br1sOBmT.mjs";
2
4
  import { AuthClientError, authClient } from "./client.mjs";
3
5
  import { Fragment, createContext, createElement, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
4
6
  //#region src/auth/react.ts
@@ -17,10 +19,15 @@ import { Fragment, createContext, createElement, useCallback, useContext, useEff
17
19
  * roles and invitations). They show only the ways in the app's settings turn on, in the app's name, logo and colour,
18
20
  * with the app's own font; set `--msa-accent`, `--msa-radius` and the other variables in `./look.ts` on any parent to
19
21
  * match the app's look. `useAuth()` gives any component who is signed in. The hosted pages under `/api/auth/ui` are
20
- * the same screens for apps that don't use React.
22
+ * the same screens for apps that don't use React. `<AuthProvider database>` also gives the components inside it the
23
+ * app's database as whoever is signed in, for `useQuery` and the other hooks of `@midsummer-ai/sdk/react`.
21
24
  */
22
25
  const Context = createContext(null);
23
- /** Gives the screens inside it the client and who is signed in; `baseURL` when the app's server is on another address. */
26
+ /**
27
+ * Gives the screens inside it the client and who is signed in; `baseURL` when the app's server is on another address.
28
+ * With `database`, the hooks of `@midsummer-ai/sdk/react` inside it (`useQuery`, `useMutation`) reach the app's
29
+ * database as whoever is signed in (`signedInDatabase`), and connect again as someone signs in or out.
30
+ */
24
31
  function AuthProvider(props) {
25
32
  const client = useMemo(() => props.client ?? authClient(props.baseURL ? { baseURL: props.baseURL } : {}), [props.client, props.baseURL]);
26
33
  const [signedIn, setSignedIn] = useState(void 0);
@@ -28,11 +35,19 @@ function AuthProvider(props) {
28
35
  const refresh = useCallback(async () => {
29
36
  setSignedIn(await client.session().catch(() => null));
30
37
  }, [client]);
38
+ const db = useMemo(() => props.database ? signedInDatabase({ url: `${props.baseURL?.replace(/\/+$/u, "") ?? ""}${DATABASE_TOKEN_PATH}` }) : null, [props.database, props.baseURL]);
31
39
  useEffect(() => {
32
40
  refresh();
33
41
  client.settings().then(setSettings, () => {});
34
- return client.onChange(() => void refresh());
35
- }, [client, refresh]);
42
+ return client.onChange(() => {
43
+ refresh();
44
+ db?.signedInChanged();
45
+ });
46
+ }, [
47
+ client,
48
+ refresh,
49
+ db
50
+ ]);
36
51
  const state = useMemo(() => ({
37
52
  client,
38
53
  signedIn,
@@ -44,7 +59,7 @@ function AuthProvider(props) {
44
59
  settings,
45
60
  refresh
46
61
  ]);
47
- return createElement(Context.Provider, { value: state }, createElement("style", { "data-msa": "" }, AUTH_CSS), props.children);
62
+ return createElement(Context.Provider, { value: state }, createElement("style", { "data-msa": "" }, AUTH_CSS), db ? createElement(DatabaseProvider, { client: db }, props.children) : props.children);
48
63
  }
49
64
  /** Who is signed in, the client and the app's settings: inside an `AuthProvider`. */
50
65
  function useAuth() {
@@ -82,7 +97,11 @@ function Card(props) {
82
97
  return createElement("div", {
83
98
  className: "msa",
84
99
  style: color ? { "--msa-brand": color } : void 0
85
- }, createElement("div", { className: props.wide ? "msa-card msa-wide" : "msa-card" }, settings?.branding.logo ? createElement("img", {
100
+ }, createElement("div", { className: [
101
+ "msa-card",
102
+ props.wide ? "msa-wide" : "",
103
+ props.appear ? "msa-appear" : ""
104
+ ].filter(Boolean).join(" ") }, settings?.branding.logo ? createElement("img", {
86
105
  className: "msa-logo",
87
106
  src: settings.branding.logo,
88
107
  alt: settings.branding.name
@@ -211,6 +230,23 @@ function Confirm(props) {
211
230
  const go = (to) => {
212
231
  globalThis.location.href = to;
213
232
  };
233
+ /**
234
+ * The sign-in screen while the app's settings load: its title, the email and password fields, button and links as bones
235
+ * the size of each, so the form takes their place without anything moving. It shows only after a moment, so a quick
236
+ * load shows none.
237
+ */
238
+ function SignInLoading() {
239
+ const bone = (width, className = "msa-bone") => createElement("span", {
240
+ className,
241
+ style: { width }
242
+ });
243
+ return createElement("div", {
244
+ className: "msa",
245
+ role: "status",
246
+ "aria-busy": true,
247
+ "aria-label": WORDS.signIn.loading
248
+ }, createElement("div", { className: "msa-card msa-loading" }, createElement("h1", null, bone("60%")), createElement("div", { className: "msa-bones" }, ...[WORDS.fields.email, WORDS.fields.password].map((label) => createElement("label", { key: label }, bone("30%"), bone("100%", "msa-bone msa-bone-control"))), createElement("span", null), bone("100%", "msa-bone msa-bone-control")), createElement("p", { className: "msa-foot" }, bone("70%", "msa-bone msa-bone-inline"))));
249
+ }
214
250
  /** Sign-in: a password, a code or a link by mail, a passkey, Google or GitHub, as the app's settings turn them on. */
215
251
  function SignIn(props) {
216
252
  const { client, settings } = useAuth();
@@ -218,7 +254,8 @@ function SignIn(props) {
218
254
  const [email, setEmail] = useState(""), [password, setPassword] = useState(""), [code, setCode] = useState(""), [captcha, setCaptcha] = useState("");
219
255
  const call = useCall();
220
256
  const done = () => go(props.redirectTo ?? "/");
221
- if (!settings) return null;
257
+ const [shaped] = useState(() => !settings);
258
+ if (!settings) return createElement(SignInLoading);
222
259
  const methods = settings.methods, app = settings.branding.name;
223
260
  const withCaptcha = captcha ? { captcha } : {};
224
261
  if (mode === "two-factor" || mode === "mail-code" || mode === "backup") return createElement(Card, {
@@ -283,7 +320,10 @@ function SignIn(props) {
283
320
  }, WORDS.confirm.back)));
284
321
  const social = ["google", "github"].filter((one) => methods[one]);
285
322
  const byMail = methods.code ? "code" : methods.link ? "link" : null;
286
- return createElement(Card, { title: WORDS.signIn.title(app) }, social.length || methods.passkey ? createElement("div", { className: "msa-stack" }, ...social.map((provider) => createElement("button", {
323
+ return createElement(Card, {
324
+ title: WORDS.signIn.title(app),
325
+ appear: shaped
326
+ }, social.length || methods.passkey ? createElement("div", { className: "msa-stack" }, ...social.map((provider) => createElement("button", {
287
327
  key: provider,
288
328
  type: "button",
289
329
  onClick: () => void call.run(() => client.signIn.social(provider, { callbackURL: props.redirectTo ?? "/" }))
@@ -358,17 +398,39 @@ function SignIn(props) {
358
398
  })
359
399
  }, WORDS.ways.link) : null) : null, createElement("p", { className: "msa-foot" }, methods.password ? createElement(Fragment, null, createElement("a", { href: props.resetUrl ?? "/api/auth/ui/reset-password" }, WORDS.signIn.forgot), " · ") : null, settings.signUp.policy === "invite" ? null : createElement(Fragment, null, `${WORDS.signIn.noAccount} `, createElement("a", { href: props.signUpUrl ?? "/api/auth/ui/sign-up" }, WORDS.signIn.signUp))));
360
400
  }
401
+ /**
402
+ * The sign-up screen while the app's settings load: its title, three fields, button and link as bones the size of each,
403
+ * so the form takes their place without anything moving. It shows only after a moment, so a quick load shows none.
404
+ */
405
+ function SignUpLoading() {
406
+ const bone = (width, className = "msa-bone") => createElement("span", {
407
+ className,
408
+ style: { width }
409
+ });
410
+ return createElement("div", {
411
+ className: "msa",
412
+ role: "status",
413
+ "aria-busy": true,
414
+ "aria-label": WORDS.signUp.loading
415
+ }, createElement("div", { className: "msa-card msa-loading" }, createElement("h1", null, bone("70%")), createElement("div", { className: "msa-bones" }, ...[
416
+ WORDS.fields.name,
417
+ WORDS.fields.email,
418
+ WORDS.fields.password
419
+ ].map((label) => createElement("label", { key: label }, bone("30%"), bone("100%", "msa-bone msa-bone-control"))), createElement("span", null), bone("100%", "msa-bone msa-bone-control")), createElement("p", { className: "msa-foot" }, bone("60%", "msa-bone msa-bone-inline"))));
420
+ }
361
421
  /** Sign-up with a name, an email and a password; under a waitlist, joining it; when the app wants emails confirmed, asking for that. */
362
422
  function SignUp(props) {
363
423
  const { client, settings } = useAuth();
364
424
  const [name, setName] = useState(""), [email, setEmail] = useState(""), [password, setPassword] = useState(""), [captcha, setCaptcha] = useState("");
365
425
  const [waiting, setWaiting] = useState(null);
366
426
  const call = useCall();
367
- if (!settings) return null;
368
- const policy = settings.signUp.policy;
369
- if (waiting) return createElement(Card, { title: WORDS.signUp.title(settings.branding.name) }, createElement(Note, null, waiting), createElement("p", { className: "msa-foot" }, createElement("a", { href: props.signInUrl ?? "/api/auth/ui/sign-in" }, WORDS.confirm.back)));
427
+ const [shaped] = useState(() => !settings);
428
+ if (!settings) return createElement(SignUpLoading);
429
+ const policy = settings.signUp.policy, app = settings.branding.name;
430
+ if (waiting) return createElement(Card, { title: WORDS.signUp.title(app) }, createElement(Note, null, waiting), createElement("p", { className: "msa-foot" }, createElement("a", { href: props.signInUrl ?? "/api/auth/ui/sign-in" }, WORDS.confirm.back)));
370
431
  return createElement(Card, {
371
- title: WORDS.signUp.title(settings.branding.name),
432
+ title: WORDS.signUp.title(app),
433
+ appear: shaped,
372
434
  ...policy === "invite" ? { lead: WORDS.signUp.invite } : {}
373
435
  }, createElement("form", { onSubmit: onSubmit(() => void call.run(async () => {
374
436
  try {
@@ -1,4 +1,4 @@
1
- import { n as AuthStore } from "../store-CLGBhEpO.mjs";
1
+ import { n as AuthStore } from "../store-Bx4dOx66.mjs";
2
2
  import { SignInMail } from "./mail.mjs";
3
3
  //#region src/auth/stand-in.d.ts
4
4
  interface StandIn {
@@ -1,10 +1,10 @@
1
- import { r as processEnv, t as here } from "./here-1plIxb0D.mjs";
2
- import { connect } from "./database/client.mjs";
1
+ import { i as processEnv, r as platformApi, t as here } from "./here-BKjizr_N.mjs";
2
+ import { a as connect, l as userToken, o as databaseUrl } from "./client-_Al5bpqX.mjs";
3
3
  import { sendSignInMail } from "./auth/mail.mjs";
4
4
  import "./files-DhPeWwcT.mjs";
5
5
  import { standIn } from "./auth/stand-in.mjs";
6
- import { a as ourWords, c as agentOfToken, d as credentialOf, f as remembering, l as challenge, n as REFUSALS, p as resourceOf, r as buildEngine, s as agentOfKey, t as JoinRefused, u as consentPage } from "./engine-DDPJ2CET.mjs";
7
- import { a as WORDS, c as setupKeyOf, i as CAPTCHA_WIDGETS, n as qrSvg, o as ago, r as AUTH_CSS, s as deviceOf } from "./qr-BR3Ld80n.mjs";
6
+ import { a as ourWords, c as agentOfToken, d as credentialOf, f as remembering, l as challenge, n as REFUSALS, p as resourceOf, r as buildEngine, s as agentOfKey, t as JoinRefused, u as consentPage } from "./engine-BmiPioJ2.mjs";
7
+ import { a as WORDS, c as deviceOf, i as CAPTCHA_WIDGETS, l as setupKeyOf, n as qrSvg, o as ago, r as AUTH_CSS, s as defaultAppName } from "./qr-Br1sOBmT.mjs";
8
8
  //#region src/auth/store.ts
9
9
  const KIND = {
10
10
  create: "mutation",
@@ -1119,6 +1119,8 @@ ${kind === "sign-in" ? `const o=await p("/passkey/generate-authenticate-options"
1119
1119
  * or (signing in) `{ twoFactor: true }`; `POST /api/auth/sign-out` returns `{ signedOut: true }`; `GET /api/auth/session`
1120
1120
  * returns `{ user, session }` or `null`. The session's cookie is `midsummer.session_token` (`__Secure-midsummer.…` over
1121
1121
  * https). Signing up signs the person in at once unless the settings' `confirmEmail` is on (`./settings.ts`).
1122
+ * `GET /api/auth/database-token` returns `{ url, token, expiresAt }`: the app's database and a token for the person
1123
+ * signed in, which the page's `signedInDatabase()` (`<AuthProvider database>`) connects with, or `{ url }` for no one.
1122
1124
  *
1123
1125
  * Email and password, codes and sign-in links by mail, Google and GitHub when their keys are set, organizations with
1124
1126
  * roles and invitations, two-factor codes, passkeys and bans. Browsers talk to it with `@midsummer-ai/sdk/auth/client`,
@@ -1194,7 +1196,6 @@ const AUTH_ROUTES = {
1194
1196
  };
1195
1197
  /** How many addresses one process keeps sign-in ready for; past it the oldest is made again when asked. */
1196
1198
  const KEPT_ORIGINS = 16;
1197
- const API = "https://api.midsummer.new";
1198
1199
  const METADATA_BYTES = 8192;
1199
1200
  /** The origin a request came to, as the dispatcher routed it. */
1200
1201
  function originOf(request) {
@@ -1232,7 +1233,7 @@ function storeFor(options, env) {
1232
1233
  const key = options.key ?? env.DATABASE_KEY;
1233
1234
  if (key) return databaseStore(requestDatabase(() => connect({
1234
1235
  key,
1235
- api: options.api ?? API
1236
+ api: options.api ?? platformApi()
1236
1237
  }), "its database with DATABASE_KEY"));
1237
1238
  if (env.MIDSUMMER_DEV === "1") return devStore();
1238
1239
  throw new AuthError("forbidden", "Sign-in has no database here. Outside Midsummer, set DATABASE_KEY to a database key (midsummer db key create). In tests, give createAuth the Stand-in: createAuth({ store: standIn().store }).");
@@ -1250,7 +1251,7 @@ function eventSendFor(options, env) {
1250
1251
  };
1251
1252
  if (here() || options.store) return null;
1252
1253
  const key = options.key ?? env.DATABASE_KEY;
1253
- if (key) return httpSend(`${options.api ?? API}/v1/db/auth/events`, { key });
1254
+ if (key) return httpSend(`${options.api ?? platformApi()}/v1/db/auth/events`, { key });
1254
1255
  const workload = env.MIDSUMMER_IDENTITY_REQUEST_TOKEN, tokenUrl = env.MIDSUMMER_IDENTITY_TOKEN_URL;
1255
1256
  if (workload && tokenUrl) return httpSend(`${new URL(tokenUrl).origin}/v1/db/auth/events`, {
1256
1257
  workload,
@@ -1263,7 +1264,7 @@ function remoteMailFor(options, env) {
1263
1264
  if (here() || options.store) return void 0;
1264
1265
  const key = options.key ?? env.DATABASE_KEY;
1265
1266
  if (key) return {
1266
- url: `${options.api ?? API}/v1/db/auth/mail`,
1267
+ url: `${options.api ?? platformApi()}/v1/db/auth/mail`,
1267
1268
  proof: { key }
1268
1269
  };
1269
1270
  const workload = env.MIDSUMMER_IDENTITY_REQUEST_TOKEN, tokenUrl = env.MIDSUMMER_IDENTITY_TOKEN_URL;
@@ -1382,7 +1383,8 @@ function createAuth(options = {}) {
1382
1383
  }
1383
1384
  return made;
1384
1385
  };
1385
- const appNameOf = (settings) => settings.branding.name ?? options.appName ?? base().env.APP_NAME ?? "your app";
1386
+ /** The app's name: its settings', `appName`, `APP_NAME`, else the address it serves at (`shop.acme.dev`), which reads right in every screen and mail. */
1387
+ const appNameOf = (settings, origin) => settings.branding.name ?? options.appName ?? base().env.APP_NAME ?? defaultAppName(origin);
1386
1388
  /** Work that follows a request, such as the new-device mail, until it ends. */
1387
1389
  const background = /* @__PURE__ */ new Set();
1388
1390
  /** The events each request on Midsummer made so far, reported as its handler ends: never before its answer. */
@@ -1421,7 +1423,7 @@ function createAuth(options = {}) {
1421
1423
  });
1422
1424
  if (!user) return;
1423
1425
  const device = deviceOf(typeof session.userAgent === "string" ? session.userAgent : null);
1424
- await sendOne(await settings(), {
1426
+ await sendOne(await settings(), origin, {
1425
1427
  to: String(user.email),
1426
1428
  kind: "device",
1427
1429
  url: `${origin}${AUTH_PATH}/ui/account`,
@@ -1429,14 +1431,14 @@ function createAuth(options = {}) {
1429
1431
  });
1430
1432
  }
1431
1433
  /** Sends one mail with the app's name, branding and sender. */
1432
- async function sendOne(settings, mail) {
1434
+ async function sendOne(settings, origin, mail) {
1433
1435
  const brand = {
1434
1436
  ...settings.branding.logo ? { logo: settings.branding.logo } : {},
1435
1437
  ...settings.branding.color ? { color: settings.branding.color } : {}
1436
1438
  };
1437
1439
  const full = {
1438
1440
  ...mail,
1439
- app: appNameOf(settings),
1441
+ app: appNameOf(settings, origin),
1440
1442
  ...Object.keys(brand).length ? { brand } : {}
1441
1443
  };
1442
1444
  await (options.mail ? options.mail(full) : sendSignInMail(full, base().env, settings.sender.from, remoteMailFor(options, base().env)));
@@ -1482,7 +1484,7 @@ function createAuth(options = {}) {
1482
1484
  const at = async (origin) => {
1483
1485
  const normal = new URL(origin).origin;
1484
1486
  const { store, env, settings } = base();
1485
- const now = await settings(), appName = appNameOf(now);
1487
+ const now = await settings(), appName = appNameOf(now, normal);
1486
1488
  const id = `${normal}\n${appName}\n${now.confirmEmail}`;
1487
1489
  let found = kept.get(id);
1488
1490
  if (!found) {
@@ -1501,7 +1503,7 @@ function createAuth(options = {}) {
1501
1503
  cacheS: 300,
1502
1504
  confirmEmail: now.confirmEmail,
1503
1505
  invitationUrl: options.invitationUrl ?? ((from, invitation) => `${from}/api/auth/ui/invitation/${invitation}`),
1504
- send: async (mail) => sendOne(await settings(), mail)
1506
+ send: async (mail) => sendOne(await settings(), normal, mail)
1505
1507
  });
1506
1508
  if (kept.size >= KEPT_ORIGINS) kept.delete(kept.keys().next().value);
1507
1509
  kept.set(id, found);
@@ -1787,12 +1789,40 @@ function createAuth(options = {}) {
1787
1789
  message: "There's nothing here."
1788
1790
  });
1789
1791
  }
1792
+ /**
1793
+ * `GET /api/auth/database-token`, for the page's `signedInDatabase()`: the address of the database sign-in keeps its
1794
+ * rows in, and for someone signed in a ten-minute token that runs the app's public functions as them (`userToken`),
1795
+ * never internal ones. Someone not signed in gets the address alone, to connect as no one. On Midsummer it needs no
1796
+ * key, previews and `midsummer dev` included; elsewhere it uses the database key sign-in uses.
1797
+ */
1798
+ async function databaseToken(request) {
1799
+ const answer = (status, body) => Response.json(body, {
1800
+ status,
1801
+ headers: { "Cache-Control": "no-store" }
1802
+ });
1803
+ const { env } = base();
1804
+ const key = options.key ?? env.DATABASE_KEY;
1805
+ const where = options.store ? void 0 : here() || env.MIDSUMMER_DATABASE_URL || env.MIDSUMMER_IDENTITY_REQUEST_TOKEN ? { binding: options.database ?? "main" } : key ? {
1806
+ key,
1807
+ api: options.api ?? platformApi()
1808
+ } : void 0;
1809
+ if (!where) return answer(503, {
1810
+ code: "UNAVAILABLE",
1811
+ message: "Sign-in keeps no database here, so there's no database token to give. Run under midsummer dev with a db/ folder, or set DATABASE_KEY outside Midsummer."
1812
+ });
1813
+ const signedIn = await person(request);
1814
+ if (!signedIn) return answer(200, { url: await databaseUrl(where) });
1815
+ return answer(200, await userToken({
1816
+ ...where,
1817
+ as: signedIn.user.id
1818
+ }));
1819
+ }
1790
1820
  /** Serves one request under `/api/auth`: settings, account calls, hosted pages, the guard, then the engine. */
1791
1821
  async function serve(request) {
1792
1822
  const origin = originOf(request), { pathname } = new URL(request.url);
1793
1823
  const { settings: read, env, allow } = base();
1794
1824
  const settings = await read();
1795
- const engine = await at(origin), appName = appNameOf(settings);
1825
+ const engine = await at(origin), appName = appNameOf(settings, origin);
1796
1826
  if (pathname === "/.well-known/oauth-authorization-server") return engine.handler(new Request(`${origin}/.well-known/oauth-authorization-server${AUTH_PATH}`, request));
1797
1827
  if (!pathname.startsWith(`/api/auth/`)) return engine.handler(request);
1798
1828
  const path = pathname.slice(9);
@@ -1809,6 +1839,7 @@ function createAuth(options = {}) {
1809
1839
  ...offered,
1810
1840
  scopes: settingsOfAgents.scopes
1811
1841
  }, { headers: { "Cache-Control": "no-store" } });
1842
+ if (`/api/auth${path}` === "/api/auth/database-token" && request.method === "GET") return databaseToken(request);
1812
1843
  if (path.startsWith("/account/")) return account(request, path.slice(8), origin);
1813
1844
  if (pathname === CONSENT_PATH && settingsOfAgents.consentPage === CONSENT_PATH) return consent(request, origin, engine, appName);
1814
1845
  if (path.startsWith("/ui/")) return hostedPage(request, path.slice(3), {
package/billing/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as late, r as processEnv, t as here } from "../here-1plIxb0D.mjs";
1
+ import { i as processEnv, n as late, t as here } from "../here-BKjizr_N.mjs";
2
2
  //#region src/billing/index.ts
3
3
  /**
4
4
  * Billing from a Project's code: send a customer to a checkout, and ask what they have bought. Each customer is your