@auth-gate/core 0.14.0 → 0.15.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/index.d.cts CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/types.d.ts
1
2
  /**
2
3
  * The authenticated user object returned after successful authentication.
3
4
  *
@@ -9,18 +10,18 @@
9
10
  * and `picture`, etc.
10
11
  */
11
12
  interface AuthGateUser {
12
- /** Unique user identifier assigned by AuthGate. */
13
- id: string;
14
- /** User's email address. Present for email/OAuth flows, `null` for SMS-only users. */
15
- email: string | null;
16
- /** User's phone number in E.164 format. Present for SMS flows, `null` otherwise. */
17
- phone: string | null;
18
- /** User's display name from the OAuth provider or signup form. */
19
- name: string | null;
20
- /** URL to the user's profile picture from the OAuth provider. */
21
- picture: string | null;
22
- /** The authentication provider used (e.g. `"google"`, `"github"`, `"email"`, `"sms"`). */
23
- provider: string;
13
+ /** Unique user identifier assigned by AuthGate. */
14
+ id: string;
15
+ /** User's email address. Present for email/OAuth flows, `null` for SMS-only users. */
16
+ email: string | null;
17
+ /** User's phone number in E.164 format. Present for SMS flows, `null` otherwise. */
18
+ phone: string | null;
19
+ /** User's display name from the OAuth provider or signup form. */
20
+ name: string | null;
21
+ /** URL to the user's profile picture from the OAuth provider. */
22
+ picture: string | null;
23
+ /** The authentication provider used (e.g. `"google"`, `"github"`, `"email"`, `"sms"`). */
24
+ provider: string;
24
25
  }
25
26
  /**
26
27
  * Result of verifying a JWT token against the AuthGate API.
@@ -29,14 +30,14 @@ interface AuthGateUser {
29
30
  * When `valid` is `false`, `error` describes why verification failed.
30
31
  */
31
32
  interface TokenVerifyResult {
32
- /** Whether the token is valid and not expired. */
33
- valid: boolean;
34
- /** The authenticated user, present when `valid` is `true`. */
35
- user?: AuthGateUser;
36
- /** ISO 8601 timestamp when the token expires, present when `valid` is `true`. */
37
- expiresAt?: string;
38
- /** Human-readable error message, present when `valid` is `false`. */
39
- error?: string;
33
+ /** Whether the token is valid and not expired. */
34
+ valid: boolean;
35
+ /** The authenticated user, present when `valid` is `true`. */
36
+ user?: AuthGateUser;
37
+ /** ISO 8601 timestamp when the token expires, present when `valid` is `true`. */
38
+ expiresAt?: string;
39
+ /** Human-readable error message, present when `valid` is `false`. */
40
+ error?: string;
40
41
  }
41
42
  /**
42
43
  * Configuration for initializing an {@link AuthGateClient}.
@@ -52,54 +53,54 @@ interface TokenVerifyResult {
52
53
  * ```
53
54
  */
54
55
  interface AuthGateConfig {
55
- /** Server-side API key for your AuthGate project. Found in the dashboard under API Key. */
56
- apiKey: string;
57
- /** Base URL of the AuthGate service (e.g. `"https://www.authgate.dev"`). */
58
- baseUrl: string;
59
- /**
60
- * Name of the session cookie.
61
- * @defaultValue `"__authgate"`
62
- */
63
- cookieName?: string;
64
- /**
65
- * Session lifetime in seconds. Controls how long the encrypted session cookie
66
- * and refresh token remain valid.
67
- * @defaultValue `604800` (7 days)
68
- */
69
- sessionMaxAge?: number;
70
- /**
71
- * Path where the OAuth callback handler is mounted.
72
- * @defaultValue `"/api/auth/callback"`
73
- */
74
- callbackPath?: string;
56
+ /** Server-side API key for your AuthGate project. Found in the dashboard under API Key. */
57
+ apiKey: string;
58
+ /** Base URL of the AuthGate service (e.g. `"https://www.authgate.dev"`). */
59
+ baseUrl: string;
60
+ /**
61
+ * Name of the session cookie.
62
+ * @defaultValue `"__authgate"`
63
+ */
64
+ cookieName?: string;
65
+ /**
66
+ * Session lifetime in seconds. Controls how long the encrypted session cookie
67
+ * and refresh token remain valid.
68
+ * @defaultValue `604800` (7 days)
69
+ */
70
+ sessionMaxAge?: number;
71
+ /**
72
+ * Path where the OAuth callback handler is mounted.
73
+ * @defaultValue `"/api/auth/callback"`
74
+ */
75
+ callbackPath?: string;
75
76
  }
76
77
  /**
77
78
  * Internal payload structure stored inside the encrypted session cookie.
78
79
  * Contains the user data plus issued-at and expiration timestamps.
79
80
  */
80
81
  interface SessionPayload {
81
- /** The authenticated user data. */
82
- user: AuthGateUser;
83
- /** Unix timestamp (seconds) when the session was created. */
84
- iat: number;
85
- /** Unix timestamp (seconds) when the session expires. */
86
- exp: number;
82
+ /** The authenticated user data. */
83
+ user: AuthGateUser;
84
+ /** Unix timestamp (seconds) when the session was created. */
85
+ iat: number;
86
+ /** Unix timestamp (seconds) when the session expires. */
87
+ exp: number;
87
88
  }
88
89
  /**
89
90
  * Options for configuring HTTP cookies set by AuthGate.
90
91
  * Maps directly to standard `Set-Cookie` attributes.
91
92
  */
92
93
  interface CookieOptions {
93
- /** Prevents client-side JavaScript from reading the cookie. */
94
- httpOnly: boolean;
95
- /** Only send the cookie over HTTPS connections. */
96
- secure: boolean;
97
- /** Controls when the cookie is sent with cross-site requests. */
98
- sameSite: "lax" | "strict" | "none";
99
- /** Cookie lifetime in seconds. */
100
- maxAge: number;
101
- /** URL path the cookie is valid for. */
102
- path: string;
94
+ /** Prevents client-side JavaScript from reading the cookie. */
95
+ httpOnly: boolean;
96
+ /** Only send the cookie over HTTPS connections. */
97
+ secure: boolean;
98
+ /** Controls when the cookie is sent with cross-site requests. */
99
+ sameSite: "lax" | "strict" | "none";
100
+ /** Cookie lifetime in seconds. */
101
+ maxAge: number;
102
+ /** URL path the cookie is valid for. */
103
+ path: string;
103
104
  }
104
105
  /**
105
106
  * Supported OAuth provider identifiers.
@@ -114,36 +115,36 @@ type OAuthProvider = "google" | "github" | "discord" | "azure" | "apple";
114
115
  * passing the `mfa_challenge` token and available `mfa_methods`.
115
116
  */
116
117
  interface MfaChallengeResponse {
117
- /** Always `true` — indicates MFA is required to complete authentication. */
118
- mfa_required: true;
119
- /** Opaque challenge token to pass to the MFA verify endpoint. */
120
- mfa_challenge: string;
121
- /** List of MFA methods the user has enrolled (e.g. `["totp", "sms"]`). */
122
- mfa_methods: string[];
118
+ /** Always `true` — indicates MFA is required to complete authentication. */
119
+ mfa_required: true;
120
+ /** Opaque challenge token to pass to the MFA verify endpoint. */
121
+ mfa_challenge: string;
122
+ /** List of MFA methods the user has enrolled (e.g. `["totp", "sms"]`). */
123
+ mfa_methods: string[];
123
124
  }
124
125
  /**
125
126
  * Current MFA enrollment status for a user.
126
127
  * Returned by the `/api/proxy/mfa/status` endpoint.
127
128
  */
