@krak-stack/auth 0.2.32 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +101 -5
  3. package/dist/access.d.ts +3 -1
  4. package/dist/admin/api.group.d.ts +41 -41
  5. package/dist/admin/schema.d.ts +23 -23
  6. package/dist/admin/schema.js +21 -19
  7. package/dist/api.d.ts +126 -77
  8. package/dist/auth/api.group.d.ts +18 -18
  9. package/dist/auth/schema.d.ts +49 -33
  10. package/dist/auth/schema.js +18 -18
  11. package/dist/components/admin-organization-form.js +2 -2
  12. package/dist/components/admin-organizations.js +6 -5
  13. package/dist/components/admin-users.js +6 -6
  14. package/dist/components/api-key-edit-form.js +19 -11
  15. package/dist/components/associated-projects-notice.d.ts +2 -1
  16. package/dist/components/associated-projects-notice.js +6 -2
  17. package/dist/components/auth-atoms.js +1 -2
  18. package/dist/components/auth-client-api.d.ts +61 -61
  19. package/dist/components/auth-forms.d.ts +1 -0
  20. package/dist/components/auth-forms.js +41 -56
  21. package/dist/components/auth-provider.d.ts +3 -1
  22. package/dist/components/hooks.d.ts +2 -0
  23. package/dist/components/hooks.js +13 -6
  24. package/dist/components/index.d.ts +3 -0
  25. package/dist/components/index.js +2 -0
  26. package/dist/components/member-required.js +3 -5
  27. package/dist/components/oauth-consent.d.ts +22 -0
  28. package/dist/components/oauth-consent.js +79 -0
  29. package/dist/components/organization-switcher.d.ts +1 -1
  30. package/dist/components/organization-switcher.js +83 -54
  31. package/dist/components/project-card-list.d.ts +6 -0
  32. package/dist/components/project-card-list.js +4 -0
  33. package/dist/components/user-button.js +115 -54
  34. package/dist/extra/schema.d.ts +3 -1
  35. package/dist/oauth/authorization.d.ts +3 -0
  36. package/dist/oauth/authorization.js +39 -0
  37. package/dist/oauth/schema.d.ts +24 -0
  38. package/dist/oauth/schema.js +12 -0
  39. package/dist/oauth/verify.d.ts +13 -0
  40. package/dist/oauth/verify.js +67 -0
  41. package/dist/schema.js +1 -1
  42. package/dist/server/actor.js +2 -4
  43. package/dist/server/api.group.d.ts +49 -0
  44. package/dist/server/api.group.js +10 -1
  45. package/dist/server/index.d.ts +3 -1
  46. package/dist/server/index.js +2 -1
  47. package/dist/server/mcp.d.ts +20 -0
  48. package/dist/server/mcp.js +66 -0
  49. package/dist/server/middleware.d.ts +5 -5
  50. package/dist/server/middleware.js +15 -5
  51. package/dist/server/schema.d.ts +51 -0
  52. package/dist/server/schema.js +7 -0
  53. package/dist/server/webhook-layer.js +8 -4
  54. package/dist/server/webhooks.d.ts +9 -3
  55. package/dist/service.d.ts +152 -46
  56. package/dist/service.js +56 -9
  57. package/package.json +2 -1
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;
@@ -614,7 +620,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
614
620
  readonly organizationGetFull: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationGetFull", "GET", "/api/auth/organization/get-full-organization", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
615
621
  readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
616
622
  readonly organizationSlug: import("effect/Schema").optional<import("effect/Schema").String>;
617
- readonly membersLimit: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
623
+ readonly membersLimit: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
618
624
  }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").NullOr<import("effect/Schema").Struct<{
619
625
  readonly id: import("effect/Schema").String;
620
626
  readonly name: import("effect/Schema").String;
@@ -702,7 +708,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
702
708
  readonly organizationId: import("effect/Schema").NonEmptyString;
703
709
  readonly actorUserId: import("effect/Schema").NonEmptyString;
704
710
  readonly targetUserId: import("effect/Schema").NonEmptyString;
705
- readonly expiresInSeconds: import("effect/Schema").optional<import("effect/Schema").Number>;
711
+ readonly expiresInSeconds: import("effect/Schema").optional<import("effect/Schema").Finite>;
706
712
  }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
