@meistrari/auth-core 2.10.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -275,6 +275,12 @@ declare const invitationAdditionalFields: {
275
275
  input: true;
276
276
  required: false;
277
277
  };
278
+ /** Application role granted when an application invitation is accepted. */
279
+ applicationRole: {
280
+ type: "string";
281
+ input: true;
282
+ required: false;
283
+ };
278
284
  };
279
285
  /**
280
286
  * Zod schema and type for the `user` claim within a JWT payload.
@@ -771,6 +777,17 @@ type DeviceAuthorizationContextResponse = {
771
777
  /** Seconds remaining before the device code expires. */
772
778
  expiresIn: number;
773
779
  };
780
+ /**
781
+ * Role of the application an application session was issued for.
782
+ */
783
+ type ApplicationRole = {
784
+ applicationId: string;
785
+ name: string;
786
+ displayName: string;
787
+ description: string;
788
+ /** Roles of the same application this role may grant, change, revoke and invite. */
789
+ manageableRoles: string[];
790
+ };
774
791
  /**
775
792
  * Response returned when approving or denying a device authorization request.
776
793
  */
@@ -1038,6 +1055,12 @@ declare class ApplicationService {
1038
1055
  * @param refreshToken - The refresh token to invalidate
1039
1056
  */
1040
1057
  logout(refreshToken: string): Promise<void>;
1058
+ /**
1059
+ * Lists the roles of the application the current session was issued for.
1060
+ *
1061
+ * @returns The application's roles
1062
+ */
1063
+ listRoles(): Promise<ApplicationRole[]>;
1041
1064
  }
1042
1065
 
1043
1066
  declare const ApiKeyMetadata: zod__default.ZodObject<{
@@ -1449,13 +1472,6 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
1449
1472
  };
1450
1473
  };
1451
1474
  };
1452
- } | {
1453
- id: "handshake";
1454
- getActions: ($fetch: better_auth_client.BetterFetch) => {
1455
- handshake: {
1456
- noncePayload: (nonce: string) => Promise<NoncePayloadResponse>;
1457
- };
1458
- };
1459
1475
  } | {
1460
1476
  id: "invitation-signup";
1461
1477
  getActions: ($fetch: better_auth_client.BetterFetch) => {
@@ -3568,6 +3584,17 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
3568
3584
  data: void;
3569
3585
  error: null;
3570
3586
  }>;
3587
+ listApplicationRoles: () => Promise<{
3588
+ data: null;
3589
+ error: {
3590
+ message?: string | undefined;
3591
+ status: number;
3592
+ statusText: string;
3593
+ };
3594
+ } | {
3595
+ data: ApplicationRole[];
3596
+ error: null;
3597
+ }>;
3571
3598
  };
3572
3599
  };
3573
3600
  } | {
@@ -4323,11 +4350,19 @@ type OrganizationSettings = {
4323
4350
  type ExtendedOrganization = BaseOrganization & {
4324
4351
  settings?: OrganizationSettings;
4325
4352
  };
4353
+ /**
4354
+ * A member of a {@link FullOrganization}.
4355
+ */
4356
+ type FullOrganizationMember = Member & {
4357
+ /** The member's role in the session's application. Only set for application sessions. */
4358
+ applicationRole?: string | null;
4359
+ };
4326
4360
  /**
4327
4361
  * A complete organization object including its members, invitations, and teams.
4328
4362
  */
4329
4363
  type FullOrganization = ExtendedOrganization & {
4330
- members: Member[];
4364
+ /** With an application session, only members with access to the application. */
4365
+ members: FullOrganizationMember[];
4331
4366
  invitations: Invitation[];
4332
4367
  teams: Team[];
4333
4368
  };
@@ -4386,6 +4421,8 @@ type ListAdminUsersOptions = {
4386
4421
  * admin, whose listing is always pinned to their own organization.
4387
4422
  */
4388
4423
  organizationId?: string;
4424
+ /** Restricts the listing to people with access to this application. Requires organizationId when listing users. */
4425
+ applicationId?: string;
4389
4426
  };
4390
4427
  /**
4391
4428
  * Organization preview returned alongside each admin user row.
@@ -4545,6 +4582,8 @@ type ListAdminOrganizationMembersOptions = {
4545
4582
  sortBy?: 'createdAt' | 'name';
4546
4583
  /** Sort direction for the listing. Defaults to 'desc'. */
4547
4584
  sortDirection?: 'asc' | 'desc';
4585
+ /** Restricts the listing to people with access to this application. */
4586
+ applicationId?: string;
4548
4587
  };
4549
4588
  /**
4550
4589
  * Options accepted when listing teams for a single organization as a global admin.
@@ -4714,20 +4753,6 @@ type AdminUserInvitation = {
4714
4753
  expiresAt: string;
4715
4754
  createdAt: string;
4716
4755
  };
4717
- /**
4718
- * Options accepted when resending an organization invitation as a global admin.
4719
- */
4720
- type ResendAdminInviteOptions = {
4721
- organizationId: string;
4722
- email: string;
4723
- role: string;
4724
- applicationId?: string;
4725
- /**
4726
- * Teams joined when the re-sent invitation is accepted. Resending replaces the
4727
- * invitation, so these must be provided to preserve the original team assignments.
4728
- */
4729
- teamIds?: string[];
4730
- };
4731
4756
  /**
4732
4757
  * User row returned by the admin user listing endpoint.
4733
4758
  */
@@ -4755,6 +4780,8 @@ type AdminUser = {
4755
4780
  organizationCount?: number;
4756
4781
  /** Preview of the first organizations the user belongs to. Present when requested via organizationsPreview. */
4757
4782
  organizations?: AdminUserOrganization[];
4783
+ /** App role. Present when the listing is scoped to an application; null on invitation rows. */
4784
+ applicationRole?: string | null;
4758
4785
  };
4759
4786
  /**
4760
4787
  * Paginated admin user listing response.
@@ -4809,6 +4836,8 @@ type AdminOrganizationMemberRecord = {
4809
4836
  expiresAt?: string;
4810
4837
  teams?: AdminOrganizationMemberTeam[];
4811
4838
  applications?: AdminOrganizationMemberApplication[];
4839
+ /** App role. Present when the listing is scoped to an application; null on invitation rows. */
4840
+ applicationRole?: string | null;
4812
4841
  };
4813
4842
  /**
4814
4843
  * Paginated organization member listing response.
@@ -4915,9 +4944,16 @@ type AdminApplicationRole = {
4915
4944
  name: string;
4916
4945
  displayName: string;
4917
4946
  description: string;
4947
+ /** Roles of the same application this role may grant, change, revoke and invite. */
4948
+ manageableRoles: string[];
4949
+ };
4950
+ /**
4951
+ * Options accepted when creating an application role. Omitting `manageableRoles`
4952
+ * creates the role with none, and on update keeps the stored list.
4953
+ */
4954
+ type CreateAdminApplicationRoleOptions = Omit<AdminApplicationRole, 'applicationId' | 'manageableRoles'> & {
4955
+ manageableRoles?: string[];
4918
4956
  };
4919
- /** Options accepted when creating an application role. */
4920
- type CreateAdminApplicationRoleOptions = Omit<AdminApplicationRole, 'applicationId'>;
4921
4957
  /** Options accepted when updating an application role. */
