@magda/authentication-plugin-sdk 2.3.3 → 3.0.0-alpha.0
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/dist/index.d.ts +334 -25
- package/dist/index.js +41689 -47100
- package/package.json +27 -17
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,147 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CookieOptions as CookieOptions_3 } from 'express';
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import passport from 'passport';
|
|
4
4
|
import { QueryDataMap } from 'urijs';
|
|
5
5
|
import { Request as Request_2 } from 'express';
|
|
6
6
|
import { Response as Response_2 } from 'express';
|
|
7
7
|
import { Router } from 'express';
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
declare class ApiClient {
|
|
10
|
+
private jwt;
|
|
11
|
+
private requestInitOption;
|
|
12
|
+
private baseUrl;
|
|
13
|
+
constructor(baseUrl: string, jwtSecret?: string, userId?: string);
|
|
14
|
+
getMergeRequestInitOption(extraOptions?: RequestInit): RequestInit;
|
|
15
|
+
processJsonResponse<T = any>(res: Response): Promise<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Get the data of a user.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} userId
|
|
20
|
+
* @returns {Promise<Maybe<User>>}
|
|
21
|
+
* @memberof ApiClient
|
|
22
|
+
*/
|
|
23
|
+
getUser(userId: string): Promise<Maybe<RequiredKeys<User, "id">>>;
|
|
24
|
+
/**
|
|
25
|
+
* Lookup user by source (identity provider) & sourceId (identity ID)
|
|
26
|
+
*
|
|
27
|
+
* @param {string} source
|
|
28
|
+
* @param {string} sourceId
|
|
29
|
+
* @returns {Promise<Maybe<User>>}
|
|
30
|
+
* @memberof ApiClient
|
|
31
|
+
*/
|
|
32
|
+
lookupUser(source: string, sourceId: string): Promise<Maybe<RequiredKeys<User, "id">>>;
|
|
33
|
+
/**
|
|
34
|
+
* create a user
|
|
35
|
+
*
|
|
36
|
+
* @param {CreateUserData} user
|
|
37
|
+
* @returns {Promise<UserRecord>}
|
|
38
|
+
* @memberof ApiClient
|
|
39
|
+
*/
|
|
40
|
+
createUser(user: CreateUserData): Promise<UserRecord>;
|
|
41
|
+
/**
|
|
42
|
+
* Add Roles to a user.
|
|
43
|
+
* Returns a list of current role ids of the user.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} userId
|
|
46
|
+
* @param {string[]} roleIds
|
|
47
|
+
* @returns {Promise<string[]>}
|
|
48
|
+
* @memberof ApiClient
|
|
49
|
+
*/
|
|
50
|
+
addUserRoles(userId: string, roleIds: string[]): Promise<string[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Remove a list roles from a user.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} userId
|
|
55
|
+
* @param {string[]} roleIds
|
|
56
|
+
* @returns {Promise<void>}
|
|
57
|
+
* @memberof ApiClient
|
|
58
|
+
*/
|
|
59
|
+
deleteUserRoles(userId: string, roleIds: string[]): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Get all roles of a user
|
|
62
|
+
*
|
|
63
|
+
* @param {string} userId
|
|
64
|
+
* @returns {Promise<Role[]>}
|
|
65
|
+
* @memberof ApiClient
|
|
66
|
+
*/
|
|
67
|
+
getUserRoles(userId: string): Promise<Role[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Get all permissions of a user
|
|
70
|
+
*
|
|
71
|
+
* @param {string} userId
|
|
72
|
+
* @returns {Promise<Permission[]>}
|
|
73
|
+
* @memberof ApiClient
|
|
74
|
+
*/
|
|
75
|
+
getUserPermissions(userId: string): Promise<Permission[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Get all permissions of a role
|
|
78
|
+
*
|
|
79
|
+
* @param {string} roleId
|
|
80
|
+
* @returns {Promise<Permission[]>}
|
|
81
|
+
* @memberof ApiClient
|
|
82
|
+
*/
|
|
83
|
+
getRolePermissions(roleId: string): Promise<Permission[]>;
|
|
84
|
+
/**
|
|
85
|
+
* List OrgUnits at certain org tree level.
|
|
86
|
+
* Optionally provide a test Org Unit Id that will be used to test the relationship with each of returned orgUnit item.
|
|
87
|
+
* Possible Value: 'ancestor', 'descendant', 'equal', 'unrelated'
|
|
88
|
+
*
|
|
89
|
+
* @param {string} orgLevel The level number (starts from 1) where org Units of the tree are taken horizontally.
|
|
90
|
+
* @param {string} [relationshipOrgUnitId] Optional; The org unit id that is used to test the relationship with each of returned orgUnit item.
|
|
91
|
+
* @returns {Promise<OrgUnit[]>}
|
|
92
|
+
* @memberof ApiClient
|
|
93
|
+
*/
|
|
94
|
+
getOrgUnitsByLevel(orgLevel: number, relationshipOrgUnitId?: string): Promise<OrgUnit[]>;
|
|
95
|
+
/**
|
|
96
|
+
* Get orgunits by name
|
|
97
|
+
*
|
|
98
|
+
* @param {string} nodeName
|
|
99
|
+
* @param {boolean} [leafNodesOnly=false] Whether only leaf nodes should be returned
|
|
100
|
+
* @param {string} [relationshipOrgUnitId] Optional; The org unit id that is used to test the relationship with each of returned orgUnit item.
|
|
101
|
+
* @returns {Promise<OrgUnit[]>}
|
|
102
|
+
* @memberof ApiClient
|
|
103
|
+
*/
|
|
104
|
+
getOrgUnitsByName(nodeName: string, leafNodesOnly?: boolean, relationshipOrgUnitId?: string): Promise<OrgUnit[]>;
|
|
105
|
+
/**
|
|
106
|
+
* Gets the root organisation unit (top of the tree).
|
|
107
|
+
*
|
|
108
|
+
* @returns {Promise<OrgUnit>}
|
|
109
|
+
* @memberof ApiClient
|
|
110
|
+
*/
|
|
111
|
+
getRootOrgUnit(): Promise<OrgUnit>;
|
|
112
|
+
/**
|
|
113
|
+
* Gets the details of the node with its id.
|
|
114
|
+
*
|
|
115
|
+
* @param {string} nodeId
|
|
116
|
+
* @returns {Promise<OrgUnit>}
|
|
117
|
+
* @memberof ApiClient
|
|
118
|
+
*/
|
|
119
|
+
getOrgUnitById(nodeId: string): Promise<OrgUnit>;
|
|
120
|
+
/**
|
|
121
|
+
* Gets all the children immediately below the requested node. If the node doesn't exist, returns an empty list.
|
|
122
|
+
*
|
|
123
|
+
* @param {string} nodeId
|
|
124
|
+
* @returns {Promise<OrgUnit[]>}
|
|
125
|
+
* @memberof ApiClient
|
|
126
|
+
*/
|
|
127
|
+
getImmediateOrgUnitChildren(nodeId: string): Promise<OrgUnit[]>;
|
|
128
|
+
/**
|
|
129
|
+
* Gets all the children below the requested node recursively. If node doesn't exist, returns an empty list.
|
|
130
|
+
*
|
|
131
|
+
* @param {string} nodeId
|
|
132
|
+
* @returns {Promise<OrgUnit[]>}
|
|
133
|
+
* @memberof ApiClient
|
|
134
|
+
*/
|
|
135
|
+
getAllOrgUnitChildren(nodeId: string): Promise<OrgUnit[]>;
|
|
136
|
+
createOrgNode(parentNodeId: string, node: Partial<Omit<OrgUnitRecord, "id" | "createBy" | "createTime" | "editBy" | "editTime" | "left" | "right">>): Promise<OrgUnit>;
|
|
137
|
+
createRole(name: string, desc?: string): Promise<Role>;
|
|
138
|
+
createRolePermission(roleId: string, permissionData: CreateRolePermissionInputData): Promise<PermissionRecord>;
|
|
139
|
+
createPermission(permissionData: CreateRolePermissionInputData): Promise<PermissionRecord>;
|
|
140
|
+
updatePermission(id: string, permissionData: UpdateRolePermissionInputData): Promise<PermissionRecord>;
|
|
141
|
+
getOperationByUri(opUri: string): Promise<OperationRecord>;
|
|
142
|
+
getResourceByUri(resUri: string): Promise<ResourceRecord>;
|
|
143
|
+
private handleGetResult;
|
|
144
|
+
}
|
|
10
145
|
|
|
11
146
|
/**
|
|
12
147
|
* Different type of AuthenticationMethod:
|
|
@@ -43,18 +178,7 @@ export declare interface AuthPluginConfig extends Omit<AuthPluginBasicConfig, "b
|
|
|
43
178
|
|
|
44
179
|
export declare type CookieOptions = CookieOptions_2;
|
|
45
180
|
|
|
46
|
-
|
|
47
|
-
declare type CookieOptions_2 = {
|
|
48
|
-
maxAge?: number;
|
|
49
|
-
signed?: boolean;
|
|
50
|
-
expires?: Date;
|
|
51
|
-
httpOnly?: boolean;
|
|
52
|
-
path?: string;
|
|
53
|
-
domain?: string;
|
|
54
|
-
secure?: boolean | "auto";
|
|
55
|
-
encode?: (val: string) => string;
|
|
56
|
-
sameSite?: boolean | "lax" | "strict" | "none";
|
|
57
|
-
};
|
|
181
|
+
declare type CookieOptions_2 = CookieOptions_3;
|
|
58
182
|
|
|
59
183
|
/**
|
|
60
184
|
* Create an express router that can be used to enable session on an express application.
|
|
@@ -75,20 +199,20 @@ export declare function createMagdaSessionRouter(options: MagdaSessionRouterOpti
|
|
|
75
199
|
* @param {passport.Profile} profile
|
|
76
200
|
* @param {string} source
|
|
77
201
|
* @param {(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
202
|
+
* authApiClient: AuthApiClient,
|
|
203
|
+
* userData: User,
|
|
204
|
+
* profile: passport.Profile
|
|
205
|
+
* ) => Promise<User>} [beforeUserCreated] an optional handler that will be called just before a user is created.
|
|
82
206
|
* The user data returned by this handler will be used to create the user record. The following parameters will be provided to the handler:
|
|
83
207
|
* - authApiClient: Auth API Client. You can use it to add a role to the user.
|
|
84
208
|
* - userData: the user data that is converted from the user profile received using the default conversion logic.
|
|
85
209
|
* - profile: the user profile received
|
|
86
210
|
*
|
|
87
211
|
* @param {(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
212
|
+
* authApiClient: AuthApiClient,
|
|
213
|
+
* user: User,
|
|
214
|
+
* profile: passport.Profile
|
|
215
|
+
* ) => Promise<void>} [afterUserCreated] an optional call that will be called when a user has just been created.
|
|
92
216
|
* The following parameters will be provided to the handler:
|
|
93
217
|
* - authApiClient: Auth API Client. You can use it to add a role to the user.
|
|
94
218
|
* - user: the user data of the magda user that is just created.
|
|
@@ -96,11 +220,21 @@ export declare function createMagdaSessionRouter(options: MagdaSessionRouterOpti
|
|
|
96
220
|
*
|
|
97
221
|
* @returns {Promise<UserToken>}
|
|
98
222
|
*/
|
|
99
|
-
export declare function createOrGetUserToken(authApi:
|
|
223
|
+
export declare function createOrGetUserToken(authApi: ApiClient, profile: passport.Profile, source: string, beforeUserCreated?: (authApiClient: ApiClient, userData: User, profile: passport.Profile) => Promise<User>, afterUserCreated?: (authApiClient: ApiClient, user: User, profile: passport.Profile) => Promise<void>): Promise<UserToken>;
|
|
224
|
+
|
|
225
|
+
declare interface CreateRolePermissionInputData extends Omit<PermissionRecord, "id" | "owner_id" | "create_by" | "create_time" | "edit_by" | "edit_time" | "allow_exemption" | "resource_id"> {
|
|
226
|
+
operationIds?: string[];
|
|
227
|
+
operationUris?: string[];
|
|
228
|
+
resource_id?: string;
|
|
229
|
+
resourceUri?: string;
|
|
230
|
+
allow_exemption?: boolean;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
declare type CreateUserData = Partial<Omit<UserRecord, "email" | "displayName" | "id">> & Pick<UserRecord, "displayName" | "email">;
|
|
100
234
|
|
|
101
235
|
export declare const DEFAULT_SESSION_COOKIE_NAME: string;
|
|
102
236
|
|
|
103
|
-
export declare const DEFAULT_SESSION_COOKIE_OPTIONS:
|
|
237
|
+
export declare const DEFAULT_SESSION_COOKIE_OPTIONS: CookieOptions_3;
|
|
104
238
|
|
|
105
239
|
export declare const deleteCookie: typeof deleteCookie_2;
|
|
106
240
|
|
|
@@ -129,6 +263,16 @@ export declare const destroySession: typeof destroySession_2;
|
|
|
129
263
|
*/
|
|
130
264
|
declare function destroySession_2(req: express.Request): Promise<void>;
|
|
131
265
|
|
|
266
|
+
declare interface Eq<T> {
|
|
267
|
+
equals(t: T): boolean;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
declare interface Functor<T> {
|
|
271
|
+
fmap<U>(f: (t: T) => U): Functor<U>;
|
|
272
|
+
lift<U>(f: (t: T) => U): Functor<U>;
|
|
273
|
+
map<U>(f: (t: T) => U): Functor<U>;
|
|
274
|
+
}
|
|
275
|
+
|
|
132
276
|
/**
|
|
133
277
|
* Join `url` with `baseUrl` if `url` is not an absolute (full) url string
|
|
134
278
|
*
|
|
@@ -153,10 +297,175 @@ export declare type MagdaSessionRouterOptions = {
|
|
|
153
297
|
sessionDBName?: string;
|
|
154
298
|
};
|
|
155
299
|
|
|
300
|
+
declare class Maybe<T> implements Monad<T>, Functor<T>, Eq<Maybe<T>> {
|
|
301
|
+
private type;
|
|
302
|
+
private value?;
|
|
303
|
+
constructor(type: MaybeType, value?: T);
|
|
304
|
+
static sequence<T>(t: {
|
|
305
|
+
[k: string]: Maybe<T>;
|
|
306
|
+
}): Maybe<{
|
|
307
|
+
[k: string]: T;
|
|
308
|
+
}>;
|
|
309
|
+
static all: (t: {
|
|
310
|
+
[k: string]: Maybe<any>;
|
|
311
|
+
}) => Maybe<{
|
|
312
|
+
[k: string]: any;
|
|
313
|
+
}>;
|
|
314
|
+
static maybe<T>(t?: T | null): Maybe<T>;
|
|
315
|
+
static just<T>(t: T): Maybe<T>;
|
|
316
|
+
static nothing<T>(): Maybe<T>;
|
|
317
|
+
static isJust<T>(t: Maybe<T>): boolean;
|
|
318
|
+
static isNothing<T>(t: Maybe<T>): boolean;
|
|
319
|
+
unit<U>(u: U): Maybe<U>;
|
|
320
|
+
bind<U>(f: (t: T) => Maybe<U>): Maybe<U>;
|
|
321
|
+
of: <U>(u: U) => Maybe<U>;
|
|
322
|
+
chain: <U>(f: (t: T) => Maybe<U>) => Maybe<U>;
|
|
323
|
+
fmap<U>(f: (t: T) => U): Maybe<U>;
|
|
324
|
+
lift: <U>(f: (t: T) => U) => Maybe<U>;
|
|
325
|
+
map: <U>(f: (t: T) => U) => Maybe<U>;
|
|
326
|
+
caseOf<U>(patterns: MaybePatterns<T, U>): U;
|
|
327
|
+
defaulting(defaultValue: T): Maybe<T>;
|
|
328
|
+
equals(other: Maybe<T>): any;
|
|
329
|
+
valueOr<U extends T>(defaultValue: U): T | U;
|
|
330
|
+
valueOrCompute<U extends T>(defaultValueFunction: () => U): T | U;
|
|
331
|
+
valueOrThrow(error?: Error): T;
|
|
332
|
+
do(patterns?: Partial<MaybePatterns<T, void>>): Maybe<T>;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
declare interface MaybePatterns<T, U> {
|
|
336
|
+
just: (t: T) => U;
|
|
337
|
+
nothing: () => U;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
declare enum MaybeType {
|
|
341
|
+
Nothing = 0,
|
|
342
|
+
Just = 1
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
declare interface Monad<T> {
|
|
346
|
+
unit<U>(t: U): Monad<U>;
|
|
347
|
+
bind<U>(f: (t: T) => Monad<U>): Monad<U>;
|
|
348
|
+
of<U>(t: U): Monad<U>;
|
|
349
|
+
chain<U>(f: (t: T) => Monad<U>): Monad<U>;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
declare interface Operation {
|
|
353
|
+
id: string;
|
|
354
|
+
uri: string;
|
|
355
|
+
name: string;
|
|
356
|
+
description?: string;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
declare type OperationRecord = {
|
|
360
|
+
id: string;
|
|
361
|
+
uri: string;
|
|
362
|
+
name: string;
|
|
363
|
+
description: string;
|
|
364
|
+
resource_id: string;
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
declare type OrgUnit = Partial<OrgUnitRecord> & {
|
|
368
|
+
relationship?: OrgUnitRelationshipType;
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
declare interface OrgUnitRecord {
|
|
372
|
+
id: string;
|
|
373
|
+
name: string;
|
|
374
|
+
description: string;
|
|
375
|
+
left: number;
|
|
376
|
+
right: number;
|
|
377
|
+
createBy: string;
|
|
378
|
+
createTime: Date;
|
|
379
|
+
editBy: string;
|
|
380
|
+
editTime: Date;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
declare type OrgUnitRelationshipType = "ancestor" | "descendant" | "equal" | "unrelated";
|
|
384
|
+
|
|
385
|
+
declare interface Permission {
|
|
386
|
+
id: string;
|
|
387
|
+
name: string;
|
|
388
|
+
description?: string;
|
|
389
|
+
resourceId: string;
|
|
390
|
+
resourceUri: string;
|
|
391
|
+
userOwnershipConstraint: boolean;
|
|
392
|
+
orgUnitOwnershipConstraint: boolean;
|
|
393
|
+
preAuthorisedConstraint: boolean;
|
|
394
|
+
operations: Operation[];
|
|
395
|
+
createBy?: string;
|
|
396
|
+
createTime?: Date;
|
|
397
|
+
editBy?: string;
|
|
398
|
+
editTime?: Date;
|
|
399
|
+
allowExemption: boolean;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
declare interface PermissionRecord {
|
|
403
|
+
id: string;
|
|
404
|
+
name: string;
|
|
405
|
+
description: string;
|
|
406
|
+
resource_id: string;
|
|
407
|
+
user_ownership_constraint: boolean;
|
|
408
|
+
org_unit_ownership_constraint: boolean;
|
|
409
|
+
pre_authorised_constraint: boolean;
|
|
410
|
+
owner_id: string;
|
|
411
|
+
create_time: string;
|
|
412
|
+
create_by: string;
|
|
413
|
+
edit_time: string;
|
|
414
|
+
edit_by: string;
|
|
415
|
+
allow_exemption: boolean;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
declare type PublicUser = Partial<Pick<UserRecord, "id" | "photoURL" | "orgUnitId">> & Omit<UserRecord, "id" | "photoURL" | "orgUnitId" | "email" | "source" | "sourceId"> & {
|
|
419
|
+
roles?: Role[];
|
|
420
|
+
permissions?: Permission[];
|
|
421
|
+
managingOrgUnitIds?: string[];
|
|
422
|
+
orgUnit?: OrgUnit;
|
|
423
|
+
};
|
|
424
|
+
|
|
156
425
|
export declare function redirectOnError(err: any, toURL: string, req: Request_2, res: Response_2): void;
|
|
157
426
|
|
|
158
427
|
export declare function redirectOnSuccess(toURL: string, req: Request_2, res: Response_2): void;
|
|
159
428
|
|
|
429
|
+
declare type RequiredKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
430
|
+
|
|
431
|
+
declare type ResourceRecord = {
|
|
432
|
+
id: string;
|
|
433
|
+
uri: string;
|
|
434
|
+
name: string;
|
|
435
|
+
description: string;
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
declare interface Role {
|
|
439
|
+
id: string;
|
|
440
|
+
name: string;
|
|
441
|
+
permissionIds: string[];
|
|
442
|
+
description?: string;
|
|
443
|
+
createBy?: string;
|
|
444
|
+
createTime?: Date;
|
|
445
|
+
editBy?: string;
|
|
446
|
+
editTime?: Date;
|
|
447
|
+
}
|
|
448
|
+
|
|
160
449
|
export declare type SessionCookieOptions = CookieOptions_2;
|
|
161
450
|
|
|
451
|
+
declare interface UpdateRolePermissionInputData extends Partial<CreateRolePermissionInputData> {
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
declare type User = PublicUser & Pick<UserRecord, "email" | "source" | "sourceId">;
|
|
455
|
+
|
|
456
|
+
declare interface UserRecord {
|
|
457
|
+
id: string;
|
|
458
|
+
displayName: string;
|
|
459
|
+
photoURL: string;
|
|
460
|
+
isAdmin: boolean;
|
|
461
|
+
orgUnitId: string;
|
|
462
|
+
email: string;
|
|
463
|
+
source: string;
|
|
464
|
+
sourceId: string;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
declare interface UserToken {
|
|
468
|
+
id: string;
|
|
469
|
+
}
|
|
470
|
+
|
|
162
471
|
export { }
|