@sixb/server 0.1.1 → 0.1.3
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/experience.d.ts +33 -0
- package/dist/auth/experience.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 +13 -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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3903 -2760
- package/dist/index.js.map +58 -50
- package/dist/openapi/tags.d.ts +15 -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 +12 -11
- 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 +230 -159
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/ai-accounting.d.ts +31 -0
- package/dist/routes/ai-accounting.d.ts.map +1 -0
- package/dist/routes/auth.d.ts +149 -92
- 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 +16 -12
- package/dist/routes/datasets.d.ts.map +1 -1
- package/dist/routes/events.d.ts +9 -9
- package/dist/routes/events.d.ts.map +1 -1
- package/dist/routes/files.d.ts +19 -18
- package/dist/routes/files.d.ts.map +1 -1
- package/dist/routes/links.d.ts +11 -11
- 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 +37 -37
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/ontology.d.ts +50 -50
- package/dist/routes/ontology.d.ts.map +1 -1
- package/dist/routes/pipelines.d.ts +28 -38
- 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 +145 -85
- 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 +23 -28
- package/dist/routes/syncs.d.ts.map +1 -1
- package/dist/routes/telemetry.d.ts +9 -9
- 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 +177 -66
- 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 +89 -194
- package/dist/schemas/actions.d.ts.map +1 -1
- package/dist/schemas/agents.d.ts +791 -471
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-accounting.d.ts +2393 -0
- package/dist/schemas/ai-accounting.d.ts.map +1 -0
- 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 +102 -102
- 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 +2 -2
- package/dist/schemas/event-payloads.d.ts +12 -12
- package/dist/schemas/events.d.ts +40 -40
- package/dist/schemas/links.d.ts +2 -2
- package/dist/schemas/logs.d.ts +22 -22
- package/dist/schemas/objects.d.ts +10 -10
- package/dist/schemas/ontology.d.ts +118 -118
- package/dist/schemas/pipelines.d.ts +89 -184
- package/dist/schemas/pipelines.d.ts.map +1 -1
- package/dist/schemas/projections.d.ts +1030 -563
- package/dist/schemas/projections.d.ts.map +1 -1
- package/dist/schemas/rules.d.ts +6 -6
- package/dist/schemas/syncs.d.ts +65 -108
- 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 +1189 -185
- package/dist/schemas/workflows.d.ts.map +1 -1
- package/dist/server.d.ts +11 -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 +5 -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/experience.ts +190 -0
- package/src/auth/guard.ts +11 -11
- package/src/auth/public-routes.ts +20 -0
- package/src/auth/scope.ts +26 -36
- package/src/auth/session-cookies.ts +3 -3
- package/src/connectors/http.ts +110 -0
- package/src/index.ts +1 -0
- package/src/openapi/tags.ts +13 -1
- package/src/registerRoutes.ts +36 -23
- package/src/routes/action-runs.ts +39 -39
- package/src/routes/actions.ts +7 -13
- package/src/routes/agent-api-gateway.ts +41 -38
- package/src/routes/agents.ts +90 -200
- package/src/routes/ai-accounting.ts +166 -0
- package/src/routes/auth.ts +274 -122
- 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 +22 -30
- package/src/routes/links.ts +31 -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 +44 -42
- 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 +242 -248
- 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 +23 -23
- package/src/schemas/ai-accounting.ts +182 -0
- 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/pipelines.ts +23 -15
- package/src/schemas/projections.ts +23 -3
- package/src/schemas/syncs.ts +13 -8
- package/src/schemas/webhook-runs.ts +10 -5
- package/src/schemas/workflows.ts +23 -8
- package/src/server.ts +75 -26
- package/src/utils/http.ts +34 -6
- package/src/utils/ws.ts +10 -5
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
LinkProjectionDefinition,
|
|
3
3
|
ObjectProjectionDefinition,
|
|
4
|
-
OntologySource,
|
|
5
4
|
ProjectionDefinition,
|
|
6
|
-
|
|
5
|
+
SixbHostView,
|
|
6
|
+
SourceEditConflictResolution,
|
|
7
7
|
TelemetryProjectionDefinition,
|
|
8
8
|
} from "@sixb/core"
|
|
9
|
-
import { canViewProjection, canViewProjectionRun } from "@sixb/core/internal/authorization"
|
|
10
9
|
import type { ProjectionRunRecord } from "@sixb/core/storage"
|
|
11
10
|
import type { Elysia } from "elysia"
|
|
12
|
-
import {
|
|
11
|
+
import { requireRequestSixb } from "../auth/scope"
|
|
13
12
|
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
14
13
|
import { ErrorResponseSchema } from "../schemas/common"
|
|
15
14
|
import {
|
|
@@ -33,20 +32,20 @@ function serializeProjectionRun(run: ProjectionRunRecord) {
|
|
|
33
32
|
return ProjectionRunSchema.parse({
|
|
34
33
|
id: run.id,
|
|
35
34
|
projectId: run.projectId,
|
|
35
|
+
executionId: run.executionId,
|
|
36
36
|
identity: run.identity,
|
|
37
37
|
target: run.target,
|
|
38
38
|
status: run.status,
|
|
39
39
|
attempt: run.attempt,
|
|
40
40
|
progress: run.progress,
|
|
41
|
-
|
|
41
|
+
queuedAt: toIsoString(run.queuedAt),
|
|
42
|
+
startedAt: run.startedAt ? toIsoString(run.startedAt) : undefined,
|
|
42
43
|
finishedAt: run.finishedAt ? toIsoString(run.finishedAt) : undefined,
|
|
43
|
-
|
|
44
|
+
error: run.error,
|
|
44
45
|
})
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
type SerializedProjectionRun = ReturnType<typeof serializeProjectionRun>
|
|
48
|
-
type RequestAuthorization = ReturnType<typeof requestAuthState>["authz"]
|
|
49
|
-
|
|
50
49
|
interface ViewableProjectionCatalog {
|
|
51
50
|
readonly objectProjections: readonly ObjectProjectionDefinition[]
|
|
52
51
|
readonly linkProjections: readonly LinkProjectionDefinition[]
|
|
@@ -54,32 +53,24 @@ interface ViewableProjectionCatalog {
|
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
async function getLatestProjectionRuns(
|
|
57
|
-
sixb:
|
|
56
|
+
sixb: ReturnType<typeof requireRequestSixb>,
|
|
58
57
|
projectionIds: readonly string[]
|
|
59
58
|
): Promise<Map<string, SerializedProjectionRun>> {
|
|
60
|
-
|
|
61
|
-
if (!storage || projectionIds.length === 0) {
|
|
59
|
+
if (projectionIds.length === 0) {
|
|
62
60
|
return new Map()
|
|
63
61
|
}
|
|
64
62
|
|
|
65
|
-
const result = await
|
|
63
|
+
const result = await sixb.projections.runs.listLatest(projectionIds)
|
|
66
64
|
return new Map(result.runs.map((run) => [run.identity.projectionId, serializeProjectionRun(run)]))
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
function listViewableProjections(
|
|
70
|
-
sixb:
|
|
71
|
-
authz: RequestAuthorization
|
|
68
|
+
sixb: ReturnType<typeof requireRequestSixb>
|
|
72
69
|
): ViewableProjectionCatalog {
|
|
73
70
|
return {
|
|
74
|
-
objectProjections: sixb
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
linkProjections: sixb
|
|
78
|
-
.listLinkProjections()
|
|
79
|
-
.filter((projection) => canViewProjection(authz, projection)),
|
|
80
|
-
telemetryProjections: sixb
|
|
81
|
-
.listTelemetryProjections()
|
|
82
|
-
.filter((projection) => canViewProjection(authz, projection)),
|
|
71
|
+
objectProjections: sixb.projections.listObjects(),
|
|
72
|
+
linkProjections: sixb.projections.listLinks(),
|
|
73
|
+
telemetryProjections: sixb.projections.listTelemetry(),
|
|
83
74
|
}
|
|
84
75
|
}
|
|
85
76
|
|
|
@@ -91,14 +82,27 @@ function projectionCatalogIds(catalog: ViewableProjectionCatalog): string[] {
|
|
|
91
82
|
].map((projection) => projection.id)
|
|
92
83
|
}
|
|
93
84
|
|
|
85
|
+
type SerializedProjection<TProjection extends ProjectionDefinition> =
|
|
86
|
+
TProjection extends ObjectProjectionDefinition
|
|
87
|
+
? Omit<TProjection, "conflictResolution"> & {
|
|
88
|
+
conflictResolution: SourceEditConflictResolution
|
|
89
|
+
latestRun: SerializedProjectionRun | null
|
|
90
|
+
}
|
|
91
|
+
: TProjection & { latestRun: SerializedProjectionRun | null }
|
|
92
|
+
|
|
94
93
|
function serializeProjection<TProjection extends ProjectionDefinition>(
|
|
95
94
|
projection: TProjection,
|
|
96
95
|
latestRuns: ReadonlyMap<string, SerializedProjectionRun>
|
|
97
|
-
): TProjection
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
): SerializedProjection<TProjection> {
|
|
97
|
+
const latestRun = latestRuns.get(projection.id) ?? null
|
|
98
|
+
if (projection._tag === "ObjectProjectionDefinition") {
|
|
99
|
+
return {
|
|
100
|
+
...projection,
|
|
101
|
+
conflictResolution: projection.conflictResolution ?? { strategy: "editsWin" },
|
|
102
|
+
latestRun,
|
|
103
|
+
} as SerializedProjection<TProjection>
|
|
101
104
|
}
|
|
105
|
+
return { ...projection, latestRun } as SerializedProjection<TProjection>
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
function serializeProjectionCatalog(
|
|
@@ -118,13 +122,13 @@ function serializeProjectionCatalog(
|
|
|
118
122
|
}
|
|
119
123
|
}
|
|
120
124
|
|
|
121
|
-
export function registerProjectionRoutes(app: Elysia,
|
|
125
|
+
export function registerProjectionRoutes(app: Elysia, host: SixbHostView) {
|
|
122
126
|
return app
|
|
123
127
|
.get(
|
|
124
128
|
"/api/projections",
|
|
125
129
|
async (context) => {
|
|
126
|
-
const
|
|
127
|
-
const catalog = listViewableProjections(sixb
|
|
130
|
+
const sixb = requireRequestSixb(context)
|
|
131
|
+
const catalog = listViewableProjections(sixb)
|
|
128
132
|
const latestRuns = await getLatestProjectionRuns(sixb, projectionCatalogIds(catalog))
|
|
129
133
|
return serializeProjectionCatalog(catalog, latestRuns)
|
|
130
134
|
},
|
|
@@ -141,9 +145,9 @@ export function registerProjectionRoutes(app: Elysia, sixb: Sixb<readonly Ontolo
|
|
|
141
145
|
"/api/projections/:projectionId",
|
|
142
146
|
async (context) => {
|
|
143
147
|
const { params, set } = context
|
|
144
|
-
const
|
|
145
|
-
const found = sixb.
|
|
146
|
-
if (!found
|
|
148
|
+
const sixb = requireRequestSixb(context)
|
|
149
|
+
const found = sixb.projections.getById(params.projectionId)
|
|
150
|
+
if (!found) {
|
|
147
151
|
set.status = 404
|
|
148
152
|
return { error: `Projection '${params.projectionId}' not found` }
|
|
149
153
|
}
|
|
@@ -165,21 +169,19 @@ export function registerProjectionRoutes(app: Elysia, sixb: Sixb<readonly Ontolo
|
|
|
165
169
|
"/api/projection-runs",
|
|
166
170
|
async (context) => {
|
|
167
171
|
const { query, set } = context
|
|
168
|
-
const
|
|
172
|
+
const sixb = requireRequestSixb(context)
|
|
169
173
|
try {
|
|
170
|
-
const storage =
|
|
174
|
+
const storage = host.storage.projectionRuns
|
|
171
175
|
if (!storage) {
|
|
172
176
|
return unconfiguredStorageResponse(set, "Projection run storage")
|
|
173
177
|
}
|
|
174
178
|
|
|
175
179
|
const parsed = ProjectionRunsQuerySchema.parse(query)
|
|
176
|
-
const result = await
|
|
177
|
-
projectId: sixb.id,
|
|
180
|
+
const result = await sixb.projections.runs.list({
|
|
178
181
|
projectionId: parsed.projectionId,
|
|
179
182
|
projectionKind: parsed.projectionKind,
|
|
180
183
|
datasetId: parsed.datasetId,
|
|
181
184
|
datasetVersionId: parsed.datasetVersionId,
|
|
182
|
-
objectTypeIds: authz ? [...authz.grants["view:object"]] : undefined,
|
|
183
185
|
statuses: parsed.status ? [parsed.status] : undefined,
|
|
184
186
|
startedAfter: parseDate(parsed.startedAfter),
|
|
185
187
|
startedBefore: parseDate(parsed.startedBefore),
|
|
@@ -215,15 +217,15 @@ export function registerProjectionRoutes(app: Elysia, sixb: Sixb<readonly Ontolo
|
|
|
215
217
|
"/api/projection-runs/:runId",
|
|
216
218
|
async (context) => {
|
|
217
219
|
const { params, set } = context
|
|
218
|
-
const
|
|
220
|
+
const sixb = requireRequestSixb(context)
|
|
219
221
|
try {
|
|
220
|
-
const storage =
|
|
222
|
+
const storage = host.storage.projectionRuns
|
|
221
223
|
if (!storage) {
|
|
222
224
|
return unconfiguredStorageResponse(set, "Projection run storage")
|
|
223
225
|
}
|
|
224
226
|
|
|
225
|
-
const run = await
|
|
226
|
-
if (!run
|
|
227
|
+
const run = await sixb.projections.runs.getById(params.runId)
|
|
228
|
+
if (!run) {
|
|
227
229
|
set.status = 404
|
|
228
230
|
return { error: "Projection run not found" }
|
|
229
231
|
}
|
package/src/routes/rules.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { RuleDefinition, SixbHostView } from "@sixb/core"
|
|
2
2
|
import { deriveRuleEventDependencies } from "@sixb/core/internal/rules"
|
|
3
3
|
import type { RuleStateRecord } from "@sixb/core/storage"
|
|
4
4
|
import type { Elysia } from "elysia"
|
|
5
|
-
import {
|
|
5
|
+
import { requireRequestSixb } from "../auth/scope"
|
|
6
6
|
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
7
7
|
import { ErrorResponseSchema } from "../schemas/common"
|
|
8
8
|
import {
|
|
@@ -25,12 +25,12 @@ function serializeRuleState(state: RuleStateRecord): ReturnType<typeof RuleState
|
|
|
25
25
|
return RuleStateSchema.parse(state)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export function registerRuleRoutes(app: Elysia,
|
|
28
|
+
export function registerRuleRoutes(app: Elysia, host: SixbHostView) {
|
|
29
29
|
return app
|
|
30
30
|
.get(
|
|
31
31
|
"/api/rules",
|
|
32
|
-
() => {
|
|
33
|
-
return
|
|
32
|
+
(context) => {
|
|
33
|
+
return requireRequestSixb(context).rules.list().map(serializeRule)
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
response: { 200: RuleSchema.array() },
|
|
@@ -43,8 +43,9 @@ export function registerRuleRoutes(app: Elysia, sixb: Sixb<readonly OntologySour
|
|
|
43
43
|
)
|
|
44
44
|
.get(
|
|
45
45
|
"/api/rules/:ruleId",
|
|
46
|
-
(
|
|
47
|
-
const
|
|
46
|
+
(context) => {
|
|
47
|
+
const { params, set } = context
|
|
48
|
+
const rule = requireRequestSixb(context).rules.getById(params.ruleId)
|
|
48
49
|
if (!rule) {
|
|
49
50
|
set.status = 404
|
|
50
51
|
return { error: "Rule not found" }
|
|
@@ -66,32 +67,17 @@ export function registerRuleRoutes(app: Elysia, sixb: Sixb<readonly OntologySour
|
|
|
66
67
|
"/api/rule-states",
|
|
67
68
|
async (context) => {
|
|
68
69
|
const { query, set } = context
|
|
69
|
-
const
|
|
70
|
+
const sixb = requireRequestSixb(context)
|
|
70
71
|
try {
|
|
71
72
|
const parsed = RuleStatesQuerySchema.parse(query)
|
|
72
|
-
const storage =
|
|
73
|
+
const storage = host.storage.rules
|
|
73
74
|
if (!storage) {
|
|
74
75
|
return unconfiguredStorageResponse(set, "Rule state storage")
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
79
|
-
authz &&
|
|
80
|
-
parsed.objectTypeId &&
|
|
81
|
-
!isAllowed(authz, { kind: "object.view", objectTypeId: parsed.objectTypeId })
|
|
82
|
-
) {
|
|
83
|
-
return {
|
|
84
|
-
states: [],
|
|
85
|
-
hasMore: false,
|
|
86
|
-
total: 0,
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const result = await storage.listActive({
|
|
91
|
-
projectId: sixb.id,
|
|
78
|
+
const result = await sixb.rules.states.list({
|
|
92
79
|
ruleId: parsed.ruleId,
|
|
93
80
|
objectTypeId: parsed.objectTypeId,
|
|
94
|
-
objectTypeIds,
|
|
95
81
|
primaryId: parsed.primaryId,
|
|
96
82
|
limit: parseOptionalInt(parsed.limit),
|
|
97
83
|
offset: parseOptionalInt(parsed.offset),
|
package/src/routes/status.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SixbHostView } from "@sixb/core"
|
|
2
2
|
import type { Elysia } from "elysia"
|
|
3
3
|
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
4
4
|
import {
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
ReadinessResponseSchema,
|
|
7
7
|
StatusResponseSchema,
|
|
8
8
|
} from "../schemas/status"
|
|
9
|
-
export function registerStatusRoutes(app: Elysia,
|
|
9
|
+
export function registerStatusRoutes(app: Elysia, host: SixbHostView) {
|
|
10
10
|
app.get("/health", () => ({ status: "ok" as const }), {
|
|
11
11
|
response: { 200: HealthResponseSchema },
|
|
12
12
|
detail: {
|
|
@@ -20,7 +20,7 @@ export function registerStatusRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
|
|
|
20
20
|
app.get(
|
|
21
21
|
"/ready",
|
|
22
22
|
async ({ set }) => {
|
|
23
|
-
const readiness = await
|
|
23
|
+
const readiness = await host.checkReadiness()
|
|
24
24
|
if (readiness.status === "unready") set.status = 503
|
|
25
25
|
return readiness
|
|
26
26
|
},
|
|
@@ -38,8 +38,8 @@ export function registerStatusRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
|
|
|
38
38
|
return app.get(
|
|
39
39
|
"/api/status",
|
|
40
40
|
async () => ({
|
|
41
|
-
...
|
|
42
|
-
objectTypes:
|
|
41
|
+
...host.getOntologyOperationalStatus(),
|
|
42
|
+
objectTypes: host.definitions.ontology.listObjectTypes().length,
|
|
43
43
|
}),
|
|
44
44
|
{
|
|
45
45
|
response: { 200: StatusResponseSchema },
|
package/src/routes/syncs.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SixbHostView, SyncDefinition } from "@sixb/core"
|
|
2
2
|
import type { SyncRunRecord } from "@sixb/core/storage"
|
|
3
3
|
import type { Elysia } from "elysia"
|
|
4
|
-
import {
|
|
4
|
+
import { requireRequestSixb } from "../auth/scope"
|
|
5
5
|
import { SIXB_CSRF_SECURITY_REQUIREMENT } from "../openapi/security"
|
|
6
6
|
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
7
7
|
import { ErrorResponseSchema } from "../schemas/common"
|
|
@@ -29,7 +29,8 @@ function serializeSyncRun(run: SyncRunRecord) {
|
|
|
29
29
|
datasetId: run.datasetId,
|
|
30
30
|
mode: run.mode,
|
|
31
31
|
status: run.status,
|
|
32
|
-
|
|
32
|
+
queuedAt: toIsoString(run.queuedAt),
|
|
33
|
+
startedAt: run.startedAt ? toIsoString(run.startedAt) : undefined,
|
|
33
34
|
finishedAt: run.finishedAt ? toIsoString(run.finishedAt) : undefined,
|
|
34
35
|
rowsRead: run.rowsRead,
|
|
35
36
|
output: run.output,
|
|
@@ -42,36 +43,24 @@ function serializeSyncRun(run: SyncRunRecord) {
|
|
|
42
43
|
type SerializedSyncRun = ReturnType<typeof serializeSyncRun>
|
|
43
44
|
|
|
44
45
|
async function getLatestSyncRun(
|
|
45
|
-
sixb:
|
|
46
|
+
sixb: ReturnType<typeof requireRequestSixb>,
|
|
46
47
|
syncId: string
|
|
47
48
|
): Promise<SerializedSyncRun | null> {
|
|
48
|
-
|
|
49
|
-
return null
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const storage = sixb.storage.syncRuns
|
|
53
|
-
const result = await storage.listLatestBySyncIds({
|
|
54
|
-
projectId: sixb.id,
|
|
55
|
-
syncIds: [syncId],
|
|
56
|
-
})
|
|
49
|
+
const result = await sixb.syncs.runs.listLatest([syncId])
|
|
57
50
|
|
|
58
51
|
const [latest] = result.runs
|
|
59
52
|
return latest ? serializeSyncRun(latest) : null
|
|
60
53
|
}
|
|
61
54
|
|
|
62
55
|
async function getLatestSyncRuns(
|
|
63
|
-
sixb:
|
|
56
|
+
sixb: ReturnType<typeof requireRequestSixb>,
|
|
64
57
|
syncIds: readonly string[]
|
|
65
58
|
): Promise<Map<string, SerializedSyncRun>> {
|
|
66
|
-
|
|
67
|
-
if (!storage || syncIds.length === 0) {
|
|
59
|
+
if (syncIds.length === 0) {
|
|
68
60
|
return new Map()
|
|
69
61
|
}
|
|
70
62
|
|
|
71
|
-
const result = await
|
|
72
|
-
projectId: sixb.id,
|
|
73
|
-
syncIds,
|
|
74
|
-
})
|
|
63
|
+
const result = await sixb.syncs.runs.listLatest(syncIds)
|
|
75
64
|
|
|
76
65
|
return new Map(result.runs.map((run) => [run.syncId, serializeSyncRun(run)]))
|
|
77
66
|
}
|
|
@@ -96,13 +85,13 @@ function serializeSync(
|
|
|
96
85
|
})
|
|
97
86
|
}
|
|
98
87
|
|
|
99
|
-
export function registerSyncRoutes(app: Elysia,
|
|
88
|
+
export function registerSyncRoutes(app: Elysia, host: SixbHostView) {
|
|
100
89
|
return app
|
|
101
90
|
.get(
|
|
102
91
|
"/api/syncs",
|
|
103
92
|
async (context) => {
|
|
104
|
-
const
|
|
105
|
-
const syncs =
|
|
93
|
+
const sixb = requireRequestSixb(context)
|
|
94
|
+
const syncs = sixb.syncs.list()
|
|
106
95
|
const latestRuns = await getLatestSyncRuns(
|
|
107
96
|
sixb,
|
|
108
97
|
syncs.map((sync) => sync.id)
|
|
@@ -123,8 +112,8 @@ export function registerSyncRoutes(app: Elysia, sixb: Sixb<readonly OntologySour
|
|
|
123
112
|
"/api/syncs/:syncId",
|
|
124
113
|
async (context) => {
|
|
125
114
|
const { params, set } = context
|
|
126
|
-
const
|
|
127
|
-
const sync =
|
|
115
|
+
const sixb = requireRequestSixb(context)
|
|
116
|
+
const sync = sixb.syncs.getById(params.syncId)
|
|
128
117
|
if (!sync) {
|
|
129
118
|
set.status = 404
|
|
130
119
|
return { error: "Sync not found" }
|
|
@@ -146,23 +135,16 @@ export function registerSyncRoutes(app: Elysia, sixb: Sixb<readonly OntologySour
|
|
|
146
135
|
"/api/sync-runs",
|
|
147
136
|
async (context) => {
|
|
148
137
|
const { query, set } = context
|
|
149
|
-
const
|
|
138
|
+
const sixb = requireRequestSixb(context)
|
|
150
139
|
try {
|
|
151
140
|
const parsed = SyncRunsQuerySchema.parse(query)
|
|
152
|
-
const storage =
|
|
141
|
+
const storage = host.storage.syncRuns
|
|
153
142
|
if (!storage) {
|
|
154
143
|
return unconfiguredStorageResponse(set, "Sync run storage")
|
|
155
144
|
}
|
|
156
145
|
|
|
157
|
-
|
|
158
|
-
// the grant allowlist alongside any explicit syncId and let storage AND
|
|
159
|
-
// them. An ungranted syncId yields an empty intersection (no rows), and
|
|
160
|
-
// an empty allowlist short-circuits to no rows.
|
|
161
|
-
const syncIds = authz ? [...authz.grants["run:sync"]] : undefined
|
|
162
|
-
const result = await storage.list({
|
|
163
|
-
projectId: sixb.id,
|
|
146
|
+
const result = await sixb.syncs.runs.list({
|
|
164
147
|
syncId: parsed.syncId,
|
|
165
|
-
syncIds,
|
|
166
148
|
datasetId: parsed.datasetId,
|
|
167
149
|
statuses: parsed.status ? [parsed.status] : undefined,
|
|
168
150
|
startedAfter: parseDate(parsed.startedAfter),
|
|
@@ -199,18 +181,10 @@ export function registerSyncRoutes(app: Elysia, sixb: Sixb<readonly OntologySour
|
|
|
199
181
|
"/api/syncs/:syncId/runs",
|
|
200
182
|
async (context) => {
|
|
201
183
|
const { params, body, set } = context
|
|
202
|
-
const
|
|
184
|
+
const sixb = requireRequestSixb(context)
|
|
203
185
|
try {
|
|
204
|
-
const sync = sixb.getSyncById(params.syncId)
|
|
205
|
-
if (!sync) {
|
|
206
|
-
set.status = 404
|
|
207
|
-
return { error: "Sync not found" }
|
|
208
|
-
}
|
|
209
|
-
|
|
210
186
|
const parsedBody = RequestSyncRunBodySchema.parse(body)
|
|
211
|
-
const result =
|
|
212
|
-
? await scoped.requestSyncRun({ syncId: sync.id, ...parsedBody })
|
|
213
|
-
: await sixb.requestSyncRun({ syncId: sync.id, ...parsedBody })
|
|
187
|
+
const result = await sixb.syncs.request({ syncId: params.syncId, ...parsedBody })
|
|
214
188
|
|
|
215
189
|
set.status = 202
|
|
216
190
|
return {
|
package/src/routes/telemetry.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getTelemetryHistoryBatch } from "@sixb/core/internal/objects"
|
|
1
|
+
import type { SixbHostView } from "@sixb/core"
|
|
3
2
|
import type { TimeseriesPoint } from "@sixb/core/storage"
|
|
4
3
|
import type { Elysia } from "elysia"
|
|
5
4
|
import { bearerSecurityRequirement } from "../auth/access-token-boundary"
|
|
6
|
-
import {
|
|
5
|
+
import { requireRequestSixb } from "../auth/scope"
|
|
7
6
|
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
8
7
|
import { ErrorResponseSchema, SuccessResponseSchema } from "../schemas/common"
|
|
9
8
|
import {
|
|
@@ -28,16 +27,15 @@ function serializeTelemetryPoint(point: TimeseriesPoint) {
|
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
export function registerTelemetryRoutes(app: Elysia,
|
|
30
|
+
export function registerTelemetryRoutes(app: Elysia, _host: SixbHostView) {
|
|
32
31
|
return app
|
|
33
32
|
.post(
|
|
34
33
|
"/api/objects/:objectTypeId/:objectId/telemetry/:propertyId",
|
|
35
34
|
async (context) => {
|
|
36
35
|
const { params, body, set } = context
|
|
37
|
-
const { scoped } = requestAuthState(context)
|
|
38
36
|
try {
|
|
39
37
|
const parsedBody = AppendTelemetryBodySchema.parse(body)
|
|
40
|
-
await (
|
|
38
|
+
await requireRequestSixb(context).objects.appendTelemetry(params.objectTypeId, [
|
|
41
39
|
{
|
|
42
40
|
id: params.objectId,
|
|
43
41
|
properties: {
|
|
@@ -75,22 +73,17 @@ export function registerTelemetryRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
|
|
|
75
73
|
"/api/telemetry/history",
|
|
76
74
|
async (context) => {
|
|
77
75
|
const { body, set } = context
|
|
78
|
-
const { authz } = requestAuthState(context)
|
|
79
76
|
try {
|
|
80
77
|
const parsedBody = BulkTelemetryHistoryBodySchema.parse(body)
|
|
81
78
|
const from = parseDate(parsedBody.from)
|
|
82
79
|
const to = parseDate(parsedBody.to)
|
|
83
|
-
const history = await getTelemetryHistoryBatch(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
order: parsedBody.order,
|
|
91
|
-
},
|
|
92
|
-
{ storage: sixb.storage.timeseries, authorization: authz }
|
|
93
|
-
)
|
|
80
|
+
const history = await requireRequestSixb(context).objects.getTelemetryHistoryBatch({
|
|
81
|
+
series: parsedBody.series,
|
|
82
|
+
from,
|
|
83
|
+
to,
|
|
84
|
+
limitPerSeries: parsedBody.limitPerSeries,
|
|
85
|
+
order: parsedBody.order,
|
|
86
|
+
})
|
|
94
87
|
|
|
95
88
|
return {
|
|
96
89
|
series: history.map((series) => ({
|
|
@@ -121,16 +114,14 @@ export function registerTelemetryRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
|
|
|
121
114
|
"/api/objects/:objectTypeId/:objectId/telemetry/:propertyId/history",
|
|
122
115
|
async (context) => {
|
|
123
116
|
const { params, query, set } = context
|
|
124
|
-
const { authz } = requestAuthState(context)
|
|
125
117
|
try {
|
|
126
|
-
const
|
|
127
|
-
if (!
|
|
118
|
+
const sixb = requireRequestSixb(context)
|
|
119
|
+
if (!sixb.objects.getTypeById(params.objectTypeId)) {
|
|
128
120
|
set.status = 404
|
|
129
121
|
return { error: "Object not found" }
|
|
130
122
|
}
|
|
131
|
-
|
|
132
|
-
const history = await sixb.
|
|
133
|
-
projectId: sixb.id,
|
|
123
|
+
const parsedQuery = TelemetryHistoryQuerySchema.parse(query)
|
|
124
|
+
const history = await sixb.objects.getTelemetryHistory({
|
|
134
125
|
objectTypeId: params.objectTypeId,
|
|
135
126
|
objectId: params.objectId,
|
|
136
127
|
propertyId: params.propertyId,
|
|
@@ -165,15 +156,13 @@ export function registerTelemetryRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
|
|
|
165
156
|
"/api/objects/:objectTypeId/:objectId/telemetry/:propertyId/latest",
|
|
166
157
|
async (context) => {
|
|
167
158
|
const { params, set } = context
|
|
168
|
-
const { authz } = requestAuthState(context)
|
|
169
159
|
try {
|
|
170
|
-
|
|
160
|
+
const sixb = requireRequestSixb(context)
|
|
161
|
+
if (!sixb.objects.getTypeById(params.objectTypeId)) {
|
|
171
162
|
set.status = 404
|
|
172
163
|
return { error: "Object not found" }
|
|
173
164
|
}
|
|
174
|
-
|
|
175
|
-
const latest = await sixb.storage.timeseries.getLatest({
|
|
176
|
-
projectId: sixb.id,
|
|
165
|
+
const latest = await sixb.objects.getLatestTelemetry({
|
|
177
166
|
objectTypeId: params.objectTypeId,
|
|
178
167
|
objectId: params.objectId,
|
|
179
168
|
propertyId: params.propertyId,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SixbHostView } from "@sixb/core"
|
|
2
2
|
import type { WebhookRunRecord } from "@sixb/core/storage"
|
|
3
3
|
import type { Elysia } from "elysia"
|
|
4
4
|
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
@@ -16,6 +16,7 @@ function serializeWebhookRun(run: WebhookRunRecord) {
|
|
|
16
16
|
return {
|
|
17
17
|
id: run.id,
|
|
18
18
|
projectId: run.projectId,
|
|
19
|
+
executionId: run.executionId,
|
|
19
20
|
connectorId: run.connectorId,
|
|
20
21
|
webhookId: run.webhookId,
|
|
21
22
|
status: run.status,
|
|
@@ -26,24 +27,23 @@ function serializeWebhookRun(run: WebhookRunRecord) {
|
|
|
26
27
|
requestBodyBytes: run.requestBodyBytes,
|
|
27
28
|
responseStatus: run.responseStatus,
|
|
28
29
|
idempotencyKey: run.idempotencyKey,
|
|
29
|
-
deliveryClaimResult: run.deliveryClaimResult,
|
|
30
30
|
error: run.error,
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export function registerWebhookRunRoutes(app: Elysia,
|
|
34
|
+
export function registerWebhookRunRoutes(app: Elysia, host: SixbHostView) {
|
|
35
35
|
return app.get(
|
|
36
36
|
"/api/webhook-runs",
|
|
37
37
|
async ({ query, set }) => {
|
|
38
38
|
try {
|
|
39
39
|
const parsed = WebhookRunsQuerySchema.parse(query)
|
|
40
|
-
const storage =
|
|
40
|
+
const storage = host.storage.webhookRuns
|
|
41
41
|
if (!storage) {
|
|
42
42
|
return unconfiguredStorageResponse(set, "Webhook run storage")
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
const result = await storage.list({
|
|
46
|
-
projectId:
|
|
46
|
+
projectId: host.id,
|
|
47
47
|
connectorId: parsed.connectorId,
|
|
48
48
|
webhookId: parsed.webhookId,
|
|
49
49
|
statuses: parsed.status ? [parsed.status] : undefined,
|