@sixb/server 0.1.1 → 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.
Files changed (166) hide show
  1. package/README.md +3 -3
  2. package/dist/auth/application-access.d.ts +2 -2
  3. package/dist/auth/application-access.d.ts.map +1 -1
  4. package/dist/auth/connector-callback-cookie.d.ts +12 -0
  5. package/dist/auth/connector-callback-cookie.d.ts.map +1 -0
  6. package/dist/auth/guard.d.ts +3 -3
  7. package/dist/auth/guard.d.ts.map +1 -1
  8. package/dist/auth/public-routes.d.ts.map +1 -1
  9. package/dist/auth/scope.d.ts +13 -27
  10. package/dist/auth/scope.d.ts.map +1 -1
  11. package/dist/auth/session-cookies.d.ts +2 -2
  12. package/dist/auth/session-cookies.d.ts.map +1 -1
  13. package/dist/connectors/http.d.ts +16 -0
  14. package/dist/connectors/http.d.ts.map +1 -0
  15. package/dist/index.js +3293 -2704
  16. package/dist/index.js.map +55 -50
  17. package/dist/openapi/tags.d.ts +11 -3
  18. package/dist/openapi/tags.d.ts.map +1 -1
  19. package/dist/registerRoutes.d.ts +6 -2
  20. package/dist/registerRoutes.d.ts.map +1 -1
  21. package/dist/routes/action-runs.d.ts +21 -31
  22. package/dist/routes/action-runs.d.ts.map +1 -1
  23. package/dist/routes/actions.d.ts +9 -8
  24. package/dist/routes/actions.d.ts.map +1 -1
  25. package/dist/routes/agent-api-gateway.d.ts +2 -2
  26. package/dist/routes/agent-api-gateway.d.ts.map +1 -1
  27. package/dist/routes/agents.d.ts +130 -131
  28. package/dist/routes/agents.d.ts.map +1 -1
  29. package/dist/routes/auth.d.ts +84 -84
  30. package/dist/routes/auth.d.ts.map +1 -1
  31. package/dist/routes/connector-connection-runs.d.ts +794 -0
  32. package/dist/routes/connector-connection-runs.d.ts.map +1 -0
  33. package/dist/routes/connector-connections.d.ts +219 -0
  34. package/dist/routes/connector-connections.d.ts.map +1 -0
  35. package/dist/routes/connectors.d.ts +10 -4
  36. package/dist/routes/connectors.d.ts.map +1 -1
  37. package/dist/routes/datasets.d.ts +8 -4
  38. package/dist/routes/datasets.d.ts.map +1 -1
  39. package/dist/routes/events.d.ts +8 -8
  40. package/dist/routes/events.d.ts.map +1 -1
  41. package/dist/routes/files.d.ts +11 -10
  42. package/dist/routes/files.d.ts.map +1 -1
  43. package/dist/routes/links.d.ts +2 -2
  44. package/dist/routes/links.d.ts.map +1 -1
  45. package/dist/routes/logs.d.ts +5 -5
  46. package/dist/routes/logs.d.ts.map +1 -1
  47. package/dist/routes/objects.d.ts +34 -34
  48. package/dist/routes/objects.d.ts.map +1 -1
  49. package/dist/routes/ontology.d.ts +50 -50
  50. package/dist/routes/ontology.d.ts.map +1 -1
  51. package/dist/routes/pipelines.d.ts +24 -34
  52. package/dist/routes/pipelines.d.ts.map +1 -1
  53. package/dist/routes/project.d.ts +2 -2
  54. package/dist/routes/project.d.ts.map +1 -1
  55. package/dist/routes/projections.d.ts +131 -83
  56. package/dist/routes/projections.d.ts.map +1 -1
  57. package/dist/routes/rules.d.ts +6 -6
  58. package/dist/routes/rules.d.ts.map +1 -1
  59. package/dist/routes/status.d.ts +2 -2
  60. package/dist/routes/status.d.ts.map +1 -1
  61. package/dist/routes/syncs.d.ts +20 -25
  62. package/dist/routes/syncs.d.ts.map +1 -1
  63. package/dist/routes/telemetry.d.ts +2 -2
  64. package/dist/routes/telemetry.d.ts.map +1 -1
  65. package/dist/routes/webhook-runs.d.ts +9 -9
  66. package/dist/routes/webhook-runs.d.ts.map +1 -1
  67. package/dist/routes/webhooks.d.ts +2 -2
  68. package/dist/routes/webhooks.d.ts.map +1 -1
  69. package/dist/routes/workflows.d.ts +74 -48
  70. package/dist/routes/workflows.d.ts.map +1 -1
  71. package/dist/routes/ws/agents.d.ts +11 -5
  72. package/dist/routes/ws/agents.d.ts.map +1 -1
  73. package/dist/routes/ws/events.d.ts +8 -8
  74. package/dist/routes/ws/events.d.ts.map +1 -1
  75. package/dist/routes/ws/log-subscription-hub.d.ts +6 -3
  76. package/dist/routes/ws/log-subscription-hub.d.ts.map +1 -1
  77. package/dist/routes/ws/logs.d.ts +10 -10
  78. package/dist/routes/ws/logs.d.ts.map +1 -1
  79. package/dist/schemas/actions.d.ts +97 -202
  80. package/dist/schemas/actions.d.ts.map +1 -1
  81. package/dist/schemas/agents.d.ts +442 -439
  82. package/dist/schemas/agents.d.ts.map +1 -1
  83. package/dist/schemas/ai-usage.d.ts +34 -0
  84. package/dist/schemas/ai-usage.d.ts.map +1 -0
  85. package/dist/schemas/auth.d.ts +142 -142
  86. package/dist/schemas/common.d.ts +37 -0
  87. package/dist/schemas/common.d.ts.map +1 -1
  88. package/dist/schemas/connectors.d.ts +713 -2
  89. package/dist/schemas/connectors.d.ts.map +1 -1
  90. package/dist/schemas/datasets.d.ts +2 -2
  91. package/dist/schemas/event-payloads.d.ts +6 -6
  92. package/dist/schemas/events.d.ts +34 -34
  93. package/dist/schemas/logs.d.ts +22 -22
  94. package/dist/schemas/objects.d.ts +10 -10
  95. package/dist/schemas/ontology.d.ts +118 -118
  96. package/dist/schemas/pipelines.d.ts +95 -190
  97. package/dist/schemas/pipelines.d.ts.map +1 -1
  98. package/dist/schemas/projections.d.ts +918 -563
  99. package/dist/schemas/projections.d.ts.map +1 -1
  100. package/dist/schemas/rules.d.ts +6 -6
  101. package/dist/schemas/status.d.ts +2 -2
  102. package/dist/schemas/syncs.d.ts +65 -108
  103. package/dist/schemas/syncs.d.ts.map +1 -1
  104. package/dist/schemas/webhook-runs.d.ts +41 -41
  105. package/dist/schemas/webhook-runs.d.ts.map +1 -1
  106. package/dist/schemas/workflows.d.ts +516 -183
  107. package/dist/schemas/workflows.d.ts.map +1 -1
  108. package/dist/server.d.ts +6 -6
  109. package/dist/server.d.ts.map +1 -1
  110. package/dist/utils/http.d.ts +2 -0
  111. package/dist/utils/http.d.ts.map +1 -1
  112. package/dist/utils/ws.d.ts +4 -3
  113. package/dist/utils/ws.d.ts.map +1 -1
  114. package/package.json +4 -4
  115. package/src/auth/access-token-boundary.ts +4 -4
  116. package/src/auth/application-access.ts +8 -9
  117. package/src/auth/connector-callback-cookie.ts +95 -0
  118. package/src/auth/guard.ts +11 -11
  119. package/src/auth/public-routes.ts +13 -0
  120. package/src/auth/scope.ts +26 -36
  121. package/src/auth/session-cookies.ts +3 -3
  122. package/src/connectors/http.ts +110 -0
  123. package/src/openapi/tags.ts +9 -1
  124. package/src/registerRoutes.ts +34 -23
  125. package/src/routes/action-runs.ts +39 -39
  126. package/src/routes/actions.ts +7 -13
  127. package/src/routes/agent-api-gateway.ts +41 -38
  128. package/src/routes/agents.ts +89 -200
  129. package/src/routes/auth.ts +87 -91
  130. package/src/routes/connector-connection-runs.ts +346 -0
  131. package/src/routes/connector-connections.ts +135 -0
  132. package/src/routes/connectors.ts +24 -12
  133. package/src/routes/datasets.ts +55 -54
  134. package/src/routes/events.ts +5 -5
  135. package/src/routes/files.ts +22 -30
  136. package/src/routes/links.ts +31 -35
  137. package/src/routes/logs.ts +6 -11
  138. package/src/routes/objects.ts +51 -114
  139. package/src/routes/ontology.ts +27 -38
  140. package/src/routes/pipelines.ts +28 -62
  141. package/src/routes/project.ts +3 -3
  142. package/src/routes/projections.ts +26 -38
  143. package/src/routes/rules.ts +11 -25
  144. package/src/routes/status.ts +5 -5
  145. package/src/routes/syncs.ts +19 -45
  146. package/src/routes/telemetry.ts +18 -29
  147. package/src/routes/webhook-runs.ts +5 -5
  148. package/src/routes/webhooks.ts +259 -341
  149. package/src/routes/workflows.ts +226 -248
  150. package/src/routes/ws/agents.ts +196 -66
  151. package/src/routes/ws/events.ts +11 -10
  152. package/src/routes/ws/log-subscription-hub.ts +6 -12
  153. package/src/routes/ws/logs.ts +13 -5
  154. package/src/schemas/actions.ts +58 -25
  155. package/src/schemas/agents.ts +19 -14
  156. package/src/schemas/ai-usage.ts +16 -0
  157. package/src/schemas/common.ts +24 -0
  158. package/src/schemas/connectors.ts +164 -0
  159. package/src/schemas/pipelines.ts +23 -15
  160. package/src/schemas/projections.ts +17 -3
  161. package/src/schemas/syncs.ts +13 -8
  162. package/src/schemas/webhook-runs.ts +10 -5
  163. package/src/schemas/workflows.ts +16 -6
  164. package/src/server.ts +65 -26
  165. package/src/utils/http.ts +34 -6
  166. package/src/utils/ws.ts +10 -5
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, OntologySource, Sixb } from "@sixb/core"
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
- sixb: Sixb<readonly OntologySource[]>
47
+ host: SixbHostView
47
48
  port?: number
