@midsummer-ai/sdk 0.1.0-staging.3728 → 0.1.0-staging.3734

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 +7 -2
  15. package/auth/react.mjs +44 -8
  16. package/auth/stand-in.d.mts +1 -1
  17. package/{auth-BA5Xdi-4.mjs → auth-BaGXVRYd.mjs} +38 -8
  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-C2Jo3JqT.d.mts → index-C8Ti5raa.d.mts} +2 -2
  37. package/index.mjs +1 -1
  38. package/package.json +1 -1
  39. package/{qr-CBh0LP2_.mjs → qr-Br1sOBmT.mjs} +1 -0
  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
@@ -1,5 +1,5 @@
1
1
  import { t as DatabaseError } from "../errors-CnQduDOt.mjs";
2
- import { a as Database, c as Reference } from "../client-D3BZs3LA.mjs";
2
+ import { o as Database, u as Reference } from "../client-oAVg6vn_.mjs";
3
3
  import { ReactNode } from "react";
4
4
  //#region src/database/react.d.ts
5
5
  type ArgsOf<F> = F extends Reference<any, infer A, any> ? A : never;
@@ -1,4 +1,4 @@
1
- import { r as storage } from "../src-BKKy9km-.mjs";
1
+ import { r as storage } from "../src-DgX-tCDn.mjs";
2
2
  import { standIn } from "../stand-in.mjs";
3
3
  import { _ as shapeError, a as tagBytes, b as valueAt, f as indexFields, g as shapeAt, i as keyBytes, o as untagBytes, v as tableCode } from "../bytes-C2pcyl9u.mjs";
4
4
  import { A as comparePrefix, M as indexTuple, O as valueKey, S as nextCron, T as readLimited, _ as isFunction, a as Refusal, b as limits, i as NotFoundError, j as documentBytes, k as compareKey, l as fetchOver, o as TooLarge, r as InsufficientError, y as isRouter } from "../server-Drjni3-F.mjs";
package/email/client.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { C as serveMessages, S as serveBound, b as boundEmail, x as client, y as MESSAGES_PATH } from "../email-ynNo0HqT.mjs";
1
+ import { C as serveMessages, S as serveBound, b as boundEmail, x as client, y as MESSAGES_PATH } from "../email-DmWG_Ug-.mjs";
2
2
  export { MESSAGES_PATH, boundEmail, client, serveBound, serveMessages };
@@ -1,4 +1,4 @@
1
- import { t as EmailError } from "../email-ynNo0HqT.mjs";
1
+ import { t as EmailError } from "../email-DmWG_Ug-.mjs";
2
2
  //#region src/email/contract.ts
