@krak-stack/auth 0.2.31 → 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.
Files changed (69) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +175 -1
  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 +141 -81
  8. package/dist/auth/api.group.d.ts +37 -19
  9. package/dist/auth/api.group.js +17 -1
  10. package/dist/auth/schema.d.ts +61 -33
  11. package/dist/auth/schema.js +30 -18
  12. package/dist/components/account-deletion-request.d.ts +5 -0
  13. package/dist/components/account-deletion-request.js +7 -0
  14. package/dist/components/account-deletion.d.ts +8 -0
  15. package/dist/components/account-deletion.js +59 -0
  16. package/dist/components/admin-organization-form.js +2 -2
  17. package/dist/components/admin-organizations.js +9 -7
  18. package/dist/components/admin-users.js +6 -6
  19. package/dist/components/api-key-edit-form.js +19 -11
  20. package/dist/components/associated-projects-notice.d.ts +2 -1
  21. package/dist/components/associated-projects-notice.js +7 -3
  22. package/dist/components/auth-atoms.js +1 -2
  23. package/dist/components/auth-client-api.d.ts +94 -61
  24. package/dist/components/auth-forms.d.ts +1 -0
  25. package/dist/components/auth-forms.js +41 -56
  26. package/dist/components/auth-provider.d.ts +3 -1
  27. package/dist/components/deletion-visibility.d.ts +1 -0
  28. package/dist/components/deletion-visibility.js +3 -0
  29. package/dist/components/hooks.d.ts +2 -0
  30. package/dist/components/hooks.js +13 -6
  31. package/dist/components/index.d.ts +3 -0
  32. package/dist/components/index.js +2 -0
  33. package/dist/components/member-required.js +3 -5
  34. package/dist/components/oauth-consent.d.ts +22 -0
  35. package/dist/components/oauth-consent.js +79 -0
  36. package/dist/components/organization-deletion-request.d.ts +17 -0
  37. package/dist/components/organization-deletion-request.js +9 -0
  38. package/dist/components/organization-switcher.d.ts +1 -1
  39. package/dist/components/organization-switcher.js +113 -55
  40. package/dist/components/project-card-list.d.ts +6 -0
  41. package/dist/components/project-card-list.js +4 -0
  42. package/dist/components/user-button.d.ts +29 -1
  43. package/dist/components/user-button.js +145 -47
  44. package/dist/extra/api.group.d.ts +13 -1
  45. package/dist/extra/api.group.js +5 -1
  46. package/dist/extra/schema.d.ts +16 -1
  47. package/dist/extra/schema.js +13 -0
  48. package/dist/oauth/authorization.d.ts +3 -0
  49. package/dist/oauth/authorization.js +39 -0
  50. package/dist/oauth/schema.d.ts +24 -0
  51. package/dist/oauth/schema.js +12 -0
  52. package/dist/oauth/verify.d.ts +13 -0
  53. package/dist/oauth/verify.js +67 -0
  54. package/dist/schema.d.ts +35 -0
  55. package/dist/schema.js +26 -1
  56. package/dist/server/actor.js +2 -4
  57. package/dist/server/index.d.ts +4 -1
  58. package/dist/server/index.js +2 -0
  59. package/dist/server/mcp.d.ts +20 -0
  60. package/dist/server/mcp.js +66 -0
  61. package/dist/server/middleware.d.ts +15 -7
  62. package/dist/server/middleware.js +19 -6
  63. package/dist/server/webhook-layer.d.ts +6 -0
  64. package/dist/server/webhook-layer.js +41 -0
  65. package/dist/server/webhooks.d.ts +44 -0
  66. package/dist/server/webhooks.js +39 -0
  67. package/dist/service.d.ts +118 -46
  68. package/dist/service.js +56 -9
  69. package/package.json +8 -3
@@ -5,7 +5,7 @@ export * from "./schema.js";
5
5
  export declare const AuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpApiEndpoint.HttpApiEndpoint<"adminBanUser", "POST", "/admin/ban-user", never, never, Schema.toCodecJson<Schema.Struct<{
6
6
  readonly userId: Schema.String;
7
7
  readonly banReason: Schema.optional<Schema.String>;
8
- readonly banExpiresIn: Schema.optional<Schema.Number>;
8
+ readonly banExpiresIn: Schema.optional<Schema.Finite>;
9
9
  }>>, never, Schema.toCodecJson<Schema.Struct<{
10
10
  readonly user: Schema.Struct<{
11
11
  readonly id: Schema.String;
@@ -240,8 +240,8 @@ export declare const AuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpApiEndp
240
240
  }>>, Schema.toCodecJson<typeof AuthBadRequest | typeof AuthUnauthorized | typeof AuthForbidden | typeof AuthNotFound | typeof AuthConflict | typeof AuthExpectationFailed | typeof AuthTooManyRequests | typeof AuthInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"apiKeyList", "GET", "/api-key/list", never, Schema.toCodecStringTree<Schema.Struct<{
241
241
  readonly configId: Schema.optional<Schema.String>;
242
242
  readonly organizationId: Schema.optional<Schema.String>;
243
- readonly limit: Schema.optional<Schema.NumberFromString>;
244
- readonly offset: Schema.optional<Schema.NumberFromString>;
243
+ readonly limit: Schema.optional<Schema.FiniteFromString>;
244
+ readonly offset: Schema.optional<Schema.FiniteFromString>;
245
245
  readonly sortBy: Schema.optional<Schema.String>;
246
246
  readonly sortDirection: Schema.optional<Schema.Literals<readonly ["asc", "desc"]>>;
247
247
  }>>, never, never, Schema.toCodecJson<Schema.Struct<{
@@ -253,15 +253,15 @@ export declare const AuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpApiEndp
253
253
  readonly userId: Schema.optional<Schema.String>;
254
254
  readonly referenceId: Schema.String;
255
255
  readonly configId: Schema.String;
256
- readonly refillInterval: Schema.NullOr<Schema.Number>;
257
- readonly refillAmount: Schema.NullOr<Schema.Number>;
256
+ readonly refillInterval: Schema.NullOr<Schema.Finite>;
257
+ readonly refillAmount: Schema.NullOr<Schema.Finite>;
258
258
  readonly lastRefillAt: Schema.NullOr<Schema.DateFromString>;
259
259
  readonly enabled: Schema.Boolean;
260
260
  readonly rateLimitEnabled: Schema.Boolean;
261
- readonly rateLimitTimeWindow: Schema.NullOr<Schema.Number>;
262
- readonly rateLimitMax: Schema.NullOr<Schema.Number>;
263
- readonly requestCount: Schema.Number;
264
- readonly remaining: Schema.NullOr<Schema.Number>;
261
+ readonly rateLimitTimeWindow: Schema.NullOr<Schema.Finite>;
262
+ readonly rateLimitMax: Schema.NullOr<Schema.Finite>;
263
+ readonly requestCount: Schema.Finite;
264
+ readonly remaining: Schema.NullOr<Schema.Finite>;
265
265
  readonly lastRequest: Schema.NullOr<Schema.DateFromString>;
266
266
  readonly expiresAt: Schema.NullOr<Schema.DateFromString>;
267
267
  readonly createdAt: Schema.DateFromString;
@@ -270,9 +270,9 @@ export declare const AuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpApiEndp
270
270
  readonly permissions: Schema.optional<Schema.NullOr<Schema.$Record<Schema.String, Schema.$Array<Schema.String>>>>;
271
271
  readonly referrers: Schema.optional<Schema.NullOr<Schema.$Array<Schema.String>>>;
272
272
  }>>;
273
- readonly total: Schema.Number;
274
- readonly limit: Schema.optional<Schema.NullOr<Schema.Number>>;
275
- readonly offset: Schema.optional<Schema.NullOr<Schema.Number>>;
273
+ readonly total: Schema.Finite;
274
+ readonly limit: Schema.optional<Schema.NullOr<Schema.Finite>>;
275
+ readonly offset: Schema.optional<Schema.NullOr<Schema.Finite>>;
276
276
  }>>, Schema.toCodecJson<typeof AuthBadRequest | typeof AuthUnauthorized | typeof AuthForbidden | typeof AuthNotFound | typeof AuthConflict | typeof AuthExpectationFailed | typeof AuthTooManyRequests | typeof AuthInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"changePassword", "POST", "/change-password", never, never, Schema.toCodecJson<Schema.Struct<{
277
277
  readonly newPassword: Schema.String;
278
278
  readonly currentPassword: Schema.String;
@@ -327,7 +327,14 @@ export declare const AuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpApiEndp
327
327
  readonly createdAt: Schema.DateFromString;
328
328
  readonly updatedAt: Schema.DateFromString;
329
329
  }>;