4922
4958
  type UpdateAdminApplicationRoleOptions = CreateAdminApplicationRoleOptions;
4923
4959
  /** Kind of matcher an entitlement rule applies. */
@@ -5520,10 +5556,11 @@ declare class AdminService {
5520
5556
  */
5521
5557
  cancelInvite(invitationId: string): Promise<void>;
5522
5558
  /**
5523
- * Re-sends an organization invitation email as a global admin.
5524
- * @param options - Organization, email, role, and optional application and teams
5559
+ * Replaces a pending invitation with a new one that keeps its roles and
5560
+ * teams, and emails it, as a global admin.
5561
+ * @param invitationId - The ID of the invitation to resend
5525
5562
  */
5526
- resendInvite(options: ResendAdminInviteOptions): Promise<void>;
5563
+ resendInvite(invitationId: string): Promise<void>;
5527
5564
  /**
5528
5565
  * Invites several users to an organization in one call, or — with
5529
5566
  * `sendInvite: false` — adds them as members immediately, creating user
@@ -5588,6 +5625,18 @@ type ListMembersOptions = {
5588
5625
  sortBy?: 'createdAt';
5589
5626
  /** Sort direction for the member page. */
5590
5627
  sortDirection?: 'asc' | 'desc';
5628
+ /** With an application session, also lists organization members without access to the application, marked hasAccess: false. Requires permission to grant access. */
5629
+ includeWithoutAccess?: boolean;
5630
+ };
5631
+ /**
5632
+ * Organization member as returned to an application session, with the member's
5633
+ * role in the application.
5634
+ */
5635
+ type ApplicationScopedMember = Member & {
5636
+ /** The member's role in the application, or null without access. */
5637
+ applicationRole?: string | null;
5638
+ /** Present when includeWithoutAccess was requested. */
5639
+ hasAccess?: boolean;
5591
5640
  };
5592
5641
  /**
5593
5642
  * Options for inviting a user to the active organization.
@@ -5601,6 +5650,8 @@ type InviteUserToOrganizationOptions = {
5601
5650
  userEmail: string;
5602
5651
  /** Organization role to assign to the invited user. */
5603
5652
  role: Role;
5653
+ /** Application role granted on acceptance. Required with an application-scoped session. */
5654
+ applicationRole?: string;
5604
5655
  /** Optional team to add the user to upon acceptance. */
5605
5656
  teamId?: string;
5606
5657
  /** Whether to resend the invitation if one already exists for this email. */
@@ -5622,12 +5673,16 @@ type RemoveUserFromOrganizationOptions = {
5622
5673
  };
5623
5674
  /**
5624
5675
  * Options for updating a member's role within the organization.
5676
+ *
5677
+ * With an application-scoped session, `role` is an application role and the
5678
+ * update grants or changes access to that application. The organization role
5679
+ * is left unchanged.
5625
5680
  */
5626
5681
  type UpdateMemberRoleOptions = {
5627
5682
  /** The member ID whose role should be updated. */
5628
5683
  memberId: string;
5629
- /** The new role to assign. */
5630
- role: Role;
5684
+ /** The new role to assign: an organization role, or an application role in app mode. */
5685
+ role: Role | (string & {});
5631
5686
  };
5632
5687
  /**
5633
5688
  * Payload for creating a new team.
@@ -5759,29 +5814,10 @@ declare class OrganizationService {
5759
5814
  * @param options - Pagination options
5760
5815
  * @param options.limit - Maximum number of members to return
5761
5816
  * @param options.offset - Number of members to skip
5762
- * @returns An array of organization members
5817
+ * @param options.includeWithoutAccess - With an application session, also list members without access to the application
5818
+ * @returns An array of organization members, with their application role when the session is an application session
5763
5819
  */
5764
- listMembers(options?: ListMembersOptions): Promise<({
5765
- id: string;
5766
- organizationId: string;
5767
- role: "org:admin" | "org:member" | "org:reviewer";
5768
- createdAt: Date;
5769
- userId: string;
5770
- teamId?: string | undefined | undefined;
5771
- user: {
5772
- id: string;
5773
- email: string;
5774
- name: string;
5775
- image?: string | undefined;
5776
- };
5777
- } & {
5778
- user: {
5779
- id: string;
5780
- name: string;
5781
- email: string;
5782
- image: string | null | undefined;
5783
- };
5784
- })[]>;
5820
+ listMembers(options?: ListMembersOptions): Promise<ApplicationScopedMember[]>;
5785
5821
  /**
5786
5822
  * Gets the currently active organization member for the authenticated user.
5787
5823
  *
@@ -5827,11 +5863,12 @@ declare class OrganizationService {
5827
5863
  * @param options - Invitation configuration
5828
5864
  * @param options.userEmail - Email address of the user to invite
5829
5865
  * @param options.role - Role to assign to the invited user
5866
+ * @param options.applicationRole - Application role granted on acceptance; required with an application-scoped session
5830
5867
  * @param options.teamId - Team ID to add the user to
5831
5868
  * @param options.resend - Whether to resend if invitation already exists
5832
5869
  * @returns The created invitation
5833
5870
  */
