@adonis-agora/authkit-server 0.85.0 → 0.85.1

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.
@@ -74,7 +74,7 @@ export default class ConsoleUsersController {
74
74
  roles: string[];
75
75
  invited: boolean;
76
76
  }>;
77
- /** PATCH {prefix}/api/users/:id/roles */
77
+ /** PATCH {prefix}/api/users/:id/roles — body `{ roles }`. */
78
78
  updateRoles(ctx: HttpContext): Promise<void | {
79
79
  id: string;
80
80
  email: string;
@@ -84,6 +84,22 @@ export default class ConsoleUsersController {
84
84
  disabled: boolean;
85
85
  roles: string[];
86
86
  }>;
87
+ /**
88
+ * PATCH {prefix}/api/users/:id — body `{ globalRoles }`, a mesma forma do
89
+ * `PATCH /users/:id` da Admin API. É o que o `client.admin.users.update` do
90
+ * authkit-react chama, e o que o botão "Salvar papéis" do console usa: sem
91
+ * esta rota ele dava 404. Só papéis por aqui; nome e avatar não se editam no
92
+ * console.
93
+ */
94
+ update(ctx: HttpContext): Promise<void | {
95
+ id: string;
96
+ email: string;
97
+ name: string | null;
98
+ avatarUrl: string | null;
99
+ globalRoles: string[];
100
+ disabled: boolean;
101
+ roles: string[];
102
+ }>;
87
103
  /** POST {prefix}/api/users/:id/disable */
88
104
  disable(ctx: HttpContext): Promise<void | {}>;
89
105
  /** POST {prefix}/api/users/:id/enable */
@@ -6,7 +6,7 @@ import { ACCOUNT_SESSION_KEY } from '../account_session_key.js';
6
6
  import { AdminUsersService } from '../admin_api/admin_users_service.js';
7
7
  import { apiError, grantDto, rolesManagedExternallyError, sessionDto, userDtoWithRoles, } from '../admin_api/dto.js';
8
8
  import { AdminSessionsService } from '../admin_sessions_service.js';
9
- import { adminUserCreateValidator, adminUserRolesValidator } from '../admin_validators.js';
9
+ import { adminUserCreateValidator, adminUserRolesValidator, adminUserUpdateValidator, } from '../admin_validators.js';
10
10
  import { resolveRuntimeSettings } from '../runtime_settings.js';
11
11
  import { resolveEffectiveRolesCatalog } from '../runtime_toggles.js';
12
12
  import { enrichSessionsWithContext } from '../session_context.js';
@@ -125,8 +125,23 @@ export default class ConsoleUsersController {
125
125
  ctx.response.status(201);
126
126
  return { ...(await userDtoWithRoles(cfg, result.account)), invited: result.invited };
127
127
  }
128
- /** PATCH {prefix}/api/users/:id/roles */
128
+ /** PATCH {prefix}/api/users/:id/roles — body `{ roles }`. */
129
129
  async updateRoles(ctx) {
130
+ const { roles } = await ctx.request.validateUsing(adminUserRolesValidator);
131
+ return this.#setRoles(ctx, roles);
132
+ }
133
+ /**
134
+ * PATCH {prefix}/api/users/:id — body `{ globalRoles }`, a mesma forma do
135
+ * `PATCH /users/:id` da Admin API. É o que o `client.admin.users.update` do
136
+ * authkit-react chama, e o que o botão "Salvar papéis" do console usa: sem
137
+ * esta rota ele dava 404. Só papéis por aqui; nome e avatar não se editam no
138
+ * console.
139
+ */
140
+ async update(ctx) {
141
+ const { globalRoles } = await ctx.request.validateUsing(adminUserUpdateValidator);
142
+ return this.#setRoles(ctx, globalRoles);
143
+ }
144
+ async #setRoles(ctx, rolesInput) {
130
145
  const service = await ctx.containerResolver.make('authkit.server');
131
146
  const cfg = service.config;
132
147
  const id = ctx.request.param('id');
@@ -139,7 +154,6 @@ export default class ConsoleUsersController {
139
154
  return ctx.response.status(409).send(rolesManagedExternallyError());
140
155
  }
141
156
  const actorId = ctx.session?.get(ACCOUNT_SESSION_KEY) ?? null;
142
- const { roles: rolesInput } = await ctx.request.validateUsing(adminUserRolesValidator);
143
157
  const roles = Array.from(new Set((rolesInput ?? []).map((r) => r.trim()).filter(Boolean)));
144
158
  const users = new AdminUsersService(cfg);
145
159
  // Proteções de escalonamento/lockout: último admin + auto-rebaixamento.
@@ -867,6 +867,7 @@ export function registerAuthHost(router, opts = {}) {
867
867
  router.get(`${ap}/api/users/:id`, [C.consoleUsers, 'show']);
868
868
  router.post(`${ap}/api/users`, [C.consoleUsers, 'store']);
869
869
  router.patch(`${ap}/api/users/:id/roles`, [C.consoleUsers, 'updateRoles']);
870
+ router.patch(`${ap}/api/users/:id`, [C.consoleUsers, 'update']);
870
871
  router.post(`${ap}/api/users/:id/disable`, [C.consoleUsers, 'disable']);
871
872
  router.post(`${ap}/api/users/:id/enable`, [C.consoleUsers, 'enable']);
872
873
  router.post(`${ap}/api/users/:id/reset-password`, [C.consoleUsers, 'resetPassword']);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonis-agora/authkit-server",
3
- "version": "0.85.0",
3
+ "version": "0.85.1",
4
4
  "description": "AdonisJS OIDC/OAuth2 provider (Identity Provider) toolkit: ejectable auth server with sessions, rate-limiting, MFA/TOTP, audit log, federated logout and OpenTelemetry metrics.",
5
5
  "license": "MIT",
6
6
  "author": "dudousxd",