@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,207 @@
|
|
|
1
|
+
import { isAllowed, type OntologySource, type Sixb } from "@sixb/core"
|
|
2
|
+
import { getTelemetryHistoryBatch } from "@sixb/core/internal/objects"
|
|
3
|
+
import type { TimeseriesPoint } from "@sixb/core/storage"
|
|
4
|
+
import type { Elysia } from "elysia"
|
|
5
|
+
import { bearerSecurityRequirement } from "../auth/access-token-boundary"
|
|
6
|
+
import { requestAuthState } from "../auth/scope"
|
|
7
|
+
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
8
|
+
import { ErrorResponseSchema, SuccessResponseSchema } from "../schemas/common"
|
|
9
|
+
import {
|
|
10
|
+
AppendTelemetryBodySchema,
|
|
11
|
+
BulkTelemetryHistoryBodySchema,
|
|
12
|
+
BulkTelemetryHistoryResponseSchema,
|
|
13
|
+
TelemetryHistoryQuerySchema,
|
|
14
|
+
TelemetryParamsSchema,
|
|
15
|
+
TelemetryPointSchema,
|
|
16
|
+
} from "../schemas/telemetry"
|
|
17
|
+
import { handleRouteError, parseDate, parseOptionalInt, toIsoString } from "../utils/http"
|
|
18
|
+
|
|
19
|
+
function serializeTelemetryPoint(point: TimeseriesPoint) {
|
|
20
|
+
return {
|
|
21
|
+
projectId: point.projectId,
|
|
22
|
+
objectTypeId: point.objectTypeId,
|
|
23
|
+
objectId: point.objectId,
|
|
24
|
+
propertyId: point.propertyId,
|
|
25
|
+
value: point.value,
|
|
26
|
+
...(point.unit === undefined ? {} : { unit: point.unit }),
|
|
27
|
+
at: toIsoString(point.at),
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function registerTelemetryRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
|
|
32
|
+
return app
|
|
33
|
+
.post(
|
|
34
|
+
"/api/objects/:objectTypeId/:objectId/telemetry/:propertyId",
|
|
35
|
+
async (context) => {
|
|
36
|
+
const { params, body, set } = context
|
|
37
|
+
const { scoped } = requestAuthState(context)
|
|
38
|
+
try {
|
|
39
|
+
const parsedBody = AppendTelemetryBodySchema.parse(body)
|
|
40
|
+
await (scoped ?? sixb).appendTelemetry(params.objectTypeId, [
|
|
41
|
+
{
|
|
42
|
+
id: params.objectId,
|
|
43
|
+
properties: {
|
|
44
|
+
[params.propertyId]: parsedBody.unit
|
|
45
|
+
? { value: parsedBody.value, unit: parsedBody.unit }
|
|
46
|
+
: parsedBody.value,
|
|
47
|
+
},
|
|
48
|
+
at: parseDate(parsedBody.at),
|
|
49
|
+
},
|
|
50
|
+
])
|
|
51
|
+
|
|
52
|
+
return { success: true }
|
|
53
|
+
} catch (error) {
|
|
54
|
+
return handleRouteError(error, set)
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
params: TelemetryParamsSchema,
|
|
59
|
+
body: AppendTelemetryBodySchema,
|
|
60
|
+
response: {
|
|
61
|
+
200: SuccessResponseSchema,
|
|
62
|
+
400: ErrorResponseSchema,
|
|
63
|
+
403: ErrorResponseSchema,
|
|
64
|
+
404: ErrorResponseSchema,
|
|
65
|
+
},
|
|
66
|
+
detail: {
|
|
67
|
+
summary: "Append telemetry point",
|
|
68
|
+
tags: [OPENAPI_TAGS.telemetry.name],
|
|
69
|
+
operationId: "appendTelemetry",
|
|
70
|
+
security: bearerSecurityRequirement("appendTelemetry"),
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
.post(
|
|
75
|
+
"/api/telemetry/history",
|
|
76
|
+
async (context) => {
|
|
77
|
+
const { body, set } = context
|
|
78
|
+
const { authz } = requestAuthState(context)
|
|
79
|
+
try {
|
|
80
|
+
const parsedBody = BulkTelemetryHistoryBodySchema.parse(body)
|
|
81
|
+
const from = parseDate(parsedBody.from)
|
|
82
|
+
const to = parseDate(parsedBody.to)
|
|
83
|
+
const history = await getTelemetryHistoryBatch(
|
|
84
|
+
{
|
|
85
|
+
projectId: sixb.id,
|
|
86
|
+
series: parsedBody.series,
|
|
87
|
+
from,
|
|
88
|
+
to,
|
|
89
|
+
limitPerSeries: parsedBody.limitPerSeries,
|
|
90
|
+
order: parsedBody.order,
|
|
91
|
+
},
|
|
92
|
+
{ storage: sixb.storage.timeseries, authorization: authz }
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
series: history.map((series) => ({
|
|
97
|
+
...series,
|
|
98
|
+
points: series.points.map(serializeTelemetryPoint),
|
|
99
|
+
})),
|
|
100
|
+
}
|
|
101
|
+
} catch (error) {
|
|
102
|
+
return handleRouteError(error, set)
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
body: BulkTelemetryHistoryBodySchema,
|
|
107
|
+
response: {
|
|
108
|
+
200: BulkTelemetryHistoryResponseSchema,
|
|
109
|
+
400: ErrorResponseSchema,
|
|
110
|
+
403: ErrorResponseSchema,
|
|
111
|
+
},
|
|
112
|
+
detail: {
|
|
113
|
+
summary: "Get bulk telemetry history",
|
|
114
|
+
tags: [OPENAPI_TAGS.telemetry.name],
|
|
115
|
+
operationId: "getBulkTelemetryHistory",
|
|
116
|
+
security: bearerSecurityRequirement("getBulkTelemetryHistory"),
|
|
117
|
+
},
|
|
118
|
+
}
|
|
119
|
+
)
|
|
120
|
+
.get(
|
|
121
|
+
"/api/objects/:objectTypeId/:objectId/telemetry/:propertyId/history",
|
|
122
|
+
async (context) => {
|
|
123
|
+
const { params, query, set } = context
|
|
124
|
+
const { authz } = requestAuthState(context)
|
|
125
|
+
try {
|
|
126
|
+
const parsedQuery = TelemetryHistoryQuerySchema.parse(query)
|
|
127
|
+
if (!isAllowed(authz, { kind: "object.view", objectTypeId: params.objectTypeId })) {
|
|
128
|
+
set.status = 404
|
|
129
|
+
return { error: "Object not found" }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const history = await sixb.storage.timeseries.getHistory({
|
|
133
|
+
projectId: sixb.id,
|
|
134
|
+
objectTypeId: params.objectTypeId,
|
|
135
|
+
objectId: params.objectId,
|
|
136
|
+
propertyId: params.propertyId,
|
|
137
|
+
from: parseDate(parsedQuery.from),
|
|
138
|
+
to: parseDate(parsedQuery.to),
|
|
139
|
+
limit: parseOptionalInt(parsedQuery.limit),
|
|
140
|
+
order: parsedQuery.order,
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
return history.map(serializeTelemetryPoint)
|
|
144
|
+
} catch (error) {
|
|
145
|
+
return handleRouteError(error, set)
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
params: TelemetryParamsSchema,
|
|
150
|
+
query: TelemetryHistoryQuerySchema,
|
|
151
|
+
response: {
|
|
152
|
+
200: TelemetryPointSchema.array(),
|
|
153
|
+
400: ErrorResponseSchema,
|
|
154
|
+
404: ErrorResponseSchema,
|
|
155
|
+
},
|
|
156
|
+
detail: {
|
|
157
|
+
summary: "Get telemetry history",
|
|
158
|
+
tags: [OPENAPI_TAGS.telemetry.name],
|
|
159
|
+
operationId: "getTelemetryHistory",
|
|
160
|
+
security: bearerSecurityRequirement("getTelemetryHistory"),
|
|
161
|
+
},
|
|
162
|
+
}
|
|
163
|
+
)
|
|
164
|
+
.get(
|
|
165
|
+
"/api/objects/:objectTypeId/:objectId/telemetry/:propertyId/latest",
|
|
166
|
+
async (context) => {
|
|
167
|
+
const { params, set } = context
|
|
168
|
+
const { authz } = requestAuthState(context)
|
|
169
|
+
try {
|
|
170
|
+
if (!isAllowed(authz, { kind: "object.view", objectTypeId: params.objectTypeId })) {
|
|
171
|
+
set.status = 404
|
|
172
|
+
return { error: "Object not found" }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const latest = await sixb.storage.timeseries.getLatest({
|
|
176
|
+
projectId: sixb.id,
|
|
177
|
+
objectTypeId: params.objectTypeId,
|
|
178
|
+
objectId: params.objectId,
|
|
179
|
+
propertyId: params.propertyId,
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
if (!latest) {
|
|
183
|
+
set.status = 404
|
|
184
|
+
return { error: "Telemetry point not found" }
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return serializeTelemetryPoint(latest)
|
|
188
|
+
} catch (error) {
|
|
189
|
+
return handleRouteError(error, set)
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
params: TelemetryParamsSchema,
|
|
194
|
+
response: {
|
|
195
|
+
200: TelemetryPointSchema,
|
|
196
|
+
400: ErrorResponseSchema,
|
|
197
|
+
404: ErrorResponseSchema,
|
|
198
|
+
},
|
|
199
|
+
detail: {
|
|
200
|
+
summary: "Get latest telemetry point",
|
|
201
|
+
tags: [OPENAPI_TAGS.telemetry.name],
|
|
202
|
+
operationId: "getLatestTelemetry",
|
|
203
|
+
security: bearerSecurityRequirement("getLatestTelemetry"),
|
|
204
|
+
},
|
|
205
|
+
}
|
|
206
|
+
)
|
|
207
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { OntologySource, Sixb } from "@sixb/core"
|
|
2
|
+
import type { WebhookRunRecord } from "@sixb/core/storage"
|
|
3
|
+
import type { Elysia } from "elysia"
|
|
4
|
+
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
5
|
+
import { ErrorResponseSchema } from "../schemas/common"
|
|
6
|
+
import { WebhookRunListResponseSchema, WebhookRunsQuerySchema } from "../schemas/webhook-runs"
|
|
7
|
+
import {
|
|
8
|
+
handleRouteError,
|
|
9
|
+
parseDate,
|
|
10
|
+
parseOptionalInt,
|
|
11
|
+
toIsoString,
|
|
12
|
+
unconfiguredStorageResponse,
|
|
13
|
+
} from "../utils/http"
|
|
14
|
+
|
|
15
|
+
function serializeWebhookRun(run: WebhookRunRecord) {
|
|
16
|
+
return {
|
|
17
|
+
id: run.id,
|
|
18
|
+
projectId: run.projectId,
|
|
19
|
+
connectorId: run.connectorId,
|
|
20
|
+
webhookId: run.webhookId,
|
|
21
|
+
status: run.status,
|
|
22
|
+
method: run.method,
|
|
23
|
+
route: run.route,
|
|
24
|
+
startedAt: toIsoString(run.startedAt),
|
|
25
|
+
finishedAt: run.finishedAt ? toIsoString(run.finishedAt) : undefined,
|
|
26
|
+
requestBodyBytes: run.requestBodyBytes,
|
|
27
|
+
responseStatus: run.responseStatus,
|
|
28
|
+
idempotencyKey: run.idempotencyKey,
|
|
29
|
+
deliveryClaimResult: run.deliveryClaimResult,
|
|
30
|
+
error: run.error,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function registerWebhookRunRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
|
|
35
|
+
return app.get(
|
|
36
|
+
"/api/webhook-runs",
|
|
37
|
+
async ({ query, set }) => {
|
|
38
|
+
try {
|
|
39
|
+
const parsed = WebhookRunsQuerySchema.parse(query)
|
|
40
|
+
const storage = sixb.storage.webhookRuns
|
|
41
|
+
if (!storage) {
|
|
42
|
+
return unconfiguredStorageResponse(set, "Webhook run storage")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const result = await storage.list({
|
|
46
|
+
projectId: sixb.id,
|
|
47
|
+
connectorId: parsed.connectorId,
|
|
48
|
+
webhookId: parsed.webhookId,
|
|
49
|
+
statuses: parsed.status ? [parsed.status] : undefined,
|
|
50
|
+
idempotencyKey: parsed.idempotencyKey,
|
|
51
|
+
startedAfter: parseDate(parsed.startedAfter),
|
|
52
|
+
startedBefore: parseDate(parsed.startedBefore),
|
|
53
|
+
limit: parseOptionalInt(parsed.limit),
|
|
54
|
+
offset: parseOptionalInt(parsed.offset),
|
|
55
|
+
order: parsed.order,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
runs: result.runs.map(serializeWebhookRun),
|
|
60
|
+
hasMore: result.hasMore,
|
|
61
|
+
total: result.total,
|
|
62
|
+
}
|
|
63
|
+
} catch (error) {
|
|
64
|
+
return handleRouteError(error, set)
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
query: WebhookRunsQuerySchema,
|
|
69
|
+
response: {
|
|
70
|
+
200: WebhookRunListResponseSchema,
|
|
71
|
+
400: ErrorResponseSchema,
|
|
72
|
+
501: ErrorResponseSchema,
|
|
73
|
+
},
|
|
74
|
+
detail: {
|
|
75
|
+
summary: "List webhook run history",
|
|
76
|
+
tags: [OPENAPI_TAGS.webhooks.name],
|
|
77
|
+
operationId: "listWebhookRuns",
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
}
|