@meistrari/auth-core 1.21.0 → 1.23.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.mjs CHANGED
@@ -8,7 +8,7 @@ import { defaultStatements } from 'better-auth/plugins/organization/access';
8
8
  import z, { z as z$1 } from 'zod';
9
9
  export { APIError } from 'better-auth';
10
10
 
11
- const version = "1.21.0";
11
+ const version = "1.23.0";
12
12
 
13
13
  function parsedEnumValues(schema) {
14
14
  return Object.fromEntries(
@@ -384,6 +384,127 @@ function createAPIClient(apiUrl, fetchOptions = {}) {
384
384
  });
385
385
  }
386
386
 
387
+ class AdminService {
388
+ /**
389
+ * Creates a new AdminService instance.
390
+ *
391
+ * @param client - The API client for making admin requests
392
+ */
393
+ constructor(client) {
394
+ this.client = client;
395
+ }
396
+ /**
397
+ * Lists all organizations, optionally with member and application previews
398
+ * and totals when a preview size is requested.
399
+ *
400
+ * @param options - Pagination, ordering, search, and preview options
401
+ * @returns The paginated organization listing
402
+ */
403
+ async listOrganizations(options = {}) {
404
+ return await this.client.$fetch("/admin/organizations", {
405
+ method: "GET",
406
+ query: {
407
+ ...options.limit !== void 0 ? { limit: options.limit } : {},
408
+ ...options.offset !== void 0 ? { offset: options.offset } : {},
409
+ ...options.sortBy ? { sortBy: options.sortBy } : {},
410
+ ...options.sortDirection ? { sortDirection: options.sortDirection } : {},
411
+ ...options.query ? { query: options.query } : {},
412
+ ...options.membersPreview !== void 0 ? { members_preview: options.membersPreview } : {},
413
+ ...options.applicationsPreview !== void 0 ? { applications_preview: options.applicationsPreview } : {}
414
+ }
415
+ });
416
+ }
417
+ /**
418
+ * Lists all Better Auth users from the user table.
419
+ *
420
+ * @param options - Pagination, search, filter, and ordering options
421
+ * @returns The paginated user listing
422
+ */
423
+ async listUsers(options = {}) {
424
+ return await this.client.$fetch("/admin/list-users", {
425
+ method: "GET",
426
+ query: {
427
+ ...options.limit !== void 0 ? { limit: options.limit } : {},
428
+ ...options.offset !== void 0 ? { offset: options.offset } : {},
429
+ ...options.searchValue ? { searchValue: options.searchValue } : {},
430
+ ...options.searchField ? { searchField: options.searchField } : {},
431
+ ...options.searchOperator ? { searchOperator: options.searchOperator } : {},
432
+ ...options.sortBy ? { sortBy: options.sortBy } : {},
433
+ ...options.sortDirection ? { sortDirection: options.sortDirection } : {},
434
+ ...options.filterField ? { filterField: options.filterField } : {},
435
+ ...options.filterValue !== void 0 ? { filterValue: options.filterValue } : {},
436
+ ...options.filterOperator ? { filterOperator: options.filterOperator } : {}
437
+ }
438
+ });
439
+ }
440
+ /**
441
+ * Fetches a single organization, optionally with adjacent IDs in
442
+ * the listing defined by the ordering options.
443
+ *
444
+ * @param options - Organization ID and listing adjacency options
445
+ * @returns The organization
446
+ */
447
+ async getOrganization(options) {
448
+ const { data } = await this.client.$fetch(`/admin/organizations/${encodeURIComponent(options.organizationId)}`, {
449
+ method: "GET",
450
+ query: {
451
+ ...options.sortBy ? { sortBy: options.sortBy } : {},
452
+ ...options.sortDirection ? { sortDirection: options.sortDirection } : {},
453
+ ...options.includeAdjacent ? { includeAdjacent: true } : {}
454
+ }
455
+ });
456
+ return data;
457
+ }
458
+ /**
459
+ * Lists active members for one organization as a global admin.
460
+ *
461
+ * @param options - Organization ID and pagination options
462
+ * @returns The paginated organization member listing
463
+ */
464
+ async listOrganizationMembers(options) {
465
+ return await this.client.$fetch(`/admin/organizations/${encodeURIComponent(options.organizationId)}/members`, {
466
+ method: "GET",
467
+ query: {
468
+ ...options.limit !== void 0 ? { limit: options.limit } : {},
469
+ ...options.offset !== void 0 ? { offset: options.offset } : {}
470
+ }
471
+ });
472
+ }
473
+ /**
474
+ * Creates an organization without adding the creator as a member.
475
+ *
476
+ * @param options - Organization name and optional slug, logo, metadata, and settings
477
+ * @returns The created organization
478
+ */
479
+ async createOrganization(options) {
480
+ const { data } = await this.client.$fetch("/admin/organizations", {
481
+ method: "POST",
482
+ body: options
483
+ });
484
+ return data;
485
+ }
486
+ /**
487
+ * Updates an organization's profile and settings.
488
+ *
489
+ * @param options - Organization ID and the fields to update
490
+ * @returns The updated organization
491
+ */
492
+ async updateOrganization(options) {
493
+ const { data } = await this.client.$fetch("/admin/organizations/update", {
494
+ method: "POST",
495
+ body: options
496
+ });
497
+ return data;
498
+ }
499
+ /**
500
+ * Bans a user from the auth system and invalidates all their sessions.
501
+ * @param userId - The ID of the user to ban
502
+ */
503
+ async banUser(userId) {
504
+ await this.client.$fetch("/admin/ban-user", { method: "POST", body: { userId } });
505
+ }
506
+ }
507
+
387
508
  class BaseError extends Error {
388
509
  /** Machine-readable error code (e.g. `"INVALID_SOCIAL_PROVIDER"`). */
389
510
  code;
@@ -1553,6 +1674,10 @@ class AuthClient {
1553
1674
  * Session assurance service for step-up operations
1554
1675
  */
1555
1676
  sessionAssurance;
1677
+ /**
1678
+ * Admin service for global admin operations
1679
+ */
1680
+ admin;
1556
1681
  /**
1557
1682
  * Creates a new AuthClient instance.
1558
1683
  *
@@ -1567,6 +1692,7 @@ class AuthClient {
1567
1692
  this.apiKey = new ApiKeyService(this.client);
1568
1693
  this.emailOtp = new EmailOTPService(this.client);
1569
1694
  this.sessionAssurance = new SessionAssuranceService(this.client);
1695
+ this.admin = new AdminService(this.client);
1570
1696
  }
1571
1697
  }
1572
1698
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/auth-core",
3
- "version": "1.21.0",
3
+ "version": "1.23.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {