@krak-stack/auth 0.2.32 → 0.3.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +101 -5
  3. package/dist/access.d.ts +3 -1
  4. package/dist/admin/api.group.d.ts +41 -41
  5. package/dist/admin/schema.d.ts +23 -23
  6. package/dist/admin/schema.js +21 -19
  7. package/dist/api.d.ts +126 -77
  8. package/dist/auth/api.group.d.ts +18 -18
  9. package/dist/auth/schema.d.ts +49 -33
  10. package/dist/auth/schema.js +18 -18
  11. package/dist/components/admin-organization-form.js +2 -2
  12. package/dist/components/admin-organizations.js +6 -5
  13. package/dist/components/admin-users.js +6 -6
  14. package/dist/components/api-key-edit-form.js +19 -11
  15. package/dist/components/associated-projects-notice.d.ts +2 -1
  16. package/dist/components/associated-projects-notice.js +6 -2
  17. package/dist/components/auth-atoms.js +1 -2
  18. package/dist/components/auth-client-api.d.ts +61 -61
  19. package/dist/components/auth-forms.d.ts +1 -0
  20. package/dist/components/auth-forms.js +41 -56
  21. package/dist/components/auth-provider.d.ts +3 -1
  22. package/dist/components/hooks.d.ts +2 -0
  23. package/dist/components/hooks.js +13 -6
  24. package/dist/components/index.d.ts +3 -0
  25. package/dist/components/index.js +2 -0
  26. package/dist/components/member-required.js +3 -5
  27. package/dist/components/oauth-consent.d.ts +22 -0
  28. package/dist/components/oauth-consent.js +79 -0
  29. package/dist/components/organization-switcher.d.ts +1 -1
  30. package/dist/components/organization-switcher.js +83 -54
  31. package/dist/components/project-card-list.d.ts +6 -0
  32. package/dist/components/project-card-list.js +4 -0
  33. package/dist/components/user-button.js +115 -54
  34. package/dist/extra/schema.d.ts +3 -1
  35. package/dist/oauth/authorization.d.ts +3 -0
  36. package/dist/oauth/authorization.js +39 -0
  37. package/dist/oauth/schema.d.ts +24 -0
  38. package/dist/oauth/schema.js +12 -0
  39. package/dist/oauth/verify.d.ts +13 -0
  40. package/dist/oauth/verify.js +67 -0
  41. package/dist/schema.js +1 -1
  42. package/dist/server/actor.js +2 -4
  43. package/dist/server/api.group.d.ts +49 -0
  44. package/dist/server/api.group.js +10 -1
  45. package/dist/server/index.d.ts +3 -1
  46. package/dist/server/index.js +2 -1
  47. package/dist/server/mcp.d.ts +20 -0
  48. package/dist/server/mcp.js +66 -0
  49. package/dist/server/middleware.d.ts +5 -5
  50. package/dist/server/middleware.js +15 -5
  51. package/dist/server/schema.d.ts +51 -0
  52. package/dist/server/schema.js +7 -0
  53. package/dist/server/webhook-layer.js +8 -4
  54. package/dist/server/webhooks.d.ts +9 -3
  55. package/dist/service.d.ts +152 -46
  56. package/dist/service.js +56 -9
  57. package/package.json +2 -1
@@ -1,4 +1,6 @@
1
1
  export { AuthService } from "../service.js";
2
+ export type { OAuthResourceOptions } from "../oauth/schema.js";
3
+ export { McpAuth } from "./mcp.js";
2
4
  export { AccountDeletionData, AccountDeletionWebhook, OrganizationDeletionData, OrganizationDeletionWebhook, AuthWebhook, AuthWebhookData, } from "../schema.js";
3
5
  export type { AuthSession, AuthSessionWithOrganization, AuthSessionWithUser, AuthSessionWithUserAndOrganization, } from "../service.js";
4
6
  export { AuthClientConfig } from "../config.js";
@@ -10,7 +12,7 @@ export { ActorRequired } from "./actor.js";
10
12
  export type { ActorConstraint } from "./actor.js";
11
13
  export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware.js";
12
14
  export type { AuthMiddlewareOptions, AuthenticationLiveOptions, AuthRouterOptions, } from "./middleware.js";
