@midsummer-ai/sdk 0.1.0-staging.3656 → 0.1.0-staging.3662

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/auth/contract.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { c as LIMIT_WINDOW_MS, l as SETTINGS_TTL_MS, n as AuthError, s as LIMITS } from "../auth-CND9RW17.mjs";
1
+ import { c as LIMIT_WINDOW_MS, l as SETTINGS_TTL_MS, n as AuthError, s as LIMITS } from "../auth-D50wCpNm.mjs";
2
2
  import { IMPERSONATION_TOKEN_MS, startImpersonation } from "./impersonate.mjs";
3
3
  //#region src/auth/contract.ts
4
4
  /**
package/auth/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as auth, i as SESSION_CACHE_S, n as AuthError, o as createAuth, r as IMPERSONATION_S, t as AUTH_PATH, u as databaseStore } from "../auth-CND9RW17.mjs";
1
+ import { a as auth, i as SESSION_CACHE_S, n as AuthError, o as createAuth, r as IMPERSONATION_S, t as AUTH_PATH, u as databaseStore } from "../auth-D50wCpNm.mjs";
2
2
  import { checkSignInMail, signInWords } from "./mail.mjs";
3
3
  import { n as authFiles } from "../files-DAFOuID_.mjs";
4
4
  export { AUTH_PATH, AuthError, IMPERSONATION_S, SESSION_CACHE_S, auth, authFiles, checkSignInMail, createAuth, databaseStore, signInWords };
@@ -1298,6 +1298,22 @@ async function inOurWords(response) {
1298
1298
  headers: response.headers
1299
1299
  });
1300
1300
  }
1301
+ /** What a person reads when sign-in couldn't serve their request; why is in the server's log. */
1302
+ const unavailable = () => Response.json({
1303
+ code: "UNAVAILABLE",
1304
+ message: "Sign-in isn't working right now. Try again in a moment."
1305
+ }, {
1306
+ status: 500,
1307
+ headers: { "Cache-Control": "no-store" }
1308
+ });
1309
+ /**
1310
+ * A request sign-in couldn't serve, such as one its database refused: the cause is logged, in our words, where the
1311
+ * deployment's logs show it, and the person is answered `unavailable`.
1312
+ */
1313
+ function failed(error) {
1314
+ console.error(`[auth] Sign-in couldn't answer a request: ${ourWords(error instanceof Error ? `${error.name}: ${error.message}` : String(error))}`);
1315
+ return unavailable();
1316
+ }
1301
1317
  /** Sign-in over `options`: nothing is made until the first request, which may be at a module's top. */
1302
1318
  function createAuth(options = {}) {
1303
1319
  const kept = /* @__PURE__ */ new Map();
@@ -1734,7 +1750,9 @@ function createAuth(options = {}) {
1734
1750
  headers.set("x-forwarded-for", here().ip);
1735
1751
  return headers;
1736
1752
  })() }) : request;
1737
- const answered = await inOurWords(await engine.handler(forwarded));
1753
+ const engineAnswer = await engine.handler(forwarded);
1754
+ if (engineAnswer.status >= 500 && !engineAnswer.headers.get("content-type")) return unavailable();
1755
+ const answered = await inOurWords(engineAnswer);
1738
1756
  return answered.ok && FRESHENS.has(path) ? freshened(engine, origin, forwarded, answered) : answered;
1739
1757
  }
1740
1758
  const recordOf = (row) => ({
@@ -1745,10 +1763,10 @@ function createAuth(options = {}) {
1745
1763
  const auth = {
1746
1764
  async handler(request) {
1747
1765
  const current = here();
1748
- if (!current || held.has(current)) return serve(request);
1766
+ if (!current || held.has(current)) return serve(request).catch(failed);
1749
1767
  held.set(current, []);
1750
1768
  try {
1751
- return await serve(request);
1769
+ return await serve(request).catch(failed);
1752
1770
  } finally {
1753
1771
  const made = held.get(current) ?? [];
1754
1772
  held.delete(current);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midsummer-ai/sdk",
3
- "version": "0.1.0-staging.3656",
3
+ "version": "0.1.0-staging.3662",
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.",