@krak-stack/auth 0.2.31 → 0.2.32

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 (37) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +79 -1
  3. package/dist/api.d.ts +1453 -1393
  4. package/dist/auth/api.group.d.ts +19 -1
  5. package/dist/auth/api.group.js +17 -1
  6. package/dist/auth/schema.d.ts +12 -0
  7. package/dist/auth/schema.js +12 -0
  8. package/dist/components/account-deletion-request.d.ts +5 -0
  9. package/dist/components/account-deletion-request.js +7 -0
  10. package/dist/components/account-deletion.d.ts +8 -0
  11. package/dist/components/account-deletion.js +59 -0
  12. package/dist/components/admin-organizations.js +3 -2
  13. package/dist/components/associated-projects-notice.js +1 -1
  14. package/dist/components/auth-client-api.d.ts +33 -0
  15. package/dist/components/deletion-visibility.d.ts +1 -0
  16. package/dist/components/deletion-visibility.js +3 -0
  17. package/dist/components/organization-deletion-request.d.ts +17 -0
  18. package/dist/components/organization-deletion-request.js +9 -0
  19. package/dist/components/organization-switcher.js +31 -2
  20. package/dist/components/user-button.d.ts +29 -1
  21. package/dist/components/user-button.js +39 -2
  22. package/dist/extra/api.group.d.ts +13 -1
  23. package/dist/extra/api.group.js +5 -1
  24. package/dist/extra/schema.d.ts +13 -0
  25. package/dist/extra/schema.js +13 -0
  26. package/dist/schema.d.ts +35 -0
  27. package/dist/schema.js +25 -0
  28. package/dist/server/index.d.ts +2 -1
  29. package/dist/server/index.js +1 -0
  30. package/dist/server/middleware.d.ts +10 -2
  31. package/dist/server/middleware.js +4 -1
  32. package/dist/server/webhook-layer.d.ts +6 -0
  33. package/dist/server/webhook-layer.js +37 -0
  34. package/dist/server/webhooks.d.ts +38 -0
  35. package/dist/server/webhooks.js +39 -0
  36. package/dist/service.d.ts +66 -0
  37. package/package.json +7 -3
@@ -1,9 +1,13 @@
1
1
  import { Schema } from "effect";
2
2
  import { OpenApi } from "effect/http-api";
3
3
  import { HttpApiEndpoint, HttpApiError, HttpApiGroup } from "effect/http-api";
4
- import { ExtraBadRequest, ExtraAssociatedProjects, ExtraAssociatedProjectsQuery, ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraImageUploadMultipartPayload, ExtraOkResponse, ExtraOrganizationPublicProfile, ExtraOrganizationPublicProfileQuery, ExtraProjectPublicConfig, ExtraProjectPublicConfigQuery, ExtraSetPasswordPayload, ExtraUpdateApiKeyPayload, ExtraUploadedAsset, ExtraVerifyApiKeyPayload, ExtraVerifyApiKeyResponse, ExtraVerifyPasswordPayload, } from "./schema.js";
4
+ import { ExtraAccountDeletionPlan, ExtraBadRequest, ExtraAssociatedProjects, ExtraAssociatedProjectsQuery, ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraImageUploadMultipartPayload, ExtraOkResponse, ExtraOrganizationPublicProfile, ExtraOrganizationPublicProfileQuery, ExtraProjectPublicConfig, ExtraProjectPublicConfigQuery, ExtraSetPasswordPayload, ExtraUpdateApiKeyPayload, ExtraUploadedAsset, ExtraVerifyApiKeyPayload, ExtraVerifyApiKeyResponse, ExtraVerifyPasswordPayload, } from "./schema.js";
5
5
  export * from "./schema.js";
6
6
  export const ExtraApiGroup = HttpApiGroup.make("authExtra")