330
- }>>, Schema.toCodecJson<typeof AuthBadRequest | typeof AuthUnauthorized | typeof AuthForbidden | typeof AuthNotFound | typeof AuthConflict | typeof AuthExpectationFailed | typeof AuthTooManyRequests | typeof AuthInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getSession", "GET", "/get-session", never, Schema.toCodecStringTree<Schema.Struct<{
330
+ }>>, Schema.toCodecJson<typeof AuthBadRequest | typeof AuthUnauthorized | typeof AuthForbidden | typeof AuthNotFound | typeof AuthConflict | typeof AuthExpectationFailed | typeof AuthTooManyRequests | typeof AuthInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"deleteUser", "POST", "/delete-user", never, never, Schema.toCodecJson<Schema.Struct<{
331
+ readonly password: Schema.optional<Schema.String>;
332
+ readonly token: Schema.optional<Schema.String>;
333
+ readonly callbackURL: Schema.optional<Schema.String>;
334
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
335
+ readonly success: Schema.Boolean;
336
+ readonly message: Schema.String;
337
+ }>>, Schema.toCodecJson<typeof AuthBadRequest | typeof AuthUnauthorized | typeof AuthForbidden | typeof AuthNotFound | typeof AuthInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getSession", "GET", "/get-session", never, Schema.toCodecStringTree<Schema.Struct<{
331
338
  readonly disableCookieCache: Schema.optional<Schema.String>;
332
339
  readonly disableRefresh: Schema.optional<Schema.String>;
333
340
  }>>, never, never, Schema.toCodecJson<Schema.NullOr<Schema.Struct<{
@@ -537,10 +544,21 @@ export declare const AuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpApiEndp
537
544
  readonly userId: Schema.optional<Schema.NullOr<Schema.String>>;
538
545
  readonly parentId: Schema.optional<Schema.NullOr<Schema.String>>;
539
546
  readonly createdAt: Schema.DateFromString;
547
+ }>>, Schema.toCodecJson<typeof AuthBadRequest | typeof AuthUnauthorized | typeof AuthForbidden | typeof AuthNotFound | typeof AuthConflict | typeof AuthExpectationFailed | typeof AuthTooManyRequests | typeof AuthInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"organizationDelete", "POST", "/organization/delete", never, never, Schema.toCodecJson<Schema.Struct<{
548
+ readonly organizationId: Schema.NonEmptyString;
549
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
550
+ readonly id: Schema.String;
551
+ readonly name: Schema.String;
552
+ readonly slug: Schema.String;
553
+ readonly logo: Schema.optional<Schema.NullOr<Schema.String>>;
554
+ readonly metadata: Schema.optional<Schema.NullOr<Schema.Union<readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.String]>>>;
555
+ readonly userId: Schema.optional<Schema.NullOr<Schema.String>>;
556
+ readonly parentId: Schema.optional<Schema.NullOr<Schema.String>>;
557
+ readonly createdAt: Schema.DateFromString;
540
558
  }>>, Schema.toCodecJson<typeof AuthBadRequest | typeof AuthUnauthorized | typeof AuthForbidden | typeof AuthNotFound | typeof AuthConflict | typeof AuthExpectationFailed | typeof AuthTooManyRequests | typeof AuthInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"organizationGetFull", "GET", "/organization/get-full-organization", never, Schema.toCodecStringTree<Schema.Struct<{
541
559
  readonly organizationId: Schema.optional<Schema.String>;
542
560
  readonly organizationSlug: Schema.optional<Schema.String>;
543
- readonly membersLimit: Schema.optional<Schema.NumberFromString>;
561
+ readonly membersLimit: Schema.optional<Schema.FiniteFromString>;
544
562
  }>>, never, never, Schema.toCodecJson<Schema.NullOr<Schema.Struct<{
545
563
  readonly id: Schema.String;
546
564
  readonly name: Schema.String;
@@ -626,7 +644,7 @@ export declare const AuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpApiEndp
626
644
  readonly organizationId: Schema.NonEmptyString;
627
645
  readonly actorUserId: Schema.NonEmptyString;
628
646
  readonly targetUserId: Schema.NonEmptyString;
629
- readonly expiresInSeconds: Schema.optional<Schema.Number>;
647
+ readonly expiresInSeconds: Schema.optional<Schema.Finite>;
630
648
  }>>, never, Schema.toCodecJson<Schema.Struct<{
631
649
  readonly session: Schema.Struct<{
632
650
  readonly id: Schema.String;
@@ -737,8 +755,8 @@ export declare const AuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpApiEndp
737
755
  readonly expiresAt: Schema.DateFromString;
738
756
  readonly createdAt: Schema.optional<Schema.DateFromString>;
739
757
  }>>>, Schema.toCodecJson<typeof AuthBadRequest | typeof AuthUnauthorized | typeof AuthForbidden | typeof AuthNotFound | typeof AuthConflict | typeof AuthExpectationFailed | typeof AuthTooManyRequests | typeof AuthInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"organizationListMembers", "GET", "/organization/list-members", never, Schema.toCodecStringTree<Schema.Struct<{
740
- readonly limit: Schema.optional<Schema.NumberFromString>;
741
- readonly offset: Schema.optional<Schema.NumberFromString>;
758
+ readonly limit: Schema.optional<Schema.FiniteFromString>;
759
+ readonly offset: Schema.optional<Schema.FiniteFromString>;
742
760
  readonly sortBy: Schema.optional<Schema.String>;
743
761
  readonly sortDirection: Schema.optional<Schema.Literals<readonly ["asc", "desc"]>>;
744
762
  readonly filterField: Schema.optional<Schema.String>;
@@ -792,7 +810,7 @@ export declare const AuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpApiEndp
792
810
  }>, Schema.Unknown, never, never>>>;
793
811
  }>;