128
129
  interface MfaStatus {
129
- /** Whether the user has any MFA method enrolled. */
130
- enrolled: boolean;
131
- /** List of enrolled MFA methods (e.g. `["totp"]`, `["sms", "totp"]`). */
132
- methods: string[];
133
- /** Whether MFA is required by the project's policy. */
134
- required: boolean;
130
+ /** Whether the user has any MFA method enrolled. */
131
+ enrolled: boolean;
132
+ /** List of enrolled MFA methods (e.g. `["totp"]`, `["sms", "totp"]`). */
133
+ methods: string[];
134
+ /** Whether MFA is required by the project's policy. */
135
+ required: boolean;
135
136
  }
136
137
  /**
137
138
  * Response from TOTP setup containing the secret and QR code.
138
139
  * Returned by the `/api/proxy/mfa/totp/setup` endpoint.
139
140
  */
140
141
  interface TotpSetupResponse {
141
- /** Base32-encoded TOTP secret for manual entry. */
142
- secret: string;
143
- /** Data URL of the QR code image (PNG) for scanning with an authenticator app. */
144
- qr_code: string;
145
- /** `otpauth://` URI for the TOTP secret. */
146
- uri: string;
142
+ /** Base32-encoded TOTP secret for manual entry. */
143
+ secret: string;
144
+ /** Data URL of the QR code image (PNG) for scanning with an authenticator app. */
145
+ qr_code: string;
146
+ /** `otpauth://` URI for the TOTP secret. */
147
+ uri: string;
147
148
  }
148
149
  /**
149
150
  * Response from generating new MFA backup codes.
@@ -152,10 +153,11 @@ interface TotpSetupResponse {
152
153
  * Each code can only be used once. Generating new codes invalidates all previous ones.
153
154
  */
154
155
  interface BackupCodesResponse {
155
- /** Array of single-use backup codes. Store these securely — they are shown only once. */
156
- codes: string[];
156
+ /** Array of single-use backup codes. Store these securely — they are shown only once. */
157
+ codes: string[];
157
158
  }
158
-
159
+ //#endregion
160
+ //#region src/client.d.ts
159
161
  /**
160
162
  * Core client for interacting with the AuthGate authentication proxy.
161
163
  *
@@ -174,437 +176,452 @@ interface BackupCodesResponse {
174
176
  * ```
175
177
  */
