@midsummer-ai/sdk 0.1.0-staging.3772 → 0.1.0-staging.3778

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.
@@ -1,6 +1,6 @@
1
- import { n as AuthStore } from "../store-DXHi6LCj.mjs";
1
+ import { n as AuthStore } from "../store-CRqU5WCe.mjs";
2
2
  import { SignInMail } from "./mail.mjs";
3
- import { a as Auth } from "../index-PL-07Sie.mjs";
3
+ import { a as Auth } from "../index-C0ykY_s9.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-B2k7Nwjx.mjs";
1
+ import { c as LIMITS, l as LIMIT_WINDOW_MS, r as AuthError, u as SETTINGS_TTL_MS } from "../auth-DBp5FHvK.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-DXHi6LCj.mjs";
1
+ import { n as AuthStore, r as databaseStore, t as AuthCall } from "../store-CRqU5WCe.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-PL-07Sie.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-C0ykY_s9.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-B2k7Nwjx.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-DBp5FHvK.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/password.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as hashPassword$1, o as verifyPassword$1 } from "../engine-BmiPioJ2.mjs";
1
+ import { i as hashPassword$1, o as verifyPassword$1 } from "../engine-o-3LFoL3.mjs";
2
2
  import { isBcrypt as isBcrypt$1 } from "./import.mjs";
3
3
  //#region src/auth/password.ts
4
4
  /**
package/auth/react.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { c as signedInDatabase, t as DATABASE_TOKEN_PATH } from "../client-D0gC0c1_.mjs";
1
+ import { t as DATABASE_TOKEN_PATH, u as signedInDatabase } from "../client-CIuYlRWZ.mjs";
2
2
  import { DatabaseProvider } from "../database/react.mjs";
3
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";
4
4
  import { AuthClientError, authClient } from "./client.mjs";
@@ -1,4 +1,4 @@
1
- import { n as AuthStore } from "../store-DXHi6LCj.mjs";
1
+ import { n as AuthStore } from "../store-CRqU5WCe.mjs";
2
2
  import { SignInMail } from "./mail.mjs";
3
3
  //#region src/auth/stand-in.d.ts
4
4
  interface StandIn {
@@ -1,9 +1,9 @@
1
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-D0gC0c1_.mjs";
2
+ import { d as userToken, o as connect, s as databaseUrl } from "./client-CIuYlRWZ.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-BmiPioJ2.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-o-3LFoL3.mjs";
7
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 = {
@@ -19,13 +19,16 @@ const KIND = {
19
19
  increment: "mutation",
20
20
  page: "query"
21
21
  };
22
+ /** The longest sign-in waits for one call to the database, connecting included, before it answers that it couldn't. */
23
+ const STORE_CALL_MS = 1e4;
22
24
  /**
23
25
  * The app's database as sign-in's store: each call one of `db/auth.ts`'s functions. `database` gives the
24
26
  * connection a call goes over; it is asked for one each call, so it can hand out the request's own. A function
25
- * that isn't there means `db/auth.ts` was never deployed: the error says to run `midsummer auth init`.
27
+ * that isn't there means `db/auth.ts` was never deployed: the error says to run `midsummer auth init`. A call
28
+ * unanswered after `waitMs` (`STORE_CALL_MS`) throws, so a request never waits on the database for longer.
26
29
  */