794
812
  }>>;
795
- readonly total: Schema.Number;
813
+ readonly total: Schema.Finite;
796
814
  }>>, Schema.toCodecJson<typeof AuthBadRequest | typeof AuthUnauthorized | typeof AuthForbidden | typeof AuthNotFound | typeof AuthConflict | typeof AuthExpectationFailed | typeof AuthTooManyRequests | typeof AuthInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"organizationListUserInvitations", "GET", "/organization/list-user-invitations", never, Schema.toCodecStringTree<Schema.Struct<{}>>, never, never, Schema.toCodecJson<Schema.$Array<Schema.Struct<{
797
815
  readonly id: Schema.String;
798
816
  readonly email: Schema.String;
@@ -1021,7 +1039,7 @@ export declare const AuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpApiEndp
1021
1039
  readonly nonce: Schema.optional<Schema.String>;
1022
1040
  readonly accessToken: Schema.optional<Schema.String>;
1023
1041
  readonly refreshToken: Schema.optional<Schema.String>;
1024
- readonly expiresAt: Schema.optional<Schema.Number>;
1042
+ readonly expiresAt: Schema.optional<Schema.Finite>;
1025
1043
  readonly user: Schema.optional<Schema.Struct<{
1026
1044
  readonly name: Schema.optional<Schema.Struct<{
1027
1045
  readonly firstName: Schema.optional<Schema.String>;
@@ -1,6 +1,6 @@
1
1
  import { Schema } from "effect";
2
2
  import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api";
3
- import { AdminBanUserPayload, AdminStopImpersonatingPayload, AdminUserIdPayload, AdminUserResponse, AuthBadRequest, AuthConflict, AuthExpectationFailed, AuthForbidden, AuthInternalServerError, AuthInvitation, AuthNotFound, AuthOrganization, AuthSessionResponse, AuthStatusResponse, AuthSuccessResponse, AuthTooManyRequests, AuthUnauthorized, ChangePasswordPayload, ChangePasswordResponse, CreateOrganizationPayload, DeleteApiKeyPayload, FullAuthOrganization, GetFullOrganizationQuery, GetInvitationQuery, GetInvitationResponse, GetSessionQuery, GetSessionResponse, InvitationActionResponse, InvitationIdPayload, InviteMemberPayload, LeaveOrganizationPayload, LinkedAccount, LinkSocialPayload, ListApiKeysQuery, ListApiKeysResponse, MemberResponse, OAuthConsentPayload, OAuthPublicClient, OAuthPublicClientQuery, OAuthRedirectResponse, OrganizationImpersonateUserPayload, OrganizationImpersonateUserResponse, OrganizationInvitationsQuery, OrganizationListMembersQuery, OrganizationListMembersResponse, RemoveMemberPayload, RequestPasswordResetPayload, RequestPasswordResetResponse, ResetPasswordPayload, SendVerificationOtpPayload, SetActiveOrganizationPayload, SignInEmailOtpPayload, SignInEmailPayload, SignInEmailResponse, SignInResponse, SignInSocialPayload, SignOutPayload, SocialRedirectResponse, TwoFactorBackupVerifyPayload, TwoFactorDisablePayload, TwoFactorEnablePayload, TwoFactorEnableResponse, TwoFactorSendPayload, TwoFactorVerifyPayload, UnlinkAccountPayload, UpdateMemberRolePayload, UpdateOrganizationPayload, UpdateUserPayload, UserInvitationsQuery, VerifyEmailOtpPayload, VerifyEmailOtpResponse, } from "./schema.js";
3
+ import { DeleteUserPayload, DeleteOrganizationPayload, DeleteUserResponse, AdminBanUserPayload, AdminStopImpersonatingPayload, AdminUserIdPayload, AdminUserResponse, AuthBadRequest, AuthConflict, AuthExpectationFailed, AuthForbidden, AuthInternalServerError, AuthInvitation, AuthNotFound, AuthOrganization, AuthSessionResponse, AuthStatusResponse, AuthSuccessResponse, AuthTooManyRequests, AuthUnauthorized, ChangePasswordPayload, ChangePasswordResponse, CreateOrganizationPayload, DeleteApiKeyPayload, FullAuthOrganization, GetFullOrganizationQuery, GetInvitationQuery, GetInvitationResponse, GetSessionQuery, GetSessionResponse, InvitationActionResponse, InvitationIdPayload, InviteMemberPayload, LeaveOrganizationPayload, LinkedAccount, LinkSocialPayload, ListApiKeysQuery, ListApiKeysResponse, MemberResponse, OAuthConsentPayload, OAuthPublicClient, OAuthPublicClientQuery, OAuthRedirectResponse, OrganizationImpersonateUserPayload, OrganizationImpersonateUserResponse, OrganizationInvitationsQuery, OrganizationListMembersQuery, OrganizationListMembersResponse, RemoveMemberPayload, RequestPasswordResetPayload, RequestPasswordResetResponse, ResetPasswordPayload, SendVerificationOtpPayload, SetActiveOrganizationPayload, SignInEmailOtpPayload, SignInEmailPayload, SignInEmailResponse, SignInResponse, SignInSocialPayload, SignOutPayload, SocialRedirectResponse, TwoFactorBackupVerifyPayload, TwoFactorDisablePayload, TwoFactorEnablePayload, TwoFactorEnableResponse, TwoFactorSendPayload, TwoFactorVerifyPayload, UnlinkAccountPayload, UpdateMemberRolePayload, UpdateOrganizationPayload, UpdateUserPayload, UserInvitationsQuery, VerifyEmailOtpPayload, VerifyEmailOtpResponse, } from "./schema.js";
4
4
  export * from "./schema.js";
5
5
  const errors = [
6
6
  AuthBadRequest,
@@ -14,6 +14,17 @@ const errors = [
14
14
  ];
15
15
  const docs = (title, description) => OpenApi.annotations({ title, summary: title, description });
16
16
  export const AuthApiGroup = HttpApiGroup.make("auth")
17
+ .add(HttpApiEndpoint.post("deleteUser", "/delete-user", {
18
+ payload: DeleteUserPayload,
19
+ success: DeleteUserResponse,
20
+ error: [
21
+ AuthBadRequest,
22
+ AuthUnauthorized,
23
+ AuthForbidden,
24
+ AuthNotFound,
25
+ AuthInternalServerError,
26
+ ],
27
+ }))
17
28
  .add(HttpApiEndpoint.get("getSession", "/get-session", {
18
29
  query: GetSessionQuery.fields,
19
30
  success: GetSessionResponse,
@@ -132,6 +143,11 @@ export const AuthApiGroup = HttpApiGroup.make("auth")
132
143
  success: AuthOrganization,
133
144
  error: errors,
134
145
  }).annotateMerge(docs("Create organization", "Creates an organization.")))
146
+ .add(HttpApiEndpoint.post("organizationDelete", "/organization/delete", {
147
+ payload: DeleteOrganizationPayload,
148
+ success: AuthOrganization,
149
+ error: errors,
150
+ }).annotateMerge(docs("Delete organization", "Permanently deletes an organization owned by the current user. Personal organizations are protected.")))
135
151
  .add(HttpApiEndpoint.post("organizationUpdate", "/organization/update", {
136
152
  payload: UpdateOrganizationPayload,
137
153
  success: AuthOrganization,
@@ -1,4 +1,13 @@
1
1
  import { Schema } from "effect";
2
+ export declare const DeleteUserPayload: Schema.Struct<{
3
+ readonly password: Schema.optional<Schema.String>;
4
+ readonly token: Schema.optional<Schema.String>;
5
+ readonly callbackURL: Schema.optional<Schema.String>;
6
+ }>;
7
+ export declare const DeleteUserResponse: Schema.Struct<{
8
+ readonly success: Schema.Boolean;
9
+ readonly message: Schema.String;
10
+ }>;
2
11
  export declare const AuthRedirectURLFromString: (origin?: string) => Schema.decodeTo<Schema.URL, Schema.String, never, never>;
3
12
  export declare const AuthUser: Schema.Struct<{
4
13
  readonly id: Schema.String;
@@ -210,7 +219,9 @@ declare const AuthBadRequest_base: Schema.Class<AuthBadRequest, Schema.TaggedStr
210
219
  error: Schema.optional<Schema.String>;
211
220
  error_description: Schema.optional<Schema.String>;
212
221
  _tag: Schema.withDecodingDefaultKey<Schema.tag<"AuthBadRequest">, never>;
213
- }>, import("effect/Cause").YieldableError>;
222
+ }>, import("effect/Cause").YieldableError & {
223
+ readonly brand: unique symbol;
224
+ }>;
214
225
  export declare class AuthBadRequest extends AuthBadRequest_base {
215
226
  }
216
227
  declare const AuthUnauthorized_base: Schema.Class<AuthUnauthorized, Schema.TaggedStruct<"AuthUnauthorized", {
@@ -219,7 +230,9 @@ declare const AuthUnauthorized_base: Schema.Class<AuthUnauthorized, Schema.Tagge
219
230
  error: Schema.optional<Schema.String>;
220
231
  error_description: Schema.optional<Schema.String>;
221
232
  _tag: Schema.withDecodingDefaultKey<Schema.tag<"AuthUnauthorized">, never>;
222
- }>, import("effect/Cause").YieldableError>;
233
+ }>, import("effect/Cause").YieldableError & {
234
+ readonly brand: unique symbol;
235
+ }>;
223
236
  export declare class AuthUnauthorized extends AuthUnauthorized_base {
224
237
  }
225
238
  declare const AuthForbidden_base: Schema.Class<AuthForbidden, Schema.TaggedStruct<"AuthForbidden", {
@@ -228,7 +241,9 @@ declare const AuthForbidden_base: Schema.Class<AuthForbidden, Schema.TaggedStruc
228
241
  error: Schema.optional<Schema.String>;
229
242
  error_description: Schema.optional<Schema.String>;
230
243
  _tag: Schema.withDecodingDefaultKey<Schema.tag<"AuthForbidden">, never>;
231
- }>, import("effect/Cause").YieldableError>;
244
+ }>, import("effect/Cause").YieldableError & {
245
+ readonly brand: unique symbol;
246
+ }>;
232
247
  export declare class AuthForbidden extends AuthForbidden_base {
233
248
  }
234
249
  declare const AuthNotFound_base: Schema.Class<AuthNotFound, Schema.TaggedStruct<"AuthNotFound", {
@@ -237,7 +252,9 @@ declare const AuthNotFound_base: Schema.Class<AuthNotFound, Schema.TaggedStruct<
237
252
  error: Schema.optional<Schema.String>;
238
253
  error_description: Schema.optional<Schema.String>;
239
254
  _tag: Schema.withDecodingDefaultKey<Schema.tag<"AuthNotFound">, never>;
240
- }>, import("effect/Cause").YieldableError>;
255
+ }>, import("effect/Cause").YieldableError & {
256
+ readonly brand: unique symbol;
257
+ }>;
241
258
  export declare class AuthNotFound extends AuthNotFound_base {
242
259
  }
243
260
  declare const AuthConflict_base: Schema.Class<AuthConflict, Schema.TaggedStruct<"AuthConflict", {
@@ -246,7 +263,9 @@ declare const AuthConflict_base: Schema.Class<AuthConflict, Schema.TaggedStruct<
246
263
  error: Schema.optional<Schema.String>;
247
264
  error_description: Schema.optional<Schema.String>;
248
265
  _tag: Schema.withDecodingDefaultKey<Schema.tag<"AuthConflict">, never>;
249
- }>, import("effect/Cause").YieldableError>;
266
+ }>, import("effect/Cause").YieldableError & {
267
+ readonly brand: unique symbol;
268
+ }>;
250
269
  export declare class AuthConflict extends AuthConflict_base {
251
270
  }
252
271
  declare const AuthExpectationFailed_base: Schema.Class<AuthExpectationFailed, Schema.TaggedStruct<"AuthExpectationFailed", {
@@ -255,7 +274,9 @@ declare const AuthExpectationFailed_base: Schema.Class<AuthExpectationFailed, Sc
255
274
  error: Schema.optional<Schema.String>;
256
275
  error_description: Schema.optional<Schema.String>;
257
276
  _tag: Schema.withDecodingDefaultKey<Schema.tag<"AuthExpectationFailed">, never>;
258
- }>, import("effect/Cause").YieldableError>;
277
+ }>, import("effect/Cause").YieldableError & {
278
+ readonly brand: unique symbol;
279
+ }>;
259
280
  export declare class AuthExpectationFailed extends AuthExpectationFailed_base {
260
281
  }
261
282
  declare const AuthTooManyRequests_base: Schema.Class<AuthTooManyRequests, Schema.TaggedStruct<"AuthTooManyRequests", {
@@ -264,7 +285,9 @@ declare const AuthTooManyRequests_base: Schema.Class<AuthTooManyRequests, Schema
264
285
  error: Schema.optional<Schema.String>;
265
286
  error_description: Schema.optional<Schema.String>;
266
287
  _tag: Schema.withDecodingDefaultKey<Schema.tag<"AuthTooManyRequests">, never>;
267
- }>, import("effect/Cause").YieldableError>;
288
+ }>, import("effect/Cause").YieldableError & {
289
+ readonly brand: unique symbol;
290
+ }>;
268
291
  export declare class AuthTooManyRequests extends AuthTooManyRequests_base {
269
292
  }