5834
- inviteUserToOrganization({ userEmail, role, teamId, resend }: InviteUserToOrganizationOptions): Promise<NonNullable<{
5871
+ inviteUserToOrganization({ userEmail, role, applicationRole, teamId, resend }: InviteUserToOrganizationOptions): Promise<NonNullable<{
5835
5872
  id: string;
5836
5873
  organizationId: string;
5837
5874
  email: string;
@@ -5892,6 +5929,9 @@ declare class OrganizationService {
5892
5929
  /**
5893
5930
  * Removes a user from the active organization.
5894
5931
  *
5932
+ * With an application-scoped session, revokes the member's access to that
5933
+ * application and keeps the membership.
5934
+ *
5895
5935
  * @param options - Provide either `memberId` or `userEmail` to identify the user
5896
5936
  * @param options.memberId - Membership ID to remove
5897
5937
  * @param options.userEmail - Email address of the member to remove
@@ -5900,6 +5940,10 @@ declare class OrganizationService {
5900
5940
  /**
5901
5941
  * Updates the role of an organization member.
5902
5942
  *
5943
+ * With an application-scoped session, `role` is an application role: the
5944
+ * update grants or changes the member's access to that application and
5945
+ * keeps the organization role.
5946
+ *
5903
5947
  * @param options - Role update configuration
5904
5948
  * @param options.memberId - The member ID to update
5905
5949
  * @param options.role - The new role to assign
@@ -6116,13 +6160,6 @@ declare class SessionService {
6116
6160
  * @param password - The new password to set
6117
6161
  */
6118
6162
  resetPassword(token: string, password: string): Promise<void>;
6119
- /**
6120
- * Retrieves the JWT token for a nonce.
6121
- *
6122
- * @param nonce - The nonce to retrieve the token for
6123
- * @returns The JWT token for the nonce
6124
- */
6125
- getNoncePayload(nonce: string): Promise<NoncePayloadResponse>;
6126
6163
  }
6127
6164
 
6128
6165
  /**
@@ -6384,14 +6421,6 @@ type TeamMembersResponse = {
6384
6421
  teamMembers: TeamMember[];
6385
6422
  };
6386
6423
 
6387
- /**
6388
- * Response from exchanging a handshake nonce for a token.
6389
- */
6390
- type NoncePayloadResponse = {
6391
- /** The JWT issued for the session the nonce was minted against. */
6392
- token: string;
6393
- };
6394
-
6395
6424
  /**
6396
6425
  * Error thrown when an invalid social provider is specified.
6397
6426
  */
@@ -6574,4 +6603,4 @@ declare function validateToken(token: string, apiUrl: string): Promise<boolean>;
6574
6603
  declare function extractTokenPayload(token: string): DecodedJWTPayload;
6575
6604
 
6576
6605
  export { AAL, AALBrand, AALs, ACR, ACRBrand, ACRs, AMR, AMRBrand, AMRs, ApiKeyMetadata, ApplicationConfig, ApplicationError, ApplicationSessionAssuranceConfig, ApplicationSessionAssuranceError, ApplicationTokenStorage, AuthClient, AuthMethod, AuthMethodBrand, AuthMethods, AuthorizationFlowError, DEFAULT_APPLICATION_CONFIG, DEFAULT_JWT_ASSURANCE, DEFAULT_SESSION_ASSURANCE_CONFIG, DeviceAccessDeniedError, DeviceAuthorizationPendingError, DeviceAuthorizationSlowDownError, DeviceCodeExpiredError, DeviceTransientServerError, EmailOTPService, EmailRequired, InvalidCallbackURL, InvalidSocialProvider, JWTPayload, JWTPayloadAssurance, JWTPayloadUser, JWTPayloadWorkspace, LOGIN_METHODS, OAuthBeginStepUpResponse, OAuthCompleteStepUpResponse, OAuthStepUpProvider, RefreshTokenExpiredError, Roles, SENSITIVE_ACTION_ASSURANCE_POLICY, STEP_UP_MAX_AGE_SECONDS, SendOtpResponse, SessionAssurancePolicy, SessionAssuranceRequiredError, SessionAssuranceRequiredPayload, SessionAssuranceResponse, SessionAssuranceService, StepUpOption, UserNotLoggedInError, ac, assuranceFields, canStepUpWithAmr, createAPIClient, extractTokenPayload, getAalRank, invitationAdditionalFields, isAssuranceSufficientForPolicy, isSessionAssuranceSufficient, isTokenExpired, memberAdditionalFields, mergeStepUpAssurance, normalizeAmr, organizationAdditionalFields, parseSessionAssuranceRequiredPayload, rolesAccessControl, sessionAssurancePluginClient, userAdditionalFields, validateToken };
6577
- export type { APIClient, AcceptInvitationResult, AdminApplication, AdminApplicationEntitlement, AdminApplicationEntitlementRecord, AdminApplicationIdentity, AdminApplicationMember, AdminApplicationMemberOrganization, AdminApplicationMemberRecord, AdminApplicationOrganization, AdminApplicationRecord, AdminApplicationRole, AdminApplicationSecret, AdminEntitlementRule, AdminEntitlementRuleType, AdminEntitlementWithRules, AdminMember, AdminOrganization, AdminOrganizationApplication, AdminOrganizationMember, AdminOrganizationMemberApplication, AdminOrganizationMemberRecord, AdminOrganizationMemberTeam, AdminOrganizationSummary, AdminOrganizationTeam, AdminOrganizationTeamRecord, AdminUser, AdminUserAccess, AdminUserAccessApplication, AdminUserAccessOrganization, AdminUserAccessTeam, AdminUserInvitation, AdminUserOrganization, ApiKey, ApiKeyWithoutSecret, Application, ApplicationAuthContextResponse, ApplicationTokenStorageOptions, AssuranceFields, BaseOrganization, BeginOAuthStepUpParams, BillingMode, ClientCredentialsGrant, ClientCredentialsTokenResponse, CompleteAuthorizationFlowResponse, CreateAdminApplicationEntitlementOptions, CreateAdminApplicationOptions, CreateAdminApplicationRoleOptions, CreateAdminApplicationSecretOptions, CreateAdminOrganizationOptions, CreateAdminOrganizationTeamOptions, CreateApiKeyPayload, CreateTeamPayload, CreatedAdminApplicationSecret, DecodedJWTPayload, DeleteAdminOrganizationTeamOptions, DeviceAuthorizationActionResponse, DeviceAuthorizationContextResponse, DeviceAuthorizationResponse, DeviceContextApplication, EmailOTPSignInOptions, FullOrganization, GetAdminOrganizationOptions, GetAdminOrganizationsSummaryOptions, GetTokenOptions, Invitation, InvitationPasswordSetupResult, InvitationSignupStatus, InviteAdminOrganizationUsersOptions, InviteAdminOrganizationUsersResult, InviteUserToOrganizationOptions, JWTPayloadData, ListAdminApplicationMembersOptions, ListAdminApplicationMembersResult, ListAdminApplicationsOptions, ListAdminApplicationsResult, ListAdminOrganizationMembersOptions, ListAdminOrganizationMembersResult, ListAdminOrganizationTeamsOptions, ListAdminOrganizationTeamsResult, ListAdminOrganizationsOptions, ListAdminOrganizationsResult, ListAdminUsersOptions, ListAdminUsersResult, ListCandidateOrganizationsInclude, ListCandidateOrganizationsOptions, ListCandidateOrganizationsResponse, ListMembersOptions, ListOrganizationsOptions, ListOrganizationsWithRoleOptions, LoginMethod, LoginMethodsResponse, Member, NoncePayloadResponse, ExtendedOrganization as Organization, OrganizationSettings, OrganizationWithRole, RemoveAdminMemberOptions, RemoveUserFromOrganizationOptions, ResendAdminInviteOptions, Role, SendVerificationOTPOptions, Session, SessionAssuranceActions, SessionData, SetAdminEntitlementRulesOptions, SetAdminUserApplicationRoleOptions, SetAdminUserPasswordOptions, SetAdminUserTeamOptions, SignInWithEmailAndPasswordOptions, SignInWithSsoOptions, SocialSignInOptions, StartAuthorizationFlowResponse, Strict, Team, TeamMember, TeamMembersResponse, UpdateAdminApplicationRoleOptions, UpdateAdminEntitlementOptions, UpdateAdminMemberRoleOptions, UpdateAdminOrganizationOptions, UpdateAdminOrganizationTeamOptions, UpdateApiKeyPayload, UpdateMemberRoleOptions, UpdateOrganizationPayload, UpdateTeamPayload, User, UserProfile, WhoAmIInclude, WhoAmIOptions, WhoAmIOrganization, WhoAmIResponse };
6606
+ export type { APIClient, AcceptInvitationResult, AdminApplication, AdminApplicationEntitlement, AdminApplicationEntitlementRecord, AdminApplicationIdentity, AdminApplicationMember, AdminApplicationMemberOrganization, AdminApplicationMemberRecord, AdminApplicationOrganization, AdminApplicationRecord, AdminApplicationRole, AdminApplicationSecret, AdminEntitlementRule, AdminEntitlementRuleType, AdminEntitlementWithRules, AdminMember, AdminOrganization, AdminOrganizationApplication, AdminOrganizationMember, AdminOrganizationMemberApplication, AdminOrganizationMemberRecord, AdminOrganizationMemberTeam, AdminOrganizationSummary, AdminOrganizationTeam, AdminOrganizationTeamRecord, AdminUser, AdminUserAccess, AdminUserAccessApplication, AdminUserAccessOrganization, AdminUserAccessTeam, AdminUserInvitation, AdminUserOrganization, ApiKey, ApiKeyWithoutSecret, Application, ApplicationAuthContextResponse, ApplicationRole, ApplicationScopedMember, ApplicationTokenStorageOptions, AssuranceFields, BaseOrganization, BeginOAuthStepUpParams, BillingMode, ClientCredentialsGrant, ClientCredentialsTokenResponse, CompleteAuthorizationFlowResponse, CreateAdminApplicationEntitlementOptions, CreateAdminApplicationOptions, CreateAdminApplicationRoleOptions, CreateAdminApplicationSecretOptions, CreateAdminOrganizationOptions, CreateAdminOrganizationTeamOptions, CreateApiKeyPayload, CreateTeamPayload, CreatedAdminApplicationSecret, DecodedJWTPayload, DeleteAdminOrganizationTeamOptions, DeviceAuthorizationActionResponse, DeviceAuthorizationContextResponse, DeviceAuthorizationResponse, DeviceContextApplication, EmailOTPSignInOptions, FullOrganization, FullOrganizationMember, GetAdminOrganizationOptions, GetAdminOrganizationsSummaryOptions, GetTokenOptions, Invitation, InvitationPasswordSetupResult, InvitationSignupStatus, InviteAdminOrganizationUsersOptions, InviteAdminOrganizationUsersResult, InviteUserToOrganizationOptions, JWTPayloadData, ListAdminApplicationMembersOptions, ListAdminApplicationMembersResult, ListAdminApplicationsOptions, ListAdminApplicationsResult, ListAdminOrganizationMembersOptions, ListAdminOrganizationMembersResult, ListAdminOrganizationTeamsOptions, ListAdminOrganizationTeamsResult, ListAdminOrganizationsOptions, ListAdminOrganizationsResult, ListAdminUsersOptions, ListAdminUsersResult, ListCandidateOrganizationsInclude, ListCandidateOrganizationsOptions, ListCandidateOrganizationsResponse, ListMembersOptions, ListOrganizationsOptions, ListOrganizationsWithRoleOptions, LoginMethod, LoginMethodsResponse, Member, ExtendedOrganization as Organization, OrganizationSettings, OrganizationWithRole, RemoveAdminMemberOptions, RemoveUserFromOrganizationOptions, Role, SendVerificationOTPOptions, Session, SessionAssuranceActions, SessionData, SetAdminEntitlementRulesOptions, SetAdminUserApplicationRoleOptions, SetAdminUserPasswordOptions, SetAdminUserTeamOptions, SignInWithEmailAndPasswordOptions, SignInWithSsoOptions, SocialSignInOptions, StartAuthorizationFlowResponse, Strict, Team, TeamMember, TeamMembersResponse, UpdateAdminApplicationRoleOptions, UpdateAdminEntitlementOptions, UpdateAdminMemberRoleOptions, UpdateAdminOrganizationOptions, UpdateAdminOrganizationTeamOptions, UpdateApiKeyPayload, UpdateMemberRoleOptions, UpdateOrganizationPayload, UpdateTeamPayload, User, UserProfile, WhoAmIInclude, WhoAmIOptions, WhoAmIOrganization, WhoAmIResponse };
package/dist/index.d.ts CHANGED
@@ -275,6 +275,12 @@ declare const invitationAdditionalFields: {
275
275
  input: true;
276
276
  required: false;
277
277
  };
278
+ /** Application role granted when an application invitation is accepted. */
279
+ applicationRole: {
280
+ type: "string";
281
+ input: true;
282
+ required: false;
283
+ };
278
284
  };
279
285
  /**
280
286
  * Zod schema and type for the `user` claim within a JWT payload.
@@ -771,6 +777,17 @@ type DeviceAuthorizationContextResponse = {
771
777
  /** Seconds remaining before the device code expires. */
772
778
  expiresIn: number;
773
779
  };
