@meistrari/auth-core 3.5.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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";
@@ -1519,8 +1569,8 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
1519
1569
  id: "invitation-signup";
1520
1570
  getActions: ($fetch: better_auth_client.BetterFetch) => {
1521
1571
  invitationSignup: {
1522
- status: (invitationId: string) => Promise<InvitationSignupStatus>;
1523
- setupPassword: (invitationId: string, password: string) => Promise<InvitationPasswordSetupResult>;
1572
+ status: (token: string) => Promise<InvitationSignupStatus>;
1573
+ setupPassword: (token: string, password: string) => Promise<InvitationPasswordSetupResult>;
1524
1574
  };
1525
1575
  };
1526
1576
  } | {
@@ -4456,22 +4506,22 @@ type UpdateTeamPayload = Pick<Team, 'name'>;
4456
4506
  /**
4457
4507
  * Status of an invitation as seen by the pre-login invite flow.
4458
4508
  *
4459
- * `email` and `requiresAccountSetup` are only present while the invitation is
4460
- * still pending; other statuses return the status alone.
4509
+ * Requires a pending invitation and an unexpired, unused setup token.
4510
+ * Invalid tokens and inactive invitations return an error without email details.
4461
4511
  */
4462
4512
  type InvitationSignupStatus = {
4513
+ invitationId: string;
4463
4514
  status: 'pending';
4464
4515
  email: string;
4465
4516
  /** True when the invited user has no account yet and has never signed in. */
4466
4517
  requiresAccountSetup: boolean;
4467
- } | {
4468
- status: 'accepted' | 'canceled' | 'rejected' | 'expired';
4469
4518
  };
4470
4519
  /**
4471
4520
  * Result of creating a password from an invitation. The user is signed in
4472
4521
  * as part of the call; the session cookie is set on the response.
4473
4522
  */
4474
4523
  type InvitationPasswordSetupResult = {
4524
+ invitationId: string;
4475
4525
  token: string;
4476
4526
  user: {
4477
4527
  id: string;
@@ -4664,14 +4714,14 @@ declare class OrganizationService {
4664
4714
  /**
4665
4715
  * Gets the pre-login signup status for an invitation.
4666
4716
  *
4667
- * Public endpoint keyed by the invitation id from the emailed invite link.
4717
+ * Requires the opaque token delivered only in the invitation email.
4668
4718
  * While the invitation is pending, the result includes the invited email
4669
4719
  * and whether the invited user still needs to set up their account.
4670
4720
  *
4671
- * @param id - The invitation ID from the invite link
4721
+ * @param token - The opaque token from the invite link
4672
4722
  * @returns The invitation status with account-setup information
4673
4723
  */
4674
- getInvitationSignupStatus(id: string): Promise<InvitationSignupStatus>;
4724
+ getInvitationSignupStatus(token: string): Promise<InvitationSignupStatus>;
4675
4725
  /**
4676
4726
  * Creates a password for an invited user who has no account yet.
4677
4727
  *
@@ -4679,11 +4729,11 @@ declare class OrganizationService {
4679
4729
  * the invited user has never signed in. The user is signed in as part of
4680
4730
  * the call; the session cookie is set on the response.
4681
4731
  *
4682
- * @param id - The invitation ID from the invite link
4732
+ * @param token - The single-use opaque token from the invite link
4683
4733
  * @param password - The password to create (minimum 8 characters)
4684
4734
  * @returns The session token and signed-in user
4685
4735
  */
4686
- setupInvitationPassword(id: string, password: string): Promise<InvitationPasswordSetupResult>;
4736
+ setupInvitationPassword(token: string, password: string): Promise<InvitationPasswordSetupResult>;
4687
4737
  /**
4688
4738
  * Removes a user from the active organization.
4689
4739
  *
@@ -5271,56 +5321,6 @@ declare class AuthClient {
5271
5321
  constructor(apiUrl: string, fetchOptions?: BetterFetchOption);
5272
5322
  }
5273
5323
 
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
5324
  type DecodedJWTPayload = Omit<JWTPayload, 'assurance'> & {
5325
5325
  assurance?: JWTPayloadAssurance;
5326
5326
  };
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";
@@ -1519,8 +1569,8 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
1519
1569
  id: "invitation-signup";
1520
1570
  getActions: ($fetch: better_auth_client.BetterFetch) => {
1521
1571
  invitationSignup: {
1522
- status: (invitationId: string) => Promise<InvitationSignupStatus>;
1523
- setupPassword: (invitationId: string, password: string) => Promise<InvitationPasswordSetupResult>;
1572
+ status: (token: string) => Promise<InvitationSignupStatus>;
1573
+ setupPassword: (token: string, password: string) => Promise<InvitationPasswordSetupResult>;
1524
1574
  };
1525
1575
  };
1526
1576
  } | {
@@ -4456,22 +4506,22 @@ type UpdateTeamPayload = Pick<Team, 'name'>;
4456
4506
  /**
4457
4507
  * Status of an invitation as seen by the pre-login invite flow.
4458
4508
  *
4459
- * `email` and `requiresAccountSetup` are only present while the invitation is
4460
- * still pending; other statuses return the status alone.
4509
+ * Requires a pending invitation and an unexpired, unused setup token.
4510
+ * Invalid tokens and inactive invitations return an error without email details.
4461
4511
  */
4462
4512
  type InvitationSignupStatus = {
4513
+ invitationId: string;
4463
4514
  status: 'pending';
4464
4515
  email: string;
4465
4516
  /** True when the invited user has no account yet and has never signed in. */
4466
4517
  requiresAccountSetup: boolean;
4467
- } | {
4468
- status: 'accepted' | 'canceled' | 'rejected' | 'expired';
4469
4518
  };
4470
4519
  /**
4471
4520
  * Result of creating a password from an invitation. The user is signed in
4472
4521
  * as part of the call; the session cookie is set on the response.
4473
4522
  */
4474
4523
  type InvitationPasswordSetupResult = {
4524
+ invitationId: string;
4475
4525
  token: string;
4476
4526
  user: {
4477
4527
  id: string;
@@ -4664,14 +4714,14 @@ declare class OrganizationService {
4664
4714
  /**
4665
4715
  * Gets the pre-login signup status for an invitation.
4666
4716
  *
4667
- * Public endpoint keyed by the invitation id from the emailed invite link.
4717
+ * Requires the opaque token delivered only in the invitation email.
4668
4718
  * While the invitation is pending, the result includes the invited email
4669
4719
  * and whether the invited user still needs to set up their account.
4670
4720
  *
4671
- * @param id - The invitation ID from the invite link
4721
+ * @param token - The opaque token from the invite link
4672
4722
  * @returns The invitation status with account-setup information
4673
4723
  */
4674
- getInvitationSignupStatus(id: string): Promise<InvitationSignupStatus>;
4724
+ getInvitationSignupStatus(token: string): Promise<InvitationSignupStatus>;
4675
4725
  /**
4676
4726
  * Creates a password for an invited user who has no account yet.
4677
4727
  *
@@ -4679,11 +4729,11 @@ declare class OrganizationService {
4679
4729
  * the invited user has never signed in. The user is signed in as part of
4680
4730
  * the call; the session cookie is set on the response.
4681
4731
  *
4682
- * @param id - The invitation ID from the invite link
4732
+ * @param token - The single-use opaque token from the invite link
4683
4733
  * @param password - The password to create (minimum 8 characters)
4684
4734
  * @returns The session token and signed-in user
4685
4735
  */
4686
- setupInvitationPassword(id: string, password: string): Promise<InvitationPasswordSetupResult>;
4736
+ setupInvitationPassword(token: string, password: string): Promise<InvitationPasswordSetupResult>;
4687
4737
  /**
4688
4738
  * Removes a user from the active organization.
4689
4739
  *
@@ -5271,56 +5321,6 @@ declare class AuthClient {
5271
5321
  constructor(apiUrl: string, fetchOptions?: BetterFetchOption);
5272
5322
  }
5273
5323
 
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
5324
  type DecodedJWTPayload = Omit<JWTPayload, 'assurance'> & {
5325
5325
  assurance?: JWTPayloadAssurance;
5326
5326
  };
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.0";
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.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {