Skip to content

Commit bf294e9

Browse files
committed
chore: add documentation for dynamic user management
1 parent 2e71143 commit bf294e9

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

src/roles/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export interface Roles {
3535
*/
3636
byName: (roleName: string) => Promise<Role | null>;
3737
/**
38-
* Retrieve the user IDs assigned to a role.
38+
* Retrieve the user IDs assigned to a role. Each user has a qualifying user type,
39+
* e.g. `'db_user' | 'db_env_user' | 'oidc'`.
3940
*
4041
* @param {string} roleName The name of the role to retrieve the assigned user IDs for.
4142
* @returns {Promise<string[]>} The user IDs assigned to the role.

src/users/index.ts

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,74 @@ export interface Users extends UsersBase {
5555
/** Operations supported for namespaced 'db' users.*/
5656
export interface DBUsers extends UsersBase {
5757
/**
58-
* Retrieve the roles assigned to a user.
58+
* Retrieve the roles assigned to a 'db_user' user.
5959
*
6060
* @param {string} userId The ID of the user to retrieve the assigned roles for.
6161
* @returns {Promise<Record<string, Role>>} A map of role names to their respective roles.
6262
*/
6363
getAssignedRoles: (userId: string, opts?: GetAssignedRolesOptions) => Promise<Record<string, Role>>;
6464

65+
/** Create a new 'db_user' user.
66+
*
67+
* @param {string} userId The ID of the user to create. Must consist of valid URL characters only.
68+
* @returns {Promise<string>} API key for the newly created user.
69+
*/
6570
create: (userId: string) => Promise<string>;
71+
72+
/**
73+
* Delete a 'db_user' user. It is not possible to delete 'db_env_user' users programmatically.
74+
*
75+
* @param {string} userId The ID of the user to delete.
76+
* @returns {Promise<boolean>} `true` if the user has been successfully deleted.
77+
*/
6678
delete: (userId: string) => Promise<boolean>;
79+
80+
/**
81+
* Rotate the API key of a 'db_user' user. The old API key becomes invalid.
82+
* API keys of 'db_env_user' users are defined in the server's environment
83+
* and cannot be modified programmatically.
84+
*
85+
* @param {string} userId The ID of the user to create a new API key for.
86+
* @returns {Promise<string>} New API key for the user.
87+
*/
6788
rotateKey: (userId: string) => Promise<string>;
89+
90+
/**
91+
* Activate 'db_user' user.
92+
*
93+
* @param {string} userId The ID of the user to activate.
94+
* @returns {Promise<boolean>} `true` if the user has been successfully activated.
95+
*/
6896
activate: (userId: string) => Promise<boolean>;
97+
98+
/**
99+
* Deactivate 'db_user' user.
100+
*
101+
* @param {string} userId The ID of the user to deactivate.
102+
* @returns {Promise<boolean>} `true` if the user has been successfully deactivated.
103+
*/
69104
deactivate: (userId: string) => Promise<boolean>;
105+
106+
/**
107+
* Retrieve information about the 'db_user' / 'db_env_user' user.
108+
*
109+
* @param {string} userId The ID of the user to get.
110+
* @returns {Promise<UserDB>} ID, status, and assigned roles of a 'db_*' user.
111+
*/
70112
byName: (userId: string) => Promise<UserDB>;
113+
114+
/**
115+
* List all 'db_user' / 'db_env_user' users.
116+
*
117+
* @returns {Promise<UserDB[]>} ID, status, and assigned roles for each 'db_*' user.
118+
*/
71119
listAll: () => Promise<UserDB[]>;
72120
}
73121

74122
/** Operations supported for namespaced 'oidc' users.*/
75123
export interface OIDCUsers extends UsersBase {
76124
/**
77-
* Retrieve the roles assigned to a user.
125+
* Retrieve the roles assigned to an 'oidc' user.
78126
*
79127
* @param {string} userId The ID of the user to retrieve the assigned roles for.
80128
* @returns {Promise<Record<string, Role>>} A map of role names to their respective roles.
@@ -167,6 +215,7 @@ interface NamespacedUsers {
167215
revokeRoles: (roleNames: string | string[], userId: string, opts?: AssignRevokeOptions) => Promise<void>;
168216
}
169217

218+
/** Implementation of the operations common to 'db', 'oidc', and legacy users. */
170219
const baseUsers = (connection: ConnectionREST): UsersBase => {
171220
const ns = namespacedUsers(connection);
172221
return {
@@ -175,13 +224,13 @@ const baseUsers = (connection: ConnectionREST): UsersBase => {
175224
};
176225
};
177226

227+
/** Implementation of the operations common to 'db' and 'oidc' users. */
178228
const namespacedUsers = (connection: ConnectionREST): NamespacedUsers => {
179229
return {
180230
getAssignedRoles: (userType: UserTypeInternal, userId: string, opts?: GetAssignedRolesOptions) =>
181231
connection
182232
.get<WeaviateRole[]>(
183-
`/authz/users/${userId}/roles/${userType}${
184-
opts?.includePermissions ? '?&includeFullRoles=true' : ''
233+
`/authz/users/${userId}/roles/${userType}${opts?.includePermissions ? '?&includeFullRoles=true' : ''
185234
}`
186235
)
187236
.then(Map.roles),

0 commit comments

Comments
 (0)