@sixb/server 0.1.18 → 0.1.20

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 (93) hide show
  1. package/README.md +15 -24
  2. package/dist/actions/serialize.d.ts +7 -0
  3. package/dist/actions/serialize.d.ts.map +1 -0
  4. package/dist/auth/browser-origin.d.ts +4 -26
  5. package/dist/auth/browser-origin.d.ts.map +1 -1
  6. package/dist/auth/experience.d.ts +0 -3
  7. package/dist/auth/experience.d.ts.map +1 -1
  8. package/dist/auth/guard.d.ts +1 -1
  9. package/dist/auth/guard.d.ts.map +1 -1
  10. package/dist/auth/public-routes.d.ts +0 -5
  11. package/dist/auth/public-routes.d.ts.map +1 -1
  12. package/dist/auth/responses.d.ts +0 -2
  13. package/dist/auth/responses.d.ts.map +1 -1
  14. package/dist/auth/session-cookies.d.ts.map +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +681 -935
  18. package/dist/index.js.map +24 -24
  19. package/dist/routes/action-runs.d.ts +11 -15
  20. package/dist/routes/action-runs.d.ts.map +1 -1
  21. package/dist/routes/actions.d.ts +44 -13
  22. package/dist/routes/actions.d.ts.map +1 -1
  23. package/dist/routes/agent-api-gateway.d.ts.map +1 -1
  24. package/dist/routes/agents.d.ts +20 -22
  25. package/dist/routes/agents.d.ts.map +1 -1
  26. package/dist/routes/auth.d.ts +8 -17
  27. package/dist/routes/auth.d.ts.map +1 -1
  28. package/dist/routes/connector-connection-runs.d.ts +21 -21
  29. package/dist/routes/connector-connections.d.ts +8 -8
  30. package/dist/routes/connectors.d.ts +2 -2
  31. package/dist/routes/datasets.d.ts +5 -5
  32. package/dist/routes/events.d.ts +4 -4
  33. package/dist/routes/files.d.ts +15 -12
  34. package/dist/routes/files.d.ts.map +1 -1
  35. package/dist/routes/objects.d.ts +0 -2
  36. package/dist/routes/objects.d.ts.map +1 -1
  37. package/dist/routes/ontology.d.ts +6 -6
  38. package/dist/routes/pipelines.d.ts +16 -16
  39. package/dist/routes/projections.d.ts +49 -49
  40. package/dist/routes/syncs.d.ts +10 -10
  41. package/dist/routes/webhook-runs.d.ts +2 -2
  42. package/dist/routes/workflows.d.ts +48 -52
  43. package/dist/routes/workflows.d.ts.map +1 -1
  44. package/dist/routes/ws/events.d.ts +6 -9
  45. package/dist/routes/ws/events.d.ts.map +1 -1
  46. package/dist/schemas/actions.d.ts +100 -84
  47. package/dist/schemas/actions.d.ts.map +1 -1
  48. package/dist/schemas/agents.d.ts +20 -20
  49. package/dist/schemas/ai-limits.d.ts +10 -10
  50. package/dist/schemas/auth.d.ts +28 -63
  51. package/dist/schemas/auth.d.ts.map +1 -1
  52. package/dist/schemas/connectors.d.ts +8 -8
  53. package/dist/schemas/datasets.d.ts +40 -40
  54. package/dist/schemas/events.d.ts +24 -24
  55. package/dist/schemas/events.d.ts.map +1 -1
  56. package/dist/schemas/files.d.ts +4 -7
  57. package/dist/schemas/files.d.ts.map +1 -1
  58. package/dist/schemas/ontology.d.ts +40 -40
  59. package/dist/schemas/pipelines.d.ts +92 -92
  60. package/dist/schemas/projections.d.ts +290 -290
  61. package/dist/schemas/syncs.d.ts +34 -34
  62. package/dist/schemas/webhook-runs.d.ts +8 -8
  63. package/dist/schemas/workflows.d.ts +160 -160
  64. package/dist/server.d.ts +2 -2
  65. package/dist/server.d.ts.map +1 -1
  66. package/dist/utils/http.d.ts.map +1 -1
  67. package/dist/utils/request-body.d.ts +20 -6
  68. package/dist/utils/request-body.d.ts.map +1 -1
  69. package/package.json +7 -7
  70. package/src/actions/serialize.ts +55 -0
  71. package/src/auth/browser-origin.ts +30 -240
  72. package/src/auth/experience.ts +1 -4
  73. package/src/auth/guard.ts +4 -32
  74. package/src/auth/public-routes.ts +1 -10
  75. package/src/auth/responses.ts +0 -5
  76. package/src/auth/session-cookies.ts +1 -3
  77. package/src/auth/shared-access.ts +1 -1
  78. package/src/index.ts +1 -1
  79. package/src/routes/action-runs.ts +1 -54
  80. package/src/routes/actions.ts +26 -8
  81. package/src/routes/agent-api-gateway.ts +18 -42
  82. package/src/routes/auth.ts +32 -111
  83. package/src/routes/files.ts +15 -63
  84. package/src/routes/ws/events.ts +2 -12
  85. package/src/schemas/actions.ts +21 -18
  86. package/src/schemas/auth.ts +2 -15
  87. package/src/schemas/files.ts +0 -6
  88. package/src/server.ts +23 -18
  89. package/src/utils/http.ts +2 -0
  90. package/src/utils/request-body.ts +55 -6
  91. package/dist/auth/application-access.d.ts +0 -4
  92. package/dist/auth/application-access.d.ts.map +0 -1
  93. package/src/auth/application-access.ts +0 -15
