@midsummer-ai/sdk 0.1.0-staging.3725 → 0.1.0-staging.3728
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.d.mts +1 -1
- package/auth/contract.mjs +1 -1
- package/auth/index.d.mts +1 -1
- package/auth/index.mjs +1 -1
- package/auth/react.d.mts +5 -1
- package/auth/react.mjs +32 -6
- package/{auth-C9V1Xb0w.mjs → auth-BA5Xdi-4.mjs} +9 -8
- package/{index-DYSS7OGg.d.mts → index-C2Jo3JqT.d.mts} +1 -1
- package/package.json +1 -1
- package/{qr-BR3Ld80n.mjs → qr-CBh0LP2_.mjs} +18 -1
package/auth/contract.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as AuthStore } from "../store-CLGBhEpO.mjs";
|
|
2
2
|
import { SignInMail } from "./mail.mjs";
|
|
3
|
-
import { a as Auth } from "../index-
|
|
3
|
+
import { a as Auth } from "../index-C2Jo3JqT.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-
|
|
1
|
+
import { c as LIMITS, l as LIMIT_WINDOW_MS, r as AuthError, u as SETTINGS_TTL_MS } from "../auth-BA5Xdi-4.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
1
|
import { n as AuthStore, r as databaseStore, t as AuthCall } from "../store-CLGBhEpO.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-
|
|
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-C2Jo3JqT.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-
|
|
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-BA5Xdi-4.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/react.d.mts
CHANGED
|
@@ -29,6 +29,7 @@ declare function SignIn(props: {
|
|
|
29
29
|
readonly title: string;
|
|
30
30
|
readonly lead?: string;
|
|
31
31
|
readonly wide?: boolean;
|
|
32
|
+
readonly appear?: boolean;
|
|
32
33
|
readonly children?: ReactNode;
|
|
33
34
|
}> | null;
|
|
34
35
|
/** Sign-up with a name, an email and a password; under a waitlist, joining it; when the app wants emails confirmed, asking for that. */
|
|
@@ -39,8 +40,9 @@ declare function SignUp(props: {
|
|
|
39
40
|
readonly title: string;
|
|
40
41
|
readonly lead?: string;
|
|
41
42
|
readonly wide?: boolean;
|
|
43
|
+
readonly appear?: boolean;
|
|
42
44
|
readonly children?: ReactNode;
|
|
43
|
-
}> |
|
|
45
|
+
}> | import("react").FunctionComponentElement<{}>;
|
|
44
46
|
/** The signed-in person's picture or initial, opening a menu: their account, and signing out. */
|
|
45
47
|
declare function UserButton(props: {
|
|
46
48
|
readonly accountUrl?: string;
|
|
@@ -63,6 +65,7 @@ declare function UserProfile(): import("react").FunctionComponentElement<{
|
|
|
63
65
|
readonly title: string;
|
|
64
66
|
readonly lead?: string;
|
|
65
67
|
readonly wide?: boolean;
|
|
68
|
+
readonly appear?: boolean;
|
|
66
69
|
readonly children?: ReactNode;
|
|
67
70
|
}> | null;
|
|
68
71
|
/** Which organization the person works in, or their personal account; and making a new one. */
|
|
@@ -80,6 +83,7 @@ declare function OrganizationProfile(props: {
|
|
|
80
83
|
readonly title: string;
|
|
81
84
|
readonly lead?: string;
|
|
82
85
|
readonly wide?: boolean;
|
|
86
|
+
readonly appear?: boolean;
|
|
83
87
|
readonly children?: ReactNode;
|
|
84
88
|
}> | null;
|
|
85
89
|
//#endregion
|
package/auth/react.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as WORDS, c as
|
|
1
|
+
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-CBh0LP2_.mjs";
|
|
2
2
|
import { AuthClientError, authClient } from "./client.mjs";
|
|
3
3
|
import { Fragment, createContext, createElement, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
4
4
|
//#region src/auth/react.ts
|
|
@@ -82,7 +82,11 @@ function Card(props) {
|
|
|
82
82
|
return createElement("div", {
|
|
83
83
|
className: "msa",
|
|
84
84
|
style: color ? { "--msa-brand": color } : void 0
|
|
85
|
-
}, createElement("div", { className:
|
|
85
|
+
}, createElement("div", { className: [
|
|
86
|
+
"msa-card",
|
|
87
|
+
props.wide ? "msa-wide" : "",
|
|
88
|
+
props.appear ? "msa-appear" : ""
|
|
89
|
+
].filter(Boolean).join(" ") }, settings?.branding.logo ? createElement("img", {
|
|
86
90
|
className: "msa-logo",
|
|
87
91
|
src: settings.branding.logo,
|
|
88
92
|
alt: settings.branding.name
|
|
@@ -358,17 +362,39 @@ function SignIn(props) {
|
|
|
358
362
|
})
|
|
359
363
|
}, 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
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* The sign-up screen while the app's settings load: its title, three fields, button and link as bones the size of each,
|
|
367
|
+
* so the form takes their place without anything moving. It shows only after a moment, so a quick load shows none.
|
|
368
|
+
*/
|
|
369
|
+
function SignUpLoading() {
|
|
370
|
+
const bone = (width, className = "msa-bone") => createElement("span", {
|
|
371
|
+
className,
|
|
372
|
+
style: { width }
|
|
373
|
+
});
|
|
374
|
+
return createElement("div", {
|
|
375
|
+
className: "msa",
|
|
376
|
+
role: "status",
|
|
377
|
+
"aria-busy": true,
|
|
378
|
+
"aria-label": WORDS.signUp.loading
|
|
379
|
+
}, createElement("div", { className: "msa-card msa-loading" }, createElement("h1", null, bone("70%")), createElement("div", { className: "msa-bones" }, ...[
|
|
380
|
+
WORDS.fields.name,
|
|
381
|
+
WORDS.fields.email,
|
|
382
|
+
WORDS.fields.password
|
|
383
|
+
].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"))));
|
|
384
|
+
}
|
|
361
385
|
/** 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
386
|
function SignUp(props) {
|
|
363
387
|
const { client, settings } = useAuth();
|
|
364
388
|
const [name, setName] = useState(""), [email, setEmail] = useState(""), [password, setPassword] = useState(""), [captcha, setCaptcha] = useState("");
|
|
365
389
|
const [waiting, setWaiting] = useState(null);
|
|
366
390
|
const call = useCall();
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
391
|
+
const [shaped] = useState(() => !settings);
|
|
392
|
+
if (!settings) return createElement(SignUpLoading);
|
|
393
|
+
const policy = settings.signUp.policy, app = settings.branding.name;
|
|
394
|
+
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
395
|
return createElement(Card, {
|
|
371
|
-
title: WORDS.signUp.title(
|
|
396
|
+
title: WORDS.signUp.title(app),
|
|
397
|
+
appear: shaped,
|
|
372
398
|
...policy === "invite" ? { lead: WORDS.signUp.invite } : {}
|
|
373
399
|
}, createElement("form", { onSubmit: onSubmit(() => void call.run(async () => {
|
|
374
400
|
try {
|
|
@@ -4,7 +4,7 @@ import { sendSignInMail } from "./auth/mail.mjs";
|
|
|
4
4
|
import "./files-DhPeWwcT.mjs";
|
|
5
5
|
import { standIn } from "./auth/stand-in.mjs";
|
|
6
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
|
|
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-CBh0LP2_.mjs";
|
|
8
8
|
//#region src/auth/store.ts
|
|
9
9
|
const KIND = {
|
|
10
10
|
create: "mutation",
|
|
@@ -1382,7 +1382,8 @@ function createAuth(options = {}) {
|
|
|
1382
1382
|
}
|
|
1383
1383
|
return made;
|
|
1384
1384
|
};
|
|
1385
|
-
|
|
1385
|
+
/** 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. */
|
|
1386
|
+
const appNameOf = (settings, origin) => settings.branding.name ?? options.appName ?? base().env.APP_NAME ?? defaultAppName(origin);
|
|
1386
1387
|
/** Work that follows a request, such as the new-device mail, until it ends. */
|
|
1387
1388
|
const background = /* @__PURE__ */ new Set();
|
|
1388
1389
|
/** The events each request on Midsummer made so far, reported as its handler ends: never before its answer. */
|
|
@@ -1421,7 +1422,7 @@ function createAuth(options = {}) {
|
|
|
1421
1422
|
});
|
|
1422
1423
|
if (!user) return;
|
|
1423
1424
|
const device = deviceOf(typeof session.userAgent === "string" ? session.userAgent : null);
|
|
1424
|
-
await sendOne(await settings(), {
|
|
1425
|
+
await sendOne(await settings(), origin, {
|
|
1425
1426
|
to: String(user.email),
|
|
1426
1427
|
kind: "device",
|
|
1427
1428
|
url: `${origin}${AUTH_PATH}/ui/account`,
|
|
@@ -1429,14 +1430,14 @@ function createAuth(options = {}) {
|
|
|
1429
1430
|
});
|
|
1430
1431
|
}
|
|
1431
1432
|
/** Sends one mail with the app's name, branding and sender. */
|
|
1432
|
-
async function sendOne(settings, mail) {
|
|
1433
|
+
async function sendOne(settings, origin, mail) {
|
|
1433
1434
|
const brand = {
|
|
1434
1435
|
...settings.branding.logo ? { logo: settings.branding.logo } : {},
|
|
1435
1436
|
...settings.branding.color ? { color: settings.branding.color } : {}
|
|
1436
1437
|
};
|
|
1437
1438
|
const full = {
|
|
1438
1439
|
...mail,
|
|
1439
|
-
app: appNameOf(settings),
|
|
1440
|
+
app: appNameOf(settings, origin),
|
|
1440
1441
|
...Object.keys(brand).length ? { brand } : {}
|
|
1441
1442
|
};
|
|
1442
1443
|
await (options.mail ? options.mail(full) : sendSignInMail(full, base().env, settings.sender.from, remoteMailFor(options, base().env)));
|
|
@@ -1482,7 +1483,7 @@ function createAuth(options = {}) {
|
|
|
1482
1483
|
const at = async (origin) => {
|
|
1483
1484
|
const normal = new URL(origin).origin;
|
|
1484
1485
|
const { store, env, settings } = base();
|
|
1485
|
-
const now = await settings(), appName = appNameOf(now);
|
|
1486
|
+
const now = await settings(), appName = appNameOf(now, normal);
|
|
1486
1487
|
const id = `${normal}\n${appName}\n${now.confirmEmail}`;
|
|
1487
1488
|
let found = kept.get(id);
|
|
1488
1489
|
if (!found) {
|
|
@@ -1501,7 +1502,7 @@ function createAuth(options = {}) {
|
|
|
1501
1502
|
cacheS: 300,
|
|
1502
1503
|
confirmEmail: now.confirmEmail,
|
|
1503
1504
|
invitationUrl: options.invitationUrl ?? ((from, invitation) => `${from}/api/auth/ui/invitation/${invitation}`),
|
|
1504
|
-
send: async (mail) => sendOne(await settings(), mail)
|
|
1505
|
+
send: async (mail) => sendOne(await settings(), normal, mail)
|
|
1505
1506
|
});
|
|
1506
1507
|
if (kept.size >= KEPT_ORIGINS) kept.delete(kept.keys().next().value);
|
|
1507
1508
|
kept.set(id, found);
|
|
@@ -1792,7 +1793,7 @@ function createAuth(options = {}) {
|
|
|
1792
1793
|
const origin = originOf(request), { pathname } = new URL(request.url);
|
|
1793
1794
|
const { settings: read, env, allow } = base();
|
|
1794
1795
|
const settings = await read();
|
|
1795
|
-
const engine = await at(origin), appName = appNameOf(settings);
|
|
1796
|
+
const engine = await at(origin), appName = appNameOf(settings, origin);
|
|
1796
1797
|
if (pathname === "/.well-known/oauth-authorization-server") return engine.handler(new Request(`${origin}/.well-known/oauth-authorization-server${AUTH_PATH}`, request));
|
|
1797
1798
|
if (!pathname.startsWith(`/api/auth/`)) return engine.handler(request);
|
|
1798
1799
|
const path = pathname.slice(9);
|
|
@@ -105,7 +105,7 @@ declare const AUTH_ROUTES: {
|
|
|
105
105
|
};
|
|
106
106
|
};
|
|
107
107
|
interface AuthOptions {
|
|
108
|
-
/** The app's name, as its mail, pages and passkeys show it, unless its settings name it. `APP_NAME`, or
|
|
108
|
+
/** The app's name, as its mail, pages and passkeys show it, unless its settings name it. `APP_NAME`, or the address it serves at, when left out. */
|
|
109
109
|
readonly appName?: string;
|
|
110
110
|
/** The name the environment binds the database under, on Midsummer. `main` when left out. */
|
|
111
111
|
readonly database?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midsummer-ai/sdk",
|
|
3
|
-
"version": "0.1.0-staging.
|
|
3
|
+
"version": "0.1.0-staging.3728",
|
|
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.",
|
|
@@ -57,8 +57,24 @@ const AUTH_CSS = `
|
|
|
57
57
|
.msa-menu [role=menuitem]:hover,.msa-menu [role=menuitem]:focus-visible{background:var(--_bg)}
|
|
58
58
|
.msa-avatar{display:inline-grid;place-items:center;width:32px;height:32px;border-radius:999px;background:var(--_accent);color:var(--_accent-text);font-weight:600;overflow:hidden;border:0;padding:0;min-height:0}
|
|
59
59
|
.msa-avatar img{width:100%;height:100%;object-fit:cover}
|
|
60
|
+
.msa .msa-bones{display:grid;gap:12px}
|
|
61
|
+
.msa .msa-bone{display:block;height:1lh;border-radius:6px;background:var(--_border)}
|
|
62
|
+
/* As tall as an input or a button: its line, padding and border. */
|
|
63
|
+
.msa .msa-bone-control{height:calc(1lh + 20px);border-radius:var(--_radius)}
|
|
64
|
+
.msa .msa-bone-inline{margin:0 auto}
|
|
65
|
+
.msa-loading{animation:msa-appear .2s ease-out .15s both}
|
|
66
|
+
.msa-appear{animation:msa-appear .2s ease-out both}
|
|
67
|
+
@keyframes msa-appear{from{opacity:0}to{opacity:1}}
|
|
68
|
+
@media (prefers-reduced-motion:reduce){.msa-loading,.msa-appear{animation-duration:0s}}
|
|
60
69
|
@media (prefers-reduced-motion:no-preference){.msa button{transition:background-color .15s,border-color .15s}}
|
|
61
70
|
`;
|
|
71
|
+
/**
|
|
72
|
+
* An app's name when nothing sets one: the host it serves at (`shop.acme.dev`), so "Create your shop.acme.dev
|
|
73
|
+
* account" and "Your shop.acme.dev code" read right, where a stand-in like "your app" would not.
|
|
74
|
+
*/
|
|
75
|
+
function defaultAppName(origin) {
|
|
76
|
+
return URL.parse(origin)?.hostname || origin;
|
|
77
|
+
}
|
|
62
78
|
/** Every word the screens show, once, so the components and the hosted pages say the same. */
|
|
63
79
|
const WORDS = {
|
|
64
80
|
signIn: {
|
|
@@ -70,6 +86,7 @@ const WORDS = {
|
|
|
70
86
|
},
|
|
71
87
|
signUp: {
|
|
72
88
|
title: (app) => `Create your ${app} account`,
|
|
89
|
+
loading: "Loading sign-up",
|
|
73
90
|
submit: "Create account",
|
|
74
91
|
haveAccount: "Already have an account?",
|
|
75
92
|
signIn: "Sign in",
|
|
@@ -1164,4 +1181,4 @@ function qrSvg(value, label, pixels = 176) {
|
|
|
1164
1181
|
})[c])}" viewBox="0 0 ${size} ${size}" width="${pixels}" height="${pixels}" shape-rendering="crispEdges"><rect width="${size}" height="${size}" fill="#ffffff"/><path d="${d}" fill="#111111"/></svg>`;
|
|
1165
1182
|
}
|
|
1166
1183
|
//#endregion
|
|
1167
|
-
export { WORDS as a,
|
|
1184
|
+
export { WORDS as a, deviceOf as c, CAPTCHA_WIDGETS as i, setupKeyOf as l, qrSvg as n, ago as o, AUTH_CSS as r, defaultAppName as s, qrPath as t };
|