7
+ .add(HttpApiEndpoint.get("getAccountDeletionPlan", "/auth/account-deletion", {
8
+ success: ExtraAccountDeletionPlan,
9
+ error: [HttpApiError.Unauthorized, HttpApiError.Forbidden, HttpApiError.InternalServerError],
10
+ }))
7
11
  .add(HttpApiEndpoint.get("getProjectPublicConfig", "/auth/project-config", {
8
12
  query: ExtraProjectPublicConfigQuery.fields,
9
13
  success: ExtraProjectPublicConfig,
@@ -1,6 +1,19 @@
1
1
  import { Schema } from "effect";
2
2
  import { Multipart } from "effect/http";
3
3
  import { HttpApiSchema } from "effect/http-api";
4
+ export declare const ExtraAccountDeletionPlan: Schema.Struct<{
5
+ readonly projects: Schema.$Array<Schema.Struct<{
6
+ readonly id: Schema.String;
7
+ readonly name: Schema.String;
8
+ readonly ready: Schema.Boolean;
9
+ }>>;
10
+ readonly organizations: Schema.$Array<Schema.Struct<{
11
+ readonly id: Schema.String;
12
+ readonly name: Schema.String;
13
+ readonly personal: Schema.Boolean;
14
+ }>>;
15
+ readonly adminAccount: Schema.Boolean;
16
+ }>;
4
17
  export declare const ExtraImageUploadPayload: Schema.Struct<{
5
18
  readonly file: Schema.decodeTo<Multipart.PersistedFileSchema, Schema.$Array<Multipart.PersistedFileSchema>, never, never>;
6
19
  }>;
@@ -2,6 +2,19 @@ import { Schema } from "effect";
2
2
  import { Multipart } from "effect/http";
3
3
  import { HttpApiSchema } from "effect/http-api";
4
4
  import { OrganizationEmail, OrganizationLocale, OrganizationPhone, OrganizationSocial, OrganizationWebsite, FormattedOrganizationAddress, } from "../schema.js";
5
+ export const ExtraAccountDeletionPlan = Schema.Struct({
6
+ projects: Schema.Array(Schema.Struct({
7
+ id: Schema.String,
8
+ name: Schema.String,
9
+ ready: Schema.Boolean,
10
+ })),
11
+ organizations: Schema.Array(Schema.Struct({
12
+ id: Schema.String,
13
+ name: Schema.String,
14
+ personal: Schema.Boolean,
15
+ })),
16
+ adminAccount: Schema.Boolean,
17
+ }).annotate({ identifier: "ExtraAccountDeletionPlan" });
5
18
  export const ExtraImageUploadPayload = Schema.Struct({
6
19
  file: Multipart.SingleFileSchema,
7
20
  }).annotate({
package/dist/schema.d.ts CHANGED
@@ -1,4 +1,39 @@
1
1
  import { Schema } from "effect";
2
+ export declare const AuthWebhookData: Schema.StructWithRest<Schema.Struct<{
3
+ readonly projectId: Schema.NonEmptyString;
4
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
5
+ export declare const AuthWebhook: Schema.Struct<{
6
+ readonly event: Schema.NonEmptyString;
7
+ readonly data: Schema.StructWithRest<Schema.Struct<{
8
+ readonly projectId: Schema.NonEmptyString;
9
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
10
+ }>;
11
+ export declare const AccountDeletionData: Schema.Struct<{
12
+ readonly projectId: Schema.NonEmptyString;
13
+ readonly userId: Schema.NonEmptyString;
14
+ readonly scope: Schema.Literal<"account">;
15
+ }>;
16
+ export declare const AccountDeletionWebhook: Schema.Struct<{
17
+ readonly event: Schema.Literal<"user.deletion_requested">;
18
+ readonly data: Schema.Struct<{
19
+ readonly projectId: Schema.NonEmptyString;
20
+ readonly userId: Schema.NonEmptyString;
21
+ readonly scope: Schema.Literal<"account">;
22
+ }>;
23
+ }>;
24
+ export declare const OrganizationDeletionData: Schema.Struct<{
25
+ readonly projectId: Schema.NonEmptyString;
26
+ readonly organizationId: Schema.NonEmptyString;
27
+ readonly scope: Schema.Literal<"organization">;
28
+ }>;
29
+ export declare const OrganizationDeletionWebhook: Schema.Struct<{
30
+ readonly event: Schema.Literal<"organization.deletion_requested">;
31
+ readonly data: Schema.Struct<{
32
+ readonly projectId: Schema.NonEmptyString;
33
+ readonly organizationId: Schema.NonEmptyString;
34
+ readonly scope: Schema.Literal<"organization">;
35
+ }>;
36
+ }>;
2
37
  export declare const Session: Schema.Struct<{
3
38
  readonly id: Schema.String;
4
39
  readonly expiresAt: Schema.Date;
package/dist/schema.js CHANGED
@@ -1,4 +1,29 @@
1
1
  import { Option, Schema, SchemaGetter } from "effect";
2
+ export const AuthWebhookData = Schema.StructWithRest(Schema.Struct({
3
+ projectId: Schema.NonEmptyString,
4
+ }), [Schema.Record(Schema.String, Schema.Json)]).annotate({ identifier: "AuthWebhookData" });
5
+ export const AuthWebhook = Schema.Struct({
6
+ event: Schema.NonEmptyString,
7
+ data: AuthWebhookData,
8
+ }).annotate({ identifier: "AuthWebhook" });
9
+ export const AccountDeletionData = Schema.Struct({
10
+ projectId: Schema.NonEmptyString,
11
+ userId: Schema.NonEmptyString,
12
+ scope: Schema.Literal("account"),
13
+ }).annotate({ identifier: "AccountDeletionData" });
14
+ export const AccountDeletionWebhook = Schema.Struct({
15
+ event: Schema.Literal("user.deletion_requested"),
16
+ data: AccountDeletionData,
17
+ }).annotate({ identifier: "AccountDeletionWebhook" });
18
+ export const OrganizationDeletionData = Schema.Struct({
19
+ projectId: Schema.NonEmptyString,
20
+ organizationId: Schema.NonEmptyString,
21
+ scope: Schema.Literal("organization"),
22
+ }).annotate({ identifier: "OrganizationDeletionData" });
23
+ export const OrganizationDeletionWebhook = Schema.Struct({
24
+ event: Schema.Literal("organization.deletion_requested"),
25
+ data: OrganizationDeletionData,
26
+ }).annotate({ identifier: "OrganizationDeletionWebhook" });
2
27
  export const Session = Schema.Struct({
3
28
  id: Schema.String,
4
29
  expiresAt: Schema.Date,
@@ -1,4 +1,5 @@
1
1
  export { AuthService } from "../service.js";
2
+ export { AccountDeletionData, AccountDeletionWebhook, OrganizationDeletionData, OrganizationDeletionWebhook, AuthWebhook, AuthWebhookData, } from "../schema.js";
2
3
  export type { AuthSession, AuthSessionWithOrganization, AuthSessionWithUser, AuthSessionWithUserAndOrganization, } from "../service.js";
3
4
  export { AuthClientConfig } from "../config.js";
4
5
  export { ServerDomainsApiGroup, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api.group.js";
@@ -8,7 +9,7 @@ export { AuthProxyError, authProxyKeyHeader, proxyOriginHeaders, readProxyOrigin
8
9
  export { ActorRequired } from "./actor.js";
9
10
  export type { ActorConstraint } from "./actor.js";
10
11
  export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware.js";
11
- export type { AuthenticationLiveOptions, AuthRouterOptions, } from "./middleware.js";
12
+ export type { AuthMiddlewareOptions, AuthenticationLiveOptions, AuthRouterOptions, } from "./middleware.js";
12
13
  export { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerMembersResponse, ServerOrganizationChildrenResponse, ServerOrganizationsResponse, ServerUpdateDomainPayload, ServerUsersResponse, } from "./schema.js";
13
14
  export type { Member, Organization, OrganizationMetadata, User, } from "../schema.js";
14
15
  export { ApiKeyPermissionGrant, CurrentActor, Forbidden, all, actorUserId, any, defineProjectAccess, permission, policy, withPolicy, } from "../access.js";
@@ -1,4 +1,5 @@
1
1
  export { AuthService } from "../service.js";
2
+ export { AccountDeletionData, AccountDeletionWebhook, OrganizationDeletionData, OrganizationDeletionWebhook, AuthWebhook, AuthWebhookData, } from "../schema.js";
2
3
  export { AuthClientConfig } from "../config.js";
3
4
  export { ServerDomainsApiGroup, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api.group.js";
4
5
  export { proxyAuthHttpEffect, proxyAuthRequest, proxyAuthRequestEffect, } from "./proxy.js";
@@ -1,7 +1,8 @@
1
- import { Layer } from "effect";
1
+ import { Effect, Layer, Redacted } from "effect";
2
2
  import { HttpRouter, HttpServerRequest } from "effect/http";
3
3
  import { HttpApiError, HttpApiMiddleware, HttpApiSecurity } from "effect/http-api";
4
4
  import { AuthService, type AuthServiceLayerOptions } from "../service.js";
5
+ import type { AccountDeletionData, OrganizationDeletionData, AuthWebhook } from "../schema.js";
5
6
  export declare const ApiKeySecurity: HttpApiSecurity.ApiKey;
6
7
  declare const AuthMiddleware_base: HttpApiMiddleware.ServiceClass<AuthMiddleware, "@krak-stack/auth/AuthMiddleware", {
7
8
  requires: never;
@@ -16,7 +17,7 @@ declare const AuthMiddleware_base: HttpApiMiddleware.ServiceClass<AuthMiddleware
16
17
  readonly apiKey: HttpApiSecurity.ApiKey;
17
18
  }, AuthService, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden, typeof HttpApiError.ServiceUnavailable], never>>;
18
19
  export declare class AuthMiddleware extends AuthMiddleware_base {
19
- static readonly layer: (options?: AuthenticationLiveOptions | Layer.Layer<AuthService, unknown>) => Layer.Layer<AuthMiddleware, never, never>;
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>>;
20
21
  /** The same optional authentication and attribution for plain HttpRouter routes. */
21
22
  static readonly routerLayer: (options?: AuthRouterOptions) => Layer.Layer<never, import("effect/Config").ConfigError, HttpRouter.Request<"Error", HttpApiError.Forbidden> | HttpRouter.Request<"Error", HttpApiError.ServiceUnavailable>>;
22
23
  }
@@ -27,6 +28,13 @@ export type AuthenticationLiveOptions = AuthServiceLayerOptions & {
27
28
  }[];
28
29
  readonly authLayer?: Layer.Layer<AuthService, unknown, HttpServerRequest.HttpServerRequest>;
29
30
  };
31
+ export type AuthMiddlewareOptions<E, R> = AuthenticationLiveOptions & {
32
+ readonly projectId?: string;
33
+ readonly webhookSecret?: Redacted.Redacted<string>;
34
+ readonly onDeleteUser: (data: typeof AccountDeletionData.Type) => Effect.Effect<void, E, R>;
35
+ readonly onDeleteOrganization: (data: typeof OrganizationDeletionData.Type) => Effect.Effect<void, E, R>;
36
+ readonly onWebhook?: (webhook: typeof AuthWebhook.Type) => Effect.Effect<void, E, R>;
37
+ };
30
38
  export type AuthRouterOptions = AuthenticationLiveOptions & {
31
39
  /** Resolve auth only for these exact URL pathnames. Defaults to every route in scope. */
32
40
  readonly paths?: readonly string[];
@@ -18,7 +18,10 @@ export class AuthMiddleware extends HttpApiMiddleware.Service()("@krak-stack/aut
18
18
  apiKey: ApiKeySecurity,
19
19
  },
20
20
  }) {
21
- static layer = (options = {}) => makeAuthenticationLive(options);
21
+ static layer = (options) => Layer.merge(makeAuthenticationLive(options), Layer.unwrap(
22
+ // API contracts also import this class in the browser. Load persistence
23
+ // only when the server acquires its implementation layer.
24
+ Effect.promise(() => import("./webhook-layer.js")).pipe(Effect.map(({ makeAuthWebhookLayer }) => makeAuthWebhookLayer(options)))));
22
25
  /** The same optional authentication and attribution for plain HttpRouter routes. */
23
26
  static routerLayer = (options = {}) => HttpRouter.middleware(Effect.gen(function* () {
24
27
  const config = options.authLayer
@@ -0,0 +1,6 @@
1
+ import { Config, Layer, Schema } from "effect";
2
+ import { HttpRouter } from "effect/http";
3
+ import { WebhooksReceiver } from "@krak-stack/registry/webhooks";
4
+ import type { AuthMiddlewareOptions } from "./middleware.js";
5
+ import { AuthWebhookConfigurationError } from "./webhooks.js";
6
+ export declare const makeAuthWebhookLayer: <E, R>(options: AuthMiddlewareOptions<E, R>) => Layer.Layer<never, AuthWebhookConfigurationError | Config.ConfigError | import("effect/sql/Migrator").MigrationError | Schema.SchemaError | import("effect/sql/SqlError").SqlError, HttpRouter.HttpRouter | import("effect/sql/SqlClient").SqlClient | Exclude<Exclude<R, import("effect/Scope").Scope>, WebhooksReceiver>>;
@@ -0,0 +1,37 @@
1
+ import { ByteSize, Config, Effect, Layer, Redacted, Schema } from "effect";
2
+ import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
3
+ import { WebhooksReceiver } from "@krak-stack/registry/webhooks";
4
+ import { AuthWebhookCleanupError, AuthWebhookConfigurationError, receiveAuthWebhook, } from "./webhooks.js";
5
+ export const makeAuthWebhookLayer = (options) => Layer.unwrap(Effect.gen(function* () {
6
+ const receiver = yield* WebhooksReceiver;
7
+ const services = yield* Effect.context();
8
+ const projectId = yield* Schema.decodeUnknownEffect(Schema.NonEmptyString)(options.projectId ??
9
+ (yield* Config.NonEmptyString("VITE_KRAKSTACK_AUTH_PROJECT_ID")));
10
+ const secret = options.webhookSecret ??
11
+ (yield* Config.Redacted("KRAKSTACK_AUTH_WEBHOOK_SECRET"));
12
+ if (!Schema.is(Schema.String.check(Schema.isMinLength(32)))(Redacted.value(secret))) {
13
+ return yield* new AuthWebhookConfigurationError({
14
+ message: "The auth webhook signing secret must contain at least 32 characters",
15
+ });
16
+ }
17
+ const onWebhook = options.onWebhook;
18
+ const handle = Effect.gen(function* () {
19
+ const request = yield* HttpServerRequest.HttpServerRequest;
20
+ const body = yield* request.text;
21
+ yield* receiveAuthWebhook({
22
+ projectId,
23
+ secret,
24
+ body,
25
+ headers: request.headers,
26
+ onDeleteUser: (data) => options.onDeleteUser(data).pipe(Effect.provideContext(services), Effect.mapError(() => new AuthWebhookCleanupError({}))),
27
+ onDeleteOrganization: (data) => options.onDeleteOrganization(data).pipe(Effect.provideContext(services), Effect.mapError(() => new AuthWebhookCleanupError({}))),
28
+ onWebhook: onWebhook
29
+ ? (webhook) => onWebhook(webhook).pipe(Effect.provideContext(services), Effect.mapError(() => new AuthWebhookCleanupError({})))
30
+ : undefined,
31
+ }).pipe(Effect.provideService(WebhooksReceiver, receiver));
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 }))));
36
+ return HttpRouter.add("POST", "/api/webhooks/auth", handle);
37
+ })).pipe(Layer.provide(WebhooksReceiver.layer));
@@ -0,0 +1,38 @@
1
+ import { Effect, Redacted, Schema } from "effect";
2
+ import { WebhooksReceiver, WebhookVerificationError } from "@krak-stack/registry/webhooks";
3
+ import { AccountDeletionData, OrganizationDeletionData, AuthWebhook } from "../schema.js";
4
+ export { AccountDeletionData, AccountDeletionWebhook } from "../schema.js";
5
+ export { OrganizationDeletionData, OrganizationDeletionWebhook, } from "../schema.js";
6
+ export { AuthWebhook, AuthWebhookData } from "../schema.js";
7
+ declare const AuthWebhookConfigurationError_base: Schema.Class<AuthWebhookConfigurationError, Schema.TaggedStruct<"AuthWebhookConfigurationError", {
8
+ readonly message: Schema.String;
9
+ }>, import("effect/Cause").YieldableError>;
10
+ export declare class AuthWebhookConfigurationError extends AuthWebhookConfigurationError_base {
11
+ }
12
+ declare const AuthWebhookCleanupError_base: Schema.Class<AuthWebhookCleanupError, Schema.TaggedStruct<"AuthWebhookCleanupError", {}>, import("effect/Cause").YieldableError>;
13
+ export declare class AuthWebhookCleanupError extends AuthWebhookCleanupError_base {
14
+ }
15
+ declare const UnsupportedAuthWebhook_base: Schema.Class<UnsupportedAuthWebhook, Schema.TaggedStruct<"UnsupportedAuthWebhook", {}>, import("effect/Cause").YieldableError>;
16
+ export declare class UnsupportedAuthWebhook extends UnsupportedAuthWebhook_base {
17
+ }
18
+ /** Acknowledge only after the app's same-database cleanup has committed. */
19
+ export declare const receiveAuthWebhook: <E, R>(input: {
20
+ readonly projectId: string;
21
+ readonly secret: Redacted.Redacted<string>;
22
+ readonly headers: Readonly<Record<string, string | undefined>>;
23
+ readonly body: string;
24
+ readonly onDeleteUser: (data: typeof AccountDeletionData.Type) => Effect.Effect<void, E, R>;
25
+ readonly onDeleteOrganization: (data: typeof OrganizationDeletionData.Type) => Effect.Effect<void, E, R>;
26
+ readonly onWebhook?: ((webhook: typeof AuthWebhook.Type) => Effect.Effect<void, E, R>) | undefined;
27
+ }) => Effect.Effect<{
28
+ duplicate: boolean;
29
+ }, E | import("effect/crypto/CryptoError").CryptoError | import("effect/Cause").NoSuchElementError | Schema.SchemaError | import("effect/sql/SqlError").SqlError | UnsupportedAuthWebhook | import("@krak-stack/registry/webhooks").WebhookReceiptConflict | WebhookVerificationError, R | WebhooksReceiver>;
30
+ export declare const receiveAccountDeletion: <E, R>(input: {
31
+ readonly projectId: string;
32
+ readonly secret: Redacted.Redacted<string>;
33
+ readonly headers: Readonly<Record<string, string | undefined>>;
34
+ readonly body: string;
35
+ readonly handle: (data: typeof AccountDeletionData.Type) => Effect.Effect<void, E, R>;
36
+ }) => Effect.Effect<{
37
+ duplicate: boolean;
38
+ }, E | import("effect/crypto/CryptoError").CryptoError | import("effect/Cause").NoSuchElementError | Schema.SchemaError | import("effect/sql/SqlError").SqlError | UnsupportedAuthWebhook | import("@krak-stack/registry/webhooks").WebhookReceiptConflict | WebhookVerificationError, R | WebhooksReceiver>;
@@ -0,0 +1,39 @@
1
+ import { Effect, Redacted, Schema } from "effect";
2
+ import { WebhooksReceiver, WebhookVerificationError, } from "@krak-stack/registry/webhooks";
3
+ import { AccountDeletionData, AccountDeletionWebhook, OrganizationDeletionData, AuthWebhook, OrganizationDeletionWebhook, } from "../schema.js";
4
+ export { AccountDeletionData, AccountDeletionWebhook } from "../schema.js";
5
+ export { OrganizationDeletionData, OrganizationDeletionWebhook, } from "../schema.js";
6
+ export { AuthWebhook, AuthWebhookData } from "../schema.js";
7
+ export class AuthWebhookConfigurationError extends Schema.TaggedError()("AuthWebhookConfigurationError", {
8
+ message: Schema.String,
9
+ }) {
10
+ }
11
+ export class AuthWebhookCleanupError extends Schema.TaggedError()("AuthWebhookCleanupError", {}) {
12
+ }
13
+ export class UnsupportedAuthWebhook extends Schema.TaggedError()("UnsupportedAuthWebhook", {}) {
14
+ }
15
+ /** Acknowledge only after the app's same-database cleanup has committed. */
16
+ export const receiveAuthWebhook = Effect.fn("Auth.receiveAuthWebhook")(function* (input) {
17
+ const receiver = yield* WebhooksReceiver;
18
+ return yield* receiver.receive({
19
+ receiver: `krakstack-auth:${input.projectId}`,
20
+ secret: input.secret,
21
+ headers: input.headers,
22
+ body: input.body,
23
+ schema: AuthWebhook.check(Schema.makeFilter((payload) => payload.data.projectId === input.projectId, { expected: "the configured auth project" })),
24
+ handle: (webhook) => {
25
+ if (webhook.event === "user.deletion_requested")
26
+ return Schema.decodeUnknownEffect(AccountDeletionWebhook)(webhook).pipe(Effect.mapError(() => new WebhookVerificationError({ reason: "payload" })), Effect.flatMap(({ data }) => input.onDeleteUser(data)));
27
+ if (webhook.event === "organization.deletion_requested")
28
+ return Schema.decodeUnknownEffect(OrganizationDeletionWebhook)(webhook).pipe(Effect.mapError(() => new WebhookVerificationError({ reason: "payload" })), Effect.flatMap(({ data }) => input.onDeleteOrganization(data)));
29
+ return input.onWebhook
30
+ ? input.onWebhook(webhook)
31
+ : Effect.fail(new UnsupportedAuthWebhook({}));
32
+ },
33
+ });
34
+ });
35
+ export const receiveAccountDeletion = (input) => receiveAuthWebhook({
36
+ ...input,
37
+ onDeleteUser: input.handle,
38
+ onDeleteOrganization: () => Effect.fail(new UnsupportedAuthWebhook({})),
39
+ });
package/dist/service.d.ts CHANGED
@@ -373,6 +373,14 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
373
373
  readonly updatedAt: import("effect/Schema").DateFromString;
374
374
  }>;
375
375
  }>>, 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>;
376
+ readonly deleteUser: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"deleteUser", "POST", "/api/auth/delete-user", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
377
+ readonly password: import("effect/Schema").optional<import("effect/Schema").String>;
378
+ readonly token: import("effect/Schema").optional<import("effect/Schema").String>;
379
+ readonly callbackURL: import("effect/Schema").optional<import("effect/Schema").String>;
380
+ }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
381
+ readonly success: import("effect/Schema").Boolean;
382
+ readonly message: import("effect/Schema").String;
383
+ }>>, 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").AuthInternalServerError>, never, never>, never, never>;
376
384
  readonly getSession: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"getSession", "GET", "/api/auth/get-session", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
377
385
  readonly disableCookieCache: import("effect/Schema").optional<import("effect/Schema").String>;
378
386
  readonly disableRefresh: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -591,6 +599,18 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
591
599
  readonly parentId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
592
600
  readonly createdAt: import("effect/Schema").DateFromString;
593
601
  }>>, 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>;
602
+ readonly organizationDelete: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationDelete", "POST", "/api/auth/organization/delete", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
603
+ readonly organizationId: import("effect/Schema").NonEmptyString;
604
+ }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
605
+ readonly id: import("effect/Schema").String;
606
+ readonly name: import("effect/Schema").String;
607
+ readonly slug: import("effect/Schema").String;
608
+ readonly logo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
609
+ readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Union<readonly [import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").Codec<import("effect/Schema").Json, import("effect/Schema").Json, never, never>>, import("effect/Schema").String]>>>;
610
+ readonly userId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
611
+ readonly parentId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
612
+ readonly createdAt: import("effect/Schema").DateFromString;
613
+ }>>, 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>;
594
614
  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<{
595
615
  readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
596
616
  readonly organizationSlug: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -1460,6 +1480,19 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
1460
1480
  readonly id: import("effect/Schema").String;
1461
1481
  readonly key: import("effect/Schema").String;
1462
1482
  }>>, import("effect/Schema").toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof import("./extra/schema.js").ExtraBadRequest>, never, never>, never, never>;
1483
+ readonly getAccountDeletionPlan: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"getAccountDeletionPlan", "GET", "/api/auth/account-deletion", never, never, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
1484
+ readonly projects: import("effect/Schema").$Array<import("effect/Schema").Struct<{
1485
+ readonly id: import("effect/Schema").String;
1486
+ readonly name: import("effect/Schema").String;
1487
+ readonly ready: import("effect/Schema").Boolean;
1488
+ }>>;
1489
+ readonly organizations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
1490
+ readonly id: import("effect/Schema").String;
1491
+ readonly name: import("effect/Schema").String;
1492
+ readonly personal: import("effect/Schema").Boolean;
1493
+ }>>;
1494
+ readonly adminAccount: import("effect/Schema").Boolean;
1495
+ }>>, import("effect/Schema").toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError>, never, never>, never, never>;
1463
1496
  readonly getOrganizationPublicProfile: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"getOrganizationPublicProfile", "GET", "/api/auth/organization-profile", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
1464
1497
  readonly organizationId: import("effect/Schema").String;
1465
1498
  readonly locale: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>>;
@@ -2422,6 +2455,14 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2422
2455
  readonly updatedAt: import("effect/Schema").DateFromString;
2423
2456
  }>;
2424
2457
  }>>, 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>;
2458
+ readonly deleteUser: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"deleteUser", "POST", "/api/auth/delete-user", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2459
+ readonly password: import("effect/Schema").optional<import("effect/Schema").String>;
2460
+ readonly token: import("effect/Schema").optional<import("effect/Schema").String>;
2461
+ readonly callbackURL: import("effect/Schema").optional<import("effect/Schema").String>;
2462
+ }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2463
+ readonly success: import("effect/Schema").Boolean;
2464
+ readonly message: import("effect/Schema").String;
2465
+ }>>, 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").AuthInternalServerError>, never, never>, never, never>;
2425
2466
  readonly getSession: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"getSession", "GET", "/api/auth/get-session", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