176
178
  declare class AuthGateClient {
177
- private readonly config;
178
- private encryptionKey;
179
- private stateKey;
180
- private keysReady;
181
- /**
182
- * @param config - Client configuration. See {@link AuthGateConfig}.
183
- */
184
- constructor(config: AuthGateConfig);
185
- private deriveKeys;
186
- private getEncryptionKey;
187
- private getStateKey;
188
- /**
189
- * Verify a JWT token against the AuthGate API.
190
- *
191
- * Makes a server-side `POST /api/v1/token/verify` call using your API key.
192
- * Times out after 5 seconds.
193
- *
194
- * @param token - The JWT token string from the OAuth callback or email/SMS flow.
195
- * @returns A {@link TokenVerifyResult} with the user data if valid.
196
- * @throws {@link TokenVerificationError} if the request times out.
197
- */
198
- verifyToken(token: string): Promise<TokenVerifyResult>;
199
- /**
200
- * Encrypt user data into a session cookie value.
201
- *
202
- * Uses AES-256-GCM with a key derived from your session secret.
203
- * The returned string is safe to store in an httpOnly cookie.
204
- *
205
- * @param user - The authenticated user to store.
206
- * @returns Base64url-encoded encrypted session string.
207
- */
208
- encryptSession(user: AuthGateUser): Promise<string>;
209
- /**
210
- * Decrypt a session cookie and return the user if the session is valid.
211
- *
212
- * Returns `null` if the cookie is expired, tampered with, or encrypted
213
- * with a different secret. All failure modes return `null` to prevent
214
- * oracle attacks.
215
- *
216
- * @param cookieValue - The encrypted cookie string.
217
- * @returns The user, or `null` if the session is invalid.
218
- */
219
- decryptSession(cookieValue: string): Promise<AuthGateUser | null>;
220
- /**
221
- * Decrypt a session cookie and return the full payload (user + timestamps).
222
- *
223
- * Used internally by middleware to check `iat` for session revalidation.
224
- *
225
- * @param cookieValue - The encrypted cookie string.
226
- * @returns The full session payload, or `null` if invalid.
227
- * @internal
228
- */
229
- decryptSessionPayload(cookieValue: string): Promise<SessionPayload | null>;
230
- /**
231
- * Create a signed OAuth state parameter and nonce for CSRF protection.
232
- *
233
- * Store the `nonce` in a short-lived httpOnly cookie and pass `state`
234
- * as a query parameter in the OAuth authorization URL.
235
- *
236
- * @returns `{ state, nonce }` — the state string and its corresponding nonce.
237
- */
238
- createState(): Promise<{
239
- state: string;
240
- nonce: string;
241
- }>;
242
- /**
243
- * Verify an OAuth state parameter returned in the callback.
244
- *
245
- * @param state - The `state` query parameter from the callback.
246
- * @param nonce - The nonce from the httpOnly cookie.
247
- * @returns `true` if the state is valid and not expired.
248
- */
249
- verifyState(state: string, nonce: string): Promise<boolean>;
250
- /**
251
- * Build the OAuth authorization URL for a given provider.
252
- *
253
- * @param provider - The OAuth provider (e.g. `"google"`, `"github"`).
254
- * @param callbackUrl - Your app's callback URL where the user is redirected after auth.
255
- * @param options - Optional parameters.
256
- * @param options.linkTo - An existing user ID to link this OAuth account to.
257
- * @returns The full authorization URL to redirect the user to.
258
- * @throws {@link AuthGateError} if the provider is not in {@link SUPPORTED_PROVIDERS}.
259
- */
260
- getOAuthUrl(provider: OAuthProvider, callbackUrl: string, options?: {
261
- state?: string;
262
- linkTo?: string;
263
- locale?: string;
264
- }): Promise<string>;
265
- /**
266
- * Register a new user with email and password.
267
- *
268
- * @param data - Signup data including email, password, optional name, and callback URL.
269
- * @returns The raw `Response` from the AuthGate proxy.
270
- */
271
- emailSignup(data: {
272
- email: string;
273
- password: string;
274
- name?: string;
275
- callbackUrl: string;
276
- locale?: string;
277
- }): Promise<Response>;
278
- /**
279
- * Sign in an existing user with email and password.
280
- *
281
- * The response may include `mfa_required: true` if the user has MFA enabled,
282
- * in which case you should redirect to an MFA verification page.
283
- *
284
- * @param data - Sign-in data including email, password, and callback URL.
285
- * @returns The raw `Response` from the AuthGate proxy.
286
- */
287
- emailSignin(data: {
288
- email: string;
289
- password: string;
290
- callbackUrl: string;
291
- locale?: string;
292
- }): Promise<Response>;
293
- /**
294
- * Send a password reset email to the user.
295
- *
296
- * @param data - The user's email and the URL to redirect to after clicking the reset link.
297
- * @returns The raw `Response` from the AuthGate proxy.
298
- */
299
- emailForgotPassword(data: {
300
- email: string;
301
- callbackUrl: string;
302
- locale?: string;
303
- }): Promise<Response>;
304
- /**
305
- * Confirm a password reset with the token from the reset email.
306
- *
307
- * @param data - The reset token and the new password.
308
- * @returns The raw `Response` from the AuthGate proxy.
309
- */
310
- emailResetPassword(data: {
311
- token: string;
312
- password: string;
313
- locale?: string;
314
- }): Promise<Response>;
315
- /**
316
- * Send a magic link email for passwordless authentication.
317
- *
318
- * @param data - The user's email and callback URL.
319
- * @returns The raw `Response` from the AuthGate proxy.
320
- */
321
- magicLinkSend(data: {
322
- email: string;
323
- callbackUrl: string;
324
- locale?: string;
325
- }): Promise<Response>;
326
- /**
327
- * Verify an email address using a one-time code.
328
- *
329
- * @param data - The user's email and the verification code.
330
- * @returns The raw `Response` from the AuthGate proxy.
331
- */
332
- emailVerifyCode(data: {
333
- email: string;
334
- code: string;
335
- locale?: string;
336
- }): Promise<Response>;
337
- /**
338
- * Send an SMS verification code to the user's phone number.
339
- *
340
- * @param data - The phone number (E.164 format) and callback URL.
341
- * @returns The raw `Response` from the AuthGate proxy.
342
- */
343
- smsSendCode(data: {
344
- phone: string;
345
- callbackUrl: string;
346
- }): Promise<Response>;
347
- /**
348
- * Verify an SMS code and authenticate the user.
349
- *
350
- * @param data - The phone number, verification code, and callback URL.
351
- * @returns The raw `Response` from the AuthGate proxy.
352
- */
353
- smsVerifyCode(data: {
354
- phone: string;
355
- code: string;
356
- callbackUrl: string;
357
- }): Promise<Response>;
358
- /**
359
- * Exchange a refresh token for a new JWT.
360
- *
361
- * Refresh tokens are single-use — each call returns a new JWT and
362
- * invalidates the previous refresh token (rotation).
363
- *
364
- * @param refreshToken - The opaque refresh token.
365
- * @returns A new JWT and its `expires_in` (seconds), or `null` if the refresh token is invalid.
366
- */
367
- refreshToken(refreshToken: string): Promise<{
368
- token: string;
369
- expires_in: number;
370
- } | null>;
371
- /**
372
- * Revoke a session by its refresh token.
373
- *
374
- * After revocation, the refresh token can no longer be used to obtain
375
- * new JWTs. The user will need to re-authenticate.
376
- *
377
- * @param refreshToken - The opaque refresh token to revoke.
378
- * @returns `true` if the session was revoked, `false` on failure.
379
- */
380
- revokeSession(refreshToken: string): Promise<boolean>;
381
- /**
382
- * Verify an MFA code to complete authentication.
383
- *
384
- * Called after a sign-in response includes `mfa_required: true`.
385
- *
386
- * @param data - The MFA challenge token, verification code, and method.
387
- * @returns The raw `Response` — includes a JWT on success.
388
- */
389
- mfaVerify(data: {
390
- challenge: string;
391
- code: string;
392
- method: "totp" | "sms" | "backup_code";
393
- }): Promise<Response>;
394
- /**
395
- * Begin TOTP (authenticator app) setup for the authenticated user.
396
- *
397
- * Requires a valid JWT in the `Authorization: Bearer` header.
398
- *
399
- * @param token - The user's current JWT.
400
- * @returns The raw `Response` with TOTP secret, QR code, and URI.
401
- */
402
- mfaTotpSetup(token: string): Promise<Response>;
403
- /**
404
- * Confirm TOTP setup by verifying a code from the authenticator app.
405
- *
406
- * @param token - The user's current JWT.
407
- * @param code - The 6-digit TOTP code from the authenticator app.
408
- * @returns The raw `Response` — confirms enrollment on success.
409
- */
410
- mfaTotpVerifySetup(token: string, code: string): Promise<Response>;
411
- /**
412
- * Disable TOTP for the authenticated user.
413
- *
414
- * @param token - The user's current JWT.
415
- * @param code - A valid TOTP code to confirm the action.
416
- * @returns The raw `Response`.
417
- */
418
- mfaTotpDisable(token: string, code: string): Promise<Response>;
419
- /**
420
- * Enable SMS-based MFA for the authenticated user.
421
- *
422
- * Uses the phone number already associated with the user's account.
423
- *
424
- * @param token - The user's current JWT.
425
- * @returns The raw `Response`.
426
- */
427
- mfaSmsEnable(token: string): Promise<Response>;
428
- /**
429
- * Disable SMS-based MFA for the authenticated user.
430
- *
431
- * @param token - The user's current JWT.
432
- * @returns The raw `Response`.
433
- */
434
- mfaSmsDisable(token: string): Promise<Response>;
435
- /**
436
- * Generate a new set of single-use MFA backup codes.
437
- *
438
- * Generating new codes invalidates all previously issued backup codes.
439
- *
440
- * @param token - The user's current JWT.
441
- * @returns The raw `Response` with an array of backup codes.
442
- */
443
- mfaBackupCodesGenerate(token: string): Promise<Response>;
444
- /**
445
- * Get the current MFA enrollment status for the authenticated user.
446
- *
447
- * @param token - The user's current JWT.
448
- * @returns The raw `Response` with {@link MfaStatus} data.
449
- */
450
- mfaStatus(token: string): Promise<Response>;
451
- /**
452
- * Send an SMS code for MFA verification during the challenge flow.
453
- *
454
- * @param challenge - The MFA challenge token from the sign-in response.
455
- * @returns The raw `Response`.
456
- */
457
- mfaSmsSendCode(challenge: string): Promise<Response>;
458
- /**
459
- * Create a new organization.
460
- *
461
- * @param data - Organization creation data including name, slug, optional image URL, and metadata.
462
- * @returns The raw `Response` from the AuthGate proxy.
463
- */
464
- createOrg(data: {
465
- name: string;
466
- slug: string;
467
- imageUrl?: string;
468
- metadata?: Record<string, unknown>;
469
- }): Promise<Response>;
470
- /**
471
- * List all organizations accessible to the current project.
472
- *
473
- * @returns The raw `Response` from the AuthGate proxy.
474
- */
475
- listOrgs(): Promise<Response>;
476
- /**
477
- * Get a single organization by ID or slug.
478
- *
479
- * @param orgIdOrSlug - The organization ID or slug.
480
- * @returns The raw `Response` from the AuthGate proxy.
481
- */
482
- getOrg(orgIdOrSlug: string): Promise<Response>;
483
- /**
484
- * Update an organization's details.
485
- *
486
- * @param orgIdOrSlug - The organization ID or slug.
487
- * @param data - Fields to update. All fields are optional.
488
- * @returns The raw `Response` from the AuthGate proxy.
489
- */
490
- updateOrg(orgIdOrSlug: string, data: {
491
- name?: string;
492
- slug?: string;
493
- imageUrl?: string;
494
- maxMembers?: number | null;
495
- metadata?: Record<string, unknown>;
496
- }): Promise<Response>;
497
- /**
498
- * Delete an organization.
499
- *
500
- * @param orgIdOrSlug - The organization ID or slug.
501
- * @returns The raw `Response` from the AuthGate proxy.
502
- */
503
- deleteOrg(orgIdOrSlug: string): Promise<Response>;
504
- /**
505
- * List all members of an organization.
506
- *
507
- * @param orgIdOrSlug - The organization ID or slug.
508
- * @returns The raw `Response` from the AuthGate proxy.
509
- */
510
- listOrgMembers(orgIdOrSlug: string): Promise<Response>;
511
- /**
512
- * Update a member's role within an organization.
513
- *
514
- * @param orgIdOrSlug - The organization ID or slug.
515
- * @param memberId - The member's user ID.
516
- * @param data - The new role to assign.
517
- * @returns The raw `Response` from the AuthGate proxy.
518
- */
519
- updateOrgMember(orgIdOrSlug: string, memberId: string, data: {
520
- roleKey: string;
521
- }): Promise<Response>;
522
- /**
523
- * Remove a member from an organization.
524
- *
525
- * @param orgIdOrSlug - The organization ID or slug.
526
- * @param memberId - The member's user ID.
527
- * @returns The raw `Response` from the AuthGate proxy.
528
- */
529
- removeOrgMember(orgIdOrSlug: string, memberId: string): Promise<Response>;
530
- /**
531
- * Invite a user to an organization by email.
532
- *
533
- * @param orgIdOrSlug - The organization ID or slug.
534
- * @param data - The invitee's email and optional role.
535
- * @returns The raw `Response` from the AuthGate proxy.
536
- */
537
- inviteToOrg(orgIdOrSlug: string, data: {
538
- email: string;
539
- roleKey?: string;
540
- }): Promise<Response>;
541
- /**
542
- * List all pending invitations for an organization.
543
- *
544
- * @param orgIdOrSlug - The organization ID or slug.
545
- * @returns The raw `Response` from the AuthGate proxy.
546
- */
547
- listOrgInvitations(orgIdOrSlug: string): Promise<Response>;
548
- /**
549
- * Revoke a pending organization invitation.
550
- *
551
- * @param orgIdOrSlug - The organization ID or slug.
552
- * @param invitationId - The invitation ID to revoke.
553
- * @returns The raw `Response` from the AuthGate proxy.
554
- */
555
- revokeOrgInvitation(orgIdOrSlug: string, invitationId: string): Promise<Response>;
556
- /**
557
- * Accept an organization invitation using a token.
558
- *
559
- * @param data - The invitation token received via email.
560
- * @returns The raw `Response` from the AuthGate proxy.
561
- */
562
- acceptOrgInvitation(data: {
563
- token: string;
564
- }): Promise<Response>;
565
- /**
566
- * Leave an organization as the current user.
567
- *
568
- * @param orgIdOrSlug - The organization ID or slug.
569
- * @returns The raw `Response` from the AuthGate proxy.
570
- */
571
- leaveOrg(orgIdOrSlug: string): Promise<Response>;
572
- /** The name of the session cookie (default: `"__authgate"`). */
573
- get cookieName(): string;
574
- /** The name of the OAuth nonce cookie (`"__authgate_nonce"`). */
575
- get nonceCookieName(): string;
576
- /** The name of the refresh token cookie (`"__authgate_refresh"`). */
577
- get refreshTokenCookieName(): string;
578
- /** The callback path where OAuth redirects are handled (default: `"/api/auth/callback"`). */
579
- get callbackPath(): string;
580
- /** The AuthGate service base URL. */
581
- get baseUrl(): string;
582
- /** Session lifetime in seconds. */
583
- get sessionMaxAge(): number;
584
- /**
585
- * Get cookie options for the session cookie.
586
- *
587
- * Returns `secure: true` in production, `httpOnly: true` always.
588
- */
589
- getSessionCookieOptions(): CookieOptions;
590
- /**
591
- * Get cookie options for the OAuth nonce cookie.
592
- *
593
- * Short-lived (10 minutes) to match the state TTL.
594
- */
595
- getNonceCookieOptions(): CookieOptions;
596
- /**
597
- * Validate the SDK configuration against the AuthGate server.
598
- *
599
- * Checks that the API key is valid and (optionally) that a callback URL
600
- * is registered for the project. This is called automatically by framework
601
- * factories (`createAuthGate`, `createAuthRoutes`) and logs errors to the
602
- * console — it does NOT throw.
603
- *
604
- * @param callbackUrl - The full callback URL to check registration for.
605
- * @internal
606
- */
607
- validateConfig(callbackUrl?: string): Promise<void>;
179
+ private readonly config;
180
+ private encryptionKey;
181
+ private stateKey;
182
+ private keysReady;
183
+ /**
184
+ * @param config - Client configuration. See {@link AuthGateConfig}.
185
+ */
186
+ constructor(config: AuthGateConfig);
187
+ private deriveKeys;
188
+ private getEncryptionKey;
189
+ private getStateKey;
190
+ /**
191
+ * Verify a JWT token against the AuthGate API.
192
+ *
193
+ * Makes a server-side `POST /api/v1/token/verify` call using your API key.
194
+ * Times out after 5 seconds.
195
+ *
196
+ * @param token - The JWT token string from the OAuth callback or email/SMS flow.
197
+ * @returns A {@link TokenVerifyResult} with the user data if valid.
198
+ * @throws {@link TokenVerificationError} if the request times out.
199
+ */
200
+ verifyToken(token: string): Promise<TokenVerifyResult>;
201
+ /**
202
+ * Encrypt user data into a session cookie value.
203
+ *
204
+ * Uses AES-256-GCM with a key derived from your session secret.
205
+ * The returned string is safe to store in an httpOnly cookie.
206
+ *
207
+ * @param user - The authenticated user to store.
208
+ * @returns Base64url-encoded encrypted session string.
209
+ */
210
+ encryptSession(user: AuthGateUser): Promise<string>;
211
+ /**
212
+ * Decrypt a session cookie and return the user if the session is valid.
213
+ *
214
+ * Returns `null` if the cookie is expired, tampered with, or encrypted
215
+ * with a different secret. All failure modes return `null` to prevent
216
+ * oracle attacks.
217
+ *
218
+ * @param cookieValue - The encrypted cookie string.
219
+ * @returns The user, or `null` if the session is invalid.
220
+ */
221
+ decryptSession(cookieValue: string): Promise<AuthGateUser | null>;
222
+ /**
223
+ * Decrypt a session cookie and return the full payload (user + timestamps).
224
+ *
225
+ * Used internally by middleware to check `iat` for session revalidation.
226
+ *
227
+ * @param cookieValue - The encrypted cookie string.
228
+ * @returns The full session payload, or `null` if invalid.
229
+ * @internal
230
+ */
231
+ decryptSessionPayload(cookieValue: string): Promise<SessionPayload | null>;
232
+ /**
233
+ * Create a signed OAuth state parameter and nonce for CSRF protection.
234
+ *
235
+ * Store the `nonce` in a short-lived httpOnly cookie and pass `state`
236
+ * as a query parameter in the OAuth authorization URL.
237
+ *
238
+ * @returns `{ state, nonce }` — the state string and its corresponding nonce.
239
+ */
240
+ createState(): Promise<{
241
+ state: string;
242
+ nonce: string;
243
+ }>;
244
+ /**
245
+ * Verify an OAuth state parameter returned in the callback.
246
+ *
247
+ * @param state - The `state` query parameter from the callback.
248
+ * @param nonce - The nonce from the httpOnly cookie.
249
+ * @returns `true` if the state is valid and not expired.
250
+ */
251
+ verifyState(state: string, nonce: string): Promise<boolean>;
252
+ /**
253
+ * Build the OAuth authorization URL for a given provider.
254
+ *
255
+ * @param provider - The OAuth provider (e.g. `"google"`, `"github"`).
256
+ * @param callbackUrl - Your app's callback URL where the user is redirected after auth.
257
+ * @param options - Optional parameters.
258
+ * @param options.linkTo - An existing user ID to link this OAuth account to.
259
+ * @returns The full authorization URL to redirect the user to.
260
+ * @throws {@link AuthGateError} if the provider is not in {@link SUPPORTED_PROVIDERS}.
261
+ */
262
+ getOAuthUrl(provider: OAuthProvider, callbackUrl: string, options?: {
263
+ state?: string;
264
+ linkTo?: string;
265
+ locale?: string;
266
+ }): Promise<string>;
267
+ /**
268
+ * Register a new user with email and password.
269
+ *
270
+ * @param data - Signup data including email, password, optional name, and callback URL.
271
+ * @returns The raw `Response` from the AuthGate proxy.
272
+ */
273
+ emailSignup(data: {
274
+ email: string;
275
+ password: string;
276
+ name?: string;
277
+ callbackUrl: string;
278
+ locale?: string;
279
+ }): Promise<Response>;
280
+ /**
281
+ * Sign in an existing user with email and password.
282
+ *
283
+ * The response may include `mfa_required: true` if the user has MFA enabled,
284
+ * in which case you should redirect to an MFA verification page.
285
+ *
286
+ * @param data - Sign-in data including email, password, and callback URL.
287
+ * @returns The raw `Response` from the AuthGate proxy.
288
+ */
289
+ emailSignin(data: {
290
+ email: string;
291
+ password: string;
292
+ callbackUrl: string;
293
+ locale?: string;
294
+ }): Promise<Response>;
295
+ /**
296
+ * Send a password reset email to the user.
297
+ *
298
+ * @param data - The user's email and the URL to redirect to after clicking the reset link.
299
+ * @returns The raw `Response` from the AuthGate proxy.
300
+ */
301
+ emailForgotPassword(data: {
302
+ email: string;
303
+ callbackUrl: string;
304
+ locale?: string;
305
+ }): Promise<Response>;
306
+ /**
307
+ * Confirm a password reset with the token from the reset email.
308
+ *
309
+ * @param data - The reset token and the new password.
310
+ * @returns The raw `Response` from the AuthGate proxy.
311
+ */
312
+ emailResetPassword(data: {
313
+ token: string;
314
+ password: string;
315
+ locale?: string;
316
+ }): Promise<Response>;
317
+ /**
318
+ * Send a magic link email for passwordless authentication.
319
+ *
320
+ * @param data - The user's email and callback URL.
321
+ * @returns The raw `Response` from the AuthGate proxy.
322
+ */
323
+ magicLinkSend(data: {
324
+ email: string;
325
+ callbackUrl: string;
326
+ locale?: string;
327
+ }): Promise<Response>;
328
+ /**
329
+ * Verify an email address using a one-time code.
330
+ *
331
+ * @param data - The user's email and the verification code.
332
+ * @returns The raw `Response` from the AuthGate proxy.
333
+ */
334
+ emailVerifyCode(data: {
335
+ email: string;
336
+ code: string;
337
+ locale?: string;
338
+ }): Promise<Response>;
339
+ /**
340
+ * Send an SMS verification code to the user's phone number.
341
+ *
342
+ * @param data - The phone number (E.164 format) and callback URL.
343
+ * @returns The raw `Response` from the AuthGate proxy.
344
+ */
345
+ smsSendCode(data: {
346
+ phone: string;
347
+ callbackUrl: string;
348
+ }): Promise<Response>;
349
+ /**
350
+ * Verify an SMS code and authenticate the user.
351
+ *
352
+ * @param data - The phone number, verification code, and callback URL.
353
+ * @returns The raw `Response` from the AuthGate proxy.
354
+ */
355
+ smsVerifyCode(data: {
356
+ phone: string;
357
+ code: string;
358
+ callbackUrl: string;
359
+ }): Promise<Response>;
360
+ /**
361
+ * Exchange a refresh token for a new JWT.
362
+ *
363
+ * Refresh tokens are single-use: each call invalidates the token it was
364
+ * given, so callers must store the `refresh_token` it returns or their next
365
+ * refresh fails.
366
+ *
367
+ * @param refreshToken - The opaque refresh token.
368
+ * @returns A new JWT, its `expires_in` (seconds) and the rotated
369
+ * `refresh_token`, or `null` if the refresh token is invalid.
370
+ */
371
+ refreshToken(refreshToken: string): Promise<{
372
+ token: string;
373
+ refresh_token?: string;
374
+ expires_in: number;
375
+ } | null>;
376
+ /**
377
+ * Exchange a single-use authorization code (delivered on the callback URL)
378
+ * for the JWT + refresh token. Codes are one-shot and expire after ~60s.
379
+ *
380
+ * @param code - The `code` query parameter from the callback redirect.
381
+ * @returns The tokens, or `null` if the code is invalid/expired/used.
382
+ */
383
+ exchangeCode(code: string): Promise<{
384
+ token: string;
385
+ refresh_token?: string;
386
+ mfa_setup_required?: boolean;
387
+ } | null>;
388
+ /**
389
+ * Revoke a session by its refresh token.
390
+ *
391
+ * After revocation, the refresh token can no longer be used to obtain
392
+ * new JWTs. The user will need to re-authenticate.
393
+ *
394
+ * @param refreshToken - The opaque refresh token to revoke.
395
+ * @returns `true` if the session was revoked, `false` on failure.
396
+ */
397
+ revokeSession(refreshToken: string): Promise<boolean>;
398
+ /**
399
+ * Verify an MFA code to complete authentication.
400
+ *
401
+ * Called after a sign-in response includes `mfa_required: true`.
402
+ *
403
+ * @param data - The MFA challenge token, verification code, and method.
404
+ * @returns The raw `Response` — includes a JWT on success.
405
+ */
406
+ mfaVerify(data: {
407
+ challenge: string;
408
+ code: string;
409
+ method: "totp" | "sms" | "backup_code";
410
+ }): Promise<Response>;
411
+ /**
412
+ * Begin TOTP (authenticator app) setup for the authenticated user.
413
+ *
414
+ * Requires a valid JWT in the `Authorization: Bearer` header.
415
+ *
416
+ * @param token - The user's current JWT.
417
+ * @returns The raw `Response` with TOTP secret, QR code, and URI.
418
+ */
419
+ mfaTotpSetup(token: string): Promise<Response>;
420
+ /**
421
+ * Confirm TOTP setup by verifying a code from the authenticator app.
422
+ *
423
+ * @param token - The user's current JWT.
424
+ * @param code - The 6-digit TOTP code from the authenticator app.
425
+ * @returns The raw `Response` — confirms enrollment on success.
426
+ */
427
+ mfaTotpVerifySetup(token: string, code: string): Promise<Response>;
428
+ /**
429
+ * Disable TOTP for the authenticated user.
430
+ *
431
+ * @param token - The user's current JWT.
432
+ * @param code - A valid TOTP code to confirm the action.
433
+ * @returns The raw `Response`.
434
+ */
435
+ mfaTotpDisable(token: string, code: string): Promise<Response>;
436
+ /**
437
+ * Enable SMS-based MFA for the authenticated user.
438
+ *
439
+ * Uses the phone number already associated with the user's account.
440
+ *
441
+ * @param token - The user's current JWT.
442
+ * @returns The raw `Response`.
443
+ */
444
+ mfaSmsEnable(token: string): Promise<Response>;
445
+ /**
446
+ * Disable SMS-based MFA for the authenticated user.
447
+ *
448
+ * @param token - The user's current JWT.
449
+ * @returns The raw `Response`.
450
+ */
451
+ mfaSmsDisable(token: string): Promise<Response>;
452
+ /**
453
+ * Generate a new set of single-use MFA backup codes.
454
+ *
455
+ * Generating new codes invalidates all previously issued backup codes.
456
+ *
457
+ * @param token - The user's current JWT.
458
+ * @returns The raw `Response` with an array of backup codes.
459
+ */
460
+ mfaBackupCodesGenerate(token: string): Promise<Response>;
461
+ /**
462
+ * Get the current MFA enrollment status for the authenticated user.
463
+ *
464
+ * @param token - The user's current JWT.
465
+ * @returns The raw `Response` with {@link MfaStatus} data.
466
+ */
467
+ mfaStatus(token: string): Promise<Response>;
468
+ /**
469
+ * Send an SMS code for MFA verification during the challenge flow.
470
+ *
471
+ * @param challenge - The MFA challenge token from the sign-in response.
472
+ * @returns The raw `Response`.
473
+ */
474
+ mfaSmsSendCode(challenge: string): Promise<Response>;
475
+ /**
476
+ * Create a new organization.
477
+ *
478
+ * @param data - Organization creation data including name, slug, optional image URL, and metadata.
479
+ * @returns The raw `Response` from the AuthGate proxy.
480
+ */
481
+ createOrg(data: {
482
+ name: string;
483
+ slug: string;
484
+ imageUrl?: string;
485
+ metadata?: Record<string, unknown>;
486
+ }): Promise<Response>;
487
+ /**
488
+ * List all organizations accessible to the current project.
489
+ *
490
+ * @returns The raw `Response` from the AuthGate proxy.
491
+ */
492
+ listOrgs(): Promise<Response>;
493
+ /**
494
+ * Get a single organization by ID or slug.
495
+ *
496
+ * @param orgIdOrSlug - The organization ID or slug.
497
+ * @returns The raw `Response` from the AuthGate proxy.
498
+ */
499
+ getOrg(orgIdOrSlug: string): Promise<Response>;
500
+ /**
501
+ * Update an organization's details.
502
+ *
503
+ * @param orgIdOrSlug - The organization ID or slug.
504
+ * @param data - Fields to update. All fields are optional.
505
+ * @returns The raw `Response` from the AuthGate proxy.
506
+ */
507
+ updateOrg(orgIdOrSlug: string, data: {
508
+ name?: string;
509
+ slug?: string;
510
+ imageUrl?: string;
511
+ maxMembers?: number | null;
512
+ metadata?: Record<string, unknown>;
513
+ }): Promise<Response>;
514
+ /**
515
+ * Delete an organization.
516
+ *
517
+ * @param orgIdOrSlug - The organization ID or slug.
518
+ * @returns The raw `Response` from the AuthGate proxy.
519
+ */
520
+ deleteOrg(orgIdOrSlug: string): Promise<Response>;
521
+ /**
522
+ * List all members of an organization.
523
+ *
524
+ * @param orgIdOrSlug - The organization ID or slug.
525
+ * @returns The raw `Response` from the AuthGate proxy.
526
+ */
527
+ listOrgMembers(orgIdOrSlug: string): Promise<Response>;
528
+ /**
529
+ * Update a member's role within an organization.
530
+ *
531
+ * @param orgIdOrSlug - The organization ID or slug.
532
+ * @param memberId - The member's user ID.
533
+ * @param data - The new role to assign.
534
+ * @returns The raw `Response` from the AuthGate proxy.
535
+ */
536
+ updateOrgMember(orgIdOrSlug: string, memberId: string, data: {
537
+ roleKey: string;
538
+ }): Promise<Response>;
539
+ /**
540
+ * Remove a member from an organization.
541
+ *
542
+ * @param orgIdOrSlug - The organization ID or slug.
543
+ * @param memberId - The member's user ID.
544
+ * @returns The raw `Response` from the AuthGate proxy.
545
+ */
546
+ removeOrgMember(orgIdOrSlug: string, memberId: string): Promise<Response>;
547
+ /**
548
+ * Invite a user to an organization by email.
549
+ *
550
+ * @param orgIdOrSlug - The organization ID or slug.
551
+ * @param data - The invitee's email and optional role.
552
+ * @returns The raw `Response` from the AuthGate proxy.
553
+ */
554
+ inviteToOrg(orgIdOrSlug: string, data: {
555
+ email: string;
556
+ roleKey?: string;
557
+ }): Promise<Response>;
558
+ /**
559
+ * List all pending invitations for an organization.
560
+ *
561
+ * @param orgIdOrSlug - The organization ID or slug.
562
+ * @returns The raw `Response` from the AuthGate proxy.
563
+ */
564
+ listOrgInvitations(orgIdOrSlug: string): Promise<Response>;
565
+ /**
566
+ * Revoke a pending organization invitation.
567
+ *
568
+ * @param orgIdOrSlug - The organization ID or slug.
569
+ * @param invitationId - The invitation ID to revoke.
570
+ * @returns The raw `Response` from the AuthGate proxy.
571
+ */
572
+ revokeOrgInvitation(orgIdOrSlug: string, invitationId: string): Promise<Response>;
573
+ /**
574
+ * Accept an organization invitation using a token.
575
+ *
576
+ * @param data - The invitation token received via email.
577
+ * @returns The raw `Response` from the AuthGate proxy.
578
+ */
579
+ acceptOrgInvitation(data: {
580
+ token: string;
581
+ }): Promise<Response>;
582
+ /**
583
+ * Leave an organization as the current user.
584
+ *
585
+ * @param orgIdOrSlug - The organization ID or slug.
586
+ * @returns The raw `Response` from the AuthGate proxy.
587
+ */
588
+ leaveOrg(orgIdOrSlug: string): Promise<Response>;
589
+ /** The name of the session cookie (default: `"__authgate"`). */
590
+ get cookieName(): string;
591
+ /** The name of the OAuth nonce cookie (`"__authgate_nonce"`). */
592
+ get nonceCookieName(): string;
593
+ /** The name of the refresh token cookie (`"__authgate_refresh"`). */
594
+ get refreshTokenCookieName(): string;
595
+ /** The callback path where OAuth redirects are handled (default: `"/api/auth/callback"`). */
596
+ get callbackPath(): string;
597
+ /** The AuthGate service base URL. */
598
+ get baseUrl(): string;
599
+ /** Session lifetime in seconds. */
600
+ get sessionMaxAge(): number;
601
+ /**
602
+ * Get cookie options for the session cookie.
603
+ *
604
+ * Returns `secure: true` in production, `httpOnly: true` always.
605
+ */
606
+ getSessionCookieOptions(): CookieOptions;
607
+ /**
608
+ * Get cookie options for the OAuth nonce cookie.
609
+ *
610
+ * Short-lived (10 minutes) to match the state TTL.
611
+ */
612
+ getNonceCookieOptions(): CookieOptions;
613
+ /**
614
+ * Validate the SDK configuration against the AuthGate server.
615
+ *
616
+ * Checks that the API key is valid and (optionally) that a callback URL
617
+ * is registered for the project. This is called automatically by framework
618
+ * factories (`createAuthGate`, `createAuthRoutes`) and logs errors to the
619
+ * console — it does NOT throw.
620
+ *
621
+ * @param callbackUrl - The full callback URL to check registration for.
622
+ * @internal
623
+ */
624
+ validateConfig(callbackUrl?: string): Promise<void>;
608
625
  }
