@sixb/server 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/auth/application-access.d.ts +2 -2
- package/dist/auth/application-access.d.ts.map +1 -1
- package/dist/auth/connector-callback-cookie.d.ts +12 -0
- package/dist/auth/connector-callback-cookie.d.ts.map +1 -0
- package/dist/auth/experience.d.ts +33 -0
- package/dist/auth/experience.d.ts.map +1 -0
- package/dist/auth/guard.d.ts +3 -3
- package/dist/auth/guard.d.ts.map +1 -1
- package/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/auth/scope.d.ts +13 -27
- package/dist/auth/scope.d.ts.map +1 -1
- package/dist/auth/session-cookies.d.ts +2 -2
- package/dist/auth/session-cookies.d.ts.map +1 -1
- package/dist/connectors/http.d.ts +16 -0
- package/dist/connectors/http.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3903 -2760
- package/dist/index.js.map +58 -50
- package/dist/openapi/tags.d.ts +15 -3
- package/dist/openapi/tags.d.ts.map +1 -1
- package/dist/registerRoutes.d.ts +6 -2
- package/dist/registerRoutes.d.ts.map +1 -1
- package/dist/routes/action-runs.d.ts +21 -31
- package/dist/routes/action-runs.d.ts.map +1 -1
- package/dist/routes/actions.d.ts +12 -11
- package/dist/routes/actions.d.ts.map +1 -1
- package/dist/routes/agent-api-gateway.d.ts +2 -2
- package/dist/routes/agent-api-gateway.d.ts.map +1 -1
- package/dist/routes/agents.d.ts +230 -159
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/ai-accounting.d.ts +31 -0
- package/dist/routes/ai-accounting.d.ts.map +1 -0
- package/dist/routes/auth.d.ts +149 -92
- package/dist/routes/auth.d.ts.map +1 -1
- package/dist/routes/connector-connection-runs.d.ts +794 -0
- package/dist/routes/connector-connection-runs.d.ts.map +1 -0
- package/dist/routes/connector-connections.d.ts +219 -0
- package/dist/routes/connector-connections.d.ts.map +1 -0
- package/dist/routes/connectors.d.ts +10 -4
- package/dist/routes/connectors.d.ts.map +1 -1
- package/dist/routes/datasets.d.ts +16 -12
- package/dist/routes/datasets.d.ts.map +1 -1
- package/dist/routes/events.d.ts +9 -9
- package/dist/routes/events.d.ts.map +1 -1
- package/dist/routes/files.d.ts +19 -18
- package/dist/routes/files.d.ts.map +1 -1
- package/dist/routes/links.d.ts +11 -11
- package/dist/routes/links.d.ts.map +1 -1
- package/dist/routes/logs.d.ts +5 -5
- package/dist/routes/logs.d.ts.map +1 -1
- package/dist/routes/objects.d.ts +37 -37
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/ontology.d.ts +50 -50
- package/dist/routes/ontology.d.ts.map +1 -1
- package/dist/routes/pipelines.d.ts +28 -38
- package/dist/routes/pipelines.d.ts.map +1 -1
- package/dist/routes/project.d.ts +2 -2
- package/dist/routes/project.d.ts.map +1 -1
- package/dist/routes/projections.d.ts +145 -85
- package/dist/routes/projections.d.ts.map +1 -1
- package/dist/routes/rules.d.ts +6 -6
- package/dist/routes/rules.d.ts.map +1 -1
- package/dist/routes/status.d.ts +2 -2
- package/dist/routes/status.d.ts.map +1 -1
- package/dist/routes/syncs.d.ts +23 -28
- package/dist/routes/syncs.d.ts.map +1 -1
- package/dist/routes/telemetry.d.ts +9 -9
- package/dist/routes/telemetry.d.ts.map +1 -1
- package/dist/routes/webhook-runs.d.ts +9 -9
- package/dist/routes/webhook-runs.d.ts.map +1 -1
- package/dist/routes/webhooks.d.ts +2 -2
- package/dist/routes/webhooks.d.ts.map +1 -1
- package/dist/routes/workflows.d.ts +177 -66
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/routes/ws/agents.d.ts +11 -5
- package/dist/routes/ws/agents.d.ts.map +1 -1
- package/dist/routes/ws/events.d.ts +8 -8
- package/dist/routes/ws/events.d.ts.map +1 -1
- package/dist/routes/ws/log-subscription-hub.d.ts +6 -3
- package/dist/routes/ws/log-subscription-hub.d.ts.map +1 -1
- package/dist/routes/ws/logs.d.ts +10 -10
- package/dist/routes/ws/logs.d.ts.map +1 -1
- package/dist/schemas/actions.d.ts +89 -194
- package/dist/schemas/actions.d.ts.map +1 -1
- package/dist/schemas/agents.d.ts +791 -471
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-accounting.d.ts +2393 -0
- package/dist/schemas/ai-accounting.d.ts.map +1 -0
- package/dist/schemas/ai-usage.d.ts +34 -0
- package/dist/schemas/ai-usage.d.ts.map +1 -0
- package/dist/schemas/auth.d.ts +102 -102
- package/dist/schemas/common.d.ts +37 -0
- package/dist/schemas/common.d.ts.map +1 -1
- package/dist/schemas/connectors.d.ts +713 -2
- package/dist/schemas/connectors.d.ts.map +1 -1
- package/dist/schemas/datasets.d.ts +2 -2
- package/dist/schemas/event-payloads.d.ts +12 -12
- package/dist/schemas/events.d.ts +40 -40
- package/dist/schemas/links.d.ts +2 -2
- package/dist/schemas/logs.d.ts +22 -22
- package/dist/schemas/objects.d.ts +10 -10
- package/dist/schemas/ontology.d.ts +118 -118
- package/dist/schemas/pipelines.d.ts +89 -184
- package/dist/schemas/pipelines.d.ts.map +1 -1
- package/dist/schemas/projections.d.ts +1030 -563
- package/dist/schemas/projections.d.ts.map +1 -1
- package/dist/schemas/rules.d.ts +6 -6
- package/dist/schemas/syncs.d.ts +65 -108
- package/dist/schemas/syncs.d.ts.map +1 -1
- package/dist/schemas/webhook-runs.d.ts +41 -41
- package/dist/schemas/webhook-runs.d.ts.map +1 -1
- package/dist/schemas/workflows.d.ts +1189 -185
- package/dist/schemas/workflows.d.ts.map +1 -1
- package/dist/server.d.ts +11 -6
- package/dist/server.d.ts.map +1 -1
- package/dist/utils/http.d.ts +2 -0
- package/dist/utils/http.d.ts.map +1 -1
- package/dist/utils/ws.d.ts +4 -3
- package/dist/utils/ws.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/auth/access-token-boundary.ts +4 -4
- package/src/auth/application-access.ts +8 -9
- package/src/auth/connector-callback-cookie.ts +95 -0
- package/src/auth/experience.ts +190 -0
- package/src/auth/guard.ts +11 -11
- package/src/auth/public-routes.ts +20 -0
- package/src/auth/scope.ts +26 -36
- package/src/auth/session-cookies.ts +3 -3
- package/src/connectors/http.ts +110 -0
- package/src/index.ts +1 -0
- package/src/openapi/tags.ts +13 -1
- package/src/registerRoutes.ts +36 -23
- package/src/routes/action-runs.ts +39 -39
- package/src/routes/actions.ts +7 -13
- package/src/routes/agent-api-gateway.ts +41 -38
- package/src/routes/agents.ts +90 -200
- package/src/routes/ai-accounting.ts +166 -0
- package/src/routes/auth.ts +274 -122
- package/src/routes/connector-connection-runs.ts +346 -0
- package/src/routes/connector-connections.ts +135 -0
- package/src/routes/connectors.ts +24 -12
- package/src/routes/datasets.ts +55 -54
- package/src/routes/events.ts +5 -5
- package/src/routes/files.ts +22 -30
- package/src/routes/links.ts +31 -35
- package/src/routes/logs.ts +6 -11
- package/src/routes/objects.ts +51 -114
- package/src/routes/ontology.ts +27 -38
- package/src/routes/pipelines.ts +28 -62
- package/src/routes/project.ts +3 -3
- package/src/routes/projections.ts +44 -42
- package/src/routes/rules.ts +11 -25
- package/src/routes/status.ts +5 -5
- package/src/routes/syncs.ts +19 -45
- package/src/routes/telemetry.ts +18 -29
- package/src/routes/webhook-runs.ts +5 -5
- package/src/routes/webhooks.ts +259 -341
- package/src/routes/workflows.ts +242 -248
- package/src/routes/ws/agents.ts +196 -66
- package/src/routes/ws/events.ts +11 -10
- package/src/routes/ws/log-subscription-hub.ts +6 -12
- package/src/routes/ws/logs.ts +13 -5
- package/src/schemas/actions.ts +58 -25
- package/src/schemas/agents.ts +23 -23
- package/src/schemas/ai-accounting.ts +182 -0
- package/src/schemas/ai-usage.ts +16 -0
- package/src/schemas/common.ts +24 -0
- package/src/schemas/connectors.ts +164 -0
- package/src/schemas/pipelines.ts +23 -15
- package/src/schemas/projections.ts +23 -3
- package/src/schemas/syncs.ts +13 -8
- package/src/schemas/webhook-runs.ts +10 -5
- package/src/schemas/workflows.ts +23 -8
- package/src/server.ts +75 -26
- package/src/utils/http.ts +34 -6
- package/src/utils/ws.ts +10 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../../src/schemas/workflows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../../src/schemas/workflows.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAGjB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAMvB,eAAO,MAAM,wBAAwB,+GAA4B,CAAA;AAMjE,eAAO,MAAM,oBAAoB;;;;;;EAE/B,CAAA;AAEF,eAAO,MAAM,uBAAuB;;;;;;EAElC,CAAA;AAEF,eAAO,MAAM,gCAAgC;;;;;;EAE3C,CAAA;AAEF,eAAO,MAAM,uBAAuB,iFAOlC,CAAA;AAEF,eAAO,MAAM,gCAAgC,6DAK3C,CAAA;AAEF,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;EAQlC,CAAA;AAEF,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAa3C,CAAA;AAEF,eAAO,MAAM,4BAA4B;;;;;;GAI3B,CAAA;AAEd,eAAO,MAAM,+BAA+B;;;;;;;;;EAG1C,CAAA;AAEF,eAAO,MAAM,2BAA2B,8DAA2B,CAAA;AAEnE,eAAO,MAAM,oCAAoC;;;;;;EAE/C,CAAA;AAEF,eAAO,MAAM,oCAAoC,8DAA2B,CAAA;AAwC5E,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUnC,CAAA;AAEF,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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HostView } from "@sixb/core";
|
|
2
2
|
import { Elysia } from "elysia";
|
|
3
3
|
import { type AuthInvitationDestinationOptions, type AuthInvitationRedirectContext, type AuthInvitationRedirectInput, type RequestAuthContext, type ResolveAuthRedirectContext, type ResolvedSixbApiBrowserPolicy, type SixbApiBrowserPolicy } from "./auth/browser-origin";
|
|
4
|
+
import type { SixbAuthExperienceOptions } from "./auth/experience";
|
|
4
5
|
export interface SixbServerOptions {
|
|
5
|
-
|
|
6
|
+
host: SixbHostView;
|
|
6
7
|
port?: number;
|
|
7
|
-
|
|
8
|
+
hostname?: string;
|
|
8
9
|
quiet?: boolean;
|
|
9
10
|
browser: SixbApiBrowserPolicy;
|
|
11
|
+
/** Optional custom-app auth bundle mounted under the API's `/auth` routes. */
|
|
12
|
+
authExperience?: SixbAuthExperienceOptions;
|
|
10
13
|
}
|
|
11
14
|
export declare function createSixbServer(options: SixbServerOptions): SixbServer;
|
|
12
15
|
export declare class SixbServer {
|
|
13
|
-
private readonly
|
|
16
|
+
private readonly hostRuntime;
|
|
14
17
|
private readonly port;
|
|
15
|
-
private readonly
|
|
18
|
+
private readonly hostname;
|
|
16
19
|
private readonly quiet;
|
|
17
20
|
private readonly apiBrowserPolicy;
|
|
18
21
|
private readonly authContextResolver;
|
|
19
22
|
private readonly authRedirectContextResolver;
|
|
23
|
+
private readonly authExperience?;
|
|
20
24
|
private app;
|
|
21
25
|
private bunServer;
|
|
22
26
|
private maintenance;
|
|
23
27
|
constructor(options: SixbServerOptions);
|
|
24
|
-
|
|
28
|
+
getHost(): SixbHostView;
|
|
25
29
|
getPort(): number;
|
|
26
30
|
resolveAuthContext(request: Request): RequestAuthContext;
|
|
27
31
|
resolveAuthRedirectContext(request: Parameters<ResolveAuthRedirectContext>[0], input: Parameters<ResolveAuthRedirectContext>[1]): ReturnType<ResolveAuthRedirectContext>;
|
|
@@ -29,6 +33,7 @@ export declare class SixbServer {
|
|
|
29
33
|
getInvitationDestinationOptions(_request: Request): AuthInvitationDestinationOptions;
|
|
30
34
|
resolveInvitationRedirectContext(request: Request, input: AuthInvitationRedirectInput): AuthInvitationRedirectContext;
|
|
31
35
|
getApiBrowserPolicy(): ResolvedSixbApiBrowserPolicy;
|
|
36
|
+
getAuthExperience(): SixbAuthExperienceOptions | undefined;
|
|
32
37
|
start(): Promise<void>;
|
|
33
38
|
stop(): Promise<void>;
|
|
34
39
|
}
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA6B,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA6B,YAAY,EAAE,MAAM,YAAY,CAAA;AAGzE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAG/B,OAAO,EACL,KAAK,gCAAgC,EACrC,KAAK,6BAA6B,EAClC,KAAK,2BAA2B,EAMhC,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,EAKjC,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAA;AAE9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAA;AAmBlE,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,YAAY,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,OAAO,EAAE,oBAAoB,CAAA;IAC7B,8EAA8E;IAC9E,cAAc,CAAC,EAAE,yBAAyB,CAAA;CAC3C;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,UAAU,CAEvE;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,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GED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type SixbErrorCode } from "@sixb/core";
|
|
1
2
|
export declare function toIsoString(value: Date): string;
|
|
2
3
|
export declare function parseDate(value: string | undefined): Date | undefined;
|
|
3
4
|
export declare function parseOptionalInt(value: string | undefined): number | undefined;
|
|
@@ -19,5 +20,6 @@ export declare function handleRouteError(error: unknown, set: {
|
|
|
19
20
|
status?: number | string;
|
|
20
21
|
}): {
|
|
21
22
|
error: string;
|
|
23
|
+
code?: SixbErrorCode;
|
|
22
24
|
};
|
|
23
25
|
//# sourceMappingURL=http.d.ts.map
|
package/dist/utils/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/utils/http.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/utils/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,YAAY,CAAA;AA2BnB,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;IACb,IAAI,CAAC,EAAE,aAAa,CAAA;CACrB,CAsCA"}
|
package/dist/utils/ws.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OntologySource } from "@sixb/core";
|
|
2
|
+
import type { Sixb } from "@sixb/core/internal/request-execution";
|
|
2
3
|
export declare function safeSend(target: {
|
|
3
4
|
send: (message: string) => void;
|
|
4
5
|
}, payload: unknown): void;
|
|
5
6
|
/** Stable per-connection key for a subscription-state WeakMap (the raw socket when Elysia wraps it). */
|
|
6
7
|
export declare function wsStateKey(ws: object): object;
|
|
7
|
-
/** The
|
|
8
|
-
export declare function
|
|
8
|
+
/** The execution SDK attached once when the WebSocket request crosses the auth boundary. */
|
|
9
|
+
export declare function wsRequestSixb(ws: object): Sixb<readonly OntologySource[]> | null;
|
|
9
10
|
export declare function decodeWsMessage(message: unknown): Promise<unknown>;
|
|
10
11
|
//# sourceMappingURL=ws.d.ts.map
|
package/dist/utils/ws.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src/utils/ws.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src/utils/ws.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAA;AAEjE,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,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC,SAAS,cAAc,EAAE,CAAC,GAAG,IAAI,CAOhF;AAUD,wBAAsB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CA4BxE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "HTTP and WebSocket API server for Sixb",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sixb",
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"zod-to-json-schema": "^3.24.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@sixb/core": "0.1.
|
|
40
|
+
"@sixb/core": "0.1.3"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@sixb/auth-magic-link": "0.1.
|
|
43
|
+
"@sixb/auth-magic-link": "0.1.2",
|
|
44
44
|
"@sixb/auth-oidc": "0.1.1",
|
|
45
|
-
"@sixb/core": "0.1.
|
|
46
|
-
"@sixb/sqlite": "0.1.
|
|
45
|
+
"@sixb/core": "0.1.3",
|
|
46
|
+
"@sixb/sqlite": "0.1.3",
|
|
47
47
|
"@types/bun": "latest",
|
|
48
48
|
"typescript": "^5.7.0"
|
|
49
49
|
},
|
|
@@ -21,9 +21,9 @@ export interface AccessTokenRoute {
|
|
|
21
21
|
// `agentApi` projection of the same table, which the table's load-time invariant keeps a strict
|
|
22
22
|
// subset of this one.
|
|
23
23
|
//
|
|
24
|
-
// Bearer tokens should only reach routes that
|
|
25
|
-
//
|
|
26
|
-
//
|
|
24
|
+
// Bearer tokens should only reach routes that enforce execution-bound authority. Admin, browser,
|
|
25
|
+
// webhook, and WebSocket routes stay session-only because bearer access is intentionally absent
|
|
26
|
+
// from SIXB_API_ROUTES.
|
|
27
27
|
export const ACCESS_TOKEN_ROUTES: readonly AccessTokenRoute[] = SIXB_API_ROUTES.filter(
|
|
28
28
|
(route) => route.accessToken
|
|
29
29
|
).map((route) => ({ operationId: route.operationId, method: route.method, path: route.path }))
|
|
@@ -63,6 +63,6 @@ export function shouldVerifyCsrfForAuthSource(
|
|
|
63
63
|
source: AuthCredentialSource
|
|
64
64
|
): boolean {
|
|
65
65
|
// CSRF protects ambient browser cookies. Bearer tokens are explicit request
|
|
66
|
-
// credentials, so they skip CSRF while still requiring
|
|
66
|
+
// credentials, so they skip CSRF while still requiring execution-bound authorization.
|
|
67
67
|
return route.csrfProtected && source === "session"
|
|
68
68
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AuthSessionAudience,
|
|
3
|
-
canAccessApplication,
|
|
4
|
-
type OntologySource,
|
|
5
|
-
type Sixb,
|
|
6
|
-
} from "@sixb/core"
|
|
1
|
+
import { type AuthSessionAudience, canAccessApplication, type SixbHostView } from "@sixb/core"
|
|
7
2
|
import type { AuthenticatedRequestAuthSession } from "@sixb/core/internal/auth"
|
|
8
3
|
|
|
9
4
|
export function sessionCanAccessApplication(
|
|
10
|
-
|
|
5
|
+
host: SixbHostView,
|
|
11
6
|
session: AuthenticatedRequestAuthSession,
|
|
12
7
|
audience: AuthSessionAudience
|
|
13
8
|
): boolean {
|
|
14
|
-
const authorization =
|
|
15
|
-
return canAccessApplication(
|
|
9
|
+
const authorization = host.auth.contextFromSession(session)
|
|
10
|
+
return canAccessApplication(
|
|
11
|
+
authorization,
|
|
12
|
+
host.definitions.security.listResolvedRoles(),
|
|
13
|
+
audience
|
|
14
|
+
)
|
|
16
15
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { getCookie } from "@sixb/core/internal/auth"
|
|
2
|
+
import { createSixbError } from "@sixb/core/internal/errors"
|
|
3
|
+
|
|
4
|
+
const CALLBACK_PATH = "/auth/connectors/callback"
|
|
5
|
+
const COOKIE_PREFIX = "sixb_connector_callback_"
|
|
6
|
+
const ATTEMPT_ID_PATTERN =
|
|
7
|
+
/^cat_[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
|
|
8
|
+
|
|
9
|
+
export function createConnectorCallbackCookie(input: {
|
|
10
|
+
readonly request: Request
|
|
11
|
+
readonly attemptId: string
|
|
12
|
+
readonly secret: string
|
|
13
|
+
readonly expiresAt: Date
|
|
14
|
+
}): string {
|
|
15
|
+
const expiresAt = validDate(input.expiresAt)
|
|
16
|
+
return serializeConnectorCallbackCookie({
|
|
17
|
+
request: input.request,
|
|
18
|
+
name: connectorCallbackCookieName(input.attemptId),
|
|
19
|
+
value: input.secret,
|
|
20
|
+
maxAge: Math.max(0, Math.floor((expiresAt.getTime() - Date.now()) / 1000)),
|
|
21
|
+
expiresAt,
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function readConnectorCallbackCookie(
|
|
26
|
+
request: Request,
|
|
27
|
+
state: string
|
|
28
|
+
): { readonly name: string; readonly value: string | undefined } {
|
|
29
|
+
const name = connectorCallbackCookieName(attemptIdFromState(state))
|
|
30
|
+
return { name, value: getCookie(request, name) }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function clearConnectorCallbackCookie(request: Request, name: string): string {
|
|
34
|
+
return serializeConnectorCallbackCookie({
|
|
35
|
+
request,
|
|
36
|
+
name,
|
|
37
|
+
value: "",
|
|
38
|
+
maxAge: 0,
|
|
39
|
+
expiresAt: new Date(0),
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function attemptIdFromState(state: string): string {
|
|
44
|
+
const separator = state.indexOf(".")
|
|
45
|
+
if (separator <= 0 || separator === state.length - 1) {
|
|
46
|
+
throw createSixbError(
|
|
47
|
+
"connector.authorization_invalid",
|
|
48
|
+
"[SixbServer] Connector OAuth state is invalid."
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
return state.slice(0, separator)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function connectorCallbackCookieName(attemptId: string): string {
|
|
55
|
+
if (!ATTEMPT_ID_PATTERN.test(attemptId)) {
|
|
56
|
+
throw createSixbError(
|
|
57
|
+
"connector.authorization_invalid",
|
|
58
|
+
"[SixbServer] Connector OAuth attempt id is invalid."
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
return `${COOKIE_PREFIX}${attemptId}`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function serializeConnectorCallbackCookie(input: {
|
|
65
|
+
readonly request: Request
|
|
66
|
+
readonly name: string
|
|
67
|
+
readonly value: string
|
|
68
|
+
readonly maxAge: number
|
|
69
|
+
readonly expiresAt: Date
|
|
70
|
+
}): string {
|
|
71
|
+
const parts = [
|
|
72
|
+
`${input.name}=${input.value}`,
|
|
73
|
+
`Path=${CALLBACK_PATH}`,
|
|
74
|
+
"HttpOnly",
|
|
75
|
+
"SameSite=Lax",
|
|
76
|
+
`Max-Age=${Math.trunc(input.maxAge)}`,
|
|
77
|
+
`Expires=${input.expiresAt.toUTCString()}`,
|
|
78
|
+
]
|
|
79
|
+
if (shouldUseSecureCookie(input.request)) parts.push("Secure")
|
|
80
|
+
return parts.join("; ")
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function shouldUseSecureCookie(request: Request): boolean {
|
|
84
|
+
return new URL(request.url).protocol === "https:" || process.env.NODE_ENV === "production"
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function validDate(value: Date): Date {
|
|
88
|
+
if (Number.isNaN(value.getTime())) {
|
|
89
|
+
throw createSixbError(
|
|
90
|
+
"internal.unexpected",
|
|
91
|
+
"[SixbServer] Connector callback cookie expiration is invalid."
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
return new Date(value)
|
|
95
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { resolve } from "node:path"
|
|
2
|
+
import type { AuthSessionAudience } from "@sixb/core"
|
|
3
|
+
|
|
4
|
+
const AUTH_BOOTSTRAP_PLACEHOLDER = "__SIXB_AUTH_BOOTSTRAP__"
|
|
5
|
+
const AUTH_ASSET_PREFIX = "/auth/assets/"
|
|
6
|
+
|
|
7
|
+
export interface SixbAuthExperienceOptions {
|
|
8
|
+
readonly outdir: string
|
|
9
|
+
readonly audience?: AuthSessionAudience
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type AuthExperiencePageState =
|
|
13
|
+
| { readonly kind: "signIn" }
|
|
14
|
+
| { readonly kind: "checkEmail" }
|
|
15
|
+
| { readonly kind: "confirm"; readonly email?: string }
|
|
16
|
+
| { readonly kind: "invalidLink" }
|
|
17
|
+
| { readonly kind: "error" }
|
|
18
|
+
|
|
19
|
+
export interface AuthExperienceSubmission {
|
|
20
|
+
readonly kind: "requestMagicLink" | "confirmSignIn"
|
|
21
|
+
readonly action: string
|
|
22
|
+
readonly fields: Readonly<Record<string, string>>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function customAuthExperienceResponse(
|
|
26
|
+
options: SixbAuthExperienceOptions | undefined,
|
|
27
|
+
input: {
|
|
28
|
+
readonly audience: AuthSessionAudience
|
|
29
|
+
readonly state: AuthExperiencePageState
|
|
30
|
+
readonly signInUrl: string
|
|
31
|
+
readonly submission?: AuthExperienceSubmission
|
|
32
|
+
readonly status?: number
|
|
33
|
+
readonly referrerPolicy?: "no-referrer" | "same-origin"
|
|
34
|
+
readonly formActionOrigins?: readonly string[]
|
|
35
|
+
}
|
|
36
|
+
): Promise<Response | null> {
|
|
37
|
+
if (!options || input.audience !== (options.audience ?? "app")) {
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const template = Bun.file(resolve(options.outdir, "index.html"))
|
|
42
|
+
if (!(await template.exists())) {
|
|
43
|
+
return null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const html = await template.text()
|
|
47
|
+
if (!html.includes(AUTH_BOOTSTRAP_PLACEHOLDER)) {
|
|
48
|
+
console.warn(
|
|
49
|
+
`[SixbServer] Custom auth experience in ${options.outdir} is missing its bootstrap placeholder. Using the generic page.`
|
|
50
|
+
)
|
|
51
|
+
return null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const bootstrap = Buffer.from(
|
|
55
|
+
JSON.stringify({
|
|
56
|
+
state: input.state,
|
|
57
|
+
signInUrl: input.signInUrl,
|
|
58
|
+
...(input.submission ? { submission: input.submission } : {}),
|
|
59
|
+
})
|
|
60
|
+
).toString("base64url")
|
|
61
|
+
const formAction = ["'self'", ...(input.formActionOrigins ?? []).map(normalizeCspOrigin)].join(
|
|
62
|
+
" "
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
return new Response(html.replace(AUTH_BOOTSTRAP_PLACEHOLDER, bootstrap), {
|
|
66
|
+
status: input.status ?? 200,
|
|
67
|
+
headers: {
|
|
68
|
+
"content-type": "text/html; charset=utf-8",
|
|
69
|
+
"cache-control": "no-store",
|
|
70
|
+
"content-security-policy": [
|
|
71
|
+
"default-src 'none'",
|
|
72
|
+
"script-src 'self'",
|
|
73
|
+
"style-src 'self' 'unsafe-inline'",
|
|
74
|
+
"img-src 'self' data:",
|
|
75
|
+
"font-src 'self'",
|
|
76
|
+
"base-uri 'none'",
|
|
77
|
+
`form-action ${formAction}`,
|
|
78
|
+
"frame-ancestors 'none'",
|
|
79
|
+
].join("; "),
|
|
80
|
+
"referrer-policy": input.referrerPolicy ?? "no-referrer",
|
|
81
|
+
"x-content-type-options": "nosniff",
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function normalizeCspOrigin(value: string): string {
|
|
87
|
+
let url: URL
|
|
88
|
+
try {
|
|
89
|
+
url = new URL(value)
|
|
90
|
+
} catch {
|
|
91
|
+
throw new Error(`[SixbServer] Invalid custom auth form-action origin: '${value}'.`)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if ((url.protocol !== "http:" && url.protocol !== "https:") || url.origin !== value) {
|
|
95
|
+
throw new Error(`[SixbServer] Invalid custom auth form-action origin: '${value}'.`)
|
|
96
|
+
}
|
|
97
|
+
return url.origin
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export async function customAuthExperienceAssetResponse(
|
|
101
|
+
options: SixbAuthExperienceOptions | undefined,
|
|
102
|
+
request: Request
|
|
103
|
+
): Promise<Response> {
|
|
104
|
+
const method = request.method.toUpperCase()
|
|
105
|
+
if (!options || (method !== "GET" && method !== "HEAD")) {
|
|
106
|
+
return notFoundResponse()
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const url = new URL(request.url)
|
|
110
|
+
if (!url.pathname.startsWith(AUTH_ASSET_PREFIX)) {
|
|
111
|
+
return notFoundResponse()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let fileName: string
|
|
115
|
+
try {
|
|
116
|
+
fileName = decodeURIComponent(url.pathname.slice(AUTH_ASSET_PREFIX.length))
|
|
117
|
+
} catch {
|
|
118
|
+
return notFoundResponse()
|
|
119
|
+
}
|
|
120
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(fileName)) {
|
|
121
|
+
return notFoundResponse()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const path = resolve(options.outdir, "assets", fileName)
|
|
125
|
+
const source = Bun.file(path)
|
|
126
|
+
if (!(await source.exists())) {
|
|
127
|
+
return notFoundResponse()
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const encoding = await resolvePrecompressedAsset(request, path)
|
|
131
|
+
const body = encoding ? Bun.file(`${path}.${encoding === "br" ? "br" : "gz"}`) : source
|
|
132
|
+
const headers = new Headers({
|
|
133
|
+
"content-type": source.type || "application/octet-stream",
|
|
134
|
+
"cache-control": "public, max-age=31536000, immutable",
|
|
135
|
+
"x-content-type-options": "nosniff",
|
|
136
|
+
})
|
|
137
|
+
if (encoding) {
|
|
138
|
+
headers.set("content-encoding", encoding)
|
|
139
|
+
headers.set("vary", "Accept-Encoding")
|
|
140
|
+
}
|
|
141
|
+
return new Response(method === "HEAD" ? null : body, { headers })
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function resolvePrecompressedAsset(
|
|
145
|
+
request: Request,
|
|
146
|
+
sourcePath: string
|
|
147
|
+
): Promise<"br" | "gzip" | null> {
|
|
148
|
+
for (const encoding of acceptedPrecompressedEncodings(request)) {
|
|
149
|
+
const suffix = encoding === "br" ? "br" : "gz"
|
|
150
|
+
if (await Bun.file(`${sourcePath}.${suffix}`).exists()) {
|
|
151
|
+
return encoding
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return null
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function acceptedPrecompressedEncodings(request: Request): ("br" | "gzip")[] {
|
|
158
|
+
const header = request.headers.get("accept-encoding")
|
|
159
|
+
if (!header) return []
|
|
160
|
+
|
|
161
|
+
const qualities = new Map<string, number>()
|
|
162
|
+
for (const item of header.split(",")) {
|
|
163
|
+
const [rawName, ...parameters] = item.trim().split(";")
|
|
164
|
+
const name = rawName.toLowerCase()
|
|
165
|
+
let quality = 1
|
|
166
|
+
for (const parameter of parameters) {
|
|
167
|
+
const match = parameter.trim().match(/^q=(0(?:\.\d+)?|1(?:\.0+)?)$/)
|
|
168
|
+
if (match) quality = Number(match[1])
|
|
169
|
+
}
|
|
170
|
+
qualities.set(name, quality)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const wildcard = qualities.get("*") ?? 0
|
|
174
|
+
return (["br", "gzip"] as const)
|
|
175
|
+
.map((encoding, preference) => ({
|
|
176
|
+
encoding,
|
|
177
|
+
preference,
|
|
178
|
+
quality: qualities.get(encoding) ?? wildcard,
|
|
179
|
+
}))
|
|
180
|
+
.filter((candidate) => candidate.quality > 0)
|
|
181
|
+
.sort((left, right) => right.quality - left.quality || left.preference - right.preference)
|
|
182
|
+
.map((candidate) => candidate.encoding)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function notFoundResponse(): Response {
|
|
186
|
+
return new Response("Not Found", {
|
|
187
|
+
status: 404,
|
|
188
|
+
headers: { "content-type": "text/plain; charset=utf-8" },
|
|
189
|
+
})
|
|
190
|
+
}
|
package/src/auth/guard.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SixbHostView } from "@sixb/core"
|
|
2
2
|
import {
|
|
3
3
|
type AuthenticatedRequestAuthSession,
|
|
4
4
|
verifyDoubleSubmitCsrf,
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
import { hasForegroundSessionActivity, isSessionTerminationRequest } from "./session-activity"
|
|
18
18
|
|
|
19
19
|
export interface ServerAuthGuardOptions {
|
|
20
|
-
readonly
|
|
20
|
+
readonly host: SixbHostView
|
|
21
21
|
readonly resolveAuthContext: ResolveRequestAuthContext
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -33,20 +33,20 @@ export type ServerAuthGuardDecision =
|
|
|
33
33
|
| { readonly kind: "allow"; readonly session: AuthenticatedRequestAuthSession | null }
|
|
34
34
|
|
|
35
35
|
export class ServerAuthGuard {
|
|
36
|
-
private readonly
|
|
36
|
+
private readonly host: SixbHostView
|
|
37
37
|
private readonly resolveAuthContext: ResolveRequestAuthContext
|
|
38
38
|
|
|
39
39
|
constructor(options: ServerAuthGuardOptions) {
|
|
40
|
-
this.
|
|
40
|
+
this.host = options.host
|
|
41
41
|
this.resolveAuthContext = options.resolveAuthContext
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
isAuthEnabled(): boolean {
|
|
45
|
-
return this.
|
|
45
|
+
return this.host.auth.isEnabled()
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
assertCanServeHttp(params: { readonly production: boolean }): void {
|
|
49
|
-
this.
|
|
49
|
+
this.host.auth.assertCanServeHttp(params)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
async resolve(request: Request): Promise<ServerAuthGuardDecision> {
|
|
@@ -64,7 +64,7 @@ export class ServerAuthGuard {
|
|
|
64
64
|
return { kind: "deny", response: authContext }
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
let session = await this.
|
|
67
|
+
let session = await this.host.auth.getSession(request, {
|
|
68
68
|
audience: authContext.audience,
|
|
69
69
|
credentialSource: "any",
|
|
70
70
|
})
|
|
@@ -86,7 +86,7 @@ export class ServerAuthGuard {
|
|
|
86
86
|
return { kind: "deny", response: jsonAuthRequiredResponse() }
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
if (!sessionCanAccessApplication(this.
|
|
89
|
+
if (!sessionCanAccessApplication(this.host, session, authContext.audience)) {
|
|
90
90
|
return {
|
|
91
91
|
kind: "deny",
|
|
92
92
|
response: jsonForbiddenResponse("Application access is not allowed"),
|
|
@@ -113,7 +113,7 @@ export class ServerAuthGuard {
|
|
|
113
113
|
!isSessionTerminationRequest(request) &&
|
|
114
114
|
hasForegroundSessionActivity(request)
|
|
115
115
|
) {
|
|
116
|
-
const activeSession = await this.
|
|
116
|
+
const activeSession = await this.host.auth.getSession(request, {
|
|
117
117
|
audience: authContext.audience,
|
|
118
118
|
credentialSource: "session",
|
|
119
119
|
sessionActivity: "foreground",
|
|
@@ -130,7 +130,7 @@ export class ServerAuthGuard {
|
|
|
130
130
|
}
|
|
131
131
|
return { kind: "deny", response: jsonAuthRequiredResponse() }
|
|
132
132
|
}
|
|
133
|
-
if (!sessionCanAccessApplication(this.
|
|
133
|
+
if (!sessionCanAccessApplication(this.host, activeSession, authContext.audience)) {
|
|
134
134
|
return {
|
|
135
135
|
kind: "deny",
|
|
136
136
|
response: jsonForbiddenResponse("Application access is not allowed"),
|
|
@@ -144,7 +144,7 @@ export class ServerAuthGuard {
|
|
|
144
144
|
|
|
145
145
|
getCsrfCookieName(request: Request): string {
|
|
146
146
|
const audience = this.resolveAuthContext(request).audience
|
|
147
|
-
return this.
|
|
147
|
+
return this.host.auth.getCookieOptions({ audience }).csrfCookieName
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
verifyCsrf(request: Request, _session: AuthenticatedRequestAuthSession): boolean {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AGENT_API_GATEWAY_PREFIX } from "@sixb/core/internal/agents"
|
|
2
2
|
import { isCsrfExemptMethod } from "@sixb/core/internal/auth"
|
|
3
3
|
|
|
4
|
+
const CONNECTOR_OAUTH_CALLBACK_PATH = "/auth/connectors/callback"
|
|
5
|
+
|
|
4
6
|
export type RouteAccessKind = "public" | "api" | "html" | "websocket"
|
|
5
7
|
|
|
6
8
|
export interface RouteAccess {
|
|
@@ -70,6 +72,13 @@ export function isPublicRoute(pathname: string, method: string): boolean {
|
|
|
70
72
|
return true
|
|
71
73
|
}
|
|
72
74
|
|
|
75
|
+
if (
|
|
76
|
+
pathname.startsWith("/auth/assets/") &&
|
|
77
|
+
(normalizedMethod === "GET" || normalizedMethod === "HEAD")
|
|
78
|
+
) {
|
|
79
|
+
return true
|
|
80
|
+
}
|
|
81
|
+
|
|
73
82
|
if (pathname === "/auth/sign-in" && (normalizedMethod === "GET" || normalizedMethod === "POST")) {
|
|
74
83
|
return true
|
|
75
84
|
}
|
|
@@ -83,5 +92,16 @@ export function isPublicRoute(pathname: string, method: string): boolean {
|
|
|
83
92
|
return true
|
|
84
93
|
}
|
|
85
94
|
|
|
95
|
+
// The callback proves one-use OAuth state plus a dedicated HttpOnly browser binding. PKCE then
|
|
96
|
+
// binds the code exchange to the attempt created by the authorized initiating request. Elysia
|
|
97
|
+
// routes both trailing-slash variants; some providers require the slash in the registered URI.
|
|
98
|
+
if (
|
|
99
|
+
(pathname === CONNECTOR_OAUTH_CALLBACK_PATH ||
|
|
100
|
+
pathname === `${CONNECTOR_OAUTH_CALLBACK_PATH}/`) &&
|
|
101
|
+
normalizedMethod === "GET"
|
|
102
|
+
) {
|
|
103
|
+
return true
|
|
104
|
+
}
|
|
105
|
+
|
|
86
106
|
return false
|
|
87
107
|
}
|