@krak-stack/auth 0.3.3 → 0.4.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.
@@ -1,6 +1,6 @@
1
1
  import { Schema } from "effect";
2
2
  import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api";
3
- import { DeleteUserPayload, DeleteOrganizationPayload, DeleteUserResponse, AdminBanUserPayload, AdminStopImpersonatingPayload, AdminUserIdPayload, AdminUserResponse, AuthBadRequest, AuthConflict, AuthExpectationFailed, AuthForbidden, AuthInternalServerError, AuthInvitation, AuthNotFound, AuthOrganization, AuthSessionResponse, AuthStatusResponse, AuthSuccessResponse, AuthTooManyRequests, AuthUnauthorized, ChangePasswordPayload, ChangePasswordResponse, CreateOrganizationPayload, DeleteApiKeyPayload, FullAuthOrganization, GetFullOrganizationQuery, GetInvitationQuery, GetInvitationResponse, GetSessionQuery, GetSessionResponse, InvitationActionResponse, InvitationIdPayload, InviteMemberPayload, LeaveOrganizationPayload, LinkedAccount, LinkSocialPayload, ListApiKeysQuery, ListApiKeysResponse, MemberResponse, OAuthConsentPayload, OAuthPublicClient, OAuthPublicClientQuery, OAuthRedirectResponse, OrganizationImpersonateUserPayload, OrganizationImpersonateUserResponse, OrganizationInvitationsQuery, OrganizationListMembersQuery, OrganizationListMembersResponse, RemoveMemberPayload, RequestPasswordResetPayload, RequestPasswordResetResponse, ResetPasswordPayload, SendVerificationOtpPayload, SetActiveOrganizationPayload, SignInEmailOtpPayload, SignInEmailPayload, SignInEmailResponse, SignInResponse, SignInSocialPayload, SignOutPayload, SocialRedirectResponse, TwoFactorBackupVerifyPayload, TwoFactorDisablePayload, TwoFactorEnablePayload, TwoFactorEnableResponse, TwoFactorSendPayload, TwoFactorVerifyPayload, UnlinkAccountPayload, UpdateMemberRolePayload, UpdateOrganizationPayload, UpdateUserPayload, UserInvitationsQuery, VerifyEmailOtpPayload, VerifyEmailOtpResponse, } from "./schema.js";
3
+ import { DeleteUserPayload, DeleteOrganizationPayload, DeleteUserResponse, AdminBanUserPayload, AdminStopImpersonatingPayload, AdminUserIdPayload, AdminUserResponse, AuthBadRequest, AuthConflict, AuthExpectationFailed, AuthForbidden, AuthInternalServerError, AuthInvitation, AuthNotFound, AuthOrganization, AuthSessionResponse, AuthStatusResponse, AuthSuccessResponse, AuthTooManyRequests, AuthUnauthorized, ChangePasswordPayload, ChangePasswordResponse, CreateOrganizationPayload, DeleteApiKeyPayload, FullAuthOrganization, GetFullOrganizationQuery, GetInvitationQuery, GetInvitationResponse, GetSessionQuery, GetSessionResponse, InvitationActionResponse, InvitationIdPayload, InviteMemberPayload, LeaveOrganizationPayload, LinkedAccount, LinkSocialPayload, ListApiKeysQuery, ListApiKeysResponse, MemberResponse, OAuthConsentPayload, OAuthPublicClient, OAuthPublicClientQuery, OAuthRedirectResponse, OrganizationImpersonateUserPayload, OrganizationImpersonateUserResponse, OrganizationInvitationsQuery, OrganizationListMembersQuery, OrganizationListMembersResponse, RemoveMemberPayload, RequestPasswordResetPayload, RequestPasswordResetResponse, ResetPasswordPayload, SendVerificationOtpPayload, SetActiveOrganizationPayload, SignInEmailOtpPayload, SignInEmailPayload, SignInEmailResponse, SignInResponse, SignInSocialPayload, SignInSsoPayload, SsoPublicConfig, SsoDiscoveryQuery, OrganizationSsoQuery, OrganizationSsoSettings, OrganizationSsoEnabled, OrganizationSsoConnection, SignOutPayload, SocialRedirectResponse, TwoFactorBackupVerifyPayload, TwoFactorDisablePayload, TwoFactorEnablePayload, TwoFactorEnableResponse, TwoFactorSendPayload, TwoFactorVerifyPayload, UnlinkAccountPayload, UpdateMemberRolePayload, UpdateOrganizationPayload, UpdateUserPayload, UserInvitationsQuery, VerifyEmailOtpPayload, VerifyEmailOtpResponse, } from "./schema.js";
4
4
  export * from "./schema.js";
