@sixb/server 0.1.18 → 0.1.20
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 +15 -24
- package/dist/actions/serialize.d.ts +7 -0
- package/dist/actions/serialize.d.ts.map +1 -0
- package/dist/auth/browser-origin.d.ts +4 -26
- package/dist/auth/browser-origin.d.ts.map +1 -1
- package/dist/auth/experience.d.ts +0 -3
- package/dist/auth/experience.d.ts.map +1 -1
- package/dist/auth/guard.d.ts +1 -1
- package/dist/auth/guard.d.ts.map +1 -1
- package/dist/auth/public-routes.d.ts +0 -5
- package/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/auth/responses.d.ts +0 -2
- package/dist/auth/responses.d.ts.map +1 -1
- package/dist/auth/session-cookies.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +681 -935
- package/dist/index.js.map +24 -24
- package/dist/routes/action-runs.d.ts +11 -15
- package/dist/routes/action-runs.d.ts.map +1 -1
- package/dist/routes/actions.d.ts +44 -13
- package/dist/routes/actions.d.ts.map +1 -1
- package/dist/routes/agent-api-gateway.d.ts.map +1 -1
- package/dist/routes/agents.d.ts +20 -22
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/auth.d.ts +8 -17
- package/dist/routes/auth.d.ts.map +1 -1
- package/dist/routes/connector-connection-runs.d.ts +21 -21
- package/dist/routes/connector-connections.d.ts +8 -8
- package/dist/routes/connectors.d.ts +2 -2
- package/dist/routes/datasets.d.ts +5 -5
- package/dist/routes/events.d.ts +4 -4
- package/dist/routes/files.d.ts +15 -12
- package/dist/routes/files.d.ts.map +1 -1
- package/dist/routes/objects.d.ts +0 -2
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/ontology.d.ts +6 -6
- package/dist/routes/pipelines.d.ts +16 -16
- package/dist/routes/projections.d.ts +49 -49
- package/dist/routes/syncs.d.ts +10 -10
- package/dist/routes/webhook-runs.d.ts +2 -2
- package/dist/routes/workflows.d.ts +48 -52
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/routes/ws/events.d.ts +6 -9
- package/dist/routes/ws/events.d.ts.map +1 -1
- package/dist/schemas/actions.d.ts +100 -84
- package/dist/schemas/actions.d.ts.map +1 -1
- package/dist/schemas/agents.d.ts +20 -20
- package/dist/schemas/ai-limits.d.ts +10 -10
- package/dist/schemas/auth.d.ts +28 -63
- package/dist/schemas/auth.d.ts.map +1 -1
- package/dist/schemas/connectors.d.ts +8 -8
- package/dist/schemas/datasets.d.ts +40 -40
- package/dist/schemas/events.d.ts +24 -24
- package/dist/schemas/events.d.ts.map +1 -1
- package/dist/schemas/files.d.ts +4 -7
- package/dist/schemas/files.d.ts.map +1 -1
- package/dist/schemas/ontology.d.ts +40 -40
- package/dist/schemas/pipelines.d.ts +92 -92
- package/dist/schemas/projections.d.ts +290 -290
- package/dist/schemas/syncs.d.ts +34 -34
- package/dist/schemas/webhook-runs.d.ts +8 -8
- package/dist/schemas/workflows.d.ts +160 -160
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/utils/http.d.ts.map +1 -1
- package/dist/utils/request-body.d.ts +20 -6
- package/dist/utils/request-body.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/actions/serialize.ts +55 -0
- package/src/auth/browser-origin.ts +30 -240
- package/src/auth/experience.ts +1 -4
- package/src/auth/guard.ts +4 -32
- package/src/auth/public-routes.ts +1 -10
- package/src/auth/responses.ts +0 -5
- package/src/auth/session-cookies.ts +1 -3
- package/src/auth/shared-access.ts +1 -1
- package/src/index.ts +1 -1
- package/src/routes/action-runs.ts +1 -54
- package/src/routes/actions.ts +26 -8
- package/src/routes/agent-api-gateway.ts +18 -42
- package/src/routes/auth.ts +32 -111
- package/src/routes/files.ts +15 -63
- package/src/routes/ws/events.ts +2 -12
- package/src/schemas/actions.ts +21 -18
- package/src/schemas/auth.ts +2 -15
- package/src/schemas/files.ts +0 -6
- package/src/server.ts +23 -18
- package/src/utils/http.ts +2 -0
- package/src/utils/request-body.ts +55 -6
- package/dist/auth/application-access.d.ts +0 -4
- package/dist/auth/application-access.d.ts.map +0 -1
- package/src/auth/application-access.ts +0 -15
package/dist/index.js
CHANGED
|
@@ -5,51 +5,21 @@ import { openapi } from "@elysiajs/openapi";
|
|
|
5
5
|
import { CSRF_HEADER_NAME as CSRF_HEADER_NAME2, setRequestClientAddress } from "@sixb/core/internal/auth";
|
|
6
6
|
import { bindRequestExecution } from "@sixb/core/internal/request-execution";
|
|
7
7
|
import { setApiPublicOrigin } from "@sixb/core/internal/runtime";
|
|
8
|
-
import { Elysia } from "elysia";
|
|
8
|
+
import { Elysia, ParseError } from "elysia";
|
|
9
9
|
import { websocket as elysiaWebSocket } from "elysia/ws";
|
|
10
10
|
import { zodToJsonSchema as zodToJsonSchema2 } from "zod-to-json-schema";
|
|
11
11
|
|
|
12
12
|
// src/auth/browser-origin.ts
|
|
13
|
-
import {
|
|
14
|
-
applications,
|
|
15
|
-
DEFAULT_AUTH_SESSION_AUDIENCE,
|
|
16
|
-
isValidAuthSessionAudience,
|
|
17
|
-
resolveAuthSessionAudience
|
|
18
|
-
} from "@sixb/core";
|
|
19
|
-
import { matchesPathPattern, normalizeRoutePath, SIXB_API_ROUTES } from "@sixb/core/internal/http";
|
|
20
|
-
var fileNavigationRoutes = SIXB_API_ROUTES.filter((route) => (route.method === "GET" || route.method === "HEAD") && route.path.endsWith("/files/content"));
|
|
21
|
-
|
|
22
13
|
class BrowserOriginError extends Error {
|
|
23
14
|
name = "BrowserOriginError";
|
|
24
15
|
}
|
|
25
16
|
function resolveApiBrowserPolicy(policy) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
for (const entry of policy.allowedOrigins) {
|
|
30
|
-
const origin = normalizeHttpOrigin(entry.origin, "browser origin");
|
|
31
|
-
const audience = resolveAuthSessionAudience(entry.audience);
|
|
32
|
-
const existingAudienceOrigin = audienceOrigins.get(audience);
|
|
33
|
-
if (existingAudienceOrigin && existingAudienceOrigin !== origin) {
|
|
34
|
-
throw new Error(`[SixbServer] Auth audience '${audience}' is mapped to multiple browser origins.`);
|
|
35
|
-
}
|
|
36
|
-
audienceOrigins.set(audience, origin);
|
|
37
|
-
const existing = origins.get(origin);
|
|
38
|
-
if (existing) {
|
|
39
|
-
if (existing.audience !== audience) {
|
|
40
|
-
throw new Error(`[SixbServer] Browser origin '${origin}' is mapped to multiple auth audiences.`);
|
|
41
|
-
}
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
origins.set(origin, { origin, audience });
|
|
45
|
-
}
|
|
46
|
-
if (origins.size === 0) {
|
|
47
|
-
throw new Error("[SixbServer] API browser policy requires at least one allowed origin.");
|
|
48
|
-
}
|
|
17
|
+
const allowedOrigins = [
|
|
18
|
+
...new Set(policy.allowedOrigins.map((origin) => normalizeHttpOrigin(origin, "browser origin")))
|
|
19
|
+
];
|
|
49
20
|
return {
|
|
50
21
|
publicOrigin: policy.publicOrigin ? normalizeHttpOrigin(policy.publicOrigin, "API public origin") : undefined,
|
|
51
|
-
|
|
52
|
-
allowedOrigins: [...origins.values()]
|
|
22
|
+
allowedOrigins
|
|
53
23
|
};
|
|
54
24
|
}
|
|
55
25
|
function createApiBrowserAuthContextResolver(policy) {
|
|
@@ -60,118 +30,38 @@ function createApiBrowserAuthRedirectContextResolver(policy) {
|
|
|
60
30
|
}
|
|
61
31
|
function resolveApiBrowserAuthContext(policy, request) {
|
|
62
32
|
const origin = normalizeRequestOrigin(request);
|
|
63
|
-
const fileAudience = resolveFileNavigationAudience(policy, request);
|
|
64
33
|
if (!origin) {
|
|
65
|
-
return {
|
|
66
|
-
}
|
|
67
|
-
const allowed = findAllowedBrowserOrigin(policy, origin);
|
|
68
|
-
if (allowed) {
|
|
69
|
-
assertFileAudienceMatchesOrigin(fileAudience, allowed.audience);
|
|
70
|
-
return {
|
|
71
|
-
audience: allowed.audience,
|
|
72
|
-
browserOrigin: allowed.origin,
|
|
73
|
-
absoluteReturnTo: true
|
|
74
|
-
};
|
|
34
|
+
return { absoluteReturnTo: true };
|
|
75
35
|
}
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
return { audience: policy.apiOriginAudience, browserOrigin: origin, absoluteReturnTo: true };
|
|
36
|
+
if (isAllowedOrigin(policy, request, origin)) {
|
|
37
|
+
return { browserOrigin: origin, absoluteReturnTo: true };
|
|
79
38
|
}
|
|
80
39
|
throw new BrowserOriginError(`[SixbServer] Browser origin '${origin}' is not allowed.`);
|
|
81
40
|
}
|
|
82
|
-
function resolveFileNavigationAudience(policy, request) {
|
|
83
|
-
const url = new URL(request.url);
|
|
84
|
-
if (!fileNavigationRoutes.some((route) => route.method === request.method && matchesPathPattern(normalizeRoutePath(url.pathname), route.path))) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const values = url.searchParams.getAll("audience");
|
|
88
|
-
if (values.length === 0)
|
|
89
|
-
return;
|
|
90
|
-
const audience = values[0];
|
|
91
|
-
if (values.length !== 1 || !audience || !isValidAuthSessionAudience(audience) || audience !== policy.apiOriginAudience && !policy.allowedOrigins.some((entry) => entry.audience === audience)) {
|
|
92
|
-
throw new BrowserOriginError("[SixbServer] File navigation audience is not allowed.");
|
|
93
|
-
}
|
|
94
|
-
return audience;
|
|
95
|
-
}
|
|
96
|
-
function assertFileAudienceMatchesOrigin(audience, originAudience) {
|
|
97
|
-
if (audience !== undefined && audience !== originAudience) {
|
|
98
|
-
throw new BrowserOriginError("[SixbServer] File navigation audience conflicts with Origin.");
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
41
|
function isAllowedApiBrowserOrigin(policy, request) {
|
|
102
42
|
const origin = normalizeRequestOrigin(request);
|
|
103
|
-
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
return findAllowedBrowserOrigin(policy, origin) !== null || isSameOriginApiRequest(policy, origin, request);
|
|
43
|
+
return origin !== null && isAllowedOrigin(policy, request, origin);
|
|
107
44
|
}
|
|
108
45
|
function resolveApiBrowserAuthRedirectContext(policy, request, input) {
|
|
109
|
-
const audience = resolveRequiredAuthAudience(input.audience);
|
|
110
|
-
const returnTo = resolveApiBrowserReturnTo(policy, request, input, audience);
|
|
111
46
|
return {
|
|
112
|
-
|
|
113
|
-
returnTo,
|
|
47
|
+
returnTo: resolveApiBrowserReturnTo(policy, request, input),
|
|
114
48
|
requestOrigin: resolveApiBrowserPublicOrigin(policy, request)
|
|
115
49
|
};
|
|
116
50
|
}
|
|
117
|
-
function getApiBrowserInvitationDestinationOptions(policy) {
|
|
118
|
-
const destinations = policy.allowedOrigins.map((entry) => ({
|
|
119
|
-
id: entry.audience,
|
|
120
|
-
label: applications[entry.audience].label
|
|
121
|
-
}));
|
|
122
|
-
const defaultDestinationId = destinations.some((destination) => destination.id === "app") ? applications.app.id : destinations.some((destination) => destination.id === "atlas") ? applications.atlas.id : undefined;
|
|
123
|
-
return {
|
|
124
|
-
destinations,
|
|
125
|
-
...defaultDestinationId ? { defaultDestinationId } : {}
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
51
|
function resolveApiBrowserInvitationRedirectContext(policy, request, input) {
|
|
129
52
|
const authContext = resolveApiBrowserAuthContext(policy, request);
|
|
130
|
-
if (!input.destinationId) {
|
|
131
|
-
return resolveApiBrowserAuthRedirectContext(policy, request, {
|
|
132
|
-
audience: authContext.audience,
|
|
133
|
-
fallbackReturnToOrigin: authContext.browserOrigin,
|
|
134
|
-
returnTo: input.returnTo
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
const destination = policy.allowedOrigins.find((entry) => entry.audience === input.destinationId);
|
|
138
|
-
if (!destination) {
|
|
139
|
-
throw new BrowserOriginError("[SixbServer] Invitation destination is not allowed.");
|
|
140
|
-
}
|
|
141
|
-
assertInvitationReturnToOrigin(input.returnTo, destination.origin);
|
|
142
53
|
return resolveApiBrowserAuthRedirectContext(policy, request, {
|
|
143
|
-
|
|
144
|
-
fallbackReturnToOrigin: destination.origin,
|
|
54
|
+
fallbackReturnToOrigin: authContext.browserOrigin ?? policy.allowedOrigins[0],
|
|
145
55
|
returnTo: input.returnTo
|
|
146
56
|
});
|
|
147
57
|
}
|
|
148
58
|
function resolveApiBrowserPublicOrigin(policy, request) {
|
|
149
59
|
return policy.publicOrigin ?? new URL(request.url).origin;
|
|
150
60
|
}
|
|
151
|
-
function
|
|
152
|
-
return policy.allowedOrigins.
|
|
153
|
-
}
|
|
154
|
-
function isSameOriginApiRequest(policy, origin, request) {
|
|
155
|
-
const apiOrigin = resolveApiBrowserPublicOrigin(policy, request);
|
|
156
|
-
return origin === apiOrigin;
|
|
61
|
+
function isAllowedOrigin(policy, request, origin) {
|
|
62
|
+
return policy.allowedOrigins.includes(origin) || origin === resolveApiBrowserPublicOrigin(policy, request);
|
|
157
63
|
}
|
|
158
|
-
function
|
|
159
|
-
if (!returnTo?.trim())
|
|
160
|
-
return;
|
|
161
|
-
try {
|
|
162
|
-
if (new URL(returnTo).origin === destinationOrigin)
|
|
163
|
-
return;
|
|
164
|
-
} catch {}
|
|
165
|
-
throw new BrowserOriginError("[SixbServer] Invitation return target is not allowed.");
|
|
166
|
-
}
|
|
167
|
-
function resolveRequiredAuthAudience(value) {
|
|
168
|
-
const audience = value?.trim();
|
|
169
|
-
if (!audience || !isValidAuthSessionAudience(audience)) {
|
|
170
|
-
throw new BrowserOriginError("[SixbServer] Auth audience is invalid or missing.");
|
|
171
|
-
}
|
|
172
|
-
return audience;
|
|
173
|
-
}
|
|
174
|
-
function resolveApiBrowserReturnTo(policy, request, input, audience) {
|
|
64
|
+
function resolveApiBrowserReturnTo(policy, request, input) {
|
|
175
65
|
const rawReturnTo = input.returnTo?.trim();
|
|
176
66
|
const value = rawReturnTo || (input.fallbackReturnToOrigin ? new URL("/", normalizeHttpOrigin(input.fallbackReturnToOrigin, "fallback return origin")).href : "");
|
|
177
67
|
if (!value) {
|
|
@@ -183,25 +73,11 @@ function resolveApiBrowserReturnTo(policy, request, input, audience) {
|
|
|
183
73
|
} catch {
|
|
184
74
|
throw new BrowserOriginError("[SixbServer] Auth return target must be an absolute URL.");
|
|
185
75
|
}
|
|
186
|
-
if (url.protocol !== "http:" && url.protocol !== "https:" || url.username || url.password) {
|
|
187
|
-
throw new BrowserOriginError("[SixbServer] Auth return target is not allowed.");
|
|
188
|
-
}
|
|
189
|
-
const returnAudience = resolveReturnToAudience(policy, request, url.origin);
|
|
190
|
-
if (returnAudience !== audience) {
|
|
76
|
+
if (url.protocol !== "http:" && url.protocol !== "https:" || url.username || url.password || !isAllowedOrigin(policy, request, url.origin)) {
|
|
191
77
|
throw new BrowserOriginError("[SixbServer] Auth return target is not allowed.");
|
|
192
78
|
}
|
|
193
79
|
return url.toString();
|
|
194
80
|
}
|
|
195
|
-
function resolveReturnToAudience(policy, request, origin) {
|
|
196
|
-
const allowed = findAllowedBrowserOrigin(policy, origin);
|
|
197
|
-
if (allowed) {
|
|
198
|
-
return allowed.audience;
|
|
199
|
-
}
|
|
200
|
-
if (origin === resolveApiBrowserPublicOrigin(policy, request)) {
|
|
201
|
-
return policy.apiOriginAudience;
|
|
202
|
-
}
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
81
|
function normalizeRequestOrigin(request) {
|
|
206
82
|
const origin = request.headers.get("origin");
|
|
207
83
|
if (!origin) {
|
|
@@ -286,7 +162,7 @@ import {
|
|
|
286
162
|
|
|
287
163
|
// src/auth/access-token-boundary.ts
|
|
288
164
|
import { isCsrfExemptMethod as isCsrfExemptMethod2 } from "@sixb/core/internal/auth";
|
|
289
|
-
import { matchesPathPattern as
|
|
165
|
+
import { matchesPathPattern as matchesPathPattern2, normalizeRoutePath as normalizeRoutePath2, SIXB_API_ROUTES as SIXB_API_ROUTES2 } from "@sixb/core/internal/http";
|
|
290
166
|
|
|
291
167
|
// src/openapi/security.ts
|
|
292
168
|
import { CSRF_HEADER_NAME } from "@sixb/core/internal/auth";
|
|
@@ -299,7 +175,7 @@ import {
|
|
|
299
175
|
isCsrfExemptMethod,
|
|
300
176
|
verifyDoubleSubmitCsrf
|
|
301
177
|
} from "@sixb/core/internal/auth";
|
|
302
|
-
import { matchesPathPattern
|
|
178
|
+
import { matchesPathPattern, normalizeRoutePath, SIXB_API_ROUTES } from "@sixb/core/internal/http";
|
|
303
179
|
import { SharedSessionProtocol } from "@sixb/core/internal/shares";
|
|
304
180
|
|
|
305
181
|
// src/auth/session-activity.ts
|
|
@@ -323,7 +199,7 @@ var SHARED_SESSION_COOKIE_PREFIX = "sixb_share_session_";
|
|
|
323
199
|
var SHARED_CSRF_COOKIE_PREFIX = "sixb_share_csrf_";
|
|
324
200
|
var SHARED_COOKIE_PATH = "/api";
|
|
325
201
|
var STORED_IDENTIFIER_MAX_LENGTH = 128;
|
|
326
|
-
var SHARED_SESSION_ROUTES =
|
|
202
|
+
var SHARED_SESSION_ROUTES = SIXB_API_ROUTES.filter((route) => route.sharedSession);
|
|
327
203
|
var SHARED_FILE_CONTENT_ROUTES = SHARED_SESSION_ROUTES.filter((route) => (route.method === "GET" || route.method === "HEAD") && route.path.endsWith("/files/content"));
|
|
328
204
|
|
|
329
205
|
class SharedAccessBoundary {
|
|
@@ -511,18 +387,18 @@ function isSharedAccessPublicRoute(request) {
|
|
|
511
387
|
}
|
|
512
388
|
function isSharedAccessPublicPath(pathname, requestMethod) {
|
|
513
389
|
const method = requestMethod.toUpperCase();
|
|
514
|
-
const normalizedPathname =
|
|
390
|
+
const normalizedPathname = normalizeRoutePath(pathname);
|
|
515
391
|
const suffix = method === "POST" && normalizedPathname.endsWith("/exchange") ? "exchange" : method === "GET" && normalizedPathname.endsWith("/session") ? "session" : method === "POST" && normalizedPathname.endsWith("/sign-out") ? "sign-out" : null;
|
|
516
392
|
if (!suffix)
|
|
517
393
|
return false;
|
|
518
|
-
return
|
|
394
|
+
return matchesPathPattern(normalizedPathname, `/api/shared-access/:grantId/${suffix}`);
|
|
519
395
|
}
|
|
520
396
|
function selectSharedAccessGrant(request) {
|
|
521
397
|
const header = request.headers.get(SHARED_ACCESS_GRANT_HEADER_NAME);
|
|
522
398
|
const url = new URL(request.url);
|
|
523
399
|
const method = request.method.toUpperCase();
|
|
524
|
-
const pathname =
|
|
525
|
-
const queryValues = SHARED_FILE_CONTENT_ROUTES.some((route) => route.method === method &&
|
|
400
|
+
const pathname = normalizeRoutePath(url.pathname);
|
|
401
|
+
const queryValues = SHARED_FILE_CONTENT_ROUTES.some((route) => route.method === method && matchesPathPattern(pathname, route.path)) ? url.searchParams.getAll(SHARED_ACCESS_GRANT_QUERY_PARAM) : [];
|
|
526
402
|
const [query, ...extra] = queryValues;
|
|
527
403
|
if (query === undefined) {
|
|
528
404
|
return header === null ? { kind: "absent" } : { kind: "selected", grantId: header };
|
|
@@ -533,8 +409,8 @@ function selectSharedAccessGrant(request) {
|
|
|
533
409
|
}
|
|
534
410
|
function isSharedSessionRoute(request) {
|
|
535
411
|
const method = request.method.toUpperCase();
|
|
536
|
-
const pathname =
|
|
537
|
-
return SHARED_SESSION_ROUTES.some((route) => route.method === method &&
|
|
412
|
+
const pathname = normalizeRoutePath(new URL(request.url).pathname);
|
|
413
|
+
return SHARED_SESSION_ROUTES.some((route) => route.method === method && matchesPathPattern(pathname, route.path));
|
|
538
414
|
}
|
|
539
415
|
function sharedAccessUnauthenticatedResponse() {
|
|
540
416
|
return sharedBoundaryJsonResponse({ error: "Shared access session is invalid" }, 401);
|
|
@@ -643,7 +519,7 @@ var SIXB_SHARED_GRANT_SECURITY_SCHEME = {
|
|
|
643
519
|
};
|
|
644
520
|
|
|
645
521
|
// src/auth/access-token-boundary.ts
|
|
646
|
-
var ACCESS_TOKEN_ROUTES =
|
|
522
|
+
var ACCESS_TOKEN_ROUTES = SIXB_API_ROUTES2.filter((route) => route.accessToken).map((route) => ({
|
|
647
523
|
operationId: route.operationId,
|
|
648
524
|
method: route.method,
|
|
649
525
|
path: route.path,
|
|
@@ -665,8 +541,8 @@ function accessTokenSecurityRequirement(operationId) {
|
|
|
665
541
|
function isAccessTokenRoute(request) {
|
|
666
542
|
const url = new URL(request.url);
|
|
667
543
|
const method = request.method.toUpperCase();
|
|
668
|
-
const pathname =
|
|
669
|
-
return ACCESS_TOKEN_ROUTES.some((route) => route.method === method &&
|
|
544
|
+
const pathname = normalizeRoutePath2(url.pathname);
|
|
545
|
+
return ACCESS_TOKEN_ROUTES.some((route) => route.method === method && matchesPathPattern2(pathname, route.path));
|
|
670
546
|
}
|
|
671
547
|
function credentialTransport(caller) {
|
|
672
548
|
return caller.credentialSource === "session" && !caller.session.bearer ? "cookie" : "bearer";
|
|
@@ -675,13 +551,6 @@ function shouldVerifyCsrf(route, transport) {
|
|
|
675
551
|
return route.csrfProtected && transport === "cookie";
|
|
676
552
|
}
|
|
677
553
|
|
|
678
|
-
// src/auth/application-access.ts
|
|
679
|
-
import { canAccessApplication } from "@sixb/core";
|
|
680
|
-
function sessionCanAccessApplication(host, session, audience) {
|
|
681
|
-
const authorization = host.auth.contextFromSession(session);
|
|
682
|
-
return canAccessApplication(authorization, host.definitions.security.listResolvedRoles(), audience);
|
|
683
|
-
}
|
|
684
|
-
|
|
685
554
|
// src/auth/public-routes.ts
|
|
686
555
|
import { AGENT_API_GATEWAY_PREFIX } from "@sixb/core/internal/agents";
|
|
687
556
|
import { isCsrfExemptMethod as isCsrfExemptMethod3 } from "@sixb/core/internal/auth";
|
|
@@ -699,10 +568,7 @@ function classifyRoute(request) {
|
|
|
699
568
|
if (pathname.startsWith("/api/")) {
|
|
700
569
|
return { kind: "api", csrfProtected: !isCsrfExemptMethod3(request.method) };
|
|
701
570
|
}
|
|
702
|
-
if (pathname === "/auth/device") {
|
|
703
|
-
return { kind: "html", csrfProtected: !isCsrfExemptMethod3(request.method), account: true };
|
|
704
|
-
}
|
|
705
|
-
if (pathname === "/docs" || pathname.startsWith("/docs/")) {
|
|
571
|
+
if (pathname === "/auth/device" || pathname === "/docs" || pathname.startsWith("/docs/")) {
|
|
706
572
|
return { kind: "html", csrfProtected: !isCsrfExemptMethod3(request.method) };
|
|
707
573
|
}
|
|
708
574
|
return { kind: "api", csrfProtected: !isCsrfExemptMethod3(request.method) };
|
|
@@ -791,9 +657,6 @@ function htmlAuthRedirectResponse(request, options = {}) {
|
|
|
791
657
|
const requestUrl = new URL(request.url);
|
|
792
658
|
const rawReturnTo = options.absoluteReturnTo ? new URL(returnToForRequest(request), requestUrl.origin).toString() : returnToForRequest(request);
|
|
793
659
|
const params = new URLSearchParams({ returnTo: rawReturnTo });
|
|
794
|
-
if (options.absoluteReturnTo && options.audience) {
|
|
795
|
-
params.set("audience", options.audience);
|
|
796
|
-
}
|
|
797
660
|
return new Response(null, {
|
|
798
661
|
status: 302,
|
|
799
662
|
headers: {
|
|
@@ -842,17 +705,13 @@ class ServerAuthGuard {
|
|
|
842
705
|
if (authContext instanceof Response) {
|
|
843
706
|
return { kind: "deny", response: authContext };
|
|
844
707
|
}
|
|
845
|
-
let session = await this.host.auth.getSession(request, {
|
|
846
|
-
audience: authContext.audience,
|
|
847
|
-
credentialSource: "any"
|
|
848
|
-
});
|
|
708
|
+
let session = await this.host.auth.getSession(request, { credentialSource: "any" });
|
|
849
709
|
if (!session.authenticated) {
|
|
850
710
|
if (route.kind === "html") {
|
|
851
711
|
return {
|
|
852
712
|
kind: "deny",
|
|
853
713
|
response: htmlAuthRedirectResponse(request, {
|
|
854
|
-
absoluteReturnTo: authContext.absoluteReturnTo ?? false
|
|
855
|
-
audience: authContext.audience
|
|
714
|
+
absoluteReturnTo: authContext.absoluteReturnTo ?? false
|
|
856
715
|
})
|
|
857
716
|
};
|
|
858
717
|
}
|
|
@@ -861,13 +720,6 @@ class ServerAuthGuard {
|
|
|
861
720
|
}
|
|
862
721
|
return { kind: "deny", response: jsonAuthRequiredResponse() };
|
|
863
722
|
}
|
|
864
|
-
const deniedApplication = (caller) => !route.account && credentialTransport(caller) === "cookie" && !sessionCanAccessApplication(this.host, caller, authContext.audience);
|
|
865
|
-
if (deniedApplication(session)) {
|
|
866
|
-
return {
|
|
867
|
-
kind: "deny",
|
|
868
|
-
response: jsonForbiddenResponse("Application access is not allowed")
|
|
869
|
-
};
|
|
870
|
-
}
|
|
871
723
|
if (session.credentialSource === "accessToken" && !isAccessTokenRoute(request)) {
|
|
872
724
|
return {
|
|
873
725
|
kind: "deny",
|
|
@@ -879,7 +731,6 @@ class ServerAuthGuard {
|
|
|
879
731
|
}
|
|
880
732
|
if (session.credentialSource === "session" && credentialTransport(session) === "cookie" && route.kind !== "websocket" && !isSessionTerminationRequest(request) && hasForegroundSessionActivity(request)) {
|
|
881
733
|
const activeSession = await this.host.auth.getSession(request, {
|
|
882
|
-
audience: authContext.audience,
|
|
883
734
|
credentialSource: "session",
|
|
884
735
|
sessionActivity: "foreground"
|
|
885
736
|
});
|
|
@@ -888,30 +739,22 @@ class ServerAuthGuard {
|
|
|
888
739
|
return {
|
|
889
740
|
kind: "deny",
|
|
890
741
|
response: htmlAuthRedirectResponse(request, {
|
|
891
|
-
absoluteReturnTo: authContext.absoluteReturnTo ?? false
|
|
892
|
-
audience: authContext.audience
|
|
742
|
+
absoluteReturnTo: authContext.absoluteReturnTo ?? false
|
|
893
743
|
})
|
|
894
744
|
};
|
|
895
745
|
}
|
|
896
746
|
return { kind: "deny", response: jsonAuthRequiredResponse() };
|
|
897
747
|
}
|
|
898
|
-
if (deniedApplication(activeSession)) {
|
|
899
|
-
return {
|
|
900
|
-
kind: "deny",
|
|
901
|
-
response: jsonForbiddenResponse("Application access is not allowed")
|
|
902
|
-
};
|
|
903
|
-
}
|
|
904
748
|
session = activeSession;
|
|
905
749
|
}
|
|
906
750
|
return { kind: "allow", session };
|
|
907
751
|
}
|
|
908
|
-
getCsrfCookieName(
|
|
909
|
-
|
|
910
|
-
return this.host.auth.getCookieOptions({ audience }).csrfCookieName;
|
|
752
|
+
getCsrfCookieName() {
|
|
753
|
+
return this.host.auth.getCookieOptions().csrfCookieName;
|
|
911
754
|
}
|
|
912
755
|
verifyCsrf(request, _session) {
|
|
913
756
|
return verifyDoubleSubmitCsrf2(request, {
|
|
914
|
-
cookieName: this.getCsrfCookieName(
|
|
757
|
+
cookieName: this.getCsrfCookieName()
|
|
915
758
|
});
|
|
916
759
|
}
|
|
917
760
|
tryResolveAuthContext(request) {
|
|
@@ -966,9 +809,7 @@ import {
|
|
|
966
809
|
getCookie as getCookie2
|
|
967
810
|
} from "@sixb/core/internal/auth";
|
|
968
811
|
function createSessionRenewalCookieHeaders(input) {
|
|
969
|
-
const cookieOptions = input.host.auth.getCookieOptions(
|
|
970
|
-
audience: input.session.session.audience
|
|
971
|
-
});
|
|
812
|
+
const cookieOptions = input.host.auth.getCookieOptions();
|
|
972
813
|
const sessionValue = getCookie2(input.request, cookieOptions.sessionCookieName);
|
|
973
814
|
if (!sessionValue) {
|
|
974
815
|
return null;
|
|
@@ -1168,352 +1009,70 @@ var OPENAPI_TAG_METADATA = Object.values(OPENAPI_TAGS).map(({ name, description
|
|
|
1168
1009
|
// src/routes/action-runs.ts
|
|
1169
1010
|
import { z as z5 } from "zod";
|
|
1170
1011
|
|
|
1171
|
-
// src/
|
|
1172
|
-
import {
|
|
1173
|
-
import { fileNameFor } from "@sixb/core";
|
|
1174
|
-
import { BlobStorageError, supportsRangeRead } from "@sixb/core/blob-storage/server";
|
|
1012
|
+
// src/schemas/actions.ts
|
|
1013
|
+
import { SIXB_ERROR_CODES } from "@sixb/core/internal/errors";
|
|
1175
1014
|
import {
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
} from "
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
}
|
|
1190
|
-
};
|
|
1191
|
-
function handleFileContentQueryValidationError(context) {
|
|
1192
|
-
if (context.code !== "VALIDATION" || context.error.type !== "query")
|
|
1193
|
-
return;
|
|
1194
|
-
context.set.status = 400;
|
|
1195
|
-
return { error: "Invalid file content query" };
|
|
1196
|
-
}
|
|
1197
|
-
function fileContentGetResponses(options = {}) {
|
|
1198
|
-
return {
|
|
1199
|
-
200: {
|
|
1200
|
-
description: "File content",
|
|
1201
|
-
content: {
|
|
1202
|
-
"application/octet-stream": {
|
|
1203
|
-
schema: { type: "string", format: "binary" }
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
},
|
|
1207
|
-
206: {
|
|
1208
|
-
description: "Partial file content",
|
|
1209
|
-
content: {
|
|
1210
|
-
"application/octet-stream": {
|
|
1211
|
-
schema: { type: "string", format: "binary" }
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
},
|
|
1215
|
-
304: {
|
|
1216
|
-
description: "File representation is unchanged; reuse the privately cached content"
|
|
1217
|
-
},
|
|
1218
|
-
400: {
|
|
1219
|
-
description: "Response for status 400",
|
|
1220
|
-
content: {
|
|
1221
|
-
"application/json": {
|
|
1222
|
-
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
},
|
|
1226
|
-
404: {
|
|
1227
|
-
description: "Response for status 404",
|
|
1228
|
-
content: {
|
|
1229
|
-
"application/json": {
|
|
1230
|
-
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
},
|
|
1234
|
-
416: {
|
|
1235
|
-
description: "Requested byte range is not satisfiable"
|
|
1236
|
-
},
|
|
1237
|
-
...options.optionalStorage ? unconfiguredStorageResponse : {}
|
|
1238
|
-
};
|
|
1015
|
+
ACTION_RUN_FAILURE_CODES,
|
|
1016
|
+
ACTION_RUN_PHASES
|
|
1017
|
+
} from "@sixb/core/storage";
|
|
1018
|
+
import { z as z3 } from "zod";
|
|
1019
|
+
|
|
1020
|
+
// src/schemas/common.ts
|
|
1021
|
+
import { SIXB_FAILURE_MAX_MESSAGE_BYTES } from "@sixb/core/internal/errors";
|
|
1022
|
+
import { z } from "zod";
|
|
1023
|
+
import { ignoreOverride } from "zod-to-json-schema";
|
|
1024
|
+
var ErrorResponseSchema = z.object({ error: z.string() });
|
|
1025
|
+
function codedErrorResponseSchema(codes) {
|
|
1026
|
+
return ErrorResponseSchema.extend({
|
|
1027
|
+
code: z.enum(codes).describe("Stable machine-readable failure code for programmatic handling.")
|
|
1028
|
+
});
|
|
1239
1029
|
}
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
},
|
|
1267
|
-
416: {
|
|
1268
|
-
description: "Requested byte range is not satisfiable"
|
|
1269
|
-
},
|
|
1270
|
-
...options.optionalStorage ? unconfiguredStorageResponse : {}
|
|
1271
|
-
};
|
|
1030
|
+
var RedactionsSchema = z.record(z.object({ reason: z.literal("missing_clearance") }));
|
|
1031
|
+
var SuccessResponseSchema = z.object({ success: z.boolean() });
|
|
1032
|
+
var PrincipalSchema = z.object({
|
|
1033
|
+
type: z.enum(["user", "serviceAccount", "system"]),
|
|
1034
|
+
id: z.string().min(1)
|
|
1035
|
+
});
|
|
1036
|
+
var JsonValueSchema = z.lazy(() => z.union([
|
|
1037
|
+
z.string(),
|
|
1038
|
+
z.number().finite(),
|
|
1039
|
+
z.boolean(),
|
|
1040
|
+
z.null(),
|
|
1041
|
+
z.array(JsonValueSchema),
|
|
1042
|
+
z.record(JsonValueSchema)
|
|
1043
|
+
]));
|
|
1044
|
+
var JsonNullSchema = JsonValueSchema.refine((value) => value === null);
|
|
1045
|
+
function sixbFailureSchema(codes) {
|
|
1046
|
+
return z.object({
|
|
1047
|
+
code: z.enum(codes),
|
|
1048
|
+
message: z.string().max(SIXB_FAILURE_MAX_MESSAGE_BYTES),
|
|
1049
|
+
retryable: z.boolean(),
|
|
1050
|
+
at: z.string().datetime(),
|
|
1051
|
+
details: JsonValueSchema.optional(),
|
|
1052
|
+
httpStatus: z.number().int().min(100).max(599).optional(),
|
|
1053
|
+
redacted: z.literal(true).optional(),
|
|
1054
|
+
truncated: z.literal(true).optional()
|
|
1055
|
+
});
|
|
1272
1056
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
}
|
|
1290
|
-
const partialHeaders = partialFileContentHeaders(headers, range, stat.sizeBytes);
|
|
1291
|
-
if (input.head) {
|
|
1292
|
-
return new Response(null, { status: 206, headers: partialHeaders });
|
|
1293
|
-
}
|
|
1294
|
-
try {
|
|
1295
|
-
const stream = await input.blobStorage.openRange(input.fileRef.blobId, range);
|
|
1296
|
-
return new Response(stream, { status: 206, headers: partialHeaders });
|
|
1297
|
-
} catch (error) {
|
|
1298
|
-
if (error instanceof BlobStorageError) {
|
|
1299
|
-
return null;
|
|
1300
|
-
}
|
|
1301
|
-
throw error;
|
|
1302
|
-
}
|
|
1057
|
+
var JsonValueOpenApiSchema = {
|
|
1058
|
+
description: "Any JSON-compatible value.",
|
|
1059
|
+
nullable: true,
|
|
1060
|
+
anyOf: [
|
|
1061
|
+
{ type: "string" },
|
|
1062
|
+
{ type: "number" },
|
|
1063
|
+
{ type: "boolean" },
|
|
1064
|
+
{ type: "array", items: {} },
|
|
1065
|
+
{ type: "object", additionalProperties: true }
|
|
1066
|
+
]
|
|
1067
|
+
};
|
|
1068
|
+
var jsonValueSchemaDef = JsonValueSchema._def;
|
|
1069
|
+
var jsonNullSchemaDef = JsonNullSchema._def;
|
|
1070
|
+
var jsonValueOpenApiOverride = (def) => {
|
|
1071
|
+
if (def === jsonValueSchemaDef) {
|
|
1072
|
+
return JsonValueOpenApiSchema;
|
|
1303
1073
|
}
|
|
1304
|
-
if (
|
|
1305
|
-
return
|
|
1306
|
-
}
|
|
1307
|
-
try {
|
|
1308
|
-
const stream = await input.blobStorage.open(input.fileRef.blobId);
|
|
1309
|
-
return new Response(stream, { headers });
|
|
1310
|
-
} catch (error) {
|
|
1311
|
-
if (error instanceof BlobStorageError) {
|
|
1312
|
-
return null;
|
|
1313
|
-
}
|
|
1314
|
-
throw error;
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
async function createContextualFileContentResponse(input) {
|
|
1318
|
-
const missingMessage = input.missingMessage ?? "File not found";
|
|
1319
|
-
const invalidQueryMessage = input.invalidQueryMessage ?? "Invalid file content query";
|
|
1320
|
-
try {
|
|
1321
|
-
const parsed = input.querySchema.parse(input.query);
|
|
1322
|
-
const root = await input.resolveRoot(parsed);
|
|
1323
|
-
if (root === null || root === undefined) {
|
|
1324
|
-
return fileContentNotFound(input.set, missingMessage);
|
|
1325
|
-
}
|
|
1326
|
-
const fileRef = resolveFileRefAtPath(root, parsed.path);
|
|
1327
|
-
if (!fileRef) {
|
|
1328
|
-
return fileContentNotFound(input.set, missingMessage);
|
|
1329
|
-
}
|
|
1330
|
-
const response = await createFileContentResponse({
|
|
1331
|
-
blobStorage: input.blobStorage,
|
|
1332
|
-
fileRef,
|
|
1333
|
-
disposition: parsed.disposition,
|
|
1334
|
-
head: input.head,
|
|
1335
|
-
rangeHeader: input.request.headers.get("range"),
|
|
1336
|
-
ifNoneMatchHeader: input.request.headers.get("if-none-match"),
|
|
1337
|
-
ifRangeHeader: input.request.headers.get("if-range")
|
|
1338
|
-
});
|
|
1339
|
-
if (!response) {
|
|
1340
|
-
return fileContentNotFound(input.set, missingMessage);
|
|
1341
|
-
}
|
|
1342
|
-
return response;
|
|
1343
|
-
} catch (error) {
|
|
1344
|
-
if (error instanceof ZodError) {
|
|
1345
|
-
input.set.status = 400;
|
|
1346
|
-
return { error: invalidQueryMessage };
|
|
1347
|
-
}
|
|
1348
|
-
if (input.hideError?.(error)) {
|
|
1349
|
-
return fileContentNotFound(input.set, missingMessage);
|
|
1350
|
-
}
|
|
1351
|
-
throw error;
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
function fileContentNotFound(set, message) {
|
|
1355
|
-
set.status = 404;
|
|
1356
|
-
return { error: message };
|
|
1357
|
-
}
|
|
1358
|
-
function matchesIfNoneMatch(header, etag) {
|
|
1359
|
-
return header?.trim() === "*" || (header?.split(",").some((value) => value.trim().replace(/^W\//, "") === etag) ?? false);
|
|
1360
|
-
}
|
|
1361
|
-
var INLINE_MEDIA_TYPES = new Set([
|
|
1362
|
-
"application/json",
|
|
1363
|
-
"application/pdf",
|
|
1364
|
-
"image/avif",
|
|
1365
|
-
"image/bmp",
|
|
1366
|
-
"image/gif",
|
|
1367
|
-
"image/jpeg",
|
|
1368
|
-
"image/png",
|
|
1369
|
-
"image/webp",
|
|
1370
|
-
"text/markdown",
|
|
1371
|
-
"text/plain"
|
|
1372
|
-
]);
|
|
1373
|
-
var FILE_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inline'; sandbox";
|
|
1374
|
-
var PDF_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inline'; object-src 'self'";
|
|
1375
|
-
function fileContentHeaders(fileRef, stat, requestedDisposition, canReadRange) {
|
|
1376
|
-
const mediaType = canonicalMediaType(fileRef.mediaType) ?? "application/octet-stream";
|
|
1377
|
-
const baseType = mediaType.split(";", 1)[0];
|
|
1378
|
-
const disposition = (requestedDisposition ?? "inline") === "inline" && INLINE_MEDIA_TYPES.has(baseType) ? "inline" : "attachment";
|
|
1379
|
-
const headers = new Headers;
|
|
1380
|
-
headers.set("content-type", mediaType);
|
|
1381
|
-
headers.set("content-length", stat.sizeBytes.toString());
|
|
1382
|
-
headers.set("content-disposition", contentDispositionHeader(disposition, fileNameFor(fileRef)));
|
|
1383
|
-
headers.set("content-security-policy", baseType === "application/pdf" ? PDF_CONTENT_SECURITY_POLICY : FILE_CONTENT_SECURITY_POLICY);
|
|
1384
|
-
const representation = JSON.stringify([
|
|
1385
|
-
fileRef.digest,
|
|
1386
|
-
mediaType,
|
|
1387
|
-
headers.get("content-disposition")
|
|
1388
|
-
]);
|
|
1389
|
-
headers.set("etag", `"sha256:${createHash2("sha256").update(representation).digest("hex")}"`);
|
|
1390
|
-
headers.set("x-content-type-options", "nosniff");
|
|
1391
|
-
headers.set("cache-control", "private, no-cache");
|
|
1392
|
-
if (canReadRange) {
|
|
1393
|
-
headers.set("accept-ranges", "bytes");
|
|
1394
|
-
}
|
|
1395
|
-
return headers;
|
|
1396
|
-
}
|
|
1397
|
-
function parseSingleByteRange(header, sizeBytes) {
|
|
1398
|
-
const normalized = header.trim();
|
|
1399
|
-
if (!normalized.startsWith("bytes=") || normalized.includes(",")) {
|
|
1400
|
-
return null;
|
|
1401
|
-
}
|
|
1402
|
-
if (sizeBytes <= 0) {
|
|
1403
|
-
return null;
|
|
1404
|
-
}
|
|
1405
|
-
const spec = normalized.slice("bytes=".length).trim();
|
|
1406
|
-
const match = spec.match(/^(\d*)-(\d*)$/);
|
|
1407
|
-
if (!match) {
|
|
1408
|
-
return null;
|
|
1409
|
-
}
|
|
1410
|
-
const [, rawStart, rawEnd] = match;
|
|
1411
|
-
if (!rawStart && !rawEnd) {
|
|
1412
|
-
return null;
|
|
1413
|
-
}
|
|
1414
|
-
if (!rawStart) {
|
|
1415
|
-
const suffixLength = Number(rawEnd);
|
|
1416
|
-
if (!Number.isSafeInteger(suffixLength) || suffixLength <= 0) {
|
|
1417
|
-
return null;
|
|
1418
|
-
}
|
|
1419
|
-
return {
|
|
1420
|
-
start: Math.max(sizeBytes - suffixLength, 0),
|
|
1421
|
-
endInclusive: sizeBytes - 1
|
|
1422
|
-
};
|
|
1423
|
-
}
|
|
1424
|
-
const start = Number(rawStart);
|
|
1425
|
-
if (!Number.isSafeInteger(start) || start >= sizeBytes) {
|
|
1426
|
-
return null;
|
|
1427
|
-
}
|
|
1428
|
-
const requestedEnd = rawEnd ? Number(rawEnd) : sizeBytes - 1;
|
|
1429
|
-
if (!Number.isSafeInteger(requestedEnd) || requestedEnd < start) {
|
|
1430
|
-
return null;
|
|
1431
|
-
}
|
|
1432
|
-
return {
|
|
1433
|
-
start,
|
|
1434
|
-
endInclusive: Math.min(requestedEnd, sizeBytes - 1)
|
|
1435
|
-
};
|
|
1436
|
-
}
|
|
1437
|
-
function partialFileContentHeaders(baseHeaders, range, sizeBytes) {
|
|
1438
|
-
const headers = new Headers(baseHeaders);
|
|
1439
|
-
headers.set("content-length", (range.endInclusive - range.start + 1).toString());
|
|
1440
|
-
headers.set("content-range", `bytes ${range.start}-${range.endInclusive}/${sizeBytes}`);
|
|
1441
|
-
return headers;
|
|
1442
|
-
}
|
|
1443
|
-
function rangeNotSatisfiableResponse(sizeBytes) {
|
|
1444
|
-
const headers = new Headers;
|
|
1445
|
-
headers.set("accept-ranges", "bytes");
|
|
1446
|
-
headers.set("content-range", `bytes */${sizeBytes}`);
|
|
1447
|
-
return new Response(null, { status: 416, headers });
|
|
1448
|
-
}
|
|
1449
|
-
function contentDispositionHeader(disposition, fileName) {
|
|
1450
|
-
const asciiFileName = fileName.replace(/[^\x20-\x7e]/g, "_").replaceAll('"', "'");
|
|
1451
|
-
return `${disposition}; filename="${asciiFileName}"; filename*=UTF-8''${encodeURIComponent(fileName)}`;
|
|
1452
|
-
}
|
|
1453
|
-
|
|
1454
|
-
// src/schemas/actions.ts
|
|
1455
|
-
import {
|
|
1456
|
-
ACTION_RUN_FAILURE_CODES,
|
|
1457
|
-
ACTION_RUN_PHASES
|
|
1458
|
-
} from "@sixb/core/storage";
|
|
1459
|
-
import { z as z3 } from "zod";
|
|
1460
|
-
|
|
1461
|
-
// src/schemas/common.ts
|
|
1462
|
-
import { SIXB_FAILURE_MAX_MESSAGE_BYTES } from "@sixb/core/internal/errors";
|
|
1463
|
-
import { z } from "zod";
|
|
1464
|
-
import { ignoreOverride } from "zod-to-json-schema";
|
|
1465
|
-
var ErrorResponseSchema = z.object({ error: z.string() });
|
|
1466
|
-
function codedErrorResponseSchema(codes) {
|
|
1467
|
-
return ErrorResponseSchema.extend({
|
|
1468
|
-
code: z.enum(codes).describe("Stable machine-readable failure code for programmatic handling.")
|
|
1469
|
-
});
|
|
1470
|
-
}
|
|
1471
|
-
var RedactionsSchema = z.record(z.object({ reason: z.literal("missing_clearance") }));
|
|
1472
|
-
var SuccessResponseSchema = z.object({ success: z.boolean() });
|
|
1473
|
-
var PrincipalSchema = z.object({
|
|
1474
|
-
type: z.enum(["user", "serviceAccount", "system"]),
|
|
1475
|
-
id: z.string().min(1)
|
|
1476
|
-
});
|
|
1477
|
-
var JsonValueSchema = z.lazy(() => z.union([
|
|
1478
|
-
z.string(),
|
|
1479
|
-
z.number().finite(),
|
|
1480
|
-
z.boolean(),
|
|
1481
|
-
z.null(),
|
|
1482
|
-
z.array(JsonValueSchema),
|
|
1483
|
-
z.record(JsonValueSchema)
|
|
1484
|
-
]));
|
|
1485
|
-
var JsonNullSchema = JsonValueSchema.refine((value) => value === null);
|
|
1486
|
-
function sixbFailureSchema(codes) {
|
|
1487
|
-
return z.object({
|
|
1488
|
-
code: z.enum(codes),
|
|
1489
|
-
message: z.string().max(SIXB_FAILURE_MAX_MESSAGE_BYTES),
|
|
1490
|
-
retryable: z.boolean(),
|
|
1491
|
-
at: z.string().datetime(),
|
|
1492
|
-
details: JsonValueSchema.optional(),
|
|
1493
|
-
httpStatus: z.number().int().min(100).max(599).optional(),
|
|
1494
|
-
redacted: z.literal(true).optional(),
|
|
1495
|
-
truncated: z.literal(true).optional()
|
|
1496
|
-
});
|
|
1497
|
-
}
|
|
1498
|
-
var JsonValueOpenApiSchema = {
|
|
1499
|
-
description: "Any JSON-compatible value.",
|
|
1500
|
-
nullable: true,
|
|
1501
|
-
anyOf: [
|
|
1502
|
-
{ type: "string" },
|
|
1503
|
-
{ type: "number" },
|
|
1504
|
-
{ type: "boolean" },
|
|
1505
|
-
{ type: "array", items: {} },
|
|
1506
|
-
{ type: "object", additionalProperties: true }
|
|
1507
|
-
]
|
|
1508
|
-
};
|
|
1509
|
-
var jsonValueSchemaDef = JsonValueSchema._def;
|
|
1510
|
-
var jsonNullSchemaDef = JsonNullSchema._def;
|
|
1511
|
-
var jsonValueOpenApiOverride = (def) => {
|
|
1512
|
-
if (def === jsonValueSchemaDef) {
|
|
1513
|
-
return JsonValueOpenApiSchema;
|
|
1514
|
-
}
|
|
1515
|
-
if (def === jsonNullSchemaDef) {
|
|
1516
|
-
return { nullable: true, enum: [null] };
|
|
1074
|
+
if (def === jsonNullSchemaDef) {
|
|
1075
|
+
return { nullable: true, enum: [null] };
|
|
1517
1076
|
}
|
|
1518
1077
|
return ignoreOverride;
|
|
1519
1078
|
};
|
|
@@ -1625,12 +1184,11 @@ var RequestActionBodySchema = z3.object({
|
|
|
1625
1184
|
params: z3.record(z3.unknown()).optional(),
|
|
1626
1185
|
runId: z3.string().min(1).optional()
|
|
1627
1186
|
});
|
|
1628
|
-
var
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
});
|
|
1187
|
+
var ActionRunInProgressResponseSchema = codedErrorResponseSchema([
|
|
1188
|
+
"action.run_in_progress"
|
|
1189
|
+
]);
|
|
1190
|
+
var ActionRequestFailedResponseSchema = codedErrorResponseSchema(SIXB_ERROR_CODES);
|
|
1191
|
+
var RuntimeStoppingResponseSchema = codedErrorResponseSchema(["runtime.stopping"]);
|
|
1634
1192
|
var ActionCatalogItemSchema = z3.object({
|
|
1635
1193
|
id: z3.string(),
|
|
1636
1194
|
name: z3.string(),
|
|
@@ -1647,13 +1205,7 @@ var ActionCatalogItemSchema = z3.object({
|
|
|
1647
1205
|
var ActionDetailSchema = ActionCatalogItemSchema.extend({
|
|
1648
1206
|
inputSchema: z3.record(z3.unknown())
|
|
1649
1207
|
});
|
|
1650
|
-
var ActionRunStatusSchema = z3.enum([
|
|
1651
|
-
"queued",
|
|
1652
|
-
"running",
|
|
1653
|
-
"succeeded",
|
|
1654
|
-
"failed",
|
|
1655
|
-
"cancelled"
|
|
1656
|
-
]);
|
|
1208
|
+
var ActionRunStatusSchema = z3.enum(["succeeded", "failed"]);
|
|
1657
1209
|
var ActionRunPhaseSchema = z3.enum(ACTION_RUN_PHASES);
|
|
1658
1210
|
var ActionRunsQuerySchema = z3.object({
|
|
1659
1211
|
actionId: z3.string().optional(),
|
|
@@ -1693,10 +1245,9 @@ var ActionRunSummarySchema = z3.object({
|
|
|
1693
1245
|
actionId: z3.string(),
|
|
1694
1246
|
subject: ActionSubjectSchema,
|
|
1695
1247
|
status: ActionRunStatusSchema,
|
|
1696
|
-
phase: ActionRunPhaseSchema
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
finishedAt: z3.string().optional(),
|
|
1248
|
+
phase: ActionRunPhaseSchema,
|
|
1249
|
+
startedAt: z3.string(),
|
|
1250
|
+
finishedAt: z3.string(),
|
|
1700
1251
|
error: ActionRunFailureSchema.optional()
|
|
1701
1252
|
});
|
|
1702
1253
|
var ActionRunWritebackRecordSchema = z3.discriminatedUnion("status", [
|
|
@@ -1733,83 +1284,6 @@ var ActionRunListResponseSchema = z3.object({
|
|
|
1733
1284
|
total: z3.number()
|
|
1734
1285
|
});
|
|
1735
1286
|
|
|
1736
|
-
// src/schemas/files.ts
|
|
1737
|
-
import { canonicalMediaType as canonicalMediaType2 } from "@sixb/core/internal/blob-storage";
|
|
1738
|
-
import { z as z4 } from "zod";
|
|
1739
|
-
var BlobDigestSchema = z4.string().regex(/^sha256:[a-f0-9]{64}$/);
|
|
1740
|
-
var FileRefSchema = z4.object({
|
|
1741
|
-
blobId: z4.string(),
|
|
1742
|
-
digest: BlobDigestSchema,
|
|
1743
|
-
sizeBytes: z4.number().int().nonnegative(),
|
|
1744
|
-
fileName: z4.string().optional(),
|
|
1745
|
-
mediaType: z4.string().optional(),
|
|
1746
|
-
logicalPath: z4.string().optional()
|
|
1747
|
-
});
|
|
1748
|
-
var CreateFileUploadBodySchema = z4.object({
|
|
1749
|
-
fileName: z4.string().optional(),
|
|
1750
|
-
mediaType: z4.string().refine((value) => canonicalMediaType2(value) !== null, {
|
|
1751
|
-
message: 'Expected a single media type, such as "application/pdf"'
|
|
1752
|
-
}).optional(),
|
|
1753
|
-
sizeBytes: z4.number().int().nonnegative().optional(),
|
|
1754
|
-
digest: BlobDigestSchema.optional(),
|
|
1755
|
-
logicalPath: z4.string().optional()
|
|
1756
|
-
});
|
|
1757
|
-
var FileUploadIdParamsSchema = z4.object({
|
|
1758
|
-
uploadId: z4.string().min(1)
|
|
1759
|
-
});
|
|
1760
|
-
var FileUploadPartParamsSchema = FileUploadIdParamsSchema.extend({
|
|
1761
|
-
partNumber: z4.string().regex(/^\d+$/)
|
|
1762
|
-
});
|
|
1763
|
-
var ServerFileUploadSchema = z4.object({
|
|
1764
|
-
strategy: z4.literal("server"),
|
|
1765
|
-
uploadId: z4.string(),
|
|
1766
|
-
method: z4.literal("PUT"),
|
|
1767
|
-
url: z4.string(),
|
|
1768
|
-
expiresAt: z4.string()
|
|
1769
|
-
});
|
|
1770
|
-
var DirectPutFileUploadSchema = z4.object({
|
|
1771
|
-
strategy: z4.literal("direct-put"),
|
|
1772
|
-
uploadId: z4.string(),
|
|
1773
|
-
method: z4.literal("PUT"),
|
|
1774
|
-
url: z4.string(),
|
|
1775
|
-
headers: z4.record(z4.string()),
|
|
1776
|
-
expiresAt: z4.string()
|
|
1777
|
-
});
|
|
1778
|
-
var MultipartFileUploadSchema = z4.object({
|
|
1779
|
-
strategy: z4.literal("multipart"),
|
|
1780
|
-
partReceipt: z4.enum(["etag", "none"]),
|
|
1781
|
-
uploadId: z4.string(),
|
|
1782
|
-
partSizeBytes: z4.number().int().positive(),
|
|
1783
|
-
expiresAt: z4.string()
|
|
1784
|
-
});
|
|
1785
|
-
var CreateFileUploadResponseSchema = z4.discriminatedUnion("strategy", [
|
|
1786
|
-
ServerFileUploadSchema,
|
|
1787
|
-
DirectPutFileUploadSchema,
|
|
1788
|
-
MultipartFileUploadSchema
|
|
1789
|
-
]);
|
|
1790
|
-
var SignedFileUploadPartSchema = z4.object({
|
|
1791
|
-
partNumber: z4.number().int().positive(),
|
|
1792
|
-
method: z4.literal("PUT"),
|
|
1793
|
-
url: z4.string(),
|
|
1794
|
-
headers: z4.record(z4.string()),
|
|
1795
|
-
expiresAt: z4.string()
|
|
1796
|
-
});
|
|
1797
|
-
var FileUploadPartSchema = z4.object({
|
|
1798
|
-
partNumber: z4.number().int().positive(),
|
|
1799
|
-
etag: z4.string().min(1).optional()
|
|
1800
|
-
});
|
|
1801
|
-
var CompleteFileUploadBodySchema = z4.object({
|
|
1802
|
-
sizeBytes: z4.number().int().nonnegative().optional(),
|
|
1803
|
-
digest: BlobDigestSchema.optional(),
|
|
1804
|
-
parts: z4.array(FileUploadPartSchema).optional()
|
|
1805
|
-
});
|
|
1806
|
-
var FileContentQuerySchema = z4.object({
|
|
1807
|
-
audience: z4.enum(["atlas", "app"]).optional().describe("Session audience for file navigation without Origin; must match Origin when present"),
|
|
1808
|
-
path: z4.string().min(1),
|
|
1809
|
-
disposition: z4.enum(["inline", "attachment"]).optional(),
|
|
1810
|
-
v: z4.string().optional().describe("Client cache key; the route still resolves the current file")
|
|
1811
|
-
});
|
|
1812
|
-
|
|
1813
1287
|
// src/utils/http.ts
|
|
1814
1288
|
import {
|
|
1815
1289
|
AuthorizationError,
|
|
@@ -1823,6 +1297,8 @@ import {
|
|
|
1823
1297
|
} from "@sixb/core/storage";
|
|
1824
1298
|
|
|
1825
1299
|
// src/utils/request-body.ts
|
|
1300
|
+
var DEFAULT_REQUEST_BODY_LIMIT_BYTES = 1024 * 1024;
|
|
1301
|
+
|
|
1826
1302
|
class RequestBodyTooLargeError extends Error {
|
|
1827
1303
|
limitBytes;
|
|
1828
1304
|
name = "RequestBodyTooLargeError";
|
|
@@ -1831,7 +1307,32 @@ class RequestBodyTooLargeError extends Error {
|
|
|
1831
1307
|
this.limitBytes = limitBytes;
|
|
1832
1308
|
}
|
|
1833
1309
|
}
|
|
1310
|
+
var requestBodyCaps = new WeakMap;
|
|
1311
|
+
function limitRequestBody(request) {
|
|
1312
|
+
if (!request.body) {
|
|
1313
|
+
return request;
|
|
1314
|
+
}
|
|
1315
|
+
const cap = { lifted: false };
|
|
1316
|
+
let total = 0;
|
|
1317
|
+
const body = request.body.pipeThrough(new TransformStream({
|
|
1318
|
+
transform(chunk, controller) {
|
|
1319
|
+
total += chunk.byteLength;
|
|
1320
|
+
if (!cap.lifted && total > DEFAULT_REQUEST_BODY_LIMIT_BYTES) {
|
|
1321
|
+
controller.error(new RequestBodyTooLargeError(DEFAULT_REQUEST_BODY_LIMIT_BYTES));
|
|
1322
|
+
return;
|
|
1323
|
+
}
|
|
1324
|
+
controller.enqueue(chunk);
|
|
1325
|
+
}
|
|
1326
|
+
}));
|
|
1327
|
+
const limited = new Request(request, { body, duplex: "half" });
|
|
1328
|
+
requestBodyCaps.set(limited, cap);
|
|
1329
|
+
return limited;
|
|
1330
|
+
}
|
|
1834
1331
|
async function readRequestBodyWithLimit(request, limitBytes, tooLargeMessage) {
|
|
1332
|
+
const cap = requestBodyCaps.get(request);
|
|
1333
|
+
if (cap) {
|
|
1334
|
+
cap.lifted = true;
|
|
1335
|
+
}
|
|
1835
1336
|
const contentLength = request.headers.get("content-length");
|
|
1836
1337
|
if (contentLength !== null) {
|
|
1837
1338
|
const declared = Number(contentLength);
|
|
@@ -1868,6 +1369,7 @@ async function readRequestBodyWithLimit(request, limitBytes, tooLargeMessage) {
|
|
|
1868
1369
|
|
|
1869
1370
|
// src/utils/http.ts
|
|
1870
1371
|
var HTTP_STATUS_BY_ERROR_CODE = {
|
|
1372
|
+
"action.run_in_progress": 409,
|
|
1871
1373
|
"connector.adapter_invalid": 502,
|
|
1872
1374
|
"connector.authorization_invalid": 400,
|
|
1873
1375
|
"connector.authorization_required": 409,
|
|
@@ -1882,6 +1384,7 @@ var HTTP_STATUS_BY_ERROR_CODE = {
|
|
|
1882
1384
|
"connector.revocation_pending": 409,
|
|
1883
1385
|
"dataset.not_found": 404,
|
|
1884
1386
|
"dataset.version_not_found": 404,
|
|
1387
|
+
"runtime.stopping": 503,
|
|
1885
1388
|
"ai.usage_limit_exceeded": 429,
|
|
1886
1389
|
"ai.usage_limit_unavailable": 429
|
|
1887
1390
|
};
|
|
@@ -1908,7 +1411,7 @@ function parseOptionalInt(value) {
|
|
|
1908
1411
|
}
|
|
1909
1412
|
return parsed;
|
|
1910
1413
|
}
|
|
1911
|
-
function
|
|
1414
|
+
function unconfiguredStorageResponse(set, role) {
|
|
1912
1415
|
set.status = 501;
|
|
1913
1416
|
return { error: `[SixbServer] ${role} is not configured on this runtime.` };
|
|
1914
1417
|
}
|
|
@@ -1924,102 +1427,462 @@ function handleRouteError(error, set) {
|
|
|
1924
1427
|
...!exposesDetails || error.details === undefined ? {} : { details: error.details }
|
|
1925
1428
|
};
|
|
1926
1429
|
}
|
|
1927
|
-
if (error instanceof AuthorizationError) {
|
|
1928
|
-
set.status = 403;
|
|
1929
|
-
return { error: error.message };
|
|
1430
|
+
if (error instanceof AuthorizationError) {
|
|
1431
|
+
set.status = 403;
|
|
1432
|
+
return { error: error.message };
|
|
1433
|
+
}
|
|
1434
|
+
if (error instanceof FileUploadSessionError) {
|
|
1435
|
+
set.status = fileUploadSessionErrorStatus(error.reason);
|
|
1436
|
+
return { error: error.message };
|
|
1437
|
+
}
|
|
1438
|
+
if (error instanceof RequestBodyTooLargeError) {
|
|
1439
|
+
set.status = 413;
|
|
1440
|
+
return { error: error.message };
|
|
1441
|
+
}
|
|
1442
|
+
if (error instanceof OntologyNotFoundError || error instanceof ObjectNotFoundError) {
|
|
1443
|
+
set.status = 404;
|
|
1444
|
+
return { error: error.message };
|
|
1445
|
+
}
|
|
1446
|
+
if (error instanceof OntologyValidationError) {
|
|
1447
|
+
set.status = 400;
|
|
1448
|
+
return { error: error.message };
|
|
1449
|
+
}
|
|
1450
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1451
|
+
set.status = 400;
|
|
1452
|
+
return { error: message };
|
|
1453
|
+
}
|
|
1454
|
+
function setRetryAfterFromDetails(set, details) {
|
|
1455
|
+
if (typeof details !== "object" || details === null || Array.isArray(details))
|
|
1456
|
+
return;
|
|
1457
|
+
const resetAt = details.resetAt;
|
|
1458
|
+
if (typeof resetAt !== "string")
|
|
1459
|
+
return;
|
|
1460
|
+
const resetTime = Date.parse(resetAt);
|
|
1461
|
+
if (!Number.isFinite(resetTime))
|
|
1462
|
+
return;
|
|
1463
|
+
const seconds = String(Math.max(0, Math.ceil((resetTime - Date.now()) / 1000)));
|
|
1464
|
+
const headers = typeof set.headers === "object" && set.headers !== null ? set.headers : {};
|
|
1465
|
+
headers["Retry-After"] = seconds;
|
|
1466
|
+
set.headers = headers;
|
|
1467
|
+
}
|
|
1468
|
+
function fileUploadSessionErrorStatus(reason) {
|
|
1469
|
+
switch (reason) {
|
|
1470
|
+
case "not_found":
|
|
1471
|
+
return 404;
|
|
1472
|
+
case "expired":
|
|
1473
|
+
return 410;
|
|
1474
|
+
case "already_completed":
|
|
1475
|
+
case "already_aborted":
|
|
1476
|
+
return 409;
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
// src/actions/serialize.ts
|
|
1481
|
+
function serializeActionRunSummary(run) {
|
|
1482
|
+
return ActionRunSummarySchema.parse({
|
|
1483
|
+
id: run.id,
|
|
1484
|
+
projectId: run.projectId,
|
|
1485
|
+
actionId: run.actionId,
|
|
1486
|
+
subject: run.subject,
|
|
1487
|
+
status: run.status,
|
|
1488
|
+
phase: run.phase,
|
|
1489
|
+
startedAt: toIsoString(run.startedAt),
|
|
1490
|
+
finishedAt: toIsoString(run.finishedAt),
|
|
1491
|
+
error: run.error
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1494
|
+
function serializeActionRunDetail(run) {
|
|
1495
|
+
return ActionRunDetailSchema.parse({
|
|
1496
|
+
...serializeActionRunSummary(run),
|
|
1497
|
+
params: run.params,
|
|
1498
|
+
writeback: run.writeback ? run.writeback.status === "succeeded" ? {
|
|
1499
|
+
status: "succeeded",
|
|
1500
|
+
completedAt: toIsoString(run.writeback.completedAt),
|
|
1501
|
+
result: run.writeback.result
|
|
1502
|
+
} : {
|
|
1503
|
+
status: "failed",
|
|
1504
|
+
completedAt: toIsoString(run.writeback.completedAt),
|
|
1505
|
+
error: run.writeback.error
|
|
1506
|
+
} : undefined,
|
|
1507
|
+
effects: run.effects ? run.effects.status === "succeeded" ? {
|
|
1508
|
+
status: "succeeded",
|
|
1509
|
+
completedAt: toIsoString(run.effects.completedAt)
|
|
1510
|
+
} : {
|
|
1511
|
+
status: "failed",
|
|
1512
|
+
completedAt: toIsoString(run.effects.completedAt),
|
|
1513
|
+
error: run.effects.error
|
|
1514
|
+
} : undefined
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
// src/files/content.ts
|
|
1519
|
+
import { createHash as createHash2 } from "crypto";
|
|
1520
|
+
import { fileNameFor } from "@sixb/core";
|
|
1521
|
+
import { BlobStorageError, supportsRangeRead } from "@sixb/core/blob-storage/server";
|
|
1522
|
+
import {
|
|
1523
|
+
canonicalMediaType,
|
|
1524
|
+
resolveFileRefAtPath,
|
|
1525
|
+
statFileRef
|
|
1526
|
+
} from "@sixb/core/internal/blob-storage";
|
|
1527
|
+
import { ZodError } from "zod";
|
|
1528
|
+
var unconfiguredStorageResponse2 = {
|
|
1529
|
+
501: {
|
|
1530
|
+
description: "The storage role backing this content is not configured",
|
|
1531
|
+
content: {
|
|
1532
|
+
"application/json": {
|
|
1533
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
};
|
|
1538
|
+
function handleFileContentQueryValidationError(context) {
|
|
1539
|
+
if (context.code !== "VALIDATION" || context.error.type !== "query")
|
|
1540
|
+
return;
|
|
1541
|
+
context.set.status = 400;
|
|
1542
|
+
return { error: "Invalid file content query" };
|
|
1543
|
+
}
|
|
1544
|
+
function fileContentGetResponses(options = {}) {
|
|
1545
|
+
return {
|
|
1546
|
+
200: {
|
|
1547
|
+
description: "File content",
|
|
1548
|
+
content: {
|
|
1549
|
+
"application/octet-stream": {
|
|
1550
|
+
schema: { type: "string", format: "binary" }
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
},
|
|
1554
|
+
206: {
|
|
1555
|
+
description: "Partial file content",
|
|
1556
|
+
content: {
|
|
1557
|
+
"application/octet-stream": {
|
|
1558
|
+
schema: { type: "string", format: "binary" }
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
},
|
|
1562
|
+
304: {
|
|
1563
|
+
description: "File representation is unchanged; reuse the privately cached content"
|
|
1564
|
+
},
|
|
1565
|
+
400: {
|
|
1566
|
+
description: "Response for status 400",
|
|
1567
|
+
content: {
|
|
1568
|
+
"application/json": {
|
|
1569
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
},
|
|
1573
|
+
404: {
|
|
1574
|
+
description: "Response for status 404",
|
|
1575
|
+
content: {
|
|
1576
|
+
"application/json": {
|
|
1577
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
},
|
|
1581
|
+
416: {
|
|
1582
|
+
description: "Requested byte range is not satisfiable"
|
|
1583
|
+
},
|
|
1584
|
+
...options.optionalStorage ? unconfiguredStorageResponse2 : {}
|
|
1585
|
+
};
|
|
1586
|
+
}
|
|
1587
|
+
function fileContentHeadResponses(options = {}) {
|
|
1588
|
+
return {
|
|
1589
|
+
200: {
|
|
1590
|
+
description: "File content headers"
|
|
1591
|
+
},
|
|
1592
|
+
206: {
|
|
1593
|
+
description: "Partial file content headers"
|
|
1594
|
+
},
|
|
1595
|
+
304: {
|
|
1596
|
+
description: "File representation is unchanged; reuse the privately cached content"
|
|
1597
|
+
},
|
|
1598
|
+
400: {
|
|
1599
|
+
description: "Response for status 400",
|
|
1600
|
+
content: {
|
|
1601
|
+
"application/json": {
|
|
1602
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
},
|
|
1606
|
+
404: {
|
|
1607
|
+
description: "Response for status 404",
|
|
1608
|
+
content: {
|
|
1609
|
+
"application/json": {
|
|
1610
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
},
|
|
1614
|
+
416: {
|
|
1615
|
+
description: "Requested byte range is not satisfiable"
|
|
1616
|
+
},
|
|
1617
|
+
...options.optionalStorage ? unconfiguredStorageResponse2 : {}
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
async function createFileContentResponse(input) {
|
|
1621
|
+
const stat = await statFileRef(input.blobStorage, input.fileRef);
|
|
1622
|
+
if (!stat) {
|
|
1623
|
+
return null;
|
|
1624
|
+
}
|
|
1625
|
+
const canReadRange = supportsRangeRead(input.blobStorage);
|
|
1626
|
+
const headers = fileContentHeaders(input.fileRef, stat, input.disposition, canReadRange);
|
|
1627
|
+
const etag = headers.get("etag");
|
|
1628
|
+
if (matchesIfNoneMatch(input.ifNoneMatchHeader, etag)) {
|
|
1629
|
+
headers.delete("content-length");
|
|
1630
|
+
return new Response(null, { status: 304, headers });
|
|
1631
|
+
}
|
|
1632
|
+
if (canReadRange && input.rangeHeader && (input.ifRangeHeader == null || input.ifRangeHeader.trim() === etag)) {
|
|
1633
|
+
const range = parseSingleByteRange(input.rangeHeader, stat.sizeBytes);
|
|
1634
|
+
if (!range) {
|
|
1635
|
+
return rangeNotSatisfiableResponse(stat.sizeBytes);
|
|
1636
|
+
}
|
|
1637
|
+
const partialHeaders = partialFileContentHeaders(headers, range, stat.sizeBytes);
|
|
1638
|
+
if (input.head) {
|
|
1639
|
+
return new Response(null, { status: 206, headers: partialHeaders });
|
|
1640
|
+
}
|
|
1641
|
+
try {
|
|
1642
|
+
const stream = await input.blobStorage.openRange(input.fileRef.blobId, range);
|
|
1643
|
+
return new Response(stream, { status: 206, headers: partialHeaders });
|
|
1644
|
+
} catch (error) {
|
|
1645
|
+
if (error instanceof BlobStorageError) {
|
|
1646
|
+
return null;
|
|
1647
|
+
}
|
|
1648
|
+
throw error;
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
if (input.head) {
|
|
1652
|
+
return new Response(null, { headers });
|
|
1653
|
+
}
|
|
1654
|
+
try {
|
|
1655
|
+
const stream = await input.blobStorage.open(input.fileRef.blobId);
|
|
1656
|
+
return new Response(stream, { headers });
|
|
1657
|
+
} catch (error) {
|
|
1658
|
+
if (error instanceof BlobStorageError) {
|
|
1659
|
+
return null;
|
|
1660
|
+
}
|
|
1661
|
+
throw error;
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
async function createContextualFileContentResponse(input) {
|
|
1665
|
+
const missingMessage = input.missingMessage ?? "File not found";
|
|
1666
|
+
const invalidQueryMessage = input.invalidQueryMessage ?? "Invalid file content query";
|
|
1667
|
+
try {
|
|
1668
|
+
const parsed = input.querySchema.parse(input.query);
|
|
1669
|
+
const root = await input.resolveRoot(parsed);
|
|
1670
|
+
if (root === null || root === undefined) {
|
|
1671
|
+
return fileContentNotFound(input.set, missingMessage);
|
|
1672
|
+
}
|
|
1673
|
+
const fileRef = resolveFileRefAtPath(root, parsed.path);
|
|
1674
|
+
if (!fileRef) {
|
|
1675
|
+
return fileContentNotFound(input.set, missingMessage);
|
|
1676
|
+
}
|
|
1677
|
+
const response = await createFileContentResponse({
|
|
1678
|
+
blobStorage: input.blobStorage,
|
|
1679
|
+
fileRef,
|
|
1680
|
+
disposition: parsed.disposition,
|
|
1681
|
+
head: input.head,
|
|
1682
|
+
rangeHeader: input.request.headers.get("range"),
|
|
1683
|
+
ifNoneMatchHeader: input.request.headers.get("if-none-match"),
|
|
1684
|
+
ifRangeHeader: input.request.headers.get("if-range")
|
|
1685
|
+
});
|
|
1686
|
+
if (!response) {
|
|
1687
|
+
return fileContentNotFound(input.set, missingMessage);
|
|
1688
|
+
}
|
|
1689
|
+
return response;
|
|
1690
|
+
} catch (error) {
|
|
1691
|
+
if (error instanceof ZodError) {
|
|
1692
|
+
input.set.status = 400;
|
|
1693
|
+
return { error: invalidQueryMessage };
|
|
1694
|
+
}
|
|
1695
|
+
if (input.hideError?.(error)) {
|
|
1696
|
+
return fileContentNotFound(input.set, missingMessage);
|
|
1697
|
+
}
|
|
1698
|
+
throw error;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
function fileContentNotFound(set, message) {
|
|
1702
|
+
set.status = 404;
|
|
1703
|
+
return { error: message };
|
|
1704
|
+
}
|
|
1705
|
+
function matchesIfNoneMatch(header, etag) {
|
|
1706
|
+
return header?.trim() === "*" || (header?.split(",").some((value) => value.trim().replace(/^W\//, "") === etag) ?? false);
|
|
1707
|
+
}
|
|
1708
|
+
var INLINE_MEDIA_TYPES = new Set([
|
|
1709
|
+
"application/json",
|
|
1710
|
+
"application/pdf",
|
|
1711
|
+
"image/avif",
|
|
1712
|
+
"image/bmp",
|
|
1713
|
+
"image/gif",
|
|
1714
|
+
"image/jpeg",
|
|
1715
|
+
"image/png",
|
|
1716
|
+
"image/webp",
|
|
1717
|
+
"text/markdown",
|
|
1718
|
+
"text/plain"
|
|
1719
|
+
]);
|
|
1720
|
+
var FILE_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inline'; sandbox";
|
|
1721
|
+
var PDF_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inline'; object-src 'self'";
|
|
1722
|
+
function fileContentHeaders(fileRef, stat, requestedDisposition, canReadRange) {
|
|
1723
|
+
const mediaType = canonicalMediaType(fileRef.mediaType) ?? "application/octet-stream";
|
|
1724
|
+
const baseType = mediaType.split(";", 1)[0];
|
|
1725
|
+
const disposition = (requestedDisposition ?? "inline") === "inline" && INLINE_MEDIA_TYPES.has(baseType) ? "inline" : "attachment";
|
|
1726
|
+
const headers = new Headers;
|
|
1727
|
+
headers.set("content-type", mediaType);
|
|
1728
|
+
headers.set("content-length", stat.sizeBytes.toString());
|
|
1729
|
+
headers.set("content-disposition", contentDispositionHeader(disposition, fileNameFor(fileRef)));
|
|
1730
|
+
headers.set("content-security-policy", baseType === "application/pdf" ? PDF_CONTENT_SECURITY_POLICY : FILE_CONTENT_SECURITY_POLICY);
|
|
1731
|
+
const representation = JSON.stringify([
|
|
1732
|
+
fileRef.digest,
|
|
1733
|
+
mediaType,
|
|
1734
|
+
headers.get("content-disposition")
|
|
1735
|
+
]);
|
|
1736
|
+
headers.set("etag", `"sha256:${createHash2("sha256").update(representation).digest("hex")}"`);
|
|
1737
|
+
headers.set("x-content-type-options", "nosniff");
|
|
1738
|
+
headers.set("cache-control", "private, no-cache");
|
|
1739
|
+
if (canReadRange) {
|
|
1740
|
+
headers.set("accept-ranges", "bytes");
|
|
1741
|
+
}
|
|
1742
|
+
return headers;
|
|
1743
|
+
}
|
|
1744
|
+
function parseSingleByteRange(header, sizeBytes) {
|
|
1745
|
+
const normalized = header.trim();
|
|
1746
|
+
if (!normalized.startsWith("bytes=") || normalized.includes(",")) {
|
|
1747
|
+
return null;
|
|
1748
|
+
}
|
|
1749
|
+
if (sizeBytes <= 0) {
|
|
1750
|
+
return null;
|
|
1751
|
+
}
|
|
1752
|
+
const spec = normalized.slice("bytes=".length).trim();
|
|
1753
|
+
const match = spec.match(/^(\d*)-(\d*)$/);
|
|
1754
|
+
if (!match) {
|
|
1755
|
+
return null;
|
|
1930
1756
|
}
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
return
|
|
1757
|
+
const [, rawStart, rawEnd] = match;
|
|
1758
|
+
if (!rawStart && !rawEnd) {
|
|
1759
|
+
return null;
|
|
1934
1760
|
}
|
|
1935
|
-
if (
|
|
1936
|
-
|
|
1937
|
-
|
|
1761
|
+
if (!rawStart) {
|
|
1762
|
+
const suffixLength = Number(rawEnd);
|
|
1763
|
+
if (!Number.isSafeInteger(suffixLength) || suffixLength <= 0) {
|
|
1764
|
+
return null;
|
|
1765
|
+
}
|
|
1766
|
+
return {
|
|
1767
|
+
start: Math.max(sizeBytes - suffixLength, 0),
|
|
1768
|
+
endInclusive: sizeBytes - 1
|
|
1769
|
+
};
|
|
1938
1770
|
}
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
return
|
|
1771
|
+
const start = Number(rawStart);
|
|
1772
|
+
if (!Number.isSafeInteger(start) || start >= sizeBytes) {
|
|
1773
|
+
return null;
|
|
1942
1774
|
}
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
return
|
|
1775
|
+
const requestedEnd = rawEnd ? Number(rawEnd) : sizeBytes - 1;
|
|
1776
|
+
if (!Number.isSafeInteger(requestedEnd) || requestedEnd < start) {
|
|
1777
|
+
return null;
|
|
1946
1778
|
}
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1779
|
+
return {
|
|
1780
|
+
start,
|
|
1781
|
+
endInclusive: Math.min(requestedEnd, sizeBytes - 1)
|
|
1782
|
+
};
|
|
1950
1783
|
}
|
|
1951
|
-
function
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
return;
|
|
1957
|
-
const resetTime = Date.parse(resetAt);
|
|
1958
|
-
if (!Number.isFinite(resetTime))
|
|
1959
|
-
return;
|
|
1960
|
-
const seconds = String(Math.max(0, Math.ceil((resetTime - Date.now()) / 1000)));
|
|
1961
|
-
const headers = typeof set.headers === "object" && set.headers !== null ? set.headers : {};
|
|
1962
|
-
headers["Retry-After"] = seconds;
|
|
1963
|
-
set.headers = headers;
|
|
1784
|
+
function partialFileContentHeaders(baseHeaders, range, sizeBytes) {
|
|
1785
|
+
const headers = new Headers(baseHeaders);
|
|
1786
|
+
headers.set("content-length", (range.endInclusive - range.start + 1).toString());
|
|
1787
|
+
headers.set("content-range", `bytes ${range.start}-${range.endInclusive}/${sizeBytes}`);
|
|
1788
|
+
return headers;
|
|
1964
1789
|
}
|
|
1965
|
-
function
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
}
|
|
1790
|
+
function rangeNotSatisfiableResponse(sizeBytes) {
|
|
1791
|
+
const headers = new Headers;
|
|
1792
|
+
headers.set("accept-ranges", "bytes");
|
|
1793
|
+
headers.set("content-range", `bytes */${sizeBytes}`);
|
|
1794
|
+
return new Response(null, { status: 416, headers });
|
|
1795
|
+
}
|
|
1796
|
+
function contentDispositionHeader(disposition, fileName) {
|
|
1797
|
+
const asciiFileName = fileName.replace(/[^\x20-\x7e]/g, "_").replaceAll('"', "'");
|
|
1798
|
+
return `${disposition}; filename="${asciiFileName}"; filename*=UTF-8''${encodeURIComponent(fileName)}`;
|
|
1975
1799
|
}
|
|
1976
1800
|
|
|
1801
|
+
// src/schemas/files.ts
|
|
1802
|
+
import { canonicalMediaType as canonicalMediaType2 } from "@sixb/core/internal/blob-storage";
|
|
1803
|
+
import { z as z4 } from "zod";
|
|
1804
|
+
var BlobDigestSchema = z4.string().regex(/^sha256:[a-f0-9]{64}$/);
|
|
1805
|
+
var FileRefSchema = z4.object({
|
|
1806
|
+
blobId: z4.string(),
|
|
1807
|
+
digest: BlobDigestSchema,
|
|
1808
|
+
sizeBytes: z4.number().int().nonnegative(),
|
|
1809
|
+
fileName: z4.string().optional(),
|
|
1810
|
+
mediaType: z4.string().optional(),
|
|
1811
|
+
logicalPath: z4.string().optional()
|
|
1812
|
+
});
|
|
1813
|
+
var CreateFileUploadBodySchema = z4.object({
|
|
1814
|
+
fileName: z4.string().optional(),
|
|
1815
|
+
mediaType: z4.string().refine((value) => canonicalMediaType2(value) !== null, {
|
|
1816
|
+
message: 'Expected a single media type, such as "application/pdf"'
|
|
1817
|
+
}).optional(),
|
|
1818
|
+
sizeBytes: z4.number().int().nonnegative().optional(),
|
|
1819
|
+
digest: BlobDigestSchema.optional(),
|
|
1820
|
+
logicalPath: z4.string().optional()
|
|
1821
|
+
});
|
|
1822
|
+
var FileUploadIdParamsSchema = z4.object({
|
|
1823
|
+
uploadId: z4.string().min(1)
|
|
1824
|
+
});
|
|
1825
|
+
var FileUploadPartParamsSchema = FileUploadIdParamsSchema.extend({
|
|
1826
|
+
partNumber: z4.string().regex(/^\d+$/)
|
|
1827
|
+
});
|
|
1828
|
+
var ServerFileUploadSchema = z4.object({
|
|
1829
|
+
strategy: z4.literal("server"),
|
|
1830
|
+
uploadId: z4.string(),
|
|
1831
|
+
method: z4.literal("PUT"),
|
|
1832
|
+
url: z4.string(),
|
|
1833
|
+
expiresAt: z4.string()
|
|
1834
|
+
});
|
|
1835
|
+
var DirectPutFileUploadSchema = z4.object({
|
|
1836
|
+
strategy: z4.literal("direct-put"),
|
|
1837
|
+
uploadId: z4.string(),
|
|
1838
|
+
method: z4.literal("PUT"),
|
|
1839
|
+
url: z4.string(),
|
|
1840
|
+
headers: z4.record(z4.string()),
|
|
1841
|
+
expiresAt: z4.string()
|
|
1842
|
+
});
|
|
1843
|
+
var MultipartFileUploadSchema = z4.object({
|
|
1844
|
+
strategy: z4.literal("multipart"),
|
|
1845
|
+
partReceipt: z4.enum(["etag", "none"]),
|
|
1846
|
+
uploadId: z4.string(),
|
|
1847
|
+
partSizeBytes: z4.number().int().positive(),
|
|
1848
|
+
expiresAt: z4.string()
|
|
1849
|
+
});
|
|
1850
|
+
var CreateFileUploadResponseSchema = z4.discriminatedUnion("strategy", [
|
|
1851
|
+
ServerFileUploadSchema,
|
|
1852
|
+
DirectPutFileUploadSchema,
|
|
1853
|
+
MultipartFileUploadSchema
|
|
1854
|
+
]);
|
|
1855
|
+
var SignedFileUploadPartSchema = z4.object({
|
|
1856
|
+
partNumber: z4.number().int().positive(),
|
|
1857
|
+
method: z4.literal("PUT"),
|
|
1858
|
+
url: z4.string(),
|
|
1859
|
+
headers: z4.record(z4.string()),
|
|
1860
|
+
expiresAt: z4.string()
|
|
1861
|
+
});
|
|
1862
|
+
var FileUploadPartSchema = z4.object({
|
|
1863
|
+
partNumber: z4.number().int().positive(),
|
|
1864
|
+
etag: z4.string().min(1).optional()
|
|
1865
|
+
});
|
|
1866
|
+
var CompleteFileUploadBodySchema = z4.object({
|
|
1867
|
+
sizeBytes: z4.number().int().nonnegative().optional(),
|
|
1868
|
+
digest: BlobDigestSchema.optional(),
|
|
1869
|
+
parts: z4.array(FileUploadPartSchema).optional()
|
|
1870
|
+
});
|
|
1871
|
+
var FileContentQuerySchema = z4.object({
|
|
1872
|
+
path: z4.string().min(1),
|
|
1873
|
+
disposition: z4.enum(["inline", "attachment"]).optional(),
|
|
1874
|
+
v: z4.string().optional().describe("Client cache key; the route still resolves the current file")
|
|
1875
|
+
});
|
|
1876
|
+
|
|
1977
1877
|
// src/routes/action-runs.ts
|
|
1978
1878
|
var ActionRunFileContentQuerySchema = FileContentQuerySchema.extend({
|
|
1979
1879
|
path: z5.string().min(1).regex(/^\/(?:params|writeback\/result)(?:\/|$)/, "Action run file content paths must start with /params/ or /writeback/result/")
|
|
1980
1880
|
});
|
|
1981
|
-
function serializeActionRunSummary(run) {
|
|
1982
|
-
return ActionRunSummarySchema.parse({
|
|
1983
|
-
id: run.id,
|
|
1984
|
-
projectId: run.projectId,
|
|
1985
|
-
actionId: run.actionId,
|
|
1986
|
-
subject: run.subject,
|
|
1987
|
-
status: run.status,
|
|
1988
|
-
phase: run.phase,
|
|
1989
|
-
queuedAt: toIsoString(run.queuedAt),
|
|
1990
|
-
startedAt: run.startedAt ? toIsoString(run.startedAt) : undefined,
|
|
1991
|
-
finishedAt: run.finishedAt ? toIsoString(run.finishedAt) : undefined,
|
|
1992
|
-
error: run.error
|
|
1993
|
-
});
|
|
1994
|
-
}
|
|
1995
|
-
function serializeActionRunDetail(run) {
|
|
1996
|
-
return ActionRunDetailSchema.parse({
|
|
1997
|
-
...serializeActionRunSummary(run),
|
|
1998
|
-
params: run.params,
|
|
1999
|
-
writeback: run.writeback ? run.writeback.status === "succeeded" ? {
|
|
2000
|
-
status: "succeeded",
|
|
2001
|
-
completedAt: toIsoString(run.writeback.completedAt),
|
|
2002
|
-
result: run.writeback.result
|
|
2003
|
-
} : {
|
|
2004
|
-
status: "failed",
|
|
2005
|
-
completedAt: toIsoString(run.writeback.completedAt),
|
|
2006
|
-
error: run.writeback.error
|
|
2007
|
-
} : undefined,
|
|
2008
|
-
effects: run.effects ? run.effects.status === "succeeded" ? {
|
|
2009
|
-
status: "succeeded",
|
|
2010
|
-
completedAt: toIsoString(run.effects.completedAt)
|
|
2011
|
-
} : {
|
|
2012
|
-
status: "failed",
|
|
2013
|
-
completedAt: toIsoString(run.effects.completedAt),
|
|
2014
|
-
error: run.effects.error
|
|
2015
|
-
} : undefined
|
|
2016
|
-
});
|
|
2017
|
-
}
|
|
2018
1881
|
async function actionRunFileContentResponse(host, context, options = {}) {
|
|
2019
1882
|
const sixb = requireRequestSixb(context);
|
|
2020
1883
|
const storage = host.storage.actionRuns;
|
|
2021
1884
|
if (!storage) {
|
|
2022
|
-
return
|
|
1885
|
+
return unconfiguredStorageResponse(context.set, "Action run storage");
|
|
2023
1886
|
}
|
|
2024
1887
|
return createContextualFileContentResponse({
|
|
2025
1888
|
blobStorage: host.blobStorage,
|
|
@@ -2041,7 +1904,7 @@ function registerActionRunRoutes(app, host) {
|
|
|
2041
1904
|
try {
|
|
2042
1905
|
const storage = host.storage.actionRuns;
|
|
2043
1906
|
if (!storage) {
|
|
2044
|
-
return
|
|
1907
|
+
return unconfiguredStorageResponse(set, "Action run storage");
|
|
2045
1908
|
}
|
|
2046
1909
|
const parsed = ActionRunsQuerySchema.parse(query);
|
|
2047
1910
|
const limit = parseOptionalInt(parsed.limit);
|
|
@@ -2084,7 +1947,7 @@ function registerActionRunRoutes(app, host) {
|
|
|
2084
1947
|
try {
|
|
2085
1948
|
const storage = host.storage.actionRuns;
|
|
2086
1949
|
if (!storage) {
|
|
2087
|
-
return
|
|
1950
|
+
return unconfiguredStorageResponse(set, "Action run storage");
|
|
2088
1951
|
}
|
|
2089
1952
|
const run = await sixb.actions.runs.getById(params.runId);
|
|
2090
1953
|
if (!run) {
|
|
@@ -2193,19 +2056,18 @@ function registerActionRoutes(app, host) {
|
|
|
2193
2056
|
security: accessTokenSecurityRequirement("getAction")
|
|
2194
2057
|
}
|
|
2195
2058
|
}).post("/api/actions/:actionId", async (context) => {
|
|
2196
|
-
const { params, body, set } = context;
|
|
2059
|
+
const { params, body, set, request, server } = context;
|
|
2060
|
+
server?.timeout(request, 0);
|
|
2197
2061
|
const sixb = requireRequestSixb(context);
|
|
2198
2062
|
try {
|
|
2199
2063
|
const parsedBody = RequestActionBodySchema.parse(body);
|
|
2200
|
-
const
|
|
2064
|
+
const run = await sixb.actions.request({
|
|
2201
2065
|
actionId: params.actionId,
|
|
2202
2066
|
subject: parsedBody.subject,
|
|
2203
2067
|
params: parsedBody.params,
|
|
2204
2068
|
runId: parsedBody.runId
|
|
2205
|
-
};
|
|
2206
|
-
|
|
2207
|
-
set.status = 202;
|
|
2208
|
-
return RequestActionResponseSchema.parse(result);
|
|
2069
|
+
});
|
|
2070
|
+
return serializeActionRunDetail(run);
|
|
2209
2071
|
} catch (error) {
|
|
2210
2072
|
return handleRouteError(error, set);
|
|
2211
2073
|
}
|
|
@@ -2213,13 +2075,17 @@ function registerActionRoutes(app, host) {
|
|
|
2213
2075
|
params: ActionIdParamsSchema,
|
|
2214
2076
|
body: RequestActionBodySchema,
|
|
2215
2077
|
response: {
|
|
2216
|
-
|
|
2078
|
+
200: ActionRunDetailSchema,
|
|
2217
2079
|
400: ErrorResponseSchema,
|
|
2218
2080
|
403: ErrorResponseSchema,
|
|
2219
|
-
404: ErrorResponseSchema
|
|
2081
|
+
404: ErrorResponseSchema,
|
|
2082
|
+
409: ActionRunInProgressResponseSchema,
|
|
2083
|
+
500: ActionRequestFailedResponseSchema,
|
|
2084
|
+
503: RuntimeStoppingResponseSchema
|
|
2220
2085
|
},
|
|
2221
2086
|
detail: {
|
|
2222
2087
|
summary: "Request an action",
|
|
2088
|
+
description: "Runs the action and returns its terminal run. A run that fails is returned with " + "status `failed`. Its effects run after the response, which does not wait for them. " + "An error response usually means no run was requested, but a 500 can follow a run " + "that started: request again with the same `runId` to get its record if it was " + "written. A `runId` that was already recorded returns that run, and 409 while this " + "server still runs it. 503 means the server is stopping and started nothing.",
|
|
2223
2089
|
tags: [OPENAPI_TAGS.actions.name],
|
|
2224
2090
|
operationId: "requestAction",
|
|
2225
2091
|
security: accessTokenSecurityRequirement("requestAction")
|
|
@@ -2237,7 +2103,7 @@ import {
|
|
|
2237
2103
|
resolveAgentExecutionAuthorization,
|
|
2238
2104
|
resolveInheritedAgentExecutionAuthorization
|
|
2239
2105
|
} from "@sixb/core/internal/agents";
|
|
2240
|
-
import { normalizeRoutePath as
|
|
2106
|
+
import { normalizeRoutePath as normalizeRoutePath3, pathSegmentsFor } from "@sixb/core/internal/http";
|
|
2241
2107
|
|
|
2242
2108
|
// src/routes/files.ts
|
|
2243
2109
|
import {
|
|
@@ -2253,12 +2119,10 @@ function registerFileRoutes(app, host) {
|
|
|
2253
2119
|
const uploadSessions = host.storage.fileUploadSessions;
|
|
2254
2120
|
return app.post("/api/files", async ({ request, set }) => {
|
|
2255
2121
|
try {
|
|
2256
|
-
const
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
}
|
|
2261
|
-
const form = await request.formData();
|
|
2122
|
+
const bytes = await readRequestBodyWithLimit(request, DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES, `File upload request exceeds the ${DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES} byte limit.`);
|
|
2123
|
+
const form = await new Response(bytes, {
|
|
2124
|
+
headers: { "content-type": request.headers.get("content-type") ?? "" }
|
|
2125
|
+
}).formData();
|
|
2262
2126
|
const file = form.get("file");
|
|
2263
2127
|
const logicalPath = form.get("logicalPath");
|
|
2264
2128
|
if (!(file instanceof File)) {
|
|
@@ -2321,7 +2185,7 @@ function registerFileRoutes(app, host) {
|
|
|
2321
2185
|
const { body, set } = context;
|
|
2322
2186
|
try {
|
|
2323
2187
|
if (!uploadSessions) {
|
|
2324
|
-
return
|
|
2188
|
+
return unconfiguredStorageResponse(set, "File upload session storage");
|
|
2325
2189
|
}
|
|
2326
2190
|
const parsed = CreateFileUploadBodySchema.parse(body);
|
|
2327
2191
|
const principal = requireRequestSixb(context).execution.requestedBy ?? SYSTEM_PRINCIPAL;
|
|
@@ -2372,7 +2236,7 @@ function registerFileRoutes(app, host) {
|
|
|
2372
2236
|
const { params, request, set } = context;
|
|
2373
2237
|
try {
|
|
2374
2238
|
if (!uploadSessions) {
|
|
2375
|
-
return
|
|
2239
|
+
return unconfiguredStorageResponse(set, "File upload session storage");
|
|
2376
2240
|
}
|
|
2377
2241
|
const principal = requireRequestSixb(context).execution.requestedBy ?? SYSTEM_PRINCIPAL;
|
|
2378
2242
|
const session = await uploadSessions.getForPrincipal(params.uploadId, principal);
|
|
@@ -2388,7 +2252,7 @@ function registerFileRoutes(app, host) {
|
|
|
2388
2252
|
set.status = 400;
|
|
2389
2253
|
return { error: contentLengthSizeError };
|
|
2390
2254
|
}
|
|
2391
|
-
const uploadBytes =
|
|
2255
|
+
const uploadBytes = await readRequestBodyWithLimit(request, DEFAULT_SIMPLE_FILE_UPLOAD_BYTES);
|
|
2392
2256
|
if (uploadBytes.byteLength === 0) {
|
|
2393
2257
|
set.status = 400;
|
|
2394
2258
|
return { error: "Expected upload content body." };
|
|
@@ -2417,14 +2281,14 @@ function registerFileRoutes(app, host) {
|
|
|
2417
2281
|
}
|
|
2418
2282
|
}, {
|
|
2419
2283
|
params: FileUploadIdParamsSchema,
|
|
2420
|
-
parse:
|
|
2421
|
-
error: mapUploadContentError,
|
|
2284
|
+
parse: "none",
|
|
2422
2285
|
response: {
|
|
2423
2286
|
200: SuccessResponseSchema,
|
|
2424
2287
|
400: ErrorResponseSchema,
|
|
2425
2288
|
404: ErrorResponseSchema,
|
|
2426
2289
|
409: ErrorResponseSchema,
|
|
2427
2290
|
410: ErrorResponseSchema,
|
|
2291
|
+
413: ErrorResponseSchema,
|
|
2428
2292
|
501: ErrorResponseSchema
|
|
2429
2293
|
},
|
|
2430
2294
|
detail: {
|
|
@@ -2448,7 +2312,7 @@ function registerFileRoutes(app, host) {
|
|
|
2448
2312
|
const { params, set } = context;
|
|
2449
2313
|
try {
|
|
2450
2314
|
if (!uploadSessions) {
|
|
2451
|
-
return
|
|
2315
|
+
return unconfiguredStorageResponse(set, "File upload session storage");
|
|
2452
2316
|
}
|
|
2453
2317
|
const principal = requireRequestSixb(context).execution.requestedBy ?? SYSTEM_PRINCIPAL;
|
|
2454
2318
|
const session = await uploadSessions.getForPrincipal(params.uploadId, principal);
|
|
@@ -2498,7 +2362,7 @@ function registerFileRoutes(app, host) {
|
|
|
2498
2362
|
const { body, params, set } = context;
|
|
2499
2363
|
try {
|
|
2500
2364
|
if (!uploadSessions) {
|
|
2501
|
-
return
|
|
2365
|
+
return unconfiguredStorageResponse(set, "File upload session storage");
|
|
2502
2366
|
}
|
|
2503
2367
|
const principal = requireRequestSixb(context).execution.requestedBy ?? SYSTEM_PRINCIPAL;
|
|
2504
2368
|
const parsed = CompleteFileUploadBodySchema.parse(body ?? {});
|
|
@@ -2554,7 +2418,7 @@ function registerFileRoutes(app, host) {
|
|
|
2554
2418
|
const { params, set } = context;
|
|
2555
2419
|
try {
|
|
2556
2420
|
if (!uploadSessions) {
|
|
2557
|
-
return
|
|
2421
|
+
return unconfiguredStorageResponse(set, "File upload session storage");
|
|
2558
2422
|
}
|
|
2559
2423
|
const principal = requireRequestSixb(context).execution.requestedBy ?? SYSTEM_PRINCIPAL;
|
|
2560
2424
|
const session = await uploadSessions.getForPrincipal(params.uploadId, principal);
|
|
@@ -2625,27 +2489,6 @@ function fileUploadResponse(session) {
|
|
|
2625
2489
|
expiresAt: session.expiresAt.toISOString()
|
|
2626
2490
|
};
|
|
2627
2491
|
}
|
|
2628
|
-
function readCappedUploadBody(context) {
|
|
2629
|
-
return readRequestBodyWithLimit(context.request, DEFAULT_SIMPLE_FILE_UPLOAD_BYTES);
|
|
2630
|
-
}
|
|
2631
|
-
function readParsedUploadBytes(context) {
|
|
2632
|
-
return context.body instanceof Uint8Array ? context.body : new Uint8Array(0);
|
|
2633
|
-
}
|
|
2634
|
-
function mapUploadContentError(context) {
|
|
2635
|
-
const tooLarge = asRequestBodyTooLarge(context.error);
|
|
2636
|
-
if (tooLarge) {
|
|
2637
|
-
context.set.status = 413;
|
|
2638
|
-
return { error: tooLarge.message };
|
|
2639
|
-
}
|
|
2640
|
-
return;
|
|
2641
|
-
}
|
|
2642
|
-
function asRequestBodyTooLarge(error) {
|
|
2643
|
-
if (error instanceof RequestBodyTooLargeError) {
|
|
2644
|
-
return error;
|
|
2645
|
-
}
|
|
2646
|
-
const cause = error?.cause;
|
|
2647
|
-
return cause instanceof RequestBodyTooLargeError ? cause : undefined;
|
|
2648
|
-
}
|
|
2649
2492
|
function terminalSessionError(status) {
|
|
2650
2493
|
return new FileUploadSessionError2(status === "completed" ? "already_completed" : "already_aborted", `File upload session is already ${status}.`);
|
|
2651
2494
|
}
|
|
@@ -2704,17 +2547,6 @@ function expectedSizeBytesError(session, actualSizeBytes) {
|
|
|
2704
2547
|
function expectedSizeBytesValueError(expectedSizeBytes, actualSizeBytes) {
|
|
2705
2548
|
return expectedSizeBytes !== undefined && actualSizeBytes !== undefined && actualSizeBytes !== expectedSizeBytes ? `File upload size mismatch: expected ${expectedSizeBytes} bytes, received ${actualSizeBytes}.` : null;
|
|
2706
2549
|
}
|
|
2707
|
-
function requestSizeLimitError(request, maxSizeBytes) {
|
|
2708
|
-
const value = request.headers.get("content-length");
|
|
2709
|
-
if (value === null) {
|
|
2710
|
-
return null;
|
|
2711
|
-
}
|
|
2712
|
-
const sizeBytes = Number(value);
|
|
2713
|
-
if (!Number.isSafeInteger(sizeBytes) || sizeBytes <= maxSizeBytes) {
|
|
2714
|
-
return null;
|
|
2715
|
-
}
|
|
2716
|
-
return `File upload request exceeds the ${maxSizeBytes} byte limit.`;
|
|
2717
|
-
}
|
|
2718
2550
|
function expectedContentLengthError(session, request) {
|
|
2719
2551
|
if (session.expectedSizeBytes === undefined) {
|
|
2720
2552
|
return null;
|
|
@@ -2781,9 +2613,9 @@ async function handleAgentApiGatewayRequest(input) {
|
|
|
2781
2613
|
}
|
|
2782
2614
|
let body;
|
|
2783
2615
|
try {
|
|
2784
|
-
body = await
|
|
2616
|
+
body = await readGatewayRequestBody(input.request, upstreamPath);
|
|
2785
2617
|
} catch (error) {
|
|
2786
|
-
if (error instanceof
|
|
2618
|
+
if (error instanceof RequestBodyTooLargeError) {
|
|
2787
2619
|
return jsonError(413, error.message);
|
|
2788
2620
|
}
|
|
2789
2621
|
throw error;
|
|
@@ -2932,7 +2764,7 @@ function gatewayUpstreamPath(pathname) {
|
|
|
2932
2764
|
const prefixLength = pathSegmentsFor(AGENT_API_GATEWAY_PREFIX2).length;
|
|
2933
2765
|
const segments = pathSegmentsFor(pathname);
|
|
2934
2766
|
const upstreamSegments = segments.slice(prefixLength + 2);
|
|
2935
|
-
return
|
|
2767
|
+
return normalizeRoutePath3(`/${upstreamSegments.join("/")}`);
|
|
2936
2768
|
}
|
|
2937
2769
|
function forwardedRequestHeaders(source) {
|
|
2938
2770
|
const headers = new Headers;
|
|
@@ -2957,49 +2789,26 @@ function copyHeader(source, target, name) {
|
|
|
2957
2789
|
target.set(name, value);
|
|
2958
2790
|
}
|
|
2959
2791
|
}
|
|
2960
|
-
async function
|
|
2792
|
+
async function readGatewayRequestBody(request, upstreamPath) {
|
|
2961
2793
|
if (!request.body || request.method === "GET" || request.method === "HEAD") {
|
|
2962
2794
|
return;
|
|
2963
2795
|
}
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
let total = 0;
|
|
2967
|
-
while (true) {
|
|
2968
|
-
const { done, value } = await reader.read();
|
|
2969
|
-
if (done)
|
|
2970
|
-
break;
|
|
2971
|
-
total += value.byteLength;
|
|
2972
|
-
if (total > maxBytes) {
|
|
2973
|
-
throw new PayloadTooLargeError(maxBytes === MAX_AGENT_API_BODY_BYTES ? "Agent API gateway request body exceeds 1MB." : `Agent API gateway file upload request body exceeds the ${maxBytes} byte limit.`);
|
|
2974
|
-
}
|
|
2975
|
-
chunks.push(value);
|
|
2796
|
+
if (isSimpleFileUpload(request.method, upstreamPath)) {
|
|
2797
|
+
return readRequestBodyWithLimit(request, DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES, `Agent API gateway file upload request body exceeds the ${DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES} byte limit.`);
|
|
2976
2798
|
}
|
|
2977
|
-
return
|
|
2799
|
+
return readRequestBodyWithLimit(request, MAX_AGENT_API_BODY_BYTES, "Agent API gateway request body exceeds 1MB.");
|
|
2978
2800
|
}
|
|
2979
2801
|
function isSimpleFileUpload(method, pathname) {
|
|
2980
|
-
return method === "POST" &&
|
|
2802
|
+
return method === "POST" && normalizeRoutePath3(pathname) === "/api/files";
|
|
2981
2803
|
}
|
|
2982
2804
|
function matchesWorkflowRunStart(pathname) {
|
|
2983
2805
|
const segments = pathSegmentsFor(pathname);
|
|
2984
2806
|
return segments.length === 4 && segments[0] === "api" && segments[1] === "workflows" && segments[3] === "runs";
|
|
2985
2807
|
}
|
|
2986
|
-
function concatChunks(chunks, total) {
|
|
2987
|
-
const buffer = new ArrayBuffer(total);
|
|
2988
|
-
const result = new Uint8Array(buffer);
|
|
2989
|
-
let offset = 0;
|
|
2990
|
-
for (const chunk of chunks) {
|
|
2991
|
-
result.set(chunk, offset);
|
|
2992
|
-
offset += chunk.byteLength;
|
|
2993
|
-
}
|
|
2994
|
-
return buffer;
|
|
2995
|
-
}
|
|
2996
2808
|
function jsonError(status, message) {
|
|
2997
2809
|
return Response.json({ error: message }, { status });
|
|
2998
2810
|
}
|
|
2999
2811
|
|
|
3000
|
-
class PayloadTooLargeError extends Error {
|
|
3001
|
-
}
|
|
3002
|
-
|
|
3003
2812
|
// src/routes/agents.ts
|
|
3004
2813
|
import {
|
|
3005
2814
|
AgentRequestError
|
|
@@ -3694,7 +3503,7 @@ function handleAgentRouteError(error, set) {
|
|
|
3694
3503
|
return handleRouteError(error, set);
|
|
3695
3504
|
}
|
|
3696
3505
|
function missingAgentStorageResponse(set) {
|
|
3697
|
-
return
|
|
3506
|
+
return unconfiguredStorageResponse(set, "Agent storage");
|
|
3698
3507
|
}
|
|
3699
3508
|
async function agentMessageFileContentResponse(host, context, options = {}) {
|
|
3700
3509
|
const authState = requestAuthState(context);
|
|
@@ -4454,7 +4263,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
4454
4263
|
sixb.aiUsage.assertObservable();
|
|
4455
4264
|
const parsed = AiAccountingOverviewQuerySchema.parse(query);
|
|
4456
4265
|
if (!sixb.aiUsage.accountingConfigured) {
|
|
4457
|
-
return
|
|
4266
|
+
return unconfiguredStorageResponse(set, "AI cost storage");
|
|
4458
4267
|
}
|
|
4459
4268
|
const overview = await sixb.aiUsage.queryOverview({
|
|
4460
4269
|
from: new Date(parsed.from),
|
|
@@ -4489,7 +4298,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
4489
4298
|
sixb.aiUsage.assertObservable();
|
|
4490
4299
|
const parsed = AiModelCallAccountingListQuerySchema.parse(query);
|
|
4491
4300
|
if (!sixb.aiUsage.accountingConfigured) {
|
|
4492
|
-
return
|
|
4301
|
+
return unconfiguredStorageResponse(set, "AI cost storage");
|
|
4493
4302
|
}
|
|
4494
4303
|
const result = await sixb.aiUsage.listModelCalls({
|
|
4495
4304
|
from: new Date(parsed.from),
|
|
@@ -4530,7 +4339,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
4530
4339
|
try {
|
|
4531
4340
|
const sixb = requireRequestSixb(context);
|
|
4532
4341
|
if (!sixb.aiUsage.limitsConfigured) {
|
|
4533
|
-
return
|
|
4342
|
+
return unconfiguredStorageResponse(set, "AI limit storage");
|
|
4534
4343
|
}
|
|
4535
4344
|
const parsed = AiLimitListQuerySchema.parse(query);
|
|
4536
4345
|
const items = await sixb.aiUsage.listLimitPolicies({
|
|
@@ -4564,7 +4373,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
4564
4373
|
const sixb = requireRequestSixb(context);
|
|
4565
4374
|
sixb.aiUsage.assertObservable();
|
|
4566
4375
|
if (!sixb.aiUsage.limitsConfigured) {
|
|
4567
|
-
return
|
|
4376
|
+
return unconfiguredStorageResponse(set, "AI limit storage");
|
|
4568
4377
|
}
|
|
4569
4378
|
const parsed = AiLimitStatusQuerySchema.parse(query);
|
|
4570
4379
|
const items = await sixb.aiUsage.listLimitStatuses({
|
|
@@ -4620,7 +4429,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
4620
4429
|
const sixb = requireRequestSixb(context);
|
|
4621
4430
|
sixb.aiUsage.assertManageable();
|
|
4622
4431
|
if (!sixb.aiUsage.limitsConfigured) {
|
|
4623
|
-
return
|
|
4432
|
+
return unconfiguredStorageResponse(set, "AI limit storage");
|
|
4624
4433
|
}
|
|
4625
4434
|
const parsed = CreateAiLimitPolicyBodySchema.parse(body);
|
|
4626
4435
|
return serializeLimitPolicy(await sixb.aiUsage.createLimitPolicy(parsed));
|
|
@@ -4649,7 +4458,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
4649
4458
|
const sixb = requireRequestSixb(context);
|
|
4650
4459
|
sixb.aiUsage.assertManageable();
|
|
4651
4460
|
if (!sixb.aiUsage.limitsConfigured) {
|
|
4652
|
-
return
|
|
4461
|
+
return unconfiguredStorageResponse(set, "AI limit storage");
|
|
4653
4462
|
}
|
|
4654
4463
|
const { limitId } = AiLimitPolicyParamsSchema.parse(params);
|
|
4655
4464
|
const parsed = UpdateAiLimitPolicyBodySchema.parse(body);
|
|
@@ -4680,7 +4489,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
4680
4489
|
const sixb = requireRequestSixb(context);
|
|
4681
4490
|
sixb.aiUsage.assertManageable();
|
|
4682
4491
|
if (!sixb.aiUsage.limitsConfigured) {
|
|
4683
|
-
return
|
|
4492
|
+
return unconfiguredStorageResponse(set, "AI limit storage");
|
|
4684
4493
|
}
|
|
4685
4494
|
const { limitId } = AiLimitPolicyParamsSchema.parse(params);
|
|
4686
4495
|
if (!await sixb.aiUsage.deleteLimitPolicy(limitId)) {
|
|
@@ -4714,7 +4523,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
4714
4523
|
const sixb = requireRequestSixb(context);
|
|
4715
4524
|
sixb.aiUsage.assertObservable();
|
|
4716
4525
|
if (!sixb.aiUsage.accountingConfigured)
|
|
4717
|
-
return
|
|
4526
|
+
return unconfiguredStorageResponse(set, "AI cost storage");
|
|
4718
4527
|
const result = await sixb.aiUsage.listModelCallGroups({
|
|
4719
4528
|
from: new Date(parsed.from),
|
|
4720
4529
|
to: new Date(parsed.to),
|
|
@@ -8192,7 +8001,7 @@ function registerPipelineRoutes(app, host) {
|
|
|
8192
8001
|
const parsed = PipelineRunsQuerySchema.parse(query);
|
|
8193
8002
|
const storage = host.storage.pipelineRuns;
|
|
8194
8003
|
if (!storage) {
|
|
8195
|
-
return
|
|
8004
|
+
return unconfiguredStorageResponse(set, "Pipeline run storage");
|
|
8196
8005
|
}
|
|
8197
8006
|
const result = await sixb.pipelines.runs.list({
|
|
8198
8007
|
pipelineId: parsed.pipelineId,
|
|
@@ -8229,7 +8038,7 @@ function registerPipelineRoutes(app, host) {
|
|
|
8229
8038
|
try {
|
|
8230
8039
|
const storage = host.storage.pipelineRuns;
|
|
8231
8040
|
if (!storage) {
|
|
8232
|
-
return
|
|
8041
|
+
return unconfiguredStorageResponse(set, "Pipeline run storage");
|
|
8233
8042
|
}
|
|
8234
8043
|
const run = await sixb.pipelines.runs.getById(params.runId);
|
|
8235
8044
|
if (!run) {
|
|
@@ -8555,7 +8364,7 @@ function registerProjectionRoutes(app, host) {
|
|
|
8555
8364
|
try {
|
|
8556
8365
|
const storage = host.storage.projectionRuns;
|
|
8557
8366
|
if (!storage) {
|
|
8558
|
-
return
|
|
8367
|
+
return unconfiguredStorageResponse(set, "Projection run storage");
|
|
8559
8368
|
}
|
|
8560
8369
|
const parsed = ProjectionRunsQuerySchema.parse(query);
|
|
8561
8370
|
const result = await sixb.projections.runs.list({
|
|
@@ -8596,7 +8405,7 @@ function registerProjectionRoutes(app, host) {
|
|
|
8596
8405
|
try {
|
|
8597
8406
|
const storage = host.storage.projectionRuns;
|
|
8598
8407
|
if (!storage) {
|
|
8599
|
-
return
|
|
8408
|
+
return unconfiguredStorageResponse(set, "Projection run storage");
|
|
8600
8409
|
}
|
|
8601
8410
|
const run = await sixb.projections.runs.getById(params.runId);
|
|
8602
8411
|
if (!run) {
|
|
@@ -8754,7 +8563,7 @@ function registerRuleRoutes(app, host) {
|
|
|
8754
8563
|
const parsed = RuleStatesQuerySchema.parse(query);
|
|
8755
8564
|
const storage = host.storage.rules;
|
|
8756
8565
|
if (!storage) {
|
|
8757
|
-
return
|
|
8566
|
+
return unconfiguredStorageResponse(set, "Rule state storage");
|
|
8758
8567
|
}
|
|
8759
8568
|
const result = await sixb.rules.states.list({
|
|
8760
8569
|
ruleId: parsed.ruleId,
|
|
@@ -9442,7 +9251,7 @@ function registerSyncRoutes(app, host) {
|
|
|
9442
9251
|
const parsed = SyncRunsQuerySchema.parse(query);
|
|
9443
9252
|
const storage = host.storage.syncRuns;
|
|
9444
9253
|
if (!storage) {
|
|
9445
|
-
return
|
|
9254
|
+
return unconfiguredStorageResponse(set, "Sync run storage");
|
|
9446
9255
|
}
|
|
9447
9256
|
const result = await sixb.syncs.runs.list({
|
|
9448
9257
|
syncId: parsed.syncId,
|
|
@@ -9773,7 +9582,7 @@ function registerWebhookRunRoutes(app, host) {
|
|
|
9773
9582
|
const parsed = WebhookRunsQuerySchema.parse(query);
|
|
9774
9583
|
const storage = host.storage.webhookRuns;
|
|
9775
9584
|
if (!storage) {
|
|
9776
|
-
return
|
|
9585
|
+
return unconfiguredStorageResponse(set, "Webhook run storage");
|
|
9777
9586
|
}
|
|
9778
9587
|
const result = await storage.list({
|
|
9779
9588
|
projectId: host.id,
|
|
@@ -10170,7 +9979,7 @@ async function workflowRunFileContentResponse(host, context, options = {}) {
|
|
|
10170
9979
|
const sixb = requireRequestSixb(context);
|
|
10171
9980
|
const storage = host.storage.workflowRuns;
|
|
10172
9981
|
if (!storage) {
|
|
10173
|
-
return
|
|
9982
|
+
return unconfiguredStorageResponse(context.set, "Workflow run storage");
|
|
10174
9983
|
}
|
|
10175
9984
|
return createContextualFileContentResponse({
|
|
10176
9985
|
blobStorage: host.blobStorage,
|
|
@@ -10189,7 +9998,7 @@ async function workflowNodeFileContentResponse(host, context, options = {}) {
|
|
|
10189
9998
|
const sixb = requireRequestSixb(context);
|
|
10190
9999
|
const storage = host.storage.workflowRuns;
|
|
10191
10000
|
if (!storage) {
|
|
10192
|
-
return
|
|
10001
|
+
return unconfiguredStorageResponse(context.set, "Workflow run storage");
|
|
10193
10002
|
}
|
|
10194
10003
|
return createContextualFileContentResponse({
|
|
10195
10004
|
blobStorage: host.blobStorage,
|
|
@@ -10437,7 +10246,7 @@ function registerWorkflowRoutes(app, host) {
|
|
|
10437
10246
|
const offset = parseOptionalInt(parsed.offset);
|
|
10438
10247
|
const storage = host.storage.workflowInterventions;
|
|
10439
10248
|
if (!storage) {
|
|
10440
|
-
return
|
|
10249
|
+
return unconfiguredStorageResponse(set, "Workflow intervention storage");
|
|
10441
10250
|
}
|
|
10442
10251
|
const result = await sixb.workflows.interventions.list({
|
|
10443
10252
|
workflowId: parsed.workflowId,
|
|
@@ -10479,7 +10288,7 @@ function registerWorkflowRoutes(app, host) {
|
|
|
10479
10288
|
try {
|
|
10480
10289
|
const storage = host.storage.workflowInterventions;
|
|
10481
10290
|
if (!storage) {
|
|
10482
|
-
return
|
|
10291
|
+
return unconfiguredStorageResponse(set, "Workflow intervention storage");
|
|
10483
10292
|
}
|
|
10484
10293
|
const intervention = await sixb.workflows.interventions.getById(params.interventionId);
|
|
10485
10294
|
if (!intervention) {
|
|
@@ -10509,7 +10318,7 @@ function registerWorkflowRoutes(app, host) {
|
|
|
10509
10318
|
try {
|
|
10510
10319
|
const storage = host.storage.workflowInterventions;
|
|
10511
10320
|
if (!storage) {
|
|
10512
|
-
return
|
|
10321
|
+
return unconfiguredStorageResponse(set, "Workflow intervention storage");
|
|
10513
10322
|
}
|
|
10514
10323
|
const intervention = await sixb.workflows.interventions.getById(params.interventionId);
|
|
10515
10324
|
if (!intervention) {
|
|
@@ -10579,11 +10388,11 @@ function registerWorkflowRoutes(app, host) {
|
|
|
10579
10388
|
try {
|
|
10580
10389
|
const interventionStorage = host.storage.workflowInterventions;
|
|
10581
10390
|
if (!interventionStorage) {
|
|
10582
|
-
return
|
|
10391
|
+
return unconfiguredStorageResponse(set, "Workflow intervention storage");
|
|
10583
10392
|
}
|
|
10584
10393
|
const runStorage = host.storage.workflowRuns;
|
|
10585
10394
|
if (!runStorage) {
|
|
10586
|
-
return
|
|
10395
|
+
return unconfiguredStorageResponse(set, "Workflow run storage");
|
|
10587
10396
|
}
|
|
10588
10397
|
const intervention = await sixb.workflows.interventions.getById(params.interventionId);
|
|
10589
10398
|
if (!intervention) {
|
|
@@ -10695,7 +10504,7 @@ function registerWorkflowRoutes(app, host) {
|
|
|
10695
10504
|
const offset = parseOptionalInt(parsed.offset);
|
|
10696
10505
|
const storage = host.storage.workflowRuns;
|
|
10697
10506
|
if (!storage) {
|
|
10698
|
-
return
|
|
10507
|
+
return unconfiguredStorageResponse(set, "Workflow run storage");
|
|
10699
10508
|
}
|
|
10700
10509
|
const result = await sixb.workflows.runs.list({
|
|
10701
10510
|
workflowId: parsed.workflowId,
|
|
@@ -10734,7 +10543,7 @@ function registerWorkflowRoutes(app, host) {
|
|
|
10734
10543
|
try {
|
|
10735
10544
|
const storage = host.storage.workflowRuns;
|
|
10736
10545
|
if (!storage) {
|
|
10737
|
-
return
|
|
10546
|
+
return unconfiguredStorageResponse(set, "Workflow run storage");
|
|
10738
10547
|
}
|
|
10739
10548
|
const run = await sixb.workflows.runs.getById(params.runId);
|
|
10740
10549
|
if (!run) {
|
|
@@ -10776,7 +10585,7 @@ function registerWorkflowRoutes(app, host) {
|
|
|
10776
10585
|
try {
|
|
10777
10586
|
const storage = host.storage.workflowRuns;
|
|
10778
10587
|
if (!storage) {
|
|
10779
|
-
return
|
|
10588
|
+
return unconfiguredStorageResponse(set, "Workflow run storage");
|
|
10780
10589
|
}
|
|
10781
10590
|
const run = await sixb.workflows.runs.getById(params.runId);
|
|
10782
10591
|
if (!run) {
|
|
@@ -10819,7 +10628,7 @@ function registerWorkflowRoutes(app, host) {
|
|
|
10819
10628
|
CancelWorkflowRunBodySchema.parse(body ?? {});
|
|
10820
10629
|
const storage = host.storage.workflowRuns;
|
|
10821
10630
|
if (!storage) {
|
|
10822
|
-
return
|
|
10631
|
+
return unconfiguredStorageResponse(set, "Workflow run storage");
|
|
10823
10632
|
}
|
|
10824
10633
|
const existing = await sixb.workflows.runs.getById(params.runId);
|
|
10825
10634
|
if (!existing) {
|
|
@@ -11020,7 +10829,7 @@ function registerWorkflowRoutes(app, host) {
|
|
|
11020
10829
|
const sixb = requireRequestSixb(context);
|
|
11021
10830
|
try {
|
|
11022
10831
|
if (!host.storage.workflowRuns) {
|
|
11023
|
-
return
|
|
10832
|
+
return unconfiguredStorageResponse(set, "Workflow run storage");
|
|
11024
10833
|
}
|
|
11025
10834
|
const parsedBody = RequestWorkflowRunBodySchema.parse(body);
|
|
11026
10835
|
const input = {
|
|
@@ -11093,9 +10902,6 @@ function registerHttpRoutes(app, host, options) {
|
|
|
11093
10902
|
|
|
11094
10903
|
// src/routes/auth.ts
|
|
11095
10904
|
import { createHash as createHash3, randomBytes, randomUUID, timingSafeEqual } from "crypto";
|
|
11096
|
-
import {
|
|
11097
|
-
DEFAULT_AUTH_SESSION_AUDIENCE as DEFAULT_AUTH_SESSION_AUDIENCE2
|
|
11098
|
-
} from "@sixb/core";
|
|
11099
10905
|
import {
|
|
11100
10906
|
AuthRuntimeError,
|
|
11101
10907
|
clearCsrfCookieHeader,
|
|
@@ -11123,7 +10929,7 @@ import { resolve } from "path";
|
|
|
11123
10929
|
var AUTH_BOOTSTRAP_PLACEHOLDER = "__SIXB_AUTH_BOOTSTRAP__";
|
|
11124
10930
|
var AUTH_ASSET_PREFIX = "/auth/assets/";
|
|
11125
10931
|
async function customAuthExperienceResponse(options, input) {
|
|
11126
|
-
if (!options
|
|
10932
|
+
if (!options) {
|
|
11127
10933
|
return null;
|
|
11128
10934
|
}
|
|
11129
10935
|
const template = Bun.file(resolve(options.outdir, "index.html"));
|
|
@@ -11438,14 +11244,8 @@ var AuthCreateInvitationCapabilitySchema = z32.union([
|
|
|
11438
11244
|
reason: z32.enum(["missing_membership_policy", "invitation_delivery_not_supported"])
|
|
11439
11245
|
})
|
|
11440
11246
|
]);
|
|
11441
|
-
var AuthInvitationDestinationSchema = z32.object({
|
|
11442
|
-
id: z32.enum(["atlas", "app"]),
|
|
11443
|
-
label: z32.string()
|
|
11444
|
-
});
|
|
11445
11247
|
var GetAuthInvitationOptionsResponseSchema = z32.object({
|
|
11446
11248
|
groups: z32.array(AuthInvitationGroupOptionSchema),
|
|
11447
|
-
destinations: z32.array(AuthInvitationDestinationSchema),
|
|
11448
|
-
defaultDestinationId: z32.enum(["atlas", "app"]).optional(),
|
|
11449
11249
|
canInviteWithoutGroups: z32.boolean(),
|
|
11450
11250
|
capabilities: z32.object({
|
|
11451
11251
|
createInvitation: AuthCreateInvitationCapabilitySchema
|
|
@@ -11453,10 +11253,12 @@ var GetAuthInvitationOptionsResponseSchema = z32.object({
|
|
|
11453
11253
|
});
|
|
11454
11254
|
var GetAuthMembershipOptionsResponseSchema = z32.object({
|
|
11455
11255
|
groups: z32.array(AuthGroupOptionSchema),
|
|
11256
|
+
serviceAccountGroups: z32.array(AuthGroupOptionSchema),
|
|
11456
11257
|
capabilities: z32.object({
|
|
11457
11258
|
invite: z32.boolean(),
|
|
11458
11259
|
assignGroups: z32.boolean(),
|
|
11459
|
-
suspend: z32.boolean()
|
|
11260
|
+
suspend: z32.boolean(),
|
|
11261
|
+
serviceAccounts: z32.boolean()
|
|
11460
11262
|
})
|
|
11461
11263
|
});
|
|
11462
11264
|
var ListAuthMembersQuerySchema = z32.object({
|
|
@@ -11487,7 +11289,6 @@ var ReactivateAuthMemberResponseSchema = z32.object({
|
|
|
11487
11289
|
var CreateAuthInvitationBodySchema = z32.object({
|
|
11488
11290
|
email: z32.string().min(1),
|
|
11489
11291
|
groupIds: z32.array(z32.string().min(1)).optional(),
|
|
11490
|
-
destinationId: z32.enum(["atlas", "app"]).optional(),
|
|
11491
11292
|
expiresAt: z32.string().optional(),
|
|
11492
11293
|
returnTo: z32.string().optional(),
|
|
11493
11294
|
revealLink: z32.boolean().optional()
|
|
@@ -11522,10 +11323,6 @@ var AuthSessionResponseSchema = z32.union([
|
|
|
11522
11323
|
z32.object({
|
|
11523
11324
|
authenticated: z32.literal(true),
|
|
11524
11325
|
csrfToken: z32.string().optional(),
|
|
11525
|
-
applicationAccess: z32.object({
|
|
11526
|
-
allowed: z32.boolean(),
|
|
11527
|
-
audience: z32.enum(["atlas", "app"])
|
|
11528
|
-
}),
|
|
11529
11326
|
user: z32.object({
|
|
11530
11327
|
id: z32.string(),
|
|
11531
11328
|
email: z32.string(),
|
|
@@ -11577,7 +11374,6 @@ var DeviceAuthorizationDecisionBodySchema = z32.object({
|
|
|
11577
11374
|
});
|
|
11578
11375
|
var AuthSessionSummarySchema = z32.object({
|
|
11579
11376
|
id: z32.string(),
|
|
11580
|
-
audience: z32.enum(["atlas", "app"]).optional(),
|
|
11581
11377
|
current: z32.boolean(),
|
|
11582
11378
|
createdAt: z32.string(),
|
|
11583
11379
|
expiresAt: z32.string(),
|
|
@@ -11739,11 +11535,10 @@ function registerAuthRoutes(app, host, options) {
|
|
|
11739
11535
|
if (!authorization || authorization.status !== "pending" || authorization.expiresAt <= now) {
|
|
11740
11536
|
return authPageResponse("<h1>This authorization has expired</h1>", 400);
|
|
11741
11537
|
}
|
|
11742
|
-
const
|
|
11743
|
-
const session = await host.auth.getSession(request, authOptions);
|
|
11538
|
+
const session = await host.auth.getSession(request);
|
|
11744
11539
|
if (!session.authenticated)
|
|
11745
11540
|
return authPageResponse("<h1>Authentication required</h1>", 401);
|
|
11746
|
-
const cookieOptions = host.auth.getCookieOptions(
|
|
11541
|
+
const cookieOptions = host.auth.getCookieOptions();
|
|
11747
11542
|
const csrf = resolveSessionCsrfToken({
|
|
11748
11543
|
request,
|
|
11749
11544
|
cookieOptions,
|
|
@@ -11768,11 +11563,10 @@ function registerAuthRoutes(app, host, options) {
|
|
|
11768
11563
|
return response;
|
|
11769
11564
|
}, { detail: { hide: true } }).post("/auth/device", async ({ body, request }) => {
|
|
11770
11565
|
const parsed = DeviceAuthorizationDecisionBodySchema.parse(body);
|
|
11771
|
-
const
|
|
11772
|
-
const session = await host.auth.getSession(request, authOptions);
|
|
11566
|
+
const session = await host.auth.getSession(request);
|
|
11773
11567
|
if (!session.authenticated)
|
|
11774
11568
|
return authPageResponse("<h1>Authentication required</h1>", 401);
|
|
11775
|
-
const csrfCookieName = host.auth.getCookieOptions(
|
|
11569
|
+
const csrfCookieName = host.auth.getCookieOptions().csrfCookieName;
|
|
11776
11570
|
if (!verifyCsrfToken(request, { cookieName: csrfCookieName, token: parsed.csrfToken })) {
|
|
11777
11571
|
return authPageResponse("<h1>Invalid authorization request</h1>", 403);
|
|
11778
11572
|
}
|
|
@@ -11816,22 +11610,18 @@ function registerAuthRoutes(app, host, options) {
|
|
|
11816
11610
|
parse: "urlencoded",
|
|
11817
11611
|
detail: { hide: true }
|
|
11818
11612
|
}).get("/api/auth/session", async ({ request }) => {
|
|
11819
|
-
const
|
|
11820
|
-
const caller = await host.auth.getSession(request, {
|
|
11821
|
-
...authOptions,
|
|
11822
|
-
credentialSource: "any"
|
|
11823
|
-
});
|
|
11613
|
+
const caller = await host.auth.getSession(request, { credentialSource: "any" });
|
|
11824
11614
|
if (!caller.authenticated || caller.credentialSource !== "session") {
|
|
11825
11615
|
return signedOutSessionResponse(host);
|
|
11826
11616
|
}
|
|
11827
11617
|
if (caller.session.bearer) {
|
|
11828
|
-
return jsonResponse2(authSessionBody(
|
|
11618
|
+
return jsonResponse2(authSessionBody(caller), 200);
|
|
11829
11619
|
}
|
|
11830
|
-
const session = hasForegroundSessionActivity(request)
|
|
11620
|
+
const session = hasForegroundSessionActivity(request) ? await host.auth.getSession(request, { sessionActivity: "foreground" }) : caller;
|
|
11831
11621
|
if (!session.authenticated) {
|
|
11832
11622
|
return signedOutSessionResponse(host);
|
|
11833
11623
|
}
|
|
11834
|
-
const cookieOptions = host.auth.getCookieOptions(
|
|
11624
|
+
const cookieOptions = host.auth.getCookieOptions();
|
|
11835
11625
|
const csrf = resolveSessionCsrfToken({
|
|
11836
11626
|
request,
|
|
11837
11627
|
cookieOptions,
|
|
@@ -11843,7 +11633,7 @@ function registerAuthRoutes(app, host, options) {
|
|
|
11843
11633
|
session,
|
|
11844
11634
|
csrfToken: csrf.token
|
|
11845
11635
|
}) : null;
|
|
11846
|
-
return authSessionJsonResponse({ ...authSessionBody(
|
|
11636
|
+
return authSessionJsonResponse({ ...authSessionBody(session), csrfToken: csrf.token }, renewal?.headers ?? (csrf.setCookie ? [csrf.setCookie] : []));
|
|
11847
11637
|
}, {
|
|
11848
11638
|
response: { 200: AuthSessionResponseSchema },
|
|
11849
11639
|
detail: {
|
|
@@ -11853,13 +11643,9 @@ function registerAuthRoutes(app, host, options) {
|
|
|
11853
11643
|
security: SIXB_OPTIONAL_SESSION_SECURITY_REQUIREMENT
|
|
11854
11644
|
}
|
|
11855
11645
|
}).post("/api/auth/sign-out", async ({ request }) => {
|
|
11856
|
-
const
|
|
11857
|
-
const result = await host.auth.getSession(request, {
|
|
11858
|
-
...authOptions,
|
|
11859
|
-
credentialSource: "any"
|
|
11860
|
-
});
|
|
11646
|
+
const result = await host.auth.getSession(request, { credentialSource: "any" });
|
|
11861
11647
|
const session = result.authenticated && result.credentialSource === "session" ? result : null;
|
|
11862
|
-
const cookieOptions = host.auth.getCookieOptions(
|
|
11648
|
+
const cookieOptions = host.auth.getCookieOptions();
|
|
11863
11649
|
if (session && !session.session.bearer && !verifyDoubleSubmitCsrf3(request, {
|
|
11864
11650
|
cookieName: cookieOptions.csrfCookieName
|
|
11865
11651
|
})) {
|
|
@@ -11889,7 +11675,6 @@ function registerAuthRoutes(app, host, options) {
|
|
|
11889
11675
|
return jsonResponse2({
|
|
11890
11676
|
sessions: sessions.map((entry) => ({
|
|
11891
11677
|
id: entry.id,
|
|
11892
|
-
audience: entry.bearer ? undefined : entry.audience,
|
|
11893
11678
|
current: entry.id === session.session.id,
|
|
11894
11679
|
createdAt: toIsoString(entry.createdAt),
|
|
11895
11680
|
expiresAt: toIsoString(entry.expiresAt),
|
|
@@ -11921,7 +11706,7 @@ function registerAuthRoutes(app, host, options) {
|
|
|
11921
11706
|
if (sessionId !== session.session.id) {
|
|
11922
11707
|
return jsonResponse2({ success: true }, 200);
|
|
11923
11708
|
}
|
|
11924
|
-
const cookieOptions = host.auth.getCookieOptions(
|
|
11709
|
+
const cookieOptions = host.auth.getCookieOptions();
|
|
11925
11710
|
return signedOutResponse(request, cookieOptions, { success: true });
|
|
11926
11711
|
}, {
|
|
11927
11712
|
params: RevokeAuthSessionParamsSchema,
|
|
@@ -11943,7 +11728,7 @@ function registerAuthRoutes(app, host, options) {
|
|
|
11943
11728
|
return session;
|
|
11944
11729
|
}
|
|
11945
11730
|
const revokedCount = await host.auth.revokeAllSessions(session);
|
|
11946
|
-
const cookieOptions = host.auth.getCookieOptions(
|
|
11731
|
+
const cookieOptions = host.auth.getCookieOptions();
|
|
11947
11732
|
return signedOutResponse(request, cookieOptions, { success: true, revokedCount });
|
|
11948
11733
|
}, {
|
|
11949
11734
|
response: {
|
|
@@ -12243,7 +12028,6 @@ function registerAuthRoutes(app, host, options) {
|
|
|
12243
12028
|
const caller = requireUserCaller(context);
|
|
12244
12029
|
const parsed = CreateAuthInvitationBodySchema.parse(body);
|
|
12245
12030
|
const deliveryContext = resolveInvitationDeliveryContext(options, request, {
|
|
12246
|
-
destinationId: parsed.destinationId,
|
|
12247
12031
|
returnTo: parsed.returnTo
|
|
12248
12032
|
});
|
|
12249
12033
|
if (deliveryContext instanceof Response) {
|
|
@@ -12282,10 +12066,7 @@ function registerAuthRoutes(app, host, options) {
|
|
|
12282
12066
|
}).get("/api/auth/invitation-options", async ({ request, ...context }) => {
|
|
12283
12067
|
try {
|
|
12284
12068
|
const caller = requireUserCaller(context);
|
|
12285
|
-
return jsonResponse2(
|
|
12286
|
-
...await host.auth.getInvitationOptions(caller),
|
|
12287
|
-
...options.getInvitationDestinationOptions(request)
|
|
12288
|
-
}, 200);
|
|
12069
|
+
return jsonResponse2(await host.auth.getInvitationOptions(caller), 200);
|
|
12289
12070
|
} catch (error) {
|
|
12290
12071
|
return authRouteErrorResponse(error);
|
|
12291
12072
|
}
|
|
@@ -12492,7 +12273,6 @@ function registerAuthRoutes(app, host, options) {
|
|
|
12492
12273
|
}).post("/auth/sign-in", async ({ body, request }) => {
|
|
12493
12274
|
const strategy = host.auth.getStrategy();
|
|
12494
12275
|
const authRedirect = resolveAuthRedirectContext(options, request, {
|
|
12495
|
-
audience: body.audience,
|
|
12496
12276
|
returnTo: body.returnTo
|
|
12497
12277
|
});
|
|
12498
12278
|
if (authRedirect instanceof Response) {
|
|
@@ -12505,7 +12285,6 @@ function registerAuthRoutes(app, host, options) {
|
|
|
12505
12285
|
projectId: host.id,
|
|
12506
12286
|
authStorage,
|
|
12507
12287
|
email: body.email ?? "",
|
|
12508
|
-
audience: authRedirect.audience,
|
|
12509
12288
|
returnTo: authRedirect.returnTo,
|
|
12510
12289
|
requestOrigin: authRedirect.requestOrigin,
|
|
12511
12290
|
requesterHash: pending.hash
|
|
@@ -12525,7 +12304,6 @@ function registerAuthRoutes(app, host, options) {
|
|
|
12525
12304
|
const result = await strategy.startOidcSignIn({
|
|
12526
12305
|
projectId: host.id,
|
|
12527
12306
|
authStorage,
|
|
12528
|
-
audience: authRedirect.audience,
|
|
12529
12307
|
returnTo: authRedirect.returnTo,
|
|
12530
12308
|
requestOrigin: authRedirect.requestOrigin
|
|
12531
12309
|
});
|
|
@@ -12534,7 +12312,6 @@ function registerAuthRoutes(app, host, options) {
|
|
|
12534
12312
|
return strategyNotImplementedResponse("Sign-in is not implemented yet.");
|
|
12535
12313
|
}, {
|
|
12536
12314
|
body: t.Object({
|
|
12537
|
-
audience: t.Optional(t.String()),
|
|
12538
12315
|
email: t.Optional(t.String()),
|
|
12539
12316
|
returnTo: t.Optional(t.String())
|
|
12540
12317
|
}),
|
|
@@ -12544,7 +12321,6 @@ function registerAuthRoutes(app, host, options) {
|
|
|
12544
12321
|
const strategy = host.auth.getStrategy();
|
|
12545
12322
|
const url = new URL(request.url);
|
|
12546
12323
|
const authRedirect = resolveAuthRedirectContext(options, request, {
|
|
12547
|
-
audience: url.searchParams.get("audience"),
|
|
12548
12324
|
returnTo: url.searchParams.get("returnTo")
|
|
12549
12325
|
});
|
|
12550
12326
|
if (authRedirect instanceof Response) {
|
|
@@ -12557,7 +12333,6 @@ function registerAuthRoutes(app, host, options) {
|
|
|
12557
12333
|
const result = await strategy.startOidcSignIn({
|
|
12558
12334
|
projectId: host.id,
|
|
12559
12335
|
authStorage: requireAuthStorage(host),
|
|
12560
|
-
audience: authRedirect.audience,
|
|
12561
12336
|
returnTo: authRedirect.returnTo,
|
|
12562
12337
|
requestOrigin: authRedirect.requestOrigin
|
|
12563
12338
|
});
|
|
@@ -12570,7 +12345,7 @@ function registerAuthRoutes(app, host, options) {
|
|
|
12570
12345
|
const url = new URL(request.url);
|
|
12571
12346
|
const magicLinkId = url.searchParams.get("magicLinkId")?.trim();
|
|
12572
12347
|
const token = url.searchParams.get("token")?.trim();
|
|
12573
|
-
const authRedirectHint = resolveAuthExperienceRedirectHint(options, request
|
|
12348
|
+
const authRedirectHint = resolveAuthExperienceRedirectHint(options, request);
|
|
12574
12349
|
if (!magicLinkId || !token) {
|
|
12575
12350
|
return await invalidMagicLinkResponse(options, authRedirectHint);
|
|
12576
12351
|
}
|
|
@@ -12623,7 +12398,6 @@ function registerAuthRoutes(app, host, options) {
|
|
|
12623
12398
|
if (!state || !matchesOidcStateCookie(request, state)) {
|
|
12624
12399
|
throw new Error("[SixbServer] OIDC callback reached a browser that did not start this sign-in.");
|
|
12625
12400
|
}
|
|
12626
|
-
const authOptions = resolveAuthOptions(options, request);
|
|
12627
12401
|
const result = await strategy.completeOidcSignIn({
|
|
12628
12402
|
projectId: host.id,
|
|
12629
12403
|
authStorage: requireAuthStorage(host),
|
|
@@ -12631,7 +12405,6 @@ function registerAuthRoutes(app, host, options) {
|
|
|
12631
12405
|
requestOrigin: options.resolveAuthRequestOrigin(request),
|
|
12632
12406
|
session: {
|
|
12633
12407
|
id: sessionCredential.sessionId,
|
|
12634
|
-
audience: authOptions.audience,
|
|
12635
12408
|
tokenHash: sessionCredential.tokenHash,
|
|
12636
12409
|
createdAt: now,
|
|
12637
12410
|
...host.auth.createSessionDeadlines(now),
|
|
@@ -12643,7 +12416,6 @@ function registerAuthRoutes(app, host, options) {
|
|
|
12643
12416
|
request,
|
|
12644
12417
|
apiOrigin: options.resolveAuthRequestOrigin(request),
|
|
12645
12418
|
sessionCredential,
|
|
12646
|
-
audience: result.session.audience,
|
|
12647
12419
|
expiresAt: result.session.expiresAt,
|
|
12648
12420
|
returnTo: result.returnTo
|
|
12649
12421
|
});
|
|
@@ -12670,7 +12442,7 @@ function registerAuthRoutes(app, host, options) {
|
|
|
12670
12442
|
}
|
|
12671
12443
|
const magicLinkId = body.magicLinkId?.trim();
|
|
12672
12444
|
const token = body.token?.trim();
|
|
12673
|
-
const authRedirectHint = resolveAuthExperienceRedirectHint(options, request
|
|
12445
|
+
const authRedirectHint = resolveAuthExperienceRedirectHint(options, request);
|
|
12674
12446
|
if (!magicLinkId || !token) {
|
|
12675
12447
|
return await invalidMagicLinkResponse(options, authRedirectHint);
|
|
12676
12448
|
}
|
|
@@ -12686,8 +12458,7 @@ function registerAuthRoutes(app, host, options) {
|
|
|
12686
12458
|
}, {
|
|
12687
12459
|
body: t.Object({
|
|
12688
12460
|
magicLinkId: t.Optional(t.String()),
|
|
12689
|
-
token: t.Optional(t.String())
|
|
12690
|
-
audience: t.Optional(t.String())
|
|
12461
|
+
token: t.Optional(t.String())
|
|
12691
12462
|
}),
|
|
12692
12463
|
parse: "urlencoded",
|
|
12693
12464
|
detail: { hide: true }
|
|
@@ -12749,7 +12520,6 @@ function callbackCookieHeader(params) {
|
|
|
12749
12520
|
return parts.join("; ");
|
|
12750
12521
|
}
|
|
12751
12522
|
async function completeMagicLinkCallback(input) {
|
|
12752
|
-
const authOptions = resolveAuthOptions(input.options, input.request);
|
|
12753
12523
|
const now = new Date;
|
|
12754
12524
|
const sessionCredential = createSessionCredential();
|
|
12755
12525
|
const device = resolveSessionDevice(input.request);
|
|
@@ -12761,7 +12531,6 @@ async function completeMagicLinkCallback(input) {
|
|
|
12761
12531
|
token: input.token,
|
|
12762
12532
|
session: {
|
|
12763
12533
|
id: sessionCredential.sessionId,
|
|
12764
|
-
audience: authOptions.audience,
|
|
12765
12534
|
tokenHash: sessionCredential.tokenHash,
|
|
12766
12535
|
createdAt: now,
|
|
12767
12536
|
...input.host.auth.createSessionDeadlines(now),
|
|
@@ -12773,7 +12542,6 @@ async function completeMagicLinkCallback(input) {
|
|
|
12773
12542
|
request: input.request,
|
|
12774
12543
|
apiOrigin: input.options.resolveAuthRequestOrigin(input.request),
|
|
12775
12544
|
sessionCredential,
|
|
12776
|
-
audience: result.session.audience,
|
|
12777
12545
|
expiresAt: result.session.expiresAt,
|
|
12778
12546
|
returnTo: result.returnTo
|
|
12779
12547
|
});
|
|
@@ -12827,7 +12595,7 @@ function resolveSessionDevice(request) {
|
|
|
12827
12595
|
};
|
|
12828
12596
|
}
|
|
12829
12597
|
function sessionCallbackCompletionResponse(input) {
|
|
12830
|
-
const cookieOptions = input.host.auth.getCookieOptions(
|
|
12598
|
+
const cookieOptions = input.host.auth.getCookieOptions();
|
|
12831
12599
|
const headers = new Headers({
|
|
12832
12600
|
"cache-control": "no-store"
|
|
12833
12601
|
});
|
|
@@ -12875,9 +12643,6 @@ function authCallbackCompletionDocumentResponse(returnTo, headers) {
|
|
|
12875
12643
|
headers
|
|
12876
12644
|
});
|
|
12877
12645
|
}
|
|
12878
|
-
function resolveAuthOptions(options, request) {
|
|
12879
|
-
return options.resolveAuthContext(request);
|
|
12880
|
-
}
|
|
12881
12646
|
function resolveAuthRedirectContext(options, request, input) {
|
|
12882
12647
|
try {
|
|
12883
12648
|
return options.resolveAuthRedirectContext(request, input);
|
|
@@ -12893,7 +12658,7 @@ function resolveInvitationDeliveryContext(options, request, input) {
|
|
|
12893
12658
|
return options.resolveInvitationRedirectContext(request, input);
|
|
12894
12659
|
} catch (error) {
|
|
12895
12660
|
if (error instanceof BrowserOriginError) {
|
|
12896
|
-
return jsonResponse2({ error: "Invitation
|
|
12661
|
+
return jsonResponse2({ error: "Invitation return target is not allowed" }, 400);
|
|
12897
12662
|
}
|
|
12898
12663
|
throw error;
|
|
12899
12664
|
}
|
|
@@ -12914,10 +12679,9 @@ function resolveSessionCsrfToken(input) {
|
|
|
12914
12679
|
})
|
|
12915
12680
|
};
|
|
12916
12681
|
}
|
|
12917
|
-
function authSessionBody(
|
|
12682
|
+
function authSessionBody(session) {
|
|
12918
12683
|
return {
|
|
12919
12684
|
authenticated: true,
|
|
12920
|
-
applicationAccess: { allowed: sessionCanAccessApplication(host, session, audience), audience },
|
|
12921
12685
|
user: {
|
|
12922
12686
|
id: session.user.id,
|
|
12923
12687
|
email: session.user.email,
|
|
@@ -13107,20 +12871,18 @@ function authPageResponse(body, status = 200) {
|
|
|
13107
12871
|
}
|
|
13108
12872
|
async function signInFormResponse(options, context) {
|
|
13109
12873
|
return await customAuthExperienceResponse(options.authExperience, {
|
|
13110
|
-
audience: context.audience,
|
|
13111
12874
|
state: { kind: "signIn" },
|
|
13112
12875
|
signInUrl: authExperienceSignInUrl(context),
|
|
13113
12876
|
submission: {
|
|
13114
12877
|
kind: "requestMagicLink",
|
|
13115
12878
|
action: "/auth/sign-in",
|
|
13116
|
-
fields: {
|
|
12879
|
+
fields: { returnTo: context.returnTo }
|
|
13117
12880
|
},
|
|
13118
12881
|
referrerPolicy: "same-origin"
|
|
13119
12882
|
}) ?? authPageResponse([
|
|
13120
12883
|
"<h1>Sign in</h1>",
|
|
13121
12884
|
"<p>We'll email you a sign-in link.</p>",
|
|
13122
12885
|
'<form method="post" action="/auth/sign-in">',
|
|
13123
|
-
`<input type="hidden" name="audience" value="${escapeHtml(context.audience)}">`,
|
|
13124
12886
|
`<input type="hidden" name="returnTo" value="${escapeHtml(context.returnTo)}">`,
|
|
13125
12887
|
'<input name="email" type="email" autocomplete="email" placeholder="you@example.com" aria-label="Email address" required autofocus>',
|
|
13126
12888
|
'<button type="submit">Send sign-in link</button>',
|
|
@@ -13129,7 +12891,6 @@ async function signInFormResponse(options, context) {
|
|
|
13129
12891
|
}
|
|
13130
12892
|
async function magicLinkRequestedResponse(options, context) {
|
|
13131
12893
|
return await customAuthExperienceResponse(options.authExperience, {
|
|
13132
|
-
audience: context.audience,
|
|
13133
12894
|
state: { kind: "checkEmail" },
|
|
13134
12895
|
signInUrl: authExperienceSignInUrl(context)
|
|
13135
12896
|
}) ?? htmlMessageResponse("If this email can sign in, we sent a link. Check your inbox to continue.", 200, "Check your email");
|
|
@@ -13137,7 +12898,6 @@ async function magicLinkRequestedResponse(options, context) {
|
|
|
13137
12898
|
async function invalidMagicLinkResponse(options, context) {
|
|
13138
12899
|
if (context) {
|
|
13139
12900
|
const custom = await customAuthExperienceResponse(options.authExperience, {
|
|
13140
|
-
audience: context.audience,
|
|
13141
12901
|
state: { kind: "invalidLink" },
|
|
13142
12902
|
signInUrl: authExperienceSignInUrl(context),
|
|
13143
12903
|
status: 400
|
|
@@ -13150,7 +12910,6 @@ async function invalidMagicLinkResponse(options, context) {
|
|
|
13150
12910
|
async function authExperienceErrorResponse(options, context) {
|
|
13151
12911
|
if (context) {
|
|
13152
12912
|
const custom = await customAuthExperienceResponse(options.authExperience, {
|
|
13153
|
-
audience: context.audience,
|
|
13154
12913
|
state: { kind: "error" },
|
|
13155
12914
|
signInUrl: authExperienceSignInUrl(context),
|
|
13156
12915
|
status: 500
|
|
@@ -13161,20 +12920,16 @@ async function authExperienceErrorResponse(options, context) {
|
|
|
13161
12920
|
return await invalidMagicLinkResponse(options, undefined);
|
|
13162
12921
|
}
|
|
13163
12922
|
function authExperienceSignInUrl(context) {
|
|
13164
|
-
const params = new URLSearchParams({
|
|
12923
|
+
const params = new URLSearchParams({ returnTo: context.returnTo });
|
|
13165
12924
|
return `/auth/sign-in?${params.toString()}`;
|
|
13166
12925
|
}
|
|
13167
|
-
function resolveAuthExperienceRedirectHint(options, request
|
|
13168
|
-
|
|
13169
|
-
return;
|
|
13170
|
-
}
|
|
13171
|
-
const context = resolveInvitationDeliveryContext(options, request, { destinationId: audience });
|
|
12926
|
+
function resolveAuthExperienceRedirectHint(options, request) {
|
|
12927
|
+
const context = resolveInvitationDeliveryContext(options, request, {});
|
|
13172
12928
|
return context instanceof Response ? undefined : context;
|
|
13173
12929
|
}
|
|
13174
12930
|
async function magicLinkConfirmResponse(options, input) {
|
|
13175
12931
|
if (input.authRedirect) {
|
|
13176
12932
|
const custom = await customAuthExperienceResponse(options.authExperience, {
|
|
13177
|
-
audience: input.authRedirect.audience,
|
|
13178
12933
|
state: { kind: "confirm", ...input.email ? { email: input.email } : {} },
|
|
13179
12934
|
signInUrl: authExperienceSignInUrl(input.authRedirect),
|
|
13180
12935
|
submission: {
|
|
@@ -13182,8 +12937,7 @@ async function magicLinkConfirmResponse(options, input) {
|
|
|
13182
12937
|
action: "/auth/callback",
|
|
13183
12938
|
fields: {
|
|
13184
12939
|
magicLinkId: input.magicLinkId,
|
|
13185
|
-
token: input.token
|
|
13186
|
-
audience: input.authRedirect.audience
|
|
12940
|
+
token: input.token
|
|
13187
12941
|
}
|
|
13188
12942
|
},
|
|
13189
12943
|
referrerPolicy: "same-origin",
|
|
@@ -13198,9 +12952,6 @@ async function magicLinkConfirmResponse(options, input) {
|
|
|
13198
12952
|
'<form method="post" action="/auth/callback" id="confirm">',
|
|
13199
12953
|
`<input type="hidden" name="magicLinkId" value="${escapeHtml(input.magicLinkId)}">`,
|
|
13200
12954
|
`<input type="hidden" name="token" value="${escapeHtml(input.token)}">`,
|
|
13201
|
-
...input.authRedirect ? [
|
|
13202
|
-
`<input type="hidden" name="audience" value="${escapeHtml(input.authRedirect.audience)}">`
|
|
13203
|
-
] : [],
|
|
13204
12955
|
'<button type="submit" id="confirm-button">Continue</button>',
|
|
13205
12956
|
"</form>",
|
|
13206
12957
|
"<script>",
|
|
@@ -14407,7 +14158,6 @@ var SubscribeSchema2 = z34.object({
|
|
|
14407
14158
|
types: z34.array(z34.enum(EVENT_TYPES)).optional(),
|
|
14408
14159
|
objectTypeId: z34.string().optional(),
|
|
14409
14160
|
primaryId: z34.string().optional(),
|
|
14410
|
-
actionId: z34.string().optional(),
|
|
14411
14161
|
runId: z34.string().optional(),
|
|
14412
14162
|
afterCursor: z34.string().optional(),
|
|
14413
14163
|
limit: z34.number().int().positive().max(500).optional()
|
|
@@ -14544,8 +14294,8 @@ function registerEventStreamRoutes(app, server) {
|
|
|
14544
14294
|
});
|
|
14545
14295
|
}
|
|
14546
14296
|
function eventMatchesScope(event, filter) {
|
|
14547
|
-
const { objectTypeId, primaryId,
|
|
14548
|
-
if (objectTypeId === undefined && primaryId === undefined &&
|
|
14297
|
+
const { objectTypeId, primaryId, runId } = filter;
|
|
14298
|
+
if (objectTypeId === undefined && primaryId === undefined && runId === undefined) {
|
|
14549
14299
|
return true;
|
|
14550
14300
|
}
|
|
14551
14301
|
const scope = scopeKeysForEvent(event);
|
|
@@ -14555,9 +14305,6 @@ function eventMatchesScope(event, filter) {
|
|
|
14555
14305
|
if (primaryId !== undefined && scope.primaryId !== primaryId) {
|
|
14556
14306
|
return false;
|
|
14557
14307
|
}
|
|
14558
|
-
if (actionId !== undefined && scope.actionId !== actionId) {
|
|
14559
|
-
return false;
|
|
14560
|
-
}
|
|
14561
14308
|
if (runId !== undefined && scope.runId !== runId) {
|
|
14562
14309
|
return false;
|
|
14563
14310
|
}
|
|
@@ -14720,6 +14467,7 @@ function registerWebSocketRoutes(app, server) {
|
|
|
14720
14467
|
}
|
|
14721
14468
|
|
|
14722
14469
|
// src/server.ts
|
|
14470
|
+
var MAX_WEBSOCKET_MESSAGE_BYTES = 64 * 1024;
|
|
14723
14471
|
function createSixbServer(options) {
|
|
14724
14472
|
return new SixbServer(options);
|
|
14725
14473
|
}
|
|
@@ -14768,9 +14516,6 @@ class SixbServer {
|
|
|
14768
14516
|
resolveAuthRequestOrigin(request) {
|
|
14769
14517
|
return resolveApiBrowserPublicOrigin(this.apiBrowserPolicy, request);
|
|
14770
14518
|
}
|
|
14771
|
-
getInvitationDestinationOptions(_request) {
|
|
14772
|
-
return getApiBrowserInvitationDestinationOptions(this.apiBrowserPolicy);
|
|
14773
|
-
}
|
|
14774
14519
|
resolveInvitationRedirectContext(request, input) {
|
|
14775
14520
|
return resolveApiBrowserInvitationRedirectContext(this.apiBrowserPolicy, request, input);
|
|
14776
14521
|
}
|
|
@@ -14863,6 +14608,12 @@ function createSixbApi(server) {
|
|
|
14863
14608
|
}
|
|
14864
14609
|
return shared.kind === "deny" ? shared.response : undefined;
|
|
14865
14610
|
});
|
|
14611
|
+
app.onError(({ error, set }) => {
|
|
14612
|
+
if (error instanceof ParseError && error.cause instanceof RequestBodyTooLargeError) {
|
|
14613
|
+
set.status = 413;
|
|
14614
|
+
return { error: error.cause.message };
|
|
14615
|
+
}
|
|
14616
|
+
});
|
|
14866
14617
|
app.derive(async ({ request }) => {
|
|
14867
14618
|
const shared = preparedSharedAccess.get(request) ?? await sharedAccess.resolveRequest(request);
|
|
14868
14619
|
preparedSharedAccess.delete(request);
|
|
@@ -14992,9 +14743,7 @@ function createSixbApi(server) {
|
|
|
14992
14743
|
}));
|
|
14993
14744
|
const authExperience = server.getAuthExperience();
|
|
14994
14745
|
registerAuthRoutes(app, host, {
|
|
14995
|
-
resolveAuthContext: (request) => server.resolveAuthContext(request),
|
|
14996
14746
|
resolveAuthRedirectContext: (request, input) => server.resolveAuthRedirectContext(request, input),
|
|
14997
|
-
getInvitationDestinationOptions: (request) => server.getInvitationDestinationOptions(request),
|
|
14998
14747
|
resolveAuthRequestOrigin: (request) => server.resolveAuthRequestOrigin(request),
|
|
14999
14748
|
authExperience: authExperience && { ...authExperience, locale: host.locale },
|
|
15000
14749
|
resolveInvitationRedirectContext: (request, input) => server.resolveInvitationRedirectContext(request, input)
|
|
@@ -15002,13 +14751,7 @@ function createSixbApi(server) {
|
|
|
15002
14751
|
registerHttpRoutes(app, host, {
|
|
15003
14752
|
sharedAccess,
|
|
15004
14753
|
connectorConnections: {
|
|
15005
|
-
resolveReturnTo: (request, returnTo) => {
|
|
15006
|
-
const authContext = server.resolveAuthContext(request);
|
|
15007
|
-
return server.resolveAuthRedirectContext(request, {
|
|
15008
|
-
audience: authContext.audience,
|
|
15009
|
-
returnTo
|
|
15010
|
-
}).returnTo;
|
|
15011
|
-
},
|
|
14754
|
+
resolveReturnTo: (request, returnTo) => server.resolveAuthRedirectContext(request, { returnTo }).returnTo,
|
|
15012
14755
|
resolveCallbackUrl: (request) => new URL("/auth/connectors/callback", server.resolveAuthRequestOrigin(request)).toString()
|
|
15013
14756
|
}
|
|
15014
14757
|
});
|
|
@@ -15068,8 +14811,10 @@ function startApiServer(app, options) {
|
|
|
15068
14811
|
const bunServer = Bun.serve({
|
|
15069
14812
|
port: options.port,
|
|
15070
14813
|
hostname: options.host,
|
|
15071
|
-
|
|
15072
|
-
|
|
14814
|
+
maxRequestBodySize: DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES,
|
|
14815
|
+
fetch: (incoming, server) => {
|
|
14816
|
+
const socketAddress = server.requestIP(incoming)?.address;
|
|
14817
|
+
const request = limitRequestBody(incoming);
|
|
15073
14818
|
if (socketAddress) {
|
|
15074
14819
|
const forwardedFor = request.headers.get("x-forwarded-for");
|
|
15075
14820
|
setRequestClientAddress(request, options.resolveClientAddress(socketAddress, forwardedFor));
|
|
@@ -15085,7 +14830,8 @@ function getElysiaWsHandler(app) {
|
|
|
15085
14830
|
const cfg = app.config;
|
|
15086
14831
|
return {
|
|
15087
14832
|
...elysiaWebSocket,
|
|
15088
|
-
...cfg?.websocket ?? {}
|
|
14833
|
+
...cfg?.websocket ?? {},
|
|
14834
|
+
maxPayloadLength: MAX_WEBSOCKET_MESSAGE_BYTES
|
|
15089
14835
|
};
|
|
15090
14836
|
}
|
|
15091
14837
|
function attachBunServer(app, bunServer) {
|
|
@@ -15096,4 +14842,4 @@ export {
|
|
|
15096
14842
|
createSixbServer
|
|
15097
14843
|
};
|
|
15098
14844
|
|
|
15099
|
-
//# debugId=
|
|
14845
|
+
//# debugId=891AB76315522D8A64756E2164756E21
|