@sixb/server 0.0.1
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/LICENSE +21 -0
- package/README.md +123 -0
- package/dist/auth/access-token-boundary.d.ts +23 -0
- package/dist/auth/access-token-boundary.d.ts.map +1 -0
- package/dist/auth/application-access.d.ts +4 -0
- package/dist/auth/application-access.d.ts.map +1 -0
- package/dist/auth/browser-origin.d.ts +62 -0
- package/dist/auth/browser-origin.d.ts.map +1 -0
- package/dist/auth/csrf.d.ts +2 -0
- package/dist/auth/csrf.d.ts.map +1 -0
- package/dist/auth/guard.d.ts +35 -0
- package/dist/auth/guard.d.ts.map +1 -0
- package/dist/auth/public-routes.d.ts +8 -0
- package/dist/auth/public-routes.d.ts.map +1 -0
- package/dist/auth/responses.d.ts +11 -0
- package/dist/auth/responses.d.ts.map +1 -0
- package/dist/auth/return-to.d.ts +3 -0
- package/dist/auth/return-to.d.ts.map +1 -0
- package/dist/auth/scope.d.ts +43 -0
- package/dist/auth/scope.d.ts.map +1 -0
- package/dist/auth/session-activity.d.ts +4 -0
- package/dist/auth/session-activity.d.ts.map +1 -0
- package/dist/auth/session-cookies.d.ts +12 -0
- package/dist/auth/session-cookies.d.ts.map +1 -0
- package/dist/files/content.d.ts +141 -0
- package/dist/files/content.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11522 -0
- package/dist/index.js.map +78 -0
- package/dist/openapi/security.d.ts +26 -0
- package/dist/openapi/security.d.ts.map +1 -0
- package/dist/openapi/tags.d.ts +151 -0
- package/dist/openapi/tags.d.ts.map +1 -0
- package/dist/registerRoutes.d.ts +31 -0
- package/dist/registerRoutes.d.ts.map +1 -0
- package/dist/routes/action-runs.d.ts +244 -0
- package/dist/routes/action-runs.d.ts.map +1 -0
- package/dist/routes/actions.d.ts +183 -0
- package/dist/routes/actions.d.ts.map +1 -0
- package/dist/routes/agent-api-gateway.d.ts +4 -0
- package/dist/routes/agent-api-gateway.d.ts.map +1 -0
- package/dist/routes/agents.d.ts +1061 -0
- package/dist/routes/agents.d.ts.map +1 -0
- package/dist/routes/auth.d.ts +1366 -0
- package/dist/routes/auth.d.ts.map +1 -0
- package/dist/routes/connectors.d.ts +108 -0
- package/dist/routes/connectors.d.ts.map +1 -0
- package/dist/routes/datasets.d.ts +339 -0
- package/dist/routes/datasets.d.ts.map +1 -0
- package/dist/routes/events.d.ts +116 -0
- package/dist/routes/events.d.ts.map +1 -0
- package/dist/routes/files.d.ts +340 -0
- package/dist/routes/files.d.ts.map +1 -0
- package/dist/routes/links.d.ts +175 -0
- package/dist/routes/links.d.ts.map +1 -0
- package/dist/routes/logs.d.ts +88 -0
- package/dist/routes/logs.d.ts.map +1 -0
- package/dist/routes/objects.d.ts +450 -0
- package/dist/routes/objects.d.ts.map +1 -0
- package/dist/routes/ontology.d.ts +240 -0
- package/dist/routes/ontology.d.ts.map +1 -0
- package/dist/routes/pipelines.d.ts +399 -0
- package/dist/routes/pipelines.d.ts.map +1 -0
- package/dist/routes/project.d.ts +56 -0
- package/dist/routes/project.d.ts.map +1 -0
- package/dist/routes/projections.d.ts +916 -0
- package/dist/routes/projections.d.ts.map +1 -0
- package/dist/routes/rules.d.ts +165 -0
- package/dist/routes/rules.d.ts.map +1 -0
- package/dist/routes/status.d.ts +81 -0
- package/dist/routes/status.d.ts.map +1 -0
- package/dist/routes/syncs.d.ts +294 -0
- package/dist/routes/syncs.d.ts.map +1 -0
- package/dist/routes/telemetry.d.ts +241 -0
- package/dist/routes/telemetry.d.ts.map +1 -0
- package/dist/routes/webhook-runs.d.ts +89 -0
- package/dist/routes/webhook-runs.d.ts.map +1 -0
- package/dist/routes/webhooks.d.ts +60 -0
- package/dist/routes/webhooks.d.ts.map +1 -0
- package/dist/routes/workflows.d.ts +973 -0
- package/dist/routes/workflows.d.ts.map +1 -0
- package/dist/routes/ws/agents.d.ts +99 -0
- package/dist/routes/ws/agents.d.ts.map +1 -0
- package/dist/routes/ws/events.d.ts +89 -0
- package/dist/routes/ws/events.d.ts.map +1 -0
- package/dist/routes/ws/index.d.ts +31 -0
- package/dist/routes/ws/index.d.ts.map +1 -0
- package/dist/routes/ws/log-subscription-hub.d.ts +47 -0
- package/dist/routes/ws/log-subscription-hub.d.ts.map +1 -0
- package/dist/routes/ws/logs.d.ts +110 -0
- package/dist/routes/ws/logs.d.ts.map +1 -0
- package/dist/schemas/actions.d.ts +644 -0
- package/dist/schemas/actions.d.ts.map +1 -0
- package/dist/schemas/agents.d.ts +3157 -0
- package/dist/schemas/agents.d.ts.map +1 -0
- package/dist/schemas/auth.d.ts +2023 -0
- package/dist/schemas/auth.d.ts.map +1 -0
- package/dist/schemas/common.d.ts +30 -0
- package/dist/schemas/common.d.ts.map +1 -0
- package/dist/schemas/connectors.d.ts +82 -0
- package/dist/schemas/connectors.d.ts.map +1 -0
- package/dist/schemas/datasets.d.ts +744 -0
- package/dist/schemas/datasets.d.ts.map +1 -0
- package/dist/schemas/event-payloads.d.ts +477 -0
- package/dist/schemas/event-payloads.d.ts.map +1 -0
- package/dist/schemas/events.d.ts +665 -0
- package/dist/schemas/events.d.ts.map +1 -0
- package/dist/schemas/files.d.ts +241 -0
- package/dist/schemas/files.d.ts.map +1 -0
- package/dist/schemas/links.d.ts +90 -0
- package/dist/schemas/links.d.ts.map +1 -0
- package/dist/schemas/logs.d.ts +231 -0
- package/dist/schemas/logs.d.ts.map +1 -0
- package/dist/schemas/objects.d.ts +288 -0
- package/dist/schemas/objects.d.ts.map +1 -0
- package/dist/schemas/ontology.d.ts +778 -0
- package/dist/schemas/ontology.d.ts.map +1 -0
- package/dist/schemas/pipelines.d.ts +1373 -0
- package/dist/schemas/pipelines.d.ts.map +1 -0
- package/dist/schemas/project.d.ts +9 -0
- package/dist/schemas/project.d.ts.map +1 -0
- package/dist/schemas/projections.d.ts +6992 -0
- package/dist/schemas/projections.d.ts.map +1 -0
- package/dist/schemas/rules.d.ts +204 -0
- package/dist/schemas/rules.d.ts.map +1 -0
- package/dist/schemas/status.d.ts +189 -0
- package/dist/schemas/status.d.ts.map +1 -0
- package/dist/schemas/syncs.d.ts +538 -0
- package/dist/schemas/syncs.d.ts.map +1 -0
- package/dist/schemas/telemetry.d.ts +265 -0
- package/dist/schemas/telemetry.d.ts.map +1 -0
- package/dist/schemas/webhook-runs.d.ts +169 -0
- package/dist/schemas/webhook-runs.d.ts.map +1 -0
- package/dist/schemas/workflows.d.ts +1720 -0
- package/dist/schemas/workflows.d.ts.map +1 -0
- package/dist/server.d.ts +64 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/tsconfig.json +5 -0
- package/dist/utils/http.d.ts +23 -0
- package/dist/utils/http.d.ts.map +1 -0
- package/dist/utils/request-body.d.ts +15 -0
- package/dist/utils/request-body.d.ts.map +1 -0
- package/dist/utils/ws.d.ts +10 -0
- package/dist/utils/ws.d.ts.map +1 -0
- package/package.json +68 -0
- package/src/auth/access-token-boundary.ts +68 -0
- package/src/auth/application-access.ts +16 -0
- package/src/auth/browser-origin.ts +367 -0
- package/src/auth/csrf.ts +1 -0
- package/src/auth/guard.ts +169 -0
- package/src/auth/public-routes.ts +87 -0
- package/src/auth/responses.ts +54 -0
- package/src/auth/return-to.ts +21 -0
- package/src/auth/scope.ts +64 -0
- package/src/auth/session-activity.ts +19 -0
- package/src/auth/session-cookies.ts +43 -0
- package/src/files/content.ts +419 -0
- package/src/index.ts +2 -0
- package/src/openapi/security.ts +37 -0
- package/src/openapi/tags.ts +151 -0
- package/src/registerRoutes.ts +49 -0
- package/src/routes/action-runs.ts +238 -0
- package/src/routes/actions.ts +126 -0
- package/src/routes/agent-api-gateway.ts +260 -0
- package/src/routes/agents.ts +943 -0
- package/src/routes/auth.ts +2233 -0
- package/src/routes/connectors.ts +69 -0
- package/src/routes/datasets.ts +402 -0
- package/src/routes/events.ts +55 -0
- package/src/routes/files.ts +675 -0
- package/src/routes/links.ts +143 -0
- package/src/routes/logs.ts +65 -0
- package/src/routes/objects.ts +838 -0
- package/src/routes/ontology.ts +138 -0
- package/src/routes/pipelines.ts +332 -0
- package/src/routes/project.ts +16 -0
- package/src/routes/projections.ts +251 -0
- package/src/routes/rules.ts +124 -0
- package/src/routes/status.ts +53 -0
- package/src/routes/syncs.ts +243 -0
- package/src/routes/telemetry.ts +207 -0
- package/src/routes/webhook-runs.ts +81 -0
- package/src/routes/webhooks.ts +508 -0
- package/src/routes/workflows.ts +1333 -0
- package/src/routes/ws/agents.ts +301 -0
- package/src/routes/ws/events.ts +278 -0
- package/src/routes/ws/index.ts +12 -0
- package/src/routes/ws/log-subscription-hub.ts +375 -0
- package/src/routes/ws/logs.ts +117 -0
- package/src/schemas/actions.ts +123 -0
- package/src/schemas/agents.ts +293 -0
- package/src/schemas/auth.ts +317 -0
- package/src/schemas/common.ts +60 -0
- package/src/schemas/connectors.ts +21 -0
- package/src/schemas/datasets.ts +107 -0
- package/src/schemas/event-payloads.ts +79 -0
- package/src/schemas/events.ts +117 -0
- package/src/schemas/files.ts +82 -0
- package/src/schemas/links.ts +38 -0
- package/src/schemas/logs.ts +76 -0
- package/src/schemas/objects.ts +759 -0
- package/src/schemas/ontology.ts +77 -0
- package/src/schemas/pipelines.ts +150 -0
- package/src/schemas/project.ts +5 -0
- package/src/schemas/projections.ts +144 -0
- package/src/schemas/rules.ts +98 -0
- package/src/schemas/status.ts +51 -0
- package/src/schemas/syncs.ts +83 -0
- package/src/schemas/telemetry.ts +59 -0
- package/src/schemas/webhook-runs.ts +40 -0
- package/src/schemas/workflows.ts +229 -0
- package/src/server.ts +383 -0
- package/src/utils/http.ts +108 -0
- package/src/utils/request-body.ts +62 -0
- package/src/utils/ws.ts +59 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { type AuthorizationContext, isAllowed, type OntologySource, type Sixb } from "@sixb/core"
|
|
2
|
+
import type { Elysia } from "elysia"
|
|
3
|
+
import { bearerSecurityRequirement } from "../auth/access-token-boundary"
|
|
4
|
+
import { requestAuthState } from "../auth/scope"
|
|
5
|
+
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
6
|
+
import { ErrorResponseSchema } from "../schemas/common"
|
|
7
|
+
import { ObjectTypeParamsSchema, ObjectTypeSchema } from "../schemas/ontology"
|
|
8
|
+
|
|
9
|
+
function serializeProperty(
|
|
10
|
+
property: ReturnType<
|
|
11
|
+
Sixb<readonly OntologySource[]>["listObjectTypes"]
|
|
12
|
+
>[number]["properties"][number]
|
|
13
|
+
) {
|
|
14
|
+
return {
|
|
15
|
+
id: property.id,
|
|
16
|
+
name: property.name,
|
|
17
|
+
description: property.description,
|
|
18
|
+
mode: property.mode,
|
|
19
|
+
required: property.required,
|
|
20
|
+
nullable: property.nullable,
|
|
21
|
+
primary: property.primary,
|
|
22
|
+
semanticType: property.semanticType,
|
|
23
|
+
schema: property.schema,
|
|
24
|
+
query: property.query ? { ...property.query } : undefined,
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function serializeSearch(
|
|
29
|
+
search: ReturnType<Sixb<readonly OntologySource[]>["listObjectTypes"]>[number]["search"]
|
|
30
|
+
) {
|
|
31
|
+
if (!search) return undefined
|
|
32
|
+
return {
|
|
33
|
+
title: search.title,
|
|
34
|
+
defaultText: search.defaultText ? [...search.defaultText] : undefined,
|
|
35
|
+
exact: search.exact ? [...search.exact] : undefined,
|
|
36
|
+
vector: search.vector
|
|
37
|
+
? {
|
|
38
|
+
property: search.vector.property,
|
|
39
|
+
source: [...search.vector.source],
|
|
40
|
+
}
|
|
41
|
+
: undefined,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function serializeObjectType(
|
|
46
|
+
sixb: Sixb<readonly OntologySource[]>,
|
|
47
|
+
objectType: ReturnType<Sixb<readonly OntologySource[]>["listObjectTypes"]>[number],
|
|
48
|
+
authorization: AuthorizationContext | null
|
|
49
|
+
) {
|
|
50
|
+
return {
|
|
51
|
+
id: objectType.id,
|
|
52
|
+
name: objectType.name,
|
|
53
|
+
description: objectType.description,
|
|
54
|
+
extends: objectType.extends,
|
|
55
|
+
implements: objectType.implements ? [...objectType.implements] : undefined,
|
|
56
|
+
properties: objectType.properties.map(serializeProperty),
|
|
57
|
+
search: serializeSearch(objectType.search),
|
|
58
|
+
links: objectType.links.map((link) => ({
|
|
59
|
+
id: link.id,
|
|
60
|
+
name: link.name,
|
|
61
|
+
description: link.description,
|
|
62
|
+
targetObjectTypeId: Array.isArray(link.targetObjectTypeId)
|
|
63
|
+
? [...link.targetObjectTypeId]
|
|
64
|
+
: link.targetObjectTypeId,
|
|
65
|
+
cardinality: link.cardinality,
|
|
66
|
+
properties: link.properties?.map(serializeProperty),
|
|
67
|
+
})),
|
|
68
|
+
actions: sixb
|
|
69
|
+
.listActionsForType(objectType)
|
|
70
|
+
.filter((action) => isAllowed(authorization, { kind: "action.apply", actionId: action.id }))
|
|
71
|
+
.map((action) => ({
|
|
72
|
+
id: action.id,
|
|
73
|
+
name: action.id,
|
|
74
|
+
description: action.description,
|
|
75
|
+
params: Object.entries(action.params).map(([id, config]) => ({
|
|
76
|
+
id,
|
|
77
|
+
name: id,
|
|
78
|
+
schema: config.schema,
|
|
79
|
+
required: config.required ?? false,
|
|
80
|
+
nullable: config.nullable,
|
|
81
|
+
description: config.description,
|
|
82
|
+
semanticType: config.semanticType,
|
|
83
|
+
})),
|
|
84
|
+
})),
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function registerOntologyRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
|
|
89
|
+
return app
|
|
90
|
+
.get(
|
|
91
|
+
"/api/object-types",
|
|
92
|
+
async (context) => {
|
|
93
|
+
const { authz } = requestAuthState(context)
|
|
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))
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
response: { 200: ObjectTypeSchema.array() },
|
|
103
|
+
detail: {
|
|
104
|
+
summary: "List registered object types",
|
|
105
|
+
tags: [OPENAPI_TAGS.ontology.name],
|
|
106
|
+
operationId: "listObjectTypes",
|
|
107
|
+
security: bearerSecurityRequirement("listObjectTypes"),
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
.get(
|
|
112
|
+
"/api/object-types/:objectTypeId",
|
|
113
|
+
async (context) => {
|
|
114
|
+
const { params, set } = context
|
|
115
|
+
const { authz } = requestAuthState(context)
|
|
116
|
+
const objectType = sixb.getObjectTypeById(params.objectTypeId)
|
|
117
|
+
if (
|
|
118
|
+
!objectType ||
|
|
119
|
+
!isAllowed(authz, { kind: "object.view", objectTypeId: objectType.id })
|
|
120
|
+
) {
|
|
121
|
+
set.status = 404
|
|
122
|
+
return { error: "Object type not found" }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return serializeObjectType(sixb, objectType, authz)
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
params: ObjectTypeParamsSchema,
|
|
129
|
+
response: { 200: ObjectTypeSchema, 404: ErrorResponseSchema },
|
|
130
|
+
detail: {
|
|
131
|
+
summary: "Get object type definition",
|
|
132
|
+
tags: [OPENAPI_TAGS.ontology.name],
|
|
133
|
+
operationId: "getObjectType",
|
|
134
|
+
security: bearerSecurityRequirement("getObjectType"),
|
|
135
|
+
},
|
|
136
|
+
}
|
|
137
|
+
)
|
|
138
|
+
}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import type { OntologySource, PipelineDefinition, PipelineStepExecutor, Sixb } from "@sixb/core"
|
|
2
|
+
import { canViewPipelineRun } from "@sixb/core/internal/authorization"
|
|
3
|
+
import type { PipelineRunRecord, PipelineStepRunRecord } from "@sixb/core/storage"
|
|
4
|
+
import type { Elysia } from "elysia"
|
|
5
|
+
import { requestAuthState } from "../auth/scope"
|
|
6
|
+
import { SIXB_CSRF_SECURITY_REQUIREMENT } from "../openapi/security"
|
|
7
|
+
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
8
|
+
import { ErrorResponseSchema } from "../schemas/common"
|
|
9
|
+
import {
|
|
10
|
+
PipelineParamsSchema,
|
|
11
|
+
PipelineRunDetailResponseSchema,
|
|
12
|
+
PipelineRunListResponseSchema,
|
|
13
|
+
PipelineRunParamsSchema,
|
|
14
|
+
PipelineRunsQuerySchema,
|
|
15
|
+
PipelineSchema,
|
|
16
|
+
RequestPipelineRunResponseSchema,
|
|
17
|
+
} from "../schemas/pipelines"
|
|
18
|
+
import {
|
|
19
|
+
handleRouteError,
|
|
20
|
+
parseDate,
|
|
21
|
+
parseOptionalInt,
|
|
22
|
+
toIsoString,
|
|
23
|
+
unconfiguredStorageResponse,
|
|
24
|
+
} from "../utils/http"
|
|
25
|
+
|
|
26
|
+
function serializePipelineRun(run: PipelineRunRecord) {
|
|
27
|
+
return {
|
|
28
|
+
id: run.id,
|
|
29
|
+
projectId: run.projectId,
|
|
30
|
+
pipelineId: run.pipelineId,
|
|
31
|
+
status: run.status,
|
|
32
|
+
startedAt: toIsoString(run.startedAt),
|
|
33
|
+
finishedAt: run.finishedAt ? toIsoString(run.finishedAt) : undefined,
|
|
34
|
+
output: run.output,
|
|
35
|
+
error: run.error,
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type SerializedPipelineRun = ReturnType<typeof serializePipelineRun>
|
|
40
|
+
|
|
41
|
+
function serializePipelineStepRun(step: PipelineStepRunRecord) {
|
|
42
|
+
return {
|
|
43
|
+
id: step.id,
|
|
44
|
+
projectId: step.projectId,
|
|
45
|
+
pipelineRunId: step.pipelineRunId,
|
|
46
|
+
pipelineId: step.pipelineId,
|
|
47
|
+
stepId: step.stepId,
|
|
48
|
+
datasetId: step.datasetId,
|
|
49
|
+
mode: step.mode,
|
|
50
|
+
status: step.status,
|
|
51
|
+
startedAt: toIsoString(step.startedAt),
|
|
52
|
+
finishedAt: step.finishedAt ? toIsoString(step.finishedAt) : undefined,
|
|
53
|
+
inputs: step.inputs,
|
|
54
|
+
output: step.output,
|
|
55
|
+
rowsWritten: step.rowsWritten,
|
|
56
|
+
error: step.error,
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function serializeExecutor(executor: PipelineStepExecutor) {
|
|
61
|
+
switch (executor.kind) {
|
|
62
|
+
case "sql":
|
|
63
|
+
return {
|
|
64
|
+
kind: "sql" as const,
|
|
65
|
+
dialect: executor.dialect,
|
|
66
|
+
}
|
|
67
|
+
case "run":
|
|
68
|
+
return {
|
|
69
|
+
kind: "run" as const,
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function getLatestPipelineRun(
|
|
75
|
+
sixb: Sixb<readonly OntologySource[]>,
|
|
76
|
+
pipelineId: string
|
|
77
|
+
): Promise<SerializedPipelineRun | null> {
|
|
78
|
+
if (!sixb.storage.pipelineRuns) {
|
|
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
|
+
})
|
|
87
|
+
|
|
88
|
+
const [latest] = result.runs
|
|
89
|
+
return latest ? serializePipelineRun(latest) : null
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function getLatestPipelineRuns(
|
|
93
|
+
sixb: Sixb<readonly OntologySource[]>,
|
|
94
|
+
pipelineIds: readonly string[]
|
|
95
|
+
): Promise<Map<string, SerializedPipelineRun>> {
|
|
96
|
+
const storage = sixb.storage.pipelineRuns
|
|
97
|
+
if (!storage || pipelineIds.length === 0) {
|
|
98
|
+
return new Map()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const result = await storage.listLatestByPipelineIds({
|
|
102
|
+
projectId: sixb.id,
|
|
103
|
+
pipelineIds,
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
return new Map(result.runs.map((run) => [run.pipelineId, serializePipelineRun(run)]))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function serializePipeline(
|
|
110
|
+
pipeline: PipelineDefinition,
|
|
111
|
+
latestRun: SerializedPipelineRun | null
|
|
112
|
+
): ReturnType<typeof PipelineSchema.parse> {
|
|
113
|
+
return PipelineSchema.parse({
|
|
114
|
+
id: pipeline.id,
|
|
115
|
+
triggers: pipeline.triggers,
|
|
116
|
+
graph: {
|
|
117
|
+
kind: pipeline.graph.kind,
|
|
118
|
+
nodes: pipeline.graph.nodes.map((node) => ({
|
|
119
|
+
kind: node.kind,
|
|
120
|
+
step: {
|
|
121
|
+
id: node.step.id,
|
|
122
|
+
mode: node.step.mode,
|
|
123
|
+
executor: serializeExecutor(node.step.executor),
|
|
124
|
+
inputs: Object.entries(node.step.inputs).map(([name, dataset]) => ({
|
|
125
|
+
name,
|
|
126
|
+
dataset,
|
|
127
|
+
})),
|
|
128
|
+
output: node.step.output,
|
|
129
|
+
},
|
|
130
|
+
})),
|
|
131
|
+
},
|
|
132
|
+
latestRun,
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function registerPipelineRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
|
|
137
|
+
return app
|
|
138
|
+
.get(
|
|
139
|
+
"/api/pipelines",
|
|
140
|
+
async (context) => {
|
|
141
|
+
const { scoped } = requestAuthState(context)
|
|
142
|
+
const pipelines = scoped ? scoped.listPipelines() : sixb.listPipelines()
|
|
143
|
+
const latestRuns = await getLatestPipelineRuns(
|
|
144
|
+
sixb,
|
|
145
|
+
pipelines.map((pipeline) => pipeline.id)
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
return pipelines.map((pipeline) =>
|
|
149
|
+
serializePipeline(pipeline, latestRuns.get(pipeline.id) ?? null)
|
|
150
|
+
)
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
response: { 200: PipelineSchema.array() },
|
|
154
|
+
detail: {
|
|
155
|
+
summary: "List registered pipelines",
|
|
156
|
+
tags: [OPENAPI_TAGS.pipelines.name],
|
|
157
|
+
operationId: "listPipelines",
|
|
158
|
+
},
|
|
159
|
+
}
|
|
160
|
+
)
|
|
161
|
+
.get(
|
|
162
|
+
"/api/pipelines/:pipelineId",
|
|
163
|
+
async (context) => {
|
|
164
|
+
const { params, set } = context
|
|
165
|
+
const { scoped } = requestAuthState(context)
|
|
166
|
+
const pipeline = scoped
|
|
167
|
+
? scoped.getPipelineById(params.pipelineId)
|
|
168
|
+
: sixb.getPipelineById(params.pipelineId)
|
|
169
|
+
if (!pipeline) {
|
|
170
|
+
set.status = 404
|
|
171
|
+
return { error: "Pipeline not found" }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return serializePipeline(pipeline, await getLatestPipelineRun(sixb, pipeline.id))
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
params: PipelineParamsSchema,
|
|
178
|
+
response: { 200: PipelineSchema, 404: ErrorResponseSchema },
|
|
179
|
+
detail: {
|
|
180
|
+
summary: "Get pipeline metadata",
|
|
181
|
+
tags: [OPENAPI_TAGS.pipelines.name],
|
|
182
|
+
operationId: "getPipeline",
|
|
183
|
+
},
|
|
184
|
+
}
|
|
185
|
+
)
|
|
186
|
+
.get(
|
|
187
|
+
"/api/pipeline-runs",
|
|
188
|
+
async (context) => {
|
|
189
|
+
const { query, set } = context
|
|
190
|
+
const { authz } = requestAuthState(context)
|
|
191
|
+
try {
|
|
192
|
+
const parsed = PipelineRunsQuerySchema.parse(query)
|
|
193
|
+
const storage = sixb.storage.pipelineRuns
|
|
194
|
+
if (!storage) {
|
|
195
|
+
return unconfiguredStorageResponse(set, "Pipeline run storage")
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Scope to runnable pipelines the same way workflow run history does:
|
|
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,
|
|
205
|
+
pipelineId: parsed.pipelineId,
|
|
206
|
+
pipelineIds,
|
|
207
|
+
statuses: parsed.status ? [parsed.status] : undefined,
|
|
208
|
+
startedAfter: parseDate(parsed.startedAfter),
|
|
209
|
+
startedBefore: parseDate(parsed.startedBefore),
|
|
210
|
+
limit: parseOptionalInt(parsed.limit),
|
|
211
|
+
offset: parseOptionalInt(parsed.offset),
|
|
212
|
+
order: parsed.order,
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
runs: result.runs.map(serializePipelineRun),
|
|
217
|
+
hasMore: result.hasMore,
|
|
218
|
+
total: result.total,
|
|
219
|
+
}
|
|
220
|
+
} catch (error) {
|
|
221
|
+
return handleRouteError(error, set)
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
query: PipelineRunsQuerySchema,
|
|
226
|
+
response: {
|
|
227
|
+
200: PipelineRunListResponseSchema,
|
|
228
|
+
400: ErrorResponseSchema,
|
|
229
|
+
501: ErrorResponseSchema,
|
|
230
|
+
},
|
|
231
|
+
detail: {
|
|
232
|
+
summary: "List pipeline run history",
|
|
233
|
+
tags: [OPENAPI_TAGS.pipelineRuns.name],
|
|
234
|
+
operationId: "listPipelineRuns",
|
|
235
|
+
},
|
|
236
|
+
}
|
|
237
|
+
)
|
|
238
|
+
.get(
|
|
239
|
+
"/api/pipeline-runs/:runId",
|
|
240
|
+
async (context) => {
|
|
241
|
+
const { params, set } = context
|
|
242
|
+
const { authz } = requestAuthState(context)
|
|
243
|
+
try {
|
|
244
|
+
const storage = sixb.storage.pipelineRuns
|
|
245
|
+
if (!storage) {
|
|
246
|
+
return unconfiguredStorageResponse(set, "Pipeline run storage")
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const run = await storage.getById({
|
|
250
|
+
projectId: sixb.id,
|
|
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)) {
|
|
256
|
+
set.status = 404
|
|
257
|
+
return { error: "Pipeline run not found" }
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const steps = await storage.listSteps({
|
|
261
|
+
projectId: sixb.id,
|
|
262
|
+
pipelineRunId: run.id,
|
|
263
|
+
order: "asc",
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
return PipelineRunDetailResponseSchema.parse({
|
|
267
|
+
run: serializePipelineRun(run),
|
|
268
|
+
steps: steps.steps.map(serializePipelineStepRun),
|
|
269
|
+
})
|
|
270
|
+
} catch (error) {
|
|
271
|
+
return handleRouteError(error, set)
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
params: PipelineRunParamsSchema,
|
|
276
|
+
response: {
|
|
277
|
+
200: PipelineRunDetailResponseSchema,
|
|
278
|
+
400: ErrorResponseSchema,
|
|
279
|
+
404: ErrorResponseSchema,
|
|
280
|
+
501: ErrorResponseSchema,
|
|
281
|
+
},
|
|
282
|
+
detail: {
|
|
283
|
+
summary: "Get pipeline run detail",
|
|
284
|
+
tags: [OPENAPI_TAGS.pipelineRuns.name],
|
|
285
|
+
operationId: "getPipelineRun",
|
|
286
|
+
},
|
|
287
|
+
}
|
|
288
|
+
)
|
|
289
|
+
.post(
|
|
290
|
+
"/api/pipelines/:pipelineId/runs",
|
|
291
|
+
async (context) => {
|
|
292
|
+
const { params, set } = context
|
|
293
|
+
const { scoped } = requestAuthState(context)
|
|
294
|
+
try {
|
|
295
|
+
const pipeline = sixb.getPipelineById(params.pipelineId)
|
|
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 })
|
|
304
|
+
|
|
305
|
+
set.status = 202
|
|
306
|
+
return {
|
|
307
|
+
runId: result.runId,
|
|
308
|
+
jobId: result.jobId ?? "",
|
|
309
|
+
pipelineId: result.pipelineId,
|
|
310
|
+
queuedAt: result.queuedAt,
|
|
311
|
+
}
|
|
312
|
+
} catch (error) {
|
|
313
|
+
return handleRouteError(error, set)
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
params: PipelineParamsSchema,
|
|
318
|
+
response: {
|
|
319
|
+
202: RequestPipelineRunResponseSchema,
|
|
320
|
+
400: ErrorResponseSchema,
|
|
321
|
+
403: ErrorResponseSchema,
|
|
322
|
+
404: ErrorResponseSchema,
|
|
323
|
+
},
|
|
324
|
+
detail: {
|
|
325
|
+
summary: "Request a pipeline run",
|
|
326
|
+
tags: [OPENAPI_TAGS.pipelineRuns.name],
|
|
327
|
+
operationId: "requestPipelineRun",
|
|
328
|
+
security: SIXB_CSRF_SECURITY_REQUIREMENT,
|
|
329
|
+
},
|
|
330
|
+
}
|
|
331
|
+
)
|
|
332
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { OntologySource, Sixb } from "@sixb/core"
|
|
2
|
+
import type { Elysia } from "elysia"
|
|
3
|
+
import { bearerSecurityRequirement } from "../auth/access-token-boundary"
|
|
4
|
+
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
5
|
+
import { ProjectInfoResponseSchema } from "../schemas/project"
|
|
6
|
+
export function registerProjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
|
|
7
|
+
return app.get("/api/project", async () => ({ id: sixb.id }), {
|
|
8
|
+
response: { 200: ProjectInfoResponseSchema },
|
|
9
|
+
detail: {
|
|
10
|
+
summary: "Get current project metadata",
|
|
11
|
+
tags: [OPENAPI_TAGS.project.name],
|
|
12
|
+
operationId: "getProjectInfo",
|
|
13
|
+
security: bearerSecurityRequirement("getProjectInfo"),
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
}
|