@meistrari/auth-core 3.5.0 → 4.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/index.d.mts CHANGED
@@ -349,6 +349,56 @@ type JWTPayload = JWTPayload$1 & JWTPayloadData;
349
349
  */
350
350
  declare function isTokenExpired(token: string, expiresInMs?: number): boolean;
351
351
 
352
+ /** Configuration for an in-memory application token cache. */
353
+ type ApplicationTokenStorageOptions = {
354
+ /** Base URL of the Auth API. */
355
+ authApiUrl: string;
356
+ /** Application identifier used for client-credentials exchanges. */
357
+ clientId: string;
358
+ /** Application secret used for client-credentials exchanges. */
359
+ clientSecret: string;
360
+ /** Full-jitter upper bound for the first retry delay. Defaults to 100 milliseconds. */
361
+ initialBackoffMs?: number;
362
+ /** Maximum number of exchange attempts, including the initial request. Defaults to 3. */
363
+ maxAttempts?: number;
364
+ /** Maximum number of organization tokens retained in memory. Defaults to 300. */
365
+ maxOrganizations?: number;
366
+ };
367
+ /** Per-call retry overrides for {@link ApplicationTokenStorage.getToken}. */
368
+ type GetTokenOptions = {
369
+ /** Full-jitter upper bound for the first retry delay. */
370
+ initialBackoffMs?: number;
371
+ /** Maximum number of exchange attempts, including the initial request. */
372
+ maxAttempts?: number;
373
+ };
374
+ /**
375
+ * Caches organization-scoped application tokens in memory.
376
+ *
377
+ * Tokens are reissued one minute before expiry. Cache hits promote their
378
+ * organization to the most-recently-used position, and insertions beyond the
379
+ * configured limit evict the least recently used organization. Transient
380
+ * exchange failures use full-jitter exponential backoff.
381
+ */
382
+ declare class ApplicationTokenStorage {
383
+ private readonly auth;
384
+ private readonly clientId;
385
+ private readonly clientSecret;
386
+ private readonly initialBackoffMs;
387
+ private readonly inFlight;
388
+ private readonly maxAttempts;
389
+ private readonly maxOrganizations;
390
+ private readonly tokens;
391
+ /** Creates an application token cache for one client-credentials identity. */
392
+ constructor({ authApiUrl, clientId, clientSecret, initialBackoffMs, maxAttempts, maxOrganizations, }: ApplicationTokenStorageOptions);
393
+ /** Returns a fresh access token scoped to the requested organization. */
394
+ getToken(organizationId: string, { initialBackoffMs, maxAttempts, }?: GetTokenOptions): Promise<string>;
395
+ private exchangeTokenWithRetry;
396
+ /** Performs the client-credentials exchange for one organization. */
397
+ protected exchangeToken(organizationId: string): Promise<string>;
398
+ /** Waits before the next exchange attempt. */
399
+ protected wait(delayMs: number): Promise<void>;
400
+ }
401
+
352
402
  declare const OAuthStepUpProvider: z__default.ZodEnum<{
353
403
  google: "google";
354
404
  microsoft: "microsoft";
@@ -1468,6 +1518,7 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
1468
1518
  EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION: better_auth.RawError<"EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION">;
1469
1519
  EMAIL_VERIFICATION_REQUIRED_FOR_INVITATION: better_auth.RawError<"EMAIL_VERIFICATION_REQUIRED_FOR_INVITATION">;
1470
1520
  YOU_ARE_NOT_ALLOWED_TO_CANCEL_THIS_INVITATION: better_auth.RawError<"YOU_ARE_NOT_ALLOWED_TO_CANCEL_THIS_INVITATION">;
1521
+ YOU_ARE_NOT_ALLOWED_TO_LIST_INVITATIONS: better_auth.RawError<"YOU_ARE_NOT_ALLOWED_TO_LIST_INVITATIONS">;
1471
1522
  INVITER_IS_NO_LONGER_A_MEMBER_OF_THE_ORGANIZATION: better_auth.RawError<"INVITER_IS_NO_LONGER_A_MEMBER_OF_THE_ORGANIZATION">;
1472
1523
  YOU_ARE_NOT_ALLOWED_TO_INVITE_USER_WITH_THIS_ROLE: better_auth.RawError<"YOU_ARE_NOT_ALLOWED_TO_INVITE_USER_WITH_THIS_ROLE">;
1473
1524
  FAILED_TO_RETRIEVE_INVITATION: better_auth.RawError<"FAILED_TO_RETRIEVE_INVITATION">;
@@ -1519,8 +1570,8 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
1519
1570
  id: "invitation-signup";
1520
1571
  getActions: ($fetch: better_auth_client.BetterFetch) => {
1521
1572
  invitationSignup: {
1522
- status: (invitationId: string) => Promise<InvitationSignupStatus>;
1523
- setupPassword: (invitationId: string, password: string) => Promise<InvitationPasswordSetupResult>;
1573
+ status: (token: string) => Promise<InvitationSignupStatus>;
1574
+ setupPassword: (token: string, password: string) => Promise<InvitationPasswordSetupResult>;
1524
1575
  };
1525
1576
  };
1526
1577
  } | {
@@ -1650,7 +1701,7 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
1650
1701
  $InferServerPlugin: {
1651
1702
  id: "admin";
1652
1703
  version: string;
1653
- init(): {
1704
+ init(authContext: better_auth.AuthContext): {
1654
1705
  options: {
1655
1706
  databaseHooks: {
1656
1707
  user: {
@@ -2457,7 +2508,7 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
2457
2508
  $Infer: {
2458
2509
  body: {
2459
2510
  permissions: {
2460
- readonly user?: ("update" | "delete" | "create" | "list" | "set-role" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "get")[] | undefined;
2511
+ readonly user?: ("update" | "delete" | "create" | "list" | "set-role" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "set-phone" | "get")[] | undefined;
2461
2512
  readonly session?: ("delete" | "list" | "revoke")[] | undefined;
2462
2513
  };
2463
2514
  } & {
@@ -2494,7 +2545,9 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
2494
2545
  YOU_CANNOT_IMPERSONATE_ADMINS: better_auth.RawError<"YOU_CANNOT_IMPERSONATE_ADMINS">;
2495
2546
  INVALID_ROLE_TYPE: better_auth.RawError<"INVALID_ROLE_TYPE">;
2496
2547
  YOU_ARE_NOT_ALLOWED_TO_SET_USERS_EMAIL: better_auth.RawError<"YOU_ARE_NOT_ALLOWED_TO_SET_USERS_EMAIL">;
2548
+ YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PHONE_NUMBER: better_auth.RawError<"YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PHONE_NUMBER">;
2497
2549
  PASSWORD_CANNOT_BE_UPDATED_VIA_UPDATE_USER: better_auth.RawError<"PASSWORD_CANNOT_BE_UPDATED_VIA_UPDATE_USER">;
2550
+ USER_ID_CANNOT_BE_UPDATED: better_auth.RawError<"USER_ID_CANNOT_BE_UPDATED">;
2498
2551
  };
2499
2552
  schema: {
2500
2553
  user: {
@@ -2534,7 +2587,7 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
2534
2587
  };
2535
2588
  options: NoInfer<{
2536
2589
  ac: better_auth_plugins.AccessControl<{
2537
- readonly user: readonly ["create", "list", "set-role", "ban", "impersonate", "impersonate-admins", "delete", "set-password", "set-email", "get", "update"];
2590
+ readonly user: readonly ["create", "list", "set-role", "ban", "impersonate", "impersonate-admins", "delete", "set-password", "set-email", "set-phone", "get", "update"];
2538
2591
  readonly session: readonly ["list", "revoke", "delete"];
2539
2592
  }>;
2540
2593
  roles: {
@@ -2547,7 +2600,7 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
2547
2600
  admin: {
2548
2601
  checkRolePermission: <R extends "admin" | "user">(data: {
2549
2602
  permissions: {
2550
- readonly user?: ("update" | "delete" | "create" | "list" | "set-role" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "get")[] | undefined;
2603
+ readonly user?: ("update" | "delete" | "create" | "list" | "set-role" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "set-phone" | "get")[] | undefined;
2551
2604
  readonly session?: ("delete" | "list" | "revoke")[] | undefined;
2552
2605
  };
2553
2606
  } & {
@@ -2587,7 +2640,9 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
2587
2640
  YOU_CANNOT_IMPERSONATE_ADMINS: better_auth.RawError<"YOU_CANNOT_IMPERSONATE_ADMINS">;
2588
2641
  INVALID_ROLE_TYPE: better_auth.RawError<"INVALID_ROLE_TYPE">;
2589
2642
  YOU_ARE_NOT_ALLOWED_TO_SET_USERS_EMAIL: better_auth.RawError<"YOU_ARE_NOT_ALLOWED_TO_SET_USERS_EMAIL">;
2643
+ YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PHONE_NUMBER: better_auth.RawError<"YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PHONE_NUMBER">;
2590
2644
  PASSWORD_CANNOT_BE_UPDATED_VIA_UPDATE_USER: better_auth.RawError<"PASSWORD_CANNOT_BE_UPDATED_VIA_UPDATE_USER">;
2645
+ USER_ID_CANNOT_BE_UPDATED: better_auth.RawError<"USER_ID_CANNOT_BE_UPDATED">;
2591
2646
  };
2592
2647
  } | {
2593
2648
  id: "additional-fields-client";
@@ -4456,22 +4511,22 @@ type UpdateTeamPayload = Pick<Team, 'name'>;
4456
4511
  /**
4457
4512
  * Status of an invitation as seen by the pre-login invite flow.
4458
4513
  *
4459
- * `email` and `requiresAccountSetup` are only present while the invitation is
4460
- * still pending; other statuses return the status alone.
4514
+ * Requires a pending invitation and an unexpired, unused setup token.
4515
+ * Invalid tokens and inactive invitations return an error without email details.
4461
4516
  */
4462
4517
  type InvitationSignupStatus = {
4518
+ invitationId: string;
4463
4519
  status: 'pending';
4464
4520
  email: string;
4465
4521
  /** True when the invited user has no account yet and has never signed in. */
4466
4522
  requiresAccountSetup: boolean;
4467
- } | {
4468
- status: 'accepted' | 'canceled' | 'rejected' | 'expired';
4469
4523
  };
4470
4524
  /**
4471
4525
  * Result of creating a password from an invitation. The user is signed in
4472
4526
  * as part of the call; the session cookie is set on the response.
4473
4527
  */
4474
4528
  type InvitationPasswordSetupResult = {
4529
+ invitationId: string;
4475
4530
  token: string;
4476
4531
  user: {
4477
4532
  id: string;
@@ -4664,14 +4719,14 @@ declare class OrganizationService {
4664
4719
  /**
4665
4720
  * Gets the pre-login signup status for an invitation.
4666
4721
  *
4667
- * Public endpoint keyed by the invitation id from the emailed invite link.
4722
+ * Requires the opaque token delivered only in the invitation email.
4668
4723
  * While the invitation is pending, the result includes the invited email
4669
4724
  * and whether the invited user still needs to set up their account.
4670
4725
  *
4671
- * @param id - The invitation ID from the invite link
4726
+ * @param token - The opaque token from the invite link
4672
4727
  * @returns The invitation status with account-setup information
4673
4728
  */
4674
- getInvitationSignupStatus(id: string): Promise<InvitationSignupStatus>;
4729
+ getInvitationSignupStatus(token: string): Promise<InvitationSignupStatus>;
4675
4730
  /**
4676
4731
  * Creates a password for an invited user who has no account yet.
4677
4732
  *
@@ -4679,11 +4734,11 @@ declare class OrganizationService {
4679
4734
  * the invited user has never signed in. The user is signed in as part of
4680
4735
  * the call; the session cookie is set on the response.
4681
4736
  *
4682
- * @param id - The invitation ID from the invite link
4737
+ * @param token - The single-use opaque token from the invite link
4683
4738
  * @param password - The password to create (minimum 8 characters)
4684
4739
  * @returns The session token and signed-in user
4685
4740
  */
4686
- setupInvitationPassword(id: string, password: string): Promise<InvitationPasswordSetupResult>;
4741
+ setupInvitationPassword(token: string, password: string): Promise<InvitationPasswordSetupResult>;
4687
4742
  /**
4688
4743
  * Removes a user from the active organization.
4689
4744
  *
@@ -5271,56 +5326,6 @@ declare class AuthClient {
5271
5326
  constructor(apiUrl: string, fetchOptions?: BetterFetchOption);
5272
5327
  }
5273
5328
 
5274
- /** Configuration for an in-memory application token cache. */
5275
- type ApplicationTokenStorageOptions = {
5276
- /** Base URL of the Auth API. */
5277
- authApiUrl: string;
5278
- /** Application identifier used for client-credentials exchanges. */
5279
- clientId: string;
5280
- /** Application secret used for client-credentials exchanges. */
5281
- clientSecret: string;
5282
- /** Full-jitter upper bound for the first retry delay. Defaults to 100 milliseconds. */
5283
- initialBackoffMs?: number;
5284
- /** Maximum number of exchange attempts, including the initial request. Defaults to 3. */
5285
- maxAttempts?: number;
5286
- /** Maximum number of organization tokens retained in memory. Defaults to 300. */
5287
- maxOrganizations?: number;
5288
- };
5289
- /** Per-call retry overrides for {@link ApplicationTokenStorage.getToken}. */
5290
- type GetTokenOptions = {
5291
- /** Full-jitter upper bound for the first retry delay. */
5292
- initialBackoffMs?: number;
5293
- /** Maximum number of exchange attempts, including the initial request. */
5294
- maxAttempts?: number;
5295
- };
5296
- /**
5297
- * Caches organization-scoped application tokens in memory.
5298
- *
5299
- * Tokens are reissued one minute before expiry. Cache hits promote their
5300
- * organization to the most-recently-used position, and insertions beyond the
5301
- * configured limit evict the least recently used organization. Transient
5302
- * exchange failures use full-jitter exponential backoff.
5303
- */
5304
- declare class ApplicationTokenStorage {
5305
- private readonly auth;
5306
- private readonly clientId;
5307
- private readonly clientSecret;
5308
- private readonly initialBackoffMs;
5309
- private readonly inFlight;
5310
- private readonly maxAttempts;
5311
- private readonly maxOrganizations;
5312
- private readonly tokens;
5313
- /** Creates an application token cache for one client-credentials identity. */
5314
- constructor({ authApiUrl, clientId, clientSecret, initialBackoffMs, maxAttempts, maxOrganizations, }: ApplicationTokenStorageOptions);
5315
- /** Returns a fresh access token scoped to the requested organization. */
5316
- getToken(organizationId: string, { initialBackoffMs, maxAttempts, }?: GetTokenOptions): Promise<string>;
5317
- private exchangeTokenWithRetry;
5318
- /** Performs the client-credentials exchange for one organization. */
5319
- protected exchangeToken(organizationId: string): Promise<string>;
5320
- /** Waits before the next exchange attempt. */
5321
- protected wait(delayMs: number): Promise<void>;
5322
- }
5323
-
5324
5329
  type DecodedJWTPayload = Omit<JWTPayload, 'assurance'> & {
5325
5330
  assurance?: JWTPayloadAssurance;
5326
5331
  };
package/dist/index.d.ts CHANGED
@@ -349,6 +349,56 @@ type JWTPayload = JWTPayload$1 & JWTPayloadData;
349
349
  */
350
350
  declare function isTokenExpired(token: string, expiresInMs?: number): boolean;
351
351
 
352
+ /** Configuration for an in-memory application token cache. */
353
+ type ApplicationTokenStorageOptions = {
354
+ /** Base URL of the Auth API. */
355
+ authApiUrl: string;
356
+ /** Application identifier used for client-credentials exchanges. */
357
+ clientId: string;
358
+ /** Application secret used for client-credentials exchanges. */
359
+ clientSecret: string;
360
+ /** Full-jitter upper bound for the first retry delay. Defaults to 100 milliseconds. */
361
+ initialBackoffMs?: number;
362
+ /** Maximum number of exchange attempts, including the initial request. Defaults to 3. */
363
+ maxAttempts?: number;
364
+ /** Maximum number of organization tokens retained in memory. Defaults to 300. */
365
+ maxOrganizations?: number;
366
+ };
367
+ /** Per-call retry overrides for {@link ApplicationTokenStorage.getToken}. */
368
+ type GetTokenOptions = {
369
+ /** Full-jitter upper bound for the first retry delay. */
370
+ initialBackoffMs?: number;
371
+ /** Maximum number of exchange attempts, including the initial request. */
372
+ maxAttempts?: number;
373
+ };
374
+ /**
375
+ * Caches organization-scoped application tokens in memory.
376
+ *
377
+ * Tokens are reissued one minute before expiry. Cache hits promote their
378
+ * organization to the most-recently-used position, and insertions beyond the
379
+ * configured limit evict the least recently used organization. Transient
380
+ * exchange failures use full-jitter exponential backoff.
381
+ */
382
+ declare class ApplicationTokenStorage {
383
+ private readonly auth;
384
+ private readonly clientId;
385
+ private readonly clientSecret;
386
+ private readonly initialBackoffMs;
387
+ private readonly inFlight;
388
+ private readonly maxAttempts;
389
+ private readonly maxOrganizations;
390
+ private readonly tokens;
391
+ /** Creates an application token cache for one client-credentials identity. */
392
+ constructor({ authApiUrl, clientId, clientSecret, initialBackoffMs, maxAttempts, maxOrganizations, }: ApplicationTokenStorageOptions);
393
+ /** Returns a fresh access token scoped to the requested organization. */
394
+ getToken(organizationId: string, { initialBackoffMs, maxAttempts, }?: GetTokenOptions): Promise<string>;
395
+ private exchangeTokenWithRetry;
396
+ /** Performs the client-credentials exchange for one organization. */
397
+ protected exchangeToken(organizationId: string): Promise<string>;
398
+ /** Waits before the next exchange attempt. */
399
+ protected wait(delayMs: number): Promise<void>;
400
+ }
401
+
352
402
  declare const OAuthStepUpProvider: z__default.ZodEnum<{
353
403
  google: "google";
354
404
  microsoft: "microsoft";
@@ -1468,6 +1518,7 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
1468
1518
  EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION: better_auth.RawError<"EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION">;
1469
1519
  EMAIL_VERIFICATION_REQUIRED_FOR_INVITATION: better_auth.RawError<"EMAIL_VERIFICATION_REQUIRED_FOR_INVITATION">;
1470
1520
  YOU_ARE_NOT_ALLOWED_TO_CANCEL_THIS_INVITATION: better_auth.RawError<"YOU_ARE_NOT_ALLOWED_TO_CANCEL_THIS_INVITATION">;
1521
+ YOU_ARE_NOT_ALLOWED_TO_LIST_INVITATIONS: better_auth.RawError<"YOU_ARE_NOT_ALLOWED_TO_LIST_INVITATIONS">;
1471
1522
  INVITER_IS_NO_LONGER_A_MEMBER_OF_THE_ORGANIZATION: better_auth.RawError<"INVITER_IS_NO_LONGER_A_MEMBER_OF_THE_ORGANIZATION">;
1472
1523
  YOU_ARE_NOT_ALLOWED_TO_INVITE_USER_WITH_THIS_ROLE: better_auth.RawError<"YOU_ARE_NOT_ALLOWED_TO_INVITE_USER_WITH_THIS_ROLE">;
1473
1524
  FAILED_TO_RETRIEVE_INVITATION: better_auth.RawError<"FAILED_TO_RETRIEVE_INVITATION">;
@@ -1519,8 +1570,8 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
1519
1570
  id: "invitation-signup";
1520
1571
  getActions: ($fetch: better_auth_client.BetterFetch) => {
1521
1572
  invitationSignup: {
1522
- status: (invitationId: string) => Promise<InvitationSignupStatus>;
1523
- setupPassword: (invitationId: string, password: string) => Promise<InvitationPasswordSetupResult>;
1573
+ status: (token: string) => Promise<InvitationSignupStatus>;
1574
+ setupPassword: (token: string, password: string) => Promise<InvitationPasswordSetupResult>;
1524
1575
  };
1525
1576
  };
1526
1577
  } | {
@@ -1650,7 +1701,7 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
1650
1701
  $InferServerPlugin: {
1651
1702
  id: "admin";
1652
1703
  version: string;
1653
- init(): {
1704
+ init(authContext: better_auth.AuthContext): {
1654
1705
  options: {
1655
1706
  databaseHooks: {
1656
1707
  user: {
@@ -2457,7 +2508,7 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
2457
2508
  $Infer: {
2458
2509
  body: {
2459
2510
  permissions: {
2460
- readonly user?: ("update" | "delete" | "create" | "list" | "set-role" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "get")[] | undefined;
2511
+ readonly user?: ("update" | "delete" | "create" | "list" | "set-role" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "set-phone" | "get")[] | undefined;
2461
2512
  readonly session?: ("delete" | "list" | "revoke")[] | undefined;
2462
2513
  };
2463
2514
  } & {
@@ -2494,7 +2545,9 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
2494
2545
  YOU_CANNOT_IMPERSONATE_ADMINS: better_auth.RawError<"YOU_CANNOT_IMPERSONATE_ADMINS">;
2495
2546
  INVALID_ROLE_TYPE: better_auth.RawError<"INVALID_ROLE_TYPE">;
2496
2547
  YOU_ARE_NOT_ALLOWED_TO_SET_USERS_EMAIL: better_auth.RawError<"YOU_ARE_NOT_ALLOWED_TO_SET_USERS_EMAIL">;
2548
+ YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PHONE_NUMBER: better_auth.RawError<"YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PHONE_NUMBER">;
2497
2549
  PASSWORD_CANNOT_BE_UPDATED_VIA_UPDATE_USER: better_auth.RawError<"PASSWORD_CANNOT_BE_UPDATED_VIA_UPDATE_USER">;
2550
+ USER_ID_CANNOT_BE_UPDATED: better_auth.RawError<"USER_ID_CANNOT_BE_UPDATED">;
2498
2551
  };
2499
2552
  schema: {
2500
2553
  user: {
@@ -2534,7 +2587,7 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
2534
2587
  };
2535
2588
  options: NoInfer<{
2536
2589
  ac: better_auth_plugins.AccessControl<{
2537
- readonly user: readonly ["create", "list", "set-role", "ban", "impersonate", "impersonate-admins", "delete", "set-password", "set-email", "get", "update"];
2590
+ readonly user: readonly ["create", "list", "set-role", "ban", "impersonate", "impersonate-admins", "delete", "set-password", "set-email", "set-phone", "get", "update"];
2538
2591
  readonly session: readonly ["list", "revoke", "delete"];
2539
2592
  }>;
2540
2593
  roles: {
@@ -2547,7 +2600,7 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
2547
2600
  admin: {
2548
2601
  checkRolePermission: <R extends "admin" | "user">(data: {
2549
2602
  permissions: {
2550
- readonly user?: ("update" | "delete" | "create" | "list" | "set-role" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "get")[] | undefined;
2603
+ readonly user?: ("update" | "delete" | "create" | "list" | "set-role" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "set-phone" | "get")[] | undefined;
2551
2604
  readonly session?: ("delete" | "list" | "revoke")[] | undefined;
2552
2605
  };
2553
2606
  } & {
@@ -2587,7 +2640,9 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
2587
2640
  YOU_CANNOT_IMPERSONATE_ADMINS: better_auth.RawError<"YOU_CANNOT_IMPERSONATE_ADMINS">;
2588
2641
  INVALID_ROLE_TYPE: better_auth.RawError<"INVALID_ROLE_TYPE">;
2589
2642
  YOU_ARE_NOT_ALLOWED_TO_SET_USERS_EMAIL: better_auth.RawError<"YOU_ARE_NOT_ALLOWED_TO_SET_USERS_EMAIL">;
2643
+ YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PHONE_NUMBER: better_auth.RawError<"YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PHONE_NUMBER">;
2590
2644
  PASSWORD_CANNOT_BE_UPDATED_VIA_UPDATE_USER: better_auth.RawError<"PASSWORD_CANNOT_BE_UPDATED_VIA_UPDATE_USER">;
2645
+ USER_ID_CANNOT_BE_UPDATED: better_auth.RawError<"USER_ID_CANNOT_BE_UPDATED">;
2591
2646
  };
2592
2647
  } | {
2593
2648
  id: "additional-fields-client";
@@ -4456,22 +4511,22 @@ type UpdateTeamPayload = Pick<Team, 'name'>;
4456
4511
  /**
4457
4512
  * Status of an invitation as seen by the pre-login invite flow.
4458
4513
  *
4459
- * `email` and `requiresAccountSetup` are only present while the invitation is
4460
- * still pending; other statuses return the status alone.
4514
+ * Requires a pending invitation and an unexpired, unused setup token.
4515
+ * Invalid tokens and inactive invitations return an error without email details.
4461
4516
  */
4462
4517
  type InvitationSignupStatus = {
4518
+ invitationId: string;
4463
4519
  status: 'pending';
4464
4520
  email: string;
4465
4521
  /** True when the invited user has no account yet and has never signed in. */
4466
4522
  requiresAccountSetup: boolean;
4467
- } | {
4468
- status: 'accepted' | 'canceled' | 'rejected' | 'expired';
4469
4523
  };
4470
4524
  /**
4471
4525
  * Result of creating a password from an invitation. The user is signed in
4472
4526
  * as part of the call; the session cookie is set on the response.
4473
4527
  */
4474
4528
  type InvitationPasswordSetupResult = {
4529
+ invitationId: string;
4475
4530
  token: string;
4476
4531
  user: {
4477
4532
  id: string;
@@ -4664,14 +4719,14 @@ declare class OrganizationService {
4664
4719
  /**
4665
4720
  * Gets the pre-login signup status for an invitation.
4666
4721
  *
4667
- * Public endpoint keyed by the invitation id from the emailed invite link.
4722
+ * Requires the opaque token delivered only in the invitation email.
4668
4723
  * While the invitation is pending, the result includes the invited email
4669
4724
  * and whether the invited user still needs to set up their account.
4670
4725
  *
4671
- * @param id - The invitation ID from the invite link
4726
+ * @param token - The opaque token from the invite link
4672
4727
  * @returns The invitation status with account-setup information
4673
4728
  */
4674
- getInvitationSignupStatus(id: string): Promise<InvitationSignupStatus>;
4729
+ getInvitationSignupStatus(token: string): Promise<InvitationSignupStatus>;
4675
4730
  /**
4676
4731
  * Creates a password for an invited user who has no account yet.
4677
4732
  *
@@ -4679,11 +4734,11 @@ declare class OrganizationService {
4679
4734
  * the invited user has never signed in. The user is signed in as part of
4680
4735
  * the call; the session cookie is set on the response.
4681
4736
  *
4682
- * @param id - The invitation ID from the invite link
4737
+ * @param token - The single-use opaque token from the invite link
4683
4738
  * @param password - The password to create (minimum 8 characters)
4684
4739
  * @returns The session token and signed-in user
4685
4740
  */
4686
- setupInvitationPassword(id: string, password: string): Promise<InvitationPasswordSetupResult>;
4741
+ setupInvitationPassword(token: string, password: string): Promise<InvitationPasswordSetupResult>;
4687
4742
  /**
4688
4743
  * Removes a user from the active organization.
4689
4744
  *
@@ -5271,56 +5326,6 @@ declare class AuthClient {
5271
5326
  constructor(apiUrl: string, fetchOptions?: BetterFetchOption);
5272
5327
  }
5273
5328
 
5274
- /** Configuration for an in-memory application token cache. */
5275
- type ApplicationTokenStorageOptions = {
5276
- /** Base URL of the Auth API. */
5277
- authApiUrl: string;
5278
- /** Application identifier used for client-credentials exchanges. */
5279
- clientId: string;
5280
- /** Application secret used for client-credentials exchanges. */
5281
- clientSecret: string;
5282
- /** Full-jitter upper bound for the first retry delay. Defaults to 100 milliseconds. */
5283
- initialBackoffMs?: number;
5284
- /** Maximum number of exchange attempts, including the initial request. Defaults to 3. */
5285
- maxAttempts?: number;
5286
- /** Maximum number of organization tokens retained in memory. Defaults to 300. */
5287
- maxOrganizations?: number;
5288
- };
5289
- /** Per-call retry overrides for {@link ApplicationTokenStorage.getToken}. */
5290
- type GetTokenOptions = {
5291
- /** Full-jitter upper bound for the first retry delay. */
5292
- initialBackoffMs?: number;
5293
- /** Maximum number of exchange attempts, including the initial request. */
5294
- maxAttempts?: number;
5295
- };
5296
- /**
5297
- * Caches organization-scoped application tokens in memory.
5298
- *
5299
- * Tokens are reissued one minute before expiry. Cache hits promote their
5300
- * organization to the most-recently-used position, and insertions beyond the
5301
- * configured limit evict the least recently used organization. Transient
5302
- * exchange failures use full-jitter exponential backoff.
5303
- */
5304
- declare class ApplicationTokenStorage {
5305
- private readonly auth;
5306
- private readonly clientId;
5307
- private readonly clientSecret;
5308
- private readonly initialBackoffMs;
5309
- private readonly inFlight;
5310
- private readonly maxAttempts;
5311
- private readonly maxOrganizations;
5312
- private readonly tokens;
5313
- /** Creates an application token cache for one client-credentials identity. */
5314
- constructor({ authApiUrl, clientId, clientSecret, initialBackoffMs, maxAttempts, maxOrganizations, }: ApplicationTokenStorageOptions);
5315
- /** Returns a fresh access token scoped to the requested organization. */
5316
- getToken(organizationId: string, { initialBackoffMs, maxAttempts, }?: GetTokenOptions): Promise<string>;
5317
- private exchangeTokenWithRetry;
5318
- /** Performs the client-credentials exchange for one organization. */
5319
- protected exchangeToken(organizationId: string): Promise<string>;
5320
- /** Waits before the next exchange attempt. */
5321
- protected wait(delayMs: number): Promise<void>;
5322
- }
5323
-
5324
5329
  type DecodedJWTPayload = Omit<JWTPayload, 'assurance'> & {
5325
5330
  assurance?: JWTPayloadAssurance;
5326
5331
  };
package/dist/index.mjs CHANGED
@@ -21,7 +21,7 @@ function isTokenExpired(token, expiresInMs) {
21
21
  return nowInSeconds > expirationTime;
22
22
  }
23
23
 
24
- const version = "3.5.0";
24
+ const version = "4.0.1";
25
25
 
26
26
  function parsedEnumValues(schema) {
27
27
  return Object.fromEntries(
@@ -405,15 +405,16 @@ function invitationSignupPluginClient() {
405
405
  id: "invitation-signup",
406
406
  getActions: ($fetch) => ({
407
407
  invitationSignup: {
408
- status: async (invitationId) => {
408
+ status: async (token) => {
409
409
  return await $fetch("/invitation/signup-status", {
410
- query: { invitationId }
410
+ method: "GET",
411
+ query: { token }
411
412
  });
412
413
  },
413
- setupPassword: async (invitationId, password) => {
414
+ setupPassword: async (token, password) => {
414
415
  return await $fetch("/invitation/setup-password", {
415
416
  method: "POST",
416
- body: { invitationId, password }
417
+ body: { token, password }
417
418
  });
418
419
  }
419
420
  }
@@ -2036,15 +2037,15 @@ class OrganizationService {
2036
2037
  /**
2037
2038
  * Gets the pre-login signup status for an invitation.
2038
2039
  *
2039
- * Public endpoint keyed by the invitation id from the emailed invite link.
2040
+ * Requires the opaque token delivered only in the invitation email.
2040
2041
  * While the invitation is pending, the result includes the invited email
2041
2042
  * and whether the invited user still needs to set up their account.
2042
2043
  *
2043
- * @param id - The invitation ID from the invite link
2044
+ * @param token - The opaque token from the invite link
2044
2045
  * @returns The invitation status with account-setup information
2045
2046
  */
2046
- async getInvitationSignupStatus(id) {
2047
- return await this.client.invitationSignup.status(id);
2047
+ async getInvitationSignupStatus(token) {
2048
+ return await this.client.invitationSignup.status(token);
2048
2049
  }
2049
2050
  /**
2050
2051
  * Creates a password for an invited user who has no account yet.
@@ -2053,12 +2054,12 @@ class OrganizationService {
2053
2054
  * the invited user has never signed in. The user is signed in as part of
2054
2055
  * the call; the session cookie is set on the response.
2055
2056
  *
2056
- * @param id - The invitation ID from the invite link
2057
+ * @param token - The single-use opaque token from the invite link
2057
2058
  * @param password - The password to create (minimum 8 characters)
2058
2059
  * @returns The session token and signed-in user
2059
2060
  */
2060
- async setupInvitationPassword(id, password) {
2061
- return await this.client.invitationSignup.setupPassword(id, password);
2061
+ async setupInvitationPassword(token, password) {
2062
+ return await this.client.invitationSignup.setupPassword(token, password);
2062
2063
  }
2063
2064
  /**
2064
2065
  * Removes a user from the active organization.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/auth-core",
3
- "version": "3.5.0",
3
+ "version": "4.0.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -18,9 +18,9 @@
18
18
  "docs": "typedoc"
19
19
  },
20
20
  "dependencies": {
21
- "@better-auth/api-key": "1.7.14",
22
- "@better-auth/sso": "1.7.14",
23
- "better-auth": "1.7.14",
21
+ "@better-auth/api-key": "1.7.16",
22
+ "@better-auth/sso": "1.7.16",
23
+ "better-auth": "1.7.16",
24
24
  "jose": "6.2.14",
25
25
  "zod": "4.6.7"
26
26
  },