707
713
  readonly session: import("effect/Schema").Struct<{
708
714
  readonly id: import("effect/Schema").String;
@@ -818,8 +824,8 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
818
824
  readonly createdAt: import("effect/Schema").optional<import("effect/Schema").DateFromString>;
819
825
  }>>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
820
826
  readonly organizationListMembers: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationListMembers", "GET", "/api/auth/organization/list-members", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
821
- readonly limit: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
822
- 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>;
823
829
  readonly sortBy: import("effect/Schema").optional<import("effect/Schema").String>;
824
830
  readonly sortDirection: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["asc", "desc"]>>;
825
831
  readonly filterField: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -873,7 +879,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
873
879
  }>, import("effect/Schema").Unknown, never, never>>>;
874
880
  }>;
875
881
  }>>;
876
- readonly total: import("effect/Schema").Number;
882
+ readonly total: import("effect/Schema").Finite;
877
883
  }>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
878
884
  readonly organizationListUserInvitations: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationListUserInvitations", "GET", "/api/auth/organization/list-user-invitations", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").$Array<import("effect/Schema").Struct<{
879
885
  readonly id: import("effect/Schema").String;
@@ -1114,7 +1120,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
1114
1120
  readonly nonce: import("effect/Schema").optional<import("effect/Schema").String>;
1115
1121
  readonly accessToken: import("effect/Schema").optional<import("effect/Schema").String>;
1116
1122
  readonly refreshToken: import("effect/Schema").optional<import("effect/Schema").String>;
1117
- readonly expiresAt: import("effect/Schema").optional<import("effect/Schema").Number>;
1123
+ readonly expiresAt: import("effect/Schema").optional<import("effect/Schema").Finite>;
1118
1124
  readonly user: import("effect/Schema").optional<import("effect/Schema").Struct<{
1119
1125
  readonly name: import("effect/Schema").optional<import("effect/Schema").Struct<{
1120
1126
  readonly firstName: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -2060,6 +2066,56 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2060
2066
  }>>, never, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2061
2067
  readonly id: import("effect/Schema").NullOr<import("effect/Schema").String>;
2062
2068
  }>>, import("effect/Schema").toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.InternalServerError>, never, never>, never, never>;
2069
+ readonly listUsersByEmails: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"listUsersByEmails", "GET", "/api/users/by-email", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
2070
+ readonly emails: import("effect/Schema").NonEmptyString;
2071
+ }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2072
+ readonly data: import("effect/Schema").$Array<import("effect/Schema").Struct<{
2073
+ readonly id: import("effect/Schema").String;
2074
+ readonly name: import("effect/Schema").String;
2075
+ readonly email: import("effect/Schema").String;
2076
+ readonly emailVerified: import("effect/Schema").Boolean;
2077
+ readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
2078
+ readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
2079
+ readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
2080
+ readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
2081
+ readonly email: import("effect/Schema").NonEmptyString;
2082
+ readonly translations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
2083
+ readonly locale: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>;
2084
+ readonly label: import("effect/Schema").NonEmptyString;
2085
+ }>>;
2086
+ }>>>;
2087
+ readonly phones: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
2088
+ readonly number: import("effect/Schema").NonEmptyString;
2089
+ readonly extension: import("effect/Schema").optional<import("effect/Schema").String>;
2090
+ readonly translations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
2091
+ readonly locale: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>;
2092
+ readonly label: import("effect/Schema").NonEmptyString;
2093
+ }>>;
2094
+ }>>>;
2095
+ readonly websites: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
2096
+ readonly url: import("effect/Schema").NonEmptyString;
2097
+ readonly translations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
2098
+ readonly locale: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>;
2099
+ readonly label: import("effect/Schema").NonEmptyString;
2100
+ }>>;
2101
+ }>>>;
2102
+ readonly socials: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
2103
+ readonly platform: import("effect/Schema").Literals<readonly ["facebook", "github", "instagram", "linkedin", "tiktok", "x", "youtube"]>;
2104
+ readonly url: import("effect/Schema").NonEmptyString;
2105
+ readonly translations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
2106
+ readonly locale: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>;
2107
+ readonly label: import("effect/Schema").NonEmptyString;
2108
+ }>>;
2109
+ }>>>;
2110
+ }>, import("effect/Schema").Unknown, never, never>>>;
2111
+ readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
2112
+ readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
2113
+ readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
2114
+ readonly createdAt: import("effect/Schema").Date;
2115
+ readonly updatedAt: import("effect/Schema").Date;
2116
+ }>>;
2117
+ readonly missingEmails: import("effect/Schema").$Array<import("effect/Schema").String>;
2118
+ }>>, import("effect/Schema").toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.InternalServerError>, never, never>, never, never>;
2063
2119
  readonly listUsersByIds: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"listUsersByIds", "GET", "/api/users", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