3
3
  /**
4
4
  * Email's contract: what every engine promises, as cases any test runner can run. The Stand-in runs
package/email/inbox.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as inbox, d as INBOX_HEADER, f as MAX_REPLY, g as checkReply, h as checkPage, m as boundInbox, p as MAX_THREADS, v as serveInbox } from "../email-ynNo0HqT.mjs";
1
+ import { _ as inbox, d as INBOX_HEADER, f as MAX_REPLY, g as checkReply, h as checkPage, m as boundInbox, p as MAX_THREADS, v as serveInbox } from "../email-DmWG_Ug-.mjs";
2
2
  export { INBOX_HEADER, MAX_REPLY, MAX_THREADS, boundInbox, checkPage, checkReply, inbox, serveInbox };
package/email/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as inbox, a as MAX_MESSAGE_BYTES, c as checkMessage, d as INBOX_HEADER, i as MAX_BATCH, l as email, n as MAX_ATTACHMENTS, o as MAX_RECIPIENTS, p as MAX_THREADS, r as MAX_ATTACHMENT_BYTES, s as addressOf, t as EmailError, u as verifyWebhook } from "../email-ynNo0HqT.mjs";
1
+ import { _ as inbox, a as MAX_MESSAGE_BYTES, c as checkMessage, d as INBOX_HEADER, i as MAX_BATCH, l as email, n as MAX_ATTACHMENTS, o as MAX_RECIPIENTS, p as MAX_THREADS, r as MAX_ATTACHMENT_BYTES, s as addressOf, t as EmailError, u as verifyWebhook } from "../email-DmWG_Ug-.mjs";
2
2
  export { EmailError, INBOX_HEADER, MAX_ATTACHMENTS, MAX_ATTACHMENT_BYTES, MAX_BATCH, MAX_MESSAGE_BYTES, MAX_RECIPIENTS, MAX_THREADS, addressOf, checkMessage, email, inbox, verifyWebhook };
package/email/smtp.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { l as email, t as EmailError, x as client } from "../email-ynNo0HqT.mjs";
1
+ import { l as email, t as EmailError, x as client } from "../email-DmWG_Ug-.mjs";
2
2
  import { createServer } from "node:net";
3
3
  import { createServer as createServer$1 } from "node:tls";
4
4
  //#region src/email/smtp.ts
@@ -1,4 +1,4 @@
1
- import { s as addressOf, t as EmailError } from "../email-ynNo0HqT.mjs";
1
+ import { s as addressOf, t as EmailError } from "../email-DmWG_Ug-.mjs";
2
2
  //#region src/email/stand-in.ts
3
3
  /**
4
4
  * Email's Stand-in: the Capability's behaviour in memory, for `midsummer dev` and tests. It sends
@@ -1,4 +1,4 @@
1
- import { n as late, 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
  import { verifyEvent } from "./apps.mjs";
3
3
  //#region src/email/client.ts
4
4
  /**
@@ -304,7 +304,8 @@ function serveInbox(engineFor) {
304
304
  * await email().batch(people.map((person) => ({ from: "news@mail.acme.dev", to: person.email, template: "digest", variables: { name: person.name },
305
305
  * stream: "broadcast", topic: "digest", key: `digest-2026-11-${person.id}` })))
306
306
  *
307
- * With no engine, `email()` sends from a deployment, in any framework, with nothing to connect.
307
+ * With no engine, `email()` sends from a deployment, in any framework, with nothing to connect. Under `midsummer dev`
308
+ * each Message is printed, never sent.
308
309
  * Otherwise `engine` is where Messages go: the Stand-in (`@midsummer-ai/sdk/email/stand-in`) in tests,
309
310
  * or code outside Midsummer with an email key (`email(client(origin, { key }))` from
310
311
  * `@midsummer-ai/sdk/email/client`). Every engine is held to the cases in `@midsummer-ai/sdk/email/contract`.
@@ -407,10 +408,23 @@ function checkMessage(message) {
407
408
  ...sendAt !== void 0 ? { sendAt } : {}
408
409
  };
409
410
  }
411
+ /**
412
+ * Email as `midsummer dev` sends it from a framework's own dev server, which has no handle: each Message is printed,
413
+ * never sent, as the runtime's own does, from any address.
414
+ */
415
+ const devEmail = { async send(message) {
416
+ console.log(`email: ${message.from} to ${message.to.join(", ")}: ${message.subject ?? `template ${message.template}`} (printed here, not sent)`);
417
+ return {
418
+ id: `msg_dev${Math.random().toString(36).slice(2, 10)}`,
419
+ state: "sent",
420
+ suppressed: []
421
+ };
422
+ } };
410
423
  function email(given) {
411
424
  const engine = given ?? late(() => {
412
425
  const handle = here()?.email;
413
426
  if (handle) return boundEmail(handle);
427
+ if (processEnv().MIDSUMMER_DEV === "1") return devEmail;
414
428
  throw new EmailError("forbidden", "This code runs outside a deployment, so it sends with an email key: email(client(origin, { key })).");
415
429
  });
416
430
  return {
@@ -48163,6 +48163,14 @@ async function verifyPassword(input) {
48163
48163
  function ourWords(text) {
48164
48164
  return text.replace(/\[better[- ]?auth\]:?\s*/gi, "").replace(/BETTER_AUTH_/g, "AUTH_").replace(/better[- ]?auth/gi, "sign-in");
48165
48165
  }
48166
+ /**
48167
+ * One of the engine's log lines in Midsummer's words: one about its own settings says what happened instead, since an
48168
+ * app can't change them; any other is `ourWords`.
48169
+ */
48170
+ function engineLine(text) {
48171
+ if (/^Rate limiting could not determine a client IP/u.test(text)) return "A request to sign-in came with no visitor's address (x-forwarded-for), so its rate limits count every such request together. On Midsummer the edge sets it; elsewhere, have your host or proxy set x-forwarded-for to the visitor's address alone.";
48172
+ return ourWords(text);
48173
+ }
48166
48174
  /** An error as one log line: its name, its `code` when it has one, and its message. */
48167
48175
  function errorLine(error) {
48168
48176
  const code = error.code;
@@ -48350,10 +48358,13 @@ function optionsFor(config, store) {
48350
48358
  });
48351
48359
  }
48352
48360
  }) },
48353
- advanced: { cookiePrefix: "midsummer" },
48361
+ advanced: {
48362
+ cookiePrefix: "midsummer",
48363
+ ipAddress: { ipAddressHeaders: ["x-forwarded-for"] }
48364
+ },
48354
48365
  logger: {
48355
48366
  level: "warn",
48356
- log: (level, message, ...args) => (level === "error" ? console.error : console.warn)(`[auth] ${ourWords(String(message))}`, ...args.map((arg) => typeof arg === "string" ? ourWords(arg) : arg instanceof Error ? ourWords(errorLine(arg)) : arg))
48367
+ log: (level, message, ...args) => (level === "error" ? console.error : console.warn)(`[auth] ${engineLine(String(message))}`, ...args.map((arg) => typeof arg === "string" ? ourWords(arg) : arg instanceof Error ? ourWords(errorLine(arg)) : arg))
48357
48368
  },
