@sixb/server 0.0.1
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/LICENSE +21 -0
- package/README.md +123 -0
- package/dist/auth/access-token-boundary.d.ts +23 -0
- package/dist/auth/access-token-boundary.d.ts.map +1 -0
- package/dist/auth/application-access.d.ts +4 -0
- package/dist/auth/application-access.d.ts.map +1 -0
- package/dist/auth/browser-origin.d.ts +62 -0
- package/dist/auth/browser-origin.d.ts.map +1 -0
- package/dist/auth/csrf.d.ts +2 -0
- package/dist/auth/csrf.d.ts.map +1 -0
- package/dist/auth/guard.d.ts +35 -0
- package/dist/auth/guard.d.ts.map +1 -0
- package/dist/auth/public-routes.d.ts +8 -0
- package/dist/auth/public-routes.d.ts.map +1 -0
- package/dist/auth/responses.d.ts +11 -0
- package/dist/auth/responses.d.ts.map +1 -0
- package/dist/auth/return-to.d.ts +3 -0
- package/dist/auth/return-to.d.ts.map +1 -0
- package/dist/auth/scope.d.ts +43 -0
- package/dist/auth/scope.d.ts.map +1 -0
- package/dist/auth/session-activity.d.ts +4 -0
- package/dist/auth/session-activity.d.ts.map +1 -0
- package/dist/auth/session-cookies.d.ts +12 -0
- package/dist/auth/session-cookies.d.ts.map +1 -0
- package/dist/files/content.d.ts +141 -0
- package/dist/files/content.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11522 -0
- package/dist/index.js.map +78 -0
- package/dist/openapi/security.d.ts +26 -0
- package/dist/openapi/security.d.ts.map +1 -0
- package/dist/openapi/tags.d.ts +151 -0
- package/dist/openapi/tags.d.ts.map +1 -0
- package/dist/registerRoutes.d.ts +31 -0
- package/dist/registerRoutes.d.ts.map +1 -0
- package/dist/routes/action-runs.d.ts +244 -0
- package/dist/routes/action-runs.d.ts.map +1 -0
- package/dist/routes/actions.d.ts +183 -0
- package/dist/routes/actions.d.ts.map +1 -0
- package/dist/routes/agent-api-gateway.d.ts +4 -0
- package/dist/routes/agent-api-gateway.d.ts.map +1 -0
- package/dist/routes/agents.d.ts +1061 -0
- package/dist/routes/agents.d.ts.map +1 -0
- package/dist/routes/auth.d.ts +1366 -0
- package/dist/routes/auth.d.ts.map +1 -0
- package/dist/routes/connectors.d.ts +108 -0
- package/dist/routes/connectors.d.ts.map +1 -0
- package/dist/routes/datasets.d.ts +339 -0
- package/dist/routes/datasets.d.ts.map +1 -0
- package/dist/routes/events.d.ts +116 -0
- package/dist/routes/events.d.ts.map +1 -0
- package/dist/routes/files.d.ts +340 -0
- package/dist/routes/files.d.ts.map +1 -0
- package/dist/routes/links.d.ts +175 -0
- package/dist/routes/links.d.ts.map +1 -0
- package/dist/routes/logs.d.ts +88 -0
- package/dist/routes/logs.d.ts.map +1 -0
- package/dist/routes/objects.d.ts +450 -0
- package/dist/routes/objects.d.ts.map +1 -0
- package/dist/routes/ontology.d.ts +240 -0
- package/dist/routes/ontology.d.ts.map +1 -0
- package/dist/routes/pipelines.d.ts +399 -0
- package/dist/routes/pipelines.d.ts.map +1 -0
- package/dist/routes/project.d.ts +56 -0
- package/dist/routes/project.d.ts.map +1 -0
- package/dist/routes/projections.d.ts +916 -0
- package/dist/routes/projections.d.ts.map +1 -0
- package/dist/routes/rules.d.ts +165 -0
- package/dist/routes/rules.d.ts.map +1 -0
- package/dist/routes/status.d.ts +81 -0
- package/dist/routes/status.d.ts.map +1 -0
- package/dist/routes/syncs.d.ts +294 -0
- package/dist/routes/syncs.d.ts.map +1 -0
- package/dist/routes/telemetry.d.ts +241 -0
- package/dist/routes/telemetry.d.ts.map +1 -0
- package/dist/routes/webhook-runs.d.ts +89 -0
- package/dist/routes/webhook-runs.d.ts.map +1 -0
- package/dist/routes/webhooks.d.ts +60 -0
- package/dist/routes/webhooks.d.ts.map +1 -0
- package/dist/routes/workflows.d.ts +973 -0
- package/dist/routes/workflows.d.ts.map +1 -0
- package/dist/routes/ws/agents.d.ts +99 -0
- package/dist/routes/ws/agents.d.ts.map +1 -0
- package/dist/routes/ws/events.d.ts +89 -0
- package/dist/routes/ws/events.d.ts.map +1 -0
- package/dist/routes/ws/index.d.ts +31 -0
- package/dist/routes/ws/index.d.ts.map +1 -0
- package/dist/routes/ws/log-subscription-hub.d.ts +47 -0
- package/dist/routes/ws/log-subscription-hub.d.ts.map +1 -0
- package/dist/routes/ws/logs.d.ts +110 -0
- package/dist/routes/ws/logs.d.ts.map +1 -0
- package/dist/schemas/actions.d.ts +644 -0
- package/dist/schemas/actions.d.ts.map +1 -0
- package/dist/schemas/agents.d.ts +3157 -0
- package/dist/schemas/agents.d.ts.map +1 -0
- package/dist/schemas/auth.d.ts +2023 -0
- package/dist/schemas/auth.d.ts.map +1 -0
- package/dist/schemas/common.d.ts +30 -0
- package/dist/schemas/common.d.ts.map +1 -0
- package/dist/schemas/connectors.d.ts +82 -0
- package/dist/schemas/connectors.d.ts.map +1 -0
- package/dist/schemas/datasets.d.ts +744 -0
- package/dist/schemas/datasets.d.ts.map +1 -0
- package/dist/schemas/event-payloads.d.ts +477 -0
- package/dist/schemas/event-payloads.d.ts.map +1 -0
- package/dist/schemas/events.d.ts +665 -0
- package/dist/schemas/events.d.ts.map +1 -0
- package/dist/schemas/files.d.ts +241 -0
- package/dist/schemas/files.d.ts.map +1 -0
- package/dist/schemas/links.d.ts +90 -0
- package/dist/schemas/links.d.ts.map +1 -0
- package/dist/schemas/logs.d.ts +231 -0
- package/dist/schemas/logs.d.ts.map +1 -0
- package/dist/schemas/objects.d.ts +288 -0
- package/dist/schemas/objects.d.ts.map +1 -0
- package/dist/schemas/ontology.d.ts +778 -0
- package/dist/schemas/ontology.d.ts.map +1 -0
- package/dist/schemas/pipelines.d.ts +1373 -0
- package/dist/schemas/pipelines.d.ts.map +1 -0
- package/dist/schemas/project.d.ts +9 -0
- package/dist/schemas/project.d.ts.map +1 -0
- package/dist/schemas/projections.d.ts +6992 -0
- package/dist/schemas/projections.d.ts.map +1 -0
- package/dist/schemas/rules.d.ts +204 -0
- package/dist/schemas/rules.d.ts.map +1 -0
- package/dist/schemas/status.d.ts +189 -0
- package/dist/schemas/status.d.ts.map +1 -0
- package/dist/schemas/syncs.d.ts +538 -0
- package/dist/schemas/syncs.d.ts.map +1 -0
- package/dist/schemas/telemetry.d.ts +265 -0
- package/dist/schemas/telemetry.d.ts.map +1 -0
- package/dist/schemas/webhook-runs.d.ts +169 -0
- package/dist/schemas/webhook-runs.d.ts.map +1 -0
- package/dist/schemas/workflows.d.ts +1720 -0
- package/dist/schemas/workflows.d.ts.map +1 -0
- package/dist/server.d.ts +64 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/tsconfig.json +5 -0
- package/dist/utils/http.d.ts +23 -0
- package/dist/utils/http.d.ts.map +1 -0
- package/dist/utils/request-body.d.ts +15 -0
- package/dist/utils/request-body.d.ts.map +1 -0
- package/dist/utils/ws.d.ts +10 -0
- package/dist/utils/ws.d.ts.map +1 -0
- package/package.json +68 -0
- package/src/auth/access-token-boundary.ts +68 -0
- package/src/auth/application-access.ts +16 -0
- package/src/auth/browser-origin.ts +367 -0
- package/src/auth/csrf.ts +1 -0
- package/src/auth/guard.ts +169 -0
- package/src/auth/public-routes.ts +87 -0
- package/src/auth/responses.ts +54 -0
- package/src/auth/return-to.ts +21 -0
- package/src/auth/scope.ts +64 -0
- package/src/auth/session-activity.ts +19 -0
- package/src/auth/session-cookies.ts +43 -0
- package/src/files/content.ts +419 -0
- package/src/index.ts +2 -0
- package/src/openapi/security.ts +37 -0
- package/src/openapi/tags.ts +151 -0
- package/src/registerRoutes.ts +49 -0
- package/src/routes/action-runs.ts +238 -0
- package/src/routes/actions.ts +126 -0
- package/src/routes/agent-api-gateway.ts +260 -0
- package/src/routes/agents.ts +943 -0
- package/src/routes/auth.ts +2233 -0
- package/src/routes/connectors.ts +69 -0
- package/src/routes/datasets.ts +402 -0
- package/src/routes/events.ts +55 -0
- package/src/routes/files.ts +675 -0
- package/src/routes/links.ts +143 -0
- package/src/routes/logs.ts +65 -0
- package/src/routes/objects.ts +838 -0
- package/src/routes/ontology.ts +138 -0
- package/src/routes/pipelines.ts +332 -0
- package/src/routes/project.ts +16 -0
- package/src/routes/projections.ts +251 -0
- package/src/routes/rules.ts +124 -0
- package/src/routes/status.ts +53 -0
- package/src/routes/syncs.ts +243 -0
- package/src/routes/telemetry.ts +207 -0
- package/src/routes/webhook-runs.ts +81 -0
- package/src/routes/webhooks.ts +508 -0
- package/src/routes/workflows.ts +1333 -0
- package/src/routes/ws/agents.ts +301 -0
- package/src/routes/ws/events.ts +278 -0
- package/src/routes/ws/index.ts +12 -0
- package/src/routes/ws/log-subscription-hub.ts +375 -0
- package/src/routes/ws/logs.ts +117 -0
- package/src/schemas/actions.ts +123 -0
- package/src/schemas/agents.ts +293 -0
- package/src/schemas/auth.ts +317 -0
- package/src/schemas/common.ts +60 -0
- package/src/schemas/connectors.ts +21 -0
- package/src/schemas/datasets.ts +107 -0
- package/src/schemas/event-payloads.ts +79 -0
- package/src/schemas/events.ts +117 -0
- package/src/schemas/files.ts +82 -0
- package/src/schemas/links.ts +38 -0
- package/src/schemas/logs.ts +76 -0
- package/src/schemas/objects.ts +759 -0
- package/src/schemas/ontology.ts +77 -0
- package/src/schemas/pipelines.ts +150 -0
- package/src/schemas/project.ts +5 -0
- package/src/schemas/projections.ts +144 -0
- package/src/schemas/rules.ts +98 -0
- package/src/schemas/status.ts +51 -0
- package/src/schemas/syncs.ts +83 -0
- package/src/schemas/telemetry.ts +59 -0
- package/src/schemas/webhook-runs.ts +40 -0
- package/src/schemas/workflows.ts +229 -0
- package/src/server.ts +383 -0
- package/src/utils/http.ts +108 -0
- package/src/utils/request-body.ts +62 -0
- package/src/utils/ws.ts +59 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../../src/schemas/workflows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,oBAAoB;;;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;EAIjD,CAAA;AAEF,eAAO,MAAM,wCAAwC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGnD,CAAA;AAEF,eAAO,MAAM,wCAAwC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEnD,CAAA;AAEF,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;EAK3C,CAAA"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { OntologySource, Sixb } from "@sixb/core";
|
|
2
|
+
import { Elysia } from "elysia";
|
|
3
|
+
import { type AuthInvitationDestinationOptions, type AuthInvitationRedirectContext, type AuthInvitationRedirectInput, type RequestAuthContext, type ResolveAuthRedirectContext, type ResolvedSixbApiBrowserPolicy, type SixbApiBrowserPolicy } from "./auth/browser-origin";
|
|
4
|
+
export interface SixbServerOptions {
|
|
5
|
+
sixb: Sixb<readonly OntologySource[]>;
|
|
6
|
+
port?: number;
|
|
7
|
+
host?: string;
|
|
8
|
+
quiet?: boolean;
|
|
9
|
+
browser: SixbApiBrowserPolicy;
|
|
10
|
+
}
|
|
11
|
+
export declare function createSixbServer(options: SixbServerOptions): SixbServer;
|
|
12
|
+
export declare class SixbServer {
|
|
13
|
+
private readonly sixb;
|
|
14
|
+
private readonly port;
|
|
15
|
+
private readonly host;
|
|
16
|
+
private readonly quiet;
|
|
17
|
+
private readonly apiBrowserPolicy;
|
|
18
|
+
private readonly authContextResolver;
|
|
19
|
+
private readonly authRedirectContextResolver;
|
|
20
|
+
private app;
|
|
21
|
+
private bunServer;
|
|
22
|
+
private maintenance;
|
|
23
|
+
constructor(options: SixbServerOptions);
|
|
24
|
+
getSixb(): Sixb<readonly OntologySource[]>;
|
|
25
|
+
getPort(): number;
|
|
26
|
+
resolveAuthContext(request: Request): RequestAuthContext;
|
|
27
|
+
resolveAuthRedirectContext(request: Parameters<ResolveAuthRedirectContext>[0], input: Parameters<ResolveAuthRedirectContext>[1]): ReturnType<ResolveAuthRedirectContext>;
|
|
28
|
+
resolveAuthRequestOrigin(request: Request): string;
|
|
29
|
+
getInvitationDestinationOptions(_request: Request): AuthInvitationDestinationOptions;
|
|
30
|
+
resolveInvitationRedirectContext(request: Request, input: AuthInvitationRedirectInput): AuthInvitationRedirectContext;
|
|
31
|
+
getApiBrowserPolicy(): ResolvedSixbApiBrowserPolicy;
|
|
32
|
+
start(): Promise<void>;
|
|
33
|
+
stop(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
export declare function createSixbApi(server: SixbServer): Elysia<"", {
|
|
36
|
+
decorator: {};
|
|
37
|
+
store: {};
|
|
38
|
+
derive: {};
|
|
39
|
+
resolve: {};
|
|
40
|
+
}, {
|
|
41
|
+
typebox: {};
|
|
42
|
+
error: {};
|
|
43
|
+
}, {
|
|
44
|
+
schema: {};
|
|
45
|
+
standaloneSchema: {};
|
|
46
|
+
macro: {};
|
|
47
|
+
macroFn: {};
|
|
48
|
+
parser: {};
|
|
49
|
+
response: {};
|
|
50
|
+
}, {}, {
|
|
51
|
+
derive: {};
|
|
52
|
+
resolve: {};
|
|
53
|
+
schema: {};
|
|
54
|
+
standaloneSchema: {};
|
|
55
|
+
response: {};
|
|
56
|
+
}, {
|
|
57
|
+
derive: {};
|
|
58
|
+
resolve: {};
|
|
59
|
+
schema: {};
|
|
60
|
+
standaloneSchema: {};
|
|
61
|
+
response: {};
|
|
62
|
+
}>;
|
|
63
|
+
export type SixbApp = ReturnType<typeof createSixbApi>;
|
|
64
|
+
//# sourceMappingURL=server.d.ts.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OAAO,IAAI,MAAM;IAIjB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,kBAAkB;IAIxD,0BAA0B,CACxB,OAAO,EAAE,UAAU,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAC,EAClD,KAAK,EAAE,UAAU,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAC,GAC/C,UAAU,CAAC,0BAA0B,CAAC;IAIzC,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM;IAIlD,+BAA+B,CAAC,QAAQ,EAAE,OAAO,GAAG,gCAAgC;IAIpF,gCAAgC,CAC9B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,2BAA2B,GACjC,6BAA6B;IAIhC,mBAAmB,IAAI,4BAA4B;IAI7C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA8BtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAe5B;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0H/C;AAiED,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Written by scripts/build-package.ts, and published on purpose.
|
|
2
|
+
// Bun applies the nearest tsconfig paths map to every import it resolves, node_modules
|
|
3
|
+
// included. An empty map here keeps a consumer's aliases from sending a module in this
|
|
4
|
+
// directory back into a second copy of its own source.
|
|
5
|
+
{ "compilerOptions": { "paths": {} } }
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare function toIsoString(value: Date): string;
|
|
2
|
+
export declare function parseDate(value: string | undefined): Date | undefined;
|
|
3
|
+
export declare function parseOptionalInt(value: string | undefined): number | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* A storage role the runtime was not configured with.
|
|
6
|
+
*
|
|
7
|
+
* 501 and not 400: the request was well-formed and the caller can do nothing
|
|
8
|
+
* about it. It is not 404 either — that would claim the resource is absent when
|
|
9
|
+
* what is absent is the store that would have recorded it. Callers that treat
|
|
10
|
+
* "no rows" and "not recorded" the same way silently report an empty history as
|
|
11
|
+
* a healthy one.
|
|
12
|
+
*/
|
|
13
|
+
export declare function unconfiguredStorageResponse(set: {
|
|
14
|
+
status?: number | string;
|
|
15
|
+
}, role: string): {
|
|
16
|
+
error: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function handleRouteError(error: unknown, set: {
|
|
19
|
+
status?: number | string;
|
|
20
|
+
}): {
|
|
21
|
+
error: string;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/utils/http.ts"],"names":[],"mappings":"AAIA,wBAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,CAE/C;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,CAWrE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAW9E;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CACzC,GAAG,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACjC,IAAI,EAAE,MAAM,GACX;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAGnB;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAChC;IACD,KAAK,EAAE,MAAM,CAAA;CACd,CAmBA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads a request body fully into memory while enforcing a hard byte ceiling.
|
|
3
|
+
*
|
|
4
|
+
* The cap is applied DURING streaming (not after buffering), so an oversized or
|
|
5
|
+
* chunked/unknown-length body is rejected before it is fully read — the
|
|
6
|
+
* `content-length` header, when present, only provides an early fast-path. This
|
|
7
|
+
* is the single bounded-reader used by request handlers that need the raw bytes.
|
|
8
|
+
*/
|
|
9
|
+
export declare class RequestBodyTooLargeError extends Error {
|
|
10
|
+
readonly limitBytes: number;
|
|
11
|
+
readonly name = "RequestBodyTooLargeError";
|
|
12
|
+
constructor(limitBytes: number, message?: string);
|
|
13
|
+
}
|
|
14
|
+
export declare function readRequestBodyWithLimit(request: Request, limitBytes: number, tooLargeMessage?: string): Promise<Uint8Array>;
|
|
15
|
+
//# sourceMappingURL=request-body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-body.d.ts","sourceRoot":"","sources":["../../src/utils/request-body.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IAI/C,QAAQ,CAAC,UAAU,EAAE,MAAM;IAH7B,QAAQ,CAAC,IAAI,8BAA6B;gBAG/B,UAAU,EAAE,MAAM,EAC3B,OAAO,SAAuD;CAIjE;AAED,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,MAAM,EAClB,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,UAAU,CAAC,CAsCrB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuthorizationContext } from "@sixb/core";
|
|
2
|
+
export declare function safeSend(target: {
|
|
3
|
+
send: (message: string) => void;
|
|
4
|
+
}, payload: unknown): void;
|
|
5
|
+
/** Stable per-connection key for a subscription-state WeakMap (the raw socket when Elysia wraps it). */
|
|
6
|
+
export declare function wsStateKey(ws: object): object;
|
|
7
|
+
/** The authorization context attached to a websocket connection; null when unauthenticated/disabled. */
|
|
8
|
+
export declare function wsAuthz(ws: object): AuthorizationContext | null;
|
|
9
|
+
export declare function decodeWsMessage(message: unknown): Promise<unknown>;
|
|
10
|
+
//# sourceMappingURL=ws.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src/utils/ws.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEtD,wBAAgB,QAAQ,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAM5F;AAED,wGAAwG;AACxG,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAG7C;AAED,wGAAwG;AACxG,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,oBAAoB,GAAG,IAAI,CAG/D;AAUD,wBAAsB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CA4BxE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sixb/server",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "HTTP and WebSocket API server for Sixb",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sixb",
|
|
7
|
+
"bun",
|
|
8
|
+
"api",
|
|
9
|
+
"openapi",
|
|
10
|
+
"elysia"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://sixb.ai",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/sixb-ai/sixb/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/sixb-ai/sixb.git",
|
|
19
|
+
"directory": "packages/server"
|
|
20
|
+
},
|
|
21
|
+
"author": "Sixb contributors",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "bun ../../scripts/build-package.ts",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"test": "bun test",
|
|
29
|
+
"generate:openapi": "bun run scripts/generate-openapi.ts",
|
|
30
|
+
"prepack": "bun run build"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@elysiajs/cors": "^1.2.0",
|
|
34
|
+
"@elysiajs/openapi": "^1.4.0",
|
|
35
|
+
"@sixb/core": "0.0.1",
|
|
36
|
+
"elysia": "^1.2.0",
|
|
37
|
+
"zod": "^3.24.0",
|
|
38
|
+
"zod-to-json-schema": "^3.24.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@sixb/auth-magic-link": "0.0.1",
|
|
42
|
+
"@sixb/auth-oidc": "0.0.1",
|
|
43
|
+
"@sixb/sqlite": "0.0.1",
|
|
44
|
+
"@types/bun": "latest",
|
|
45
|
+
"typescript": "^5.7.0"
|
|
46
|
+
},
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"engines": {
|
|
49
|
+
"bun": ">=1.3.0"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"dist",
|
|
56
|
+
"src",
|
|
57
|
+
"README.md",
|
|
58
|
+
"LICENSE"
|
|
59
|
+
],
|
|
60
|
+
"exports": {
|
|
61
|
+
".": {
|
|
62
|
+
"types": "./dist/index.d.ts",
|
|
63
|
+
"bun": "./src/index.ts",
|
|
64
|
+
"import": "./dist/index.js",
|
|
65
|
+
"default": "./dist/index.js"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isCsrfExemptMethod } from "@sixb/core/internal/auth"
|
|
2
|
+
import { matchesPathPattern, normalizeRoutePath, SIXB_API_ROUTES } from "@sixb/core/internal/http"
|
|
3
|
+
import {
|
|
4
|
+
SIXB_BEARER_SECURITY_REQUIREMENT,
|
|
5
|
+
SIXB_CSRF_OR_BEARER_SECURITY_REQUIREMENT,
|
|
6
|
+
} from "../openapi/security"
|
|
7
|
+
import type { RouteAccess } from "./public-routes"
|
|
8
|
+
|
|
9
|
+
export type AuthCredentialSource = "session" | "accessToken"
|
|
10
|
+
|
|
11
|
+
export interface AccessTokenRoute {
|
|
12
|
+
readonly operationId: string
|
|
13
|
+
readonly method: string
|
|
14
|
+
readonly path: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// The routes that accept bearer access tokens: the `accessToken` projection of the canonical
|
|
18
|
+
// SIXB_API_ROUTES table in @sixb/core. `isAccessTokenRoute` enforces this list at request time and
|
|
19
|
+
// `bearerSecurityRequirement` derives each route's OpenAPI security entry from it, so the enforced
|
|
20
|
+
// boundary and the documented contract cannot drift apart. The agent gateway allow-list is the
|
|
21
|
+
// `agentApi` projection of the same table, which the table's load-time invariant keeps a strict
|
|
22
|
+
// subset of this one.
|
|
23
|
+
//
|
|
24
|
+
// Bearer tokens should only reach routes that already enforce scoped authz. Raw storage, admin,
|
|
25
|
+
// browser, webhook, and websocket routes stay session-only until each has an intentional scoped
|
|
26
|
+
// API surface — i.e. they are simply absent from SIXB_API_ROUTES.
|
|
27
|
+
export const ACCESS_TOKEN_ROUTES: readonly AccessTokenRoute[] = SIXB_API_ROUTES.filter(
|
|
28
|
+
(route) => route.accessToken
|
|
29
|
+
).map((route) => ({ operationId: route.operationId, method: route.method, path: route.path }))
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* OpenAPI security requirement for a bearer-capable route, derived from the
|
|
33
|
+
* canonical table. Reads (CSRF-exempt methods) accept a bearer token only;
|
|
34
|
+
* mutations accept either a CSRF token (cookie sessions) or a bearer token.
|
|
35
|
+
* Throws when the operation is not a registered bearer route, so a route can
|
|
36
|
+
* never claim bearer access without being added to the boundary.
|
|
37
|
+
*/
|
|
38
|
+
export function bearerSecurityRequirement(operationId: string) {
|
|
39
|
+
const route = ACCESS_TOKEN_ROUTES.find((candidate) => candidate.operationId === operationId)
|
|
40
|
+
if (!route) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`[SixbServer] '${operationId}' is not a registered bearer route. Add it to ACCESS_TOKEN_ROUTES.`
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return isCsrfExemptMethod(route.method)
|
|
47
|
+
? SIXB_BEARER_SECURITY_REQUIREMENT
|
|
48
|
+
: SIXB_CSRF_OR_BEARER_SECURITY_REQUIREMENT
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isAccessTokenRoute(request: Request): boolean {
|
|
52
|
+
const url = new URL(request.url)
|
|
53
|
+
const method = request.method.toUpperCase()
|
|
54
|
+
const pathname = normalizeRoutePath(url.pathname)
|
|
55
|
+
|
|
56
|
+
return ACCESS_TOKEN_ROUTES.some(
|
|
57
|
+
(route) => route.method === method && matchesPathPattern(pathname, route.path)
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function shouldVerifyCsrfForAuthSource(
|
|
62
|
+
route: RouteAccess,
|
|
63
|
+
source: AuthCredentialSource
|
|
64
|
+
): boolean {
|
|
65
|
+
// CSRF protects ambient browser cookies. Bearer tokens are explicit request
|
|
66
|
+
// credentials, so they skip CSRF while still requiring authz checks.
|
|
67
|
+
return route.csrfProtected && source === "session"
|
|
68
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthSessionAudience,
|
|
3
|
+
canAccessApplication,
|
|
4
|
+
type OntologySource,
|
|
5
|
+
type Sixb,
|
|
6
|
+
} from "@sixb/core"
|
|
7
|
+
import type { AuthenticatedRequestAuthSession } from "@sixb/core/internal/auth"
|
|
8
|
+
|
|
9
|
+
export function sessionCanAccessApplication(
|
|
10
|
+
sixb: Sixb<readonly OntologySource[]>,
|
|
11
|
+
session: AuthenticatedRequestAuthSession,
|
|
12
|
+
audience: AuthSessionAudience
|
|
13
|
+
): boolean {
|
|
14
|
+
const authorization = sixb.auth.contextFromSession(session)
|
|
15
|
+
return canAccessApplication(authorization, sixb.security.listResolvedRoles(), audience)
|
|
16
|
+
}
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthSessionAudience,
|
|
3
|
+
applications,
|
|
4
|
+
DEFAULT_AUTH_SESSION_AUDIENCE,
|
|
5
|
+
isValidAuthSessionAudience,
|
|
6
|
+
resolveAuthSessionAudience,
|
|
7
|
+
} from "@sixb/core"
|
|
8
|
+
|
|
9
|
+
export interface SixbBrowserOrigin {
|
|
10
|
+
readonly origin: string
|
|
11
|
+
readonly audience: AuthSessionAudience
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface SixbApiBrowserPolicy {
|
|
15
|
+
readonly publicOrigin?: string
|
|
16
|
+
readonly allowedOrigins: readonly SixbBrowserOrigin[]
|
|
17
|
+
readonly apiOriginAudience?: AuthSessionAudience
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ResolvedSixbBrowserOrigin {
|
|
21
|
+
readonly origin: string
|
|
22
|
+
readonly audience: AuthSessionAudience
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ResolvedSixbApiBrowserPolicy {
|
|
26
|
+
readonly publicOrigin?: string
|
|
27
|
+
readonly apiOriginAudience: AuthSessionAudience
|
|
28
|
+
readonly allowedOrigins: readonly ResolvedSixbBrowserOrigin[]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface RequestAuthContext {
|
|
32
|
+
readonly audience: AuthSessionAudience
|
|
33
|
+
readonly browserOrigin?: string
|
|
34
|
+
readonly absoluteReturnTo?: boolean
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface AuthInvitationDestination {
|
|
38
|
+
readonly id: AuthSessionAudience
|
|
39
|
+
readonly label: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface AuthInvitationDestinationOptions {
|
|
43
|
+
readonly destinations: readonly AuthInvitationDestination[]
|
|
44
|
+
readonly defaultDestinationId?: AuthSessionAudience
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface AuthInvitationRedirectInput {
|
|
48
|
+
readonly destinationId?: AuthSessionAudience
|
|
49
|
+
readonly returnTo?: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type AuthInvitationRedirectContext = AuthRedirectContext
|
|
53
|
+
|
|
54
|
+
export type ResolveRequestAuthContext = (request: Request) => RequestAuthContext
|
|
55
|
+
|
|
56
|
+
export interface AuthRedirectInput {
|
|
57
|
+
readonly audience?: string | null
|
|
58
|
+
readonly returnTo?: string | null
|
|
59
|
+
readonly fallbackReturnToOrigin?: string
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface AuthRedirectContext {
|
|
63
|
+
readonly audience: AuthSessionAudience
|
|
64
|
+
readonly returnTo: string
|
|
65
|
+
readonly requestOrigin: string
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type ResolveAuthRedirectContext = (
|
|
69
|
+
request: Request,
|
|
70
|
+
input: AuthRedirectInput
|
|
71
|
+
) => AuthRedirectContext
|
|
72
|
+
|
|
73
|
+
export class BrowserOriginError extends Error {
|
|
74
|
+
readonly name = "BrowserOriginError"
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function resolveApiBrowserPolicy(
|
|
78
|
+
policy: SixbApiBrowserPolicy
|
|
79
|
+
): ResolvedSixbApiBrowserPolicy {
|
|
80
|
+
const apiOriginAudience = resolveAuthSessionAudience(
|
|
81
|
+
policy.apiOriginAudience ?? DEFAULT_AUTH_SESSION_AUDIENCE
|
|
82
|
+
)
|
|
83
|
+
const origins = new Map<string, ResolvedSixbBrowserOrigin>()
|
|
84
|
+
const audienceOrigins = new Map<AuthSessionAudience, string>()
|
|
85
|
+
|
|
86
|
+
for (const entry of policy.allowedOrigins) {
|
|
87
|
+
const origin = normalizeHttpOrigin(entry.origin, "browser origin")
|
|
88
|
+
const audience = resolveAuthSessionAudience(entry.audience)
|
|
89
|
+
const existingAudienceOrigin = audienceOrigins.get(audience)
|
|
90
|
+
if (existingAudienceOrigin && existingAudienceOrigin !== origin) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`[SixbServer] Auth audience '${audience}' is mapped to multiple browser origins.`
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
audienceOrigins.set(audience, origin)
|
|
96
|
+
|
|
97
|
+
const existing = origins.get(origin)
|
|
98
|
+
if (existing) {
|
|
99
|
+
if (existing.audience !== audience) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`[SixbServer] Browser origin '${origin}' is mapped to multiple auth audiences.`
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
continue
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
origins.set(origin, { origin, audience })
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (origins.size === 0) {
|
|
111
|
+
throw new Error("[SixbServer] API browser policy requires at least one allowed origin.")
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
publicOrigin: policy.publicOrigin
|
|
116
|
+
? normalizeHttpOrigin(policy.publicOrigin, "API public origin")
|
|
117
|
+
: undefined,
|
|
118
|
+
apiOriginAudience,
|
|
119
|
+
allowedOrigins: [...origins.values()],
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function createApiBrowserAuthContextResolver(
|
|
124
|
+
policy: ResolvedSixbApiBrowserPolicy
|
|
125
|
+
): ResolveRequestAuthContext {
|
|
126
|
+
return (request) => resolveApiBrowserAuthContext(policy, request)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function createApiBrowserAuthRedirectContextResolver(
|
|
130
|
+
policy: ResolvedSixbApiBrowserPolicy
|
|
131
|
+
): ResolveAuthRedirectContext {
|
|
132
|
+
return (request, input) => resolveApiBrowserAuthRedirectContext(policy, request, input)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function resolveApiBrowserAuthContext(
|
|
136
|
+
policy: ResolvedSixbApiBrowserPolicy,
|
|
137
|
+
request: Request
|
|
138
|
+
): RequestAuthContext {
|
|
139
|
+
const origin = normalizeRequestOrigin(request)
|
|
140
|
+
if (!origin) {
|
|
141
|
+
return { audience: policy.apiOriginAudience, absoluteReturnTo: true }
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const allowed = findAllowedBrowserOrigin(policy, origin)
|
|
145
|
+
if (allowed) {
|
|
146
|
+
return {
|
|
147
|
+
audience: allowed.audience,
|
|
148
|
+
browserOrigin: allowed.origin,
|
|
149
|
+
absoluteReturnTo: true,
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (isSameOriginApiRequest(policy, origin, request)) {
|
|
154
|
+
return { audience: policy.apiOriginAudience, browserOrigin: origin, absoluteReturnTo: true }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
throw new BrowserOriginError(`[SixbServer] Browser origin '${origin}' is not allowed.`)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function isAllowedApiBrowserOrigin(
|
|
161
|
+
policy: ResolvedSixbApiBrowserPolicy,
|
|
162
|
+
request: Request
|
|
163
|
+
): boolean {
|
|
164
|
+
const origin = normalizeRequestOrigin(request)
|
|
165
|
+
if (!origin) {
|
|
166
|
+
return false
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
findAllowedBrowserOrigin(policy, origin) !== null ||
|
|
171
|
+
isSameOriginApiRequest(policy, origin, request)
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function resolveApiBrowserAuthRedirectContext(
|
|
176
|
+
policy: ResolvedSixbApiBrowserPolicy,
|
|
177
|
+
request: Request,
|
|
178
|
+
input: AuthRedirectInput
|
|
179
|
+
): AuthRedirectContext {
|
|
180
|
+
const audience = resolveRequiredAuthAudience(input.audience)
|
|
181
|
+
const returnTo = resolveApiBrowserReturnTo(policy, request, input, audience)
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
audience,
|
|
185
|
+
returnTo,
|
|
186
|
+
requestOrigin: resolveApiBrowserPublicOrigin(policy, request),
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function getApiBrowserInvitationDestinationOptions(
|
|
191
|
+
policy: ResolvedSixbApiBrowserPolicy
|
|
192
|
+
): AuthInvitationDestinationOptions {
|
|
193
|
+
const destinations = policy.allowedOrigins.map((entry) => ({
|
|
194
|
+
id: entry.audience,
|
|
195
|
+
label: applications[entry.audience].label,
|
|
196
|
+
}))
|
|
197
|
+
const defaultDestinationId = destinations.some((destination) => destination.id === "app")
|
|
198
|
+
? applications.app.id
|
|
199
|
+
: destinations.some((destination) => destination.id === "atlas")
|
|
200
|
+
? applications.atlas.id
|
|
201
|
+
: undefined
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
destinations,
|
|
205
|
+
...(defaultDestinationId ? { defaultDestinationId } : {}),
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function resolveApiBrowserInvitationRedirectContext(
|
|
210
|
+
policy: ResolvedSixbApiBrowserPolicy,
|
|
211
|
+
request: Request,
|
|
212
|
+
input: AuthInvitationRedirectInput
|
|
213
|
+
): AuthInvitationRedirectContext {
|
|
214
|
+
const authContext = resolveApiBrowserAuthContext(policy, request)
|
|
215
|
+
if (!input.destinationId) {
|
|
216
|
+
return resolveApiBrowserAuthRedirectContext(policy, request, {
|
|
217
|
+
audience: authContext.audience,
|
|
218
|
+
fallbackReturnToOrigin: authContext.browserOrigin,
|
|
219
|
+
returnTo: input.returnTo,
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const destination = policy.allowedOrigins.find((entry) => entry.audience === input.destinationId)
|
|
224
|
+
if (!destination) {
|
|
225
|
+
throw new BrowserOriginError("[SixbServer] Invitation destination is not allowed.")
|
|
226
|
+
}
|
|
227
|
+
assertInvitationReturnToOrigin(input.returnTo, destination.origin)
|
|
228
|
+
|
|
229
|
+
return resolveApiBrowserAuthRedirectContext(policy, request, {
|
|
230
|
+
audience: destination.audience,
|
|
231
|
+
fallbackReturnToOrigin: destination.origin,
|
|
232
|
+
returnTo: input.returnTo,
|
|
233
|
+
})
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function resolveApiBrowserPublicOrigin(
|
|
237
|
+
policy: ResolvedSixbApiBrowserPolicy,
|
|
238
|
+
request: Request
|
|
239
|
+
): string {
|
|
240
|
+
return policy.publicOrigin ?? new URL(request.url).origin
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function findAllowedBrowserOrigin(
|
|
244
|
+
policy: ResolvedSixbApiBrowserPolicy,
|
|
245
|
+
origin: string
|
|
246
|
+
): ResolvedSixbBrowserOrigin | null {
|
|
247
|
+
return policy.allowedOrigins.find((entry) => entry.origin === origin) ?? null
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function isSameOriginApiRequest(
|
|
251
|
+
policy: ResolvedSixbApiBrowserPolicy,
|
|
252
|
+
origin: string,
|
|
253
|
+
request: Request
|
|
254
|
+
): boolean {
|
|
255
|
+
const apiOrigin = resolveApiBrowserPublicOrigin(policy, request)
|
|
256
|
+
return origin === apiOrigin
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function assertInvitationReturnToOrigin(
|
|
260
|
+
returnTo: string | undefined,
|
|
261
|
+
destinationOrigin: string
|
|
262
|
+
): void {
|
|
263
|
+
if (!returnTo?.trim()) return
|
|
264
|
+
|
|
265
|
+
try {
|
|
266
|
+
if (new URL(returnTo).origin === destinationOrigin) return
|
|
267
|
+
} catch {
|
|
268
|
+
// Fall through to the same public validation error as an origin mismatch.
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
throw new BrowserOriginError("[SixbServer] Invitation return target is not allowed.")
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function resolveRequiredAuthAudience(value: string | null | undefined): AuthSessionAudience {
|
|
275
|
+
const audience = value?.trim()
|
|
276
|
+
if (!audience || !isValidAuthSessionAudience(audience)) {
|
|
277
|
+
throw new BrowserOriginError("[SixbServer] Auth audience is invalid or missing.")
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return audience
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function resolveApiBrowserReturnTo(
|
|
284
|
+
policy: ResolvedSixbApiBrowserPolicy,
|
|
285
|
+
request: Request,
|
|
286
|
+
input: AuthRedirectInput,
|
|
287
|
+
audience: AuthSessionAudience
|
|
288
|
+
): string {
|
|
289
|
+
const rawReturnTo = input.returnTo?.trim()
|
|
290
|
+
const value =
|
|
291
|
+
rawReturnTo ||
|
|
292
|
+
(input.fallbackReturnToOrigin
|
|
293
|
+
? new URL("/", normalizeHttpOrigin(input.fallbackReturnToOrigin, "fallback return origin"))
|
|
294
|
+
.href
|
|
295
|
+
: "")
|
|
296
|
+
|
|
297
|
+
if (!value) {
|
|
298
|
+
throw new BrowserOriginError("[SixbServer] Auth return target is required.")
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
let url: URL
|
|
302
|
+
try {
|
|
303
|
+
url = new URL(value)
|
|
304
|
+
} catch {
|
|
305
|
+
throw new BrowserOriginError("[SixbServer] Auth return target must be an absolute URL.")
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if ((url.protocol !== "http:" && url.protocol !== "https:") || url.username || url.password) {
|
|
309
|
+
throw new BrowserOriginError("[SixbServer] Auth return target is not allowed.")
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const returnAudience = resolveReturnToAudience(policy, request, url.origin)
|
|
313
|
+
if (returnAudience !== audience) {
|
|
314
|
+
throw new BrowserOriginError("[SixbServer] Auth return target is not allowed.")
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return url.toString()
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function resolveReturnToAudience(
|
|
321
|
+
policy: ResolvedSixbApiBrowserPolicy,
|
|
322
|
+
request: Request,
|
|
323
|
+
origin: string
|
|
324
|
+
): AuthSessionAudience | null {
|
|
325
|
+
const allowed = findAllowedBrowserOrigin(policy, origin)
|
|
326
|
+
if (allowed) {
|
|
327
|
+
return allowed.audience
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (origin === resolveApiBrowserPublicOrigin(policy, request)) {
|
|
331
|
+
return policy.apiOriginAudience
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return null
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function normalizeRequestOrigin(request: Request): string | null {
|
|
338
|
+
const origin = request.headers.get("origin")
|
|
339
|
+
if (!origin) {
|
|
340
|
+
return null
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
try {
|
|
344
|
+
return normalizeHttpOrigin(origin, "Origin header")
|
|
345
|
+
} catch {
|
|
346
|
+
throw new BrowserOriginError("[SixbServer] Origin header is not allowed.")
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function normalizeHttpOrigin(value: string, label: string): string {
|
|
351
|
+
let url: URL
|
|
352
|
+
try {
|
|
353
|
+
url = new URL(value)
|
|
354
|
+
} catch {
|
|
355
|
+
throw new Error(`[SixbServer] Invalid ${label}: '${value}'.`)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
359
|
+
throw new Error(`[SixbServer] ${label} must use http or https.`)
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (url.pathname !== "/" || url.search || url.hash) {
|
|
363
|
+
throw new Error(`[SixbServer] ${label} must be an origin, not a full URL.`)
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return url.origin
|
|
367
|
+
}
|
package/src/auth/csrf.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const CSRF_TOKEN_RESPONSE_HEADER_NAME = "x-sixb-csrf-token"
|