@sixb/server 0.1.19 → 0.1.21

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 (103) hide show
  1. package/README.md +13 -22
  2. package/dist/artifacts/frame.d.ts +13 -0
  3. package/dist/artifacts/frame.d.ts.map +1 -0
  4. package/dist/auth/browser-origin.d.ts +9 -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/files/content.d.ts +2 -3
  16. package/dist/files/content.d.ts.map +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +3241 -2445
  20. package/dist/index.js.map +31 -26
  21. package/dist/openapi/tags.d.ts +10 -2
  22. package/dist/openapi/tags.d.ts.map +1 -1
  23. package/dist/registerRoutes.d.ts +3 -0
  24. package/dist/registerRoutes.d.ts.map +1 -1
  25. package/dist/routes/action-runs.d.ts +0 -2
  26. package/dist/routes/action-runs.d.ts.map +1 -1
  27. package/dist/routes/activity.d.ts +35 -0
  28. package/dist/routes/activity.d.ts.map +1 -0
  29. package/dist/routes/agents.d.ts +18 -29
  30. package/dist/routes/agents.d.ts.map +1 -1
  31. package/dist/routes/artifact-frames.d.ts +98 -0
  32. package/dist/routes/artifact-frames.d.ts.map +1 -0
  33. package/dist/routes/artifacts.d.ts +852 -0
  34. package/dist/routes/artifacts.d.ts.map +1 -0
  35. package/dist/routes/auth.d.ts +9 -18
  36. package/dist/routes/auth.d.ts.map +1 -1
  37. package/dist/routes/connector-connection-runs.d.ts +59 -59
  38. package/dist/routes/connector-connections.d.ts +2 -2
  39. package/dist/routes/datasets.d.ts +7 -7
  40. package/dist/routes/events.d.ts +1 -1
  41. package/dist/routes/objects.d.ts +0 -2
  42. package/dist/routes/objects.d.ts.map +1 -1
  43. package/dist/routes/pipelines.d.ts +31 -31
  44. package/dist/routes/projections.d.ts +10 -10
  45. package/dist/routes/share-grants.d.ts +5 -5
  46. package/dist/routes/syncs.d.ts +38 -38
  47. package/dist/routes/workflows.d.ts +30 -34
  48. package/dist/routes/workflows.d.ts.map +1 -1
  49. package/dist/routes/ws/events.d.ts.map +1 -1
  50. package/dist/routes/ws/subscription-hub.d.ts +8 -3
  51. package/dist/routes/ws/subscription-hub.d.ts.map +1 -1
  52. package/dist/schemas/activity.d.ts +1278 -0
  53. package/dist/schemas/activity.d.ts.map +1 -0
  54. package/dist/schemas/agents.d.ts +96 -144
  55. package/dist/schemas/agents.d.ts.map +1 -1
  56. package/dist/schemas/ai-accounting.d.ts +24 -24
  57. package/dist/schemas/ai-limits.d.ts +26 -26
  58. package/dist/schemas/artifacts.d.ts +1305 -0
  59. package/dist/schemas/artifacts.d.ts.map +1 -0
  60. package/dist/schemas/auth.d.ts +34 -69
  61. package/dist/schemas/auth.d.ts.map +1 -1
  62. package/dist/schemas/connectors.d.ts +30 -30
  63. package/dist/schemas/datasets.d.ts +10 -10
  64. package/dist/schemas/events.d.ts +6 -6
  65. package/dist/schemas/files.d.ts +0 -3
  66. package/dist/schemas/files.d.ts.map +1 -1
  67. package/dist/schemas/pipelines.d.ts +35 -35
  68. package/dist/schemas/projections.d.ts +40 -40
  69. package/dist/schemas/share-grants.d.ts +16 -16
  70. package/dist/schemas/syncs.d.ts +36 -36
  71. package/dist/schemas/workflows.d.ts +84 -84
  72. package/dist/server.d.ts +1 -2
  73. package/dist/server.d.ts.map +1 -1
  74. package/package.json +6 -6
  75. package/src/artifacts/frame.ts +46 -0
  76. package/src/auth/browser-origin.ts +40 -240
  77. package/src/auth/experience.ts +1 -4
  78. package/src/auth/guard.ts +4 -32
  79. package/src/auth/public-routes.ts +11 -10
  80. package/src/auth/responses.ts +0 -5
  81. package/src/auth/session-cookies.ts +1 -3
  82. package/src/auth/shared-access.ts +1 -1
  83. package/src/files/content.ts +9 -13
  84. package/src/index.ts +1 -1
  85. package/src/openapi/tags.ts +8 -0
  86. package/src/registerRoutes.ts +9 -0
  87. package/src/routes/activity.ts +327 -0
  88. package/src/routes/agents.ts +1 -1
  89. package/src/routes/artifact-frames.ts +138 -0
  90. package/src/routes/artifacts.ts +442 -0
  91. package/src/routes/auth.ts +32 -111
  92. package/src/routes/file-downloads.ts +1 -3
  93. package/src/routes/ws/events.ts +3 -2
  94. package/src/routes/ws/subscription-hub.ts +53 -20
  95. package/src/schemas/activity.ts +285 -0
  96. package/src/schemas/agents.ts +1 -2
  97. package/src/schemas/artifacts.ts +158 -0
  98. package/src/schemas/auth.ts +2 -15
  99. package/src/schemas/files.ts +0 -6
  100. package/src/server.ts +27 -24
  101. package/dist/auth/application-access.d.ts +0 -4
  102. package/dist/auth/application-access.d.ts.map +0 -1
  103. package/src/auth/application-access.ts +0 -15