780
+ /**
781
+ * Role of the application an application session was issued for.
782
+ */
783
+ type ApplicationRole = {
784
+ applicationId: string;
785
+ name: string;
786
+ displayName: string;
787
+ description: string;
788
+ /** Roles of the same application this role may grant, change, revoke and invite. */
789
+ manageableRoles: string[];
790
+ };
774
791
  /**
775
792
  * Response returned when approving or denying a device authorization request.
776
793
  */
@@ -1038,6 +1055,12 @@ declare class ApplicationService {
1038
1055
  * @param refreshToken - The refresh token to invalidate
1039
1056
  */
1040
1057
  logout(refreshToken: string): Promise<void>;
1058
+ /**
1059
+ * Lists the roles of the application the current session was issued for.
1060
+ *
1061
+ * @returns The application's roles
1062
+ */
1063
+ listRoles(): Promise<ApplicationRole[]>;
1041
1064
  }
1042
1065
 
1043
1066
  declare const ApiKeyMetadata: zod__default.ZodObject<{
@@ -1449,13 +1472,6 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
1449
1472
  };
1450
1473
  };
1451
1474
  };
1452
- } | {
1453
- id: "handshake";
1454
- getActions: ($fetch: better_auth_client.BetterFetch) => {
1455
- handshake: {
1456
- noncePayload: (nonce: string) => Promise<NoncePayloadResponse>;
1457
- };
1458
- };
1459
1475
  } | {
1460
1476
  id: "invitation-signup";
1461
1477
  getActions: ($fetch: better_auth_client.BetterFetch) => {
@@ -3568,6 +3584,17 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
3568
3584
  data: void;
3569
3585
  error: null;
3570
3586
  }>;
3587
+ listApplicationRoles: () => Promise<{
3588
+ data: null;
3589
+ error: {
3590
+ message?: string | undefined;
3591
+ status: number;
3592
+ statusText: string;
3593
+ };
3594
+ } | {
3595
+ data: ApplicationRole[];
3596
+ error: null;
3597
+ }>;
3571
3598
  };
3572
3599
  };