609
626
  /**
610
627
  * Create an {@link AuthGateClient} instance.
@@ -615,7 +632,8 @@ declare class AuthGateClient {
615
632
  * @returns A configured {@link AuthGateClient}.
616
633
  */
617
634
  declare function createAuthGateClient(config: AuthGateConfig): AuthGateClient;
618
-
635
+ //#endregion
636
+ //#region src/constants.d.ts
619
637
  /** Default name for the encrypted session cookie. */
620
638
  declare const DEFAULT_COOKIE_NAME = "__authgate";
621
639
  /** Cookie name used to store the OAuth CSRF nonce during the authorization flow. */
@@ -637,7 +655,8 @@ declare const STATE_TTL_MS = 600000;
637
655
  * Configure provider credentials in the AuthGate dashboard under Providers.
638
656
  */
639
657
  declare const SUPPORTED_PROVIDERS: OAuthProvider[];
640
-
658
+ //#endregion
659
+ //#region src/errors.d.ts
641
660
  /**
642
661
  * Base error class for all AuthGate errors.
643
662
  *
@@ -656,7 +675,7 @@ declare const SUPPORTED_PROVIDERS: OAuthProvider[];
656
675
  * ```
657
676
  */
658
677
  declare class AuthGateError extends Error {
659
- constructor(message: string);
678
+ constructor(message: string);
660
679
  }