5
5
  const errors = [
6
6
  AuthBadRequest,
@@ -14,6 +14,41 @@ const errors = [
14
14
  ];
15
15
  const docs = (title, description) => OpenApi.annotations({ title, summary: title, description });
16
16
  export const AuthApiGroup = HttpApiGroup.make("auth")
17
+ .add(HttpApiEndpoint.get("getSsoConfig", "/sso/config", {
18
+ query: SsoDiscoveryQuery.fields,
19
+ success: SsoPublicConfig,
20
+ error: errors,
21
+ }).annotateMerge(docs("Get SSO configuration", "Returns the available organization SSO provider, or null.")))
22
+ .add(HttpApiEndpoint.get("getOrganizationSso", "/organization/sso", {
23
+ query: OrganizationSsoQuery.fields,
24
+ success: Schema.NullOr(OrganizationSsoConnection),
25
+ error: errors,
26
+ }))
27
+ .add(HttpApiEndpoint.post("saveOrganizationSso", "/organization/sso", {
28
+ payload: OrganizationSsoSettings,
29
+ success: OrganizationSsoConnection,
30
+ error: errors,
31
+ }))
32
+ .add(HttpApiEndpoint.post("verifyOrganizationSso", "/organization/sso/verify", {
33
+ payload: OrganizationSsoQuery,
34
+ success: OrganizationSsoConnection,
35
+ error: errors,
36
+ }))
37
+ .add(HttpApiEndpoint.post("setOrganizationSsoEnabled", "/organization/sso/enabled", {
38
+ payload: OrganizationSsoEnabled,
39
+ success: OrganizationSsoConnection,
40
+ error: errors,
41
+ }))
42
+ .add(HttpApiEndpoint.post("deleteOrganizationSso", "/organization/sso/delete", {
43
+ payload: OrganizationSsoQuery,
44
+ success: AuthSuccessResponse,
45
+ error: errors,
46
+ }))
47
+ .add(HttpApiEndpoint.post("signInSso", "/sign-in/sso", {
48
+ payload: SignInSsoPayload,
49
+ success: SocialRedirectResponse,
50
+ error: errors,
51
+ }).annotateMerge(docs("Sign in with SSO", "Starts organization SSO for an existing member.")))
17
52
  .add(HttpApiEndpoint.post("deleteUser", "/delete-user", {
18
53
  payload: DeleteUserPayload,
19
54
  success: DeleteUserResponse,
@@ -204,6 +204,44 @@ export declare const AuthStatusResponse: Schema.Struct<{
204
204
  readonly status: Schema.Boolean;
205
205
  }>;
206
206
  export declare const SignOutPayload: Schema.Struct<{}>;
207
+ export declare const SignInSsoPayload: Schema.Struct<{
208
+ readonly providerId: Schema.NonEmptyString;
209
+ readonly callbackURL: Schema.NonEmptyString;
210
+ readonly errorCallbackURL: Schema.optional<Schema.NonEmptyString>;
211
+ }>;
212
+ export declare const SsoPublicConfig: Schema.NullOr<Schema.Struct<{
213
+ readonly providerId: Schema.NonEmptyString;
214
+ }>>;
215
+ export declare const SsoDiscoveryQuery: Schema.Struct<{
216
+ readonly email: Schema.optional<Schema.NonEmptyString>;
217
+ readonly organizationSlug: Schema.optional<Schema.NonEmptyString>;
218
+ }>;
219
+ export declare const OrganizationSsoQuery: Schema.Struct<{
220
+ readonly organizationId: Schema.NonEmptyString;
221
+ }>;
222
+ export declare const OrganizationSsoSettings: Schema.Struct<{
223
+ readonly organizationId: Schema.NonEmptyString;
224
+ readonly issuer: Schema.NonEmptyString;
225
+ readonly domain: Schema.NonEmptyString;
226
+ readonly clientId: Schema.NonEmptyString;
227
+ readonly clientSecret: Schema.optional<Schema.NonEmptyString>;
228
+ }>;
229
+ export declare const OrganizationSsoEnabled: Schema.Struct<{
230
+ readonly organizationId: Schema.NonEmptyString;
231
+ readonly enabled: Schema.Boolean;
232
+ }>;
233
+ export declare const OrganizationSsoConnection: Schema.Struct<{
234
+ readonly callbackURL: Schema.optional<Schema.NonEmptyString>;
235
+ readonly organizationId: Schema.NonEmptyString;
236
+ readonly providerId: Schema.NonEmptyString;
237
+ readonly issuer: Schema.NonEmptyString;
238
+ readonly domain: Schema.NonEmptyString;
239
+ readonly clientId: Schema.NonEmptyString;
240
+ readonly enabled: Schema.Boolean;
241
+ readonly domainVerified: Schema.Boolean;
242
+ readonly verificationName: Schema.NonEmptyString;
243
+ readonly verificationToken: Schema.optional<Schema.NonEmptyString>;
244
+ }>;
207
245
  export declare const AuthSuccessResponse: Schema.Struct<{
208
246
  readonly success: Schema.Boolean;
209
247
  }>;
@@ -85,6 +85,44 @@ export const AuthStatusResponse = Schema.Struct({
85
85
  export const SignOutPayload = Schema.Struct({}).annotate({
86
86
  identifier: "SignOutPayload",
87
87
  });
88
+ export const SignInSsoPayload = Schema.Struct({
89
+ providerId: Schema.NonEmptyString,
90
+ callbackURL: Schema.NonEmptyString,
91
+ errorCallbackURL: Schema.optional(Schema.NonEmptyString),
92
+ }).annotate({ identifier: "SignInSsoPayload" });
93
+ export const SsoPublicConfig = Schema.NullOr(Schema.Struct({
94
+ providerId: Schema.NonEmptyString,
95
+ })).annotate({ identifier: "SsoPublicConfig" });
96
+ export const SsoDiscoveryQuery = Schema.Struct({
97
+ email: Schema.optional(Schema.NonEmptyString),
98
+ organizationSlug: Schema.optional(Schema.NonEmptyString),
99
+ }).annotate({ identifier: "SsoDiscoveryQuery" });
100
+ export const OrganizationSsoQuery = Schema.Struct({
101
+ organizationId: Schema.NonEmptyString,
102
+ }).annotate({ identifier: "OrganizationSsoQuery" });
103
+ export const OrganizationSsoSettings = Schema.Struct({
104
+ organizationId: Schema.NonEmptyString,
105
+ issuer: Schema.NonEmptyString,
106
+ domain: Schema.NonEmptyString,
107
+ clientId: Schema.NonEmptyString,
108
+ clientSecret: Schema.optional(Schema.NonEmptyString),
109
+ }).annotate({ identifier: "OrganizationSsoSettings" });
110
+ export const OrganizationSsoEnabled = Schema.Struct({
111
+ organizationId: Schema.NonEmptyString,
112
+ enabled: Schema.Boolean,
113
+ }).annotate({ identifier: "OrganizationSsoEnabled" });
114
+ export const OrganizationSsoConnection = Schema.Struct({
115
+ callbackURL: Schema.optional(Schema.NonEmptyString),
116
+ organizationId: Schema.NonEmptyString,
117
+ providerId: Schema.NonEmptyString,
118
+ issuer: Schema.NonEmptyString,
119
+ domain: Schema.NonEmptyString,
120
+ clientId: Schema.NonEmptyString,
121
+ enabled: Schema.Boolean,
122
+ domainVerified: Schema.Boolean,
123
+ verificationName: Schema.NonEmptyString,
124
+ verificationToken: Schema.optional(Schema.NonEmptyString),
125
+ }).annotate({ identifier: "OrganizationSsoConnection" });
88
126
  export const AuthSuccessResponse = Schema.Struct({
89
127
  success: Schema.Boolean,
90
128
  }).annotate({ identifier: "AuthSuccessResponse", title: "Success response" });
@@ -848,6 +848,11 @@ export declare const authHttpClient: (baseUrl?: string, getLocale?: () => "en" |
848
848
  readonly updatedAt: import("effect/Schema").DateFromString;
849
849
  }>;
850
850
  }>>, 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>;
851
+ readonly deleteOrganizationSso: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"deleteOrganizationSso", "POST", "/api/auth/organization/sso/delete", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
852
+ readonly organizationId: import("effect/Schema").NonEmptyString;
853
+ }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
854
+ readonly success: import("effect/Schema").Boolean;
855
+ }>>, 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>;
851
856
  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<{
852
857
  readonly password: import("effect/Schema").optional<import("effect/Schema").String>;
853
858
  readonly token: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -856,6 +861,20 @@ export declare const authHttpClient: (baseUrl?: string, getLocale?: () => "en" |
856
861
  readonly success: import("effect/Schema").Boolean;
857
862
  readonly message: import("effect/Schema").String;
858
863
  }>>, 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>;
864
+ readonly getOrganizationSso: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"getOrganizationSso", "GET", "/api/auth/organization/sso", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
865
+ readonly organizationId: import("effect/Schema").NonEmptyString;
866
+ }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").NullOr<import("effect/Schema").Struct<{
867
+ readonly callbackURL: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
868
+ readonly organizationId: import("effect/Schema").NonEmptyString;
869
+ readonly providerId: import("effect/Schema").NonEmptyString;
870
+ readonly issuer: import("effect/Schema").NonEmptyString;
871
+ readonly domain: import("effect/Schema").NonEmptyString;
872
+ readonly clientId: import("effect/Schema").NonEmptyString;
873
+ readonly enabled: import("effect/Schema").Boolean;
874
+ readonly domainVerified: import("effect/Schema").Boolean;
875
+ readonly verificationName: import("effect/Schema").NonEmptyString;
876
+ readonly verificationToken: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
877
+ }>>>, 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>;
859
878
  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<{
860
879
  readonly disableCookieCache: import("effect/Schema").optional<import("effect/Schema").String>;
861
880
  readonly disableRefresh: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -922,6 +941,12 @@ export declare const authHttpClient: (baseUrl?: string, getLocale?: () => "en" |
922
941
  readonly updatedAt: import("effect/Schema").DateFromString;
923
942
  }>;
924
943
  }>>>, 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>;
944
+ readonly getSsoConfig: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"getSsoConfig", "GET", "/api/auth/sso/config", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
945
+ readonly email: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
946
+ readonly organizationSlug: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
947
+ }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").NullOr<import("effect/Schema").Struct<{
948
+ readonly providerId: import("effect/Schema").NonEmptyString;
949
+ }>>>, 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>;
925
950
  readonly linkSocial: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"linkSocial", "POST", "/api/auth/link-social", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
