@meistrari/auth-core 1.2.1 → 1.3.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
@@ -1,6 +1,5 @@
1
1
  import * as better_auth_client from 'better-auth/client';
2
2
  import { BetterFetchOption } from 'better-auth/client';
3
- export { BetterFetchError as APIError } from 'better-auth/client';
4
3
  import * as better_auth from 'better-auth';
5
4
  import { JWTPayload } from 'better-auth';
6
5
  import * as better_auth_plugins from 'better-auth/plugins';
@@ -9,6 +8,7 @@ import * as _better_auth_sso from '@better-auth/sso';
9
8
  import * as better_call from 'better-call';
10
9
  import * as nanostores from 'nanostores';
11
10
  import * as _better_fetch_fetch from '@better-fetch/fetch';
11
+ export { BetterFetchError as APIError } from '@better-fetch/fetch';
12
12
  import * as better_auth_client_plugins from 'better-auth/client/plugins';
13
13
 
14
14
  declare const ac: {
@@ -302,10 +302,14 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
302
302
  };
303
303
  };
304
304
  } & {
305
- handshake: <FetchOptions extends better_auth.ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: better_auth_client_plugins.Prettify<{
306
- query?: Record<string, any> | undefined;
305
+ handshake: <FetchOptions extends better_auth.ClientFetchOption<never, Partial<{
306
+ origin: string;
307
+ }> & Record<string, any>, Record<string, any> | undefined>>(data_0: better_auth_client_plugins.Prettify<{
308
+ query: {
309
+ origin: string;
310
+ };
307
311
  fetchOptions?: FetchOptions | undefined;
308
- }> | undefined, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch.BetterFetchResponse<{
312
+ }>, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch.BetterFetchResponse<{
309
313
  status: ("OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "FOUND" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "REQUEST_TIMEOUT" | "CONFLICT" | "GONE" | "LENGTH_REQUIRED" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "URI_TOO_LONG" | "UNSUPPORTED_MEDIA_TYPE" | "RANGE_NOT_SATISFIABLE" | "EXPECTATION_FAILED" | "I'M_A_TEAPOT" | "MISDIRECTED_REQUEST" | "UNPROCESSABLE_ENTITY" | "LOCKED" | "FAILED_DEPENDENCY" | "TOO_EARLY" | "UPGRADE_REQUIRED" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "REQUEST_HEADER_FIELDS_TOO_LARGE" | "UNAVAILABLE_FOR_LEGAL_REASONS" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "HTTP_VERSION_NOT_SUPPORTED" | "VARIANT_ALSO_NEGOTIATES" | "INSUFFICIENT_STORAGE" | "LOOP_DETECTED" | "NOT_EXTENDED" | "NETWORK_AUTHENTICATION_REQUIRED") | better_call.Status;
310
314
  body: ({
311
315
  message?: string;
@@ -3075,10 +3079,14 @@ declare const stub: {
3075
3079
  };
3076
3080
  };
3077
3081
  } & {
3078
- handshake: <FetchOptions extends better_auth.ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: better_auth_client_plugins.Prettify<{
3079
- query?: Record<string, any> | undefined;
3082
+ handshake: <FetchOptions extends better_auth.ClientFetchOption<never, Partial<{
3083
+ origin: string;
3084
+ }> & Record<string, any>, Record<string, any> | undefined>>(data_0: better_auth_client_plugins.Prettify<{
3085
+ query: {
3086
+ origin: string;
3087
+ };
3080
3088
  fetchOptions?: FetchOptions | undefined;
3081
- }> | undefined, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch.BetterFetchResponse<{
3089
+ }>, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch.BetterFetchResponse<{
3082
3090
  status: ("OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "FOUND" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "REQUEST_TIMEOUT" | "CONFLICT" | "GONE" | "LENGTH_REQUIRED" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "URI_TOO_LONG" | "UNSUPPORTED_MEDIA_TYPE" | "RANGE_NOT_SATISFIABLE" | "EXPECTATION_FAILED" | "I'M_A_TEAPOT" | "MISDIRECTED_REQUEST" | "UNPROCESSABLE_ENTITY" | "LOCKED" | "FAILED_DEPENDENCY" | "TOO_EARLY" | "UPGRADE_REQUIRED" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "REQUEST_HEADER_FIELDS_TOO_LARGE" | "UNAVAILABLE_FOR_LEGAL_REASONS" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "HTTP_VERSION_NOT_SUPPORTED" | "VARIANT_ALSO_NEGOTIATES" | "INSUFFICIENT_STORAGE" | "LOOP_DETECTED" | "NOT_EXTENDED" | "NETWORK_AUTHENTICATION_REQUIRED") | better_call.Status;
3083
3091
  body: ({
3084
3092
  message?: string;
@@ -6069,6 +6077,7 @@ declare class OrganizationService {
6069
6077
  *
6070
6078
  * @param teamId - The team ID
6071
6079
  * @param userId - The user ID to add
6080
+ * @returns The added team member
6072
6081
  */
6073
6082
  addTeamMember(teamId: string, userId: string): Promise<{
6074
6083
  id: string;
@@ -6224,6 +6233,141 @@ declare class SessionService {
6224
6233
  }>;
6225
6234
  }
6226
6235
 
6236
+ type CreateApiKeyPayload = {
6237
+ name?: string;
6238
+ expiresIn?: number;
6239
+ prefix?: string;
6240
+ metadata?: ApiKeyMetadata;
6241
+ };
6242
+ type UpdateApiKeyPayload = {
6243
+ id: string;
6244
+ name?: string;
6245
+ };
6246
+ type ApiKeyMetadata = {
6247
+ user: {
6248
+ id: string;
6249
+ email: string;
6250
+ };
6251
+ workspace: {
6252
+ id: string;
6253
+ title: string;
6254
+ };
6255
+ } & Record<string, unknown>;
6256
+
6257
+ /**
6258
+ * Service for managing API keys
6259
+ *
6260
+ * Provides comprehensive API key management including:
6261
+ * - API key CRUD operations
6262
+ */
6263
+ declare class ApiKeyService {
6264
+ private client;
6265
+ /**
6266
+ * Creates a new ApiKeyService instance.
6267
+ *
6268
+ * @param client - The API client for making API key requests
6269
+ */
6270
+ constructor(client: APIClient);
6271
+ createApiKey(payload: CreateApiKeyPayload): Promise<{
6272
+ key: string;
6273
+ metadata: any;
6274
+ permissions: any;
6275
+ id: string;
6276
+ name: string | null;
6277
+ start: string | null;
6278
+ prefix: string | null;
6279
+ userId: string;
6280
+ refillInterval: number | null;
6281
+ refillAmount: number | null;
6282
+ lastRefillAt: Date | null;
6283
+ enabled: boolean;
6284
+ rateLimitEnabled: boolean;
6285
+ rateLimitTimeWindow: number | null;
6286
+ rateLimitMax: number | null;
6287
+ requestCount: number;
6288
+ remaining: number | null;
6289
+ lastRequest: Date | null;
6290
+ expiresAt: Date | null;
6291
+ createdAt: Date;
6292
+ updatedAt: Date;
6293
+ }>;
6294
+ getApiKey(id: string): Promise<{
6295
+ permissions: {
6296
+ [key: string]: string[];
6297
+ } | null;
6298
+ id: string;
6299
+ name: string | null;
6300
+ start: string | null;
6301
+ prefix: string | null;
6302
+ userId: string;
6303
+ refillInterval: number | null;
6304
+ refillAmount: number | null;
6305
+ lastRefillAt: Date | null;
6306
+ enabled: boolean;
6307
+ rateLimitEnabled: boolean;
6308
+ rateLimitTimeWindow: number | null;
6309
+ rateLimitMax: number | null;
6310
+ requestCount: number;
6311
+ remaining: number | null;
6312
+ lastRequest: Date | null;
6313
+ expiresAt: Date | null;
6314
+ createdAt: Date;
6315
+ updatedAt: Date;
6316
+ metadata: Record<string, any> | null;
6317
+ }>;
6318
+ listApiKeys(): Promise<{
6319
+ permissions: {
6320
+ [key: string]: string[];
6321
+ } | null;
6322
+ id: string;
6323
+ name: string | null;
6324
+ start: string | null;
6325
+ prefix: string | null;
6326
+ userId: string;
6327
+ refillInterval: number | null;
6328
+ refillAmount: number | null;
6329
+ lastRefillAt: Date | null;
6330
+ enabled: boolean;
6331
+ rateLimitEnabled: boolean;
6332
+ rateLimitTimeWindow: number | null;
6333
+ rateLimitMax: number | null;
6334
+ requestCount: number;
6335
+ remaining: number | null;
6336
+ lastRequest: Date | null;
6337
+ expiresAt: Date | null;
6338
+ createdAt: Date;
6339
+ updatedAt: Date;
6340
+ metadata: Record<string, any> | null;
6341
+ }[]>;
6342
+ updateApiKey(payload: UpdateApiKeyPayload): Promise<{
6343
+ permissions: {
6344
+ [key: string]: string[];
6345
+ } | null;
6346
+ id: string;
6347
+ name: string | null;
6348
+ start: string | null;
6349
+ prefix: string | null;
6350
+ userId: string;
6351
+ refillInterval: number | null;
6352
+ refillAmount: number | null;
6353
+ lastRefillAt: Date | null;
6354
+ enabled: boolean;
6355
+ rateLimitEnabled: boolean;
6356
+ rateLimitTimeWindow: number | null;
6357
+ rateLimitMax: number | null;
6358
+ requestCount: number;
6359
+ remaining: number | null;
6360
+ lastRequest: Date | null;
6361
+ expiresAt: Date | null;
6362
+ createdAt: Date;
6363
+ updatedAt: Date;
6364
+ metadata: Record<string, any> | null;
6365
+ }>;
6366
+ deleteApiKey(id: string): Promise<{
6367
+ success: boolean;
6368
+ }>;
6369
+ }
6370
+
6227
6371
  declare class BaseError extends Error {
6228
6372
  code: string;
6229
6373
  constructor(code: string, message: string, options?: ErrorOptions);
@@ -6281,6 +6425,10 @@ declare class AuthClient {
6281
6425
  * Organization management service for multi-tenant operations
6282
6426
  */
6283
6427
  organization: OrganizationService;
6428
+ /**
6429
+ * API key management service for API key operations
6430
+ */
6431
+ apiKey: ApiKeyService;
6284
6432
  /**
6285
6433
  * Creates a new AuthClient instance.
6286
6434
  *
@@ -6344,4 +6492,4 @@ declare function validateToken(token: string, apiUrl: string): Promise<boolean>;
6344
6492
  declare function extractTokenPayload(token: string): JWTTokenPayload;
6345
6493
 
6346
6494
  export { AuthClient, EmailRequired, InvalidCallbackURL, InvalidSocialProvider, Roles, ac, createAPIClient, extractTokenPayload, isTokenExpired, organizationAdditionalFields, rolesAccessControl, userAdditionalFields, validateToken };
6347
- export type { APIClient, CreateTeamPayload, FullOrganization, GetOrganizationOptions, Invitation, InviteUserToOrganizationOptions, JWTTokenPayload, ListMembersOptions, ExtendedMember as Member, ExtendedOrganization as Organization, RemoveUserFromOrganizationOptions, Role, Session, SignInWithEmailAndPasswordOptions, SignInWithSamlOptions, SocialSignInOptions, Team, TeamMember, UpdateMemberRoleOptions, UpdateOrganizationPayload, UpdateTeamPayload, User };
6495
+ export type { APIClient, ApiKeyMetadata, CreateApiKeyPayload, CreateTeamPayload, FullOrganization, GetOrganizationOptions, Invitation, InviteUserToOrganizationOptions, JWTTokenPayload, ListMembersOptions, ExtendedMember as Member, ExtendedOrganization as Organization, RemoveUserFromOrganizationOptions, Role, Session, SignInWithEmailAndPasswordOptions, SignInWithSamlOptions, SocialSignInOptions, Team, TeamMember, UpdateApiKeyPayload, UpdateMemberRoleOptions, UpdateOrganizationPayload, UpdateTeamPayload, User };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import * as better_auth_client from 'better-auth/client';
2
2
  import { BetterFetchOption } from 'better-auth/client';
3
- export { BetterFetchError as APIError } from 'better-auth/client';
4
3
  import * as better_auth from 'better-auth';
5
4
  import { JWTPayload } from 'better-auth';
6
5
  import * as better_auth_plugins from 'better-auth/plugins';
@@ -9,6 +8,7 @@ import * as _better_auth_sso from '@better-auth/sso';
9
8
  import * as better_call from 'better-call';
10
9
  import * as nanostores from 'nanostores';
11
10
  import * as _better_fetch_fetch from '@better-fetch/fetch';
11
+ export { BetterFetchError as APIError } from '@better-fetch/fetch';
12
12
  import * as better_auth_client_plugins from 'better-auth/client/plugins';
13
13
 
14
14
  declare const ac: {
@@ -302,10 +302,14 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
302
302
  };
303
303
  };
304
304
  } & {
305
- handshake: <FetchOptions extends better_auth.ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: better_auth_client_plugins.Prettify<{
306
- query?: Record<string, any> | undefined;
305
+ handshake: <FetchOptions extends better_auth.ClientFetchOption<never, Partial<{
306
+ origin: string;
307
+ }> & Record<string, any>, Record<string, any> | undefined>>(data_0: better_auth_client_plugins.Prettify<{
308
+ query: {
309
+ origin: string;
310
+ };
307
311
  fetchOptions?: FetchOptions | undefined;
308
- }> | undefined, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch.BetterFetchResponse<{
312
+ }>, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch.BetterFetchResponse<{
309
313
  status: ("OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "FOUND" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "REQUEST_TIMEOUT" | "CONFLICT" | "GONE" | "LENGTH_REQUIRED" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "URI_TOO_LONG" | "UNSUPPORTED_MEDIA_TYPE" | "RANGE_NOT_SATISFIABLE" | "EXPECTATION_FAILED" | "I'M_A_TEAPOT" | "MISDIRECTED_REQUEST" | "UNPROCESSABLE_ENTITY" | "LOCKED" | "FAILED_DEPENDENCY" | "TOO_EARLY" | "UPGRADE_REQUIRED" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "REQUEST_HEADER_FIELDS_TOO_LARGE" | "UNAVAILABLE_FOR_LEGAL_REASONS" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "HTTP_VERSION_NOT_SUPPORTED" | "VARIANT_ALSO_NEGOTIATES" | "INSUFFICIENT_STORAGE" | "LOOP_DETECTED" | "NOT_EXTENDED" | "NETWORK_AUTHENTICATION_REQUIRED") | better_call.Status;
310
314
  body: ({
311
315
  message?: string;
@@ -3075,10 +3079,14 @@ declare const stub: {
3075
3079
  };
3076
3080
  };
3077
3081
  } & {
3078
- handshake: <FetchOptions extends better_auth.ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: better_auth_client_plugins.Prettify<{
3079
- query?: Record<string, any> | undefined;
3082
+ handshake: <FetchOptions extends better_auth.ClientFetchOption<never, Partial<{
3083
+ origin: string;
3084
+ }> & Record<string, any>, Record<string, any> | undefined>>(data_0: better_auth_client_plugins.Prettify<{
3085
+ query: {
3086
+ origin: string;
3087
+ };
3080
3088
  fetchOptions?: FetchOptions | undefined;
3081
- }> | undefined, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch.BetterFetchResponse<{
3089
+ }>, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch.BetterFetchResponse<{
3082
3090
  status: ("OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "FOUND" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "REQUEST_TIMEOUT" | "CONFLICT" | "GONE" | "LENGTH_REQUIRED" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "URI_TOO_LONG" | "UNSUPPORTED_MEDIA_TYPE" | "RANGE_NOT_SATISFIABLE" | "EXPECTATION_FAILED" | "I'M_A_TEAPOT" | "MISDIRECTED_REQUEST" | "UNPROCESSABLE_ENTITY" | "LOCKED" | "FAILED_DEPENDENCY" | "TOO_EARLY" | "UPGRADE_REQUIRED" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "REQUEST_HEADER_FIELDS_TOO_LARGE" | "UNAVAILABLE_FOR_LEGAL_REASONS" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "HTTP_VERSION_NOT_SUPPORTED" | "VARIANT_ALSO_NEGOTIATES" | "INSUFFICIENT_STORAGE" | "LOOP_DETECTED" | "NOT_EXTENDED" | "NETWORK_AUTHENTICATION_REQUIRED") | better_call.Status;
3083
3091
  body: ({
3084
3092
  message?: string;
@@ -6069,6 +6077,7 @@ declare class OrganizationService {
6069
6077
  *
6070
6078
  * @param teamId - The team ID
6071
6079
  * @param userId - The user ID to add
6080
+ * @returns The added team member
6072
6081
  */
6073
6082
  addTeamMember(teamId: string, userId: string): Promise<{
6074
6083
  id: string;
@@ -6224,6 +6233,141 @@ declare class SessionService {
6224
6233
  }>;
6225
6234
  }
6226
6235
 
6236
+ type CreateApiKeyPayload = {
6237
+ name?: string;
6238
+ expiresIn?: number;
6239
+ prefix?: string;
6240
+ metadata?: ApiKeyMetadata;
6241
+ };
6242
+ type UpdateApiKeyPayload = {
6243
+ id: string;
6244
+ name?: string;
6245
+ };
6246
+ type ApiKeyMetadata = {
6247
+ user: {
6248
+ id: string;
6249
+ email: string;
6250
+ };
6251
+ workspace: {
6252
+ id: string;
6253
+ title: string;
6254
+ };
6255
+ } & Record<string, unknown>;
6256
+
6257
+ /**
6258
+ * Service for managing API keys
6259
+ *
6260
+ * Provides comprehensive API key management including:
6261
+ * - API key CRUD operations
6262
+ */
6263
+ declare class ApiKeyService {
6264
+ private client;
6265
+ /**
6266
+ * Creates a new ApiKeyService instance.
6267
+ *
6268
+ * @param client - The API client for making API key requests
6269
+ */
6270
+ constructor(client: APIClient);
6271
+ createApiKey(payload: CreateApiKeyPayload): Promise<{
6272
+ key: string;
6273
+ metadata: any;
6274
+ permissions: any;
6275
+ id: string;
6276
+ name: string | null;
6277
+ start: string | null;
6278
+ prefix: string | null;
6279
+ userId: string;
6280
+ refillInterval: number | null;
6281
+ refillAmount: number | null;
6282
+ lastRefillAt: Date | null;
6283
+ enabled: boolean;
6284
+ rateLimitEnabled: boolean;
6285
+ rateLimitTimeWindow: number | null;
6286
+ rateLimitMax: number | null;
6287
+ requestCount: number;
6288
+ remaining: number | null;
6289
+ lastRequest: Date | null;
6290
+ expiresAt: Date | null;
6291
+ createdAt: Date;
6292
+ updatedAt: Date;
6293
+ }>;
6294
+ getApiKey(id: string): Promise<{
6295
+ permissions: {
6296
+ [key: string]: string[];
6297
+ } | null;
6298
+ id: string;
6299
+ name: string | null;
6300
+ start: string | null;
6301
+ prefix: string | null;
6302
+ userId: string;
6303
+ refillInterval: number | null;
6304
+ refillAmount: number | null;
6305
+ lastRefillAt: Date | null;
6306
+ enabled: boolean;
6307
+ rateLimitEnabled: boolean;
6308
+ rateLimitTimeWindow: number | null;
6309
+ rateLimitMax: number | null;
6310
+ requestCount: number;
6311
+ remaining: number | null;
6312
+ lastRequest: Date | null;
6313
+ expiresAt: Date | null;
6314
+ createdAt: Date;
6315
+ updatedAt: Date;
6316
+ metadata: Record<string, any> | null;
6317
+ }>;
6318
+ listApiKeys(): Promise<{
6319
+ permissions: {
6320
+ [key: string]: string[];
6321
+ } | null;
6322
+ id: string;
6323
+ name: string | null;
6324
+ start: string | null;
6325
+ prefix: string | null;
6326
+ userId: string;
6327
+ refillInterval: number | null;
6328
+ refillAmount: number | null;
6329
+ lastRefillAt: Date | null;
6330
+ enabled: boolean;
6331
+ rateLimitEnabled: boolean;
6332
+ rateLimitTimeWindow: number | null;
6333
+ rateLimitMax: number | null;
6334
+ requestCount: number;
6335
+ remaining: number | null;
6336
+ lastRequest: Date | null;
6337
+ expiresAt: Date | null;
6338
+ createdAt: Date;
6339
+ updatedAt: Date;
6340
+ metadata: Record<string, any> | null;
6341
+ }[]>;
6342
+ updateApiKey(payload: UpdateApiKeyPayload): Promise<{
6343
+ permissions: {
6344
+ [key: string]: string[];
6345
+ } | null;
6346
+ id: string;
6347
+ name: string | null;
6348
+ start: string | null;
6349
+ prefix: string | null;
6350
+ userId: string;
6351
+ refillInterval: number | null;
6352
+ refillAmount: number | null;
6353
+ lastRefillAt: Date | null;
6354
+ enabled: boolean;
6355
+ rateLimitEnabled: boolean;
6356
+ rateLimitTimeWindow: number | null;
6357
+ rateLimitMax: number | null;
6358
+ requestCount: number;
6359
+ remaining: number | null;
6360
+ lastRequest: Date | null;
6361
+ expiresAt: Date | null;
6362
+ createdAt: Date;
6363
+ updatedAt: Date;
6364
+ metadata: Record<string, any> | null;
6365
+ }>;
6366
+ deleteApiKey(id: string): Promise<{
6367
+ success: boolean;
6368
+ }>;
6369
+ }
6370
+
6227
6371
  declare class BaseError extends Error {
6228
6372
  code: string;
6229
6373
  constructor(code: string, message: string, options?: ErrorOptions);
@@ -6281,6 +6425,10 @@ declare class AuthClient {
6281
6425
  * Organization management service for multi-tenant operations
6282
6426
  */
6283
6427
  organization: OrganizationService;
6428
+ /**
6429
+ * API key management service for API key operations
6430
+ */
6431
+ apiKey: ApiKeyService;
6284
6432
  /**
6285
6433
  * Creates a new AuthClient instance.
6286
6434
  *
@@ -6344,4 +6492,4 @@ declare function validateToken(token: string, apiUrl: string): Promise<boolean>;
6344
6492
  declare function extractTokenPayload(token: string): JWTTokenPayload;
6345
6493
 
6346
6494
  export { AuthClient, EmailRequired, InvalidCallbackURL, InvalidSocialProvider, Roles, ac, createAPIClient, extractTokenPayload, isTokenExpired, organizationAdditionalFields, rolesAccessControl, userAdditionalFields, validateToken };
6347
- export type { APIClient, CreateTeamPayload, FullOrganization, GetOrganizationOptions, Invitation, InviteUserToOrganizationOptions, JWTTokenPayload, ListMembersOptions, ExtendedMember as Member, ExtendedOrganization as Organization, RemoveUserFromOrganizationOptions, Role, Session, SignInWithEmailAndPasswordOptions, SignInWithSamlOptions, SocialSignInOptions, Team, TeamMember, UpdateMemberRoleOptions, UpdateOrganizationPayload, UpdateTeamPayload, User };
6495
+ export type { APIClient, ApiKeyMetadata, CreateApiKeyPayload, CreateTeamPayload, FullOrganization, GetOrganizationOptions, Invitation, InviteUserToOrganizationOptions, JWTTokenPayload, ListMembersOptions, ExtendedMember as Member, ExtendedOrganization as Organization, RemoveUserFromOrganizationOptions, Role, Session, SignInWithEmailAndPasswordOptions, SignInWithSamlOptions, SocialSignInOptions, Team, TeamMember, UpdateApiKeyPayload, UpdateMemberRoleOptions, UpdateOrganizationPayload, UpdateTeamPayload, User };
package/dist/index.mjs CHANGED
@@ -4,8 +4,9 @@ import { createAuthClient } from 'better-auth/client';
4
4
  import { organizationClient, twoFactorClient, jwtClient, apiKeyClient, adminClient, inferAdditionalFields } from 'better-auth/client/plugins';
5
5
  import { createAccessControl } from 'better-auth/plugins/access';
6
6
  import { defaultStatements } from 'better-auth/plugins/organization/access';
7
+ export { BetterFetchError as APIError } from '@better-fetch/fetch';
7
8
 
8
- const version = "1.2.1";
9
+ const version = "1.3.0";
9
10
 
10
11
  const statements = {
11
12
  ...defaultStatements,
@@ -99,7 +100,7 @@ function createAPIClient(apiUrl, fetchOptions = {}) {
99
100
  ...fetchOptions,
100
101
  credentials: "include",
101
102
  headers: {
102
- "User-Agent": userAgent,
103
+ "X-User-Agent": userAgent,
103
104
  ...fetchOptions.headers ?? {}
104
105
  },
105
106
  throw: true
@@ -339,6 +340,7 @@ class OrganizationService {
339
340
  *
340
341
  * @param teamId - The team ID
341
342
  * @param userId - The user ID to add
343
+ * @returns The added team member
342
344
  */
343
345
  async addTeamMember(teamId, userId) {
344
346
  return this.client.organization.addTeamMember({
@@ -556,6 +558,46 @@ class SessionService {
556
558
  }
557
559
  }
558
560
 
561
+ class ApiKeyService {
562
+ /**
563
+ * Creates a new ApiKeyService instance.
564
+ *
565
+ * @param client - The API client for making API key requests
566
+ */
567
+ constructor(client) {
568
+ this.client = client;
569
+ }
570
+ async createApiKey(payload) {
571
+ return this.client.apiKey.create({
572
+ name: payload.name,
573
+ expiresIn: payload.expiresIn,
574
+ prefix: payload.prefix,
575
+ metadata: payload.metadata
576
+ });
577
+ }
578
+ async getApiKey(id) {
579
+ return this.client.apiKey.get({
580
+ query: {
581
+ id
582
+ }
583
+ });
584
+ }
585
+ async listApiKeys() {
586
+ return this.client.apiKey.list();
587
+ }
588
+ async updateApiKey(payload) {
589
+ return this.client.apiKey.update({
590
+ keyId: payload.id,
591
+ name: payload.name
592
+ });
593
+ }
594
+ async deleteApiKey(id) {
595
+ return this.client.apiKey.delete({
596
+ keyId: id
597
+ });
598
+ }
599
+ }
600
+
559
601
  class AuthClient {
560
602
  client;
561
603
  /**
@@ -566,6 +608,10 @@ class AuthClient {
566
608
  * Organization management service for multi-tenant operations
567
609
  */
568
610
  organization;
611
+ /**
612
+ * API key management service for API key operations
613
+ */
614
+ apiKey;
569
615
  /**
570
616
  * Creates a new AuthClient instance.
571
617
  *
@@ -576,6 +622,7 @@ class AuthClient {
576
622
  this.client = createAPIClient(apiUrl, fetchOptions);
577
623
  this.session = new SessionService(this.client, apiUrl);
578
624
  this.organization = new OrganizationService(this.client);
625
+ this.apiKey = new ApiKeyService(this.client);
579
626
  }
580
627
  }
581
628
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/auth-core",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -29,4 +29,4 @@
29
29
  "typescript": "5.9.2",
30
30
  "unbuild": "3.6.1"
31
31
  }
32
- }
32
+ }