48
- host?: string
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 sixb: Sixb<readonly OntologySource[]>
59
+ private readonly hostRuntime: SixbHostView
59
60
  private readonly port: number
60
- private readonly host: string
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.sixb = options.sixb
71
+ this.hostRuntime = options.host
71
72
  this.port = options.port ?? 3000
72
- this.host = options.host ?? "0.0.0.0"
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
- getSixb(): Sixb<readonly OntologySource[]> {
82
- return this.sixb
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.sixb.startOntologyMaintenance()
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.host,
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.host}:${this.port}: ${message}`)
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.host}:${this.port}`
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 sixb = server.getSixb()
168
+ const host = server.getHost()
168
169
  const guard = new ServerAuthGuard({
169
- sixb,
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 the session once per request and attach the principal's scoped SDK.
200
- // The beforeHandle enforces the auth decision before any route runs; `scoped`
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
- return { auth: { kind: "allow" as const, session: null }, ...internalAuthState }
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 { auth, authz: null, scoped: null }
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 = sixb.auth.contextFromSession(auth.session)
215
- return { auth, authz, scoped: sixb.as(authz) }
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
- sixb,
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, sixb, {
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, sixb)
284
- registerWebhookRoutes(app, sixb)
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 { AuthorizationError, OntologyNotFoundError, OntologyValidationError } from "@sixb/core"
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
- // The tail. Core still throws a bare `Error` for "Unknown sync 'x'" and its siblings, so the
90
- // message is all a route has to go on; reading it is a guess that misfires whenever a validation
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 = message.includes("not found") || message.includes("Unknown") ? 404 : 400
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 { AuthorizationContext } from "@sixb/core"
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 authorization context attached to a websocket connection; null when unauthenticated/disabled. */
18
- export function wsAuthz(ws: object): AuthorizationContext | null {
19
- const data = (ws as { data?: { authz?: AuthorizationContext | null } }).data
20
- return data?.authz ?? null
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 {