Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement Search API for cozy-dataproxy-api #1279

Merged
merged 3 commits into from
Jan 17, 2025
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
4 changes: 4 additions & 0 deletions __tests__/jestSetupFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,7 @@ jest.mock('cozy-pouch-link', () => {
jest.mock('react-native-mail', () => ({
mail: jest.fn()
}))

jest.mock('/app/domain/search/dataproxy-wrapper', () => ({
SearchEngine: jest.fn()
}))
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"base-64": "^1.0.0",
"cozy-client": "^52.0.0",
"cozy-clisk": "^0.38.1",
"cozy-dataproxy-lib": "^2.3.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be 2.4.0 I assume? To get cozy/cozy-libs#2697

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not needed, 2.4.0 only impacts the DataProxyProvider that is hosted in web cozy-apps.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, my bad

"cozy-device-helper": "^2.7.0",
"cozy-flags": "^3.2.0",
"cozy-intent": "^2.23.0",
Expand Down
7 changes: 7 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import LauncherView from '/screens/konnectors/LauncherView'
import { makeImportantFilesAvailableOfflineInBackground } from '/app/domain/io.cozy.files/importantFiles'
import { useOfflineReplicationOnRealtime } from '/app/domain/offline/hooks/useOfflineReplicationOnRealtime'
import { useShareFiles } from '/app/domain/osReceive/services/shareFilesService'
import { initSearchEngine } from '/app/domain/search/search'
import { ClouderyOffer } from '/app/view/IAP/ClouderyOffer'
import { useDimensions } from '/libs/dimensions'
import { configureFileLogger } from '/app/domain/logger/fileLogger'
Expand Down Expand Up @@ -135,6 +136,12 @@ const App = ({ setClient }) => {
useOfflineDebugUniversalLinks(client)
usePerformancesUniversalLinks(client)

useEffect(() => {
if (client) {
initSearchEngine(client)
}
}, [client])

const {
LauncherDialog,
canDisplayLauncher,
Expand Down
5 changes: 5 additions & 0 deletions src/app/domain/search/dataproxy-wrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// We cannot use `cozy-dataproxy-lib/api` here due to our bundler configuration
// even if it is declared in the package.json file. Instead we should target the
// 'dist' directory.
// In the future we should find a way to homogenize bundlers configuration.
export { SearchEngine } from 'cozy-dataproxy-lib/dist/api'
21 changes: 21 additions & 0 deletions src/app/domain/search/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import CozyClient from 'cozy-client'
import type { SearchOptions } from 'cozy-dataproxy-lib/dist/search/types'
import Minilog from 'cozy-minilog'

import { SearchEngine } from '/app/domain/search/dataproxy-wrapper'

const log = Minilog('📱🗂️ Search')

let searchEngine: SearchEngine | undefined = undefined

export const initSearchEngine = (client: CozyClient): void => {
log.debug('Init SearchEngine')
searchEngine = new SearchEngine(client)
}

export const search = (query: string, options: SearchOptions): unknown => {
log.debug('Search for', query)
if (!searchEngine) return undefined

return searchEngine.search(query, options)
}
14 changes: 14 additions & 0 deletions src/libs/intents/localMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getDeviceName } from 'react-native-device-info'

import CozyClient, { QueryDefinition } from 'cozy-client'
import type { FileDocument } from 'cozy-client/types/types'
import type { SearchOptions } from 'cozy-dataproxy-lib/dist/search/types'
import {
FlagshipUI,
NativeMethodsRegisterWithOptions,
Expand All @@ -17,6 +18,7 @@ import {
isScannerAvailable
} from '/app/domain/scanner/services/scanner'
import { processOcr, isOcrAvailable } from '/app/domain/ocr/services/ocr'
import { search as doSearch } from '/app/domain/search/search'
import { setColorScheme } from '/app/theme/colorScheme'
import { printBase64Doc as print } from '/libs/intents/printBase64Doc'
import { setHomeThemeIntent } from '/libs/intents/setHomeThemeIntent'
Expand Down Expand Up @@ -95,6 +97,10 @@ export const backToHome = (): Promise<null> => {
return Promise.resolve(null)
}

const search = (query: string, options: SearchOptions): unknown => {
return doSearch(query, options)
}

const isAvailable = (featureName: string): Promise<boolean> => {
if (featureName === 'geolocationTracking') {
return Promise.resolve(true)
Expand All @@ -116,6 +122,8 @@ const isAvailable = (featureName: string): Promise<boolean> => {
return Promise.resolve(true)
} else if (featureName === 'downloadFile') {
return Promise.resolve(true)
} else if (featureName === 'search') {
return Promise.resolve(true)
}

return Promise.resolve(false)
Expand Down Expand Up @@ -219,6 +227,7 @@ interface CustomMethods {
storeSharedMemory: (key: string, value: SharedMemoryData) => Promise<void>
removeSharedMemory: (key: string) => Promise<void>
setColorScheme: (colorScheme: string | undefined) => Promise<void>
search: (query: string, options: SearchOptions) => unknown
}

type WithOptions<T> = {
Expand Down Expand Up @@ -407,6 +416,11 @@ export const localMethods = (
flagshipLinkRequest(operation as QueryDefinition, client),
downloadFile: (_options, file) =>
downloadFileAndPreview(file as FileDocument, client),
search: (
_options: PostMeMessageOptions,
query: string,
options: SearchOptions
) => search(query, options),
...mergedMethods
}
}
106 changes: 105 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8232,6 +8232,11 @@ class-utils@^0.3.5:
isobject "^3.0.0"
static-extend "^0.1.1"

[email protected]:
version "2.5.1"
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.5.1.tgz#ba774c614be0f016da105c858e7159eae8e7687b"
integrity sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow==

clean-css@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/clean-css/-/clean-css-4.2.3.tgz#507b5de7d97b48ee53d84adb0160ff6216380f78"
Expand Down Expand Up @@ -8412,6 +8417,11 @@ combined-stream@^1.0.8:
dependencies:
delayed-stream "~1.0.0"

[email protected]:
version "4.4.1"
resolved "https://registry.yarnpkg.com/comlink/-/comlink-4.4.1.tgz#e568b8e86410b809e8600eb2cf40c189371ef981"
integrity sha512-+1dlx0aY5Jo1vHy/tSsIGpSkN4tS9rZSW8FIhG0JH/crs9wwweswIo/POr451r7bZww3hFbPAKnTpimzL/mm4Q==

command-exists@^1.2.8:
version "1.2.9"
resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.9.tgz#c50725af3808c8ab0260fd60b01fbfa25b954f69"
Expand Down Expand Up @@ -8683,6 +8693,31 @@ cosmiconfig@^8.1.3:
parse-json "^5.2.0"
path-type "^4.0.0"

cozy-client@^50.4.0:
version "50.4.0"
resolved "https://registry.yarnpkg.com/cozy-client/-/cozy-client-50.4.0.tgz#dc341e71b2acee90342cf86e17392e890e7e7093"
integrity sha512-DINi/YwDrzBkXzcm63hFj8Y09yzzLaRWhJqyCu1JT6bdIpV2jc9lJMJe1pcud8xfg29OzSQ5/8gDf5MaQLkzsQ==
dependencies:
"@cozy/minilog" "1.0.0"
"@types/jest" "^26.0.20"
"@types/lodash" "^4.14.170"
btoa "^1.2.1"
cozy-stack-client "^50.4.0"
date-fns "2.29.3"
json-stable-stringify "^1.0.1"
lodash "^4.17.13"
microee "^0.0.6"
node-fetch "^2.6.1"
node-polyglot "2.4.2"
open "7.4.2"
prop-types "^15.6.2"
react-redux "^7.2.0"
redux "3 || 4"
redux-thunk "^2.3.0"
server-destroy "^1.0.1"
sift "^6.0.0"
url-search-params-polyfill "^8.0.0"

cozy-client@^52.0.0:
version "52.0.0"
resolved "https://registry.yarnpkg.com/cozy-client/-/cozy-client-52.0.0.tgz#bedbdee24846b8cc24cd4966ec8d19dd9661c872"
Expand Down Expand Up @@ -8722,6 +8757,20 @@ cozy-clisk@^0.38.1:
p-wait-for "^5.0.2"
post-me "^0.4.5"

cozy-dataproxy-lib@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/cozy-dataproxy-lib/-/cozy-dataproxy-lib-2.3.0.tgz#c702c36a674c61edffd31e10d3c9e3665f64c4ef"
integrity sha512-rDYd3yOykArExr8Iz/hoP+2jI57NX0Z/LIDsPmH3W9vifXnb1SVBfekxE4vNXj9vJKLSZ8vfKgl3OuqYbOKVow==
dependencies:
classnames "2.5.1"
comlink "4.4.1"
cozy-pouch-link "^50.3.1"
flexsearch "0.7.43"
lodash "4.17.21"
mime-types "2.1.35"
react-type-animation "3.2.0"
rooks "7.14.1"

cozy-device-helper@^2.7.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/cozy-device-helper/-/cozy-device-helper-2.7.0.tgz#573749997f18e5a1f11f720faec8c9bf2406beeb"
Expand Down Expand Up @@ -8759,6 +8808,15 @@ [email protected], cozy-minilog@^3.3.1:
dependencies:
microee "0.0.6"

cozy-pouch-link@^50.3.1:
version "50.4.0"
resolved "https://registry.yarnpkg.com/cozy-pouch-link/-/cozy-pouch-link-50.4.0.tgz#6cd18521a8652502783d35ec6735de40af47ce62"
integrity sha512-7CkyEpsjjxE/24oMsxOcrQT+FWi7LPK0kYKx/KoiD7VX1QxHcZSubjnPjREJJkECs1JwIiAH5z/h99qVO4hArQ==
dependencies:
cozy-client "^50.4.0"
pouchdb-browser "^7.2.2"
pouchdb-find "^7.2.2"

cozy-pouch-link@^52.0.0:
version "52.0.0"
resolved "https://registry.yarnpkg.com/cozy-pouch-link/-/cozy-pouch-link-52.0.0.tgz#c3dac6497ecc1af6827657a20072f03d99c3e7e9"
Expand All @@ -8775,6 +8833,15 @@ cozy-realtime@^5.6.2:
dependencies:
"@cozy/minilog" "^1.0.0"

cozy-stack-client@^50.4.0:
version "50.4.0"
resolved "https://registry.yarnpkg.com/cozy-stack-client/-/cozy-stack-client-50.4.0.tgz#3326a1299cacb06b95a484dc656cc301ce811ade"
integrity sha512-u8NXO6uUrcT0SggtOePpOXftGdwe1zCiOHQIzvUAeuZIt4mVruF1zYXaPz90/zI4pHzr8mHH2h6KXHgH1McjWA==
dependencies:
detect-node "^2.0.4"
mime "^2.4.0"
qs "^6.7.0"

cozy-stack-client@^52.0.0:
version "52.0.0"
resolved "https://registry.yarnpkg.com/cozy-stack-client/-/cozy-stack-client-52.0.0.tgz#b146997637facc8de55033a84fd7e4b30ea4533d"
Expand Down Expand Up @@ -11027,6 +11094,11 @@ flatten@^1.0.2:
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.3.tgz#c1283ac9f27b368abc1e36d1ff7b04501a30356b"
integrity sha512-dVsPA/UwQ8+2uoFe5GHtiBMu48dWLTdsuEd7CKGlZlD78r1TTWBvDuFaFGKCo/ZfEr95Uk56vZoX86OsHkUeIg==

[email protected]:
version "0.7.43"
resolved "https://registry.yarnpkg.com/flexsearch/-/flexsearch-0.7.43.tgz#34f89b36278a466ce379c5bf6fb341965ed3f16c"
integrity sha512-c5o/+Um8aqCSOXGcZoqZOm+NqtVwNsvVpWv6lfmSclU954O3wvQKxxK8zj74fPaSJbXpSLTs4PRhh+wnoCXnKg==

flow-enums-runtime@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/flow-enums-runtime/-/flow-enums-runtime-0.0.6.tgz#5bb0cd1b0a3e471330f4d109039b7eba5cb3e787"
Expand Down Expand Up @@ -14204,7 +14276,7 @@ lodash.uniq@^4.5.0:
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=

"lodash@>=3.5 <5", lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.5, lodash@^4.7.0:
[email protected], "lodash@>=3.5 <5", lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.5, lodash@^4.7.0:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
Expand Down Expand Up @@ -14688,6 +14760,18 @@ [email protected], "mime-db@>= 1.43.0 < 2":
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.48.0.tgz#e35b31045dd7eada3aaad537ed88a33afbef2d1d"
integrity sha512-FM3QwxV+TnZYQ2aRqhlKBMHxk10lTbMt3bBkMAp54ddrNeVSfcQYOOKuGuy3Ddrm38I04If834fOUSq1yzslJQ==

[email protected]:
version "1.52.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==

[email protected]:
version "2.1.35"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
dependencies:
mime-db "1.52.0"

mime-types@^2.1.12, mime-types@^2.1.27, mime-types@~2.1.17, mime-types@~2.1.24:
version "2.1.31"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.31.tgz#a00d76b74317c61f9c2db2218b8e9f8e9c5c9e6b"
Expand Down Expand Up @@ -18027,6 +18111,11 @@ [email protected]:
react-shallow-renderer "^16.15.0"
scheduler "^0.23.0"

[email protected]:
version "3.2.0"
resolved "https://registry.yarnpkg.com/react-type-animation/-/react-type-animation-3.2.0.tgz#6863d5d60e3beb237f2bd690cceb585402c47e6a"
integrity sha512-WXTe0i3rRNKjmggPvT5ntye1QBt0ATGbijeW6V3cQe2W0jaMABXXlPPEdtofnS9tM7wSRHchEvI9SUw+0kUohw==

[email protected]:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
Expand Down Expand Up @@ -18588,6 +18677,16 @@ rollup@^1.31.1:
"@types/node" "*"
acorn "^7.1.0"

[email protected]:
version "7.14.1"
resolved "https://registry.yarnpkg.com/rooks/-/rooks-7.14.1.tgz#f3660752c299da02eb6cc733c55f8270c3376a87"
integrity sha512-oPuLNGm3OaFm3WfZHzmDvJvRit8QrXGm9/Kn49Bz8lJUjkThSBtERWzuQ9wb5DveqrpUZvmNyBXjBE0KWVt13w==
dependencies:
fast-deep-equal "^3.1.3"
lodash.debounce "^4.0.8"
raf "^3.4.1"
use-sync-external-store "^1.2.0"

rsvp@^4.8.4:
version "4.8.5"
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-4.8.5.tgz#c8f155311d167f68f21e168df71ec5b083113734"
Expand Down Expand Up @@ -20601,6 +20700,11 @@ use-sync-external-store@^1.0.0:
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz#7dbefd6ef3fe4e767a0cf5d7287aacfb5846928a"
integrity sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==

use-sync-external-store@^1.2.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.4.0.tgz#adbc795d8eeb47029963016cefdf89dc799fcebc"
integrity sha512-9WXSPC5fMv61vaupRkCKCxsPxBocVnwakBEkMIHHpkTTg6icbJtg6jzgtLDm4bl3cSHAca52rYWih0k4K3PfHw==

use@^3.1.0:
version "3.1.1"
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
Expand Down
Loading