@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
package/dist/service.d.ts CHANGED
@@ -5,6 +5,7 @@ import { HttpApiError } from "effect/http-api";
5
5
  import { AuthClientConfig, type ClientConfig } from "./config.js";
6
6
  import { ExtraVerifiedApiKey } from "./extra/schema.js";
7
7
  import type { Session, User } from "./schema.js";
8
+ import type { OAuthResourceOptions } from "./oauth/schema.js";
8
9
  type ExtraVerifiedApiKeyType = typeof ExtraVerifiedApiKey.Type;
9
10
  export type AuthSession = {
10
11
  readonly session: Session;
@@ -12,6 +13,10 @@ export type AuthSession = {
12
13
  readonly isSuperAdminImpersonation: false;
13
14
  readonly authMethod: {
14
15
  readonly type: "cookie";
16
+ } | {
17
+ readonly type: "oauth";
18
+ readonly clientId: string;
19
+ readonly scopes: readonly string[];
15
20
  } | {
16
21
  readonly type: "apiKey";
17
22
  readonly apiKey: ExtraVerifiedApiKeyType;
@@ -27,15 +32,16 @@ export type AuthSessionWithUser = AuthSession & {
27
32
  };
28
33
  export type AuthSessionWithUserAndOrganization = AuthSessionWithUser & AuthSessionWithOrganization;
29
34
  export type AuthServiceLayerOptions = Partial<ClientConfig> & {
35
+ readonly oauth?: OAuthResourceOptions;
30
36
  readonly headers?: Record<string, string>;
31
37
  readonly apiKeyConfigId?: "user" | "organization" | "service";
32
38
  };
33
39
  declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/auth/AuthService", {
34
- getSession: () => Effect.Effect<AuthSession | null, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
35
- requireSession: () => Effect.Effect<AuthSession, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
36
- requireUser: () => Effect.Effect<AuthSessionWithUser, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
37
- requireOrganization: () => Effect.Effect<AuthSessionWithOrganization, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
38
- requireUserOrganization: () => Effect.Effect<AuthSessionWithUserAndOrganization, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
40
+ getSession: () => Effect.Effect<AuthSession | null, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
41
+ requireSession: () => Effect.Effect<AuthSession, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
42
+ requireUser: () => Effect.Effect<AuthSessionWithUser, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
43
+ requireOrganization: () => Effect.Effect<AuthSessionWithOrganization, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
44
+ requireUserOrganization: () => Effect.Effect<AuthSessionWithUserAndOrganization, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
39
45
  getActiveMemberRole: (input: {
40
46
  readonly organizationId: string;
41
47
  readonly userId: string;
@@ -44,7 +50,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
44
50
  readonly adminBanUser: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"adminBanUser", "POST", "/api/auth/admin/ban-user", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
45
51
  readonly userId: import("effect/Schema").String;
46
52
  readonly banReason: import("effect/Schema").optional<import("effect/Schema").String>;
47
- readonly banExpiresIn: import("effect/Schema").optional<import("effect/Schema").Number>;
53
+ readonly banExpiresIn: import("effect/Schema").optional<import("effect/Schema").Finite>;
48
54
  }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
49
55
  readonly user: import("effect/Schema").Struct<{
50
56
  readonly id: import("effect/Schema").String;
@@ -284,8 +290,8 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
284
290
  readonly apiKeyList: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"apiKeyList", "GET", "/api/auth/api-key/list", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
285
291
  readonly configId: import("effect/Schema").optional<import("effect/Schema").String>;
286
292
  readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
287
- readonly limit: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
288
- readonly offset: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
293
+ readonly limit: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
294
+ readonly offset: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
289
295
  readonly sortBy: import("effect/Schema").optional<import("effect/Schema").String>;
290
296
  readonly sortDirection: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["asc", "desc"]>>;
291
297
  }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
@@ -297,15 +303,15 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
297
303
  readonly userId: import("effect/Schema").optional<import("effect/Schema").String>;
298
304
  readonly referenceId: import("effect/Schema").String;
299
305
  readonly configId: import("effect/Schema").String;
300
- readonly refillInterval: import("effect/Schema").NullOr<import("effect/Schema").Number>;
301
- readonly refillAmount: import("effect/Schema").NullOr<import("effect/Schema").Number>;
306
+ readonly refillInterval: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
307
+ readonly refillAmount: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
302
308
  readonly lastRefillAt: import("effect/Schema").NullOr<import("effect/Schema").DateFromString>;
303
309
  readonly enabled: import("effect/Schema").Boolean;
304
310
  readonly rateLimitEnabled: import("effect/Schema").Boolean;
305
- readonly rateLimitTimeWindow: import("effect/Schema").NullOr<import("effect/Schema").Number>;
306
- readonly rateLimitMax: import("effect/Schema").NullOr<import("effect/Schema").Number>;
307
- readonly requestCount: import("effect/Schema").Number;
308
- readonly remaining: import("effect/Schema").NullOr<import("effect/Schema").Number>;
311
+ readonly rateLimitTimeWindow: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
312
+ readonly rateLimitMax: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
313
+ readonly requestCount: import("effect/Schema").Finite;
314
+ readonly remaining: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
309
315
  readonly lastRequest: import("effect/Schema").NullOr<import("effect/Schema").DateFromString>;
310
316
  readonly expiresAt: import("effect/Schema").NullOr<import("effect/Schema").DateFromString>;
311
317
  readonly createdAt: import("effect/Schema").DateFromString;
@@ -314,9 +320,9 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
314
320
  readonly permissions: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>>;
315
321
  readonly referrers: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").$Array<import("effect/Schema").String>>>;
316
322
  }>>;
317
- readonly total: import("effect/Schema").Number;
318
- readonly limit: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Number>>;
319
- readonly offset: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Number>>;
323
+ readonly total: import("effect/Schema").Finite;
324
+ readonly limit: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Finite>>;
325
+ readonly offset: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Finite>>;
320
326
  }>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
321
327
  readonly changePassword: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"changePassword", "POST", "/api/auth/change-password", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
322
328
  readonly newPassword: import("effect/Schema").String;
@@ -373,6 +379,14 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
373
379
  readonly updatedAt: import("effect/Schema").DateFromString;
374
380
  }>;
375
381
  }>>, 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>;