270
293
  declare const AuthInternalServerError_base: Schema.Class<AuthInternalServerError, Schema.TaggedStruct<"AuthInternalServerError", {
@@ -273,7 +296,9 @@ declare const AuthInternalServerError_base: Schema.Class<AuthInternalServerError
273
296
  error: Schema.optional<Schema.String>;
274
297
  error_description: Schema.optional<Schema.String>;
275
298
  _tag: Schema.withDecodingDefaultKey<Schema.tag<"AuthInternalServerError">, never>;
276
- }>, import("effect/Cause").YieldableError>;
299
+ }>, import("effect/Cause").YieldableError & {
300
+ readonly brand: unique symbol;
301
+ }>;
277
302
  export declare class AuthInternalServerError extends AuthInternalServerError_base {
278
303
  }
279
304
  export declare const UpdateUserPayload: Schema.Struct<{
@@ -439,7 +464,7 @@ export declare const SocialIdToken: Schema.Struct<{
439
464
  readonly nonce: Schema.optional<Schema.String>;
440
465
  readonly accessToken: Schema.optional<Schema.String>;
441
466
  readonly refreshToken: Schema.optional<Schema.String>;
442
- readonly expiresAt: Schema.optional<Schema.Number>;
467
+ readonly expiresAt: Schema.optional<Schema.Finite>;
443
468
  readonly user: Schema.optional<Schema.Struct<{
444
469
  readonly name: Schema.optional<Schema.Struct<{
445
470
  readonly firstName: Schema.optional<Schema.String>;
@@ -459,7 +484,7 @@ export declare const SignInSocialPayload: Schema.Struct<{
459
484
  readonly nonce: Schema.optional<Schema.String>;
460
485
  readonly accessToken: Schema.optional<Schema.String>;
461
486
  readonly refreshToken: Schema.optional<Schema.String>;
462
- readonly expiresAt: Schema.optional<Schema.Number>;
487
+ readonly expiresAt: Schema.optional<Schema.Finite>;
463
488
  readonly user: Schema.optional<Schema.Struct<{
464
489
  readonly name: Schema.optional<Schema.Struct<{
465
490
  readonly firstName: Schema.optional<Schema.String>;
@@ -892,7 +917,7 @@ export declare const FullAuthOrganization: Schema.Struct<{
892
917
  export declare const GetFullOrganizationQuery: Schema.Struct<{
893
918
  readonly organizationId: Schema.optional<Schema.String>;
894
919
  readonly organizationSlug: Schema.optional<Schema.String>;
895
- readonly membersLimit: Schema.optional<Schema.NumberFromString>;
920
+ readonly membersLimit: Schema.optional<Schema.FiniteFromString>;
896
921
  }>;
897
922
  export declare const SetActiveOrganizationPayload: Schema.Struct<{
898
923
  readonly organizationId: Schema.optional<Schema.NullOr<Schema.String>>;
@@ -917,8 +942,8 @@ export declare const UpdateOrganizationPayload: Schema.Struct<{
917
942
  }>;
918
943
  }>;
919
944
  export declare const OrganizationListMembersQuery: Schema.Struct<{
920
- readonly limit: Schema.optional<Schema.NumberFromString>;
921
- readonly offset: Schema.optional<Schema.NumberFromString>;
945
+ readonly limit: Schema.optional<Schema.FiniteFromString>;
946
+ readonly offset: Schema.optional<Schema.FiniteFromString>;
922
947
  readonly sortBy: Schema.optional<Schema.String>;
923
948
  readonly sortDirection: Schema.optional<Schema.Literals<readonly ["asc", "desc"]>>;
924
949
  readonly filterField: Schema.optional<Schema.String>;
@@ -973,7 +998,7 @@ export declare const OrganizationListMembersResponse: Schema.Struct<{
973
998
  }>, Schema.Unknown, never, never>>>;
974
999
  }>;
975
1000
  }>>;
976
- readonly total: Schema.Number;
1001
+ readonly total: Schema.Finite;
977
1002
  }>;
978
1003
  export declare const InviteMemberPayload: Schema.Struct<{
979
1004
  readonly email: Schema.String;
@@ -991,6 +1016,9 @@ export declare const RemoveMemberPayload: Schema.Struct<{
991
1016
  readonly memberIdOrEmail: Schema.String;
992
1017
  readonly organizationId: Schema.optional<Schema.String>;
993
1018
  }>;
1019
+ export declare const DeleteOrganizationPayload: Schema.Struct<{
1020
+ readonly organizationId: Schema.NonEmptyString;
1021
+ }>;
994
1022
  export declare const LeaveOrganizationPayload: Schema.Struct<{
995
1023
  readonly organizationId: Schema.String;
996
1024
  }>;
@@ -1052,7 +1080,7 @@ export declare const OrganizationImpersonateUserPayload: Schema.Struct<{
1052
1080
  readonly organizationId: Schema.NonEmptyString;
1053
1081
  readonly actorUserId: Schema.NonEmptyString;
1054
1082
  readonly targetUserId: Schema.NonEmptyString;
1055
- readonly expiresInSeconds: Schema.optional<Schema.Number>;
1083
+ readonly expiresInSeconds: Schema.optional<Schema.Finite>;
1056
1084
  }>;
1057
1085
  export declare const OrganizationImpersonateUserResponse: Schema.Struct<{
1058
1086
  readonly session: Schema.Struct<{
@@ -1125,15 +1153,15 @@ export declare const AuthApiKey: Schema.Struct<{
1125
1153
  readonly userId: Schema.optional<Schema.String>;
1126
1154
  readonly referenceId: Schema.String;
1127
1155
  readonly configId: Schema.String;
1128
- readonly refillInterval: Schema.NullOr<Schema.Number>;
1129
- readonly refillAmount: Schema.NullOr<Schema.Number>;
1156
+ readonly refillInterval: Schema.NullOr<Schema.Finite>;
1157
+ readonly refillAmount: Schema.NullOr<Schema.Finite>;
1130
1158
  readonly lastRefillAt: Schema.NullOr<Schema.DateFromString>;
1131
1159
  readonly enabled: Schema.Boolean;
1132
1160
  readonly rateLimitEnabled: Schema.Boolean;
1133
- readonly rateLimitTimeWindow: Schema.NullOr<Schema.Number>;
1134
- readonly rateLimitMax: Schema.NullOr<Schema.Number>;
1135
- readonly requestCount: Schema.Number;
1136
- readonly remaining: Schema.NullOr<Schema.Number>;
1161
+ readonly rateLimitTimeWindow: Schema.NullOr<Schema.Finite>;
1162
+ readonly rateLimitMax: Schema.NullOr<Schema.Finite>;
1163
+ readonly requestCount: Schema.Finite;
1164
+ readonly remaining: Schema.NullOr<Schema.Finite>;
1137
1165
  readonly lastRequest: Schema.NullOr<Schema.DateFromString>;
1138
1166
  readonly expiresAt: Schema.NullOr<Schema.DateFromString>;
1139
1167
  readonly createdAt: Schema.DateFromString;
@@ -1145,8 +1173,8 @@ export declare const AuthApiKey: Schema.Struct<{
1145
1173
  export declare const ListApiKeysQuery: Schema.Struct<{
1146
1174
  readonly configId: Schema.optional<Schema.String>;
1147
1175
  readonly organizationId: Schema.optional<Schema.String>;
1148
- readonly limit: Schema.optional<Schema.NumberFromString>;
1149
- readonly offset: Schema.optional<Schema.NumberFromString>;
1176
+ readonly limit: Schema.optional<Schema.FiniteFromString>;
1177
+ readonly offset: Schema.optional<Schema.FiniteFromString>;
1150
1178
  readonly sortBy: Schema.optional<Schema.String>;
1151
1179
  readonly sortDirection: Schema.optional<Schema.Literals<readonly ["asc", "desc"]>>;
1152
1180
  }>;
@@ -1159,15 +1187,15 @@ export declare const ListApiKeysResponse: Schema.Struct<{
1159
1187
  readonly userId: Schema.optional<Schema.String>;
1160
1188
  readonly referenceId: Schema.String;
1161
1189
  readonly configId: Schema.String;
1162
- readonly refillInterval: Schema.NullOr<Schema.Number>;
1163
- readonly refillAmount: Schema.NullOr<Schema.Number>;
1190
+ readonly refillInterval: Schema.NullOr<Schema.Finite>;
1191
+ readonly refillAmount: Schema.NullOr<Schema.Finite>;
1164
1192
  readonly lastRefillAt: Schema.NullOr<Schema.DateFromString>;
1165
1193
  readonly enabled: Schema.Boolean;
1166
1194
  readonly rateLimitEnabled: Schema.Boolean;
1167
- readonly rateLimitTimeWindow: Schema.NullOr<Schema.Number>;
1168
- readonly rateLimitMax: Schema.NullOr<Schema.Number>;
1169
- readonly requestCount: Schema.Number;
1170
- readonly remaining: Schema.NullOr<Schema.Number>;
1195
+ readonly rateLimitTimeWindow: Schema.NullOr<Schema.Finite>;
1196
+ readonly rateLimitMax: Schema.NullOr<Schema.Finite>;
1197
+ readonly requestCount: Schema.Finite;
1198
+ readonly remaining: Schema.NullOr<Schema.Finite>;
1171
1199
  readonly lastRequest: Schema.NullOr<Schema.DateFromString>;
1172
1200
  readonly expiresAt: Schema.NullOr<Schema.DateFromString>;
1173
1201
  readonly createdAt: Schema.DateFromString;
@@ -1176,9 +1204,9 @@ export declare const ListApiKeysResponse: Schema.Struct<{
1176
1204
  readonly permissions: Schema.optional<Schema.NullOr<Schema.$Record<Schema.String, Schema.$Array<Schema.String>>>>;
1177
1205
  readonly referrers: Schema.optional<Schema.NullOr<Schema.$Array<Schema.String>>>;
1178
1206
  }>>;
1179
- readonly total: Schema.Number;
1180
- readonly limit: Schema.optional<Schema.NullOr<Schema.Number>>;
1181
- readonly offset: Schema.optional<Schema.NullOr<Schema.Number>>;
1207
+ readonly total: Schema.Finite;
1208
+ readonly limit: Schema.optional<Schema.NullOr<Schema.Finite>>;
1209
+ readonly offset: Schema.optional<Schema.NullOr<Schema.Finite>>;
1182
1210
  }>;
1183
1211
  export declare const DeleteApiKeyPayload: Schema.Struct<{
1184
1212
  readonly configId: Schema.optional<Schema.String>;
@@ -1191,7 +1219,7 @@ export declare const AdminStopImpersonatingPayload: Schema.Struct<{}>;
1191
1219
  export declare const AdminBanUserPayload: Schema.Struct<{
1192
1220
  readonly userId: Schema.String;
1193
1221
  readonly banReason: Schema.optional<Schema.String>;
1194
- readonly banExpiresIn: Schema.optional<Schema.Number>;
1222
+ readonly banExpiresIn: Schema.optional<Schema.Finite>;
1195
1223
  }>;
1196
1224
  export declare const AdminUserResponse: Schema.Struct<{
1197
1225
  readonly user: Schema.Struct<{
@@ -1,4 +1,13 @@
1
1
  import { Effect, Schema, SchemaIssue, SchemaTransformation } from "effect";
2
+ export const DeleteUserPayload = Schema.Struct({
3
+ password: Schema.optional(Schema.String),
4
+ token: Schema.optional(Schema.String),
5
+ callbackURL: Schema.optional(Schema.String),
6
+ }).annotate({ identifier: "DeleteUserPayload" });
7
+ export const DeleteUserResponse = Schema.Struct({
8
+ success: Schema.Boolean,
9
+ message: Schema.String,
10
+ }).annotate({ identifier: "DeleteUserResponse" });
2
11
  import { User, UserLocale, UserMetadata } from "../schema.js";
3
12
  const JsonRecord = Schema.Record(Schema.String, Schema.Json);
4
13
  const StringArrayRecord = Schema.Record(Schema.String, Schema.Array(Schema.String));
@@ -191,7 +200,7 @@ export const SocialIdToken = Schema.Struct({
191
200
  nonce: Schema.optional(Schema.String),
192
201
  accessToken: Schema.optional(Schema.String),
193
202
  refreshToken: Schema.optional(Schema.String),
194
- expiresAt: Schema.optional(Schema.Number),
203
+ expiresAt: Schema.optional(Schema.Finite),
195
204
  user: Schema.optional(Schema.Struct({
196
205
  name: Schema.optional(Schema.Struct({
197
206
  firstName: Schema.optional(Schema.String),
@@ -419,7 +428,7 @@ export const FullAuthOrganization = Schema.Struct({
419
428
  export const GetFullOrganizationQuery = Schema.Struct({
420
429
  organizationId: Schema.optional(Schema.String),
421
430
  organizationSlug: Schema.optional(Schema.String),
422
- membersLimit: Schema.optional(Schema.NumberFromString),
431
+ membersLimit: Schema.optional(Schema.FiniteFromString),
423
432
  }).annotate({
424
433
  identifier: "GetFullOrganizationQuery",
425
434
  title: "Get full organization query",
@@ -456,8 +465,8 @@ export const UpdateOrganizationPayload = Schema.Struct({
456
465
  title: "Update organization payload",
457
466
  });
458
467
  export const OrganizationListMembersQuery = Schema.Struct({
459
- limit: Schema.optional(Schema.NumberFromString),
460
- offset: Schema.optional(Schema.NumberFromString),
468
+ limit: Schema.optional(Schema.FiniteFromString),
469
+ offset: Schema.optional(Schema.FiniteFromString),
461
470
  sortBy: Schema.optional(Schema.String),
462
471
  sortDirection: Schema.optional(Schema.Literals(["asc", "desc"])),
463
472
  filterField: Schema.optional(Schema.String),
@@ -471,7 +480,7 @@ export const OrganizationListMembersQuery = Schema.Struct({
471
480
  });
472
481
  export const OrganizationListMembersResponse = Schema.Struct({
473
482
  members: Schema.Array(AuthMember),
474
- total: Schema.Number,
483
+ total: Schema.Finite,
475
484
  }).annotate({
476
485
  identifier: "OrganizationListMembersResponse",
477
486
  title: "List organization members response",
@@ -501,6 +510,9 @@ export const RemoveMemberPayload = Schema.Struct({
501
510
  identifier: "RemoveMemberPayload",
502
511
  title: "Remove member payload",
503
512
  });
513
+ export const DeleteOrganizationPayload = Schema.Struct({
514
+ organizationId: Schema.NonEmptyString,
515
+ }).annotate({ identifier: "DeleteOrganizationPayload" });
504
516
  export const LeaveOrganizationPayload = Schema.Struct({
505
517
  organizationId: Schema.String,
506
518
  }).annotate({
@@ -550,7 +562,7 @@ export const OrganizationImpersonateUserPayload = Schema.Struct({
550
562
  organizationId: Schema.NonEmptyString,
551
563
  actorUserId: Schema.NonEmptyString,
552
564
  targetUserId: Schema.NonEmptyString,
553
- expiresInSeconds: Schema.optional(Schema.Number),
565
+ expiresInSeconds: Schema.optional(Schema.Finite),
554
566
  }).annotate({
555
567
  identifier: "OrganizationImpersonateUserPayload",
556
568
  title: "Organization impersonate user payload",
@@ -568,15 +580,15 @@ export const AuthApiKey = Schema.Struct({
568
580
  userId: Schema.optional(Schema.String),
569
581
  referenceId: Schema.String,
570
582
  configId: Schema.String,
571
- refillInterval: Schema.NullOr(Schema.Number),
572
- refillAmount: Schema.NullOr(Schema.Number),
583
+ refillInterval: Schema.NullOr(Schema.Finite),
584
+ refillAmount: Schema.NullOr(Schema.Finite),
573
585
  lastRefillAt: Schema.NullOr(Schema.DateFromString),
574
586
  enabled: Schema.Boolean,
575
587
  rateLimitEnabled: Schema.Boolean,
576
- rateLimitTimeWindow: Schema.NullOr(Schema.Number),
577
- rateLimitMax: Schema.NullOr(Schema.Number),
578
- requestCount: Schema.Number,
579
- remaining: Schema.NullOr(Schema.Number),
588
+ rateLimitTimeWindow: Schema.NullOr(Schema.Finite),
589
+ rateLimitMax: Schema.NullOr(Schema.Finite),
590
+ requestCount: Schema.Finite,
591
+ remaining: Schema.NullOr(Schema.Finite),
580
592
  lastRequest: Schema.NullOr(Schema.DateFromString),
581
593
  expiresAt: Schema.NullOr(Schema.DateFromString),
582
594
  createdAt: Schema.DateFromString,
@@ -588,16 +600,16 @@ export const AuthApiKey = Schema.Struct({
588
600
  export const ListApiKeysQuery = Schema.Struct({
589
601
  configId: Schema.optional(Schema.String),
590
602
  organizationId: Schema.optional(Schema.String),
591
- limit: Schema.optional(Schema.NumberFromString),
592
- offset: Schema.optional(Schema.NumberFromString),
603
+ limit: Schema.optional(Schema.FiniteFromString),
604
+ offset: Schema.optional(Schema.FiniteFromString),
593
605
  sortBy: Schema.optional(Schema.String),
594
606
  sortDirection: Schema.optional(Schema.Literals(["asc", "desc"])),
595
607
  }).annotate({ identifier: "ListApiKeysQuery", title: "List API keys query" });
596
608
  export const ListApiKeysResponse = Schema.Struct({
597
609
  apiKeys: Schema.Array(AuthApiKey),
598
- total: Schema.Number,
599
- limit: Schema.optional(Schema.NullOr(Schema.Number)),
600
- offset: Schema.optional(Schema.NullOr(Schema.Number)),
610
+ total: Schema.Finite,
611
+ limit: Schema.optional(Schema.NullOr(Schema.Finite)),
612
+ offset: Schema.optional(Schema.NullOr(Schema.Finite)),
601
613
  }).annotate({
602
614
  identifier: "ListApiKeysResponse",
603
615
  title: "List API keys response",
@@ -622,7 +634,7 @@ export const AdminStopImpersonatingPayload = Schema.Struct({}).annotate({
622
634
  export const AdminBanUserPayload = Schema.Struct({
623
635
  userId: Schema.String,
624
636
  banReason: Schema.optional(Schema.String),
625
- banExpiresIn: Schema.optional(Schema.Number),
637
+ banExpiresIn: Schema.optional(Schema.Finite),
626
638
  }).annotate({ identifier: "AdminBanUserPayload", title: "Ban user payload" });
627
639
  export const AdminUserResponse = Schema.Struct({ user: AuthUser }).annotate({
628
640
  identifier: "AdminUserResponse",
@@ -0,0 +1,5 @@
1
+ import { Effect } from "effect";
2
+ export declare const requestAccountDeletion: (password: string, baseUrl?: string) => Effect.Effect<{
3
+ readonly success: boolean;
4
+ readonly message: string;
5
+ }, import("../auth/schema.js").AuthBadRequest | import("../auth/schema.js").AuthForbidden | import("../auth/schema.js").AuthInternalServerError | import("../auth/schema.js").AuthNotFound | import("../auth/schema.js").AuthUnauthorized | import("effect/http/HttpClientError").HttpClientError | import("effect/Schema").SchemaError, never>;
@@ -0,0 +1,7 @@
1
+ import { Effect } from "effect";
2
+ import { authHttpClient } from "./auth-client-api.js";
3
+ export const requestAccountDeletion = (password, baseUrl) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.deleteUser({
4
+ // Better Auth accepts an absent password, not null. Explicit undefined
5
+ // values are encoded as null by the HTTP API's JSON codec.
6
+ payload: password ? { password } : {},
7
+ })));
@@ -0,0 +1,8 @@
1
+ export type AccountDeletionLabels = Record<"title" | "description" | "projects" | "organizations" | "retention" | "missing" | "owner" | "admin" | "confirm" | "password" | "error" | "loadError" | "cancel" | "submit" | "done" | "complete", string>;
2
+ export declare const AccountDeletionDialog: (props: {
3
+ baseUrl?: string | undefined;
4
+ userId: string;
5
+ labels: AccountDeletionLabels;
6
+ onClose: () => void;
7
+ onDeleted: () => void;
8
+ }) => import("react").JSX.Element;
@@ -0,0 +1,59 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useAtomSet, useAtomValue } from "@effect/atom-react";
3
+ import { AsyncResult, Atom } from "effect/reactivity";
4
+ import { Schema } from "effect";
5
+ import { useId, useState } from "react";
6
+ import { AppWindow, Building2, TriangleAlert, UserRound } from "lucide-react";
7
+ import { Button } from "@/components/ui/button";
8
+ import { Card, CardContent } from "@/components/ui/card";
9
+ import { Input } from "@/components/ui/input";
10
+ import { FieldLabel } from "@/components/ui/field";
11
+ import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, } from "@/components/ui/dialog";
12
+ import { authClientApi } from "./auth-client-api.js";
13
+ import { requestAccountDeletion } from "./account-deletion-request.js";
14
+ import { refreshOnAuthChange } from "./auth-atoms.js";
15
+ const planQueries = Atom.family((baseUrl) => Atom.family((userId) => authClientApi(baseUrl)
16
+ .query("authExtra", "getAccountDeletionPlan", {
17
+ timeToLive: "0 seconds",
18
+ serializationKey: `account-deletion:${userId}`,
19
+ })
20
+ .pipe(refreshOnAuthChange)));
21
+ const plans = Atom.family((baseUrl) => Atom.family((userId) => Atom.optimistic(planQueries(baseUrl)(userId))));
22
+ export const AccountDeletionDialog = (props) => {
23
+ const [confirmation, setConfirmation] = useState("");
24
+ const passwordId = useId();
25
+ const confirmationId = useId();
26
+ const projectsId = useId();
27
+ const organizationsId = useId();
28
+ const [password, setPassword] = useState("");
29
+ const planResult = useAtomValue(plans(props.baseUrl)(props.userId));
30
+ const [mutation] = useState(() => authClientApi(props.baseUrl).runtime.fn((password) => requestAccountDeletion(password, props.baseUrl)));
31
+ const remove = useAtomSet(mutation);
32
+ const result = useAtomValue(mutation);
33
+ const plan = AsyncResult.match(planResult, {
34
+ onInitial: () => null,
35
+ onFailure: () => null,
36
+ onSuccess: ({ value }) => value,
37
+ });
38
+ const completed = AsyncResult.isSuccess(result) && result.value.success;
39
+ const blockedByOrganizations = (plan?.organizations.length ?? 0) > 0;
40
+ const busy = result.waiting;
41
+ const disabled = !plan ||
42
+ plan.organizations.length > 0 ||
43
+ plan.adminAccount ||
44
+ !Schema.is(Schema.Literal("DELETE"))(confirmation) ||
45
+ busy;
46
+ const labels = props.labels;
47
+ return (_jsx(Dialog, { open: true, onOpenChange: (open) => {
48
+ if (!open && !busy) {
49
+ if (completed)
50
+ props.onDeleted();
51
+ else
52
+ props.onClose();
53
+ }
54
+ }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: labels.title }), _jsx(DialogDescription, { children: completed ? labels.complete : labels.description })] }), completed ? (_jsx(Button, { onClick: props.onDeleted, children: labels.done })) : (_jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
55
+ event.preventDefault();
56
+ if (!disabled)
57
+ remove(password);
58
+ }, children: [plan ? (_jsxs(_Fragment, { children: [plan.projects.length ? (_jsxs("section", { "aria-labelledby": projectsId, className: "space-y-2", children: [_jsxs("h3", { id: projectsId, className: "text-muted-foreground text-xs font-medium", children: [labels.projects, " ", _jsx("span", { className: "ml-1 tabular-nums", children: plan.projects.length })] }), _jsx("ul", { className: "grid gap-2 sm:grid-cols-2", children: plan.projects.map((project) => (_jsx("li", { children: _jsx(Card, { size: "sm", className: "h-full py-3 shadow-none", children: _jsxs(CardContent, { className: "flex items-center gap-3 px-3", children: [_jsx("span", { className: "bg-muted text-muted-foreground flex size-9 shrink-0 items-center justify-center rounded-lg", children: _jsx(AppWindow, { "aria-hidden": "true", className: "size-4" }) }), _jsx("span", { className: "min-w-0 flex-1 text-sm font-medium break-words", children: project.name }), !project.ready ? (_jsxs("span", { title: labels.missing, className: "text-muted-foreground shrink-0", children: [_jsx(TriangleAlert, { "aria-hidden": "true", className: "size-4" }), _jsx("span", { className: "sr-only", children: labels.missing })] })) : null] }) }) }, project.id))) }), plan.projects.some((project) => !project.ready) ? (_jsx("p", { role: "status", className: "text-muted-foreground text-xs", children: labels.missing })) : null] })) : null, plan.organizations.length ? (_jsxs("section", { "aria-labelledby": organizationsId, className: "space-y-2", children: [_jsxs("h3", { id: organizationsId, className: "text-destructive text-xs font-medium", children: [labels.organizations, " ", _jsx("span", { className: "ml-1 tabular-nums", children: plan.organizations.length })] }), _jsx("ul", { className: "grid gap-2 sm:grid-cols-2", children: plan.organizations.map((organization) => (_jsx("li", { children: _jsx(Card, { size: "sm", className: "bg-destructive/5 ring-destructive/20 h-full py-3 shadow-none", children: _jsxs(CardContent, { className: "flex items-center gap-3 px-3", children: [_jsx("span", { className: "bg-destructive/10 text-destructive flex size-9 shrink-0 items-center justify-center rounded-lg", children: organization.personal ? (_jsx(UserRound, { "aria-hidden": "true", className: "size-4" })) : (_jsx(Building2, { "aria-hidden": "true", className: "size-4" })) }), _jsx("span", { className: "min-w-0 text-sm font-medium break-words", children: organization.name })] }) }) }, organization.id))) }), _jsx("p", { role: "alert", className: "text-destructive text-xs", children: labels.owner })] })) : null, plan.adminAccount ? (_jsx("p", { role: "alert", className: "text-destructive text-sm", children: labels.admin })) : null] })) : (_jsx("p", { role: "status", className: "text-muted-foreground text-sm", children: labels.loadError })), !blockedByOrganizations ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(FieldLabel, { htmlFor: passwordId, children: labels.password }), _jsx(Input, { id: passwordId, type: "password", autoComplete: "current-password", value: password, onChange: (event) => setPassword(event.target.value) })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(FieldLabel, { htmlFor: confirmationId, children: labels.confirm }), _jsx(Input, { id: confirmationId, value: confirmation, autoComplete: "off", onChange: (event) => setConfirmation(event.target.value) })] }), AsyncResult.isFailure(result) ? (_jsx("p", { role: "alert", className: "text-destructive text-sm", children: labels.error })) : null] })) : null, _jsx("p", { className: "text-muted-foreground text-xs", children: labels.retention }), _jsxs(DialogFooter, { children: [_jsx(Button, { type: "button", variant: "outline", disabled: busy, onClick: props.onClose, children: labels.cancel }), !blockedByOrganizations ? (_jsx(Button, { type: "submit", variant: "destructive", disabled: disabled, children: labels.submit })) : null] })] }))] }) }));
59
+ };