2064
2120
  readonly ids: import("effect/Schema").NonEmptyString;
2065
2121
  }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
@@ -2113,11 +2169,11 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2113
2169
  };
2114
2170
  }> & {
2115
2171
  readonly make: (options?: AuthServiceLayerOptions) => Effect.Effect<{
2116
- getSession: () => Effect.Effect<AuthSession | null, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
2117
- requireSession: () => Effect.Effect<AuthSession, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
2118
- requireUser: () => Effect.Effect<AuthSessionWithUser, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
2119
- requireOrganization: () => Effect.Effect<AuthSessionWithOrganization, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
2120
- requireUserOrganization: () => Effect.Effect<AuthSessionWithUserAndOrganization, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
2172
+ getSession: () => Effect.Effect<AuthSession | null, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
2173
+ requireSession: () => Effect.Effect<AuthSession, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
2174
+ requireUser: () => Effect.Effect<AuthSessionWithUser, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
2175
+ requireOrganization: () => Effect.Effect<AuthSessionWithOrganization, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
2176
+ requireUserOrganization: () => Effect.Effect<AuthSessionWithUserAndOrganization, HttpApiError.Unauthorized | HttpApiError.Forbidden | HttpApiError.ServiceUnavailable>;
2121
2177
  getActiveMemberRole: (input: {
2122
2178
  readonly organizationId: string;
2123
2179
  readonly userId: string;
@@ -2126,7 +2182,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2126
2182
  readonly adminBanUser: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"adminBanUser", "POST", "/api/auth/admin/ban-user", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2127
2183
  readonly userId: import("effect/Schema").String;
2128
2184
  readonly banReason: import("effect/Schema").optional<import("effect/Schema").String>;
2129
- readonly banExpiresIn: import("effect/Schema").optional<import("effect/Schema").Number>;
2185
+ readonly banExpiresIn: import("effect/Schema").optional<import("effect/Schema").Finite>;
2130
2186
  }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2131
2187
  readonly user: import("effect/Schema").Struct<{
2132
2188
  readonly id: import("effect/Schema").String;
@@ -2366,8 +2422,8 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2366
2422
  readonly apiKeyList: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"apiKeyList", "GET", "/api/auth/api-key/list", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
2367
2423
  readonly configId: import("effect/Schema").optional<import("effect/Schema").String>;
2368
2424
  readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
2369
- readonly limit: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
2370
- readonly offset: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
2425
+ readonly limit: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
2426
+ readonly offset: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
2371
2427
  readonly sortBy: import("effect/Schema").optional<import("effect/Schema").String>;
2372
2428
  readonly sortDirection: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["asc", "desc"]>>;
2373
2429
  }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
@@ -2379,15 +2435,15 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2379
2435
  readonly userId: import("effect/Schema").optional<import("effect/Schema").String>;
2380
2436
  readonly referenceId: import("effect/Schema").String;
2381
2437
  readonly configId: import("effect/Schema").String;
2382
- readonly refillInterval: import("effect/Schema").NullOr<import("effect/Schema").Number>;
2383
- readonly refillAmount: import("effect/Schema").NullOr<import("effect/Schema").Number>;
2438
+ readonly refillInterval: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
2439
+ readonly refillAmount: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
2384
2440
  readonly lastRefillAt: import("effect/Schema").NullOr<import("effect/Schema").DateFromString>;
2385
2441
  readonly enabled: import("effect/Schema").Boolean;
2386
2442
  readonly rateLimitEnabled: import("effect/Schema").Boolean;
2387
- readonly rateLimitTimeWindow: import("effect/Schema").NullOr<import("effect/Schema").Number>;
2388
- readonly rateLimitMax: import("effect/Schema").NullOr<import("effect/Schema").Number>;
2389
- readonly requestCount: import("effect/Schema").Number;
2390
- readonly remaining: import("effect/Schema").NullOr<import("effect/Schema").Number>;
2443
+ readonly rateLimitTimeWindow: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
2444
+ readonly rateLimitMax: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
2445
+ readonly requestCount: import("effect/Schema").Finite;
2446
+ readonly remaining: import("effect/Schema").NullOr<import("effect/Schema").Finite>;
2391
2447
  readonly lastRequest: import("effect/Schema").NullOr<import("effect/Schema").DateFromString>;
2392
2448
  readonly expiresAt: import("effect/Schema").NullOr<import("effect/Schema").DateFromString>;
2393
2449
  readonly createdAt: import("effect/Schema").DateFromString;
@@ -2396,9 +2452,9 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2396
2452
  readonly permissions: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>>;
2397
2453
  readonly referrers: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").$Array<import("effect/Schema").String>>>;
2398
2454
  }>>;
2399
- readonly total: import("effect/Schema").Number;
2400
- readonly limit: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Number>>;
2401
- readonly offset: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Number>>;
2455
+ readonly total: import("effect/Schema").Finite;
2456
+ readonly limit: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Finite>>;
2457
+ readonly offset: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Finite>>;
2402
2458
  }>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
2403
2459
  readonly changePassword: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"changePassword", "POST", "/api/auth/change-password", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2404
2460
  readonly newPassword: import("effect/Schema").String;
@@ -2696,7 +2752,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2696
2752
  readonly organizationGetFull: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationGetFull", "GET", "/api/auth/organization/get-full-organization", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
2697
2753
  readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
2698
2754
  readonly organizationSlug: import("effect/Schema").optional<import("effect/Schema").String>;
2699
- readonly membersLimit: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
2755
+ readonly membersLimit: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
2700
2756
  }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").NullOr<import("effect/Schema").Struct<{