661
680
  /**
662
681
  * Thrown when JWT token verification fails or times out.
@@ -665,7 +684,7 @@ declare class AuthGateError extends Error {
665
684
  * AuthGate API is unreachable within the 5-second timeout.
666
685
  */
667
686
  declare class TokenVerificationError extends AuthGateError {
668
- constructor(message?: string);
687
+ constructor(message?: string);
669
688
  }
670
689
  /**
671
690
  * Thrown when an encrypted session cookie cannot be decrypted.
@@ -674,7 +693,7 @@ declare class TokenVerificationError extends AuthGateError {
674
693
  * tampered with, or the cookie format version is unsupported.
675
694
  */
676
695
  declare class SessionDecryptionError extends AuthGateError {
677
- constructor(message?: string);
696
+ constructor(message?: string);
678
697
  }
679
698
  /**
680
699
  * Thrown when OAuth state verification fails.
@@ -683,7 +702,7 @@ declare class SessionDecryptionError extends AuthGateError {
683
702
  * (older than 10 minutes), or a nonce mismatch.
684
703
  */
685
704
  declare class InvalidStateError extends AuthGateError {
686
- constructor(message?: string);
705
+ constructor(message?: string);
687
706
  }
688
707
  /**
689
708
  * Thrown when the AuthGate SDK is initialized with invalid configuration.
@@ -692,9 +711,10 @@ declare class InvalidStateError extends AuthGateError {
692
711
  * and how to fix it.
693
712
  */