382
+ 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<{
383
+ readonly password: import("effect/Schema").optional<import("effect/Schema").String>;
384
+ readonly token: import("effect/Schema").optional<import("effect/Schema").String>;
385
+ readonly callbackURL: import("effect/Schema").optional<import("effect/Schema").String>;
386
+ }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
387
+ readonly success: import("effect/Schema").Boolean;
388
+ readonly message: import("effect/Schema").String;
389
+ }>>, 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
390
  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
391
  readonly disableCookieCache: import("effect/Schema").optional<import("effect/Schema").String>;
378
392
  readonly disableRefresh: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -591,10 +605,22 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
591
605
  readonly parentId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
592
606
  readonly createdAt: import("effect/Schema").DateFromString;
593
607
  }>>, 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>;
608
+ 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<{
609
+ readonly organizationId: import("effect/Schema").NonEmptyString;
610
+ }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
611
+ readonly id: import("effect/Schema").String;
612
+ readonly name: import("effect/Schema").String;
613
+ readonly slug: import("effect/Schema").String;
614
+ readonly logo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
615
+ 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]>>>;
616
+ readonly userId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
617
+ readonly parentId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
618
+ readonly createdAt: import("effect/Schema").DateFromString;
619
+ }>>, 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
620
  readonly organizationGetFull: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationGetFull", "GET", "/api/auth/organization/get-full-organization", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
595
621
  readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
596
622
  readonly organizationSlug: import("effect/Schema").optional<import("effect/Schema").String>;
597
- readonly membersLimit: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
623
+ readonly membersLimit: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
598
624
  }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").NullOr<import("effect/Schema").Struct<{
599
625
  readonly id: import("effect/Schema").String;
600
626
  readonly name: import("effect/Schema").String;
@@ -682,7 +708,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
682
708
  readonly organizationId: import("effect/Schema").NonEmptyString;