926
951
  readonly callbackURL: import("effect/Schema").optional<import("effect/Schema").String>;
927
952
  readonly provider: import("effect/Schema").String;
@@ -1453,12 +1478,45 @@ export declare const authHttpClient: (baseUrl?: string, getLocale?: () => "en" |
1453
1478
  }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
1454
1479
  readonly status: import("effect/Schema").Boolean;
1455
1480
  }>>, 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>;
1481
+ readonly saveOrganizationSso: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"saveOrganizationSso", "POST", "/api/auth/organization/sso", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
1482
+ readonly organizationId: import("effect/Schema").NonEmptyString;
1483
+ readonly issuer: import("effect/Schema").NonEmptyString;
1484
+ readonly domain: import("effect/Schema").NonEmptyString;
1485
+ readonly clientId: import("effect/Schema").NonEmptyString;
1486
+ readonly clientSecret: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
1487
+ }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
1488
+ readonly callbackURL: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
1489
+ readonly organizationId: import("effect/Schema").NonEmptyString;
1490
+ readonly providerId: import("effect/Schema").NonEmptyString;
1491
+ readonly issuer: import("effect/Schema").NonEmptyString;
1492
+ readonly domain: import("effect/Schema").NonEmptyString;
1493
+ readonly clientId: import("effect/Schema").NonEmptyString;
1494
+ readonly enabled: import("effect/Schema").Boolean;
1495
+ readonly domainVerified: import("effect/Schema").Boolean;
1496
+ readonly verificationName: import("effect/Schema").NonEmptyString;
1497
+ readonly verificationToken: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
1498
+ }>>, 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>;
1456
1499
  readonly sendVerificationOtp: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"sendVerificationOtp", "POST", "/api/auth/email-otp/send-verification-otp", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
