@effect-auth/core 0.1.0-alpha.1 → 0.1.0-alpha.13
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.
- package/README.md +790 -73
- package/dist/ApiKey.d.ts +207 -0
- package/dist/ApiKey.d.ts.map +1 -0
- package/dist/ApiKey.js +275 -0
- package/dist/ApiKey.js.map +1 -0
- package/dist/AuditLog.d.ts +335 -1
- package/dist/AuditLog.d.ts.map +1 -1
- package/dist/AuditLog.js +318 -1
- package/dist/AuditLog.js.map +1 -1
- package/dist/AuthConfig.d.ts +42 -0
- package/dist/AuthConfig.d.ts.map +1 -0
- package/dist/AuthConfig.js +43 -0
- package/dist/AuthConfig.js.map +1 -0
- package/dist/AuthFlow.d.ts +462 -36
- package/dist/AuthFlow.d.ts.map +1 -1
- package/dist/AuthFlow.js +657 -5
- package/dist/AuthFlow.js.map +1 -1
- package/dist/AuthKernel.d.ts +3 -0
- package/dist/AuthKernel.d.ts.map +1 -0
- package/dist/AuthKernel.js +9 -0
- package/dist/AuthKernel.js.map +1 -0
- package/dist/Challenge.d.ts +24 -4
- package/dist/Challenge.d.ts.map +1 -1
- package/dist/Challenge.js +167 -1
- package/dist/Challenge.js.map +1 -1
- package/dist/Client.d.ts +449 -0
- package/dist/Client.d.ts.map +1 -0
- package/dist/Client.js +985 -0
- package/dist/Client.js.map +1 -0
- package/dist/Crypto.d.ts +6 -1
- package/dist/Crypto.d.ts.map +1 -1
- package/dist/Crypto.js +62 -1
- package/dist/Crypto.js.map +1 -1
- package/dist/DomainVerification.d.ts +200 -0
- package/dist/DomainVerification.d.ts.map +1 -0
- package/dist/DomainVerification.js +304 -0
- package/dist/DomainVerification.js.map +1 -0
- package/dist/EffectQbSqliteStorage.d.ts +985 -0
- package/dist/EffectQbSqliteStorage.d.ts.map +1 -0
- package/dist/EffectQbSqliteStorage.js +2824 -0
- package/dist/EffectQbSqliteStorage.js.map +1 -0
- package/dist/EmailOtp.d.ts +120 -0
- package/dist/EmailOtp.d.ts.map +1 -0
- package/dist/EmailOtp.js +286 -0
- package/dist/EmailOtp.js.map +1 -0
- package/dist/EmailVerification.d.ts +121 -0
- package/dist/EmailVerification.d.ts.map +1 -0
- package/dist/EmailVerification.js +200 -0
- package/dist/EmailVerification.js.map +1 -0
- package/dist/HttpApi/Api.d.ts +2410 -0
- package/dist/HttpApi/Api.d.ts.map +1 -0
- package/dist/HttpApi/Api.js +3026 -0
- package/dist/HttpApi/Api.js.map +1 -0
- package/dist/HttpApi/Endpoints.d.ts +1073 -0
- package/dist/HttpApi/Endpoints.d.ts.map +1 -0
- package/dist/HttpApi/Endpoints.js +428 -0
- package/dist/HttpApi/Endpoints.js.map +1 -0
- package/dist/HttpApi/Errors.d.ts +114 -0
- package/dist/HttpApi/Errors.d.ts.map +1 -0
- package/dist/HttpApi/Errors.js +230 -0
- package/dist/HttpApi/Errors.js.map +1 -0
- package/dist/HttpApi/Schemas.d.ts +1254 -0
- package/dist/HttpApi/Schemas.d.ts.map +1 -0
- package/dist/HttpApi/Schemas.js +862 -0
- package/dist/HttpApi/Schemas.js.map +1 -0
- package/dist/HttpApi/Security.d.ts +159 -0
- package/dist/HttpApi/Security.d.ts.map +1 -0
- package/dist/HttpApi/Security.js +530 -0
- package/dist/HttpApi/Security.js.map +1 -0
- package/dist/HttpApi/Transport.d.ts +65 -0
- package/dist/HttpApi/Transport.d.ts.map +1 -0
- package/dist/HttpApi/Transport.js +311 -0
- package/dist/HttpApi/Transport.js.map +1 -0
- package/dist/HttpApi/index.d.ts +8 -0
- package/dist/HttpApi/index.d.ts.map +1 -0
- package/dist/HttpApi/index.js +7 -0
- package/dist/HttpApi/index.js.map +1 -0
- package/dist/HttpApi.d.ts +2 -0
- package/dist/HttpApi.d.ts.map +1 -0
- package/dist/HttpApi.js +2 -0
- package/dist/HttpApi.js.map +1 -0
- package/dist/Identifiers.d.ts +3 -0
- package/dist/Identifiers.d.ts.map +1 -1
- package/dist/Identifiers.js +2 -0
- package/dist/Identifiers.js.map +1 -1
- package/dist/IncidentAction.d.ts +80 -0
- package/dist/IncidentAction.d.ts.map +1 -0
- package/dist/IncidentAction.js +158 -0
- package/dist/IncidentAction.js.map +1 -0
- package/dist/Internal.d.ts +7 -0
- package/dist/Internal.d.ts.map +1 -0
- package/dist/Internal.js +12 -0
- package/dist/Internal.js.map +1 -0
- package/dist/Jwt.d.ts +281 -0
- package/dist/Jwt.d.ts.map +1 -0
- package/dist/Jwt.js +721 -0
- package/dist/Jwt.js.map +1 -0
- package/dist/LoginApproval.d.ts +314 -0
- package/dist/LoginApproval.d.ts.map +1 -0
- package/dist/LoginApproval.js +551 -0
- package/dist/LoginApproval.js.map +1 -0
- package/dist/LoginNotification.d.ts +183 -0
- package/dist/LoginNotification.d.ts.map +1 -0
- package/dist/LoginNotification.js +329 -0
- package/dist/LoginNotification.js.map +1 -0
- package/dist/LoginRisk.d.ts +344 -0
- package/dist/LoginRisk.d.ts.map +1 -0
- package/dist/LoginRisk.js +484 -0
- package/dist/LoginRisk.js.map +1 -0
- package/dist/MachineAuth.d.ts +73 -0
- package/dist/MachineAuth.d.ts.map +1 -0
- package/dist/MachineAuth.js +147 -0
- package/dist/MachineAuth.js.map +1 -0
- package/dist/MagicLink.d.ts +85 -0
- package/dist/MagicLink.d.ts.map +1 -0
- package/dist/MagicLink.js +206 -0
- package/dist/MagicLink.js.map +1 -0
- package/dist/Mailer.d.ts +147 -0
- package/dist/Mailer.d.ts.map +1 -0
- package/dist/Mailer.js +208 -0
- package/dist/Mailer.js.map +1 -0
- package/dist/OAuth.d.ts +1890 -0
- package/dist/OAuth.d.ts.map +1 -0
- package/dist/OAuth.js +3063 -0
- package/dist/OAuth.js.map +1 -0
- package/dist/Passkey.d.ts +334 -0
- package/dist/Passkey.d.ts.map +1 -0
- package/dist/Passkey.js +422 -0
- package/dist/Passkey.js.map +1 -0
- package/dist/PasskeySimpleWebAuthn.d.ts +11 -0
- package/dist/PasskeySimpleWebAuthn.d.ts.map +1 -0
- package/dist/PasskeySimpleWebAuthn.js +181 -0
- package/dist/PasskeySimpleWebAuthn.js.map +1 -0
- package/dist/Password.d.ts +237 -0
- package/dist/Password.d.ts.map +1 -0
- package/dist/Password.js +641 -0
- package/dist/Password.js.map +1 -0
- package/dist/Policy.d.ts +7 -4
- package/dist/Policy.d.ts.map +1 -1
- package/dist/Policy.js +28 -5
- package/dist/Policy.js.map +1 -1
- package/dist/Privacy.d.ts +15 -0
- package/dist/Privacy.d.ts.map +1 -1
- package/dist/Privacy.js +58 -1
- package/dist/Privacy.js.map +1 -1
- package/dist/RateLimiter.d.ts +104 -0
- package/dist/RateLimiter.d.ts.map +1 -0
- package/dist/RateLimiter.js +118 -0
- package/dist/RateLimiter.js.map +1 -0
- package/dist/RecoveryCode.d.ts +169 -0
- package/dist/RecoveryCode.d.ts.map +1 -0
- package/dist/RecoveryCode.js +299 -0
- package/dist/RecoveryCode.js.map +1 -0
- package/dist/RefreshToken.d.ts +222 -0
- package/dist/RefreshToken.d.ts.map +1 -0
- package/dist/RefreshToken.js +342 -0
- package/dist/RefreshToken.js.map +1 -0
- package/dist/Retention.d.ts +98 -0
- package/dist/Retention.d.ts.map +1 -0
- package/dist/Retention.js +204 -0
- package/dist/Retention.js.map +1 -0
- package/dist/SecurityTimeline.d.ts +78 -0
- package/dist/SecurityTimeline.d.ts.map +1 -0
- package/dist/SecurityTimeline.js +461 -0
- package/dist/SecurityTimeline.js.map +1 -0
- package/dist/Sessions.d.ts +123 -11
- package/dist/Sessions.d.ts.map +1 -1
- package/dist/Sessions.js +534 -1
- package/dist/Sessions.js.map +1 -1
- package/dist/StepUp.d.ts +44 -0
- package/dist/StepUp.d.ts.map +1 -0
- package/dist/StepUp.js +82 -0
- package/dist/StepUp.js.map +1 -0
- package/dist/Storage.d.ts +73 -5
- package/dist/Storage.d.ts.map +1 -1
- package/dist/Storage.js +11 -1
- package/dist/Storage.js.map +1 -1
- package/dist/StorageMigrations.d.ts +23 -1
- package/dist/StorageMigrations.d.ts.map +1 -1
- package/dist/StorageMigrations.js +462 -2
- package/dist/StorageMigrations.js.map +1 -1
- package/dist/Testing.d.ts +9 -1
- package/dist/Testing.d.ts.map +1 -1
- package/dist/Testing.js +30 -2
- package/dist/Testing.js.map +1 -1
- package/dist/Totp.d.ts +220 -0
- package/dist/Totp.d.ts.map +1 -0
- package/dist/Totp.js +477 -0
- package/dist/Totp.js.map +1 -0
- package/dist/TrustedDevice.d.ts +127 -0
- package/dist/TrustedDevice.d.ts.map +1 -0
- package/dist/TrustedDevice.js +252 -0
- package/dist/TrustedDevice.js.map +1 -0
- package/dist/WaitUntil.d.ts.map +1 -1
- package/dist/WaitUntil.js +1 -1
- package/dist/WaitUntil.js.map +1 -1
- package/dist/Webhook.d.ts +380 -0
- package/dist/Webhook.d.ts.map +1 -0
- package/dist/Webhook.js +592 -0
- package/dist/Webhook.js.map +1 -0
- package/dist/alchemy/cloudflare/Email.d.ts +25 -0
- package/dist/alchemy/cloudflare/Email.d.ts.map +1 -0
- package/dist/alchemy/cloudflare/Email.js +117 -0
- package/dist/alchemy/cloudflare/Email.js.map +1 -0
- package/dist/alchemy/cloudflare/RateLimitDurableObject.d.ts +34 -0
- package/dist/alchemy/cloudflare/RateLimitDurableObject.d.ts.map +1 -0
- package/dist/alchemy/cloudflare/RateLimitDurableObject.js +30 -0
- package/dist/alchemy/cloudflare/RateLimitDurableObject.js.map +1 -0
- package/dist/cloudflare/Email.d.ts +25 -0
- package/dist/cloudflare/Email.d.ts.map +1 -0
- package/dist/cloudflare/Email.js +153 -0
- package/dist/cloudflare/Email.js.map +1 -0
- package/dist/cloudflare/RateLimitDurableObject.d.ts +50 -0
- package/dist/cloudflare/RateLimitDurableObject.d.ts.map +1 -0
- package/dist/cloudflare/RateLimitDurableObject.js +51 -0
- package/dist/cloudflare/RateLimitDurableObject.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/RateLimitDurableObject.d.ts +32 -0
- package/dist/internal/RateLimitDurableObject.d.ts.map +1 -0
- package/dist/internal/RateLimitDurableObject.js +80 -0
- package/dist/internal/RateLimitDurableObject.js.map +1 -0
- package/migrations/0002_auth_password.sql +25 -0
- package/migrations/0003_auth_login_approval_review.sql +22 -0
- package/migrations/0004_auth_trusted_device.sql +12 -0
- package/migrations/0005_auth_passkey.sql +17 -0
- package/migrations/0006_auth_totp_factor.sql +17 -0
- package/migrations/0007_auth_recovery_code.sql +13 -0
- package/migrations/0008_auth_api_key.sql +17 -0
- package/migrations/0009_auth_refresh_token.sql +21 -0
- package/migrations/0010_auth_jwt_revocation.sql +8 -0
- package/migrations/0011_auth_oauth_account.sql +16 -0
- package/migrations/0012_auth_oauth_provider_token_vault.sql +20 -0
- package/migrations/0013_auth_security_timeline.sql +16 -0
- package/migrations/0014_auth_webhook_outbox.sql +16 -0
- package/migrations/0015_auth_webhook_replay.sql +7 -0
- package/migrations/0016_auth_login_risk_history.sql +23 -0
- package/migrations/0017_auth_audit_log.sql +17 -0
- package/migrations/0018_auth_domain_verification.sql +18 -0
- package/migrations/0019_auth_oauth_authorization_code.sql +17 -0
- package/migrations/0020_auth_oauth_provider_mode_token.sql +24 -0
- package/migrations/0021_auth_oauth_client_secret.sql +14 -0
- package/migrations/0022_auth_oauth_client.sql +15 -0
- package/migrations/0023_auth_oauth_consent.sql +15 -0
- package/package.json +162 -26
- package/dist/D1Kysely.d.ts +0 -40
- package/dist/D1Kysely.d.ts.map +0 -1
- package/dist/D1Kysely.js +0 -75
- package/dist/D1Kysely.js.map +0 -1
- package/dist/KyselyStorage.d.ts +0 -41
- package/dist/KyselyStorage.d.ts.map +0 -1
- package/dist/KyselyStorage.js +0 -176
- package/dist/KyselyStorage.js.map +0 -1
package/dist/Client.js
ADDED
|
@@ -0,0 +1,985 @@
|
|
|
1
|
+
import { Effect, Layer, ManagedRuntime, Schema } from "effect";
|
|
2
|
+
import { FetchHttpClient, HttpClient } from "effect/unstable/http";
|
|
3
|
+
import { HttpApiClient } from "effect/unstable/httpapi";
|
|
4
|
+
import { AdminSecurityTimelineListQuery, AdminSessionListQuery, AdminSessionRevokeAllBody, AdminSessionRevokeBody, AdminSessionsHttpBody, AdminTrustedDeviceListQuery, AdminTrustedDeviceRevokeBody, AuthApi, AuthUnauthenticatedError, ActiveSessionsHttpBody, ApiKeyCreateBody, ApiKeyCreatedBody, ApiKeysBody, ApiKeyRevokeBody, AuthenticatedHttpBody, CurrentSessionHttpBody, EmailOtpStartedBody, EmailOtpStartBody, EmailOtpVerifyBody, EmailVerificationStartBody, EmailVerificationVerifyBody, LoginApprovalApproveBody, LoginApprovalFinalizeBody, LoginNotificationReportBody, LoginApprovalReviewStatusBody, LoginApprovalReviewStatusHttpBody, JwtIntrospectBody, JwtIntrospectionBody, JwtJwksBody, JwtRevokeBody, MagicLinkStartedBody, MagicLinkStartBody, MagicLinkVerifyBody, MfaOptionsBody, MfaOptionsResultBody, OAuthAccountUnlinkBody, OAuthAccountUnlinkResolutionBody, OAuthAuthorizationStartedBody, OAuthAuthorizationStartBody, OAuthLinkConfirmationConfirmBody, OAuthLinkConfirmationConfirmedBody, OAuthLinkConfirmationInspectBody, OAuthLinkConfirmationPendingBody, OAuthLinkConfirmationStartBody, OAuthLinkConfirmationStartedBody, OidcDiscoveryMetadataBody, PasskeyAuthenticationFinishBody, PasskeyAuthenticationStartBody, PasskeyAuthenticationStartedBody, PasskeyCredentialRevokeBody, PasskeyCredentialsBody, PasskeyMfaStartBody, PasskeyMfaVerifyBody, PasskeyRegisteredBody, PasskeyRegistrationFinishBody, PasskeyRegistrationStartBody, PasskeyRegistrationStartedBody, PasswordChangeBody, PasswordAuthSuccess, PasswordResetStartBody, PasswordResetVerifyBody, PasswordSetBody, SessionRevokeBody, PasswordSignInBody, PasswordSignUpBody, RecoveryCodeGenerateBody, RecoveryCodeMfaVerifyBody, RecoveryCodeMfaVerifyForFlowBody, RefreshTokenRefreshBody, RefreshTokenRefreshedBody, RecoveryCodeRevokeBody, RecoveryCodesBody, RecoveryCodesGeneratedBody, RecoveryCodeVerifyBody, RecoveryCodeVerifyResultBody, SecurityTimelineEventsBody, SecurityTimelineListQuery, StepUpOptionsResultBody, StepUpPasskeyStartBody, StepUpPasskeyVerifyBody, StepUpRecoveryCodeVerifyBody, StepUpTotpVerifyBody, TrustedDeviceRevokeBody, TrustedDevicesBody, TotpEnrollmentConfirmBody, TotpEnrollmentStartedBody, TotpEnrollmentStartBody, TotpFactorHttpBody, TotpFactorRevokeBody, TotpFactorsBody, TotpMfaVerifyBody, TotpMfaVerifyForFlowBody, TotpVerifyBody, TotpVerifyResultBody, } from "./HttpApi.js";
|
|
5
|
+
const defaultRequestInit = { credentials: "include" };
|
|
6
|
+
const defaultPasskeyPrefix = "/auth/passkey";
|
|
7
|
+
const defaultPasskeyClientPaths = {
|
|
8
|
+
registrationStart: "/register/start",
|
|
9
|
+
registrationFinish: "/register/finish",
|
|
10
|
+
authenticationStart: "/authenticate/start",
|
|
11
|
+
authenticationFinish: "/authenticate/finish",
|
|
12
|
+
credentialList: "/credentials",
|
|
13
|
+
credentialRevoke: "/credentials/revoke",
|
|
14
|
+
};
|
|
15
|
+
const defaultTotpPrefix = "/auth/totp";
|
|
16
|
+
const defaultTotpClientPaths = {
|
|
17
|
+
enrollmentStart: "/enroll/start",
|
|
18
|
+
enrollmentConfirm: "/enroll/confirm",
|
|
19
|
+
verify: "/verify",
|
|
20
|
+
factorList: "/factors",
|
|
21
|
+
factorRevoke: "/factors/revoke",
|
|
22
|
+
};
|
|
23
|
+
const defaultRecoveryCodePrefix = "/auth/recovery-codes";
|
|
24
|
+
const defaultRecoveryCodeClientPaths = {
|
|
25
|
+
generate: "/generate",
|
|
26
|
+
verify: "/verify",
|
|
27
|
+
list: "/codes",
|
|
28
|
+
revoke: "/codes/revoke",
|
|
29
|
+
};
|
|
30
|
+
const defaultApiKeyPrefix = "/auth/api-keys";
|
|
31
|
+
const defaultApiKeyClientPaths = {
|
|
32
|
+
create: "/",
|
|
33
|
+
list: "/",
|
|
34
|
+
revoke: "/revoke",
|
|
35
|
+
};
|
|
36
|
+
const defaultRefreshTokenPrefix = "/auth/token";
|
|
37
|
+
const defaultRefreshTokenClientPaths = {
|
|
38
|
+
refresh: "/refresh",
|
|
39
|
+
};
|
|
40
|
+
const defaultJwtPrefix = "/auth/jwt";
|
|
41
|
+
const defaultJwtClientPaths = {
|
|
42
|
+
introspect: "/introspect",
|
|
43
|
+
revoke: "/revoke",
|
|
44
|
+
};
|
|
45
|
+
const defaultJwtDiscoveryPrefix = "/.well-known";
|
|
46
|
+
const defaultJwtDiscoveryClientPaths = {
|
|
47
|
+
jwks: "/jwks.json",
|
|
48
|
+
openidConfiguration: "/openid-configuration",
|
|
49
|
+
};
|
|
50
|
+
const defaultMfaPrefix = "/auth/mfa";
|
|
51
|
+
const defaultMfaClientPaths = {
|
|
52
|
+
options: "/options",
|
|
53
|
+
totpVerify: "/totp/verify",
|
|
54
|
+
totpVerifyForFlow: "/totp/verify-flow",
|
|
55
|
+
recoveryCodeVerify: "/recovery-code/verify",
|
|
56
|
+
recoveryCodeVerifyForFlow: "/recovery-code/verify-flow",
|
|
57
|
+
passkeyStart: "/passkey/start",
|
|
58
|
+
passkeyVerify: "/passkey/verify",
|
|
59
|
+
};
|
|
60
|
+
const defaultStepUpPrefix = "/auth/step-up";
|
|
61
|
+
const defaultStepUpClientPaths = {
|
|
62
|
+
options: "/options",
|
|
63
|
+
totpVerify: "/totp/verify",
|
|
64
|
+
recoveryCodeVerify: "/recovery-code/verify",
|
|
65
|
+
passkeyStart: "/passkey/start",
|
|
66
|
+
passkeyVerify: "/passkey/verify",
|
|
67
|
+
};
|
|
68
|
+
const defaultSecurityTimelinePrefix = "/auth/security";
|
|
69
|
+
const defaultSecurityTimelineClientPaths = {
|
|
70
|
+
list: "/timeline",
|
|
71
|
+
};
|
|
72
|
+
const defaultAdminSecurityTimelinePrefix = "/auth/admin/security";
|
|
73
|
+
const defaultAdminSecurityTimelineClientPaths = {
|
|
74
|
+
list: "/timeline",
|
|
75
|
+
};
|
|
76
|
+
const defaultAdminSessionPrefix = "/auth/admin/sessions";
|
|
77
|
+
const defaultAdminSessionClientPaths = {
|
|
78
|
+
list: "/",
|
|
79
|
+
revoke: "/revoke",
|
|
80
|
+
revokeAll: "/revoke-all",
|
|
81
|
+
};
|
|
82
|
+
const defaultTrustedDevicePrefix = "/auth/trusted-devices";
|
|
83
|
+
const defaultTrustedDeviceClientPaths = {
|
|
84
|
+
list: "/",
|
|
85
|
+
revoke: "/revoke",
|
|
86
|
+
};
|
|
87
|
+
const defaultAdminTrustedDevicePrefix = "/auth/admin/trusted-devices";
|
|
88
|
+
const defaultAdminTrustedDeviceClientPaths = {
|
|
89
|
+
list: "/",
|
|
90
|
+
revoke: "/revoke",
|
|
91
|
+
};
|
|
92
|
+
const defaultOAuthPrefix = "/auth/oauth";
|
|
93
|
+
const defaultOAuthClientPaths = {
|
|
94
|
+
authorizationStart: "/start",
|
|
95
|
+
accountUnlink: "/unlink",
|
|
96
|
+
linkConfirmationStart: "/link-confirmation/start",
|
|
97
|
+
linkConfirmationInspect: "/link-confirmation/inspect",
|
|
98
|
+
linkConfirmationConfirm: "/link-confirmation/confirm",
|
|
99
|
+
};
|
|
100
|
+
const joinPath = (prefix, path) => {
|
|
101
|
+
const normalizedPrefix = prefix.replace(/\/+$/, "");
|
|
102
|
+
const normalizedPath = path.replace(/^\/+/, "");
|
|
103
|
+
if (normalizedPath.length === 0) {
|
|
104
|
+
return normalizedPrefix.length === 0 ? "/" : normalizedPrefix;
|
|
105
|
+
}
|
|
106
|
+
if (normalizedPath.startsWith("?") || normalizedPath.startsWith("#")) {
|
|
107
|
+
return `${normalizedPrefix}${normalizedPath}`;
|
|
108
|
+
}
|
|
109
|
+
return normalizedPrefix.length === 0
|
|
110
|
+
? `/${normalizedPath}`
|
|
111
|
+
: `${normalizedPrefix}/${normalizedPath}`;
|
|
112
|
+
};
|
|
113
|
+
const clientUrl = (baseUrl, path) => (baseUrl === undefined ? path : String(new URL(path, baseUrl)));
|
|
114
|
+
const pathWithSearch = (path, searchParams) => {
|
|
115
|
+
const search = searchParams.toString();
|
|
116
|
+
if (search.length === 0) {
|
|
117
|
+
return path;
|
|
118
|
+
}
|
|
119
|
+
return `${path}${path.includes("?") ? "&" : "?"}${search}`;
|
|
120
|
+
};
|
|
121
|
+
const responseJson = async (response) => {
|
|
122
|
+
const text = await response.text();
|
|
123
|
+
if (text.length === 0) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
return JSON.parse(text);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return { message: text };
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const throwFailedResponse = async (response) => {
|
|
134
|
+
const body = await responseJson(response);
|
|
135
|
+
throw body ?? {
|
|
136
|
+
code: `http_${response.status}`,
|
|
137
|
+
message: response.statusText || "Request failed",
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
const requestHeaders = (requestInit, body) => {
|
|
141
|
+
const headers = new Headers(requestInit.headers);
|
|
142
|
+
if (body !== undefined && !headers.has("content-type")) {
|
|
143
|
+
headers.set("content-type", "application/json");
|
|
144
|
+
}
|
|
145
|
+
return headers;
|
|
146
|
+
};
|
|
147
|
+
const authClientErrorShape = (error) => typeof error === "object" && error !== null
|
|
148
|
+
? error
|
|
149
|
+
: undefined;
|
|
150
|
+
export const authClientErrorMessage = (error) => {
|
|
151
|
+
const shape = authClientErrorShape(error);
|
|
152
|
+
if (typeof shape?.message === "string") {
|
|
153
|
+
return shape.message;
|
|
154
|
+
}
|
|
155
|
+
if (typeof shape?.code === "string") {
|
|
156
|
+
return shape.code;
|
|
157
|
+
}
|
|
158
|
+
return error instanceof Error ? error.message : "Request failed";
|
|
159
|
+
};
|
|
160
|
+
export const createPasskeyClient = (options = {}) => {
|
|
161
|
+
const requestInit = {
|
|
162
|
+
...defaultRequestInit,
|
|
163
|
+
...options.requestInit,
|
|
164
|
+
};
|
|
165
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
166
|
+
const prefix = options.prefix ?? defaultPasskeyPrefix;
|
|
167
|
+
const paths = {
|
|
168
|
+
...defaultPasskeyClientPaths,
|
|
169
|
+
...options.paths,
|
|
170
|
+
};
|
|
171
|
+
const url = (path) => clientUrl(options.baseUrl, joinPath(prefix, path));
|
|
172
|
+
const decodePasskeyRegistrationStart = Schema.decodeUnknownEffect(PasskeyRegistrationStartBody);
|
|
173
|
+
const decodePasskeyRegistrationFinish = Schema.decodeUnknownEffect(PasskeyRegistrationFinishBody);
|
|
174
|
+
const decodePasskeyAuthenticationStart = Schema.decodeUnknownEffect(PasskeyAuthenticationStartBody);
|
|
175
|
+
const decodePasskeyAuthenticationFinish = Schema.decodeUnknownEffect(PasskeyAuthenticationFinishBody);
|
|
176
|
+
const decodePasskeyCredentialRevoke = Schema.decodeUnknownEffect(PasskeyCredentialRevokeBody);
|
|
177
|
+
const decodePasskeyRegistrationStarted = Schema.decodeUnknownEffect(PasskeyRegistrationStartedBody);
|
|
178
|
+
const decodePasskeyRegistered = Schema.decodeUnknownEffect(PasskeyRegisteredBody);
|
|
179
|
+
const decodePasskeyAuthenticationStarted = Schema.decodeUnknownEffect(PasskeyAuthenticationStartedBody);
|
|
180
|
+
const decodeAuthenticated = Schema.decodeUnknownEffect(AuthenticatedHttpBody);
|
|
181
|
+
const decodePasskeyCredentials = Schema.decodeUnknownEffect(PasskeyCredentialsBody);
|
|
182
|
+
const decode = (effect) => Effect.runPromise(effect);
|
|
183
|
+
const request = async (method, path, body, requestOptions, decodeResponse) => {
|
|
184
|
+
const response = await fetch(url(path), {
|
|
185
|
+
...requestInit,
|
|
186
|
+
method,
|
|
187
|
+
headers: requestHeaders(requestInit, body),
|
|
188
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
189
|
+
signal: requestOptions?.signal,
|
|
190
|
+
});
|
|
191
|
+
if (!response.ok) {
|
|
192
|
+
return throwFailedResponse(response);
|
|
193
|
+
}
|
|
194
|
+
return decode(decodeResponse(await responseJson(response)));
|
|
195
|
+
};
|
|
196
|
+
const requestNoContent = async (path, body, requestOptions) => {
|
|
197
|
+
const response = await fetch(url(path), {
|
|
198
|
+
...requestInit,
|
|
199
|
+
method: "POST",
|
|
200
|
+
headers: requestHeaders(requestInit, body),
|
|
201
|
+
body: JSON.stringify(body),
|
|
202
|
+
signal: requestOptions?.signal,
|
|
203
|
+
});
|
|
204
|
+
if (!response.ok) {
|
|
205
|
+
return throwFailedResponse(response);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
return {
|
|
209
|
+
registration: {
|
|
210
|
+
start: async (input, requestOptions) => request("POST", paths.registrationStart, await decode(decodePasskeyRegistrationStart(input)), requestOptions, decodePasskeyRegistrationStarted),
|
|
211
|
+
finish: async (input, requestOptions) => request("POST", paths.registrationFinish, await decode(decodePasskeyRegistrationFinish(input)), requestOptions, decodePasskeyRegistered),
|
|
212
|
+
},
|
|
213
|
+
authentication: {
|
|
214
|
+
start: async (input, requestOptions) => request("POST", paths.authenticationStart, await decode(decodePasskeyAuthenticationStart(input)), requestOptions, decodePasskeyAuthenticationStarted),
|
|
215
|
+
finish: async (input, requestOptions) => request("POST", paths.authenticationFinish, await decode(decodePasskeyAuthenticationFinish(input)), requestOptions, decodeAuthenticated),
|
|
216
|
+
},
|
|
217
|
+
credentials: {
|
|
218
|
+
list: (requestOptions) => request("GET", paths.credentialList, undefined, requestOptions, decodePasskeyCredentials),
|
|
219
|
+
revoke: async (input, requestOptions) => requestNoContent(paths.credentialRevoke, await decode(decodePasskeyCredentialRevoke(input)), requestOptions),
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
export const createTotpClient = (options = {}) => {
|
|
224
|
+
const requestInit = {
|
|
225
|
+
...defaultRequestInit,
|
|
226
|
+
...options.requestInit,
|
|
227
|
+
};
|
|
228
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
229
|
+
const prefix = options.prefix ?? defaultTotpPrefix;
|
|
230
|
+
const paths = {
|
|
231
|
+
...defaultTotpClientPaths,
|
|
232
|
+
...options.paths,
|
|
233
|
+
};
|
|
234
|
+
const url = (path) => clientUrl(options.baseUrl, joinPath(prefix, path));
|
|
235
|
+
const decodeTotpEnrollmentStart = Schema.decodeUnknownEffect(TotpEnrollmentStartBody);
|
|
236
|
+
const decodeTotpEnrollmentConfirm = Schema.decodeUnknownEffect(TotpEnrollmentConfirmBody);
|
|
237
|
+
const decodeTotpVerify = Schema.decodeUnknownEffect(TotpVerifyBody);
|
|
238
|
+
const decodeTotpFactorRevoke = Schema.decodeUnknownEffect(TotpFactorRevokeBody);
|
|
239
|
+
const decodeTotpEnrollmentStarted = Schema.decodeUnknownEffect(TotpEnrollmentStartedBody);
|
|
240
|
+
const decodeTotpFactor = Schema.decodeUnknownEffect(TotpFactorHttpBody);
|
|
241
|
+
const decodeTotpVerifyResult = Schema.decodeUnknownEffect(TotpVerifyResultBody);
|
|
242
|
+
const decodeTotpFactors = Schema.decodeUnknownEffect(TotpFactorsBody);
|
|
243
|
+
const decode = (effect) => Effect.runPromise(effect);
|
|
244
|
+
const request = async (method, path, body, requestOptions, decodeResponse) => {
|
|
245
|
+
const response = await fetch(url(path), {
|
|
246
|
+
...requestInit,
|
|
247
|
+
method,
|
|
248
|
+
headers: requestHeaders(requestInit, body),
|
|
249
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
250
|
+
signal: requestOptions?.signal,
|
|
251
|
+
});
|
|
252
|
+
if (!response.ok) {
|
|
253
|
+
return throwFailedResponse(response);
|
|
254
|
+
}
|
|
255
|
+
return decode(decodeResponse(await responseJson(response)));
|
|
256
|
+
};
|
|
257
|
+
const requestNoContent = async (path, body, requestOptions) => {
|
|
258
|
+
const response = await fetch(url(path), {
|
|
259
|
+
...requestInit,
|
|
260
|
+
method: "POST",
|
|
261
|
+
headers: requestHeaders(requestInit, body),
|
|
262
|
+
body: JSON.stringify(body),
|
|
263
|
+
signal: requestOptions?.signal,
|
|
264
|
+
});
|
|
265
|
+
if (!response.ok) {
|
|
266
|
+
return throwFailedResponse(response);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
return {
|
|
270
|
+
enrollment: {
|
|
271
|
+
start: async (input, requestOptions) => request("POST", paths.enrollmentStart, await decode(decodeTotpEnrollmentStart(input)), requestOptions, decodeTotpEnrollmentStarted),
|
|
272
|
+
confirm: async (input, requestOptions) => request("POST", paths.enrollmentConfirm, await decode(decodeTotpEnrollmentConfirm(input)), requestOptions, decodeTotpFactor),
|
|
273
|
+
},
|
|
274
|
+
verification: {
|
|
275
|
+
verify: async (input, requestOptions) => request("POST", paths.verify, await decode(decodeTotpVerify(input)), requestOptions, decodeTotpVerifyResult),
|
|
276
|
+
},
|
|
277
|
+
factors: {
|
|
278
|
+
list: (requestOptions) => request("GET", paths.factorList, undefined, requestOptions, decodeTotpFactors),
|
|
279
|
+
revoke: async (input, requestOptions) => requestNoContent(paths.factorRevoke, await decode(decodeTotpFactorRevoke(input)), requestOptions),
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
export const createRecoveryCodeClient = (options = {}) => {
|
|
284
|
+
const requestInit = {
|
|
285
|
+
...defaultRequestInit,
|
|
286
|
+
...options.requestInit,
|
|
287
|
+
};
|
|
288
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
289
|
+
const prefix = options.prefix ?? defaultRecoveryCodePrefix;
|
|
290
|
+
const paths = {
|
|
291
|
+
...defaultRecoveryCodeClientPaths,
|
|
292
|
+
...options.paths,
|
|
293
|
+
};
|
|
294
|
+
const url = (path) => clientUrl(options.baseUrl, joinPath(prefix, path));
|
|
295
|
+
const decodeRecoveryCodeGenerate = Schema.decodeUnknownEffect(RecoveryCodeGenerateBody);
|
|
296
|
+
const decodeRecoveryCodeVerify = Schema.decodeUnknownEffect(RecoveryCodeVerifyBody);
|
|
297
|
+
const decodeRecoveryCodeRevoke = Schema.decodeUnknownEffect(RecoveryCodeRevokeBody);
|
|
298
|
+
const decodeRecoveryCodesGenerated = Schema.decodeUnknownEffect(RecoveryCodesGeneratedBody);
|
|
299
|
+
const decodeRecoveryCodeVerifyResult = Schema.decodeUnknownEffect(RecoveryCodeVerifyResultBody);
|
|
300
|
+
const decodeRecoveryCodes = Schema.decodeUnknownEffect(RecoveryCodesBody);
|
|
301
|
+
const decode = (effect) => Effect.runPromise(effect);
|
|
302
|
+
const request = async (method, path, body, requestOptions, decodeResponse) => {
|
|
303
|
+
const response = await fetch(url(path), {
|
|
304
|
+
...requestInit,
|
|
305
|
+
method,
|
|
306
|
+
headers: requestHeaders(requestInit, body),
|
|
307
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
308
|
+
signal: requestOptions?.signal,
|
|
309
|
+
});
|
|
310
|
+
if (!response.ok) {
|
|
311
|
+
return throwFailedResponse(response);
|
|
312
|
+
}
|
|
313
|
+
return decode(decodeResponse(await responseJson(response)));
|
|
314
|
+
};
|
|
315
|
+
const requestNoContent = async (path, body, requestOptions) => {
|
|
316
|
+
const response = await fetch(url(path), {
|
|
317
|
+
...requestInit,
|
|
318
|
+
method: "POST",
|
|
319
|
+
headers: requestHeaders(requestInit, body),
|
|
320
|
+
body: JSON.stringify(body),
|
|
321
|
+
signal: requestOptions?.signal,
|
|
322
|
+
});
|
|
323
|
+
if (!response.ok) {
|
|
324
|
+
return throwFailedResponse(response);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
return {
|
|
328
|
+
generation: {
|
|
329
|
+
generate: async (input, requestOptions) => request("POST", paths.generate, await decode(decodeRecoveryCodeGenerate(input)), requestOptions, decodeRecoveryCodesGenerated),
|
|
330
|
+
},
|
|
331
|
+
verification: {
|
|
332
|
+
verify: async (input, requestOptions) => request("POST", paths.verify, await decode(decodeRecoveryCodeVerify(input)), requestOptions, decodeRecoveryCodeVerifyResult),
|
|
333
|
+
},
|
|
334
|
+
codes: {
|
|
335
|
+
list: (requestOptions) => request("GET", paths.list, undefined, requestOptions, decodeRecoveryCodes),
|
|
336
|
+
revoke: async (input, requestOptions) => requestNoContent(paths.revoke, await decode(decodeRecoveryCodeRevoke(input)), requestOptions),
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
export const createApiKeyClient = (options = {}) => {
|
|
341
|
+
const requestInit = {
|
|
342
|
+
...defaultRequestInit,
|
|
343
|
+
...options.requestInit,
|
|
344
|
+
};
|
|
345
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
346
|
+
const prefix = options.prefix ?? defaultApiKeyPrefix;
|
|
347
|
+
const paths = {
|
|
348
|
+
...defaultApiKeyClientPaths,
|
|
349
|
+
...options.paths,
|
|
350
|
+
};
|
|
351
|
+
const url = (path) => clientUrl(options.baseUrl, joinPath(prefix, path));
|
|
352
|
+
const decodeApiKeyCreate = Schema.decodeUnknownEffect(ApiKeyCreateBody);
|
|
353
|
+
const decodeApiKeyRevoke = Schema.decodeUnknownEffect(ApiKeyRevokeBody);
|
|
354
|
+
const decodeApiKeyCreated = Schema.decodeUnknownEffect(ApiKeyCreatedBody);
|
|
355
|
+
const decodeApiKeys = Schema.decodeUnknownEffect(ApiKeysBody);
|
|
356
|
+
const decode = (effect) => Effect.runPromise(effect);
|
|
357
|
+
const request = async (method, path, body, requestOptions, decodeResponse) => {
|
|
358
|
+
const response = await fetch(url(path), {
|
|
359
|
+
...requestInit,
|
|
360
|
+
method,
|
|
361
|
+
headers: requestHeaders(requestInit, body),
|
|
362
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
363
|
+
signal: requestOptions?.signal,
|
|
364
|
+
});
|
|
365
|
+
if (!response.ok) {
|
|
366
|
+
return throwFailedResponse(response);
|
|
367
|
+
}
|
|
368
|
+
return decode(decodeResponse(await responseJson(response)));
|
|
369
|
+
};
|
|
370
|
+
const requestNoContent = async (path, body, requestOptions) => {
|
|
371
|
+
const response = await fetch(url(path), {
|
|
372
|
+
...requestInit,
|
|
373
|
+
method: "POST",
|
|
374
|
+
headers: requestHeaders(requestInit, body),
|
|
375
|
+
body: JSON.stringify(body),
|
|
376
|
+
signal: requestOptions?.signal,
|
|
377
|
+
});
|
|
378
|
+
if (!response.ok) {
|
|
379
|
+
return throwFailedResponse(response);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
return {
|
|
383
|
+
keys: {
|
|
384
|
+
create: async (input, requestOptions) => request("POST", paths.create, await decode(decodeApiKeyCreate(input)), requestOptions, decodeApiKeyCreated),
|
|
385
|
+
list: (requestOptions) => request("GET", paths.list, undefined, requestOptions, decodeApiKeys),
|
|
386
|
+
revoke: async (input, requestOptions) => requestNoContent(paths.revoke, await decode(decodeApiKeyRevoke(input)), requestOptions),
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
export const createRefreshTokenClient = (options = {}) => {
|
|
391
|
+
const requestInit = {
|
|
392
|
+
...defaultRequestInit,
|
|
393
|
+
...options.requestInit,
|
|
394
|
+
};
|
|
395
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
396
|
+
const prefix = options.prefix ?? defaultRefreshTokenPrefix;
|
|
397
|
+
const paths = {
|
|
398
|
+
...defaultRefreshTokenClientPaths,
|
|
399
|
+
...options.paths,
|
|
400
|
+
};
|
|
401
|
+
const url = (path) => clientUrl(options.baseUrl, joinPath(prefix, path));
|
|
402
|
+
const decodeRefreshTokenRefresh = Schema.decodeUnknownEffect(RefreshTokenRefreshBody);
|
|
403
|
+
const decodeRefreshTokenRefreshed = Schema.decodeUnknownEffect(RefreshTokenRefreshedBody);
|
|
404
|
+
const decode = (effect) => Effect.runPromise(effect);
|
|
405
|
+
const request = async (path, body, requestOptions, decodeResponse) => {
|
|
406
|
+
const response = await fetch(url(path), {
|
|
407
|
+
...requestInit,
|
|
408
|
+
method: "POST",
|
|
409
|
+
headers: requestHeaders(requestInit, body),
|
|
410
|
+
body: JSON.stringify(body),
|
|
411
|
+
signal: requestOptions?.signal,
|
|
412
|
+
});
|
|
413
|
+
if (!response.ok) {
|
|
414
|
+
return throwFailedResponse(response);
|
|
415
|
+
}
|
|
416
|
+
return decode(decodeResponse(await responseJson(response)));
|
|
417
|
+
};
|
|
418
|
+
return {
|
|
419
|
+
token: {
|
|
420
|
+
refresh: async (input, requestOptions) => request(paths.refresh, await decode(decodeRefreshTokenRefresh(input)), requestOptions, decodeRefreshTokenRefreshed),
|
|
421
|
+
},
|
|
422
|
+
};
|
|
423
|
+
};
|
|
424
|
+
export const createJwtClient = (options = {}) => {
|
|
425
|
+
const requestInit = {
|
|
426
|
+
...defaultRequestInit,
|
|
427
|
+
...options.requestInit,
|
|
428
|
+
};
|
|
429
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
430
|
+
const prefix = options.prefix ?? defaultJwtPrefix;
|
|
431
|
+
const paths = {
|
|
432
|
+
...defaultJwtClientPaths,
|
|
433
|
+
...options.paths,
|
|
434
|
+
};
|
|
435
|
+
const url = (path) => clientUrl(options.baseUrl, joinPath(prefix, path));
|
|
436
|
+
const decodeJwtIntrospect = Schema.decodeUnknownEffect(JwtIntrospectBody);
|
|
437
|
+
const decodeJwtRevoke = Schema.decodeUnknownEffect(JwtRevokeBody);
|
|
438
|
+
const decodeJwtIntrospection = Schema.decodeUnknownEffect(JwtIntrospectionBody);
|
|
439
|
+
const decode = (effect) => Effect.runPromise(effect);
|
|
440
|
+
const request = async (path, body, requestOptions, decodeResponse) => {
|
|
441
|
+
const response = await fetch(url(path), {
|
|
442
|
+
...requestInit,
|
|
443
|
+
method: "POST",
|
|
444
|
+
headers: requestHeaders(requestInit, body),
|
|
445
|
+
body: JSON.stringify(body),
|
|
446
|
+
signal: requestOptions?.signal,
|
|
447
|
+
});
|
|
448
|
+
if (!response.ok) {
|
|
449
|
+
return throwFailedResponse(response);
|
|
450
|
+
}
|
|
451
|
+
return decode(decodeResponse(await responseJson(response)));
|
|
452
|
+
};
|
|
453
|
+
const requestNoContent = async (path, body, requestOptions) => {
|
|
454
|
+
const response = await fetch(url(path), {
|
|
455
|
+
...requestInit,
|
|
456
|
+
method: "POST",
|
|
457
|
+
headers: requestHeaders(requestInit, body),
|
|
458
|
+
body: JSON.stringify(body),
|
|
459
|
+
signal: requestOptions?.signal,
|
|
460
|
+
});
|
|
461
|
+
if (!response.ok) {
|
|
462
|
+
return throwFailedResponse(response);
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
return {
|
|
466
|
+
token: {
|
|
467
|
+
introspect: async (input, requestOptions) => request(paths.introspect, await decode(decodeJwtIntrospect(input)), requestOptions, decodeJwtIntrospection),
|
|
468
|
+
revoke: async (input, requestOptions) => requestNoContent(paths.revoke, await decode(decodeJwtRevoke(input)), requestOptions),
|
|
469
|
+
},
|
|
470
|
+
};
|
|
471
|
+
};
|
|
472
|
+
export const createJwtDiscoveryClient = (options = {}) => {
|
|
473
|
+
const requestInit = {
|
|
474
|
+
credentials: "same-origin",
|
|
475
|
+
...options.requestInit,
|
|
476
|
+
};
|
|
477
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
478
|
+
const prefix = options.prefix ?? defaultJwtDiscoveryPrefix;
|
|
479
|
+
const paths = {
|
|
480
|
+
...defaultJwtDiscoveryClientPaths,
|
|
481
|
+
...options.paths,
|
|
482
|
+
};
|
|
483
|
+
const url = (path) => clientUrl(options.baseUrl, joinPath(prefix, path));
|
|
484
|
+
const decodeJwtJwks = Schema.decodeUnknownEffect(JwtJwksBody);
|
|
485
|
+
const decodeOidcDiscoveryMetadata = Schema.decodeUnknownEffect(OidcDiscoveryMetadataBody);
|
|
486
|
+
const decode = (effect) => Effect.runPromise(effect);
|
|
487
|
+
const request = async (path, requestOptions, decodeResponse) => {
|
|
488
|
+
const response = await fetch(url(path), {
|
|
489
|
+
...requestInit,
|
|
490
|
+
method: "GET",
|
|
491
|
+
headers: requestHeaders(requestInit, undefined),
|
|
492
|
+
signal: requestOptions?.signal,
|
|
493
|
+
});
|
|
494
|
+
if (!response.ok) {
|
|
495
|
+
return throwFailedResponse(response);
|
|
496
|
+
}
|
|
497
|
+
return decode(decodeResponse(await responseJson(response)));
|
|
498
|
+
};
|
|
499
|
+
return {
|
|
500
|
+
keys: {
|
|
501
|
+
jwks: (requestOptions) => request(paths.jwks, requestOptions, decodeJwtJwks),
|
|
502
|
+
},
|
|
503
|
+
metadata: {
|
|
504
|
+
openidConfiguration: (requestOptions) => request(paths.openidConfiguration, requestOptions, decodeOidcDiscoveryMetadata),
|
|
505
|
+
},
|
|
506
|
+
};
|
|
507
|
+
};
|
|
508
|
+
export const createMfaClient = (options = {}) => {
|
|
509
|
+
const requestInit = {
|
|
510
|
+
...defaultRequestInit,
|
|
511
|
+
...options.requestInit,
|
|
512
|
+
};
|
|
513
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
514
|
+
const prefix = options.prefix ?? defaultMfaPrefix;
|
|
515
|
+
const paths = {
|
|
516
|
+
...defaultMfaClientPaths,
|
|
517
|
+
...options.paths,
|
|
518
|
+
};
|
|
519
|
+
const url = (path) => clientUrl(options.baseUrl, joinPath(prefix, path));
|
|
520
|
+
const decodeMfaOptions = Schema.decodeUnknownEffect(MfaOptionsBody);
|
|
521
|
+
const decodeTotpMfaVerify = Schema.decodeUnknownEffect(TotpMfaVerifyBody);
|
|
522
|
+
const decodeTotpMfaVerifyForFlow = Schema.decodeUnknownEffect(TotpMfaVerifyForFlowBody);
|
|
523
|
+
const decodeRecoveryCodeMfaVerify = Schema.decodeUnknownEffect(RecoveryCodeMfaVerifyBody);
|
|
524
|
+
const decodeRecoveryCodeMfaVerifyForFlow = Schema.decodeUnknownEffect(RecoveryCodeMfaVerifyForFlowBody);
|
|
525
|
+
const decodePasskeyMfaStart = Schema.decodeUnknownEffect(PasskeyMfaStartBody);
|
|
526
|
+
const decodePasskeyMfaVerify = Schema.decodeUnknownEffect(PasskeyMfaVerifyBody);
|
|
527
|
+
const decodePasskeyAuthenticationStarted = Schema.decodeUnknownEffect(PasskeyAuthenticationStartedBody);
|
|
528
|
+
const decodeMfaOptionsResult = Schema.decodeUnknownEffect(MfaOptionsResultBody);
|
|
529
|
+
const decodeAuthenticated = Schema.decodeUnknownEffect(AuthenticatedHttpBody);
|
|
530
|
+
const decode = (effect) => Effect.runPromise(effect);
|
|
531
|
+
const request = async (path, body, requestOptions, decodeResponse) => {
|
|
532
|
+
const response = await fetch(url(path), {
|
|
533
|
+
...requestInit,
|
|
534
|
+
method: "POST",
|
|
535
|
+
headers: requestHeaders(requestInit, body),
|
|
536
|
+
body: JSON.stringify(body),
|
|
537
|
+
signal: requestOptions?.signal,
|
|
538
|
+
});
|
|
539
|
+
if (!response.ok) {
|
|
540
|
+
return throwFailedResponse(response);
|
|
541
|
+
}
|
|
542
|
+
return decode(decodeResponse(await responseJson(response)));
|
|
543
|
+
};
|
|
544
|
+
return {
|
|
545
|
+
options: async (input, requestOptions) => request(paths.options, await decode(decodeMfaOptions(input)), requestOptions, decodeMfaOptionsResult),
|
|
546
|
+
totp: {
|
|
547
|
+
verify: async (input, requestOptions) => request(paths.totpVerify, await decode(decodeTotpMfaVerify(input)), requestOptions, decodeAuthenticated),
|
|
548
|
+
verifyForFlow: async (input, requestOptions) => request(paths.totpVerifyForFlow, await decode(decodeTotpMfaVerifyForFlow(input)), requestOptions, decodeAuthenticated),
|
|
549
|
+
},
|
|
550
|
+
recoveryCode: {
|
|
551
|
+
verify: async (input, requestOptions) => request(paths.recoveryCodeVerify, await decode(decodeRecoveryCodeMfaVerify(input)), requestOptions, decodeAuthenticated),
|
|
552
|
+
verifyForFlow: async (input, requestOptions) => request(paths.recoveryCodeVerifyForFlow, await decode(decodeRecoveryCodeMfaVerifyForFlow(input)), requestOptions, decodeAuthenticated),
|
|
553
|
+
},
|
|
554
|
+
passkey: {
|
|
555
|
+
start: async (input, requestOptions) => request(paths.passkeyStart, await decode(decodePasskeyMfaStart(input)), requestOptions, decodePasskeyAuthenticationStarted),
|
|
556
|
+
verify: async (input, requestOptions) => request(paths.passkeyVerify, await decode(decodePasskeyMfaVerify(input)), requestOptions, decodeAuthenticated),
|
|
557
|
+
},
|
|
558
|
+
};
|
|
559
|
+
};
|
|
560
|
+
export const createStepUpClient = (options = {}) => {
|
|
561
|
+
const requestInit = {
|
|
562
|
+
...defaultRequestInit,
|
|
563
|
+
...options.requestInit,
|
|
564
|
+
};
|
|
565
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
566
|
+
const prefix = options.prefix ?? defaultStepUpPrefix;
|
|
567
|
+
const paths = {
|
|
568
|
+
...defaultStepUpClientPaths,
|
|
569
|
+
...options.paths,
|
|
570
|
+
};
|
|
571
|
+
const url = (path) => clientUrl(options.baseUrl, joinPath(prefix, path));
|
|
572
|
+
const decodeStepUpTotpVerify = Schema.decodeUnknownEffect(StepUpTotpVerifyBody);
|
|
573
|
+
const decodeStepUpRecoveryCodeVerify = Schema.decodeUnknownEffect(StepUpRecoveryCodeVerifyBody);
|
|
574
|
+
const decodeStepUpPasskeyStart = Schema.decodeUnknownEffect(StepUpPasskeyStartBody);
|
|
575
|
+
const decodeStepUpPasskeyVerify = Schema.decodeUnknownEffect(StepUpPasskeyVerifyBody);
|
|
576
|
+
const decodeStepUpOptions = Schema.decodeUnknownEffect(StepUpOptionsResultBody);
|
|
577
|
+
const decodePasskeyAuthenticationStarted = Schema.decodeUnknownEffect(PasskeyAuthenticationStartedBody);
|
|
578
|
+
const decodeAuthenticated = Schema.decodeUnknownEffect(AuthenticatedHttpBody);
|
|
579
|
+
const decode = (effect) => Effect.runPromise(effect);
|
|
580
|
+
const request = async (method, path, body, requestOptions, decodeResponse) => {
|
|
581
|
+
const response = await fetch(url(path), {
|
|
582
|
+
...requestInit,
|
|
583
|
+
method,
|
|
584
|
+
headers: requestHeaders(requestInit, body),
|
|
585
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
586
|
+
signal: requestOptions?.signal,
|
|
587
|
+
});
|
|
588
|
+
if (!response.ok) {
|
|
589
|
+
return throwFailedResponse(response);
|
|
590
|
+
}
|
|
591
|
+
return decode(decodeResponse(await responseJson(response)));
|
|
592
|
+
};
|
|
593
|
+
return {
|
|
594
|
+
options: (requestOptions) => request("GET", paths.options, undefined, requestOptions, decodeStepUpOptions),
|
|
595
|
+
totp: {
|
|
596
|
+
verify: async (input, requestOptions) => request("POST", paths.totpVerify, await decode(decodeStepUpTotpVerify(input)), requestOptions, decodeAuthenticated),
|
|
597
|
+
},
|
|
598
|
+
recoveryCode: {
|
|
599
|
+
verify: async (input, requestOptions) => request("POST", paths.recoveryCodeVerify, await decode(decodeStepUpRecoveryCodeVerify(input)), requestOptions, decodeAuthenticated),
|
|
600
|
+
},
|
|
601
|
+
passkey: {
|
|
602
|
+
start: async (input, requestOptions) => request("POST", paths.passkeyStart, await decode(decodeStepUpPasskeyStart(input)), requestOptions, decodePasskeyAuthenticationStarted),
|
|
603
|
+
verify: async (input, requestOptions) => request("POST", paths.passkeyVerify, await decode(decodeStepUpPasskeyVerify(input)), requestOptions, decodeAuthenticated),
|
|
604
|
+
},
|
|
605
|
+
};
|
|
606
|
+
};
|
|
607
|
+
export const createSecurityTimelineClient = (options = {}) => {
|
|
608
|
+
const requestInit = {
|
|
609
|
+
...defaultRequestInit,
|
|
610
|
+
...options.requestInit,
|
|
611
|
+
};
|
|
612
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
613
|
+
const prefix = options.prefix ?? defaultSecurityTimelinePrefix;
|
|
614
|
+
const paths = {
|
|
615
|
+
...defaultSecurityTimelineClientPaths,
|
|
616
|
+
...options.paths,
|
|
617
|
+
};
|
|
618
|
+
const url = (path) => clientUrl(options.baseUrl, joinPath(prefix, path));
|
|
619
|
+
const decodeSecurityTimelineList = Schema.decodeUnknownEffect(SecurityTimelineListQuery);
|
|
620
|
+
const decodeSecurityTimelineEvents = Schema.decodeUnknownEffect(SecurityTimelineEventsBody);
|
|
621
|
+
const decode = (effect) => Effect.runPromise(effect);
|
|
622
|
+
const listPath = (query) => {
|
|
623
|
+
const searchParams = new URLSearchParams();
|
|
624
|
+
if (query.limit !== undefined) {
|
|
625
|
+
searchParams.set("limit", String(query.limit));
|
|
626
|
+
}
|
|
627
|
+
if (query.beforeOccurredAt !== undefined) {
|
|
628
|
+
searchParams.set("beforeOccurredAt", String(query.beforeOccurredAt));
|
|
629
|
+
}
|
|
630
|
+
for (const type of query.types ?? []) {
|
|
631
|
+
searchParams.append("types", type);
|
|
632
|
+
}
|
|
633
|
+
for (const category of query.categories ?? []) {
|
|
634
|
+
searchParams.append("categories", category);
|
|
635
|
+
}
|
|
636
|
+
return pathWithSearch(paths.list, searchParams);
|
|
637
|
+
};
|
|
638
|
+
const request = async (path, requestOptions) => {
|
|
639
|
+
const response = await fetch(url(path), {
|
|
640
|
+
...requestInit,
|
|
641
|
+
method: "GET",
|
|
642
|
+
headers: requestHeaders(requestInit, undefined),
|
|
643
|
+
signal: requestOptions?.signal,
|
|
644
|
+
});
|
|
645
|
+
if (!response.ok) {
|
|
646
|
+
return throwFailedResponse(response);
|
|
647
|
+
}
|
|
648
|
+
return decode(decodeSecurityTimelineEvents(await responseJson(response)));
|
|
649
|
+
};
|
|
650
|
+
return {
|
|
651
|
+
events: {
|
|
652
|
+
list: async (input, requestOptions) => request(listPath(await decode(decodeSecurityTimelineList(input ?? {}))), requestOptions),
|
|
653
|
+
},
|
|
654
|
+
};
|
|
655
|
+
};
|
|
656
|
+
export const createAdminSecurityTimelineClient = (options = {}) => {
|
|
657
|
+
const requestInit = {
|
|
658
|
+
...defaultRequestInit,
|
|
659
|
+
...options.requestInit,
|
|
660
|
+
};
|
|
661
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
662
|
+
const prefix = options.prefix ?? defaultAdminSecurityTimelinePrefix;
|
|
663
|
+
const paths = {
|
|
664
|
+
...defaultAdminSecurityTimelineClientPaths,
|
|
665
|
+
...options.paths,
|
|
666
|
+
};
|
|
667
|
+
const url = (path) => clientUrl(options.baseUrl, joinPath(prefix, path));
|
|
668
|
+
const decodeAdminSecurityTimelineList = Schema.decodeUnknownEffect(AdminSecurityTimelineListQuery);
|
|
669
|
+
const decodeSecurityTimelineEvents = Schema.decodeUnknownEffect(SecurityTimelineEventsBody);
|
|
670
|
+
const decode = (effect) => Effect.runPromise(effect);
|
|
671
|
+
const listPath = (query) => {
|
|
672
|
+
const searchParams = new URLSearchParams();
|
|
673
|
+
searchParams.set("userId", query.userId);
|
|
674
|
+
if (query.limit !== undefined) {
|
|
675
|
+
searchParams.set("limit", String(query.limit));
|
|
676
|
+
}
|
|
677
|
+
if (query.beforeOccurredAt !== undefined) {
|
|
678
|
+
searchParams.set("beforeOccurredAt", String(query.beforeOccurredAt));
|
|
679
|
+
}
|
|
680
|
+
for (const type of query.types ?? []) {
|
|
681
|
+
searchParams.append("types", type);
|
|
682
|
+
}
|
|
683
|
+
for (const category of query.categories ?? []) {
|
|
684
|
+
searchParams.append("categories", category);
|
|
685
|
+
}
|
|
686
|
+
return pathWithSearch(paths.list, searchParams);
|
|
687
|
+
};
|
|
688
|
+
const request = async (path, requestOptions) => {
|
|
689
|
+
const response = await fetch(url(path), {
|
|
690
|
+
...requestInit,
|
|
691
|
+
method: "GET",
|
|
692
|
+
headers: requestHeaders(requestInit, undefined),
|
|
693
|
+
signal: requestOptions?.signal,
|
|
694
|
+
});
|
|
695
|
+
if (!response.ok) {
|
|
696
|
+
return throwFailedResponse(response);
|
|
697
|
+
}
|
|
698
|
+
return decode(decodeSecurityTimelineEvents(await responseJson(response)));
|
|
699
|
+
};
|
|
700
|
+
return {
|
|
701
|
+
events: {
|
|
702
|
+
list: async (input, requestOptions) => request(listPath(await decode(decodeAdminSecurityTimelineList(input))), requestOptions),
|
|
703
|
+
},
|
|
704
|
+
};
|
|
705
|
+
};
|
|
706
|
+
export const createAdminSessionClient = (options = {}) => {
|
|
707
|
+
const requestInit = {
|
|
708
|
+
...defaultRequestInit,
|
|
709
|
+
...options.requestInit,
|
|
710
|
+
};
|
|
711
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
712
|
+
const prefix = options.prefix ?? defaultAdminSessionPrefix;
|
|
713
|
+
const paths = {
|
|
714
|
+
...defaultAdminSessionClientPaths,
|
|
715
|
+
...options.paths,
|
|
716
|
+
};
|
|
717
|
+
const url = (path) => clientUrl(options.baseUrl, joinPath(prefix, path));
|
|
718
|
+
const decodeAdminSessionList = Schema.decodeUnknownEffect(AdminSessionListQuery);
|
|
719
|
+
const decodeAdminSessionRevoke = Schema.decodeUnknownEffect(AdminSessionRevokeBody);
|
|
720
|
+
const decodeAdminSessionRevokeAll = Schema.decodeUnknownEffect(AdminSessionRevokeAllBody);
|
|
721
|
+
const decodeAdminSessions = Schema.decodeUnknownEffect(AdminSessionsHttpBody);
|
|
722
|
+
const decode = (effect) => Effect.runPromise(effect);
|
|
723
|
+
const listPath = (query) => {
|
|
724
|
+
const searchParams = new URLSearchParams();
|
|
725
|
+
searchParams.set("userId", query.userId);
|
|
726
|
+
return pathWithSearch(paths.list === "/" ? "" : paths.list, searchParams);
|
|
727
|
+
};
|
|
728
|
+
const request = async (method, path, body, requestOptions, decodeResponse) => {
|
|
729
|
+
const response = await fetch(url(path), {
|
|
730
|
+
...requestInit,
|
|
731
|
+
method,
|
|
732
|
+
headers: requestHeaders(requestInit, body),
|
|
733
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
734
|
+
signal: requestOptions?.signal,
|
|
735
|
+
});
|
|
736
|
+
if (!response.ok) {
|
|
737
|
+
return throwFailedResponse(response);
|
|
738
|
+
}
|
|
739
|
+
return decode(decodeResponse(await responseJson(response)));
|
|
740
|
+
};
|
|
741
|
+
const requestNoContent = async (path, body, requestOptions) => {
|
|
742
|
+
const response = await fetch(url(path), {
|
|
743
|
+
...requestInit,
|
|
744
|
+
method: "POST",
|
|
745
|
+
headers: requestHeaders(requestInit, body),
|
|
746
|
+
body: JSON.stringify(body),
|
|
747
|
+
signal: requestOptions?.signal,
|
|
748
|
+
});
|
|
749
|
+
if (!response.ok) {
|
|
750
|
+
return throwFailedResponse(response);
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
return {
|
|
754
|
+
sessions: {
|
|
755
|
+
list: async (input, requestOptions) => request("GET", listPath(await decode(decodeAdminSessionList(input))), undefined, requestOptions, decodeAdminSessions),
|
|
756
|
+
revoke: async (input, requestOptions) => requestNoContent(paths.revoke, await decode(decodeAdminSessionRevoke(input)), requestOptions),
|
|
757
|
+
revokeAll: async (input, requestOptions) => requestNoContent(paths.revokeAll, await decode(decodeAdminSessionRevokeAll(input)), requestOptions),
|
|
758
|
+
},
|
|
759
|
+
};
|
|
760
|
+
};
|
|
761
|
+
export const createTrustedDeviceClient = (options = {}) => {
|
|
762
|
+
const requestInit = {
|
|
763
|
+
...defaultRequestInit,
|
|
764
|
+
...options.requestInit,
|
|
765
|
+
};
|
|
766
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
767
|
+
const prefix = options.prefix ?? defaultTrustedDevicePrefix;
|
|
768
|
+
const paths = {
|
|
769
|
+
...defaultTrustedDeviceClientPaths,
|
|
770
|
+
...options.paths,
|
|
771
|
+
};
|
|
772
|
+
const url = (path) => clientUrl(options.baseUrl, joinPath(prefix, path));
|
|
773
|
+
const decodeTrustedDeviceRevoke = Schema.decodeUnknownEffect(TrustedDeviceRevokeBody);
|
|
774
|
+
const decodeTrustedDevices = Schema.decodeUnknownEffect(TrustedDevicesBody);
|
|
775
|
+
const decode = (effect) => Effect.runPromise(effect);
|
|
776
|
+
const request = async (method, path, body, requestOptions, decodeResponse) => {
|
|
777
|
+
const response = await fetch(url(path), {
|
|
778
|
+
...requestInit,
|
|
779
|
+
method,
|
|
780
|
+
headers: requestHeaders(requestInit, body),
|
|
781
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
782
|
+
signal: requestOptions?.signal,
|
|
783
|
+
});
|
|
784
|
+
if (!response.ok) {
|
|
785
|
+
return throwFailedResponse(response);
|
|
786
|
+
}
|
|
787
|
+
return decode(decodeResponse(await responseJson(response)));
|
|
788
|
+
};
|
|
789
|
+
const requestNoContent = async (path, body, requestOptions) => {
|
|
790
|
+
const response = await fetch(url(path), {
|
|
791
|
+
...requestInit,
|
|
792
|
+
method: "POST",
|
|
793
|
+
headers: requestHeaders(requestInit, body),
|
|
794
|
+
body: JSON.stringify(body),
|
|
795
|
+
signal: requestOptions?.signal,
|
|
796
|
+
});
|
|
797
|
+
if (!response.ok) {
|
|
798
|
+
return throwFailedResponse(response);
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
return {
|
|
802
|
+
devices: {
|
|
803
|
+
list: (requestOptions) => request("GET", paths.list, undefined, requestOptions, decodeTrustedDevices),
|
|
804
|
+
revoke: async (input, requestOptions) => requestNoContent(paths.revoke, await decode(decodeTrustedDeviceRevoke(input)), requestOptions),
|
|
805
|
+
},
|
|
806
|
+
};
|
|
807
|
+
};
|
|
808
|
+
export const createAdminTrustedDeviceClient = (options = {}) => {
|
|
809
|
+
const requestInit = {
|
|
810
|
+
...defaultRequestInit,
|
|
811
|
+
...options.requestInit,
|
|
812
|
+
};
|
|
813
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
814
|
+
const prefix = options.prefix ?? defaultAdminTrustedDevicePrefix;
|
|
815
|
+
const paths = {
|
|
816
|
+
...defaultAdminTrustedDeviceClientPaths,
|
|
817
|
+
...options.paths,
|
|
818
|
+
};
|
|
819
|
+
const url = (path) => clientUrl(options.baseUrl, joinPath(prefix, path));
|
|
820
|
+
const decodeAdminTrustedDeviceList = Schema.decodeUnknownEffect(AdminTrustedDeviceListQuery);
|
|
821
|
+
const decodeAdminTrustedDeviceRevoke = Schema.decodeUnknownEffect(AdminTrustedDeviceRevokeBody);
|
|
822
|
+
const decodeTrustedDevices = Schema.decodeUnknownEffect(TrustedDevicesBody);
|
|
823
|
+
const decode = (effect) => Effect.runPromise(effect);
|
|
824
|
+
const listPath = (query) => {
|
|
825
|
+
const searchParams = new URLSearchParams();
|
|
826
|
+
searchParams.set("userId", query.userId);
|
|
827
|
+
return pathWithSearch(paths.list === "/" ? "" : paths.list, searchParams);
|
|
828
|
+
};
|
|
829
|
+
const request = async (method, path, body, requestOptions, decodeResponse) => {
|
|
830
|
+
const response = await fetch(url(path), {
|
|
831
|
+
...requestInit,
|
|
832
|
+
method,
|
|
833
|
+
headers: requestHeaders(requestInit, body),
|
|
834
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
835
|
+
signal: requestOptions?.signal,
|
|
836
|
+
});
|
|
837
|
+
if (!response.ok) {
|
|
838
|
+
return throwFailedResponse(response);
|
|
839
|
+
}
|
|
840
|
+
return decode(decodeResponse(await responseJson(response)));
|
|
841
|
+
};
|
|
842
|
+
const requestNoContent = async (path, body, requestOptions) => {
|
|
843
|
+
const response = await fetch(url(path), {
|
|
844
|
+
...requestInit,
|
|
845
|
+
method: "POST",
|
|
846
|
+
headers: requestHeaders(requestInit, body),
|
|
847
|
+
body: JSON.stringify(body),
|
|
848
|
+
signal: requestOptions?.signal,
|
|
849
|
+
});
|
|
850
|
+
if (!response.ok) {
|
|
851
|
+
return throwFailedResponse(response);
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
return {
|
|
855
|
+
devices: {
|
|
856
|
+
list: async (input, requestOptions) => request("GET", listPath(await decode(decodeAdminTrustedDeviceList(input))), undefined, requestOptions, decodeTrustedDevices),
|
|
857
|
+
revoke: async (input, requestOptions) => requestNoContent(paths.revoke, await decode(decodeAdminTrustedDeviceRevoke(input)), requestOptions),
|
|
858
|
+
},
|
|
859
|
+
};
|
|
860
|
+
};
|
|
861
|
+
export const createOAuthClient = (options = {}) => {
|
|
862
|
+
const requestInit = {
|
|
863
|
+
...defaultRequestInit,
|
|
864
|
+
...options.requestInit,
|
|
865
|
+
};
|
|
866
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
867
|
+
const prefix = options.prefix ?? defaultOAuthPrefix;
|
|
868
|
+
const paths = {
|
|
869
|
+
...defaultOAuthClientPaths,
|
|
870
|
+
...options.paths,
|
|
871
|
+
};
|
|
872
|
+
const url = (path) => clientUrl(options.baseUrl, joinPath(prefix, path));
|
|
873
|
+
const decodeOAuthAuthorizationStart = Schema.decodeUnknownEffect(OAuthAuthorizationStartBody);
|
|
874
|
+
const decodeOAuthAccountUnlink = Schema.decodeUnknownEffect(OAuthAccountUnlinkBody);
|
|
875
|
+
const decodeOAuthLinkConfirmationStart = Schema.decodeUnknownEffect(OAuthLinkConfirmationStartBody);
|
|
876
|
+
const decodeOAuthLinkConfirmationInspect = Schema.decodeUnknownEffect(OAuthLinkConfirmationInspectBody);
|
|
877
|
+
const decodeOAuthLinkConfirmationConfirm = Schema.decodeUnknownEffect(OAuthLinkConfirmationConfirmBody);
|
|
878
|
+
const decodeOAuthAuthorizationStarted = Schema.decodeUnknownEffect(OAuthAuthorizationStartedBody);
|
|
879
|
+
const decodeOAuthAccountUnlinkResolution = Schema.decodeUnknownEffect(OAuthAccountUnlinkResolutionBody);
|
|
880
|
+
const decodeOAuthLinkConfirmationStarted = Schema.decodeUnknownEffect(OAuthLinkConfirmationStartedBody);
|
|
881
|
+
const decodeOAuthLinkConfirmationPending = Schema.decodeUnknownEffect(OAuthLinkConfirmationPendingBody);
|
|
882
|
+
const decodeOAuthLinkConfirmationConfirmed = Schema.decodeUnknownEffect(OAuthLinkConfirmationConfirmedBody);
|
|
883
|
+
const decode = (effect) => Effect.runPromise(effect);
|
|
884
|
+
const request = async (path, body, requestOptions, decodeResponse) => {
|
|
885
|
+
const response = await fetch(url(path), {
|
|
886
|
+
...requestInit,
|
|
887
|
+
method: "POST",
|
|
888
|
+
headers: requestHeaders(requestInit, body),
|
|
889
|
+
body: JSON.stringify(body),
|
|
890
|
+
signal: requestOptions?.signal,
|
|
891
|
+
});
|
|
892
|
+
if (!response.ok) {
|
|
893
|
+
return throwFailedResponse(response);
|
|
894
|
+
}
|
|
895
|
+
return decode(decodeResponse(await responseJson(response)));
|
|
896
|
+
};
|
|
897
|
+
return {
|
|
898
|
+
authorization: {
|
|
899
|
+
start: async (input, requestOptions) => request(paths.authorizationStart, await decode(decodeOAuthAuthorizationStart(input)), requestOptions, decodeOAuthAuthorizationStarted),
|
|
900
|
+
},
|
|
901
|
+
accounts: {
|
|
902
|
+
unlink: async (input, requestOptions) => request(paths.accountUnlink, await decode(decodeOAuthAccountUnlink(input)), requestOptions, decodeOAuthAccountUnlinkResolution),
|
|
903
|
+
},
|
|
904
|
+
linkConfirmation: {
|
|
905
|
+
start: async (input, requestOptions) => request(paths.linkConfirmationStart, await decode(decodeOAuthLinkConfirmationStart(input)), requestOptions, decodeOAuthLinkConfirmationStarted),
|
|
906
|
+
inspect: async (input, requestOptions) => request(paths.linkConfirmationInspect, await decode(decodeOAuthLinkConfirmationInspect(input)), requestOptions, decodeOAuthLinkConfirmationPending),
|
|
907
|
+
confirm: async (input, requestOptions) => request(paths.linkConfirmationConfirm, await decode(decodeOAuthLinkConfirmationConfirm(input)), requestOptions, decodeOAuthLinkConfirmationConfirmed),
|
|
908
|
+
},
|
|
909
|
+
};
|
|
910
|
+
};
|
|
911
|
+
export const createAuthClient = (options = {}) => {
|
|
912
|
+
const requestInit = {
|
|
913
|
+
...defaultRequestInit,
|
|
914
|
+
...options.requestInit,
|
|
915
|
+
};
|
|
916
|
+
const fetchLayer = FetchHttpClient.layer.pipe(Layer.provide(Layer.succeed(FetchHttpClient.RequestInit, requestInit)), options.fetch === undefined
|
|
917
|
+
? (layer) => layer
|
|
918
|
+
: Layer.provide(Layer.succeed(FetchHttpClient.Fetch, options.fetch)));
|
|
919
|
+
const runtime = ManagedRuntime.make(fetchLayer);
|
|
920
|
+
const clientEffect = HttpApiClient.make(AuthApi, {
|
|
921
|
+
baseUrl: options.baseUrl,
|
|
922
|
+
});
|
|
923
|
+
const decodePasswordSignIn = Schema.decodeUnknownEffect(PasswordSignInBody);
|
|
924
|
+
const decodePasswordSignUp = Schema.decodeUnknownEffect(PasswordSignUpBody);
|
|
925
|
+
const decodePasswordResetStart = Schema.decodeUnknownEffect(PasswordResetStartBody);
|
|
926
|
+
const decodePasswordResetVerify = Schema.decodeUnknownEffect(PasswordResetVerifyBody);
|
|
927
|
+
const decodePasswordSet = Schema.decodeUnknownEffect(PasswordSetBody);
|
|
928
|
+
const decodePasswordChange = Schema.decodeUnknownEffect(PasswordChangeBody);
|
|
929
|
+
const decodeSessionRevoke = Schema.decodeUnknownEffect(SessionRevokeBody);
|
|
930
|
+
const decodeEmailVerificationStart = Schema.decodeUnknownEffect(EmailVerificationStartBody);
|
|
931
|
+
const decodeEmailVerificationVerify = Schema.decodeUnknownEffect(EmailVerificationVerifyBody);
|
|
932
|
+
const decodeEmailOtpStart = Schema.decodeUnknownEffect(EmailOtpStartBody);
|
|
933
|
+
const decodeEmailOtpVerify = Schema.decodeUnknownEffect(EmailOtpVerifyBody);
|
|
934
|
+
const decodeMagicLinkStart = Schema.decodeUnknownEffect(MagicLinkStartBody);
|
|
935
|
+
const decodeMagicLinkVerify = Schema.decodeUnknownEffect(MagicLinkVerifyBody);
|
|
936
|
+
const decodeLoginApprovalApprove = Schema.decodeUnknownEffect(LoginApprovalApproveBody);
|
|
937
|
+
const decodeLoginApprovalStatus = Schema.decodeUnknownEffect(LoginApprovalReviewStatusBody);
|
|
938
|
+
const decodeLoginApprovalFinalize = Schema.decodeUnknownEffect(LoginApprovalFinalizeBody);
|
|
939
|
+
const decodeLoginNotificationReport = Schema.decodeUnknownEffect(LoginNotificationReportBody);
|
|
940
|
+
const run = (effect, requestOptions = {}) => runtime.runPromise(effect, requestOptions);
|
|
941
|
+
const withClient = (effect, requestOptions) => run(Effect.flatMap(clientEffect, effect), requestOptions);
|
|
942
|
+
return {
|
|
943
|
+
password: {
|
|
944
|
+
signIn: (input, requestOptions) => withClient((client) => Effect.flatMap(decodePasswordSignIn(input), (payload) => client.password.signIn({ payload })), requestOptions),
|
|
945
|
+
signUp: (input, requestOptions) => withClient((client) => Effect.flatMap(decodePasswordSignUp(input), (payload) => client.password.signUp({ payload })), requestOptions),
|
|
946
|
+
reset: {
|
|
947
|
+
start: (input, requestOptions) => withClient((client) => Effect.flatMap(decodePasswordResetStart(input), (payload) => client.password.resetStart({ payload })), requestOptions),
|
|
948
|
+
verify: (input, requestOptions) => withClient((client) => Effect.flatMap(decodePasswordResetVerify(input), (payload) => client.password.resetVerify({ payload })), requestOptions),
|
|
949
|
+
},
|
|
950
|
+
set: (input, requestOptions) => withClient((client) => Effect.flatMap(decodePasswordSet(input), (payload) => client.password.set({ payload })), requestOptions),
|
|
951
|
+
change: (input, requestOptions) => withClient((client) => Effect.flatMap(decodePasswordChange(input), (payload) => client.password.change({ payload })), requestOptions),
|
|
952
|
+
},
|
|
953
|
+
session: {
|
|
954
|
+
current: (requestOptions) => withClient((client) => client.session.current(), requestOptions),
|
|
955
|
+
currentOrUndefined: (requestOptions) => withClient((client) => client.session.current().pipe(Effect.catchIf((error) => error instanceof AuthUnauthenticatedError, () => Effect.succeed(undefined))), requestOptions),
|
|
956
|
+
refresh: (requestOptions) => withClient((client) => client.session.refresh(), requestOptions),
|
|
957
|
+
logout: (requestOptions) => withClient((client) => client.session.logout(), requestOptions),
|
|
958
|
+
list: (requestOptions) => withClient((client) => client.session.list(), requestOptions),
|
|
959
|
+
revoke: (input, requestOptions) => withClient((client) => Effect.flatMap(decodeSessionRevoke(input), (payload) => client.session.revoke({ payload })), requestOptions),
|
|
960
|
+
revokeOthers: (requestOptions) => withClient((client) => client.session.revokeOthers(), requestOptions),
|
|
961
|
+
},
|
|
962
|
+
emailVerification: {
|
|
963
|
+
start: (input, requestOptions) => withClient((client) => Effect.flatMap(decodeEmailVerificationStart(input), (payload) => client.emailVerification.start({ payload })), requestOptions),
|
|
964
|
+
verify: (input, requestOptions) => withClient((client) => Effect.flatMap(decodeEmailVerificationVerify(input), (payload) => client.emailVerification.verify({ payload })), requestOptions),
|
|
965
|
+
},
|
|
966
|
+
emailOtp: {
|
|
967
|
+
start: (input, requestOptions) => withClient((client) => Effect.flatMap(decodeEmailOtpStart(input), (payload) => client.emailOtp.start({ payload })), requestOptions),
|
|
968
|
+
verify: (input, requestOptions) => withClient((client) => Effect.flatMap(decodeEmailOtpVerify(input), (payload) => client.emailOtp.verify({ payload })), requestOptions),
|
|
969
|
+
},
|
|
970
|
+
magicLink: {
|
|
971
|
+
start: (input, requestOptions) => withClient((client) => Effect.flatMap(decodeMagicLinkStart(input), (payload) => client.magicLink.start({ payload })), requestOptions),
|
|
972
|
+
verify: (input, requestOptions) => withClient((client) => Effect.flatMap(decodeMagicLinkVerify(input), (payload) => client.magicLink.verify({ payload })), requestOptions),
|
|
973
|
+
},
|
|
974
|
+
loginApproval: {
|
|
975
|
+
approve: (input, requestOptions) => withClient((client) => Effect.flatMap(decodeLoginApprovalApprove(input), (payload) => client.loginApproval.approve({ payload })), requestOptions),
|
|
976
|
+
status: (input, requestOptions) => withClient((client) => Effect.flatMap(decodeLoginApprovalStatus(input), (payload) => client.loginApproval.status({ payload })), requestOptions),
|
|
977
|
+
finalize: (input, requestOptions) => withClient((client) => Effect.flatMap(decodeLoginApprovalFinalize(input), (payload) => client.loginApproval.finalize({ payload })), requestOptions),
|
|
978
|
+
},
|
|
979
|
+
security: {
|
|
980
|
+
reportLogin: (input, requestOptions) => withClient((client) => Effect.flatMap(decodeLoginNotificationReport(input), (payload) => client.security.reportLogin({ payload })), requestOptions),
|
|
981
|
+
},
|
|
982
|
+
dispose: () => runtime.dispose(),
|
|
983
|
+
};
|
|
984
|
+
};
|
|
985
|
+
//# sourceMappingURL=Client.js.map
|