@temboplus/afloat 0.1.31 → 0.1.33

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.
Files changed (69) hide show
  1. package/esm/mod.d.ts +1 -0
  2. package/esm/mod.d.ts.map +1 -1
  3. package/esm/mod.js +1 -0
  4. package/esm/src/features/admin/contract.d.ts +648 -0
  5. package/esm/src/features/admin/contract.d.ts.map +1 -0
  6. package/esm/src/features/admin/contract.js +184 -0
  7. package/esm/src/features/admin/index.d.ts +4 -0
  8. package/esm/src/features/admin/index.d.ts.map +1 -0
  9. package/esm/src/features/admin/index.js +3 -0
  10. package/esm/src/features/admin/repository.d.ts +104 -0
  11. package/esm/src/features/admin/repository.d.ts.map +1 -0
  12. package/esm/src/features/admin/repository.js +224 -0
  13. package/esm/src/features/admin/schemas.d.ts +119 -0
  14. package/esm/src/features/admin/schemas.d.ts.map +1 -0
  15. package/esm/src/features/admin/schemas.js +172 -0
  16. package/esm/src/models/index.d.ts +1 -0
  17. package/esm/src/models/index.d.ts.map +1 -1
  18. package/esm/src/models/index.js +1 -0
  19. package/esm/src/models/permission.d.ts +11 -1
  20. package/esm/src/models/permission.d.ts.map +1 -1
  21. package/esm/src/models/permission.js +10 -0
  22. package/esm/src/models/role.d.ts +21 -0
  23. package/esm/src/models/role.d.ts.map +1 -0
  24. package/esm/src/models/role.js +73 -0
  25. package/esm/src/models/user/{user.d.ts → authenticated-user.d.ts} +1 -1
  26. package/esm/src/models/user/authenticated-user.d.ts.map +1 -0
  27. package/esm/src/models/user/index.d.ts +2 -1
  28. package/esm/src/models/user/index.d.ts.map +1 -1
  29. package/esm/src/models/user/index.js +2 -1
  30. package/esm/src/models/user/managed-user.d.ts +102 -0
  31. package/esm/src/models/user/managed-user.d.ts.map +1 -0
  32. package/esm/src/models/user/managed-user.js +226 -0
  33. package/package.json +2 -2
  34. package/script/mod.d.ts +1 -0
  35. package/script/mod.d.ts.map +1 -1
  36. package/script/mod.js +1 -0
  37. package/script/src/features/admin/contract.d.ts +648 -0
  38. package/script/src/features/admin/contract.d.ts.map +1 -0
  39. package/script/src/features/admin/contract.js +187 -0
  40. package/script/src/features/admin/index.d.ts +4 -0
  41. package/script/src/features/admin/index.d.ts.map +1 -0
  42. package/script/src/features/admin/index.js +19 -0
  43. package/script/src/features/admin/repository.d.ts +104 -0
  44. package/script/src/features/admin/repository.d.ts.map +1 -0
  45. package/script/src/features/admin/repository.js +228 -0
  46. package/script/src/features/admin/schemas.d.ts +119 -0
  47. package/script/src/features/admin/schemas.d.ts.map +1 -0
  48. package/script/src/features/admin/schemas.js +175 -0
  49. package/script/src/models/index.d.ts +1 -0
  50. package/script/src/models/index.d.ts.map +1 -1
  51. package/script/src/models/index.js +1 -0
  52. package/script/src/models/permission.d.ts +11 -1
  53. package/script/src/models/permission.d.ts.map +1 -1
  54. package/script/src/models/permission.js +10 -0
  55. package/script/src/models/role.d.ts +21 -0
  56. package/script/src/models/role.d.ts.map +1 -0
  57. package/script/src/models/role.js +77 -0
  58. package/script/src/models/user/{user.d.ts → authenticated-user.d.ts} +1 -1
  59. package/script/src/models/user/authenticated-user.d.ts.map +1 -0
  60. package/script/src/models/user/index.d.ts +2 -1
  61. package/script/src/models/user/index.d.ts.map +1 -1
  62. package/script/src/models/user/index.js +2 -1
  63. package/script/src/models/user/managed-user.d.ts +102 -0
  64. package/script/src/models/user/managed-user.d.ts.map +1 -0
  65. package/script/src/models/user/managed-user.js +231 -0
  66. package/esm/src/models/user/user.d.ts.map +0 -1
  67. package/script/src/models/user/user.d.ts.map +0 -1
  68. /package/esm/src/models/user/{user.js → authenticated-user.js} +0 -0
  69. /package/script/src/models/user/{user.js → authenticated-user.js} +0 -0