2426
2467
  readonly disableCookieCache: import("effect/Schema").optional<import("effect/Schema").String>;
2427
2468
  readonly disableRefresh: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -2640,6 +2681,18 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2640
2681
  readonly parentId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
2641
2682
  readonly createdAt: import("effect/Schema").DateFromString;
2642
2683
  }>>, 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>;
2684
+ readonly organizationDelete: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationDelete", "POST", "/api/auth/organization/delete", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2685
+ readonly organizationId: import("effect/Schema").NonEmptyString;
2686
+ }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2687
+ readonly id: import("effect/Schema").String;
2688
+ readonly name: import("effect/Schema").String;
2689
+ readonly slug: import("effect/Schema").String;
2690
+ readonly logo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
2691
+ readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Union<readonly [import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").Codec<import("effect/Schema").Json, import("effect/Schema").Json, never, never>>, import("effect/Schema").String]>>>;
2692
+ readonly userId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
2693
+ readonly parentId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
2694
+ readonly createdAt: import("effect/Schema").DateFromString;
2695
+ }>>, 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>;
2643
2696
  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<{
2644
2697
  readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
2645
2698
  readonly organizationSlug: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -3509,6 +3562,19 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
3509
3562
  readonly id: import("effect/Schema").String;
3510
3563
  readonly key: import("effect/Schema").String;
3511
3564
  }>>, import("effect/Schema").toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof import("./extra/schema.js").ExtraBadRequest>, never, never>, never, never>;
