@magda/authentication-plugin-sdk
Advanced tools
Comparing version 2.3.3 to 3.0.0-alpha.0
@@ -1,2 +0,2 @@ | ||
import AuthApiClient from '@magda/auth-api-client'; | ||
import { CookieOptions as CookieOptions_3 } from 'express'; | ||
import express from 'express'; | ||
@@ -8,5 +8,140 @@ import passport from 'passport'; | ||
import { Router } from 'express'; | ||
import { User } from '@magda/auth-api-client'; | ||
import { UserToken } from '@magda/auth-api-client'; | ||
declare class ApiClient { | ||
private jwt; | ||
private requestInitOption; | ||
private baseUrl; | ||
constructor(baseUrl: string, jwtSecret?: string, userId?: string); | ||
getMergeRequestInitOption(extraOptions?: RequestInit): RequestInit; | ||
processJsonResponse<T = any>(res: Response): Promise<T>; | ||
/** | ||
* Get the data of a user. | ||
* | ||
* @param {string} userId | ||
* @returns {Promise<Maybe<User>>} | ||
* @memberof ApiClient | ||
*/ | ||
getUser(userId: string): Promise<Maybe<RequiredKeys<User, "id">>>; | ||
/** | ||
* Lookup user by source (identity provider) & sourceId (identity ID) | ||
* | ||
* @param {string} source | ||
* @param {string} sourceId | ||
* @returns {Promise<Maybe<User>>} | ||
* @memberof ApiClient | ||
*/ | ||
lookupUser(source: string, sourceId: string): Promise<Maybe<RequiredKeys<User, "id">>>; | ||
/** | ||
* create a user | ||
* | ||
* @param {CreateUserData} user | ||
* @returns {Promise<UserRecord>} | ||
* @memberof ApiClient | ||
*/ | ||
createUser(user: CreateUserData): Promise<UserRecord>; | ||
/** | ||
* Add Roles to a user. | ||
* Returns a list of current role ids of the user. | ||
* | ||
* @param {string} userId | ||
* @param {string[]} roleIds | ||
* @returns {Promise<string[]>} | ||
* @memberof ApiClient | ||
*/ | ||
addUserRoles(userId: string, roleIds: string[]): Promise<string[]>; | ||
/** | ||
* Remove a list roles from a user. | ||
* | ||
* @param {string} userId | ||
* @param {string[]} roleIds | ||
* @returns {Promise<void>} | ||
* @memberof ApiClient | ||
*/ | ||
deleteUserRoles(userId: string, roleIds: string[]): Promise<void>; | ||
/** | ||
* Get all roles of a user | ||
* | ||
* @param {string} userId | ||
* @returns {Promise<Role[]>} | ||
* @memberof ApiClient | ||
*/ | ||
getUserRoles(userId: string): Promise<Role[]>; | ||
/** | ||
* Get all permissions of a user | ||
* | ||
* @param {string} userId | ||
* @returns {Promise<Permission[]>} | ||
* @memberof ApiClient | ||
*/ | ||
getUserPermissions(userId: string): Promise<Permission[]>; | ||
/** | ||
* Get all permissions of a role | ||
* | ||
* @param {string} roleId | ||
* @returns {Promise<Permission[]>} | ||
* @memberof ApiClient | ||
*/ | ||
getRolePermissions(roleId: string): Promise<Permission[]>; | ||
/** | ||
* List OrgUnits at certain org tree level. | ||
* Optionally provide a test Org Unit Id that will be used to test the relationship with each of returned orgUnit item. | ||
* Possible Value: 'ancestor', 'descendant', 'equal', 'unrelated' | ||
* | ||
* @param {string} orgLevel The level number (starts from 1) where org Units of the tree are taken horizontally. | ||
* @param {string} [relationshipOrgUnitId] Optional; The org unit id that is used to test the relationship with each of returned orgUnit item. | ||
* @returns {Promise<OrgUnit[]>} | ||
* @memberof ApiClient | ||
*/ | ||
getOrgUnitsByLevel(orgLevel: number, relationshipOrgUnitId?: string): Promise<OrgUnit[]>; | ||
/** | ||
* Get orgunits by name | ||
* | ||
* @param {string} nodeName | ||
* @param {boolean} [leafNodesOnly=false] Whether only leaf nodes should be returned | ||
* @param {string} [relationshipOrgUnitId] Optional; The org unit id that is used to test the relationship with each of returned orgUnit item. | ||
* @returns {Promise<OrgUnit[]>} | ||
* @memberof ApiClient | ||
*/ | ||
getOrgUnitsByName(nodeName: string, leafNodesOnly?: boolean, relationshipOrgUnitId?: string): Promise<OrgUnit[]>; | ||
/** | ||
* Gets the root organisation unit (top of the tree). | ||
* | ||
* @returns {Promise<OrgUnit>} | ||
* @memberof ApiClient | ||
*/ | ||
getRootOrgUnit(): Promise<OrgUnit>; | ||
/** | ||
* Gets the details of the node with its id. | ||
* | ||
* @param {string} nodeId | ||
* @returns {Promise<OrgUnit>} | ||
* @memberof ApiClient | ||
*/ | ||
getOrgUnitById(nodeId: string): Promise<OrgUnit>; | ||
/** | ||
* Gets all the children immediately below the requested node. If the node doesn't exist, returns an empty list. | ||
* | ||
* @param {string} nodeId | ||
* @returns {Promise<OrgUnit[]>} | ||
* @memberof ApiClient | ||
*/ | ||
getImmediateOrgUnitChildren(nodeId: string): Promise<OrgUnit[]>; | ||
/** | ||
* Gets all the children below the requested node recursively. If node doesn't exist, returns an empty list. | ||
* | ||
* @param {string} nodeId | ||
* @returns {Promise<OrgUnit[]>} | ||
* @memberof ApiClient | ||
*/ | ||
getAllOrgUnitChildren(nodeId: string): Promise<OrgUnit[]>; | ||
createOrgNode(parentNodeId: string, node: Partial<Omit<OrgUnitRecord, "id" | "createBy" | "createTime" | "editBy" | "editTime" | "left" | "right">>): Promise<OrgUnit>; | ||
createRole(name: string, desc?: string): Promise<Role>; | ||
createRolePermission(roleId: string, permissionData: CreateRolePermissionInputData): Promise<PermissionRecord>; | ||
createPermission(permissionData: CreateRolePermissionInputData): Promise<PermissionRecord>; | ||
updatePermission(id: string, permissionData: UpdateRolePermissionInputData): Promise<PermissionRecord>; | ||
getOperationByUri(opUri: string): Promise<OperationRecord>; | ||
getResourceByUri(resUri: string): Promise<ResourceRecord>; | ||
private handleGetResult; | ||
} | ||
/** | ||
@@ -47,14 +182,3 @@ * Different type of AuthenticationMethod: | ||
/** This is present in the express-session types but not actually exported properly, so it needs to be copy-pasted here */ | ||
declare type CookieOptions_2 = { | ||
maxAge?: number; | ||
signed?: boolean; | ||
expires?: Date; | ||
httpOnly?: boolean; | ||
path?: string; | ||
domain?: string; | ||
secure?: boolean | "auto"; | ||
encode?: (val: string) => string; | ||
sameSite?: boolean | "lax" | "strict" | "none"; | ||
}; | ||
declare type CookieOptions_2 = CookieOptions_3; | ||
@@ -80,6 +204,6 @@ /** | ||
* @param {( | ||
* authApiClient: AuthApiClient, | ||
* userData: User, | ||
* profile: passport.Profile | ||
* ) => Promise<User>} [beforeUserCreated] an optional handler that will be called just before a user is created. | ||
* authApiClient: AuthApiClient, | ||
* userData: User, | ||
* profile: passport.Profile | ||
* ) => Promise<User>} [beforeUserCreated] an optional handler that will be called just before a user is created. | ||
* The user data returned by this handler will be used to create the user record. The following parameters will be provided to the handler: | ||
@@ -91,6 +215,6 @@ * - authApiClient: Auth API Client. You can use it to add a role to the user. | ||
* @param {( | ||
* authApiClient: AuthApiClient, | ||
* user: User, | ||
* profile: passport.Profile | ||
* ) => Promise<void>} [afterUserCreated] an optional call that will be called when a user has just been created. | ||
* authApiClient: AuthApiClient, | ||
* user: User, | ||
* profile: passport.Profile | ||
* ) => Promise<void>} [afterUserCreated] an optional call that will be called when a user has just been created. | ||
* The following parameters will be provided to the handler: | ||
@@ -103,7 +227,17 @@ * - authApiClient: Auth API Client. You can use it to add a role to the user. | ||
*/ | ||
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>; | ||
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>; | ||
declare interface CreateRolePermissionInputData extends Omit<PermissionRecord, "id" | "owner_id" | "create_by" | "create_time" | "edit_by" | "edit_time" | "allow_exemption" | "resource_id"> { | ||
operationIds?: string[]; | ||
operationUris?: string[]; | ||
resource_id?: string; | ||
resourceUri?: string; | ||
allow_exemption?: boolean; | ||
} | ||
declare type CreateUserData = Partial<Omit<UserRecord, "email" | "displayName" | "id">> & Pick<UserRecord, "displayName" | "email">; | ||
export declare const DEFAULT_SESSION_COOKIE_NAME: string; | ||
export declare const DEFAULT_SESSION_COOKIE_OPTIONS: CookieOptions_2; | ||
export declare const DEFAULT_SESSION_COOKIE_OPTIONS: CookieOptions_3; | ||
@@ -137,2 +271,12 @@ export declare const deleteCookie: typeof deleteCookie_2; | ||
declare interface Eq<T> { | ||
equals(t: T): boolean; | ||
} | ||
declare interface Functor<T> { | ||
fmap<U>(f: (t: T) => U): Functor<U>; | ||
lift<U>(f: (t: T) => U): Functor<U>; | ||
map<U>(f: (t: T) => U): Functor<U>; | ||
} | ||
/** | ||
@@ -162,2 +306,127 @@ * Join `url` with `baseUrl` if `url` is not an absolute (full) url string | ||
declare class Maybe<T> implements Monad<T>, Functor<T>, Eq<Maybe<T>> { | ||
private type; | ||
private value?; | ||
constructor(type: MaybeType, value?: T); | ||
static sequence<T>(t: { | ||
[k: string]: Maybe<T>; | ||
}): Maybe<{ | ||
[k: string]: T; | ||
}>; | ||
static all: (t: { | ||
[k: string]: Maybe<any>; | ||
}) => Maybe<{ | ||
[k: string]: any; | ||
}>; | ||
static maybe<T>(t?: T | null): Maybe<T>; | ||
static just<T>(t: T): Maybe<T>; | ||
static nothing<T>(): Maybe<T>; | ||
static isJust<T>(t: Maybe<T>): boolean; | ||
static isNothing<T>(t: Maybe<T>): boolean; | ||
unit<U>(u: U): Maybe<U>; | ||
bind<U>(f: (t: T) => Maybe<U>): Maybe<U>; | ||
of: <U>(u: U) => Maybe<U>; | ||
chain: <U>(f: (t: T) => Maybe<U>) => Maybe<U>; | ||
fmap<U>(f: (t: T) => U): Maybe<U>; | ||
lift: <U>(f: (t: T) => U) => Maybe<U>; | ||
map: <U>(f: (t: T) => U) => Maybe<U>; | ||
caseOf<U>(patterns: MaybePatterns<T, U>): U; | ||
defaulting(defaultValue: T): Maybe<T>; | ||
equals(other: Maybe<T>): any; | ||
valueOr<U extends T>(defaultValue: U): T | U; | ||
valueOrCompute<U extends T>(defaultValueFunction: () => U): T | U; | ||
valueOrThrow(error?: Error): T; | ||
do(patterns?: Partial<MaybePatterns<T, void>>): Maybe<T>; | ||
} | ||
declare interface MaybePatterns<T, U> { | ||
just: (t: T) => U; | ||
nothing: () => U; | ||
} | ||
declare enum MaybeType { | ||
Nothing = 0, | ||
Just = 1 | ||
} | ||
declare interface Monad<T> { | ||
unit<U>(t: U): Monad<U>; | ||
bind<U>(f: (t: T) => Monad<U>): Monad<U>; | ||
of<U>(t: U): Monad<U>; | ||
chain<U>(f: (t: T) => Monad<U>): Monad<U>; | ||
} | ||
declare interface Operation { | ||
id: string; | ||
uri: string; | ||
name: string; | ||
description?: string; | ||
} | ||
declare type OperationRecord = { | ||
id: string; | ||
uri: string; | ||
name: string; | ||
description: string; | ||
resource_id: string; | ||
}; | ||
declare type OrgUnit = Partial<OrgUnitRecord> & { | ||
relationship?: OrgUnitRelationshipType; | ||
}; | ||
declare interface OrgUnitRecord { | ||
id: string; | ||
name: string; | ||
description: string; | ||
left: number; | ||
right: number; | ||
createBy: string; | ||
createTime: Date; | ||
editBy: string; | ||
editTime: Date; | ||
} | ||
declare type OrgUnitRelationshipType = "ancestor" | "descendant" | "equal" | "unrelated"; | ||
declare interface Permission { | ||
id: string; | ||
name: string; | ||
description?: string; | ||
resourceId: string; | ||
resourceUri: string; | ||
userOwnershipConstraint: boolean; | ||
orgUnitOwnershipConstraint: boolean; | ||
preAuthorisedConstraint: boolean; | ||
operations: Operation[]; | ||
createBy?: string; | ||
createTime?: Date; | ||
editBy?: string; | ||
editTime?: Date; | ||
allowExemption: boolean; | ||
} | ||
declare interface PermissionRecord { | ||
id: string; | ||
name: string; | ||
description: string; | ||
resource_id: string; | ||
user_ownership_constraint: boolean; | ||
org_unit_ownership_constraint: boolean; | ||
pre_authorised_constraint: boolean; | ||
owner_id: string; | ||
create_time: string; | ||
create_by: string; | ||
edit_time: string; | ||
edit_by: string; | ||
allow_exemption: boolean; | ||
} | ||
declare type PublicUser = Partial<Pick<UserRecord, "id" | "photoURL" | "orgUnitId">> & Omit<UserRecord, "id" | "photoURL" | "orgUnitId" | "email" | "source" | "sourceId"> & { | ||
roles?: Role[]; | ||
permissions?: Permission[]; | ||
managingOrgUnitIds?: string[]; | ||
orgUnit?: OrgUnit; | ||
}; | ||
export declare function redirectOnError(err: any, toURL: string, req: Request_2, res: Response_2): void; | ||
@@ -167,4 +436,44 @@ | ||
declare type RequiredKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>; | ||
declare type ResourceRecord = { | ||
id: string; | ||
uri: string; | ||
name: string; | ||
description: string; | ||
}; | ||
declare interface Role { | ||
id: string; | ||
name: string; | ||
permissionIds: string[]; | ||
description?: string; | ||
createBy?: string; | ||
createTime?: Date; | ||
editBy?: string; | ||
editTime?: Date; | ||
} | ||
export declare type SessionCookieOptions = CookieOptions_2; | ||
declare interface UpdateRolePermissionInputData extends Partial<CreateRolePermissionInputData> { | ||
} | ||
declare type User = PublicUser & Pick<UserRecord, "email" | "source" | "sourceId">; | ||
declare interface UserRecord { | ||
id: string; | ||
displayName: string; | ||
photoURL: string; | ||
isAdmin: boolean; | ||
orgUnitId: string; | ||
email: string; | ||
source: string; | ||
sourceId: string; | ||
} | ||
declare interface UserToken { | ||
id: string; | ||
} | ||
export { } |
{ | ||
"name": "@magda/authentication-plugin-sdk", | ||
"description": "MAGDA Authentication Plugin SDK", | ||
"version": "2.3.3", | ||
"version": "3.0.0-alpha.0", | ||
"type": "module", | ||
"exports": { | ||
".": "./dist/index.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"engines": { | ||
"node": ">=16.0.0" | ||
}, | ||
"scripts": { | ||
"prebuild": "rimraf dist tsconfig.tsbuildinfo", | ||
"build": "webpack && api-extractor run -l", | ||
"build": "yarn build-main && yarn build-types && yarn build-types-bundle", | ||
"build-main": "node esbuild.js", | ||
"build-types": "tsc --emitDeclarationOnly", | ||
"build-types-bundle": "api-extractor run --local", | ||
"release": "npm publish || echo \"Skip releasing npm package @magda/authentication-plugin-sdk.\"" | ||
@@ -15,24 +26,23 @@ }, | ||
"devDependencies": { | ||
"@magda/auth-api-client": "^2.3.3", | ||
"@magda/typescript-common": "^2.3.3", | ||
"@types/express": "^4.17.6", | ||
"@types/express-session": "^1.15.15", | ||
"@magda/auth-api-client": "^3.0.0-alpha.0", | ||
"@magda/typescript-common": "^3.0.0-alpha.0", | ||
"@types/express-session": "^1.17.10", | ||
"@types/lodash": "^4.14.74", | ||
"@types/passport": "^1.0.3", | ||
"@types/pg": "^8.6.5", | ||
"@types/urijs": "^1.19.19", | ||
"ts-loader": "^6.2.1", | ||
"typescript": "~4.2.4", | ||
"webpack": "^4.41.2", | ||
"webpack-cli": "^3.3.10" | ||
}, | ||
"dependencies": { | ||
"connect-pg-simple": "^6.2.1", | ||
"cookie-parser": "^1.4.5", | ||
"express": "^4.17.1", | ||
"express-session": "^1.17.1", | ||
"esbuild": "^0.19.10", | ||
"express": "^4.17.2", | ||
"express-session": "^1.17.3", | ||
"lodash": "^4.17.4", | ||
"pg": "^8.7.3", | ||
"ts-loader": "^9.5.1", | ||
"typescript": "~5.2.2", | ||
"urijs": "^1.19.11" | ||
}, | ||
"dependencies": { | ||
"@types/express": "^4.17.21", | ||
"@types/passport": "^1.0.3", | ||
"@types/urijs": "^1.19.19", | ||
"pg": "^8.7.3" | ||
}, | ||
"magda": { | ||
@@ -39,0 +49,0 @@ "language": "typescript", |
Sorry, the diff of this file is too big to display
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1804307
4
44052
Yes
14
2
+ Added@types/express@^4.17.21
+ Added@types/passport@^1.0.3
+ Added@types/urijs@^1.19.19
+ Added@types/body-parser@1.19.5(transitive)
+ Added@types/connect@3.4.38(transitive)
+ Added@types/express@4.17.21(transitive)
+ Added@types/express-serve-static-core@4.19.6(transitive)
+ Added@types/http-errors@2.0.4(transitive)
+ Added@types/mime@1.3.5(transitive)
+ Added@types/passport@1.0.17(transitive)
+ Added@types/qs@6.9.18(transitive)
+ Added@types/range-parser@1.2.7(transitive)
+ Added@types/send@0.17.4(transitive)
+ Added@types/serve-static@1.15.7(transitive)
+ Added@types/urijs@1.19.25(transitive)
- Removedconnect-pg-simple@^6.2.1
- Removedcookie-parser@^1.4.5
- Removedexpress@^4.17.1
- Removedexpress-session@^1.17.1
- Removedlodash@^4.17.4
- Removedurijs@^1.19.11
- Removed@types/pg@7.14.11(transitive)
- Removedaccepts@1.3.8(transitive)
- Removedarray-flatten@1.1.1(transitive)
- Removedbody-parser@1.20.3(transitive)
- Removedbytes@3.1.2(transitive)
- Removedcall-bind-apply-helpers@1.0.1(transitive)
- Removedcall-bound@1.0.3(transitive)
- Removedconnect-pg-simple@6.2.1(transitive)
- Removedcontent-disposition@0.5.4(transitive)
- Removedcontent-type@1.0.5(transitive)
- Removedcookie@0.7.10.7.2(transitive)
- Removedcookie-parser@1.4.7(transitive)
- Removedcookie-signature@1.0.61.0.7(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddepd@2.0.0(transitive)
- Removeddestroy@1.2.0(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedee-first@1.1.1(transitive)
- Removedencodeurl@1.0.22.0.0(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.1.1(transitive)
- Removedescape-html@1.0.3(transitive)
- Removedetag@1.8.1(transitive)
- Removedexpress@4.21.2(transitive)
- Removedexpress-session@1.18.1(transitive)
- Removedfinalhandler@1.3.1(transitive)
- Removedforwarded@0.2.0(transitive)
- Removedfresh@0.5.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.7(transitive)
- Removedget-proto@1.0.1(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhttp-errors@2.0.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedinherits@2.0.4(transitive)
- Removedipaddr.js@1.9.1(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedmedia-typer@0.3.0(transitive)
- Removedmerge-descriptors@1.0.3(transitive)
- Removedmethods@1.1.2(transitive)
- Removedmime@1.6.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedms@2.0.02.1.3(transitive)
- Removednegotiator@0.6.3(transitive)
- Removedobject-inspect@1.13.4(transitive)
- Removedon-finished@2.4.1(transitive)
- Removedon-headers@1.0.2(transitive)
- Removedparseurl@1.3.3(transitive)
- Removedpath-to-regexp@0.1.12(transitive)
- Removedproxy-addr@2.0.7(transitive)
- Removedqs@6.13.0(transitive)
- Removedrandom-bytes@1.0.0(transitive)
- Removedrange-parser@1.2.1(transitive)
- Removedraw-body@2.5.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsend@0.19.0(transitive)
- Removedserve-static@1.16.2(transitive)
- Removedsetprototypeof@1.2.0(transitive)
- Removedside-channel@1.1.0(transitive)
- Removedside-channel-list@1.0.0(transitive)
- Removedside-channel-map@1.0.1(transitive)
- Removedside-channel-weakmap@1.0.2(transitive)
- Removedstatuses@2.0.1(transitive)
- Removedtoidentifier@1.0.1(transitive)
- Removedtype-is@1.6.18(transitive)
- Removeduid-safe@2.1.5(transitive)
- Removedunpipe@1.0.0(transitive)
- Removedurijs@1.19.11(transitive)
- Removedutils-merge@1.0.1(transitive)
- Removedvary@1.1.2(transitive)