@meistrari/auth-core 1.15.0 → 1.17.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.ts CHANGED
@@ -77,6 +77,11 @@ declare const Roles: {
77
77
  * Type representing a valid organization role.
78
78
  */
79
79
  type Role = typeof Roles[keyof typeof Roles];
80
+ /**
81
+ * Role-based access control definitions mapping each role to its permissions.
82
+ *
83
+ * Used internally by the organization plugin to enforce access control.
84
+ */
80
85
  declare const rolesAccessControl: {
81
86
  "org:admin": {
82
87
  authorize<K_1 extends "member" | "access" | "organization" | "invitation" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins.Subset<"member" | "access" | "organization" | "invitation" | "team", {
@@ -163,6 +168,11 @@ declare const rolesAccessControl: {
163
168
  }>;
164
169
  };
165
170
  };
171
+ /**
172
+ * Additional database fields added to the `user` table.
173
+ *
174
+ * @internal
175
+ */
166
176
  declare const userAdditionalFields: {
167
177
  lastActiveAt: {
168
178
  type: "date";
@@ -170,6 +180,11 @@ declare const userAdditionalFields: {
170
180
  defaultValue: null;
171
181
  };
172
182
  };
183
+ /**
184
+ * Additional database fields added to the `organization` table.
185
+ *
186
+ * @internal
187
+ */
173
188
  declare const organizationAdditionalFields: {
174
189
  settings: {
175
190
  type: "json";
@@ -177,6 +192,11 @@ declare const organizationAdditionalFields: {
177
192
  required: false;
178
193
  };
179
194
  };
195
+ /**
196
+ * Additional database fields added to the `member` table.
197
+ *
198
+ * @internal
199
+ */
180
200
  declare const memberAdditionalFields: {
181
201
  deletedAt: {
182
202
  type: "date";
@@ -189,6 +209,21 @@ declare const memberAdditionalFields: {
189
209
  defaultValue: null;
190
210
  };
191
211
  };
212
+ /**
213
+ * Additional database fields added to the `invitation` table.
214
+ *
215
+ * @internal
216
+ */
217
+ declare const invitationAdditionalFields: {
218
+ applicationId: {
219
+ type: "string";
220
+ input: true;
221
+ required: false;
222
+ };
223
+ };
224
+ /**
225
+ * Zod schema and type for the `user` claim within a JWT payload.
226
+ */
192
227
  declare const JWTPayloadUser: z.ZodObject<{
193
228
  id: z.ZodString;
194
229
  name: z.ZodString;
@@ -196,11 +231,20 @@ declare const JWTPayloadUser: z.ZodObject<{
196
231
  role: z.ZodNullable<z.ZodString>;
197
232
  }, z.core.$strip>;
198
233
  type JWTPayloadUser = z.infer<typeof JWTPayloadUser>;
234
+ /**
235
+ * Zod schema and type for the `workspace` claim within a JWT payload.
236
+ */
199
237
  declare const JWTPayloadWorkspace: z.ZodObject<{
200
238
  id: z.ZodString;
201
239
  title: z.ZodString;
202
240
  }, z.core.$strip>;
203
241
  type JWTPayloadWorkspace = z.infer<typeof JWTPayloadWorkspace>;
242
+ /**
243
+ * Zod schema and type for the full JWT payload issued by the auth API.
244
+ *
245
+ * Includes `email`, `user`, `workspace`, and `sessionKey` claims
246
+ * on top of the standard Better Auth JWT fields (`sub`, `iss`, `exp`, etc.).
247
+ */
204
248
  declare const JWTPayload: z.ZodObject<{
205
249
  email: z.ZodString;
206
250
  user: z.ZodObject<{
@@ -217,29 +261,58 @@ declare const JWTPayload: z.ZodObject<{
217
261
  }, z.core.$strip>;
218
262
  type JWTPayload = JWTPayload$1 & z.infer<typeof JWTPayload>;
219
263
 
264
+ /**
265
+ * Metadata attached to an API key, identifying the owning user and workspace.
266
+ */
220
267
  type ApiKeyMetadata = {
268
+ /** The user who owns this API key. */
221
269
  user: {
222
270
  id: string;
223
271
  email: string;
224
272
  };
273
+ /** The workspace this API key belongs to. */
225
274
  workspace: {
226
275
  id: string;
227
276
  title: string;
228
277
  };
229
278
  } & Record<string, unknown>;
279
+ /**
280
+ * A full API key including the secret key value.
281
+ *
282
+ * The secret `key` field is only returned once at creation time.
283
+ */
230
284
  type ApiKey = Omit<ApiKey$1, 'metadata' | 'name'> & {
285
+ /** Display name of the API key. */
231
286
  name: string;
287
+ /** Metadata identifying the key's owner and workspace. */
232
288
  metadata: ApiKeyMetadata;
233
289
  };
290
+ /**
291
+ * An API key with the secret key value omitted.
292
+ *
293
+ * Used in list and get operations where the secret should not be exposed.
294
+ */
234
295
  type ApiKeyWithoutSecret = Omit<ApiKey, 'key'>;
296
+ /**
297
+ * Payload for creating a new API key.
298
+ */
235
299
  type CreateApiKeyPayload = {
300
+ /** Display name for the API key. */
236
301
  name: string;
302
+ /** Time in milliseconds until the key expires. Omit for a non-expiring key. */
237
303
  expiresIn?: number;
304
+ /** Optional prefix prepended to the generated key for identification. */
238
305
  prefix?: string;
306
+ /** Optional metadata to attach to the key. */
239
307
  metadata?: ApiKeyMetadata;
240
308
  };
309
+ /**
310
+ * Payload for updating an existing API key.
311
+ */
241
312
  type UpdateApiKeyPayload = {
313
+ /** The ID of the API key to update. */
242
314
  id: string;
315
+ /** The new display name for the API key. */
243
316
  name: string;
244
317
  };
245
318
 
@@ -260,6 +333,15 @@ type UpdateApiKeyPayload = {
260
333
  type Strict<T> = {
261
334
  [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
262
335
  };
336
+ /**
337
+ * Creates a configured Better Auth API client with all required plugins.
338
+ *
339
+ * @param apiUrl - The base URL of the authentication API
340
+ * @param fetchOptions - Custom fetch options to include in all API requests
341
+ * @returns A fully-configured Better Auth client instance
342
+ *
343
+ * @internal
344
+ */
263
345
  declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOption): {
264
346
  useActiveOrganization: better_auth_client.AuthQueryAtom<better_auth.Prettify<{
265
347
  id: string;
@@ -3313,6 +3395,17 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
3313
3395
  statusText: string;
3314
3396
  };
3315
3397
  }>;
3398
+ inviteUserToApplication: (options: InviteUserToApplicationOptions) => Promise<{
3399
+ data: null;
3400
+ error: {
3401
+ message?: string | undefined;
3402
+ status: number;
3403
+ statusText: string;
3404
+ };
3405
+ } | {
3406
+ data: CreateApplicationInvitationResponse;
3407
+ error: null;
3408
+ }>;
3316
3409
  startAuthorizationFlow: (applicationId: string, redirectUri: string, codeChallenge: string, organizationId: string) => Promise<{
3317
3410
  data: null;
3318
3411
  error: {
@@ -3401,7 +3494,7 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
3401
3494
  data: CompleteAuthorizationFlowResponse;
3402
3495
  error: null;
3403
3496
  }>;
3404
- whoAmI: (accessToken: string) => Promise<{
3497
+ whoAmI: (accessToken: string, options?: WhoAmIOptions) => Promise<{
3405
3498
  data: null;
3406
3499
  error: {
3407
3500
  message?: string | undefined;
@@ -4365,112 +4458,305 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
4365
4458
  };
4366
4459
  };
4367
4460
  };
4461
+ /**
4462
+ * The configured Better Auth client type with all plugins applied.
4463
+ *
4464
+ * @internal
4465
+ */
4368
4466
  type APIClient = ReturnType<typeof createAPIClient>;
4467
+ /** An authenticated user. */
4369
4468
  type User = APIClient['$Infer']['Session']['user'];
4469
+ /** A user session containing the user and session metadata. */
4370
4470
  type Session = APIClient['$Infer']['Session'];
4371
- type Organization = Strict<APIClient['$Infer']['Organization']>;
4471
+ /** An organization the user belongs to. */
4472
+ type BaseOrganization = Strict<APIClient['$Infer']['Organization']>;
4473
+ /** A team within an organization. */
4372
4474
  type Team = Strict<APIClient['$Infer']['Team']>;
4475
+ /** A pending invitation to join an organization. */
4373
4476
  type Invitation = Strict<APIClient['$Infer']['Invitation']>;
4477
+ /** A member of an organization with role information. */
4374
4478
  type Member = Strict<APIClient['$Infer']['Member']>;
4479
+ /**
4480
+ * Custom settings that can be applied to an organization.
4481
+ */
4375
4482
  type OrganizationSettings = {
4483
+ /** Whether file storage is disabled for this organization. */
4376
4484
  disableStorage?: boolean;
4485
+ /** Number of hours to retain data before automatic cleanup. */
4377
4486
  dataRetentionHours?: number;
4378
4487
  };
4379
- type ExtendedOrganization = Organization & {
4488
+ /**
4489
+ * An organization with optional custom settings.
4490
+ */
4491
+ type ExtendedOrganization = BaseOrganization & {
4380
4492
  settings?: OrganizationSettings;
4381
4493
  };
4494
+ /**
4495
+ * A complete organization object including its members, invitations, and teams.
4496
+ */
4382
4497
  type FullOrganization = Omit<ExtendedOrganization, 'slug'> & {
4383
4498
  slug: string | null;
4384
4499
  members: Member[];
4385
4500
  invitations: Invitation[];
4386
4501
  teams: Team[];
4387
4502
  };
4503
+ /**
4504
+ * An organization as returned by the "who am I" endpoint, where related
4505
+ * collections (`members`, `teams`, `invitations`) are optional and only
4506
+ * populated when explicitly requested via the `include` query parameter.
4507
+ */
4508
+ type WhoAmIOrganization = Omit<FullOrganization, 'members' | 'invitations' | 'teams'> & {
4509
+ members?: Member[];
4510
+ invitations?: Invitation[];
4511
+ teams?: Team[];
4512
+ };
4513
+ /**
4514
+ * A record linking a user to a team.
4515
+ */
4388
4516
  type TeamMember = {
4517
+ /** Unique identifier for this team membership. */
4389
4518
  id: string;
4519
+ /** The team this membership belongs to. */
4390
4520
  teamId: string;
4521
+ /** The user who is a member of the team. */
4391
4522
  userId: string;
4523
+ /** When the user was added to the team. */
4392
4524
  createdAt: Date;
4393
4525
  };
4394
4526
 
4527
+ /**
4528
+ * Keys of the organization's related collections that can be optionally
4529
+ * included in the "who am I" response.
4530
+ */
4531
+ type WhoAmIInclude = 'members' | 'teams' | 'invitations';
4532
+ /**
4533
+ * Represents a registered OAuth application.
4534
+ */
4395
4535
  type Application = {
4536
+ /** Unique application identifier. */
4396
4537
  id: string;
4538
+ /** Display name of the application. */
4397
4539
  name: string;
4540
+ /** Human-readable description of the application. */
4398
4541
  description: string;
4542
+ /** Allowed OAuth redirect URIs for this application. */
4399
4543
  redirectUris: string[];
4400
4544
  };
4545
+ /**
4546
+ * Response returned when listing candidate organizations for an application.
4547
+ */
4401
4548
  type ListCandidateOrganizationsResponse = {
4549
+ /** The application being queried. */
4402
4550
  application: Application;
4551
+ /** Organizations where the user is a member and the application is entitled. */
4403
4552
  organizations: FullOrganization[];
4404
4553
  };
4554
+ /**
4555
+ * Response returned when starting an authorization flow.
4556
+ */
4405
4557
  type StartAuthorizationFlowResponse = {
4558
+ /** The authorization code to exchange for tokens. */
4406
4559
  code: string;
4407
4560
  };
4561
+ /**
4562
+ * Response returned when completing an authorization flow or refreshing tokens.
4563
+ */
4408
4564
  type CompleteAuthorizationFlowResponse = {
4565
+ /** Short-lived JWT access token. */
4409
4566
  accessToken: string;
4567
+ /** Long-lived refresh token for obtaining new access tokens. */
4410
4568
  refreshToken: string;
4569
+ /** The authenticated user. */
4411
4570
  user: User;
4571
+ /** The organization the tokens are scoped to. */
4412
4572
  organization: FullOrganization;
4413
4573
  };
4574
+ /**
4575
+ * Response returned by the "who am I" endpoint.
4576
+ *
4577
+ * By default, the `organization` only contains the base organization fields.
4578
+ * The `members`, `teams`, and `invitations` collections are only populated
4579
+ * when explicitly requested via the `include` query parameter.
4580
+ */
4414
4581
  type WhoAmIResponse = {
4582
+ /** The authenticated user. */
4415
4583
  user: User;
4416
- organization: FullOrganization;
4584
+ /** The user's active organization. */
4585
+ organization: WhoAmIOrganization;
4417
4586
  };
4587
+ /**
4588
+ * Options accepted by the "who am I" client method.
4589
+ */
4590
+ type WhoAmIOptions = {
4591
+ /**
4592
+ * Collections to include in the returned organization. When omitted or
4593
+ * empty, only the base organization fields are returned.
4594
+ */
4595
+ include?: WhoAmIInclude[];
4596
+ };
4597
+ type InviteUserToApplicationOptions = {
4598
+ organizationId: string;
4599
+ applicationId: string;
4600
+ email: string;
4601
+ role: Role;
4602
+ teamId?: string;
4603
+ resend?: boolean;
4604
+ sendEmail?: boolean;
4605
+ };
4606
+ type ApplicationInvitationResponse = {
4607
+ id: string;
4608
+ organizationId: string;
4609
+ email: string;
4610
+ role: string | null;
4611
+ teamId: string | null;
4612
+ applicationId: string | null;
4613
+ status: string;
4614
+ expiresAt: Date | string;
4615
+ inviterId: string;
4616
+ createdAt: Date | string;
4617
+ };
4618
+ type CreateApplicationInvitationResponse = {
4619
+ data?: ApplicationInvitationResponse;
4620
+ };
4621
+ /**
4622
+ * Response returned when starting a device authorization flow (RFC 8628).
4623
+ */
4418
4624
  type DeviceAuthorizationResponse = {
4625
+ /** The device verification code for polling. */
4419
4626
  device_code: string;
4627
+ /** The user-facing code to enter on the verification page. */
4420
4628
  user_code: string;
4629
+ /** The URI the user should visit to authorize the device. */
4421
4630
  verification_uri: string;
4631
+ /** A complete URI including the user code for convenience. */
4422
4632
  verification_uri_complete: string;
4633
+ /** Number of seconds until the device code expires. */
4423
4634
  expires_in: number;
4635
+ /** Minimum polling interval in seconds. */
4424
4636
  interval: number;
4425
4637
  };
4638
+ /**
4639
+ * Minimal application info shown in device authorization context.
4640
+ *
4641
+ * @internal
4642
+ */
4426
4643
  type DeviceContextApplication = {
4644
+ /** Unique application identifier. */
4427
4645
  id: string;
4646
+ /** Display name of the application. */
4428
4647
  name: string;
4648
+ /** Human-readable description, or `null` if not set. */
4429
4649
  description: string | null;
4430
4650
  };
4651
+ /**
4652
+ * Context information for a pending device authorization request.
4653
+ */
4431
4654
  type DeviceAuthorizationContextResponse = {
4655
+ /** The application that initiated the device flow, with verification status. */
4432
4656
  requester: DeviceContextApplication & {
4433
4657
  isVerified: boolean;
4434
4658
  };
4659
+ /** The target application the requester wants access to. */
4435
4660
  target: DeviceContextApplication;
4661
+ /** Organizations the user can authorize the device for. */
4436
4662
  organizations: FullOrganization[];
4663
+ /** Organization pre-selected by the requester, if any. */
4437
4664
  preselectedOrganizationId: string | null;
4665
+ /** Current status of the device authorization request. */
4438
4666
  status: 'pending' | 'approved' | 'denied';
4667
+ /** Seconds remaining before the device code expires. */
4439
4668
  expiresIn: number;
4440
4669
  };
4670
+ /**
4671
+ * Response returned when approving or denying a device authorization request.
4672
+ */
4441
4673
  type DeviceAuthorizationActionResponse = {
4674
+ /** Whether the action was performed successfully. */
4442
4675
  success: boolean;
4443
4676
  };
4444
4677
 
4678
+ /**
4679
+ * Base error class for all SDK errors.
4680
+ *
4681
+ * Extends the native `Error` with a machine-readable `code` property
4682
+ * that can be used for programmatic error handling.
4683
+ */
4445
4684
  declare class BaseError extends Error {
4685
+ /** Machine-readable error code (e.g. `"INVALID_SOCIAL_PROVIDER"`). */
4446
4686
  code: string;
4687
+ /**
4688
+ * @param code - A machine-readable error code
4689
+ * @param message - A human-readable error message
4690
+ * @param options - Standard `ErrorOptions` (e.g. `cause`)
4691
+ */
4447
4692
  constructor(code: string, message: string, options?: ErrorOptions);
4448
4693
  }
4449
4694
 
4695
+ /**
4696
+ * Generic error thrown by the `ApplicationService`.
4697
+ *
4698
+ * All application-specific errors extend this class, so you can catch
4699
+ * `ApplicationError` to handle any application-related failure.
4700
+ */
4450
4701
  declare class ApplicationError extends BaseError {
4451
4702
  constructor(message: string, options?: ErrorOptions);
4452
4703
  }
4704
+ /**
4705
+ * Thrown when a refresh token has expired or been revoked.
4706
+ *
4707
+ * The client should discard its stored tokens and prompt the user
4708
+ * to re-authenticate.
4709
+ */
4453
4710
  declare class RefreshTokenExpiredError extends ApplicationError {
4454
4711
  constructor(options?: ErrorOptions);
4455
4712
  }
4713
+ /**
4714
+ * Thrown when an authorization flow fails unexpectedly.
4715
+ */
4456
4716
  declare class AuthorizationFlowError extends ApplicationError {
4457
4717
  constructor(message: string, options?: ErrorOptions);
4458
4718
  }
4719
+ /**
4720
+ * Thrown when an operation requires an authenticated user but no session exists.
4721
+ */
4459
4722
  declare class UserNotLoggedInError extends ApplicationError {
4460
4723
  constructor(message: string, options?: ErrorOptions);
4461
4724
  }
4725
+ /**
4726
+ * Thrown during device code polling when the user has not yet authorized the request.
4727
+ *
4728
+ * The client should continue polling at the specified interval.
4729
+ */
4462
4730
  declare class DeviceAuthorizationPendingError extends ApplicationError {
4463
4731
  constructor(options?: ErrorOptions);
4464
4732
  }
4733
+ /**
4734
+ * Thrown when the client is polling too frequently during the device flow.
4735
+ *
4736
+ * The client should increase its polling interval before retrying.
4737
+ */
4465
4738
  declare class DeviceAuthorizationSlowDownError extends ApplicationError {
4466
4739
  constructor(options?: ErrorOptions);
4467
4740
  }
4741
+ /**
4742
+ * Thrown when the user explicitly denies the device authorization request.
4743
+ */
4468
4744
  declare class DeviceAccessDeniedError extends ApplicationError {
4469
4745
  constructor(options?: ErrorOptions);
4470
4746
  }
4747
+ /**
4748
+ * Thrown when the device code has expired or has already been consumed.
4749
+ *
4750
+ * The client must start a new device authorization flow.
4751
+ */
4471
4752
  declare class DeviceCodeExpiredError extends ApplicationError {
4472
4753
  constructor(options?: ErrorOptions);
4473
4754
  }
4755
+ /**
4756
+ * Thrown when the authorization server returns a transient error during the device flow.
4757
+ *
4758
+ * The token exchange can be safely retried.
4759
+ */
4474
4760
  declare class DeviceTransientServerError extends ApplicationError {
4475
4761
  constructor(options?: ErrorOptions);
4476
4762
  }
@@ -4479,7 +4765,10 @@ declare class DeviceTransientServerError extends ApplicationError {
4479
4765
  * Service for managing applications and their candidate organizations.
4480
4766
  *
4481
4767
  * Provides functionality for:
4482
- * - Listing candidate organizations for an application
4768
+ * - OAuth authorization code flow (PKCE)
4769
+ * - Device authorization flow (RFC 8628)
4770
+ * - Token management (refresh, exchange)
4771
+ * - Organization switching
4483
4772
  */
4484
4773
  declare class ApplicationService {
4485
4774
  private client;
@@ -4505,6 +4794,13 @@ declare class ApplicationService {
4505
4794
  organizations: FullOrganization[];
4506
4795
  application?: Application | undefined;
4507
4796
  }>;
4797
+ /**
4798
+ * Invites a user to an application through an organization entitlement.
4799
+ *
4800
+ * @param options - Invitation details including organization, application, email, and role
4801
+ * @returns The created invitation
4802
+ */
4803
+ inviteUserToApplication(options: InviteUserToApplicationOptions): Promise<CreateApplicationInvitationResponse>;
4508
4804
  /**
4509
4805
  * Starts an authorization flow for a specific application.
4510
4806
  *
@@ -4514,10 +4810,57 @@ declare class ApplicationService {
4514
4810
  * @param organizationId - The organization ID to start the authorization flow for
4515
4811
  */
4516
4812
  startAuthorizationFlow(applicationId: string, redirectUri: string, codeChallenge: string, organizationId: string): Promise<StartAuthorizationFlowResponse>;
4813
+ /**
4814
+ * Starts a device authorization flow (RFC 8628).
4815
+ *
4816
+ * Returns a device code and user code that the end user must enter
4817
+ * on the verification URI to authorize the device.
4818
+ *
4819
+ * @param requesterApplicationId - The application requesting authorization
4820
+ * @param targetApplicationId - The target application to gain access to
4821
+ * @returns Device authorization details including codes and verification URI
4822
+ */
4517
4823
  startDeviceAuthorizationFlow(requesterApplicationId: string, targetApplicationId: string): Promise<DeviceAuthorizationResponse>;
4824
+ /**
4825
+ * Retrieves the context for a pending device authorization request.
4826
+ *
4827
+ * Used by the authorization page to display details about the requesting
4828
+ * and target applications before the user approves or denies.
4829
+ *
4830
+ * @param userCode - The user code from the device authorization response
4831
+ * @returns Context including application info, available organizations, and status
4832
+ */
4518
4833
  getDeviceAuthorizationContext(userCode: string): Promise<DeviceAuthorizationContextResponse>;
4834
+ /**
4835
+ * Approves a pending device authorization request.
4836
+ *
4837
+ * @param userCode - The user code identifying the device authorization request
4838
+ * @param organizationId - The organization to authorize the device for
4839
+ * @returns Confirmation of the approval action
4840
+ */
4519
4841
  approveDeviceAuthorizationFlow(userCode: string, organizationId: string): Promise<DeviceAuthorizationActionResponse>;
4842
+ /**
4843
+ * Denies a pending device authorization request.
4844
+ *
4845
+ * @param userCode - The user code identifying the device authorization request
4846
+ * @returns Confirmation of the denial action
4847
+ */
4520
4848
  denyDeviceAuthorizationFlow(userCode: string): Promise<DeviceAuthorizationActionResponse>;
4849
+ /**
4850
+ * Exchanges a device code for access and refresh tokens.
4851
+ *
4852
+ * This should be called by the device client while polling. It will throw
4853
+ * typed errors to indicate the polling state (pending, slow down, denied, expired).
4854
+ *
4855
+ * @param deviceCode - The device code obtained from {@link startDeviceAuthorizationFlow}
4856
+ * @returns Access and refresh tokens along with user and organization info
4857
+ *
4858
+ * @throws {DeviceAuthorizationPendingError} The user hasn't authorized yet — keep polling
4859
+ * @throws {DeviceAuthorizationSlowDownError} Polling too fast — increase the interval
4860
+ * @throws {DeviceAccessDeniedError} The user denied the request
4861
+ * @throws {DeviceCodeExpiredError} The device code has expired
4862
+ * @throws {DeviceTransientServerError} Transient server error — safe to retry
4863
+ */
4521
4864
  exchangeDeviceCodeForTokens(deviceCode: string): Promise<CompleteAuthorizationFlowResponse>;
4522
4865
  /**
4523
4866
  * Completes an authorization flow for a specific application.
@@ -4537,10 +4880,15 @@ declare class ApplicationService {
4537
4880
  /**
4538
4881
  * Gets the current user and organization for a specific application.
4539
4882
  *
4883
+ * By default, the returned organization does not include its `members`,
4884
+ * `teams`, or `invitations` collections. Pass `options.include` to request
4885
+ * any of them explicitly.
4886
+ *
4540
4887
  * @param accessToken - The access token to use for the who am I request
4888
+ * @param options - Optional include list controlling which relations are loaded
4541
4889
  * @returns The current user and organization
4542
4890
  */
4543
- whoAmI(accessToken: string): Promise<WhoAmIResponse>;
4891
+ whoAmI(accessToken: string, options?: WhoAmIOptions): Promise<WhoAmIResponse>;
4544
4892
  /**
4545
4893
  * Switches the active organization for the authenticated user.
4546
4894
  *
@@ -4564,29 +4912,72 @@ declare class ApplicationService {
4564
4912
  logout(refreshToken: string): Promise<void>;
4565
4913
  }
4566
4914
 
4915
+ /**
4916
+ * Fields that can be updated on an organization.
4917
+ */
4567
4918
  type UpdateOrganizationPayload = Partial<Pick<ExtendedOrganization, 'name' | 'logo' | 'settings'>>;
4919
+ /**
4920
+ * Pagination options for listing organization members.
4921
+ */
4568
4922
  type ListMembersOptions = {
4923
+ /** Maximum number of members to return. */
4569
4924
  limit?: number;
4925
+ /** Number of members to skip for pagination. */
4570
4926
  offset?: number;
4571
4927
  };
4928
+ /**
4929
+ * Options for inviting a user to the active organization.
4930
+ */
4572
4931
  type InviteUserToOrganizationOptions = {
4932
+ /** Email address of the user to invite. */
4573
4933
  userEmail: string;
4934
+ /** Organization role to assign to the invited user. */
4574
4935
  role: Role;
4936
+ /** Optional team to add the user to upon acceptance. */
4575
4937
  teamId?: string;
4938
+ /** Whether to resend the invitation if one already exists for this email. */
4576
4939
  resend?: boolean;
4940
+ /**
4941
+ * Application scope for legacy callers that still pass this option through
4942
+ * the organization invitation path.
4943
+ *
4944
+ * New app-scoped invitations should use
4945
+ * `applications.inviteUserToApplication`, which calls
4946
+ * `POST /api/auth/applications/invitations`. The server rejects legacy
4947
+ * organization invitation creation when this field is present.
4948
+ */
4949
+ applicationId?: string;
4577
4950
  };
4951
+ /**
4952
+ * Options for removing a user from the active organization.
4953
+ *
4954
+ * Provide either `memberId` or `userEmail`, but not both.
4955
+ */
4578
4956
  type RemoveUserFromOrganizationOptions = {
4957
+ /** The member ID to remove. */
4579
4958
  memberId: string;
4580
4959
  userEmail?: never;
4581
4960
  } | {
4961
+ /** The user's email address to remove. */
4582
4962
  userEmail: string;
4583
4963
  memberId?: never;
4584
4964
  };
4965
+ /**
4966
+ * Options for updating a member's role within the organization.
4967
+ */
4585
4968
  type UpdateMemberRoleOptions = {
4969
+ /** The member ID whose role should be updated. */
4586
4970
  memberId: string;
4971
+ /** The new role to assign. */
4587
4972
  role: Role;
4588
4973
  };
4974
+ /**
4975
+ * Payload for creating a new team.
4976
+ */
4589
4977
  type CreateTeamPayload = Pick<Team, 'name'>;
4978
+ /**
4979
+ * Payload for updating an existing team.
4980
+ */
4590
4981
  type UpdateTeamPayload = Pick<Team, 'name'>;
4591
4982
 
4592
4983
  /**
@@ -4668,10 +5059,7 @@ declare class OrganizationService {
4668
5059
  /**
4669
5060
  * Updates an organization's details.
4670
5061
  *
4671
- * @param payload - The organization fields to update
4672
- * @param payload.name - New organization name
4673
- * @param payload.logo - New organization logo URL
4674
- * @param payload.settings - New organization settings
5062
+ * @param payload - The organization fields to update (name, logo, settings)
4675
5063
  * @returns The updated organization
4676
5064
  */
4677
5065
  updateOrganization(payload: UpdateOrganizationPayload): Promise<ExtendedOrganization>;
@@ -4747,10 +5135,11 @@ declare class OrganizationService {
4747
5135
  * @param options.userEmail - Email address of the user to invite
4748
5136
  * @param options.role - Role to assign to the invited user
4749
5137
  * @param options.teamId - Team ID to add the user to
5138
+ * @param options.applicationId - Legacy application scope; prefer applications.inviteUserToApplication for new app-scoped invites
4750
5139
  * @param options.resend - Whether to resend if invitation already exists
4751
5140
  * @returns The created invitation
4752
5141
  */
4753
- inviteUserToOrganization({ userEmail, role, teamId, resend }: InviteUserToOrganizationOptions): Promise<NonNullable<{
5142
+ inviteUserToOrganization({ userEmail, role, teamId, resend, applicationId }: InviteUserToOrganizationOptions): Promise<NonNullable<{
4754
5143
  id: string;
4755
5144
  organizationId: string;
4756
5145
  email: string;
@@ -4781,14 +5170,16 @@ declare class OrganizationService {
4781
5170
  * Accepts an organization invitation.
4782
5171
  *
4783
5172
  * @param id - The invitation ID to accept
5173
+ * @returns Object containing the application's `homeUrl` when the invitation is
5174
+ * scoped to an application that defines one; otherwise `null`.
4784
5175
  */
4785
- acceptInvitation(id: string): Promise<void>;
5176
+ acceptInvitation(id: string): Promise<{
5177
+ homeUrl: string | null;
5178
+ }>;
4786
5179
  /**
4787
5180
  * Removes a user from the active organization.
4788
5181
  *
4789
- * @param options - User identifier (either memberId or userEmail must be provided)
4790
- * @param options.memberId - The member ID to remove
4791
- * @param options.userEmail - The user email to remove
5182
+ * @param options - Provide either `memberId` or `userEmail` to identify the user
4792
5183
  */
4793
5184
  removeUserFromOrganization({ memberId, userEmail }: RemoveUserFromOrganizationOptions): Promise<void>;
4794
5185
  /**
@@ -4802,8 +5193,7 @@ declare class OrganizationService {
4802
5193
  /**
4803
5194
  * Creates a new team within the active organization.
4804
5195
  *
4805
- * @param payload - Team configuration
4806
- * @param payload.name - The name of the team
5196
+ * @param payload - Team configuration with a `name` field
4807
5197
  * @returns The created team
4808
5198
  */
4809
5199
  createTeam(payload: CreateTeamPayload): Promise<{
@@ -4817,8 +5207,7 @@ declare class OrganizationService {
4817
5207
  * Updates an existing team's details.
4818
5208
  *
4819
5209
  * @param id - The team ID to update
4820
- * @param payload - Team fields to update
4821
- * @param payload.name - The new team name
5210
+ * @param payload - Team fields to update (currently supports `name`)
4822
5211
  * @returns The updated team
4823
5212
  */
4824
5213
  updateTeam(id: string, payload: UpdateTeamPayload): Promise<{
@@ -4880,20 +5269,39 @@ declare class OrganizationService {
4880
5269
  removeTeamMember(teamId: string, userId: string): Promise<void>;
4881
5270
  }
4882
5271
 
5272
+ /**
5273
+ * Options for signing in with a social provider (Google or Microsoft).
5274
+ */
4883
5275
  type SocialSignInOptions = {
5276
+ /** The social identity provider to authenticate with. */
4884
5277
  provider: 'google' | 'microsoft';
5278
+ /** URL to redirect to after successful authentication. */
4885
5279
  callbackURL: string;
5280
+ /** URL to redirect to if authentication fails. Falls back to the API's default error page if not provided. */
4886
5281
  errorCallbackURL?: string;
4887
5282
  };
5283
+ /**
5284
+ * Options for signing in via SAML Single Sign-On.
5285
+ */
4888
5286
  type SignInWithSamlOptions = {
5287
+ /** The user's email address, used to resolve the correct SAML identity provider. */
4889
5288
  email: string;
5289
+ /** URL to redirect to after successful authentication. */
4890
5290
  callbackURL: string;
5291
+ /** URL to redirect to if authentication fails. Falls back to the API's default error page if not provided. */
4891
5292
  errorCallbackURL?: string;
4892
5293
  };
5294
+ /**
5295
+ * Options for signing in with email and password credentials.
5296
+ */
4893
5297
  type SignInWithEmailAndPasswordOptions = {
5298
+ /** The user's email address. */
4894
5299
  email: string;
5300
+ /** The user's password. */
4895
5301
  password: string;
5302
+ /** URL to redirect to after successful authentication. */
4896
5303
  callbackURL: string;
5304
+ /** URL to redirect to if authentication fails. */
4897
5305
  errorCallbackURL?: string;
4898
5306
  };
4899
5307
 
@@ -5026,10 +5434,10 @@ declare class SessionService {
5026
5434
  }
5027
5435
 
5028
5436
  /**
5029
- * Service for managing API keys
5437
+ * Service for managing API keys.
5030
5438
  *
5031
- * Provides comprehensive API key management including:
5032
- * - API key CRUD operations
5439
+ * Provides CRUD operations for API keys scoped to the authenticated
5440
+ * user or their active organization.
5033
5441
  */
5034
5442
  declare class ApiKeyService {
5035
5443
  private client;
@@ -5039,16 +5447,52 @@ declare class ApiKeyService {
5039
5447
  * @param client - The API client for making API key requests
5040
5448
  */
5041
5449
  constructor(client: APIClient);
5450
+ /**
5451
+ * Creates a new API key.
5452
+ *
5453
+ * The returned object includes the secret `key` value, which is only
5454
+ * available at creation time and cannot be retrieved later.
5455
+ *
5456
+ * @param payload - The API key configuration
5457
+ * @returns The created API key including the secret key value
5458
+ */
5042
5459
  createApiKey(payload: CreateApiKeyPayload): Promise<ApiKey>;
5460
+ /**
5461
+ * Retrieves an API key by its ID.
5462
+ *
5463
+ * @param id - The API key ID
5464
+ * @returns The API key (without the secret key value)
5465
+ */
5043
5466
  getApiKey(id: string): Promise<ApiKeyWithoutSecret>;
5467
+ /**
5468
+ * Lists all API keys owned by the authenticated user.
5469
+ *
5470
+ * @returns An object containing the API keys array and pagination metadata
5471
+ */
5044
5472
  listApiKeys(): Promise<{
5045
5473
  apiKeys: ApiKeyWithoutSecret[];
5046
5474
  total: number;
5047
5475
  limit: number | undefined;
5048
5476
  offset: number | undefined;
5049
5477
  }>;
5478
+ /**
5479
+ * Lists all API keys belonging to the active organization.
5480
+ *
5481
+ * @returns An array of API keys (without secret key values)
5482
+ */
5050
5483
  listOrganizationApiKeys(): Promise<ApiKeyWithoutSecret[]>;
5484
+ /**
5485
+ * Updates an existing API key.
5486
+ *
5487
+ * @param payload - The fields to update
5488
+ * @returns The updated API key (without the secret key value)
5489
+ */
5051
5490
  updateApiKey(payload: UpdateApiKeyPayload): Promise<ApiKeyWithoutSecret>;
5491
+ /**
5492
+ * Permanently deletes an API key.
5493
+ *
5494
+ * @param id - The API key ID to delete
5495
+ */
5052
5496
  deleteApiKey(id: string): Promise<{
5053
5497
  success: boolean;
5054
5498
  }>;
@@ -5184,5 +5628,5 @@ declare function validateToken(token: string, apiUrl: string): Promise<boolean>;
5184
5628
  */
5185
5629
  declare function extractTokenPayload(token: string): JWTPayload;
5186
5630
 
5187
- export { ApplicationError, AuthClient, AuthorizationFlowError, DeviceAccessDeniedError, DeviceAuthorizationPendingError, DeviceAuthorizationSlowDownError, DeviceCodeExpiredError, DeviceTransientServerError, EmailRequired, InvalidCallbackURL, InvalidSocialProvider, JWTPayload, JWTPayloadUser, JWTPayloadWorkspace, RefreshTokenExpiredError, Roles, UserNotLoggedInError, ac, createAPIClient, extractTokenPayload, isTokenExpired, memberAdditionalFields, organizationAdditionalFields, rolesAccessControl, userAdditionalFields, validateToken };
5188
- export type { APIClient, ApiKey, ApiKeyMetadata, ApiKeyWithoutSecret, Application, CompleteAuthorizationFlowResponse, CreateApiKeyPayload, CreateTeamPayload, DeviceAuthorizationActionResponse, DeviceAuthorizationContextResponse, DeviceAuthorizationResponse, FullOrganization, Invitation, InviteUserToOrganizationOptions, ListCandidateOrganizationsResponse, ListMembersOptions, Member, ExtendedOrganization as Organization, RemoveUserFromOrganizationOptions, Role, Session, SignInWithEmailAndPasswordOptions, SignInWithSamlOptions, SocialSignInOptions, StartAuthorizationFlowResponse, Team, TeamMember, UpdateApiKeyPayload, UpdateMemberRoleOptions, UpdateOrganizationPayload, UpdateTeamPayload, User, WhoAmIResponse };
5631
+ export { ApplicationError, AuthClient, AuthorizationFlowError, DeviceAccessDeniedError, DeviceAuthorizationPendingError, DeviceAuthorizationSlowDownError, DeviceCodeExpiredError, DeviceTransientServerError, EmailRequired, InvalidCallbackURL, InvalidSocialProvider, JWTPayload, JWTPayloadUser, JWTPayloadWorkspace, RefreshTokenExpiredError, Roles, UserNotLoggedInError, ac, createAPIClient, extractTokenPayload, invitationAdditionalFields, isTokenExpired, memberAdditionalFields, organizationAdditionalFields, rolesAccessControl, userAdditionalFields, validateToken };
5632
+ export type { APIClient, ApiKey, ApiKeyMetadata, ApiKeyWithoutSecret, Application, ApplicationInvitationResponse, BaseOrganization, CompleteAuthorizationFlowResponse, CreateApiKeyPayload, CreateApplicationInvitationResponse, CreateTeamPayload, DeviceAuthorizationActionResponse, DeviceAuthorizationContextResponse, DeviceAuthorizationResponse, DeviceContextApplication, FullOrganization, Invitation, InviteUserToApplicationOptions, InviteUserToOrganizationOptions, ListCandidateOrganizationsResponse, ListMembersOptions, Member, ExtendedOrganization as Organization, OrganizationSettings, RemoveUserFromOrganizationOptions, Role, Session, SignInWithEmailAndPasswordOptions, SignInWithSamlOptions, SocialSignInOptions, StartAuthorizationFlowResponse, Strict, Team, TeamMember, UpdateApiKeyPayload, UpdateMemberRoleOptions, UpdateOrganizationPayload, UpdateTeamPayload, User, WhoAmIInclude, WhoAmIOptions, WhoAmIOrganization, WhoAmIResponse };