1457
1500
  readonly email: import("effect/Schema").String;
1458
1501
  readonly type: import("effect/Schema").Literals<readonly ["sign-in", "email-verification", "forget-password"]>;
1459
1502
  }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
1460
1503
  readonly success: import("effect/Schema").Boolean;
1461
1504
  }>>, 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>;
1505
+ readonly setOrganizationSsoEnabled: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"setOrganizationSsoEnabled", "POST", "/api/auth/organization/sso/enabled", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
1506
+ readonly organizationId: import("effect/Schema").NonEmptyString;
1507
+ readonly enabled: import("effect/Schema").Boolean;
1508
+ }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
1509
+ readonly callbackURL: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
1510
+ readonly organizationId: import("effect/Schema").NonEmptyString;
1511
+ readonly providerId: import("effect/Schema").NonEmptyString;
1512
+ readonly issuer: import("effect/Schema").NonEmptyString;
1513
+ readonly domain: import("effect/Schema").NonEmptyString;
1514
+ readonly clientId: import("effect/Schema").NonEmptyString;
1515
+ readonly enabled: import("effect/Schema").Boolean;
1516
+ readonly domainVerified: import("effect/Schema").Boolean;
1517
+ readonly verificationName: import("effect/Schema").NonEmptyString;
1518
+ readonly verificationToken: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
1519
+ }>>, 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>;
1462
1520
  readonly signInEmail: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"signInEmail", "POST", "/api/auth/sign-in/email", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
1463
1521
  readonly email: import("effect/Schema").String;
1464
1522
  readonly password: import("effect/Schema").String;
@@ -1657,6 +1715,64 @@ export declare const authHttpClient: (baseUrl?: string, getLocale?: () => "en" |
1657
1715
  }>>;
1658
1716
  readonly status: import("effect/Schema").optional<import("effect/Schema").Boolean>;
1659
1717
  }>>, 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>;
1718
+ readonly signInSso: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"signInSso", "POST", "/api/auth/sign-in/sso", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
1719
+ readonly providerId: import("effect/Schema").NonEmptyString;
1720
+ readonly callbackURL: import("effect/Schema").NonEmptyString;
1721
+ readonly errorCallbackURL: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
1722
+ }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
1723
+ readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
1724
+ readonly redirect: import("effect/Schema").Boolean;
1725
+ readonly token: import("effect/Schema").optional<import("effect/Schema").String>;
1726
+ readonly user: import("effect/Schema").optional<import("effect/Schema").Struct<{
1727
+ readonly id: import("effect/Schema").String;
1728
+ readonly name: import("effect/Schema").String;
1729
+ readonly email: import("effect/Schema").String;
1730
+ readonly emailVerified: import("effect/Schema").Boolean;
1731
+ readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
1732
+ readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
1733
+ readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
1734
+ readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
1735
+ readonly email: import("effect/Schema").NonEmptyString;
1736
+ readonly translations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
1737
+ readonly locale: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>;
1738
+ readonly label: import("effect/Schema").NonEmptyString;
1739
+ }>>;
1740
+ }>>>;
1741
+ readonly phones: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
1742
+ readonly number: import("effect/Schema").NonEmptyString;
1743
+ readonly extension: import("effect/Schema").optional<import("effect/Schema").String>;
1744
+ readonly translations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
1745
+ readonly locale: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>;
1746
+ readonly label: import("effect/Schema").NonEmptyString;
1747
+ }>>;
1748
+ }>>>;
1749
+ readonly websites: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
1750
+ readonly url: import("effect/Schema").NonEmptyString;
1751
+ readonly translations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
1752
+ readonly locale: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>;
1753
+ readonly label: import("effect/Schema").NonEmptyString;
1754
+ }>>;
1755
+ }>>>;
1756
+ readonly socials: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
1757
+ readonly platform: import("effect/Schema").Literals<readonly ["facebook", "github", "instagram", "linkedin", "tiktok", "x", "youtube"]>;
1758
+ readonly url: import("effect/Schema").NonEmptyString;
1759
+ readonly translations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
1760
+ readonly locale: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>;
1761
+ readonly label: import("effect/Schema").NonEmptyString;
1762
+ }>>;
1763
+ }>>>;
1764
+ }>, import("effect/Schema").Unknown, never, never>>>;
1765
+ readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
1766
+ readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
1767
+ readonly banReason: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
1768
+ readonly banExpires: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").DateFromString>>;
1769
+ readonly twoFactorEnabled: import("effect/Schema").optional<import("effect/Schema").Boolean>;
1770
+ readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
1771
+ readonly createdAt: import("effect/Schema").DateFromString;
1772
+ readonly updatedAt: import("effect/Schema").DateFromString;
1773
+ }>>;
1774
+ readonly status: import("effect/Schema").optional<import("effect/Schema").Boolean>;
1775
+ }>>, 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>;
1660
1776
  readonly signOut: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"signOut", "POST", "/api/auth/sign-out", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
