@openmrs/esm-api
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "@openmrs/esm-api", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "The javascript module for interacting with the OpenMRS API", | ||
"main": "dist/openmrs-esm-api.js", | ||
"types": "dist/openmrs-esm-api.d.ts", | ||
"types": "src/openmrs-esm-api.ts", | ||
"scripts": { | ||
@@ -12,3 +12,2 @@ "test": "jest", | ||
"typescript": "tsc", | ||
"prepublishOnly": "tsc src/openmrs-esm-api.ts --jsx react --outFile dist/openmrs-esm-api.js --module system -d --moduleResolution node", | ||
"prettier": "prettier src/**/* --write", | ||
@@ -15,0 +14,0 @@ "lint": "eslint src --ext ts" |
@@ -1,15 +0,21 @@ | ||
import { BehaviorSubject } from "rxjs"; | ||
import { BehaviorSubject, Observable } from "rxjs"; | ||
import { openmrsObservableFetch, FetchResponse } from "../openmrs-fetch"; | ||
import { mergeAll, filter, map } from "rxjs/operators"; | ||
const userSubject = new BehaviorSubject( | ||
openmrsObservableFetch("/ws/rest/v1/session") | ||
const userSubject = new BehaviorSubject<Observable<LoggedInUserFetchResponse>>( | ||
openmrsObservableFetch("/ws/rest/v1/session") as Observable< | ||
LoggedInUserFetchResponse | ||
> | ||
); | ||
export function getCurrentUser(opts: CurrentUserOptions = {}) { | ||
export function getCurrentUser( | ||
opts: CurrentUserOptions = {} | ||
): Observable<LoggedInUser | UnauthenticatedUser> { | ||
return userSubject.asObservable().pipe( | ||
mergeAll(), | ||
map((r: FetchResponse) => (opts.includeAuthStatus ? r.data : r.data.user)), | ||
map((r: LoggedInUserFetchResponse) => | ||
opts.includeAuthStatus ? r.data : r.data.user | ||
), | ||
filter(Boolean) | ||
); | ||
) as Observable<LoggedInUser | UnauthenticatedUser>; | ||
} | ||
@@ -28,1 +34,45 @@ | ||
}; | ||
interface LoggedInUser { | ||
uuid: string; | ||
display: string; | ||
username: string; | ||
systemId: string; | ||
userProperties: any; | ||
person: Person; | ||
privileges: Privilege[]; | ||
roles: Role[]; | ||
retired: boolean; | ||
locale: string; | ||
allowedLocales: string[]; | ||
[anythingElse: string]: any; | ||
} | ||
type UnauthenticatedUser = { | ||
sessionId: string; | ||
authenticated: boolean; | ||
}; | ||
type Person = { | ||
uuid: string; | ||
display: string; | ||
links: any[]; | ||
}; | ||
type Privilege = { | ||
uuid: string; | ||
display: string; | ||
links: any[]; | ||
}; | ||
type Role = { | ||
uuid: string; | ||
display: string; | ||
links: any[]; | ||
}; | ||
interface LoggedInUserFetchResponse extends FetchResponse { | ||
data: UnauthenticatedUser & { | ||
user?: LoggedInUser; | ||
}; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22130
17
577
1