@@ -0,0 +1,285 @@
1
+ import {
2
+ ACTIVITY_BATCH_LIMIT,
3
+ ACTIVITY_EVENT_ID_PATTERN,
4
+ ACTIVITY_HOSTNAME_PATTERN,
5
+ ACTIVITY_ID_MAX_LENGTH,
6
+ ACTIVITY_INTERACTION_NAME_MAX_LENGTH,
7
+ ACTIVITY_INTERACTION_NAME_PATTERN,
8
+ ACTIVITY_LABEL_MAX_LENGTH,
9
+ ACTIVITY_LABEL_PATTERN,
10
+ ACTIVITY_MAX_PAGE_SIZE,
11
+ ACTIVITY_MAX_PERIOD_MS,
12
+ ACTIVITY_REFERRER_MAX_LENGTH,
13
+ ACTIVITY_ROUTE_MAX_LENGTH,
14
+ ACTIVITY_VISIT_ID_PATTERN,
15
+ isActivityRoutePattern,
16
+ } from "@sixb/core/internal/storage"
17
+ import { z } from "zod"
18
+ import { ActionRunStatusSchema } from "./actions"
19
+ import { AgentRunStatusSchema } from "./agents"
20
+ import { AiCostSummarySchema } from "./ai-accounting"
21
+ import { WorkflowRunStatusSchema } from "./workflows"
22
+
23
+ // The limits come from the activity policy, so the API refuses what the providers would.
24
+ const VisitIdSchema = z.string().regex(ACTIVITY_VISIT_ID_PATTERN)
25
+
26
+ const UserIdSchema = z
27
+ .string()
28
+ .min(1)
29
+ .max(ACTIVITY_ID_MAX_LENGTH)
30
+ .refine((value) => value.trim().length > 0, "Expected a user id")
31
+
32
+ const RouteSchema = z
33
+ .string()
34
+ .min(1)
35
+ .max(ACTIVITY_ROUTE_MAX_LENGTH)
36
+ .startsWith("/")
37
+ .refine(isActivityRoutePattern, "Expected a normalized route pattern")
38
+
39
+ const LabelSchema = z
40
+ .string()
41
+ .min(1)
42
+ .max(ACTIVITY_LABEL_MAX_LENGTH)
43
+ .regex(ACTIVITY_LABEL_PATTERN)
44
+ .refine((value) => value === value.trim(), "Expected a trimmed label")
45
+
46
+ const ActivityAttributionSchema = z
47
+ .object({
48
+ source: LabelSchema.optional(),
49
+ medium: LabelSchema.optional(),
50
+ campaign: LabelSchema.optional(),
51
+ referrer: z
52
+ .string()
53
+ .min(1)
54
+ .max(ACTIVITY_REFERRER_MAX_LENGTH)
55
+ .regex(ACTIVITY_HOSTNAME_PATTERN)
56
+ .optional(),
57
+ })
58
+ .strict()
59
+
60
+ export const ActivityEventInputSchema = z.discriminatedUnion("type", [
61
+ z
62
+ .object({
63
+ id: z.string().regex(ACTIVITY_EVENT_ID_PATTERN),
64
+ type: z.enum(["page.view", "visit.activity"]),
65
+ route: RouteSchema,
66
+ attribution: ActivityAttributionSchema.optional(),
67
+ })
68
+ .strict(),
69
+ z
70
+ .object({
71
+ id: z.string().regex(ACTIVITY_EVENT_ID_PATTERN),
72
+ type: z.literal("ui.interaction"),
73
+ name: z
74
+ .string()
75
+ .min(1)
76
+ .max(ACTIVITY_INTERACTION_NAME_MAX_LENGTH)
77
+ .regex(ACTIVITY_INTERACTION_NAME_PATTERN),
78
+ route: RouteSchema,
79
+ })
80
+ .strict(),
81
+ ])
82
+
83
+ export const CaptureActivityBodySchema = z
84
+ .object({ events: z.array(ActivityEventInputSchema).min(1).max(ACTIVITY_BATCH_LIMIT) })
85
+ .strict()
86
+ .refine(
87
+ (body) => new Set(body.events.map((event) => event.id)).size === body.events.length,
88
+ "Event ids must be unique"
89
+ )
90
+
91
+ export const ActivityCaptureOptionsSchema = z.object({
92
+ enabled: z.boolean(),
93
+ idleTimeoutMs: z.number(),
94
+ })
95
+
96
+ export const ActivityCaptureResultSchema = z.object({
97
+ status: z.enum(["accepted", "disabled", "throttled"]),
98
+ accepted: z.number(),
99
+ })
100
+
101
+ const ActivityActorSchema = z.discriminatedUnion("type", [
102
+ z.object({ type: z.literal("user"), userId: z.string() }),
103
+ z.object({
104
+ type: z.literal("share"),
105
+ grantId: z.string(),
106
+ definitionId: z.string().optional(),
107
+ }),
108
+ ])
109
+
110
+ const ActivityVisitSchema = z.object({
111
+ id: VisitIdSchema,
112
+ actor: ActivityActorSchema,
113
+ attribution: ActivityAttributionSchema.nullable(),
114
+ startedAt: z.string().datetime(),
115
+ lastSeenAt: z.string().datetime(),
116
+ pageViews: z.number(),
117
+ interactions: z.number(),
118
+ })
119
+
120
+ export const ActivityVisitsPageSchema = z.object({
121
+ visits: z.array(ActivityVisitSchema),
122
+ hasMore: z.boolean(),
123
+ })
124
+
125
+ export const ActivityUsersPageSchema = z.object({
126
+ users: z.array(
127
+ z.object({
128
+ userId: z.string(),
129
+ displayName: z.string().optional(),
130
+ lastSeenAt: z.string().datetime(),
131
+ visits: z.number(),
132
+ pageViews: z.number(),
133
+ })
134
+ ),
135
+ hasMore: z.boolean(),
136
+ })
137
+
138
+ export const ActivitySummarySchema = z.object({
139
+ users: z.number(),
140
+ visits: z.number(),
141
+ sharedVisits: z.number(),
142
+ pageViews: z.number(),
143
+ })
144
+
145
+ const ActivityConnectionStatusSchema = z.enum(["active", "expired", "revoked"])
146
+
147
+ const ActivitySessionConnectionSchema = z.object({
148
+ type: z.literal("session"),
149
+ device: z.object({ browser: z.string().optional(), os: z.string().optional() }),
150
+ clientName: z.string().optional(),
151
+ status: ActivityConnectionStatusSchema,
152
+ createdAt: z.string().datetime(),
153
+ lastSeenAt: z.string().datetime().optional(),
154
+ revokedAt: z.string().datetime().optional(),
155
+ })
156
+
157
+ const ActivityShareConnectionSchema = z.object({
158
+ type: z.literal("share"),
159
+ grantId: z.string(),
160
+ definitionId: z.string().optional(),
161
+ status: ActivityConnectionStatusSchema,
162
+ createdAt: z.string().datetime(),
163
+ revokedAt: z.string().datetime().optional(),
164
+ })
165
+
166
+ const ActivityTimelineEntrySchema = z.discriminatedUnion("kind", [
167
+ z.object({
168
+ kind: z.literal("page"),
169
+ at: z.string().datetime(),
170
+ sequence: z.number(),
171
+ route: z.string(),
172
+ }),
173
+ z.object({
174
+ kind: z.literal("interaction"),
175
+ at: z.string().datetime(),
176
+ sequence: z.number(),
177
+ name: z.string(),
178
+ route: z.string(),
179
+ }),
180
+ z.object({
181
+ kind: z.literal("action"),
182
+ at: z.string().datetime(),
183
+ executionId: z.string(),
184
+ actionId: z.string(),
185
+ runId: z.string(),
186
+ status: z.union([ActionRunStatusSchema, z.literal("incomplete")]),
187
+ runVisible: z.boolean().describe("Whether the viewer may read the run itself."),
188
+ object: z.object({ objectTypeId: z.string(), primaryId: z.string() }).optional(),
189
+ }),
190
+ z.object({
191
+ kind: z.literal("workflow"),
192
+ at: z.string().datetime(),
193
+ executionId: z.string(),
194
+ workflowId: z.string(),
195
+ runId: z.string(),
196
+ status: z.union([WorkflowRunStatusSchema, z.literal("incomplete")]),
197
+ runVisible: z.boolean().describe("Whether the viewer may read the run itself."),
198
+ }),
199
+ z.object({
200
+ kind: z.literal("agent"),
201
+ at: z.string().datetime(),
202
+ executionId: z.string(),
203
+ runId: z.string(),
204
+ threadId: z.string(),
205
+ status: AgentRunStatusSchema,
206
+ messages: z.number(),
207
+ cost: AiCostSummarySchema.optional(),
208
+ }),
209
+ ])
210
+
211
+ export const ActivityVisitTimelineSchema = z.object({
212
+ visit: ActivityVisitSchema,
213
+ connection: z
214
+ .discriminatedUnion("type", [ActivitySessionConnectionSchema, ActivityShareConnectionSchema])
215
+ .optional(),
216
+ entries: z.array(ActivityTimelineEntrySchema),
217
+ truncated: z.boolean(),
218
+ })
219
+
220
+ export const ActivityConnectionsPageSchema = z.object({
221
+ connections: z.array(
222
+ ActivitySessionConnectionSchema.extend({
223
+ visits: z.number(),
224
+ latestVisits: z.array(ActivityVisitSchema),
225
+ })
226
+ ),
227
+ nextCursor: z.string().optional(),
228
+ })
229
+
230
+ export const ActivityCalendarSchema = z.object({
231
+ userId: z.string(),
232
+ year: z.number(),
233
+ days: z.array(z.object({ day: z.string(), visits: z.number(), pageViews: z.number() })),
234
+ })
235
+
236
+ const periodFields = {
237
+ from: z.string().datetime(),
238
+ to: z.string().datetime(),
239
+ userId: UserIdSchema.optional(),
240
+ }
241
+
242
+ const PageSizeSchema = z.coerce.number().int().min(1).max(ACTIVITY_MAX_PAGE_SIZE)
243
+
244
+ const pageFields = {
245
+ limit: PageSizeSchema.optional(),
246
+ beforeAt: z.string().datetime().optional(),
247
+ beforeId: z.string().min(1).max(ACTIVITY_ID_MAX_LENGTH).optional(),
248
+ }
249
+
250
+ function isBoundedPeriod(input: { readonly from: string; readonly to: string }): boolean {
251
+ const span = Date.parse(input.to) - Date.parse(input.from)
252
+ return span > 0 && span <= ACTIVITY_MAX_PERIOD_MS
253
+ }
254
+
255
+ function hasWholeCursor(input: { readonly beforeAt?: string; readonly beforeId?: string }) {
256
+ return (input.beforeAt === undefined) === (input.beforeId === undefined)
257
+ }
258
+
259
+ export const ActivityPeriodQuerySchema = z
260
+ .object(periodFields)
261
+ .refine(isBoundedPeriod, "Expected an ordered period of at most 31 days")
262
+
263
+ export const ActivityPageQuerySchema = z
264
+ .object({ ...periodFields, ...pageFields })
265
+ .refine(isBoundedPeriod, "Expected an ordered period of at most 31 days")
266
+ .refine(hasWholeCursor, "beforeAt and beforeId go together")
267
+
268
+ export const ActivityCalendarQuerySchema = z.object({
269
+ userId: UserIdSchema,
270
+ year: z.coerce.number().int().min(1970).max(9998),
271
+ })
272
+
273
+ export const ActivityConnectionsQuerySchema = z.object({
274
+ userId: UserIdSchema,
275
+ limit: PageSizeSchema.optional(),
276
+ cursor: z
277
+ .string()
278
+ .min(1)
279
+ .max(200)
280
+ .regex(/^[A-Za-z0-9_-]+$/)
281
+ .optional()
282
+ .describe("The previous page's nextCursor."),
283
+ })
284
+
285
+ export const ActivityVisitParamsSchema = z.object({ visitId: VisitIdSchema })
@@ -202,8 +202,7 @@ export const AgentMessagePartSchema = z.union([
202
202
  export const AgentRunDiagnosticSchema = z.object({
203
203
  code: z.enum(AGENT_RUN_DIAGNOSTIC_CODES),
204
204
  severity: z.enum(["warning", "error"]),
205
- scope: z.enum(["output", "run"]),
206
- path: z.string().optional(),
205
+ scope: z.enum(["run"]),
207
206
  message: z.string(),
208
207
  })
209
208
 
@@ -0,0 +1,158 @@
1
+ import { ARTIFACT_KINDS } from "@sixb/core/artifacts"
2
+ import { z } from "zod"
3
+ import { ErrorResponseSchema, PrincipalSchema } from "./common"
4
+ import { FileRefSchema } from "./files"
5
+
6
+ const ArtifactKindSchema = z.enum(ARTIFACT_KINDS)
7
+
8
+ const ArtifactFileSchema = z.object({
9
+ path: z
10
+ .string()
11
+ .min(1)
12
+ .describe("The file's path inside the artifact, such as figures/revenue.svg"),
13
+ file: FileRefSchema,
14
+ })
15
+
16
+ const DocumentOutlineSchema = z.object({
17
+ kind: z.literal("document"),
18
+ headings: z.array(z.object({ depth: z.number().int(), text: z.string(), slug: z.string() })),
19
+ })
20
+
21
+ const SheetOutlineSchema = z.object({
22
+ kind: z.literal("sheet"),
23
+ sheets: z.array(
24
+ z.object({ name: z.string(), rows: z.number().int(), columns: z.array(z.string()) })
25
+ ),
26
+ charts: z.array(z.string()),
27
+ })
28
+
29
+ const SlidesOutlineSchema = z.object({
30
+ kind: z.literal("slides"),
31
+ slides: z.array(z.object({ title: z.string().optional() })),
32
+ })
33
+
34
+ const FileOutlineSchema = z.object({ kind: z.literal("file"), mediaType: z.string() })
35
+
36
+ const ArtifactOutlineSchema = z.discriminatedUnion("kind", [
37
+ DocumentOutlineSchema,
38
+ SheetOutlineSchema,
39
+ SlidesOutlineSchema,
40
+ FileOutlineSchema,
41
+ ])
42
+
43
+ const ArtifactReferenceSchema = z.object({
44
+ address: z.string(),
45
+ as: z.enum(["embed", "link"]),
46
+ at: z.string(),
47
+ resolvedVersion: z.number().int().positive(),
48
+ })
49
+
50
+ const ArtifactWarningSchema = z.object({
51
+ code: z.string(),
52
+ message: z.string(),
53
+ part: z.string().optional(),
54
+ })
55
+
56
+ const ArtifactSchema = z.object({
57
+ id: z.string(),
58
+ projectId: z.string(),
59
+ kind: ArtifactKindSchema,
60
+ title: z.string(),
61
+ owner: PrincipalSchema,
62
+ latestVersion: z.number().int().positive(),
63
+ createdAt: z.string(),
64
+ updatedAt: z.string(),
65
+ })
66
+
67
+ const ArtifactOriginSchema = z.object({ threadId: z.string(), runId: z.string() })
68
+
69
+ export const ArtifactVersionSchema = z.object({
70
+ artifactId: z.string(),
71
+ version: z.number().int().positive(),
72
+ title: z.string(),
73
+ entry: z.string(),
74
+ files: z.array(ArtifactFileSchema),
75
+ outline: ArtifactOutlineSchema,
76
+ references: z.array(ArtifactReferenceSchema),
77
+ author: PrincipalSchema,
78
+ origin: ArtifactOriginSchema.optional(),
79
+ createdAt: z.string(),
80
+ })
81
+
82
+ const ArtifactVersionSummarySchema = ArtifactVersionSchema.pick({
83
+ version: true,
84
+ title: true,
85
+ author: true,
86
+ origin: true,
87
+ createdAt: true,
88
+ })
89
+
90
+ export const ArtifactParamsSchema = z.object({ artifactId: z.string().min(1) })
91
+
92
+ export const ArtifactVersionParamsSchema = ArtifactParamsSchema.extend({
93
+ version: z
94
+ .string()
95
+ .regex(/^(?:latest|[1-9]\d*)$/)
96
+ .describe('A version number, or "latest"'),
97
+ })
98
+
99
+ export const ArtifactListQuerySchema = z
100
+ .object({
101
+ thread: z
102
+ .string()
103
+ .min(1)
104
+ .optional()
105
+ .describe("Only artifacts with a version the Agent published in this thread"),
106
+ kind: ArtifactKindSchema.optional().describe("Only artifacts of this kind"),
107
+ limit: z.string().optional(),
108
+ offset: z.string().optional(),
109
+ })
110
+ .strict()
111
+
112
+ export const ArtifactListResponseSchema = z.object({
113
+ artifacts: z.array(ArtifactSchema),
114
+ hasMore: z.boolean(),
115
+ total: z.number().int(),
116
+ })
117
+
118
+ export const ArtifactResponseSchema = z.object({
119
+ artifact: ArtifactSchema,
120
+ versions: z.array(ArtifactVersionSummarySchema).describe("Newest first"),
121
+ })
122
+
123
+ export const PublishArtifactBodySchema = z
124
+ .object({
125
+ kind: ArtifactKindSchema,
126
+ title: z.string(),
127
+ files: z
128
+ .array(ArtifactFileSchema)
129
+ .min(1)
130
+ .describe("Files stored with POST /api/files, at their paths in the artifact"),
131
+ })
132
+ .strict()
133
+
134
+ export const PublishedArtifactResponseSchema = z.object({
135
+ artifact: ArtifactSchema,
136
+ version: ArtifactVersionSchema,
137
+ warnings: z.array(ArtifactWarningSchema),
138
+ })
139
+
140
+ export const DeleteArtifactResponseSchema = z.object({ deleted: z.literal(true) })
141
+
142
+ export const ArtifactFrameResponseSchema = z.object({
143
+ path: z
144
+ .string()
145
+ .describe(
146
+ "The frame's base path on this API, ending in /; the deck's entry is served under it"
147
+ ),
148
+ expiresAt: z.string().describe("When the frame stops serving; ask for a new one before then"),
149
+ })
150
+
151
+ export const ArtifactErrorResponseSchema = ErrorResponseSchema.extend({
152
+ code: z
153
+ .string()
154
+ .optional()
155
+ .describe(
156
+ "Stable machine-readable failure code: artifact_not_found, artifact_kind_mismatch, invalid_artifact, not_allowed, or storage_unavailable."
157
+ ),
158
+ })
@@ -179,15 +179,8 @@ export const AuthCreateInvitationCapabilitySchema = z.union([
179
179
  }),
180
180
  ])