3573
3600
  } | {
@@ -4323,11 +4350,19 @@ type OrganizationSettings = {
4323
4350
  type ExtendedOrganization = BaseOrganization & {
4324
4351
  settings?: OrganizationSettings;
4325
4352
  };
4353
+ /**
4354
+ * A member of a {@link FullOrganization}.
4355
+ */
4356
+ type FullOrganizationMember = Member & {
4357
+ /** The member's role in the session's application. Only set for application sessions. */
4358
+ applicationRole?: string | null;
4359
+ };
4326
4360
  /**
4327
4361
  * A complete organization object including its members, invitations, and teams.
4328
4362
  */
4329
4363
  type FullOrganization = ExtendedOrganization & {
4330
- members: Member[];
4364
+ /** With an application session, only members with access to the application. */
4365
+ members: FullOrganizationMember[];
4331
4366
  invitations: Invitation[];
4332
4367
  teams: Team[];
4333
4368
  };
@@ -4386,6 +4421,8 @@ type ListAdminUsersOptions = {
4386
4421
  * admin, whose listing is always pinned to their own organization.
4387
4422
  */
4388
4423
  organizationId?: string;
4424
+ /** Restricts the listing to people with access to this application. Requires organizationId when listing users. */
4425
+ applicationId?: string;
4389
4426
  };
4390
4427
  /**
4391
4428
  * Organization preview returned alongside each admin user row.
@@ -4545,6 +4582,8 @@ type ListAdminOrganizationMembersOptions = {
4545
4582
  sortBy?: 'createdAt' | 'name';
4546
4583
  /** Sort direction for the listing. Defaults to 'desc'. */
4547
4584
  sortDirection?: 'asc' | 'desc';
4585
+ /** Restricts the listing to people with access to this application. */
4586
+ applicationId?: string;
4548
4587
  };
4549
4588
  /**
4550
4589
  * Options accepted when listing teams for a single organization as a global admin.
@@ -4714,20 +4753,6 @@ type AdminUserInvitation = {
4714
4753
  expiresAt: string;
4715
4754
  createdAt: string;
4716
4755
  };
4717
- /**
4718
- * Options accepted when resending an organization invitation as a global admin.
4719
- */
4720
- type ResendAdminInviteOptions = {
4721
- organizationId: string;
4722
- email: string;
4723
- role: string;
4724
- applicationId?: string;
4725
- /**
4726
- * Teams joined when the re-sent invitation is accepted. Resending replaces the
4727
- * invitation, so these must be provided to preserve the original team assignments.
4728
- */
4729
- teamIds?: string[];
4730
- };
4731
4756
  /**
4732
4757
  * User row returned by the admin user listing endpoint.
4733
4758
  */
@@ -4755,6 +4780,8 @@ type AdminUser = {
4755
4780
  organizationCount?: number;
4756
4781
  /** Preview of the first organizations the user belongs to. Present when requested via organizationsPreview. */
4757
4782
  organizations?: AdminUserOrganization[];
4783
+ /** App role. Present when the listing is scoped to an application; null on invitation rows. */
4784
+ applicationRole?: string | null;
4758
4785
  };
4759
4786
  /**
4760
4787
  * Paginated admin user listing response.
@@ -4809,6 +4836,8 @@ type AdminOrganizationMemberRecord = {
4809
4836
  expiresAt?: string;
4810
4837
  teams?: AdminOrganizationMemberTeam[];
4811
4838
  applications?: AdminOrganizationMemberApplication[];
4839
+ /** App role. Present when the listing is scoped to an application; null on invitation rows. */
4840
+ applicationRole?: string | null;
4812
4841
  };
4813
4842
  /**
4814
4843
  * Paginated organization member listing response.
@@ -4915,9 +4944,16 @@ type AdminApplicationRole = {
4915
4944
  name: string;
4916
4945
  displayName: string;
4917
4946
  description: string;
4947
+ /** Roles of the same application this role may grant, change, revoke and invite. */
4948
+ manageableRoles: string[];
4949
+ };
4950
+ /**
4951
+ * Options accepted when creating an application role. Omitting `manageableRoles`
4952
+ * creates the role with none, and on update keeps the stored list.
4953
+ */
4954
+ type CreateAdminApplicationRoleOptions = Omit<AdminApplicationRole, 'applicationId' | 'manageableRoles'> & {
4955
+ manageableRoles?: string[];
4918
4956
  };
4919
- /** Options accepted when creating an application role. */
4920
- type CreateAdminApplicationRoleOptions = Omit<AdminApplicationRole, 'applicationId'>;
4921
4957
  /** Options accepted when updating an application role. */
4922
4958
  type UpdateAdminApplicationRoleOptions = CreateAdminApplicationRoleOptions;
4923
4959
  /** Kind of matcher an entitlement rule applies. */
@@ -5520,10 +5556,11 @@ declare class AdminService {
5520
5556
  */
5521
5557
  cancelInvite(invitationId: string): Promise<void>;
5522
5558
  /**
5523
- * Re-sends an organization invitation email as a global admin.
5524
- * @param options - Organization, email, role, and optional application and teams
5559
+ * Replaces a pending invitation with a new one that keeps its roles and
5560
+ * teams, and emails it, as a global admin.
5561
+ * @param invitationId - The ID of the invitation to resend
5525
5562
  */
5526
- resendInvite(options: ResendAdminInviteOptions): Promise<void>;
5563
+ resendInvite(invitationId: string): Promise<void>;
5527
5564
  /**
5528
5565
  * Invites several users to an organization in one call, or — with
5529
5566
  * `sendInvite: false` — adds them as members immediately, creating user
@@ -5588,6 +5625,18 @@ type ListMembersOptions = {
5588
5625
  sortBy?: 'createdAt';
5589
5626
  /** Sort direction for the member page. */
5590
5627
  sortDirection?: 'asc' | 'desc';
5628
+ /** With an application session, also lists organization members without access to the application, marked hasAccess: false. Requires permission to grant access. */
5629
+ includeWithoutAccess?: boolean;
5630
+ };
5631
+ /**
5632
+ * Organization member as returned to an application session, with the member's
5633
+ * role in the application.
5634
+ */
5635
+ type ApplicationScopedMember = Member & {
5636
+ /** The member's role in the application, or null without access. */
5637
+ applicationRole?: string | null;
5638
+ /** Present when includeWithoutAccess was requested. */
5639
+ hasAccess?: boolean;
5591
5640
  };
5592
5641
  /**
5593
5642
  * Options for inviting a user to the active organization.
@@ -5601,6 +5650,8 @@ type InviteUserToOrganizationOptions = {
5601
5650
  userEmail: string;
5602
5651
  /** Organization role to assign to the invited user. */
5603
5652
  role: Role;
5653
+ /** Application role granted on acceptance. Required with an application-scoped session. */
5654
+ applicationRole?: string;
5604
5655
  /** Optional team to add the user to upon acceptance. */
5605
5656
  teamId?: string;
5606
5657
  /** Whether to resend the invitation if one already exists for this email. */
@@ -5622,12 +5673,16 @@ type RemoveUserFromOrganizationOptions = {
5622
5673
  };
5623
5674
  /**
5624
5675
  * Options for updating a member's role within the organization.
5676
+ *
5677
+ * With an application-scoped session, `role` is an application role and the
5678
+ * update grants or changes access to that application. The organization role
5679
+ * is left unchanged.
5625
5680
  */
5626
5681
  type UpdateMemberRoleOptions = {
5627
5682
  /** The member ID whose role should be updated. */
5628
5683
  memberId: string;
5629
- /** The new role to assign. */
5630
- role: Role;
5684
+ /** The new role to assign: an organization role, or an application role in app mode. */
5685
+ role: Role | (string & {});
5631
5686
  };
5632
5687
  /**
5633
5688
  * Payload for creating a new team.
@@ -5759,29 +5814,10 @@ declare class OrganizationService {
5759
5814
  * @param options - Pagination options
5760
5815
  * @param options.limit - Maximum number of members to return
5761
5816
  * @param options.offset - Number of members to skip
5762
- * @returns An array of organization members
5817
+ * @param options.includeWithoutAccess - With an application session, also list members without access to the application
5818
+ * @returns An array of organization members, with their application role when the session is an application session
5763
5819
  */
