@sixb/server 0.1.7 → 0.1.8
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/dist/auth/access-token-boundary.d.ts +3 -0
- package/dist/auth/access-token-boundary.d.ts.map +1 -1
- package/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/auth/shared-access.d.ts +66 -0
- package/dist/auth/shared-access.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1419 -627
- package/dist/index.js.map +19 -14
- package/dist/openapi/security.d.ts +15 -1
- package/dist/openapi/security.d.ts.map +1 -1
- package/dist/openapi/tags.d.ts +6 -2
- package/dist/openapi/tags.d.ts.map +1 -1
- package/dist/registerRoutes.d.ts +2 -0
- package/dist/registerRoutes.d.ts.map +1 -1
- package/dist/routes/actions.d.ts.map +1 -1
- package/dist/routes/agents.d.ts +5 -5
- package/dist/routes/auth.d.ts +9 -9
- package/dist/routes/connector-connection-runs.d.ts +8 -8
- package/dist/routes/connector-connections.d.ts +4 -4
- package/dist/routes/datasets.d.ts +5 -3
- package/dist/routes/datasets.d.ts.map +1 -1
- package/dist/routes/logs.d.ts +1 -1
- package/dist/routes/pipelines.d.ts +4 -0
- package/dist/routes/pipelines.d.ts.map +1 -1
- package/dist/routes/share-grants.d.ts +264 -0
- package/dist/routes/share-grants.d.ts.map +1 -0
- package/dist/routes/shared-access.d.ts +155 -0
- package/dist/routes/shared-access.d.ts.map +1 -0
- package/dist/routes/syncs.d.ts +2 -0
- package/dist/routes/syncs.d.ts.map +1 -1
- package/dist/routes/workflows.d.ts +1 -1
- package/dist/schemas/agents.d.ts +22 -30
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/auth.d.ts +40 -40
- package/dist/schemas/datasets.d.ts +28 -22
- package/dist/schemas/datasets.d.ts.map +1 -1
- package/dist/schemas/logs.d.ts +6 -6
- package/dist/schemas/pipelines.d.ts +36 -0
- package/dist/schemas/pipelines.d.ts.map +1 -1
- package/dist/schemas/share-grants.d.ts +518 -0
- package/dist/schemas/share-grants.d.ts.map +1 -0
- package/dist/schemas/shared-access.d.ts +42 -0
- package/dist/schemas/shared-access.d.ts.map +1 -0
- package/dist/schemas/syncs.d.ts +7 -0
- package/dist/schemas/syncs.d.ts.map +1 -1
- package/dist/schemas/workflows.d.ts +4 -4
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/auth/access-token-boundary.ts +17 -2
- package/src/auth/public-routes.ts +5 -0
- package/src/auth/shared-access.ts +376 -0
- package/src/index.ts +1 -0
- package/src/openapi/security.ts +20 -1
- package/src/openapi/tags.ts +4 -0
- package/src/registerRoutes.ts +6 -0
- package/src/routes/actions.ts +5 -10
- package/src/routes/agent-api-gateway.ts +1 -1
- package/src/routes/share-grants.ts +238 -0
- package/src/routes/shared-access.ts +165 -0
- package/src/schemas/agents.ts +1 -4
- package/src/schemas/datasets.ts +2 -1
- package/src/schemas/share-grants.ts +109 -0
- package/src/schemas/shared-access.ts +31 -0
- package/src/server.ts +91 -1
package/src/server.ts
CHANGED
|
@@ -30,11 +30,18 @@ import { ServerAuthGuard } from "./auth/guard"
|
|
|
30
30
|
import { consumeInternalRequestAuthState } from "./auth/scope"
|
|
31
31
|
import { SESSION_ACTIVITY_HEADER_NAME } from "./auth/session-activity"
|
|
32
32
|
import { createSessionRenewalCookieHeaders } from "./auth/session-cookies"
|
|
33
|
+
import {
|
|
34
|
+
SHARED_ACCESS_GRANT_HEADER_NAME,
|
|
35
|
+
SharedAccessBoundary,
|
|
36
|
+
type SixbSharedAccessOptions,
|
|
37
|
+
} from "./auth/shared-access"
|
|
33
38
|
import {
|
|
34
39
|
SIXB_BEARER_SECURITY_SCHEME,
|
|
35
40
|
SIXB_BEARER_SECURITY_SCHEME_ID,
|
|
36
41
|
SIXB_CSRF_SECURITY_SCHEME,
|
|
37
42
|
SIXB_CSRF_SECURITY_SCHEME_ID,
|
|
43
|
+
SIXB_SHARED_GRANT_SECURITY_SCHEME,
|
|
44
|
+
SIXB_SHARED_GRANT_SECURITY_SCHEME_ID,
|
|
38
45
|
} from "./openapi/security"
|
|
39
46
|
import { OPENAPI_TAG_METADATA } from "./openapi/tags"
|
|
40
47
|
import { registerHttpRoutes } from "./registerRoutes"
|
|
@@ -52,6 +59,8 @@ export interface SixbServerOptions {
|
|
|
52
59
|
browser: SixbApiBrowserPolicy
|
|
53
60
|
/** Optional custom-app auth bundle mounted under the API's `/auth` routes. */
|
|
54
61
|
authExperience?: SixbAuthExperienceOptions
|
|
62
|
+
/** Optional server limits for short-lived shared-access sessions. */
|
|
63
|
+
sharedAccess?: SixbSharedAccessOptions
|
|
55
64
|
}
|
|
56
65
|
|
|
57
66
|
export function createSixbServer(options: SixbServerOptions): SixbServer {
|
|
@@ -67,6 +76,7 @@ export class SixbServer {
|
|
|
67
76
|
private readonly authContextResolver: ResolveRequestAuthContext
|
|
68
77
|
private readonly authRedirectContextResolver: ResolveAuthRedirectContext
|
|
69
78
|
private readonly authExperience?: SixbAuthExperienceOptions
|
|
79
|
+
private readonly sharedAccessOptions: SixbSharedAccessOptions
|
|
70
80
|
private app: SixbApp | null = null
|
|
71
81
|
private bunServer: ReturnType<typeof Bun.serve> | null = null
|
|
72
82
|
private maintenance: OntologyMaintenanceHandle | null = null
|
|
@@ -82,6 +92,7 @@ export class SixbServer {
|
|
|
82
92
|
this.apiBrowserPolicy
|
|
83
93
|
)
|
|
84
94
|
this.authExperience = options.authExperience
|
|
95
|
+
this.sharedAccessOptions = options.sharedAccess ?? {}
|
|
85
96
|
}
|
|
86
97
|
|
|
87
98
|
getHost(): SixbHostView {
|
|
@@ -126,6 +137,10 @@ export class SixbServer {
|
|
|
126
137
|
return this.authExperience
|
|
127
138
|
}
|
|
128
139
|
|
|
140
|
+
getSharedAccessOptions(): SixbSharedAccessOptions {
|
|
141
|
+
return this.sharedAccessOptions
|
|
142
|
+
}
|
|
143
|
+
|
|
129
144
|
async start(): Promise<void> {
|
|
130
145
|
if (this.app !== null || this.bunServer !== null || this.maintenance !== null) {
|
|
131
146
|
throw new Error("[SixbServer] Server is already running.")
|
|
@@ -179,6 +194,11 @@ export function createSixbApi(server: SixbServer) {
|
|
|
179
194
|
host,
|
|
180
195
|
resolveAuthContext: (request) => server.resolveAuthContext(request),
|
|
181
196
|
})
|
|
197
|
+
const sharedAccess = new SharedAccessBoundary(host, server.getSharedAccessOptions())
|
|
198
|
+
const preparedSharedAccess = new WeakMap<
|
|
199
|
+
Request,
|
|
200
|
+
Awaited<ReturnType<SharedAccessBoundary["resolveRequest"]>>
|
|
201
|
+
>()
|
|
182
202
|
guard.assertCanServeHttp({ production: process.env.NODE_ENV === "production" })
|
|
183
203
|
const apiBrowserPolicy = server.getApiBrowserPolicy()
|
|
184
204
|
|
|
@@ -200,21 +220,65 @@ export function createSixbApi(server: SixbServer) {
|
|
|
200
220
|
"content-type",
|
|
201
221
|
CSRF_HEADER_NAME,
|
|
202
222
|
SESSION_ACTIVITY_HEADER_NAME,
|
|
223
|
+
SHARED_ACCESS_GRANT_HEADER_NAME,
|
|
203
224
|
],
|
|
204
225
|
exposeHeaders: [CSRF_TOKEN_RESPONSE_HEADER_NAME],
|
|
205
226
|
maxAge: 600,
|
|
206
227
|
})
|
|
207
228
|
)
|
|
229
|
+
app.onRequest(async ({ request, set }) => {
|
|
230
|
+
// Resolve Share intent before Elysia parses route inputs. Otherwise an unsupported route or an
|
|
231
|
+
// invalid shared session could escape through a route-specific 4xx before this boundary ran.
|
|
232
|
+
// CORS is registered first so allowed app origins can read these generic boundary responses.
|
|
233
|
+
const shared = await sharedAccess.resolveRequest(request)
|
|
234
|
+
preparedSharedAccess.set(request, shared)
|
|
235
|
+
if (shared.kind === "allow") {
|
|
236
|
+
// Route parsing happens after onRequest but before derive. Set this here so parse/schema
|
|
237
|
+
// failures from an authenticated shared request cannot become cacheable.
|
|
238
|
+
setResponseHeader(set, "cache-control", "no-store")
|
|
239
|
+
}
|
|
240
|
+
return shared.kind === "deny" ? shared.response : undefined
|
|
241
|
+
})
|
|
208
242
|
|
|
209
243
|
// Resolve authentication and bind one execution SDK at the request boundary. Protected routes
|
|
210
244
|
// never choose between a principal SDK and the ambient runtime themselves.
|
|
211
245
|
app
|
|
212
246
|
.derive(async ({ request }) => {
|
|
247
|
+
const shared =
|
|
248
|
+
preparedSharedAccess.get(request) ?? (await sharedAccess.resolveRequest(request))
|
|
249
|
+
preparedSharedAccess.delete(request)
|
|
250
|
+
if (shared.kind === "deny") {
|
|
251
|
+
return {
|
|
252
|
+
auth: { kind: "deny" as const, response: shared.response },
|
|
253
|
+
sharedAccessCookies: null,
|
|
254
|
+
sixb: null,
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (shared.kind === "allow") {
|
|
258
|
+
return {
|
|
259
|
+
auth: { kind: "allow" as const, session: null },
|
|
260
|
+
sharedAccessCookies: shared.cookies,
|
|
261
|
+
sixb: bindRequestExecution(host, {
|
|
262
|
+
request,
|
|
263
|
+
authorization: {
|
|
264
|
+
type: "delegated",
|
|
265
|
+
access: shared.context.access,
|
|
266
|
+
delegation: {
|
|
267
|
+
kind: "share",
|
|
268
|
+
grantId: shared.context.grantId,
|
|
269
|
+
sessionId: shared.context.sessionId,
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
}),
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
213
276
|
const internalAuthState = consumeInternalRequestAuthState(request)
|
|
214
277
|
if (internalAuthState) {
|
|
215
278
|
const { authorization, ...agentState } = internalAuthState
|
|
216
279
|
return {
|
|
217
280
|
auth: { kind: "allow" as const, session: null },
|
|
281
|
+
sharedAccessCookies: null,
|
|
218
282
|
...agentState,
|
|
219
283
|
sixb: bindRequestExecution(host, {
|
|
220
284
|
request,
|
|
@@ -227,6 +291,7 @@ export function createSixbApi(server: SixbServer) {
|
|
|
227
291
|
if (auth.kind === "deny" || !auth.session?.authenticated) {
|
|
228
292
|
return {
|
|
229
293
|
auth,
|
|
294
|
+
sharedAccessCookies: null,
|
|
230
295
|
sixb:
|
|
231
296
|
auth.kind === "allow" && !guard.isAuthEnabled()
|
|
232
297
|
? bindRequestExecution(host, {
|
|
@@ -244,6 +309,7 @@ export function createSixbApi(server: SixbServer) {
|
|
|
244
309
|
: { type: "accessToken" as const, id: auth.session.accessToken.id }
|
|
245
310
|
return {
|
|
246
311
|
auth,
|
|
312
|
+
sharedAccessCookies: null,
|
|
247
313
|
sixb: bindRequestExecution(host, {
|
|
248
314
|
request,
|
|
249
315
|
authorization: { type: "principal", context: authz, credential },
|
|
@@ -251,7 +317,29 @@ export function createSixbApi(server: SixbServer) {
|
|
|
251
317
|
}
|
|
252
318
|
})
|
|
253
319
|
.onBeforeHandle(({ auth }) => (auth.kind === "deny" ? auth.response : undefined))
|
|
254
|
-
.mapResponse(({ auth, request, set }) => {
|
|
320
|
+
.mapResponse(({ auth, request, responseValue, set, sharedAccessCookies }) => {
|
|
321
|
+
if (sharedAccessCookies) {
|
|
322
|
+
if (sharedAccessCookies.setCookies.length > 0) {
|
|
323
|
+
appendSetCookieHeaders(set, sharedAccessCookies.setCookies)
|
|
324
|
+
}
|
|
325
|
+
setResponseHeader(set, CSRF_TOKEN_RESPONSE_HEADER_NAME, sharedAccessCookies.csrfToken)
|
|
326
|
+
setResponseHeader(set, "cache-control", "no-store")
|
|
327
|
+
|
|
328
|
+
// Elysia intentionally gives headers from an explicit Response precedence over `set`.
|
|
329
|
+
// File reads carry their normal long-lived private cache policy on such a Response, so
|
|
330
|
+
// rebuild it with `no-store` at the same boundary that selected the Share authority.
|
|
331
|
+
if (responseValue instanceof Response) {
|
|
332
|
+
const headers = new Headers(responseValue.headers)
|
|
333
|
+
headers.set("cache-control", "no-store")
|
|
334
|
+
return new Response(responseValue.body, {
|
|
335
|
+
status: responseValue.status,
|
|
336
|
+
statusText: responseValue.statusText,
|
|
337
|
+
headers,
|
|
338
|
+
})
|
|
339
|
+
}
|
|
340
|
+
return
|
|
341
|
+
}
|
|
342
|
+
|
|
255
343
|
if (
|
|
256
344
|
!auth ||
|
|
257
345
|
auth.kind !== "allow" ||
|
|
@@ -288,6 +376,7 @@ export function createSixbApi(server: SixbServer) {
|
|
|
288
376
|
securitySchemes: {
|
|
289
377
|
[SIXB_CSRF_SECURITY_SCHEME_ID]: SIXB_CSRF_SECURITY_SCHEME,
|
|
290
378
|
[SIXB_BEARER_SECURITY_SCHEME_ID]: SIXB_BEARER_SECURITY_SCHEME,
|
|
379
|
+
[SIXB_SHARED_GRANT_SECURITY_SCHEME_ID]: SIXB_SHARED_GRANT_SECURITY_SCHEME,
|
|
291
380
|
},
|
|
292
381
|
schemas: ObjectQueryOpenApiSchemas,
|
|
293
382
|
},
|
|
@@ -318,6 +407,7 @@ export function createSixbApi(server: SixbServer) {
|
|
|
318
407
|
server.resolveInvitationRedirectContext(request, input),
|
|
319
408
|
})
|
|
320
409
|
registerHttpRoutes(app, host, {
|
|
410
|
+
sharedAccess,
|
|
321
411
|
connectorConnections: {
|
|
322
412
|
resolveReturnTo: (request, returnTo) => {
|
|
323
413
|
const authContext = server.resolveAuthContext(request)
|