694
713
  declare class ConfigurationError extends AuthGateError {
695
- constructor(message: string);
714
+ constructor(message: string);
696
715
  }
697
-
716
+ //#endregion
717
+ //#region src/project-config.d.ts
698
718
  /**
699
719
  * Connection details for the AuthGate API.
700
720
  *
@@ -703,8 +723,8 @@ declare class ConfigurationError extends AuthGateError {
703
723
  * auto-loads `.env` and `.env.local` before importing the config file.
704
724
  */
705
725
  type AuthGateConnection = {
706
- baseUrl?: string;
707
- apiKey?: string;
726
+ baseUrl?: string;
727
+ apiKey?: string;
708
728
  };
709
729
  /**
710
730
  * Project-level config shape for `authgate.config.ts`.
@@ -717,31 +737,31 @@ type AuthGateConnection = {
717
737
  * so you can reference `process.env` directly.
718
738
  */
719
739
  interface AuthGateProjectConfig {
720
- /**
721
- * Connection details for the AuthGate API.
722
- *
723
- * If omitted, the CLI falls back to `AUTHGATE_URL` and `AUTHGATE_API_KEY`
724
- * environment variables.
725
- */
726
- connection?: AuthGateConnection;
727
- /**
728
- * Path to the RBAC config file (`authgate.rbac.ts`).
729
- *
730
- * Overrides auto-discovery. Useful in monorepos where the RBAC config
731
- * lives in a different directory than the project root.
732
- *
733
- * @example `"./packages/api/authgate.rbac.ts"`
734
- */
735
- rbacConfig?: string;
736
- /**
737
- * Path to the Billing config file (`authgate.billing.ts`).
738
- *
739
- * Overrides auto-discovery. Useful in monorepos where the billing config
740
- * lives in a different directory than the project root.
741
- *
742
- * @example `"./packages/api/authgate.billing.ts"`
743
- */
744
- billingConfig?: string;
740
+ /**
741
+ * Connection details for the AuthGate API.
742
+ *
743
+ * If omitted, the CLI falls back to `AUTHGATE_URL` and `AUTHGATE_API_KEY`
744
+ * environment variables.
745
+ */
746
+ connection?: AuthGateConnection;
747
+ /**
748
+ * Path to the RBAC config file (`authgate.rbac.ts`).
749
+ *
750
+ * Overrides auto-discovery. Useful in monorepos where the RBAC config
751
+ * lives in a different directory than the project root.
752
+ *
753
+ * @example `"./packages/api/authgate.rbac.ts"`
754
+ */
755
+ rbacConfig?: string;
756
+ /**
757
+ * Path to the Billing config file (`authgate.billing.ts`).
758
+ *
759
+ * Overrides auto-discovery. Useful in monorepos where the billing config
760
+ * lives in a different directory than the project root.
761
+ *
762
+ * @example `"./packages/api/authgate.billing.ts"`
763
+ */
764
+ billingConfig?: string;
745
765
  }