1661
1777
  readonly success: import("effect/Schema").Boolean;
1662
1778
  }>>, 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>;
@@ -1943,6 +2059,20 @@ export declare const authHttpClient: (baseUrl?: string, getLocale?: () => "en" |
1943
2059
  readonly updatedAt: import("effect/Schema").DateFromString;
1944
2060
  }>;
1945
2061
  }>>, 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>;
2062
+ readonly verifyOrganizationSso: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"verifyOrganizationSso", "POST", "/api/auth/organization/sso/verify", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2063
+ readonly organizationId: import("effect/Schema").NonEmptyString;
2064
+ }>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2065
+ readonly callbackURL: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
2066
+ readonly organizationId: import("effect/Schema").NonEmptyString;
2067
+ readonly providerId: import("effect/Schema").NonEmptyString;
2068
+ readonly issuer: import("effect/Schema").NonEmptyString;
2069
+ readonly domain: import("effect/Schema").NonEmptyString;
2070
+ readonly clientId: import("effect/Schema").NonEmptyString;
2071
+ readonly enabled: import("effect/Schema").Boolean;
2072
+ readonly domainVerified: import("effect/Schema").Boolean;
2073
+ readonly verificationName: import("effect/Schema").NonEmptyString;
2074
+ readonly verificationToken: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
2075
+ }>>, 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>;
1946
2076
  };
1947
2077
  readonly authExtra: {
1948
2078
  readonly createApiKey: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"createApiKey", "POST", "/api/auth/create-api-key", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
@@ -13,7 +13,11 @@ export declare const resolveInitialAuthMethod: ({ requestedMethod, lastLoginMeth
13
13
  emailPassword: boolean;
14
14
  emailOtp: boolean;
15
15
  }) => AuthMethod;
16
- export declare function Signin(props: AuthFormProps): import("react").JSX.Element;
16
+ export declare function Signin(props: AuthFormProps & {
17
+ sso?: {
18
+ label: string;
19
+ };
20
+ }): import("react").JSX.Element;
17
21
  export declare function VerifyEmail(props: AuthFormProps): import("react").JSX.Element;
18
22
  export declare function ForgotPassword(props: AuthFormProps): import("react").JSX.Element;
19
23
  export declare function ResetPassword(props: AuthFormProps): import("react").JSX.Element;
@@ -23,9 +23,10 @@ import { useKrakstackAuth } from "./auth-provider.js";
23
23
  import { cn } from "./utils.js";
24
24
  import { getOAuthAuthorizationQuery } from "../oauth/authorization.js";
25
25
  import { ExtraProjectPublicConfig as ExtraProjectPublicConfigSchema, } from "../extra/schema.js";
26
+ import { EmailAddress } from "../schema.js";
26
27
  import { AuthBadRequest, AuthInternalServerError, AuthTooManyRequests, AuthUnauthorized, AuthRedirectURLFromString, } from "../auth/schema.js";
27
28
  const signinFormBuilder = FormBuilder.empty
28
- .addField("email", Schema.String)
29
+ .addField("email", EmailAddress)
29
30
  .addField("password", Schema.String)
30
31
  .addField("otp", Schema.String);
31
32
  const verifyEmailFormBuilder = FormBuilder.empty
@@ -297,7 +298,9 @@ export function Signin(props) {
297
298
  emailPassword: options.emailPassword,
298
299
  emailOtp: options.emailOtp,
299
300
  }));
300
- const initialMethodStep = Boolean(initialEmail) && requestedMethod === initialAuthMethod;
301
+ const initialMethodStep = Option.isSome(Schema.decodeOption(EmailAddress)(initialEmail)) &&
302
+ (options.emailPassword || options.emailOtp) &&
303
+ requestedMethod === initialAuthMethod;
301
304
  const [emailSubmitted, setEmailSubmitted] = useState(initialMethodStep);
302
305
  const [authMethod, setAuthMethod] = useState(initialAuthMethod);
303
306
  const [otpSentTo, setOtpSentTo] = useState(initialMethodStep && initialAuthMethod === "emailOtp" ? initialEmail : "");
@@ -386,6 +389,11 @@ export function Signin(props) {
386
389
  return;
387
390
  }
388
391
  if (!action.emailSubmitted) {
392
+ if ((!options.emailPassword && !options.emailOtp) ||
393
+ (props.sso && action.method === "emailOtp")) {
394
+ setEmailSubmitted(true);
395
+ return;
396
+ }
389
397
  if (action.method === "emailOtp")
390
398
  yield* sendEmailOtp;
391
399
  else {
@@ -459,6 +467,34 @@ export function Signin(props) {
459
467
  })));