683
709
  readonly actorUserId: import("effect/Schema").NonEmptyString;
684
710
  readonly targetUserId: import("effect/Schema").NonEmptyString;
685
- readonly expiresInSeconds: import("effect/Schema").optional<import("effect/Schema").Number>;
711
+ readonly expiresInSeconds: import("effect/Schema").optional<import("effect/Schema").Finite>;
686
712
  }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
687
713
  readonly session: import("effect/Schema").Struct<{
688
714
  readonly id: import("effect/Schema").String;
@@ -798,8 +824,8 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
798
824
  readonly createdAt: import("effect/Schema").optional<import("effect/Schema").DateFromString>;
799
825
  }>>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
800
826
  readonly organizationListMembers: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationListMembers", "GET", "/api/auth/organization/list-members", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
801
- readonly limit: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
802
- readonly offset: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
827
+ readonly limit: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
828
+ readonly offset: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
803
829
  readonly sortBy: import("effect/Schema").optional<import("effect/Schema").String>;
804
830
  readonly sortDirection: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["asc", "desc"]>>;
805
831
  readonly filterField: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -853,7 +879,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
853
879
  }>, import("effect/Schema").Unknown, never, never>>>;
854
880
  }>;
855
881
  }>>;
856
- readonly total: import("effect/Schema").Number;
882
+ readonly total: import("effect/Schema").Finite;
857
883
  }>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
858
884
  readonly organizationListUserInvitations: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationListUserInvitations", "GET", "/api/auth/organization/list-user-invitations", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").$Array<import("effect/Schema").Struct<{
859
885
  readonly id: import("effect/Schema").String;
@@ -1094,7 +1120,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
1094
1120
  readonly nonce: import("effect/Schema").optional<import("effect/Schema").String>;
1095
1121
  readonly accessToken: import("effect/Schema").optional<import("effect/Schema").String>;
1096
1122
  readonly refreshToken: import("effect/Schema").optional<import("effect/Schema").String>;
1097
- readonly expiresAt: import("effect/Schema").optional<import("effect/Schema").Number>;
1123
+ readonly expiresAt: import("effect/Schema").optional<import("effect/Schema").Finite>;
1098
1124
  readonly user: import("effect/Schema").optional<import("effect/Schema").Struct<{
1099
1125
  readonly name: import("effect/Schema").optional<import("effect/Schema").Struct<{
1100
1126
  readonly firstName: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -1460,6 +1486,19 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
1460
1486
  readonly id: import("effect/Schema").String;
1461
1487
  readonly key: import("effect/Schema").String;
1462
1488
  }>>, import("effect/Schema").toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof import("./extra/schema.js").ExtraBadRequest>, never, never>, never, never>;
1489
+ 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<{
1490
+ readonly projects: import("effect/Schema").$Array<import("effect/Schema").Struct<{
1491
+ readonly id: import("effect/Schema").String;
1492
+ readonly name: import("effect/Schema").String;
1493
+ readonly ready: import("effect/Schema").Boolean;
1494
+ }>>;
1495
+ readonly organizations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
1496
+ readonly id: import("effect/Schema").String;
1497
+ readonly name: import("effect/Schema").String;
1498
+ readonly personal: import("effect/Schema").Boolean;
1499
+ }>>;
1500
+ readonly adminAccount: import("effect/Schema").Boolean;
1501
+ }>>, import("effect/Schema").toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError>, never, never>, never, never>;
1463
1502
  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
1503
  readonly organizationId: import("effect/Schema").String;
1465
1504
  readonly locale: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>>;
@@ -2080,11 +2119,11 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2080
2119
  };