746
766
  /**
747
767
  * Define your project-level AuthGate configuration.
@@ -797,90 +817,91 @@ interface AuthGateProjectConfig {
797
817
  * ```
798
818
  */
799
819
  declare function defineConfig(config: AuthGateProjectConfig): AuthGateProjectConfig;
800
-
820
+ //#endregion
821
+ //#region src/billing.d.ts
801
822
  /** A product/plan in the billing catalog. */
802
823
  interface BillingPlan {
803
- id: string;
804
- name: string;
805
- description: string | null;
806
- features: string[];
807
- prices: BillingPrice[];
824
+ id: string;
825
+ name: string;
826
+ description: string | null;
827
+ features: string[];
828
+ prices: BillingPrice[];
808
829
  }
809
830
  /** A price attached to a plan. */
810
831
  interface BillingPrice {
811
- id: string;
812
- type: "recurring" | "metered" | "tiered";
813
- amount: number | null;
814
- currency: string;
815
- interval: "daily" | "weekly" | "monthly" | "yearly";
816
- intervalCount: number;
832
+ id: string;
833
+ type: "recurring" | "metered" | "tiered";
834
+ amount: number | null;
835
+ currency: string;
836
+ interval: "daily" | "weekly" | "monthly" | "yearly";
837
+ intervalCount: number;
817
838
  }
818
839
  /** A single item within a subscription (price + product). */
819
840
  interface BillingSubscriptionItem {
841
+ id: string;
842
+ quantity: number;
843
+ price: BillingPrice;
844
+ product: {
820
845
  id: string;
821
- quantity: number;
822
- price: BillingPrice;
823
- product: {
824
- id: string;
825
- name: string;
826
- description: string | null;
827
- features: string[];
828
- };
846
+ name: string;
847
+ description: string | null;
848
+ features: string[];
849
+ };
829
850
  }
830
851
  /** An active subscription for an end user. */
831
852
  interface BillingSubscription {
853
+ id: string;
854
+ status: "active" | "past_due" | "canceled" | "paused" | "trialing" | "unpaid";
855
+ /** Convenience: derived from the first subscription item's product. */
856
+ plan: {
832
857
  id: string;
833
- status: "active" | "past_due" | "canceled" | "paused" | "trialing" | "unpaid";
834
- /** Convenience: derived from the first subscription item's product. */
835
- plan: {
836
- id: string;
837
- name: string;
838
- } | null;
839
- /** Convenience: derived from the first subscription item's price. */
840
- price: BillingPrice | null;
841
- /** The full list of subscription items returned by the API. */
842
- items: BillingSubscriptionItem[];
843
- currentPeriodStart: string;
844
- currentPeriodEnd: string;
845
- cancelAtPeriodEnd: boolean;
846
- trialEnd: string | null;
858
+ name: string;
859
+ } | null;
860
+ /** Convenience: derived from the first subscription item's price. */
861
+ price: BillingPrice | null;
862
+ /** The full list of subscription items returned by the API. */
863
+ items: BillingSubscriptionItem[];
864
+ currentPeriodStart: string;
865
+ currentPeriodEnd: string;
866
+ cancelAtPeriodEnd: boolean;
867
+ trialEnd: string | null;
847
868
  }
848
869
  /** Entitlement data for an end user — what plan they're on and what features they have. */
849
870
  interface BillingEntitlement {
850
- plan: string | null;
851
- features: string[];
852
- status: string | null;
853
- currentPeriodEnd: string | null;
854
- cancelAtPeriodEnd: boolean;
871
+ plan: string | null;
872
+ features: string[];
873
+ status: string | null;
874
+ currentPeriodEnd: string | null;
875
+ cancelAtPeriodEnd: boolean;
855
876
  }
856
877
  /** Typed entitlement detail for a boolean feature. */
857
878
  interface BooleanEntitlementDetail {
858
- type: "boolean";
859
- feature: string;
860
- allowed: boolean;
879
+ type: "boolean";
880
+ feature: string;
881
+ allowed: boolean;
861
882
  }
862
883
  /** Typed entitlement detail for a metered feature. */
863
884
  interface MeteredEntitlementDetail {
864
- type: "metered";
865
- feature: string;
866
- allowed: boolean;
867
- used: number;
868
- limit: number;
869
- remaining: number;
885
+ type: "metered";
886
+ feature: string;
887
+ allowed: boolean;
888
+ used: number;
889
+ limit: number;
890
+ remaining: number;
870
891
  }