3565
+ readonly getAccountDeletionPlan: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"getAccountDeletionPlan", "GET", "/api/auth/account-deletion", never, never, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
3566
+ readonly projects: import("effect/Schema").$Array<import("effect/Schema").Struct<{
3567
+ readonly id: import("effect/Schema").String;
3568
+ readonly name: import("effect/Schema").String;
3569
+ readonly ready: import("effect/Schema").Boolean;
3570
+ }>>;
3571
+ readonly organizations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
3572
+ readonly id: import("effect/Schema").String;
3573
+ readonly name: import("effect/Schema").String;
3574
+ readonly personal: import("effect/Schema").Boolean;
3575
+ }>>;
3576
+ readonly adminAccount: import("effect/Schema").Boolean;
3577
+ }>>, import("effect/Schema").toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError>, never, never>, never, never>;
3512
3578
  readonly getOrganizationPublicProfile: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"getOrganizationPublicProfile", "GET", "/api/auth/organization-profile", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
3513
3579
  readonly organizationId: import("effect/Schema").String;
3514
3580
  readonly locale: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.2.31",
3
+ "version": "0.2.32",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -11,6 +11,10 @@
11
11
  "type": "module",
12
12
  "sideEffects": false,
13
13
  "exports": {
14
+ "./server/webhooks": {
15
+ "types": "./dist/server/webhooks.d.ts",
16
+ "default": "./dist/server/webhooks.js"
17
+ },
14
18
  ".": {
15
19
  "types": "./dist/index.d.ts",
16
20
  "default": "./dist/index.js"
@@ -76,10 +80,10 @@
76
80
  "react-qr-code": "^2.2.0"
77
81
  },
78
82
  "devDependencies": {
79
- "@krak-stack/registry": "0.1.58"
83
+ "@krak-stack/registry": "0.1.61"
80
84
  },
81
85
  "peerDependencies": {
82
- "@krak-stack/registry": "^0.1.58",
86
+ "@krak-stack/registry": "^0.1.61",
83
87
  "@tanstack/react-router": "^1.170.15",
84
88
  "effect": "^4.1.0",
85
89
  "input-otp": "^1.5.0",