@@ -0,0 +1,184 @@
1
+ import { initContract } from "@ts-rest/core";
2
+ import { z } from "zod";
3
+ import { UserManagementSchemas } from "./schemas.js";
4
+ // ====================== API Contract ====================== //
5
+ const c = initContract();
6
+ export const userManagementContract = c.router({
7
+ // List all users
8
+ getUsers: {
9
+ method: "GET",
10
+ path: "/login",
11
+ responses: {
12
+ 200: z.array(UserManagementSchemas.managedUser),
13
+ 401: z.object({
14
+ message: z.string(),
15
+ }),
16
+ 403: z.object({
17
+ message: z.string(),
18
+ }),
19
+ },
20
+ summary: "List all user accounts",
21
+ description: "Retrieve a list of all user accounts in the system",
22
+ },
23
+ // Get user by ID
24
+ getUser: {
25
+ method: "GET",
26
+ path: "/login/:id",
27
+ pathParams: z.object({
28
+ id: z.string(),
29
+ }),
30
+ responses: {
31
+ 200: UserManagementSchemas.managedUser,
32
+ 401: z.object({
33
+ message: z.string(),
34
+ }),
35
+ 403: z.object({
36
+ message: z.string(),
37
+ }),
38
+ 404: z.object({
39
+ message: z.string(),
40
+ }),
41
+ },
42
+ summary: "Get user account details",
43
+ description: "Retrieve detailed information about a specific user account",
44
+ },
45
+ // Create new user
46
+ createUser: {
47
+ method: "POST",
48
+ path: "/login",
49
+ body: UserManagementSchemas.createUserRequest,
50
+ responses: {
51
+ 201: UserManagementSchemas.createUserResponse,
52
+ 400: z.object({
53
+ message: z.string(),
54
+ errors: z.array(z.string()).optional(),
55
+ }),
56
+ 401: z.object({
57
+ message: z.string(),
58
+ }),
59
+ 403: z.object({
60
+ message: z.string(),
61
+ }),
62
+ 409: z.object({
63
+ message: z.string(),
64
+ }),
65
+ },
66
+ summary: "Create new user account",
67
+ description: "Create a new user account with specified role and permissions",
68
+ },
69
+ // Update user
70
+ updateUser: {
71
+ method: "PATCH",
72
+ path: "/login/:id",
73
+ pathParams: z.object({
74
+ id: z.string(),
75
+ }),
76
+ body: UserManagementSchemas.updateUserRequest,
77
+ responses: {
78
+ 200: UserManagementSchemas.managedUser,
79
+ 400: z.object({
80
+ message: z.string(),
81
+ errors: z.array(z.string()).optional(),
82
+ }),
83
+ 401: z.object({
84
+ message: z.string(),
85
+ }),
86
+ 403: z.object({
87
+ message: z.string(),
88
+ }),
89
+ 404: z.object({
90
+ message: z.string(),
91
+ }),
92
+ },
93
+ summary: "Update user account",
94
+ description: "Update user account information, role, status, or force password reset",
95
+ },
96
+ // Archive user (soft delete)
97
+ archiveUser: {
98
+ method: "DELETE",
99
+ path: "/login/:id",
100
+ pathParams: z.object({
101
+ id: z.string(),
102
+ }),
103
+ responses: {
104
+ 200: UserManagementSchemas.managedUser,
105
+ 401: z.object({
106
+ message: z.string(),
107
+ }),
108
+ 403: z.object({
109
+ message: z.string(),
110
+ }),
111
+ 404: z.object({
112
+ message: z.string(),
113
+ }),
114
+ },
115
+ summary: "Archive user account",
116
+ description: "Archive (soft delete) a user account",
117
+ },
118
+ // Reset user password
119
+ resetPassword: {
120
+ method: "POST",
121
+ path: "/login/:id/reset-password",
122
+ pathParams: z.object({
123
+ id: z.string(),
124
+ }),
125
+ body: UserManagementSchemas.resetPasswordRequest,
126
+ responses: {
127
+ 200: z.object({
128
+ message: z.string(),
129
+ }),
130
+ 400: z.object({
131
+ message: z.string(),
132
+ }),
133
+ 401: z.object({
134
+ message: z.string(),
135
+ }),
136
+ 403: z.object({
137
+ message: z.string(),
138
+ }),
139
+ 404: z.object({
140
+ message: z.string(),
141
+ }),
142
+ },
143
+ summary: "Reset user password",
144
+ description: "Reset a user's password and optionally send notification",
145
+ },
146
+ // Get all roles
147
+ getRoles: {
148
+ method: "GET",
149
+ path: "/role",
150
+ responses: {
151
+ 200: z.array(UserManagementSchemas.role),
152
+ 401: z.object({
153
+ message: z.string(),
154
+ }),
155
+ 403: z.object({
156
+ message: z.string(),
157
+ }),
158
+ },
159
+ summary: "List all roles",
160
+ description: "Retrieve a list of all available roles in the system",
161
+ },
162
+ // Get role by ID
163
+ getRole: {
164
+ method: "GET",
165
+ path: "/role/:id",
166
+ pathParams: z.object({
167
+ id: z.string(),
168
+ }),
169
+ responses: {
170
+ 200: UserManagementSchemas.role,
171
+ 401: z.object({
172
+ message: z.string(),
173
+ }),
174
+ 403: z.object({
175
+ message: z.string(),
176
+ }),
177
+ 404: z.object({
178
+ message: z.string(),
179
+ }),
180
+ },
181
+ summary: "Get role details",
182
+ description: "Retrieve detailed information about a specific role",
183
+ },
184
+ });
@@ -0,0 +1,4 @@
1
+ export * from "./contract.js";
2
+ export * from "./repository.js";
3
+ export * from "./schemas.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/features/admin/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from "./contract.js";
2
+ export * from "./repository.js";
3
+ export * from "./schemas.js";
@@ -0,0 +1,104 @@
1
+ import { BaseRepository } from "../../shared/base_repository.js";
2
+ import { userManagementContract } from "./contract.js";
3
+ import type { CreateUserRequest, CreateUserResponse, ResetPasswordRequest, UpdateUserRequest } from "./schemas.js";
4
+ import type { AfloatAuth } from "../auth/manager.js";
5
+ import { ManagedUser } from "../../models/index.js";
6
+ import { Role } from "../../models/role.js";
7
+ /**
8
+ * Repository class for managing user accounts through API interactions.
9
+ * Extends the `BaseRepository` to leverage shared functionality.
10
+ */
11
+ export declare class UserManagementRepository extends BaseRepository<typeof userManagementContract> {
12
+ /**
13
+ * Creates an instance of `UserManagementRepository` using the user management contract.
14
+ * @param {Object} [props] - Optional constructor properties
15
+ * @param {AfloatAuth} [props.auth] - Optional auth instance to use
16
+ * @param {string} [props.root] - Optional API root URL
17
+ */
18
+ constructor(props?: {
19
+ auth?: AfloatAuth;
20
+ root?: string;
21
+ });
22
+ /**
23
+ * Creates a new user account.
24
+ * @param {CreateUserRequest} input - The data required to create a new user account.
25
+ * @returns {Promise<CreateUserResponse>} A promise that resolves to the newly created user response.
26
+ * @throws {PermissionError} If the user lacks required permissions
27
+ * @throws {APIError} If the response status code is not 201.
28
+ */
29
+ createUser(input: CreateUserRequest): Promise<CreateUserResponse>;
30
+ /**
31
+ * Updates an existing user account by ID.
32
+ * @param {string} id - The unique identifier of the user account to update.
33
+ * @param {UpdateUserRequest} input - The data to update the user account with.
34
+ * @returns {Promise<ManagedUser>} A promise that resolves to the updated user account.
35
+ * @throws {PermissionError} If the user lacks required permissions
36
+ * @throws {APIError} If the response status code is not 200.
37
+ */
38
+ updateUser(id: string, input: UpdateUserRequest): Promise<ManagedUser>;
39
+ /**
40
+ * Archives (soft deletes) a user account by ID.
41
+ * @param {string} id - The unique identifier of the user account to archive.
42
+ * @returns {Promise<ManagedUser>} A promise that resolves to the archived user account.
43
+ * @throws {PermissionError} If the user lacks required permissions
44
+ * @throws {APIError} If the response status code is not 200.
45
+ */
46
+ archiveUser(id: string): Promise<ManagedUser>;
47
+ /**
48
+ * Resets a user's password.
49
+ * @param {string} id - The unique identifier of the user account.
50
+ * @param {ResetPasswordRequest} [input] - Optional password reset configuration.
51
+ * @returns {Promise<void>} A promise that resolves when the password reset is complete.
52
+ * @throws {PermissionError} If the user lacks required permissions
53
+ * @throws {APIError} If the response status code is not 200.
54
+ */
55
+ resetUserPassword(id: string, input?: ResetPasswordRequest): Promise<void>;
56
+ /**
57
+ * Retrieves all user accounts.
58
+ * Results are ordered in descending order by creation date by default.
59
+ *
60
+ * @returns {Promise<ManagedUser[]>} A promise that resolves to an array of managed users.
61
+ * @throws {PermissionError} If the user lacks required permissions
62
+ * @throws {APIError} If the response status code is not 200.
63
+ * @example
64
+ * const repository = new UserManagementRepository();
65
+ * repository.getAllUsers().then(users => console.log(users));
66
+ */
67
+ getAllUsers(): Promise<ManagedUser[]>;
68
+ /**
69
+ * Retrieves a specific user account by ID.
70
+ *
71
+ * @param {string} id - The unique identifier of the user account to retrieve.
72
+ * @returns {Promise<ManagedUser>} A promise that resolves to the managed user.
73
+ * @throws {PermissionError} If the user lacks required permissions
74
+ * @throws {APIError} If the response status code is not 200 or user not found.
75
+ * @example
76
+ * const repository = new UserManagementRepository();
77
+ * repository.getUser('user-id').then(user => console.log(user));
78
+ */
79
+ getUser(id: string): Promise<ManagedUser>;
80
+ /**
81
+ * Retrieves all available roles in the system.
82
+ *
83
+ * @returns {Promise<Role[]>} A promise that resolves to an array of roles.
84
+ * @throws {PermissionError} If the user lacks required permissions
85
+ * @throws {APIError} If the response status code is not 200.
86
+ * @example
87
+ * const repository = new UserManagementRepository();
88
+ * repository.getAllRoles().then(roles => console.log(roles));
89
+ */
90
+ getAllRoles(): Promise<Role[]>;
91
+ /**
92
+ * Retrieves a specific role by ID.
93
+ *
94
+ * @param {string} id - The unique identifier of the role to retrieve.
95
+ * @returns {Promise<Role>} A promise that resolves to the role.
96
+ * @throws {PermissionError} If the user lacks required permissions
97
+ * @throws {APIError} If the response status code is not 200 or role not found.
98
+ * @example
99
+ * const repository = new UserManagementRepository();
100
+ * repository.getRole('role-id').then(role => console.log(role));
101
+ */
102
+ getRole(id: string): Promise<Role>;
103
+ }
104
+ //# sourceMappingURL=repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/admin/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAqC,MAAM,uBAAuB,CAAC;AAEvF,OAAO,EAAE,IAAI,EAAiB,MAAM,sBAAsB,CAAC;AAE3D;;;GAGG;AACH,qBAAa,wBACX,SAAQ,cAAc,CAAC,OAAO,sBAAsB,CAAC;IACrD;;;;;OAKG;gBACS,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,UAAU,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE;IAIxD;;;;;;OAMG;IACG,UAAU,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAgBvE;;;;;;;OAOG;IACG,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;IAuB5E;;;;;;OAMG;IACG,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAoBnD;;;;;;;OAOG;IACG,iBAAiB,CACrB,EAAE,EAAE,MAAM,EACV,KAAK,GAAE,oBAAyB,GAC/B,OAAO,CAAC,IAAI,CAAC;IAkBhB;;;;;;;;;;OAUG;IACG,WAAW,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAgB3C;;;;;;;;;;OAUG;IACG,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAoB/C;;;;;;;;;OASG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAsBpC;;;;;;;;;;OAUG;IACG,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAmBzC"}
@@ -0,0 +1,224 @@
1
+ import { BaseRepository } from "../../shared/base_repository.js";
2
+ import { userManagementContract } from "./contract.js";
3
+ import { ManagedUser, Permissions } from "../../models/index.js";
4
+ import { PermissionError } from "../../errors/index.js";
5
+ import { Role } from "../../models/role.js";
6
+ /**
7
+ * Repository class for managing user accounts through API interactions.
8
+ * Extends the `BaseRepository` to leverage shared functionality.
9
+ */
10
+ export class UserManagementRepository extends BaseRepository {
11
+ /**
12
+ * Creates an instance of `UserManagementRepository` using the user management contract.
13
+ * @param {Object} [props] - Optional constructor properties
14
+ * @param {AfloatAuth} [props.auth] - Optional auth instance to use
15
+ * @param {string} [props.root] - Optional API root URL
16
+ */
17
+ constructor(props) {
18
+ super("admin", userManagementContract, props);
19
+ }
20
+ /**
21
+ * Creates a new user account.
22
+ * @param {CreateUserRequest} input - The data required to create a new user account.
23
+ * @returns {Promise<CreateUserResponse>} A promise that resolves to the newly created user response.
24
+ * @throws {PermissionError} If the user lacks required permissions
25
+ * @throws {APIError} If the response status code is not 201.
26
+ */
27
+ async createUser(input) {
28
+ const auth = this.getAuthForPermissionCheck();
29
+ const requiredPerm = Permissions.UserManagement.CreateUser;
30
+ if (!auth.checkPermission(requiredPerm)) {
31
+ throw new PermissionError({
32
+ message: "You are not authorized to create user accounts.",
33
+ requiredPermissions: [requiredPerm],
34
+ });
35
+ }
36
+ const result = await this.client.createUser({ body: input });
37
+ const data = this.handleResponse(result, 201);
38
+ return data;
39
+ }
40
+ /**
41
+ * Updates an existing user account by ID.
42
+ * @param {string} id - The unique identifier of the user account to update.
43
+ * @param {UpdateUserRequest} input - The data to update the user account with.
44
+ * @returns {Promise<ManagedUser>} A promise that resolves to the updated user account.
45
+ * @throws {PermissionError} If the user lacks required permissions
46
+ * @throws {APIError} If the response status code is not 200.
47
+ */
48
+ async updateUser(id, input) {
49
+ const auth = this.getAuthForPermissionCheck();
50
+ const requiredPerm = Permissions.UserManagement.UpdateUser;
51
+ if (!auth.checkPermission(requiredPerm)) {
52
+ throw new PermissionError({
53
+ message: "You are not authorized to update user accounts.",
54
+ requiredPermissions: [requiredPerm],
55
+ });
56
+ }
57
+ const result = await this.client.updateUser({
58
+ params: { id },
59
+ body: input,
60
+ });
61
+ const data = this.handleResponse(result, 200);
62
+ const managedUser = ManagedUser.from(data);
63
+ if (!managedUser) {
64
+ throw new Error("Invalid user data received from server");
65
+ }
66
+ return managedUser;
67
+ }
68
+ /**
69
+ * Archives (soft deletes) a user account by ID.
70
+ * @param {string} id - The unique identifier of the user account to archive.
71
+ * @returns {Promise<ManagedUser>} A promise that resolves to the archived user account.
72
+ * @throws {PermissionError} If the user lacks required permissions
73
+ * @throws {APIError} If the response status code is not 200.
74
+ */
75
+ async archiveUser(id) {
76
+ const auth = this.getAuthForPermissionCheck();
77
+ const requiredPerm = Permissions.UserManagement.ArchiveUser;
78
+ if (!auth.checkPermission(requiredPerm)) {
79
+ throw new PermissionError({
80
+ message: "You are not authorized to archive user accounts.",
81
+ requiredPermissions: [requiredPerm],
82
+ });
83
+ }
84
+ const result = await this.client.archiveUser({ params: { id } });
85
+ const data = this.handleResponse(result, 200);
86
+ const managedUser = ManagedUser.from(data);
87
+ if (!managedUser) {
88
+ throw new Error("Invalid user data received from server");
89
+ }
90
+ return managedUser;
91
+ }
92
+ /**
93
+ * Resets a user's password.
94
+ * @param {string} id - The unique identifier of the user account.
95
+ * @param {ResetPasswordRequest} [input] - Optional password reset configuration.
96
+ * @returns {Promise<void>} A promise that resolves when the password reset is complete.
97
+ * @throws {PermissionError} If the user lacks required permissions
98
+ * @throws {APIError} If the response status code is not 200.
99
+ */
100
+ async resetUserPassword(id, input = {}) {
101
+ const auth = this.getAuthForPermissionCheck();
102
+ const requiredPerm = Permissions.UserManagement.ResetPassword;
103
+ if (!auth.checkPermission(requiredPerm)) {
104
+ throw new PermissionError({
105
+ message: "You are not authorized to reset user passwords.",
106
+ requiredPermissions: [requiredPerm],
107
+ });
108
+ }
109
+ const result = await this.client.resetPassword({
110
+ params: { id },
111
+ body: input,
112
+ });
113
+ this.handleResponse(result, 200);
114
+ }
115
+ /**
116
+ * Retrieves all user accounts.
117
+ * Results are ordered in descending order by creation date by default.
118
+ *
119
+ * @returns {Promise<ManagedUser[]>} A promise that resolves to an array of managed users.
120
+ * @throws {PermissionError} If the user lacks required permissions
121
+ * @throws {APIError} If the response status code is not 200.
122
+ * @example
123
+ * const repository = new UserManagementRepository();
124
+ * repository.getAllUsers().then(users => console.log(users));
125
+ */
126
+ async getAllUsers() {
127
+ const auth = this.getAuthForPermissionCheck();
128
+ const requiredPerm = Permissions.UserManagement.ViewUsers;
129
+ if (!auth.checkPermission(requiredPerm)) {
130
+ throw new PermissionError({
131
+ message: "You are not authorized to view user accounts.",
132
+ requiredPermissions: [requiredPerm],
133
+ });
134
+ }
135
+ const result = await this.client.getUsers();
136
+ const data = this.handleResponse(result, 200);
137
+ return ManagedUser.createMany(data);
138
+ }
139
+ /**
140
+ * Retrieves a specific user account by ID.
141
+ *
142
+ * @param {string} id - The unique identifier of the user account to retrieve.
143
+ * @returns {Promise<ManagedUser>} A promise that resolves to the managed user.
144
+ * @throws {PermissionError} If the user lacks required permissions
145
+ * @throws {APIError} If the response status code is not 200 or user not found.
146
+ * @example
147
+ * const repository = new UserManagementRepository();
148
+ * repository.getUser('user-id').then(user => console.log(user));
149
+ */
150
+ async getUser(id) {
151
+ const auth = this.getAuthForPermissionCheck();
152
+ const requiredPerm = Permissions.UserManagement.ViewUser;
153
+ if (!auth.checkPermission(requiredPerm)) {
154
+ throw new PermissionError({
155
+ message: "You are not authorized to view user account details.",
156
+ requiredPermissions: [requiredPerm],
157
+ });
158
+ }
159
+ const result = await this.client.getUser({ params: { id } });
160
+ const data = this.handleResponse(result, 200);
161
+ const managedUser = ManagedUser.from(data);
162
+ if (!managedUser) {
163
+ throw new Error("Invalid user data received from server");
164
+ }
165
+ return managedUser;
166
+ }
167
+ /**
168
+ * Retrieves all available roles in the system.
169
+ *
170
+ * @returns {Promise<Role[]>} A promise that resolves to an array of roles.
171
+ * @throws {PermissionError} If the user lacks required permissions
172
+ * @throws {APIError} If the response status code is not 200.
173
+ * @example
174
+ * const repository = new UserManagementRepository();
175
+ * repository.getAllRoles().then(roles => console.log(roles));
176
+ */
177
+ async getAllRoles() {
178
+ const auth = this.getAuthForPermissionCheck();
179
+ const requiredPerm = Permissions.UserManagement.ViewRoles;
180
+ if (!auth.checkPermission(requiredPerm)) {
181
+ throw new PermissionError({
182
+ message: "You are not authorized to view system roles.",
183
+ requiredPermissions: [requiredPerm],
184
+ });
185
+ }
186
+ const result = await this.client.getRoles();
187
+ const data = this.handleResponse(result, 200);
188
+ return data.map((roleData) => {
189
+ const role = Role.from(roleData);
190
+ if (!role) {
191
+ throw new Error("Invalid role data received from server");
192
+ }
193
+ return role;
194
+ });
195
+ }
196
+ /**
197
+ * Retrieves a specific role by ID.
198
+ *
199
+ * @param {string} id - The unique identifier of the role to retrieve.
200
+ * @returns {Promise<Role>} A promise that resolves to the role.
201
+ * @throws {PermissionError} If the user lacks required permissions
202
+ * @throws {APIError} If the response status code is not 200 or role not found.
203
+ * @example
204
+ * const repository = new UserManagementRepository();
205
+ * repository.getRole('role-id').then(role => console.log(role));
206
+ */
207
+ async getRole(id) {
208
+ const auth = this.getAuthForPermissionCheck();
209
+ const requiredPerm = Permissions.UserManagement.ViewRoles;
210
+ if (!auth.checkPermission(requiredPerm)) {
211
+ throw new PermissionError({
212
+ message: "You are not authorized to view role details.",
213
+ requiredPermissions: [requiredPerm],
214
+ });
215
+ }
216
+ const result = await this.client.getRole({ params: { id } });
217
+ const data = this.handleResponse(result, 200);
218
+ const role = Role.from(data);
219
+ if (!role) {
220
+ throw new Error("Invalid role data received from server");
221
+ }
222
+ return role;
223
+ }
224
+ }
@@ -0,0 +1,119 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Type definition for password schema using Zod.
4
+ * This is used as a TypeScript type helper for the actual schema implementation.
5
+ */
6
+ type _PasswordType = z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>, string, string>;
7
+ /**
8
+ * Type definition for role schema using Zod.
9
+ * This is used as a TypeScript type helper for the actual schema implementation.
10
+ */
11
+ type _RoleType = z.ZodObject<{
12
+ id: z.ZodString;
13
+ name: z.ZodString;
14
+ description: z.ZodOptional<z.ZodString>;
15
+ access: z.ZodArray<z.ZodString>;
16
+ createdAt: z.ZodString;
17
+ updatedAt: z.ZodString;
18
+ }>;
19
+ /**
20
+ * Type definition for managed user schema using Zod.
21
+ * This is used as a TypeScript type helper for the actual schema implementation.
22
+ */
23
+ type _ManagedUserType = z.ZodObject<{
24
+ id: z.ZodString;
25
+ name: z.ZodString;
26
+ identity: z.ZodString;
27
+ type: z.ZodString;
28
+ profileId: z.ZodString;
29
+ roleId: z.ZodString;
30
+ resetPassword: z.ZodBoolean;
31
+ isActive: z.ZodBoolean;
32
+ role: z.ZodType<Role>;
33
+ createdAt: z.ZodString;
34
+ updatedAt: z.ZodString;
35
+ }>;
36
+ /**
37
+ * Type definition for create user request schema using Zod.
38
+ * This is used as a TypeScript type helper for the actual schema implementation.
39
+ */
40
+ type _CreateUserRequestType = z.ZodObject<{
41
+ name: z.ZodString;
42
+ identity: z.ZodString;
43
+ password: _PasswordType;
44
+ roleId: z.ZodOptional<z.ZodString>;
45
+ resetPassword: z.ZodOptional<z.ZodBoolean>;
46
+ }>;
47
+ /**
48
+ * Type definition for update user request schema using Zod.
49
+ * This is used as a TypeScript type helper for the actual schema implementation.
50
+ */
51
+ type _UpdateUserRequestType = z.ZodObject<{
52
+ name: z.ZodOptional<z.ZodString>;
53
+ roleId: z.ZodOptional<z.ZodString>;
54
+ password: z.ZodOptional<_PasswordType>;
55
+ resetPassword: z.ZodOptional<z.ZodBoolean>;
56
+ isActive: z.ZodOptional<z.ZodBoolean>;
57
+ }>;
58
+ /**
59
+ * Type definition for reset password request schema using Zod.
60
+ * This is used as a TypeScript type helper for the actual schema implementation.
61
+ */
62
+ type _ResetPasswordRequestType = z.ZodObject<{
63
+ newPassword: z.ZodOptional<_PasswordType>;
64
+ sendNotification: z.ZodOptional<z.ZodBoolean>;
65
+ }>;
66
+ /**
67
+ * Type definition for create user response schema using Zod.
68
+ * This is used as a TypeScript type helper for the actual schema implementation.
69
+ */
70
+ type _CreateUserResponseType = z.ZodObject<{
71
+ id: z.ZodString;
72
+ name: z.ZodString;
73
+ identity: z.ZodString;
74
+ type: z.ZodString;
75
+ profileId: z.ZodString;
76
+ roleId: z.ZodString;
77
+ isActive: z.ZodBoolean;
78
+ createdAt: z.ZodString;
79
+ }>;
80
+ /**
81
+ * Collection of user management schemas for export.
82
+ * Provides access to all user and role validation schemas.
83
+ */
84
+ export declare const UserManagementSchemas: {
85
+ role: _RoleType;
86
+ managedUser: _ManagedUserType;
87
+ createUserRequest: _CreateUserRequestType;
88
+ updateUserRequest: _UpdateUserRequestType;
89
+ resetPasswordRequest: _ResetPasswordRequestType;
90
+ createUserResponse: _CreateUserResponseType;
91
+ password: _PasswordType;
92
+ };
93
+ /**
94
+ * TypeScript type for a validated role object.
95
+ * Use this type for role instances that have been validated against the schema.
96
+ */
97
+ type Role = z.infer<typeof UserManagementSchemas.role>;
98
+ /**
99
+ * TypeScript type for a create user request object.
100
+ * Use this type for user creation requests that have been validated against the schema.
101
+ */
102
+ export type CreateUserRequest = z.infer<typeof UserManagementSchemas.createUserRequest>;
103
+ /**
104
+ * TypeScript type for an update user request object.
105
+ * Use this type for user update requests that have been validated against the schema.
106
+ */
107
+ export type UpdateUserRequest = z.infer<typeof UserManagementSchemas.updateUserRequest>;
108
+ /**
109
+ * TypeScript type for a reset password request object.
110
+ * Use this type for password reset requests that have been validated against the schema.
111
+ */
112
+ export type ResetPasswordRequest = z.infer<typeof UserManagementSchemas.resetPasswordRequest>;
113
+ /**
114
+ * TypeScript type for a create user response object.
115
+ * Use this type for user creation responses that have been validated against the schema.
116
+ */
117
+ export type CreateUserResponse = z.infer<typeof UserManagementSchemas.createUserResponse>;
118
+ export {};
119
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/src/features/admin/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,KAAK,aAAa,GAAG,CAAC,CAAC,UAAU,CAC/B,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EACvE,MAAM,EACN,MAAM,CACP,CAAC;AAuDF;;;GAGG;AACH,KAAK,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;IAC3B,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC;IAChB,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC;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