@nextcloud/auth
Advanced tools
Comparing version 2.0.0 to 2.1.0
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var eventBus = require('@nextcloud/event-bus'); | ||
var tokenElement = document.getElementsByTagName('head')[0]; | ||
var token = tokenElement ? tokenElement.getAttribute('data-requesttoken') : null; | ||
var token = undefined; | ||
var observers = []; | ||
/** | ||
* Get current request token | ||
* | ||
* @return {string|null} Current request token or null if not set | ||
*/ | ||
function getRequestToken() { | ||
if (token === undefined) { | ||
// Only on first load, try to get token from document | ||
var tokenElement = document === null || document === void 0 ? void 0 : document.getElementsByTagName('head')[0]; | ||
token = tokenElement ? tokenElement.getAttribute('data-requesttoken') : null; | ||
} | ||
return token; | ||
} | ||
/** | ||
* Add an observer which is called when the CSRF token changes | ||
* | ||
* @param observer The observer | ||
*/ | ||
function onRequestTokenUpdate(observer) { | ||
@@ -36,17 +48,23 @@ observers.push(observer); | ||
}; | ||
var head = document.getElementsByTagName('head')[0]; | ||
var uid = getAttribute(head, 'data-user'); | ||
var displayName = getAttribute(head, 'data-user-displayname'); | ||
var isAdmin = (typeof OC === 'undefined') | ||
? false | ||
: OC.isUserAdmin(); | ||
var currentUser = undefined; | ||
function getCurrentUser() { | ||
if (uid === null) { | ||
if (currentUser !== undefined) { | ||
return currentUser; | ||
} | ||
var head = document === null || document === void 0 ? void 0 : document.getElementsByTagName('head')[0]; | ||
if (!head) { | ||
return null; | ||
} | ||
return { | ||
// No user logged in so cache and return null | ||
var uid = getAttribute(head, 'data-user'); | ||
if (uid === null) { | ||
currentUser = null; | ||
return currentUser; | ||
} | ||
currentUser = { | ||
uid: uid, | ||
displayName: displayName, | ||
isAdmin: isAdmin, | ||
displayName: getAttribute(head, 'data-user-displayname'), | ||
isAdmin: (typeof OC === 'undefined') ? false : OC.isUserAdmin(), | ||
}; | ||
return currentUser; | ||
} | ||
@@ -53,0 +71,0 @@ |
export interface CsrfTokenObserver { | ||
(token: string): void; | ||
} | ||
/** | ||
* Get current request token | ||
* | ||
* @return {string|null} Current request token or null if not set | ||
*/ | ||
export declare function getRequestToken(): string | null; | ||
/** | ||
* Add an observer which is called when the CSRF token changes | ||
* | ||
* @param observer The observer | ||
*/ | ||
export declare function onRequestTokenUpdate(observer: CsrfTokenObserver): void; |
export interface NextcloudUser { | ||
uid: String; | ||
displayName: String | null; | ||
isAdmin: Boolean; | ||
uid: string; | ||
displayName: string | null; | ||
isAdmin: boolean; | ||
} | ||
export declare function getCurrentUser(): NextcloudUser | null; |
{ | ||
"name": "@nextcloud/auth", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Nextcloud helpers related to authentication and the current user", | ||
"main": "dist/index.js", | ||
"module": "dist/index.esm.js", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
"import": "./dist/index.esm.js", | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.es.mjs", | ||
"require": "./dist/index.js" | ||
@@ -16,6 +16,6 @@ }, | ||
"scripts": { | ||
"build": "rollup --config rollup.config.js", | ||
"build": "rollup --config rollup.config.mjs", | ||
"build:doc": "typedoc --out dist/doc lib/index.ts && touch dist/doc/.nojekyll", | ||
"check-types": "tsc --noEmit", | ||
"dev": "rollup --config rollup.config.js --watch", | ||
"dev": "rollup --config rollup.config.mjs --watch", | ||
"test": "jest", | ||
@@ -35,14 +35,18 @@ "test:watch": "jest --watchAll" | ||
"dependencies": { | ||
"@nextcloud/event-bus": "^3.0.0" | ||
"@nextcloud/event-bus": "^3.1.0" | ||
}, | ||
"devDependencies": { | ||
"@nextcloud/typings": "^1.4.3", | ||
"@rollup/plugin-typescript": "^8.3.4", | ||
"jest": "^28.1.3", | ||
"jest-environment-jsdom": "^28.1.3", | ||
"rollup": "^2.77.2", | ||
"tslib": "^2.4.0", | ||
"typedoc": "^0.23.10", | ||
"typescript": "^4.7.4" | ||
"@nextcloud/typings": "^1.6.0", | ||
"@rollup/plugin-typescript": "^11.1.1", | ||
"jest": "^29.5.0", | ||
"jest-environment-jsdom": "^29.5.0", | ||
"rollup": "^3.22.0", | ||
"tslib": "^2.5.0", | ||
"typedoc": "^0.24.7", | ||
"typescript": "^5.0.4" | ||
}, | ||
"engines": { | ||
"node": "^16.0.0", | ||
"npm": "^7.0.0 || ^8.0.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
426786
29
2098
1
3
Updated@nextcloud/event-bus@^3.1.0