Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .eslintrc.json

This file was deleted.

8 changes: 8 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*!
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: CC0-1.0
*/

import { recommendedLibrary } from '@nextcloud/eslint-config'

export default [...recommendedLibrary]
2 changes: 1 addition & 1 deletion lib/csp-nonce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import { getRequestToken } from './requesttoken'
import { getRequestToken } from './requesttoken.ts'

/**
* Get the CSP nonce for script loading
Expand Down
3 changes: 2 additions & 1 deletion lib/eventbus.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { NextcloudUser } from './user'

import type { NextcloudUser } from './user.ts'

declare module '@nextcloud/event-bus' {
export interface NextcloudEvents {
Expand Down
12 changes: 12 additions & 0 deletions lib/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*!
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

declare global {
interface Window {
_oc_isadmin?: boolean
}
}

export {}
12 changes: 6 additions & 6 deletions lib/guest.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/**
/*!
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import type { NextcloudUser } from './user.ts'

import { getBuilder } from '@nextcloud/browser-storage'
import { NextcloudUser } from './user'
import { emit, subscribe } from '@nextcloud/event-bus'

const browserStorage = getBuilder('public').persist().build()

class GuestUser implements NextcloudUser {

private _displayName: string | null
readonly uid: string
readonly isAdmin: boolean
Expand All @@ -27,7 +28,6 @@ class GuestUser implements NextcloudUser {
this._displayName = guest.displayName
browserStorage.setItem('guestNickname', guest.displayName || '')
})

}

get displayName(): string | null {
Expand All @@ -39,7 +39,6 @@ class GuestUser implements NextcloudUser {
browserStorage.setItem('guestNickname', displayName)
emit('user:info:changed', this)
}

}

let currentUser: NextcloudUser | undefined
Expand All @@ -64,7 +63,8 @@ export function getGuestNickname(): string | null {

/**
* Set the guest nickname for public pages
* @param nickname The nickname to set
*
* @param nickname - The nickname to set
*/
export function setGuestNickname(nickname: string): void {
if (!nickname || nickname.trim().length === 0) {
Expand Down
13 changes: 7 additions & 6 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
export type { CsrfTokenObserver } from './requesttoken'
export type { NextcloudUser } from './user'

export { getCSPNonce } from './csp-nonce'
export { getGuestUser, getGuestNickname, setGuestNickname } from './guest'
export { getRequestToken, onRequestTokenUpdate } from './requesttoken'
export { getCurrentUser } from './user'
export type { CsrfTokenObserver } from './requesttoken.ts'
export type { NextcloudUser } from './user.ts'

export { getCSPNonce } from './csp-nonce.ts'
export { getGuestNickname, getGuestUser, setGuestNickname } from './guest.ts'
export { getRequestToken, onRequestTokenUpdate } from './requesttoken.ts'
export { getCurrentUser } from './user.ts'
11 changes: 7 additions & 4 deletions lib/requesttoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import { subscribe } from '@nextcloud/event-bus'

export interface CsrfTokenObserver {
(token: string): void;
(token: string): void
}

let token: string | null | undefined
Expand All @@ -14,7 +15,7 @@ const observers: CsrfTokenObserver[] = []
/**
* Get current request token
*
* @return {string|null} Current request token or null if not set
* @return Current request token or null if not set
*/
export function getRequestToken(): string | null {
if (token === undefined) {
Expand All @@ -40,8 +41,10 @@ subscribe('csrf-token-update', (e: unknown) => {
observers.forEach((observer) => {
try {
observer(token!)
} catch (e) {
console.error('Error updating CSRF token observer', e)
} catch (error) {
// we cannot use the logger as the logger uses this library = circular dependency
// eslint-disable-next-line no-console
console.error('Error updating CSRF token observer', error)
}
})
})
17 changes: 8 additions & 9 deletions lib/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
declare global {
interface Window {
_oc_isadmin?: boolean
}
}

export interface NextcloudUser {
uid: string,
displayName: string | null,
isAdmin: boolean,
uid: string
displayName: string | null
isAdmin: boolean
}

let currentUser: NextcloudUser | null | undefined

const getAttribute = (el: HTMLHeadElement | undefined, attribute: string): string | null => {
/**
* @param el - The element
* @param attribute - The attribute to fetch
*/
function getAttribute(el: HTMLHeadElement | undefined, attribute: string): string | null {
if (el) {
return el.getAttribute(attribute)
}
Expand Down
Loading