@krak-stack/auth 0.2.32 → 0.3.0
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/CHANGELOG.md +8 -0
- package/README.md +101 -5
- package/dist/access.d.ts +3 -1
- package/dist/admin/api.group.d.ts +41 -41
- package/dist/admin/schema.d.ts +23 -23
- package/dist/admin/schema.js +21 -19
- package/dist/api.d.ts +1313 -1313
- package/dist/auth/api.group.d.ts +18 -18
- package/dist/auth/schema.d.ts +49 -33
- package/dist/auth/schema.js +18 -18
- package/dist/components/admin-organization-form.js +2 -2
- package/dist/components/admin-organizations.js +6 -5
- package/dist/components/admin-users.js +6 -6
- package/dist/components/api-key-edit-form.js +19 -11
- package/dist/components/associated-projects-notice.d.ts +2 -1
- package/dist/components/associated-projects-notice.js +6 -2
- package/dist/components/auth-atoms.js +1 -2
- package/dist/components/auth-client-api.d.ts +61 -61
- package/dist/components/auth-forms.d.ts +1 -0
- package/dist/components/auth-forms.js +41 -56
- package/dist/components/auth-provider.d.ts +3 -1
- package/dist/components/hooks.d.ts +2 -0
- package/dist/components/hooks.js +13 -6
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.js +2 -0
- package/dist/components/member-required.js +3 -5
- package/dist/components/oauth-consent.d.ts +22 -0
- package/dist/components/oauth-consent.js +79 -0
- package/dist/components/organization-switcher.d.ts +1 -1
- package/dist/components/organization-switcher.js +83 -54
- package/dist/components/project-card-list.d.ts +6 -0
- package/dist/components/project-card-list.js +4 -0
- package/dist/components/user-button.js +115 -54
- package/dist/extra/schema.d.ts +3 -1
- package/dist/oauth/authorization.d.ts +3 -0
- package/dist/oauth/authorization.js +39 -0
- package/dist/oauth/schema.d.ts +24 -0
- package/dist/oauth/schema.js +12 -0
- package/dist/oauth/verify.d.ts +13 -0
- package/dist/oauth/verify.js +67 -0
- package/dist/schema.js +1 -1
- package/dist/server/actor.js +2 -4
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +1 -0
- package/dist/server/mcp.d.ts +20 -0
- package/dist/server/mcp.js +66 -0
- package/dist/server/middleware.d.ts +5 -5
- package/dist/server/middleware.js +15 -5
- package/dist/server/webhook-layer.js +8 -4
- package/dist/server/webhooks.d.ts +9 -3
- package/dist/service.d.ts +52 -46
- package/dist/service.js +56 -9
- package/package.json +2 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Effect, Layer } from "effect";
|
|
2
|
+
import { FetchHttpClient, HttpRouter, HttpServerRequest, HttpServerResponse, } from "effect/http";
|
|
3
|
+
import { verifyOAuthAccessToken } from "../oauth/verify.js";
|
|
4
|
+
const metadataPath = (resource) => `/.well-known/oauth-protected-resource${new URL(resource).pathname.replace(/\/$/, "")}`;
|
|
5
|
+
const challenge = (options, insufficientScope = false) => {
|
|
6
|
+
const metadataUrl = new URL(metadataPath(options.resource), options.resource)
|
|
7
|
+
.href;
|
|
8
|
+
const scopes = insufficientScope
|
|
9
|
+
? options.requiredScopes
|
|
10
|
+
: (options.challengeScopes ?? options.requiredScopes);
|
|
11
|
+
return `Bearer resource_metadata="${metadataUrl}"${insufficientScope ? ', error="insufficient_scope"' : ""}, scope="${scopes.join(" ")}"`;
|
|
12
|
+
};
|
|
13
|
+
/** OAuth discovery and authentication for an existing MCP transport. */
|
|
14
|
+
export const McpAuth = {
|
|
15
|
+
metadataPath,
|
|
16
|
+
/** Forward public discovery through the consumer's existing auth proxy. */
|
|
17
|
+
discoveryRequest: (request, options) => {
|
|
18
|
+
const url = new URL(request.url);
|
|
19
|
+
const issuer = new URL(options.issuer);
|
|
20
|
+
if (url.pathname ===
|
|
21
|
+
`/.well-known/oauth-authorization-server${issuer.pathname.replace(/\/$/, "")}`) {
|
|
22
|
+
url.pathname = `${issuer.pathname.replace(/\/$/, "")}/.well-known/oauth-authorization-server`;
|
|
23
|
+
return new Request(url, request);
|
|
24
|
+
}
|
|
25
|
+
if (url.pathname === "/.well-known/oauth-protected-resource" ||
|
|
26
|
+
url.pathname === metadataPath(options.resource))
|
|
27
|
+
return request;
|
|
28
|
+
return undefined;
|
|
29
|
+
},
|
|
30
|
+
metadataLayer: (options) => {
|
|
31
|
+
const response = HttpServerResponse.jsonUnsafe({
|
|
32
|
+
resource: options.resource,
|
|
33
|
+
authorization_servers: [options.issuer],
|
|
34
|
+
scopes_supported: options.scopesSupported ?? options.requiredScopes,
|
|
35
|
+
bearer_methods_supported: ["header"],
|
|
36
|
+
}, { headers: { "access-control-allow-origin": "*" } });
|
|
37
|
+
return Layer.mergeAll(HttpRouter.add("GET", metadataPath(options.resource), Effect.succeed(response)), HttpRouter.add("GET", "/.well-known/oauth-protected-resource", Effect.succeed(response)));
|
|
38
|
+
},
|
|
39
|
+
middleware: (options) => HttpRouter.middleware((httpEffect) => Effect.gen(function* () {
|
|
40
|
+
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
41
|
+
const authorization = request.headers.authorization;
|
|
42
|
+
// Preserve explicitly supplied API keys for existing integrations. Their
|
|
43
|
+
// normal API authorization remains authoritative for tool execution.
|
|
44
|
+
if (authorization === undefined && request.headers["x-api-key"])
|
|
45
|
+
return yield* httpEffect;
|
|
46
|
+
const match = authorization?.match(/^Bearer ([^\s]+)$/i);
|
|
47
|
+
if (!match?.[1])
|
|
48
|
+
return HttpServerResponse.empty({
|
|
49
|
+
status: 401,
|
|
50
|
+
headers: { "www-authenticate": challenge(options) },
|
|
51
|
+
});
|
|
52
|
+
const result = yield* verifyOAuthAccessToken(match[1], options).pipe(Effect.provide(FetchHttpClient.layer), Effect.result);
|
|
53
|
+
if (result._tag === "Failure") {
|
|
54
|
+
if (result.failure._tag === "ServiceUnavailable")
|
|
55
|
+
return HttpServerResponse.empty({ status: 503 });
|
|
56
|
+
const insufficientScope = result.failure._tag === "Forbidden";
|
|
57
|
+
return HttpServerResponse.empty({
|
|
58
|
+
status: insufficientScope ? 403 : 401,
|
|
59
|
+
headers: {
|
|
60
|
+
"www-authenticate": challenge(options, insufficientScope),
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return yield* httpEffect;
|
|
65
|
+
})),
|
|
66
|
+
};
|
|
@@ -19,14 +19,14 @@ declare const AuthMiddleware_base: HttpApiMiddleware.ServiceClass<AuthMiddleware
|
|
|
19
19
|
export declare class AuthMiddleware extends AuthMiddleware_base {
|
|
20
20
|
static readonly layer: <E, R>(options: AuthMiddlewareOptions<E, R>) => Layer.Layer<AuthMiddleware, import("./webhooks.js").AuthWebhookConfigurationError | import("effect/Config").ConfigError | import("effect/sql/Migrator").MigrationError | import("effect/Schema").SchemaError | import("effect/sql/SqlError").SqlError, HttpRouter.HttpRouter | import("effect/sql/SqlClient").SqlClient | Exclude<Exclude<R, import("effect/Scope").Scope>, import("@krak-stack/registry/webhooks").WebhooksReceiver>>;
|
|
21
21
|
/** The same optional authentication and attribution for plain HttpRouter routes. */
|
|
22
|
-
static readonly routerLayer: (options?: AuthRouterOptions) => Layer.Layer<never, import("effect/Config").ConfigError, HttpRouter.Request<"Error", HttpApiError.Forbidden> | HttpRouter.Request<"Error", HttpApiError.ServiceUnavailable>>;
|
|
22
|
+
static readonly routerLayer: <E>(options?: AuthRouterOptions<E>) => Layer.Layer<never, import("effect/Config").ConfigError, HttpRouter.Request<"Error", HttpApiError.Forbidden> | HttpRouter.Request<"Error", HttpApiError.ServiceUnavailable>>;
|
|
23
23
|
}
|
|
24
|
-
export type AuthenticationLiveOptions = AuthServiceLayerOptions & {
|
|
24
|
+
export type AuthenticationLiveOptions<E = unknown> = AuthServiceLayerOptions & {
|
|
25
25
|
readonly allowedOrganizationImpersonationRoutes?: readonly {
|
|
26
26
|
readonly method: string;
|
|
27
27
|
readonly path: string;
|
|
28
28
|
}[];
|
|
29
|
-
readonly authLayer?: Layer.Layer<AuthService,
|
|
29
|
+
readonly authLayer?: Layer.Layer<AuthService, E, HttpServerRequest.HttpServerRequest>;
|
|
30
30
|
};
|
|
31
31
|
export type AuthMiddlewareOptions<E, R> = AuthenticationLiveOptions & {
|
|
32
32
|
readonly projectId?: string;
|
|
@@ -35,9 +35,9 @@ export type AuthMiddlewareOptions<E, R> = AuthenticationLiveOptions & {
|
|
|
35
35
|
readonly onDeleteOrganization: (data: typeof OrganizationDeletionData.Type) => Effect.Effect<void, E, R>;
|
|
36
36
|
readonly onWebhook?: (webhook: typeof AuthWebhook.Type) => Effect.Effect<void, E, R>;
|
|
37
37
|
};
|
|
38
|
-
export type AuthRouterOptions = AuthenticationLiveOptions & {
|
|
38
|
+
export type AuthRouterOptions<E = unknown> = AuthenticationLiveOptions<E> & {
|
|
39
39
|
/** Resolve auth only for these exact URL pathnames. Defaults to every route in scope. */
|
|
40
40
|
readonly paths?: readonly string[];
|
|
41
41
|
};
|
|
42
|
-
export declare const makeAuthenticationLive: (options?: AuthenticationLiveOptions | Layer.Layer<AuthService,
|
|
42
|
+
export declare const makeAuthenticationLive: <E>(options?: AuthenticationLiveOptions<E> | Layer.Layer<AuthService, E>) => Layer.Layer<AuthMiddleware, never, never>;
|
|
43
43
|
export {};
|
|
@@ -51,16 +51,22 @@ export const makeAuthenticationLive = (options = {}) => {
|
|
|
51
51
|
};
|
|
52
52
|
const authenticateRequest = Effect.fnUntraced(function* (options, authLayer, apiKey) {
|
|
53
53
|
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
54
|
-
const
|
|
54
|
+
const resolvedAuthLayer = authLayer ??
|
|
55
55
|
AuthService.layer({
|
|
56
56
|
...options,
|
|
57
57
|
headers: apiKey
|
|
58
58
|
? { ...request.headers, "x-api-key": apiKey }
|
|
59
59
|
: request.headers,
|
|
60
|
-
})
|
|
60
|
+
});
|
|
61
|
+
const auth = yield* AuthService.pipe(Effect.provide(resolvedAuthLayer), Effect.tapCause((cause) => Effect.logError("Authentication rejected: auth client initialization failed", Cause.pretty(cause))), Effect.mapError(() => new HttpApiError.ServiceUnavailable({})));
|
|
61
62
|
const session = yield* auth
|
|
62
63
|
.getSession()
|
|
63
64
|
.pipe(Effect.catchTag("Unauthorized", () => Effect.succeed(null)));
|
|
65
|
+
if (session?.authMethod.type === "oauth" &&
|
|
66
|
+
(!(options.oauth?.allowedMethods ?? ["GET", "HEAD"]).includes(request.method) ||
|
|
67
|
+
(!["GET", "HEAD"].includes(request.method) &&
|
|
68
|
+
!session.authMethod.scopes.includes(options.oauth?.writeScope ?? "mcp:write"))))
|
|
69
|
+
return yield* new HttpApiError.Forbidden({});
|
|
64
70
|
if (session?.session.impersonatedByOrganizationId &&
|
|
65
71
|
!isAllowedRoute(options.allowedOrganizationImpersonationRoutes ?? [], request)) {
|
|
66
72
|
return yield* new HttpApiError.Forbidden({});
|
|
@@ -72,7 +78,7 @@ const sessionAnnotations = (session) => {
|
|
|
72
78
|
if (!session)
|
|
73
79
|
return attributes;
|
|
74
80
|
if (session.user &&
|
|
75
|
-
(session.authMethod.type
|
|
81
|
+
(session.authMethod.type !== "apiKey" ||
|
|
76
82
|
session.authMethod.apiKey.configId === "user")) {
|
|
77
83
|
attributes["user.id"] = session.user.id;
|
|
78
84
|
attributes["user.full_name"] = session.user.name;
|
|
@@ -81,10 +87,14 @@ const sessionAnnotations = (session) => {
|
|
|
81
87
|
if (session.session.activeOrganizationId) {
|
|
82
88
|
attributes["organization.id"] = session.session.activeOrganizationId;
|
|
83
89
|
}
|
|
84
|
-
if (session.authMethod.type
|
|
90
|
+
if (session.authMethod.type !== "apiKey" && session.user) {
|
|
85
91
|
attributes["app.actor.type"] = "user";
|
|
86
92
|
attributes["app.actor.id"] = session.user.id;
|
|
87
|
-
attributes["app.auth.method"] =
|
|
93
|
+
attributes["app.auth.method"] =
|
|
94
|
+
session.authMethod.type === "oauth" ? "oauth" : "session";
|
|
95
|
+
if (session.authMethod.type === "oauth") {
|
|
96
|
+
attributes["app.auth.client.id"] = session.authMethod.clientId;
|
|
97
|
+
}
|
|
88
98
|
if (session.session.impersonatedBy) {
|
|
89
99
|
attributes["app.auth.impersonator.id"] = session.session.impersonatedBy;
|
|
90
100
|
}
|
|
@@ -5,7 +5,7 @@ import { AuthWebhookCleanupError, AuthWebhookConfigurationError, receiveAuthWebh
|
|
|
5
5
|
export const makeAuthWebhookLayer = (options) => Layer.unwrap(Effect.gen(function* () {
|
|
6
6
|
const receiver = yield* WebhooksReceiver;
|
|
7
7
|
const services = yield* Effect.context();
|
|
8
|
-
const projectId = yield* Schema.
|
|
8
|
+
const projectId = yield* Schema.decodeEffect(Schema.NonEmptyString)(options.projectId ??
|
|
9
9
|
(yield* Config.NonEmptyString("VITE_KRAKSTACK_AUTH_PROJECT_ID")));
|
|
10
10
|
const secret = options.webhookSecret ??
|
|
11
11
|
(yield* Config.Redacted("KRAKSTACK_AUTH_WEBHOOK_SECRET"));
|
|
@@ -30,8 +30,12 @@ export const makeAuthWebhookLayer = (options) => Layer.unwrap(Effect.gen(functio
|
|
|
30
30
|
: undefined,
|
|
31
31
|
}).pipe(Effect.provideService(WebhooksReceiver, receiver));
|
|
32
32
|
return HttpServerResponse.empty({ status: 204 });
|
|
33
|
-
}).pipe(Effect.provideService(HttpServerRequest.MaxBodySize, ByteSize.kibibytes(16)), Effect.
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
}).pipe(Effect.provideService(HttpServerRequest.MaxBodySize, ByteSize.kibibytes(16)), Effect.catchTags({
|
|
34
|
+
WebhookVerificationError: (error) => Effect.succeed(HttpServerResponse.empty({
|
|
35
|
+
status: error.reason === "payload" ? 400 : 401,
|
|
36
|
+
})),
|
|
37
|
+
WebhookReceiptConflict: () => Effect.succeed(HttpServerResponse.empty({ status: 409 })),
|
|
38
|
+
UnsupportedAuthWebhook: () => Effect.succeed(HttpServerResponse.empty({ status: 400 })),
|
|
39
|
+
}), Effect.orElseSucceed(() => HttpServerResponse.empty({ status: 500 })));
|
|
36
40
|
return HttpRouter.add("POST", "/api/webhooks/auth", handle);
|
|
37
41
|
})).pipe(Layer.provide(WebhooksReceiver.layer));
|
|
@@ -6,13 +6,19 @@ export { OrganizationDeletionData, OrganizationDeletionWebhook, } from "../schem
|
|
|
6
6
|
export { AuthWebhook, AuthWebhookData } from "../schema.js";
|
|
7
7
|
declare const AuthWebhookConfigurationError_base: Schema.Class<AuthWebhookConfigurationError, Schema.TaggedStruct<"AuthWebhookConfigurationError", {
|
|
8
8
|
readonly message: Schema.String;
|
|
9
|
-
}>, import("effect/Cause").YieldableError
|
|
9
|
+
}>, import("effect/Cause").YieldableError & {
|
|
10
|
+
readonly brand: unique symbol;
|
|
11
|
+
}>;
|
|
10
12
|
export declare class AuthWebhookConfigurationError extends AuthWebhookConfigurationError_base {
|
|
11
13
|
}
|
|
12
|
-
declare const AuthWebhookCleanupError_base: Schema.Class<AuthWebhookCleanupError, Schema.TaggedStruct<"AuthWebhookCleanupError", {}>, import("effect/Cause").YieldableError
|
|
14
|
+
declare const AuthWebhookCleanupError_base: Schema.Class<AuthWebhookCleanupError, Schema.TaggedStruct<"AuthWebhookCleanupError", {}>, import("effect/Cause").YieldableError & {
|
|
15
|
+
readonly brand: unique symbol;
|
|
16
|
+
}>;
|
|
13
17
|
export declare class AuthWebhookCleanupError extends AuthWebhookCleanupError_base {
|
|
14
18
|
}
|
|
15
|
-
declare const UnsupportedAuthWebhook_base: Schema.Class<UnsupportedAuthWebhook, Schema.TaggedStruct<"UnsupportedAuthWebhook", {}>, import("effect/Cause").YieldableError
|
|
19
|
+
declare const UnsupportedAuthWebhook_base: Schema.Class<UnsupportedAuthWebhook, Schema.TaggedStruct<"UnsupportedAuthWebhook", {}>, import("effect/Cause").YieldableError & {
|
|
20
|
+
readonly brand: unique symbol;
|
|
21
|
+
}>;
|
|
16
22
|
export declare class UnsupportedAuthWebhook extends UnsupportedAuthWebhook_base {
|
|
17
23
|
}
|
|
18
24
|
/** Acknowledge only after the app's same-database cleanup has committed. */
|
package/dist/service.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { HttpApiError } from "effect/http-api";
|
|
|
5
5
|
import { AuthClientConfig, type ClientConfig } from "./config.js";
|
|
6
6
|
import { ExtraVerifiedApiKey } from "./extra/schema.js";
|
|
7
7
|
import type { Session, User } from "./schema.js";
|
|
8
|
+
import type { OAuthResourceOptions } from "./oauth/schema.js";
|
|
8
9
|
type ExtraVerifiedApiKeyType = typeof ExtraVerifiedApiKey.Type;
|
|
9
10
|
export type AuthSession = {
|
|
10
11
|
readonly session: Session;
|
|
@@ -12,6 +13,10 @@ export type AuthSession = {
|
|
|
12
13
|
readonly isSuperAdminImpersonation: false;
|
|
13
14
|
readonly authMethod: {
|
|
14
15
|
readonly type: "cookie";
|
|
16
|
+
} | {
|
|
17
|
+
readonly type: "oauth";
|
|
18
|
+
readonly clientId: string;
|
|
19
|
+
readonly scopes: readonly string[];
|
|
15
20
|
} | {
|
|
16
21
|
readonly type: "apiKey";
|
|
17
22
|
readonly apiKey: ExtraVerifiedApiKeyType;
|
|
@@ -27,15 +32,16 @@ export type AuthSessionWithUser = AuthSession & {
|
|
|
27
32
|
};
|
|
28
33
|
export type AuthSessionWithUserAndOrganization = AuthSessionWithUser & AuthSessionWithOrganization;
|
|
29
34
|
export type AuthServiceLayerOptions = Partial<ClientConfig> & {
|
|
35
|
+
readonly oauth?: OAuthResourceOptions;
|
|
30
36
|
readonly headers?: Record<string, string>;
|
|
31
37
|
readonly apiKeyConfigId?: "user" | "organization" | "service";
|
|
32
38
|
};
|
|
33
39
|
declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/auth/AuthService", {
|
|
34
|
-
getSession: () => Effect.Effect<AuthSession | null, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
35
|
-
requireSession: () => Effect.Effect<AuthSession, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
36
|
-
requireUser: () => Effect.Effect<AuthSessionWithUser, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
37
|
-
requireOrganization: () => Effect.Effect<AuthSessionWithOrganization, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
38
|
-
requireUserOrganization: () => Effect.Effect<AuthSessionWithUserAndOrganization, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
40
|
+
getSession: () => Effect.Effect<AuthSession | null, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
|
|
41
|
+
requireSession: () => Effect.Effect<AuthSession, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
|
|
42
|
+
requireUser: () => Effect.Effect<AuthSessionWithUser, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
|
|
43
|
+
requireOrganization: () => Effect.Effect<AuthSessionWithOrganization, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
|
|
44
|
+
requireUserOrganization: () => Effect.Effect<AuthSessionWithUserAndOrganization, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
|
|
39
45
|
getActiveMemberRole: (input: {
|
|
40
46
|
readonly organizationId: string;
|
|
41
47
|
readonly userId: string;
|
|
@@ -44,7 +50,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
44
50
|
readonly adminBanUser: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"adminBanUser", "POST", "/api/auth/admin/ban-user", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
45
51
|
readonly userId: import("effect/Schema").String;
|
|
46
52
|
readonly banReason: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
47
|
-
readonly banExpiresIn: import("effect/Schema").optional<import("effect/Schema").
|
|
53
|
+
readonly banExpiresIn: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
48
54
|
}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
49
55
|
readonly user: import("effect/Schema").Struct<{
|
|
50
56
|
readonly id: import("effect/Schema").String;
|
|
@@ -284,8 +290,8 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
284
290
|
readonly apiKeyList: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"apiKeyList", "GET", "/api/auth/api-key/list", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
285
291
|
readonly configId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
286
292
|
readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
287
|
-
readonly limit: import("effect/Schema").optional<import("effect/Schema").
|
|
288
|
-
readonly offset: import("effect/Schema").optional<import("effect/Schema").
|
|
293
|
+
readonly limit: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
|
|
294
|
+
readonly offset: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
|
|
289
295
|
readonly sortBy: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
290
296
|
readonly sortDirection: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["asc", "desc"]>>;
|
|
291
297
|
}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
@@ -297,15 +303,15 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
297
303
|
readonly userId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
298
304
|
readonly referenceId: import("effect/Schema").String;
|
|
299
305
|
readonly configId: import("effect/Schema").String;
|
|
300
|
-
readonly refillInterval: import("effect/Schema").NullOr<import("effect/Schema").
|
|
301
|
-
readonly refillAmount: import("effect/Schema").NullOr<import("effect/Schema").
|
|
306
|
+
readonly refillInterval: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
|
|
307
|
+
readonly refillAmount: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
|
|
302
308
|
readonly lastRefillAt: import("effect/Schema").NullOr<import("effect/Schema").DateFromString>;
|
|
303
309
|
readonly enabled: import("effect/Schema").Boolean;
|
|
304
310
|
readonly rateLimitEnabled: import("effect/Schema").Boolean;
|
|
305
|
-
readonly rateLimitTimeWindow: import("effect/Schema").NullOr<import("effect/Schema").
|
|
306
|
-
readonly rateLimitMax: import("effect/Schema").NullOr<import("effect/Schema").
|
|
307
|
-
readonly requestCount: import("effect/Schema").
|
|
308
|
-
readonly remaining: import("effect/Schema").NullOr<import("effect/Schema").
|
|
311
|
+
readonly rateLimitTimeWindow: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
|
|
312
|
+
readonly rateLimitMax: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
|
|
313
|
+
readonly requestCount: import("effect/Schema").Finite;
|
|
314
|
+
readonly remaining: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
|
|
309
315
|
readonly lastRequest: import("effect/Schema").NullOr<import("effect/Schema").DateFromString>;
|
|
310
316
|
readonly expiresAt: import("effect/Schema").NullOr<import("effect/Schema").DateFromString>;
|
|
311
317
|
readonly createdAt: import("effect/Schema").DateFromString;
|
|
@@ -314,9 +320,9 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
314
320
|
readonly permissions: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>>;
|
|
315
321
|
readonly referrers: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").$Array<import("effect/Schema").String>>>;
|
|
316
322
|
}>>;
|
|
317
|
-
readonly total: import("effect/Schema").
|
|
318
|
-
readonly limit: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").
|
|
319
|
-
readonly offset: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").
|
|
323
|
+
readonly total: import("effect/Schema").Finite;
|
|
324
|
+
readonly limit: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Finite>>;
|
|
325
|
+
readonly offset: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Finite>>;
|
|
320
326
|
}>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
|
|
321
327
|
readonly changePassword: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"changePassword", "POST", "/api/auth/change-password", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
322
328
|
readonly newPassword: import("effect/Schema").String;
|
|
@@ -614,7 +620,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
614
620
|
readonly organizationGetFull: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationGetFull", "GET", "/api/auth/organization/get-full-organization", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
615
621
|
readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
616
622
|
readonly organizationSlug: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
617
|
-
readonly membersLimit: import("effect/Schema").optional<import("effect/Schema").
|
|
623
|
+
readonly membersLimit: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
|
|
618
624
|
}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").NullOr<import("effect/Schema").Struct<{
|
|
619
625
|
readonly id: import("effect/Schema").String;
|
|
620
626
|
readonly name: import("effect/Schema").String;
|
|
@@ -702,7 +708,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
702
708
|
readonly organizationId: import("effect/Schema").NonEmptyString;
|
|
703
709
|
readonly actorUserId: import("effect/Schema").NonEmptyString;
|
|
704
710
|
readonly targetUserId: import("effect/Schema").NonEmptyString;
|
|
705
|
-
readonly expiresInSeconds: import("effect/Schema").optional<import("effect/Schema").
|
|
711
|
+
readonly expiresInSeconds: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
706
712
|
}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
707
713
|
readonly session: import("effect/Schema").Struct<{
|
|
708
714
|
readonly id: import("effect/Schema").String;
|
|
@@ -818,8 +824,8 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
818
824
|
readonly createdAt: import("effect/Schema").optional<import("effect/Schema").DateFromString>;
|
|
819
825
|
}>>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
|
|
820
826
|
readonly organizationListMembers: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationListMembers", "GET", "/api/auth/organization/list-members", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
821
|
-
readonly limit: import("effect/Schema").optional<import("effect/Schema").
|
|
822
|
-
readonly offset: import("effect/Schema").optional<import("effect/Schema").
|
|
827
|
+
readonly limit: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
|
|
828
|
+
readonly offset: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
|
|
823
829
|
readonly sortBy: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
824
830
|
readonly sortDirection: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["asc", "desc"]>>;
|
|
825
831
|
readonly filterField: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
@@ -873,7 +879,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
873
879
|
}>, import("effect/Schema").Unknown, never, never>>>;
|
|
874
880
|
}>;
|
|
875
881
|
}>>;
|
|
876
|
-
readonly total: import("effect/Schema").
|
|
882
|
+
readonly total: import("effect/Schema").Finite;
|
|
877
883
|
}>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
|
|
878
884
|
readonly organizationListUserInvitations: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationListUserInvitations", "GET", "/api/auth/organization/list-user-invitations", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
879
885
|
readonly id: import("effect/Schema").String;
|
|
@@ -1114,7 +1120,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
1114
1120
|
readonly nonce: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
1115
1121
|
readonly accessToken: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
1116
1122
|
readonly refreshToken: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
1117
|
-
readonly expiresAt: import("effect/Schema").optional<import("effect/Schema").
|
|
1123
|
+
readonly expiresAt: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
1118
1124
|
readonly user: import("effect/Schema").optional<import("effect/Schema").Struct<{
|
|
1119
1125
|
readonly name: import("effect/Schema").optional<import("effect/Schema").Struct<{
|
|
1120
1126
|
readonly firstName: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
@@ -2113,11 +2119,11 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
2113
2119
|
};
|
|
2114
2120
|
}> & {
|
|
2115
2121
|
readonly make: (options?: AuthServiceLayerOptions) => Effect.Effect<{
|
|
2116
|
-
getSession: () => Effect.Effect<AuthSession | null, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
2117
|
-
requireSession: () => Effect.Effect<AuthSession, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
2118
|
-
requireUser: () => Effect.Effect<AuthSessionWithUser, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
2119
|
-
requireOrganization: () => Effect.Effect<AuthSessionWithOrganization, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
2120
|
-
requireUserOrganization: () => Effect.Effect<AuthSessionWithUserAndOrganization, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
2122
|
+
getSession: () => Effect.Effect<AuthSession | null, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
|
|
2123
|
+
requireSession: () => Effect.Effect<AuthSession, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
|
|
2124
|
+
requireUser: () => Effect.Effect<AuthSessionWithUser, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
|
|
2125
|
+
requireOrganization: () => Effect.Effect<AuthSessionWithOrganization, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
|
|
2126
|
+
requireUserOrganization: () => Effect.Effect<AuthSessionWithUserAndOrganization, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
|
|
2121
2127
|
getActiveMemberRole: (input: {
|
|
2122
2128
|
readonly organizationId: string;
|
|
2123
2129
|
readonly userId: string;
|
|
@@ -2126,7 +2132,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
2126
2132
|
readonly adminBanUser: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"adminBanUser", "POST", "/api/auth/admin/ban-user", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
2127
2133
|
readonly userId: import("effect/Schema").String;
|
|
2128
2134
|
readonly banReason: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
2129
|
-
readonly banExpiresIn: import("effect/Schema").optional<import("effect/Schema").
|
|
2135
|
+
readonly banExpiresIn: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
2130
2136
|
}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
2131
2137
|
readonly user: import("effect/Schema").Struct<{
|
|
2132
2138
|
readonly id: import("effect/Schema").String;
|
|
@@ -2366,8 +2372,8 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
2366
2372
|
readonly apiKeyList: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"apiKeyList", "GET", "/api/auth/api-key/list", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
2367
2373
|
readonly configId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
2368
2374
|
readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
2369
|
-
readonly limit: import("effect/Schema").optional<import("effect/Schema").
|
|
2370
|
-
readonly offset: import("effect/Schema").optional<import("effect/Schema").
|
|
2375
|
+
readonly limit: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
|
|
2376
|
+
readonly offset: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
|
|
2371
2377
|
readonly sortBy: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
2372
2378
|
readonly sortDirection: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["asc", "desc"]>>;
|
|
2373
2379
|
}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
@@ -2379,15 +2385,15 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
2379
2385
|
readonly userId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
2380
2386
|
readonly referenceId: import("effect/Schema").String;
|
|
2381
2387
|
readonly configId: import("effect/Schema").String;
|
|
2382
|
-
readonly refillInterval: import("effect/Schema").NullOr<import("effect/Schema").
|
|
2383
|
-
readonly refillAmount: import("effect/Schema").NullOr<import("effect/Schema").
|
|
2388
|
+
readonly refillInterval: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
|
|
2389
|
+
readonly refillAmount: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
|
|
2384
2390
|
readonly lastRefillAt: import("effect/Schema").NullOr<import("effect/Schema").DateFromString>;
|
|
2385
2391
|
readonly enabled: import("effect/Schema").Boolean;
|
|
2386
2392
|
readonly rateLimitEnabled: import("effect/Schema").Boolean;
|
|
2387
|
-
readonly rateLimitTimeWindow: import("effect/Schema").NullOr<import("effect/Schema").
|
|
2388
|
-
readonly rateLimitMax: import("effect/Schema").NullOr<import("effect/Schema").
|
|
2389
|
-
readonly requestCount: import("effect/Schema").
|
|
2390
|
-
readonly remaining: import("effect/Schema").NullOr<import("effect/Schema").
|
|
2393
|
+
readonly rateLimitTimeWindow: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
|
|
2394
|
+
readonly rateLimitMax: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
|
|
2395
|
+
readonly requestCount: import("effect/Schema").Finite;
|
|
2396
|
+
readonly remaining: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
|
|
2391
2397
|
readonly lastRequest: import("effect/Schema").NullOr<import("effect/Schema").DateFromString>;
|
|
2392
2398
|
readonly expiresAt: import("effect/Schema").NullOr<import("effect/Schema").DateFromString>;
|
|
2393
2399
|
readonly createdAt: import("effect/Schema").DateFromString;
|
|
@@ -2396,9 +2402,9 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
2396
2402
|
readonly permissions: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>>;
|
|
2397
2403
|
readonly referrers: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").$Array<import("effect/Schema").String>>>;
|
|
2398
2404
|
}>>;
|
|
2399
|
-
readonly total: import("effect/Schema").
|
|
2400
|
-
readonly limit: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").
|
|
2401
|
-
readonly offset: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").
|
|
2405
|
+
readonly total: import("effect/Schema").Finite;
|
|
2406
|
+
readonly limit: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Finite>>;
|
|
2407
|
+
readonly offset: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Finite>>;
|
|
2402
2408
|
}>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
|
|
2403
2409
|
readonly changePassword: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"changePassword", "POST", "/api/auth/change-password", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
2404
2410
|
readonly newPassword: import("effect/Schema").String;
|
|
@@ -2696,7 +2702,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
2696
2702
|
readonly organizationGetFull: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationGetFull", "GET", "/api/auth/organization/get-full-organization", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
2697
2703
|
readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
2698
2704
|
readonly organizationSlug: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
2699
|
-
readonly membersLimit: import("effect/Schema").optional<import("effect/Schema").
|
|
2705
|
+
readonly membersLimit: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
|
|
2700
2706
|
}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").NullOr<import("effect/Schema").Struct<{
|
|
2701
2707
|
readonly id: import("effect/Schema").String;
|
|
2702
2708
|
readonly name: import("effect/Schema").String;
|
|
@@ -2784,7 +2790,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
2784
2790
|
readonly organizationId: import("effect/Schema").NonEmptyString;
|
|
2785
2791
|
readonly actorUserId: import("effect/Schema").NonEmptyString;
|
|
2786
2792
|
readonly targetUserId: import("effect/Schema").NonEmptyString;
|
|
2787
|
-
readonly expiresInSeconds: import("effect/Schema").optional<import("effect/Schema").
|
|
2793
|
+
readonly expiresInSeconds: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
2788
2794
|
}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
2789
2795
|
readonly session: import("effect/Schema").Struct<{
|
|
2790
2796
|
readonly id: import("effect/Schema").String;
|
|
@@ -2900,8 +2906,8 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
2900
2906
|
readonly createdAt: import("effect/Schema").optional<import("effect/Schema").DateFromString>;
|
|
2901
2907
|
}>>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
|
|
2902
2908
|
readonly organizationListMembers: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationListMembers", "GET", "/api/auth/organization/list-members", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
2903
|
-
readonly limit: import("effect/Schema").optional<import("effect/Schema").
|
|
2904
|
-
readonly offset: import("effect/Schema").optional<import("effect/Schema").
|
|
2909
|
+
readonly limit: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
|
|
2910
|
+
readonly offset: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
|
|
2905
2911
|
readonly sortBy: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
2906
2912
|
readonly sortDirection: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["asc", "desc"]>>;
|
|
2907
2913
|
readonly filterField: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
@@ -2955,7 +2961,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
2955
2961
|
}>, import("effect/Schema").Unknown, never, never>>>;
|
|
2956
2962
|
}>;
|
|
2957
2963
|
}>>;
|
|
2958
|
-
readonly total: import("effect/Schema").
|
|
2964
|
+
readonly total: import("effect/Schema").Finite;
|
|
2959
2965
|
}>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
|
|
2960
2966
|
readonly organizationListUserInvitations: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationListUserInvitations", "GET", "/api/auth/organization/list-user-invitations", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
2961
2967
|
readonly id: import("effect/Schema").String;
|
|
@@ -3196,7 +3202,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
3196
3202
|
readonly nonce: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
3197
3203
|
readonly accessToken: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
3198
3204
|
readonly refreshToken: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
3199
|
-
readonly expiresAt: import("effect/Schema").optional<import("effect/Schema").
|
|
3205
|
+
readonly expiresAt: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
3200
3206
|
readonly user: import("effect/Schema").optional<import("effect/Schema").Struct<{
|
|
3201
3207
|
readonly name: import("effect/Schema").optional<import("effect/Schema").Struct<{
|
|
3202
3208
|
readonly firstName: import("effect/Schema").optional<import("effect/Schema").String>;
|
package/dist/service.js
CHANGED
|
@@ -51,7 +51,7 @@ class SessionLookup extends Context.Service()("@krak-stack/auth/SessionLookup")
|
|
|
51
51
|
}
|
|
52
52
|
const sessionCache = Effect.runSync(Cache.makeWith(() => Effect.gen(function* () {
|
|
53
53
|
const lookup = yield* SessionLookup;
|
|
54
|
-
return yield* lookup.getSession
|
|
54
|
+
return yield* lookup.getSession;
|
|
55
55
|
}), {
|
|
56
56
|
capacity: 500,
|
|
57
57
|
timeToLive: (exit) => Exit.isSuccess(exit) ? Duration.seconds(2) : Duration.zero,
|
|
@@ -72,10 +72,13 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
|
|
|
72
72
|
});
|
|
73
73
|
const sessionCacheKey = getSessionCacheKey(headers);
|
|
74
74
|
const apiKey = headerValue(headers, "x-api-key")?.trim();
|
|
75
|
+
const authorization = headerValue(headers, "authorization");
|
|
75
76
|
const organizationId = headerValue(headers, "x-organization-id")?.trim();
|
|
76
77
|
const getCookieSession = () => Cache.get(sessionCache, sessionCacheKey).pipe(Effect.provideService(SessionLookup, {
|
|
77
|
-
getSession:
|
|
78
|
-
|
|
78
|
+
getSession: api.auth
|
|
79
|
+
.getSession({ query: {} })
|
|
80
|
+
.pipe(Effect.mapError(serviceUnavailable)),
|
|
81
|
+
}), Effect.map((authSession) => authSession
|
|
79
82
|
? {
|
|
80
83
|
...authSession,
|
|
81
84
|
isSuperAdminImpersonation: false,
|
|
@@ -84,7 +87,7 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
|
|
|
84
87
|
: null));
|
|
85
88
|
const userForApiKey = (verifiedKey) => {
|
|
86
89
|
if (verifiedKey.configId === "organization") {
|
|
87
|
-
return Effect.
|
|
90
|
+
return Effect.undefined;
|
|
88
91
|
}
|
|
89
92
|
return api.users
|
|
90
93
|
.getUser({ params: { id: verifiedKey.referenceId } })
|
|
@@ -111,7 +114,7 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
|
|
|
111
114
|
.verifyApiKey({ payload: verifyPayload })
|
|
112
115
|
.pipe(Effect.mapError(serviceUnavailable));
|
|
113
116
|
if (!verified.valid || !verified.key) {
|
|
114
|
-
return yield*
|
|
117
|
+
return yield* unauthorized();
|
|
115
118
|
}
|
|
116
119
|
const user = yield* userForApiKey(verified.key);
|
|
117
120
|
const activeOrganization = yield* activeOrganizationIdForApiKey(verified.key, user);
|
|
@@ -134,10 +137,54 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
|
|
|
134
137
|
},
|
|
135
138
|
};
|
|
136
139
|
});
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
140
|
+
const getOAuthSession = () => Effect.gen(function* () {
|
|
141
|
+
// An explicit Authorization header must never downgrade to cookies
|
|
142
|
+
// or an API key, even if OAuth is not configured for this service.
|
|
143
|
+
const match = authorization?.match(/^Bearer ([^\s]+)$/i);
|
|
144
|
+
if (!options.oauth || !match?.[1])
|
|
145
|
+
return yield* unauthorized();
|
|
146
|
+
const { verifyOAuthAccessToken } = yield* Effect.promise(() => import("./oauth/verify.js"));
|
|
147
|
+
const claims = yield* verifyOAuthAccessToken(match[1], options.oauth).pipe(Effect.provideService(HttpClient.HttpClient, http));
|
|
148
|
+
const user = yield* api.users
|
|
149
|
+
.getUser({ params: { id: claims.sub } })
|
|
150
|
+
.pipe(Effect.mapError(serviceUnavailable));
|
|
151
|
+
if (user.banned)
|
|
152
|
+
return yield* unauthorized();
|
|
153
|
+
// Consent binds the organization. A caller header or a later browser
|
|
154
|
+
// organization switch must not change the grant's tenant.
|
|
155
|
+
yield* api.organizations
|
|
156
|
+
.getActiveMember({
|
|
157
|
+
params: {
|
|
158
|
+
organizationId: claims.organization_id,
|
|
159
|
+
userId: user.id,
|
|
160
|
+
},
|
|
161
|
+
})
|
|
162
|
+
.pipe(Effect.mapError(() => new HttpApiError.Forbidden({})));
|
|
163
|
+
return {
|
|
164
|
+
session: {
|
|
165
|
+
id: `oauth:${claims.azp}:${claims.sub}`,
|
|
166
|
+
token: "",
|
|
167
|
+
userId: user.id,
|
|
168
|
+
activeOrganizationId: claims.organization_id,
|
|
169
|
+
createdAt: new Date(claims.iat * 1000),
|
|
170
|
+
updatedAt: new Date(claims.iat * 1000),
|
|
171
|
+
expiresAt: new Date(claims.exp * 1000),
|
|
172
|
+
},
|
|
173
|
+
user,
|
|
174
|
+
isSuperAdminImpersonation: false,
|
|
175
|
+
authMethod: {
|
|
176
|
+
type: "oauth",
|
|
177
|
+
clientId: claims.azp,
|
|
178
|
+
scopes: claims.scope.split(/\s+/).filter(Boolean),
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
const getSession = () => authorization !== undefined
|
|
183
|
+
? getOAuthSession()
|
|
184
|
+
: apiKey
|
|
185
|
+
? getApiKeySession(apiKey)
|
|
186
|
+
: getCookieSession();
|
|
187
|
+
const requireSession = () => getSession().pipe(Effect.filterOrFail((authSession) => authSession !== null, () => unauthorized()));
|
|
141
188
|
const requireUser = () => requireSession().pipe(Effect.flatMap((authSession) => authSession.user
|
|
142
189
|
? Effect.succeed({ ...authSession, user: authSession.user })
|
|
143
190
|
: Effect.fail(unauthorized())));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krak-stack/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Effect HttpApi clients and schemas for KrakStack Auth.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"prepack": "bun run build"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
+
"@better-auth/core": "1.7.6",
|
|
78
79
|
"@effect/atom-react": "^4.1.0",
|
|
79
80
|
"@lucas-barake/effect-form-react": "1.1.0",
|
|
80
81
|
"react-qr-code": "^2.2.0"
|