@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
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
LinkProjectionDefinition,
|
|
3
3
|
ObjectProjectionDefinition,
|
|
4
|
-
OntologySource,
|
|
5
4
|
ProjectionDefinition,
|
|
6
|
-
|
|
5
|
+
SixbHostView,
|
|
7
6
|
TelemetryProjectionDefinition,
|
|
8
7
|
} from "@sixb/core"
|
|
9
|
-
import { canViewProjection, canViewProjectionRun } from "@sixb/core/internal/authorization"
|
|
10
8
|
import type { ProjectionRunRecord } from "@sixb/core/storage"
|
|
11
9
|
import type { Elysia } from "elysia"
|
|
12
|
-
import {
|
|
10
|
+
import { requireRequestSixb } from "../auth/scope"
|
|
13
11
|
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
14
12
|
import { ErrorResponseSchema } from "../schemas/common"
|
|
15
13
|
import {
|
|
@@ -33,20 +31,20 @@ function serializeProjectionRun(run: ProjectionRunRecord) {
|
|
|
33
31
|
return ProjectionRunSchema.parse({
|
|
34
32
|
id: run.id,
|
|
35
33
|
projectId: run.projectId,
|
|
34
|
+
executionId: run.executionId,
|
|
36
35
|
identity: run.identity,
|
|
37
36
|
target: run.target,
|
|
38
37
|
status: run.status,
|
|
39
38
|
attempt: run.attempt,
|
|
40
39
|
progress: run.progress,
|
|
41
|
-
|
|
40
|
+
queuedAt: toIsoString(run.queuedAt),
|
|
41
|
+
startedAt: run.startedAt ? toIsoString(run.startedAt) : undefined,
|
|
42
42
|
finishedAt: run.finishedAt ? toIsoString(run.finishedAt) : undefined,
|
|
43
|
-
|
|
43
|
+
error: run.error,
|
|
44
44
|
})
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
type SerializedProjectionRun = ReturnType<typeof serializeProjectionRun>
|
|
48
|
-
type RequestAuthorization = ReturnType<typeof requestAuthState>["authz"]
|
|
49
|
-
|
|
50
48
|
interface ViewableProjectionCatalog {
|
|
51
49
|
readonly objectProjections: readonly ObjectProjectionDefinition[]
|
|
52
50
|
readonly linkProjections: readonly LinkProjectionDefinition[]
|
|
@@ -54,32 +52,24 @@ interface ViewableProjectionCatalog {
|
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
async function getLatestProjectionRuns(
|
|
57
|
-
sixb:
|
|
55
|
+
sixb: ReturnType<typeof requireRequestSixb>,
|
|
58
56
|
projectionIds: readonly string[]
|
|
59
57
|
): Promise<Map<string, SerializedProjectionRun>> {
|
|
60
|
-
|
|
61
|
-
if (!storage || projectionIds.length === 0) {
|
|
58
|
+
if (projectionIds.length === 0) {
|
|
62
59
|
return new Map()
|
|
63
60
|
}
|
|
64
61
|
|
|
65
|
-
const result = await
|
|
62
|
+
const result = await sixb.projections.runs.listLatest(projectionIds)
|
|
66
63
|
return new Map(result.runs.map((run) => [run.identity.projectionId, serializeProjectionRun(run)]))
|
|
67
64
|
}
|
|
68
65
|
|
|
69
66
|
function listViewableProjections(
|
|
70
|
-
sixb:
|
|
71
|
-
authz: RequestAuthorization
|
|
67
|
+
sixb: ReturnType<typeof requireRequestSixb>
|
|
72
68
|
): ViewableProjectionCatalog {
|
|
73
69
|
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)),
|
|
70
|
+
objectProjections: sixb.projections.listObjects(),
|
|
71
|
+
linkProjections: sixb.projections.listLinks(),
|
|
72
|
+
telemetryProjections: sixb.projections.listTelemetry(),
|
|
83
73
|
}
|
|
84
74
|
}
|
|
85
75
|
|
|
@@ -118,13 +108,13 @@ function serializeProjectionCatalog(
|
|
|
118
108
|
}
|
|
119
109
|
}
|
|
120
110
|
|
|
121
|
-
export function registerProjectionRoutes(app: Elysia,
|
|
111
|
+
export function registerProjectionRoutes(app: Elysia, host: SixbHostView) {
|
|
122
112
|
return app
|
|
123
113
|
.get(
|
|
124
114
|
"/api/projections",
|
|
125
115
|
async (context) => {
|
|
126
|
-
const
|
|
127
|
-
const catalog = listViewableProjections(sixb
|
|
116
|
+
const sixb = requireRequestSixb(context)
|
|
117
|
+
const catalog = listViewableProjections(sixb)
|
|
128
118
|
const latestRuns = await getLatestProjectionRuns(sixb, projectionCatalogIds(catalog))
|
|
129
119
|
return serializeProjectionCatalog(catalog, latestRuns)
|
|
130
120
|
},
|
|
@@ -141,9 +131,9 @@ export function registerProjectionRoutes(app: Elysia, sixb: Sixb<readonly Ontolo
|
|
|
141
131
|
"/api/projections/:projectionId",
|
|
142
132
|
async (context) => {
|
|
143
133
|
const { params, set } = context
|
|
144
|
-
const
|
|
145
|
-
const found = sixb.
|
|
146
|
-
if (!found
|
|
134
|
+
const sixb = requireRequestSixb(context)
|
|
135
|
+
const found = sixb.projections.getById(params.projectionId)
|
|
136
|
+
if (!found) {
|
|
147
137
|
set.status = 404
|
|
148
138
|
return { error: `Projection '${params.projectionId}' not found` }
|
|
149
139
|
}
|
|
@@ -165,21 +155,19 @@ export function registerProjectionRoutes(app: Elysia, sixb: Sixb<readonly Ontolo
|
|
|
165
155
|
"/api/projection-runs",
|
|
166
156
|
async (context) => {
|
|
167
157
|
const { query, set } = context
|
|
168
|
-
const
|
|
158
|
+
const sixb = requireRequestSixb(context)
|
|
169
159
|
try {
|
|
170
|
-
const storage =
|
|
160
|
+
const storage = host.storage.projectionRuns
|
|
171
161
|
if (!storage) {
|
|
172
162
|
return unconfiguredStorageResponse(set, "Projection run storage")
|
|
173
163
|
}
|
|
174
164
|
|
|
175
165
|
const parsed = ProjectionRunsQuerySchema.parse(query)
|
|
176
|
-
const result = await
|
|
177
|
-
projectId: sixb.id,
|
|
166
|
+
const result = await sixb.projections.runs.list({
|
|
178
167
|
projectionId: parsed.projectionId,
|
|
179
168
|
projectionKind: parsed.projectionKind,
|
|
180
169
|
datasetId: parsed.datasetId,
|
|
181
170
|
datasetVersionId: parsed.datasetVersionId,
|
|
182
|
-
objectTypeIds: authz ? [...authz.grants["view:object"]] : undefined,
|
|
183
171
|
statuses: parsed.status ? [parsed.status] : undefined,
|
|
184
172
|
startedAfter: parseDate(parsed.startedAfter),
|
|
185
173
|
startedBefore: parseDate(parsed.startedBefore),
|
|
@@ -215,15 +203,15 @@ export function registerProjectionRoutes(app: Elysia, sixb: Sixb<readonly Ontolo
|
|
|
215
203
|
"/api/projection-runs/:runId",
|
|
216
204
|
async (context) => {
|
|
217
205
|
const { params, set } = context
|
|
218
|
-
const
|
|
206
|
+
const sixb = requireRequestSixb(context)
|
|
219
207
|
try {
|
|
220
|
-
const storage =
|
|
208
|
+
const storage = host.storage.projectionRuns
|
|
221
209
|
if (!storage) {
|
|
222
210
|
return unconfiguredStorageResponse(set, "Projection run storage")
|
|
223
211
|
}
|
|
224
212
|
|
|
225
|
-
const run = await
|
|
226
|
-
if (!run
|
|
213
|
+
const run = await sixb.projections.runs.getById(params.runId)
|
|
214
|
+
if (!run) {
|
|
227
215
|
set.status = 404
|
|
228
216
|
return { error: "Projection run not found" }
|
|
229
217
|
}
|
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,
|