@engenty/wizards-runtime 0.11.11 → 0.11.12
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/apps/runtime/dist/app.js +2 -1
- package/apps/runtime/dist/auth/impersonation.js +33 -0
- package/apps/runtime/dist/auth/index.js +30 -5
- package/apps/runtime/dist/db/control-schema.js +3 -0
- package/apps/runtime/dist/db/migrations/control/0013_session_impersonated_by.sql +2 -0
- package/apps/runtime/dist/db/migrations/control/meta/0013_snapshot.json +621 -0
- package/apps/runtime/dist/db/migrations/control/meta/_journal.json +7 -0
- package/apps/runtime/dist/db/migrations/tenant/0026_run_impersonated_by.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0026_snapshot.json +3966 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +7 -0
- package/apps/runtime/dist/db/schema.js +2 -0
- package/apps/runtime/dist/engine/runner.js +2 -0
- package/apps/runtime/dist/manage.js +14 -0
- package/apps/runtime/dist/routes/runs.js +18 -7
- package/apps/runtime/dist/routes/studio.js +4 -0
- package/apps/runtime/dist/services/runs.js +1 -0
- package/apps/runtime/dist/sharing/index.js +1 -0
- package/apps/runtime/dist/texts.js +2 -0
- package/apps/web/dist/assets/{AboutDialog-BxPhyBQC.js → AboutDialog-DKGBCS3o.js} +1 -1
- package/apps/web/dist/assets/{ChangelogDialog-BLst4UYt.js → ChangelogDialog-Dc66LqBg.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-ydfkafOX.js → CodeEditor-BijLsoJX.js} +1 -1
- package/apps/web/dist/assets/{EditorPage-tBrPWV2R.js → EditorPage-CWtOGKs7.js} +3 -3
- package/apps/web/dist/assets/{FlowPreview-CPEK110v.js → FlowPreview-Wjt28MdG.js} +1 -1
- package/apps/web/dist/assets/{Harness-Cm1i8s2W.js → Harness-CdmCoeEZ.js} +1 -1
- package/apps/web/dist/assets/{Marketplace-_IfcAgYO.js → Marketplace-CpjRqTvn.js} +2 -2
- package/apps/web/dist/assets/{NewWizardChannels-45GyOXYL.js → NewWizardChannels-g3CJzwr5.js} +1 -1
- package/apps/web/dist/assets/{NewWizardPage-XFt4YtU3.js → NewWizardPage-DGHwvXLf.js} +1 -1
- package/apps/web/dist/assets/{OnboardingPage-Mko1anYV.js → OnboardingPage-CoCBYKvL.js} +1 -1
- package/apps/web/dist/assets/{PreviewPane-Dw9WG3lP.js → PreviewPane-BgIEsVjy.js} +5 -5
- package/apps/web/dist/assets/{ProjectPage-DRnVIWQs.js → ProjectPage-Cmhm9qh1.js} +1 -1
- package/apps/web/dist/assets/PublicRunner-C7i0QdlT.js +1 -0
- package/apps/web/dist/assets/{ReadOnly-CBNxkYUt.js → ReadOnly-C3SYrBNk.js} +1 -1
- package/apps/web/dist/assets/SettingsPage-Ctul7RLy.js +2 -0
- package/apps/web/dist/assets/SetupPage-CuuQVDH2.js +1 -0
- package/apps/web/dist/assets/{SharePage-gjQQ0CtP.js → SharePage-BDeYhYRB.js} +1 -1
- package/apps/web/dist/assets/changelog-BXyvVCpB.js +1 -0
- package/apps/web/dist/assets/{i18n-BX8GnEZT.js → i18n-BYeH2Dmi.js} +1 -1
- package/apps/web/dist/assets/index-C0yASttP.js +34 -0
- package/apps/web/dist/assets/{phone-Dd7IVbpJ.js → phone-JGS60FQU.js} +1 -1
- package/apps/web/dist/assets/{runners-XifDCQG3.js → runners-CwTP03YR.js} +1 -1
- package/apps/web/dist/assets/{session-BwtsznZF.js → session-CngLvd02.js} +1 -1
- package/apps/web/dist/assets/{settings-menu-CS-fXrFW.js → settings-menu-C0yo5q3t.js} +1 -1
- package/apps/web/dist/assets/{theme-DFKNqmEY.js → theme-DftQJmEW.js} +2 -2
- package/apps/web/dist/assets/{ui-D719V_Yj.js → ui-Bhp_a_44.js} +1 -1
- package/apps/web/dist/assets/{upload-CYTDCrYd.js → upload-DPLDQsRT.js} +1 -1
- package/apps/web/dist/assets/{useMutation-CVVmJvyz.js → useMutation-Cmn8b7tT.js} +1 -1
- package/apps/web/dist/assets/{volume-2-Do0dsjv2.js → volume-2-DGqbhyPO.js} +1 -1
- package/apps/web/dist/assets/{wrench-C5syJD9J.js → wrench-Dr19y-10.js} +1 -1
- package/apps/web/dist/index.html +7 -7
- package/apps/web/dist/mcp/flow.html +1 -1
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/apps/web/dist/assets/PublicRunner-C3NwpZKh.js +0 -1
- package/apps/web/dist/assets/SettingsPage-DBckGRCS.js +0 -2
- package/apps/web/dist/assets/SetupPage-BJxbmS68.js +0 -1
- package/apps/web/dist/assets/changelog-C67l3TZ1.js +0 -1
- package/apps/web/dist/assets/index-BtNnNYyZ.js +0 -34
package/apps/runtime/dist/app.js
CHANGED
|
@@ -9,6 +9,7 @@ import { Hono } from "hono";
|
|
|
9
9
|
import { bodyLimit } from "hono/body-limit";
|
|
10
10
|
import { HTTPException } from "hono/http-exception";
|
|
11
11
|
import { ZodError } from "zod";
|
|
12
|
+
import { asImpersonator } from "./auth/impersonation.js";
|
|
12
13
|
import { authRoutes, principalOf } from "./auth/index.js";
|
|
13
14
|
import { db, schema, withTenant } from "./db/client.js";
|
|
14
15
|
import { basePath, env } from "./env.js";
|
|
@@ -251,7 +252,7 @@ if (serves.studio) {
|
|
|
251
252
|
// A save: open studios hear of it now, not at the next tick (live/hub.ts).
|
|
252
253
|
const writes = c.req.method !== "GET";
|
|
253
254
|
if (managed) {
|
|
254
|
-
await withTenant(user.tenantId, () => asRole(user.role, next));
|
|
255
|
+
await withTenant(user.tenantId, () => asImpersonator(user.impersonatedBy?.id, requestLang(c), () => asRole(user.role, next)));
|
|
255
256
|
if (writes) {
|
|
256
257
|
nudge(user.tenantId);
|
|
257
258
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
const store = new AsyncLocalStorage();
|
|
3
|
+
/** Runs `fn` as the admin signed in as someone; without an admin, as it is. */
|
|
4
|
+
export function asImpersonator(adminId, lang, fn) {
|
|
5
|
+
return adminId ? store.run({ adminId, lang }, fn) : fn();
|
|
6
|
+
}
|
|
7
|
+
/** The admin signed in as the person this request is for; null for the person themselves. */
|
|
8
|
+
export function currentImpersonator() {
|
|
9
|
+
return store.getStore() ?? null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The Manage-App's calls that change the person's account or their organization: people,
|
|
13
|
+
* address, domains, API keys, name, connected apps and computers, the organization's name and
|
|
14
|
+
* profile, the install mail, phone numbers — and the invoices, which carry payment details.
|
|
15
|
+
*/
|
|
16
|
+
const OFF = [
|
|
17
|
+
[/^(POST|DELETE)$/, /^\/v1\/tenants\/[^/]+\/invitations(\/|$)/],
|
|
18
|
+
[/^(PATCH|DELETE)$/, /^\/v1\/tenants\/[^/]+\/members\//],
|
|
19
|
+
[/^PUT$/, /^\/v1\/tenants\/[^/]+\/address$/],
|
|
20
|
+
[/^(POST|DELETE)$/, /^\/v1\/tenants\/[^/]+\/domains(\/|$)/],
|
|
21
|
+
[/^(POST|DELETE)$/, /^\/v1\/tenants\/[^/]+\/keys(\/|$)/],
|
|
22
|
+
[/^GET$/, /^\/v1\/tenants\/[^/]+\/invoices\//],
|
|
23
|
+
[/^(PATCH|PUT)$/, /^\/v1\/tenants\/[^/]+(\/profile)?$/],
|
|
24
|
+
[/^(POST|DELETE)$/, /^\/v1\/tenants\/[^/]+\/channels\/requests$/],
|
|
25
|
+
[/^PATCH$/, /^\/v1\/users\/[^/]+$/],
|
|
26
|
+
[/^DELETE$/, /^\/v1\/users\/[^/]+\/(connections|computers)\//],
|
|
27
|
+
[/^POST$/, /^\/v1\/install-mail$/],
|
|
28
|
+
];
|
|
29
|
+
/** Whether a call to the Manage-App stays off while an admin is signed in as the person. */
|
|
30
|
+
export function refusedWhileImpersonating(method, path) {
|
|
31
|
+
const bare = path.split("?")[0] ?? path;
|
|
32
|
+
return OFF.some(([m, p]) => m.test(method) && p.test(bare));
|
|
33
|
+
}
|
|
@@ -102,13 +102,14 @@ function safeReturn(path) {
|
|
|
102
102
|
: path === start || path.startsWith(`${start}/`) || path.startsWith(`${start}?`));
|
|
103
103
|
return into ? path : home;
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
/** The session's cookie; one that ends at `until` (an admin's sign-in as someone) ends then. */
|
|
106
|
+
function setSessionCookie(c, id, until) {
|
|
106
107
|
setCookie(c, SESSION_COOKIE, id, {
|
|
107
108
|
httpOnly: true,
|
|
108
109
|
sameSite: "Lax",
|
|
109
110
|
secure,
|
|
110
111
|
path: cookiePath,
|
|
111
|
-
maxAge: SESSION_DAYS * 24 * 3600,
|
|
112
|
+
maxAge: until ? Math.max(0, Math.floor((until - Date.now()) / 1000)) : SESSION_DAYS * 24 * 3600,
|
|
112
113
|
});
|
|
113
114
|
}
|
|
114
115
|
async function claimsOf(tokens) {
|
|
@@ -127,6 +128,10 @@ async function renew(row) {
|
|
|
127
128
|
try {
|
|
128
129
|
const tokens = await tokenRequest({ grant_type: "refresh_token", refresh_token: refresh, resource: env.appUrl }, client());
|
|
129
130
|
const claims = await claimsOf(tokens);
|
|
131
|
+
// An admin's sign-in as this person renews as that or not at all.
|
|
132
|
+
if ((claims.impersonatedBy?.id ?? null) !== row.impersonatedBy) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
130
135
|
const next = {
|
|
131
136
|
...row,
|
|
132
137
|
tenantId: claims.tenantId,
|
|
@@ -169,6 +174,13 @@ async function sessionPrincipal(id) {
|
|
|
169
174
|
name: row.name,
|
|
170
175
|
email: row.email,
|
|
171
176
|
image: row.image,
|
|
177
|
+
impersonatedBy: row.impersonatedBy
|
|
178
|
+
? {
|
|
179
|
+
id: row.impersonatedBy,
|
|
180
|
+
email: row.impersonatorEmail ?? "",
|
|
181
|
+
until: row.expiresAt.getTime(),
|
|
182
|
+
}
|
|
183
|
+
: null,
|
|
172
184
|
};
|
|
173
185
|
}
|
|
174
186
|
/** A new name for the person in every session of theirs here: the menu shows it at the next read. */
|
|
@@ -356,7 +368,13 @@ export const authRoutes = new Hono()
|
|
|
356
368
|
resource: env.appUrl,
|
|
357
369
|
}, client());
|
|
358
370
|
const claims = await claimsOf(tokens);
|
|
371
|
+
const admin = claims.impersonatedBy;
|
|
372
|
+
// An admin's sign-in as someone stays in this browser: no desktop window takes it.
|
|
373
|
+
if (admin && state.desktop) {
|
|
374
|
+
return c.redirect(`${home}?signin=failed`);
|
|
375
|
+
}
|
|
359
376
|
const id = randomBytes(32).toString("base64url");
|
|
377
|
+
const expiresAt = admin ? admin.until : Date.now() + SESSION_DAYS * 24 * 3600_000;
|
|
360
378
|
await controlDb.insert(control.session).values({
|
|
361
379
|
id,
|
|
362
380
|
userId: claims.userId,
|
|
@@ -366,7 +384,9 @@ export const authRoutes = new Hono()
|
|
|
366
384
|
email: claims.email,
|
|
367
385
|
refreshToken: tokens.refresh_token ? seal(tokens.refresh_token) : null,
|
|
368
386
|
claimsExpireAt: new Date(claims.expiresAt),
|
|
369
|
-
expiresAt: new Date(
|
|
387
|
+
expiresAt: new Date(expiresAt),
|
|
388
|
+
impersonatedBy: admin?.id ?? null,
|
|
389
|
+
impersonatorEmail: admin?.email ?? null,
|
|
370
390
|
});
|
|
371
391
|
if (state.desktop) {
|
|
372
392
|
// The session belongs to the app's window, not to this browser.
|
|
@@ -379,7 +399,7 @@ export const authRoutes = new Hono()
|
|
|
379
399
|
return c.html(`${closePage(c, say(c, "desktopSignedIn"))}
|
|
380
400
|
<script>location.href = ${JSON.stringify(link)};</script>`);
|
|
381
401
|
}
|
|
382
|
-
setSessionCookie(c, id);
|
|
402
|
+
setSessionCookie(c, id, admin ? admin.until : undefined);
|
|
383
403
|
return c.redirect(state.returnTo);
|
|
384
404
|
}
|
|
385
405
|
catch (err) {
|
|
@@ -389,6 +409,9 @@ export const authRoutes = new Hono()
|
|
|
389
409
|
})
|
|
390
410
|
.post("/auth/sign-out", async (c) => {
|
|
391
411
|
const id = getCookie(c, SESSION_COOKIE);
|
|
412
|
+
const row = id
|
|
413
|
+
? await controlDb.query.session.findFirst({ where: eq(control.session.id, id) })
|
|
414
|
+
: undefined;
|
|
392
415
|
if (id) {
|
|
393
416
|
await controlDb.delete(control.session).where(eq(control.session.id, id));
|
|
394
417
|
sessions.delete(id);
|
|
@@ -400,6 +423,8 @@ export const authRoutes = new Hono()
|
|
|
400
423
|
}
|
|
401
424
|
// The person signs out of the account too (the Manage-App's `/api/sign-out`, a form the page
|
|
402
425
|
// sends there): still signed in there, the sign-in page would sign them in again at once.
|
|
426
|
+
// An admin signed in as someone goes back to their own account there instead.
|
|
403
427
|
const d = await discovery().catch(() => null);
|
|
404
|
-
|
|
428
|
+
const there = row?.impersonatedBy ? "/api/impersonate/stop" : "/api/sign-out";
|
|
429
|
+
return c.json({ ok: true, account: d ? new URL(there, d.issuer).toString() : null });
|
|
405
430
|
});
|
|
@@ -76,6 +76,9 @@ export const session = sqliteTable("session", {
|
|
|
76
76
|
/** When the access token's claims (tenant, role) must be renewed. */
|
|
77
77
|
claimsExpireAt: integer("claims_expire_at", { mode: "timestamp_ms" }).notNull(),
|
|
78
78
|
expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
|
|
79
|
+
/** The platform admin signed in as this person (the token's `act`); null for their own sign-in. */
|
|
80
|
+
impersonatedBy: text("impersonated_by"),
|
|
81
|
+
impersonatorEmail: text("impersonator_email"),
|
|
79
82
|
createdAt: createdAt(),
|
|
80
83
|
}, (t) => [index("session_expires").on(t.expiresAt)]);
|
|
81
84
|
/** Settings of a runtime that runs alone: model bindings, the linked account. Never secrets. */
|