From a349d71b2ef11c6c33d0b3c79c3c8e9f6f192a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Poizat?= Date: Thu, 30 Jan 2025 17:26:39 +0100 Subject: [PATCH] feat: Remove fsnative model and mobile cordova helpers It is cordova related code that is unused now. BREAKING CHANGE: fsnative model has been removed. readMobileFile and doMobileUpload methods have been removed on file model. If you still have them in an app, you can safely remove the code. --- docs/api/cozy-client/classes/CozyClient.md | 67 +++-- docs/api/cozy-client/modules/models.file.md | 60 +---- packages/cozy-client/src/CozyClient.js | 3 +- .../cozy-client/src/authentication/mobile.js | 120 +-------- packages/cozy-client/src/models/file.js | 57 ----- packages/cozy-client/src/models/fsnative.js | 240 ------------------ .../cozy-client/src/models/fsnative.spec.js | 118 --------- packages/cozy-client/src/types.js | 15 -- packages/cozy-client/types/CozyClient.d.ts | 3 +- .../types/authentication/mobile.d.ts | 3 +- packages/cozy-client/types/models/file.d.ts | 2 - .../cozy-client/types/models/fsnative.d.ts | 22 -- packages/cozy-client/types/types.d.ts | 11 - .../cozy-pouch-link/src/PouchManager.spec.js | 2 +- packages/cozy-pouch-link/src/helpers.js | 2 +- 15 files changed, 47 insertions(+), 678 deletions(-) delete mode 100644 packages/cozy-client/src/models/fsnative.js delete mode 100644 packages/cozy-client/src/models/fsnative.spec.js delete mode 100644 packages/cozy-client/types/models/fsnative.d.ts diff --git a/docs/api/cozy-client/classes/CozyClient.md b/docs/api/cozy-client/classes/CozyClient.md index 75c391d847..46aa09142f 100644 --- a/docs/api/cozy-client/classes/CozyClient.md +++ b/docs/api/cozy-client/classes/CozyClient.md @@ -73,7 +73,7 @@ Cozy-Client will automatically call `this.login()` if provided with a token and *Defined in* -[packages/cozy-client/src/CozyClient.js:1859](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1859) +[packages/cozy-client/src/CozyClient.js:1858](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1858) *** @@ -83,7 +83,7 @@ Cozy-Client will automatically call `this.login()` if provided with a token and *Defined in* -[packages/cozy-client/src/CozyClient.js:1719](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1719) +[packages/cozy-client/src/CozyClient.js:1718](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1718) *** @@ -123,7 +123,7 @@ Cozy-Client will automatically call `this.login()` if provided with a token and *Defined in* -[packages/cozy-client/src/CozyClient.js:1855](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1855) +[packages/cozy-client/src/CozyClient.js:1854](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1854) *** @@ -209,7 +209,7 @@ Cozy-Client will automatically call `this.login()` if provided with a token and *Defined in* -[packages/cozy-client/src/CozyClient.js:1694](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1694) +[packages/cozy-client/src/CozyClient.js:1693](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1693) *** @@ -219,7 +219,7 @@ Cozy-Client will automatically call `this.login()` if provided with a token and *Defined in* -[packages/cozy-client/src/CozyClient.js:1624](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1624) +[packages/cozy-client/src/CozyClient.js:1623](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1623) *** @@ -363,7 +363,7 @@ Contains the fetched token and the client information. These should be stored an *Defined in* -[packages/cozy-client/src/CozyClient.js:1540](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1540) +[packages/cozy-client/src/CozyClient.js:1539](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1539) *** @@ -381,7 +381,7 @@ This mechanism is described in https://github.com/cozy/cozy-client/blob/master/p *Defined in* -[packages/cozy-client/src/CozyClient.js:1521](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1521) +[packages/cozy-client/src/CozyClient.js:1520](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1520) *** @@ -397,7 +397,7 @@ Returns whether the client has been revoked on the server *Defined in* -[packages/cozy-client/src/CozyClient.js:1636](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1636) +[packages/cozy-client/src/CozyClient.js:1635](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1635) *** @@ -481,7 +481,7 @@ If `oauth` options are passed, stackClient is an OAuthStackClient. *Defined in* -[packages/cozy-client/src/CozyClient.js:1674](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1674) +[packages/cozy-client/src/CozyClient.js:1673](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1673) *** @@ -526,7 +526,7 @@ The document that has been deleted *Defined in* -[packages/cozy-client/src/CozyClient.js:1745](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1745) +[packages/cozy-client/src/CozyClient.js:1744](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1744) *** @@ -612,7 +612,7 @@ Makes sure that the query exists in the store *Defined in* -[packages/cozy-client/src/CozyClient.js:1627](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1627) +[packages/cozy-client/src/CozyClient.js:1626](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1626) *** @@ -757,7 +757,7 @@ Creates an association that is linked to the store. *Defined in* -[packages/cozy-client/src/CozyClient.js:1727](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1727) +[packages/cozy-client/src/CozyClient.js:1726](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1726) *** @@ -877,7 +877,7 @@ getInstanceOptions - Returns current instance options, such as domain or app slu *Defined in* -[packages/cozy-client/src/CozyClient.js:1754](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1754) +[packages/cozy-client/src/CozyClient.js:1753](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1753) *** @@ -965,7 +965,7 @@ extract the value corresponding to the given `key` *Defined in* -[packages/cozy-client/src/CozyClient.js:1883](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1883) +[packages/cozy-client/src/CozyClient.js:1882](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1882) *** @@ -979,7 +979,7 @@ extract the value corresponding to the given `key` *Defined in* -[packages/cozy-client/src/CozyClient.js:1734](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1734) +[packages/cozy-client/src/CozyClient.js:1733](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1733) *** @@ -1001,7 +1001,7 @@ Sets public attribute and emits event related to revocation *Defined in* -[packages/cozy-client/src/CozyClient.js:1645](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1645) +[packages/cozy-client/src/CozyClient.js:1644](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1644) *** @@ -1023,7 +1023,7 @@ Emits event when token is refreshed *Defined in* -[packages/cozy-client/src/CozyClient.js:1656](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1656) +[packages/cozy-client/src/CozyClient.js:1655](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1655) *** @@ -1109,7 +1109,7 @@ Instead, the relationships will have null documents. *Defined in* -[packages/cozy-client/src/CozyClient.js:1497](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1497) +[packages/cozy-client/src/CozyClient.js:1496](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1496) *** @@ -1131,7 +1131,7 @@ loadInstanceOptionsFromDOM - Loads the dataset injected by the Stack in web page *Defined in* -[packages/cozy-client/src/CozyClient.js:1765](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1765) +[packages/cozy-client/src/CozyClient.js:1764](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1764) *** @@ -1149,7 +1149,7 @@ This method is not iso with loadInstanceOptionsFromDOM for now. *Defined in* -[packages/cozy-client/src/CozyClient.js:1786](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1786) +[packages/cozy-client/src/CozyClient.js:1785](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1785) *** @@ -1411,7 +1411,7 @@ All documents matching the query *Defined in* -[packages/cozy-client/src/CozyClient.js:1741](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1741) +[packages/cozy-client/src/CozyClient.js:1740](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1740) *** @@ -1419,8 +1419,7 @@ All documents matching the query ▸ **register**(`cozyURL`): `any` -Performs a complete OAuth flow using a Cordova webview -or React Native WebView for auth. +Performs a complete OAuth flow using a React Native WebView for auth. The `register` method's name has been chosen for compat reasons with the Authentication compo. *Parameters* @@ -1437,7 +1436,7 @@ Contains the fetched token and the client information. *Defined in* -[packages/cozy-client/src/CozyClient.js:1491](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1491) +[packages/cozy-client/src/CozyClient.js:1490](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1490) *** @@ -1558,7 +1557,7 @@ Contains the fetched token and the client information. *Defined in* -[packages/cozy-client/src/CozyClient.js:1586](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1586) +[packages/cozy-client/src/CozyClient.js:1585](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1585) *** @@ -1605,7 +1604,7 @@ This method will reset the query state to its initial state and refetch it. *Defined in* -[packages/cozy-client/src/CozyClient.js:1912](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1912) +[packages/cozy-client/src/CozyClient.js:1911](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1911) *** @@ -1663,7 +1662,7 @@ save the new resulting settings into database *Defined in* -[packages/cozy-client/src/CozyClient.js:1900](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1900) +[packages/cozy-client/src/CozyClient.js:1899](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1899) *** @@ -1712,7 +1711,7 @@ Saves multiple documents in one batch *Defined in* -[packages/cozy-client/src/CozyClient.js:1840](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1840) +[packages/cozy-client/src/CozyClient.js:1839](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1839) *** @@ -1736,7 +1735,7 @@ set some data in the store. *Defined in* -[packages/cozy-client/src/CozyClient.js:1813](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1813) +[packages/cozy-client/src/CozyClient.js:1812](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1812) *** @@ -1760,7 +1759,7 @@ we manually call the links onLogin methods *Defined in* -[packages/cozy-client/src/CozyClient.js:1854](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1854) +[packages/cozy-client/src/CozyClient.js:1853](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1853) *** @@ -1784,7 +1783,7 @@ At any time put an error function *Defined in* -[packages/cozy-client/src/CozyClient.js:1826](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1826) +[packages/cozy-client/src/CozyClient.js:1825](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1825) *** @@ -1822,7 +1821,7 @@ use options.force = true. *Defined in* -[packages/cozy-client/src/CozyClient.js:1612](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1612) +[packages/cozy-client/src/CozyClient.js:1611](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1611) *** @@ -1846,7 +1845,7 @@ Contains the fetched token and the client information. These should be stored an *Defined in* -[packages/cozy-client/src/CozyClient.js:1507](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1507) +[packages/cozy-client/src/CozyClient.js:1506](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1506) *** @@ -1860,7 +1859,7 @@ Contains the fetched token and the client information. These should be stored an *Defined in* -[packages/cozy-client/src/CozyClient.js:1833](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1833) +[packages/cozy-client/src/CozyClient.js:1832](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1832) *** diff --git a/docs/api/cozy-client/modules/models.file.md b/docs/api/cozy-client/modules/models.file.md index 05dfffa1be..f191a50106 100644 --- a/docs/api/cozy-client/modules/models.file.md +++ b/docs/api/cozy-client/modules/models.file.md @@ -44,31 +44,7 @@ Copies a file to a specified destination. *Defined in* -[packages/cozy-client/src/models/file.js:695](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/file.js#L695) - -*** - -### doMobileUpload - -▸ **doMobileUpload**(`client`, `fileURL`, `options`): `Promise`<`any`> - -Upload a file on a mobile - -*Parameters* - -| Name | Type | Description | -| :------ | :------ | :------ | -| `client` | [`CozyClient`](../classes/CozyClient.md) | The CozyClient instance | -| `fileURL` | `string` | The local file path (file://) | -| `options` | [`FileUploadOptions`](../interfaces/models.file.FileUploadOptions.md) | The upload options | - -*Returns* - -`Promise`<`any`> - -*Defined in* - -[packages/cozy-client/src/models/file.js:632](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/file.js#L632) +[packages/cozy-client/src/models/file.js:638](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/file.js#L638) *** @@ -99,7 +75,7 @@ that will process the download *Defined in* -[packages/cozy-client/src/models/file.js:749](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/file.js#L749) +[packages/cozy-client/src/models/file.js:692](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/file.js#L692) *** @@ -145,7 +121,7 @@ file object with path attribute *Defined in* -[packages/cozy-client/src/models/file.js:678](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/file.js#L678) +[packages/cozy-client/src/models/file.js:621](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/file.js#L621) *** @@ -383,7 +359,7 @@ The mime-type of the target file, or an empty string is the target is not a file *Defined in* -[packages/cozy-client/src/models/file.js:658](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/file.js#L658) +[packages/cozy-client/src/models/file.js:601](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/file.js#L601) *** @@ -427,7 +403,7 @@ Whether the file's metadata attribute exists *Defined in* -[packages/cozy-client/src/models/file.js:650](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/file.js#L650) +[packages/cozy-client/src/models/file.js:593](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/file.js#L593) *** @@ -553,7 +529,7 @@ Whether the folder is client-side encrypted *Defined in* -[packages/cozy-client/src/models/file.js:669](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/file.js#L669) +[packages/cozy-client/src/models/file.js:612](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/file.js#L612) *** @@ -618,7 +594,7 @@ Whether the file is supported by Only Office *Defined in* -[packages/cozy-client/src/models/file.js:642](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/file.js#L642) +[packages/cozy-client/src/models/file.js:585](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/file.js#L585) *** @@ -824,28 +800,6 @@ The overrided file *** -### readMobileFile - -▸ **readMobileFile**(`fileURL`): `Promise`<`any`> - -Read a file on a mobile - -*Parameters* - -| Name | Type | Description | -| :------ | :------ | :------ | -| `fileURL` | `string` | The local file path (file://) | - -*Returns* - -`Promise`<`any`> - -*Defined in* - -[packages/cozy-client/src/models/file.js:585](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/file.js#L585) - -*** - ### saveFileQualification ▸ **saveFileQualification**(`client`, `file`, `qualification`): `Promise`<`IOCozyFile`> diff --git a/packages/cozy-client/src/CozyClient.js b/packages/cozy-client/src/CozyClient.js index ef98bc1365..f0991ab16c 100644 --- a/packages/cozy-client/src/CozyClient.js +++ b/packages/cozy-client/src/CozyClient.js @@ -1481,8 +1481,7 @@ client.query(Q('io.cozy.bills'))`) } /** - * Performs a complete OAuth flow using a Cordova webview - * or React Native WebView for auth. + * Performs a complete OAuth flow using a React Native WebView for auth. * The `register` method's name has been chosen for compat reasons with the Authentication compo. * * @param {string} cozyURL Receives the URL of the cozy instance. diff --git a/packages/cozy-client/src/authentication/mobile.js b/packages/cozy-client/src/authentication/mobile.js index 9fe365b1de..a11bc603db 100644 --- a/packages/cozy-client/src/authentication/mobile.js +++ b/packages/cozy-client/src/authentication/mobile.js @@ -1,119 +1,3 @@ -/* global prompt */ -import { REGISTRATION_ABORT } from '../const' -import { - hasInAppBrowserPlugin, - hasSafariPlugin, - isIOSApp -} from 'cozy-device-helper' - -/** - * @type {import("../types").CordovaWindow} - */ -// @ts-ignore -const win = typeof window !== 'undefined' ? window : null - -/** - * Open a SafariView Controller and resolve with the URL containing the token - * - * @param {string} url - Url containing access_code and state - * @returns {Promise} - */ -const authenticateWithSafari = url => { - return new Promise((resolve, reject) => { - win.SafariViewController.show( - { - url: url, - transition: 'curl' // (this only works in iOS 9.1/9.2 and lower) unless animated is false you can choose from: curl, flip, fade, slide (default) - // enterReaderModeIfAvailable: readerMode, // default false - // tintColor: "#00ffff", // default is ios blue - // barColor: "#0000ff", // on iOS 10+ you can change the background color as well - // controlTintColor: "#ffffff" // on iOS 10+ you can override the default tintColor - }, - // this success handler will be invoked for the lifecycle events 'opened', 'loaded' and 'closed' - result => { - if (result.event === 'closed') { - reject(new Error(REGISTRATION_ABORT)) - } - }, - error => { - console.log('KO: ' + error) - reject(new Error(REGISTRATION_ABORT)) - } - ) - - const handle = win.handleOpenURL - win.handleOpenURL = url => { - win.SafariViewController.hide() - resolve(url) - if (handle) { - win.handleOpenURL = handle - } - } - }) +export const authFunction = () => { + throw 'Not implemented' } -/** - * Opens an InAppBrowser and resolves with the URL containing the token - * - * @param {string} url - Url containing access_code and state - * @returns {Promise} - */ -const authenticateWithInAppBrowser = url => { - return new Promise((resolve, reject) => { - const target = '_blank' - const options = 'clearcache=yes,zoom=no' - const inAppBrowser = win.cordova.InAppBrowser.open(url, target, options) - - const removeListener = () => { - inAppBrowser.removeEventListener('loadstart', onLoadStart) - inAppBrowser.removeEventListener('exit', onExit) - } - - const onLoadStart = ({ url }) => { - const accessCode = /\?access_code=(.+)$/.test(url) - const state = /\?state=(.+)$/.test(url) - - if (accessCode || state) { - resolve(url) - removeListener() - inAppBrowser.close() - } - } - - const onExit = () => { - reject(new Error(REGISTRATION_ABORT)) - removeListener() - inAppBrowser.close() - } - - inAppBrowser.addEventListener('loadstart', onLoadStart) - inAppBrowser.addEventListener('exit', onExit) - }) -} - -export const authenticateWithCordova = async url => { - if (isIOSApp() && (await hasSafariPlugin())) { - return authenticateWithSafari(url) - } else if (hasInAppBrowserPlugin()) { - return authenticateWithInAppBrowser(url) - } else { - /** - * for dev purpose: - * In oauth workflow, the server displays an authorization page - * User must accept to give permission then the server gives an url - * with query parameters used by cozy-client-js to initialize itself. - * - * This hack let developers open the authorization page in a new tab - * then get the "access_code" url and paste it in the prompt to let the - * application initialize and redirect to other pages. - */ - console.log(url) // Useful for dev (see above). - return new Promise(resolve => { - setTimeout(() => { - const token = prompt('Paste the url here:') - resolve(token) - }, 5000) - }) - } -} - -export const authFunction = authenticateWithCordova diff --git a/packages/cozy-client/src/models/file.js b/packages/cozy-client/src/models/file.js index ac5be3b91a..83e48a760c 100644 --- a/packages/cozy-client/src/models/file.js +++ b/packages/cozy-client/src/models/file.js @@ -577,63 +577,6 @@ export const uploadFileWithConflictStrategy = async (client, file, options) => { } } -/** - * Read a file on a mobile - * - * @param {string} fileURL - The local file path (file://) - */ -export const readMobileFile = async fileURL => { - /** Cordova plugin doesn't support promise since they are supporting Android 4.X.X - * so we have to create manually a promise to be able to write beautiful code ;) - */ - - const p = new Promise((resolve, reject) => { - const onResolvedLocalFS = async fileEntry => { - fileEntry.file( - async file => { - const reader = new FileReader() - reader.onloadend = async () => { - resolve(reader.result) - } - // Read the file as an ArrayBuffer - reader.readAsArrayBuffer(file) - }, - err => { - // Since this module is pretty recent, let's have this info in sentry if needed - console.error('error getting fileentry file!' + err) // eslint-disable-line no-console - reject(err) - } - ) - } - const onError = error => { - reject(error) - } - /** - * file:/// can not be converted to a fileEntry without the Cordova's File plugin. - * `resolveLocalFileSystemURL` is provided by this plugin and can resolve the native - * path to a fileEntry readable by a `FileReader` - * - * When we finished to read the fileEntry as buffer, we start the upload process - * - */ - // @ts-ignore - window.resolveLocalFileSystemURL(fileURL, onResolvedLocalFS, onError) - }) - return p -} - -/** - * Upload a file on a mobile - * - * @param {CozyClient} client - The CozyClient instance - * @param {string} fileURL - The local file path (file://) - * @param {FileUploadOptions} options - The upload options - */ -export const doMobileUpload = async (client, fileURL, options) => { - const file = await readMobileFile(fileURL) - return uploadFileWithConflictStrategy(client, file, options) -} - /** * @param {string} [mimeType=''] - Mime type of file * @param {string} [fileName=''] - Name of file diff --git a/packages/cozy-client/src/models/fsnative.js b/packages/cozy-client/src/models/fsnative.js deleted file mode 100644 index 821fd490da..0000000000 --- a/packages/cozy-client/src/models/fsnative.js +++ /dev/null @@ -1,240 +0,0 @@ -import { isMobileApp, isAndroidApp, isIOS } from 'cozy-device-helper' - -import CozyClient from '../CozyClient' -import { CordovaWindow } from '../types' -import logger from '../logger' -import { DOCTYPE_FILES } from '../const' - -const ERROR_GET_DIRECTORY = 'Error to get directory' -const ERROR_WRITE_FILE = 'Error to write file' -const ERROR_GET_FILE = 'Error to get file' -const COZY_PATH = 'Cozy' -const COZY_FILES_PATH = isIOS() ? 'CozyDrive' : 'Cozy Drive' - -/** - * @typedef {object} FilesystemEntry - */ - -/** - * @type {CordovaWindow} - */ -// @ts-ignore -const win = window - -/** - * Get root path according the OS - * - * @returns {string} - */ -export const getRootPath = () => { - return isAndroidApp() - ? win.cordova.file.externalDataDirectory - : win.cordova.file.dataDirectory -} - -/** - * Get the temporary root path according to the OS - */ -export const getTemporaryRootPath = () => - isAndroidApp() - ? win.cordova.file.externalCacheDirectory - : win.cordova.file.cacheDirectory - -/** - * Get Cozy path according to the OS - * - * @returns {string} - */ -export const getCozyPath = () => COZY_PATH + '/' + COZY_FILES_PATH + '/' - -/** - * Get entry of a path in the cordova.file location - * - * @param {string} path - Path wanting to be getted - * @returns {Promise} - */ -export const getEntry = path => - new Promise((resolve, reject) => { - win.resolveLocalFileSystemURL(path, resolve, err => { - logger.error(`${path} could not be resolved: ${err.message}`) - reject(err) - }) - }) - -/** - * Get Cozy location on the device - */ -export const getCozyEntry = () => - getEntry(getRootPath() + getCozyPath()).catch(() => createCozyPath()) - -/** - * Create Cozy path on the device - */ -export const createCozyPath = () => - getEntry(getRootPath()).then(entry => - getDirectory(entry, COZY_PATH).then(entry => - getDirectory(entry, COZY_FILES_PATH) - ) - ) - -/** - * Get the directory according to its name - * - * @param {object} rootDirEntry - The root directory entry - * @param {string} folderName - The folder's name - */ -export const getDirectory = (rootDirEntry, folderName) => - new Promise((resolve, reject) => { - rootDirEntry.getDirectory(folderName, { create: true }, resolve, error => { - logger.warn(ERROR_GET_DIRECTORY, folderName) - logger.warn(error) - reject(ERROR_GET_DIRECTORY) - }) - }) - -/** - * @param {object} fileEntry - The file entry - * @param {object} dataObj - The data to be written - */ -export const writeFile = (fileEntry, dataObj) => - new Promise((resolve, reject) => { - fileEntry.createWriter(fileWriter => { - fileWriter.onwriteend = () => { - resolve(fileEntry) - } - fileWriter.onerror = error => { - logger.warn(ERROR_WRITE_FILE) - logger.warn(error) - reject(ERROR_WRITE_FILE) - } - fileWriter.write(dataObj) - }) - }) - -/** - * @param {object} dirEntry - The directory entry - * @param {object} fileData - The file data - * @param {string} fileName - The file name - */ -const saveFile = (dirEntry, fileData, fileName) => - new Promise((resolve, reject) => { - dirEntry.getFile( - fileName, - { create: true, exclusive: false }, - fileEntry => { - writeFile(fileEntry, fileData) - .then(() => { - resolve(fileEntry) - }) - .catch(reject) - }, - error => { - logger.warn(ERROR_GET_FILE) - logger.warn(error) - reject(ERROR_GET_FILE) - } - ) - }) - -/** - * Open a file in an other app - * - * @param {*} URI - URI to be opened - * @param {*} mimetype - Mimetype of the opened file - */ -export const openFileWithCordova = (URI, mimetype) => - new Promise((resolve, reject) => { - const callbacks = { - error: reject, - success: resolve - } - win.cordova.plugins.fileOpener2.open(URI, mimetype, callbacks) - }) - -/** - * @param {string} fileName - The file name - */ -export const deleteOfflineFile = async fileName => { - const entry = await getCozyEntry() - const fileEntry = await getEntry(`${entry.nativeURL}${fileName}`) - return fileEntry.remove() -} - -/** - * @param {object} fileData - The file data - * @param {string} fileName - The file name - */ -export const saveFileWithCordova = (fileData, fileName) => - getCozyEntry().then(entry => saveFile(entry, fileData, fileName)) - -/** - * Save the document in the temporary folder - * - * @param {object} file - io.cozy.files document - * @param {string} fileName - The file name - */ -export const temporarySave = (file, fileName) => - getEntry(getTemporaryRootPath()).then(entry => - saveFile(entry, file, fileName) - ) - -/** - * Save the document in the temporary folder and open it in an other app - * - * @param {Blob} blob - Binary of the file - * @param {object} file - io.cozy.files document - */ -export const saveAndOpenWithCordova = (blob, file) => { - return temporarySave(blob, file.name).then(entry => - openFileWithCordova(entry.nativeURL, file.mime) - ) -} - -/** - * @param {object} file - io.cozy.files document - */ -export const getNativeFile = async file => { - const entry = await getCozyEntry() - return getEntry(`${entry.nativeURL}${file.id}`) -} - -/** - * @param {object} file - io.cozy.files document - */ -export const openOfflineFile = async file => { - const fileEntry = await getNativeFile(file) - return openFileWithCordova(fileEntry.nativeURL, file.mime) -} - -/** - * openFileWith - Opens a file on a mobile device - * - * @param {CozyClient} client - The CozyClient instance - * @param {object} file - io.cozy.files document - */ -export const openFileWith = async (client, file) => { - if (isMobileApp() && win.cordova.plugins.fileOpener2) { - let fileData - try { - fileData = await client - .collection(DOCTYPE_FILES) - .fetchFileContent(file.id) - } catch (e) { - throw e.status === 404 ? 'missing' : 'offline' - } - const blob = await fileData.blob() - try { - await fsnative.saveAndOpenWithCordova(blob, file) - } catch (e) { - throw 'noapp' - } - } else { - throw 'noapp' - } -} - -const fsnative = { - saveAndOpenWithCordova -} - -export default fsnative diff --git a/packages/cozy-client/src/models/fsnative.spec.js b/packages/cozy-client/src/models/fsnative.spec.js deleted file mode 100644 index 4019b86b9b..0000000000 --- a/packages/cozy-client/src/models/fsnative.spec.js +++ /dev/null @@ -1,118 +0,0 @@ -import { isMobileApp } from 'cozy-device-helper' - -import { createMockClient } from '../mock' - -import fsnative, { getRootPath, openFileWith } from './fsnative' - -jest.spyOn(fsnative, 'saveAndOpenWithCordova').mockReturnValue() - -jest.mock('cozy-device-helper', () => ({ - ...jest.requireActual('cozy-device-helper'), - isMobileApp: jest.fn() -})) - -const ANDROID_ROOT_DIRECTORY = 'externalDataDirectory' -const IOS_ROOT_DIRECTORY = 'dataDirectory' -const EXTERNAL_CACHE_DIRECTORY = 'externalCacheDirectory' -const CACHE_DIRECTORY = 'cacheDirectory' -const ANDROID = 'android' -const IOS = 'ios' - -describe('getRootPath', () => { - beforeEach(() => { - window.cordova = { - file: { - externalDataDirectory: ANDROID_ROOT_DIRECTORY, - dataDirectory: IOS_ROOT_DIRECTORY - }, - platformId: ANDROID - } - }) - - it('should get root path', () => { - window.cordova.platformId = ANDROID - expect(getRootPath()).toEqual(ANDROID_ROOT_DIRECTORY) - window.cordova.platformId = IOS - expect(getRootPath()).toEqual(IOS_ROOT_DIRECTORY) - }) -}) - -describe('openFileWith', () => { - const mockClient = createMockClient({}) - const blobMock = jest.fn() - const file = { id: 'fileId' } - - beforeEach(() => { - jest.resetAllMocks() - isMobileApp.mockReturnValue(true) - - mockClient.collection = jest.fn().mockReturnValue(mockClient) - mockClient.fetchFileContent = jest.fn().mockReturnValue({ - blob: blobMock - }) - - window.cordova = { - file: { - externalCacheDirectory: EXTERNAL_CACHE_DIRECTORY, - cacheDirectory: CACHE_DIRECTORY - }, - plugins: { fileOpener2: {} } - } - }) - - it('opens the file with cordova', async () => { - blobMock.mockReturnValue('fake file blob') - await openFileWith(mockClient, file) - expect(mockClient.fetchFileContent).toHaveBeenCalledWith(file.id) - expect(fsnative.saveAndOpenWithCordova).toHaveBeenCalledWith( - 'fake file blob', - file - ) - }) - - it('errors when it fails to download the file without 404', async () => { - expect.assertions(1) - mockClient.fetchFileContent = jest.fn().mockRejectedValue(new Error()) - - try { - await openFileWith(mockClient, file) - } catch (e) { - expect(e).toMatch('offline') - } - }) - - it('errors when it fails to download the file with 404', async () => { - expect.assertions(1) - const error = new Error('Not Found') - error.status = 404 - mockClient.fetchFileContent = jest.fn().mockRejectedValue(error) - - try { - await openFileWith(mockClient, file) - } catch (e) { - expect(e).toMatch('missing') - } - }) - - it('errors when opening the filewith cordova fails', async () => { - expect.assertions(1) - fsnative.saveAndOpenWithCordova.mockRejectedValue(new Error()) - - try { - await openFileWith(mockClient, file) - } catch (e) { - expect(e).toMatch('noapp') - } - }) - - it('errors when the plugin is not present', async () => { - expect.assertions(1) - window.cordova.plugins.fileOpener2 = null - - try { - await openFileWith(mockClient, file) - } catch (e) { - expect(e).toMatch('noapp') - } - }) -}) diff --git a/packages/cozy-client/src/types.js b/packages/cozy-client/src/types.js index 5e404c938f..1c1e3092a0 100644 --- a/packages/cozy-client/src/types.js +++ b/packages/cozy-client/src/types.js @@ -691,21 +691,6 @@ import { QueryDefinition } from './queries/dsl' * @description Read more about client capabilities here https://docs.cozy.io/en/cozy-stack/settings/#get-settingscapabilities. */ -/** - * @typedef Cordova - * @property {FilePlugin} file - * @property {InAppBrowser} InAppBrowser - * @property {object} plugins - */ - -/** - * @typedef CordovaWindow - * @property {Cordova} cordova - * @property {object} SafariViewController - * @property {Function} resolveLocalFileSystemURL - * @property {Function} handleOpenURL - */ - /** * @typedef {object} CouchDBDocument - A document * @property {string} _id - Id of the document diff --git a/packages/cozy-client/types/CozyClient.d.ts b/packages/cozy-client/types/CozyClient.d.ts index c4080afb3a..565f17de4c 100644 --- a/packages/cozy-client/types/CozyClient.d.ts +++ b/packages/cozy-client/types/CozyClient.d.ts @@ -643,8 +643,7 @@ declare class CozyClient { options: import("./types").QueryOptions; }) => Promise; /** - * Performs a complete OAuth flow using a Cordova webview - * or React Native WebView for auth. + * Performs a complete OAuth flow using a React Native WebView for auth. * The `register` method's name has been chosen for compat reasons with the Authentication compo. * * @param {string} cozyURL Receives the URL of the cozy instance. diff --git a/packages/cozy-client/types/authentication/mobile.d.ts b/packages/cozy-client/types/authentication/mobile.d.ts index 1fad40794a..43f74c6504 100644 --- a/packages/cozy-client/types/authentication/mobile.d.ts +++ b/packages/cozy-client/types/authentication/mobile.d.ts @@ -1,2 +1 @@ -export function authenticateWithCordova(url: any): Promise; -export function authFunction(url: any): Promise; +export function authFunction(): never; diff --git a/packages/cozy-client/types/models/file.d.ts b/packages/cozy-client/types/models/file.d.ts index 301e36a52e..127ff2d0e7 100644 --- a/packages/cozy-client/types/models/file.d.ts +++ b/packages/cozy-client/types/models/file.d.ts @@ -63,8 +63,6 @@ export function overrideFileForPath(client: CozyClient, dirPath: string, file: o export function generateNewFileNameOnConflict(filenameWithoutExtension: string, conflictOptions?: import('../types').ConflictOptions): string; export function generateFileNameForRevision(file: import("../types").IOCozyFile, revision: object, f: Function): string; export function uploadFileWithConflictStrategy(client: CozyClient, file: string | ArrayBuffer, options: FileUploadOptions): any; -export function readMobileFile(fileURL: string): Promise; -export function doMobileUpload(client: CozyClient, fileURL: string, options: FileUploadOptions): Promise; export function isPlainText(mimeType?: string, fileName?: string): boolean; export function hasQualifications(file: import("../types").IOCozyFile): boolean; export function hasCertifications(file: import("../types").IOCozyFile): boolean; diff --git a/packages/cozy-client/types/models/fsnative.d.ts b/packages/cozy-client/types/models/fsnative.d.ts deleted file mode 100644 index 27e77c0ab5..0000000000 --- a/packages/cozy-client/types/models/fsnative.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -export function getRootPath(): string; -export function getTemporaryRootPath(): any; -export function getCozyPath(): string; -export function getEntry(path: string): Promise; -export function getCozyEntry(): Promise; -export function createCozyPath(): Promise; -export function getDirectory(rootDirEntry: object, folderName: string): Promise; -export function writeFile(fileEntry: object, dataObj: object): Promise; -export function openFileWithCordova(URI: any, mimetype: any): Promise; -export function deleteOfflineFile(fileName: string): Promise; -export function saveFileWithCordova(fileData: object, fileName: string): Promise; -export function temporarySave(file: object, fileName: string): Promise; -export function saveAndOpenWithCordova(blob: Blob, file: object): Promise; -export function getNativeFile(file: object): Promise; -export function openOfflineFile(file: object): Promise; -export function openFileWith(client: CozyClient, file: object): Promise; -export default fsnative; -export type FilesystemEntry = any; -import CozyClient from "../CozyClient"; -declare namespace fsnative { - export { saveAndOpenWithCordova }; -} diff --git a/packages/cozy-client/types/types.d.ts b/packages/cozy-client/types/types.d.ts index 3f713da2ae..165ca73ad9 100644 --- a/packages/cozy-client/types/types.d.ts +++ b/packages/cozy-client/types/types.d.ts @@ -1375,17 +1375,6 @@ export type ClientCapabilities = { */ flat_subdomains?: boolean; }; -export type Cordova = { - file: FilePlugin; - InAppBrowser: InAppBrowser; - plugins: object; -}; -export type CordovaWindow = { - cordova: Cordova; - SafariViewController: object; - resolveLocalFileSystemURL: Function; - handleOpenURL: Function; -}; /** * - A document */ diff --git a/packages/cozy-pouch-link/src/PouchManager.spec.js b/packages/cozy-pouch-link/src/PouchManager.spec.js index a002639381..feef3974a2 100644 --- a/packages/cozy-pouch-link/src/PouchManager.spec.js +++ b/packages/cozy-pouch-link/src/PouchManager.spec.js @@ -247,7 +247,7 @@ describe('PouchManager', () => { }) it('should instanciate pouch with options', async () => { - const pouchOptions = { adapter: 'cordova-sqlite', location: 'default' } + const pouchOptions = { adapter: 'sqlite', location: 'default' } const options = { ...managerOptions, pouch: { options: pouchOptions } } const manager = new PouchManager(['io.cozy.todos'], options) await manager.init() diff --git a/packages/cozy-pouch-link/src/helpers.js b/packages/cozy-pouch-link/src/helpers.js index f630efbe05..a70cf5cd8f 100644 --- a/packages/cozy-pouch-link/src/helpers.js +++ b/packages/cozy-pouch-link/src/helpers.js @@ -7,7 +7,7 @@ const helpers = {} // https://github.com/pouchdb/pouchdb/issues/7011 const LIMIT_BUG = 999 -const ADAPTERS_WITH_LIMIT_BUG = ['cordova-sqlite', 'websql'] +const ADAPTERS_WITH_LIMIT_BUG = ['websql'] helpers.isAdapterBugged = adapterName => { return ADAPTERS_WITH_LIMIT_BUG.includes(adapterName)