@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
package/src/schemas/workflows.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type SixbFailure,
|
|
3
|
+
WORKFLOW_RUN_FAILURE_CODES,
|
|
4
|
+
type WorkflowRunFailureCode,
|
|
5
|
+
} from "@sixb/core/storage"
|
|
1
6
|
import { z } from "zod"
|
|
7
|
+
import { AgentRunFailureSchema } from "./agents"
|
|
8
|
+
import { AiUsageSummarySchema } from "./ai-usage"
|
|
9
|
+
import { JsonValueSchema, sixbFailureSchema } from "./common"
|
|
10
|
+
|
|
11
|
+
export const WorkflowIOSnapshotSchema = z.record(JsonValueSchema)
|
|
12
|
+
|
|
13
|
+
const WorkflowRunFailureSchema: z.ZodType<SixbFailure<WorkflowRunFailureCode>> = sixbFailureSchema(
|
|
14
|
+
WORKFLOW_RUN_FAILURE_CODES
|
|
15
|
+
)
|
|
2
16
|
|
|
3
17
|
export const WorkflowParamsSchema = z.object({
|
|
4
18
|
workflowId: z.string().min(1),
|
|
@@ -55,7 +69,7 @@ export const WorkflowInterventionsQuerySchema = z.object({
|
|
|
55
69
|
|
|
56
70
|
export const RequestWorkflowRunBodySchema = z
|
|
57
71
|
.object({
|
|
58
|
-
input:
|
|
72
|
+
input: WorkflowIOSnapshotSchema.optional(),
|
|
59
73
|
})
|
|
60
74
|
.default({})
|
|
61
75
|
|
|
@@ -67,7 +81,7 @@ export const WorkflowInterventionActorSchema = z.object({
|
|
|
67
81
|
export const CancelWorkflowRunBodySchema = z.object({}).default({})
|
|
68
82
|
|
|
69
83
|
export const SubmitWorkflowInterventionBodySchema = z.object({
|
|
70
|
-
response:
|
|
84
|
+
response: WorkflowIOSnapshotSchema,
|
|
71
85
|
})
|
|
72
86
|
|
|
73
87
|
export const CancelWorkflowInterventionBodySchema = z.object({}).default({})
|
|
@@ -82,22 +96,22 @@ const WorkflowNodeSchema = z.union([
|
|
|
82
96
|
type: z.literal("step"),
|
|
83
97
|
id: z.string(),
|
|
84
98
|
key: z.string(),
|
|
85
|
-
input:
|
|
86
|
-
output:
|
|
99
|
+
input: WorkflowIOSnapshotSchema,
|
|
100
|
+
output: WorkflowIOSnapshotSchema,
|
|
87
101
|
}),
|
|
88
102
|
z.object({
|
|
89
103
|
type: z.literal("action"),
|
|
90
104
|
id: z.string(),
|
|
91
105
|
key: z.string(),
|
|
92
106
|
objectTypeId: z.string().optional(),
|
|
93
|
-
params:
|
|
107
|
+
params: WorkflowIOSnapshotSchema,
|
|
94
108
|
}),
|
|
95
109
|
z.object({
|
|
96
110
|
type: z.literal("intervention"),
|
|
97
111
|
id: z.string(),
|
|
98
112
|
key: z.string(),
|
|
99
|
-
input:
|
|
100
|
-
response:
|
|
113
|
+
input: WorkflowIOSnapshotSchema,
|
|
114
|
+
response: WorkflowIOSnapshotSchema,
|
|
101
115
|
description: z.string().optional(),
|
|
102
116
|
}),
|
|
103
117
|
z.object({
|
|
@@ -105,31 +119,35 @@ const WorkflowNodeSchema = z.union([
|
|
|
105
119
|
id: z.string(),
|
|
106
120
|
key: z.string(),
|
|
107
121
|
agentId: z.string(),
|
|
108
|
-
input:
|
|
109
|
-
output:
|
|
122
|
+
input: WorkflowIOSnapshotSchema,
|
|
123
|
+
output: WorkflowIOSnapshotSchema,
|
|
110
124
|
}),
|
|
111
125
|
])
|
|
112
126
|
|
|
113
|
-
export const
|
|
127
|
+
export const WorkflowRunSummarySchema = z.object({
|
|
114
128
|
id: z.string(),
|
|
115
129
|
projectId: z.string(),
|
|
116
130
|
workflowId: z.string(),
|
|
117
131
|
status: WorkflowRunStatusSchema,
|
|
118
|
-
input: z.record(z.unknown()),
|
|
119
132
|
queuedAt: z.string().optional(),
|
|
120
133
|
startedAt: z.string(),
|
|
121
134
|
finishedAt: z.string().optional(),
|
|
122
|
-
error:
|
|
135
|
+
error: WorkflowRunFailureSchema.optional(),
|
|
123
136
|
requestedBy: WorkflowInterventionActorSchema,
|
|
124
137
|
})
|
|
125
138
|
|
|
139
|
+
export const WorkflowRunDetailSchema = WorkflowRunSummarySchema.extend({
|
|
140
|
+
input: WorkflowIOSnapshotSchema,
|
|
141
|
+
output: WorkflowIOSnapshotSchema.optional(),
|
|
142
|
+
})
|
|
143
|
+
|
|
126
144
|
export const WorkflowAgentNodeExecutionSummarySchema = z.object({
|
|
127
145
|
agentId: z.string(),
|
|
128
146
|
status: z.enum(["queued", "running", "succeeded", "failed", "cancelled"]),
|
|
129
147
|
attempt: z.number().int().nonnegative(),
|
|
130
148
|
modelId: z.string().optional(),
|
|
131
149
|
finishReason: z.string().optional(),
|
|
132
|
-
usage:
|
|
150
|
+
usage: AiUsageSummarySchema.optional(),
|
|
133
151
|
startedAt: z.string().optional(),
|
|
134
152
|
completedAt: z.string().optional(),
|
|
135
153
|
})
|
|
@@ -137,10 +155,9 @@ export const WorkflowAgentNodeExecutionSummarySchema = z.object({
|
|
|
137
155
|
export const WorkflowAgentNodeExecutionSchema = WorkflowAgentNodeExecutionSummarySchema.extend({
|
|
138
156
|
nodeRunId: z.string(),
|
|
139
157
|
prompt: z.string(),
|
|
140
|
-
executionPrincipal: WorkflowInterventionActorSchema.optional(),
|
|
141
158
|
trace: z.array(z.unknown()).optional(),
|
|
142
159
|
diagnostics: z.array(z.unknown()).optional(),
|
|
143
|
-
error:
|
|
160
|
+
error: AgentRunFailureSchema.optional(),
|
|
144
161
|
createdAt: z.string(),
|
|
145
162
|
})
|
|
146
163
|
|
|
@@ -154,11 +171,11 @@ export const WorkflowNodeRunSchema = z.object({
|
|
|
154
171
|
nodeId: z.string(),
|
|
155
172
|
nodeKey: z.string(),
|
|
156
173
|
status: z.enum(["running", "waiting", "succeeded", "failed", "cancelled"]),
|
|
157
|
-
input:
|
|
174
|
+
input: WorkflowIOSnapshotSchema,
|
|
158
175
|
startedAt: z.string(),
|
|
159
176
|
finishedAt: z.string().optional(),
|
|
160
|
-
output:
|
|
161
|
-
error:
|
|
177
|
+
output: WorkflowIOSnapshotSchema.optional(),
|
|
178
|
+
error: WorkflowRunFailureSchema.optional(),
|
|
162
179
|
agentExecution: WorkflowAgentNodeExecutionSummarySchema.optional(),
|
|
163
180
|
})
|
|
164
181
|
|
|
@@ -172,14 +189,14 @@ export const WorkflowInterventionSchema = z.object({
|
|
|
172
189
|
nodeId: z.string(),
|
|
173
190
|
nodeKey: z.string(),
|
|
174
191
|
interventionId: z.string(),
|
|
175
|
-
input:
|
|
176
|
-
defaultResponse:
|
|
192
|
+
input: WorkflowIOSnapshotSchema,
|
|
193
|
+
defaultResponse: WorkflowIOSnapshotSchema,
|
|
177
194
|
status: WorkflowInterventionStatusSchema,
|
|
178
195
|
requestedAt: z.string(),
|
|
179
196
|
expiresAt: z.string().optional(),
|
|
180
197
|
submittedAt: z.string().optional(),
|
|
181
198
|
submittedBy: WorkflowInterventionActorSchema.optional(),
|
|
182
|
-
response:
|
|
199
|
+
response: WorkflowIOSnapshotSchema.optional(),
|
|
183
200
|
cancelledAt: z.string().optional(),
|
|
184
201
|
cancelledBy: WorkflowInterventionActorSchema.optional(),
|
|
185
202
|
expiredAt: z.string().optional(),
|
|
@@ -187,20 +204,20 @@ export const WorkflowInterventionSchema = z.object({
|
|
|
187
204
|
|
|
188
205
|
export const WorkflowSchema = z.object({
|
|
189
206
|
id: z.string(),
|
|
190
|
-
input:
|
|
207
|
+
input: WorkflowIOSnapshotSchema,
|
|
191
208
|
triggers: z.array(WorkflowTriggerSchema),
|
|
192
209
|
nodes: z.array(WorkflowNodeSchema),
|
|
193
|
-
latestRun:
|
|
210
|
+
latestRun: WorkflowRunSummarySchema.nullable(),
|
|
194
211
|
})
|
|
195
212
|
|
|
196
213
|
export const WorkflowRunListResponseSchema = z.object({
|
|
197
|
-
runs: z.array(
|
|
214
|
+
runs: z.array(WorkflowRunSummarySchema),
|
|
198
215
|
hasMore: z.boolean(),
|
|
199
216
|
total: z.number(),
|
|
200
217
|
})
|
|
201
218
|
|
|
202
219
|
export const WorkflowRunDetailResponseSchema = z.object({
|
|
203
|
-
run:
|
|
220
|
+
run: WorkflowRunDetailSchema,
|
|
204
221
|
nodes: z.array(WorkflowNodeRunSchema),
|
|
205
222
|
})
|
|
206
223
|
|
package/src/server.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { cors } from "@elysiajs/cors"
|
|
2
2
|
import { openapi } from "@elysiajs/openapi"
|
|
3
|
-
import type { OntologyMaintenanceHandle,
|
|
3
|
+
import type { OntologyMaintenanceHandle, SixbHostView } from "@sixb/core"
|
|
4
4
|
import { CSRF_HEADER_NAME } from "@sixb/core/internal/auth"
|
|
5
|
+
import { bindRequestExecution } from "@sixb/core/internal/request-execution"
|
|
5
6
|
import { Elysia } from "elysia"
|
|
6
7
|
import { websocket as elysiaWebSocket } from "elysia/ws"
|
|
7
8
|
import { zodToJsonSchema } from "zod-to-json-schema"
|
|
@@ -43,9 +44,9 @@ import { jsonValueOpenApiOverride } from "./schemas/common"
|
|
|
43
44
|
import { ObjectQueryOpenApiSchemas } from "./schemas/objects"
|
|
44
45
|
|
|
45
46
|
export interface SixbServerOptions {
|
|
46
|
-
|
|
47
|
+
host: SixbHostView
|
|
47
48
|
port?: number
|
|
48
|
-
|
|
49
|
+
hostname?: string
|
|
49
50
|
quiet?: boolean
|
|
50
51
|
browser: SixbApiBrowserPolicy
|
|
51
52
|
}
|
|
@@ -55,9 +56,9 @@ export function createSixbServer(options: SixbServerOptions): SixbServer {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
export class SixbServer {
|
|
58
|
-
private readonly
|
|
59
|
+
private readonly hostRuntime: SixbHostView
|
|
59
60
|
private readonly port: number
|
|
60
|
-
private readonly
|
|
61
|
+
private readonly hostname: string
|
|
61
62
|
private readonly quiet: boolean
|
|
62
63
|
private readonly apiBrowserPolicy: ResolvedSixbApiBrowserPolicy
|
|
63
64
|
private readonly authContextResolver: ResolveRequestAuthContext
|
|
@@ -67,9 +68,9 @@ export class SixbServer {
|
|
|
67
68
|
private maintenance: OntologyMaintenanceHandle | null = null
|
|
68
69
|
|
|
69
70
|
constructor(options: SixbServerOptions) {
|
|
70
|
-
this.
|
|
71
|
+
this.hostRuntime = options.host
|
|
71
72
|
this.port = options.port ?? 3000
|
|
72
|
-
this.
|
|
73
|
+
this.hostname = options.hostname ?? "0.0.0.0"
|
|
73
74
|
this.quiet = options.quiet ?? false
|
|
74
75
|
this.apiBrowserPolicy = resolveApiBrowserPolicy(options.browser)
|
|
75
76
|
this.authContextResolver = createApiBrowserAuthContextResolver(this.apiBrowserPolicy)
|
|
@@ -78,8 +79,8 @@ export class SixbServer {
|
|
|
78
79
|
)
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
return this.
|
|
82
|
+
getHost(): SixbHostView {
|
|
83
|
+
return this.hostRuntime
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
getPort(): number {
|
|
@@ -121,13 +122,13 @@ export class SixbServer {
|
|
|
121
122
|
throw new Error("[SixbServer] Server is already running.")
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
const maintenance = await this.
|
|
125
|
+
const maintenance = await this.hostRuntime.startOntologyMaintenance()
|
|
125
126
|
this.maintenance = maintenance
|
|
126
127
|
|
|
127
128
|
try {
|
|
128
129
|
this.app = createSixbApi(this)
|
|
129
130
|
this.bunServer = startApiServer(this.app, {
|
|
130
|
-
host: this.
|
|
131
|
+
host: this.hostname,
|
|
131
132
|
port: this.port,
|
|
132
133
|
})
|
|
133
134
|
} catch (error) {
|
|
@@ -136,11 +137,11 @@ export class SixbServer {
|
|
|
136
137
|
this.maintenance = null
|
|
137
138
|
await maintenance.stop()
|
|
138
139
|
const message = error instanceof Error ? error.message : String(error)
|
|
139
|
-
throw new Error(`[SixbServer] Failed to listen on ${this.
|
|
140
|
+
throw new Error(`[SixbServer] Failed to listen on ${this.hostname}:${this.port}: ${message}`)
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
if (!this.quiet) {
|
|
143
|
-
const base = `http://${this.
|
|
144
|
+
const base = `http://${this.hostname}:${this.port}`
|
|
144
145
|
console.log(`Sixb server running at ${base}`)
|
|
145
146
|
console.log(`OpenAPI docs at ${base}/docs`)
|
|
146
147
|
}
|
|
@@ -164,9 +165,9 @@ export class SixbServer {
|
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
export function createSixbApi(server: SixbServer) {
|
|
167
|
-
const
|
|
168
|
+
const host = server.getHost()
|
|
168
169
|
const guard = new ServerAuthGuard({
|
|
169
|
-
|
|
170
|
+
host,
|
|
170
171
|
resolveAuthContext: (request) => server.resolveAuthContext(request),
|
|
171
172
|
})
|
|
172
173
|
guard.assertCanServeHttp({ production: process.env.NODE_ENV === "production" })
|
|
@@ -196,23 +197,49 @@ export function createSixbApi(server: SixbServer) {
|
|
|
196
197
|
})
|
|
197
198
|
)
|
|
198
199
|
|
|
199
|
-
// Resolve
|
|
200
|
-
//
|
|
201
|
-
// and `authz` stay null for public routes and disabled auth (privileged mode).
|
|
200
|
+
// Resolve authentication and bind one execution SDK at the request boundary. Protected routes
|
|
201
|
+
// never choose between a principal SDK and the ambient runtime themselves.
|
|
202
202
|
app
|
|
203
203
|
.derive(async ({ request }) => {
|
|
204
204
|
const internalAuthState = consumeInternalRequestAuthState(request)
|
|
205
205
|
if (internalAuthState) {
|
|
206
|
-
|
|
206
|
+
const { authorization, ...agentState } = internalAuthState
|
|
207
|
+
return {
|
|
208
|
+
auth: { kind: "allow" as const, session: null },
|
|
209
|
+
...agentState,
|
|
210
|
+
sixb: bindRequestExecution(host, {
|
|
211
|
+
request,
|
|
212
|
+
authorization,
|
|
213
|
+
}),
|
|
214
|
+
}
|
|
207
215
|
}
|
|
208
216
|
|
|
209
217
|
const auth = await guard.resolve(request)
|
|
210
218
|
if (auth.kind === "deny" || !auth.session?.authenticated) {
|
|
211
|
-
return {
|
|
219
|
+
return {
|
|
220
|
+
auth,
|
|
221
|
+
sixb:
|
|
222
|
+
auth.kind === "allow" && !guard.isAuthEnabled()
|
|
223
|
+
? bindRequestExecution(host, {
|
|
224
|
+
request,
|
|
225
|
+
authorization: { type: "disabled" },
|
|
226
|
+
})
|
|
227
|
+
: null,
|
|
228
|
+
}
|
|
212
229
|
}
|
|
213
230
|
|
|
214
|
-
const authz =
|
|
215
|
-
|
|
231
|
+
const authz = host.auth.contextFromSession(auth.session)
|
|
232
|
+
const credential =
|
|
233
|
+
auth.session.credentialSource === "session"
|
|
234
|
+
? { type: "session" as const, id: auth.session.session.id }
|
|
235
|
+
: { type: "accessToken" as const, id: auth.session.accessToken.id }
|
|
236
|
+
return {
|
|
237
|
+
auth,
|
|
238
|
+
sixb: bindRequestExecution(host, {
|
|
239
|
+
request,
|
|
240
|
+
authorization: { type: "principal", context: authz, credential },
|
|
241
|
+
}),
|
|
242
|
+
}
|
|
216
243
|
})
|
|
217
244
|
.onBeforeHandle(({ auth }) => (auth.kind === "deny" ? auth.response : undefined))
|
|
218
245
|
.mapResponse(({ auth, request, set }) => {
|
|
@@ -226,7 +253,7 @@ export function createSixbApi(server: SixbServer) {
|
|
|
226
253
|
}
|
|
227
254
|
|
|
228
255
|
const renewal = createSessionRenewalCookieHeaders({
|
|
229
|
-
|
|
256
|
+
host: host,
|
|
230
257
|
request,
|
|
231
258
|
session: auth.session,
|
|
232
259
|
})
|
|
@@ -271,7 +298,7 @@ export function createSixbApi(server: SixbServer) {
|
|
|
271
298
|
})
|
|
272
299
|
)
|
|
273
300
|
|
|
274
|
-
registerAuthRoutes(app,
|
|
301
|
+
registerAuthRoutes(app, host, {
|
|
275
302
|
resolveAuthContext: (request) => server.resolveAuthContext(request),
|
|
276
303
|
resolveAuthRedirectContext: (request, input) =>
|
|
277
304
|
server.resolveAuthRedirectContext(request, input),
|
|
@@ -280,8 +307,20 @@ export function createSixbApi(server: SixbServer) {
|
|
|
280
307
|
resolveInvitationRedirectContext: (request, input) =>
|
|
281
308
|
server.resolveInvitationRedirectContext(request, input),
|
|
282
309
|
})
|
|
283
|
-
registerHttpRoutes(app,
|
|
284
|
-
|
|
310
|
+
registerHttpRoutes(app, host, {
|
|
311
|
+
connectorConnections: {
|
|
312
|
+
resolveReturnTo: (request, returnTo) => {
|
|
313
|
+
const authContext = server.resolveAuthContext(request)
|
|
314
|
+
return server.resolveAuthRedirectContext(request, {
|
|
315
|
+
audience: authContext.audience,
|
|
316
|
+
returnTo,
|
|
317
|
+
}).returnTo
|
|
318
|
+
},
|
|
319
|
+
resolveCallbackUrl: (request) =>
|
|
320
|
+
new URL("/auth/connectors/callback", server.resolveAuthRequestOrigin(request)).toString(),
|
|
321
|
+
},
|
|
322
|
+
})
|
|
323
|
+
registerWebhookRoutes(app, host)
|
|
285
324
|
registerWebSocketRoutes(app, server)
|
|
286
325
|
|
|
287
326
|
return app
|
package/src/utils/http.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AuthorizationError,
|
|
3
|
+
OntologyNotFoundError,
|
|
4
|
+
OntologyValidationError,
|
|
5
|
+
type SixbErrorCode,
|
|
6
|
+
} from "@sixb/core"
|
|
7
|
+
import { isSixbError } from "@sixb/core/internal/errors"
|
|
2
8
|
import {
|
|
3
9
|
FileUploadSessionError,
|
|
4
10
|
type FileUploadSessionErrorReason,
|
|
@@ -6,6 +12,24 @@ import {
|
|
|
6
12
|
} from "@sixb/core/storage"
|
|
7
13
|
import { RequestBodyTooLargeError } from "./request-body"
|
|
8
14
|
|
|
15
|
+
/** Explicit transport policy for coded failures that are safe to surface as non-500 responses. */
|
|
16
|
+
const HTTP_STATUS_BY_ERROR_CODE: Partial<Record<SixbErrorCode, number>> = {
|
|
17
|
+
"connector.adapter_invalid": 502,
|
|
18
|
+
"connector.authorization_invalid": 400,
|
|
19
|
+
"connector.authorization_required": 409,
|
|
20
|
+
"connector.configuration_invalid": 400,
|
|
21
|
+
"connector.credentials_unavailable": 503,
|
|
22
|
+
"connector.not_found": 404,
|
|
23
|
+
"connector.operation_conflict": 409,
|
|
24
|
+
"connector.operation_in_progress": 409,
|
|
25
|
+
"connector.provider_failed": 502,
|
|
26
|
+
"connector.provider_unavailable": 503,
|
|
27
|
+
"connector.replacement_required": 409,
|
|
28
|
+
"connector.revocation_pending": 409,
|
|
29
|
+
"dataset.not_found": 404,
|
|
30
|
+
"dataset.version_not_found": 404,
|
|
31
|
+
}
|
|
32
|
+
|
|
9
33
|
export function toIsoString(value: Date): string {
|
|
10
34
|
return value.toISOString()
|
|
11
35
|
}
|
|
@@ -58,7 +82,13 @@ export function handleRouteError(
|
|
|
58
82
|
set: { status?: number | string }
|
|
59
83
|
): {
|
|
60
84
|
error: string
|
|
85
|
+
code?: SixbErrorCode
|
|
61
86
|
} {
|
|
87
|
+
if (isSixbError(error)) {
|
|
88
|
+
set.status = HTTP_STATUS_BY_ERROR_CODE[error.code] ?? 500
|
|
89
|
+
return { error: error.message, code: error.code }
|
|
90
|
+
}
|
|
91
|
+
|
|
62
92
|
if (error instanceof AuthorizationError) {
|
|
63
93
|
set.status = 403
|
|
64
94
|
return { error: error.message }
|
|
@@ -86,12 +116,10 @@ export function handleRouteError(
|
|
|
86
116
|
return { error: error.message }
|
|
87
117
|
}
|
|
88
118
|
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
// message happens to contain one of these words. Every error that gains a class moves above this
|
|
92
|
-
// line and the guess covers less.
|
|
119
|
+
// Legacy uncoded errors remain bad requests until their primitive receives a vertical migration.
|
|
120
|
+
// Crucially, wording no longer changes transport semantics.
|
|
93
121
|
const message = error instanceof Error ? error.message : String(error)
|
|
94
|
-
set.status =
|
|
122
|
+
set.status = 400
|
|
95
123
|
return { error: message }
|
|
96
124
|
}
|
|
97
125
|
|
package/src/utils/ws.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OntologySource } from "@sixb/core"
|
|
2
|
+
import type { Sixb } from "@sixb/core/internal/request-execution"
|
|
2
3
|
|
|
3
4
|
export function safeSend(target: { send: (message: string) => void }, payload: unknown): void {
|
|
4
5
|
try {
|
|
@@ -14,10 +15,14 @@ export function wsStateKey(ws: object): object {
|
|
|
14
15
|
return raw && typeof raw === "object" ? raw : ws
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
/** The
|
|
18
|
-
export function
|
|
19
|
-
const data = (
|
|
20
|
-
|
|
18
|
+
/** The execution SDK attached once when the WebSocket request crosses the auth boundary. */
|
|
19
|
+
export function wsRequestSixb(ws: object): Sixb<readonly OntologySource[]> | null {
|
|
20
|
+
const data = (
|
|
21
|
+
ws as {
|
|
22
|
+
data?: { sixb?: Sixb<readonly OntologySource[]> | null }
|
|
23
|
+
}
|
|
24
|
+
).data
|
|
25
|
+
return data?.sixb ?? null
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
function parseJson(text: string): unknown {
|