@sixb/server 0.1.0 → 0.1.2
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/README.md +3 -3
- package/dist/auth/application-access.d.ts +2 -2
- package/dist/auth/application-access.d.ts.map +1 -1
- package/dist/auth/connector-callback-cookie.d.ts +12 -0
- package/dist/auth/connector-callback-cookie.d.ts.map +1 -0
- package/dist/auth/guard.d.ts +3 -3
- package/dist/auth/guard.d.ts.map +1 -1
- package/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/auth/scope.d.ts +21 -27
- package/dist/auth/scope.d.ts.map +1 -1
- package/dist/auth/session-cookies.d.ts +2 -2
- package/dist/auth/session-cookies.d.ts.map +1 -1
- package/dist/connectors/http.d.ts +16 -0
- package/dist/connectors/http.d.ts.map +1 -0
- package/dist/files/content.d.ts +11 -0
- package/dist/files/content.d.ts.map +1 -1
- package/dist/index.js +4164 -3541
- package/dist/index.js.map +57 -52
- package/dist/openapi/tags.d.ts +11 -3
- package/dist/openapi/tags.d.ts.map +1 -1
- package/dist/registerRoutes.d.ts +6 -2
- package/dist/registerRoutes.d.ts.map +1 -1
- package/dist/routes/action-runs.d.ts +21 -31
- package/dist/routes/action-runs.d.ts.map +1 -1
- package/dist/routes/actions.d.ts +9 -8
- package/dist/routes/actions.d.ts.map +1 -1
- package/dist/routes/agent-api-gateway.d.ts +2 -2
- package/dist/routes/agent-api-gateway.d.ts.map +1 -1
- package/dist/routes/agents.d.ts +130 -131
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/auth.d.ts +90 -90
- package/dist/routes/auth.d.ts.map +1 -1
- package/dist/routes/connector-connection-runs.d.ts +794 -0
- package/dist/routes/connector-connection-runs.d.ts.map +1 -0
- package/dist/routes/connector-connections.d.ts +219 -0
- package/dist/routes/connector-connections.d.ts.map +1 -0
- package/dist/routes/connectors.d.ts +10 -4
- package/dist/routes/connectors.d.ts.map +1 -1
- package/dist/routes/datasets.d.ts +15 -9
- package/dist/routes/datasets.d.ts.map +1 -1
- package/dist/routes/events.d.ts +8 -8
- package/dist/routes/events.d.ts.map +1 -1
- package/dist/routes/files.d.ts +11 -10
- package/dist/routes/files.d.ts.map +1 -1
- package/dist/routes/links.d.ts +2 -2
- package/dist/routes/links.d.ts.map +1 -1
- package/dist/routes/logs.d.ts +5 -5
- package/dist/routes/logs.d.ts.map +1 -1
- package/dist/routes/objects.d.ts +34 -34
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/ontology.d.ts +62 -62
- package/dist/routes/ontology.d.ts.map +1 -1
- package/dist/routes/pipelines.d.ts +28 -34
- package/dist/routes/pipelines.d.ts.map +1 -1
- package/dist/routes/project.d.ts +2 -2
- package/dist/routes/project.d.ts.map +1 -1
- package/dist/routes/projections.d.ts +131 -83
- package/dist/routes/projections.d.ts.map +1 -1
- package/dist/routes/rules.d.ts +6 -6
- package/dist/routes/rules.d.ts.map +1 -1
- package/dist/routes/status.d.ts +2 -2
- package/dist/routes/status.d.ts.map +1 -1
- package/dist/routes/syncs.d.ts +27 -30
- package/dist/routes/syncs.d.ts.map +1 -1
- package/dist/routes/telemetry.d.ts +2 -2
- package/dist/routes/telemetry.d.ts.map +1 -1
- package/dist/routes/webhook-runs.d.ts +9 -9
- package/dist/routes/webhook-runs.d.ts.map +1 -1
- package/dist/routes/webhooks.d.ts +2 -2
- package/dist/routes/webhooks.d.ts.map +1 -1
- package/dist/routes/workflows.d.ts +132 -107
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/routes/ws/agents.d.ts +11 -5
- package/dist/routes/ws/agents.d.ts.map +1 -1
- package/dist/routes/ws/events.d.ts +8 -8
- package/dist/routes/ws/events.d.ts.map +1 -1
- package/dist/routes/ws/log-subscription-hub.d.ts +6 -3
- package/dist/routes/ws/log-subscription-hub.d.ts.map +1 -1
- package/dist/routes/ws/logs.d.ts +10 -10
- package/dist/routes/ws/logs.d.ts.map +1 -1
- package/dist/schemas/actions.d.ts +97 -202
- package/dist/schemas/actions.d.ts.map +1 -1
- package/dist/schemas/agents.d.ts +443 -440
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-usage.d.ts +34 -0
- package/dist/schemas/ai-usage.d.ts.map +1 -0
- package/dist/schemas/auth.d.ts +168 -168
- package/dist/schemas/common.d.ts +37 -0
- package/dist/schemas/common.d.ts.map +1 -1
- package/dist/schemas/connectors.d.ts +713 -2
- package/dist/schemas/connectors.d.ts.map +1 -1
- package/dist/schemas/datasets.d.ts +29 -23
- package/dist/schemas/datasets.d.ts.map +1 -1
- package/dist/schemas/event-payloads.d.ts +6 -6
- package/dist/schemas/events.d.ts +34 -34
- package/dist/schemas/logs.d.ts +22 -22
- package/dist/schemas/objects.d.ts +10 -10
- package/dist/schemas/ontology.d.ts +174 -174
- package/dist/schemas/pipelines.d.ts +131 -190
- package/dist/schemas/pipelines.d.ts.map +1 -1
- package/dist/schemas/projections.d.ts +918 -563
- package/dist/schemas/projections.d.ts.map +1 -1
- package/dist/schemas/rules.d.ts +6 -6
- package/dist/schemas/status.d.ts +2 -2
- package/dist/schemas/syncs.d.ts +88 -124
- package/dist/schemas/syncs.d.ts.map +1 -1
- package/dist/schemas/webhook-runs.d.ts +41 -41
- package/dist/schemas/webhook-runs.d.ts.map +1 -1
- package/dist/schemas/workflows.d.ts +792 -406
- package/dist/schemas/workflows.d.ts.map +1 -1
- package/dist/server.d.ts +6 -6
- package/dist/server.d.ts.map +1 -1
- package/dist/utils/http.d.ts +2 -0
- package/dist/utils/http.d.ts.map +1 -1
- package/dist/utils/ws.d.ts +4 -3
- package/dist/utils/ws.d.ts.map +1 -1
- package/package.json +8 -5
- package/src/auth/access-token-boundary.ts +4 -4
- package/src/auth/application-access.ts +8 -9
- package/src/auth/connector-callback-cookie.ts +95 -0
- package/src/auth/guard.ts +11 -11
- package/src/auth/public-routes.ts +13 -0
- package/src/auth/scope.ts +34 -30
- package/src/auth/session-cookies.ts +3 -3
- package/src/connectors/http.ts +110 -0
- package/src/files/content.ts +11 -0
- package/src/openapi/tags.ts +9 -1
- package/src/registerRoutes.ts +34 -23
- package/src/routes/action-runs.ts +49 -42
- package/src/routes/actions.ts +7 -13
- package/src/routes/agent-api-gateway.ts +87 -42
- package/src/routes/agents.ts +89 -200
- package/src/routes/auth.ts +87 -91
- package/src/routes/connector-connection-runs.ts +346 -0
- package/src/routes/connector-connections.ts +135 -0
- package/src/routes/connectors.ts +24 -12
- package/src/routes/datasets.ts +55 -54
- package/src/routes/events.ts +5 -5
- package/src/routes/files.ts +24 -31
- package/src/routes/links.ts +32 -35
- package/src/routes/logs.ts +6 -11
- package/src/routes/objects.ts +51 -114
- package/src/routes/ontology.ts +27 -38
- package/src/routes/pipelines.ts +28 -62
- package/src/routes/project.ts +3 -3
- package/src/routes/projections.ts +26 -38
- package/src/routes/rules.ts +11 -25
- package/src/routes/status.ts +5 -5
- package/src/routes/syncs.ts +19 -45
- package/src/routes/telemetry.ts +18 -29
- package/src/routes/webhook-runs.ts +5 -5
- package/src/routes/webhooks.ts +259 -341
- package/src/routes/workflows.ts +260 -259
- package/src/routes/ws/agents.ts +196 -66
- package/src/routes/ws/events.ts +11 -10
- package/src/routes/ws/log-subscription-hub.ts +6 -12
- package/src/routes/ws/logs.ts +13 -5
- package/src/schemas/actions.ts +58 -25
- package/src/schemas/agents.ts +19 -14
- package/src/schemas/ai-usage.ts +16 -0
- package/src/schemas/common.ts +24 -0
- package/src/schemas/connectors.ts +164 -0
- package/src/schemas/datasets.ts +3 -2
- package/src/schemas/pipelines.ts +24 -40
- package/src/schemas/projections.ts +17 -3
- package/src/schemas/syncs.ts +16 -10
- package/src/schemas/webhook-runs.ts +10 -5
- package/src/schemas/workflows.ts +42 -25
- package/src/server.ts +65 -26
- package/src/utils/http.ts +34 -6
- package/src/utils/ws.ts +10 -5
package/src/routes/objects.ts
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthorizationError,
|
|
3
|
-
isAllowed,
|
|
4
3
|
type ObjectQuery,
|
|
5
4
|
ObjectQueryExecutionError,
|
|
6
5
|
ObjectQueryPlanningError,
|
|
7
6
|
ObjectQueryValidationError,
|
|
8
7
|
type ObjectRef,
|
|
9
|
-
type
|
|
10
|
-
type Sixb,
|
|
8
|
+
type SixbHostView,
|
|
11
9
|
} from "@sixb/core"
|
|
12
|
-
import {
|
|
13
|
-
countObjects,
|
|
14
|
-
executeObjectQuery,
|
|
15
|
-
existsObjects,
|
|
16
|
-
facetObjects,
|
|
17
|
-
} from "@sixb/core/internal/query"
|
|
18
10
|
import type {
|
|
19
11
|
ExpandedLinkValue,
|
|
20
12
|
ExpandedObjectRow,
|
|
@@ -24,7 +16,7 @@ import type {
|
|
|
24
16
|
import type { Elysia } from "elysia"
|
|
25
17
|
import { ZodError, z } from "zod"
|
|
26
18
|
import { bearerSecurityRequirement } from "../auth/access-token-boundary"
|
|
27
|
-
import {
|
|
19
|
+
import { requireRequestSixb } from "../auth/scope"
|
|
28
20
|
import {
|
|
29
21
|
createContextualFileContentResponse,
|
|
30
22
|
fileContentGetResponses,
|
|
@@ -106,7 +98,13 @@ function serializeLinkValue(value: ExpandedLinkValue): SerializedLinkValue {
|
|
|
106
98
|
return serializeExpandedObject(value as ExpandedObjectRow)
|
|
107
99
|
}
|
|
108
100
|
|
|
109
|
-
function serializePlan(plan:
|
|
101
|
+
function serializePlan(plan: {
|
|
102
|
+
readonly mode: string
|
|
103
|
+
readonly providerIssues: readonly unknown[]
|
|
104
|
+
readonly fallbackIssues: readonly unknown[]
|
|
105
|
+
readonly issues: readonly unknown[]
|
|
106
|
+
readonly fallback?: { readonly maxRows: number; readonly requiresExplicitBound: boolean }
|
|
107
|
+
}) {
|
|
110
108
|
return {
|
|
111
109
|
mode: plan.mode,
|
|
112
110
|
providerIssues: plan.providerIssues,
|
|
@@ -171,19 +169,10 @@ function formatZodIssuePath(path: readonly (string | number)[]): string {
|
|
|
171
169
|
}
|
|
172
170
|
|
|
173
171
|
async function getObjectRow(
|
|
174
|
-
sixb:
|
|
175
|
-
scoped: ReturnType<typeof requestAuthState>["scoped"],
|
|
172
|
+
sixb: ReturnType<typeof requireRequestSixb>,
|
|
176
173
|
params: { objectTypeId: string; objectId: string }
|
|
177
174
|
) {
|
|
178
|
-
|
|
179
|
-
return scoped.getObject(params.objectTypeId, params.objectId)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return sixb.storage.objects.getByPrimaryId({
|
|
183
|
-
projectId: sixb.id,
|
|
184
|
-
objectTypeId: params.objectTypeId,
|
|
185
|
-
primaryId: params.objectId,
|
|
186
|
-
})
|
|
175
|
+
return sixb.objects.get(params.objectTypeId, params.objectId)
|
|
187
176
|
}
|
|
188
177
|
|
|
189
178
|
interface ObjectSearchItem {
|
|
@@ -192,34 +181,27 @@ interface ObjectSearchItem {
|
|
|
192
181
|
}
|
|
193
182
|
|
|
194
183
|
async function searchObjects(
|
|
195
|
-
|
|
196
|
-
|
|
184
|
+
host: SixbHostView,
|
|
185
|
+
sixb: ReturnType<typeof requireRequestSixb>,
|
|
197
186
|
query: string,
|
|
198
187
|
limit: number
|
|
199
188
|
): Promise<readonly ObjectSearchItem[]> {
|
|
200
189
|
// Primary ids are available on every object store and form the reliable fallback. Scoped.list()
|
|
201
190
|
// narrows broad searches to viewable types before storage, rather than filtering rows afterwards.
|
|
202
|
-
const primaryMatches = await (
|
|
203
|
-
? authState.scoped.list({ idPrefix: query, limit })
|
|
204
|
-
: sixb.list({ idPrefix: query, limit }))
|
|
191
|
+
const primaryMatches = await sixb.objects.list({ idPrefix: query, limit })
|
|
205
192
|
|
|
206
|
-
const capabilities =
|
|
193
|
+
const capabilities = host.storage.objects.queryCapabilities()
|
|
207
194
|
const supportsTextSearch =
|
|
208
195
|
capabilities.queryObjects === true &&
|
|
209
196
|
capabilities.nodes?.start === true &&
|
|
210
197
|
capabilities.nodes?.text === true &&
|
|
211
198
|
capabilities.nodes?.limit === true &&
|
|
212
|
-
typeof
|
|
199
|
+
typeof host.storage.objects.queryObjects === "function"
|
|
213
200
|
|
|
214
201
|
const searchableTypes = supportsTextSearch
|
|
215
|
-
? sixb.
|
|
216
|
-
(
|
|
217
|
-
|
|
218
|
-
isAllowed(authState.authz, {
|
|
219
|
-
kind: "object.view",
|
|
220
|
-
objectTypeId: objectType.id,
|
|
221
|
-
})
|
|
222
|
-
)
|
|
202
|
+
? sixb.objects
|
|
203
|
+
.listTypes()
|
|
204
|
+
.filter((objectType) => Boolean(objectType.search?.defaultText?.length))
|
|
223
205
|
: []
|
|
224
206
|
|
|
225
207
|
const textMatches = await Promise.all(
|
|
@@ -233,14 +215,7 @@ async function searchObjects(
|
|
|
233
215
|
input: { kind: "start", objectTypeId: objectType.id },
|
|
234
216
|
},
|
|
235
217
|
}
|
|
236
|
-
const result = await
|
|
237
|
-
{ projectId: sixb.id, query: objectQuery },
|
|
238
|
-
{
|
|
239
|
-
ontology: sixb.ontology,
|
|
240
|
-
storage: sixb.storage.objects,
|
|
241
|
-
authorization: authState.authz ?? undefined,
|
|
242
|
-
}
|
|
243
|
-
)
|
|
218
|
+
const result = await sixb.objects.executeQuery({ query: objectQuery })
|
|
244
219
|
return result.objects
|
|
245
220
|
})
|
|
246
221
|
)
|
|
@@ -256,8 +231,8 @@ async function searchObjects(
|
|
|
256
231
|
return [...items.values()]
|
|
257
232
|
}
|
|
258
233
|
|
|
259
|
-
function objectSearchLabel(sixb:
|
|
260
|
-
const objectType = sixb.
|
|
234
|
+
function objectSearchLabel(sixb: ReturnType<typeof requireRequestSixb>, row: ObjectRow): string {
|
|
235
|
+
const objectType = sixb.objects.resolveType(row.objectTypeId)
|
|
261
236
|
const titlePropertyId = objectType.search?.title
|
|
262
237
|
const title = titlePropertyId ? row.properties[titlePropertyId] : undefined
|
|
263
238
|
const displayTitle =
|
|
@@ -272,7 +247,7 @@ function objectRefIdentity(ref: ObjectRef): string {
|
|
|
272
247
|
}
|
|
273
248
|
|
|
274
249
|
async function objectFileContentResponse(
|
|
275
|
-
|
|
250
|
+
host: SixbHostView,
|
|
276
251
|
context: {
|
|
277
252
|
readonly params: { readonly objectTypeId: string; readonly objectId: string }
|
|
278
253
|
readonly query: unknown
|
|
@@ -281,10 +256,10 @@ async function objectFileContentResponse(
|
|
|
281
256
|
},
|
|
282
257
|
options: { readonly head?: boolean } = {}
|
|
283
258
|
) {
|
|
284
|
-
const
|
|
259
|
+
const sixb = requireRequestSixb(context)
|
|
285
260
|
|
|
286
261
|
return createContextualFileContentResponse({
|
|
287
|
-
blobStorage:
|
|
262
|
+
blobStorage: host.blobStorage,
|
|
288
263
|
query: context.query,
|
|
289
264
|
querySchema: ObjectFileContentQuerySchema,
|
|
290
265
|
request: context.request,
|
|
@@ -292,7 +267,7 @@ async function objectFileContentResponse(
|
|
|
292
267
|
head: options.head,
|
|
293
268
|
hideError: (error) => error instanceof AuthorizationError,
|
|
294
269
|
resolveRoot: async () => {
|
|
295
|
-
const row = await getObjectRow(sixb,
|
|
270
|
+
const row = await getObjectRow(sixb, context.params)
|
|
296
271
|
if (!row) {
|
|
297
272
|
return null
|
|
298
273
|
}
|
|
@@ -302,7 +277,7 @@ async function objectFileContentResponse(
|
|
|
302
277
|
})
|
|
303
278
|
}
|
|
304
279
|
|
|
305
|
-
export function registerObjectRoutes(app: Elysia,
|
|
280
|
+
export function registerObjectRoutes(app: Elysia, host: SixbHostView) {
|
|
306
281
|
return app
|
|
307
282
|
.get(
|
|
308
283
|
"/api/objects/search",
|
|
@@ -315,7 +290,7 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
|
|
|
315
290
|
set.status = 400
|
|
316
291
|
return { error: "Object search limit must be positive" }
|
|
317
292
|
}
|
|
318
|
-
const items = await searchObjects(
|
|
293
|
+
const items = await searchObjects(host, requireRequestSixb(context), parsed.q, limit)
|
|
319
294
|
return ObjectSearchResponseSchema.parse({ items })
|
|
320
295
|
} catch (error) {
|
|
321
296
|
return handleObjectQueryError(error, set)
|
|
@@ -340,7 +315,7 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
|
|
|
340
315
|
"/api/objects",
|
|
341
316
|
async (context) => {
|
|
342
317
|
const { query, set } = context
|
|
343
|
-
const
|
|
318
|
+
const sixb = requireRequestSixb(context)
|
|
344
319
|
|
|
345
320
|
try {
|
|
346
321
|
const params = {
|
|
@@ -356,7 +331,7 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
|
|
|
356
331
|
orderBy: query.orderBy,
|
|
357
332
|
order: query.order,
|
|
358
333
|
}
|
|
359
|
-
const result =
|
|
334
|
+
const result = await sixb.objects.list(params)
|
|
360
335
|
|
|
361
336
|
return {
|
|
362
337
|
objects: result.objects.map(serializeObject),
|
|
@@ -403,18 +378,10 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
|
|
|
403
378
|
query: ObjectQuery
|
|
404
379
|
includeTotal?: boolean
|
|
405
380
|
}
|
|
406
|
-
const result = await
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
includeTotal: parsed.includeTotal,
|
|
411
|
-
},
|
|
412
|
-
{
|
|
413
|
-
ontology: sixb.ontology,
|
|
414
|
-
storage: sixb.storage.objects,
|
|
415
|
-
authorization: requestAuthState(context).authz ?? undefined,
|
|
416
|
-
}
|
|
417
|
-
)
|
|
381
|
+
const result = await requireRequestSixb(context).objects.executeQuery({
|
|
382
|
+
query: parsed.query,
|
|
383
|
+
includeTotal: parsed.includeTotal,
|
|
384
|
+
})
|
|
418
385
|
|
|
419
386
|
return {
|
|
420
387
|
objects: result.objects.map(serializeExpandedObject),
|
|
@@ -486,17 +453,7 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
|
|
|
486
453
|
const parsed = ObjectQueryCountRequestSchema.parse(body) as {
|
|
487
454
|
query: ObjectQuery
|
|
488
455
|
}
|
|
489
|
-
const result = await
|
|
490
|
-
{
|
|
491
|
-
projectId: sixb.id,
|
|
492
|
-
query: parsed.query,
|
|
493
|
-
},
|
|
494
|
-
{
|
|
495
|
-
ontology: sixb.ontology,
|
|
496
|
-
storage: sixb.storage.objects,
|
|
497
|
-
authorization: requestAuthState(context).authz ?? undefined,
|
|
498
|
-
}
|
|
499
|
-
)
|
|
456
|
+
const result = await requireRequestSixb(context).objects.count({ query: parsed.query })
|
|
500
457
|
|
|
501
458
|
return {
|
|
502
459
|
count: result.count,
|
|
@@ -565,17 +522,7 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
|
|
|
565
522
|
const parsed = ObjectQueryExistsRequestSchema.parse(body) as {
|
|
566
523
|
query: ObjectQuery
|
|
567
524
|
}
|
|
568
|
-
const result = await
|
|
569
|
-
{
|
|
570
|
-
projectId: sixb.id,
|
|
571
|
-
query: parsed.query,
|
|
572
|
-
},
|
|
573
|
-
{
|
|
574
|
-
ontology: sixb.ontology,
|
|
575
|
-
storage: sixb.storage.objects,
|
|
576
|
-
authorization: requestAuthState(context).authz ?? undefined,
|
|
577
|
-
}
|
|
578
|
-
)
|
|
525
|
+
const result = await requireRequestSixb(context).objects.exists({ query: parsed.query })
|
|
579
526
|
|
|
580
527
|
return {
|
|
581
528
|
exists: result.exists,
|
|
@@ -645,18 +592,10 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
|
|
|
645
592
|
query: ObjectQuery
|
|
646
593
|
facets: { propertyId: string; limit: number }[]
|
|
647
594
|
}
|
|
648
|
-
const result = await
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
facets: parsed.facets,
|
|
653
|
-
},
|
|
654
|
-
{
|
|
655
|
-
ontology: sixb.ontology,
|
|
656
|
-
storage: sixb.storage.objects,
|
|
657
|
-
authorization: requestAuthState(context).authz ?? undefined,
|
|
658
|
-
}
|
|
659
|
-
)
|
|
595
|
+
const result = await requireRequestSixb(context).objects.facet({
|
|
596
|
+
query: parsed.query,
|
|
597
|
+
facets: parsed.facets,
|
|
598
|
+
})
|
|
660
599
|
|
|
661
600
|
return {
|
|
662
601
|
facets: result.facets,
|
|
@@ -719,7 +658,7 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
|
|
|
719
658
|
)
|
|
720
659
|
.get(
|
|
721
660
|
"/api/objects/:objectTypeId/:objectId/files/content",
|
|
722
|
-
(context) => objectFileContentResponse(
|
|
661
|
+
(context) => objectFileContentResponse(host, context),
|
|
723
662
|
{
|
|
724
663
|
params: ObjectParamsSchema,
|
|
725
664
|
// Register the loose query so framework validation only requires `path`;
|
|
@@ -742,7 +681,7 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
|
|
|
742
681
|
)
|
|
743
682
|
.head(
|
|
744
683
|
"/api/objects/:objectTypeId/:objectId/files/content",
|
|
745
|
-
(context) => objectFileContentResponse(
|
|
684
|
+
(context) => objectFileContentResponse(host, context, { head: true }),
|
|
746
685
|
{
|
|
747
686
|
params: ObjectParamsSchema,
|
|
748
687
|
// See the GET route: register the loose query so the handler owns the
|
|
@@ -763,10 +702,10 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
|
|
|
763
702
|
"/api/objects/:objectTypeId/:objectId",
|
|
764
703
|
async (context) => {
|
|
765
704
|
const { params, set } = context
|
|
766
|
-
const
|
|
705
|
+
const sixb = requireRequestSixb(context)
|
|
767
706
|
|
|
768
707
|
try {
|
|
769
|
-
const row = await getObjectRow(sixb,
|
|
708
|
+
const row = await getObjectRow(sixb, params)
|
|
770
709
|
if (!row) {
|
|
771
710
|
set.status = 404
|
|
772
711
|
return { error: "Object not found" }
|
|
@@ -798,18 +737,16 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
|
|
|
798
737
|
"/api/objects/:objectTypeId/:objectId",
|
|
799
738
|
async (context) => {
|
|
800
739
|
const { params, body, set } = context
|
|
801
|
-
const
|
|
740
|
+
const sixb = requireRequestSixb(context)
|
|
802
741
|
try {
|
|
803
742
|
const parsedBody = UpsertObjectBodySchema.parse(body)
|
|
804
|
-
//
|
|
805
|
-
//
|
|
806
|
-
//
|
|
807
|
-
//
|
|
808
|
-
|
|
809
|
-
const runtime = scoped ?? sixb
|
|
810
|
-
const primaryPropertyId = runtime.getPrimaryPropertyId(params.objectTypeId)
|
|
743
|
+
// The same bound SDK performs the primary-property lookup and the write. Otherwise an
|
|
744
|
+
// ambient host lookup could answer 404 for an unregistered type before the principal's
|
|
745
|
+
// grant is checked, distinguishing it from a registered but ungranted type (403) and
|
|
746
|
+
// leaking the type universe that `listObjectTypes` filters out.
|
|
747
|
+
const primaryPropertyId = sixb.objects.getPrimaryPropertyId(params.objectTypeId)
|
|
811
748
|
const properties = { ...parsedBody.properties, [primaryPropertyId]: params.objectId }
|
|
812
|
-
const object = await
|
|
749
|
+
const object = await sixb.objects.upsert(params.objectTypeId, properties)
|
|
813
750
|
return serializeObject(object)
|
|
814
751
|
} catch (error) {
|
|
815
752
|
// Was a local catch mapping every error to 404/400, which turned a missing grant into
|
package/src/routes/ontology.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { OntologySource, SixbHostView } from "@sixb/core"
|
|
2
|
+
import type { Sixb } from "@sixb/core/internal/request-execution"
|
|
2
3
|
import type { Elysia } from "elysia"
|
|
3
4
|
import { bearerSecurityRequirement } from "../auth/access-token-boundary"
|
|
4
|
-
import {
|
|
5
|
+
import { requireRequestSixb } from "../auth/scope"
|
|
5
6
|
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
6
7
|
import { ErrorResponseSchema } from "../schemas/common"
|
|
7
8
|
import { ObjectTypeParamsSchema, ObjectTypeSchema } from "../schemas/ontology"
|
|
8
9
|
|
|
9
10
|
function serializeProperty(
|
|
10
11
|
property: ReturnType<
|
|
11
|
-
|
|
12
|
+
SixbHostView["definitions"]["ontology"]["listObjectTypes"]
|
|
12
13
|
>[number]["properties"][number]
|
|
13
14
|
) {
|
|
14
15
|
return {
|
|
@@ -26,7 +27,7 @@ function serializeProperty(
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
function serializeSearch(
|
|
29
|
-
search: ReturnType<
|
|
30
|
+
search: ReturnType<SixbHostView["definitions"]["ontology"]["listObjectTypes"]>[number]["search"]
|
|
30
31
|
) {
|
|
31
32
|
if (!search) return undefined
|
|
32
33
|
return {
|
|
@@ -43,9 +44,8 @@ function serializeSearch(
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
function serializeObjectType(
|
|
46
|
-
|
|
47
|
-
objectType: ReturnType<
|
|
48
|
-
authorization: AuthorizationContext | null
|
|
47
|
+
execution: Sixb<readonly OntologySource[]>,
|
|
48
|
+
objectType: ReturnType<SixbHostView["definitions"]["ontology"]["listObjectTypes"]>[number]
|
|
49
49
|
) {
|
|
50
50
|
return {
|
|
51
51
|
id: objectType.id,
|
|
@@ -65,38 +65,30 @@ function serializeObjectType(
|
|
|
65
65
|
cardinality: link.cardinality,
|
|
66
66
|
properties: link.properties?.map(serializeProperty),
|
|
67
67
|
})),
|
|
68
|
-
actions:
|
|
69
|
-
.
|
|
70
|
-
|
|
71
|
-
.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
nullable: config.nullable,
|
|
81
|
-
description: config.description,
|
|
82
|
-
semanticType: config.semanticType,
|
|
83
|
-
})),
|
|
68
|
+
actions: execution.actions.listForType(objectType).map((action) => ({
|
|
69
|
+
id: action.id,
|
|
70
|
+
name: action.id,
|
|
71
|
+
description: action.description,
|
|
72
|
+
params: Object.entries(action.params).map(([id, config]) => ({
|
|
73
|
+
id,
|
|
74
|
+
name: id,
|
|
75
|
+
schema: config.schema,
|
|
76
|
+
required: config.required ?? false,
|
|
77
|
+
nullable: config.nullable,
|
|
78
|
+
description: config.description,
|
|
79
|
+
semanticType: config.semanticType,
|
|
84
80
|
})),
|
|
81
|
+
})),
|
|
85
82
|
}
|
|
86
83
|
}
|
|
87
84
|
|
|
88
|
-
export function registerOntologyRoutes(app: Elysia,
|
|
85
|
+
export function registerOntologyRoutes(app: Elysia, _host: SixbHostView) {
|
|
89
86
|
return app
|
|
90
87
|
.get(
|
|
91
88
|
"/api/object-types",
|
|
92
89
|
async (context) => {
|
|
93
|
-
const
|
|
94
|
-
return sixb
|
|
95
|
-
.listObjectTypes()
|
|
96
|
-
.filter((objectType) =>
|
|
97
|
-
isAllowed(authz, { kind: "object.view", objectTypeId: objectType.id })
|
|
98
|
-
)
|
|
99
|
-
.map((objectType) => serializeObjectType(sixb, objectType, authz))
|
|
90
|
+
const sixb = requireRequestSixb(context)
|
|
91
|
+
return sixb.objects.listTypes().map((objectType) => serializeObjectType(sixb, objectType))
|
|
100
92
|
},
|
|
101
93
|
{
|
|
102
94
|
response: { 200: ObjectTypeSchema.array() },
|
|
@@ -112,17 +104,14 @@ export function registerOntologyRoutes(app: Elysia, sixb: Sixb<readonly Ontology
|
|
|
112
104
|
"/api/object-types/:objectTypeId",
|
|
113
105
|
async (context) => {
|
|
114
106
|
const { params, set } = context
|
|
115
|
-
const
|
|
116
|
-
const objectType = sixb.
|
|
117
|
-
if (
|
|
118
|
-
!objectType ||
|
|
119
|
-
!isAllowed(authz, { kind: "object.view", objectTypeId: objectType.id })
|
|
120
|
-
) {
|
|
107
|
+
const sixb = requireRequestSixb(context)
|
|
108
|
+
const objectType = sixb.objects.getTypeById(params.objectTypeId)
|
|
109
|
+
if (!objectType) {
|
|
121
110
|
set.status = 404
|
|
122
111
|
return { error: "Object type not found" }
|
|
123
112
|
}
|
|
124
113
|
|
|
125
|
-
return serializeObjectType(sixb, objectType
|
|
114
|
+
return serializeObjectType(sixb, objectType)
|
|
126
115
|
},
|
|
127
116
|
{
|
|
128
117
|
params: ObjectTypeParamsSchema,
|
package/src/routes/pipelines.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { canViewPipelineRun } from "@sixb/core/internal/authorization"
|
|
1
|
+
import type { PipelineDefinition, PipelineStepExecutor, SixbHostView } from "@sixb/core"
|
|
3
2
|
import type { PipelineRunRecord, PipelineStepRunRecord } from "@sixb/core/storage"
|
|
4
3
|
import type { Elysia } from "elysia"
|
|
5
|
-
import {
|
|
4
|
+
import { requireRequestSixb } from "../auth/scope"
|
|
6
5
|
import { SIXB_CSRF_SECURITY_REQUIREMENT } from "../openapi/security"
|
|
7
6
|
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
8
7
|
import { ErrorResponseSchema } from "../schemas/common"
|
|
@@ -29,7 +28,8 @@ function serializePipelineRun(run: PipelineRunRecord) {
|
|
|
29
28
|
projectId: run.projectId,
|
|
30
29
|
pipelineId: run.pipelineId,
|
|
31
30
|
status: run.status,
|
|
32
|
-
|
|
31
|
+
queuedAt: toIsoString(run.queuedAt),
|
|
32
|
+
startedAt: run.startedAt ? toIsoString(run.startedAt) : undefined,
|
|
33
33
|
finishedAt: run.finishedAt ? toIsoString(run.finishedAt) : undefined,
|
|
34
34
|
output: run.output,
|
|
35
35
|
error: run.error,
|
|
@@ -72,36 +72,24 @@ function serializeExecutor(executor: PipelineStepExecutor) {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
async function getLatestPipelineRun(
|
|
75
|
-
sixb:
|
|
75
|
+
sixb: ReturnType<typeof requireRequestSixb>,
|
|
76
76
|
pipelineId: string
|
|
77
77
|
): Promise<SerializedPipelineRun | null> {
|
|
78
|
-
|
|
79
|
-
return null
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const storage = sixb.storage.pipelineRuns
|
|
83
|
-
const result = await storage.listLatestByPipelineIds({
|
|
84
|
-
projectId: sixb.id,
|
|
85
|
-
pipelineIds: [pipelineId],
|
|
86
|
-
})
|
|
78
|
+
const result = await sixb.pipelines.runs.listLatest([pipelineId])
|
|
87
79
|
|
|
88
80
|
const [latest] = result.runs
|
|
89
81
|
return latest ? serializePipelineRun(latest) : null
|
|
90
82
|
}
|
|
91
83
|
|
|
92
84
|
async function getLatestPipelineRuns(
|
|
93
|
-
sixb:
|
|
85
|
+
sixb: ReturnType<typeof requireRequestSixb>,
|
|
94
86
|
pipelineIds: readonly string[]
|
|
95
87
|
): Promise<Map<string, SerializedPipelineRun>> {
|
|
96
|
-
|
|
97
|
-
if (!storage || pipelineIds.length === 0) {
|
|
88
|
+
if (pipelineIds.length === 0) {
|
|
98
89
|
return new Map()
|
|
99
90
|
}
|
|
100
91
|
|
|
101
|
-
const result = await
|
|
102
|
-
projectId: sixb.id,
|
|
103
|
-
pipelineIds,
|
|
104
|
-
})
|
|
92
|
+
const result = await sixb.pipelines.runs.listLatest(pipelineIds)
|
|
105
93
|
|
|
106
94
|
return new Map(result.runs.map((run) => [run.pipelineId, serializePipelineRun(run)]))
|
|
107
95
|
}
|
|
@@ -133,13 +121,13 @@ function serializePipeline(
|
|
|
133
121
|
})
|
|
134
122
|
}
|
|
135
123
|
|
|
136
|
-
export function registerPipelineRoutes(app: Elysia,
|
|
124
|
+
export function registerPipelineRoutes(app: Elysia, host: SixbHostView) {
|
|
137
125
|
return app
|
|
138
126
|
.get(
|
|
139
127
|
"/api/pipelines",
|
|
140
128
|
async (context) => {
|
|
141
|
-
const
|
|
142
|
-
const pipelines =
|
|
129
|
+
const sixb = requireRequestSixb(context)
|
|
130
|
+
const pipelines = sixb.pipelines.list()
|
|
143
131
|
const latestRuns = await getLatestPipelineRuns(
|
|
144
132
|
sixb,
|
|
145
133
|
pipelines.map((pipeline) => pipeline.id)
|
|
@@ -162,10 +150,8 @@ export function registerPipelineRoutes(app: Elysia, sixb: Sixb<readonly Ontology
|
|
|
162
150
|
"/api/pipelines/:pipelineId",
|
|
163
151
|
async (context) => {
|
|
164
152
|
const { params, set } = context
|
|
165
|
-
const
|
|
166
|
-
const pipeline =
|
|
167
|
-
? scoped.getPipelineById(params.pipelineId)
|
|
168
|
-
: sixb.getPipelineById(params.pipelineId)
|
|
153
|
+
const sixb = requireRequestSixb(context)
|
|
154
|
+
const pipeline = sixb.pipelines.getById(params.pipelineId)
|
|
169
155
|
if (!pipeline) {
|
|
170
156
|
set.status = 404
|
|
171
157
|
return { error: "Pipeline not found" }
|
|
@@ -187,23 +173,16 @@ export function registerPipelineRoutes(app: Elysia, sixb: Sixb<readonly Ontology
|
|
|
187
173
|
"/api/pipeline-runs",
|
|
188
174
|
async (context) => {
|
|
189
175
|
const { query, set } = context
|
|
190
|
-
const
|
|
176
|
+
const sixb = requireRequestSixb(context)
|
|
191
177
|
try {
|
|
192
178
|
const parsed = PipelineRunsQuerySchema.parse(query)
|
|
193
|
-
const storage =
|
|
179
|
+
const storage = host.storage.pipelineRuns
|
|
194
180
|
if (!storage) {
|
|
195
181
|
return unconfiguredStorageResponse(set, "Pipeline run storage")
|
|
196
182
|
}
|
|
197
183
|
|
|
198
|
-
|
|
199
|
-
// pass the grant allowlist alongside any explicit pipelineId and let
|
|
200
|
-
// storage AND them. An ungranted pipelineId yields an empty
|
|
201
|
-
// intersection, and an empty allowlist short-circuits to no rows.
|
|
202
|
-
const pipelineIds = authz ? [...authz.grants["run:pipeline"]] : undefined
|
|
203
|
-
const result = await storage.list({
|
|
204
|
-
projectId: sixb.id,
|
|
184
|
+
const result = await sixb.pipelines.runs.list({
|
|
205
185
|
pipelineId: parsed.pipelineId,
|
|
206
|
-
pipelineIds,
|
|
207
186
|
statuses: parsed.status ? [parsed.status] : undefined,
|
|
208
187
|
startedAfter: parseDate(parsed.startedAfter),
|
|
209
188
|
startedBefore: parseDate(parsed.startedBefore),
|
|
@@ -239,29 +218,24 @@ export function registerPipelineRoutes(app: Elysia, sixb: Sixb<readonly Ontology
|
|
|
239
218
|
"/api/pipeline-runs/:runId",
|
|
240
219
|
async (context) => {
|
|
241
220
|
const { params, set } = context
|
|
242
|
-
const
|
|
221
|
+
const sixb = requireRequestSixb(context)
|
|
243
222
|
try {
|
|
244
|
-
const storage =
|
|
223
|
+
const storage = host.storage.pipelineRuns
|
|
245
224
|
if (!storage) {
|
|
246
225
|
return unconfiguredStorageResponse(set, "Pipeline run storage")
|
|
247
226
|
}
|
|
248
227
|
|
|
249
|
-
const run = await
|
|
250
|
-
|
|
251
|
-
id: params.runId,
|
|
252
|
-
})
|
|
253
|
-
// A run the principal cannot run is hidden as 404, never surfaced as a
|
|
254
|
-
// distinct 403, mirroring the catalog and run-history routes.
|
|
255
|
-
if (!run || !canViewPipelineRun(authz, run)) {
|
|
228
|
+
const run = await sixb.pipelines.runs.getById(params.runId)
|
|
229
|
+
if (!run) {
|
|
256
230
|
set.status = 404
|
|
257
231
|
return { error: "Pipeline run not found" }
|
|
258
232
|
}
|
|
259
233
|
|
|
260
|
-
const steps = await
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
234
|
+
const steps = await sixb.pipelines.runs.listSteps(run.id, { order: "asc" })
|
|
235
|
+
if (!steps) {
|
|
236
|
+
set.status = 404
|
|
237
|
+
return { error: "Pipeline run not found" }
|
|
238
|
+
}
|
|
265
239
|
|
|
266
240
|
return PipelineRunDetailResponseSchema.parse({
|
|
267
241
|
run: serializePipelineRun(run),
|
|
@@ -290,17 +264,9 @@ export function registerPipelineRoutes(app: Elysia, sixb: Sixb<readonly Ontology
|
|
|
290
264
|
"/api/pipelines/:pipelineId/runs",
|
|
291
265
|
async (context) => {
|
|
292
266
|
const { params, set } = context
|
|
293
|
-
const
|
|
267
|
+
const sixb = requireRequestSixb(context)
|
|
294
268
|
try {
|
|
295
|
-
const
|
|
296
|
-
if (!pipeline) {
|
|
297
|
-
set.status = 404
|
|
298
|
-
return { error: "Pipeline not found" }
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
const result = scoped
|
|
302
|
-
? await scoped.requestPipelineRun({ pipelineId: pipeline.id })
|
|
303
|
-
: await sixb.requestPipelineRun({ pipelineId: pipeline.id })
|
|
269
|
+
const result = await sixb.pipelines.request({ pipelineId: params.pipelineId })
|
|
304
270
|
|
|
305
271
|
set.status = 202
|
|
306
272
|
return {
|
package/src/routes/project.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SixbHostView } from "@sixb/core"
|
|
2
2
|
import type { Elysia } from "elysia"
|
|
3
3
|
import { bearerSecurityRequirement } from "../auth/access-token-boundary"
|
|
4
4
|
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
5
5
|
import { ProjectInfoResponseSchema } from "../schemas/project"
|
|
6
|
-
export function registerProjectRoutes(app: Elysia,
|
|
7
|
-
return app.get("/api/project", async () => ({ id:
|
|
6
|
+
export function registerProjectRoutes(app: Elysia, host: SixbHostView) {
|
|
7
|
+
return app.get("/api/project", async () => ({ id: host.id }), {
|
|
8
8
|
response: { 200: ProjectInfoResponseSchema },
|
|
9
9
|
detail: {
|
|
10
10
|
summary: "Get current project metadata",
|