@enonic-types/lib-auth 0.1.1 → 7.11.0-B3

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 (3) hide show
  1. package/README.md +4 -4
  2. package/auth.d.ts +350 -355
  3. package/package.json +35 -32
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  ## Install
6
6
 
7
7
  ```bash
8
- npm i --save-dev @enonic/lib-auth
8
+ npm i --save-dev @enonic-types/lib-auth
9
9
  ```
10
10
 
11
11
  ## Use
@@ -26,8 +26,8 @@ Add the corresponding types to your `tsconfig.json` file that is used for applic
26
26
 
27
27
  ### Require and custom imports
28
28
 
29
- To make `require` work out of box, you must install and add the `@enonic-types/global` types. Aside from providing definitions for XP global
30
- objects, e.g. `log`, `app`, `__`, etc, requiring library by the default path will return typed object.
29
+ To make `require` work out of the box, you must install and add the `@enonic-types/global` types. Aside from providing definitions for XP
30
+ global objects, e.g. `log`, `app`, `__`, etc, requiring a library by the default path will return typed object.
31
31
 
32
32
  `tsconfig.json`
33
33
 
@@ -49,7 +49,7 @@ const {login, logout, getUser, generatePassword} = require('/lib/xp/auth');
49
49
  ```
50
50
 
51
51
  More detailed explanation on how it works and how to type custom import function can be
52
- found [here](https://github.com/enonic/xp/tree/master/modules/lib/typescript/README.md).
52
+ found [here](https://developer.enonic.com/docs/xp/stable/api).
53
53
 
54
54
  ### ES6-style import
55
55
 
package/auth.d.ts CHANGED
@@ -1,355 +1,350 @@
1
- /**
2
- * Built-in authentication functions.
3
- *
4
- * @example
5
- * var authLib = require('/lib/xp/auth');
6
- *
7
- * @module auth
8
- */
9
- declare global {
10
- interface XpLibraries {
11
- '/lib/xp/auth': typeof import('./auth');
12
- }
13
- }
14
- export declare type EditorFn<T> = (value: T) => T;
15
- export declare type LoginScopeType = 'SESSION' | 'REQUEST' | 'NONE';
16
- export interface LoginParams {
17
- user: string;
18
- skipAuth?: boolean;
19
- password?: string;
20
- idProvider?: string;
21
- scope?: LoginScopeType;
22
- sessionTimeout?: number;
23
- }
24
- export interface Principal {
25
- type: string;
26
- key: string;
27
- displayName: string;
28
- modifiedTime: string;
29
- }
30
- export interface User extends Principal {
31
- disabled?: boolean;
32
- email?: string;
33
- login?: string;
34
- idProvider: string;
35
- profile?: Record<string, unknown>;
36
- }
37
- export interface Role extends Principal {
38
- description?: string;
39
- }
40
- export interface Group extends Principal {
41
- description?: string;
42
- }
43
- export interface LoginResult {
44
- authenticated: boolean;
45
- message: string;
46
- users?: Principal;
47
- }
48
- /**
49
- * Login a user with the specified idProvider, userName, password and scope.
50
- *
51
- * @example-ref examples/auth/login.js
52
- *
53
- * @param {object} params JSON parameters.
54
- * @param {string} params.user Name of user to log in.
55
- * @param {string} [params.idProvider] Name of id provider where the user is stored. If not specified it will try all available id providers, in alphabetical order.
56
- * @param {string} [params.password] Password for the user. Ignored if skipAuth is set to true, mandatory otherwise.
57
- * @param {('SESSION'|'REQUEST'|'NONE')} [params.scope=SESSION] The scope of this login. Two values are valid. SESSION logs the user in and creates a session in XP for use in future requests. REQUEST logs the user in but only for this particular request and thus does not create a session.
58
- * @param {boolean} [params.skipAuth=false] Skip authentication.
59
- * @param {number} [params.sessionTimeout] Session timeout (in seconds). By default, the value of session.timeout from com.enonic.xp.web.jetty.cfg
60
- * @returns {LoginResult} Information for logged-in user.
61
- */
62
- export declare function login(params: LoginParams): LoginResult;
63
- /**
64
- * Logout an already logged-in user.
65
- *
66
- * @example-ref examples/auth/logout.js
67
- */
68
- export declare function logout(): void;
69
- export interface GetUserParams {
70
- includeProfile?: boolean;
71
- }
72
- /**
73
- * Returns the logged-in user. If not logged-in, this will return *undefined*.
74
- *
75
- * @example-ref examples/auth/getUser.js
76
- *
77
- * @param {object} [params] JSON parameters.
78
- * @param {boolean} [params.includeProfile=false] Include profile.
79
- *
80
- * @returns {User} Information for logged-in user.
81
- */
82
- export declare function getUser(params: GetUserParams): User;
83
- /**
84
- * Checks if the logged-in user has the specified role.
85
- *
86
- * @example-ref examples/auth/hasRole.js
87
- *
88
- * @param {string} role Role to check for.
89
- * @returns {boolean} True if the user has specfied role, false otherwise.
90
- */
91
- export declare function hasRole(role: string): boolean;
92
- /**
93
- * Generates a secure password.
94
- *
95
- * @example-ref examples/auth/generatePassword.js
96
- *
97
- * @returns {string} A secure generated password.
98
- */
99
- export declare function generatePassword(): string;
100
- export interface ChangePasswordParams {
101
- userKey: string;
102
- password: string;
103
- }
104
- /**
105
- * Changes password for specified user.
106
- *
107
- * @example-ref examples/auth/changePassword.js
108
- *
109
- * @param {object} params JSON parameters.
110
- * @param {string} params.userKey Key for user to change password.
111
- * @param {string} params.password New password to set.
112
- */
113
- export declare function changePassword(params: ChangePasswordParams): void;
114
- /**
115
- * Returns the principal with the specified key.
116
- *
117
- * @example-ref examples/auth/getPrincipal.js
118
- *
119
- * @param {string} principalKey Principal key to look for.
120
- * @returns {Principal} the principal specified, or null if it doesn't exist.
121
- */
122
- export declare function getPrincipal(principalKey: string): User | Group | Role;
123
- /**
124
- * Returns a list of principals the specified principal is a member of.
125
- *
126
- * @example-ref examples/auth/getMemberships.js
127
- *
128
- * @param {string} principalKey Principal key to retrieve memberships for.
129
- * @param {boolean} [transitive=false] Retrieve transitive memberships.
130
- * @returns {(User | Group | Role)[]} Returns the list of principals.
131
- */
132
- export declare function getMemberships(principalKey: string, transitive: boolean): (User | Group | Role)[];
133
- /**
134
- * Returns a list of principals that are members of the specified principal.
135
- *
136
- * @example-ref examples/auth/getMembers.js
137
- *
138
- * @param {string} principalKey Principal key to retrieve members for.
139
- * @returns {(User | Group | Role)[]} Returns the list of principals.
140
- */
141
- export declare function getMembers(principalKey: string): (User | Group | Role)[];
142
- export interface CreateUserParams {
143
- name: string;
144
- displayName: string;
145
- idProvider: string;
146
- email?: string;
147
- }
148
- /**
149
- * Creates user from passed parameters.
150
- *
151
- * @example-ref examples/auth/createUser.js
152
- *
153
- * @param {object} params JSON parameters.
154
- * @param {string} params.idProvider Key for id provider where user has to be created.
155
- * @param {string} params.name User login name to set.
156
- * @param {string} params.displayName User display name.
157
- * @param {string} [params.email] User email.
158
- */
159
- export declare function createUser(params: CreateUserParams): User | null;
160
- export interface ModifyUserParams {
161
- key: string;
162
- editor: EditorFn<User>;
163
- }
164
- /**
165
- * Retrieves the user specified and updates it with the changes applied.
166
- *
167
- * @example-ref examples/auth/modifyUser.js
168
- *
169
- * @param {object} params JSON parameters.
170
- * @param {string} params.key Principal key of the user to modify.
171
- * @param {function} params.editor User editor function to apply to user.
172
- * @returns {User} the updated user or null if a user not found.
173
- */
174
- export declare function modifyUser(params: ModifyUserParams): User | null;
175
- export interface CreateGroupParams {
176
- idProvider: string;
177
- name: string;
178
- displayName: string;
179
- description: string;
180
- }
181
- /**
182
- * Creates a group.
183
- *
184
- * @example-ref examples/auth/createGroup.js
185
- *
186
- * @param {object} params JSON parameters.
187
- * @param {string} params.idProvider Key for id provider where group has to be created.
188
- * @param {string} params.name Group name.
189
- * @param {string} params.displayName Group display name.
190
- * @param {string} params.description as principal description .
191
- */
192
- export declare function createGroup(params: CreateGroupParams): Group | null;
193
- export interface ModifyGroupParams {
194
- key: string;
195
- editor: EditorFn<Group>;
196
- }
197
- /**
198
- * Retrieves the group specified and updates it with the changes applied.
199
- *
200
- * @example-ref examples/auth/modifyGroup.js
201
- *
202
- * @param {object} params JSON parameters.
203
- * @param {string} params.key Principal key of the group to modify.
204
- * @param {function} params.editor Group editor function to apply to group.
205
- * @returns {Group} the updated group or null if a group not found.
206
- */
207
- export declare function modifyGroup(params: ModifyGroupParams): Group | null;
208
- /**
209
- * Adds members to a principal (user or role).
210
- *
211
- * @example-ref examples/auth/addMembers.js
212
- *
213
- * @param {string} principalKey Key of the principal to add members to.
214
- * @param {string} members Keys of the principals to add.
215
- */
216
- export declare function addMembers(principalKey: string, members: string): void;
217
- /**
218
- * Removes members from a principal (user or role).
219
- *
220
- * @example-ref examples/auth/removeMembers.js
221
- *
222
- * @param {string} principalKey Key of the principal to remove members from.
223
- * @param {string} members Keys of the principals to remove.
224
- */
225
- export declare function removeMembers(principalKey: string, members: string): void;
226
- export interface FindPrincipalsParams {
227
- type?: string;
228
- idProvider?: string;
229
- start?: number;
230
- count?: number;
231
- name?: string;
232
- searchText?: string;
233
- }
234
- export interface FindPrincipalsResult {
235
- total: number;
236
- count: number;
237
- hits: (User | Group | Role)[];
238
- }
239
- /**
240
- * Search for principals matching the specified criteria.
241
- *
242
- * @example-ref examples/auth/findPrincipals.js
243
- *
244
- * @param {object} params JSON parameters.
245
- * @param {string} [params.type] Principal type to look for, one of: 'user', 'group' or 'role'. If not specified all principal types will be included.
246
- * @param {string} [params.idProvider] Key of the id provider to look for. If not specified all id providers will be included.
247
- * @param {number} [params.start=0] First principal to return from the search results. It can be used for pagination.
248
- * @param {number} [params.count=10] A limit on the number of principals to be returned.
249
- * @param {string} [params.name] Name of the principal to look for.
250
- * @param {string} [params.searchText] Text to look for in any principal field.
251
- * @returns {FindPrincipalsResult} The "total" number of principals matching the search, the "count" of principals included, and an array of "hits" containing the principals.
252
- */
253
- export declare function findPrincipals(params: FindPrincipalsParams): FindPrincipalsResult;
254
- /**
255
- * Deletes the principal with the specified key.
256
- *
257
- * @example-ref examples/auth/deletePrincipal.js
258
- *
259
- * @param {string} principalKey Principal key to delete.
260
- * @returns {boolean} True if deleted, false otherwise.
261
- */
262
- export declare function deletePrincipal(principalKey: string): boolean;
263
- /**
264
- * This function returns the ID provider configuration.
265
- * It is meant to be called from an ID provider controller.
266
- *
267
- * @example-ref examples/auth/getIdProviderConfig.js
268
- *
269
- * @returns {object} The ID provider configuration as JSON.
270
- */
271
- export declare function getIdProviderConfig(): Record<string, unknown>;
272
- export interface GetProfileParams {
273
- key: string;
274
- scope?: string;
275
- }
276
- /**
277
- * This function retrieves the profile of a user.
278
- *
279
- * @example-ref examples/auth/getProfile.js
280
- *
281
- * @param {object} params JSON parameters.
282
- * @param {string} params.key Principal key of the user.
283
- * @param {string} [params.scope] Scope of the data to retrieve.
284
- * @returns {object} The extra data as JSON
285
- */
286
- export declare function getProfile(params: GetProfileParams): Record<string, unknown>;
287
- export interface ModifyProfileParams {
288
- key: string;
289
- scope?: string | null;
290
- editor: EditorFn<User>;
291
- }
292
- /**
293
- * This function retrieves the profile of a user and updates it.
294
- *
295
- * @example-ref examples/auth/modifyProfile.js
296
- *
297
- * @param {object} params JSON parameters.
298
- * @param {string} params.key Principal key of the user.
299
- * @param {string} [params.scope] Scope of the data to retrieve and update.
300
- * @param {function} params.editor Profile editor function to apply.
301
- * @returns {object} The extra data as JSON
302
- */
303
- export declare function modifyProfile(params: ModifyProfileParams): Record<string, unknown> | null;
304
- export interface FindUsersParams {
305
- start?: number;
306
- count?: number;
307
- query: string;
308
- sort?: string;
309
- includeProfile?: boolean;
310
- }
311
- /**
312
- * Search for users matching the specified query.
313
- *
314
- * @example-ref examples/auth/findUsers.js
315
- *
316
- * @param {object} params JSON with the parameters.
317
- * @param {number} [params.start=0] Start index (used for paging).
318
- * @param {number} [params.count=10] Number of contents to fetch.
319
- * @param {string} params.query Query expression.
320
- * @param {string} [params.sort] Sorting expression.
321
- * @param {boolean} [params.includeProfile=false] Include profile.
322
- *
323
- * @returns {FindPrincipalsResult} Result of query.
324
- */
325
- export declare function findUsers(params: FindUsersParams): FindPrincipalsResult;
326
- export interface CreateRoleParams {
327
- name: string;
328
- displayName: string;
329
- description: string;
330
- }
331
- /**
332
- * Creates a role.
333
- *
334
- * @example-ref examples/auth/createRole.js
335
- *
336
- * @param {string} params.name Role name.
337
- * @param {string} [params.displayName] Role display name.
338
- * @param {string} [params.description] as principal description .
339
- */
340
- export declare function createRole(params: CreateRoleParams): Role;
341
- export interface ModifyRoleParams {
342
- key: string;
343
- editor: EditorFn<Role>;
344
- }
345
- /**
346
- * Retrieves the role specified and updates it with the changes applied.
347
- *
348
- * @example-ref examples/auth/modifyRole.js
349
- *
350
- * @param {object} params JSON parameters.
351
- * @param {string} params.key Principal key of the role to modify.
352
- * @param {function} params.editor Role editor function to apply to role.
353
- * @returns {Role} the updated role or null if a role not found.
354
- */
355
- export declare function modifyRole(params: ModifyRoleParams): Role | null;
1
+ /**
2
+ * Built-in authentication functions.
3
+ *
4
+ * @example
5
+ * var authLib = require('/lib/xp/auth');
6
+ *
7
+ * @module auth
8
+ */
9
+ declare global {
10
+ interface XpLibraries {
11
+ '/lib/xp/auth': typeof import('./auth');
12
+ }
13
+ }
14
+ import type { Group, GroupKey, Principal, PrincipalKey, Role, RoleKey, User, UserKey } from '@enonic-types/core';
15
+ export type { PrincipalKey, UserKey, GroupKey, RoleKey, Principal, User, Group, Role } from '@enonic-types/core';
16
+ export declare type LoginScopeType = 'SESSION' | 'REQUEST' | 'NONE';
17
+ export interface UserWithProfile<Profile extends Record<string, unknown> = Record<string, unknown>> extends User {
18
+ profile?: Profile;
19
+ }
20
+ export interface LoginParams {
21
+ user: string;
22
+ skipAuth?: boolean;
23
+ password?: string;
24
+ idProvider?: string;
25
+ scope?: LoginScopeType;
26
+ sessionTimeout?: number;
27
+ }
28
+ export interface LoginResult {
29
+ authenticated: boolean;
30
+ message: string;
31
+ user?: User;
32
+ }
33
+ /**
34
+ * Login a user with the specified idProvider, userName, password and scope.
35
+ *
36
+ * @example-ref examples/auth/login.js
37
+ *
38
+ * @param {object} params JSON parameters.
39
+ * @param {string} params.user Name of user to log in.
40
+ * @param {string} [params.idProvider] Name of id provider where the user is stored. If not specified it will try all available id providers, in alphabetical order.
41
+ * @param {string} [params.password] Password for the user. Ignored if skipAuth is set to true, mandatory otherwise.
42
+ * @param {('SESSION'|'REQUEST'|'NONE')} [params.scope=SESSION] The scope of this login. Two values are valid. SESSION logs the user in and creates a session in XP for use in future requests. REQUEST logs the user in but only for this particular request and thus does not create a session.
43
+ * @param {boolean} [params.skipAuth=false] Skip authentication.
44
+ * @param {number} [params.sessionTimeout] Session timeout (in seconds). By default, the value of session.timeout from com.enonic.xp.web.jetty.cfg
45
+ * @returns {LoginResult} Information for logged-in user.
46
+ */
47
+ export declare function login(params: LoginParams): LoginResult;
48
+ /**
49
+ * Logout an already logged-in user.
50
+ *
51
+ * @example-ref examples/auth/logout.js
52
+ */
53
+ export declare function logout(): void;
54
+ export interface GetUserParams {
55
+ includeProfile?: boolean;
56
+ }
57
+ /**
58
+ * Returns the logged-in user. If not logged-in, this will return *undefined*.
59
+ *
60
+ * @example-ref examples/auth/getUser.js
61
+ *
62
+ * @param {object} [params] JSON parameters.
63
+ * @param {boolean} [params.includeProfile=false] Include profile.
64
+ *
65
+ * @returns {User} Information for logged-in user.
66
+ */
67
+ export declare function getUser(params?: {
68
+ includeProfile?: false;
69
+ }): User | null;
70
+ export declare function getUser<Profile extends Record<string, unknown> = Record<string, unknown>>(params: {
71
+ includeProfile: true;
72
+ }): UserWithProfile<Profile> | null;
73
+ /**
74
+ * Checks if the logged-in user has the specified role.
75
+ *
76
+ * @example-ref examples/auth/hasRole.js
77
+ *
78
+ * @param {string} role Role name to check for.
79
+ * @returns {boolean} True if the user has specified role, false otherwise.
80
+ */
81
+ export declare function hasRole(role: string): boolean;
82
+ /**
83
+ * Generates a secure password.
84
+ *
85
+ * @example-ref examples/auth/generatePassword.js
86
+ *
87
+ * @returns {string} A secure generated password.
88
+ */
89
+ export declare function generatePassword(): string;
90
+ export interface ChangePasswordParams {
91
+ userKey: string;
92
+ password: string;
93
+ }
94
+ /**
95
+ * Changes password for specified user.
96
+ *
97
+ * @example-ref examples/auth/changePassword.js
98
+ *
99
+ * @param {object} params JSON parameters.
100
+ * @param {string} params.userKey Key for user to change password.
101
+ * @param {string} params.password New password to set.
102
+ */
103
+ export declare function changePassword(params: ChangePasswordParams): void;
104
+ /**
105
+ * Returns the principal with the specified key.
106
+ *
107
+ * @example-ref examples/auth/getPrincipal.js
108
+ *
109
+ * @param {string} principalKey Principal key to look for.
110
+ * @returns {User | Group | Role} the principal specified, or null if it doesn't exist.
111
+ */
112
+ export declare function getPrincipal(principalKey: PrincipalKey): Principal | null;
113
+ /**
114
+ * Returns a list of principals the specified principal is a member of.
115
+ *
116
+ * @example-ref examples/auth/getMemberships.js
117
+ *
118
+ * @param {string} principalKey Principal key of user or group to retrieve memberships for.
119
+ * @param {boolean} [transitive=false] Retrieve transitive memberships.
120
+ * @returns {Array<Group | Role>} Returns the list of groups and roles.
121
+ */
122
+ export declare function getMemberships(principalKey: UserKey | GroupKey, transitive?: boolean): (Group | Role)[];
123
+ /**
124
+ * Returns a list of principals that are members of the specified principal.
125
+ *
126
+ * @example-ref examples/auth/getMembers.js
127
+ *
128
+ * @param {string} principalKey Principal key to retrieve members for.
129
+ * @returns {Array<User | Group>} Returns the list of users and groups.
130
+ */
131
+ export declare function getMembers(principalKey: GroupKey | RoleKey): (User | Group)[];
132
+ export interface CreateUserParams {
133
+ name: string;
134
+ displayName?: string;
135
+ idProvider: string;
136
+ email?: string;
137
+ }
138
+ /**
139
+ * Creates user from passed parameters.
140
+ *
141
+ * @example-ref examples/auth/createUser.js
142
+ *
143
+ * @param {object} params JSON parameters.
144
+ * @param {string} params.idProvider Key for id provider where user has to be created.
145
+ * @param {string} params.name User login name to set.
146
+ * @param {string} [params.displayName] User display name.
147
+ * @param {string} [params.email] User email.
148
+ */
149
+ export declare function createUser(params: CreateUserParams): User;
150
+ export interface ModifyUserParams {
151
+ key: UserKey;
152
+ editor: (user: User) => User;
153
+ }
154
+ /**
155
+ * Retrieves the user specified and updates it with the changes applied.
156
+ *
157
+ * @example-ref examples/auth/modifyUser.js
158
+ *
159
+ * @param {object} params JSON parameters.
160
+ * @param {string} params.key Principal key of the user to modify.
161
+ * @param {function} params.editor User editor function to apply to user.
162
+ * @returns {User} the updated user or null if a user not found.
163
+ */
164
+ export declare function modifyUser(params: ModifyUserParams): User | null;
165
+ export interface CreateGroupParams {
166
+ idProvider: string;
167
+ name: string;
168
+ displayName?: string;
169
+ description?: string;
170
+ }
171
+ /**
172
+ * Creates a group.
173
+ *
174
+ * @example-ref examples/auth/createGroup.js
175
+ *
176
+ * @param {object} params JSON parameters.
177
+ * @param {string} params.idProvider Key for id provider where group has to be created.
178
+ * @param {string} params.name Group name.
179
+ * @param {string} [params.displayName] Group display name.
180
+ * @param {string} [params.description] as principal description .
181
+ */
182
+ export declare function createGroup(params: CreateGroupParams): Group;
183
+ export interface ModifyGroupParams {
184
+ key: GroupKey;
185
+ editor: (group: Group) => Group;
186
+ }
187
+ /**
188
+ * Retrieves the group specified and updates it with the changes applied.
189
+ *
190
+ * @example-ref examples/auth/modifyGroup.js
191
+ *
192
+ * @param {object} params JSON parameters.
193
+ * @param {string} params.key Principal key of the group to modify.
194
+ * @param {function} params.editor Group editor function to apply to group.
195
+ * @returns {Group} the updated group or null if a group not found.
196
+ */
197
+ export declare function modifyGroup(params: ModifyGroupParams): Group | null;
198
+ /**
199
+ * Adds members to a principal (user or role).
200
+ *
201
+ * @example-ref examples/auth/addMembers.js
202
+ *
203
+ * @param {string} principalKey Key of the principal to add members to.
204
+ * @param {Array<string>} members Keys of users and groups to add.
205
+ */
206
+ export declare function addMembers(principalKey: GroupKey | RoleKey, members: (UserKey | GroupKey)[]): void;
207
+ /**
208
+ * Removes members from a principal (user or role).
209
+ *
210
+ * @example-ref examples/auth/removeMembers.js
211
+ *
212
+ * @param {string} principalKey Key of the principal to remove members from.
213
+ * @param {string} members Keys of the principals to remove.
214
+ */
215
+ export declare function removeMembers(principalKey: GroupKey | RoleKey, members: (UserKey | GroupKey)[]): void;
216
+ export interface FindPrincipalsParams {
217
+ type?: Principal['type'];
218
+ idProvider?: string;
219
+ start?: number;
220
+ count?: number;
221
+ name?: string;
222
+ searchText?: string;
223
+ }
224
+ export interface FindPrincipalsResult<P extends Principal = Principal> {
225
+ total: number;
226
+ count: number;
227
+ hits: P[];
228
+ }
229
+ /**
230
+ * Search for principals matching the specified criteria.
231
+ *
232
+ * @example-ref examples/auth/findPrincipals.js
233
+ *
234
+ * @param {object} params JSON parameters.
235
+ * @param {string} [params.type] Principal type to look for, one of: 'user', 'group' or 'role'. If not specified all principal types will be included.
236
+ * @param {string} [params.idProvider] Key of the id provider to look for. If not specified all id providers will be included.
237
+ * @param {number} [params.start=0] First principal to return from the search results. It can be used for pagination.
238
+ * @param {number} [params.count=10] A limit on the number of principals to be returned.
239
+ * @param {string} [params.name] Name of the principal to look for.
240
+ * @param {string} [params.searchText] Text to look for in any principal field.
241
+ * @returns {FindPrincipalsResult} The "total" number of principals matching the search, the "count" of principals included, and an array of "hits" containing the principals.
242
+ */
243
+ export declare function findPrincipals(params: FindPrincipalsParams): FindPrincipalsResult;
244
+ /**
245
+ * Deletes the principal with the specified key.
246
+ *
247
+ * @example-ref examples/auth/deletePrincipal.js
248
+ *
249
+ * @param {string} principalKey Principal key to delete.
250
+ * @returns {boolean} True if deleted, false otherwise.
251
+ */
252
+ export declare function deletePrincipal(principalKey: PrincipalKey): boolean;
253
+ /**
254
+ * This function returns the ID provider configuration.
255
+ * It is meant to be called from an ID provider controller.
256
+ *
257
+ * @example-ref examples/auth/getIdProviderConfig.js
258
+ *
259
+ * @returns {object} The ID provider configuration as JSON.
260
+ */
261
+ export declare function getIdProviderConfig<IdProviderConfig extends Record<string, unknown>>(): IdProviderConfig | null;
262
+ export interface GetProfileParams {
263
+ key: UserKey;
264
+ scope?: string;
265
+ }
266
+ /**
267
+ * This function retrieves the profile of a user.
268
+ *
269
+ * @example-ref examples/auth/getProfile.js
270
+ *
271
+ * @param {object} params JSON parameters.
272
+ * @param {string} params.key Principal key of the user.
273
+ * @param {string} [params.scope] Scope of the data to retrieve.
274
+ * @returns {object} The extra data as JSON
275
+ */
276
+ export declare function getProfile<Profile extends Record<string, unknown> = Record<string, unknown>>(params: GetProfileParams): Profile | null;
277
+ export interface ModifyProfileParams {
278
+ key: UserKey;
279
+ scope?: string | null;
280
+ editor: (user: User) => User;
281
+ }
282
+ /**
283
+ * This function retrieves the profile of a user and updates it.
284
+ *
285
+ * @example-ref examples/auth/modifyProfile.js
286
+ *
287
+ * @param {object} params JSON parameters.
288
+ * @param {string} params.key Principal key of the user.
289
+ * @param {string} [params.scope] Scope of the data to retrieve and update.
290
+ * @param {function} params.editor Profile editor function to apply.
291
+ * @returns {object} The extra data as JSON
292
+ */
293
+ export declare function modifyProfile<Profile extends Record<string, unknown> = Record<string, unknown>>(params: ModifyProfileParams): Profile | null;
294
+ export interface FindUsersParams {
295
+ start?: number;
296
+ count?: number;
297
+ query: string;
298
+ sort?: string;
299
+ includeProfile?: boolean;
300
+ }
301
+ /**
302
+ * Search for users matching the specified query.
303
+ *
304
+ * @example-ref examples/auth/findUsers.js
305
+ *
306
+ * @param {object} params JSON with the parameters.
307
+ * @param {number} [params.start=0] Start index (used for paging).
308
+ * @param {number} [params.count=10] Number of contents to fetch.
309
+ * @param {string} params.query Query expression.
310
+ * @param {string} [params.sort] Sorting expression.
311
+ * @param {boolean} [params.includeProfile=false] Include profile.
312
+ *
313
+ * @returns {FindPrincipalsResult} Result of query.
314
+ */
315
+ export declare function findUsers(params: FindUsersParams & {
316
+ includeProfile?: false;
317
+ }): FindPrincipalsResult<User>;
318
+ export declare function findUsers<Profile extends Record<string, unknown> = Record<string, unknown>>(params: FindUsersParams & {
319
+ includeProfile: true;
320
+ }): FindPrincipalsResult<UserWithProfile<Profile>>;
321
+ export interface CreateRoleParams {
322
+ name: string;
323
+ displayName?: string;
324
+ description?: string;
325
+ }
326
+ /**
327
+ * Creates a role.
328
+ *
329
+ * @example-ref examples/auth/createRole.js
330
+ *
331
+ * @param {string} params.name Role name.
332
+ * @param {string} [params.displayName] Role display name.
333
+ * @param {string} [params.description] as principal description .
334
+ */
335
+ export declare function createRole(params: CreateRoleParams): Role;
336
+ export interface ModifyRoleParams {
337
+ key: RoleKey;
338
+ editor: (role: Role) => Role;
339
+ }
340
+ /**
341
+ * Retrieves the role specified and updates it with the changes applied.
342
+ *
343
+ * @example-ref examples/auth/modifyRole.js
344
+ *
345
+ * @param {object} params JSON parameters.
346
+ * @param {string} params.key Principal key of the role to modify.
347
+ * @param {function} params.editor Role editor function to apply to role.
348
+ * @returns {Role} the updated role or null if a role not found.
349
+ */
350
+ export declare function modifyRole(params: ModifyRoleParams): Role | null;
package/package.json CHANGED
@@ -1,32 +1,35 @@
1
- {
2
- "name": "@enonic-types/lib-auth",
3
- "version": "0.1.1",
4
- "description": "Type definitions for lib-auth.",
5
- "types": "auth.d.ts",
6
- "files": [
7
- "auth.d.ts"
8
- ],
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/enonic/xp.git#master"
12
- },
13
- "keywords": [
14
- "enonic",
15
- "enonic-xp",
16
- "lib-auth",
17
- "auth",
18
- "types",
19
- "typescript"
20
- ],
21
- "contributors": [
22
- "Mikita Taukachou <edloidas@gmail.com> (https://edloidas.github.io/)"
23
- ],
24
- "license": "Apache-2.0",
25
- "bugs": {
26
- "url": "https://github.com/enonic/xp/issues"
27
- },
28
- "homepage": "https://github.com/enonic/xp/tree/master#readme",
29
- "publishConfig": {
30
- "access": "public"
31
- }
32
- }
1
+ {
2
+ "name": "@enonic-types/lib-auth",
3
+ "version": "7.11.0-B3",
4
+ "description": "Type definitions for lib-auth.",
5
+ "types": "auth.d.ts",
6
+ "files": [
7
+ "auth.d.ts"
8
+ ],
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/enonic/xp.git#master"
12
+ },
13
+ "keywords": [
14
+ "enonic",
15
+ "enonic-xp",
16
+ "lib-auth",
17
+ "auth",
18
+ "types",
19
+ "typescript"
20
+ ],
21
+ "contributors": [
22
+ "Mikita Taukachou <edloidas@gmail.com> (https://edloidas.github.io/)"
23
+ ],
24
+ "license": "Apache-2.0",
25
+ "bugs": {
26
+ "url": "https://github.com/enonic/xp/issues"
27
+ },
28
+ "homepage": "https://github.com/enonic/xp/tree/master#readme",
29
+ "dependencies": {
30
+ "@enonic-types/core": "7.11.0-B3"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ }
35
+ }