2081
2120
  }> & {
2082
2121
  readonly make: (options?: AuthServiceLayerOptions) => Effect.Effect<{
2083
- getSession: () => Effect.Effect<AuthSession | null, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
2084
- requireSession: () => Effect.Effect<AuthSession, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
2085
- requireUser: () => Effect.Effect<AuthSessionWithUser, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
2086
- requireOrganization: () => Effect.Effect<AuthSessionWithOrganization, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
2087
- requireUserOrganization: () => Effect.Effect<AuthSessionWithUserAndOrganization, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
2122
+ getSession: () => Effect.Effect<AuthSession | null, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
2123
+ requireSession: () => Effect.Effect<AuthSession, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
2124
+ requireUser: () => Effect.Effect<AuthSessionWithUser, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
2125
+ requireOrganization: () => Effect.Effect<AuthSessionWithOrganization, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
2126
+ requireUserOrganization: () => Effect.Effect<AuthSessionWithUserAndOrganization, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
2088
2127
  getActiveMemberRole: (input: {
2089
2128
  readonly organizationId: string;
2090
2129
  readonly userId: string;
@@ -2093,7 +2132,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2093
2132
  readonly adminBanUser: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"adminBanUser", "POST", "/api/auth/admin/ban-user", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2094
2133
  readonly userId: import("effect/Schema").String;
2095
2134
  readonly banReason: import("effect/Schema").optional<import("effect/Schema").String>;
2096
- readonly banExpiresIn: import("effect/Schema").optional<import("effect/Schema").Number>;
2135
+ readonly banExpiresIn: import("effect/Schema").optional<import("effect/Schema").Finite>;
2097
2136
  }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2098
2137
  readonly user: import("effect/Schema").Struct<{
2099
2138
  readonly id: import("effect/Schema").String;
@@ -2333,8 +2372,8 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2333
2372
  readonly apiKeyList: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"apiKeyList", "GET", "/api/auth/api-key/list", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
2334
2373
  readonly configId: import("effect/Schema").optional<import("effect/Schema").String>;
2335
2374
  readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
2336
- readonly limit: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
2337
- readonly offset: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
2375
+ readonly limit: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
2376
+ readonly offset: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
2338
2377
  readonly sortBy: import("effect/Schema").optional<import("effect/Schema").String>;
2339
2378
  readonly sortDirection: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["asc", "desc"]>>;
2340
2379
  }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
@@ -2346,15 +2385,15 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2346
2385
  readonly userId: import("effect/Schema").optional<import("effect/Schema").String>;
2347
2386
  readonly referenceId: import("effect/Schema").String;
2348
2387
  readonly configId: import("effect/Schema").String;
2349
- readonly refillInterval: import("effect/Schema").NullOr<import("effect/Schema").Number>;
2350
- readonly refillAmount: import("effect/Schema").NullOr<import("effect/Schema").Number>;
2388
+ readonly refillInterval: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
2389
+ readonly refillAmount: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
2351
2390
  readonly lastRefillAt: import("effect/Schema").NullOr<import("effect/Schema").DateFromString>;
2352
2391
  readonly enabled: import("effect/Schema").Boolean;
2353
2392
  readonly rateLimitEnabled: import("effect/Schema").Boolean;
2354
- readonly rateLimitTimeWindow: import("effect/Schema").NullOr<import("effect/Schema").Number>;
2355
- readonly rateLimitMax: import("effect/Schema").NullOr<import("effect/Schema").Number>;
2356
- readonly requestCount: import("effect/Schema").Number;
2357
- readonly remaining: import("effect/Schema").NullOr<import("effect/Schema").Number>;
2393
+ readonly rateLimitTimeWindow: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
2394
+ readonly rateLimitMax: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
2395
+ readonly requestCount: import("effect/Schema").Finite;
2396
+ readonly remaining: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
2358
2397
  readonly lastRequest: import("effect/Schema").NullOr<import("effect/Schema").DateFromString>;
2359
2398
  readonly expiresAt: import("effect/Schema").NullOr<import("effect/Schema").DateFromString>;
2360
2399
  readonly createdAt: import("effect/Schema").DateFromString;
@@ -2363,9 +2402,9 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2363
2402
  readonly permissions: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>>;
2364
2403
  readonly referrers: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").$Array<import("effect/Schema").String>>>;
2365
2404
  }>>;
2366
- readonly total: import("effect/Schema").Number;
2367
- readonly limit: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Number>>;
2368
- readonly offset: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Number>>;
2405
+ readonly total: import("effect/Schema").Finite;
2406
+ readonly limit: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Finite>>;
2407
+ readonly offset: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Finite>>;
2369
2408
  }>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
2370
2409
  readonly changePassword: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"changePassword", "POST", "/api/auth/change-password", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2371
2410
  readonly newPassword: import("effect/Schema").String;
@@ -2422,6 +2461,14 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2422
2461
  readonly updatedAt: import("effect/Schema").DateFromString;
2423
2462
  }>;
