@sixb/server 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/auth/application-access.d.ts +2 -2
- package/dist/auth/application-access.d.ts.map +1 -1
- package/dist/auth/connector-callback-cookie.d.ts +12 -0
- package/dist/auth/connector-callback-cookie.d.ts.map +1 -0
- package/dist/auth/experience.d.ts +33 -0
- package/dist/auth/experience.d.ts.map +1 -0
- package/dist/auth/guard.d.ts +3 -3
- package/dist/auth/guard.d.ts.map +1 -1
- package/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/auth/scope.d.ts +13 -27
- package/dist/auth/scope.d.ts.map +1 -1
- package/dist/auth/session-cookies.d.ts +2 -2
- package/dist/auth/session-cookies.d.ts.map +1 -1
- package/dist/connectors/http.d.ts +16 -0
- package/dist/connectors/http.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3903 -2760
- package/dist/index.js.map +58 -50
- package/dist/openapi/tags.d.ts +15 -3
- package/dist/openapi/tags.d.ts.map +1 -1
- package/dist/registerRoutes.d.ts +6 -2
- package/dist/registerRoutes.d.ts.map +1 -1
- package/dist/routes/action-runs.d.ts +21 -31
- package/dist/routes/action-runs.d.ts.map +1 -1
- package/dist/routes/actions.d.ts +12 -11
- package/dist/routes/actions.d.ts.map +1 -1
- package/dist/routes/agent-api-gateway.d.ts +2 -2
- package/dist/routes/agent-api-gateway.d.ts.map +1 -1
- package/dist/routes/agents.d.ts +230 -159
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/ai-accounting.d.ts +31 -0
- package/dist/routes/ai-accounting.d.ts.map +1 -0
- package/dist/routes/auth.d.ts +149 -92
- package/dist/routes/auth.d.ts.map +1 -1
- package/dist/routes/connector-connection-runs.d.ts +794 -0
- package/dist/routes/connector-connection-runs.d.ts.map +1 -0
- package/dist/routes/connector-connections.d.ts +219 -0
- package/dist/routes/connector-connections.d.ts.map +1 -0
- package/dist/routes/connectors.d.ts +10 -4
- package/dist/routes/connectors.d.ts.map +1 -1
- package/dist/routes/datasets.d.ts +16 -12
- package/dist/routes/datasets.d.ts.map +1 -1
- package/dist/routes/events.d.ts +9 -9
- package/dist/routes/events.d.ts.map +1 -1
- package/dist/routes/files.d.ts +19 -18
- package/dist/routes/files.d.ts.map +1 -1
- package/dist/routes/links.d.ts +11 -11
- package/dist/routes/links.d.ts.map +1 -1
- package/dist/routes/logs.d.ts +5 -5
- package/dist/routes/logs.d.ts.map +1 -1
- package/dist/routes/objects.d.ts +37 -37
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/ontology.d.ts +50 -50
- package/dist/routes/ontology.d.ts.map +1 -1
- package/dist/routes/pipelines.d.ts +28 -38
- package/dist/routes/pipelines.d.ts.map +1 -1
- package/dist/routes/project.d.ts +2 -2
- package/dist/routes/project.d.ts.map +1 -1
- package/dist/routes/projections.d.ts +145 -85
- package/dist/routes/projections.d.ts.map +1 -1
- package/dist/routes/rules.d.ts +6 -6
- package/dist/routes/rules.d.ts.map +1 -1
- package/dist/routes/status.d.ts +2 -2
- package/dist/routes/status.d.ts.map +1 -1
- package/dist/routes/syncs.d.ts +23 -28
- package/dist/routes/syncs.d.ts.map +1 -1
- package/dist/routes/telemetry.d.ts +9 -9
- package/dist/routes/telemetry.d.ts.map +1 -1
- package/dist/routes/webhook-runs.d.ts +9 -9
- package/dist/routes/webhook-runs.d.ts.map +1 -1
- package/dist/routes/webhooks.d.ts +2 -2
- package/dist/routes/webhooks.d.ts.map +1 -1
- package/dist/routes/workflows.d.ts +177 -66
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/routes/ws/agents.d.ts +11 -5
- package/dist/routes/ws/agents.d.ts.map +1 -1
- package/dist/routes/ws/events.d.ts +8 -8
- package/dist/routes/ws/events.d.ts.map +1 -1
- package/dist/routes/ws/log-subscription-hub.d.ts +6 -3
- package/dist/routes/ws/log-subscription-hub.d.ts.map +1 -1
- package/dist/routes/ws/logs.d.ts +10 -10
- package/dist/routes/ws/logs.d.ts.map +1 -1
- package/dist/schemas/actions.d.ts +89 -194
- package/dist/schemas/actions.d.ts.map +1 -1
- package/dist/schemas/agents.d.ts +791 -471
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-accounting.d.ts +2393 -0
- package/dist/schemas/ai-accounting.d.ts.map +1 -0
- package/dist/schemas/ai-usage.d.ts +34 -0
- package/dist/schemas/ai-usage.d.ts.map +1 -0
- package/dist/schemas/auth.d.ts +102 -102
- package/dist/schemas/common.d.ts +37 -0
- package/dist/schemas/common.d.ts.map +1 -1
- package/dist/schemas/connectors.d.ts +713 -2
- package/dist/schemas/connectors.d.ts.map +1 -1
- package/dist/schemas/datasets.d.ts +2 -2
- package/dist/schemas/event-payloads.d.ts +12 -12
- package/dist/schemas/events.d.ts +40 -40
- package/dist/schemas/links.d.ts +2 -2
- package/dist/schemas/logs.d.ts +22 -22
- package/dist/schemas/objects.d.ts +10 -10
- package/dist/schemas/ontology.d.ts +118 -118
- package/dist/schemas/pipelines.d.ts +89 -184
- package/dist/schemas/pipelines.d.ts.map +1 -1
- package/dist/schemas/projections.d.ts +1030 -563
- package/dist/schemas/projections.d.ts.map +1 -1
- package/dist/schemas/rules.d.ts +6 -6
- package/dist/schemas/syncs.d.ts +65 -108
- package/dist/schemas/syncs.d.ts.map +1 -1
- package/dist/schemas/webhook-runs.d.ts +41 -41
- package/dist/schemas/webhook-runs.d.ts.map +1 -1
- package/dist/schemas/workflows.d.ts +1189 -185
- package/dist/schemas/workflows.d.ts.map +1 -1
- package/dist/server.d.ts +11 -6
- package/dist/server.d.ts.map +1 -1
- package/dist/utils/http.d.ts +2 -0
- package/dist/utils/http.d.ts.map +1 -1
- package/dist/utils/ws.d.ts +4 -3
- package/dist/utils/ws.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/auth/access-token-boundary.ts +4 -4
- package/src/auth/application-access.ts +8 -9
- package/src/auth/connector-callback-cookie.ts +95 -0
- package/src/auth/experience.ts +190 -0
- package/src/auth/guard.ts +11 -11
- package/src/auth/public-routes.ts +20 -0
- package/src/auth/scope.ts +26 -36
- package/src/auth/session-cookies.ts +3 -3
- package/src/connectors/http.ts +110 -0
- package/src/index.ts +1 -0
- package/src/openapi/tags.ts +13 -1
- package/src/registerRoutes.ts +36 -23
- package/src/routes/action-runs.ts +39 -39
- package/src/routes/actions.ts +7 -13
- package/src/routes/agent-api-gateway.ts +41 -38
- package/src/routes/agents.ts +90 -200
- package/src/routes/ai-accounting.ts +166 -0
- package/src/routes/auth.ts +274 -122
- package/src/routes/connector-connection-runs.ts +346 -0
- package/src/routes/connector-connections.ts +135 -0
- package/src/routes/connectors.ts +24 -12
- package/src/routes/datasets.ts +55 -54
- package/src/routes/events.ts +5 -5
- package/src/routes/files.ts +22 -30
- package/src/routes/links.ts +31 -35
- package/src/routes/logs.ts +6 -11
- package/src/routes/objects.ts +51 -114
- package/src/routes/ontology.ts +27 -38
- package/src/routes/pipelines.ts +28 -62
- package/src/routes/project.ts +3 -3
- package/src/routes/projections.ts +44 -42
- package/src/routes/rules.ts +11 -25
- package/src/routes/status.ts +5 -5
- package/src/routes/syncs.ts +19 -45
- package/src/routes/telemetry.ts +18 -29
- package/src/routes/webhook-runs.ts +5 -5
- package/src/routes/webhooks.ts +259 -341
- package/src/routes/workflows.ts +242 -248
- package/src/routes/ws/agents.ts +196 -66
- package/src/routes/ws/events.ts +11 -10
- package/src/routes/ws/log-subscription-hub.ts +6 -12
- package/src/routes/ws/logs.ts +13 -5
- package/src/schemas/actions.ts +58 -25
- package/src/schemas/agents.ts +23 -23
- package/src/schemas/ai-accounting.ts +182 -0
- package/src/schemas/ai-usage.ts +16 -0
- package/src/schemas/common.ts +24 -0
- package/src/schemas/connectors.ts +164 -0
- package/src/schemas/pipelines.ts +23 -15
- package/src/schemas/projections.ts +23 -3
- package/src/schemas/syncs.ts +13 -8
- package/src/schemas/webhook-runs.ts +10 -5
- package/src/schemas/workflows.ts +23 -8
- package/src/server.ts +75 -26
- package/src/utils/http.ts +34 -6
- package/src/utils/ws.ts +10 -5
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import type { SixbFailure } from "@sixb/core"
|
|
2
|
+
import type { WebhookRunFailureCode } from "@sixb/core/storage"
|
|
3
|
+
import { WEBHOOK_RUN_FAILURE_CODES } from "@sixb/core/storage"
|
|
1
4
|
import { z } from "zod"
|
|
5
|
+
import { sixbFailureSchema } from "./common"
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
const WebhookRunFailureSchema: z.ZodType<SixbFailure<WebhookRunFailureCode>> =
|
|
8
|
+
sixbFailureSchema(WEBHOOK_RUN_FAILURE_CODES)
|
|
4
9
|
|
|
5
|
-
export const
|
|
10
|
+
export const WebhookRunStatusSchema = z.enum(["running", "succeeded", "failed"])
|
|
6
11
|
|
|
7
12
|
export const WebhookRunsQuerySchema = z.object({
|
|
8
13
|
connectorId: z.string().optional(),
|
|
@@ -19,6 +24,7 @@ export const WebhookRunsQuerySchema = z.object({
|
|
|
19
24
|
export const WebhookRunSchema = z.object({
|
|
20
25
|
id: z.string(),
|
|
21
26
|
projectId: z.string(),
|
|
27
|
+
executionId: z.string(),
|
|
22
28
|
connectorId: z.string(),
|
|
23
29
|
webhookId: z.string(),
|
|
24
30
|
status: WebhookRunStatusSchema,
|
|
@@ -26,11 +32,10 @@ export const WebhookRunSchema = z.object({
|
|
|
26
32
|
route: z.string(),
|
|
27
33
|
startedAt: z.string(),
|
|
28
34
|
finishedAt: z.string().optional(),
|
|
29
|
-
requestBodyBytes: z.number()
|
|
35
|
+
requestBodyBytes: z.number(),
|
|
30
36
|
responseStatus: z.number().optional(),
|
|
31
37
|
idempotencyKey: z.string().optional(),
|
|
32
|
-
|
|
33
|
-
error: z.string().optional(),
|
|
38
|
+
error: WebhookRunFailureSchema.optional(),
|
|
34
39
|
})
|
|
35
40
|
|
|
36
41
|
export const WebhookRunListResponseSchema = z.object({
|
package/src/schemas/workflows.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type SixbFailure,
|
|
3
|
+
WORKFLOW_RUN_FAILURE_CODES,
|
|
4
|
+
type WorkflowRunFailureCode,
|
|
5
|
+
} from "@sixb/core/storage"
|
|
1
6
|
import { z } from "zod"
|
|
2
|
-
import {
|
|
7
|
+
import { AgentMessagePartSchema, AgentRunFailureSchema } from "./agents"
|
|
8
|
+
import { AiCostSummarySchema } from "./ai-accounting"
|
|
9
|
+
import { AiUsageSummarySchema } from "./ai-usage"
|
|
10
|
+
import { JsonValueSchema, sixbFailureSchema } from "./common"
|
|
3
11
|
|
|
4
12
|
export const WorkflowIOSnapshotSchema = z.record(JsonValueSchema)
|
|
5
13
|
|
|
14
|
+
const WorkflowRunFailureSchema: z.ZodType<SixbFailure<WorkflowRunFailureCode>> = sixbFailureSchema(
|
|
15
|
+
WORKFLOW_RUN_FAILURE_CODES
|
|
16
|
+
)
|
|
17
|
+
|
|
6
18
|
export const WorkflowParamsSchema = z.object({
|
|
7
19
|
workflowId: z.string().min(1),
|
|
8
20
|
})
|
|
@@ -121,7 +133,7 @@ export const WorkflowRunSummarySchema = z.object({
|
|
|
121
133
|
queuedAt: z.string().optional(),
|
|
122
134
|
startedAt: z.string(),
|
|
123
135
|
finishedAt: z.string().optional(),
|
|
124
|
-
error:
|
|
136
|
+
error: WorkflowRunFailureSchema.optional(),
|
|
125
137
|
requestedBy: WorkflowInterventionActorSchema,
|
|
126
138
|
})
|
|
127
139
|
|
|
@@ -136,18 +148,21 @@ export const WorkflowAgentNodeExecutionSummarySchema = z.object({
|
|
|
136
148
|
attempt: z.number().int().nonnegative(),
|
|
137
149
|
modelId: z.string().optional(),
|
|
138
150
|
finishReason: z.string().optional(),
|
|
139
|
-
usage:
|
|
151
|
+
usage: AiUsageSummarySchema.optional(),
|
|
152
|
+
cost: AiCostSummarySchema.optional(),
|
|
140
153
|
startedAt: z.string().optional(),
|
|
141
154
|
completedAt: z.string().optional(),
|
|
142
155
|
})
|
|
143
156
|
|
|
157
|
+
export const WorkflowAgentFailurePhaseSchema = z.enum(["agent-loop", "structured-finalizer"])
|
|
158
|
+
|
|
144
159
|
export const WorkflowAgentNodeExecutionSchema = WorkflowAgentNodeExecutionSummarySchema.extend({
|
|
145
160
|
nodeRunId: z.string(),
|
|
146
161
|
prompt: z.string(),
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
error:
|
|
162
|
+
trace: z.array(AgentMessagePartSchema).optional(),
|
|
163
|
+
diagnostics: z.array(JsonValueSchema).optional(),
|
|
164
|
+
failurePhase: WorkflowAgentFailurePhaseSchema.optional(),
|
|
165
|
+
error: AgentRunFailureSchema.optional(),
|
|
151
166
|
createdAt: z.string(),
|
|
152
167
|
})
|
|
153
168
|
|
|
@@ -165,7 +180,7 @@ export const WorkflowNodeRunSchema = z.object({
|
|
|
165
180
|
startedAt: z.string(),
|
|
166
181
|
finishedAt: z.string().optional(),
|
|
167
182
|
output: WorkflowIOSnapshotSchema.optional(),
|
|
168
|
-
error:
|
|
183
|
+
error: WorkflowRunFailureSchema.optional(),
|
|
169
184
|
agentExecution: WorkflowAgentNodeExecutionSummarySchema.optional(),
|
|
170
185
|
})
|
|
171
186
|
|
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"
|
|
@@ -24,6 +25,7 @@ import {
|
|
|
24
25
|
type SixbApiBrowserPolicy,
|
|
25
26
|
} from "./auth/browser-origin"
|
|
26
27
|
import { CSRF_TOKEN_RESPONSE_HEADER_NAME } from "./auth/csrf"
|
|
28
|
+
import type { SixbAuthExperienceOptions } from "./auth/experience"
|
|
27
29
|
import { ServerAuthGuard } from "./auth/guard"
|
|
28
30
|
import { consumeInternalRequestAuthState } from "./auth/scope"
|
|
29
31
|
import { SESSION_ACTIVITY_HEADER_NAME } from "./auth/session-activity"
|
|
@@ -43,11 +45,13 @@ import { jsonValueOpenApiOverride } from "./schemas/common"
|
|
|
43
45
|
import { ObjectQueryOpenApiSchemas } from "./schemas/objects"
|
|
44
46
|
|
|
45
47
|
export interface SixbServerOptions {
|
|
46
|
-
|
|
48
|
+
host: SixbHostView
|
|
47
49
|
port?: number
|
|
48
|
-
|
|
50
|
+
hostname?: string
|
|
49
51
|
quiet?: boolean
|
|
50
52
|
browser: SixbApiBrowserPolicy
|
|
53
|
+
/** Optional custom-app auth bundle mounted under the API's `/auth` routes. */
|
|
54
|
+
authExperience?: SixbAuthExperienceOptions
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
export function createSixbServer(options: SixbServerOptions): SixbServer {
|
|
@@ -55,31 +59,33 @@ export function createSixbServer(options: SixbServerOptions): SixbServer {
|
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
export class SixbServer {
|
|
58
|
-
private readonly
|
|
62
|
+
private readonly hostRuntime: SixbHostView
|
|
59
63
|
private readonly port: number
|
|
60
|
-
private readonly
|
|
64
|
+
private readonly hostname: string
|
|
61
65
|
private readonly quiet: boolean
|
|
62
66
|
private readonly apiBrowserPolicy: ResolvedSixbApiBrowserPolicy
|
|
63
67
|
private readonly authContextResolver: ResolveRequestAuthContext
|
|
64
68
|
private readonly authRedirectContextResolver: ResolveAuthRedirectContext
|
|
69
|
+
private readonly authExperience?: SixbAuthExperienceOptions
|
|
65
70
|
private app: SixbApp | null = null
|
|
66
71
|
private bunServer: ReturnType<typeof Bun.serve> | null = null
|
|
67
72
|
private maintenance: OntologyMaintenanceHandle | null = null
|
|
68
73
|
|
|
69
74
|
constructor(options: SixbServerOptions) {
|
|
70
|
-
this.
|
|
75
|
+
this.hostRuntime = options.host
|
|
71
76
|
this.port = options.port ?? 3000
|
|
72
|
-
this.
|
|
77
|
+
this.hostname = options.hostname ?? "0.0.0.0"
|
|
73
78
|
this.quiet = options.quiet ?? false
|
|
74
79
|
this.apiBrowserPolicy = resolveApiBrowserPolicy(options.browser)
|
|
75
80
|
this.authContextResolver = createApiBrowserAuthContextResolver(this.apiBrowserPolicy)
|
|
76
81
|
this.authRedirectContextResolver = createApiBrowserAuthRedirectContextResolver(
|
|
77
82
|
this.apiBrowserPolicy
|
|
78
83
|
)
|
|
84
|
+
this.authExperience = options.authExperience
|
|
79
85
|
}
|
|
80
86
|
|
|
81
|
-
|
|
82
|
-
return this.
|
|
87
|
+
getHost(): SixbHostView {
|
|
88
|
+
return this.hostRuntime
|
|
83
89
|
}
|
|
84
90
|
|
|
85
91
|
getPort(): number {
|
|
@@ -116,18 +122,22 @@ export class SixbServer {
|
|
|
116
122
|
return this.apiBrowserPolicy
|
|
117
123
|
}
|
|
118
124
|
|
|
125
|
+
getAuthExperience(): SixbAuthExperienceOptions | undefined {
|
|
126
|
+
return this.authExperience
|
|
127
|
+
}
|
|
128
|
+
|
|
119
129
|
async start(): Promise<void> {
|
|
120
130
|
if (this.app !== null || this.bunServer !== null || this.maintenance !== null) {
|
|
121
131
|
throw new Error("[SixbServer] Server is already running.")
|
|
122
132
|
}
|
|
123
133
|
|
|
124
|
-
const maintenance = await this.
|
|
134
|
+
const maintenance = await this.hostRuntime.startOntologyMaintenance()
|
|
125
135
|
this.maintenance = maintenance
|
|
126
136
|
|
|
127
137
|
try {
|
|
128
138
|
this.app = createSixbApi(this)
|
|
129
139
|
this.bunServer = startApiServer(this.app, {
|
|
130
|
-
host: this.
|
|
140
|
+
host: this.hostname,
|
|
131
141
|
port: this.port,
|
|
132
142
|
})
|
|
133
143
|
} catch (error) {
|
|
@@ -136,11 +146,11 @@ export class SixbServer {
|
|
|
136
146
|
this.maintenance = null
|
|
137
147
|
await maintenance.stop()
|
|
138
148
|
const message = error instanceof Error ? error.message : String(error)
|
|
139
|
-
throw new Error(`[SixbServer] Failed to listen on ${this.
|
|
149
|
+
throw new Error(`[SixbServer] Failed to listen on ${this.hostname}:${this.port}: ${message}`)
|
|
140
150
|
}
|
|
141
151
|
|
|
142
152
|
if (!this.quiet) {
|
|
143
|
-
const base = `http://${this.
|
|
153
|
+
const base = `http://${this.hostname}:${this.port}`
|
|
144
154
|
console.log(`Sixb server running at ${base}`)
|
|
145
155
|
console.log(`OpenAPI docs at ${base}/docs`)
|
|
146
156
|
}
|
|
@@ -164,9 +174,9 @@ export class SixbServer {
|
|
|
164
174
|
}
|
|
165
175
|
|
|
166
176
|
export function createSixbApi(server: SixbServer) {
|
|
167
|
-
const
|
|
177
|
+
const host = server.getHost()
|
|
168
178
|
const guard = new ServerAuthGuard({
|
|
169
|
-
|
|
179
|
+
host,
|
|
170
180
|
resolveAuthContext: (request) => server.resolveAuthContext(request),
|
|
171
181
|
})
|
|
172
182
|
guard.assertCanServeHttp({ production: process.env.NODE_ENV === "production" })
|
|
@@ -196,23 +206,49 @@ export function createSixbApi(server: SixbServer) {
|
|
|
196
206
|
})
|
|
197
207
|
)
|
|
198
208
|
|
|
199
|
-
// Resolve
|
|
200
|
-
//
|
|
201
|
-
// and `authz` stay null for public routes and disabled auth (privileged mode).
|
|
209
|
+
// Resolve authentication and bind one execution SDK at the request boundary. Protected routes
|
|
210
|
+
// never choose between a principal SDK and the ambient runtime themselves.
|
|
202
211
|
app
|
|
203
212
|
.derive(async ({ request }) => {
|
|
204
213
|
const internalAuthState = consumeInternalRequestAuthState(request)
|
|
205
214
|
if (internalAuthState) {
|
|
206
|
-
|
|
215
|
+
const { authorization, ...agentState } = internalAuthState
|
|
216
|
+
return {
|
|
217
|
+
auth: { kind: "allow" as const, session: null },
|
|
218
|
+
...agentState,
|
|
219
|
+
sixb: bindRequestExecution(host, {
|
|
220
|
+
request,
|
|
221
|
+
authorization,
|
|
222
|
+
}),
|
|
223
|
+
}
|
|
207
224
|
}
|
|
208
225
|
|
|
209
226
|
const auth = await guard.resolve(request)
|
|
210
227
|
if (auth.kind === "deny" || !auth.session?.authenticated) {
|
|
211
|
-
return {
|
|
228
|
+
return {
|
|
229
|
+
auth,
|
|
230
|
+
sixb:
|
|
231
|
+
auth.kind === "allow" && !guard.isAuthEnabled()
|
|
232
|
+
? bindRequestExecution(host, {
|
|
233
|
+
request,
|
|
234
|
+
authorization: { type: "disabled" },
|
|
235
|
+
})
|
|
236
|
+
: null,
|
|
237
|
+
}
|
|
212
238
|
}
|
|
213
239
|
|
|
214
|
-
const authz =
|
|
215
|
-
|
|
240
|
+
const authz = host.auth.contextFromSession(auth.session)
|
|
241
|
+
const credential =
|
|
242
|
+
auth.session.credentialSource === "session"
|
|
243
|
+
? { type: "session" as const, id: auth.session.session.id }
|
|
244
|
+
: { type: "accessToken" as const, id: auth.session.accessToken.id }
|
|
245
|
+
return {
|
|
246
|
+
auth,
|
|
247
|
+
sixb: bindRequestExecution(host, {
|
|
248
|
+
request,
|
|
249
|
+
authorization: { type: "principal", context: authz, credential },
|
|
250
|
+
}),
|
|
251
|
+
}
|
|
216
252
|
})
|
|
217
253
|
.onBeforeHandle(({ auth }) => (auth.kind === "deny" ? auth.response : undefined))
|
|
218
254
|
.mapResponse(({ auth, request, set }) => {
|
|
@@ -226,7 +262,7 @@ export function createSixbApi(server: SixbServer) {
|
|
|
226
262
|
}
|
|
227
263
|
|
|
228
264
|
const renewal = createSessionRenewalCookieHeaders({
|
|
229
|
-
|
|
265
|
+
host: host,
|
|
230
266
|
request,
|
|
231
267
|
session: auth.session,
|
|
232
268
|
})
|
|
@@ -271,17 +307,30 @@ export function createSixbApi(server: SixbServer) {
|
|
|
271
307
|
})
|
|
272
308
|
)
|
|
273
309
|
|
|
274
|
-
registerAuthRoutes(app,
|
|
310
|
+
registerAuthRoutes(app, host, {
|
|
275
311
|
resolveAuthContext: (request) => server.resolveAuthContext(request),
|
|
276
312
|
resolveAuthRedirectContext: (request, input) =>
|
|
277
313
|
server.resolveAuthRedirectContext(request, input),
|
|
278
314
|
getInvitationDestinationOptions: (request) => server.getInvitationDestinationOptions(request),
|
|
279
315
|
resolveAuthRequestOrigin: (request) => server.resolveAuthRequestOrigin(request),
|
|
316
|
+
authExperience: server.getAuthExperience(),
|
|
280
317
|
resolveInvitationRedirectContext: (request, input) =>
|
|
281
318
|
server.resolveInvitationRedirectContext(request, input),
|
|
282
319
|
})
|
|
283
|
-
registerHttpRoutes(app,
|
|
284
|
-
|
|
320
|
+
registerHttpRoutes(app, host, {
|
|
321
|
+
connectorConnections: {
|
|
322
|
+
resolveReturnTo: (request, returnTo) => {
|
|
323
|
+
const authContext = server.resolveAuthContext(request)
|
|
324
|
+
return server.resolveAuthRedirectContext(request, {
|
|
325
|
+
audience: authContext.audience,
|
|
326
|
+
returnTo,
|
|
327
|
+
}).returnTo
|
|
328
|
+
},
|
|
329
|
+
resolveCallbackUrl: (request) =>
|
|
330
|
+
new URL("/auth/connectors/callback", server.resolveAuthRequestOrigin(request)).toString(),
|
|
331
|
+
},
|
|
332
|
+
})
|
|
333
|
+
registerWebhookRoutes(app, host)
|
|
285
334
|
registerWebSocketRoutes(app, server)
|
|
286
335
|
|
|
287
336
|
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 {
|