48358
48369
  telemetry: { enabled: false },
48359
48370
  database: engineAdapter(store, config.changed),
@@ -9,6 +9,14 @@ function processEnv() {
9
9
  return globalThis.process?.env ?? {};
10
10
  }
11
11
  /**
12
+ * Where a call to Midsummer's API goes when the caller names no `api`: `MIDSUMMER_API`, which Midsummer sets for
13
+ * every build and deployment, so code reaches the site it runs on; else the site this package was published for
14
+ * (`PUBLISHED_API`).
15
+ */
16
+ function platformApi() {
17
+ return (here()?.env?.MIDSUMMER_API || processEnv().MIDSUMMER_API || "https://api.staging.midsummer.new").replace(/\/+$/u, "");
18
+ }
19
+ /**
12
20
  * An engine whose every call goes to the one `current` gives at that moment: the request's own, made
13
21
  * when the call is. `current` throws the product's own error when there is none. It may give the
14
22
  * engine as a promise, for one whose every call returns a promise, as the queues engine does.
@@ -51,4 +59,4 @@ function workloadTransport(path, fail) {
51
59
  } };
52
60
  }
53
61
  //#endregion
54
- export { workloadTransport as i, late as n, processEnv as r, here as t };
62
+ export { workloadTransport as a, processEnv as i, late as n, platformApi as r, here as t };
@@ -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 { n as CaptchaProvider, t as AuthSettings } from "./settings-Dz3irtlu.mjs";
3
3
  import { SignInMail } from "./auth/mail.mjs";
4
4
  //#region src/auth/events.d.ts
@@ -111,7 +111,7 @@ interface AuthOptions {
111
111
  readonly database?: string;
112
112
  /** A database key, for an app hosted outside Midsummer: `DATABASE_KEY` when left out. */
113
113
  readonly key?: string;
114
- /** The platform's API, where a database key is exchanged and events go: `https://api.midsummer.new` when left out. */
114
+ /** The platform's API, where a database key is exchanged and events go: `MIDSUMMER_API` when left out, else the API of the site this package was published for. */
115
115
  readonly api?: string;
116
116
  /** The secret sessions are signed with: `AUTH_SECRET` when left out. */
117
117
  readonly secret?: string;
