@adonis-agora/authkit-sdk 1.0.0-rc.2 → 1.0.0-rc.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,54 @@
1
1
  # @adonis-agora/authkit-sdk
2
2
 
3
+ ## 1.0.0-rc.4
4
+
5
+ ### Minor Changes
6
+
7
+ - [#495](https://github.com/DavideCarvalho/adonis-agora-authkit/pull/495) [`4830805`](https://github.com/DavideCarvalho/adonis-agora-authkit/commit/4830805039c3f0e978c403d3062275a892704eb7) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Separate servers: every piece of an Agora deployment can run without authkit-server in its process.
8
+
9
+ - `authkitTenantVerifier({ issuer, resource, environment? })` (authkit-client) verifies service-tenant tokens on any server against the issuer's discovered JWKS and returns `{ partition, environment?, capabilities, clientId, expiresAt }` or `null`. `authkitTenantToken` now takes the token endpoint only from discovery (no guessed path).
10
+ - Service tenants get an optional `environment` (console, Admin API, SDK, `--environment`), emitted as the `environment` claim. Both verifiers take `environment` and, when it is set, accept only tokens claiming exactly that environment (fail closed); authkit-server's in-process verifier also returns `environment`. One service-tenant client gets tokens for every `urn:agora:*` resource declared.
11
+ - `registerOidcClient` announces `POST /auth/logout` as `account.signOut` on the `agora.consoles` registry (skipped when authkit-server runs in the app), so every console shows a sign-out.
12
+ - `Identity.actor` (`{ sub, email? }`) from the RFC 8693 `act` claim of an impersonated token (`deriveActor` in authkit-core).
13
+ - Org labels: authkit-server serves `GET /api/orgs/labels?ids=` (first-party confidential clients, Basic auth) and emits `org_name` for the active org; authkit-client installs a cached `Context.setTenantLabeler` (`orgLabels` option, `authkitOrgLabels`).
14
+ - Webhooks: the body carries `id` and `actorId`, `events.webhook` accepts a list; authkit-client's `registerAuthkitWebhook` / `authkitWebhookHandler` verify the HMAC, the `ts` window and the id, and re-emit on the diagnostics bus as `agora:authkit:<type>` with the in-process payload.
15
+ - `identityFromAccessToken`, `bindAuthkitIdentity` and `bridgeAuthkitToken` put a verified authkit bearer token on `ctx.authkit`.
16
+
17
+ ## 1.0.0-rc.3
18
+
19
+ ### Major Changes
20
+
21
+ - [#484](https://github.com/DavideCarvalho/adonis-agora-authkit/pull/484) [`4a9eeb4`](https://github.com/DavideCarvalho/adonis-agora-authkit/commit/4a9eeb46782e78ad06ad0c2955e49398ab21bc7e) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Lists use the `@adonis-agora/filter` wire format: `filter[field]=…`, `search`, `sort=-field`, then `page`/`size` or a cursor. A filter field, operator or sort a list does not support answers `400 { error: { code: 'invalid_list_query' } }`.
22
+
23
+ `@adonis-agora/authkit-server`:
24
+
25
+ - `GET {admin}/api/users` and Admin API `GET /users`: `?search&sort&page&size` (`sort` accepts `email` only) → `{ data, meta: { total, perPage, currentPage, lastPage, firstPage } }` (was `meta: { page, size, total }`).
26
+ - `GET {admin}/api/clients` and `GET /clients`: page with `?search&sort&page&size` (`sort`: `clientId`, `clientName`) → `{ data, meta, canList }`.
27
+ - `GET {admin}/api/orgs` and `GET /organizations`: page with `?search&sort&page&size` (`sort`: `name`, `slug`, `createdAt`, `memberCount`) → `{ data, meta }`.
28
+ - `GET {admin}/api/audit` and `GET /audit`: newest first, by cursor. `?filter[type]` (one or more), `?filter[subject]`, `after` / `before` + `first` / `last` → `{ data, meta: { nextCursor, prevCursor, hasNext, hasPrev } }`. `?type`, `?subject`, `page` and `size` are gone.
29
+ - `GET {admin}/api/sessions`: `?filter[accountId]&search&sort&page&size` (`sort`: `loginTs`, `email`; default `-loginTs`) → `{ data, meta, supported, truncated, grants }` (was `{ supported, truncated, sessions, grants }` with `?accountId`).
30
+ - `GET {admin}/api/personal-agents/connections`: `filter[protocol]`, `filter[clientId]`, `filter[accountId]` (were flat `?protocol=`…) → `{ data, meta }` with the offset meta above.
31
+ - `GET {admin}/api/overview`: `auditTotal` is `null` when the audit sink cannot count.
32
+ - `AuditSink.list` pages by cursor: it takes `{ type?: string | string[], subject?, size?, after?, before? }` and returns `{ data, nextCursor, prevCursor, hasNext, hasPrev }` (newest first). New optional `AuditSink.count({ type?, subject? })`. `lucidAuditSink` implements both (keyset on `createdAt`, `id`). Custom sinks with `list` must follow the new shape.
33
+ - The `authkit_list_audit` dev tool takes `cursor` (the previous result's `next`) instead of `page`, and no longer returns `total`.
34
+ - The `authkit_get_overview` dev tool returns `auditTotal: null` when the audit sink cannot count.
35
+ - Removed exports: `ListMeta`, `PaginatedResponse`, `parseListPage`, `parseListSize`. New exports: `listAccountsPage`, `listAuditPage`, `listClientsPage`, `listOrgsPage`, the list filter classes and `CountAuditParams`.
36
+ - Depends on `@adonis-agora/filter`.
37
+
38
+ `@adonis-agora/authkit-react`:
39
+
40
+ - `client.admin.users.list({ search?, sort?, page?, size? })`, `clients.list(params?)`, `orgs.list(params?)` return `OffsetPage<T>` (`meta: { total, perPage, currentPage, lastPage, firstPage }`).
41
+ - `client.admin.sessions.list({ accountId?, search?, sort?, page?, size? })` (was `list(accountId?)`) returns `AdminSessionListResult` (`data` instead of `sessions`).
42
+ - `client.admin.audit.list({ type?, subject?, after?, before?, first?, last? })` returns `CursorPageResponse<AuditEventEntry>`; `page` / `size` are gone.
43
+ - `useSessionsQueryOptions(params?)`, `useClientsQueryOptions(params?)` and `useOrgsQueryOptions(params?)` take the list params; `authkitKeys.admin.sessions/clients/orgs` take them too.
44
+ - `ListMeta` is removed; `OffsetPage`, `OffsetPageMeta`, `CursorPageResponse`, `CursorPageMeta`, `AdminListParams`, `CursorListParams`, `AdminSessionListParams` and `AdminSessionListResult` are exported. `AdminOverview.auditTotal` is `number | null`.
45
+
46
+ `@adonis-agora/authkit-sdk`:
47
+
48
+ - `users.list`, `clients.list` and `organizations.list` take `{ search?, sort?, page?, size? }` and return `OffsetPage<T>` (`clients.list` adds `canList`).
49
+ - `audit.list({ type?, subject?, after?, before?, first?, last? })` returns `CursorPageResponse<AuthkitAuditEvent>`.
50
+ - `ListMeta` is removed; `OffsetPage`, `CursorPageResponse`, `OffsetListParams`, `CursorListParams`, `ListClientsParams` and `ListOrganizationsParams` are exported.
51
+
3
52
  ## 1.0.0-rc.2
4
53
 
5
54
  ### Patch Changes
package/README.md CHANGED
@@ -51,7 +51,7 @@ const authkit = await createAuthkit({ mode: 'embedded', app })
51
51
 
52
52
  ```ts
53
53
  // Users
54
- await authkit.users.list({ search: 'jane' })
54
+ await authkit.users.list({ search: 'jane', page: 1, size: 20 }) // { data, meta }
55
55
  const user = await authkit.users.create({ email: 'jane@acme.dev' })
56
56
  await authkit.users.delete(user.id) // cascades sessions, grants, tokens (LGPD/GDPR)
57
57
 
@@ -68,7 +68,7 @@ await authkit.organizations.create({ name: 'Acme' })
68
68
  await authkit.organizations.members.add(orgId, { accountId, role: 'admin' })
69
69
 
70
70
  // Audit log, stats, settings, signing keys
71
- await authkit.audit.list({ action: 'user.login' })
71
+ await authkit.audit.list({ type: 'login.success', first: 50 }) // { data, meta: { nextCursor, … } }
72
72
  await authkit.stats()
73
73
  await authkit.settings.set('branding.name', 'Acme')
74
74
  await authkit.keys.rotate({ retire: false })
@@ -1,4 +1,16 @@
1
- import { ADMIN_LIST_DEFAULT_SIZE, ADMIN_LIST_MAX_SIZE, LIST_FIRST_PAGE } from './types.js';
1
+ import { auditListObject, offsetListObject } from './list_query.js';
2
+ /**
3
+ * Where the server keeps `auth_settings`: `schema.connection` and `schema.name` of its resolved
4
+ * config (the same rule the server applies), in `RuntimeSettings` options.
5
+ */
6
+ function tablesLocation(cfg) {
7
+ const out = {};
8
+ if (cfg?.schema?.connection)
9
+ out.connection = cfg.schema.connection;
10
+ if (cfg?.schema?.name)
11
+ out.schema = cfg.schema.name;
12
+ return out;
13
+ }
2
14
  /** Audit actor used for SDK-originated writes — mirrors the REST `admin-api` source. */
3
15
  const ACTOR = { actorId: null, ip: null, source: 'admin-api' };
4
16
  /**
@@ -58,7 +70,7 @@ export async function createEmbeddedAuthkit(opts) {
58
70
  const { app } = opts;
59
71
  // Lazy import: only remote-mode consumers may not have the server installed.
60
72
  const server = await import('@adonis-agora/authkit-server');
61
- const { AdminUsersService, AdminClientsService, AdminSessionsService, AdminOrgsService, TokenVerifyService, enrichSessionsWithContext, computeAdminStats, buildKeysStatus, rotateNow, } = server;
73
+ const { AdminUsersService, AdminClientsService, AdminSessionsService, AdminOrgsService, TokenVerifyService, enrichSessionsWithContext, computeAdminStats, buildKeysStatus, rotateNow, listAccountsPage, listAuditPage, listClientsPage, listOrgsPage, } = server;
62
74
  const service = await app.container.make('authkit.server');
63
75
  const cfg = service.config;
64
76
  const ctx = fakeCtx(app);
@@ -168,12 +180,8 @@ export async function createEmbeddedAuthkit(opts) {
168
180
  return {
169
181
  users: {
170
182
  async list(params = {}) {
171
- const search = (params.search ?? '').trim();
172
- const page = Math.max(LIST_FIRST_PAGE, params.page ?? LIST_FIRST_PAGE);
173
- const size = Math.max(1, Math.min(ADMIN_LIST_MAX_SIZE, params.size ?? ADMIN_LIST_DEFAULT_SIZE));
174
- const result = await cfg.accountStore.listAccounts({ search, page, size });
175
- const data = await Promise.all(result.data.map((u) => userDto(u)));
176
- return { meta: { page, size, total: result.total }, data };
183
+ const page = await listAccountsPage(cfg.accountStore, offsetListObject(params));
184
+ return { ...page, data: await Promise.all(page.data.map((u) => userDto(u))) };
177
185
  },
178
186
  async get(id) {
179
187
  const account = await cfg.accountStore.findById(id);
@@ -263,12 +271,11 @@ export async function createEmbeddedAuthkit(opts) {
263
271
  },
264
272
  },
265
273
  clients: {
266
- async list() {
274
+ async list(params = {}) {
267
275
  const svc = new AdminClientsService(service);
268
- if (!svc.canList)
269
- return { data: [], canList: false };
270
- const clients = await svc.list();
271
- return { data: clients.map(clientDto), canList: true };
276
+ const rows = svc.canList ? await svc.list() : [];
277
+ const page = await listClientsPage(rows, offsetListObject(params));
278
+ return { ...page, data: page.data.map(clientDto), canList: svc.canList };
272
279
  },
273
280
  async get(id) {
274
281
  const client = await new AdminClientsService(service).find(id);
@@ -337,12 +344,8 @@ export async function createEmbeddedAuthkit(opts) {
337
344
  if (!sink || typeof sink.list !== 'function') {
338
345
  throw new Error('O sink de auditoria configurado não suporta consulta.');
339
346
  }
340
- const page = Math.max(LIST_FIRST_PAGE, params.page ?? LIST_FIRST_PAGE);
341
- const size = Math.max(1, Math.min(ADMIN_LIST_MAX_SIZE, params.size ?? ADMIN_LIST_DEFAULT_SIZE));
342
- const type = params.type?.trim() || undefined;
343
- const subject = params.subject?.trim() || undefined;
344
- const result = await sink.list({ page, size, type, subject });
345
- return { meta: { page, size, total: result.total }, data: result.data.map(auditDto) };
347
+ const page = await listAuditPage(sink, auditListObject(params));
348
+ return { ...page, data: page.data.map(auditDto) };
346
349
  },
347
350
  },
348
351
  async stats() {
@@ -392,11 +395,12 @@ export async function createEmbeddedAuthkit(opts) {
392
395
  };
393
396
  }
394
397
  return {
395
- async list() {
398
+ async list(params = {}) {
396
399
  const result = await orgsService.listOrgs();
397
400
  if (!Array.isArray(result))
398
401
  throw new Error('Organizations não é suportado nesta instalação.');
399
- return { data: result.map(orgDto) };
402
+ const page = await listOrgsPage(result, offsetListObject(params));
403
+ return { ...page, data: page.data.map(orgDto) };
400
404
  },
401
405
  async create(input) {
402
406
  const result = await orgsService.createOrg(input, ACTOR);
@@ -494,8 +498,7 @@ export async function createEmbeddedAuthkit(opts) {
494
498
  catch {
495
499
  return { data: [] };
496
500
  }
497
- const connection = cfg.schema?.connection;
498
- const svc = new RuntimeSettings(db, connection ? { connection } : {});
501
+ const svc = new RuntimeSettings(db, tablesLocation(cfg));
499
502
  const rows = await svc.listSettings();
500
503
  return {
501
504
  data: rows.map((r) => ({
@@ -515,8 +518,7 @@ export async function createEmbeddedAuthkit(opts) {
515
518
  catch {
516
519
  throw new Error('Runtime settings not available.');
517
520
  }
518
- const connection = cfg.schema?.connection;
519
- const svc = new RuntimeSettings(db, connection ? { connection } : {});
521
+ const svc = new RuntimeSettings(db, tablesLocation(cfg));
520
522
  const value = await svc.getSetting(key);
521
523
  if (value === null)
522
524
  throw new Error(`Setting '${key}' not found.`);
@@ -531,8 +533,7 @@ export async function createEmbeddedAuthkit(opts) {
531
533
  catch {
532
534
  throw new Error('Runtime settings not available.');
533
535
  }
534
- const connection = cfg.schema?.connection;
535
- const svc = new RuntimeSettings(db, connection ? { connection } : {});
536
+ const svc = new RuntimeSettings(db, tablesLocation(cfg));
536
537
  await svc.setSetting(key, value, null);
537
538
  const saved = await svc.getSetting(key);
538
539
  await cfg.audit?.record({
@@ -552,8 +553,7 @@ export async function createEmbeddedAuthkit(opts) {
552
553
  catch {
553
554
  throw new Error('Runtime settings not available.');
554
555
  }
555
- const connection = cfg.schema?.connection;
556
- const svc = new RuntimeSettings(db, connection ? { connection } : {});
556
+ const svc = new RuntimeSettings(db, tablesLocation(cfg));
557
557
  await svc.deleteSetting(key);
558
558
  await cfg.audit?.record({
559
559
  type: 'settings.updated',
@@ -571,8 +571,7 @@ export async function createEmbeddedAuthkit(opts) {
571
571
  let settingsSvc = null;
572
572
  try {
573
573
  const db = await app.container.make('lucid.db');
574
- const connection = cfg.schema?.connection;
575
- settingsSvc = new RuntimeSettings(db, connection ? { connection } : {});
574
+ settingsSvc = new RuntimeSettings(db, tablesLocation(cfg));
576
575
  }
577
576
  catch {
578
577
  // RuntimeSettings unavailable — buildKeysStatus will fall back to defaults.
@@ -0,0 +1,11 @@
1
+ import type { ListAuditParams, OffsetListParams } from './types.js';
2
+ /**
3
+ * The query string of an offset list (`search`, `sort`, `page`, `size`), in the
4
+ * `@adonis-agora/filter` wire format.
5
+ */
6
+ export declare function offsetListQuery(params?: OffsetListParams): string;
7
+ /** The query string of `audit.list`: `filter[type]`, `filter[subject]` and the cursor params. */
8
+ export declare function auditListQuery(params?: ListAuditParams): string;
9
+ /** The same lists as decoded query objects, for the embedded driver. */
10
+ export declare function offsetListObject(params?: OffsetListParams): Record<string, unknown>;
11
+ export declare function auditListObject(params?: ListAuditParams): Record<string, unknown>;
@@ -0,0 +1,72 @@
1
+ import { filterQuery } from '@adonis-agora/filter-client';
2
+ /** The `sort` string as builder calls: `'-createdAt,name'` → desc createdAt, asc name. */
3
+ function sortItems(sort) {
4
+ return (sort ?? '')
5
+ .split(',')
6
+ .map((s) => s.trim())
7
+ .filter(Boolean)
8
+ .map((s) => s.startsWith('-') ? { field: s.slice(1), desc: true } : { field: s, desc: false });
9
+ }
10
+ /**
11
+ * The query string of an offset list (`search`, `sort`, `page`, `size`), in the
12
+ * `@adonis-agora/filter` wire format.
13
+ */
14
+ export function offsetListQuery(params = {}) {
15
+ const q = filterQuery();
16
+ if (params.search)
17
+ q.search(params.search);
18
+ for (const { field, desc } of sortItems(params.sort))
19
+ q.sort(field, desc ? 'desc' : 'asc');
20
+ if (params.page !== undefined || params.size !== undefined) {
21
+ q.page(params.page ?? 1, params.size ?? 20);
22
+ }
23
+ const qs = q.toQueryString();
24
+ return qs ? `?${qs}` : '';
25
+ }
26
+ function applyCursor(q, params) {
27
+ if (params.after)
28
+ q.after(params.after);
29
+ else if (params.before)
30
+ q.before(params.before);
31
+ if (params.first !== undefined)
32
+ q.first(params.first);
33
+ if (params.last !== undefined)
34
+ q.last(params.last);
35
+ }
36
+ /** The query string of `audit.list`: `filter[type]`, `filter[subject]` and the cursor params. */
37
+ export function auditListQuery(params = {}) {
38
+ const q = filterQuery();
39
+ const types = params.type === undefined ? [] : [].concat(params.type);
40
+ if (types.length === 1)
41
+ q.equals('type', types[0]);
42
+ else if (types.length > 1)
43
+ q.in('type', types);
44
+ if (params.subject)
45
+ q.equals('subject', params.subject);
46
+ applyCursor(q, params);
47
+ const qs = q.toQueryString();
48
+ return qs ? `?${qs}` : '';
49
+ }
50
+ /** The same lists as decoded query objects, for the embedded driver. */
51
+ export function offsetListObject(params = {}) {
52
+ return {
53
+ ...(params.search !== undefined && { search: params.search }),
54
+ ...(params.sort !== undefined && { sort: params.sort }),
55
+ ...(params.page !== undefined && { page: params.page }),
56
+ ...(params.size !== undefined && { size: params.size }),
57
+ };
58
+ }
59
+ export function auditListObject(params = {}) {
60
+ const filter = {};
61
+ if (params.type !== undefined)
62
+ filter.type = params.type;
63
+ if (params.subject !== undefined)
64
+ filter.subject = params.subject;
65
+ return {
66
+ ...(Object.keys(filter).length > 0 && { filter }),
67
+ ...(params.after !== undefined && { after: params.after }),
68
+ ...(params.before !== undefined && { before: params.before }),
69
+ ...(params.first !== undefined && { first: params.first }),
70
+ ...(params.last !== undefined && { last: params.last }),
71
+ };
72
+ }
@@ -1,15 +1,5 @@
1
1
  import { AuthkitApiError } from './errors.js';
2
- /** Drops `undefined` query params and stringifies the rest. */
3
- function buildQuery(params) {
4
- const search = new URLSearchParams();
5
- for (const [key, value] of Object.entries(params)) {
6
- if (value === undefined || value === null)
7
- continue;
8
- search.set(key, String(value));
9
- }
10
- const qs = search.toString();
11
- return qs ? `?${qs}` : '';
12
- }
2
+ import { auditListQuery, offsetListQuery } from './list_query.js';
13
3
  /**
14
4
  * Remote driver: a thin typed fetch wrapper over the Admin REST API
15
5
  * (`/api/authkit/v1/*`). Paths match the server route list EXACTLY. Non-2xx
@@ -64,7 +54,7 @@ export function createRemoteAuthkit(opts) {
64
54
  return {
65
55
  users: {
66
56
  list(params = {}) {
67
- return request('GET', `/users${buildQuery({ ...params })}`);
57
+ return request('GET', `/users${offsetListQuery(params)}`);
68
58
  },
69
59
  get(id) {
70
60
  return request('GET', `/users/${encodeURIComponent(id)}`);
@@ -97,8 +87,8 @@ export function createRemoteAuthkit(opts) {
97
87
  },
98
88
  },
99
89
  clients: {
100
- list() {
101
- return request('GET', '/clients');
90
+ list(params = {}) {
91
+ return request('GET', `/clients${offsetListQuery(params)}`);
102
92
  },
103
93
  get(id) {
104
94
  return request('GET', `/clients/${encodeURIComponent(id)}`);
@@ -124,7 +114,7 @@ export function createRemoteAuthkit(opts) {
124
114
  },
125
115
  audit: {
126
116
  list(params = {}) {
127
- return request('GET', `/audit${buildQuery({ ...params })}`);
117
+ return request('GET', `/audit${auditListQuery(params)}`);
128
118
  },
129
119
  },
130
120
  stats() {
@@ -150,8 +140,8 @@ export function createRemoteAuthkit(opts) {
150
140
  },
151
141
  },
152
142
  organizations: {
153
- list() {
154
- return request('GET', '/organizations');
143
+ list(params = {}) {
144
+ return request('GET', `/organizations${offsetListQuery(params)}`);
155
145
  },
156
146
  create(input) {
157
147
  return request('POST', '/organizations', input);
@@ -6,18 +6,36 @@
6
6
  * kit. The embedded driver maps the server's runtime values into these exact
7
7
  * shapes — keep them in sync with the server DTOs.
8
8
  */
9
- /**
10
- * Shared offset-pagination constants for the Authkit SDK listings. They mirror
11
- * the `@adonis-agora/authkit-server` values of the same name (and, structurally,
12
- * `@adonis-agora/filter`'s `{ page, size }` contract) — declared locally so the
13
- * SDK keeps working against any supported server version.
14
- */
15
- /** First page — pagination is 1-based. */
9
+ import type { CursorPageResponse, OffsetPage } from '@adonis-agora/filter-client';
10
+ export type { CursorPageMeta, CursorPageResponse, OffsetPage, OffsetPageMeta, } from '@adonis-agora/filter-client';
11
+ /** First page — offset pagination is 1-based. */
16
12
  export declare const LIST_FIRST_PAGE = 1;
17
- /** Default page size when a listing call omits `size`. */
13
+ /** Page size the server uses when a listing call omits `size` (or `first`/`last`). */
18
14
  export declare const ADMIN_LIST_DEFAULT_SIZE = 20;
19
- /** Hard cap applied to a caller-supplied `size`. */
15
+ /** Largest page size the server accepts; bigger values are clamped. */
20
16
  export declare const ADMIN_LIST_MAX_SIZE = 200;
17
+ /** Offset paging and sort shared by `users.list`, `clients.list` and `organizations.list`. */
18
+ export interface OffsetListParams {
19
+ /** Free-text search (what it matches depends on the list). */
20
+ search?: string;
21
+ /** Sort, `-field` for descending: `'-createdAt'`, `'name,slug'`. */
22
+ sort?: string;
23
+ /** 1-based page. Default 1. */
24
+ page?: number;
25
+ /** Page size. Default 20, at most 200. */
26
+ size?: number;
27
+ }
28
+ /** Cursor paging of the audit log (newest first). */
29
+ export interface CursorListParams {
30
+ /** The `meta.nextCursor` of a page: returns the next (older) page. */
31
+ after?: string;
32
+ /** The `meta.prevCursor` of a page: returns the previous (newer) page. */
33
+ before?: string;
34
+ /** Page size when paging forward. Default 20, at most 200. */
35
+ first?: number;
36
+ /** Page size when paging backward. Default 20, at most 200. */
37
+ last?: number;
38
+ }
21
39
  /** A user/account as projected by the Admin API (`userDto`). */
22
40
  export interface AuthkitUser {
23
41
  id: string;
@@ -31,41 +49,10 @@ export interface AuthkitUser {
31
49
  export interface AuthkitCreatedUser extends AuthkitUser {
32
50
  invited: boolean;
33
51
  }
34
- /**
35
- * Offset pagination for `users.list`.
36
- *
37
- * `{ page, size }` intentionally mirrors `@adonis-agora/filter`'s
38
- * `FilterInput.page`/`.size` so every `@adonis-agora/*` package exposes the same
39
- * pagination interface. The match is STRUCTURAL on purpose — there is no
40
- * dependency on `@adonis-agora/filter` here.
41
- */
42
- export interface ListUsersParams {
43
- search?: string;
44
- /** 1-based page number. Default: 1. */
45
- page?: number;
46
- /** Page size. Default: 20; capped at {@link ADMIN_LIST_MAX_SIZE}. */
47
- size?: number;
48
- }
49
- /**
50
- * Pagination envelope of every paginated authkit listing.
51
- *
52
- * The `meta` key (and keeping `{ page, size }` inside it) is Lucid's own
53
- * `.paginate()` convention — `{ meta, data }` — which is where
54
- * `@adonis-agora/filter`'s offset path lands, and therefore the envelope every
55
- * `@adonis-agora/*` package answers with.
56
- */
57
- export interface ListMeta {
58
- /** 1-based page returned. */
59
- page: number;
60
- /** Page size actually applied (already normalized/capped). */
61
- size: number;
62
- /** Absolute number of matching items across all pages. */
63
- total: number;
64
- }
65
- export interface ListUsersResult {
66
- meta: ListMeta;
67
- data: AuthkitUser[];
68
- }
52
+ /** `users.list`: `search` matches the email; the list is sorted by email (`sort: 'email'`). */
53
+ export type ListUsersParams = OffsetListParams;
54
+ /** A page of users. */
55
+ export type ListUsersResult = OffsetPage<AuthkitUser>;
69
56
  export interface CreateUserInput {
70
57
  email: string;
71
58
  name?: string | null;
@@ -133,10 +120,13 @@ export interface AuthkitClient {
133
120
  serviceTenant: {
134
121
  partition: string;
135
122
  capabilities: string[];
123
+ environment?: string;
136
124
  } | null;
137
125
  }
138
- export interface ListClientsResult {
139
- data: AuthkitClient[];
126
+ /** `clients.list`: `search` matches the client id or name; `sort` is `clientId` or `clientName`. */
127
+ export type ListClientsParams = OffsetListParams;
128
+ /** A page of clients. `canList` is `false` when the adapter cannot enumerate clients. */
129
+ export interface ListClientsResult extends OffsetPage<AuthkitClient> {
140
130
  canList: boolean;
141
131
  }
142
132
  export type TokenEndpointAuthMethod = 'client_secret_basic' | 'client_secret_post' | 'none';
@@ -153,6 +143,7 @@ export interface ClientInput {
153
143
  serviceTenant?: {
154
144
  partition: string;
155
145
  capabilities?: string[];
146
+ environment?: string | null;
156
147
  } | null;
157
148
  }
158
149
  /** Created/regenerated client — the secret is shown ONCE (`createdClientDto`). */
@@ -180,22 +171,15 @@ export interface AuthkitAuditEvent {
180
171
  metadata: Record<string, unknown> | null;
181
172
  createdAt: string;
182
173
  }
183
- /**
184
- * Offset pagination for `audit.list` — same `{ page, size }` shape as
185
- * {@link ListUsersParams} and `@adonis-agora/filter`.
186
- */
187
- export interface ListAuditParams {
188
- type?: string;
174
+ /** `audit.list`: newest first, by cursor. */
175
+ export interface ListAuditParams extends CursorListParams {
176
+ /** Only events of this type, or of any of these types. */
177
+ type?: string | string[];
178
+ /** Only events about this account id. */
189
179
  subject?: string;
190
- /** 1-based page number. Default: 1. */
191
- page?: number;
192
- /** Page size. Default: 20; capped at {@link ADMIN_LIST_MAX_SIZE}. */
193
- size?: number;
194
- }
195
- export interface ListAuditResult {
196
- meta: ListMeta;
197
- data: AuthkitAuditEvent[];
198
180
  }
181
+ /** A page of audit events, newest first. */
182
+ export type ListAuditResult = CursorPageResponse<AuthkitAuditEvent>;
199
183
  /** A daily series point (ISO `YYYY-MM-DD` day + count). */
200
184
  export interface AuthkitDailyPoint {
201
185
  date: string;
@@ -290,9 +274,13 @@ export interface AuthkitOrgInvitation {
290
274
  acceptedAt: string | null;
291
275
  createdAt: string;
292
276
  }
293
- export interface ListOrganizationsResult {
294
- data: AuthkitOrganization[];
295
- }
277
+ /**
278
+ * `organizations.list`: `search` matches the name or slug; `sort` is `name`, `slug`,
279
+ * `createdAt` or `memberCount`.
280
+ */
281
+ export type ListOrganizationsParams = OffsetListParams;
282
+ /** A page of organizations, with their member counts. */
283
+ export type ListOrganizationsResult = OffsetPage<AuthkitOrganization>;
296
284
  export interface CreateOrganizationInput {
297
285
  name: string;
298
286
  slug: string;
@@ -391,7 +379,7 @@ export interface Authkit {
391
379
  revokeAll(userId: string): Promise<RevokeSessionsResult>;
392
380
  };
393
381
  clients: {
394
- list(): Promise<ListClientsResult>;
382
+ list(params?: ListClientsParams): Promise<ListClientsResult>;
395
383
  get(id: string): Promise<AuthkitClient>;
396
384
  create(input: ClientInput): Promise<AuthkitCreatedClient>;
397
385
  update(id: string, input: ClientInput): Promise<AuthkitClient>;
@@ -410,7 +398,7 @@ export interface Authkit {
410
398
  verify(token: string): Promise<VerifyTokenResult>;
411
399
  };
412
400
  organizations: {
413
- list(): Promise<ListOrganizationsResult>;
401
+ list(params?: ListOrganizationsParams): Promise<ListOrganizationsResult>;
414
402
  create(input: CreateOrganizationInput): Promise<AuthkitOrganization>;
415
403
  get(id: string): Promise<AuthkitOrganizationDetail>;
416
404
  update(id: string, input: UpdateOrganizationInput): Promise<AuthkitOrganization>;
@@ -6,15 +6,9 @@
6
6
  * kit. The embedded driver maps the server's runtime values into these exact
7
7
  * shapes — keep them in sync with the server DTOs.
8
8
  */
9
- /**
10
- * Shared offset-pagination constants for the Authkit SDK listings. They mirror
11
- * the `@adonis-agora/authkit-server` values of the same name (and, structurally,
12
- * `@adonis-agora/filter`'s `{ page, size }` contract) — declared locally so the
13
- * SDK keeps working against any supported server version.
14
- */
15
- /** First page — pagination is 1-based. */
9
+ /** First page — offset pagination is 1-based. */
16
10
  export const LIST_FIRST_PAGE = 1;
17
- /** Default page size when a listing call omits `size`. */
11
+ /** Page size the server uses when a listing call omits `size` (or `first`/`last`). */
18
12
  export const ADMIN_LIST_DEFAULT_SIZE = 20;
19
- /** Hard cap applied to a caller-supplied `size`. */
13
+ /** Largest page size the server accepts; bigger values are clamped. */
20
14
  export const ADMIN_LIST_MAX_SIZE = 200;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonis-agora/authkit-sdk",
3
- "version": "1.0.0-rc.2",
3
+ "version": "1.0.0-rc.4",
4
4
  "description": "Backend SDK for the AuthKit Admin API with one typed interface and two drivers: remote (HTTP/Bearer) and embedded (in-process when the IdP runs in the same AdonisJS app).",
5
5
  "license": "MIT",
6
6
  "author": "dudousxd",
@@ -51,7 +51,7 @@
51
51
  }
52
52
  },
53
53
  "devDependencies": {
54
- "@adonis-agora/authkit-server": "1.0.0-rc.11",
54
+ "@adonis-agora/authkit-server": "1.0.0-rc.24",
55
55
  "@adonisjs/core": "7.6.0",
56
56
  "@adonisjs/tsconfig": "2.0.0",
57
57
  "@japa/assert": "4.2.0",
@@ -60,6 +60,9 @@
60
60
  "@types/node": "26.6.6",
61
61
  "typescript": "7.0.2"
62
62
  },
63
+ "dependencies": {
64
+ "@adonis-agora/filter-client": "^1.0.0-rc.1"
65
+ },
63
66
  "scripts": {
64
67
  "build": "tsc",
65
68
  "typecheck": "tsc --noEmit && tsc -p tsconfig.tests.json",