181
181
 
182
- export const AuthInvitationDestinationSchema = z.object({
183
- id: z.enum(["atlas", "app"]),
184
- label: z.string(),
185
- })
186
-
187
182
  export const GetAuthInvitationOptionsResponseSchema = z.object({
188
183
  groups: z.array(AuthInvitationGroupOptionSchema),
189
- destinations: z.array(AuthInvitationDestinationSchema),
190
- defaultDestinationId: z.enum(["atlas", "app"]).optional(),
191
184
  canInviteWithoutGroups: z.boolean(),
192
185
  capabilities: z.object({
193
186
  createInvitation: AuthCreateInvitationCapabilitySchema,
@@ -196,10 +189,12 @@ export const GetAuthInvitationOptionsResponseSchema = z.object({
196
189
 
197
190
  export const GetAuthMembershipOptionsResponseSchema = z.object({
198
191
  groups: z.array(AuthGroupOptionSchema),
192
+ serviceAccountGroups: z.array(AuthGroupOptionSchema),
199
193
  capabilities: z.object({
200
194
  invite: z.boolean(),
201
195
  assignGroups: z.boolean(),
202
196
  suspend: z.boolean(),
197
+ serviceAccounts: z.boolean(),
203
198
  }),
204
199
  })
205
200
 
@@ -238,7 +233,6 @@ export const ReactivateAuthMemberResponseSchema = z.object({
238
233
  export const CreateAuthInvitationBodySchema = z.object({
239
234
  email: z.string().min(1),
240
235
  groupIds: z.array(z.string().min(1)).optional(),
241
- destinationId: z.enum(["atlas", "app"]).optional(),
242
236
  expiresAt: z.string().optional(),
243
237
  returnTo: z.string().optional(),
244
238
  revealLink: z.boolean().optional(),
@@ -284,11 +278,6 @@ export const AuthSessionResponseSchema = z.union([
284
278
  authenticated: z.literal(true),
285
279
  /** Browser sessions only: send it back in `x-sixb-csrf` on mutations. */
286
280
  csrfToken: z.string().optional(),
287
- /** Whether the user may open a web app: the browser session's own, or Atlas for a native client. */
288
- applicationAccess: z.object({
289
- allowed: z.boolean(),
290
- audience: z.enum(["atlas", "app"]),
291
- }),
292
281
  user: z.object({
293
282
  id: z.string(),
294
283
  email: z.string(),
@@ -352,8 +341,6 @@ export const DeviceAuthorizationDecisionBodySchema = z.object({
352
341
 
353
342
  export const AuthSessionSummarySchema = z.object({
354
343
  id: z.string(),
355
- /** The web app a browser session belongs to. Native clients' sessions have none. */
356
- audience: z.enum(["atlas", "app"]).optional(),
357
344
  current: z.boolean(),
358
345
  createdAt: z.string(),
359
346
  expiresAt: z.string(),
@@ -84,12 +84,6 @@ export const CompleteFileUploadBodySchema = z.object({
84
84
  })
85
85
 
86
86
  export const FileContentQuerySchema = z.object({
87
- audience: z
88
- .enum(["atlas", "app"])
89
- .optional()
90
- .describe(
91
- "Session audience for file navigation without Origin; must match Origin when present"
92
- ),
93
87
  path: z.string().min(1),
94
88
  disposition: z.enum(["inline", "attachment"]).optional(),
95
89
  v: z.string().optional().describe("Client cache key; the route still resolves the current file"),
package/src/server.ts CHANGED
@@ -1,21 +1,20 @@
1
1
  import { cors } from "@elysiajs/cors"
2
2
  import { openapi } from "@elysiajs/openapi"
3
3
  import type { OntologyMaintenanceHandle, SixbHostView } from "@sixb/core"
4
+ import { ARTIFACT_FRAME_ROUTE_PREFIX } from "@sixb/core/internal/artifacts/frames"
4
5
  import { CSRF_HEADER_NAME, setRequestClientAddress } from "@sixb/core/internal/auth"
5
6
  import { bindRequestExecution } from "@sixb/core/internal/request-execution"
6
7
  import { setApiPublicOrigin } from "@sixb/core/internal/runtime"
8
+ import { checkPipelineMarkings, warmAppliedMarkings } from "@sixb/core/internal/security"
7
9
  import type { Server } from "bun"
8
10
  import { Elysia, ParseError } from "elysia"
9
11
  import { websocket as elysiaWebSocket } from "elysia/ws"
10
12
  import { zodToJsonSchema } from "zod-to-json-schema"
11
13
  import {
12
- type AuthInvitationDestinationOptions,
13
14
  type AuthInvitationRedirectContext,
14
15
  type AuthInvitationRedirectInput,
15
- BrowserOriginError,
16
16
  createApiBrowserAuthContextResolver,
17
17
  createApiBrowserAuthRedirectContextResolver,
18
- getApiBrowserInvitationDestinationOptions,
19
18
  isAllowedApiBrowserOrigin,
20
19
  type RequestAuthContext,
21
20
  type ResolveAuthRedirectContext,
@@ -146,10 +145,6 @@ export class SixbServer {
146
145
  return resolveApiBrowserPublicOrigin(this.apiBrowserPolicy, request)
147
146
  }
148
147
 
149
- getInvitationDestinationOptions(_request: Request): AuthInvitationDestinationOptions {
150
- return getApiBrowserInvitationDestinationOptions(this.apiBrowserPolicy)
151
- }
152
-
153
148
  resolveInvitationRedirectContext(
154
149
  request: Request,
155
150
  input: AuthInvitationRedirectInput
@@ -174,6 +169,16 @@ export class SixbServer {
174
169
  throw new Error("[SixbServer] Server is already running.")
175
170
  }
176
171
 
172
+ // Startup cannot see through SQL steps: check what they derive before serving any request.
173
+ await checkPipelineMarkings({
174
+ definitions: this.hostRuntime.definitions,
175
+ lakeStorage: this.hostRuntime.lakeStorage,
176
+ })
177
+
178
+ // Objects keep the markings of the versions they were projected from. The first read that
179
+ // needs them waits for them; reading them now spares that read the wait.
180
+ warmAppliedMarkings(this.hostRuntime)
181
+
177
182
  const maintenance = await this.hostRuntime.startOntologyMaintenance()
178
183
  this.maintenance = maintenance
179
184
 
@@ -439,10 +444,8 @@ export function createSixbApi(server: SixbServer) {
439
444
 
440
445
  const authExperience = server.getAuthExperience()
441
446
  registerAuthRoutes(app, host, {
442
- resolveAuthContext: (request) => server.resolveAuthContext(request),
443
447
  resolveAuthRedirectContext: (request, input) =>
444
448
  server.resolveAuthRedirectContext(request, input),
445
- getInvitationDestinationOptions: (request) => server.getInvitationDestinationOptions(request),
446
449
  resolveAuthRequestOrigin: (request) => server.resolveAuthRequestOrigin(request),
447
450
  authExperience: authExperience && { ...authExperience, locale: host.locale },
448
451
  resolveInvitationRedirectContext: (request, input) =>
@@ -450,14 +453,10 @@ export function createSixbApi(server: SixbServer) {
450
453
  })
451
454
  registerHttpRoutes(app, host, {
452
455
  sharedAccess,
456
+ browserPolicy: apiBrowserPolicy,
453
457
  connectorConnections: {
454
- resolveReturnTo: (request, returnTo) => {
455
- const authContext = server.resolveAuthContext(request)
456
- return server.resolveAuthRedirectContext(request, {
457
- audience: authContext.audience,
458
- returnTo,
459
- }).returnTo
460
- },
458
+ resolveReturnTo: (request, returnTo) =>
459
+ server.resolveAuthRedirectContext(request, { returnTo }).returnTo,
461
460
  resolveCallbackUrl: (request) =>
462
461
  new URL("/auth/connectors/callback", server.resolveAuthRequestOrigin(request)).toString(),
463
462
  },
@@ -512,14 +511,18 @@ function rejectDisallowedBrowserOrigin(
512
511
  return undefined
513
512
  }
514
513
 
515
- try {
516
- if (isAllowedApiBrowserOrigin(policy, request)) {
517
- return undefined
518
- }
519
- } catch (error) {
520
- if (!(error instanceof BrowserOriginError)) {
521
- throw error
522
- }
514
+ // A frame's page has an opaque origin, so what it loads arrives with `Origin: null`. Its token
515
+ // is the credential and no cookie counts there, so frames are the one place that is allowed, and
516
+ // only to read, as `classifyRoute` makes them public.
517
+ if (
518
+ (request.method === "GET" || request.method === "HEAD") &&
519
+ new URL(request.url).pathname.startsWith(ARTIFACT_FRAME_ROUTE_PREFIX)
520
+ ) {
521
+ return undefined
522
+ }
523
+
524
+ if (isAllowedApiBrowserOrigin(policy, request)) {
525
+ return undefined
523
526
  }
524
527
 
525
528
  return new Response(JSON.stringify({ error: "Browser origin is not allowed" }), {
@@ -1,4 +0,0 @@
1
- import { type AuthSessionAudience, type SixbHostView } from "@sixb/core";
2
- import type { AuthenticatedRequestAuthSession } from "@sixb/core/internal/auth";
3
- export declare function sessionCanAccessApplication(host: SixbHostView, session: AuthenticatedRequestAuthSession, audience: AuthSessionAudience): boolean;
4
- //# sourceMappingURL=application-access.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"application-access.d.ts","sourceRoot":"","sources":["../../src/auth/application-access.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAwB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9F,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,0BAA0B,CAAA;AAE/E,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,+BAA+B,EACxC,QAAQ,EAAE,mBAAmB,GAC5B,OAAO,CAOT"}
@@ -1,15 +0,0 @@
1
- import { type AuthSessionAudience, canAccessApplication, type SixbHostView } from "@sixb/core"
2
- import type { AuthenticatedRequestAuthSession } from "@sixb/core/internal/auth"
3
-
4
- export function sessionCanAccessApplication(
5
- host: SixbHostView,
6
- session: AuthenticatedRequestAuthSession,
7
- audience: AuthSessionAudience
8
- ): boolean {
9
- const authorization = host.auth.contextFromSession(session)
10
- return canAccessApplication(
11
- authorization,
12
- host.definitions.security.listResolvedRoles(),
13
- audience
14
- )
15
- }