@effect-auth/core 0.1.0-alpha.1 → 0.1.0-alpha.10
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 +728 -72
- 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 +275 -1
- package/dist/AuditLog.d.ts.map +1 -1
- package/dist/AuditLog.js +213 -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 +378 -0
- package/dist/Client.d.ts.map +1 -0
- package/dist/Client.js +768 -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/EffectQbSqliteStorage.d.ts +600 -0
- package/dist/EffectQbSqliteStorage.d.ts.map +1 -0
- package/dist/EffectQbSqliteStorage.js +1637 -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 +1956 -0
- package/dist/HttpApi/Api.d.ts.map +1 -0
- package/dist/HttpApi/Api.js +2325 -0
- package/dist/HttpApi/Api.js.map +1 -0
- package/dist/HttpApi/Endpoints.d.ts +945 -0
- package/dist/HttpApi/Endpoints.d.ts.map +1 -0
- package/dist/HttpApi/Endpoints.js +373 -0
- package/dist/HttpApi/Endpoints.js.map +1 -0
- package/dist/HttpApi/Errors.d.ts +82 -0
- package/dist/HttpApi/Errors.d.ts.map +1 -0
- package/dist/HttpApi/Errors.js +184 -0
- package/dist/HttpApi/Errors.js.map +1 -0
- package/dist/HttpApi/Schemas.d.ts +1113 -0
- package/dist/HttpApi/Schemas.d.ts.map +1 -0
- package/dist/HttpApi/Schemas.js +734 -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.map +1 -1
- package/dist/Identifiers.js.map +1 -1
- 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 +271 -0
- package/dist/Jwt.d.ts.map +1 -0
- package/dist/Jwt.js +512 -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 +73 -0
- package/dist/LoginRisk.d.ts.map +1 -0
- package/dist/LoginRisk.js +57 -0
- package/dist/LoginRisk.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 +934 -0
- package/dist/OAuth.d.ts.map +1 -0
- package/dist/OAuth.js +1661 -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/SecurityTimeline.d.ts +72 -0
- package/dist/SecurityTimeline.d.ts.map +1 -0
- package/dist/SecurityTimeline.js +386 -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 +13 -1
- package/dist/StorageMigrations.d.ts.map +1 -1
- package/dist/StorageMigrations.js +256 -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 +72 -0
- package/dist/Webhook.d.ts.map +1 -0
- package/dist/Webhook.js +82 -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 +21 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -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/package.json +146 -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
|
@@ -0,0 +1,1637 @@
|
|
|
1
|
+
import { Data, Effect, Layer, Option, Redacted } from "effect";
|
|
2
|
+
import { Column, Executor, Query, Scalar, Table } from "effect-qb/sqlite";
|
|
3
|
+
import { ApiKeyId, ApiKeyPrefix, ApiKeySecretHash, ApiKeyStore, ApiKeyStoreError, } from "./ApiKey.js";
|
|
4
|
+
import { AuthFlowId, ChallengeId, CredentialId, Email, OAuthAccountId, OAuthProviderId, SessionId, UnixMillis, UserId, } from "./Identifiers.js";
|
|
5
|
+
import { JwtError, JwtRevocationStore } from "./Jwt.js";
|
|
6
|
+
import { LoginApprovalReviewError, LoginApprovalReviewStore, } from "./LoginApproval.js";
|
|
7
|
+
import { LoginRiskContext, LoginRiskSignal } from "./LoginRisk.js";
|
|
8
|
+
import { OAuthAccountStore, OAuthAccountStoreError, OAuthProviderTokenVault, OAuthProviderTokenVaultError, } from "./OAuth.js";
|
|
9
|
+
import { PasskeyCredentialId, PasskeyCredentialStore, PasskeyCredentialStoreError, } from "./Passkey.js";
|
|
10
|
+
import { RecoveryCodeHash, RecoveryCodeStore, RecoveryCodeStoreError, } from "./RecoveryCode.js";
|
|
11
|
+
import { RefreshTokenFamilyId, RefreshTokenId, RefreshTokenSecretHash, RefreshTokenStore, RefreshTokenStoreError, } from "./RefreshToken.js";
|
|
12
|
+
import { filterSecurityTimelineEvents, SecurityTimelineEventId, SecurityTimelineStore, SecurityTimelineStoreError, } from "./SecurityTimeline.js";
|
|
13
|
+
import { CredentialStore, SessionStore, StorageError, UserStore, VerificationStore, } from "./Storage.js";
|
|
14
|
+
import { TotpFactorStore, TotpFactorStoreError, TotpSecret, } from "./Totp.js";
|
|
15
|
+
import { filterTrustedDevicesForUser, TrustedDeviceError, TrustedDeviceStore, } from "./TrustedDevice.js";
|
|
16
|
+
export class D1EffectQbError extends Data.TaggedError("D1EffectQbError") {
|
|
17
|
+
}
|
|
18
|
+
const makeAuthUserTable = (name) => Table.make(name, {
|
|
19
|
+
id: Column.text().pipe(Column.primaryKey),
|
|
20
|
+
email: Column.text(),
|
|
21
|
+
email_verified: Column.int(),
|
|
22
|
+
created_at: Column.int(),
|
|
23
|
+
updated_at: Column.int(),
|
|
24
|
+
disabled_at: Column.int().pipe(Column.nullable),
|
|
25
|
+
metadata: Column.text().pipe(Column.nullable),
|
|
26
|
+
});
|
|
27
|
+
const makeAuthCredentialTable = (name) => Table.make(name, {
|
|
28
|
+
id: Column.text().pipe(Column.primaryKey),
|
|
29
|
+
user_id: Column.text(),
|
|
30
|
+
type: Column.text(),
|
|
31
|
+
password_hash: Column.text().pipe(Column.nullable),
|
|
32
|
+
created_at: Column.int(),
|
|
33
|
+
updated_at: Column.int(),
|
|
34
|
+
revoked_at: Column.int().pipe(Column.nullable),
|
|
35
|
+
metadata: Column.text().pipe(Column.nullable),
|
|
36
|
+
});
|
|
37
|
+
const makeAuthSessionTable = (name) => Table.make(name, {
|
|
38
|
+
id: Column.text().pipe(Column.primaryKey),
|
|
39
|
+
user_id: Column.text(),
|
|
40
|
+
secret_hash: Column.text(),
|
|
41
|
+
created_at: Column.int(),
|
|
42
|
+
expires_at: Column.int(),
|
|
43
|
+
auth_time: Column.int(),
|
|
44
|
+
aal: Column.text(),
|
|
45
|
+
amr: Column.text(),
|
|
46
|
+
mfa_verified_at: Column.int().pipe(Column.nullable),
|
|
47
|
+
metadata: Column.text().pipe(Column.nullable),
|
|
48
|
+
revoked_at: Column.int().pipe(Column.nullable),
|
|
49
|
+
last_seen_at: Column.int().pipe(Column.nullable),
|
|
50
|
+
rotated_at: Column.int().pipe(Column.nullable),
|
|
51
|
+
});
|
|
52
|
+
const makeAuthVerificationTable = (name) => Table.make(name, {
|
|
53
|
+
id: Column.text().pipe(Column.primaryKey),
|
|
54
|
+
type: Column.text(),
|
|
55
|
+
subject: Column.text(),
|
|
56
|
+
secret_hash: Column.text().pipe(Column.nullable),
|
|
57
|
+
created_at: Column.int(),
|
|
58
|
+
expires_at: Column.int(),
|
|
59
|
+
metadata: Column.text().pipe(Column.nullable),
|
|
60
|
+
consumed_at: Column.int().pipe(Column.nullable),
|
|
61
|
+
});
|
|
62
|
+
const makeAuthLoginApprovalReviewTable = (name) => Table.make(name, {
|
|
63
|
+
approval_challenge_id: Column.text().pipe(Column.primaryKey),
|
|
64
|
+
flow_id: Column.text(),
|
|
65
|
+
user_id: Column.text(),
|
|
66
|
+
channel: Column.text(),
|
|
67
|
+
reason: Column.text(),
|
|
68
|
+
session_binding: Column.text(),
|
|
69
|
+
same_device_required: Column.int(),
|
|
70
|
+
status: Column.text(),
|
|
71
|
+
created_at: Column.int(),
|
|
72
|
+
expires_at: Column.int(),
|
|
73
|
+
reviewed_at: Column.int().pipe(Column.nullable),
|
|
74
|
+
reviewed_by: Column.text().pipe(Column.nullable),
|
|
75
|
+
denied_reason: Column.text().pipe(Column.nullable),
|
|
76
|
+
risk: Column.text().pipe(Column.nullable),
|
|
77
|
+
metadata: Column.text().pipe(Column.nullable),
|
|
78
|
+
review_metadata: Column.text().pipe(Column.nullable),
|
|
79
|
+
});
|
|
80
|
+
const makeAuthTrustedDeviceTable = (name) => Table.make(name, {
|
|
81
|
+
user_id: Column.text(),
|
|
82
|
+
token_hash: Column.text(),
|
|
83
|
+
created_at: Column.int(),
|
|
84
|
+
last_seen_at: Column.int(),
|
|
85
|
+
expires_at: Column.int(),
|
|
86
|
+
metadata: Column.text().pipe(Column.nullable),
|
|
87
|
+
});
|
|
88
|
+
const makeAuthPasskeyCredentialTable = (name) => Table.make(name, {
|
|
89
|
+
id: Column.text().pipe(Column.primaryKey),
|
|
90
|
+
user_id: Column.text(),
|
|
91
|
+
credential_id: Column.text(),
|
|
92
|
+
public_key: Column.text(),
|
|
93
|
+
sign_count: Column.int(),
|
|
94
|
+
transports: Column.text().pipe(Column.nullable),
|
|
95
|
+
backed_up: Column.int().pipe(Column.nullable),
|
|
96
|
+
created_at: Column.int(),
|
|
97
|
+
last_used_at: Column.int().pipe(Column.nullable),
|
|
98
|
+
revoked_at: Column.int().pipe(Column.nullable),
|
|
99
|
+
metadata: Column.text().pipe(Column.nullable),
|
|
100
|
+
});
|
|
101
|
+
const makeAuthTotpFactorTable = (name) => Table.make(name, {
|
|
102
|
+
id: Column.text().pipe(Column.primaryKey),
|
|
103
|
+
user_id: Column.text(),
|
|
104
|
+
secret: Column.text(),
|
|
105
|
+
algorithm: Column.text(),
|
|
106
|
+
digits: Column.int(),
|
|
107
|
+
period: Column.int(),
|
|
108
|
+
created_at: Column.int(),
|
|
109
|
+
confirmed_at: Column.int().pipe(Column.nullable),
|
|
110
|
+
last_used_at: Column.int().pipe(Column.nullable),
|
|
111
|
+
revoked_at: Column.int().pipe(Column.nullable),
|
|
112
|
+
metadata: Column.text().pipe(Column.nullable),
|
|
113
|
+
});
|
|
114
|
+
const makeAuthRecoveryCodeTable = (name) => Table.make(name, {
|
|
115
|
+
id: Column.text().pipe(Column.primaryKey),
|
|
116
|
+
user_id: Column.text(),
|
|
117
|
+
code_hash: Column.text(),
|
|
118
|
+
created_at: Column.int(),
|
|
119
|
+
used_at: Column.int().pipe(Column.nullable),
|
|
120
|
+
revoked_at: Column.int().pipe(Column.nullable),
|
|
121
|
+
metadata: Column.text().pipe(Column.nullable),
|
|
122
|
+
});
|
|
123
|
+
const makeAuthApiKeyTable = (name) => Table.make(name, {
|
|
124
|
+
id: Column.text().pipe(Column.primaryKey),
|
|
125
|
+
user_id: Column.text(),
|
|
126
|
+
prefix: Column.text(),
|
|
127
|
+
secret_hash: Column.text(),
|
|
128
|
+
scopes: Column.text(),
|
|
129
|
+
created_at: Column.int(),
|
|
130
|
+
expires_at: Column.int().pipe(Column.nullable),
|
|
131
|
+
last_used_at: Column.int().pipe(Column.nullable),
|
|
132
|
+
revoked_at: Column.int().pipe(Column.nullable),
|
|
133
|
+
metadata: Column.text().pipe(Column.nullable),
|
|
134
|
+
});
|
|
135
|
+
const makeAuthRefreshTokenTable = (name) => Table.make(name, {
|
|
136
|
+
id: Column.text().pipe(Column.primaryKey),
|
|
137
|
+
family_id: Column.text(),
|
|
138
|
+
user_id: Column.text(),
|
|
139
|
+
secret_hash: Column.text(),
|
|
140
|
+
created_at: Column.int(),
|
|
141
|
+
expires_at: Column.int(),
|
|
142
|
+
last_used_at: Column.int().pipe(Column.nullable),
|
|
143
|
+
rotated_at: Column.int().pipe(Column.nullable),
|
|
144
|
+
replaced_by_id: Column.text().pipe(Column.nullable),
|
|
145
|
+
revoked_at: Column.int().pipe(Column.nullable),
|
|
146
|
+
reuse_detected_at: Column.int().pipe(Column.nullable),
|
|
147
|
+
metadata: Column.text().pipe(Column.nullable),
|
|
148
|
+
});
|
|
149
|
+
const makeAuthJwtRevocationTable = (name) => Table.make(name, {
|
|
150
|
+
jwt_id: Column.text().pipe(Column.primaryKey),
|
|
151
|
+
revoked_at: Column.int(),
|
|
152
|
+
expires_at: Column.int().pipe(Column.nullable),
|
|
153
|
+
reason: Column.text().pipe(Column.nullable),
|
|
154
|
+
});
|
|
155
|
+
const makeAuthOAuthAccountTable = (name) => Table.make(name, {
|
|
156
|
+
id: Column.text().pipe(Column.primaryKey),
|
|
157
|
+
provider_id: Column.text(),
|
|
158
|
+
provider_account_id: Column.text(),
|
|
159
|
+
user_id: Column.text(),
|
|
160
|
+
email: Column.text().pipe(Column.nullable),
|
|
161
|
+
email_verified: Column.int().pipe(Column.nullable),
|
|
162
|
+
created_at: Column.int(),
|
|
163
|
+
updated_at: Column.int(),
|
|
164
|
+
unlinked_at: Column.int().pipe(Column.nullable),
|
|
165
|
+
metadata: Column.text().pipe(Column.nullable),
|
|
166
|
+
});
|
|
167
|
+
const makeAuthOAuthProviderTokenVaultTable = (name) => Table.make(name, {
|
|
168
|
+
account_id: Column.text().pipe(Column.primaryKey),
|
|
169
|
+
user_id: Column.text(),
|
|
170
|
+
provider_id: Column.text(),
|
|
171
|
+
provider_account_id: Column.text(),
|
|
172
|
+
access_token_ciphertext: Column.text(),
|
|
173
|
+
refresh_token_ciphertext: Column.text().pipe(Column.nullable),
|
|
174
|
+
id_token_ciphertext: Column.text().pipe(Column.nullable),
|
|
175
|
+
token_type: Column.text(),
|
|
176
|
+
scopes: Column.text().pipe(Column.nullable),
|
|
177
|
+
expires_at: Column.int().pipe(Column.nullable),
|
|
178
|
+
updated_at: Column.int(),
|
|
179
|
+
revoked_at: Column.int().pipe(Column.nullable),
|
|
180
|
+
revocation_reason: Column.text().pipe(Column.nullable),
|
|
181
|
+
});
|
|
182
|
+
const makeAuthSecurityTimelineTable = (name) => Table.make(name, {
|
|
183
|
+
id: Column.text().pipe(Column.primaryKey),
|
|
184
|
+
user_id: Column.text(),
|
|
185
|
+
type: Column.text(),
|
|
186
|
+
category: Column.text(),
|
|
187
|
+
severity: Column.text(),
|
|
188
|
+
occurred_at: Column.int(),
|
|
189
|
+
summary: Column.text(),
|
|
190
|
+
actor: Column.text().pipe(Column.nullable),
|
|
191
|
+
request: Column.text().pipe(Column.nullable),
|
|
192
|
+
metadata: Column.text().pipe(Column.nullable),
|
|
193
|
+
});
|
|
194
|
+
const authSqliteTablesTypeId = Symbol.for("@effect-auth/core/EffectQbSqliteStorage/AuthSqliteTables");
|
|
195
|
+
const jsonEncode = (value) => value === undefined ? null : JSON.stringify(value);
|
|
196
|
+
const jsonDecode = (value) => {
|
|
197
|
+
if (value === null || value === undefined) {
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
return typeof value === "string" ? JSON.parse(value) : value;
|
|
201
|
+
};
|
|
202
|
+
const optionalUnixMillis = (value) => value === null || value === undefined ? undefined : UnixMillis(Number(value));
|
|
203
|
+
const decodeAmr = (value) => typeof value === "string"
|
|
204
|
+
? JSON.parse(value)
|
|
205
|
+
: value;
|
|
206
|
+
const decodeBoolean = (value) => {
|
|
207
|
+
if (typeof value === "boolean") {
|
|
208
|
+
return value;
|
|
209
|
+
}
|
|
210
|
+
if (typeof value === "number") {
|
|
211
|
+
return value !== 0;
|
|
212
|
+
}
|
|
213
|
+
if (typeof value === "string") {
|
|
214
|
+
return value !== "" && value !== "0" && value !== "false";
|
|
215
|
+
}
|
|
216
|
+
return value !== null && value !== undefined;
|
|
217
|
+
};
|
|
218
|
+
const mutationValues = (value) => value;
|
|
219
|
+
const queryInsert = (table, values) => Query.insert(table, values);
|
|
220
|
+
const queryUpdate = (table, values) => Query.update(table, values);
|
|
221
|
+
const queryEq = (left, right) => Query.eq(left, right);
|
|
222
|
+
const queryGt = (left, right) => Query.gt(left, right);
|
|
223
|
+
const queryLte = (left, right) => Query.lte(left, right);
|
|
224
|
+
const queryIsNull = (value) => Query.isNull(value);
|
|
225
|
+
const queryIn = (value, first, ...rest) => Query.in(value, first, ...rest);
|
|
226
|
+
const executePlan = (executor, plan) => executor.execute(plan);
|
|
227
|
+
const omitUndefined = (record) => Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined));
|
|
228
|
+
const sessionMetadataEnvelopeKey = "__effectAuthSession";
|
|
229
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
230
|
+
const metadataWithReason = (metadata, key, reason) => reason === undefined ? metadata : { ...metadata, [key]: reason };
|
|
231
|
+
const isLoginRiskLevel = (value) => value === "unknown" ||
|
|
232
|
+
value === "low" ||
|
|
233
|
+
value === "medium" ||
|
|
234
|
+
value === "high" ||
|
|
235
|
+
value === "critical";
|
|
236
|
+
const decodeLoginRiskSignal = (value) => {
|
|
237
|
+
const record = isRecord(value) ? value : {};
|
|
238
|
+
const level = isLoginRiskLevel(record.level) ? record.level : undefined;
|
|
239
|
+
return LoginRiskSignal.make({
|
|
240
|
+
type: typeof record.type === "string" ? record.type : "unknown",
|
|
241
|
+
...(level === undefined ? {} : { level }),
|
|
242
|
+
...(isRecord(record.metadata) ? { metadata: record.metadata } : {}),
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
const decodeLoginRiskContext = (value) => {
|
|
246
|
+
const decoded = jsonDecode(value);
|
|
247
|
+
if (!isRecord(decoded)) {
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
return LoginRiskContext.make({
|
|
251
|
+
level: isLoginRiskLevel(decoded.level) ? decoded.level : "unknown",
|
|
252
|
+
signals: Array.isArray(decoded.signals)
|
|
253
|
+
? decoded.signals.map(decodeLoginRiskSignal)
|
|
254
|
+
: [],
|
|
255
|
+
...(isRecord(decoded.metadata) ? { metadata: decoded.metadata } : {}),
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
const encodeLoginRiskSignal = (signal) => omitUndefined({
|
|
259
|
+
type: signal.type,
|
|
260
|
+
level: signal.level,
|
|
261
|
+
metadata: signal.metadata,
|
|
262
|
+
});
|
|
263
|
+
const encodeLoginRiskContext = (risk) => risk === undefined
|
|
264
|
+
? null
|
|
265
|
+
: jsonEncode(omitUndefined({
|
|
266
|
+
level: risk.level,
|
|
267
|
+
signals: risk.signals.map(encodeLoginRiskSignal),
|
|
268
|
+
metadata: risk.metadata,
|
|
269
|
+
}));
|
|
270
|
+
const decodeSessionMetadata = (value) => {
|
|
271
|
+
const decoded = jsonDecode(value);
|
|
272
|
+
const envelope = isRecord(decoded)
|
|
273
|
+
? decoded[sessionMetadataEnvelopeKey]
|
|
274
|
+
: undefined;
|
|
275
|
+
if (!isRecord(envelope) || envelope.version !== 1) {
|
|
276
|
+
return omitUndefined({
|
|
277
|
+
metadata: decoded,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return omitUndefined({
|
|
281
|
+
metadata: envelope.metadata,
|
|
282
|
+
claims: envelope.claims,
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
const encodeSessionMetadata = (row) => {
|
|
286
|
+
if (row.claims === undefined) {
|
|
287
|
+
return jsonEncode(row.metadata);
|
|
288
|
+
}
|
|
289
|
+
return jsonEncode({
|
|
290
|
+
[sessionMetadataEnvelopeKey]: omitUndefined({
|
|
291
|
+
version: 1,
|
|
292
|
+
metadata: row.metadata,
|
|
293
|
+
claims: row.claims,
|
|
294
|
+
}),
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
const decodeDefaultUserRow = (row) => omitUndefined({
|
|
298
|
+
id: UserId(row.id),
|
|
299
|
+
email: Email(row.email),
|
|
300
|
+
emailVerified: decodeBoolean(row.emailVerified),
|
|
301
|
+
createdAt: UnixMillis(Number(row.createdAt)),
|
|
302
|
+
updatedAt: UnixMillis(Number(row.updatedAt)),
|
|
303
|
+
disabledAt: optionalUnixMillis(row.disabledAt),
|
|
304
|
+
metadata: jsonDecode(row.metadata),
|
|
305
|
+
});
|
|
306
|
+
const decodeUserRow = (tables, row) => tables.user.decode === undefined
|
|
307
|
+
? decodeDefaultUserRow(row)
|
|
308
|
+
: tables.user.decode(row);
|
|
309
|
+
const decodeDefaultPasswordCredentialRow = (row) => omitUndefined({
|
|
310
|
+
id: CredentialId(row.id),
|
|
311
|
+
userId: UserId(row.userId),
|
|
312
|
+
passwordHash: row.passwordHash ?? "",
|
|
313
|
+
createdAt: UnixMillis(Number(row.createdAt)),
|
|
314
|
+
updatedAt: UnixMillis(Number(row.updatedAt)),
|
|
315
|
+
revokedAt: optionalUnixMillis(row.revokedAt),
|
|
316
|
+
metadata: jsonDecode(row.metadata),
|
|
317
|
+
});
|
|
318
|
+
const decodePasswordCredentialRow = (tables, row) => tables.credential.decodePassword === undefined
|
|
319
|
+
? decodeDefaultPasswordCredentialRow(row)
|
|
320
|
+
: tables.credential.decodePassword(row);
|
|
321
|
+
const decodeDefaultSessionRow = (row) => {
|
|
322
|
+
const sessionMetadata = decodeSessionMetadata(row.metadata);
|
|
323
|
+
return omitUndefined({
|
|
324
|
+
id: SessionId(row.id),
|
|
325
|
+
userId: UserId(row.userId),
|
|
326
|
+
secretHash: row.secretHash,
|
|
327
|
+
createdAt: UnixMillis(Number(row.createdAt)),
|
|
328
|
+
expiresAt: UnixMillis(Number(row.expiresAt)),
|
|
329
|
+
authTime: UnixMillis(Number(row.authTime)),
|
|
330
|
+
aal: row.aal,
|
|
331
|
+
amr: decodeAmr(row.amr),
|
|
332
|
+
mfaVerifiedAt: optionalUnixMillis(row.mfaVerifiedAt),
|
|
333
|
+
metadata: sessionMetadata.metadata,
|
|
334
|
+
claims: sessionMetadata.claims,
|
|
335
|
+
revokedAt: optionalUnixMillis(row.revokedAt),
|
|
336
|
+
lastSeenAt: optionalUnixMillis(row.lastSeenAt),
|
|
337
|
+
rotatedAt: optionalUnixMillis(row.rotatedAt),
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
const decodeSessionRow = (tables, row) => tables.session.decode === undefined
|
|
341
|
+
? decodeDefaultSessionRow(row)
|
|
342
|
+
: tables.session.decode(row);
|
|
343
|
+
const decodeDefaultVerificationRow = (row) => omitUndefined({
|
|
344
|
+
id: ChallengeId(row.id),
|
|
345
|
+
type: row.type,
|
|
346
|
+
subject: row.subject,
|
|
347
|
+
secretHash: row.secretHash ?? undefined,
|
|
348
|
+
createdAt: UnixMillis(Number(row.createdAt)),
|
|
349
|
+
expiresAt: UnixMillis(Number(row.expiresAt)),
|
|
350
|
+
metadata: jsonDecode(row.metadata),
|
|
351
|
+
consumedAt: optionalUnixMillis(row.consumedAt),
|
|
352
|
+
});
|
|
353
|
+
const decodeVerificationRow = (tables, row) => tables.verification.decode === undefined
|
|
354
|
+
? decodeDefaultVerificationRow(row)
|
|
355
|
+
: tables.verification.decode(row);
|
|
356
|
+
const decodeDefaultLoginApprovalReviewRow = (row) => omitUndefined({
|
|
357
|
+
approvalChallengeId: ChallengeId(row.approvalChallengeId),
|
|
358
|
+
flowId: AuthFlowId(row.flowId),
|
|
359
|
+
userId: UserId(row.userId),
|
|
360
|
+
channel: row.channel,
|
|
361
|
+
reason: row.reason,
|
|
362
|
+
sessionBinding: row.sessionBinding,
|
|
363
|
+
sameDeviceRequired: decodeBoolean(row.sameDeviceRequired),
|
|
364
|
+
status: row.status,
|
|
365
|
+
createdAt: UnixMillis(Number(row.createdAt)),
|
|
366
|
+
expiresAt: UnixMillis(Number(row.expiresAt)),
|
|
367
|
+
reviewedAt: optionalUnixMillis(row.reviewedAt),
|
|
368
|
+
reviewedBy: row.reviewedBy === null
|
|
369
|
+
? undefined
|
|
370
|
+
: row.reviewedBy,
|
|
371
|
+
deniedReason: row.deniedReason === null ? undefined : row.deniedReason,
|
|
372
|
+
risk: decodeLoginRiskContext(row.risk),
|
|
373
|
+
metadata: jsonDecode(row.metadata),
|
|
374
|
+
reviewMetadata: jsonDecode(row.reviewMetadata),
|
|
375
|
+
});
|
|
376
|
+
const decodeLoginApprovalReviewRow = (tables, row) => tables.loginApprovalReview.decode === undefined
|
|
377
|
+
? decodeDefaultLoginApprovalReviewRow(row)
|
|
378
|
+
: tables.loginApprovalReview.decode(row);
|
|
379
|
+
const decodeDefaultTrustedDeviceRow = (row) => omitUndefined({
|
|
380
|
+
userId: UserId(row.userId),
|
|
381
|
+
tokenHash: row.tokenHash,
|
|
382
|
+
createdAt: UnixMillis(Number(row.createdAt)),
|
|
383
|
+
lastSeenAt: UnixMillis(Number(row.lastSeenAt)),
|
|
384
|
+
expiresAt: UnixMillis(Number(row.expiresAt)),
|
|
385
|
+
metadata: jsonDecode(row.metadata),
|
|
386
|
+
});
|
|
387
|
+
const decodeTrustedDeviceRow = (tables, row) => tables.trustedDevice.decode === undefined
|
|
388
|
+
? decodeDefaultTrustedDeviceRow(row)
|
|
389
|
+
: tables.trustedDevice.decode(row);
|
|
390
|
+
const decodePasskeyTransports = (value) => {
|
|
391
|
+
const decoded = jsonDecode(value);
|
|
392
|
+
return Array.isArray(decoded) ? decoded : undefined;
|
|
393
|
+
};
|
|
394
|
+
const decodeDefaultPasskeyCredentialRow = (row) => omitUndefined({
|
|
395
|
+
id: CredentialId(row.id),
|
|
396
|
+
userId: UserId(row.userId),
|
|
397
|
+
credentialId: PasskeyCredentialId(row.credentialId),
|
|
398
|
+
publicKey: row.publicKey,
|
|
399
|
+
signCount: Number(row.signCount),
|
|
400
|
+
transports: decodePasskeyTransports(row.transports),
|
|
401
|
+
backedUp: row.backedUp === null || row.backedUp === undefined
|
|
402
|
+
? undefined
|
|
403
|
+
: decodeBoolean(row.backedUp),
|
|
404
|
+
createdAt: UnixMillis(Number(row.createdAt)),
|
|
405
|
+
lastUsedAt: optionalUnixMillis(row.lastUsedAt),
|
|
406
|
+
revokedAt: optionalUnixMillis(row.revokedAt),
|
|
407
|
+
metadata: jsonDecode(row.metadata),
|
|
408
|
+
});
|
|
409
|
+
const decodePasskeyCredentialRow = (tables, row) => tables.passkeyCredential.decode === undefined
|
|
410
|
+
? decodeDefaultPasskeyCredentialRow(row)
|
|
411
|
+
: tables.passkeyCredential.decode(row);
|
|
412
|
+
const decodeDefaultTotpFactorRow = (row) => omitUndefined({
|
|
413
|
+
id: CredentialId(row.id),
|
|
414
|
+
userId: UserId(row.userId),
|
|
415
|
+
secret: Redacted.make(TotpSecret(row.secret)),
|
|
416
|
+
algorithm: row.algorithm,
|
|
417
|
+
digits: Number(row.digits),
|
|
418
|
+
period: Number(row.period),
|
|
419
|
+
createdAt: UnixMillis(Number(row.createdAt)),
|
|
420
|
+
confirmedAt: optionalUnixMillis(row.confirmedAt),
|
|
421
|
+
lastUsedAt: optionalUnixMillis(row.lastUsedAt),
|
|
422
|
+
revokedAt: optionalUnixMillis(row.revokedAt),
|
|
423
|
+
metadata: jsonDecode(row.metadata),
|
|
424
|
+
});
|
|
425
|
+
const decodeTotpFactorRow = (tables, row) => tables.totpFactor.decode === undefined
|
|
426
|
+
? decodeDefaultTotpFactorRow(row)
|
|
427
|
+
: tables.totpFactor.decode(row);
|
|
428
|
+
const decodeDefaultRecoveryCodeRow = (row) => omitUndefined({
|
|
429
|
+
id: CredentialId(row.id),
|
|
430
|
+
userId: UserId(row.userId),
|
|
431
|
+
codeHash: RecoveryCodeHash(row.codeHash),
|
|
432
|
+
createdAt: UnixMillis(Number(row.createdAt)),
|
|
433
|
+
usedAt: optionalUnixMillis(row.usedAt),
|
|
434
|
+
revokedAt: optionalUnixMillis(row.revokedAt),
|
|
435
|
+
metadata: jsonDecode(row.metadata),
|
|
436
|
+
});
|
|
437
|
+
const decodeRecoveryCodeRow = (tables, row) => tables.recoveryCode.decode === undefined
|
|
438
|
+
? decodeDefaultRecoveryCodeRow(row)
|
|
439
|
+
: tables.recoveryCode.decode(row);
|
|
440
|
+
const decodeStringArray = (value) => {
|
|
441
|
+
const decoded = jsonDecode(value);
|
|
442
|
+
return Array.isArray(decoded) ? decoded.map(String) : [];
|
|
443
|
+
};
|
|
444
|
+
const decodeOptionalStringArray = (value) => {
|
|
445
|
+
const decoded = jsonDecode(value);
|
|
446
|
+
return Array.isArray(decoded) ? decoded.map(String) : undefined;
|
|
447
|
+
};
|
|
448
|
+
const decodeDefaultApiKeyRow = (row) => omitUndefined({
|
|
449
|
+
id: ApiKeyId(row.id),
|
|
450
|
+
userId: UserId(row.userId),
|
|
451
|
+
prefix: ApiKeyPrefix(row.prefix),
|
|
452
|
+
secretHash: ApiKeySecretHash(row.secretHash),
|
|
453
|
+
scopes: decodeStringArray(row.scopes),
|
|
454
|
+
createdAt: UnixMillis(Number(row.createdAt)),
|
|
455
|
+
expiresAt: optionalUnixMillis(row.expiresAt),
|
|
456
|
+
lastUsedAt: optionalUnixMillis(row.lastUsedAt),
|
|
457
|
+
revokedAt: optionalUnixMillis(row.revokedAt),
|
|
458
|
+
metadata: jsonDecode(row.metadata),
|
|
459
|
+
});
|
|
460
|
+
const decodeApiKeyRow = (tables, row) => tables.apiKey.decode === undefined
|
|
461
|
+
? decodeDefaultApiKeyRow(row)
|
|
462
|
+
: tables.apiKey.decode(row);
|
|
463
|
+
const decodeDefaultRefreshTokenRow = (row) => omitUndefined({
|
|
464
|
+
id: RefreshTokenId(row.id),
|
|
465
|
+
familyId: RefreshTokenFamilyId(row.familyId),
|
|
466
|
+
userId: UserId(row.userId),
|
|
467
|
+
secretHash: RefreshTokenSecretHash(row.secretHash),
|
|
468
|
+
createdAt: UnixMillis(Number(row.createdAt)),
|
|
469
|
+
expiresAt: UnixMillis(Number(row.expiresAt)),
|
|
470
|
+
lastUsedAt: optionalUnixMillis(row.lastUsedAt),
|
|
471
|
+
rotatedAt: optionalUnixMillis(row.rotatedAt),
|
|
472
|
+
replacedById: row.replacedById === null ? undefined : RefreshTokenId(row.replacedById),
|
|
473
|
+
revokedAt: optionalUnixMillis(row.revokedAt),
|
|
474
|
+
reuseDetectedAt: optionalUnixMillis(row.reuseDetectedAt),
|
|
475
|
+
metadata: jsonDecode(row.metadata),
|
|
476
|
+
});
|
|
477
|
+
const decodeRefreshTokenRow = (tables, row) => tables.refreshToken.decode === undefined
|
|
478
|
+
? decodeDefaultRefreshTokenRow(row)
|
|
479
|
+
: tables.refreshToken.decode(row);
|
|
480
|
+
const decodeDefaultJwtRevocationRow = (row) => omitUndefined({
|
|
481
|
+
jwtId: row.jwtId,
|
|
482
|
+
revokedAt: UnixMillis(Number(row.revokedAt)),
|
|
483
|
+
expiresAt: optionalUnixMillis(row.expiresAt),
|
|
484
|
+
reason: row.reason ?? undefined,
|
|
485
|
+
});
|
|
486
|
+
const decodeJwtRevocationRow = (tables, row) => tables.jwtRevocation.decode === undefined
|
|
487
|
+
? decodeDefaultJwtRevocationRow(row)
|
|
488
|
+
: tables.jwtRevocation.decode(row);
|
|
489
|
+
const decodeDefaultOAuthAccountRow = (row) => omitUndefined({
|
|
490
|
+
id: OAuthAccountId(row.id),
|
|
491
|
+
providerId: OAuthProviderId(row.providerId),
|
|
492
|
+
providerAccountId: row.providerAccountId,
|
|
493
|
+
userId: UserId(row.userId),
|
|
494
|
+
email: row.email === null ? undefined : Email(row.email),
|
|
495
|
+
emailVerified: row.emailVerified === null || row.emailVerified === undefined
|
|
496
|
+
? undefined
|
|
497
|
+
: decodeBoolean(row.emailVerified),
|
|
498
|
+
createdAt: UnixMillis(Number(row.createdAt)),
|
|
499
|
+
updatedAt: UnixMillis(Number(row.updatedAt)),
|
|
500
|
+
unlinkedAt: optionalUnixMillis(row.unlinkedAt),
|
|
501
|
+
metadata: jsonDecode(row.metadata),
|
|
502
|
+
});
|
|
503
|
+
const decodeOAuthAccountRow = (tables, row) => tables.oauthAccount.decode === undefined
|
|
504
|
+
? decodeDefaultOAuthAccountRow(row)
|
|
505
|
+
: tables.oauthAccount.decode(row);
|
|
506
|
+
const decodeDefaultOAuthProviderTokenVaultRow = (row) => omitUndefined({
|
|
507
|
+
accountId: OAuthAccountId(row.accountId),
|
|
508
|
+
userId: UserId(row.userId),
|
|
509
|
+
providerId: OAuthProviderId(row.providerId),
|
|
510
|
+
providerAccountId: row.providerAccountId,
|
|
511
|
+
accessTokenCiphertext: Redacted.make(row.accessTokenCiphertext),
|
|
512
|
+
refreshTokenCiphertext: row.refreshTokenCiphertext === null
|
|
513
|
+
? undefined
|
|
514
|
+
: Redacted.make(row.refreshTokenCiphertext),
|
|
515
|
+
idTokenCiphertext: row.idTokenCiphertext === null
|
|
516
|
+
? undefined
|
|
517
|
+
: Redacted.make(row.idTokenCiphertext),
|
|
518
|
+
tokenType: row.tokenType,
|
|
519
|
+
scopes: decodeOptionalStringArray(row.scopes),
|
|
520
|
+
expiresAt: optionalUnixMillis(row.expiresAt),
|
|
521
|
+
updatedAt: UnixMillis(Number(row.updatedAt)),
|
|
522
|
+
revokedAt: optionalUnixMillis(row.revokedAt),
|
|
523
|
+
revocationReason: row.revocationReason ?? undefined,
|
|
524
|
+
});
|
|
525
|
+
const decodeOAuthProviderTokenVaultRow = (tables, row) => tables.oauthProviderTokenVault.decode === undefined
|
|
526
|
+
? decodeDefaultOAuthProviderTokenVaultRow(row)
|
|
527
|
+
: tables.oauthProviderTokenVault.decode(row);
|
|
528
|
+
const decodeDefaultSecurityTimelineEvent = (row) => omitUndefined({
|
|
529
|
+
id: SecurityTimelineEventId(row.id),
|
|
530
|
+
userId: UserId(row.userId),
|
|
531
|
+
type: row.type,
|
|
532
|
+
category: row.category,
|
|
533
|
+
severity: row.severity,
|
|
534
|
+
occurredAt: UnixMillis(Number(row.occurredAt)),
|
|
535
|
+
summary: row.summary,
|
|
536
|
+
actor: jsonDecode(row.actor),
|
|
537
|
+
request: jsonDecode(row.request),
|
|
538
|
+
metadata: jsonDecode(row.metadata),
|
|
539
|
+
});
|
|
540
|
+
const decodeSecurityTimelineEvent = (tables, row) => tables.securityTimeline.decode === undefined
|
|
541
|
+
? decodeDefaultSecurityTimelineEvent(row)
|
|
542
|
+
: tables.securityTimeline.decode(row);
|
|
543
|
+
const providerTokenVaultTokens = (record) => omitUndefined({
|
|
544
|
+
accessTokenCiphertext: record.accessTokenCiphertext,
|
|
545
|
+
refreshTokenCiphertext: record.refreshTokenCiphertext,
|
|
546
|
+
idTokenCiphertext: record.idTokenCiphertext,
|
|
547
|
+
tokenType: record.tokenType,
|
|
548
|
+
scopes: record.scopes === undefined ? undefined : [...record.scopes],
|
|
549
|
+
expiresAt: record.expiresAt,
|
|
550
|
+
});
|
|
551
|
+
const userInsert = (row) => ({
|
|
552
|
+
id: row.id,
|
|
553
|
+
email: row.email,
|
|
554
|
+
email_verified: row.emailVerified ? 1 : 0,
|
|
555
|
+
created_at: Number(row.createdAt),
|
|
556
|
+
updated_at: Number(row.updatedAt),
|
|
557
|
+
disabled_at: row.disabledAt === undefined ? null : Number(row.disabledAt),
|
|
558
|
+
metadata: jsonEncode(row.metadata),
|
|
559
|
+
});
|
|
560
|
+
const passwordCredentialInsert = (row) => ({
|
|
561
|
+
id: row.id,
|
|
562
|
+
user_id: row.userId,
|
|
563
|
+
type: "password",
|
|
564
|
+
password_hash: row.passwordHash,
|
|
565
|
+
created_at: Number(row.createdAt),
|
|
566
|
+
updated_at: Number(row.updatedAt),
|
|
567
|
+
revoked_at: row.revokedAt === undefined ? null : Number(row.revokedAt),
|
|
568
|
+
metadata: jsonEncode(row.metadata),
|
|
569
|
+
});
|
|
570
|
+
const passwordCredentialUpdatePassword = (input) => ({
|
|
571
|
+
password_hash: input.passwordHash,
|
|
572
|
+
updated_at: Number(input.updatedAt),
|
|
573
|
+
});
|
|
574
|
+
const sessionInsert = (row) => ({
|
|
575
|
+
id: row.id,
|
|
576
|
+
user_id: row.userId,
|
|
577
|
+
secret_hash: row.secretHash,
|
|
578
|
+
created_at: Number(row.createdAt),
|
|
579
|
+
expires_at: Number(row.expiresAt),
|
|
580
|
+
auth_time: Number(row.authTime),
|
|
581
|
+
aal: row.aal,
|
|
582
|
+
amr: JSON.stringify(row.amr),
|
|
583
|
+
mfa_verified_at: row.mfaVerifiedAt === undefined ? null : Number(row.mfaVerifiedAt),
|
|
584
|
+
metadata: encodeSessionMetadata(row),
|
|
585
|
+
revoked_at: null,
|
|
586
|
+
last_seen_at: null,
|
|
587
|
+
rotated_at: null,
|
|
588
|
+
});
|
|
589
|
+
const verificationInsert = (row) => ({
|
|
590
|
+
id: row.id,
|
|
591
|
+
type: row.type,
|
|
592
|
+
subject: row.subject,
|
|
593
|
+
secret_hash: row.secretHash ?? null,
|
|
594
|
+
created_at: Number(row.createdAt),
|
|
595
|
+
expires_at: Number(row.expiresAt),
|
|
596
|
+
metadata: jsonEncode(row.metadata),
|
|
597
|
+
consumed_at: null,
|
|
598
|
+
});
|
|
599
|
+
const loginApprovalReviewInsert = (row) => ({
|
|
600
|
+
approval_challenge_id: row.approvalChallengeId,
|
|
601
|
+
flow_id: row.flowId,
|
|
602
|
+
user_id: row.userId,
|
|
603
|
+
channel: row.channel,
|
|
604
|
+
reason: row.reason,
|
|
605
|
+
session_binding: row.sessionBinding,
|
|
606
|
+
same_device_required: row.sameDeviceRequired ? 1 : 0,
|
|
607
|
+
status: row.status,
|
|
608
|
+
created_at: Number(row.createdAt),
|
|
609
|
+
expires_at: Number(row.expiresAt),
|
|
610
|
+
reviewed_at: row.reviewedAt === undefined ? null : Number(row.reviewedAt),
|
|
611
|
+
reviewed_by: row.reviewedBy ?? null,
|
|
612
|
+
denied_reason: row.deniedReason ?? null,
|
|
613
|
+
risk: encodeLoginRiskContext(row.risk),
|
|
614
|
+
metadata: jsonEncode(row.metadata),
|
|
615
|
+
review_metadata: jsonEncode(row.reviewMetadata),
|
|
616
|
+
});
|
|
617
|
+
const userMarkEmailVerifiedUpdate = (input) => ({
|
|
618
|
+
email_verified: 1,
|
|
619
|
+
updated_at: Number(input.updatedAt),
|
|
620
|
+
});
|
|
621
|
+
const sessionRefreshUpdate = (input) => omitUndefined({
|
|
622
|
+
expires_at: Number(input.expiresAt),
|
|
623
|
+
last_seen_at: input.lastSeenAt === undefined ? undefined : Number(input.lastSeenAt),
|
|
624
|
+
});
|
|
625
|
+
const sessionRotateUpdate = (input) => omitUndefined({
|
|
626
|
+
secret_hash: input.secretHash,
|
|
627
|
+
rotated_at: Number(input.rotatedAt),
|
|
628
|
+
expires_at: input.expiresAt === undefined ? undefined : Number(input.expiresAt),
|
|
629
|
+
});
|
|
630
|
+
const sessionUpdateClaimsUpdate = (row, input) => omitUndefined({
|
|
631
|
+
aal: input.aal,
|
|
632
|
+
amr: input.amr === undefined ? undefined : JSON.stringify(input.amr),
|
|
633
|
+
mfa_verified_at: input.mfaVerifiedAt === undefined ? undefined : Number(input.mfaVerifiedAt),
|
|
634
|
+
metadata: encodeSessionMetadata({
|
|
635
|
+
...row,
|
|
636
|
+
claims: input.claims ?? row.claims,
|
|
637
|
+
}),
|
|
638
|
+
});
|
|
639
|
+
const sessionRevokeUpdate = (input) => ({
|
|
640
|
+
revoked_at: Number(input.revokedAt),
|
|
641
|
+
});
|
|
642
|
+
const verificationConsumeUpdate = (input) => ({
|
|
643
|
+
consumed_at: Number(input.consumedAt),
|
|
644
|
+
});
|
|
645
|
+
const loginApprovalReviewApproveUpdate = (input) => ({
|
|
646
|
+
status: "approved",
|
|
647
|
+
reviewed_at: Number(input.reviewedAt),
|
|
648
|
+
reviewed_by: input.reviewedBy ?? null,
|
|
649
|
+
review_metadata: jsonEncode(input.metadata),
|
|
650
|
+
});
|
|
651
|
+
const loginApprovalReviewDenyUpdate = (input) => ({
|
|
652
|
+
status: "denied",
|
|
653
|
+
reviewed_at: Number(input.reviewedAt),
|
|
654
|
+
reviewed_by: input.reviewedBy ?? null,
|
|
655
|
+
denied_reason: input.reason ?? null,
|
|
656
|
+
review_metadata: jsonEncode(input.metadata),
|
|
657
|
+
});
|
|
658
|
+
const trustedDeviceInsert = (input, createdAt) => ({
|
|
659
|
+
user_id: input.userId,
|
|
660
|
+
token_hash: input.tokenHash,
|
|
661
|
+
created_at: Number(createdAt),
|
|
662
|
+
last_seen_at: Number(input.now),
|
|
663
|
+
expires_at: Number(input.expiresAt),
|
|
664
|
+
metadata: jsonEncode(input.metadata),
|
|
665
|
+
});
|
|
666
|
+
const trustedDeviceUpdate = (input, existing) => ({
|
|
667
|
+
last_seen_at: Number(input.now),
|
|
668
|
+
expires_at: Number(input.expiresAt),
|
|
669
|
+
metadata: jsonEncode(input.metadata ?? existing.metadata),
|
|
670
|
+
});
|
|
671
|
+
const passkeyCredentialInsert = (row) => ({
|
|
672
|
+
id: row.id,
|
|
673
|
+
user_id: row.userId,
|
|
674
|
+
credential_id: row.credentialId,
|
|
675
|
+
public_key: row.publicKey,
|
|
676
|
+
sign_count: row.signCount,
|
|
677
|
+
transports: jsonEncode(row.transports),
|
|
678
|
+
backed_up: row.backedUp === undefined ? null : row.backedUp ? 1 : 0,
|
|
679
|
+
created_at: Number(row.createdAt),
|
|
680
|
+
last_used_at: row.lastUsedAt === undefined ? null : Number(row.lastUsedAt),
|
|
681
|
+
revoked_at: row.revokedAt === undefined ? null : Number(row.revokedAt),
|
|
682
|
+
metadata: jsonEncode(row.metadata),
|
|
683
|
+
});
|
|
684
|
+
const passkeyCredentialUpdateSignCount = (input) => omitUndefined({
|
|
685
|
+
sign_count: input.signCount,
|
|
686
|
+
last_used_at: Number(input.lastUsedAt),
|
|
687
|
+
metadata: input.metadata === undefined ? undefined : jsonEncode(input.metadata),
|
|
688
|
+
});
|
|
689
|
+
const passkeyCredentialRevoke = (input, row) => ({
|
|
690
|
+
revoked_at: Number(input.revokedAt),
|
|
691
|
+
metadata: jsonEncode(metadataWithReason(row.metadata, "revokeReason", input.reason)),
|
|
692
|
+
});
|
|
693
|
+
const totpFactorInsert = (row) => ({
|
|
694
|
+
id: row.id,
|
|
695
|
+
user_id: row.userId,
|
|
696
|
+
secret: Redacted.value(row.secret),
|
|
697
|
+
algorithm: row.algorithm,
|
|
698
|
+
digits: row.digits,
|
|
699
|
+
period: row.period,
|
|
700
|
+
created_at: Number(row.createdAt),
|
|
701
|
+
confirmed_at: row.confirmedAt === undefined ? null : Number(row.confirmedAt),
|
|
702
|
+
last_used_at: row.lastUsedAt === undefined ? null : Number(row.lastUsedAt),
|
|
703
|
+
revoked_at: row.revokedAt === undefined ? null : Number(row.revokedAt),
|
|
704
|
+
metadata: jsonEncode(row.metadata),
|
|
705
|
+
});
|
|
706
|
+
const totpFactorConfirm = (input) => omitUndefined({
|
|
707
|
+
confirmed_at: Number(input.confirmedAt),
|
|
708
|
+
metadata: input.metadata === undefined ? undefined : jsonEncode(input.metadata),
|
|
709
|
+
});
|
|
710
|
+
const totpFactorMarkUsed = (input) => omitUndefined({
|
|
711
|
+
last_used_at: Number(input.lastUsedAt),
|
|
712
|
+
metadata: input.metadata === undefined ? undefined : jsonEncode(input.metadata),
|
|
713
|
+
});
|
|
714
|
+
const totpFactorRevoke = (input, row) => ({
|
|
715
|
+
revoked_at: Number(input.revokedAt),
|
|
716
|
+
metadata: jsonEncode(metadataWithReason(row.metadata, "revokeReason", input.reason)),
|
|
717
|
+
});
|
|
718
|
+
const recoveryCodeInsert = (row) => ({
|
|
719
|
+
id: row.id,
|
|
720
|
+
user_id: row.userId,
|
|
721
|
+
code_hash: row.codeHash,
|
|
722
|
+
created_at: Number(row.createdAt),
|
|
723
|
+
used_at: row.usedAt === undefined ? null : Number(row.usedAt),
|
|
724
|
+
revoked_at: row.revokedAt === undefined ? null : Number(row.revokedAt),
|
|
725
|
+
metadata: jsonEncode(row.metadata),
|
|
726
|
+
});
|
|
727
|
+
const recoveryCodeMarkUsed = (input) => omitUndefined({
|
|
728
|
+
used_at: Number(input.usedAt),
|
|
729
|
+
metadata: input.metadata === undefined ? undefined : jsonEncode(input.metadata),
|
|
730
|
+
});
|
|
731
|
+
const recoveryCodeRevoke = (input, row) => ({
|
|
732
|
+
revoked_at: Number(input.revokedAt),
|
|
733
|
+
metadata: jsonEncode(metadataWithReason(row.metadata, "revokeReason", input.reason)),
|
|
734
|
+
});
|
|
735
|
+
const apiKeyInsert = (row) => ({
|
|
736
|
+
id: row.id,
|
|
737
|
+
user_id: row.userId,
|
|
738
|
+
prefix: row.prefix,
|
|
739
|
+
secret_hash: row.secretHash,
|
|
740
|
+
scopes: JSON.stringify(row.scopes),
|
|
741
|
+
created_at: Number(row.createdAt),
|
|
742
|
+
expires_at: row.expiresAt === undefined ? null : Number(row.expiresAt),
|
|
743
|
+
last_used_at: row.lastUsedAt === undefined ? null : Number(row.lastUsedAt),
|
|
744
|
+
revoked_at: row.revokedAt === undefined ? null : Number(row.revokedAt),
|
|
745
|
+
metadata: jsonEncode(row.metadata),
|
|
746
|
+
});
|
|
747
|
+
const apiKeyMarkUsed = (input) => omitUndefined({
|
|
748
|
+
last_used_at: Number(input.lastUsedAt),
|
|
749
|
+
metadata: input.metadata === undefined ? undefined : jsonEncode(input.metadata),
|
|
750
|
+
});
|
|
751
|
+
const apiKeyRevoke = (input, row) => ({
|
|
752
|
+
revoked_at: Number(input.revokedAt),
|
|
753
|
+
metadata: jsonEncode(metadataWithReason(row.metadata, "revokeReason", input.reason)),
|
|
754
|
+
});
|
|
755
|
+
const refreshTokenInsert = (row) => ({
|
|
756
|
+
id: row.id,
|
|
757
|
+
family_id: row.familyId,
|
|
758
|
+
user_id: row.userId,
|
|
759
|
+
secret_hash: row.secretHash,
|
|
760
|
+
created_at: Number(row.createdAt),
|
|
761
|
+
expires_at: Number(row.expiresAt),
|
|
762
|
+
last_used_at: row.lastUsedAt === undefined ? null : Number(row.lastUsedAt),
|
|
763
|
+
rotated_at: row.rotatedAt === undefined ? null : Number(row.rotatedAt),
|
|
764
|
+
replaced_by_id: row.replacedById ?? null,
|
|
765
|
+
revoked_at: row.revokedAt === undefined ? null : Number(row.revokedAt),
|
|
766
|
+
reuse_detected_at: row.reuseDetectedAt === undefined ? null : Number(row.reuseDetectedAt),
|
|
767
|
+
metadata: jsonEncode(row.metadata),
|
|
768
|
+
});
|
|
769
|
+
const refreshTokenRotate = (input) => ({
|
|
770
|
+
last_used_at: Number(input.rotatedAt),
|
|
771
|
+
rotated_at: Number(input.rotatedAt),
|
|
772
|
+
replaced_by_id: input.replacement.id,
|
|
773
|
+
});
|
|
774
|
+
const refreshTokenMarkReuseDetected = (input) => ({
|
|
775
|
+
reuse_detected_at: Number(input.reuseDetectedAt),
|
|
776
|
+
});
|
|
777
|
+
const refreshTokenRevoke = (input, row) => ({
|
|
778
|
+
revoked_at: Number(input.revokedAt),
|
|
779
|
+
metadata: jsonEncode(metadataWithReason(row.metadata, "revokeReason", input.reason)),
|
|
780
|
+
});
|
|
781
|
+
const refreshTokenRevokeFamily = (input, row) => ({
|
|
782
|
+
revoked_at: Number(input.revokedAt),
|
|
783
|
+
metadata: jsonEncode(metadataWithReason(row.metadata, "familyRevokeReason", input.reason)),
|
|
784
|
+
});
|
|
785
|
+
const jwtRevocationInsert = (record) => ({
|
|
786
|
+
jwt_id: record.jwtId,
|
|
787
|
+
revoked_at: Number(record.revokedAt),
|
|
788
|
+
expires_at: record.expiresAt === undefined ? null : Number(record.expiresAt),
|
|
789
|
+
reason: record.reason ?? null,
|
|
790
|
+
});
|
|
791
|
+
const oauthAccountInsert = (row) => ({
|
|
792
|
+
id: row.id,
|
|
793
|
+
provider_id: row.providerId,
|
|
794
|
+
provider_account_id: row.providerAccountId,
|
|
795
|
+
user_id: row.userId,
|
|
796
|
+
email: row.email ?? null,
|
|
797
|
+
email_verified: row.emailVerified === undefined ? null : row.emailVerified ? 1 : 0,
|
|
798
|
+
created_at: Number(row.createdAt),
|
|
799
|
+
updated_at: Number(row.updatedAt),
|
|
800
|
+
unlinked_at: row.unlinkedAt === undefined ? null : Number(row.unlinkedAt),
|
|
801
|
+
metadata: jsonEncode(row.metadata),
|
|
802
|
+
});
|
|
803
|
+
const oauthAccountUnlink = (input, row) => ({
|
|
804
|
+
unlinked_at: Number(input.unlinkedAt),
|
|
805
|
+
metadata: jsonEncode(metadataWithReason(row.metadata, "unlinkReason", input.reason)),
|
|
806
|
+
});
|
|
807
|
+
const oauthProviderTokenVaultValues = (row) => ({
|
|
808
|
+
account_id: row.accountId,
|
|
809
|
+
user_id: row.userId,
|
|
810
|
+
provider_id: row.providerId,
|
|
811
|
+
provider_account_id: row.providerAccountId,
|
|
812
|
+
access_token_ciphertext: Redacted.value(row.accessTokenCiphertext),
|
|
813
|
+
refresh_token_ciphertext: row.refreshTokenCiphertext === undefined
|
|
814
|
+
? null
|
|
815
|
+
: Redacted.value(row.refreshTokenCiphertext),
|
|
816
|
+
id_token_ciphertext: row.idTokenCiphertext === undefined ? null : Redacted.value(row.idTokenCiphertext),
|
|
817
|
+
token_type: row.tokenType,
|
|
818
|
+
scopes: jsonEncode(row.scopes),
|
|
819
|
+
expires_at: row.expiresAt === undefined ? null : Number(row.expiresAt),
|
|
820
|
+
updated_at: Number(row.updatedAt),
|
|
821
|
+
revoked_at: row.revokedAt === undefined ? null : Number(row.revokedAt),
|
|
822
|
+
revocation_reason: row.revocationReason ?? null,
|
|
823
|
+
});
|
|
824
|
+
const oauthProviderTokenVaultMarkRevoked = (input) => ({
|
|
825
|
+
revoked_at: Number(input.revokedAt),
|
|
826
|
+
revocation_reason: input.reason,
|
|
827
|
+
});
|
|
828
|
+
const securityTimelineInsert = (event) => ({
|
|
829
|
+
id: event.id,
|
|
830
|
+
user_id: event.userId,
|
|
831
|
+
type: event.type,
|
|
832
|
+
category: event.category,
|
|
833
|
+
severity: event.severity,
|
|
834
|
+
occurred_at: Number(event.occurredAt),
|
|
835
|
+
summary: event.summary,
|
|
836
|
+
actor: jsonEncode(event.actor),
|
|
837
|
+
request: jsonEncode(event.request),
|
|
838
|
+
metadata: jsonEncode(event.metadata),
|
|
839
|
+
});
|
|
840
|
+
const jwtRevocationUpdate = (record) => ({
|
|
841
|
+
revoked_at: Number(record.revokedAt),
|
|
842
|
+
expires_at: record.expiresAt === undefined ? null : Number(record.expiresAt),
|
|
843
|
+
reason: record.reason ?? null,
|
|
844
|
+
});
|
|
845
|
+
const makeInternalAuthSqliteTables = (names = {}) => {
|
|
846
|
+
const user = makeAuthUserTable(names.user ?? "auth_user");
|
|
847
|
+
const credential = makeAuthCredentialTable(names.credential ?? "auth_credential");
|
|
848
|
+
const session = makeAuthSessionTable(names.session ?? "auth_session");
|
|
849
|
+
const verification = makeAuthVerificationTable(names.verification ?? "auth_verification");
|
|
850
|
+
const loginApprovalReview = makeAuthLoginApprovalReviewTable(names.loginApprovalReview ?? "auth_login_approval_review");
|
|
851
|
+
const trustedDevice = makeAuthTrustedDeviceTable(names.trustedDevice ?? "auth_trusted_device");
|
|
852
|
+
const passkeyCredential = makeAuthPasskeyCredentialTable(names.passkeyCredential ?? "auth_passkey_credential");
|
|
853
|
+
const totpFactor = makeAuthTotpFactorTable(names.totpFactor ?? "auth_totp_factor");
|
|
854
|
+
const recoveryCode = makeAuthRecoveryCodeTable(names.recoveryCode ?? "auth_recovery_code");
|
|
855
|
+
const apiKey = makeAuthApiKeyTable(names.apiKey ?? "auth_api_key");
|
|
856
|
+
const refreshToken = makeAuthRefreshTokenTable(names.refreshToken ?? "auth_refresh_token");
|
|
857
|
+
const jwtRevocation = makeAuthJwtRevocationTable(names.jwtRevocation ?? "auth_jwt_revocation");
|
|
858
|
+
const oauthAccount = makeAuthOAuthAccountTable(names.oauthAccount ?? "auth_oauth_account");
|
|
859
|
+
const oauthProviderTokenVault = makeAuthOAuthProviderTokenVaultTable(names.oauthProviderTokenVault ?? "auth_oauth_provider_token_vault");
|
|
860
|
+
const securityTimeline = makeAuthSecurityTimelineTable(names.securityTimeline ?? "auth_security_timeline");
|
|
861
|
+
return {
|
|
862
|
+
user: {
|
|
863
|
+
table: user,
|
|
864
|
+
select: {
|
|
865
|
+
id: user.id,
|
|
866
|
+
email: user.email,
|
|
867
|
+
emailVerified: user.email_verified,
|
|
868
|
+
createdAt: user.created_at,
|
|
869
|
+
updatedAt: user.updated_at,
|
|
870
|
+
disabledAt: user.disabled_at,
|
|
871
|
+
metadata: user.metadata,
|
|
872
|
+
},
|
|
873
|
+
insert: userInsert,
|
|
874
|
+
markEmailVerified: userMarkEmailVerifiedUpdate,
|
|
875
|
+
},
|
|
876
|
+
credential: {
|
|
877
|
+
table: credential,
|
|
878
|
+
select: {
|
|
879
|
+
id: credential.id,
|
|
880
|
+
userId: credential.user_id,
|
|
881
|
+
type: credential.type,
|
|
882
|
+
passwordHash: credential.password_hash,
|
|
883
|
+
createdAt: credential.created_at,
|
|
884
|
+
updatedAt: credential.updated_at,
|
|
885
|
+
revokedAt: credential.revoked_at,
|
|
886
|
+
metadata: credential.metadata,
|
|
887
|
+
},
|
|
888
|
+
insertPassword: passwordCredentialInsert,
|
|
889
|
+
updatePassword: passwordCredentialUpdatePassword,
|
|
890
|
+
},
|
|
891
|
+
session: {
|
|
892
|
+
table: session,
|
|
893
|
+
select: {
|
|
894
|
+
id: session.id,
|
|
895
|
+
userId: session.user_id,
|
|
896
|
+
secretHash: session.secret_hash,
|
|
897
|
+
createdAt: session.created_at,
|
|
898
|
+
expiresAt: session.expires_at,
|
|
899
|
+
authTime: session.auth_time,
|
|
900
|
+
aal: session.aal,
|
|
901
|
+
amr: session.amr,
|
|
902
|
+
mfaVerifiedAt: session.mfa_verified_at,
|
|
903
|
+
metadata: session.metadata,
|
|
904
|
+
revokedAt: session.revoked_at,
|
|
905
|
+
lastSeenAt: session.last_seen_at,
|
|
906
|
+
rotatedAt: session.rotated_at,
|
|
907
|
+
},
|
|
908
|
+
insert: sessionInsert,
|
|
909
|
+
refresh: sessionRefreshUpdate,
|
|
910
|
+
rotate: sessionRotateUpdate,
|
|
911
|
+
updateClaims: sessionUpdateClaimsUpdate,
|
|
912
|
+
revoke: sessionRevokeUpdate,
|
|
913
|
+
},
|
|
914
|
+
verification: {
|
|
915
|
+
table: verification,
|
|
916
|
+
select: {
|
|
917
|
+
id: verification.id,
|
|
918
|
+
type: verification.type,
|
|
919
|
+
subject: verification.subject,
|
|
920
|
+
secretHash: verification.secret_hash,
|
|
921
|
+
createdAt: verification.created_at,
|
|
922
|
+
expiresAt: verification.expires_at,
|
|
923
|
+
metadata: verification.metadata,
|
|
924
|
+
consumedAt: verification.consumed_at,
|
|
925
|
+
},
|
|
926
|
+
insert: verificationInsert,
|
|
927
|
+
consume: verificationConsumeUpdate,
|
|
928
|
+
},
|
|
929
|
+
loginApprovalReview: {
|
|
930
|
+
table: loginApprovalReview,
|
|
931
|
+
select: {
|
|
932
|
+
approvalChallengeId: loginApprovalReview.approval_challenge_id,
|
|
933
|
+
flowId: loginApprovalReview.flow_id,
|
|
934
|
+
userId: loginApprovalReview.user_id,
|
|
935
|
+
channel: loginApprovalReview.channel,
|
|
936
|
+
reason: loginApprovalReview.reason,
|
|
937
|
+
sessionBinding: loginApprovalReview.session_binding,
|
|
938
|
+
sameDeviceRequired: loginApprovalReview.same_device_required,
|
|
939
|
+
status: loginApprovalReview.status,
|
|
940
|
+
createdAt: loginApprovalReview.created_at,
|
|
941
|
+
expiresAt: loginApprovalReview.expires_at,
|
|
942
|
+
reviewedAt: loginApprovalReview.reviewed_at,
|
|
943
|
+
reviewedBy: loginApprovalReview.reviewed_by,
|
|
944
|
+
deniedReason: loginApprovalReview.denied_reason,
|
|
945
|
+
risk: loginApprovalReview.risk,
|
|
946
|
+
metadata: loginApprovalReview.metadata,
|
|
947
|
+
reviewMetadata: loginApprovalReview.review_metadata,
|
|
948
|
+
},
|
|
949
|
+
insertPending: loginApprovalReviewInsert,
|
|
950
|
+
approve: loginApprovalReviewApproveUpdate,
|
|
951
|
+
deny: loginApprovalReviewDenyUpdate,
|
|
952
|
+
},
|
|
953
|
+
trustedDevice: {
|
|
954
|
+
table: trustedDevice,
|
|
955
|
+
select: {
|
|
956
|
+
userId: trustedDevice.user_id,
|
|
957
|
+
tokenHash: trustedDevice.token_hash,
|
|
958
|
+
createdAt: trustedDevice.created_at,
|
|
959
|
+
lastSeenAt: trustedDevice.last_seen_at,
|
|
960
|
+
expiresAt: trustedDevice.expires_at,
|
|
961
|
+
metadata: trustedDevice.metadata,
|
|
962
|
+
},
|
|
963
|
+
insert: trustedDeviceInsert,
|
|
964
|
+
update: trustedDeviceUpdate,
|
|
965
|
+
},
|
|
966
|
+
passkeyCredential: {
|
|
967
|
+
table: passkeyCredential,
|
|
968
|
+
select: {
|
|
969
|
+
id: passkeyCredential.id,
|
|
970
|
+
userId: passkeyCredential.user_id,
|
|
971
|
+
credentialId: passkeyCredential.credential_id,
|
|
972
|
+
publicKey: passkeyCredential.public_key,
|
|
973
|
+
signCount: passkeyCredential.sign_count,
|
|
974
|
+
transports: passkeyCredential.transports,
|
|
975
|
+
backedUp: passkeyCredential.backed_up,
|
|
976
|
+
createdAt: passkeyCredential.created_at,
|
|
977
|
+
lastUsedAt: passkeyCredential.last_used_at,
|
|
978
|
+
revokedAt: passkeyCredential.revoked_at,
|
|
979
|
+
metadata: passkeyCredential.metadata,
|
|
980
|
+
},
|
|
981
|
+
insert: passkeyCredentialInsert,
|
|
982
|
+
updateSignCount: passkeyCredentialUpdateSignCount,
|
|
983
|
+
revoke: passkeyCredentialRevoke,
|
|
984
|
+
},
|
|
985
|
+
totpFactor: {
|
|
986
|
+
table: totpFactor,
|
|
987
|
+
select: {
|
|
988
|
+
id: totpFactor.id,
|
|
989
|
+
userId: totpFactor.user_id,
|
|
990
|
+
secret: totpFactor.secret,
|
|
991
|
+
algorithm: totpFactor.algorithm,
|
|
992
|
+
digits: totpFactor.digits,
|
|
993
|
+
period: totpFactor.period,
|
|
994
|
+
createdAt: totpFactor.created_at,
|
|
995
|
+
confirmedAt: totpFactor.confirmed_at,
|
|
996
|
+
lastUsedAt: totpFactor.last_used_at,
|
|
997
|
+
revokedAt: totpFactor.revoked_at,
|
|
998
|
+
metadata: totpFactor.metadata,
|
|
999
|
+
},
|
|
1000
|
+
insert: totpFactorInsert,
|
|
1001
|
+
confirm: totpFactorConfirm,
|
|
1002
|
+
markUsed: totpFactorMarkUsed,
|
|
1003
|
+
revoke: totpFactorRevoke,
|
|
1004
|
+
},
|
|
1005
|
+
recoveryCode: {
|
|
1006
|
+
table: recoveryCode,
|
|
1007
|
+
select: {
|
|
1008
|
+
id: recoveryCode.id,
|
|
1009
|
+
userId: recoveryCode.user_id,
|
|
1010
|
+
codeHash: recoveryCode.code_hash,
|
|
1011
|
+
createdAt: recoveryCode.created_at,
|
|
1012
|
+
usedAt: recoveryCode.used_at,
|
|
1013
|
+
revokedAt: recoveryCode.revoked_at,
|
|
1014
|
+
metadata: recoveryCode.metadata,
|
|
1015
|
+
},
|
|
1016
|
+
insert: recoveryCodeInsert,
|
|
1017
|
+
markUsed: recoveryCodeMarkUsed,
|
|
1018
|
+
revoke: recoveryCodeRevoke,
|
|
1019
|
+
},
|
|
1020
|
+
apiKey: {
|
|
1021
|
+
table: apiKey,
|
|
1022
|
+
select: {
|
|
1023
|
+
id: apiKey.id,
|
|
1024
|
+
userId: apiKey.user_id,
|
|
1025
|
+
prefix: apiKey.prefix,
|
|
1026
|
+
secretHash: apiKey.secret_hash,
|
|
1027
|
+
scopes: apiKey.scopes,
|
|
1028
|
+
createdAt: apiKey.created_at,
|
|
1029
|
+
expiresAt: apiKey.expires_at,
|
|
1030
|
+
lastUsedAt: apiKey.last_used_at,
|
|
1031
|
+
revokedAt: apiKey.revoked_at,
|
|
1032
|
+
metadata: apiKey.metadata,
|
|
1033
|
+
},
|
|
1034
|
+
insert: apiKeyInsert,
|
|
1035
|
+
markUsed: apiKeyMarkUsed,
|
|
1036
|
+
revoke: apiKeyRevoke,
|
|
1037
|
+
},
|
|
1038
|
+
refreshToken: {
|
|
1039
|
+
table: refreshToken,
|
|
1040
|
+
select: {
|
|
1041
|
+
id: refreshToken.id,
|
|
1042
|
+
familyId: refreshToken.family_id,
|
|
1043
|
+
userId: refreshToken.user_id,
|
|
1044
|
+
secretHash: refreshToken.secret_hash,
|
|
1045
|
+
createdAt: refreshToken.created_at,
|
|
1046
|
+
expiresAt: refreshToken.expires_at,
|
|
1047
|
+
lastUsedAt: refreshToken.last_used_at,
|
|
1048
|
+
rotatedAt: refreshToken.rotated_at,
|
|
1049
|
+
replacedById: refreshToken.replaced_by_id,
|
|
1050
|
+
revokedAt: refreshToken.revoked_at,
|
|
1051
|
+
reuseDetectedAt: refreshToken.reuse_detected_at,
|
|
1052
|
+
metadata: refreshToken.metadata,
|
|
1053
|
+
},
|
|
1054
|
+
insert: refreshTokenInsert,
|
|
1055
|
+
rotate: refreshTokenRotate,
|
|
1056
|
+
markReuseDetected: refreshTokenMarkReuseDetected,
|
|
1057
|
+
revoke: refreshTokenRevoke,
|
|
1058
|
+
revokeFamily: refreshTokenRevokeFamily,
|
|
1059
|
+
},
|
|
1060
|
+
jwtRevocation: {
|
|
1061
|
+
table: jwtRevocation,
|
|
1062
|
+
select: {
|
|
1063
|
+
jwtId: jwtRevocation.jwt_id,
|
|
1064
|
+
revokedAt: jwtRevocation.revoked_at,
|
|
1065
|
+
expiresAt: jwtRevocation.expires_at,
|
|
1066
|
+
reason: jwtRevocation.reason,
|
|
1067
|
+
},
|
|
1068
|
+
insert: jwtRevocationInsert,
|
|
1069
|
+
update: jwtRevocationUpdate,
|
|
1070
|
+
},
|
|
1071
|
+
oauthAccount: {
|
|
1072
|
+
table: oauthAccount,
|
|
1073
|
+
select: {
|
|
1074
|
+
id: oauthAccount.id,
|
|
1075
|
+
providerId: oauthAccount.provider_id,
|
|
1076
|
+
providerAccountId: oauthAccount.provider_account_id,
|
|
1077
|
+
userId: oauthAccount.user_id,
|
|
1078
|
+
email: oauthAccount.email,
|
|
1079
|
+
emailVerified: oauthAccount.email_verified,
|
|
1080
|
+
createdAt: oauthAccount.created_at,
|
|
1081
|
+
updatedAt: oauthAccount.updated_at,
|
|
1082
|
+
unlinkedAt: oauthAccount.unlinked_at,
|
|
1083
|
+
metadata: oauthAccount.metadata,
|
|
1084
|
+
},
|
|
1085
|
+
insert: oauthAccountInsert,
|
|
1086
|
+
unlink: oauthAccountUnlink,
|
|
1087
|
+
},
|
|
1088
|
+
oauthProviderTokenVault: {
|
|
1089
|
+
table: oauthProviderTokenVault,
|
|
1090
|
+
select: {
|
|
1091
|
+
accountId: oauthProviderTokenVault.account_id,
|
|
1092
|
+
userId: oauthProviderTokenVault.user_id,
|
|
1093
|
+
providerId: oauthProviderTokenVault.provider_id,
|
|
1094
|
+
providerAccountId: oauthProviderTokenVault.provider_account_id,
|
|
1095
|
+
accessTokenCiphertext: oauthProviderTokenVault.access_token_ciphertext,
|
|
1096
|
+
refreshTokenCiphertext: oauthProviderTokenVault.refresh_token_ciphertext,
|
|
1097
|
+
idTokenCiphertext: oauthProviderTokenVault.id_token_ciphertext,
|
|
1098
|
+
tokenType: oauthProviderTokenVault.token_type,
|
|
1099
|
+
scopes: oauthProviderTokenVault.scopes,
|
|
1100
|
+
expiresAt: oauthProviderTokenVault.expires_at,
|
|
1101
|
+
updatedAt: oauthProviderTokenVault.updated_at,
|
|
1102
|
+
revokedAt: oauthProviderTokenVault.revoked_at,
|
|
1103
|
+
revocationReason: oauthProviderTokenVault.revocation_reason,
|
|
1104
|
+
},
|
|
1105
|
+
insert: oauthProviderTokenVaultValues,
|
|
1106
|
+
update: oauthProviderTokenVaultValues,
|
|
1107
|
+
markRevoked: oauthProviderTokenVaultMarkRevoked,
|
|
1108
|
+
},
|
|
1109
|
+
securityTimeline: {
|
|
1110
|
+
table: securityTimeline,
|
|
1111
|
+
select: {
|
|
1112
|
+
id: securityTimeline.id,
|
|
1113
|
+
userId: securityTimeline.user_id,
|
|
1114
|
+
type: securityTimeline.type,
|
|
1115
|
+
category: securityTimeline.category,
|
|
1116
|
+
severity: securityTimeline.severity,
|
|
1117
|
+
occurredAt: securityTimeline.occurred_at,
|
|
1118
|
+
summary: securityTimeline.summary,
|
|
1119
|
+
actor: securityTimeline.actor,
|
|
1120
|
+
request: securityTimeline.request,
|
|
1121
|
+
metadata: securityTimeline.metadata,
|
|
1122
|
+
},
|
|
1123
|
+
insert: securityTimelineInsert,
|
|
1124
|
+
},
|
|
1125
|
+
};
|
|
1126
|
+
};
|
|
1127
|
+
const asAuthSqliteTables = (tables) => tables;
|
|
1128
|
+
export const defineEffectQbAuthTables = (tables) => asAuthSqliteTables(tables);
|
|
1129
|
+
export const makeAuthSqliteTables = (names = {}) => asAuthSqliteTables(makeInternalAuthSqliteTables(names));
|
|
1130
|
+
export const authSqliteTables = makeAuthSqliteTables();
|
|
1131
|
+
const selectUserColumns = (tables) => tables.user.select;
|
|
1132
|
+
const selectCredentialColumns = (tables) => tables.credential.select;
|
|
1133
|
+
const selectSessionColumns = (tables) => tables.session.select;
|
|
1134
|
+
const selectVerificationColumns = (tables) => tables.verification.select;
|
|
1135
|
+
const selectLoginApprovalReviewColumns = (tables) => tables.loginApprovalReview.select;
|
|
1136
|
+
const selectTrustedDeviceColumns = (tables) => tables.trustedDevice.select;
|
|
1137
|
+
const selectPasskeyCredentialColumns = (tables) => tables.passkeyCredential.select;
|
|
1138
|
+
const selectTotpFactorColumns = (tables) => tables.totpFactor.select;
|
|
1139
|
+
const selectRecoveryCodeColumns = (tables) => tables.recoveryCode.select;
|
|
1140
|
+
const selectApiKeyColumns = (tables) => tables.apiKey.select;
|
|
1141
|
+
const selectRefreshTokenColumns = (tables) => tables.refreshToken.select;
|
|
1142
|
+
const selectJwtRevocationColumns = (tables) => tables.jwtRevocation.select;
|
|
1143
|
+
const selectOAuthAccountColumns = (tables) => tables.oauthAccount.select;
|
|
1144
|
+
const selectOAuthProviderTokenVaultColumns = (tables) => tables.oauthProviderTokenVault.select;
|
|
1145
|
+
const selectSecurityTimelineColumns = (tables) => tables.securityTimeline.select;
|
|
1146
|
+
const storageError = (entity, operation, cause) => StorageError.fromUnknown(entity, operation, cause);
|
|
1147
|
+
const loginApprovalReviewStoreError = (operation, cause) => new LoginApprovalReviewError({
|
|
1148
|
+
message: `Login approval review ${operation} failed`,
|
|
1149
|
+
cause,
|
|
1150
|
+
});
|
|
1151
|
+
const trustedDeviceStoreError = (operation, cause) => new TrustedDeviceError({
|
|
1152
|
+
operation,
|
|
1153
|
+
message: `Trusted device ${operation} failed`,
|
|
1154
|
+
cause,
|
|
1155
|
+
});
|
|
1156
|
+
const passkeyCredentialStoreError = (operation, cause) => new PasskeyCredentialStoreError({
|
|
1157
|
+
operation,
|
|
1158
|
+
message: `Passkey credential ${operation} failed`,
|
|
1159
|
+
cause,
|
|
1160
|
+
});
|
|
1161
|
+
const totpFactorStoreError = (operation, cause) => new TotpFactorStoreError({
|
|
1162
|
+
operation,
|
|
1163
|
+
message: `TOTP factor ${operation} failed`,
|
|
1164
|
+
cause,
|
|
1165
|
+
});
|
|
1166
|
+
const recoveryCodeStoreError = (operation, cause) => new RecoveryCodeStoreError({
|
|
1167
|
+
operation,
|
|
1168
|
+
message: `Recovery code ${operation} failed`,
|
|
1169
|
+
cause,
|
|
1170
|
+
});
|
|
1171
|
+
const apiKeyStoreError = (operation, cause) => new ApiKeyStoreError({
|
|
1172
|
+
operation,
|
|
1173
|
+
message: `API key ${operation} failed`,
|
|
1174
|
+
cause,
|
|
1175
|
+
});
|
|
1176
|
+
const refreshTokenStoreError = (operation, cause) => new RefreshTokenStoreError({
|
|
1177
|
+
operation,
|
|
1178
|
+
message: `Refresh token ${operation} failed`,
|
|
1179
|
+
cause,
|
|
1180
|
+
});
|
|
1181
|
+
const jwtRevocationStoreError = (operation, cause) => new JwtError({
|
|
1182
|
+
operation: "revocation",
|
|
1183
|
+
message: `JWT revocation ${operation} failed`,
|
|
1184
|
+
cause,
|
|
1185
|
+
});
|
|
1186
|
+
const oauthAccountStoreError = (operation, cause) => new OAuthAccountStoreError({
|
|
1187
|
+
operation,
|
|
1188
|
+
message: `OAuth account ${operation} failed`,
|
|
1189
|
+
cause,
|
|
1190
|
+
});
|
|
1191
|
+
const oauthProviderTokenVaultError = (operation, cause) => new OAuthProviderTokenVaultError({
|
|
1192
|
+
operation,
|
|
1193
|
+
message: `OAuth provider token vault ${operation} failed`,
|
|
1194
|
+
cause,
|
|
1195
|
+
});
|
|
1196
|
+
const securityTimelineStoreError = (operation, cause) => new SecurityTimelineStoreError({
|
|
1197
|
+
operation,
|
|
1198
|
+
message: `Security timeline ${operation} failed`,
|
|
1199
|
+
cause,
|
|
1200
|
+
});
|
|
1201
|
+
const findUserById = (executor, tables, id, operation = "find") => executePlan(executor, Query.select(selectUserColumns(tables)).pipe(Query.from(tables.user.table), Query.where(queryEq(tables.user.select.id, id)))).pipe(Effect.mapError((cause) => storageError("user", operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1202
|
+
? Option.none()
|
|
1203
|
+
: Option.some(decodeUserRow(tables, rows[0]))));
|
|
1204
|
+
const findUserByEmail = (executor, tables, email, operation = "find") => executePlan(executor, Query.select(selectUserColumns(tables)).pipe(Query.from(tables.user.table), Query.where(queryEq(tables.user.select.email, email)))).pipe(Effect.mapError((cause) => storageError("user", operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1205
|
+
? Option.none()
|
|
1206
|
+
: Option.some(decodeUserRow(tables, rows[0]))));
|
|
1207
|
+
const findPasswordCredentialByUserId = (executor, tables, userId, operation = "find") => executePlan(executor, Query.select(selectCredentialColumns(tables)).pipe(Query.from(tables.credential.table), Query.where(queryEq(tables.credential.select.userId, userId)), Query.where(queryEq(tables.credential.select.type, "password")))).pipe(Effect.mapError((cause) => storageError("credential", operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1208
|
+
? Option.none()
|
|
1209
|
+
: Option.some(decodePasswordCredentialRow(tables, rows[0]))));
|
|
1210
|
+
const findJwtRevocation = (executor, tables, jwtId, operation = "find") => executePlan(executor, Query.select(selectJwtRevocationColumns(tables)).pipe(Query.from(tables.jwtRevocation.table), Query.where(queryEq(tables.jwtRevocation.select.jwtId, jwtId)))).pipe(Effect.mapError((cause) => jwtRevocationStoreError(operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1211
|
+
? Option.none()
|
|
1212
|
+
: Option.some(decodeJwtRevocationRow(tables, rows[0]))));
|
|
1213
|
+
const findSessionById = (executor, tables, id, operation = "find") => executePlan(executor, Query.select(selectSessionColumns(tables)).pipe(Query.from(tables.session.table), Query.where(queryEq(tables.session.select.id, id)))).pipe(Effect.mapError((cause) => storageError("session", operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1214
|
+
? Option.none()
|
|
1215
|
+
: Option.some(decodeSessionRow(tables, rows[0]))));
|
|
1216
|
+
const listSessionsByUser = (executor, tables, input, operation = "listByUser") => executePlan(executor, Query.select(selectSessionColumns(tables)).pipe(Query.from(tables.session.table), Query.where(queryEq(tables.session.select.userId, input.userId)))).pipe(Effect.mapError((cause) => storageError("session", operation, cause)), Effect.map((rows) => rows.map((row) => decodeSessionRow(tables, row))));
|
|
1217
|
+
const findVerificationById = (executor, tables, id, operation = "find") => executePlan(executor, Query.select(selectVerificationColumns(tables)).pipe(Query.from(tables.verification.table), Query.where(queryEq(tables.verification.select.id, id)))).pipe(Effect.mapError((cause) => storageError("verification", operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1218
|
+
? Option.none()
|
|
1219
|
+
: Option.some(decodeVerificationRow(tables, rows[0]))));
|
|
1220
|
+
const findLoginApprovalReviewByApprovalChallengeId = (executor, tables, input, operation = "find") => executePlan(executor, Query.select(selectLoginApprovalReviewColumns(tables)).pipe(Query.from(tables.loginApprovalReview.table), Query.where(queryEq(tables.loginApprovalReview.select.approvalChallengeId, input.approvalChallengeId)))).pipe(Effect.mapError((cause) => loginApprovalReviewStoreError(operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1221
|
+
? Option.none()
|
|
1222
|
+
: Option.some(decodeLoginApprovalReviewRow(tables, rows[0]))));
|
|
1223
|
+
const findTrustedDevice = (executor, tables, input, operation = "status") => executePlan(executor, Query.select(selectTrustedDeviceColumns(tables)).pipe(Query.from(tables.trustedDevice.table), Query.where(queryEq(tables.trustedDevice.select.userId, input.userId)), Query.where(queryEq(tables.trustedDevice.select.tokenHash, input.tokenHash)), Query.where(queryGt(tables.trustedDevice.select.expiresAt, Number(input.now))))).pipe(Effect.mapError((cause) => trustedDeviceStoreError(operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1224
|
+
? Option.none()
|
|
1225
|
+
: Option.some(decodeTrustedDeviceRow(tables, rows[0]))));
|
|
1226
|
+
const findTrustedDeviceIncludingExpired = (executor, tables, input) => executePlan(executor, Query.select(selectTrustedDeviceColumns(tables)).pipe(Query.from(tables.trustedDevice.table), Query.where(queryEq(tables.trustedDevice.select.userId, input.userId)), Query.where(queryEq(tables.trustedDevice.select.tokenHash, input.tokenHash)))).pipe(Effect.mapError((cause) => trustedDeviceStoreError("trust", cause)), Effect.map((rows) => rows[0] === undefined
|
|
1227
|
+
? Option.none()
|
|
1228
|
+
: Option.some(decodeTrustedDeviceRow(tables, rows[0]))));
|
|
1229
|
+
const listTrustedDevicesForUser = (executor, tables, input, operation = "list") => executePlan(executor, Query.select(selectTrustedDeviceColumns(tables)).pipe(Query.from(tables.trustedDevice.table), Query.where(queryEq(tables.trustedDevice.select.userId, input.userId)), Query.where(queryGt(tables.trustedDevice.select.expiresAt, Number(input.now))))).pipe(Effect.mapError((cause) => trustedDeviceStoreError(operation, cause)), Effect.map((rows) => filterTrustedDevicesForUser(rows.map((row) => decodeTrustedDeviceRow(tables, row)), input)));
|
|
1230
|
+
const findPasskeyCredentialByCredentialId = (executor, tables, credentialId, operation = "find") => executePlan(executor, Query.select(selectPasskeyCredentialColumns(tables)).pipe(Query.from(tables.passkeyCredential.table), Query.where(queryEq(tables.passkeyCredential.select.credentialId, credentialId)))).pipe(Effect.mapError((cause) => passkeyCredentialStoreError(operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1231
|
+
? Option.none()
|
|
1232
|
+
: Option.some(decodePasskeyCredentialRow(tables, rows[0]))));
|
|
1233
|
+
const findTotpFactorById = (executor, tables, id, operation = "find") => executePlan(executor, Query.select(selectTotpFactorColumns(tables)).pipe(Query.from(tables.totpFactor.table), Query.where(queryEq(tables.totpFactor.select.id, id)))).pipe(Effect.mapError((cause) => totpFactorStoreError(operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1234
|
+
? Option.none()
|
|
1235
|
+
: Option.some(decodeTotpFactorRow(tables, rows[0]))));
|
|
1236
|
+
const findRecoveryCodeById = (executor, tables, id, operation = "find") => executePlan(executor, Query.select(selectRecoveryCodeColumns(tables)).pipe(Query.from(tables.recoveryCode.table), Query.where(queryEq(tables.recoveryCode.select.id, id)))).pipe(Effect.mapError((cause) => recoveryCodeStoreError(operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1237
|
+
? Option.none()
|
|
1238
|
+
: Option.some(decodeRecoveryCodeRow(tables, rows[0]))));
|
|
1239
|
+
const findApiKeyById = (executor, tables, id, operation = "find") => executePlan(executor, Query.select(selectApiKeyColumns(tables)).pipe(Query.from(tables.apiKey.table), Query.where(queryEq(tables.apiKey.select.id, id)))).pipe(Effect.mapError((cause) => apiKeyStoreError(operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1240
|
+
? Option.none()
|
|
1241
|
+
: Option.some(decodeApiKeyRow(tables, rows[0]))));
|
|
1242
|
+
const findApiKeyByPrefix = (executor, tables, prefix, operation = "find") => executePlan(executor, Query.select(selectApiKeyColumns(tables)).pipe(Query.from(tables.apiKey.table), Query.where(queryEq(tables.apiKey.select.prefix, prefix)))).pipe(Effect.mapError((cause) => apiKeyStoreError(operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1243
|
+
? Option.none()
|
|
1244
|
+
: Option.some(decodeApiKeyRow(tables, rows[0]))));
|
|
1245
|
+
const findRefreshTokenById = (executor, tables, id, operation = "find") => executePlan(executor, Query.select(selectRefreshTokenColumns(tables)).pipe(Query.from(tables.refreshToken.table), Query.where(queryEq(tables.refreshToken.select.id, id)))).pipe(Effect.mapError((cause) => refreshTokenStoreError(operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1246
|
+
? Option.none()
|
|
1247
|
+
: Option.some(decodeRefreshTokenRow(tables, rows[0]))));
|
|
1248
|
+
const findRefreshTokenBySecretHash = (executor, tables, hash, operation = "find") => executePlan(executor, Query.select(selectRefreshTokenColumns(tables)).pipe(Query.from(tables.refreshToken.table), Query.where(queryEq(tables.refreshToken.select.secretHash, hash)))).pipe(Effect.mapError((cause) => refreshTokenStoreError(operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1249
|
+
? Option.none()
|
|
1250
|
+
: Option.some(decodeRefreshTokenRow(tables, rows[0]))));
|
|
1251
|
+
const findOAuthAccountById = (executor, tables, id, operation = "find") => executePlan(executor, Query.select(selectOAuthAccountColumns(tables)).pipe(Query.from(tables.oauthAccount.table), Query.where(queryEq(tables.oauthAccount.select.id, id)))).pipe(Effect.mapError((cause) => oauthAccountStoreError(operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1252
|
+
? Option.none()
|
|
1253
|
+
: Option.some(decodeOAuthAccountRow(tables, rows[0]))));
|
|
1254
|
+
const findOAuthAccountByProviderAccount = (executor, tables, input, operation = "find") => {
|
|
1255
|
+
const base = Query.select(selectOAuthAccountColumns(tables)).pipe(Query.from(tables.oauthAccount.table), Query.where(queryEq(tables.oauthAccount.select.providerId, input.providerId)), Query.where(queryEq(tables.oauthAccount.select.providerAccountId, input.providerAccountId)));
|
|
1256
|
+
const query = input.includeUnlinked === true
|
|
1257
|
+
? base
|
|
1258
|
+
: base.pipe(Query.where(queryIsNull(tables.oauthAccount.select.unlinkedAt)));
|
|
1259
|
+
return executePlan(executor, query).pipe(Effect.mapError((cause) => oauthAccountStoreError(operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1260
|
+
? Option.none()
|
|
1261
|
+
: Option.some(decodeOAuthAccountRow(tables, rows[0]))));
|
|
1262
|
+
};
|
|
1263
|
+
const findOAuthProviderTokenVaultRecordByAccountId = (executor, tables, input, operation, includeRevoked = false) => {
|
|
1264
|
+
const base = Query.select(selectOAuthProviderTokenVaultColumns(tables)).pipe(Query.from(tables.oauthProviderTokenVault.table), Query.where(queryEq(tables.oauthProviderTokenVault.select.accountId, input.accountId)));
|
|
1265
|
+
const query = includeRevoked
|
|
1266
|
+
? base
|
|
1267
|
+
: base.pipe(Query.where(queryIsNull(tables.oauthProviderTokenVault.select.revokedAt)));
|
|
1268
|
+
return executePlan(executor, query).pipe(Effect.mapError((cause) => oauthProviderTokenVaultError(operation, cause)), Effect.map((rows) => rows[0] === undefined
|
|
1269
|
+
? Option.none()
|
|
1270
|
+
: Option.some(decodeOAuthProviderTokenVaultRow(tables, rows[0]))));
|
|
1271
|
+
};
|
|
1272
|
+
const listSecurityTimelineByUser = (executor, tables, input, operation = "list") => executePlan(executor, Query.select(selectSecurityTimelineColumns(tables)).pipe(Query.from(tables.securityTimeline.table), Query.where(queryEq(tables.securityTimeline.select.userId, input.userId)))).pipe(Effect.mapError((cause) => securityTimelineStoreError(operation, cause)), Effect.map((rows) => filterSecurityTimelineEvents(rows.map((row) => decodeSecurityTimelineEvent(tables, row)), input)));
|
|
1273
|
+
export const makeEffectQbSqliteUserStore = (executor, options = {}) => {
|
|
1274
|
+
const tables = options.tables ?? authSqliteTables;
|
|
1275
|
+
return UserStore.make({
|
|
1276
|
+
findById: (id) => findUserById(executor, tables, id),
|
|
1277
|
+
findByEmail: (email) => findUserByEmail(executor, tables, email),
|
|
1278
|
+
insert: (row) => executePlan(executor, queryInsert(tables.user.table, mutationValues(tables.user.insert(row)))).pipe(Effect.mapError((cause) => storageError("user", "insert", cause)), Effect.asVoid),
|
|
1279
|
+
markEmailVerified: (input) => executePlan(executor, queryUpdate(tables.user.table, mutationValues(tables.user.markEmailVerified(input))).pipe(Query.where(queryEq(tables.user.select.id, input.userId)), Query.returning(selectUserColumns(tables)))).pipe(Effect.mapError((cause) => storageError("user", "markEmailVerified", cause)), Effect.map((rows) => rows[0] === undefined
|
|
1280
|
+
? Option.none()
|
|
1281
|
+
: Option.some(decodeUserRow(tables, rows[0])))),
|
|
1282
|
+
});
|
|
1283
|
+
};
|
|
1284
|
+
export const makeEffectQbSqliteCredentialStore = (executor, options = {}) => {
|
|
1285
|
+
const tables = options.tables ?? authSqliteTables;
|
|
1286
|
+
return CredentialStore.make({
|
|
1287
|
+
findPasswordByUserId: (userId) => findPasswordCredentialByUserId(executor, tables, userId),
|
|
1288
|
+
insertPassword: (row) => executePlan(executor, queryInsert(tables.credential.table, mutationValues(tables.credential.insertPassword(row)))).pipe(Effect.mapError((cause) => storageError("credential", "insert", cause)), Effect.asVoid),
|
|
1289
|
+
updatePassword: (input) => executePlan(executor, queryUpdate(tables.credential.table, mutationValues(tables.credential.updatePassword(input))).pipe(Query.where(queryEq(tables.credential.select.userId, input.userId)), Query.where(queryEq(tables.credential.select.type, "password")), Query.where(queryIsNull(tables.credential.select.revokedAt)), Query.returning({ id: tables.credential.select.id }))).pipe(Effect.mapError((cause) => storageError("credential", "updatePassword", cause)), Effect.flatMap((rows) => rows[0] === undefined
|
|
1290
|
+
? Effect.succeed(Option.none())
|
|
1291
|
+
: findPasswordCredentialByUserId(executor, tables, input.userId, "updatePassword"))),
|
|
1292
|
+
});
|
|
1293
|
+
};
|
|
1294
|
+
export const makeEffectQbSqliteSessionStore = (executor, options = {}) => {
|
|
1295
|
+
const tables = options.tables ?? authSqliteTables;
|
|
1296
|
+
return SessionStore.make({
|
|
1297
|
+
findById: (id) => findSessionById(executor, tables, id),
|
|
1298
|
+
listByUser: (input) => listSessionsByUser(executor, tables, input),
|
|
1299
|
+
insert: (row) => executePlan(executor, queryInsert(tables.session.table, mutationValues(tables.session.insert(row)))).pipe(Effect.mapError((cause) => storageError("session", "insert", cause)), Effect.asVoid),
|
|
1300
|
+
refresh: (input) => {
|
|
1301
|
+
const query = queryUpdate(tables.session.table, mutationValues(tables.session.refresh(input))).pipe(Query.where(queryEq(tables.session.select.id, input.sessionId)), Query.returning(selectSessionColumns(tables)));
|
|
1302
|
+
return executePlan(executor, query).pipe(Effect.mapError((cause) => storageError("session", "refresh", cause)), Effect.map((rows) => rows[0] === undefined
|
|
1303
|
+
? Option.none()
|
|
1304
|
+
: Option.some(decodeSessionRow(tables, rows[0]))));
|
|
1305
|
+
},
|
|
1306
|
+
rotate: (input) => {
|
|
1307
|
+
const query = queryUpdate(tables.session.table, mutationValues(tables.session.rotate(input))).pipe(Query.where(queryEq(tables.session.select.id, input.sessionId)), Query.returning(selectSessionColumns(tables)));
|
|
1308
|
+
return executePlan(executor, query).pipe(Effect.mapError((cause) => storageError("session", "rotate", cause)), Effect.map((rows) => rows[0] === undefined
|
|
1309
|
+
? Option.none()
|
|
1310
|
+
: Option.some(decodeSessionRow(tables, rows[0]))));
|
|
1311
|
+
},
|
|
1312
|
+
updateClaims: (input) => findSessionById(executor, tables, input.sessionId, "updateClaims").pipe(Effect.flatMap((rowOption) => {
|
|
1313
|
+
if (Option.isNone(rowOption)) {
|
|
1314
|
+
return Effect.succeed(Option.none());
|
|
1315
|
+
}
|
|
1316
|
+
return executePlan(executor, queryUpdate(tables.session.table, mutationValues(tables.session.updateClaims(rowOption.value, input))).pipe(Query.where(queryEq(tables.session.select.id, input.sessionId)), Query.returning(selectSessionColumns(tables)))).pipe(Effect.mapError((cause) => storageError("session", "updateClaims", cause)), Effect.map((rows) => rows[0] === undefined
|
|
1317
|
+
? Option.none()
|
|
1318
|
+
: Option.some(decodeSessionRow(tables, rows[0]))));
|
|
1319
|
+
})),
|
|
1320
|
+
revoke: (input) => executePlan(executor, queryUpdate(tables.session.table, mutationValues(tables.session.revoke(input))).pipe(Query.where(queryEq(tables.session.select.id, input.sessionId)))).pipe(Effect.mapError((cause) => storageError("session", "revoke", cause)), Effect.asVoid),
|
|
1321
|
+
revokeAllForUser: (input) => executePlan(executor, queryUpdate(tables.session.table, mutationValues(tables.session.revoke(input))).pipe(Query.where(queryEq(tables.session.select.userId, input.userId)))).pipe(Effect.mapError((cause) => storageError("session", "revokeAllForUser", cause)), Effect.asVoid),
|
|
1322
|
+
});
|
|
1323
|
+
};
|
|
1324
|
+
export const makeEffectQbSqliteVerificationStore = (executor, options = {}) => {
|
|
1325
|
+
const tables = options.tables ?? authSqliteTables;
|
|
1326
|
+
return VerificationStore.make({
|
|
1327
|
+
findById: (id) => findVerificationById(executor, tables, id),
|
|
1328
|
+
insert: (row) => executePlan(executor, queryInsert(tables.verification.table, mutationValues(tables.verification.insert(row)))).pipe(Effect.mapError((cause) => storageError("verification", "insert", cause)), Effect.asVoid),
|
|
1329
|
+
consume: (input) => {
|
|
1330
|
+
const base = queryUpdate(tables.verification.table, mutationValues(tables.verification.consume(input))).pipe(Query.where(queryEq(tables.verification.select.id, input.id)), Query.where(queryIsNull(tables.verification.select.consumedAt)), Query.where(queryGt(tables.verification.select.expiresAt, Number(input.consumedAt))));
|
|
1331
|
+
const plan = input.type === undefined
|
|
1332
|
+
? base
|
|
1333
|
+
: base.pipe(Query.where(queryEq(tables.verification.select.type, input.type)));
|
|
1334
|
+
return executePlan(executor, plan.pipe(Query.returning({ id: tables.verification.select.id }))).pipe(Effect.mapError((cause) => storageError("verification", "consume", cause)), Effect.flatMap((rows) => rows[0] === undefined
|
|
1335
|
+
? Effect.succeed(Option.none())
|
|
1336
|
+
: findVerificationById(executor, tables, input.id, "consume")));
|
|
1337
|
+
},
|
|
1338
|
+
deleteExpired: (input) => {
|
|
1339
|
+
if (input.limit === undefined) {
|
|
1340
|
+
return executePlan(executor, Query.delete(tables.verification.table).pipe(Query.where(queryLte(tables.verification.select.expiresAt, Number(input.now))), Query.returning({ id: tables.verification.select.id }))).pipe(Effect.mapError((cause) => storageError("verification", "deleteExpired", cause)), Effect.map((rows) => rows.length));
|
|
1341
|
+
}
|
|
1342
|
+
return executePlan(executor, Query.select({ id: tables.verification.select.id }).pipe(Query.from(tables.verification.table), Query.where(queryLte(tables.verification.select.expiresAt, Number(input.now))), Query.limit(input.limit))).pipe(Effect.mapError((cause) => storageError("verification", "deleteExpired", cause)), Effect.flatMap((rows) => {
|
|
1343
|
+
const [first, ...rest] = rows.map((row) => row.id);
|
|
1344
|
+
if (first === undefined) {
|
|
1345
|
+
return Effect.succeed(0);
|
|
1346
|
+
}
|
|
1347
|
+
return executePlan(executor, Query.delete(tables.verification.table).pipe(Query.where(queryIn(tables.verification.select.id, first, ...rest)), Query.returning({ id: tables.verification.select.id }))).pipe(Effect.mapError((cause) => storageError("verification", "deleteExpired", cause)), Effect.map((deleted) => deleted.length));
|
|
1348
|
+
}));
|
|
1349
|
+
},
|
|
1350
|
+
});
|
|
1351
|
+
};
|
|
1352
|
+
export const makeEffectQbSqliteLoginApprovalReviewStore = (executor, options = {}) => {
|
|
1353
|
+
const tables = options.tables ?? authSqliteTables;
|
|
1354
|
+
return LoginApprovalReviewStore.make({
|
|
1355
|
+
insertPending: (input) => executePlan(executor, queryInsert(tables.loginApprovalReview.table, mutationValues(tables.loginApprovalReview.insertPending(input)))).pipe(Effect.mapError((cause) => loginApprovalReviewStoreError("insert", cause)), Effect.as(input)),
|
|
1356
|
+
findByApprovalChallengeId: (input) => findLoginApprovalReviewByApprovalChallengeId(executor, tables, input),
|
|
1357
|
+
approve: (input) => executePlan(executor, queryUpdate(tables.loginApprovalReview.table, mutationValues(tables.loginApprovalReview.approve(input))).pipe(Query.where(queryEq(tables.loginApprovalReview.select.approvalChallengeId, input.approvalChallengeId)), Query.where(queryEq(tables.loginApprovalReview.select.status, "pending")), Query.returning(selectLoginApprovalReviewColumns(tables)))).pipe(Effect.mapError((cause) => loginApprovalReviewStoreError("approve", cause)), Effect.map((rows) => rows[0] === undefined
|
|
1358
|
+
? Option.none()
|
|
1359
|
+
: Option.some(decodeLoginApprovalReviewRow(tables, rows[0])))),
|
|
1360
|
+
deny: (input) => executePlan(executor, queryUpdate(tables.loginApprovalReview.table, mutationValues(tables.loginApprovalReview.deny(input))).pipe(Query.where(queryEq(tables.loginApprovalReview.select.approvalChallengeId, input.approvalChallengeId)), Query.where(queryEq(tables.loginApprovalReview.select.status, "pending")), Query.returning(selectLoginApprovalReviewColumns(tables)))).pipe(Effect.mapError((cause) => loginApprovalReviewStoreError("deny", cause)), Effect.map((rows) => rows[0] === undefined
|
|
1361
|
+
? Option.none()
|
|
1362
|
+
: Option.some(decodeLoginApprovalReviewRow(tables, rows[0])))),
|
|
1363
|
+
});
|
|
1364
|
+
};
|
|
1365
|
+
export const makeEffectQbSqliteTrustedDeviceStore = (executor, options = {}) => {
|
|
1366
|
+
const tables = options.tables ?? authSqliteTables;
|
|
1367
|
+
return TrustedDeviceStore.make({
|
|
1368
|
+
find: (input) => findTrustedDevice(executor, tables, input),
|
|
1369
|
+
listForUser: (input) => listTrustedDevicesForUser(executor, tables, input),
|
|
1370
|
+
revokeForUser: (input) => executePlan(executor, Query.delete(tables.trustedDevice.table).pipe(Query.where(queryEq(tables.trustedDevice.select.userId, input.userId)), Query.where(queryEq(tables.trustedDevice.select.tokenHash, input.tokenHash)))).pipe(Effect.mapError((cause) => trustedDeviceStoreError("revoke", cause)), Effect.asVoid),
|
|
1371
|
+
upsert: (input) => findTrustedDeviceIncludingExpired(executor, tables, input).pipe(Effect.flatMap((existing) => {
|
|
1372
|
+
if (Option.isNone(existing)) {
|
|
1373
|
+
return executePlan(executor, queryInsert(tables.trustedDevice.table, mutationValues(tables.trustedDevice.insert(input, input.now)))).pipe(Effect.mapError((cause) => trustedDeviceStoreError("trust", cause)), Effect.asVoid);
|
|
1374
|
+
}
|
|
1375
|
+
return executePlan(executor, queryUpdate(tables.trustedDevice.table, mutationValues(tables.trustedDevice.update(input, existing.value))).pipe(Query.where(queryEq(tables.trustedDevice.select.userId, input.userId)), Query.where(queryEq(tables.trustedDevice.select.tokenHash, input.tokenHash)))).pipe(Effect.mapError((cause) => trustedDeviceStoreError("trust", cause)), Effect.asVoid);
|
|
1376
|
+
}), Effect.flatMap(() => findTrustedDeviceIncludingExpired(executor, tables, input)), Effect.flatMap((stored) => Option.isSome(stored)
|
|
1377
|
+
? Effect.succeed(stored.value)
|
|
1378
|
+
: Effect.fail(trustedDeviceStoreError("trust", "missing row")))),
|
|
1379
|
+
});
|
|
1380
|
+
};
|
|
1381
|
+
export const makeEffectQbSqlitePasskeyCredentialStore = (executor, options = {}) => {
|
|
1382
|
+
const tables = options.tables ?? authSqliteTables;
|
|
1383
|
+
return PasskeyCredentialStore.make({
|
|
1384
|
+
insert: (row) => executePlan(executor, queryInsert(tables.passkeyCredential.table, mutationValues(tables.passkeyCredential.insert(row)))).pipe(Effect.mapError((cause) => passkeyCredentialStoreError("insert", cause)), Effect.asVoid),
|
|
1385
|
+
findByCredentialId: (credentialId) => findPasskeyCredentialByCredentialId(executor, tables, credentialId),
|
|
1386
|
+
listByUser: (input) => {
|
|
1387
|
+
const base = Query.select(selectPasskeyCredentialColumns(tables)).pipe(Query.from(tables.passkeyCredential.table), Query.where(queryEq(tables.passkeyCredential.select.userId, input.userId)));
|
|
1388
|
+
const query = input.includeRevoked === true
|
|
1389
|
+
? base
|
|
1390
|
+
: base.pipe(Query.where(queryIsNull(tables.passkeyCredential.select.revokedAt)));
|
|
1391
|
+
return executePlan(executor, query).pipe(Effect.mapError((cause) => passkeyCredentialStoreError("list", cause)), Effect.map((rows) => rows.map((row) => decodePasskeyCredentialRow(tables, row))));
|
|
1392
|
+
},
|
|
1393
|
+
updateSignCount: (input) => executePlan(executor, queryUpdate(tables.passkeyCredential.table, mutationValues(tables.passkeyCredential.updateSignCount(input))).pipe(Query.where(queryEq(tables.passkeyCredential.select.credentialId, input.credentialId)), Query.where(queryIsNull(tables.passkeyCredential.select.revokedAt)), Query.returning(selectPasskeyCredentialColumns(tables)))).pipe(Effect.mapError((cause) => passkeyCredentialStoreError("update-sign-count", cause)), Effect.map((rows) => rows[0] === undefined
|
|
1394
|
+
? Option.none()
|
|
1395
|
+
: Option.some(decodePasskeyCredentialRow(tables, rows[0])))),
|
|
1396
|
+
revoke: (input) => findPasskeyCredentialByCredentialId(executor, tables, input.credentialId, "revoke").pipe(Effect.flatMap((row) => {
|
|
1397
|
+
if (Option.isNone(row)) {
|
|
1398
|
+
return Effect.void;
|
|
1399
|
+
}
|
|
1400
|
+
return executePlan(executor, queryUpdate(tables.passkeyCredential.table, mutationValues(tables.passkeyCredential.revoke(input, row.value))).pipe(Query.where(queryEq(tables.passkeyCredential.select.credentialId, input.credentialId)))).pipe(Effect.mapError((cause) => passkeyCredentialStoreError("revoke", cause)), Effect.asVoid);
|
|
1401
|
+
})),
|
|
1402
|
+
});
|
|
1403
|
+
};
|
|
1404
|
+
export const makeEffectQbSqliteTotpFactorStore = (executor, options = {}) => {
|
|
1405
|
+
const tables = options.tables ?? authSqliteTables;
|
|
1406
|
+
return TotpFactorStore.make({
|
|
1407
|
+
insert: (row) => executePlan(executor, queryInsert(tables.totpFactor.table, mutationValues(tables.totpFactor.insert(row)))).pipe(Effect.mapError((cause) => totpFactorStoreError("insert", cause)), Effect.asVoid),
|
|
1408
|
+
findById: (id) => findTotpFactorById(executor, tables, id),
|
|
1409
|
+
listByUser: (input) => {
|
|
1410
|
+
const byUser = Query.select(selectTotpFactorColumns(tables)).pipe(Query.from(tables.totpFactor.table), Query.where(queryEq(tables.totpFactor.select.userId, input.userId)));
|
|
1411
|
+
const byRevoked = input.includeRevoked === true
|
|
1412
|
+
? byUser
|
|
1413
|
+
: byUser.pipe(Query.where(queryIsNull(tables.totpFactor.select.revokedAt)));
|
|
1414
|
+
const query = input.includeUnconfirmed === true
|
|
1415
|
+
? byRevoked
|
|
1416
|
+
: byRevoked.pipe(Query.where(queryGt(tables.totpFactor.select.confirmedAt, 0)));
|
|
1417
|
+
return executePlan(executor, query).pipe(Effect.mapError((cause) => totpFactorStoreError("list", cause)), Effect.map((rows) => rows.map((row) => decodeTotpFactorRow(tables, row))));
|
|
1418
|
+
},
|
|
1419
|
+
confirm: (input) => executePlan(executor, queryUpdate(tables.totpFactor.table, mutationValues(tables.totpFactor.confirm(input))).pipe(Query.where(queryEq(tables.totpFactor.select.id, input.id)), Query.where(queryIsNull(tables.totpFactor.select.revokedAt)), Query.returning(selectTotpFactorColumns(tables)))).pipe(Effect.mapError((cause) => totpFactorStoreError("confirm", cause)), Effect.map((rows) => rows[0] === undefined
|
|
1420
|
+
? Option.none()
|
|
1421
|
+
: Option.some(decodeTotpFactorRow(tables, rows[0])))),
|
|
1422
|
+
markUsed: (input) => executePlan(executor, queryUpdate(tables.totpFactor.table, mutationValues(tables.totpFactor.markUsed(input))).pipe(Query.where(queryEq(tables.totpFactor.select.id, input.id)), Query.where(queryIsNull(tables.totpFactor.select.revokedAt)), Query.where(queryGt(tables.totpFactor.select.confirmedAt, 0)), Query.returning(selectTotpFactorColumns(tables)))).pipe(Effect.mapError((cause) => totpFactorStoreError("mark-used", cause)), Effect.map((rows) => rows[0] === undefined
|
|
1423
|
+
? Option.none()
|
|
1424
|
+
: Option.some(decodeTotpFactorRow(tables, rows[0])))),
|
|
1425
|
+
revoke: (input) => findTotpFactorById(executor, tables, input.id, "revoke").pipe(Effect.flatMap((row) => {
|
|
1426
|
+
if (Option.isNone(row)) {
|
|
1427
|
+
return Effect.void;
|
|
1428
|
+
}
|
|
1429
|
+
return executePlan(executor, queryUpdate(tables.totpFactor.table, mutationValues(tables.totpFactor.revoke(input, row.value))).pipe(Query.where(queryEq(tables.totpFactor.select.id, input.id)))).pipe(Effect.mapError((cause) => totpFactorStoreError("revoke", cause)), Effect.asVoid);
|
|
1430
|
+
})),
|
|
1431
|
+
});
|
|
1432
|
+
};
|
|
1433
|
+
export const makeEffectQbSqliteRecoveryCodeStore = (executor, options = {}) => {
|
|
1434
|
+
const tables = options.tables ?? authSqliteTables;
|
|
1435
|
+
return RecoveryCodeStore.make({
|
|
1436
|
+
insertMany: (rows) => Effect.forEach(rows, (row) => executePlan(executor, queryInsert(tables.recoveryCode.table, mutationValues(tables.recoveryCode.insert(row)))).pipe(Effect.mapError((cause) => recoveryCodeStoreError("insert", cause)), Effect.asVoid), { discard: true }),
|
|
1437
|
+
findById: (id) => findRecoveryCodeById(executor, tables, id),
|
|
1438
|
+
listByUser: (input) => {
|
|
1439
|
+
const byUser = Query.select(selectRecoveryCodeColumns(tables)).pipe(Query.from(tables.recoveryCode.table), Query.where(queryEq(tables.recoveryCode.select.userId, input.userId)));
|
|
1440
|
+
const byUsed = input.includeUsed === true
|
|
1441
|
+
? byUser
|
|
1442
|
+
: byUser.pipe(Query.where(queryIsNull(tables.recoveryCode.select.usedAt)));
|
|
1443
|
+
const query = input.includeRevoked === true
|
|
1444
|
+
? byUsed
|
|
1445
|
+
: byUsed.pipe(Query.where(queryIsNull(tables.recoveryCode.select.revokedAt)));
|
|
1446
|
+
return executePlan(executor, query).pipe(Effect.mapError((cause) => recoveryCodeStoreError("list", cause)), Effect.map((rows) => rows.map((row) => decodeRecoveryCodeRow(tables, row))));
|
|
1447
|
+
},
|
|
1448
|
+
markUsed: (input) => executePlan(executor, queryUpdate(tables.recoveryCode.table, mutationValues(tables.recoveryCode.markUsed(input))).pipe(Query.where(queryEq(tables.recoveryCode.select.id, input.id)), Query.where(queryIsNull(tables.recoveryCode.select.usedAt)), Query.where(queryIsNull(tables.recoveryCode.select.revokedAt)), Query.returning({ id: tables.recoveryCode.select.id }))).pipe(Effect.mapError((cause) => recoveryCodeStoreError("mark-used", cause)), Effect.flatMap((rows) => rows[0] === undefined
|
|
1449
|
+
? Effect.succeed(Option.none())
|
|
1450
|
+
: findRecoveryCodeById(executor, tables, input.id, "mark-used"))),
|
|
1451
|
+
revoke: (input) => findRecoveryCodeById(executor, tables, input.id, "revoke").pipe(Effect.flatMap((row) => {
|
|
1452
|
+
if (Option.isNone(row)) {
|
|
1453
|
+
return Effect.void;
|
|
1454
|
+
}
|
|
1455
|
+
return executePlan(executor, queryUpdate(tables.recoveryCode.table, mutationValues(tables.recoveryCode.revoke(input, row.value))).pipe(Query.where(queryEq(tables.recoveryCode.select.id, input.id)))).pipe(Effect.mapError((cause) => recoveryCodeStoreError("revoke", cause)), Effect.asVoid);
|
|
1456
|
+
})),
|
|
1457
|
+
});
|
|
1458
|
+
};
|
|
1459
|
+
export const makeEffectQbSqliteApiKeyStore = (executor, options = {}) => {
|
|
1460
|
+
const tables = options.tables ?? authSqliteTables;
|
|
1461
|
+
return ApiKeyStore.make({
|
|
1462
|
+
insert: (row) => executePlan(executor, queryInsert(tables.apiKey.table, mutationValues(tables.apiKey.insert(row)))).pipe(Effect.mapError((cause) => apiKeyStoreError("insert", cause)), Effect.asVoid),
|
|
1463
|
+
findById: (id) => findApiKeyById(executor, tables, id),
|
|
1464
|
+
findByPrefix: (prefix) => findApiKeyByPrefix(executor, tables, prefix),
|
|
1465
|
+
listByUser: (input) => {
|
|
1466
|
+
const base = Query.select(selectApiKeyColumns(tables)).pipe(Query.from(tables.apiKey.table), Query.where(queryEq(tables.apiKey.select.userId, input.userId)));
|
|
1467
|
+
const query = input.includeRevoked === true
|
|
1468
|
+
? base
|
|
1469
|
+
: base.pipe(Query.where(queryIsNull(tables.apiKey.select.revokedAt)));
|
|
1470
|
+
return executePlan(executor, query).pipe(Effect.mapError((cause) => apiKeyStoreError("list", cause)), Effect.map((rows) => rows.map((row) => decodeApiKeyRow(tables, row))));
|
|
1471
|
+
},
|
|
1472
|
+
markUsed: (input) => executePlan(executor, queryUpdate(tables.apiKey.table, mutationValues(tables.apiKey.markUsed(input))).pipe(Query.where(queryEq(tables.apiKey.select.id, input.id)), Query.where(queryIsNull(tables.apiKey.select.revokedAt)), Query.returning(selectApiKeyColumns(tables)))).pipe(Effect.mapError((cause) => apiKeyStoreError("mark-used", cause)), Effect.map((rows) => rows[0] === undefined
|
|
1473
|
+
? Option.none()
|
|
1474
|
+
: Option.some(decodeApiKeyRow(tables, rows[0])))),
|
|
1475
|
+
revoke: (input) => findApiKeyById(executor, tables, input.id, "revoke").pipe(Effect.flatMap((row) => {
|
|
1476
|
+
if (Option.isNone(row)) {
|
|
1477
|
+
return Effect.void;
|
|
1478
|
+
}
|
|
1479
|
+
return executePlan(executor, queryUpdate(tables.apiKey.table, mutationValues(tables.apiKey.revoke(input, row.value))).pipe(Query.where(queryEq(tables.apiKey.select.id, input.id)))).pipe(Effect.mapError((cause) => apiKeyStoreError("revoke", cause)), Effect.asVoid);
|
|
1480
|
+
})),
|
|
1481
|
+
});
|
|
1482
|
+
};
|
|
1483
|
+
export const makeEffectQbSqliteRefreshTokenStore = (executor, options = {}) => {
|
|
1484
|
+
const tables = options.tables ?? authSqliteTables;
|
|
1485
|
+
return RefreshTokenStore.make({
|
|
1486
|
+
insert: (row) => executePlan(executor, queryInsert(tables.refreshToken.table, mutationValues(tables.refreshToken.insert(row)))).pipe(Effect.mapError((cause) => refreshTokenStoreError("insert", cause)), Effect.asVoid),
|
|
1487
|
+
findById: (id) => findRefreshTokenById(executor, tables, id),
|
|
1488
|
+
findBySecretHash: (hash) => findRefreshTokenBySecretHash(executor, tables, hash),
|
|
1489
|
+
listByUser: (input) => {
|
|
1490
|
+
const base = Query.select(selectRefreshTokenColumns(tables)).pipe(Query.from(tables.refreshToken.table), Query.where(queryEq(tables.refreshToken.select.userId, input.userId)));
|
|
1491
|
+
const query = input.includeRevoked === true
|
|
1492
|
+
? base
|
|
1493
|
+
: base.pipe(Query.where(queryIsNull(tables.refreshToken.select.revokedAt)));
|
|
1494
|
+
return executePlan(executor, query).pipe(Effect.mapError((cause) => refreshTokenStoreError("list", cause)), Effect.map((rows) => rows.map((row) => decodeRefreshTokenRow(tables, row))));
|
|
1495
|
+
},
|
|
1496
|
+
listByFamily: (input) => {
|
|
1497
|
+
const base = Query.select(selectRefreshTokenColumns(tables)).pipe(Query.from(tables.refreshToken.table), Query.where(queryEq(tables.refreshToken.select.familyId, input.familyId)));
|
|
1498
|
+
const query = input.includeRevoked === true
|
|
1499
|
+
? base
|
|
1500
|
+
: base.pipe(Query.where(queryIsNull(tables.refreshToken.select.revokedAt)));
|
|
1501
|
+
return executePlan(executor, query).pipe(Effect.mapError((cause) => refreshTokenStoreError("list", cause)), Effect.map((rows) => rows.map((row) => decodeRefreshTokenRow(tables, row))));
|
|
1502
|
+
},
|
|
1503
|
+
rotate: (input) => executePlan(executor, queryUpdate(tables.refreshToken.table, mutationValues(tables.refreshToken.rotate(input))).pipe(Query.where(queryEq(tables.refreshToken.select.id, input.id)), Query.where(queryIsNull(tables.refreshToken.select.rotatedAt)), Query.where(queryIsNull(tables.refreshToken.select.revokedAt)), Query.returning({ id: tables.refreshToken.select.id }))).pipe(Effect.mapError((cause) => refreshTokenStoreError("rotate", cause)), Effect.flatMap((rows) => {
|
|
1504
|
+
const [updated] = rows;
|
|
1505
|
+
if (updated === undefined) {
|
|
1506
|
+
return Effect.succeed(Option.none());
|
|
1507
|
+
}
|
|
1508
|
+
return findRefreshTokenById(executor, tables, RefreshTokenId(updated.id), "rotate").pipe(Effect.flatMap((previous) => {
|
|
1509
|
+
if (Option.isNone(previous)) {
|
|
1510
|
+
return Effect.succeed(Option.none());
|
|
1511
|
+
}
|
|
1512
|
+
return executePlan(executor, queryInsert(tables.refreshToken.table, mutationValues(tables.refreshToken.insert(input.replacement)))).pipe(Effect.mapError((cause) => refreshTokenStoreError("rotate", cause)), Effect.as(Option.some({
|
|
1513
|
+
previous: previous.value,
|
|
1514
|
+
replacement: input.replacement,
|
|
1515
|
+
})));
|
|
1516
|
+
}));
|
|
1517
|
+
})),
|
|
1518
|
+
markReuseDetected: (input) => executePlan(executor, queryUpdate(tables.refreshToken.table, mutationValues(tables.refreshToken.markReuseDetected(input))).pipe(Query.where(queryEq(tables.refreshToken.select.id, input.id)), Query.returning(selectRefreshTokenColumns(tables)))).pipe(Effect.mapError((cause) => refreshTokenStoreError("reuse", cause)), Effect.map((rows) => rows[0] === undefined
|
|
1519
|
+
? Option.none()
|
|
1520
|
+
: Option.some(decodeRefreshTokenRow(tables, rows[0])))),
|
|
1521
|
+
revoke: (input) => findRefreshTokenById(executor, tables, input.id, "revoke").pipe(Effect.flatMap((row) => {
|
|
1522
|
+
if (Option.isNone(row)) {
|
|
1523
|
+
return Effect.void;
|
|
1524
|
+
}
|
|
1525
|
+
return executePlan(executor, queryUpdate(tables.refreshToken.table, mutationValues(tables.refreshToken.revoke(input, row.value))).pipe(Query.where(queryEq(tables.refreshToken.select.id, input.id)))).pipe(Effect.mapError((cause) => refreshTokenStoreError("revoke", cause)), Effect.asVoid);
|
|
1526
|
+
})),
|
|
1527
|
+
revokeFamily: (input) => executePlan(executor, Query.select(selectRefreshTokenColumns(tables)).pipe(Query.from(tables.refreshToken.table), Query.where(queryEq(tables.refreshToken.select.familyId, input.familyId)))).pipe(Effect.mapError((cause) => refreshTokenStoreError("revoke", cause)), Effect.flatMap((rows) => Effect.forEach(rows.map((row) => decodeRefreshTokenRow(tables, row)), (row) => executePlan(executor, queryUpdate(tables.refreshToken.table, mutationValues(tables.refreshToken.revokeFamily(input, row))).pipe(Query.where(queryEq(tables.refreshToken.select.id, row.id)))).pipe(Effect.mapError((cause) => refreshTokenStoreError("revoke", cause)), Effect.asVoid), { discard: true }))),
|
|
1528
|
+
});
|
|
1529
|
+
};
|
|
1530
|
+
export const makeEffectQbSqliteJwtRevocationStore = (executor, options = {}) => {
|
|
1531
|
+
const tables = options.tables ?? authSqliteTables;
|
|
1532
|
+
return JwtRevocationStore.make({
|
|
1533
|
+
revoke: (record) => findJwtRevocation(executor, tables, record.jwtId, "revoke").pipe(Effect.flatMap((existing) => {
|
|
1534
|
+
if (Option.isNone(existing)) {
|
|
1535
|
+
return executePlan(executor, queryInsert(tables.jwtRevocation.table, mutationValues(tables.jwtRevocation.insert(record))));
|
|
1536
|
+
}
|
|
1537
|
+
return executePlan(executor, queryUpdate(tables.jwtRevocation.table, mutationValues(tables.jwtRevocation.update(record))).pipe(Query.where(queryEq(tables.jwtRevocation.select.jwtId, record.jwtId))));
|
|
1538
|
+
}), Effect.mapError((cause) => cause instanceof JwtError
|
|
1539
|
+
? cause
|
|
1540
|
+
: jwtRevocationStoreError("revoke", cause)), Effect.asVoid),
|
|
1541
|
+
find: (jwtId) => findJwtRevocation(executor, tables, jwtId),
|
|
1542
|
+
});
|
|
1543
|
+
};
|
|
1544
|
+
export const makeEffectQbSqliteOAuthAccountStore = (executor, options = {}) => {
|
|
1545
|
+
const tables = options.tables ?? authSqliteTables;
|
|
1546
|
+
return OAuthAccountStore.make({
|
|
1547
|
+
insert: (row) => executePlan(executor, queryInsert(tables.oauthAccount.table, mutationValues(tables.oauthAccount.insert(row)))).pipe(Effect.mapError((cause) => oauthAccountStoreError("insert", cause)), Effect.asVoid),
|
|
1548
|
+
findById: (id) => findOAuthAccountById(executor, tables, id),
|
|
1549
|
+
findByProviderAccount: (input) => findOAuthAccountByProviderAccount(executor, tables, input),
|
|
1550
|
+
listByUser: (input) => {
|
|
1551
|
+
const base = Query.select(selectOAuthAccountColumns(tables)).pipe(Query.from(tables.oauthAccount.table), Query.where(queryEq(tables.oauthAccount.select.userId, input.userId)));
|
|
1552
|
+
const query = input.includeUnlinked === true
|
|
1553
|
+
? base
|
|
1554
|
+
: base.pipe(Query.where(queryIsNull(tables.oauthAccount.select.unlinkedAt)));
|
|
1555
|
+
return executePlan(executor, query).pipe(Effect.mapError((cause) => oauthAccountStoreError("list", cause)), Effect.map((rows) => rows.map((row) => decodeOAuthAccountRow(tables, row))));
|
|
1556
|
+
},
|
|
1557
|
+
unlink: (input) => findOAuthAccountByProviderAccount(executor, tables, {
|
|
1558
|
+
providerId: input.providerId,
|
|
1559
|
+
providerAccountId: input.providerAccountId,
|
|
1560
|
+
}, "unlink").pipe(Effect.flatMap((row) => {
|
|
1561
|
+
if (Option.isNone(row)) {
|
|
1562
|
+
return Effect.succeed(Option.none());
|
|
1563
|
+
}
|
|
1564
|
+
return executePlan(executor, queryUpdate(tables.oauthAccount.table, mutationValues(tables.oauthAccount.unlink(input, row.value))).pipe(Query.where(queryEq(tables.oauthAccount.select.id, row.value.id)), Query.returning(selectOAuthAccountColumns(tables)))).pipe(Effect.mapError((cause) => oauthAccountStoreError("unlink", cause)), Effect.map((rows) => rows[0] === undefined
|
|
1565
|
+
? Option.none()
|
|
1566
|
+
: Option.some(decodeOAuthAccountRow(tables, rows[0]))));
|
|
1567
|
+
})),
|
|
1568
|
+
});
|
|
1569
|
+
};
|
|
1570
|
+
export const makeEffectQbSqliteOAuthProviderTokenVault = (executor, options = {}) => {
|
|
1571
|
+
const tables = options.tables ?? authSqliteTables;
|
|
1572
|
+
return OAuthProviderTokenVault.make({
|
|
1573
|
+
upsert: (record) => findOAuthProviderTokenVaultRecordByAccountId(executor, tables, { accountId: record.accountId }, "upsert", true).pipe(Effect.flatMap((existing) => Option.isNone(existing)
|
|
1574
|
+
? executePlan(executor, queryInsert(tables.oauthProviderTokenVault.table, mutationValues(tables.oauthProviderTokenVault.insert(record))))
|
|
1575
|
+
: executePlan(executor, queryUpdate(tables.oauthProviderTokenVault.table, mutationValues(tables.oauthProviderTokenVault.update(record))).pipe(Query.where(queryEq(tables.oauthProviderTokenVault.select.accountId, record.accountId))))), Effect.mapError((cause) => cause instanceof OAuthProviderTokenVaultError
|
|
1576
|
+
? cause
|
|
1577
|
+
: oauthProviderTokenVaultError("upsert", cause)), Effect.asVoid),
|
|
1578
|
+
refreshTokenForAccount: (input) => findOAuthProviderTokenVaultRecordByAccountId(executor, tables, input, "refresh-token").pipe(Effect.map((row) => Option.isNone(row) || row.value.refreshTokenCiphertext === undefined
|
|
1579
|
+
? Option.none()
|
|
1580
|
+
: Option.some(row.value.refreshTokenCiphertext))),
|
|
1581
|
+
tokensForAccount: (input) => findOAuthProviderTokenVaultRecordByAccountId(executor, tables, input, "tokens").pipe(Effect.map((row) => Option.isNone(row)
|
|
1582
|
+
? Option.none()
|
|
1583
|
+
: Option.some(providerTokenVaultTokens(row.value)))),
|
|
1584
|
+
markRevoked: (input) => executePlan(executor, queryUpdate(tables.oauthProviderTokenVault.table, mutationValues(tables.oauthProviderTokenVault.markRevoked(input))).pipe(Query.where(queryEq(tables.oauthProviderTokenVault.select.accountId, input.accountId)), Query.returning({
|
|
1585
|
+
accountId: tables.oauthProviderTokenVault.select.accountId,
|
|
1586
|
+
}))).pipe(Effect.mapError((cause) => oauthProviderTokenVaultError("mark-revoked", cause)), Effect.flatMap((rows) => {
|
|
1587
|
+
const [updated] = rows;
|
|
1588
|
+
if (updated === undefined) {
|
|
1589
|
+
return Effect.succeed(Option.none());
|
|
1590
|
+
}
|
|
1591
|
+
return findOAuthProviderTokenVaultRecordByAccountId(executor, tables, { accountId: OAuthAccountId(updated.accountId) }, "mark-revoked", true);
|
|
1592
|
+
})),
|
|
1593
|
+
});
|
|
1594
|
+
};
|
|
1595
|
+
export const makeEffectQbSqliteSecurityTimelineStore = (executor, options = {}) => {
|
|
1596
|
+
const tables = options.tables ?? authSqliteTables;
|
|
1597
|
+
return SecurityTimelineStore.make({
|
|
1598
|
+
insert: (event) => executePlan(executor, queryInsert(tables.securityTimeline.table, mutationValues(tables.securityTimeline.insert(event)))).pipe(Effect.mapError((cause) => securityTimelineStoreError("insert", cause)), Effect.asVoid),
|
|
1599
|
+
listByUser: (input) => listSecurityTimelineByUser(executor, tables, input),
|
|
1600
|
+
});
|
|
1601
|
+
};
|
|
1602
|
+
export const makeEffectQbSqliteStorage = (executor, options = {}) => ({
|
|
1603
|
+
userStore: makeEffectQbSqliteUserStore(executor, options),
|
|
1604
|
+
credentialStore: makeEffectQbSqliteCredentialStore(executor, options),
|
|
1605
|
+
sessionStore: makeEffectQbSqliteSessionStore(executor, options),
|
|
1606
|
+
verificationStore: makeEffectQbSqliteVerificationStore(executor, options),
|
|
1607
|
+
loginApprovalReviewStore: makeEffectQbSqliteLoginApprovalReviewStore(executor, options),
|
|
1608
|
+
trustedDeviceStore: makeEffectQbSqliteTrustedDeviceStore(executor, options),
|
|
1609
|
+
passkeyCredentialStore: makeEffectQbSqlitePasskeyCredentialStore(executor, options),
|
|
1610
|
+
totpFactorStore: makeEffectQbSqliteTotpFactorStore(executor, options),
|
|
1611
|
+
recoveryCodeStore: makeEffectQbSqliteRecoveryCodeStore(executor, options),
|
|
1612
|
+
apiKeyStore: makeEffectQbSqliteApiKeyStore(executor, options),
|
|
1613
|
+
refreshTokenStore: makeEffectQbSqliteRefreshTokenStore(executor, options),
|
|
1614
|
+
jwtRevocationStore: makeEffectQbSqliteJwtRevocationStore(executor, options),
|
|
1615
|
+
oauthAccountStore: makeEffectQbSqliteOAuthAccountStore(executor, options),
|
|
1616
|
+
oauthProviderTokenVault: makeEffectQbSqliteOAuthProviderTokenVault(executor, options),
|
|
1617
|
+
securityTimelineStore: makeEffectQbSqliteSecurityTimelineStore(executor, options),
|
|
1618
|
+
});
|
|
1619
|
+
export const EffectQbSqliteAuthStorageLive = (executor, options = {}) => Layer.mergeAll(Layer.succeed(UserStore)(makeEffectQbSqliteUserStore(executor, options)), Layer.succeed(CredentialStore)(makeEffectQbSqliteCredentialStore(executor, options)), Layer.succeed(SessionStore)(makeEffectQbSqliteSessionStore(executor, options)), Layer.succeed(VerificationStore)(makeEffectQbSqliteVerificationStore(executor, options)), Layer.succeed(LoginApprovalReviewStore)(makeEffectQbSqliteLoginApprovalReviewStore(executor, options)), Layer.succeed(TrustedDeviceStore)(makeEffectQbSqliteTrustedDeviceStore(executor, options)), Layer.succeed(PasskeyCredentialStore)(makeEffectQbSqlitePasskeyCredentialStore(executor, options)), Layer.succeed(TotpFactorStore)(makeEffectQbSqliteTotpFactorStore(executor, options)), Layer.succeed(RecoveryCodeStore)(makeEffectQbSqliteRecoveryCodeStore(executor, options)), Layer.succeed(ApiKeyStore)(makeEffectQbSqliteApiKeyStore(executor, options)), Layer.succeed(RefreshTokenStore)(makeEffectQbSqliteRefreshTokenStore(executor, options)), Layer.succeed(JwtRevocationStore)(makeEffectQbSqliteJwtRevocationStore(executor, options)), Layer.succeed(OAuthAccountStore)(makeEffectQbSqliteOAuthAccountStore(executor, options)), Layer.succeed(OAuthProviderTokenVault)(makeEffectQbSqliteOAuthProviderTokenVault(executor, options)), Layer.succeed(SecurityTimelineStore)(makeEffectQbSqliteSecurityTimelineStore(executor, options)));
|
|
1620
|
+
export const makeD1EffectQbSqliteExecutor = (database) => Executor.make({
|
|
1621
|
+
driver: Executor.driver((query) => Effect.tryPromise({
|
|
1622
|
+
try: () => database
|
|
1623
|
+
.prepare(query.sql)
|
|
1624
|
+
.bind(...query.params)
|
|
1625
|
+
.all(),
|
|
1626
|
+
catch: (cause) => new D1EffectQbError({ message: "D1 query failed", cause }),
|
|
1627
|
+
}).pipe(Effect.flatMap((result) => {
|
|
1628
|
+
if (result.success === false || result.error !== undefined) {
|
|
1629
|
+
return Effect.fail(new D1EffectQbError({
|
|
1630
|
+
message: result.error ?? "D1 query failed",
|
|
1631
|
+
}));
|
|
1632
|
+
}
|
|
1633
|
+
return Effect.succeed([...(result.results ?? [])]);
|
|
1634
|
+
}))),
|
|
1635
|
+
});
|
|
1636
|
+
export const D1EffectQbSqliteAuthStorageLive = (database, options = {}) => EffectQbSqliteAuthStorageLive(makeD1EffectQbSqliteExecutor(database), options);
|
|
1637
|
+
//# sourceMappingURL=EffectQbSqliteStorage.js.map
|