@parsrun/auth 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -0
- package/dist/adapters/hono.d.ts +9 -0
- package/dist/adapters/hono.js +6 -0
- package/dist/adapters/hono.js.map +1 -0
- package/dist/adapters/index.d.ts +9 -0
- package/dist/adapters/index.js +7 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/authorization-By1Xp8Za.d.ts +213 -0
- package/dist/base-BKyR8rcE.d.ts +646 -0
- package/dist/chunk-42MGHABB.js +263 -0
- package/dist/chunk-42MGHABB.js.map +1 -0
- package/dist/chunk-7GOBAL4G.js +3 -0
- package/dist/chunk-7GOBAL4G.js.map +1 -0
- package/dist/chunk-G5I3T73A.js +152 -0
- package/dist/chunk-G5I3T73A.js.map +1 -0
- package/dist/chunk-IB4WUQDZ.js +410 -0
- package/dist/chunk-IB4WUQDZ.js.map +1 -0
- package/dist/chunk-MOG4Y6I7.js +415 -0
- package/dist/chunk-MOG4Y6I7.js.map +1 -0
- package/dist/chunk-NK4TJV2W.js +295 -0
- package/dist/chunk-NK4TJV2W.js.map +1 -0
- package/dist/chunk-RHNVRCF3.js +838 -0
- package/dist/chunk-RHNVRCF3.js.map +1 -0
- package/dist/chunk-YTCPXJR5.js +570 -0
- package/dist/chunk-YTCPXJR5.js.map +1 -0
- package/dist/cloudflare-kv-L64CZKDK.js +105 -0
- package/dist/cloudflare-kv-L64CZKDK.js.map +1 -0
- package/dist/deno-kv-F55HKKP6.js +111 -0
- package/dist/deno-kv-F55HKKP6.js.map +1 -0
- package/dist/index-C3kz9XqE.d.ts +226 -0
- package/dist/index-DOGcetyD.d.ts +1041 -0
- package/dist/index.d.ts +1579 -0
- package/dist/index.js +4294 -0
- package/dist/index.js.map +1 -0
- package/dist/jwt-manager-CH8H0kmm.d.ts +182 -0
- package/dist/providers/index.d.ts +90 -0
- package/dist/providers/index.js +3 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/otp/index.d.ts +3 -0
- package/dist/providers/otp/index.js +4 -0
- package/dist/providers/otp/index.js.map +1 -0
- package/dist/redis-5TIS6XCA.js +121 -0
- package/dist/redis-5TIS6XCA.js.map +1 -0
- package/dist/security/index.d.ts +301 -0
- package/dist/security/index.js +5 -0
- package/dist/security/index.js.map +1 -0
- package/dist/session/index.d.ts +117 -0
- package/dist/session/index.js +4 -0
- package/dist/session/index.js.map +1 -0
- package/dist/storage/index.d.ts +97 -0
- package/dist/storage/index.js +3 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/types-DSjafxJ4.d.ts +193 -0
- package/package.json +102 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1579 @@
|
|
|
1
|
+
import { A as AuthProvider, b as AuthInput, c as AuthResult, a as ProviderInfo, T as TwoFactorProvider, e as TwoFactorSetupResult, h as AuthAdapter, i as ParsAuthConfig } from './base-BKyR8rcE.js';
|
|
2
|
+
export { t as AdapterAuthMethod, v as AdapterMembership, s as AdapterSession, u as AdapterTenant, r as AdapterUser, q as AuthCallbacks, C as CookieConfig, y as CreateAuthMethodInput, z as CreateMembershipInput, x as CreateSessionInput, w as CreateUserInput, j as CsrfConfig, J as JwtConfig, M as MagicLinkConfig, O as OAuthProvider, o as OAuthProviderConfig, f as OAuthUserInfo, g as OtpConfig, n as PasswordConfig, P as ProviderType, p as SecurityConfig, S as SessionConfig, k as TenantConfig, l as TenantResolutionStrategy, m as TotpConfig, V as VerifyInput, d as VerifyResult, W as WebAuthnConfig, D as defaultConfig, E as mergeConfig, F as validateConfig } from './base-BKyR8rcE.js';
|
|
3
|
+
import { P as ParsAuthEngine } from './index-DOGcetyD.js';
|
|
4
|
+
export { t as AcceptInvitationInput, u as AcceptInvitationResult, X as AdapterAuthContext, k as AddMemberInput, A as AuthContext, Z as AuthResponse, Q as AuthVariables, Y as CookieOptions, C as CreateTenantInput, W as HonoAdapterConfig, p as InvitationConfig, q as InvitationRecord, I as InvitationService, v as InvitationStatusResult, M as MultiStrategyTenantResolver, R as RefreshTokenResult, r as SendInvitationInput, s as SendInvitationResult, d as SessionInfo, S as SignInInput, a as SignInResult, b as SignUpInput, c as SignUpResult, i as TenantManager, h as TenantResolutionResult, T as TenantResolver, g as TenantResolverConfig, m as TenantWithMembers, l as UpdateMemberInput, U as UpdateTenantInput, n as UserTenantMembership, V as VerifyTokenResult, B as createAuthCookies, w as createAuthMiddleware, y as createAuthRoutes, z as createHonoAuth, o as createInvitationService, D as createLogoutCookies, f as createMultiStrategyResolver, x as createOptionalAuthMiddleware, j as createTenantManager, e as createTenantResolver, K as requireAdmin, N as requireAll, O as requireAny, G as requireAnyPermission, L as requireOwnerOrPermission, F as requirePermission, E as requireRole, H as requireTenant, J as requireTenantAccess } from './index-DOGcetyD.js';
|
|
5
|
+
export { ProviderRegistry } from './providers/index.js';
|
|
6
|
+
export { e as OTPConfig, a as OTPManager, O as OTPProvider, f as OTPRecord, g as RateLimitCheck, R as RequestOTPInput, d as RequestOTPResult, S as StoreOTPResult, V as VerifyOTPResult, b as createOTPManager, c as createOTPProvider } from './index-C3kz9XqE.js';
|
|
7
|
+
import { K as KVStorage } from './types-DSjafxJ4.js';
|
|
8
|
+
export { C as CloudflareKVConfig, D as DenoKVConfig, M as MemoryConfig, R as RedisConfig, S as StorageConfig, a as StorageType } from './types-DSjafxJ4.js';
|
|
9
|
+
export { a as JwtError, J as JwtManager, b as JwtManagerConfig, d as JwtPayload, K as KeyRotationResult, T as TokenPair, c as createJwtManager, e as extractBearerToken, p as parseDuration } from './jwt-manager-CH8H0kmm.js';
|
|
10
|
+
export { BlocklistConfig, SessionBlocklist, TokenBlocklist, createSessionBlocklist, createTokenBlocklist } from './session/index.js';
|
|
11
|
+
export { MemoryStorage, StorageKeys, createMemoryStorage, createStorage, createStorageSync } from './storage/index.js';
|
|
12
|
+
export { CsrfManager, CsrfConfig as CsrfManagerConfig, CsrfTokenPair, CsrfUtils, DefaultLockoutConfig, LockoutConfig, LockoutManager, LockoutStatus, RateLimitConfig, RateLimitPresets, RateLimitResult, RateLimiter, createCsrfManager, createLockoutManager, createRateLimiter } from './security/index.js';
|
|
13
|
+
export { b as AuthorizationContext, A as AuthorizationGuard, e as AuthorizationRequirements, d as AuthorizationResult, f as PermissionPattern, P as Permissions, R as Roles, T as TenantMembershipInfo, a as authorize, c as createAuthorizationGuard } from './authorization-By1Xp8Za.js';
|
|
14
|
+
import 'hono/types';
|
|
15
|
+
import 'hono';
|
|
16
|
+
import 'jose';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* OAuth Types
|
|
20
|
+
*/
|
|
21
|
+
interface OAuthUserInfo {
|
|
22
|
+
/** Provider-specific user ID */
|
|
23
|
+
id: string;
|
|
24
|
+
/** User email */
|
|
25
|
+
email: string;
|
|
26
|
+
/** Display name */
|
|
27
|
+
name?: string;
|
|
28
|
+
/** Avatar URL */
|
|
29
|
+
avatarUrl?: string;
|
|
30
|
+
/** Whether email is verified */
|
|
31
|
+
emailVerified: boolean;
|
|
32
|
+
/** Raw provider response */
|
|
33
|
+
raw: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
interface OAuthTokens {
|
|
36
|
+
accessToken: string;
|
|
37
|
+
refreshToken?: string;
|
|
38
|
+
expiresIn?: number;
|
|
39
|
+
idToken?: string;
|
|
40
|
+
tokenType?: string;
|
|
41
|
+
scope?: string;
|
|
42
|
+
}
|
|
43
|
+
interface OAuthProviderConfig {
|
|
44
|
+
clientId: string;
|
|
45
|
+
clientSecret: string;
|
|
46
|
+
redirectUri: string;
|
|
47
|
+
scopes?: string[];
|
|
48
|
+
}
|
|
49
|
+
interface GoogleConfig extends OAuthProviderConfig {
|
|
50
|
+
}
|
|
51
|
+
interface GitHubConfig extends OAuthProviderConfig {
|
|
52
|
+
}
|
|
53
|
+
interface MicrosoftConfig extends OAuthProviderConfig {
|
|
54
|
+
tenantId?: string;
|
|
55
|
+
}
|
|
56
|
+
interface AppleConfig {
|
|
57
|
+
clientId: string;
|
|
58
|
+
teamId: string;
|
|
59
|
+
keyId: string;
|
|
60
|
+
privateKey: string;
|
|
61
|
+
redirectUri: string;
|
|
62
|
+
scopes?: string[];
|
|
63
|
+
}
|
|
64
|
+
interface OAuthProvider {
|
|
65
|
+
readonly name: string;
|
|
66
|
+
getAuthorizationUrl(state: string, codeChallenge?: string): Promise<string>;
|
|
67
|
+
exchangeCode(code: string, codeVerifier?: string): Promise<OAuthTokens>;
|
|
68
|
+
getUserInfo(accessToken: string): Promise<OAuthUserInfo>;
|
|
69
|
+
/**
|
|
70
|
+
* Refresh access token using refresh token
|
|
71
|
+
* Not all providers support refresh tokens
|
|
72
|
+
*/
|
|
73
|
+
refreshToken?(refreshToken: string): Promise<OAuthTokens>;
|
|
74
|
+
}
|
|
75
|
+
type OAuthProviderName = 'google' | 'github' | 'microsoft' | 'apple';
|
|
76
|
+
interface OAuthState {
|
|
77
|
+
state: string;
|
|
78
|
+
provider: OAuthProviderName;
|
|
79
|
+
codeVerifier?: string;
|
|
80
|
+
tenantId?: string;
|
|
81
|
+
redirectUrl?: string;
|
|
82
|
+
expiresAt: Date;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Google OAuth Provider
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
declare class GoogleProvider implements OAuthProvider {
|
|
90
|
+
readonly name = "google";
|
|
91
|
+
private config;
|
|
92
|
+
constructor(config: GoogleConfig);
|
|
93
|
+
getAuthorizationUrl(state: string, codeChallenge?: string): Promise<string>;
|
|
94
|
+
exchangeCode(code: string, codeVerifier?: string): Promise<OAuthTokens>;
|
|
95
|
+
getUserInfo(accessToken: string): Promise<OAuthUserInfo>;
|
|
96
|
+
refreshToken(refreshToken: string): Promise<OAuthTokens>;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* GitHub OAuth Provider
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
declare class GitHubProvider implements OAuthProvider {
|
|
104
|
+
readonly name = "github";
|
|
105
|
+
private config;
|
|
106
|
+
constructor(config: GitHubConfig);
|
|
107
|
+
getAuthorizationUrl(state: string, _codeChallenge?: string): Promise<string>;
|
|
108
|
+
exchangeCode(code: string, _codeVerifier?: string): Promise<OAuthTokens>;
|
|
109
|
+
getUserInfo(accessToken: string): Promise<OAuthUserInfo>;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Microsoft OAuth Provider
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
declare class MicrosoftProvider implements OAuthProvider {
|
|
117
|
+
readonly name = "microsoft";
|
|
118
|
+
private config;
|
|
119
|
+
private baseUrl;
|
|
120
|
+
constructor(config: MicrosoftConfig);
|
|
121
|
+
getAuthorizationUrl(state: string, codeChallenge?: string): Promise<string>;
|
|
122
|
+
exchangeCode(code: string, codeVerifier?: string): Promise<OAuthTokens>;
|
|
123
|
+
getUserInfo(accessToken: string): Promise<OAuthUserInfo>;
|
|
124
|
+
refreshToken(refreshToken: string): Promise<OAuthTokens>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Apple OAuth Provider
|
|
129
|
+
* Uses Sign in with Apple
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
declare class AppleProvider implements OAuthProvider {
|
|
133
|
+
readonly name = "apple";
|
|
134
|
+
private config;
|
|
135
|
+
constructor(config: AppleConfig);
|
|
136
|
+
getAuthorizationUrl(state: string, _codeChallenge?: string): Promise<string>;
|
|
137
|
+
exchangeCode(code: string, _codeVerifier?: string): Promise<OAuthTokens>;
|
|
138
|
+
getUserInfo(accessToken: string): Promise<OAuthUserInfo>;
|
|
139
|
+
/**
|
|
140
|
+
* Parse user info from id_token and form post data
|
|
141
|
+
* Apple sends user info only on first authorization
|
|
142
|
+
*/
|
|
143
|
+
parseUserFromCallback(idToken: string, userData?: {
|
|
144
|
+
name?: {
|
|
145
|
+
firstName?: string;
|
|
146
|
+
lastName?: string;
|
|
147
|
+
};
|
|
148
|
+
email?: string;
|
|
149
|
+
}): OAuthUserInfo;
|
|
150
|
+
/**
|
|
151
|
+
* Generate client secret JWT for Apple
|
|
152
|
+
* Apple requires a JWT signed with your private key
|
|
153
|
+
*/
|
|
154
|
+
private generateClientSecret;
|
|
155
|
+
private pemToArrayBuffer;
|
|
156
|
+
private base64UrlEncode;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* OAuth Provider
|
|
161
|
+
* Manages OAuth2 authentication flows with PKCE support
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* OAuth configuration
|
|
166
|
+
*/
|
|
167
|
+
interface OAuthConfig {
|
|
168
|
+
google?: GoogleConfig;
|
|
169
|
+
github?: GitHubConfig;
|
|
170
|
+
microsoft?: MicrosoftConfig;
|
|
171
|
+
apple?: AppleConfig;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* OAuth flow result
|
|
175
|
+
*/
|
|
176
|
+
interface OAuthFlowResult {
|
|
177
|
+
authorizationUrl: string;
|
|
178
|
+
state: string;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* OAuth callback result
|
|
182
|
+
*/
|
|
183
|
+
interface OAuthCallbackResult {
|
|
184
|
+
userInfo: OAuthUserInfo;
|
|
185
|
+
tokens: OAuthTokens;
|
|
186
|
+
tenantId?: string;
|
|
187
|
+
redirectUrl?: string;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Generate PKCE code verifier and challenge
|
|
191
|
+
*/
|
|
192
|
+
declare function generatePKCE(): Promise<{
|
|
193
|
+
codeVerifier: string;
|
|
194
|
+
codeChallenge: string;
|
|
195
|
+
}>;
|
|
196
|
+
/**
|
|
197
|
+
* Generate secure random state
|
|
198
|
+
*/
|
|
199
|
+
declare function generateState(): string;
|
|
200
|
+
/**
|
|
201
|
+
* OAuth Manager
|
|
202
|
+
* Handles OAuth flows with state management via KVStorage
|
|
203
|
+
*/
|
|
204
|
+
declare class OAuthManager {
|
|
205
|
+
private storage;
|
|
206
|
+
private providers;
|
|
207
|
+
private stateExpirySeconds;
|
|
208
|
+
constructor(storage: KVStorage, config: OAuthConfig, options?: {
|
|
209
|
+
stateExpirySeconds?: number;
|
|
210
|
+
});
|
|
211
|
+
/**
|
|
212
|
+
* Get available providers
|
|
213
|
+
*/
|
|
214
|
+
getAvailableProviders(): OAuthProviderName[];
|
|
215
|
+
/**
|
|
216
|
+
* Check if a provider is configured
|
|
217
|
+
*/
|
|
218
|
+
hasProvider(name: string): boolean;
|
|
219
|
+
/**
|
|
220
|
+
* Get a provider by name
|
|
221
|
+
*/
|
|
222
|
+
getProvider(name: string): OAuthProvider | undefined;
|
|
223
|
+
/**
|
|
224
|
+
* Start OAuth flow - returns authorization URL
|
|
225
|
+
*/
|
|
226
|
+
startFlow(providerName: OAuthProviderName, options?: {
|
|
227
|
+
tenantId?: string;
|
|
228
|
+
redirectUrl?: string;
|
|
229
|
+
}): Promise<OAuthFlowResult>;
|
|
230
|
+
/**
|
|
231
|
+
* Handle OAuth callback
|
|
232
|
+
*/
|
|
233
|
+
handleCallback(providerName: OAuthProviderName, code: string, state: string): Promise<OAuthCallbackResult>;
|
|
234
|
+
/**
|
|
235
|
+
* Refresh OAuth tokens (if supported by provider)
|
|
236
|
+
*/
|
|
237
|
+
refreshTokens(providerName: OAuthProviderName, refreshToken: string): Promise<OAuthTokens>;
|
|
238
|
+
/**
|
|
239
|
+
* Check if provider supports token refresh
|
|
240
|
+
*/
|
|
241
|
+
supportsRefresh(providerName: OAuthProviderName): boolean;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Create OAuth manager
|
|
245
|
+
*/
|
|
246
|
+
declare function createOAuthManager(storage: KVStorage, config: OAuthConfig, options?: {
|
|
247
|
+
stateExpirySeconds?: number;
|
|
248
|
+
}): OAuthManager;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Magic Link Provider
|
|
252
|
+
* Passwordless email authentication via secure links
|
|
253
|
+
*/
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Magic Link configuration
|
|
257
|
+
*/
|
|
258
|
+
interface MagicLinkConfig {
|
|
259
|
+
/** Base URL for magic links (e.g., https://app.example.com) */
|
|
260
|
+
baseUrl: string;
|
|
261
|
+
/** Path for callback (default: /auth/magic-link/callback) */
|
|
262
|
+
callbackPath?: string;
|
|
263
|
+
/** Token expiration in seconds (default: 900 = 15 minutes) */
|
|
264
|
+
expiresIn?: number;
|
|
265
|
+
/** Token length in bytes (default: 32) */
|
|
266
|
+
tokenLength?: number;
|
|
267
|
+
/** Email sender function */
|
|
268
|
+
send: (email: string, url: string, expiresIn: number) => Promise<void>;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Send magic link result
|
|
272
|
+
*/
|
|
273
|
+
interface SendMagicLinkResult {
|
|
274
|
+
success: boolean;
|
|
275
|
+
expiresAt?: Date;
|
|
276
|
+
error?: string;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Verify magic link result
|
|
280
|
+
*/
|
|
281
|
+
interface VerifyMagicLinkResult {
|
|
282
|
+
success: boolean;
|
|
283
|
+
email?: string;
|
|
284
|
+
tenantId?: string;
|
|
285
|
+
redirectUrl?: string;
|
|
286
|
+
error?: string;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Magic Link Provider
|
|
290
|
+
*/
|
|
291
|
+
declare class MagicLinkProvider implements AuthProvider {
|
|
292
|
+
readonly name = "magic-link";
|
|
293
|
+
readonly type: "magic-link";
|
|
294
|
+
private storage;
|
|
295
|
+
private config;
|
|
296
|
+
private _enabled;
|
|
297
|
+
constructor(storage: KVStorage, config: MagicLinkConfig);
|
|
298
|
+
get enabled(): boolean;
|
|
299
|
+
/**
|
|
300
|
+
* Send magic link to email
|
|
301
|
+
*/
|
|
302
|
+
sendMagicLink(email: string, options?: {
|
|
303
|
+
tenantId?: string;
|
|
304
|
+
redirectUrl?: string;
|
|
305
|
+
}): Promise<SendMagicLinkResult>;
|
|
306
|
+
/**
|
|
307
|
+
* Verify magic link token
|
|
308
|
+
*/
|
|
309
|
+
verifyMagicLink(token: string): Promise<VerifyMagicLinkResult>;
|
|
310
|
+
/**
|
|
311
|
+
* Authenticate with magic link token (implements AuthProvider)
|
|
312
|
+
*/
|
|
313
|
+
authenticate(input: AuthInput): Promise<AuthResult>;
|
|
314
|
+
/**
|
|
315
|
+
* Get provider info
|
|
316
|
+
*/
|
|
317
|
+
getInfo(): ProviderInfo;
|
|
318
|
+
/**
|
|
319
|
+
* Request magic link (for use in auth routes)
|
|
320
|
+
*/
|
|
321
|
+
requestMagicLink(email: string, options?: {
|
|
322
|
+
tenantId?: string;
|
|
323
|
+
redirectUrl?: string;
|
|
324
|
+
}): Promise<SendMagicLinkResult>;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Create Magic Link provider
|
|
328
|
+
*/
|
|
329
|
+
declare function createMagicLinkProvider(storage: KVStorage, config: MagicLinkConfig): MagicLinkProvider;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* TOTP Provider (Time-based One-Time Password)
|
|
333
|
+
* RFC 6238 compliant, Google Authenticator compatible
|
|
334
|
+
*/
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* TOTP Configuration
|
|
338
|
+
*/
|
|
339
|
+
interface TOTPConfig {
|
|
340
|
+
/** Issuer name (your app name) */
|
|
341
|
+
issuer: string;
|
|
342
|
+
/** Hash algorithm (default: SHA1 for compatibility) */
|
|
343
|
+
algorithm?: 'SHA1' | 'SHA256' | 'SHA512';
|
|
344
|
+
/** Number of digits (default: 6) */
|
|
345
|
+
digits?: 6 | 8;
|
|
346
|
+
/** Time period in seconds (default: 30) */
|
|
347
|
+
period?: number;
|
|
348
|
+
/** Time window for drift tolerance (default: 1) */
|
|
349
|
+
window?: number;
|
|
350
|
+
/** Number of backup codes (default: 10) */
|
|
351
|
+
backupCodeCount?: number;
|
|
352
|
+
/** Encryption key for storing secrets */
|
|
353
|
+
encryptionKey?: string;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* TOTP setup result
|
|
357
|
+
*/
|
|
358
|
+
interface TOTPSetupData {
|
|
359
|
+
/** Base32 encoded secret */
|
|
360
|
+
secret: string;
|
|
361
|
+
/** QR code URL */
|
|
362
|
+
qrCodeUrl: string;
|
|
363
|
+
/** Backup codes */
|
|
364
|
+
backupCodes: string[];
|
|
365
|
+
/** otpauth:// URI */
|
|
366
|
+
otpauthUri: string;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* TOTP verify result
|
|
370
|
+
*/
|
|
371
|
+
interface TOTPVerifyResult {
|
|
372
|
+
valid: boolean;
|
|
373
|
+
usedBackupCode?: boolean;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* TOTP Provider
|
|
377
|
+
*/
|
|
378
|
+
declare class TOTPProvider implements TwoFactorProvider {
|
|
379
|
+
readonly name = "totp";
|
|
380
|
+
readonly type: "totp";
|
|
381
|
+
private storage;
|
|
382
|
+
private config;
|
|
383
|
+
private _enabled;
|
|
384
|
+
constructor(storage: KVStorage, config: TOTPConfig);
|
|
385
|
+
get enabled(): boolean;
|
|
386
|
+
/**
|
|
387
|
+
* Setup TOTP for a user
|
|
388
|
+
* Note: Use setupWithEmail for full setup including QR code URL
|
|
389
|
+
*/
|
|
390
|
+
setup(userId: string): Promise<TwoFactorSetupResult>;
|
|
391
|
+
/**
|
|
392
|
+
* Setup TOTP for a user with email for QR code label
|
|
393
|
+
*/
|
|
394
|
+
setupWithEmail(userId: string, userEmail: string): Promise<TwoFactorSetupResult & {
|
|
395
|
+
qrCodeUrl: string;
|
|
396
|
+
otpauthUri: string;
|
|
397
|
+
}>;
|
|
398
|
+
/**
|
|
399
|
+
* Verify TOTP and activate 2FA (for TwoFactorProvider interface)
|
|
400
|
+
*/
|
|
401
|
+
verifySetup(userId: string, token: string): Promise<boolean>;
|
|
402
|
+
/**
|
|
403
|
+
* Verify TOTP during login (for TwoFactorProvider interface)
|
|
404
|
+
*/
|
|
405
|
+
verifyLogin(userId: string, code: string): Promise<boolean>;
|
|
406
|
+
/**
|
|
407
|
+
* Authenticate (for AuthProvider interface)
|
|
408
|
+
*/
|
|
409
|
+
authenticate(_input: AuthInput): Promise<AuthResult>;
|
|
410
|
+
/**
|
|
411
|
+
* Verify TOTP token
|
|
412
|
+
*/
|
|
413
|
+
verifyCode(userId: string, token: string): Promise<TOTPVerifyResult>;
|
|
414
|
+
/**
|
|
415
|
+
* Disable TOTP for user
|
|
416
|
+
*/
|
|
417
|
+
disable(userId: string): Promise<void>;
|
|
418
|
+
/**
|
|
419
|
+
* Regenerate backup codes
|
|
420
|
+
*/
|
|
421
|
+
regenerateBackupCodes(userId: string): Promise<string[]>;
|
|
422
|
+
/**
|
|
423
|
+
* Get remaining backup codes count
|
|
424
|
+
*/
|
|
425
|
+
getBackupCodesCount(userId: string): Promise<number>;
|
|
426
|
+
/**
|
|
427
|
+
* Check if TOTP is enabled for user
|
|
428
|
+
*/
|
|
429
|
+
isEnabled(userId: string): Promise<boolean>;
|
|
430
|
+
/**
|
|
431
|
+
* Generate current TOTP (for testing)
|
|
432
|
+
*/
|
|
433
|
+
generateCurrent(userId: string): Promise<string>;
|
|
434
|
+
/**
|
|
435
|
+
* Get provider info
|
|
436
|
+
*/
|
|
437
|
+
getInfo(): ProviderInfo;
|
|
438
|
+
/**
|
|
439
|
+
* Create otpauth URI for QR code
|
|
440
|
+
*/
|
|
441
|
+
private createOtpauthUri;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Create TOTP provider
|
|
445
|
+
*/
|
|
446
|
+
declare function createTOTPProvider(storage: KVStorage, config: TOTPConfig): TOTPProvider;
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* WebAuthn Provider (Passkeys)
|
|
450
|
+
* FIDO2 passwordless authentication
|
|
451
|
+
*/
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* WebAuthn Configuration
|
|
455
|
+
*/
|
|
456
|
+
interface WebAuthnConfig {
|
|
457
|
+
/** Relying Party name (your app name) */
|
|
458
|
+
rpName: string;
|
|
459
|
+
/** Relying Party ID (domain without protocol) */
|
|
460
|
+
rpId: string;
|
|
461
|
+
/** Full origin (e.g., https://example.com) */
|
|
462
|
+
origin: string;
|
|
463
|
+
/** Timeout in milliseconds (default: 60000) */
|
|
464
|
+
timeout?: number;
|
|
465
|
+
/** Attestation preference (default: none) */
|
|
466
|
+
attestation?: 'none' | 'indirect' | 'direct';
|
|
467
|
+
/** User verification preference (default: preferred) */
|
|
468
|
+
userVerification?: 'required' | 'preferred' | 'discouraged';
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Registration options returned to client
|
|
472
|
+
*/
|
|
473
|
+
interface RegistrationOptions {
|
|
474
|
+
challenge: string;
|
|
475
|
+
rp: {
|
|
476
|
+
name: string;
|
|
477
|
+
id: string;
|
|
478
|
+
};
|
|
479
|
+
user: {
|
|
480
|
+
id: string;
|
|
481
|
+
name: string;
|
|
482
|
+
displayName: string;
|
|
483
|
+
};
|
|
484
|
+
pubKeyCredParams: Array<{
|
|
485
|
+
type: 'public-key';
|
|
486
|
+
alg: number;
|
|
487
|
+
}>;
|
|
488
|
+
timeout: number;
|
|
489
|
+
attestation: 'none' | 'indirect' | 'direct';
|
|
490
|
+
authenticatorSelection: {
|
|
491
|
+
authenticatorAttachment?: 'platform' | 'cross-platform';
|
|
492
|
+
residentKey: 'required' | 'preferred' | 'discouraged';
|
|
493
|
+
userVerification: 'required' | 'preferred' | 'discouraged';
|
|
494
|
+
};
|
|
495
|
+
excludeCredentials: Array<{
|
|
496
|
+
id: string;
|
|
497
|
+
type: 'public-key';
|
|
498
|
+
transports?: string[];
|
|
499
|
+
}>;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Authentication options returned to client
|
|
503
|
+
*/
|
|
504
|
+
interface AuthenticationOptions {
|
|
505
|
+
challenge: string;
|
|
506
|
+
timeout: number;
|
|
507
|
+
rpId: string;
|
|
508
|
+
allowCredentials: Array<{
|
|
509
|
+
id: string;
|
|
510
|
+
type: 'public-key';
|
|
511
|
+
transports?: string[];
|
|
512
|
+
}>;
|
|
513
|
+
userVerification: 'required' | 'preferred' | 'discouraged';
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Registration response from client
|
|
517
|
+
*/
|
|
518
|
+
interface RegistrationResponse {
|
|
519
|
+
id: string;
|
|
520
|
+
rawId: string;
|
|
521
|
+
type: 'public-key';
|
|
522
|
+
response: {
|
|
523
|
+
clientDataJSON: string;
|
|
524
|
+
attestationObject: string;
|
|
525
|
+
transports?: string[];
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Authentication response from client
|
|
530
|
+
*/
|
|
531
|
+
interface AuthenticationResponse {
|
|
532
|
+
id: string;
|
|
533
|
+
rawId: string;
|
|
534
|
+
type: 'public-key';
|
|
535
|
+
response: {
|
|
536
|
+
clientDataJSON: string;
|
|
537
|
+
authenticatorData: string;
|
|
538
|
+
signature: string;
|
|
539
|
+
userHandle?: string;
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Client data JSON structure
|
|
544
|
+
*/
|
|
545
|
+
interface ClientDataJSON {
|
|
546
|
+
type: 'webauthn.create' | 'webauthn.get';
|
|
547
|
+
challenge: string;
|
|
548
|
+
origin: string;
|
|
549
|
+
crossOrigin?: boolean;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Authenticator data structure
|
|
553
|
+
*/
|
|
554
|
+
interface AuthenticatorData {
|
|
555
|
+
rpIdHash: Uint8Array;
|
|
556
|
+
flags: {
|
|
557
|
+
userPresent: boolean;
|
|
558
|
+
userVerified: boolean;
|
|
559
|
+
attestedCredentialData: boolean;
|
|
560
|
+
extensionDataIncluded?: boolean;
|
|
561
|
+
};
|
|
562
|
+
signCount: number;
|
|
563
|
+
attestedCredentialData?: {
|
|
564
|
+
aaguid: Uint8Array;
|
|
565
|
+
credentialId: Uint8Array;
|
|
566
|
+
publicKey: Uint8Array;
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Stored credential (exported as WebAuthnCredential)
|
|
571
|
+
*/
|
|
572
|
+
interface WebAuthnCredential {
|
|
573
|
+
id: string;
|
|
574
|
+
credentialId: string;
|
|
575
|
+
userId: string;
|
|
576
|
+
publicKey: string;
|
|
577
|
+
counter: number;
|
|
578
|
+
transports: string[];
|
|
579
|
+
name: string;
|
|
580
|
+
deviceType?: string;
|
|
581
|
+
createdAt: string;
|
|
582
|
+
lastUsedAt?: string;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* WebAuthn Provider
|
|
586
|
+
*/
|
|
587
|
+
declare class WebAuthnProvider implements TwoFactorProvider {
|
|
588
|
+
readonly name = "webauthn";
|
|
589
|
+
readonly type: "webauthn";
|
|
590
|
+
private storage;
|
|
591
|
+
private config;
|
|
592
|
+
private _enabled;
|
|
593
|
+
constructor(storage: KVStorage, config: WebAuthnConfig);
|
|
594
|
+
get enabled(): boolean;
|
|
595
|
+
/**
|
|
596
|
+
* Generate registration options
|
|
597
|
+
*/
|
|
598
|
+
generateRegistrationOptions(userId: string, userName: string, userDisplayName: string, authenticatorType?: 'platform' | 'cross-platform'): Promise<RegistrationOptions>;
|
|
599
|
+
/**
|
|
600
|
+
* Verify registration response
|
|
601
|
+
*/
|
|
602
|
+
verifyRegistration(response: RegistrationResponse, challenge: string, credentialName?: string): Promise<{
|
|
603
|
+
success: boolean;
|
|
604
|
+
credentialId?: string;
|
|
605
|
+
error?: string;
|
|
606
|
+
}>;
|
|
607
|
+
/**
|
|
608
|
+
* Generate authentication options
|
|
609
|
+
*/
|
|
610
|
+
generateAuthenticationOptions(userId?: string): Promise<AuthenticationOptions>;
|
|
611
|
+
/**
|
|
612
|
+
* Verify authentication response
|
|
613
|
+
*/
|
|
614
|
+
verifyAuthentication(response: AuthenticationResponse, challenge: string): Promise<{
|
|
615
|
+
success: boolean;
|
|
616
|
+
userId?: string;
|
|
617
|
+
credentialId?: string;
|
|
618
|
+
error?: string;
|
|
619
|
+
}>;
|
|
620
|
+
/**
|
|
621
|
+
* Get user's credentials
|
|
622
|
+
*/
|
|
623
|
+
getUserCredentials(userId: string): Promise<WebAuthnCredential[]>;
|
|
624
|
+
/**
|
|
625
|
+
* Remove a credential
|
|
626
|
+
*/
|
|
627
|
+
removeCredential(userId: string, credentialId: string): Promise<boolean>;
|
|
628
|
+
/**
|
|
629
|
+
* Check if user has any passkeys
|
|
630
|
+
*/
|
|
631
|
+
hasPasskeys(userId: string): Promise<boolean>;
|
|
632
|
+
/**
|
|
633
|
+
* Setup (for TwoFactorProvider interface)
|
|
634
|
+
*/
|
|
635
|
+
setup(userId: string): Promise<TwoFactorSetupResult>;
|
|
636
|
+
/**
|
|
637
|
+
* Verify setup (for TwoFactorProvider interface)
|
|
638
|
+
*/
|
|
639
|
+
verifySetup(userId: string, _code: string): Promise<boolean>;
|
|
640
|
+
/**
|
|
641
|
+
* Verify login (for TwoFactorProvider interface)
|
|
642
|
+
*/
|
|
643
|
+
verifyLogin(userId: string, _code: string): Promise<boolean>;
|
|
644
|
+
/**
|
|
645
|
+
* Disable 2FA for user
|
|
646
|
+
*/
|
|
647
|
+
disable(userId: string): Promise<void>;
|
|
648
|
+
/**
|
|
649
|
+
* Authenticate (for AuthProvider interface)
|
|
650
|
+
*/
|
|
651
|
+
authenticate(_input: AuthInput): Promise<AuthResult>;
|
|
652
|
+
/**
|
|
653
|
+
* Get provider info
|
|
654
|
+
*/
|
|
655
|
+
getInfo(): ProviderInfo;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Create WebAuthn provider
|
|
659
|
+
*/
|
|
660
|
+
declare function createWebAuthnProvider(storage: KVStorage, config: WebAuthnConfig): WebAuthnProvider;
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Password Provider
|
|
664
|
+
* Traditional password-based authentication
|
|
665
|
+
* DISABLED BY DEFAULT - use passwordless methods when possible
|
|
666
|
+
*/
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Password configuration
|
|
670
|
+
*/
|
|
671
|
+
interface PasswordConfig {
|
|
672
|
+
/** Minimum password length (default: 8) */
|
|
673
|
+
minLength?: number;
|
|
674
|
+
/** Maximum password length (default: 128) */
|
|
675
|
+
maxLength?: number;
|
|
676
|
+
/** Require uppercase letter (default: true) */
|
|
677
|
+
requireUppercase?: boolean;
|
|
678
|
+
/** Require lowercase letter (default: true) */
|
|
679
|
+
requireLowercase?: boolean;
|
|
680
|
+
/** Require number (default: true) */
|
|
681
|
+
requireNumber?: boolean;
|
|
682
|
+
/** Require special character (default: false) */
|
|
683
|
+
requireSpecial?: boolean;
|
|
684
|
+
/** Bcrypt cost factor (default: 12) */
|
|
685
|
+
bcryptCost?: number;
|
|
686
|
+
/** Password hash function (for custom implementations) */
|
|
687
|
+
hashPassword?: (password: string) => Promise<string>;
|
|
688
|
+
/** Password verify function (for custom implementations) */
|
|
689
|
+
verifyPassword?: (password: string, hash: string) => Promise<boolean>;
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Password validation result
|
|
693
|
+
*/
|
|
694
|
+
interface PasswordValidationResult {
|
|
695
|
+
valid: boolean;
|
|
696
|
+
errors: string[];
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Password strength levels
|
|
700
|
+
*/
|
|
701
|
+
type PasswordStrength = 'weak' | 'fair' | 'strong' | 'very-strong';
|
|
702
|
+
/**
|
|
703
|
+
* Password Provider
|
|
704
|
+
* WARNING: This provider is disabled by default.
|
|
705
|
+
* Consider using passwordless authentication (OTP, Magic Link, OAuth) for better security.
|
|
706
|
+
*/
|
|
707
|
+
declare class PasswordProvider implements AuthProvider {
|
|
708
|
+
readonly name = "password";
|
|
709
|
+
readonly type: "password";
|
|
710
|
+
private storage;
|
|
711
|
+
private config;
|
|
712
|
+
private _enabled;
|
|
713
|
+
constructor(storage: KVStorage, config?: PasswordConfig);
|
|
714
|
+
get enabled(): boolean;
|
|
715
|
+
/**
|
|
716
|
+
* Enable the password provider
|
|
717
|
+
* Must be explicitly called to enable password authentication
|
|
718
|
+
*/
|
|
719
|
+
enable(): void;
|
|
720
|
+
/**
|
|
721
|
+
* Disable the password provider
|
|
722
|
+
*/
|
|
723
|
+
disable(): void;
|
|
724
|
+
/**
|
|
725
|
+
* Validate password against policy
|
|
726
|
+
*/
|
|
727
|
+
validatePassword(password: string): PasswordValidationResult;
|
|
728
|
+
/**
|
|
729
|
+
* Check password strength
|
|
730
|
+
*/
|
|
731
|
+
checkStrength(password: string): PasswordStrength;
|
|
732
|
+
/**
|
|
733
|
+
* Hash a password
|
|
734
|
+
* Uses Web Crypto API for PBKDF2 (bcrypt alternative for edge runtime)
|
|
735
|
+
*/
|
|
736
|
+
hashPassword(password: string): Promise<string>;
|
|
737
|
+
/**
|
|
738
|
+
* Verify a password against a hash
|
|
739
|
+
*/
|
|
740
|
+
verifyPassword(password: string, hash: string): Promise<boolean>;
|
|
741
|
+
/**
|
|
742
|
+
* Authenticate with password (implements AuthProvider)
|
|
743
|
+
*/
|
|
744
|
+
authenticate(input: AuthInput): Promise<AuthResult>;
|
|
745
|
+
/**
|
|
746
|
+
* Store password hash for a user
|
|
747
|
+
*/
|
|
748
|
+
setPassword(userId: string, password: string): Promise<{
|
|
749
|
+
success: boolean;
|
|
750
|
+
errors?: string[];
|
|
751
|
+
}>;
|
|
752
|
+
/**
|
|
753
|
+
* Verify password for a user
|
|
754
|
+
*/
|
|
755
|
+
verifyUserPassword(userId: string, password: string): Promise<boolean>;
|
|
756
|
+
/**
|
|
757
|
+
* Check if user has password set
|
|
758
|
+
*/
|
|
759
|
+
hasPassword(userId: string): Promise<boolean>;
|
|
760
|
+
/**
|
|
761
|
+
* Remove password for a user (switch to passwordless)
|
|
762
|
+
*/
|
|
763
|
+
removePassword(userId: string): Promise<void>;
|
|
764
|
+
/**
|
|
765
|
+
* Get provider info
|
|
766
|
+
*/
|
|
767
|
+
getInfo(): ProviderInfo;
|
|
768
|
+
/**
|
|
769
|
+
* Constant-time comparison to prevent timing attacks
|
|
770
|
+
*/
|
|
771
|
+
private constantTimeEquals;
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* Create Password provider
|
|
775
|
+
*/
|
|
776
|
+
declare function createPasswordProvider(storage: KVStorage, config?: PasswordConfig): PasswordProvider;
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Runtime detection utilities for multi-runtime support
|
|
780
|
+
* Supports: Node.js, Deno, Cloudflare Workers, Bun
|
|
781
|
+
*/
|
|
782
|
+
type Runtime = 'node' | 'deno' | 'cloudflare' | 'bun' | 'unknown';
|
|
783
|
+
/**
|
|
784
|
+
* Detect the current JavaScript runtime environment
|
|
785
|
+
*/
|
|
786
|
+
declare function detectRuntime(): Runtime;
|
|
787
|
+
/**
|
|
788
|
+
* Check if running in Node.js
|
|
789
|
+
*/
|
|
790
|
+
declare function isNode(): boolean;
|
|
791
|
+
/**
|
|
792
|
+
* Check if running in Deno
|
|
793
|
+
*/
|
|
794
|
+
declare function isDeno(): boolean;
|
|
795
|
+
/**
|
|
796
|
+
* Check if running in Cloudflare Workers
|
|
797
|
+
*/
|
|
798
|
+
declare function isCloudflare(): boolean;
|
|
799
|
+
/**
|
|
800
|
+
* Check if running in Bun
|
|
801
|
+
*/
|
|
802
|
+
declare function isBun(): boolean;
|
|
803
|
+
/**
|
|
804
|
+
* Check if running in an edge runtime (CF Workers, Deno Deploy, etc.)
|
|
805
|
+
*/
|
|
806
|
+
declare function isEdge(): boolean;
|
|
807
|
+
/**
|
|
808
|
+
* Get environment variable across runtimes
|
|
809
|
+
*/
|
|
810
|
+
declare function getEnv(key: string): string | undefined;
|
|
811
|
+
|
|
812
|
+
/**
|
|
813
|
+
* Runtime-agnostic Crypto Utilities
|
|
814
|
+
* Uses Web Crypto API (works in Node.js, Deno, Bun, Cloudflare Workers)
|
|
815
|
+
*/
|
|
816
|
+
/**
|
|
817
|
+
* Generate cryptographically secure random bytes as hex string
|
|
818
|
+
*/
|
|
819
|
+
declare function generateRandomHex(byteLength?: number): string;
|
|
820
|
+
/**
|
|
821
|
+
* Generate cryptographically secure random bytes as base64url string
|
|
822
|
+
*/
|
|
823
|
+
declare function generateRandomBase64Url(byteLength?: number): string;
|
|
824
|
+
/**
|
|
825
|
+
* Generate a random integer between min (inclusive) and max (exclusive)
|
|
826
|
+
* Uses rejection sampling for uniform distribution
|
|
827
|
+
*/
|
|
828
|
+
declare function randomInt(min: number, max: number): number;
|
|
829
|
+
/**
|
|
830
|
+
* Hash data using SHA-256 and return as hex string
|
|
831
|
+
*/
|
|
832
|
+
declare function sha256Hex(data: string): Promise<string>;
|
|
833
|
+
/**
|
|
834
|
+
* Hash data using SHA-256 and return as Uint8Array
|
|
835
|
+
*/
|
|
836
|
+
declare function sha256(data: string): Promise<Uint8Array>;
|
|
837
|
+
/**
|
|
838
|
+
* Timing-safe comparison of two strings
|
|
839
|
+
* Prevents timing attacks by always comparing all bytes
|
|
840
|
+
*/
|
|
841
|
+
declare function timingSafeEqual(a: string, b: string): boolean;
|
|
842
|
+
/**
|
|
843
|
+
* Timing-safe comparison of two Uint8Arrays
|
|
844
|
+
*/
|
|
845
|
+
declare function timingSafeEqualBytes(a: Uint8Array, b: Uint8Array): boolean;
|
|
846
|
+
/**
|
|
847
|
+
* Base64URL encode (URL-safe base64 without padding)
|
|
848
|
+
*/
|
|
849
|
+
declare function base64UrlEncode(data: Uint8Array): string;
|
|
850
|
+
/**
|
|
851
|
+
* Base64URL decode
|
|
852
|
+
*/
|
|
853
|
+
declare function base64UrlDecode(str: string): Uint8Array;
|
|
854
|
+
/**
|
|
855
|
+
* Hex string to Uint8Array
|
|
856
|
+
*/
|
|
857
|
+
declare function hexToBytes(hex: string): Uint8Array;
|
|
858
|
+
/**
|
|
859
|
+
* Uint8Array to hex string
|
|
860
|
+
*/
|
|
861
|
+
declare function bytesToHex(bytes: Uint8Array): string;
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
* Drizzle Adapter Types
|
|
865
|
+
* Database table definitions for auth (PostgreSQL)
|
|
866
|
+
*/
|
|
867
|
+
/**
|
|
868
|
+
* Database schema types - these should match your actual Drizzle schema
|
|
869
|
+
* Import these from your database package when using the adapter
|
|
870
|
+
*/
|
|
871
|
+
interface DrizzleAuthSchema {
|
|
872
|
+
/** Users table */
|
|
873
|
+
users: any;
|
|
874
|
+
/** Sessions table */
|
|
875
|
+
sessions: any;
|
|
876
|
+
/** Auth methods table (email, phone, oauth) */
|
|
877
|
+
authMethods: any;
|
|
878
|
+
/** Tenants table */
|
|
879
|
+
tenants?: any;
|
|
880
|
+
/** Tenant memberships table */
|
|
881
|
+
tenantMemberships?: any;
|
|
882
|
+
/** Roles table */
|
|
883
|
+
roles?: any;
|
|
884
|
+
/** Email verification tokens table */
|
|
885
|
+
emailVerificationTokens?: any;
|
|
886
|
+
/** TOTP secrets table */
|
|
887
|
+
totpSecrets?: any;
|
|
888
|
+
/** WebAuthn credentials table */
|
|
889
|
+
webauthnCredentials?: any;
|
|
890
|
+
/** OAuth states table */
|
|
891
|
+
oauthStates?: any;
|
|
892
|
+
/** Magic link tokens table */
|
|
893
|
+
magicLinkTokens?: any;
|
|
894
|
+
/** Audit log table */
|
|
895
|
+
authAuditLog?: any;
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* User model
|
|
899
|
+
*/
|
|
900
|
+
interface DrizzleUser {
|
|
901
|
+
id: string;
|
|
902
|
+
displayName: string | null;
|
|
903
|
+
avatarUrl: string | null;
|
|
904
|
+
emailVerified: boolean;
|
|
905
|
+
phoneVerified: boolean;
|
|
906
|
+
twoFactorEnabled: boolean;
|
|
907
|
+
twoFactorSecret: string | null;
|
|
908
|
+
status: string;
|
|
909
|
+
metadata: Record<string, unknown> | null;
|
|
910
|
+
insertedAt: Date;
|
|
911
|
+
updatedAt: Date;
|
|
912
|
+
deletedAt: Date | null;
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Session model
|
|
916
|
+
*/
|
|
917
|
+
interface DrizzleSession {
|
|
918
|
+
id: string;
|
|
919
|
+
userId: string;
|
|
920
|
+
authMethodId: string | null;
|
|
921
|
+
currentTenantId: string | null;
|
|
922
|
+
accessTokenHash: string | null;
|
|
923
|
+
refreshTokenHash: string | null;
|
|
924
|
+
csrfTokenHash: string;
|
|
925
|
+
expiresAt: Date;
|
|
926
|
+
refreshExpiresAt: Date | null;
|
|
927
|
+
deviceType: string | null;
|
|
928
|
+
deviceName: string | null;
|
|
929
|
+
userAgent: string | null;
|
|
930
|
+
ipAddress: string | null;
|
|
931
|
+
locationData: Record<string, unknown> | null;
|
|
932
|
+
deviceFingerprint: string | null;
|
|
933
|
+
status: string;
|
|
934
|
+
lastActivityAt: Date;
|
|
935
|
+
revokedAt: Date | null;
|
|
936
|
+
revokedReason: string | null;
|
|
937
|
+
insertedAt: Date;
|
|
938
|
+
updatedAt: Date;
|
|
939
|
+
deletedAt: Date | null;
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* Auth method model
|
|
943
|
+
*/
|
|
944
|
+
interface DrizzleAuthMethod {
|
|
945
|
+
id: string;
|
|
946
|
+
userId: string;
|
|
947
|
+
provider: string;
|
|
948
|
+
providerId: string;
|
|
949
|
+
verified: boolean;
|
|
950
|
+
metadata: Record<string, unknown> | null;
|
|
951
|
+
insertedAt: Date;
|
|
952
|
+
updatedAt: Date;
|
|
953
|
+
deletedAt: Date | null;
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Tenant model
|
|
957
|
+
*/
|
|
958
|
+
interface DrizzleTenant {
|
|
959
|
+
id: string;
|
|
960
|
+
name: string;
|
|
961
|
+
slug: string;
|
|
962
|
+
status: string;
|
|
963
|
+
subscriptionPlan: string;
|
|
964
|
+
settings: Record<string, unknown>;
|
|
965
|
+
insertedAt: Date;
|
|
966
|
+
updatedAt: Date;
|
|
967
|
+
deletedAt: Date | null;
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Tenant membership model
|
|
971
|
+
*/
|
|
972
|
+
interface DrizzleTenantMembership {
|
|
973
|
+
id: string;
|
|
974
|
+
userId: string;
|
|
975
|
+
tenantId: string;
|
|
976
|
+
roleId: string | null;
|
|
977
|
+
status: string;
|
|
978
|
+
permissions: Record<string, unknown>;
|
|
979
|
+
accessLevel: string;
|
|
980
|
+
resourceRestrictions: Record<string, unknown>;
|
|
981
|
+
ipRestrictions: Record<string, unknown> | null;
|
|
982
|
+
timeRestrictions: Record<string, unknown> | null;
|
|
983
|
+
expiresAt: Date | null;
|
|
984
|
+
invitedBy: string | null;
|
|
985
|
+
invitedAt: Date | null;
|
|
986
|
+
joinedAt: Date | null;
|
|
987
|
+
lastLoginAt: Date | null;
|
|
988
|
+
insertedAt: Date;
|
|
989
|
+
updatedAt: Date;
|
|
990
|
+
deletedAt: Date | null;
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Role model
|
|
994
|
+
*/
|
|
995
|
+
interface DrizzleRole {
|
|
996
|
+
id: string;
|
|
997
|
+
tenantId: string;
|
|
998
|
+
name: string;
|
|
999
|
+
description: string | null;
|
|
1000
|
+
isSystem: boolean;
|
|
1001
|
+
isActive: boolean;
|
|
1002
|
+
color: string | null;
|
|
1003
|
+
insertedAt: Date;
|
|
1004
|
+
updatedAt: Date;
|
|
1005
|
+
deletedAt: Date | null;
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* Email verification token model
|
|
1009
|
+
*/
|
|
1010
|
+
interface DrizzleEmailVerificationToken {
|
|
1011
|
+
id: string;
|
|
1012
|
+
email: string;
|
|
1013
|
+
tokenHash: string;
|
|
1014
|
+
expiresAt: Date;
|
|
1015
|
+
usedAt: Date | null;
|
|
1016
|
+
createdBy: string | null;
|
|
1017
|
+
insertedAt: Date;
|
|
1018
|
+
updatedAt: Date;
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Drizzle database instance type
|
|
1022
|
+
*/
|
|
1023
|
+
type DrizzleDatabase = {
|
|
1024
|
+
select: (fields?: any) => any;
|
|
1025
|
+
insert: (table: any) => any;
|
|
1026
|
+
update: (table: any) => any;
|
|
1027
|
+
delete: (table: any) => any;
|
|
1028
|
+
query: Record<string, any>;
|
|
1029
|
+
};
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* Drizzle ORM Adapter for @parsrun/auth
|
|
1033
|
+
* Implements AuthAdapter interface using Drizzle ORM with PostgreSQL
|
|
1034
|
+
*/
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* Drizzle adapter configuration
|
|
1038
|
+
*/
|
|
1039
|
+
interface DrizzleAdapterConfig {
|
|
1040
|
+
/** Drizzle database instance */
|
|
1041
|
+
db: DrizzleDatabase;
|
|
1042
|
+
/** Database schema with auth tables */
|
|
1043
|
+
schema: DrizzleAuthSchema;
|
|
1044
|
+
/** Enable soft deletes (default: true) */
|
|
1045
|
+
softDelete?: boolean;
|
|
1046
|
+
/** Enable audit logging (default: false) */
|
|
1047
|
+
enableAuditLog?: boolean;
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Create Drizzle adapter
|
|
1051
|
+
*/
|
|
1052
|
+
declare function createDrizzleAdapter(config: DrizzleAdapterConfig): AuthAdapter;
|
|
1053
|
+
|
|
1054
|
+
/**
|
|
1055
|
+
* Email Service Types
|
|
1056
|
+
*/
|
|
1057
|
+
/**
|
|
1058
|
+
* Email provider interface
|
|
1059
|
+
*/
|
|
1060
|
+
interface EmailProvider {
|
|
1061
|
+
/** Send an email */
|
|
1062
|
+
sendEmail(options: EmailOptions): Promise<EmailResult>;
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Email options
|
|
1066
|
+
*/
|
|
1067
|
+
interface EmailOptions {
|
|
1068
|
+
/** Recipient email address */
|
|
1069
|
+
to: string;
|
|
1070
|
+
/** Email subject */
|
|
1071
|
+
subject: string;
|
|
1072
|
+
/** HTML content */
|
|
1073
|
+
html?: string;
|
|
1074
|
+
/** Plain text content */
|
|
1075
|
+
text?: string;
|
|
1076
|
+
/** From email (overrides default) */
|
|
1077
|
+
from?: string;
|
|
1078
|
+
/** Reply-to address */
|
|
1079
|
+
replyTo?: string;
|
|
1080
|
+
/** CC recipients */
|
|
1081
|
+
cc?: string[];
|
|
1082
|
+
/** BCC recipients */
|
|
1083
|
+
bcc?: string[];
|
|
1084
|
+
/** Custom headers */
|
|
1085
|
+
headers?: Record<string, string>;
|
|
1086
|
+
/** Attachments */
|
|
1087
|
+
attachments?: EmailAttachment[];
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* Email attachment
|
|
1091
|
+
*/
|
|
1092
|
+
interface EmailAttachment {
|
|
1093
|
+
filename: string;
|
|
1094
|
+
content: string | Buffer;
|
|
1095
|
+
contentType?: string;
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Email send result
|
|
1099
|
+
*/
|
|
1100
|
+
interface EmailResult {
|
|
1101
|
+
success: boolean;
|
|
1102
|
+
messageId?: string;
|
|
1103
|
+
error?: string;
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Email service configuration
|
|
1107
|
+
*/
|
|
1108
|
+
interface EmailServiceConfig {
|
|
1109
|
+
/** Email provider instance */
|
|
1110
|
+
provider?: EmailProvider;
|
|
1111
|
+
/** API key for default provider */
|
|
1112
|
+
apiKey?: string;
|
|
1113
|
+
/** Default from email */
|
|
1114
|
+
fromEmail?: string;
|
|
1115
|
+
/** Default from name */
|
|
1116
|
+
fromName?: string;
|
|
1117
|
+
/** Development mode (logs emails instead of sending) */
|
|
1118
|
+
devMode?: boolean;
|
|
1119
|
+
}
|
|
1120
|
+
/**
|
|
1121
|
+
* OTP email options
|
|
1122
|
+
*/
|
|
1123
|
+
interface OTPEmailOptions {
|
|
1124
|
+
/** Recipient email */
|
|
1125
|
+
email: string;
|
|
1126
|
+
/** OTP code */
|
|
1127
|
+
code: string;
|
|
1128
|
+
/** Expiration in minutes (default: 10) */
|
|
1129
|
+
expiresInMinutes?: number;
|
|
1130
|
+
/** User name (for personalization) */
|
|
1131
|
+
userName?: string;
|
|
1132
|
+
/** App name */
|
|
1133
|
+
appName?: string;
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Verification email options
|
|
1137
|
+
*/
|
|
1138
|
+
interface VerificationEmailOptions {
|
|
1139
|
+
/** Recipient email */
|
|
1140
|
+
email: string;
|
|
1141
|
+
/** Verification URL */
|
|
1142
|
+
verificationUrl: string;
|
|
1143
|
+
/** User name (for personalization) */
|
|
1144
|
+
userName?: string;
|
|
1145
|
+
/** Expiration in hours (default: 24) */
|
|
1146
|
+
expiresInHours?: number;
|
|
1147
|
+
/** App name */
|
|
1148
|
+
appName?: string;
|
|
1149
|
+
}
|
|
1150
|
+
/**
|
|
1151
|
+
* Welcome email options
|
|
1152
|
+
*/
|
|
1153
|
+
interface WelcomeEmailOptions {
|
|
1154
|
+
/** Recipient email */
|
|
1155
|
+
email: string;
|
|
1156
|
+
/** User name */
|
|
1157
|
+
userName?: string;
|
|
1158
|
+
/** App name */
|
|
1159
|
+
appName?: string;
|
|
1160
|
+
/** Login URL */
|
|
1161
|
+
loginUrl?: string;
|
|
1162
|
+
}
|
|
1163
|
+
/**
|
|
1164
|
+
* Magic link email options
|
|
1165
|
+
*/
|
|
1166
|
+
interface MagicLinkEmailOptions {
|
|
1167
|
+
/** Recipient email */
|
|
1168
|
+
email: string;
|
|
1169
|
+
/** Magic link URL */
|
|
1170
|
+
magicLinkUrl: string;
|
|
1171
|
+
/** Expiration in minutes (default: 15) */
|
|
1172
|
+
expiresInMinutes?: number;
|
|
1173
|
+
/** User name (for personalization) */
|
|
1174
|
+
userName?: string;
|
|
1175
|
+
/** App name */
|
|
1176
|
+
appName?: string;
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* Password reset email options
|
|
1180
|
+
*/
|
|
1181
|
+
interface PasswordResetEmailOptions {
|
|
1182
|
+
/** Recipient email */
|
|
1183
|
+
email: string;
|
|
1184
|
+
/** Reset URL */
|
|
1185
|
+
resetUrl: string;
|
|
1186
|
+
/** Expiration in hours (default: 1) */
|
|
1187
|
+
expiresInHours?: number;
|
|
1188
|
+
/** User name (for personalization) */
|
|
1189
|
+
userName?: string;
|
|
1190
|
+
/** App name */
|
|
1191
|
+
appName?: string;
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* Invitation email options
|
|
1195
|
+
*/
|
|
1196
|
+
interface InvitationEmailOptions {
|
|
1197
|
+
/** Recipient email */
|
|
1198
|
+
email: string;
|
|
1199
|
+
/** Invitation URL */
|
|
1200
|
+
invitationUrl: string;
|
|
1201
|
+
/** Inviter name */
|
|
1202
|
+
inviterName: string;
|
|
1203
|
+
/** Organization/tenant name */
|
|
1204
|
+
organizationName: string;
|
|
1205
|
+
/** Role being assigned */
|
|
1206
|
+
roleName?: string;
|
|
1207
|
+
/** Expiration in days (default: 7) */
|
|
1208
|
+
expiresInDays?: number;
|
|
1209
|
+
/** App name */
|
|
1210
|
+
appName?: string;
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
/**
|
|
1214
|
+
* Resend Email Provider
|
|
1215
|
+
* Uses Resend API for sending emails
|
|
1216
|
+
*/
|
|
1217
|
+
|
|
1218
|
+
/**
|
|
1219
|
+
* Resend provider configuration
|
|
1220
|
+
*/
|
|
1221
|
+
interface ResendProviderConfig {
|
|
1222
|
+
/** Resend API key */
|
|
1223
|
+
apiKey: string;
|
|
1224
|
+
/** Default from email */
|
|
1225
|
+
fromEmail?: string;
|
|
1226
|
+
/** Default from name */
|
|
1227
|
+
fromName?: string;
|
|
1228
|
+
/** Resend API base URL (default: https://api.resend.com) */
|
|
1229
|
+
baseUrl?: string;
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Resend Email Provider
|
|
1233
|
+
*/
|
|
1234
|
+
declare class ResendEmailProvider implements EmailProvider {
|
|
1235
|
+
private apiKey;
|
|
1236
|
+
private fromEmail;
|
|
1237
|
+
private fromName;
|
|
1238
|
+
private baseUrl;
|
|
1239
|
+
constructor(config: ResendProviderConfig);
|
|
1240
|
+
/**
|
|
1241
|
+
* Send email via Resend API
|
|
1242
|
+
*/
|
|
1243
|
+
sendEmail(options: EmailOptions): Promise<EmailResult>;
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* Create Resend email provider
|
|
1247
|
+
*/
|
|
1248
|
+
declare function createResendProvider(config: ResendProviderConfig): ResendEmailProvider;
|
|
1249
|
+
|
|
1250
|
+
/**
|
|
1251
|
+
* Email Service
|
|
1252
|
+
* Provides email sending functionality with templates
|
|
1253
|
+
*/
|
|
1254
|
+
|
|
1255
|
+
/**
|
|
1256
|
+
* Email Service
|
|
1257
|
+
* Singleton service for sending emails
|
|
1258
|
+
*/
|
|
1259
|
+
declare class EmailService {
|
|
1260
|
+
private provider;
|
|
1261
|
+
private fromEmail;
|
|
1262
|
+
private fromName;
|
|
1263
|
+
private devMode;
|
|
1264
|
+
constructor(config: EmailServiceConfig);
|
|
1265
|
+
/**
|
|
1266
|
+
* Send email
|
|
1267
|
+
*/
|
|
1268
|
+
sendEmail(options: EmailOptions): Promise<EmailResult>;
|
|
1269
|
+
/**
|
|
1270
|
+
* Send OTP verification email
|
|
1271
|
+
*/
|
|
1272
|
+
sendOTPEmail(options: OTPEmailOptions): Promise<EmailResult>;
|
|
1273
|
+
/**
|
|
1274
|
+
* Send email verification email
|
|
1275
|
+
*/
|
|
1276
|
+
sendVerificationEmail(options: VerificationEmailOptions): Promise<EmailResult>;
|
|
1277
|
+
/**
|
|
1278
|
+
* Send magic link email
|
|
1279
|
+
*/
|
|
1280
|
+
sendMagicLinkEmail(options: MagicLinkEmailOptions): Promise<EmailResult>;
|
|
1281
|
+
/**
|
|
1282
|
+
* Send welcome email
|
|
1283
|
+
*/
|
|
1284
|
+
sendWelcomeEmail(options: WelcomeEmailOptions): Promise<EmailResult>;
|
|
1285
|
+
/**
|
|
1286
|
+
* Send password reset email
|
|
1287
|
+
*/
|
|
1288
|
+
sendPasswordResetEmail(options: PasswordResetEmailOptions): Promise<EmailResult>;
|
|
1289
|
+
/**
|
|
1290
|
+
* Send invitation email
|
|
1291
|
+
*/
|
|
1292
|
+
sendInvitationEmail(options: InvitationEmailOptions): Promise<EmailResult>;
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Create email service
|
|
1296
|
+
*/
|
|
1297
|
+
declare function createEmailService(config: EmailServiceConfig): EmailService;
|
|
1298
|
+
|
|
1299
|
+
/**
|
|
1300
|
+
* NetGSM SMS Provider
|
|
1301
|
+
* Turkish SMS gateway provider
|
|
1302
|
+
*/
|
|
1303
|
+
|
|
1304
|
+
/**
|
|
1305
|
+
* NetGSM configuration
|
|
1306
|
+
*/
|
|
1307
|
+
interface NetGSMConfig {
|
|
1308
|
+
/** NetGSM username */
|
|
1309
|
+
username: string;
|
|
1310
|
+
/** NetGSM password */
|
|
1311
|
+
password: string;
|
|
1312
|
+
/** SMS header/sender ID */
|
|
1313
|
+
header: string;
|
|
1314
|
+
/** NetGSM API URL (default: https://api.netgsm.com.tr/sms/send/otp) */
|
|
1315
|
+
apiUrl?: string;
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* NetGSM SMS Provider
|
|
1319
|
+
*/
|
|
1320
|
+
declare class NetGSMProvider implements SMSProvider {
|
|
1321
|
+
private config;
|
|
1322
|
+
constructor(config: NetGSMConfig);
|
|
1323
|
+
/**
|
|
1324
|
+
* Send SMS via NetGSM API
|
|
1325
|
+
*/
|
|
1326
|
+
sendSMS(options: SMSOptions): Promise<SMSResult>;
|
|
1327
|
+
/**
|
|
1328
|
+
* Parse NetGSM XML response
|
|
1329
|
+
*/
|
|
1330
|
+
private parseResponse;
|
|
1331
|
+
/**
|
|
1332
|
+
* Get human-readable error message
|
|
1333
|
+
*/
|
|
1334
|
+
private getErrorMessage;
|
|
1335
|
+
/**
|
|
1336
|
+
* Escape XML special characters
|
|
1337
|
+
*/
|
|
1338
|
+
private escapeXml;
|
|
1339
|
+
/**
|
|
1340
|
+
* Sanitize phone number
|
|
1341
|
+
*/
|
|
1342
|
+
private sanitizePhoneNumber;
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Create NetGSM provider
|
|
1346
|
+
*/
|
|
1347
|
+
declare function createNetGSMProvider(config: NetGSMConfig): NetGSMProvider;
|
|
1348
|
+
|
|
1349
|
+
/**
|
|
1350
|
+
* SMS Service
|
|
1351
|
+
* Provides SMS sending functionality
|
|
1352
|
+
*/
|
|
1353
|
+
/**
|
|
1354
|
+
* SMS provider interface
|
|
1355
|
+
*/
|
|
1356
|
+
interface SMSProvider {
|
|
1357
|
+
/** Send an SMS */
|
|
1358
|
+
sendSMS(options: SMSOptions): Promise<SMSResult>;
|
|
1359
|
+
}
|
|
1360
|
+
/**
|
|
1361
|
+
* SMS options
|
|
1362
|
+
*/
|
|
1363
|
+
interface SMSOptions {
|
|
1364
|
+
/** Recipient phone number (E.164 format) */
|
|
1365
|
+
to: string;
|
|
1366
|
+
/** Message content */
|
|
1367
|
+
message: string;
|
|
1368
|
+
/** Sender ID (alphanumeric, max 11 chars) */
|
|
1369
|
+
from?: string;
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* SMS send result
|
|
1373
|
+
*/
|
|
1374
|
+
interface SMSResult {
|
|
1375
|
+
success: boolean;
|
|
1376
|
+
messageId?: string;
|
|
1377
|
+
error?: string;
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* SMS service configuration
|
|
1381
|
+
*/
|
|
1382
|
+
interface SMSServiceConfig {
|
|
1383
|
+
/** SMS provider instance */
|
|
1384
|
+
provider?: SMSProvider;
|
|
1385
|
+
/** Default sender ID */
|
|
1386
|
+
senderId?: string;
|
|
1387
|
+
/** Development mode (logs SMS instead of sending) */
|
|
1388
|
+
devMode?: boolean;
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* OTP SMS options
|
|
1392
|
+
*/
|
|
1393
|
+
interface OTPSMSOptions {
|
|
1394
|
+
/** Recipient phone number */
|
|
1395
|
+
phone: string;
|
|
1396
|
+
/** OTP code */
|
|
1397
|
+
code: string;
|
|
1398
|
+
/** Expiration in minutes (default: 10) */
|
|
1399
|
+
expiresInMinutes?: number;
|
|
1400
|
+
/** App name */
|
|
1401
|
+
appName?: string;
|
|
1402
|
+
}
|
|
1403
|
+
/**
|
|
1404
|
+
* SMS Service
|
|
1405
|
+
*/
|
|
1406
|
+
declare class SMSService {
|
|
1407
|
+
private provider;
|
|
1408
|
+
private senderId;
|
|
1409
|
+
private devMode;
|
|
1410
|
+
constructor(config: SMSServiceConfig);
|
|
1411
|
+
/**
|
|
1412
|
+
* Send SMS
|
|
1413
|
+
*/
|
|
1414
|
+
sendSMS(options: SMSOptions): Promise<SMSResult>;
|
|
1415
|
+
/**
|
|
1416
|
+
* Send OTP SMS
|
|
1417
|
+
*/
|
|
1418
|
+
sendOTPSMS(options: OTPSMSOptions): Promise<SMSResult>;
|
|
1419
|
+
}
|
|
1420
|
+
/**
|
|
1421
|
+
* Create SMS service
|
|
1422
|
+
*/
|
|
1423
|
+
declare function createSMSService(config: SMSServiceConfig): SMSService;
|
|
1424
|
+
|
|
1425
|
+
/**
|
|
1426
|
+
* Email Verification Service
|
|
1427
|
+
* Handles email verification tokens and status
|
|
1428
|
+
*/
|
|
1429
|
+
|
|
1430
|
+
/**
|
|
1431
|
+
* Email verification configuration
|
|
1432
|
+
*/
|
|
1433
|
+
interface EmailVerificationConfig {
|
|
1434
|
+
/** Base URL for verification links */
|
|
1435
|
+
baseUrl: string;
|
|
1436
|
+
/** Verification callback path (default: /auth/verify-email) */
|
|
1437
|
+
callbackPath?: string;
|
|
1438
|
+
/** Token expiration in seconds (default: 86400 = 24 hours) */
|
|
1439
|
+
expiresIn?: number;
|
|
1440
|
+
/** Token length in bytes (default: 32) */
|
|
1441
|
+
tokenLength?: number;
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* Request verification result
|
|
1445
|
+
*/
|
|
1446
|
+
interface RequestVerificationResult {
|
|
1447
|
+
success: boolean;
|
|
1448
|
+
token?: string;
|
|
1449
|
+
verificationUrl?: string;
|
|
1450
|
+
expiresAt?: Date;
|
|
1451
|
+
error?: string;
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Verify email result
|
|
1455
|
+
*/
|
|
1456
|
+
interface VerifyEmailResult {
|
|
1457
|
+
success: boolean;
|
|
1458
|
+
email?: string;
|
|
1459
|
+
error?: string;
|
|
1460
|
+
}
|
|
1461
|
+
/**
|
|
1462
|
+
* Verification status
|
|
1463
|
+
*/
|
|
1464
|
+
interface VerificationStatus {
|
|
1465
|
+
email: string;
|
|
1466
|
+
verified: boolean;
|
|
1467
|
+
pendingVerification: boolean;
|
|
1468
|
+
expiresAt?: Date;
|
|
1469
|
+
}
|
|
1470
|
+
/**
|
|
1471
|
+
* Email Verification Service
|
|
1472
|
+
*/
|
|
1473
|
+
declare class EmailVerificationService {
|
|
1474
|
+
private storage;
|
|
1475
|
+
private config;
|
|
1476
|
+
constructor(storage: KVStorage, config: EmailVerificationConfig);
|
|
1477
|
+
/**
|
|
1478
|
+
* Create verification token for an email
|
|
1479
|
+
*/
|
|
1480
|
+
createVerificationToken(email: string, options?: {
|
|
1481
|
+
createdBy?: string;
|
|
1482
|
+
}): Promise<RequestVerificationResult>;
|
|
1483
|
+
/**
|
|
1484
|
+
* Verify an email token
|
|
1485
|
+
*/
|
|
1486
|
+
verifyToken(token: string): Promise<VerifyEmailResult>;
|
|
1487
|
+
/**
|
|
1488
|
+
* Check verification status for an email
|
|
1489
|
+
*/
|
|
1490
|
+
getStatus(email: string): Promise<VerificationStatus>;
|
|
1491
|
+
/**
|
|
1492
|
+
* Resend verification email
|
|
1493
|
+
* Returns a new token for the same email
|
|
1494
|
+
*/
|
|
1495
|
+
resendVerification(email: string, options?: {
|
|
1496
|
+
createdBy?: string;
|
|
1497
|
+
}): Promise<RequestVerificationResult>;
|
|
1498
|
+
/**
|
|
1499
|
+
* Cancel pending verification
|
|
1500
|
+
*/
|
|
1501
|
+
cancelVerification(email: string): Promise<void>;
|
|
1502
|
+
/**
|
|
1503
|
+
* Delete token by hash
|
|
1504
|
+
*/
|
|
1505
|
+
private deleteToken;
|
|
1506
|
+
/**
|
|
1507
|
+
* Delete all tokens for an email
|
|
1508
|
+
*/
|
|
1509
|
+
private deleteTokensByEmail;
|
|
1510
|
+
}
|
|
1511
|
+
/**
|
|
1512
|
+
* Create email verification service
|
|
1513
|
+
*/
|
|
1514
|
+
declare function createEmailVerificationService(storage: KVStorage, config: EmailVerificationConfig): EmailVerificationService;
|
|
1515
|
+
|
|
1516
|
+
/**
|
|
1517
|
+
* @parsrun/auth - Passwordless-First Authentication
|
|
1518
|
+
*
|
|
1519
|
+
* A provider-based, multi-runtime authentication library.
|
|
1520
|
+
*
|
|
1521
|
+
* @example
|
|
1522
|
+
* ```typescript
|
|
1523
|
+
* import { createAuth } from '@parsrun/auth';
|
|
1524
|
+
*
|
|
1525
|
+
* const auth = createAuth({
|
|
1526
|
+
* secret: process.env.AUTH_SECRET,
|
|
1527
|
+
* adapter: myDatabaseAdapter,
|
|
1528
|
+
* providers: {
|
|
1529
|
+
* otp: {
|
|
1530
|
+
* email: {
|
|
1531
|
+
* send: async (to, code) => {
|
|
1532
|
+
* await sendEmail(to, `Your code is: ${code}`);
|
|
1533
|
+
* },
|
|
1534
|
+
* },
|
|
1535
|
+
* },
|
|
1536
|
+
* },
|
|
1537
|
+
* });
|
|
1538
|
+
*
|
|
1539
|
+
* await auth.initialize();
|
|
1540
|
+
*
|
|
1541
|
+
* // Request OTP
|
|
1542
|
+
* await auth.requestOTP({ identifier: 'user@example.com', type: 'email' });
|
|
1543
|
+
*
|
|
1544
|
+
* // Sign in with OTP
|
|
1545
|
+
* const result = await auth.signIn({
|
|
1546
|
+
* provider: 'otp',
|
|
1547
|
+
* identifier: 'user@example.com',
|
|
1548
|
+
* credential: '123456',
|
|
1549
|
+
* data: { type: 'email' },
|
|
1550
|
+
* });
|
|
1551
|
+
* ```
|
|
1552
|
+
*/
|
|
1553
|
+
|
|
1554
|
+
/**
|
|
1555
|
+
* Create a Pars Auth instance
|
|
1556
|
+
*
|
|
1557
|
+
* @param config - Auth configuration
|
|
1558
|
+
* @returns ParsAuth instance (must call initialize() before use)
|
|
1559
|
+
*
|
|
1560
|
+
* @example
|
|
1561
|
+
* ```typescript
|
|
1562
|
+
* const auth = createAuth({
|
|
1563
|
+
* secret: 'your-secret-key',
|
|
1564
|
+
* adapter: drizzleAdapter(db),
|
|
1565
|
+
* providers: {
|
|
1566
|
+
* otp: {
|
|
1567
|
+
* email: {
|
|
1568
|
+
* send: async (to, code) => sendEmail(to, code),
|
|
1569
|
+
* },
|
|
1570
|
+
* },
|
|
1571
|
+
* },
|
|
1572
|
+
* });
|
|
1573
|
+
*
|
|
1574
|
+
* await auth.initialize();
|
|
1575
|
+
* ```
|
|
1576
|
+
*/
|
|
1577
|
+
declare function createAuth(config: ParsAuthConfig): ParsAuthEngine;
|
|
1578
|
+
|
|
1579
|
+
export { type AppleConfig, AppleProvider, AuthAdapter, AuthInput, AuthProvider, AuthResult, type AuthenticationOptions, type AuthenticatorData, type ClientDataJSON, type DrizzleAdapterConfig, type DrizzleAuthMethod, type DrizzleAuthSchema, type DrizzleDatabase, type DrizzleEmailVerificationToken, type DrizzleRole, type DrizzleSession, type DrizzleTenant, type DrizzleTenantMembership, type DrizzleUser, type EmailAttachment, type EmailOptions, type EmailProvider, type EmailResult, EmailService, type EmailServiceConfig, type EmailVerificationConfig, EmailVerificationService, type GitHubConfig, GitHubProvider, type GoogleConfig, GoogleProvider, type InvitationEmailOptions, KVStorage, type MagicLinkEmailOptions, MagicLinkProvider, type MagicLinkConfig as MagicLinkProviderConfig, type MicrosoftConfig, MicrosoftProvider, type NetGSMConfig, NetGSMProvider, type OAuthCallbackResult, type OAuthConfig, type OAuthFlowResult, OAuthManager, type OAuthProviderName, type OAuthState, type OAuthTokens, type OAuthUserInfo as OAuthUser, type OTPEmailOptions, type OTPSMSOptions, ParsAuthConfig, ParsAuthEngine, PasswordProvider, type PasswordConfig as PasswordProviderConfig, type PasswordResetEmailOptions, type PasswordStrength, type PasswordValidationResult, ProviderInfo, type RegistrationOptions, type RequestVerificationResult, ResendEmailProvider, type Runtime, type SMSOptions, type SMSProvider, type SMSResult, SMSService, type SMSServiceConfig, type SendMagicLinkResult, TOTPProvider, type TOTPConfig as TOTPProviderConfig, type TOTPSetupData, type TOTPVerifyResult, TwoFactorProvider, TwoFactorSetupResult, type VerificationEmailOptions, type VerificationStatus, type VerifyEmailResult, type VerifyMagicLinkResult, type WebAuthnCredential, WebAuthnProvider, type WebAuthnConfig as WebAuthnProviderConfig, type WelcomeEmailOptions, base64UrlDecode, base64UrlEncode, bytesToHex, createAuth, createDrizzleAdapter, createEmailService, createEmailVerificationService, createMagicLinkProvider, createNetGSMProvider, createOAuthManager, createPasswordProvider, createResendProvider, createSMSService, createTOTPProvider, createWebAuthnProvider, detectRuntime, generatePKCE, generateRandomBase64Url, generateRandomHex, generateState, getEnv, hexToBytes, isBun, isCloudflare, isDeno, isEdge, isNode, randomInt, sha256, sha256Hex, timingSafeEqual, timingSafeEqualBytes };
|