@emdash-cms/auth 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/kysely.d.mts +62 -0
- package/dist/adapters/kysely.d.mts.map +1 -0
- package/dist/adapters/kysely.mjs +379 -0
- package/dist/adapters/kysely.mjs.map +1 -0
- package/dist/authenticate-D5UgaoTH.d.mts +124 -0
- package/dist/authenticate-D5UgaoTH.d.mts.map +1 -0
- package/dist/authenticate-j5GayLXB.mjs +373 -0
- package/dist/authenticate-j5GayLXB.mjs.map +1 -0
- package/dist/index.d.mts +444 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +728 -0
- package/dist/index.mjs.map +1 -0
- package/dist/oauth/providers/github.d.mts +12 -0
- package/dist/oauth/providers/github.d.mts.map +1 -0
- package/dist/oauth/providers/github.mjs +55 -0
- package/dist/oauth/providers/github.mjs.map +1 -0
- package/dist/oauth/providers/google.d.mts +7 -0
- package/dist/oauth/providers/google.d.mts.map +1 -0
- package/dist/oauth/providers/google.mjs +38 -0
- package/dist/oauth/providers/google.mjs.map +1 -0
- package/dist/passkey/index.d.mts +2 -0
- package/dist/passkey/index.mjs +3 -0
- package/dist/types-Bu4irX9A.d.mts +35 -0
- package/dist/types-Bu4irX9A.d.mts.map +1 -0
- package/dist/types-CiSNpRI9.mjs +60 -0
- package/dist/types-CiSNpRI9.mjs.map +1 -0
- package/dist/types-HtRc90Wi.d.mts +208 -0
- package/dist/types-HtRc90Wi.d.mts.map +1 -0
- package/package.json +72 -0
- package/src/adapters/kysely.ts +715 -0
- package/src/config.ts +214 -0
- package/src/index.ts +135 -0
- package/src/invite.ts +205 -0
- package/src/magic-link/index.ts +150 -0
- package/src/oauth/consumer.ts +324 -0
- package/src/oauth/providers/github.ts +68 -0
- package/src/oauth/providers/google.ts +34 -0
- package/src/oauth/types.ts +36 -0
- package/src/passkey/authenticate.ts +183 -0
- package/src/passkey/index.ts +27 -0
- package/src/passkey/register.ts +232 -0
- package/src/passkey/types.ts +120 -0
- package/src/rbac.test.ts +141 -0
- package/src/rbac.ts +205 -0
- package/src/signup.ts +210 -0
- package/src/tokens.test.ts +141 -0
- package/src/tokens.ts +238 -0
- package/src/types.ts +352 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
import { A as toDeviceType, C as TokenType, D as UserWithDetails, E as UserListItem, M as toTokenType, O as roleFromLevel, S as SessionData, T as User, _ as OAuthConnection, a as AuthToken, b as RoleName, c as DeviceType, d as NewAuthToken, f as NewCredential, g as OAuthClient, h as OAuthAccount, i as AuthErrorCode, j as toRoleLevel, k as roleToLevel, l as EmailAdapter, m as NewUser, n as AuthAdapter, o as AuthenticatorTransport, p as NewOAuthAccount, r as AuthError, s as Credential, t as AllowedDomain, u as EmailMessage, v as Role, w as UpdateUser, x as Session, y as RoleLevel } from "./types-HtRc90Wi.mjs";
|
|
2
|
+
import { a as registerPasskey, c as AuthenticationResponse, d as PasskeyConfig, f as RegistrationOptions, h as VerifiedRegistration, i as generateRegistrationOptions, l as ChallengeData, m as VerifiedAuthentication, n as generateAuthenticationOptions, o as verifyRegistrationResponse, p as RegistrationResponse, r as verifyAuthenticationResponse, s as AuthenticationOptions, t as authenticateWithPasskey, u as ChallengeStore } from "./authenticate-D5UgaoTH.mjs";
|
|
3
|
+
import { i as OAuthState, n as OAuthProfile, r as OAuthProvider, t as OAuthConfig } from "./types-Bu4irX9A.mjs";
|
|
4
|
+
import { github } from "./oauth/providers/github.mjs";
|
|
5
|
+
import { google } from "./oauth/providers/google.mjs";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
|
|
8
|
+
//#region src/config.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* Full auth configuration schema
|
|
11
|
+
*/
|
|
12
|
+
declare const authConfigSchema: z.ZodObject<{
|
|
13
|
+
secret: z.ZodString;
|
|
14
|
+
passkeys: z.ZodOptional<z.ZodObject<{
|
|
15
|
+
rpName: z.ZodString;
|
|
16
|
+
rpId: z.ZodOptional<z.ZodString>;
|
|
17
|
+
}, z.core.$strip>>;
|
|
18
|
+
selfSignup: z.ZodOptional<z.ZodObject<{
|
|
19
|
+
domains: z.ZodArray<z.ZodString>;
|
|
20
|
+
defaultRole: z.ZodDefault<z.ZodEnum<{
|
|
21
|
+
subscriber: "subscriber";
|
|
22
|
+
contributor: "contributor";
|
|
23
|
+
author: "author";
|
|
24
|
+
}>>;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
oauth: z.ZodOptional<z.ZodObject<{
|
|
27
|
+
github: z.ZodOptional<z.ZodObject<{
|
|
28
|
+
clientId: z.ZodString;
|
|
29
|
+
clientSecret: z.ZodString;
|
|
30
|
+
}, z.core.$strip>>;
|
|
31
|
+
google: z.ZodOptional<z.ZodObject<{
|
|
32
|
+
clientId: z.ZodString;
|
|
33
|
+
clientSecret: z.ZodString;
|
|
34
|
+
}, z.core.$strip>>;
|
|
35
|
+
}, z.core.$strip>>;
|
|
36
|
+
provider: z.ZodOptional<z.ZodObject<{
|
|
37
|
+
enabled: z.ZodBoolean;
|
|
38
|
+
issuer: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, z.core.$strip>>;
|
|
40
|
+
sso: z.ZodOptional<z.ZodObject<{
|
|
41
|
+
enabled: z.ZodBoolean;
|
|
42
|
+
}, z.core.$strip>>;
|
|
43
|
+
session: z.ZodOptional<z.ZodObject<{
|
|
44
|
+
maxAge: z.ZodDefault<z.ZodNumber>;
|
|
45
|
+
sliding: z.ZodDefault<z.ZodBoolean>;
|
|
46
|
+
}, z.core.$strip>>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
type AuthConfig = z.infer<typeof authConfigSchema>;
|
|
49
|
+
/**
|
|
50
|
+
* Validated and resolved auth configuration
|
|
51
|
+
*/
|
|
52
|
+
interface ResolvedAuthConfig {
|
|
53
|
+
secret: string;
|
|
54
|
+
baseUrl: string;
|
|
55
|
+
siteName: string;
|
|
56
|
+
passkeys: {
|
|
57
|
+
rpName: string;
|
|
58
|
+
rpId: string;
|
|
59
|
+
origin: string;
|
|
60
|
+
};
|
|
61
|
+
selfSignup?: {
|
|
62
|
+
domains: string[];
|
|
63
|
+
defaultRole: RoleName;
|
|
64
|
+
};
|
|
65
|
+
oauth?: {
|
|
66
|
+
github?: {
|
|
67
|
+
clientId: string;
|
|
68
|
+
clientSecret: string;
|
|
69
|
+
};
|
|
70
|
+
google?: {
|
|
71
|
+
clientId: string;
|
|
72
|
+
clientSecret: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
provider?: {
|
|
76
|
+
enabled: boolean;
|
|
77
|
+
issuer: string;
|
|
78
|
+
};
|
|
79
|
+
sso?: {
|
|
80
|
+
enabled: boolean;
|
|
81
|
+
};
|
|
82
|
+
session: {
|
|
83
|
+
maxAge: number;
|
|
84
|
+
sliding: boolean;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Resolve auth configuration with defaults
|
|
89
|
+
*/
|
|
90
|
+
declare function resolveConfig(config: AuthConfig, baseUrl: string, siteName: string): ResolvedAuthConfig;
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/tokens.d.ts
|
|
93
|
+
/**
|
|
94
|
+
* Secure token utilities
|
|
95
|
+
*
|
|
96
|
+
* Crypto via Oslo.js (@oslojs/crypto). Base64url via @oslojs/encoding.
|
|
97
|
+
*
|
|
98
|
+
* Tokens are opaque random values. We store only the SHA-256 hash in the database.
|
|
99
|
+
*/
|
|
100
|
+
/** Valid API token prefixes */
|
|
101
|
+
declare const TOKEN_PREFIXES: {
|
|
102
|
+
readonly PAT: "ec_pat_";
|
|
103
|
+
readonly OAUTH_ACCESS: "ec_oat_";
|
|
104
|
+
readonly OAUTH_REFRESH: "ec_ort_";
|
|
105
|
+
};
|
|
106
|
+
/** All valid API token scopes */
|
|
107
|
+
declare const VALID_SCOPES: readonly ["content:read", "content:write", "media:read", "media:write", "schema:read", "schema:write", "admin"];
|
|
108
|
+
type ApiTokenScope = (typeof VALID_SCOPES)[number];
|
|
109
|
+
/**
|
|
110
|
+
* Validate that scopes are all valid.
|
|
111
|
+
* Returns the invalid scopes, or empty array if all valid.
|
|
112
|
+
*/
|
|
113
|
+
declare function validateScopes(scopes: string[]): string[];
|
|
114
|
+
/**
|
|
115
|
+
* Check if a set of scopes includes a required scope.
|
|
116
|
+
* The `admin` scope grants access to everything.
|
|
117
|
+
*/
|
|
118
|
+
declare function hasScope(scopes: string[], required: string): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Generate a cryptographically secure random token
|
|
121
|
+
* Returns base64url-encoded string (URL-safe)
|
|
122
|
+
*/
|
|
123
|
+
declare function generateToken(): string;
|
|
124
|
+
/**
|
|
125
|
+
* Hash a token for storage
|
|
126
|
+
* We never store raw tokens - only their SHA-256 hash
|
|
127
|
+
*/
|
|
128
|
+
declare function hashToken(token: string): string;
|
|
129
|
+
/**
|
|
130
|
+
* Generate a token and its hash together
|
|
131
|
+
*/
|
|
132
|
+
declare function generateTokenWithHash(): {
|
|
133
|
+
token: string;
|
|
134
|
+
hash: string;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Generate a session ID (shorter, for cookie storage)
|
|
138
|
+
*/
|
|
139
|
+
declare function generateSessionId(): string;
|
|
140
|
+
/**
|
|
141
|
+
* Generate an auth secret for configuration
|
|
142
|
+
*/
|
|
143
|
+
declare function generateAuthSecret(): string;
|
|
144
|
+
/**
|
|
145
|
+
* Generate a prefixed API token and its hash.
|
|
146
|
+
* Returns the raw token (shown once to the user), the hash (stored server-side),
|
|
147
|
+
* and a display prefix (for identification in UIs/logs).
|
|
148
|
+
*
|
|
149
|
+
* Uses oslo/crypto for SHA-256 hashing.
|
|
150
|
+
*/
|
|
151
|
+
declare function generatePrefixedToken(prefix: string): {
|
|
152
|
+
raw: string;
|
|
153
|
+
hash: string;
|
|
154
|
+
prefix: string;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Hash a prefixed API token for storage/lookup.
|
|
158
|
+
* Hashes the full prefixed token string via SHA-256, returns base64url (no padding).
|
|
159
|
+
*/
|
|
160
|
+
declare function hashPrefixedToken(token: string): string;
|
|
161
|
+
/**
|
|
162
|
+
* Compute an S256 PKCE code challenge from a code verifier.
|
|
163
|
+
* Used server-side to verify that code_verifier matches the stored code_challenge.
|
|
164
|
+
*
|
|
165
|
+
* Equivalent to: BASE64URL(SHA256(ASCII(code_verifier)))
|
|
166
|
+
*/
|
|
167
|
+
declare function computeS256Challenge(codeVerifier: string): string;
|
|
168
|
+
/**
|
|
169
|
+
* Constant-time comparison to prevent timing attacks
|
|
170
|
+
*/
|
|
171
|
+
declare function secureCompare(a: string, b: string): boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Encrypt a value using AES-GCM
|
|
174
|
+
*/
|
|
175
|
+
declare function encrypt(plaintext: string, secret: string): Promise<string>;
|
|
176
|
+
/**
|
|
177
|
+
* Decrypt a value encrypted with encrypt()
|
|
178
|
+
*/
|
|
179
|
+
declare function decrypt(encrypted: string, secret: string): Promise<string>;
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/rbac.d.ts
|
|
182
|
+
/**
|
|
183
|
+
* Permission definitions with minimum role required
|
|
184
|
+
*/
|
|
185
|
+
declare const Permissions: {
|
|
186
|
+
readonly "content:read": 10;
|
|
187
|
+
readonly "content:create": 20;
|
|
188
|
+
readonly "content:edit_own": 30;
|
|
189
|
+
readonly "content:edit_any": 40;
|
|
190
|
+
readonly "content:delete_own": 30;
|
|
191
|
+
readonly "content:delete_any": 40;
|
|
192
|
+
readonly "content:publish_own": 30;
|
|
193
|
+
readonly "content:publish_any": 40;
|
|
194
|
+
readonly "media:read": 10;
|
|
195
|
+
readonly "media:upload": 20;
|
|
196
|
+
readonly "media:edit_own": 30;
|
|
197
|
+
readonly "media:edit_any": 40;
|
|
198
|
+
readonly "media:delete_own": 30;
|
|
199
|
+
readonly "media:delete_any": 40;
|
|
200
|
+
readonly "taxonomies:read": 10;
|
|
201
|
+
readonly "taxonomies:manage": 40;
|
|
202
|
+
readonly "comments:read": 10;
|
|
203
|
+
readonly "comments:moderate": 40;
|
|
204
|
+
readonly "comments:delete": 50;
|
|
205
|
+
readonly "comments:settings": 50;
|
|
206
|
+
readonly "menus:read": 10;
|
|
207
|
+
readonly "menus:manage": 40;
|
|
208
|
+
readonly "widgets:read": 10;
|
|
209
|
+
readonly "widgets:manage": 40;
|
|
210
|
+
readonly "sections:read": 10;
|
|
211
|
+
readonly "sections:manage": 40;
|
|
212
|
+
readonly "redirects:read": 40;
|
|
213
|
+
readonly "redirects:manage": 50;
|
|
214
|
+
readonly "users:read": 50;
|
|
215
|
+
readonly "users:invite": 50;
|
|
216
|
+
readonly "users:manage": 50;
|
|
217
|
+
readonly "settings:read": 40;
|
|
218
|
+
readonly "settings:manage": 50;
|
|
219
|
+
readonly "schema:read": 40;
|
|
220
|
+
readonly "schema:manage": 50;
|
|
221
|
+
readonly "plugins:read": 40;
|
|
222
|
+
readonly "plugins:manage": 50;
|
|
223
|
+
readonly "import:execute": 50;
|
|
224
|
+
readonly "search:read": 10;
|
|
225
|
+
readonly "search:manage": 50;
|
|
226
|
+
readonly "auth:manage_own_credentials": 10;
|
|
227
|
+
readonly "auth:manage_connections": 50;
|
|
228
|
+
};
|
|
229
|
+
type Permission = keyof typeof Permissions;
|
|
230
|
+
/**
|
|
231
|
+
* Check if a user has a specific permission
|
|
232
|
+
*/
|
|
233
|
+
declare function hasPermission(user: {
|
|
234
|
+
role: RoleLevel;
|
|
235
|
+
} | null | undefined, permission: Permission): boolean;
|
|
236
|
+
/**
|
|
237
|
+
* Require a permission, throwing if not met
|
|
238
|
+
*/
|
|
239
|
+
declare function requirePermission(user: {
|
|
240
|
+
role: RoleLevel;
|
|
241
|
+
} | null | undefined, permission: Permission): asserts user is {
|
|
242
|
+
role: RoleLevel;
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* Check if user can perform action on a resource they own
|
|
246
|
+
*/
|
|
247
|
+
declare function canActOnOwn(user: {
|
|
248
|
+
role: RoleLevel;
|
|
249
|
+
id: string;
|
|
250
|
+
} | null | undefined, ownerId: string, ownPermission: Permission, anyPermission: Permission): boolean;
|
|
251
|
+
/**
|
|
252
|
+
* Require permission on a resource, checking ownership
|
|
253
|
+
*/
|
|
254
|
+
declare function requirePermissionOnResource(user: {
|
|
255
|
+
role: RoleLevel;
|
|
256
|
+
id: string;
|
|
257
|
+
} | null | undefined, ownerId: string, ownPermission: Permission, anyPermission: Permission): asserts user is {
|
|
258
|
+
role: RoleLevel;
|
|
259
|
+
id: string;
|
|
260
|
+
};
|
|
261
|
+
declare class PermissionError extends Error {
|
|
262
|
+
code: "unauthorized" | "forbidden";
|
|
263
|
+
constructor(code: "unauthorized" | "forbidden", message: string);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Return the maximum set of API token scopes a given role level may hold.
|
|
267
|
+
*
|
|
268
|
+
* Used at token issuance time (device flow, authorization code exchange)
|
|
269
|
+
* to enforce: effective_scopes = requested_scopes ∩ scopesForRole(role).
|
|
270
|
+
*/
|
|
271
|
+
declare function scopesForRole(role: RoleLevel): ApiTokenScope[];
|
|
272
|
+
/**
|
|
273
|
+
* Clamp a set of requested scopes to those permitted by a user's role.
|
|
274
|
+
*
|
|
275
|
+
* Returns the intersection of `requested` and the scopes the role allows.
|
|
276
|
+
* This is the central policy enforcement point: effective permissions =
|
|
277
|
+
* role permissions ∩ token scopes.
|
|
278
|
+
*/
|
|
279
|
+
declare function clampScopes(requested: string[], role: RoleLevel): string[];
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/magic-link/index.d.ts
|
|
282
|
+
/** Function that sends an email (matches the EmailPipeline.send signature) */
|
|
283
|
+
type EmailSendFn$2 = (message: EmailMessage) => Promise<void>;
|
|
284
|
+
interface MagicLinkConfig {
|
|
285
|
+
baseUrl: string;
|
|
286
|
+
siteName: string;
|
|
287
|
+
/** Optional email sender. When omitted, magic links cannot be sent. */
|
|
288
|
+
email?: EmailSendFn$2;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Send a magic link to a user's email.
|
|
292
|
+
*
|
|
293
|
+
* Requires `config.email` to be set. Throws if no email sender is configured.
|
|
294
|
+
*/
|
|
295
|
+
declare function sendMagicLink(config: MagicLinkConfig, adapter: AuthAdapter, email: string, type?: "magic_link" | "recovery"): Promise<void>;
|
|
296
|
+
/**
|
|
297
|
+
* Verify a magic link token and return the user
|
|
298
|
+
*/
|
|
299
|
+
declare function verifyMagicLink(adapter: AuthAdapter, token: string): Promise<User>;
|
|
300
|
+
declare class MagicLinkError extends Error {
|
|
301
|
+
code: "invalid_token" | "token_expired" | "user_not_found" | "email_not_configured";
|
|
302
|
+
constructor(code: "invalid_token" | "token_expired" | "user_not_found" | "email_not_configured", message: string);
|
|
303
|
+
}
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region src/invite.d.ts
|
|
306
|
+
/** Escape HTML special characters to prevent injection in email templates */
|
|
307
|
+
declare function escapeHtml(s: string): string;
|
|
308
|
+
/** Function that sends an email (matches the EmailPipeline.send signature) */
|
|
309
|
+
type EmailSendFn = (message: EmailMessage) => Promise<void>;
|
|
310
|
+
interface InviteConfig {
|
|
311
|
+
baseUrl: string;
|
|
312
|
+
siteName: string;
|
|
313
|
+
/** Optional email sender. When omitted, invite URL is returned without sending. */
|
|
314
|
+
email?: EmailSendFn;
|
|
315
|
+
}
|
|
316
|
+
/** Result of creating an invite token (without sending email) */
|
|
317
|
+
interface InviteTokenResult {
|
|
318
|
+
/** The complete invite URL */
|
|
319
|
+
url: string;
|
|
320
|
+
/** The invite email address */
|
|
321
|
+
email: string;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Create an invite token and URL without sending email.
|
|
325
|
+
*
|
|
326
|
+
* Validates the user doesn't already exist, generates a token, stores it,
|
|
327
|
+
* and returns the invite URL. Callers decide whether to send email or
|
|
328
|
+
* display the URL as a copy-link fallback.
|
|
329
|
+
*/
|
|
330
|
+
declare function createInviteToken(config: Pick<InviteConfig, "baseUrl">, adapter: AuthAdapter, email: string, role: RoleLevel, invitedBy: string): Promise<InviteTokenResult>;
|
|
331
|
+
/**
|
|
332
|
+
* Create and send an invite to a new user.
|
|
333
|
+
*
|
|
334
|
+
* When `config.email` is provided, sends the invite email.
|
|
335
|
+
* When omitted, creates the token and returns the invite URL
|
|
336
|
+
* without sending (for the copy-link fallback).
|
|
337
|
+
*/
|
|
338
|
+
declare function createInvite(config: InviteConfig, adapter: AuthAdapter, email: string, role: RoleLevel, invitedBy: string): Promise<InviteTokenResult>;
|
|
339
|
+
/**
|
|
340
|
+
* Validate an invite token and return the invite data
|
|
341
|
+
*/
|
|
342
|
+
declare function validateInvite(adapter: AuthAdapter, token: string): Promise<{
|
|
343
|
+
email: string;
|
|
344
|
+
role: RoleLevel;
|
|
345
|
+
}>;
|
|
346
|
+
/**
|
|
347
|
+
* Complete the invite process (after passkey registration)
|
|
348
|
+
*/
|
|
349
|
+
declare function completeInvite(adapter: AuthAdapter, token: string, userData: {
|
|
350
|
+
name?: string;
|
|
351
|
+
avatarUrl?: string;
|
|
352
|
+
}): Promise<User>;
|
|
353
|
+
declare class InviteError extends Error {
|
|
354
|
+
code: "invalid_token" | "token_expired" | "user_exists";
|
|
355
|
+
constructor(code: "invalid_token" | "token_expired" | "user_exists", message: string);
|
|
356
|
+
}
|
|
357
|
+
//#endregion
|
|
358
|
+
//#region src/signup.d.ts
|
|
359
|
+
/** Function that sends an email (matches the EmailPipeline.send signature) */
|
|
360
|
+
type EmailSendFn$1 = (message: EmailMessage) => Promise<void>;
|
|
361
|
+
interface SignupConfig {
|
|
362
|
+
baseUrl: string;
|
|
363
|
+
siteName: string;
|
|
364
|
+
/** Optional email sender. When omitted, signup verification cannot be sent. */
|
|
365
|
+
email?: EmailSendFn$1;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Check if an email domain is allowed for self-signup
|
|
369
|
+
*/
|
|
370
|
+
declare function canSignup(adapter: AuthAdapter, email: string): Promise<{
|
|
371
|
+
allowed: boolean;
|
|
372
|
+
role: RoleLevel;
|
|
373
|
+
} | null>;
|
|
374
|
+
/**
|
|
375
|
+
* Request self-signup (sends verification email).
|
|
376
|
+
*
|
|
377
|
+
* Requires `config.email` to be set. Throws if no email sender is configured.
|
|
378
|
+
*/
|
|
379
|
+
declare function requestSignup(config: SignupConfig, adapter: AuthAdapter, email: string): Promise<void>;
|
|
380
|
+
/**
|
|
381
|
+
* Validate a signup verification token
|
|
382
|
+
*/
|
|
383
|
+
declare function validateSignupToken(adapter: AuthAdapter, token: string): Promise<{
|
|
384
|
+
email: string;
|
|
385
|
+
role: RoleLevel;
|
|
386
|
+
}>;
|
|
387
|
+
/**
|
|
388
|
+
* Complete signup process (after passkey registration)
|
|
389
|
+
*/
|
|
390
|
+
declare function completeSignup(adapter: AuthAdapter, token: string, userData: {
|
|
391
|
+
name?: string;
|
|
392
|
+
avatarUrl?: string;
|
|
393
|
+
}): Promise<User>;
|
|
394
|
+
declare class SignupError extends Error {
|
|
395
|
+
code: "invalid_token" | "token_expired" | "user_exists" | "domain_not_allowed" | "email_not_configured";
|
|
396
|
+
constructor(code: "invalid_token" | "token_expired" | "user_exists" | "domain_not_allowed" | "email_not_configured", message: string);
|
|
397
|
+
}
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region src/oauth/consumer.d.ts
|
|
400
|
+
interface OAuthConsumerConfig {
|
|
401
|
+
baseUrl: string;
|
|
402
|
+
providers: {
|
|
403
|
+
github?: OAuthConfig;
|
|
404
|
+
google?: OAuthConfig;
|
|
405
|
+
};
|
|
406
|
+
/**
|
|
407
|
+
* Check if self-signup is allowed for this email domain
|
|
408
|
+
*/
|
|
409
|
+
canSelfSignup?: (email: string) => Promise<{
|
|
410
|
+
allowed: boolean;
|
|
411
|
+
role: RoleLevel;
|
|
412
|
+
} | null>;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Generate an OAuth authorization URL
|
|
416
|
+
*/
|
|
417
|
+
declare function createAuthorizationUrl(config: OAuthConsumerConfig, providerName: "github" | "google", stateStore: StateStore): Promise<{
|
|
418
|
+
url: string;
|
|
419
|
+
state: string;
|
|
420
|
+
}>;
|
|
421
|
+
/**
|
|
422
|
+
* Handle OAuth callback
|
|
423
|
+
*/
|
|
424
|
+
declare function handleOAuthCallback(config: OAuthConsumerConfig, adapter: AuthAdapter, providerName: "github" | "google", code: string, state: string, stateStore: StateStore): Promise<User>;
|
|
425
|
+
interface StateStore {
|
|
426
|
+
set(state: string, data: OAuthState): Promise<void>;
|
|
427
|
+
get(state: string): Promise<OAuthState | null>;
|
|
428
|
+
delete(state: string): Promise<void>;
|
|
429
|
+
}
|
|
430
|
+
declare class OAuthError extends Error {
|
|
431
|
+
code: "invalid_state" | "token_exchange_failed" | "profile_fetch_failed" | "user_not_found" | "signup_not_allowed";
|
|
432
|
+
constructor(code: "invalid_state" | "token_exchange_failed" | "profile_fetch_failed" | "user_not_found" | "signup_not_allowed", message: string);
|
|
433
|
+
}
|
|
434
|
+
//#endregion
|
|
435
|
+
//#region src/index.d.ts
|
|
436
|
+
/**
|
|
437
|
+
* Create an auth configuration
|
|
438
|
+
*
|
|
439
|
+
* This is a helper function that validates the config at runtime.
|
|
440
|
+
*/
|
|
441
|
+
declare function auth(config: AuthConfig): AuthConfig;
|
|
442
|
+
//#endregion
|
|
443
|
+
export { AllowedDomain, type ApiTokenScope, AuthAdapter, type AuthConfig, AuthError, AuthErrorCode, AuthToken, AuthenticationOptions, AuthenticationResponse, AuthenticatorTransport, ChallengeData, ChallengeStore, Credential, DeviceType, type EmailAdapter, type EmailMessage, type EmailSendFn, type InviteConfig, InviteError, type InviteTokenResult, type MagicLinkConfig, MagicLinkError, NewAuthToken, NewCredential, NewOAuthAccount, NewUser, OAuthAccount, OAuthClient, type OAuthConfig, OAuthConnection, type OAuthConsumerConfig, OAuthError, type OAuthProfile, type OAuthProvider, type OAuthState, PasskeyConfig, type Permission, PermissionError, Permissions, RegistrationOptions, RegistrationResponse, type ResolvedAuthConfig, Role, RoleLevel, RoleName, Session, SessionData, type SignupConfig, SignupError, type StateStore, TOKEN_PREFIXES, TokenType, UpdateUser, User, UserListItem, UserWithDetails, VALID_SCOPES, VerifiedAuthentication, VerifiedRegistration, auth, authConfigSchema, authenticateWithPasskey, canActOnOwn, canSignup, clampScopes, completeInvite, completeSignup, computeS256Challenge, createAuthorizationUrl, createInvite, createInviteToken, decrypt, encrypt, escapeHtml, generateAuthSecret, generateAuthenticationOptions, generatePrefixedToken, generateRegistrationOptions, generateSessionId, generateToken, generateTokenWithHash, github, google, handleOAuthCallback, hasPermission, hasScope, hashPrefixedToken, hashToken, registerPasskey, requestSignup, requirePermission, requirePermissionOnResource, resolveConfig, roleFromLevel, roleToLevel, scopesForRole, secureCompare, sendMagicLink, toDeviceType, toRoleLevel, toTokenType, validateInvite, validateScopes, validateSignupToken, verifyAuthenticationResponse, verifyMagicLink, verifyRegistrationResponse };
|
|
444
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/config.ts","../src/tokens.ts","../src/rbac.ts","../src/magic-link/index.ts","../src/invite.ts","../src/signup.ts","../src/oauth/consumer.ts","../src/index.ts"],"mappings":";;;;;;;;;;;cA4Ba,gBAAA,EAAgB,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAwFjB,UAAA,GAAa,CAAA,CAAE,KAAA,QAAa,gBAAA;;;;UAKvB,kBAAA;EAChB,MAAA;EACA,OAAA;EACA,QAAA;EAEA,QAAA;IACC,MAAA;IACA,IAAA;IACA,MAAA;EAAA;EAGD,UAAA;IACC,OAAA;IACA,WAAA,EAAa,QAAA;EAAA;EAGd,KAAA;IACC,MAAA;MACC,QAAA;MACA,YAAA;IAAA;IAED,MAAA;MACC,QAAA;MACA,YAAA;IAAA;EAAA;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