5764
- listMembers(options?: ListMembersOptions): Promise<({
5765
- id: string;
5766
- organizationId: string;
5767
- role: "org:admin" | "org:member" | "org:reviewer";
5768
- createdAt: Date;
5769
- userId: string;
5770
- teamId?: string | undefined | undefined;
5771
- user: {
5772
- id: string;
5773
- email: string;
5774
- name: string;
5775
- image?: string | undefined;
5776
- };
5777
- } & {
5778
- user: {
5779
- id: string;
5780
- name: string;
5781
- email: string;
5782
- image: string | null | undefined;
5783
- };
5784
- })[]>;
5820
+ listMembers(options?: ListMembersOptions): Promise<ApplicationScopedMember[]>;
5785
5821
  /**
5786
5822
  * Gets the currently active organization member for the authenticated user.
5787
5823
  *
@@ -5827,11 +5863,12 @@ declare class OrganizationService {
5827
5863
  * @param options - Invitation configuration
5828
5864
  * @param options.userEmail - Email address of the user to invite
5829
5865
  * @param options.role - Role to assign to the invited user
5866
+ * @param options.applicationRole - Application role granted on acceptance; required with an application-scoped session
5830
5867
  * @param options.teamId - Team ID to add the user to
5831
5868
  * @param options.resend - Whether to resend if invitation already exists
5832
5869
  * @returns The created invitation
5833
5870
  */