871
892
  /** A single feature entitlement detail. */
872
893
  type EntitlementDetail = BooleanEntitlementDetail | MeteredEntitlementDetail;
873
894
  /** Extended entitlement data with typed feature details. */
874
895
  interface BillingEntitlementV2 extends BillingEntitlement {
875
- /** Typed feature details with metered usage info. */
876
- featureDetails?: Record<string, EntitlementDetail>;
896
+ /** Typed feature details with metered usage info. */
897
+ featureDetails?: Record<string, EntitlementDetail>;
877
898
  }
878
899
  /** A single usage event to report. */
879
900
  interface UsageEvent {
880
- metric: string;
881
- quantity: number;
882
- idempotencyKey?: string;
883
- timestamp?: string;
901
+ metric: string;
902
+ quantity: number;
903
+ idempotencyKey?: string;
904
+ timestamp?: string;
884
905
  }
885
906
  /**
886
907
  * Check whether the user's entitlements include a specific plan.
@@ -906,52 +927,53 @@ declare function hasFeature(entitlements: BillingEntitlement | null | undefined,
906
927
  * @returns The typed entitlement detail, or a denied boolean detail if not found.
907
928
  */
908
929
  declare function checkFeature(entitlements: BillingEntitlementV2 | null | undefined, feature: string): EntitlementDetail;
909
-
930
+ //#endregion
931
+ //#region src/organizations.d.ts
910
932
  /** An organization within a project. */
911
933
  interface Organization {
912
- id: string;
913
- name: string;
914
- slug: string;
915
- imageUrl: string | null;
916
- metadata: Record<string, unknown> | null;
917
- createdAt: string;
934
+ id: string;
935
+ name: string;
936
+ slug: string;
937
+ imageUrl: string | null;
938
+ metadata: Record<string, unknown> | null;
939
+ createdAt: string;
918
940
  }
919
941
  /** A role definition with its permissions. */
920
942
  interface OrgRole {
921
- key: string;
922
- name: string;
923
- permissions: string[];
943
+ key: string;
944
+ name: string;
945
+ permissions: string[];
924
946
  }
925
947
  /** The current user's membership in an organization. */
926
948
  interface OrgMembership {
927
- id: string;
928
- orgId: string;
929
- role: OrgRole;
930
- createdAt: string;
949
+ id: string;
950
+ orgId: string;
951
+ role: OrgRole;
952
+ createdAt: string;
931
953
  }
932
954
  /** A member of an organization with user details. */
933
955
  interface OrgMember {
934
- id: string;
935
- endUserId: string;
936
- name: string | null;
937
- email: string | null;
938
- avatarUrl: string | null;
939
- role: OrgRole;
940
- createdAt: string;
956
+ id: string;
957
+ endUserId: string;
958
+ name: string | null;
959
+ email: string | null;
960
+ avatarUrl: string | null;
961
+ role: OrgRole;
962
+ createdAt: string;
941
963
  }
942
964
  /** An invitation to join an organization. */
943
965
  interface OrgInvitation {
944
- id: string;
945
- email: string;
946
- roleKey: string | null;
947
- status: "pending" | "accepted" | "revoked" | "expired";
948
- expiresAt: string;
949
- createdAt: string;
966
+ id: string;
967
+ email: string;
968
+ roleKey: string | null;
969
+ status: "pending" | "accepted" | "revoked" | "expired";
970
+ expiresAt: string;
971
+ createdAt: string;
950
972
  }
951
973
  /** An organization paired with the current user's membership. */
952
974
  interface OrgWithMembership {
953
- organization: Organization;
954
- membership: OrgMembership;
975
+ organization: Organization;
976
+ membership: OrgMembership;
955
977
  }
956
978
  /**
957
979
  * Check whether a membership includes a specific permission.
@@ -991,10 +1013,18 @@ declare function hasAnyPermission(membership: OrgMembership | null | undefined,
991
1013
  declare function hasAllPermissions(membership: OrgMembership | null | undefined, permissions: string[]): boolean;
992
1014
  /** A user's project-level role assignment (no org required). */
993
1015
  interface UserRoleAssignment {
994
- roleKey: string;
995
- roleName: string;
996
- permissions: string[];
997
- assignedAt: string;
1016
+ roleKey: string;
1017
+ roleName: string;
1018
+ permissions: string[];
1019
+ assignedAt: string;
1020
+ /**
1021
+ * Bumped whenever this user's effective permissions change.
1022
+ *
1023
+ * Optional so an older server that does not send it still parses. A client
1024
+ * caching permissions compares this to decide whether to refetch — see
1025
+ * AuthContextValue.permissions.
1026
+ */
1027
+ permissionsEpoch?: number;
998
1028
  }
999
1029
  /**
1000
1030
  * Merge permissions from a project-level role and an org-level role (union).
@@ -1006,5 +1036,5 @@ declare function mergePermissions(projectRole: UserRoleAssignment | null | undef
1006
1036
  * Supports wildcard matching.
1007
1037
  */
1008
1038
  declare function hasMergedPermission(projectRole: UserRoleAssignment | null | undefined, orgMembership: OrgMembership | null | undefined, permission: string): boolean;
1009
-
1010
- export { AuthGateClient, type AuthGateConfig, type AuthGateConnection, AuthGateError, type AuthGateProjectConfig, type AuthGateUser, type BackupCodesResponse, type BillingEntitlement, type BillingEntitlementV2, type BillingPlan, type BillingPrice, type BillingSubscription, type BillingSubscriptionItem, type BooleanEntitlementDetail, ConfigurationError, type CookieOptions, DEFAULT_COOKIE_NAME, type EntitlementDetail, InvalidStateError, type MeteredEntitlementDetail, type MfaChallengeResponse, type MfaStatus, NONCE_COOKIE_NAME, type OAuthProvider, type OrgInvitation, type OrgMember, type OrgMembership, type OrgRole, type OrgWithMembership, type Organization, REFRESH_TOKEN_COOKIE_NAME, SESSION_MAX_AGE, STATE_TTL_MS, SUPPORTED_PROVIDERS, SessionDecryptionError, type SessionPayload, TokenVerificationError, type TokenVerifyResult, type TotpSetupResponse, type UsageEvent, type UserRoleAssignment, checkFeature, createAuthGateClient, defineConfig, hasAllPermissions, hasAnyPermission, hasFeature, hasMergedPermission, hasPermission, hasPlan, hasRole, mergePermissions };
1039
+ //#endregion
1040
+ export { AuthGateClient, type AuthGateConfig, type AuthGateConnection, AuthGateError, type AuthGateProjectConfig, type AuthGateUser, type BackupCodesResponse, type BillingEntitlement, type BillingEntitlementV2, type BillingPlan, type BillingPrice, type BillingSubscription, type BillingSubscriptionItem, type BooleanEntitlementDetail, ConfigurationError, type CookieOptions, DEFAULT_COOKIE_NAME, type EntitlementDetail, InvalidStateError, type MeteredEntitlementDetail, type MfaChallengeResponse, type MfaStatus, NONCE_COOKIE_NAME, type OAuthProvider, type OrgInvitation, type OrgMember, type OrgMembership, type OrgRole, type OrgWithMembership, type Organization, REFRESH_TOKEN_COOKIE_NAME, SESSION_MAX_AGE, STATE_TTL_MS, SUPPORTED_PROVIDERS, SessionDecryptionError, type SessionPayload, TokenVerificationError, type TokenVerifyResult, type TotpSetupResponse, type UsageEvent, type UserRoleAssignment, checkFeature, createAuthGateClient, defineConfig, hasAllPermissions, hasAnyPermission, hasFeature, hasMergedPermission, hasPermission, hasPlan, hasRole, mergePermissions };