2701
2757
  readonly id: import("effect/Schema").String;
2702
2758
  readonly name: import("effect/Schema").String;
@@ -2784,7 +2840,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2784
2840
  readonly organizationId: import("effect/Schema").NonEmptyString;
2785
2841
  readonly actorUserId: import("effect/Schema").NonEmptyString;
2786
2842
  readonly targetUserId: import("effect/Schema").NonEmptyString;
2787
- readonly expiresInSeconds: import("effect/Schema").optional<import("effect/Schema").Number>;
2843
+ readonly expiresInSeconds: import("effect/Schema").optional<import("effect/Schema").Finite>;
2788
2844
  }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2789
2845
  readonly session: import("effect/Schema").Struct<{
2790
2846
  readonly id: import("effect/Schema").String;
@@ -2900,8 +2956,8 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2900
2956
  readonly createdAt: import("effect/Schema").optional<import("effect/Schema").DateFromString>;
2901
2957
  }>>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
2902
2958
  readonly organizationListMembers: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationListMembers", "GET", "/api/auth/organization/list-members", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
2903
- readonly limit: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
2904
- readonly offset: import("effect/Schema").optional<import("effect/Schema").NumberFromString>;
2959
+ readonly limit: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
2960
+ readonly offset: import("effect/Schema").optional<import("effect/Schema").FiniteFromString>;
2905
2961
  readonly sortBy: import("effect/Schema").optional<import("effect/Schema").String>;
2906
2962
  readonly sortDirection: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["asc", "desc"]>>;
2907
2963
  readonly filterField: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -2955,7 +3011,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2955
3011
  }>, import("effect/Schema").Unknown, never, never>>>;
2956
3012
  }>;
2957
3013
  }>>;