5834
- inviteUserToOrganization({ userEmail, role, teamId, resend }: InviteUserToOrganizationOptions): Promise<NonNullable<{
5871
+ inviteUserToOrganization({ userEmail, role, applicationRole, teamId, resend }: InviteUserToOrganizationOptions): Promise<NonNullable<{
5835
5872
  id: string;
5836
5873
  organizationId: string;
5837
5874
  email: string;
@@ -5892,6 +5929,9 @@ declare class OrganizationService {
5892
5929
  /**
5893
5930
  * Removes a user from the active organization.
5894
5931
  *
5932
+ * With an application-scoped session, revokes the member's access to that
5933
+ * application and keeps the membership.
5934
+ *
5895
5935
  * @param options - Provide either `memberId` or `userEmail` to identify the user
5896
5936
  * @param options.memberId - Membership ID to remove
5897
5937
  * @param options.userEmail - Email address of the member to remove
@@ -5900,6 +5940,10 @@ declare class OrganizationService {
5900
5940
  /**
5901
5941
  * Updates the role of an organization member.
5902
5942
  *
5943
+ * With an application-scoped session, `role` is an application role: the
5944
+ * update grants or changes the member's access to that application and
5945
+ * keeps the organization role.
5946
+ *
5903
5947
  * @param options - Role update configuration
5904
5948
  * @param options.memberId - The member ID to update
5905
5949
  * @param options.role - The new role to assign
@@ -6116,13 +6160,6 @@ declare class SessionService {
6116
6160
  * @param password - The new password to set
6117
6161
  */
6118
6162
  resetPassword(token: string, password: string): Promise<void>;
6119
- /**
6120
- * Retrieves the JWT token for a nonce.
6121
- *
6122
- * @param nonce - The nonce to retrieve the token for
6123
- * @returns The JWT token for the nonce
6124
- */
6125
- getNoncePayload(nonce: string): Promise<NoncePayloadResponse>;
6126
6163
  }
6127
6164
 
6128
6165
  /**
@@ -6384,14 +6421,6 @@ type TeamMembersResponse = {
6384
6421
  teamMembers: TeamMember[];
6385
6422
  };
6386
6423
 
6387
- /**
6388
- * Response from exchanging a handshake nonce for a token.
6389
- */
6390
- type NoncePayloadResponse = {
6391
- /** The JWT issued for the session the nonce was minted against. */
6392
- token: string;
6393
- };
6394
-
6395
6424
  /**
6396
6425
  * Error thrown when an invalid social provider is specified.
6397
6426
  */
@@ -6574,4 +6603,4 @@ declare function validateToken(token: string, apiUrl: string): Promise<boolean>;
6574
6603
  declare function extractTokenPayload(token: string): DecodedJWTPayload;
6575
6604
 
6576
6605
  export { AAL, AALBrand, AALs, ACR, ACRBrand, ACRs, AMR, AMRBrand, AMRs, ApiKeyMetadata, ApplicationConfig, ApplicationError, ApplicationSessionAssuranceConfig, ApplicationSessionAssuranceError, ApplicationTokenStorage, AuthClient, AuthMethod, AuthMethodBrand, AuthMethods, AuthorizationFlowError, DEFAULT_APPLICATION_CONFIG, DEFAULT_JWT_ASSURANCE, DEFAULT_SESSION_ASSURANCE_CONFIG, DeviceAccessDeniedError, DeviceAuthorizationPendingError, DeviceAuthorizationSlowDownError, DeviceCodeExpiredError, DeviceTransientServerError, EmailOTPService, EmailRequired, InvalidCallbackURL, InvalidSocialProvider, JWTPayload, JWTPayloadAssurance, JWTPayloadUser, JWTPayloadWorkspace, LOGIN_METHODS, OAuthBeginStepUpResponse, OAuthCompleteStepUpResponse, OAuthStepUpProvider, RefreshTokenExpiredError, Roles, SENSITIVE_ACTION_ASSURANCE_POLICY, STEP_UP_MAX_AGE_SECONDS, SendOtpResponse, SessionAssurancePolicy, SessionAssuranceRequiredError, SessionAssuranceRequiredPayload, SessionAssuranceResponse, SessionAssuranceService, StepUpOption, UserNotLoggedInError, ac, assuranceFields, canStepUpWithAmr, createAPIClient, extractTokenPayload, getAalRank, invitationAdditionalFields, isAssuranceSufficientForPolicy, isSessionAssuranceSufficient, isTokenExpired, memberAdditionalFields, mergeStepUpAssurance, normalizeAmr, organizationAdditionalFields, parseSessionAssuranceRequiredPayload, rolesAccessControl, sessionAssurancePluginClient, userAdditionalFields, validateToken };
6577
- export type { APIClient, AcceptInvitationResult, AdminApplication, AdminApplicationEntitlement, AdminApplicationEntitlementRecord, AdminApplicationIdentity, AdminApplicationMember, AdminApplicationMemberOrganization, AdminApplicationMemberRecord, AdminApplicationOrganization, AdminApplicationRecord, AdminApplicationRole, AdminApplicationSecret, AdminEntitlementRule, AdminEntitlementRuleType, AdminEntitlementWithRules, AdminMember, AdminOrganization, AdminOrganizationApplication, AdminOrganizationMember, AdminOrganizationMemberApplication, AdminOrganizationMemberRecord, AdminOrganizationMemberTeam, AdminOrganizationSummary, AdminOrganizationTeam, AdminOrganizationTeamRecord, AdminUser, AdminUserAccess, AdminUserAccessApplication, AdminUserAccessOrganization, AdminUserAccessTeam, AdminUserInvitation, AdminUserOrganization, ApiKey, ApiKeyWithoutSecret, Application, ApplicationAuthContextResponse, ApplicationTokenStorageOptions, AssuranceFields, BaseOrganization, BeginOAuthStepUpParams, BillingMode, ClientCredentialsGrant, ClientCredentialsTokenResponse, CompleteAuthorizationFlowResponse, CreateAdminApplicationEntitlementOptions, CreateAdminApplicationOptions, CreateAdminApplicationRoleOptions, CreateAdminApplicationSecretOptions, CreateAdminOrganizationOptions, CreateAdminOrganizationTeamOptions, CreateApiKeyPayload, CreateTeamPayload, CreatedAdminApplicationSecret, DecodedJWTPayload, DeleteAdminOrganizationTeamOptions, DeviceAuthorizationActionResponse, DeviceAuthorizationContextResponse, DeviceAuthorizationResponse, DeviceContextApplication, EmailOTPSignInOptions, FullOrganization, GetAdminOrganizationOptions, GetAdminOrganizationsSummaryOptions, GetTokenOptions, Invitation, InvitationPasswordSetupResult, InvitationSignupStatus, InviteAdminOrganizationUsersOptions, InviteAdminOrganizationUsersResult, InviteUserToOrganizationOptions, JWTPayloadData, ListAdminApplicationMembersOptions, ListAdminApplicationMembersResult, ListAdminApplicationsOptions, ListAdminApplicationsResult, ListAdminOrganizationMembersOptions, ListAdminOrganizationMembersResult, ListAdminOrganizationTeamsOptions, ListAdminOrganizationTeamsResult, ListAdminOrganizationsOptions, ListAdminOrganizationsResult, ListAdminUsersOptions, ListAdminUsersResult, ListCandidateOrganizationsInclude, ListCandidateOrganizationsOptions, ListCandidateOrganizationsResponse, ListMembersOptions, ListOrganizationsOptions, ListOrganizationsWithRoleOptions, LoginMethod, LoginMethodsResponse, Member, NoncePayloadResponse, ExtendedOrganization as Organization, OrganizationSettings, OrganizationWithRole, RemoveAdminMemberOptions, RemoveUserFromOrganizationOptions, ResendAdminInviteOptions, Role, SendVerificationOTPOptions, Session, SessionAssuranceActions, SessionData, SetAdminEntitlementRulesOptions, SetAdminUserApplicationRoleOptions, SetAdminUserPasswordOptions, SetAdminUserTeamOptions, SignInWithEmailAndPasswordOptions, SignInWithSsoOptions, SocialSignInOptions, StartAuthorizationFlowResponse, Strict, Team, TeamMember, TeamMembersResponse, UpdateAdminApplicationRoleOptions, UpdateAdminEntitlementOptions, UpdateAdminMemberRoleOptions, UpdateAdminOrganizationOptions, UpdateAdminOrganizationTeamOptions, UpdateApiKeyPayload, UpdateMemberRoleOptions, UpdateOrganizationPayload, UpdateTeamPayload, User, UserProfile, WhoAmIInclude, WhoAmIOptions, WhoAmIOrganization, WhoAmIResponse };
6606
+ export type { APIClient, AcceptInvitationResult, AdminApplication, AdminApplicationEntitlement, AdminApplicationEntitlementRecord, AdminApplicationIdentity, AdminApplicationMember, AdminApplicationMemberOrganization, AdminApplicationMemberRecord, AdminApplicationOrganization, AdminApplicationRecord, AdminApplicationRole, AdminApplicationSecret, AdminEntitlementRule, AdminEntitlementRuleType, AdminEntitlementWithRules, AdminMember, AdminOrganization, AdminOrganizationApplication, AdminOrganizationMember, AdminOrganizationMemberApplication, AdminOrganizationMemberRecord, AdminOrganizationMemberTeam, AdminOrganizationSummary, AdminOrganizationTeam, AdminOrganizationTeamRecord, AdminUser, AdminUserAccess, AdminUserAccessApplication, AdminUserAccessOrganization, AdminUserAccessTeam, AdminUserInvitation, AdminUserOrganization, ApiKey, ApiKeyWithoutSecret, Application, ApplicationAuthContextResponse, ApplicationRole, ApplicationScopedMember, ApplicationTokenStorageOptions, AssuranceFields, BaseOrganization, BeginOAuthStepUpParams, BillingMode, ClientCredentialsGrant, ClientCredentialsTokenResponse, CompleteAuthorizationFlowResponse, CreateAdminApplicationEntitlementOptions, CreateAdminApplicationOptions, CreateAdminApplicationRoleOptions, CreateAdminApplicationSecretOptions, CreateAdminOrganizationOptions, CreateAdminOrganizationTeamOptions, CreateApiKeyPayload, CreateTeamPayload, CreatedAdminApplicationSecret, DecodedJWTPayload, DeleteAdminOrganizationTeamOptions, DeviceAuthorizationActionResponse, DeviceAuthorizationContextResponse, DeviceAuthorizationResponse, DeviceContextApplication, EmailOTPSignInOptions, FullOrganization, FullOrganizationMember, GetAdminOrganizationOptions, GetAdminOrganizationsSummaryOptions, GetTokenOptions, Invitation, InvitationPasswordSetupResult, InvitationSignupStatus, InviteAdminOrganizationUsersOptions, InviteAdminOrganizationUsersResult, InviteUserToOrganizationOptions, JWTPayloadData, ListAdminApplicationMembersOptions, ListAdminApplicationMembersResult, ListAdminApplicationsOptions, ListAdminApplicationsResult, ListAdminOrganizationMembersOptions, ListAdminOrganizationMembersResult, ListAdminOrganizationTeamsOptions, ListAdminOrganizationTeamsResult, ListAdminOrganizationsOptions, ListAdminOrganizationsResult, ListAdminUsersOptions, ListAdminUsersResult, ListCandidateOrganizationsInclude, ListCandidateOrganizationsOptions, ListCandidateOrganizationsResponse, ListMembersOptions, ListOrganizationsOptions, ListOrganizationsWithRoleOptions, LoginMethod, LoginMethodsResponse, Member, ExtendedOrganization as Organization, OrganizationSettings, OrganizationWithRole, RemoveAdminMemberOptions, RemoveUserFromOrganizationOptions, Role, SendVerificationOTPOptions, Session, SessionAssuranceActions, SessionData, SetAdminEntitlementRulesOptions, SetAdminUserApplicationRoleOptions, SetAdminUserPasswordOptions, SetAdminUserTeamOptions, SignInWithEmailAndPasswordOptions, SignInWithSsoOptions, SocialSignInOptions, StartAuthorizationFlowResponse, Strict, Team, TeamMember, TeamMembersResponse, UpdateAdminApplicationRoleOptions, UpdateAdminEntitlementOptions, UpdateAdminMemberRoleOptions, UpdateAdminOrganizationOptions, UpdateAdminOrganizationTeamOptions, UpdateApiKeyPayload, UpdateMemberRoleOptions, UpdateOrganizationPayload, UpdateTeamPayload, User, UserProfile, WhoAmIInclude, WhoAmIOptions, WhoAmIOrganization, WhoAmIResponse };
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 = "2.10.0";
24
+ const version = "3.1.0";
25
25
 
26
26
  function parsedEnumValues(schema) {
27
27
  return Object.fromEntries(
@@ -178,6 +178,12 @@ const invitationAdditionalFields = {
178
178
  type: "string",
179
179
  input: true,
180
180
  required: false
181
+ },
182
+ /** Application role granted when an application invitation is accepted. */
183
+ applicationRole: {
184
+ type: "string",
185
+ input: true,
186
+ required: false
181
187
  }
182
188
  };
183
189
  const JWTPayloadUser = z$1.object({
@@ -362,6 +368,11 @@ function applicationsPluginClient() {
362
368
  method: "POST",
363
369
  headers
364
370
  });
371
+ },
372
+ listApplicationRoles: async () => {
373
+ return await $fetch("/applications/roles", {
374
+ method: "GET"
375
+ });
365
376
  }
366
377
  }
367
378
  };
@@ -389,21 +400,6 @@ function customEndpointsPluginClient() {
389
400
  };
390
401
  }