2424
2463
  }>>, 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>;
2464
+ 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<{
2465
+ readonly password: import("effect/Schema").optional<import("effect/Schema").String>;
2466
+ readonly token: import("effect/Schema").optional<import("effect/Schema").String>;
2467
+ readonly callbackURL: import("effect/Schema").optional<import("effect/Schema").String>;
2468
+ }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2469
+ readonly success: import("effect/Schema").Boolean;
2470
+ readonly message: import("effect/Schema").String;
2471
+ }>>, 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
2472
  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
2473
  readonly disableCookieCache: import("effect/Schema").optional<import("effect/Schema").String>;
2427
2474
  readonly disableRefresh: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -2640,10 +2687,22 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2640
2687
  readonly parentId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
2641
2688
  readonly createdAt: import("effect/Schema").DateFromString;
2642
2689
  }>>, 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>;
2690
+ 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<{
2691
+ readonly organizationId: import("effect/Schema").NonEmptyString;
2692
+ }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2693
+ readonly id: import("effect/Schema").String;
2694
+ readonly name: import("effect/Schema").String;
2695
+ readonly slug: import("effect/Schema").String;
2696
+ readonly logo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
2697
+ 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]>>>;
2698
+ readonly userId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
2699
+ readonly parentId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
2700
+ readonly createdAt: import("effect/Schema").DateFromString;
2701
+ }>>, 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
2702
  readonly organizationGetFull: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationGetFull", "GET", "/api/auth/organization/get-full-organization", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
2644
2703
  readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
2645
2704
  readonly organizationSlug: import("effect/Schema").optional<import("effect/Schema").String>;
2646
- readonly membersLimit: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
2705
+ readonly membersLimit: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
2647
2706
  }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").NullOr<import("effect/Schema").Struct<{
2648
2707
  readonly id: import("effect/Schema").String;
2649
2708
  readonly name: import("effect/Schema").String;
@@ -2731,7 +2790,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2731
2790
  readonly organizationId: import("effect/Schema").NonEmptyString;
2732
2791
  readonly actorUserId: import("effect/Schema").NonEmptyString;
2733
2792
  readonly targetUserId: import("effect/Schema").NonEmptyString;
2734
- readonly expiresInSeconds: import("effect/Schema").optional<import("effect/Schema").Number>;
2793
+ readonly expiresInSeconds: import("effect/Schema").optional<import("effect/Schema").Finite>;
2735
2794
  }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2736
2795
  readonly session: import("effect/Schema").Struct<{
2737
2796
  readonly id: import("effect/Schema").String;
@@ -2847,8 +2906,8 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2847
2906
  readonly createdAt: import("effect/Schema").optional<import("effect/Schema").DateFromString>;
2848
2907
  }>>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
2849
2908
  readonly organizationListMembers: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationListMembers", "GET", "/api/auth/organization/list-members", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
2850
- readonly limit: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
2851
- readonly offset: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
2909
+ readonly limit: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
2910
+ readonly offset: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
2852
2911
  readonly sortBy: import("effect/Schema").optional<import("effect/Schema").String>;
2853
2912
  readonly sortDirection: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["asc", "desc"]>>;
2854
2913
  readonly filterField: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -2902,7 +2961,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2902
2961
  }>, import("effect/Schema").Unknown, never, never>>>;
2903
2962
  }>;
2904
2963
  }>>;
2905
- readonly total: import("effect/Schema").Number;
2964
+ readonly total: import("effect/Schema").Finite;
2906
2965
  }>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
