aboutsummaryrefslogtreecommitdiffstats
path: root/core/src/services
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/services')
-rw-r--r--core/src/services/BrowserStorageService.js11
-rw-r--r--core/src/services/BrowsersListService.js13
-rw-r--r--core/src/services/LegacyUnifiedSearchService.js76
-rw-r--r--core/src/services/UnifiedSearchService.js87
-rw-r--r--core/src/services/WebAuthnAuthenticationService.js37
-rw-r--r--core/src/services/WebAuthnAuthenticationService.ts42
6 files changed, 195 insertions, 71 deletions
diff --git a/core/src/services/BrowserStorageService.js b/core/src/services/BrowserStorageService.js
new file mode 100644
index 00000000000..b7d34bf1716
--- /dev/null
+++ b/core/src/services/BrowserStorageService.js
@@ -0,0 +1,11 @@
+/**
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import { getBuilder } from '@nextcloud/browser-storage'
+
+export default getBuilder('core')
+ .clearOnLogout()
+ .persist()
+ .build()
diff --git a/core/src/services/BrowsersListService.js b/core/src/services/BrowsersListService.js
new file mode 100644
index 00000000000..77f217a86ac
--- /dev/null
+++ b/core/src/services/BrowsersListService.js
@@ -0,0 +1,13 @@
+/**
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import { getUserAgentRegex } from 'browserslist-useragent-regexp'
+// eslint-disable-next-line n/no-extraneous-import
+import browserslist from 'browserslist'
+import browserslistConfig from '@nextcloud/browserslist-config'
+
+// Generate a regex that matches user agents to detect incompatible browsers
+export const supportedBrowsersRegExp = getUserAgentRegex({ allowHigherVersions: true, browsers: browserslistConfig })
+export const supportedBrowsers = browserslist(browserslistConfig)
diff --git a/core/src/services/LegacyUnifiedSearchService.js b/core/src/services/LegacyUnifiedSearchService.js
new file mode 100644
index 00000000000..5b79c09b8b2
--- /dev/null
+++ b/core/src/services/LegacyUnifiedSearchService.js
@@ -0,0 +1,76 @@
+/**
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import { generateOcsUrl } from '@nextcloud/router'
+import { loadState } from '@nextcloud/initial-state'
+import axios from '@nextcloud/axios'
+
+export const defaultLimit = loadState('unified-search', 'limit-default')
+export const minSearchLength = loadState('unified-search', 'min-search-length', 1)
+export const enableLiveSearch = loadState('unified-search', 'live-search', true)
+
+export const regexFilterIn = /(^|\s)in:([a-z_-]+)/ig
+export const regexFilterNot = /(^|\s)-in:([a-z_-]+)/ig
+
+/**
+ * Create a cancel token
+ *
+ * @return {import('axios').CancelTokenSource}
+ */
+const createCancelToken = () => axios.CancelToken.source()
+
+/**
+ * Get the list of available search providers
+ *
+ * @return {Promise<Array>}
+ */
+export async function getTypes() {
+ try {
+ const { data } = await axios.get(generateOcsUrl('search/providers'), {
+ params: {
+ // Sending which location we're currently at
+ from: window.location.pathname.replace('/index.php', '') + window.location.search,
+ },
+ })
+ if ('ocs' in data && 'data' in data.ocs && Array.isArray(data.ocs.data) && data.ocs.data.length > 0) {
+ // Providers are sorted by the api based on their order key
+ return data.ocs.data
+ }
+ } catch (error) {
+ console.error(error)
+ }
+ return []
+}
+
+/**
+ * Get the list of available search providers
+ *
+ * @param {object} options destructuring object
+ * @param {string} options.type the type to search
+ * @param {string} options.query the search
+ * @param {number|string|undefined} options.cursor the offset for paginated searches
+ * @return {object} {request: Promise, cancel: Promise}
+ */
+export function search({ type, query, cursor }) {
+ /**
+ * Generate an axios cancel token
+ */
+ const cancelToken = createCancelToken()
+
+ const request = async () => axios.get(generateOcsUrl('search/providers/{type}/search', { type }), {
+ cancelToken: cancelToken.token,
+ params: {
+ term: query,
+ cursor,
+ // Sending which location we're currently at
+ from: window.location.pathname.replace('/index.php', '') + window.location.search,
+ },
+ })
+
+ return {
+ request,
+ cancel: cancelToken.cancel,
+ }
+}
diff --git a/core/src/services/UnifiedSearchService.js b/core/src/services/UnifiedSearchService.js
index eb91f18f8c9..7067c994c90 100644
--- a/core/src/services/UnifiedSearchService.js
+++ b/core/src/services/UnifiedSearchService.js
@@ -1,47 +1,27 @@
/**
- * @copyright 2020, John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-import { generateOcsUrl } from '@nextcloud/router'
-import { loadState } from '@nextcloud/initial-state'
+import { generateOcsUrl, generateUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
-
-export const defaultLimit = loadState('unified-search', 'limit-default')
-export const minSearchLength = 2
-export const regexFilterIn = /[^-]in:([a-z_-]+)/ig
-export const regexFilterNot = /-in:([a-z_-]+)/ig
+import { getCurrentUser } from '@nextcloud/auth'
/**
* Create a cancel token
- * @returns {CancelTokenSource}
+ *
+ * @return {import('axios').CancelTokenSource}
*/
const createCancelToken = () => axios.CancelToken.source()
/**
* Get the list of available search providers
*
- * @returns {Array}
+ * @return {Promise<Array>}
*/
-export async function getTypes() {
+export async function getProviders() {
try {
- const { data } = await axios.get(generateOcsUrl('search', 2) + 'providers', {
+ const { data } = await axios.get(generateOcsUrl('search/providers'), {
params: {
// Sending which location we're currently at
from: window.location.pathname.replace('/index.php', '') + window.location.search,
@@ -60,25 +40,35 @@ export async function getTypes() {
/**
* Get the list of available search providers
*
- * @param {Object} options destructuring object
+ * @param {object} options destructuring object
* @param {string} options.type the type to search
* @param {string} options.query the search
- * @param {int|string|undefined} options.cursor the offset for paginated searches
- * @returns {Object} {request: Promise, cancel: Promise}
+ * @param {number|string|undefined} options.cursor the offset for paginated searches
+ * @param {string} options.since the search
+ * @param {string} options.until the search
+ * @param {string} options.limit the search
+ * @param {string} options.person the search
+ * @param {object} options.extraQueries additional queries to filter search results
+ * @return {object} {request: Promise, cancel: Promise}
*/
-export function search({ type, query, cursor }) {
+export function search({ type, query, cursor, since, until, limit, person, extraQueries = {} }) {
/**
* Generate an axios cancel token
*/
const cancelToken = createCancelToken()
- const request = async() => axios.get(generateOcsUrl('search', 2) + `providers/${type}/search`, {
+ const request = async () => axios.get(generateOcsUrl('search/providers/{type}/search', { type }), {
cancelToken: cancelToken.token,
params: {
term: query,
cursor,
+ since,
+ until,
+ limit,
+ person,
// Sending which location we're currently at
from: window.location.pathname.replace('/index.php', '') + window.location.search,
+ ...extraQueries,
},
})
@@ -87,3 +77,32 @@ export function search({ type, query, cursor }) {
cancel: cancelToken.cancel,
}
}
+
+/**
+ * Get the list of active contacts
+ *
+ * @param {object} filter filter contacts by string
+ * @param {string} filter.searchTerm the query
+ * @return {object} {request: Promise}
+ */
+export async function getContacts({ searchTerm }) {
+ const { data: { contacts } } = await axios.post(generateUrl('/contactsmenu/contacts'), {
+ filter: searchTerm,
+ })
+ /*
+ * Add authenticated user to list of contacts for search filter
+ * If authtenicated user is searching/filtering, do not add them to the list
+ */
+ if (!searchTerm) {
+ let authenticatedUser = getCurrentUser()
+ authenticatedUser = {
+ id: authenticatedUser.uid,
+ fullName: authenticatedUser.displayName,
+ emailAddresses: [],
+ }
+ contacts.unshift(authenticatedUser)
+ return contacts
+ }
+
+ return contacts
+}
diff --git a/core/src/services/WebAuthnAuthenticationService.js b/core/src/services/WebAuthnAuthenticationService.js
deleted file mode 100644
index 91f19177066..00000000000
--- a/core/src/services/WebAuthnAuthenticationService.js
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * @copyright 2020, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import Axios from '@nextcloud/axios'
-import { generateUrl } from '@nextcloud/router'
-
-export function startAuthentication(loginName) {
- const url = generateUrl('/login/webauthn/start')
-
- return Axios.post(url, { loginName })
- .then(resp => resp.data)
-}
-
-export function finishAuthentication(data) {
- const url = generateUrl('/login/webauthn/finish')
-
- return Axios.post(url, { data })
- .then(resp => resp.data)
-}
diff --git a/core/src/services/WebAuthnAuthenticationService.ts b/core/src/services/WebAuthnAuthenticationService.ts
new file mode 100644
index 00000000000..df1837254ad
--- /dev/null
+++ b/core/src/services/WebAuthnAuthenticationService.ts
@@ -0,0 +1,42 @@
+/**
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import type { AuthenticationResponseJSON, PublicKeyCredentialRequestOptionsJSON } from '@simplewebauthn/browser'
+
+import { startAuthentication as startWebauthnAuthentication } from '@simplewebauthn/browser'
+import { generateUrl } from '@nextcloud/router'
+
+import Axios from '@nextcloud/axios'
+import logger from '../logger'
+
+export class NoValidCredentials extends Error {}
+
+/**
+ * Start webautn authentication
+ * This loads the challenge, connects to the authenticator and returns the repose that needs to be sent to the server.
+ *
+ * @param loginName Name to login
+ */
+export async function startAuthentication(loginName: string) {
+ const url = generateUrl('/login/webauthn/start')
+
+ const { data } = await Axios.post<PublicKeyCredentialRequestOptionsJSON>(url, { loginName })
+ if (!data.allowCredentials || data.allowCredentials.length === 0) {
+ logger.error('No valid credentials returned for webauthn')
+ throw new NoValidCredentials()
+ }
+ return await startWebauthnAuthentication({ optionsJSON: data })
+}
+
+/**
+ * Verify webauthn authentication
+ * @param authData The authentication data to sent to the server
+ */
+export async function finishAuthentication(authData: AuthenticationResponseJSON) {
+ const url = generateUrl('/login/webauthn/finish')
+
+ const { data } = await Axios.post(url, { data: JSON.stringify(authData) })
+ return data
+}