2958
- readonly total: import("effect/Schema").Number;
3014
+ readonly total: import("effect/Schema").Finite;
2959
3015
  }>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest | typeof import("./auth/schema.js").AuthUnauthorized | typeof import("./auth/schema.js").AuthForbidden | typeof import("./auth/schema.js").AuthNotFound | typeof import("./auth/schema.js").AuthConflict | typeof import("./auth/schema.js").AuthExpectationFailed | typeof import("./auth/schema.js").AuthTooManyRequests | typeof import("./auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
2960
3016
  readonly organizationListUserInvitations: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationListUserInvitations", "GET", "/api/auth/organization/list-user-invitations", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{}>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").$Array<import("effect/Schema").Struct<{
2961
3017
  readonly id: import("effect/Schema").String;
@@ -3196,7 +3252,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
3196
3252
  readonly nonce: import("effect/Schema").optional<import("effect/Schema").String>;
3197
3253
  readonly accessToken: import("effect/Schema").optional<import("effect/Schema").String>;
3198
3254
  readonly refreshToken: import("effect/Schema").optional<import("effect/Schema").String>;
3199
- readonly expiresAt: import("effect/Schema").optional<import("effect/Schema").Number>;
3255
+ readonly expiresAt: import("effect/Schema").optional<import("effect/Schema").Finite>;
3200
3256
  readonly user: import("effect/Schema").optional<import("effect/Schema").Struct<{
3201
3257
  readonly name: import("effect/Schema").optional<import("effect/Schema").Struct<{
3202
3258
  readonly firstName: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -4142,6 +4198,56 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
4142
4198
  }>>, never, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
4143
4199
  readonly id: import("effect/Schema").NullOr<import("effect/Schema").String>;
4144
4200
  }>>, import("effect/Schema").toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.InternalServerError>, never, never>, never, never>;
4201
+ readonly listUsersByEmails: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"listUsersByEmails", "GET", "/api/users/by-email", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
4202
+ readonly emails: import("effect/Schema").NonEmptyString;
4203
+ }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
4204
+ readonly data: import("effect/Schema").$Array<import("effect/Schema").Struct<{
4205
+ readonly id: import("effect/Schema").String;
4206
+ readonly name: import("effect/Schema").String;
4207
+ readonly email: import("effect/Schema").String;
4208
+ readonly emailVerified: import("effect/Schema").Boolean;
4209
+ readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
4210
+ readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
4211
+ readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
4212
+ readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
4213
+ readonly email: import("effect/Schema").NonEmptyString;
4214
+ readonly translations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
4215
+ readonly locale: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>;
4216
+ readonly label: import("effect/Schema").NonEmptyString;
4217
+ }>>;
4218
+ }>>>;
4219
+ readonly phones: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
4220
+ readonly number: import("effect/Schema").NonEmptyString;
4221
+ readonly extension: import("effect/Schema").optional<import("effect/Schema").String>;
4222
+ readonly translations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
4223
+ readonly locale: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>;
4224
+ readonly label: import("effect/Schema").NonEmptyString;
4225
+ }>>;
4226
+ }>>>;
4227
+ readonly websites: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
4228
+ readonly url: import("effect/Schema").NonEmptyString;
4229
+ readonly translations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
4230
+ readonly locale: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>;
4231
+ readonly label: import("effect/Schema").NonEmptyString;
4232
+ }>>;
4233
+ }>>>;
4234
+ readonly socials: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
4235
+ readonly platform: import("effect/Schema").Literals<readonly ["facebook", "github", "instagram", "linkedin", "tiktok", "x", "youtube"]>;
4236
+ readonly url: import("effect/Schema").NonEmptyString;
4237
+ readonly translations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
4238
+ readonly locale: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>;
4239
+ readonly label: import("effect/Schema").NonEmptyString;
4240
+ }>>;
4241
+ }>>>;
4242
+ }>, import("effect/Schema").Unknown, never, never>>>;
4243
+ readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
4244
+ readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
4245
+ readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
4246
+ readonly createdAt: import("effect/Schema").Date;
4247
+ readonly updatedAt: import("effect/Schema").Date;
4248
+ }>>;
4249
+ readonly missingEmails: import("effect/Schema").$Array<import("effect/Schema").String>;
4250
+ }>>, import("effect/Schema").toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.InternalServerError>, never, never>, never, never>;
4145
4251
  readonly listUsersByIds: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"listUsersByIds", "GET", "/api/users", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
4146
4252
  readonly ids: import("effect/Schema").NonEmptyString;
4147
4253
  }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
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.32",
3
+ "version": "0.3.1",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -75,6 +75,7 @@
75
75
  "prepack": "bun run build"
76
76
  },
77
77
  "dependencies": {
78
+ "@better-auth/core": "1.7.6",
78
79
  "@effect/atom-react": "^4.1.0",
79
80
  "@lucas-barake/effect-form-react": "1.1.0",
80
81
  "react-qr-code": "^2.2.0"