13
- export { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerMembersResponse, ServerOrganizationChildrenResponse, ServerOrganizationsResponse, ServerUpdateDomainPayload, ServerUsersResponse, } from "./schema.js";
15
+ export { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerMembersResponse, ServerOrganizationChildrenResponse, ServerOrganizationsResponse, ServerUpdateDomainPayload, ServerUsersResponse, ServerEmailsQuery, ServerUsersByEmailsResponse, } from "./schema.js";
14
16
  export type { Member, Organization, OrganizationMetadata, User, } from "../schema.js";
15
17
  export { ApiKeyPermissionGrant, CurrentActor, Forbidden, all, actorUserId, any, defineProjectAccess, permission, policy, withPolicy, } from "../access.js";
16
18
  export type { ApiKeyOwner, ApiKeyActor, Actor, Policy, ProjectAccessConfig, ProjectAccessCatalog, ProjectAccessDefinition, UserActor, } from "../access.js";
@@ -1,4 +1,5 @@
1
1
  export { AuthService } from "../service.js";
2
+ export { McpAuth } from "./mcp.js";
2
3
  export { AccountDeletionData, AccountDeletionWebhook, OrganizationDeletionData, OrganizationDeletionWebhook, AuthWebhook, AuthWebhookData, } from "../schema.js";
3
4
  export { AuthClientConfig } from "../config.js";
4
5
  export { ServerDomainsApiGroup, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api.group.js";
@@ -6,5 +7,5 @@ export { proxyAuthHttpEffect, proxyAuthRequest, proxyAuthRequestEffect, } from "
6
7
  export { AuthProxyError, authProxyKeyHeader, proxyOriginHeaders, readProxyOrigin, stripProxyOriginHeaders, } from "./proxy-origin.js";
7
8
  export { ActorRequired } from "./actor.js";
8
9
  export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware.js";
9
- export { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerMembersResponse, ServerOrganizationChildrenResponse, ServerOrganizationsResponse, ServerUpdateDomainPayload, ServerUsersResponse, } from "./schema.js";
10
+ export { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerMembersResponse, ServerOrganizationChildrenResponse, ServerOrganizationsResponse, ServerUpdateDomainPayload, ServerUsersResponse, ServerEmailsQuery, ServerUsersByEmailsResponse, } from "./schema.js";
10
11
  export { ApiKeyPermissionGrant, CurrentActor, Forbidden, all, actorUserId, any, defineProjectAccess, permission, policy, withPolicy, } from "../access.js";
@@ -0,0 +1,20 @@
1
+ import { Layer } from "effect";
2
+ import { HttpRouter } from "effect/http";
3
+ import type { OAuthResourceOptions } from "../oauth/schema.js";
4
+ declare const metadataPath: (resource: string) => `/${string}`;
5
+ /** OAuth discovery and authentication for an existing MCP transport. */
6
+ export declare const McpAuth: {
7
+ metadataPath: typeof metadataPath;
8
+ /** Forward public discovery through the consumer's existing auth proxy. */
9
+ discoveryRequest: (request: Request, options: OAuthResourceOptions) => Request | undefined;
10
+ metadataLayer: (options: OAuthResourceOptions) => Layer.Layer<never, never, HttpRouter.HttpRouter>;
11
+ middleware: (options: OAuthResourceOptions) => HttpRouter.Middleware<{
12
+ provides: never;
13
+ handles: never;
14
+ error: never;
15
+ requires: never;
16
+ layerError: never;
17
+ layerRequires: never;
18
+ }>;
19
+ };
20
+ export {};
@@ -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, unknown, HttpServerRequest.HttpServerRequest>;
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, unknown>) => Layer.Layer<AuthMiddleware, never, never>;
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 auth = yield* AuthService.pipe(Effect.provide(authLayer ??
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
- })), Effect.tapCause((cause) => Effect.logError("Authentication rejected: auth client initialization failed", Cause.pretty(cause))), Effect.mapError(() => new HttpApiError.ServiceUnavailable({})));
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 === "cookie" ||
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 === "cookie" && session.user) {
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"] = "session";
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
  }
@@ -1,4 +1,55 @@
1
1
  import { Schema } from "effect";