2907
2966
  readonly organizationListUserInvitations: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationListUserInvitations", "GET", "/api/auth/organization/list-user-invitations", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").$Array<import("effect/Schema").Struct<{
2908
2967
  readonly id: import("effect/Schema").String;
@@ -3143,7 +3202,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
3143
3202
  readonly nonce: import("effect/Schema").optional<import("effect/Schema").String>;
3144
3203
  readonly accessToken: import("effect/Schema").optional<import("effect/Schema").String>;
3145
3204
  readonly refreshToken: import("effect/Schema").optional<import("effect/Schema").String>;
3146
- readonly expiresAt: import("effect/Schema").optional<import("effect/Schema").Number>;
3205
+ readonly expiresAt: import("effect/Schema").optional<import("effect/Schema").Finite>;
3147
3206
  readonly user: import("effect/Schema").optional<import("effect/Schema").Struct<{
3148
3207
  readonly name: import("effect/Schema").optional<import("effect/Schema").Struct<{
3149
3208
  readonly firstName: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -3509,6 +3568,19 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
3509
3568
  readonly id: import("effect/Schema").String;
3510
3569
  readonly key: import("effect/Schema").String;
3511
3570
  }>>, import("effect/Schema").toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof import("./extra/schema.js").ExtraBadRequest>, never, never>, never, never>;
3571
+ 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<{
3572
+ readonly projects: import("effect/Schema").$Array<import("effect/Schema").Struct<{
3573
+ readonly id: import("effect/Schema").String;
3574
+ readonly name: import("effect/Schema").String;
3575
+ readonly ready: import("effect/Schema").Boolean;
3576
+ }>>;
3577
+ readonly organizations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
3578
+ readonly id: import("effect/Schema").String;
3579
+ readonly name: import("effect/Schema").String;
3580
+ readonly personal: import("effect/Schema").Boolean;
3581
+ }>>;
3582
+ readonly adminAccount: import("effect/Schema").Boolean;
3583
+ }>>, import("effect/Schema").toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError>, never, never>, never, never>;
3512
3584
  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
3585
  readonly organizationId: import("effect/Schema").String;
3514
3586
  readonly locale: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>>;
package/dist/service.js CHANGED
@@ -51,7 +51,7 @@ class SessionLookup extends Context.Service()("@krak-stack/auth/SessionLookup")
51
51
  }
52
52
  const sessionCache = Effect.runSync(Cache.makeWith(() => Effect.gen(function* () {
53
53
  const lookup = yield* SessionLookup;
54
- return yield* lookup.getSession();
54
+ return yield* lookup.getSession;
55
55
  }), {
56
56
  capacity: 500,
57
57
  timeToLive: (exit) => Exit.isSuccess(exit) ? Duration.seconds(2) : Duration.zero,
@@ -72,10 +72,13 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
72
72
  });
73
73
  const sessionCacheKey = getSessionCacheKey(headers);
74
74
  const apiKey = headerValue(headers, "x-api-key")?.trim();
75
+ const authorization = headerValue(headers, "authorization");
75
76
  const organizationId = headerValue(headers, "x-organization-id")?.trim();
76
77
  const getCookieSession = () => Cache.get(sessionCache, sessionCacheKey).pipe(Effect.provideService(SessionLookup, {
77
- getSession: () => api.auth.getSession({ query: {} }),
78
- }), Effect.mapError(serviceUnavailable), Effect.map((authSession) => authSession
78
+ getSession: api.auth
79
+ .getSession({ query: {} })
80
+ .pipe(Effect.mapError(serviceUnavailable)),
81
+ }), Effect.map((authSession) => authSession
79
82
  ? {
80
83
  ...authSession,
81
84
  isSuperAdminImpersonation: false,
@@ -84,7 +87,7 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
84
87
  : null));
85
88
  const userForApiKey = (verifiedKey) => {
86
89
  if (verifiedKey.configId === "organization") {
87
- return Effect.succeed(undefined);
90
+ return Effect.undefined;
88
91
  }
89
92
  return api.users
90
93
  .getUser({ params: { id: verifiedKey.referenceId } })
@@ -111,7 +114,7 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
111
114
  .verifyApiKey({ payload: verifyPayload })
112
115
  .pipe(Effect.mapError(serviceUnavailable));
113
116
  if (!verified.valid || !verified.key) {
114
- return yield* Effect.fail(unauthorized());
117
+ return yield* unauthorized();
115
118
  }
116
119
  const user = yield* userForApiKey(verified.key);
117
120
  const activeOrganization = yield* activeOrganizationIdForApiKey(verified.key, user);
@@ -134,10 +137,54 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
134
137
  },
135
138
  };