@@ -1,10 +1,5 @@
1
1
  import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto"
2
- import {
3
- type AuthSessionAudience,
4
- DEFAULT_AUTH_SESSION_AUDIENCE,
5
- type GroupDefinition,
6
- type SixbHostView,
7
- } from "@sixb/core"
2
+ import type { GroupDefinition, SixbHostView } from "@sixb/core"
8
3
  import {
9
4
  type AuthenticatedAuthSession,
10
5
  type AuthenticatedUserRequestSession,
@@ -38,15 +33,12 @@ import {
38
33
  } from "@sixb/core/storage"
39
34
  import { type Elysia, t } from "elysia"
40
35
  import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
41
- import { sessionCanAccessApplication } from "../auth/application-access"
42
36
  import {
43
- type AuthInvitationDestinationOptions,
44
37
  type AuthInvitationRedirectContext,
45
38
  type AuthInvitationRedirectInput,
46
39
  type AuthRedirectContext,
47
40
  BrowserOriginError,
48
41
  type ResolveAuthRedirectContext,
49
- type ResolveRequestAuthContext,
50
42
  } from "../auth/browser-origin"
51
43
  import { CSRF_TOKEN_RESPONSE_HEADER_NAME } from "../auth/csrf"
52
44
  import {
@@ -117,10 +109,6 @@ type ResolvedCookieOptions = Parameters<typeof createCsrfCookieHeader>[0]["optio
117
109
  type AuthenticatedAuthSessionResponse = {
118
110
  readonly authenticated: true
119
111
  readonly csrfToken: string
120
- readonly applicationAccess: {
121
- readonly allowed: boolean
122
- readonly audience: AuthSessionAudience
123
- }
124
112
  readonly user: {
125
113
  readonly id: string
126
114
  readonly email: string
@@ -135,9 +123,7 @@ type AuthenticatedAuthSessionResponse = {
135
123
  }
136
124
 
137
125
  export interface AuthRoutesOptions {
138
- readonly resolveAuthContext: ResolveRequestAuthContext
139
126
  readonly resolveAuthRedirectContext: ResolveAuthRedirectContext
140
- readonly getInvitationDestinationOptions: (request: Request) => AuthInvitationDestinationOptions
141
127
  readonly resolveAuthRequestOrigin: (request: Request) => string
142
128
  readonly resolveInvitationRedirectContext: (
143
129
  request: Request,
@@ -341,10 +327,9 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
341
327
  ) {
342
328
  return authPageResponse("<h1>This authorization has expired</h1>", 400)
343
329
  }
344
- const authOptions = resolveAuthOptions(options, request)
345
- const session = await host.auth.getSession(request, authOptions)
330
+ const session = await host.auth.getSession(request)
346
331
  if (!session.authenticated) return authPageResponse("<h1>Authentication required</h1>", 401)
347
- const cookieOptions = host.auth.getCookieOptions(authOptions)
332
+ const cookieOptions = host.auth.getCookieOptions()
348
333
  const csrf = resolveSessionCsrfToken({
349
334
  request,
350
335
  cookieOptions,
@@ -377,11 +362,10 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
377
362
  "/auth/device",
378
363
  async ({ body, request }) => {
379
364
  const parsed = DeviceAuthorizationDecisionBodySchema.parse(body)
380
- const authOptions = resolveAuthOptions(options, request)
381
- const session = await host.auth.getSession(request, authOptions)
382
- // Every signed-in user may approve their own CLI login, whichever web app they may open.
365
+ const session = await host.auth.getSession(request)
366
+ // Every signed-in user may approve their own CLI login.
383
367
  if (!session.authenticated) return authPageResponse("<h1>Authentication required</h1>", 401)
384
- const csrfCookieName = host.auth.getCookieOptions(authOptions).csrfCookieName
368
+ const csrfCookieName = host.auth.getCookieOptions().csrfCookieName
385
369
  if (!verifyCsrfToken(request, { cookieName: csrfCookieName, token: parsed.csrfToken })) {
386
370
  return authPageResponse("<h1>Invalid authorization request</h1>", 403)
387
371
  }
@@ -434,30 +418,23 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
434
418
  .get(
435
419
  "/api/auth/session",
436
420
  async ({ request }) => {
437
- const authOptions = resolveAuthOptions(options, request)
438
- const caller = await host.auth.getSession(request, {
439
- ...authOptions,
440
- credentialSource: "any",
441
- })
421
+ const caller = await host.auth.getSession(request, { credentialSource: "any" })
442
422
  // Access tokens are not sessions; a native client's session has no cookies to renew.
443
423
  if (!caller.authenticated || caller.credentialSource !== "session") {
444
424
  return signedOutSessionResponse(host)
445
425
  }
446
- // A native client belongs to no web app; tell it whether its user may open Atlas.
447
426
  if (caller.session.bearer) {
448
- return jsonResponse(authSessionBody(host, caller, DEFAULT_AUTH_SESSION_AUDIENCE), 200)
427
+ return jsonResponse(authSessionBody(caller), 200)
449
428
  }
450
429
 
451
- const session =
452
- hasForegroundSessionActivity(request) &&
453
- sessionCanAccessApplication(host, caller, authOptions.audience)
454
- ? await host.auth.getSession(request, { ...authOptions, sessionActivity: "foreground" })
455
- : caller
430
+ const session = hasForegroundSessionActivity(request)
431
+ ? await host.auth.getSession(request, { sessionActivity: "foreground" })
432
+ : caller
456
433
  if (!session.authenticated) {
457
434
  return signedOutSessionResponse(host)
458
435
  }
459
436
 
460
- const cookieOptions = host.auth.getCookieOptions(authOptions)
437
+ const cookieOptions = host.auth.getCookieOptions()
461
438
  const csrf = resolveSessionCsrfToken({
462
439
  request,
463
440
  cookieOptions,
@@ -473,7 +450,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
473
450
  })
474
451
  : null
475
452
  return authSessionJsonResponse(
476
- { ...authSessionBody(host, session, authOptions.audience), csrfToken: csrf.token },
453
+ { ...authSessionBody(session), csrfToken: csrf.token },
477
454
  renewal?.headers ?? (csrf.setCookie ? [csrf.setCookie] : [])
478
455
  )
479
456
  },
@@ -490,15 +467,11 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
490
467
  .post(
491
468
  "/api/auth/sign-out",
492
469
  async ({ request }) => {
493
- const authOptions = resolveAuthOptions(options, request)
494
- const result = await host.auth.getSession(request, {
495
- ...authOptions,
496
- credentialSource: "any",
497
- })
470
+ const result = await host.auth.getSession(request, { credentialSource: "any" })
498
471
  // Access tokens are not sessions; revoke those through their own route.
499
472
  const session =
500
473
  result.authenticated && result.credentialSource === "session" ? result : null
501
- const cookieOptions = host.auth.getCookieOptions(authOptions)
474
+ const cookieOptions = host.auth.getCookieOptions()
502
475
  if (
503
476
  session &&
504
477
  !session.session.bearer &&
@@ -541,7 +514,6 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
541
514
  {
542
515
  sessions: sessions.map((entry) => ({
543
516
  id: entry.id,
544
- audience: entry.bearer ? undefined : entry.audience,
545
517
  current: entry.id === session.session.id,
546
518
  createdAt: toIsoString(entry.createdAt),
547
519
  expiresAt: toIsoString(entry.expiresAt),
@@ -582,7 +554,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
582
554
  if (sessionId !== session.session.id) {
583
555
  return jsonResponse({ success: true }, 200)
584
556
  }
585
- const cookieOptions = host.auth.getCookieOptions(resolveAuthOptions(options, request))
557
+ const cookieOptions = host.auth.getCookieOptions()
586
558
  return signedOutResponse(request, cookieOptions, { success: true })
587
559
  },
588
560
  {
@@ -609,10 +581,10 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
609
581
  return session
610
582
  }
611
583
 
612
- // Other audiences' cookies stay in their browsers, but their sessions are revoked, so the
613
- // next request there re-authenticates.
584
+ // Other browsers keep their cookies, but their sessions are revoked, so the next request
585
+ // there re-authenticates.
614
586
  const revokedCount = await host.auth.revokeAllSessions(session)
615
- const cookieOptions = host.auth.getCookieOptions(resolveAuthOptions(options, request))
587
+ const cookieOptions = host.auth.getCookieOptions()
616
588
  return signedOutResponse(request, cookieOptions, { success: true, revokedCount })
617
589
  },
618
590
  {
@@ -716,7 +688,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
716
688
  })
717
689
 
718
690
  // The raw token is only returned on creation. Storage keeps a hash, so
719
- // Atlas can never reveal it again after this response leaves the page.
691
+ // nothing can reveal it again after this response leaves the page.
720
692
  return jsonResponse(
721
693
  {
722
694
  accessToken: serializeAccessToken(result.accessToken, {
@@ -1030,7 +1002,6 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
1030
1002
  const caller = requireUserCaller(context)
1031
1003
  const parsed = CreateAuthInvitationBodySchema.parse(body)
1032
1004
  const deliveryContext = resolveInvitationDeliveryContext(options, request, {
1033
- destinationId: parsed.destinationId,
1034
1005
  returnTo: parsed.returnTo,
1035
1006
  })
1036
1007
  if (deliveryContext instanceof Response) {
@@ -1083,13 +1054,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
1083
1054
  async ({ request, ...context }) => {
1084
1055
  try {
1085
1056
  const caller = requireUserCaller(context)
1086
- return jsonResponse(
1087
- {
1088
- ...(await host.auth.getInvitationOptions(caller)),
1089
- ...options.getInvitationDestinationOptions(request),
1090
- },
1091
- 200
1092
- )
1057
+ return jsonResponse(await host.auth.getInvitationOptions(caller), 200)
1093
1058
  } catch (error) {
1094
1059
  return authRouteErrorResponse(error)
1095
1060
  }
@@ -1351,7 +1316,6 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
1351
1316
  async ({ body, request }) => {
1352
1317
  const strategy = host.auth.getStrategy()
1353
1318
  const authRedirect = resolveAuthRedirectContext(options, request, {
1354
- audience: body.audience,
1355
1319
  returnTo: body.returnTo,
1356
1320
  })
1357
1321
  if (authRedirect instanceof Response) {
@@ -1366,7 +1330,6 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
1366
1330
  projectId: host.id,
1367
1331
  authStorage,
1368
1332
  email: body.email ?? "",
1369
- audience: authRedirect.audience,
1370
1333
  returnTo: authRedirect.returnTo,
1371
1334
  requestOrigin: authRedirect.requestOrigin,
1372
1335
  requesterHash: pending.hash,
@@ -1399,7 +1362,6 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
1399
1362
  const result = await strategy.startOidcSignIn({
1400
1363
  projectId: host.id,
1401
1364
  authStorage,
1402
- audience: authRedirect.audience,
1403
1365
  returnTo: authRedirect.returnTo,
1404
1366
  requestOrigin: authRedirect.requestOrigin,
1405
1367
  })
@@ -1410,7 +1372,6 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
1410
1372
  },
1411
1373
  {
1412
1374
  body: t.Object({
1413
- audience: t.Optional(t.String()),
1414
1375
  email: t.Optional(t.String()),
1415
1376
  returnTo: t.Optional(t.String()),
1416
1377
  }),
@@ -1424,7 +1385,6 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
1424
1385
  const strategy = host.auth.getStrategy()
1425
1386
  const url = new URL(request.url)
1426
1387
  const authRedirect = resolveAuthRedirectContext(options, request, {
1427
- audience: url.searchParams.get("audience"),
1428
1388
  returnTo: url.searchParams.get("returnTo"),
1429
1389
  })
1430
1390
  if (authRedirect instanceof Response) {
@@ -1439,7 +1399,6 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
1439
1399
  const result = await strategy.startOidcSignIn({
1440
1400
  projectId: host.id,
1441
1401
  authStorage: requireAuthStorage(host),
1442
- audience: authRedirect.audience,
1443
1402
  returnTo: authRedirect.returnTo,
1444
1403
  requestOrigin: authRedirect.requestOrigin,
1445
1404
  })
@@ -1459,11 +1418,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
1459
1418
  const url = new URL(request.url)
1460
1419
  const magicLinkId = url.searchParams.get("magicLinkId")?.trim()
1461
1420
  const token = url.searchParams.get("token")?.trim()
1462
- const authRedirectHint = resolveAuthExperienceRedirectHint(
1463
- options,
1464
- request,
1465
- url.searchParams.get("audience")
1466
- )
1421
+ const authRedirectHint = resolveAuthExperienceRedirectHint(options, request)
1467
1422
 
1468
1423
  if (!magicLinkId || !token) {
1469
1424
  return await invalidMagicLinkResponse(options, authRedirectHint)
@@ -1539,7 +1494,6 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
1539
1494
  "[SixbServer] OIDC callback reached a browser that did not start this sign-in."
1540
1495
  )
1541
1496
  }
1542
- const authOptions = resolveAuthOptions(options, request)
1543
1497
  const result = await strategy.completeOidcSignIn({
1544
1498
  projectId: host.id,
1545
1499
  authStorage: requireAuthStorage(host),
@@ -1547,7 +1501,6 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
1547
1501
  requestOrigin: options.resolveAuthRequestOrigin(request),
1548
1502
  session: {
1549
1503
  id: sessionCredential.sessionId,
1550
- audience: authOptions.audience,
1551
1504
  tokenHash: sessionCredential.tokenHash,
1552
1505
  createdAt: now,
1553
1506
  ...host.auth.createSessionDeadlines(now),
@@ -1560,7 +1513,6 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
1560
1513
  request,
1561
1514
  apiOrigin: options.resolveAuthRequestOrigin(request),
1562
1515
  sessionCredential,
1563
- audience: result.session.audience,
1564
1516
  expiresAt: result.session.expiresAt,
1565
1517
  returnTo: result.returnTo,
1566
1518
  })
@@ -1602,7 +1554,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
1602
1554
 
1603
1555
  const magicLinkId = body.magicLinkId?.trim()
1604
1556
  const token = body.token?.trim()
1605
- const authRedirectHint = resolveAuthExperienceRedirectHint(options, request, body.audience)
1557
+ const authRedirectHint = resolveAuthExperienceRedirectHint(options, request)
1606
1558
  if (!magicLinkId || !token) {
1607
1559
  return await invalidMagicLinkResponse(options, authRedirectHint)
1608
1560
  }
@@ -1621,7 +1573,6 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
1621
1573
  body: t.Object({
1622
1574
  magicLinkId: t.Optional(t.String()),
1623
1575
  token: t.Optional(t.String()),
1624
- audience: t.Optional(t.String()),
1625
1576
  }),
1626
1577
  parse: "urlencoded",
1627
1578
  detail: { hide: true },
@@ -1727,7 +1678,6 @@ async function completeMagicLinkCallback(input: {
1727
1678
  readonly clearPendingCookie?: boolean
1728
1679
  readonly authRedirectHint?: AuthRedirectContext
1729
1680
  }): Promise<Response> {
1730
- const authOptions = resolveAuthOptions(input.options, input.request)
1731
1681
  const now = new Date()
1732
1682
  const sessionCredential = createSessionCredential()
1733
1683
  const device = resolveSessionDevice(input.request)
@@ -1740,7 +1690,6 @@ async function completeMagicLinkCallback(input: {
1740
1690
  token: input.token,
1741
1691
  session: {
1742
1692
  id: sessionCredential.sessionId,
1743
- audience: authOptions.audience,
1744
1693
  tokenHash: sessionCredential.tokenHash,
1745
1694
  createdAt: now,
1746
1695
  ...input.host.auth.createSessionDeadlines(now),
@@ -1753,7 +1702,6 @@ async function completeMagicLinkCallback(input: {
1753
1702
  request: input.request,
1754
1703
  apiOrigin: input.options.resolveAuthRequestOrigin(input.request),
1755
1704
  sessionCredential,
1756
- audience: result.session.audience,
1757
1705
  expiresAt: result.session.expiresAt,
1758
1706
  returnTo: result.returnTo,
1759
1707
  })
@@ -1838,11 +1786,10 @@ function sessionCallbackCompletionResponse(input: {
1838
1786
  readonly request: Request
1839
1787
  readonly apiOrigin: string
1840
1788
  readonly sessionCredential: ReturnType<typeof createSessionCredential>
1841
- readonly audience: AuthSessionAudience
1842
1789
  readonly expiresAt: Date
1843
1790
  readonly returnTo: string
1844
1791
  }): Response {
1845
- const cookieOptions = input.host.auth.getCookieOptions({ audience: input.audience })
1792
+ const cookieOptions = input.host.auth.getCookieOptions()
1846
1793
  const headers = new Headers({
1847
1794
  "cache-control": "no-store",
1848
1795
  })
@@ -1928,13 +1875,6 @@ function authCallbackCompletionDocumentResponse(returnTo: string, headers: Heade
1928
1875
  )
1929
1876
  }
1930
1877
 
1931
- function resolveAuthOptions(
1932
- options: AuthRoutesOptions,
1933
- request: Request
1934
- ): ReturnType<ResolveRequestAuthContext> {
1935
- return options.resolveAuthContext(request)
1936
- }
1937
-
1938
1878
  function resolveAuthRedirectContext(
1939
1879
  options: AuthRoutesOptions,
1940
1880
  request: Request,
@@ -1960,7 +1900,7 @@ function resolveInvitationDeliveryContext(
1960
1900
  return options.resolveInvitationRedirectContext(request, input)
1961
1901
  } catch (error) {
1962
1902
  if (error instanceof BrowserOriginError) {
1963
- return jsonResponse({ error: "Invitation destination is not allowed" }, 400)
1903
+ return jsonResponse({ error: "Invitation return target is not allowed" }, 400)
1964
1904
  }
1965
1905
 
1966
1906
  throw error
@@ -1990,13 +1930,10 @@ function resolveSessionCsrfToken(input: {
1990
1930
  }
1991
1931
 
1992
1932
  function authSessionBody(
1993
- host: SixbHostView,
1994
- session: AuthenticatedAuthSession,
1995
- audience: AuthSessionAudience
1933
+ session: AuthenticatedAuthSession
1996
1934
  ): Omit<AuthenticatedAuthSessionResponse, "csrfToken"> {
1997
1935
  return {
1998
1936
  authenticated: true,
1999
- applicationAccess: { allowed: sessionCanAccessApplication(host, session, audience), audience },
2000
1937
  user: {
2001
1938
  id: session.user.id,
2002
1939
  email: session.user.email,
@@ -2045,7 +1982,7 @@ function strategyNotImplementedResponse(message: string): Response {
2045
1982
  })
2046
1983
  }
2047
1984
 
2048
- // Mirrors the Atlas design tokens (packages/ui/src/styles/globals.css) so the
1985
+ // Mirrors the app's design tokens (packages/ui/src/styles/globals.css) so the
2049
1986
  // server-rendered auth pages feel familiar. Self-contained: no external CSS, and dark mode
2050
1987
  // follows the system preference since these standalone pages have no client theme runtime.
2051
1988
  const AUTH_PAGE_STYLE = `<style>
@@ -2204,13 +2141,12 @@ async function signInFormResponse(
2204
2141
  ): Promise<Response> {
2205
2142
  return (
2206
2143
  (await customAuthExperienceResponse(options.authExperience, {
2207
- audience: context.audience,
2208
2144
  state: { kind: "signIn" },
2209
2145
  signInUrl: authExperienceSignInUrl(context),
2210
2146
  submission: {
2211
2147
  kind: "requestMagicLink",
2212
2148
  action: "/auth/sign-in",
2213
- fields: { audience: context.audience, returnTo: context.returnTo },
2149
+ fields: { returnTo: context.returnTo },
2214
2150
  },
2215
2151
  // Native POST forms inherit the document's referrer policy when
2216
2152
  // constructing their Origin header. `no-referrer` produces
@@ -2222,7 +2158,6 @@ async function signInFormResponse(
2222
2158
  "<h1>Sign in</h1>",
2223
2159
  "<p>We'll email you a sign-in link.</p>",
2224
2160
  '<form method="post" action="/auth/sign-in">',
2225
- `<input type="hidden" name="audience" value="${escapeHtml(context.audience)}">`,
2226
2161
  `<input type="hidden" name="returnTo" value="${escapeHtml(context.returnTo)}">`,
2227
2162
  '<input name="email" type="email" autocomplete="email" placeholder="you@example.com" aria-label="Email address" required autofocus>',
2228
2163
  '<button type="submit">Send sign-in link</button>',
@@ -2238,7 +2173,6 @@ async function magicLinkRequestedResponse(
2238
2173
  ): Promise<Response> {
2239
2174
  return (
2240
2175
  (await customAuthExperienceResponse(options.authExperience, {
2241
- audience: context.audience,
2242
2176
  state: { kind: "checkEmail" },
2243
2177
  signInUrl: authExperienceSignInUrl(context),
2244
2178
  })) ??
@@ -2256,7 +2190,6 @@ async function invalidMagicLinkResponse(
2256
2190
  ): Promise<Response> {
2257
2191
  if (context) {
2258
2192
  const custom = await customAuthExperienceResponse(options.authExperience, {
2259
- audience: context.audience,
2260
2193
  state: { kind: "invalidLink" },
2261
2194
  signInUrl: authExperienceSignInUrl(context),
2262
2195
  status: 400,
@@ -2273,7 +2206,6 @@ async function authExperienceErrorResponse(
2273
2206
  ): Promise<Response> {
2274
2207
  if (context) {
2275
2208
  const custom = await customAuthExperienceResponse(options.authExperience, {
2276
- audience: context.audience,
2277
2209
  state: { kind: "error" },
2278
2210
  signInUrl: authExperienceSignInUrl(context),
2279
2211
  status: 500,
@@ -2285,20 +2217,16 @@ async function authExperienceErrorResponse(
2285
2217
  }
2286
2218
 
2287
2219
  function authExperienceSignInUrl(context: AuthRedirectContext): string {
2288
- const params = new URLSearchParams({ audience: context.audience, returnTo: context.returnTo })
2220
+ const params = new URLSearchParams({ returnTo: context.returnTo })
2289
2221
  return `/auth/sign-in?${params.toString()}`
2290
2222
  }
2291
2223
 
2224
+ // A magic link's own page carries no return target, so the app's custom pages get the app's home.
2292
2225
  function resolveAuthExperienceRedirectHint(
2293
2226
  options: AuthRoutesOptions,
2294
- request: Request,
2295
- audience: string | null | undefined
2227
+ request: Request
2296
2228
  ): AuthRedirectContext | undefined {
2297
- if (audience !== "app" && audience !== "atlas") {
2298
- return undefined
2299
- }
2300
-
2301
- const context = resolveInvitationDeliveryContext(options, request, { destinationId: audience })
2229
+ const context = resolveInvitationDeliveryContext(options, request, {})
2302
2230
  return context instanceof Response ? undefined : context
2303
2231
  }
2304
2232
 
@@ -2322,7 +2250,6 @@ async function magicLinkConfirmResponse(
2322
2250
  ): Promise<Response> {
2323
2251
  if (input.authRedirect) {
2324
2252
  const custom = await customAuthExperienceResponse(options.authExperience, {
2325
- audience: input.authRedirect.audience,
2326
2253
  state: { kind: "confirm", ...(input.email ? { email: input.email } : {}) },
2327
2254
  signInUrl: authExperienceSignInUrl(input.authRedirect),
2328
2255
  submission: {
@@ -2331,7 +2258,6 @@ async function magicLinkConfirmResponse(
2331
2258
  fields: {
2332
2259
  magicLinkId: input.magicLinkId,
2333
2260
  token: input.token,
2334
- audience: input.authRedirect.audience,
2335
2261
  },
2336
2262
  },
2337
2263
  referrerPolicy: "same-origin",
@@ -2352,11 +2278,6 @@ async function magicLinkConfirmResponse(
2352
2278
  '<form method="post" action="/auth/callback" id="confirm">',
2353
2279
  `<input type="hidden" name="magicLinkId" value="${escapeHtml(input.magicLinkId)}">`,
2354
2280
  `<input type="hidden" name="token" value="${escapeHtml(input.token)}">`,
2355
- ...(input.authRedirect
2356
- ? [
2357
- `<input type="hidden" name="audience" value="${escapeHtml(input.authRedirect.audience)}">`,
2358
- ]
2359
- : []),
2360
2281
  '<button type="submit" id="confirm-button">Continue</button>',
2361
2282
  "</form>",
2362
2283
  "<script>",
@@ -25,7 +25,7 @@ import {
25
25
  SignedFileUploadPartSchema,
26
26
  } from "../schemas/files"
27
27
  import { handleRouteError, unconfiguredStorageResponse } from "../utils/http"
28
- import { RequestBodyTooLargeError, readRequestBodyWithLimit } from "../utils/request-body"
28
+ import { readRequestBodyWithLimit } from "../utils/request-body"
29
29
  // The simple-upload ceiling lives in @sixb/core so the client staged-switch
30
30
  // threshold and this server limit stay a single source of truth. The body limit
31
31
  // adds headroom for multipart/form-data encoding overhead on the `POST /api/files`
@@ -40,16 +40,14 @@ export function registerFileRoutes(app: Elysia, host: SixbHostView) {
40
40
  "/api/files",
41
41
  async ({ request, set }) => {
42
42
  try {
43
- const requestSizeError = requestSizeLimitError(
43
+ const bytes = await readRequestBodyWithLimit(
44
44
  request,
45
- DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES
45
+ DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES,
46
+ `File upload request exceeds the ${DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES} byte limit.`
46
47
  )
47
- if (requestSizeError) {
48
- set.status = 413
49
- return { error: requestSizeError }
50
- }
51
-
52
- const form = await request.formData()
48
+ const form = await new Response(bytes, {
49
+ headers: { "content-type": request.headers.get("content-type") ?? "" },
50
+ }).formData()
53
51
  const file = form.get("file")
54
52
  const logicalPath = form.get("logicalPath")
55
53
 
@@ -205,7 +203,10 @@ export function registerFileRoutes(app: Elysia, host: SixbHostView) {
205
203
  return { error: contentLengthSizeError }
206
204
  }
207
205
 
208
- const uploadBytes = readParsedUploadBytes(context)
206
+ const uploadBytes = await readRequestBodyWithLimit(
207
+ request,
208
+ DEFAULT_SIMPLE_FILE_UPLOAD_BYTES
209
+ )
209
210
  if (uploadBytes.byteLength === 0) {
210
211
  set.status = 400
211
212
  return { error: "Expected upload content body." }
@@ -239,18 +240,16 @@ export function registerFileRoutes(app: Elysia, host: SixbHostView) {
239
240
  },
240
241
  {
241
242
  params: FileUploadIdParamsSchema,
242
- // Replace Elysia's default body parser so the octet-stream is read through
243
- // the size-capped streaming reader instead of being fully buffered first.
244
- parse: readCappedUploadBody,
245
- // The cap is enforced during parsing, which is outside the handler's
246
- // try/catch, so map its too-large error to 413 here.
247
- error: mapUploadContentError,
243
+ // The handler reads the content itself, once it knows the caller and the session, so
244
+ // Elysia must not parse the body first.
245
+ parse: "none",
248
246
  response: {
249
247
  200: SuccessResponseSchema,
250
248
  400: ErrorResponseSchema,
251
249
  404: ErrorResponseSchema,
252
250
  409: ErrorResponseSchema,
253
251
  410: ErrorResponseSchema,
252
+ 413: ErrorResponseSchema,
254
253
  501: ErrorResponseSchema,
255
254
  },
256
255
  detail: {
@@ -498,39 +497,6 @@ function fileUploadResponse(session: FileUploadSession) {
498
497
  }
499
498
  }
500
499
 
501
- // Elysia `parse` hook: reads the staged content stream with a hard size ceiling,
502
- // so an oversized (or chunked, content-length-lying) body is rejected before it
503
- // is fully buffered. Its result becomes `context.body`.
504
- function readCappedUploadBody(context: { request: Request }): Promise<Uint8Array> {
505
- return readRequestBodyWithLimit(context.request, DEFAULT_SIMPLE_FILE_UPLOAD_BYTES)
506
- }
507
-
508
- function readParsedUploadBytes(context: { body?: unknown }): Uint8Array {
509
- return context.body instanceof Uint8Array ? context.body : new Uint8Array(0)
510
- }
511
-
512
- function mapUploadContentError(context: {
513
- error: unknown
514
- set: { status?: number | string }
515
- }): { error: string } | undefined {
516
- const tooLarge = asRequestBodyTooLarge(context.error)
517
- if (tooLarge) {
518
- context.set.status = 413
519
- return { error: tooLarge.message }
520
- }
521
- return undefined
522
- }
523
-
524
- // The cap runs in the `parse` phase, so Elysia surfaces it wrapped in a
525
- // ParseError; the original error is carried on `cause`.
526
- function asRequestBodyTooLarge(error: unknown): RequestBodyTooLargeError | undefined {
527
- if (error instanceof RequestBodyTooLargeError) {
528
- return error
529
- }
530
- const cause = (error as { cause?: unknown } | null | undefined)?.cause
531
- return cause instanceof RequestBodyTooLargeError ? cause : undefined
532
- }
533
-
534
500
  // A non-pending session is terminal; surface which terminal state so the route
535
501
  // boundary maps it to 409. Store lookups already raise `not_found`/`expired`.
536
502
  function terminalSessionError(status: "completed" | "aborted"): FileUploadSessionError {
@@ -649,20 +615,6 @@ function expectedSizeBytesValueError(
649
615
  : null
650
616
  }
651
617
 
652
- function requestSizeLimitError(request: Request, maxSizeBytes: number): string | null {
653
- const value = request.headers.get("content-length")
654
- if (value === null) {
655
- return null
656
- }
657
-
658
- const sizeBytes = Number(value)
659
- if (!Number.isSafeInteger(sizeBytes) || sizeBytes <= maxSizeBytes) {
660
- return null
661
- }
662
-
663
- return `File upload request exceeds the ${maxSizeBytes} byte limit.`
664
- }
665
-
666
618
  function expectedContentLengthError(session: FileUploadSession, request: Request): string | null {
667
619
  if (session.expectedSizeBytes === undefined) {
668
620
  return null
@@ -23,7 +23,6 @@ const SubscribeSchema = z.object({
23
23
  types: z.array(z.enum(EVENT_TYPES)).optional(),
24
24
  objectTypeId: z.string().optional(),
25
25
  primaryId: z.string().optional(),
26
- actionId: z.string().optional(),
27
26
  runId: z.string().optional(),
28
27
  afterCursor: z.string().optional(),
29
28
  limit: z.number().int().positive().max(500).optional(),
@@ -212,17 +211,11 @@ function eventMatchesScope(
212
211
  filter: {
213
212
  readonly objectTypeId?: string
214
213
  readonly primaryId?: string
215
- readonly actionId?: string
216
214
  readonly runId?: string
217
215
  }
218
216
  ): boolean {
219
- const { objectTypeId, primaryId, actionId, runId } = filter
220
- if (
221
- objectTypeId === undefined &&
222
- primaryId === undefined &&
223
- actionId === undefined &&
224
- runId === undefined
225
- ) {
217
+ const { objectTypeId, primaryId, runId } = filter
218
+ if (objectTypeId === undefined && primaryId === undefined && runId === undefined) {
226
219
  return true
227
220
  }
228
221
 
@@ -233,9 +226,6 @@ function eventMatchesScope(
233
226
  if (primaryId !== undefined && scope.primaryId !== primaryId) {
234
227
  return false
235
228
  }
236
- if (actionId !== undefined && scope.actionId !== actionId) {
237
- return false
238
- }
239
229
  if (runId !== undefined && scope.runId !== runId) {
240
230
  return false
241
231
  }