460
468
  const startSocialSignIn = useAtomSet(socialSignIn);
461
469
  const socialSignInResult = useAtomValue(socialSignIn);
470
+ const [ssoSignIn] = useState(() => authClientApi(baseUrl).runtime.fn((payload) => authHttpClient(baseUrl, locale).pipe(Effect.flatMap((client) => Effect.gen(function* () {
471
+ const query = {};
472
+ if (payload.email)
473
+ query.email = payload.email;
474
+ if (payload.organizationSlug)
475
+ query.organizationSlug = payload.organizationSlug;
476
+ const connection = yield* client.auth.getSsoConfig({
477
+ query,
478
+ });
479
+ if (!connection)
480
+ return yield* new AuthBadRequest({
481
+ message: "SSO unavailable",
482
+ });
483
+ return yield* client.auth.signInSso({
484
+ payload: {
485
+ providerId: connection.providerId,
486
+ callbackURL: payload.callbackURL,
487
+ errorCallbackURL: payload.errorCallbackURL,
488
+ },
489
+ });
490
+ })), Effect.flatMap((result) => {
491
+ const url = result.url;
492
+ return url
493
+ ? Effect.promise(() => Promise.resolve(onNavigate(url)))
494
+ : Effect.void;
495
+ }))));
496
+ const startSsoSignIn = useAtomSet(ssoSignIn);
497
+ const ssoSignInResult = useAtomValue(ssoSignIn);
462
498
  const formValues = Option.getOrElse(useAtomValue(form.values), () => ({
463
499
  email: "",
464
500
  password: "",
@@ -504,9 +540,18 @@ export function Signin(props) {
504
540
  submit({ type: "resendEmailOtp" });
505
541
  };
506
542
  const signInWithGoogle = () => startSocialSignIn(getSocialSignInDestinations(router, props.defaultRedirectTo, window.location.href));
543
+ const signInWithSso = () => {
544
+ const { callbackURL, errorCallbackURL } = getSocialSignInDestinations(router, props.defaultRedirectTo, window.location.href);
545
+ startSsoSignIn({
546
+ email: formValues.email.trim(),
547
+ organizationSlug: getSearchParam(searchString, "organization") ?? undefined,
548
+ callbackURL,
549
+ errorCallbackURL,
550
+ });
551
+ };
507
552
  return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [emailSubmitted ? (_jsxs(Button, { type: "button", variant: "link", className: "w-fit justify-self-start p-0", disabled: submitResult.waiting, onClick: resetEmailStep, children: [_jsx(ArrowLeft, {}), m.sign_in_change_email] })) : null, _jsx(CardTitle, { className: "text-3xl", children: m.auth_sign_in }), _jsx(CardDescription, { children: !emailSubmitted
508
553
  ? m.sign_in_description
509
- : text(m.sign_in_email_as, { email: formValues.email }) })] }), _jsxs(CardContent, { children: [hasPrimaryAuth ? (_jsx(form.Initialize, { defaultValues: { email: initialEmail, password: "", otp: "" }, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
554
+ : text(m.sign_in_email_as, { email: formValues.email }) })] }), _jsxs(CardContent, { children: [getSearchParam(searchString, "error") ? (_jsx(ErrorMessage, { text: m.sign_in_error })) : null, hasPrimaryAuth || props.sso ? (_jsx(form.Initialize, { defaultValues: { email: initialEmail, password: "", otp: "" }, children: hasPrimaryAuth || !emailSubmitted ? (_jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
510
555
  event.preventDefault();
511
556
  event.stopPropagation();
512
557
  setErrorContext(!emailSubmitted ||
@@ -533,7 +578,9 @@ export function Signin(props) {
533
578
  setErrorContext("resetPassword");
534
579
  submit({ type: "resetPassword" });
535
580
  },
536
- }, required: true }) })) : null, emailSubmitted && selectedAuthMethod === "emailOtp" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.otp, { label: m.sign_in_email_otp_code }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.sign_in_otp_expiry }), _jsx("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: otpSentTo ? (_jsx(Button, { type: "button", variant: "link", className: "h-auto px-0", disabled: submitResult.waiting || emailOtpResendSeconds > 0, onClick: resendEmailOtp, children: emailOtpResendSeconds > 0
581
+ }, required: true }) })) : null, emailSubmitted &&
582
+ selectedAuthMethod === "emailOtp" &&
583
+ otpSentTo ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.otp, { label: m.sign_in_email_otp_code }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.sign_in_otp_expiry }), _jsx("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: otpSentTo ? (_jsx(Button, { type: "button", variant: "link", className: "h-auto px-0", disabled: submitResult.waiting || emailOtpResendSeconds > 0, onClick: resendEmailOtp, children: emailOtpResendSeconds > 0
537
584
  ? text(m.sign_in_email_otp_resend_countdown, {
538
585
  seconds: String(emailOtpResendSeconds),
539
586
  })
@@ -560,11 +607,17 @@ export function Signin(props) {
560
607
  } }), _jsx("div", { children: _jsxs(Button, { type: "submit", disabled: submitResult.waiting, children: [submitResult.waiting ? (_jsx(Loader2, { className: "animate-spin", "data-icon": "inline-start" })) : null, !emailSubmitted
561
608
  ? m.sign_in_continue
562
609
  : selectedAuthMethod === "emailOtp"
563
- ? m.sign_in_email_otp_verify
564
- : m.auth_sign_in] }) })] }) })) : null, (emailSubmitted && canChangeAuthMethod) ||
610
+ ? otpSentTo
611
+ ? m.sign_in_email_otp_verify
612
+ : m.sign_in_use_email_otp
613
+ : m.auth_sign_in] }) })] })) : null })) : null, (emailSubmitted && (canChangeAuthMethod || props.sso)) ||
565
614
  (options.google && !emailSubmitted) ? (_jsxs("div", { className: "mt-4 flex flex-col gap-3", children: [hasPrimaryAuth ? (_jsx(Divider, { label: m.auth_or_continue_with })) : null, emailSubmitted && canChangeAuthMethod ? (_jsxs(Button, { type: "button", variant: "outline", className: "w-full", disabled: submitResult.waiting, onClick: switchAuthMethod, children: [selectedAuthMethod === "password" ? _jsx(Mail, {}) : _jsx(KeyRound, {}), selectedAuthMethod === "password"
566
615
  ? m.sign_in_use_email_otp
567
- : m.sign_in_use_password] })) : null, options.google && !emailSubmitted ? (_jsxs(_Fragment, { children: [_jsxs(Button, { type: "button", variant: "outline", className: "w-full", disabled: submitResult.waiting, onClick: signInWithGoogle, children: [_jsx(GoogleLogo, {}), m.auth_continue_with_google] }), _jsx(AuthSubmitError, { result: socialSignInResult, labels: m, messages: { fallback: m.sign_in_error } })] })) : null] })) : null, !hasPrimaryAuth && !options.google ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.oauth_client_no_auth_methods })) : null] })] }));
616
+ : m.sign_in_use_password] })) : null, options.google && !emailSubmitted ? (_jsxs(_Fragment, { children: [_jsxs(Button, { type: "button", variant: "outline", className: "w-full", disabled: submitResult.waiting ||
617
+ socialSignInResult.waiting ||
618
+ ssoSignInResult.waiting, onClick: signInWithGoogle, children: [_jsx(GoogleLogo, {}), m.auth_continue_with_google] }), _jsx(AuthSubmitError, { result: socialSignInResult, labels: m, messages: { fallback: m.sign_in_error } })] })) : null, props.sso && emailSubmitted ? (_jsxs(_Fragment, { children: [_jsxs(Button, { type: "button", variant: "outline", className: "w-full", disabled: submitResult.waiting ||
619
+ socialSignInResult.waiting ||
620
+ ssoSignInResult.waiting, onClick: signInWithSso, children: [ssoSignInResult.waiting ? (_jsx(Loader2, { className: "animate-spin" })) : (_jsx(KeyRound, {})), props.sso.label] }), _jsx(AuthSubmitError, { result: ssoSignInResult, labels: m, messages: { fallback: m.sign_in_error } })] })) : null] })) : null, !hasPrimaryAuth && !options.google && !props.sso ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.oauth_client_no_auth_methods })) : null] })] }));
568
621
  }