2
+ export declare const ServerEmailsQuery: Schema.Struct<{
3
+ readonly emails: Schema.NonEmptyString;
4
+ }>;
5
+ export declare const ServerUsersByEmailsResponse: Schema.Struct<{
6
+ readonly data: Schema.$Array<Schema.Struct<{
7
+ readonly id: Schema.String;
8
+ readonly name: Schema.String;
9
+ readonly email: Schema.String;
10
+ readonly emailVerified: Schema.Boolean;
11
+ readonly locale: Schema.optional<Schema.Literals<readonly ["en", "fr"]>>;
12
+ readonly image: Schema.NullOr<Schema.String>;
13
+ readonly metadata: Schema.optional<Schema.NullOr<Schema.decodeTo<Schema.Struct<{
14
+ readonly emails: Schema.optional<Schema.$Array<Schema.Struct<{
15
+ readonly email: Schema.NonEmptyString;
16
+ readonly translations: Schema.$Array<Schema.Struct<{
17
+ readonly locale: Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>;
18
+ readonly label: Schema.NonEmptyString;
19
+ }>>;
20
+ }>>>;
21
+ readonly phones: Schema.optional<Schema.$Array<Schema.Struct<{
22
+ readonly number: Schema.NonEmptyString;
23
+ readonly extension: Schema.optional<Schema.String>;
24
+ readonly translations: Schema.$Array<Schema.Struct<{
25
+ readonly locale: Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>;
26
+ readonly label: Schema.NonEmptyString;
27
+ }>>;
28
+ }>>>;
29
+ readonly websites: Schema.optional<Schema.$Array<Schema.Struct<{
30
+ readonly url: Schema.NonEmptyString;
31
+ readonly translations: Schema.$Array<Schema.Struct<{
32
+ readonly locale: Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>;
33
+ readonly label: Schema.NonEmptyString;
34
+ }>>;
35
+ }>>>;
36
+ readonly socials: Schema.optional<Schema.$Array<Schema.Struct<{
37
+ readonly platform: Schema.Literals<readonly ["facebook", "github", "instagram", "linkedin", "tiktok", "x", "youtube"]>;
38
+ readonly url: Schema.NonEmptyString;
39
+ readonly translations: Schema.$Array<Schema.Struct<{
40
+ readonly locale: Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>;
41
+ readonly label: Schema.NonEmptyString;
42
+ }>>;
43
+ }>>>;
44
+ }>, Schema.Unknown, never, never>>>;
45
+ readonly role: Schema.NullOr<Schema.String>;
46
+ readonly banned: Schema.NullOr<Schema.Boolean>;
47
+ readonly lastLoginMethod: Schema.optional<Schema.NullOr<Schema.String>>;
48
+ readonly createdAt: Schema.Date;
49
+ readonly updatedAt: Schema.Date;
50
+ }>>;
51
+ readonly missingEmails: Schema.$Array<Schema.String>;
52
+ }>;
2
53
  export declare const AuthProxyOrigin: Schema.Struct<{
3
54
  readonly apiKey: Schema.RedactedFromValue<Schema.NonEmptyString>;
4
55
  readonly host: Schema.String;
@@ -1,5 +1,12 @@
1
1
  import { Schema } from "effect";
2
2
  import { Member, Organization, User } from "../schema.js";
3
+ export const ServerEmailsQuery = Schema.Struct({
4
+ emails: Schema.NonEmptyString,
5
+ }).annotate({ identifier: "ServerEmailsQuery" });
6
+ export const ServerUsersByEmailsResponse = Schema.Struct({
7
+ data: Schema.Array(User),
8
+ missingEmails: Schema.Array(Schema.String),
9
+ }).annotate({ identifier: "ServerUsersByEmailsResponse" });
3
10
  export const AuthProxyOrigin = Schema.Struct({
4
11
  apiKey: Schema.RedactedFromValue(Schema.NonEmptyString),
5
12
  host: Schema.String.check(Schema.isPattern(/^(?:[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?|\[[a-f0-9:]+\])(?::[0-9]{1,5})?$/)),
@@ -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.decodeUnknownEffect(Schema.NonEmptyString)(options.projectId ??
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.catchTag("WebhookVerificationError", (error) => Effect.succeed(HttpServerResponse.empty({
34
- status: error.reason === "payload" ? 400 : 401,
35
- }))), Effect.catchTag("WebhookReceiptConflict", () => Effect.succeed(HttpServerResponse.empty({ status: 409 }))), Effect.catchTag("UnsupportedAuthWebhook", () => Effect.succeed(HttpServerResponse.empty({ status: 400 }))), Effect.catch(() => Effect.succeed(HttpServerResponse.empty({ status: 500 }))));
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. */