27
- function databaseStore(database) {
28
- return { async call(fn, args) {
30
+ function databaseStore(database, waitMs = STORE_CALL_MS) {
31
+ const run = async (fn, args) => {
29
32
  const db = await database();
30
33
  try {
31
34
  return KIND[fn] === "query" ? await db.query({
@@ -39,6 +42,17 @@ function databaseStore(database) {
39
42
  if (/no function|not found|unknown function/i.test(String(error?.message))) throw new Error(`The database has no auth.${fn}: add sign-in's tables and functions with midsummer auth init, then deploy db/.`);
40
43
  throw error;
41
44
  }
45
+ };
46
+ return { async call(fn, args) {
47
+ let timer;
48
+ const late = new Promise((_, refuse) => {
49
+ timer = setTimeout(() => refuse(/* @__PURE__ */ new Error(`The database didn't answer auth.${fn} within ${waitMs / 1e3} seconds.`)), waitMs);
50
+ });
51
+ try {
52
+ return await Promise.race([run(fn, args), late]);
53
+ } finally {
54
+ clearTimeout(timer);
55
+ }
42
56
  } };
43
57
  }
44
58
  //#endregion
@@ -139,13 +153,21 @@ function publicSettings(settings, appName) {
139
153
  };
140
154
  }
141
155
  /**
142
- * The app's settings from `store`, read again once `SETTINGS_TTL_MS` has passed since the last read. Reads asked
143
- * for while one is on its way share it.
156
+ * The app's settings from `store`, read again once `SETTINGS_TTL_MS` has passed since the last read began. Only a
157
+ * read that has answered is kept. Reads asked for while one is on its way share it when `scope` gives them the same
158
+ * owner (a deployment's request, `here()`), or when it gives none: a request never waits on another request's read,
159
+ * which ends when that request does.
144
160
  */
145
- function settingsReader(store, clock = Date.now) {
161
+ function settingsReader(store, clock = Date.now, scope = () => void 0) {
146
162
  let kept;
163
+ const reading = /* @__PURE__ */ new WeakMap();
164
+ let unscoped;
147
165
  return () => {
148
- if (kept && kept.until > clock()) return kept.value;
166
+ if (kept && kept.until > clock()) return Promise.resolve(kept.value);
167
+ const owner = scope();
168
+ const pending = owner ? reading.get(owner) : unscoped;
169
+ if (pending) return pending;
170
+ const began = clock();
149
171
  const value = store.call("findOne", {
150
172
  model: "authSettings",
151
173
  where: [{
@@ -153,13 +175,17 @@ function settingsReader(store, clock = Date.now) {
153
175
  value: "settings"
154
176
  }]
155
177
  }).then(settingsOf);
156
- kept = {
157
- until: clock() + SETTINGS_TTL_MS,
158
- value
159
- };
160
- value.catch(() => {
161
- kept = void 0;
178
+ value.then((settings) => {
179
+ kept = {
180
+ until: began + SETTINGS_TTL_MS,
181
+ value: settings
182
+ };
183
+ }, () => {}).finally(() => {
184
+ if (owner) reading.delete(owner);
185
+ else if (unscoped === value) unscoped = void 0;
162
186
  });
187
+ if (owner) reading.set(owner, value);
188
+ else unscoped = value;
163
189
  return value;
164
190
  };
165
191
  }
@@ -1201,6 +1227,23 @@ const METADATA_BYTES = 8192;
1201
1227
  function originOf(request) {
1202
1228
  return new URL(request.url).origin;
1203
1229
  }
1230
+ /** The session's cookie, by its name over http and over https. */
1231
+ const SESSION_COOKIES = /* @__PURE__ */ new Set(["midsummer.session_token", "__Secure-midsummer.session_token"]);
1232
+ /** Whether a request carries a session's cookie: without one no one is signed in, and nothing need be read. */
1233
+ function hasSessionCookie(request) {
1234
+ const cookie = request.headers.get("cookie");
1235
+ if (!cookie) return false;
1236
+ return cookie.split(";").some((pair) => {
1237
+ const at = pair.indexOf("=");
1238
+ return at > 0 && SESSION_COOKIES.has(pair.slice(0, at).trim()) && pair.slice(at + 1).trim() !== "";
1239
+ });
1240
+ }
1241
+ /**
1242
+ * The request as the runtime's own `Request`. A framework may hand its own kind (Next.js's `NextRequest`), which some
1243
+ * runtimes can't copy as a `Request` (`new Request(it, init)` reads it as the text `[object Request]`) but read
1244
+ * well as the options of a new one.
1245
+ */
1246
+ const plainRequest = (request) => new Request(request.url, request);
1204
1247
  /** The Database connection a request's sign-in uses: one per request in a deployment, one per process elsewhere. */
1205
1248
  function requestDatabase(open, what) {
1206
1249
  const perRequest = /* @__PURE__ */ new WeakMap();
@@ -1377,12 +1420,23 @@ function createAuth(options = {}) {
1377
1420
  made = {
1378
1421
  store,
1379
1422
  env,
1380
- settings: settingsReader(store, options.clock),
1423
+ settings: settingsReader(store, options.clock, here),
1381
1424
  allow: rateLimiter(store, options.clock)
1382
1425
  };
1383
1426
  }
1384
1427
  return made;
1385
1428
  };
1429
+ /** The secret sessions are signed with; throws, saying how to set it, where there is none. */
1430
+ const secretOf = () => {
1431
+ const secret = options.secret || base().env.AUTH_SECRET;
1432
+ if (!secret) throw new AuthError("forbidden", "Sign-in needs AUTH_SECRET in this environment: midsummer env set <team>/<project> AUTH_SECRET --kind secret --generate --environment <environment>. Outside Midsummer, set it to 32 random characters or more.");
1433
+ return secret;
1434
+ };
1435
+ /** Throws what a misconfigured app is told (no database to keep rows in, no AUTH_SECRET), reading nothing: before any answer that needs no read. */
1436
+ const configured = () => {
1437
+ base();
1438
+ secretOf();
1439
+ };
1386
1440
  /** 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
1441
  const appNameOf = (settings, origin) => settings.branding.name ?? options.appName ?? base().env.APP_NAME ?? defaultAppName(origin);
1388
1442
  /** Work that follows a request, such as the new-device mail, until it ends. */
@@ -1486,35 +1540,38 @@ function createAuth(options = {}) {
1486
1540
  const { store, env, settings } = base();
1487
1541
  const now = await settings(), appName = appNameOf(now, normal);
1488
1542
  const id = `${normal}\n${appName}\n${now.confirmEmail}`;
1489
- let found = kept.get(id);
1490
- if (!found) {
1491
- const secret = options.secret || env.AUTH_SECRET;
1492
- if (!secret) throw new AuthError("forbidden", "Sign-in needs AUTH_SECRET in this environment: midsummer env set <team>/<project> AUTH_SECRET --kind secret --generate --environment <environment>. Outside Midsummer, set it to 32 random characters or more.");
1493
- found = buildEngine({
1494
- origin: normal,
1495
- appName,
1496
- secret,
1497
- store,
1498
- env,
1499
- agents: settingsOfAgents,
1500
- admit,
1501
- changed: changed(normal),
1502
- impersonationS: IMPERSONATION_S,
1503
- cacheS: 300,
1504
- confirmEmail: now.confirmEmail,
1505
- invitationUrl: options.invitationUrl ?? ((from, invitation) => `${from}/api/auth/ui/invitation/${invitation}`),
1506
- send: async (mail) => sendOne(await settings(), normal, mail)
1507
- });
1508
- if (kept.size >= KEPT_ORIGINS) kept.delete(kept.keys().next().value);
1509
- kept.set(id, found);
1510
- }
1511
- return found;
1543
+ const found = kept.get(id);
1544
+ if (found) return found;
1545
+ const secret = secretOf();
1546
+ const built = buildEngine({
1547
+ origin: normal,
1548
+ appName,
1549
+ secret,
1550
+ store,
1551
+ env,
1552
+ agents: settingsOfAgents,
1553
+ admit,
1554
+ changed: changed(normal),
1555
+ impersonationS: IMPERSONATION_S,
1556
+ cacheS: 300,
1557
+ confirmEmail: now.confirmEmail,
1558
+ invitationUrl: options.invitationUrl ?? ((from, invitation) => `${from}/api/auth/ui/invitation/${invitation}`),
1559
+ send: async (mail) => sendOne(await settings(), normal, mail)
1560
+ });
1561
+ await built.ready;
1562
+ if (kept.size >= KEPT_ORIGINS) kept.delete(kept.keys().next().value);
1563
+ kept.set(id, built);
1564
+ return built;
1512
1565
  };
1513
1566
  const declared = (scope, what) => {
1514
1567
  if (!Object.hasOwn(settingsOfAgents.scopes, scope)) throw new AuthError("invalid", `${what} the scope ${scope}, which the app doesn't declare: add it to createAuth({ scopes }).`);
1515
1568
  };
1516
- /** The person signed in themselves, with their session's cookie. */
1569
+ /** The person signed in themselves, with their session's cookie; null at once, reading nothing, for a request without one. */
1517
1570
  async function person(request, fresh = false) {
1571
+ if (!hasSessionCookie(request)) {
1572
+ configured();
1573
+ return null;
1574
+ }
1518
1575
  const found = await (await at(originOf(request))).api.getSession({
1519
1576
  headers: request.headers,
1520
1577
  ...fresh ? { query: { disableCookieCache: true } } : {}
@@ -1792,7 +1849,7 @@ function createAuth(options = {}) {
1792
1849
  /**
1793
1850
  * `GET /api/auth/database-token`, for the page's `signedInDatabase()`: the address of the database sign-in keeps its
1794
1851
  * 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
1852
+ * never internal ones, carrying their name and email as claims (on Midsummer; a key's token carries their id alone). Someone not signed in gets the address alone, to connect as no one. On Midsummer it needs no
1796
1853
  * key, previews and `midsummer dev` included; elsewhere it uses the database key sign-in uses.
1797
1854
  */
1798
1855
  async function databaseToken(request) {
@@ -1814,18 +1871,26 @@ function createAuth(options = {}) {
1814
1871
  if (!signedIn) return answer(200, { url: await databaseUrl(where) });
1815
1872
  return answer(200, await userToken({
1816
1873
  ...where,
1817
- as: signedIn.user.id
1874
+ as: signedIn.user.id,
1875
+ profile: {
1876
+ name: signedIn.user.name,
1877
+ email: signedIn.user.email
1878
+ }
1818
1879
  }));
1819
1880
  }
1820
1881
  /** Serves one request under `/api/auth`: settings, account calls, hosted pages, the guard, then the engine. */
1821
1882
  async function serve(request) {
1822
1883
  const origin = originOf(request), { pathname } = new URL(request.url);
1884
+ const path = pathname.startsWith(`/api/auth/`) ? pathname.slice(9) : void 0;
1885
+ if (path === "/session" && request.method === "GET" && !hasSessionCookie(request)) {
1886
+ configured();
1887
+ return Response.json(null, { headers: { "Cache-Control": "no-store" } });
1888
+ }
1823
1889
  const { settings: read, env, allow } = base();
1824
1890
  const settings = await read();
1825
- const engine = await at(origin), appName = appNameOf(settings, origin);
1826
- if (pathname === "/.well-known/oauth-authorization-server") return engine.handler(new Request(`${origin}/.well-known/oauth-authorization-server${AUTH_PATH}`, request));
1827
- if (!pathname.startsWith(`/api/auth/`)) return engine.handler(request);
1828
- const path = pathname.slice(9);
1891
+ const appName = appNameOf(settings, origin);
1892
+ if (pathname === "/.well-known/oauth-authorization-server") return (await at(origin)).handler(new Request(`${origin}/.well-known/oauth-authorization-server${AUTH_PATH}`, request));
1893
+ if (path === void 0) return (await at(origin)).handler(request);
1829
1894
  const shown = publicSettings(settings, appName), keyed = (name) => !!(env[`${name}_CLIENT_ID`] && env[`${name}_CLIENT_SECRET`]);
1830
1895
  const offered = {
1831
1896
  ...shown,
@@ -1841,12 +1906,13 @@ function createAuth(options = {}) {
1841
1906
  }, { headers: { "Cache-Control": "no-store" } });
1842
1907
  if (`/api/auth${path}` === "/api/auth/database-token" && request.method === "GET") return databaseToken(request);
1843
1908
  if (path.startsWith("/account/")) return account(request, path.slice(8), origin);
1844
- if (pathname === CONSENT_PATH && settingsOfAgents.consentPage === CONSENT_PATH) return consent(request, origin, engine, appName);
1845
1909
  if (path.startsWith("/ui/")) return hostedPage(request, path.slice(3), {
1846
1910
  auth,
1847
1911
  settings: offered,
1848
1912
  scopes: settingsOfAgents.scopes
1849
1913
  });
1914
+ const engine = await at(origin);
1915
+ if (pathname === CONSENT_PATH && settingsOfAgents.consentPage === CONSENT_PATH) return consent(request, origin, engine, appName);
1850
1916
  const route = Object.hasOwn(AUTH_ROUTES, path) ? path : void 0;
1851
1917
  if (route && request.method !== AUTH_ROUTES[route].method) return refusal(405, "METHOD_NOT_ALLOWED", `${AUTH_PATH}${route} takes ${AUTH_ROUTES[route].method}.`);
1852
1918
  const inner = route ? new Request(`${origin}${AUTH_PATH}${AUTH_ROUTES[route].engine}${new URL(request.url).search}`, request) : request;
@@ -1885,7 +1951,8 @@ function createAuth(options = {}) {
1885
1951
  });
1886
1952
  const fits = (value) => value === void 0 || JSON.stringify(value ?? null).length <= METADATA_BYTES;
1887
1953
  const auth = {
1888
- async handler(request) {
1954
+ async handler(given) {
1955
+ const request = plainRequest(given);
1889
1956
  const current = here();
1890
1957
  if (!current || held.has(current)) return serve(request).catch(failed);
1891
1958
  held.set(current, []);
@@ -1,4 +1,14 @@
1
1
  import { t as DatabaseError } from "./errors-CnQduDOt.mjs";
2
+ //#region src/database/door-socket.d.ts
3
+ /** A TCP + TLS socket as the runtime opens one: its two streams, when it opened and closed, and `close`. */
4
+ interface StreamSocket {
5
+ readonly readable: ReadableStream<Uint8Array>;
6
+ readonly writable: WritableStream<Uint8Array>;
7
+ readonly opened?: Promise<unknown>;
8
+ readonly closed?: Promise<unknown>;
9
+ close(): unknown;
10
+ }
11
+ //#endregion
2
12
  //#region src/database/client.d.ts
3
13
  /** A function's reference, as `api.<file>.<export>` holds it, typed by its arguments and its answer. */
4
14
  interface Reference<Kind extends "query" | "mutation" | "action", Args = any, Returns = any> {
@@ -60,18 +70,27 @@ interface DatabaseToken {
60
70
  readonly url: string;
61
71
  readonly expiresAt: number;
62
72
  }
73
+ /** A door a request hands its server: the Database's address and token, and where its socket is (`host:port`), where it has one. */
74
+ interface DoorToken extends DatabaseToken {
75
+ readonly socket?: string;
76
+ }
63
77
  /**
64
78
  * What Midsummer hands a Deployment as `context.database`: a token and address for a Database its Environment binds,
65
79
  * as the app's server, and (`userToken`) as one of the app's users, for that user's browser.
66
80
  */
67
81
  interface BoundDatabases {
68
82
  token(binding: string): Promise<DatabaseToken>;
69
- userToken?(binding: string, as: string): Promise<DatabaseToken>;
83
+ userToken?(binding: string, as: string, profile?: UserProfile): Promise<DatabaseToken>;
70
84
  /**
71
85
  * Where the app's server calls the Database bound as `binding`, with its token and when that runs out, handed in
72
86
  * with the request, so connecting asks for nothing. Undefined where the request was handed none: `token` serves.
73
87
  */
74
- door?(binding: string): DatabaseToken | undefined;
88
+ door?(binding: string): DoorToken | undefined;
89
+ /**
90
+ * Opens a TCP + TLS socket to `address` (`host:port`, a door's `socket`) for the request being served, which lives
91
+ * only as long as that request. Undefined where the runtime has none: every call goes over HTTP.
92
+ */
93
+ socket?(address: string): StreamSocket | Promise<StreamSocket>;
75
94
  /**
76
95
  * Has the Database bound as `binding` made again after its door returned that it has none for a call sent at `since`
77
96
  * (as after a move, its rows gone): true when that call should be sent once more.
@@ -80,10 +99,21 @@ interface BoundDatabases {
80
99
  /** Adds an entry to the `Server-Timing` of the request's response, where Midsummer turned that on for its own diagnostics. */
81
100
  note?(entry: string): void;
82
101
  }
102
+ /** What a user's token says of them beside their id, as the OIDC claims `name` and `email`, each at most `PROFILE_MOST` characters. */
103
+ interface UserProfile {
104
+ readonly name?: string;
105
+ readonly email?: string;
106
+ }
107
+ /** The most characters a `UserProfile`'s name or email carries. */
108
+ declare const PROFILE_MOST = 320;
109
+ /** The profile a token carries: each of its fields that is text of 1 to `PROFILE_MOST` characters, else left out. */
110
+ declare function profileClaims(profile: UserProfile | undefined): UserProfile;
83
111
  /**
84
112
  * A token for one signed-in user of your app, for your server to hand to that user's browser, which connects with
85
113
  * it (`signedInDatabase()`, `@midsummer-ai/sdk/react`'s `DatabaseProvider`, or `connect({ url, token, refresh })`).
86
- * Your server gives the user's id as `as`; your functions see that id as `ctx.auth.subject`. The token
114
+ * Your server gives the user's id as `as`; your functions see that id as `ctx.auth.subject`. On Midsummer, `profile`
115
+ * puts the user's name and email in the token too, as the claims `name` and `email`; a token exchanged for a
116
+ * database key carries the id alone. The token
87
117
  * runs public functions only, never internal ones. It lasts ten minutes: the browser asks your server again before
88
118
  * then. With Auth, `auth.handler` serves it already, at `/api/auth/database-token`.
89
119
  *
@@ -96,6 +126,7 @@ interface BoundDatabases {
96
126
  */
97
127
  declare function userToken(options: {
98
128
  readonly as: string;
129
+ readonly profile?: UserProfile;
99
130
  readonly binding?: string;
100
131
  readonly key?: string;
101
132
  readonly api?: string;
@@ -208,4 +239,4 @@ declare function clerk(getToken: (options: {
208
239
  */
209
240
  declare function oidc(getToken: (forceRefresh: boolean) => Promise<string | null | undefined> | string | null | undefined): FetchToken;
210
241
  //#endregion
211
- export { oidc as _, DATABASE_TOKEN_PATH as a, DatabaseToken as c, ReturnsOf as d, SignedInDatabase as f, databaseUrl as g, connect as h, ConnectOptions as i, FetchToken as l, clerk as m, AuthState as n, Database as o, auth0 as p, BoundDatabases as r, DatabaseClient as s, ArgsOf as t, Reference as u, signedInDatabase as v, userToken as y };
242
+ export { userToken as C, signedInDatabase as S, clerk as _, DATABASE_TOKEN_PATH as a, oidc as b, DatabaseToken as c, PROFILE_MOST as d, Reference as f, auth0 as g, UserProfile as h, ConnectOptions as i, DoorToken as l, SignedInDatabase as m, AuthState as n, Database as o, ReturnsOf as p, BoundDatabases as r, DatabaseClient as s, ArgsOf as t, FetchToken as u, connect as v, profileClaims as x, databaseUrl as y };