569
622
  export function VerifyEmail(props) {
570
623
  const registry = useContext(RegistryContext);
@@ -0,0 +1,71 @@
1
+ import { AsyncResult, Atom } from "effect/reactivity";
2
+ export declare const organizationSsoAtoms: (arg: string | undefined) => (arg: string) => {
3
+ settings: Atom.Writable<AsyncResult.AsyncResult<{
4
+ readonly callbackURL?: string | undefined;
5
+ readonly organizationId: string;
6
+ readonly providerId: string;
7
+ readonly issuer: string;
8
+ readonly domain: string;
9
+ readonly clientId: string;
10
+ readonly enabled: boolean;
11
+ readonly domainVerified: boolean;
12
+ readonly verificationName: string;
13
+ readonly verificationToken?: string | undefined;
14
+ } | null, import("../auth/schema.js").AuthBadRequest | import("../auth/schema.js").AuthConflict | import("../auth/schema.js").AuthExpectationFailed | import("../auth/schema.js").AuthForbidden | import("../auth/schema.js").AuthInternalServerError | import("../auth/schema.js").AuthNotFound | import("../auth/schema.js").AuthTooManyRequests | import("../auth/schema.js").AuthUnauthorized>, Atom.Atom<AsyncResult.AsyncResult<AsyncResult.AsyncResult<{
15
+ readonly callbackURL?: string | undefined;
16
+ readonly organizationId: string;
17
+ readonly providerId: string;
18
+ readonly issuer: string;
19
+ readonly domain: string;
20
+ readonly clientId: string;
21
+ readonly enabled: boolean;
22
+ readonly domainVerified: boolean;
23
+ readonly verificationName: string;
24
+ readonly verificationToken?: string | undefined;
25
+ } | null, import("../auth/schema.js").AuthBadRequest | import("../auth/schema.js").AuthConflict | import("../auth/schema.js").AuthExpectationFailed | import("../auth/schema.js").AuthForbidden | import("../auth/schema.js").AuthInternalServerError | import("../auth/schema.js").AuthNotFound | import("../auth/schema.js").AuthTooManyRequests | import("../auth/schema.js").AuthUnauthorized>, unknown>>>;
26
+ save: Atom.AtomResultFn<Omit<{
27
+ readonly organizationId: string;
28
+ readonly issuer: string;
29
+ readonly domain: string;
30
+ readonly clientId: string;
31
+ readonly clientSecret?: string | undefined;
32
+ }, "organizationId">, {
33
+ readonly callbackURL?: string | undefined;
34
+ readonly organizationId: string;
35
+ readonly providerId: string;
36
+ readonly issuer: string;
37
+ readonly domain: string;
38
+ readonly clientId: string;
39
+ readonly enabled: boolean;
40
+ readonly domainVerified: boolean;
41
+ readonly verificationName: string;
42
+ readonly verificationToken?: string | undefined;
43
+ }, import("../auth/schema.js").AuthBadRequest | import("../auth/schema.js").AuthConflict | import("../auth/schema.js").AuthExpectationFailed | import("../auth/schema.js").AuthForbidden | import("../auth/schema.js").AuthInternalServerError | import("../auth/schema.js").AuthNotFound | import("../auth/schema.js").AuthTooManyRequests | import("../auth/schema.js").AuthUnauthorized>;
44
+ verify: Atom.AtomResultFn<void, {
45
+ readonly callbackURL?: string | undefined;
46
+ readonly organizationId: string;
47
+ readonly providerId: string;
48
+ readonly issuer: string;
49
+ readonly domain: string;
50
+ readonly clientId: string;
51
+ readonly enabled: boolean;
52
+ readonly domainVerified: boolean;
53
+ readonly verificationName: string;
54
+ readonly verificationToken?: string | undefined;
55
+ }, import("../auth/schema.js").AuthBadRequest | import("../auth/schema.js").AuthConflict | import("../auth/schema.js").AuthExpectationFailed | import("../auth/schema.js").AuthForbidden | import("../auth/schema.js").AuthInternalServerError | import("../auth/schema.js").AuthNotFound | import("../auth/schema.js").AuthTooManyRequests | import("../auth/schema.js").AuthUnauthorized>;
56
+ remove: Atom.AtomResultFn<void, {
57
+ readonly success: boolean;
58
+ }, import("../auth/schema.js").AuthBadRequest | import("../auth/schema.js").AuthConflict | import("../auth/schema.js").AuthExpectationFailed | import("../auth/schema.js").AuthForbidden | import("../auth/schema.js").AuthInternalServerError | import("../auth/schema.js").AuthNotFound | import("../auth/schema.js").AuthTooManyRequests | import("../auth/schema.js").AuthUnauthorized>;
59
+ enable: Atom.AtomResultFn<boolean, {
60
+ readonly callbackURL?: string | undefined;
61
+ readonly organizationId: string;
62
+ readonly providerId: string;
63
+ readonly issuer: string;
64
+ readonly domain: string;
65
+ readonly clientId: string;
66
+ readonly enabled: boolean;
67
+ readonly domainVerified: boolean;
68
+ readonly verificationName: string;
69
+ readonly verificationToken?: string | undefined;
70
+ }, import("../auth/schema.js").AuthBadRequest | import("../auth/schema.js").AuthConflict | import("../auth/schema.js").AuthExpectationFailed | import("../auth/schema.js").AuthForbidden | import("../auth/schema.js").AuthInternalServerError | import("../auth/schema.js").AuthNotFound | import("../auth/schema.js").AuthTooManyRequests | import("../auth/schema.js").AuthUnauthorized>;
71
+ };
@@ -0,0 +1,40 @@
1
+ import { AsyncResult, Atom } from "effect/reactivity";
2
+ import { authClientApi } from "./auth-client-api.js";
3
+ export const organizationSsoAtoms = Atom.family((baseUrl) => {
4
+ const client = authClientApi(baseUrl);
5
+ return Atom.family((organizationId) => {
6
+ const reactivityKeys = [
7
+ `organization-sso:${baseUrl ?? ""}:${organizationId}`,
8
+ ];
9
+ const settings = Atom.optimistic(client.query("auth", "getOrganizationSso", {
10
+ query: { organizationId },
11
+ reactivityKeys,
12
+ timeToLive: "1 minute",
13
+ }));
14
+ const saveMutation = client.mutation("auth", "saveOrganizationSso");
15
+ const verifyMutation = client.mutation("auth", "verifyOrganizationSso");
16
+ const enableMutation = client.mutation("auth", "setOrganizationSsoEnabled");
17
+ const deleteMutation = client.mutation("auth", "deleteOrganizationSso");
18
+ // Discovery, DNS proof and account unlinking cannot be predicted safely.
19
+ const save = Atom.fn((payload, get) => get.setResult(saveMutation, {
20
+ payload: { ...payload, organizationId },
21
+ reactivityKeys,
22
+ }));
23
+ const verify = Atom.fn((_, get) => get.setResult(verifyMutation, {
24
+ payload: { organizationId },
25
+ reactivityKeys,
26
+ }));
27
+ const remove = Atom.fn((_, get) => get.setResult(deleteMutation, {
28
+ payload: { organizationId },
29
+ reactivityKeys,
30
+ }));
31
+ const enable = Atom.optimisticFn(settings, {
32
+ reducer: (state, enabled) => AsyncResult.map(state, (connection) => connection ? { ...connection, enabled } : null),
33
+ fn: Atom.fn((enabled, get) => get.setResult(enableMutation, {
34
+ payload: { organizationId, enabled },
35
+ reactivityKeys,
36
+ })),
37
+ });
38
+ return { settings, save, verify, remove, enable };
39
+ });
40
+ });