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

[PRD-600] feat: Use local search only for persistent sessions #11

Merged
merged 2 commits into from
Nov 8, 2024
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: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"dependencies": {
"comlink": "^4.4.1",
"cozy-app-publish": "^0.34.0",
"cozy-client": "^50.3.1",
"cozy-dataproxy-lib": "^1.1.1",
"cozy-client": "^51.0.0",
"cozy-dataproxy-lib": "^1.3.0",
"cozy-device-helper": "^3.1.0",
"cozy-flags": "^4.0.0",
"cozy-logger": "^1.10.4",
Expand Down
1 change: 1 addition & 0 deletions src/@types/cozy-client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ declare module 'cozy-client' {
capabilities: ClientCapabilities
registerPlugin: (Plugin: Function, options: unknown) => void
getCollectionFromState: (doctype: string) => unknown
setLinks: (links: unknown[]) => void
}

export const createMockClient = (options?: ClientOptions): CozyClient =>
Expand Down
2 changes: 1 addition & 1 deletion src/dataproxy/worker/SharedWorkerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
DataProxyWorkerPartialState
} from '@/dataproxy/common/DataProxyInterface'
import { TabCountSync } from '@/dataproxy/common/TabCountSync'
import { removeStaleLocalData } from '@/dataproxy/worker/utils'
import { removeStaleLocalData } from '@/dataproxy/worker/data'

const log = Minilog('👷‍♂️ [SharedWorkerProvider]')

Expand Down
23 changes: 23 additions & 0 deletions src/dataproxy/worker/utils.ts → src/dataproxy/worker/data.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
import CozyClient from 'cozy-client'
import Minilog from 'cozy-minilog'

import { LOCALSTORAGE_KEY_DELETING_DATA } from '@/consts'
const log = Minilog('👷‍♂️ [Worker utils]')

interface SessionInfo {
last_seen: string
long_run: boolean
}

interface SessionResponse {
data: {
attributes: SessionInfo
}
}

export const queryIsTrustedDevice = async (
client: CozyClient
): Promise<boolean> => {
const resp: SessionResponse = await client
.getStackClient()
.fetchJSON('GET', '/settings/sessions/current')

const isLongRun = resp?.data?.attributes?.long_run
return !!isLongRun
}

const deleteDatabases = async (): Promise<void> => {
const databases = await window.indexedDB.databases()
// Remove all indexedDB databases
Expand Down
15 changes: 12 additions & 3 deletions src/dataproxy/worker/shared-worker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Comlink from 'comlink'

import CozyClient from 'cozy-client'
import CozyClient, { StackLink } from 'cozy-client'
import { SearchEngine } from 'cozy-dataproxy-lib'
import Minilog from 'cozy-minilog'
import PouchLink from 'cozy-pouch-link'
Expand All @@ -17,6 +17,7 @@ import {
DataProxyWorker,
DataProxyWorkerPartialState
} from '@/dataproxy/common/DataProxyInterface'
import { queryIsTrustedDevice } from '@/dataproxy/worker/data'
import { platformWorker } from '@/dataproxy/worker/platformWorker'
import schema from '@/doctypes'
import { getPouchLink } from '@/helpers/client'
Expand Down Expand Up @@ -63,9 +64,17 @@ const dataProxy: DataProxyWorker = {
version: '1'
},
schema,
store: true,
links: [new PouchLink(pouchLinkOptions)]
store: true
})

// If the device is not trusted, we do not want to store any private data in Pouch
// So use the PouchLink only if the user declared a trustful device for the given session
const isTrustedDevice = await queryIsTrustedDevice(client)
const link = isTrustedDevice
? new PouchLink(pouchLinkOptions)
: new StackLink()

client.setLinks([link])
client.instanceOptions = clientData.instanceOptions
client.capabilities = clientData.capabilities

Expand Down
44 changes: 39 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2248,7 +2248,7 @@ cozy-app-publish@^0.34.0:
tar "^6.1.11"
verror "^1.10.1"

cozy-client@^50.3.1, cozy-client@^50.4.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==
Expand All @@ -2273,10 +2273,35 @@ cozy-client@^50.3.1, cozy-client@^50.4.0:
sift "^6.0.0"
url-search-params-polyfill "^8.0.0"

cozy-dataproxy-lib@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/cozy-dataproxy-lib/-/cozy-dataproxy-lib-1.1.1.tgz#2a70f62ef92cff6fea156408db3e2ed48ada2918"
integrity sha512-iHLJRU6lTtN8MxQU5thepcIaaWzd3RwPOnmigC95O1Yy/heoTDVTZlBC1B937tbBJZbuVO7OdDINt5iSGjNEEg==
cozy-client@^51.0.0:
version "51.0.0"
resolved "https://registry.yarnpkg.com/cozy-client/-/cozy-client-51.0.0.tgz#84b7f9c6a3c678791de7b06539af6595e0bb51c2"
integrity sha512-txbEkQFuZX1ZXi1/2bXLJK9SQR+sbZjjztIv3pt+g73veuVVz5wyDoJkMbLLf5dSiHARpHIWgIdBfX4prZwpWQ==
dependencies:
"@cozy/minilog" "1.0.0"
"@types/jest" "^26.0.20"
"@types/lodash" "^4.14.170"
btoa "^1.2.1"
cozy-stack-client "^51.0.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-dataproxy-lib@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/cozy-dataproxy-lib/-/cozy-dataproxy-lib-1.3.0.tgz#f2c1c1d5f72a4426ba51206cb412e4efffd1c57a"
integrity sha512-M2lIuFDEIHh0uw08o+LaPdiIttUsyKheC2tbjWfSxhpgOgePzmbj3Lpt474hOwVatxFsSjy2aiKKd9mWd9s/zw==
dependencies:
comlink "^4.4.1"
flexsearch "^0.7.43"
Expand Down Expand Up @@ -2336,6 +2361,15 @@ cozy-stack-client@^50.4.0:
mime "^2.4.0"
qs "^6.7.0"

cozy-stack-client@^51.0.0:
version "51.0.0"
resolved "https://registry.yarnpkg.com/cozy-stack-client/-/cozy-stack-client-51.0.0.tgz#73fbdb1cf8efc46cb89ad2266d04e1289a9ae355"
integrity sha512-ToaheKT0cziulvAxUl+H8mqmSXQmblCp6a5TKNnrEHOS3ExTmzOHmIgNrRDgDKi4G8hK93CZTi8gj49ffk0HYw==
dependencies:
detect-node "^2.0.4"
mime "^2.4.0"
qs "^6.7.0"

cozy-tsconfig@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/cozy-tsconfig/-/cozy-tsconfig-1.2.0.tgz#17e61f960f139fae4d26cbac2254b9ab632b269e"
Expand Down