@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,419 @@
|
|
|
1
|
+
import { type BlobInfo, type BlobStorage, type FileRef, isFileRef } from "@sixb/core"
|
|
2
|
+
import { BlobStorageError, supportsRangeRead } from "@sixb/core/blob-storage/server"
|
|
3
|
+
import { ZodError } from "zod"
|
|
4
|
+
|
|
5
|
+
export type FileContentDisposition = "inline" | "attachment"
|
|
6
|
+
|
|
7
|
+
export interface FileContentResponseInput {
|
|
8
|
+
readonly blobStorage: BlobStorage
|
|
9
|
+
readonly fileRef: FileRef
|
|
10
|
+
readonly disposition?: FileContentDisposition
|
|
11
|
+
readonly head?: boolean
|
|
12
|
+
readonly rangeHeader?: string | null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface FileContentQuery {
|
|
16
|
+
readonly path: string
|
|
17
|
+
readonly disposition?: FileContentDisposition
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ContextualFileContentResponseInput<TQuery extends FileContentQuery> {
|
|
21
|
+
readonly blobStorage: BlobStorage
|
|
22
|
+
readonly query: unknown
|
|
23
|
+
readonly querySchema: { parse(value: unknown): TQuery }
|
|
24
|
+
readonly request: Request
|
|
25
|
+
readonly set: { status?: number | string }
|
|
26
|
+
readonly head?: boolean
|
|
27
|
+
readonly resolveRoot: (query: TQuery) => Promise<unknown | null | undefined> | unknown | null
|
|
28
|
+
readonly hideError?: (error: unknown) => boolean
|
|
29
|
+
readonly missingMessage?: string
|
|
30
|
+
readonly invalidQueryMessage?: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Declared only by routes whose content lives behind an optional storage role
|
|
35
|
+
* (action runs, workflow runs, agent messages). Object file content is not one of
|
|
36
|
+
* them — object storage is mandatory — so this stays opt-in rather than being
|
|
37
|
+
* folded into the shared shape, or the schema would promise a status those routes
|
|
38
|
+
* can never return.
|
|
39
|
+
*/
|
|
40
|
+
const unconfiguredStorageResponse = {
|
|
41
|
+
501: {
|
|
42
|
+
description: "The storage role backing this content is not configured",
|
|
43
|
+
content: {
|
|
44
|
+
"application/json": {
|
|
45
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" },
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
} as const
|
|
50
|
+
|
|
51
|
+
export interface FileContentResponsesOptions {
|
|
52
|
+
/** Add the 501 the route returns when its storage role is absent. */
|
|
53
|
+
readonly optionalStorage?: boolean
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function fileContentGetResponses(options: FileContentResponsesOptions = {}) {
|
|
57
|
+
return {
|
|
58
|
+
200: {
|
|
59
|
+
description: "File content",
|
|
60
|
+
content: {
|
|
61
|
+
"application/octet-stream": {
|
|
62
|
+
schema: { type: "string", format: "binary" },
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
206: {
|
|
67
|
+
description: "Partial file content",
|
|
68
|
+
content: {
|
|
69
|
+
"application/octet-stream": {
|
|
70
|
+
schema: { type: "string", format: "binary" },
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
400: {
|
|
75
|
+
description: "Response for status 400",
|
|
76
|
+
content: {
|
|
77
|
+
"application/json": {
|
|
78
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" },
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
404: {
|
|
83
|
+
description: "Response for status 404",
|
|
84
|
+
content: {
|
|
85
|
+
"application/json": {
|
|
86
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" },
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
416: {
|
|
91
|
+
description: "Requested byte range is not satisfiable",
|
|
92
|
+
},
|
|
93
|
+
...(options.optionalStorage ? unconfiguredStorageResponse : {}),
|
|
94
|
+
} as const
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function fileContentHeadResponses(options: FileContentResponsesOptions = {}) {
|
|
98
|
+
return {
|
|
99
|
+
200: {
|
|
100
|
+
description: "File content headers",
|
|
101
|
+
},
|
|
102
|
+
206: {
|
|
103
|
+
description: "Partial file content headers",
|
|
104
|
+
},
|
|
105
|
+
400: {
|
|
106
|
+
description: "Response for status 400",
|
|
107
|
+
content: {
|
|
108
|
+
"application/json": {
|
|
109
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" },
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
404: {
|
|
114
|
+
description: "Response for status 404",
|
|
115
|
+
content: {
|
|
116
|
+
"application/json": {
|
|
117
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" },
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
416: {
|
|
122
|
+
description: "Requested byte range is not satisfiable",
|
|
123
|
+
},
|
|
124
|
+
...(options.optionalStorage ? unconfiguredStorageResponse : {}),
|
|
125
|
+
} as const
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export async function createFileContentResponse(
|
|
129
|
+
input: FileContentResponseInput
|
|
130
|
+
): Promise<Response | null> {
|
|
131
|
+
const stat = await input.blobStorage.stat(input.fileRef.blobId)
|
|
132
|
+
if (!stat || !blobMatchesFileRef(stat, input.fileRef)) {
|
|
133
|
+
return null
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const canReadRange = supportsRangeRead(input.blobStorage)
|
|
137
|
+
const headers = fileContentHeaders(input.fileRef, stat, input.disposition, canReadRange)
|
|
138
|
+
if (canReadRange && input.rangeHeader) {
|
|
139
|
+
const range = parseSingleByteRange(input.rangeHeader, stat.sizeBytes)
|
|
140
|
+
if (!range) {
|
|
141
|
+
return rangeNotSatisfiableResponse(stat.sizeBytes)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const partialHeaders = partialFileContentHeaders(headers, range, stat.sizeBytes)
|
|
145
|
+
if (input.head) {
|
|
146
|
+
return new Response(null, { status: 206, headers: partialHeaders })
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
const stream = await input.blobStorage.openRange(input.fileRef.blobId, range)
|
|
151
|
+
return new Response(stream, { status: 206, headers: partialHeaders })
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (error instanceof BlobStorageError) {
|
|
154
|
+
return null
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
throw error
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (input.head) {
|
|
162
|
+
return new Response(null, { headers })
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
const stream = await input.blobStorage.open(input.fileRef.blobId)
|
|
167
|
+
return new Response(stream, { headers })
|
|
168
|
+
} catch (error) {
|
|
169
|
+
if (error instanceof BlobStorageError) {
|
|
170
|
+
return null
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
throw error
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Serve a FileRef only through the record that contains it. Callers authorize the containing
|
|
179
|
+
* context first, then this helper validates the content-addressed FileRef before streaming.
|
|
180
|
+
*/
|
|
181
|
+
export async function createContextualFileContentResponse<TQuery extends FileContentQuery>(
|
|
182
|
+
input: ContextualFileContentResponseInput<TQuery>
|
|
183
|
+
): Promise<Response | { readonly error: string }> {
|
|
184
|
+
const missingMessage = input.missingMessage ?? "File not found"
|
|
185
|
+
const invalidQueryMessage = input.invalidQueryMessage ?? "Invalid file content query"
|
|
186
|
+
|
|
187
|
+
try {
|
|
188
|
+
const parsed = input.querySchema.parse(input.query)
|
|
189
|
+
const root = await input.resolveRoot(parsed)
|
|
190
|
+
if (root === null || root === undefined) {
|
|
191
|
+
return fileContentNotFound(input.set, missingMessage)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const fileRef = resolveFileRefAtPath(root, parsed.path)
|
|
195
|
+
if (!fileRef) {
|
|
196
|
+
return fileContentNotFound(input.set, missingMessage)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const response = await createFileContentResponse({
|
|
200
|
+
blobStorage: input.blobStorage,
|
|
201
|
+
fileRef,
|
|
202
|
+
disposition: parsed.disposition,
|
|
203
|
+
head: input.head,
|
|
204
|
+
rangeHeader: input.request.headers.get("range"),
|
|
205
|
+
})
|
|
206
|
+
if (!response) {
|
|
207
|
+
return fileContentNotFound(input.set, missingMessage)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return response
|
|
211
|
+
} catch (error) {
|
|
212
|
+
if (error instanceof ZodError) {
|
|
213
|
+
input.set.status = 400
|
|
214
|
+
return { error: invalidQueryMessage }
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (input.hideError?.(error)) {
|
|
218
|
+
return fileContentNotFound(input.set, missingMessage)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
throw error
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function resolveFileRefAtPath(root: unknown, path: string): FileRef | null {
|
|
226
|
+
const value = resolveJsonPointer(root, path)
|
|
227
|
+
return isFileRef(value) ? value : null
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function fileContentNotFound(
|
|
231
|
+
set: { status?: number | string },
|
|
232
|
+
message: string
|
|
233
|
+
): { readonly error: string } {
|
|
234
|
+
set.status = 404
|
|
235
|
+
return { error: message }
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function blobMatchesFileRef(stat: BlobInfo, fileRef: FileRef): boolean {
|
|
239
|
+
return (
|
|
240
|
+
stat.blobId === fileRef.blobId &&
|
|
241
|
+
stat.digest === fileRef.digest &&
|
|
242
|
+
stat.sizeBytes === fileRef.sizeBytes
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function resolveJsonPointer(root: unknown, pointer: string): unknown {
|
|
247
|
+
if (pointer === "") {
|
|
248
|
+
return root
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (!pointer.startsWith("/")) {
|
|
252
|
+
return undefined
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
let current = root
|
|
256
|
+
for (const rawSegment of pointer.slice(1).split("/")) {
|
|
257
|
+
const segment = decodeJsonPointerSegment(rawSegment)
|
|
258
|
+
if (Array.isArray(current)) {
|
|
259
|
+
const index = Number.parseInt(segment, 10)
|
|
260
|
+
if (!Number.isInteger(index) || index < 0 || index.toString() !== segment) {
|
|
261
|
+
return undefined
|
|
262
|
+
}
|
|
263
|
+
if (!Object.hasOwn(current, segment)) {
|
|
264
|
+
return undefined
|
|
265
|
+
}
|
|
266
|
+
current = current[index]
|
|
267
|
+
continue
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (typeof current !== "object" || current === null || !Object.hasOwn(current, segment)) {
|
|
271
|
+
return undefined
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
current = (current as Record<string, unknown>)[segment]
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return current
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function decodeJsonPointerSegment(segment: string): string {
|
|
281
|
+
return segment.replaceAll("~1", "/").replaceAll("~0", "~")
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function fileContentHeaders(
|
|
285
|
+
fileRef: FileRef,
|
|
286
|
+
stat: BlobInfo,
|
|
287
|
+
requestedDisposition: FileContentDisposition | undefined,
|
|
288
|
+
canReadRange: boolean
|
|
289
|
+
): Headers {
|
|
290
|
+
const mediaType = fileRef.mediaType?.trim() || "application/octet-stream"
|
|
291
|
+
const disposition =
|
|
292
|
+
(requestedDisposition ?? "inline") === "inline" && canRenderInline(mediaType)
|
|
293
|
+
? "inline"
|
|
294
|
+
: "attachment"
|
|
295
|
+
const headers = new Headers()
|
|
296
|
+
headers.set("content-type", mediaType)
|
|
297
|
+
headers.set("content-length", stat.sizeBytes.toString())
|
|
298
|
+
headers.set("content-disposition", contentDispositionHeader(disposition, fileNameFor(fileRef)))
|
|
299
|
+
headers.set("etag", `"${fileRef.digest}"`)
|
|
300
|
+
headers.set("x-content-type-options", "nosniff")
|
|
301
|
+
// Blobs are content-addressed and immutable, so responses can be cached
|
|
302
|
+
// aggressively — but only privately: reads are grant-enforced and must never
|
|
303
|
+
// land in a shared cache.
|
|
304
|
+
headers.set("cache-control", "private, max-age=31536000, immutable")
|
|
305
|
+
if (canReadRange) {
|
|
306
|
+
headers.set("accept-ranges", "bytes")
|
|
307
|
+
}
|
|
308
|
+
return headers
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
interface ParsedByteRange {
|
|
312
|
+
readonly start: number
|
|
313
|
+
readonly endInclusive: number
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function parseSingleByteRange(header: string, sizeBytes: number): ParsedByteRange | null {
|
|
317
|
+
const normalized = header.trim()
|
|
318
|
+
if (!normalized.startsWith("bytes=") || normalized.includes(",")) {
|
|
319
|
+
return null
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (sizeBytes <= 0) {
|
|
323
|
+
return null
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const spec = normalized.slice("bytes=".length).trim()
|
|
327
|
+
const match = spec.match(/^(\d*)-(\d*)$/)
|
|
328
|
+
if (!match) {
|
|
329
|
+
return null
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const [, rawStart, rawEnd] = match
|
|
333
|
+
if (!rawStart && !rawEnd) {
|
|
334
|
+
return null
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (!rawStart) {
|
|
338
|
+
const suffixLength = Number(rawEnd)
|
|
339
|
+
if (!Number.isSafeInteger(suffixLength) || suffixLength <= 0) {
|
|
340
|
+
return null
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return {
|
|
344
|
+
start: Math.max(sizeBytes - suffixLength, 0),
|
|
345
|
+
endInclusive: sizeBytes - 1,
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const start = Number(rawStart)
|
|
350
|
+
if (!Number.isSafeInteger(start) || start >= sizeBytes) {
|
|
351
|
+
return null
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const requestedEnd = rawEnd ? Number(rawEnd) : sizeBytes - 1
|
|
355
|
+
if (!Number.isSafeInteger(requestedEnd) || requestedEnd < start) {
|
|
356
|
+
return null
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return {
|
|
360
|
+
start,
|
|
361
|
+
endInclusive: Math.min(requestedEnd, sizeBytes - 1),
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function partialFileContentHeaders(
|
|
366
|
+
baseHeaders: Headers,
|
|
367
|
+
range: ParsedByteRange,
|
|
368
|
+
sizeBytes: number
|
|
369
|
+
): Headers {
|
|
370
|
+
const headers = new Headers(baseHeaders)
|
|
371
|
+
headers.set("content-length", (range.endInclusive - range.start + 1).toString())
|
|
372
|
+
headers.set("content-range", `bytes ${range.start}-${range.endInclusive}/${sizeBytes}`)
|
|
373
|
+
return headers
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function rangeNotSatisfiableResponse(sizeBytes: number): Response {
|
|
377
|
+
const headers = new Headers()
|
|
378
|
+
headers.set("accept-ranges", "bytes")
|
|
379
|
+
headers.set("content-range", `bytes */${sizeBytes}`)
|
|
380
|
+
return new Response(null, { status: 416, headers })
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function canRenderInline(mediaType: string): boolean {
|
|
384
|
+
const baseType = mediaType.split(";")[0]?.trim().toLowerCase()
|
|
385
|
+
if (!baseType) {
|
|
386
|
+
return false
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
if (
|
|
390
|
+
baseType === "text/html" ||
|
|
391
|
+
baseType === "image/svg+xml" ||
|
|
392
|
+
baseType === "application/xhtml+xml"
|
|
393
|
+
) {
|
|
394
|
+
return false
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
return (
|
|
398
|
+
baseType === "application/pdf" ||
|
|
399
|
+
baseType === "text/plain" ||
|
|
400
|
+
baseType === "text/markdown" ||
|
|
401
|
+
baseType === "application/json" ||
|
|
402
|
+
baseType.startsWith("image/")
|
|
403
|
+
)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function fileNameFor(fileRef: FileRef): string {
|
|
407
|
+
const fromFileName = fileRef.fileName?.split(/[\\/]/).filter(Boolean).at(-1)
|
|
408
|
+
if (fromFileName) {
|
|
409
|
+
return fromFileName
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const fromLogicalPath = fileRef.logicalPath?.split(/[\\/]/).filter(Boolean).at(-1)
|
|
413
|
+
return fromLogicalPath || `${fileRef.blobId}.bin`
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function contentDispositionHeader(disposition: FileContentDisposition, fileName: string): string {
|
|
417
|
+
const asciiFileName = fileName.replace(/[^\x20-\x7e]/g, "_").replaceAll('"', "'")
|
|
418
|
+
return `${disposition}; filename="${asciiFileName}"; filename*=UTF-8''${encodeURIComponent(fileName)}`
|
|
419
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CSRF_HEADER_NAME } from "@sixb/core/internal/auth"
|
|
2
|
+
|
|
3
|
+
export const SIXB_CSRF_SECURITY_SCHEME_ID = "sixbCsrf"
|
|
4
|
+
export const SIXB_BEARER_SECURITY_SCHEME_ID = "sixbBearer"
|
|
5
|
+
|
|
6
|
+
export const SIXB_CSRF_SECURITY_REQUIREMENT = [
|
|
7
|
+
{
|
|
8
|
+
[SIXB_CSRF_SECURITY_SCHEME_ID]: [] as string[],
|
|
9
|
+
},
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
export const SIXB_BEARER_SECURITY_REQUIREMENT = [
|
|
13
|
+
{
|
|
14
|
+
[SIXB_BEARER_SECURITY_SCHEME_ID]: [] as string[],
|
|
15
|
+
},
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
export const SIXB_CSRF_OR_BEARER_SECURITY_REQUIREMENT = [
|
|
19
|
+
...SIXB_CSRF_SECURITY_REQUIREMENT,
|
|
20
|
+
...SIXB_BEARER_SECURITY_REQUIREMENT,
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
export const SIXB_CSRF_SECURITY_SCHEME = {
|
|
24
|
+
type: "apiKey",
|
|
25
|
+
in: "header",
|
|
26
|
+
name: CSRF_HEADER_NAME,
|
|
27
|
+
description:
|
|
28
|
+
"Required for authenticated mutating requests. Use the csrfToken returned by GET /api/auth/session.",
|
|
29
|
+
} as const
|
|
30
|
+
|
|
31
|
+
export const SIXB_BEARER_SECURITY_SCHEME = {
|
|
32
|
+
type: "http",
|
|
33
|
+
scheme: "bearer",
|
|
34
|
+
bearerFormat: "Sixb access token",
|
|
35
|
+
description:
|
|
36
|
+
"Use a Sixb personal access token or service-account token. Bearer tokens are accepted only on routes that explicitly document this scheme.",
|
|
37
|
+
} as const
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
export const OPENAPI_TAGS = {
|
|
2
|
+
project: {
|
|
3
|
+
name: "Project",
|
|
4
|
+
description: "Current project metadata",
|
|
5
|
+
},
|
|
6
|
+
status: {
|
|
7
|
+
name: "Status",
|
|
8
|
+
description: "Runtime status",
|
|
9
|
+
},
|
|
10
|
+
ontology: {
|
|
11
|
+
name: "Ontology",
|
|
12
|
+
description: "Object type definitions",
|
|
13
|
+
},
|
|
14
|
+
connectors: {
|
|
15
|
+
name: "Connectors",
|
|
16
|
+
description: "Connector metadata and webhook routes",
|
|
17
|
+
},
|
|
18
|
+
webhooks: {
|
|
19
|
+
name: "Webhooks",
|
|
20
|
+
description: "Webhook run history",
|
|
21
|
+
},
|
|
22
|
+
datasets: {
|
|
23
|
+
name: "Datasets",
|
|
24
|
+
description: "Dataset definitions",
|
|
25
|
+
},
|
|
26
|
+
datasetVersions: {
|
|
27
|
+
name: "Dataset Versions",
|
|
28
|
+
description: "Dataset version history",
|
|
29
|
+
},
|
|
30
|
+
datasetRows: {
|
|
31
|
+
name: "Dataset Rows",
|
|
32
|
+
description: "Dataset row previews",
|
|
33
|
+
},
|
|
34
|
+
syncs: {
|
|
35
|
+
name: "Syncs",
|
|
36
|
+
description: "Sync metadata",
|
|
37
|
+
},
|
|
38
|
+
syncRuns: {
|
|
39
|
+
name: "Sync Runs",
|
|
40
|
+
description: "Sync run history and requests",
|
|
41
|
+
},
|
|
42
|
+
pipelines: {
|
|
43
|
+
name: "Pipelines",
|
|
44
|
+
description: "Pipeline metadata",
|
|
45
|
+
},
|
|
46
|
+
pipelineRuns: {
|
|
47
|
+
name: "Pipeline Runs",
|
|
48
|
+
description: "Pipeline run history and requests",
|
|
49
|
+
},
|
|
50
|
+
workflows: {
|
|
51
|
+
name: "Workflows",
|
|
52
|
+
description: "Workflow metadata",
|
|
53
|
+
},
|
|
54
|
+
workflowRuns: {
|
|
55
|
+
name: "Workflow Runs",
|
|
56
|
+
description: "Workflow run history and requests",
|
|
57
|
+
},
|
|
58
|
+
workflowInterventions: {
|
|
59
|
+
name: "Workflow Interventions",
|
|
60
|
+
description: "Workflow intervention tasks",
|
|
61
|
+
},
|
|
62
|
+
rules: {
|
|
63
|
+
name: "Rules",
|
|
64
|
+
description: "Rule definitions",
|
|
65
|
+
},
|
|
66
|
+
ruleStates: {
|
|
67
|
+
name: "Rule States",
|
|
68
|
+
description: "Active rule states",
|
|
69
|
+
},
|
|
70
|
+
projections: {
|
|
71
|
+
name: "Projections",
|
|
72
|
+
description: "Projection definitions",
|
|
73
|
+
},
|
|
74
|
+
projectionRuns: {
|
|
75
|
+
name: "Projection Runs",
|
|
76
|
+
description: "Projection run history",
|
|
77
|
+
},
|
|
78
|
+
objects: {
|
|
79
|
+
name: "Objects",
|
|
80
|
+
description: "Twin objects and state",
|
|
81
|
+
},
|
|
82
|
+
objectFiles: {
|
|
83
|
+
name: "Object Files",
|
|
84
|
+
description: "Object-backed file content",
|
|
85
|
+
},
|
|
86
|
+
actions: {
|
|
87
|
+
name: "Actions",
|
|
88
|
+
description: "Action metadata and requests",
|
|
89
|
+
},
|
|
90
|
+
actionRuns: {
|
|
91
|
+
name: "Action Runs",
|
|
92
|
+
description: "Action run history",
|
|
93
|
+
},
|
|
94
|
+
agents: {
|
|
95
|
+
name: "Agents",
|
|
96
|
+
description: "Agent catalog",
|
|
97
|
+
},
|
|
98
|
+
agentThreads: {
|
|
99
|
+
name: "Agent Threads",
|
|
100
|
+
description: "Agent conversation threads and messages",
|
|
101
|
+
},
|
|
102
|
+
agentRuns: {
|
|
103
|
+
name: "Agent Runs",
|
|
104
|
+
description: "Agent run state and cancellation",
|
|
105
|
+
},
|
|
106
|
+
files: {
|
|
107
|
+
name: "Files",
|
|
108
|
+
description: "File uploads and file references",
|
|
109
|
+
},
|
|
110
|
+
links: {
|
|
111
|
+
name: "Links",
|
|
112
|
+
description: "Object relationship links",
|
|
113
|
+
},
|
|
114
|
+
telemetry: {
|
|
115
|
+
name: "Telemetry",
|
|
116
|
+
description: "Telemetry history and appends",
|
|
117
|
+
},
|
|
118
|
+
events: {
|
|
119
|
+
name: "Events",
|
|
120
|
+
description: "Domain event stream",
|
|
121
|
+
},
|
|
122
|
+
logs: {
|
|
123
|
+
name: "Logs",
|
|
124
|
+
description: "Run log stream",
|
|
125
|
+
},
|
|
126
|
+
authSessions: {
|
|
127
|
+
name: "Auth Sessions",
|
|
128
|
+
description: "Authentication sessions and sign-out",
|
|
129
|
+
},
|
|
130
|
+
authMembers: {
|
|
131
|
+
name: "Auth Members",
|
|
132
|
+
description: "User membership administration",
|
|
133
|
+
},
|
|
134
|
+
authInvitations: {
|
|
135
|
+
name: "Auth Invitations",
|
|
136
|
+
description: "User invitations",
|
|
137
|
+
},
|
|
138
|
+
authAccessTokens: {
|
|
139
|
+
name: "Auth Access Tokens",
|
|
140
|
+
description: "Personal access-token management",
|
|
141
|
+
},
|
|
142
|
+
authServiceAccounts: {
|
|
143
|
+
name: "Auth Service Accounts",
|
|
144
|
+
description: "Service accounts and service-account access tokens",
|
|
145
|
+
},
|
|
146
|
+
} as const
|
|
147
|
+
|
|
148
|
+
export const OPENAPI_TAG_METADATA = Object.values(OPENAPI_TAGS).map(({ name, description }) => ({
|
|
149
|
+
name,
|
|
150
|
+
description,
|
|
151
|
+
}))
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { OntologySource, Sixb } from "@sixb/core"
|
|
2
|
+
import type { Elysia } from "elysia"
|
|
3
|
+
import { registerActionRunRoutes } from "./routes/action-runs"
|
|
4
|
+
import { registerActionRoutes } from "./routes/actions"
|
|
5
|
+
import { registerAgentApiGatewayRoutes } from "./routes/agent-api-gateway"
|
|
6
|
+
import { registerAgentRoutes } from "./routes/agents"
|
|
7
|
+
import { registerConnectorRoutes } from "./routes/connectors"
|
|
8
|
+
import { registerDatasetRoutes } from "./routes/datasets"
|
|
9
|
+
import { registerEventRoutes } from "./routes/events"
|
|
10
|
+
import { registerFileRoutes } from "./routes/files"
|
|
11
|
+
import { registerLinkRoutes } from "./routes/links"
|
|
12
|
+
import { registerLogRoutes } from "./routes/logs"
|
|
13
|
+
import { registerObjectRoutes } from "./routes/objects"
|
|
14
|
+
import { registerOntologyRoutes } from "./routes/ontology"
|
|
15
|
+
import { registerPipelineRoutes } from "./routes/pipelines"
|
|
16
|
+
import { registerProjectRoutes } from "./routes/project"
|
|
17
|
+
import { registerProjectionRoutes } from "./routes/projections"
|
|
18
|
+
import { registerRuleRoutes } from "./routes/rules"
|
|
19
|
+
import { registerStatusRoutes } from "./routes/status"
|
|
20
|
+
import { registerSyncRoutes } from "./routes/syncs"
|
|
21
|
+
import { registerTelemetryRoutes } from "./routes/telemetry"
|
|
22
|
+
import { registerWebhookRunRoutes } from "./routes/webhook-runs"
|
|
23
|
+
import { registerWorkflowRoutes } from "./routes/workflows"
|
|
24
|
+
|
|
25
|
+
export function registerHttpRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
|
|
26
|
+
registerAgentApiGatewayRoutes(app, sixb)
|
|
27
|
+
registerProjectRoutes(app, sixb)
|
|
28
|
+
registerStatusRoutes(app, sixb)
|
|
29
|
+
registerConnectorRoutes(app, sixb)
|
|
30
|
+
registerDatasetRoutes(app, sixb)
|
|
31
|
+
registerSyncRoutes(app, sixb)
|
|
32
|
+
registerPipelineRoutes(app, sixb)
|
|
33
|
+
registerWorkflowRoutes(app, sixb)
|
|
34
|
+
registerRuleRoutes(app, sixb)
|
|
35
|
+
registerOntologyRoutes(app, sixb)
|
|
36
|
+
registerObjectRoutes(app, sixb)
|
|
37
|
+
registerActionRoutes(app, sixb)
|
|
38
|
+
registerFileRoutes(app, sixb)
|
|
39
|
+
registerActionRunRoutes(app, sixb)
|
|
40
|
+
registerAgentRoutes(app, sixb)
|
|
41
|
+
registerLinkRoutes(app, sixb)
|
|
42
|
+
registerTelemetryRoutes(app, sixb)
|
|
43
|
+
registerEventRoutes(app, sixb)
|
|
44
|
+
registerLogRoutes(app, sixb)
|
|
45
|
+
registerProjectionRoutes(app, sixb)
|
|
46
|
+
registerWebhookRunRoutes(app, sixb)
|
|
47
|
+
|
|
48
|
+
return app
|
|
49
|
+
}
|