136
139
  });
137
- const getSession = () => (apiKey ? getApiKeySession(apiKey) : getCookieSession());
138
- const requireSession = () => getSession().pipe(Effect.flatMap((authSession) => authSession
139
- ? Effect.succeed(authSession)
140
- : Effect.fail(unauthorized())));
140
+ const getOAuthSession = () => Effect.gen(function* () {
141
+ // An explicit Authorization header must never downgrade to cookies
142
+ // or an API key, even if OAuth is not configured for this service.
143
+ const match = authorization?.match(/^Bearer ([^\s]+)$/i);
144
+ if (!options.oauth || !match?.[1])
145
+ return yield* unauthorized();
146
+ const { verifyOAuthAccessToken } = yield* Effect.promise(() => import("./oauth/verify.js"));
147
+ const claims = yield* verifyOAuthAccessToken(match[1], options.oauth).pipe(Effect.provideService(HttpClient.HttpClient, http));
148
+ const user = yield* api.users
149
+ .getUser({ params: { id: claims.sub } })
150
+ .pipe(Effect.mapError(serviceUnavailable));
151
+ if (user.banned)
152
+ return yield* unauthorized();
153
+ // Consent binds the organization. A caller header or a later browser
154
+ // organization switch must not change the grant's tenant.
155
+ yield* api.organizations
156
+ .getActiveMember({
157
+ params: {
158
+ organizationId: claims.organization_id,
159
+ userId: user.id,
160
+ },
161
+ })
162
+ .pipe(Effect.mapError(() => new HttpApiError.Forbidden({})));
163
+ return {
164
+ session: {
165
+ id: `oauth:${claims.azp}:${claims.sub}`,
166
+ token: "",
167
+ userId: user.id,
168
+ activeOrganizationId: claims.organization_id,
169
+ createdAt: new Date(claims.iat * 1000),
170
+ updatedAt: new Date(claims.iat * 1000),
171
+ expiresAt: new Date(claims.exp * 1000),
172
+ },
173
+ user,
174
+ isSuperAdminImpersonation: false,
175
+ authMethod: {
176
+ type: "oauth",
177
+ clientId: claims.azp,
178
+ scopes: claims.scope.split(/\s+/).filter(Boolean),
179
+ },
180
+ };
181
+ });
182
+ const getSession = () => authorization !== undefined
183
+ ? getOAuthSession()
184
+ : apiKey
185
+ ? getApiKeySession(apiKey)
186
+ : getCookieSession();
187
+ const requireSession = () => getSession().pipe(Effect.filterOrFail((authSession) => authSession !== null, () => unauthorized()));
141
188
  const requireUser = () => requireSession().pipe(Effect.flatMap((authSession) => authSession.user
142
189
  ? Effect.succeed({ ...authSession, user: authSession.user })
143
190
  : Effect.fail(unauthorized())));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.2.31",
3
+ "version": "0.3.0",
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"
@@ -71,15 +75,16 @@
71
75
  "prepack": "bun run build"
72
76
  },
73
77
  "dependencies": {
78
+ "@better-auth/core": "1.7.6",
74
79
  "@effect/atom-react": "^4.1.0",
75
80
  "@lucas-barake/effect-form-react": "1.1.0",
76
81
  "react-qr-code": "^2.2.0"
77
82
  },
78
83
  "devDependencies": {
79
- "@krak-stack/registry": "0.1.58"
84
+ "@krak-stack/registry": "0.1.61"
80
85
  },
81
86
  "peerDependencies": {
82
- "@krak-stack/registry": "^0.1.58",
87
+ "@krak-stack/registry": "^0.1.61",
83
88
  "@tanstack/react-router": "^1.170.15",
84
89
  "effect": "^4.1.0",
85
90
  "input-otp": "^1.5.0",