package/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  import { t as StorageError } from "./errors-B1tO_wdm.mjs";
2
- import { i as streamsOf, n as bucket, r as storage, t as WORKLOAD_PATH } from "./src-BKKy9km-.mjs";
2
+ import { i as streamsOf, n as bucket, r as storage, t as WORKLOAD_PATH } from "./src-DgX-tCDn.mjs";
3
3
  export { StorageError, WORKLOAD_PATH, bucket, storage, streamsOf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midsummer-ai/sdk",
3
- "version": "0.1.0-staging.3728",
3
+ "version": "0.1.0-staging.3734",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "description": "Midsummer's handles for an app's code: its Database, Storage, Queues, Vector DB, AI, Email and Agents, with stand-ins for tests.",
@@ -79,6 +79,7 @@ function defaultAppName(origin) {
79
79
  const WORDS = {
80
80
  signIn: {
81
81
  title: (app) => `Sign in to ${app}`,
82
+ loading: "Loading sign-in",
82
83
  submit: "Sign in",
83
84
  noAccount: "Don't have an account?",
84
85
  signUp: "Sign up",
package/queues/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as workloadTransport, n as late, r as processEnv, t as here } from "../here-1plIxb0D.mjs";
1
+ import { a as workloadTransport, i as processEnv, n as late, t as here } from "../here-BKjizr_N.mjs";
2
2
  //#region src/queues/index.ts
3
3
  /**
4
4
  * Queues: a Team's Queues of Messages, which the SDK reaches by the name an Environment binds each one
package/s3.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as StorageError } from "./errors-B1tO_wdm.mjs";
2
2
  import { a as checkMetadata, l as checkUploadId, m as sha256, n as checkBucketName, o as checkPartNumber, r as checkKey, s as checkParts } from "./names-Do0ot5Ha.mjs";
3
- import { i as streamsOf } from "./src-BKKy9km-.mjs";
3
+ import { i as streamsOf } from "./src-DgX-tCDn.mjs";
4
4
  //#region src/s3.ts
5
5
  /**
6
6
  * Storage over the S3 protocol, so the tools and SDKs that speak it reach a Project's Buckets
package/socket.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { d as sameHex, f as sign, m as socketSession, p as socket, u as keyed } from "./src-BKKy9km-.mjs";
1
+ import { d as sameHex, f as sign, m as socketSession, p as socket, u as keyed } from "./src-DgX-tCDn.mjs";
2
2
  export { keyed, sameHex, sign, socket, socketSession };
@@ -1,7 +1,7 @@
1
1
  import { t as StorageError } from "./errors-B1tO_wdm.mjs";
2
2
  import { a as checkMetadata, c as checkRange, d as invalid, i as checkListLimit, l as checkUploadId, n as checkBucketName, o as checkPartNumber, r as checkKey, s as checkParts } from "./names-Do0ot5Ha.mjs";
3
3
  import { bucketsOf, remote, repeatable, serve } from "./wire.mjs";
4
- import { i as workloadTransport, n as late, r as processEnv, t as here } from "./here-1plIxb0D.mjs";
4
+ import { a as workloadTransport, i as processEnv, n as late, t as here } from "./here-BKjizr_N.mjs";
5
5
  //#region src/socket.ts
6
6
  /**
7
7
  * Storage's wire over a WebSocket: one connection carries every call, so a client pays for one HTTP
@@ -383,7 +383,7 @@ function serveSigned(options) {
383
383
  * import { storage } from "@midsummer-ai/sdk"
384
384
  * import { client } from "@midsummer-ai/sdk/client"
385
385
  *
386
- * const files = storage(client("https://api.midsummer.new", { key, secret }))
386
+ * const files = storage(client("https://api.<site>", { key, secret }))
387
387
  *
388
388
  * In tests, `standIn` from `@midsummer-ai/sdk/stand-in` keeps files in memory. All three pass the same
389
389
  * tests, in `@midsummer-ai/sdk/contract`, and only what those tests check is guaranteed.
@@ -120,7 +120,7 @@ interface Files {
120
120
  }
121
121
  /**
122
122
  * A bucket's files for one of your app's users, from their browser or your own code: `origin` is the API's address
123
- * (`https://api.midsummer.new`), and `token` gives the user's token from your sign-in provider, or nothing for anyone.
123
+ * (`https://api.<site>`, the site your team is on), and `token` gives the user's token from your sign-in provider, or nothing for anyone.
124
124
  */
125
125
  declare function files(options: {
126
126
  readonly origin: string;
package/storage/files.mjs CHANGED
@@ -24,7 +24,7 @@ import { i as verifier, r as trustedOf, t as authConfigOf } from "../auth-1W-Szp
24
24
  *
25
25
  * import { files } from "@midsummer-ai/sdk/files"
26
26
  *
27
- * const avatars = files({ origin: "https://api.midsummer.new", team: "acme", bucket: "avatars", token: () => auth.getToken() })
27
+ * const avatars = files({ origin: "https://api.<site>", team: "acme", bucket: "avatars", token: () => auth.getToken() })
28
28
  * await avatars.put(`users/${user.id}/photo.png`, file, { contentType: file.type })
29
29
  * const mine = await avatars.list({ prefix: `users/${user.id}/` })
30
30
  *
@@ -415,7 +415,7 @@ function filesServer(options) {
415
415
  }
416
416
  /**
417
417
  * A bucket's files for one of your app's users, from their browser or your own code: `origin` is the API's address
418
- * (`https://api.midsummer.new`), and `token` gives the user's token from your sign-in provider, or nothing for anyone.
418
+ * (`https://api.<site>`, the site your team is on), and `token` gives the user's token from your sign-in provider, or nothing for anyone.
419
419
  */
420
420
  function files(options) {
421
421
  checkBucketName(options.bucket);
@@ -1,4 +1,4 @@
1
- import { a as Database } from "./client-D3BZs3LA.mjs";
1
+ import { o as Database } from "./client-oAVg6vn_.mjs";
2
2
  //#region src/auth/store.d.ts
3
3
  /** One of `db/auth.ts`'s functions. */
4
4
  type AuthCall = "create" | "findOne" | "findMany" | "count" | "update" | "updateMany" | "upsert" | "deleteMany" | "consume" | "increment" | "page";
package/vector/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as late, t as here } from "../here-1plIxb0D.mjs";
1
+ import { n as late, t as here } from "../here-BKjizr_N.mjs";
2
2
  import { C as Vectors, E as vectorErrorCodes, S as TextSearch, T as VectorError, _ as MAX_TOP_K, a as remote, b as NamespaceName, c as Aggregation, d as MAX_BATCH, f as MAX_DIMENSION, g as MAX_TEXT, h as MAX_QUERIES, l as Ids, m as MAX_METADATA_BYTES, n as direct, p as MAX_FULL_TEXT, u as List, v as MAX_VALUE, w as checked, x as Query, y as MultiQuery } from "../wire-BnZXAFNf.mjs";
3
3
  //#region src/vector/index.ts
4
4
  /**