@magda/authentication-plugin-sdk 5.0.0-alpha.0 → 5.0.0-alpha.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.
Files changed (2) hide show
  1. package/dist/index.d.ts +5 -324
  2. package/package.json +3 -3
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import AuthApiClient from '@magda/auth-api-client';
1
2
  import { CookieOptions as CookieOptions_3 } from 'express';
2
3
  import express from 'express';
3
4
  import passport from 'passport';
@@ -5,147 +6,12 @@ import { QueryDataMap } from 'urijs';
5
6
  import { Request as Request_2 } from 'express';
6
7
  import { Response as Response_2 } from 'express';
7
8
  import { Router } from 'express';
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
- }
9
+ import { User } from '@magda/auth-api-client';
10
+ import { UserToken } from '@magda/auth-api-client';
145
11
 
146
12
  /**
147
13
  * Different type of AuthenticationMethod:
148
- * - IDP-URI-REDIRECTION: the plugin will rediredct user agent to idp (identity provider) for authentication. e.g. Google & fackebook oauth etc.
14
+ * - IDP-URI-REDIRECTION: the plugin will redirect user agent to idp (identity provider) for authentication. e.g. Google & fackebook oauth etc.
149
15
  * - This is the default method.
150
16
  * - PASSWORD: the plugin expect frontend do a form post that contains username & password to the plugin for authentication
151
17
  * - QR-CODE: the plugin offers a url that is used by the frontend to request auth challenge data. The data will be encoded into a QR-code image and expect the user scan the QR code with a mobile app to complete the authentication request.
@@ -220,17 +86,7 @@ export declare function createMagdaSessionRouter(options: MagdaSessionRouterOpti
220
86
  *
221
87
  * @returns {Promise<UserToken>}
222
88
  */
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">;
89
+ export declare function createOrGetUserToken(authApi: AuthApiClient, profile: passport.Profile, source: string, beforeUserCreated?: (authApiClient: AuthApiClient, userData: User, profile: passport.Profile) => Promise<User>, afterUserCreated?: (authApiClient: AuthApiClient, user: User, profile: passport.Profile) => Promise<void>): Promise<UserToken>;
234
90
 
235
91
  export declare const DEFAULT_SESSION_COOKIE_NAME: string;
236
92
 
@@ -263,16 +119,6 @@ export declare const destroySession: typeof destroySession_2;
263
119
  */
264
120
  declare function destroySession_2(req: express.Request): Promise<void>;
265
121
 
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
-
276
122
  /**
277
123
  * Join `url` with `baseUrl` if `url` is not an absolute (full) url string
278
124
  *
@@ -297,175 +143,10 @@ export declare type MagdaSessionRouterOptions = {
297
143
  sessionDBName?: string;
298
144
  };
299
145
 
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
-
425
146
  export declare function redirectOnError(err: any, toURL: string, req: Request_2, res: Response_2): void;
426
147
 
427
148
  export declare function redirectOnSuccess(toURL: string, req: Request_2, res: Response_2): void;
428
149
 
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
-
449
150
  export declare type SessionCookieOptions = CookieOptions_2;
450
151
 
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
-
471
152
  export { }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@magda/authentication-plugin-sdk",
3
3
  "description": "MAGDA Authentication Plugin SDK",
4
- "version": "5.0.0-alpha.0",
4
+ "version": "5.0.0-alpha.1",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": "./dist/index.js",
@@ -23,8 +23,8 @@
23
23
  "main": "dist/index.js",
24
24
  "types": "dist/index.d.ts",
25
25
  "devDependencies": {
26
- "@magda/auth-api-client": "^5.0.0-alpha.0",
27
- "@magda/typescript-common": "^5.0.0-alpha.0",
26
+ "@magda/auth-api-client": "^5.0.0-alpha.1",
27
+ "@magda/typescript-common": "^5.0.0-alpha.1",
28
28
  "@types/express-session": "^1.18.1",
29
29
  "@types/lodash": "^4.14.74",
30
30
  "@types/pg": "^8.6.5",