391
402
 
392
- function handshakePluginClient() {
393
- return {
394
- id: "handshake",
395
- getActions: ($fetch) => ({
396
- handshake: {
397
- noncePayload: async (nonce) => {
398
- return await $fetch("/handshake/nonce-payload", {
399
- query: { nonce }
400
- });
401
- }
402
- }
403
- })
404
- };
405
- }
406
-
407
403
  function invitationSignupPluginClient() {
408
404
  return {
409
405
  id: "invitation-signup",
@@ -483,7 +479,6 @@ function createAPIClient(apiUrl, fetchOptions = {}) {
483
479
  schema: inferOrgAdditionalFields()
484
480
  }),
485
481
  customEndpointsPluginClient(),
486
- handshakePluginClient(),
487
482
  invitationSignupPluginClient(),
488
483
  ssoClient(),
489
484
  twoFactorClient(),
@@ -746,7 +741,8 @@ class AdminService {
746
741
  ...options.query ? { query: options.query } : {},
747
742
  ...options.organizationsPreview !== void 0 ? { organizations_preview: options.organizationsPreview } : {},
748
743
  ...options.includeInvitations !== void 0 ? { include_invitations: options.includeInvitations } : {},
749
- ...options.organizationId ? { organization_id: options.organizationId } : {}
744
+ ...options.organizationId ? { organization_id: options.organizationId } : {},
745
+ ...options.applicationId ? { application_id: options.applicationId } : {}
750
746
  }
751
747
  });
752
748
  }
@@ -880,7 +876,8 @@ class AdminService {
880
876
  ...options.includeInvitations !== void 0 ? { include_invitations: options.includeInvitations } : {},
881
877
  ...options.includeAccess !== void 0 ? { include_access: options.includeAccess } : {},
882
878
  ...options.sortBy ? { sortBy: options.sortBy } : {},
883
- ...options.sortDirection ? { sortDirection: options.sortDirection } : {}
879
+ ...options.sortDirection ? { sortDirection: options.sortDirection } : {},
880
+ ...options.applicationId ? { application_id: options.applicationId } : {}
884
881
  }
885
882
  });
886
883
  }
@@ -1130,14 +1127,12 @@ class AdminService {
1130
1127
  await this.client.$fetch("/admin/invites/cancel", { method: "POST", body: { invitationId } });
1131
1128
  }
1132
1129
  /**
1133
- * Re-sends an organization invitation email as a global admin.
1134
- * @param options - Organization, email, role, and optional application and teams
1130
+ * Replaces a pending invitation with a new one that keeps its roles and
1131
+ * teams, and emails it, as a global admin.
1132
+ * @param invitationId - The ID of the invitation to resend
1135
1133
  */
1136
- async resendInvite(options) {
1137
- await this.client.$fetch("/admin/organizations/users", {
1138
- method: "POST",
1139
- body: { ...options, sendInvite: true, resend: true }
1140
- });
1134
+ async resendInvite(invitationId) {
1135
+ await this.client.$fetch("/admin/invites/resend", { method: "POST", body: { invitationId } });
1141
1136
  }
1142
1137
  /**
1143
1138
  * Invites several users to an organization in one call, or — with
@@ -1730,6 +1725,18 @@ class ApplicationService {
1730
1725
  async logout(refreshToken) {
1731
1726
  await this.client.applications.logout(refreshToken);
1732
1727
  }
1728
+ /**
1729
+ * Lists the roles of the application the current session was issued for.
1730
+ *
1731
+ * @returns The application's roles
1732
+ */
1733
+ async listRoles() {
1734
+ const response = await this.client.applications.listApplicationRoles();
1735
+ if (!response.data) {
1736
+ throw new Error("No data returned from the API", { cause: response.error });
1737
+ }
1738
+ return response.data;
1739
+ }
1733
1740
  }
1734
1741
 
1735
1742
  class OrganizationService {
@@ -1792,7 +1799,8 @@ class OrganizationService {
1792
1799
  * @param options - Pagination options
1793
1800
  * @param options.limit - Maximum number of members to return
1794
1801
  * @param options.offset - Number of members to skip
1795
- * @returns An array of organization members
1802
+ * @param options.includeWithoutAccess - With an application session, also list members without access to the application
1803
+ * @returns An array of organization members, with their application role when the session is an application session
1796
1804
  */
1797
1805
  async listMembers(options) {
1798
1806
  const members = await this.client.organization.listMembers({
@@ -1817,16 +1825,18 @@ class OrganizationService {
1817
1825
  * @param options - Invitation configuration
1818
1826
  * @param options.userEmail - Email address of the user to invite
1819
1827
  * @param options.role - Role to assign to the invited user
1828
+ * @param options.applicationRole - Application role granted on acceptance; required with an application-scoped session
1820
1829
  * @param options.teamId - Team ID to add the user to
1821
1830
  * @param options.resend - Whether to resend if invitation already exists
1822
1831
  * @returns The created invitation
1823
1832
  */
1824
- async inviteUserToOrganization({ userEmail, role, teamId, resend }) {
1833
+ async inviteUserToOrganization({ userEmail, role, applicationRole, teamId, resend }) {
1825
1834
  return await this.client.organization.inviteMember({
1826
1835
  email: userEmail,
1827
1836
  role,
1828
1837
  teamId,
1829
- resend: resend ?? false
1838
+ resend: resend ?? false,
1839
+ ...applicationRole ? { applicationRole } : {}
1830
1840
  });
1831
1841
  }
1832
1842
  /**
@@ -1889,6 +1899,9 @@ class OrganizationService {
1889
1899
  /**
1890
1900
  * Removes a user from the active organization.
1891
1901
  *
1902
+ * With an application-scoped session, revokes the member's access to that
1903
+ * application and keeps the membership.
1904
+ *
1892
1905
  * @param options - Provide either `memberId` or `userEmail` to identify the user
1893
1906
  * @param options.memberId - Membership ID to remove
1894
1907
  * @param options.userEmail - Email address of the member to remove
@@ -1901,6 +1914,10 @@ class OrganizationService {
1901
1914
  /**
1902
1915
  * Updates the role of an organization member.
1903
1916
  *
1917
+ * With an application-scoped session, `role` is an application role: the
1918
+ * update grants or changes the member's access to that application and
1919
+ * keeps the organization role.
1920
+ *
1904
1921
  * @param options - Role update configuration
1905
1922
  * @param options.memberId - The member ID to update
1906
1923
  * @param options.role - The new role to assign
@@ -2183,15 +2200,6 @@ class SessionService {
2183
2200
  newPassword: password
2184
2201
  });
2185
2202
  }
2186
- /**
2187
- * Retrieves the JWT token for a nonce.
2188
- *
2189
- * @param nonce - The nonce to retrieve the token for
2190
- * @returns The JWT token for the nonce
2191
- */
2192
- async getNoncePayload(nonce) {
2193
- return await this.client.handshake.noncePayload(nonce);
2194
- }
2195
2203
  }
2196
2204
 
2197
2205
  class ApiKeyService {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/auth-core",
3
- "version": "2.10.0",
3
+ "version": "3.1.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {