@adonis-agora/authkit-sdk 1.0.0-rc.2 → 1.0.0-rc.3
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 +35 -0
- package/README.md +2 -2
- package/build/src/embedded_driver.js +30 -31
- package/build/src/list_query.d.ts +11 -0
- package/build/src/list_query.js +72 -0
- package/build/src/remote_driver.js +7 -17
- package/build/src/types.d.ts +51 -65
- package/build/src/types.js +3 -9
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @adonis-agora/authkit-sdk
|
|
2
2
|
|
|
3
|
+
## 1.0.0-rc.3
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#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' } }`.
|
|
8
|
+
|
|
9
|
+
`@adonis-agora/authkit-server`:
|
|
10
|
+
|
|
11
|
+
- `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 }`).
|
|
12
|
+
- `GET {admin}/api/clients` and `GET /clients`: page with `?search&sort&page&size` (`sort`: `clientId`, `clientName`) → `{ data, meta, canList }`.
|
|
13
|
+
- `GET {admin}/api/orgs` and `GET /organizations`: page with `?search&sort&page&size` (`sort`: `name`, `slug`, `createdAt`, `memberCount`) → `{ data, meta }`.
|
|
14
|
+
- `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.
|
|
15
|
+
- `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`).
|
|
16
|
+
- `GET {admin}/api/personal-agents/connections`: `filter[protocol]`, `filter[clientId]`, `filter[accountId]` (were flat `?protocol=`…) → `{ data, meta }` with the offset meta above.
|
|
17
|
+
- `GET {admin}/api/overview`: `auditTotal` is `null` when the audit sink cannot count.
|
|
18
|
+
- `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.
|
|
19
|
+
- The `authkit_list_audit` dev tool takes `cursor` (the previous result's `next`) instead of `page`, and no longer returns `total`.
|
|
20
|
+
- The `authkit_get_overview` dev tool returns `auditTotal: null` when the audit sink cannot count.
|
|
21
|
+
- Removed exports: `ListMeta`, `PaginatedResponse`, `parseListPage`, `parseListSize`. New exports: `listAccountsPage`, `listAuditPage`, `listClientsPage`, `listOrgsPage`, the list filter classes and `CountAuditParams`.
|
|
22
|
+
- Depends on `@adonis-agora/filter`.
|
|
23
|
+
|
|
24
|
+
`@adonis-agora/authkit-react`:
|
|
25
|
+
|
|
26
|
+
- `client.admin.users.list({ search?, sort?, page?, size? })`, `clients.list(params?)`, `orgs.list(params?)` return `OffsetPage<T>` (`meta: { total, perPage, currentPage, lastPage, firstPage }`).
|
|
27
|
+
- `client.admin.sessions.list({ accountId?, search?, sort?, page?, size? })` (was `list(accountId?)`) returns `AdminSessionListResult` (`data` instead of `sessions`).
|
|
28
|
+
- `client.admin.audit.list({ type?, subject?, after?, before?, first?, last? })` returns `CursorPageResponse<AuditEventEntry>`; `page` / `size` are gone.
|
|
29
|
+
- `useSessionsQueryOptions(params?)`, `useClientsQueryOptions(params?)` and `useOrgsQueryOptions(params?)` take the list params; `authkitKeys.admin.sessions/clients/orgs` take them too.
|
|
30
|
+
- `ListMeta` is removed; `OffsetPage`, `OffsetPageMeta`, `CursorPageResponse`, `CursorPageMeta`, `AdminListParams`, `CursorListParams`, `AdminSessionListParams` and `AdminSessionListResult` are exported. `AdminOverview.auditTotal` is `number | null`.
|
|
31
|
+
|
|
32
|
+
`@adonis-agora/authkit-sdk`:
|
|
33
|
+
|
|
34
|
+
- `users.list`, `clients.list` and `organizations.list` take `{ search?, sort?, page?, size? }` and return `OffsetPage<T>` (`clients.list` adds `canList`).
|
|
35
|
+
- `audit.list({ type?, subject?, after?, before?, first?, last? })` returns `CursorPageResponse<AuthkitAuditEvent>`.
|
|
36
|
+
- `ListMeta` is removed; `OffsetPage`, `CursorPageResponse`, `OffsetListParams`, `CursorListParams`, `ListClientsParams` and `ListOrganizationsParams` are exported.
|
|
37
|
+
|
|
3
38
|
## 1.0.0-rc.2
|
|
4
39
|
|
|
5
40
|
### 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({
|
|
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 {
|
|
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
|
|
172
|
-
|
|
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
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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 =
|
|
341
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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${
|
|
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',
|
|
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${
|
|
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',
|
|
143
|
+
list(params = {}) {
|
|
144
|
+
return request('GET', `/organizations${offsetListQuery(params)}`);
|
|
155
145
|
},
|
|
156
146
|
create(input) {
|
|
157
147
|
return request('POST', '/organizations', input);
|
package/build/src/types.d.ts
CHANGED
|
@@ -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
|
-
|
|
11
|
-
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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;
|
|
@@ -135,8 +122,10 @@ export interface AuthkitClient {
|
|
|
135
122
|
capabilities: string[];
|
|
136
123
|
} | null;
|
|
137
124
|
}
|
|
138
|
-
|
|
139
|
-
|
|
125
|
+
/** `clients.list`: `search` matches the client id or name; `sort` is `clientId` or `clientName`. */
|
|
126
|
+
export type ListClientsParams = OffsetListParams;
|
|
127
|
+
/** A page of clients. `canList` is `false` when the adapter cannot enumerate clients. */
|
|
128
|
+
export interface ListClientsResult extends OffsetPage<AuthkitClient> {
|
|
140
129
|
canList: boolean;
|
|
141
130
|
}
|
|
142
131
|
export type TokenEndpointAuthMethod = 'client_secret_basic' | 'client_secret_post' | 'none';
|
|
@@ -180,22 +169,15 @@ export interface AuthkitAuditEvent {
|
|
|
180
169
|
metadata: Record<string, unknown> | null;
|
|
181
170
|
createdAt: string;
|
|
182
171
|
}
|
|
183
|
-
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
type?: string;
|
|
172
|
+
/** `audit.list`: newest first, by cursor. */
|
|
173
|
+
export interface ListAuditParams extends CursorListParams {
|
|
174
|
+
/** Only events of this type, or of any of these types. */
|
|
175
|
+
type?: string | string[];
|
|
176
|
+
/** Only events about this account id. */
|
|
189
177
|
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
178
|
}
|
|
179
|
+
/** A page of audit events, newest first. */
|
|
180
|
+
export type ListAuditResult = CursorPageResponse<AuthkitAuditEvent>;
|
|
199
181
|
/** A daily series point (ISO `YYYY-MM-DD` day + count). */
|
|
200
182
|
export interface AuthkitDailyPoint {
|
|
201
183
|
date: string;
|
|
@@ -290,9 +272,13 @@ export interface AuthkitOrgInvitation {
|
|
|
290
272
|
acceptedAt: string | null;
|
|
291
273
|
createdAt: string;
|
|
292
274
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
275
|
+
/**
|
|
276
|
+
* `organizations.list`: `search` matches the name or slug; `sort` is `name`, `slug`,
|
|
277
|
+
* `createdAt` or `memberCount`.
|
|
278
|
+
*/
|
|
279
|
+
export type ListOrganizationsParams = OffsetListParams;
|
|
280
|
+
/** A page of organizations, with their member counts. */
|
|
281
|
+
export type ListOrganizationsResult = OffsetPage<AuthkitOrganization>;
|
|
296
282
|
export interface CreateOrganizationInput {
|
|
297
283
|
name: string;
|
|
298
284
|
slug: string;
|
|
@@ -391,7 +377,7 @@ export interface Authkit {
|
|
|
391
377
|
revokeAll(userId: string): Promise<RevokeSessionsResult>;
|
|
392
378
|
};
|
|
393
379
|
clients: {
|
|
394
|
-
list(): Promise<ListClientsResult>;
|
|
380
|
+
list(params?: ListClientsParams): Promise<ListClientsResult>;
|
|
395
381
|
get(id: string): Promise<AuthkitClient>;
|
|
396
382
|
create(input: ClientInput): Promise<AuthkitCreatedClient>;
|
|
397
383
|
update(id: string, input: ClientInput): Promise<AuthkitClient>;
|
|
@@ -410,7 +396,7 @@ export interface Authkit {
|
|
|
410
396
|
verify(token: string): Promise<VerifyTokenResult>;
|
|
411
397
|
};
|
|
412
398
|
organizations: {
|
|
413
|
-
list(): Promise<ListOrganizationsResult>;
|
|
399
|
+
list(params?: ListOrganizationsParams): Promise<ListOrganizationsResult>;
|
|
414
400
|
create(input: CreateOrganizationInput): Promise<AuthkitOrganization>;
|
|
415
401
|
get(id: string): Promise<AuthkitOrganizationDetail>;
|
|
416
402
|
update(id: string, input: UpdateOrganizationInput): Promise<AuthkitOrganization>;
|
package/build/src/types.js
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
-
/**
|
|
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.
|
|
3
|
+
"version": "1.0.0-rc.3",
|
|
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.
|
|
54
|
+
"@adonis-agora/authkit-server": "1.0.0-rc.17",
|
|
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",
|