From 2276094ce201582cc173802df81589292af62c97 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Mon, 18 Sep 2023 21:53:28 +0200 Subject: [PATCH 01/13] Migrated src/libs/Device to TypeScript --- .../{index.android.js => index.android.ts} | 4 ++-- .../{index.desktop.js => index.desktop.ts} | 5 ++-- .../{index.ios.js => index.ios.ts} | 6 ++--- .../{index.website.js => index.website.ts} | 4 ++-- .../Device/getDeviceInfo/getBaseInfo.js | 8 ------- .../Device/getDeviceInfo/getBaseInfo.ts | 16 +++++++++++++ .../{index.native.js => index.native.ts} | 6 ++++- .../getOSAndName/{index.js => index.ts} | 0 .../Device/getDeviceInfo/index.android.js | 10 -------- .../Device/getDeviceInfo/index.android.ts | 10 ++++++++ .../Device/getDeviceInfo/index.desktop.js | 10 -------- .../Device/getDeviceInfo/index.desktop.ts | 9 ++++++++ .../actions/Device/getDeviceInfo/index.ios.js | 10 -------- .../actions/Device/getDeviceInfo/index.ios.ts | 10 ++++++++ .../actions/Device/getDeviceInfo/index.js | 23 ------------------- .../actions/Device/getDeviceInfo/index.ts | 18 +++++++++++++++ .../actions/Device/{index.js => index.ts} | 18 +++++++-------- src/types/global.d.ts | 8 +++++++ 18 files changed, 95 insertions(+), 80 deletions(-) rename src/libs/actions/Device/generateDeviceID/{index.android.js => index.android.ts} (95%) rename src/libs/actions/Device/generateDeviceID/{index.desktop.js => index.desktop.ts} (81%) rename src/libs/actions/Device/generateDeviceID/{index.ios.js => index.ios.ts} (62%) rename src/libs/actions/Device/generateDeviceID/{index.website.js => index.website.ts} (92%) delete mode 100644 src/libs/actions/Device/getDeviceInfo/getBaseInfo.js create mode 100644 src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts rename src/libs/actions/Device/getDeviceInfo/getOSAndName/{index.native.js => index.native.ts} (76%) rename src/libs/actions/Device/getDeviceInfo/getOSAndName/{index.js => index.ts} (100%) delete mode 100644 src/libs/actions/Device/getDeviceInfo/index.android.js create mode 100644 src/libs/actions/Device/getDeviceInfo/index.android.ts delete mode 100644 src/libs/actions/Device/getDeviceInfo/index.desktop.js create mode 100644 src/libs/actions/Device/getDeviceInfo/index.desktop.ts delete mode 100644 src/libs/actions/Device/getDeviceInfo/index.ios.js create mode 100644 src/libs/actions/Device/getDeviceInfo/index.ios.ts delete mode 100644 src/libs/actions/Device/getDeviceInfo/index.js create mode 100644 src/libs/actions/Device/getDeviceInfo/index.ts rename src/libs/actions/Device/{index.js => index.ts} (76%) diff --git a/src/libs/actions/Device/generateDeviceID/index.android.js b/src/libs/actions/Device/generateDeviceID/index.android.ts similarity index 95% rename from src/libs/actions/Device/generateDeviceID/index.android.js rename to src/libs/actions/Device/generateDeviceID/index.android.ts index f61b860bda7d..57a98521e865 100644 --- a/src/libs/actions/Device/generateDeviceID/index.android.js +++ b/src/libs/actions/Device/generateDeviceID/index.android.ts @@ -23,9 +23,9 @@ const uniqueID = Str.guid(deviceID); * Furthermore, the deviceID prefix is not unique to a specific device, but is likely to change from one type of device to another. * Including this prefix will tell us with a reasonable degree of confidence if the user just uninstalled and reinstalled the app, or if they got a new device. * - * @returns {Promise} + * @returns - deviceID */ -function generateDeviceID() { +function generateDeviceID(): Promise { return Promise.resolve(uniqueID); } diff --git a/src/libs/actions/Device/generateDeviceID/index.desktop.js b/src/libs/actions/Device/generateDeviceID/index.desktop.ts similarity index 81% rename from src/libs/actions/Device/generateDeviceID/index.desktop.js rename to src/libs/actions/Device/generateDeviceID/index.desktop.ts index 26de25e326e8..a4b9dea521dd 100644 --- a/src/libs/actions/Device/generateDeviceID/index.desktop.js +++ b/src/libs/actions/Device/generateDeviceID/index.desktop.ts @@ -3,9 +3,10 @@ import ELECTRON_EVENTS from '../../../../../desktop/ELECTRON_EVENTS'; /** * Get the unique ID of the current device. This should remain the same even if the user uninstalls and reinstalls the app. * - * @returns {Promise} + * @returns - device ID */ -function generateDeviceID() { + +function generateDeviceID(): Promise { return window.electron.invoke(ELECTRON_EVENTS.REQUEST_DEVICE_ID); } diff --git a/src/libs/actions/Device/generateDeviceID/index.ios.js b/src/libs/actions/Device/generateDeviceID/index.ios.ts similarity index 62% rename from src/libs/actions/Device/generateDeviceID/index.ios.js rename to src/libs/actions/Device/generateDeviceID/index.ios.ts index 6836edf1fcee..5dbdb290e8b2 100644 --- a/src/libs/actions/Device/generateDeviceID/index.ios.js +++ b/src/libs/actions/Device/generateDeviceID/index.ios.ts @@ -5,10 +5,10 @@ const deviceID = DeviceInfo.getDeviceId(); /** * Get the unique ID of the current device. This should remain the same even if the user uninstalls and reinstalls the app. * - * @returns {Promise} + * @returns - device ID */ -function generateDeviceID() { - return DeviceInfo.getUniqueId().then((uniqueID) => `${deviceID}_${uniqueID}`); +function generateDeviceID(): Promise { + return DeviceInfo.getUniqueId().then((uniqueID: string) => `${deviceID}_${uniqueID}`); } export default generateDeviceID; diff --git a/src/libs/actions/Device/generateDeviceID/index.website.js b/src/libs/actions/Device/generateDeviceID/index.website.ts similarity index 92% rename from src/libs/actions/Device/generateDeviceID/index.website.js rename to src/libs/actions/Device/generateDeviceID/index.website.ts index b8abc4734134..5ee5d0a13fbd 100644 --- a/src/libs/actions/Device/generateDeviceID/index.website.js +++ b/src/libs/actions/Device/generateDeviceID/index.website.ts @@ -14,9 +14,9 @@ const uniqueID = Str.guid(); * While this isn't perfect, it's just as good as any other obvious web solution, such as this one https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo/deviceId * which is also different/reset under the same circumstances * - * @returns {Promise} + * @returns - device ID */ -function generateDeviceID() { +function generateDeviceID(): Promise { return Promise.resolve(uniqueID); } diff --git a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.js b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.js deleted file mode 100644 index bb66f3fe7a9b..000000000000 --- a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.js +++ /dev/null @@ -1,8 +0,0 @@ -import packageConfig from '../../../../../package.json'; - -export default function getBaseInfo() { - return { - app_version: packageConfig.version, - timestamp: new Date().toISOString().slice(0, 19), - }; -} diff --git a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts new file mode 100644 index 000000000000..bebff1917b11 --- /dev/null +++ b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts @@ -0,0 +1,16 @@ +import packageConfig from '../../../../../package.json'; +import {OSAndName} from "./getOSAndName/index.native"; + +export type BaseInfo = { + app_version: string; + timestamp: string; +}; + +export type DeviceInfo = BaseInfo & OSAndName & {os?: string, device_name?: string, device_version?: string}; + +export default function getBaseInfo(): BaseInfo { + return { + app_version: packageConfig.version, + timestamp: new Date().toISOString().slice(0, 19), + }; +} diff --git a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.js b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts similarity index 76% rename from src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.js rename to src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts index 11d59abea1f1..7744c71164d0 100644 --- a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.js +++ b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts @@ -1,7 +1,11 @@ import Str from 'expensify-common/lib/str'; import RNDeviceInfo from 'react-native-device-info'; -export default function getOSAndName() { +export type OSAndName = { + device_name: string; + os_version: string; +} +export default function getOSAndName(): OSAndName { const deviceName = RNDeviceInfo.getDeviceNameSync(); const prettyName = `${Str.UCFirst(RNDeviceInfo.getManufacturerSync() || '')} ${deviceName}`; return { diff --git a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.js b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts similarity index 100% rename from src/libs/actions/Device/getDeviceInfo/getOSAndName/index.js rename to src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts diff --git a/src/libs/actions/Device/getDeviceInfo/index.android.js b/src/libs/actions/Device/getDeviceInfo/index.android.js deleted file mode 100644 index 343fb165459c..000000000000 --- a/src/libs/actions/Device/getDeviceInfo/index.android.js +++ /dev/null @@ -1,10 +0,0 @@ -import getBaseInfo from './getBaseInfo'; -import getOSAndName from './getOSAndName'; - -export default function getDeviceInfo() { - return { - ...getBaseInfo(), - ...getOSAndName(), - os: 'Android', - }; -} diff --git a/src/libs/actions/Device/getDeviceInfo/index.android.ts b/src/libs/actions/Device/getDeviceInfo/index.android.ts new file mode 100644 index 000000000000..26167461974c --- /dev/null +++ b/src/libs/actions/Device/getDeviceInfo/index.android.ts @@ -0,0 +1,10 @@ +import getBaseInfo, {DeviceInfo} from './getBaseInfo'; +import getOSAndName from './getOSAndName/index.native'; + +export default function getDeviceInfo(): DeviceInfo { + return { + ...getBaseInfo(), + ...getOSAndName(), + os: 'Android', + }; +} diff --git a/src/libs/actions/Device/getDeviceInfo/index.desktop.js b/src/libs/actions/Device/getDeviceInfo/index.desktop.js deleted file mode 100644 index 7a15857bd682..000000000000 --- a/src/libs/actions/Device/getDeviceInfo/index.desktop.js +++ /dev/null @@ -1,10 +0,0 @@ -import getBaseInfo from './getBaseInfo'; -import getOSAndName from './getOSAndName'; - -export default function getDeviceInfo() { - return { - ...getBaseInfo(), - ...getOSAndName(), - device_name: 'Desktop', - }; -} diff --git a/src/libs/actions/Device/getDeviceInfo/index.desktop.ts b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts new file mode 100644 index 000000000000..46ab1b0217ad --- /dev/null +++ b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts @@ -0,0 +1,9 @@ +import getBaseInfo, {DeviceInfo} from './getBaseInfo'; +import getOSAndName from './getOSAndName/index.native'; +export default function getDeviceInfo(): DeviceInfo { + return { + ...getBaseInfo(), + ...getOSAndName(), + device_name: 'Desktop', + }; +} diff --git a/src/libs/actions/Device/getDeviceInfo/index.ios.js b/src/libs/actions/Device/getDeviceInfo/index.ios.js deleted file mode 100644 index 5a5195a247d1..000000000000 --- a/src/libs/actions/Device/getDeviceInfo/index.ios.js +++ /dev/null @@ -1,10 +0,0 @@ -import getBaseInfo from './getBaseInfo'; -import getOSAndName from './getOSAndName'; - -export default function getDeviceInfo() { - return { - ...getBaseInfo(), - ...getOSAndName(), - os: 'iOS', - }; -} diff --git a/src/libs/actions/Device/getDeviceInfo/index.ios.ts b/src/libs/actions/Device/getDeviceInfo/index.ios.ts new file mode 100644 index 000000000000..966538c1418d --- /dev/null +++ b/src/libs/actions/Device/getDeviceInfo/index.ios.ts @@ -0,0 +1,10 @@ +import getBaseInfo, {DeviceInfo} from './getBaseInfo'; +import getOSAndName from './getOSAndName/index.native'; + +export default function getDeviceInfo(): DeviceInfo { + return { + ...getBaseInfo(), + ...getOSAndName(), + os: 'iOS', + }; +} diff --git a/src/libs/actions/Device/getDeviceInfo/index.js b/src/libs/actions/Device/getDeviceInfo/index.js deleted file mode 100644 index a955a235a88b..000000000000 --- a/src/libs/actions/Device/getDeviceInfo/index.js +++ /dev/null @@ -1,23 +0,0 @@ -import getBaseInfo from './getBaseInfo'; -import getOSAndName from './getOSAndName'; - -/** - * @typedef DeviceInfo - * @type {object} - * @property {string} os - * @property {string} os_version - * @property {string} timestamp - ISO without ms - * @property {string} app_version - * @property {string} device_name - * @property {string} [device_version] - */ - -/** - * @returns {DeviceInfo} - */ -export default function getDeviceInfo() { - return { - ...getBaseInfo(), - ...getOSAndName(), - }; -} diff --git a/src/libs/actions/Device/getDeviceInfo/index.ts b/src/libs/actions/Device/getDeviceInfo/index.ts new file mode 100644 index 000000000000..ffc35c58b53f --- /dev/null +++ b/src/libs/actions/Device/getDeviceInfo/index.ts @@ -0,0 +1,18 @@ +import getBaseInfo, {DeviceInfo} from './getBaseInfo'; +import getOSAndName from './getOSAndName/index.native'; + +/** + * @typedef DeviceInfo + * @type {object} + + */ + +/** + * @returns {DeviceInfo} + */ +export default function getDeviceInfo(): DeviceInfo { + return { + ...getBaseInfo(), + ...getOSAndName(), + }; +} diff --git a/src/libs/actions/Device/index.js b/src/libs/actions/Device/index.ts similarity index 76% rename from src/libs/actions/Device/index.js rename to src/libs/actions/Device/index.ts index 8f548b75bd93..6d881526b2e2 100644 --- a/src/libs/actions/Device/index.js +++ b/src/libs/actions/Device/index.ts @@ -1,15 +1,15 @@ -import Onyx from 'react-native-onyx'; +import Onyx, {OnyxEntry} from 'react-native-onyx'; import ONYXKEYS from '../../../ONYXKEYS'; import Log from '../../Log'; -import generateDeviceID from './generateDeviceID'; -import getDeviceInfo from './getDeviceInfo'; +import generateDeviceID from './generateDeviceID/index.ios'; +import getDeviceInfo from './getDeviceInfo/index.ios'; -let deviceID; +let deviceID: string | null = null; /** * @returns {Promise} */ -function getDeviceID() { +function getDeviceID(): Promise { return new Promise((resolve) => { if (deviceID) { return resolve(deviceID); @@ -17,7 +17,7 @@ function getDeviceID() { const connectionID = Onyx.connect({ key: ONYXKEYS.DEVICE_ID, - callback: (ID) => { + callback: (ID: OnyxEntry) => { Onyx.disconnect(connectionID); deviceID = ID; return resolve(ID); @@ -38,7 +38,7 @@ function setDeviceID() { throw new Error(existingDeviceID); }) .then(generateDeviceID) - .then((uniqueID) => { + .then((uniqueID: string) => { Log.info('Got new deviceID', false, uniqueID); Onyx.set(ONYXKEYS.DEVICE_ID, uniqueID); }) @@ -47,9 +47,9 @@ function setDeviceID() { /** * Returns a string object with device info and uniqueID - * @returns {Promise} + * @returns - device info with ID */ -function getDeviceInfoWithID() { +function getDeviceInfoWithID(): Promise { return new Promise((resolve) => { getDeviceID().then((currentDeviceID) => resolve( diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 1910b5a994b8..43b3fa482dd1 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -16,4 +16,12 @@ declare module '*.svg' { export default content; } +declare global { + interface Window { + electron: Electron.IpcRenderer + } +} + declare module 'react-native-device-info/jest/react-native-device-info-mock'; + +export {} From 8786f6823607999bb954a0027de08a5b3f2c4413 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Thu, 21 Sep 2023 10:42:01 +0200 Subject: [PATCH 02/13] Added missing explicit type. --- src/libs/actions/Device/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Device/index.ts b/src/libs/actions/Device/index.ts index 6d881526b2e2..437753c6a5f6 100644 --- a/src/libs/actions/Device/index.ts +++ b/src/libs/actions/Device/index.ts @@ -7,7 +7,7 @@ import getDeviceInfo from './getDeviceInfo/index.ios'; let deviceID: string | null = null; /** - * @returns {Promise} + * @returns - device ID string or null in case of failure */ function getDeviceID(): Promise { return new Promise((resolve) => { @@ -29,7 +29,7 @@ function getDeviceID(): Promise { /** * Saves a unique deviceID into Onyx. */ -function setDeviceID() { +function setDeviceID(): void { getDeviceID() .then((existingDeviceID) => { if (!existingDeviceID) { From 06a907cd51304c3bfbe15c2e4fec4207e82ed230 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Thu, 21 Sep 2023 10:58:43 +0200 Subject: [PATCH 03/13] Fixed JSDoc removal. --- src/libs/actions/Device/getDeviceInfo/index.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/libs/actions/Device/getDeviceInfo/index.ts b/src/libs/actions/Device/getDeviceInfo/index.ts index ffc35c58b53f..b5911b8b3d10 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.ts @@ -1,15 +1,6 @@ import getBaseInfo, {DeviceInfo} from './getBaseInfo'; import getOSAndName from './getOSAndName/index.native'; -/** - * @typedef DeviceInfo - * @type {object} - - */ - -/** - * @returns {DeviceInfo} - */ export default function getDeviceInfo(): DeviceInfo { return { ...getBaseInfo(), From ce892be5ebe20fa69cc76c3760491d5dffdcafd5 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Thu, 21 Sep 2023 13:08:28 +0200 Subject: [PATCH 04/13] Refactored platform specific functions and typings. --- .../actions/Device/generateDeviceID/index.android.ts | 3 ++- .../actions/Device/generateDeviceID/index.desktop.ts | 3 ++- src/libs/actions/Device/generateDeviceID/index.ios.ts | 3 ++- src/libs/actions/Device/generateDeviceID/index.ts | 1 + .../actions/Device/generateDeviceID/index.website.ts | 4 +++- src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts | 9 ++++----- .../Device/getDeviceInfo/getOSAndName/index.native.ts | 9 ++++----- .../Device/getDeviceInfo/getOSAndName/index.ts | 5 +++++ .../actions/Device/getDeviceInfo/index.android.ts | 7 +++++-- .../actions/Device/getDeviceInfo/index.desktop.ts | 7 +++++-- src/libs/actions/Device/getDeviceInfo/index.ios.ts | 8 +++++--- src/libs/actions/Device/getDeviceInfo/index.ts | 11 ++++++++--- src/types/global.d.ts | 2 ++ 13 files changed, 48 insertions(+), 24 deletions(-) create mode 100644 src/libs/actions/Device/generateDeviceID/index.ts diff --git a/src/libs/actions/Device/generateDeviceID/index.android.ts b/src/libs/actions/Device/generateDeviceID/index.android.ts index 57a98521e865..5e061fd00ab2 100644 --- a/src/libs/actions/Device/generateDeviceID/index.android.ts +++ b/src/libs/actions/Device/generateDeviceID/index.android.ts @@ -1,5 +1,6 @@ import DeviceInfo from 'react-native-device-info'; import Str from 'expensify-common/lib/str'; +import {GenerateDeviceID} from "./index"; const deviceID = DeviceInfo.getDeviceId(); const uniqueID = Str.guid(deviceID); @@ -25,7 +26,7 @@ const uniqueID = Str.guid(deviceID); * * @returns - deviceID */ -function generateDeviceID(): Promise { +const generateDeviceID: GenerateDeviceID = (): Promise => { return Promise.resolve(uniqueID); } diff --git a/src/libs/actions/Device/generateDeviceID/index.desktop.ts b/src/libs/actions/Device/generateDeviceID/index.desktop.ts index a4b9dea521dd..f6f6c482b5b8 100644 --- a/src/libs/actions/Device/generateDeviceID/index.desktop.ts +++ b/src/libs/actions/Device/generateDeviceID/index.desktop.ts @@ -1,4 +1,5 @@ import ELECTRON_EVENTS from '../../../../../desktop/ELECTRON_EVENTS'; +import {GenerateDeviceID} from "./index"; /** * Get the unique ID of the current device. This should remain the same even if the user uninstalls and reinstalls the app. @@ -6,7 +7,7 @@ import ELECTRON_EVENTS from '../../../../../desktop/ELECTRON_EVENTS'; * @returns - device ID */ -function generateDeviceID(): Promise { +const generateDeviceID: GenerateDeviceID = (): Promise => { return window.electron.invoke(ELECTRON_EVENTS.REQUEST_DEVICE_ID); } diff --git a/src/libs/actions/Device/generateDeviceID/index.ios.ts b/src/libs/actions/Device/generateDeviceID/index.ios.ts index 5dbdb290e8b2..40292e5bc010 100644 --- a/src/libs/actions/Device/generateDeviceID/index.ios.ts +++ b/src/libs/actions/Device/generateDeviceID/index.ios.ts @@ -1,4 +1,5 @@ import DeviceInfo from 'react-native-device-info'; +import {GenerateDeviceID} from "./index"; const deviceID = DeviceInfo.getDeviceId(); @@ -7,7 +8,7 @@ const deviceID = DeviceInfo.getDeviceId(); * * @returns - device ID */ -function generateDeviceID(): Promise { +const generateDeviceID: GenerateDeviceID = (): Promise => { return DeviceInfo.getUniqueId().then((uniqueID: string) => `${deviceID}_${uniqueID}`); } diff --git a/src/libs/actions/Device/generateDeviceID/index.ts b/src/libs/actions/Device/generateDeviceID/index.ts new file mode 100644 index 000000000000..59d3348aa27c --- /dev/null +++ b/src/libs/actions/Device/generateDeviceID/index.ts @@ -0,0 +1 @@ +export type GenerateDeviceID = () => Promise; diff --git a/src/libs/actions/Device/generateDeviceID/index.website.ts b/src/libs/actions/Device/generateDeviceID/index.website.ts index 5ee5d0a13fbd..488b6515100d 100644 --- a/src/libs/actions/Device/generateDeviceID/index.website.ts +++ b/src/libs/actions/Device/generateDeviceID/index.website.ts @@ -1,4 +1,5 @@ import Str from 'expensify-common/lib/str'; +import {GenerateDeviceID} from "./index"; const uniqueID = Str.guid(); @@ -16,7 +17,8 @@ const uniqueID = Str.guid(); * * @returns - device ID */ -function generateDeviceID(): Promise { + +const generateDeviceID: GenerateDeviceID = (): Promise => { return Promise.resolve(uniqueID); } diff --git a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts index bebff1917b11..21ab4157f4e9 100644 --- a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts +++ b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts @@ -1,16 +1,15 @@ import packageConfig from '../../../../../package.json'; -import {OSAndName} from "./getOSAndName/index.native"; +import {GetBaseInfo} from "./index"; export type BaseInfo = { app_version: string; timestamp: string; }; - -export type DeviceInfo = BaseInfo & OSAndName & {os?: string, device_name?: string, device_version?: string}; - -export default function getBaseInfo(): BaseInfo { +export const getBaseInfo: GetBaseInfo = (): BaseInfo => { return { app_version: packageConfig.version, timestamp: new Date().toISOString().slice(0, 19), }; } + +export default getBaseInfo; diff --git a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts index 7744c71164d0..286d0fe9a6e9 100644 --- a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts +++ b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts @@ -1,11 +1,8 @@ import Str from 'expensify-common/lib/str'; import RNDeviceInfo from 'react-native-device-info'; +import {GetOSAndName, OSAndName} from "./index"; -export type OSAndName = { - device_name: string; - os_version: string; -} -export default function getOSAndName(): OSAndName { +const getOSAndName: GetOSAndName = (): OSAndName => { const deviceName = RNDeviceInfo.getDeviceNameSync(); const prettyName = `${Str.UCFirst(RNDeviceInfo.getManufacturerSync() || '')} ${deviceName}`; return { @@ -13,3 +10,5 @@ export default function getOSAndName(): OSAndName { os_version: RNDeviceInfo.getSystemVersion(), }; } + +export default getOSAndName; diff --git a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts index 29b004412f64..ffcc5014ddf5 100644 --- a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts +++ b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts @@ -1,4 +1,9 @@ // Don't import this file with '* as Device'. It's known to make VSCode IntelliSense crash. import {getOSAndName} from 'expensify-common/lib/Device'; +export type GetOSAndName = () => OSAndName; +export type OSAndName = { + device_name: string; + os_version: string; +} export default getOSAndName; diff --git a/src/libs/actions/Device/getDeviceInfo/index.android.ts b/src/libs/actions/Device/getDeviceInfo/index.android.ts index 26167461974c..157053e3ad44 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.android.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.android.ts @@ -1,10 +1,13 @@ -import getBaseInfo, {DeviceInfo} from './getBaseInfo'; +import getBaseInfo from './getBaseInfo'; import getOSAndName from './getOSAndName/index.native'; +import {GetDeviceInfo, DeviceInfo} from "./index"; -export default function getDeviceInfo(): DeviceInfo { +const getDeviceInfo: GetDeviceInfo = (): DeviceInfo => { return { ...getBaseInfo(), ...getOSAndName(), os: 'Android', }; } + +export default getDeviceInfo; diff --git a/src/libs/actions/Device/getDeviceInfo/index.desktop.ts b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts index 46ab1b0217ad..fb149725dddf 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.desktop.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts @@ -1,9 +1,12 @@ -import getBaseInfo, {DeviceInfo} from './getBaseInfo'; +import getBaseInfo from './getBaseInfo'; import getOSAndName from './getOSAndName/index.native'; -export default function getDeviceInfo(): DeviceInfo { +import {GetDeviceInfo, DeviceInfo} from "./index"; +const getDeviceInfo: GetDeviceInfo = (): DeviceInfo => { return { ...getBaseInfo(), ...getOSAndName(), device_name: 'Desktop', }; } + +export default getDeviceInfo; diff --git a/src/libs/actions/Device/getDeviceInfo/index.ios.ts b/src/libs/actions/Device/getDeviceInfo/index.ios.ts index 966538c1418d..7a310b8129c1 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.ios.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.ios.ts @@ -1,10 +1,12 @@ -import getBaseInfo, {DeviceInfo} from './getBaseInfo'; +import getBaseInfo from './getBaseInfo'; import getOSAndName from './getOSAndName/index.native'; - -export default function getDeviceInfo(): DeviceInfo { +import {GetDeviceInfo, DeviceInfo} from "./index"; +const getDeviceInfo: GetDeviceInfo = (): DeviceInfo => { return { ...getBaseInfo(), ...getOSAndName(), os: 'iOS', }; } + +export default getDeviceInfo; diff --git a/src/libs/actions/Device/getDeviceInfo/index.ts b/src/libs/actions/Device/getDeviceInfo/index.ts index b5911b8b3d10..21951554b98c 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.ts @@ -1,9 +1,14 @@ -import getBaseInfo, {DeviceInfo} from './getBaseInfo'; -import getOSAndName from './getOSAndName/index.native'; +import getBaseInfo, {BaseInfo} from './getBaseInfo'; +import getOSAndName, {OSAndName} from './getOSAndName/index.native'; -export default function getDeviceInfo(): DeviceInfo { +export type GetDeviceInfo = () => DeviceInfo; +export type DeviceInfo = BaseInfo & OSAndName & {os?: string, device_name?: string, device_version?: string}; +export type GetBaseInfo = () => BaseInfo; +const getDeviceInfo: GetDeviceInfo = () => { return { ...getBaseInfo(), ...getOSAndName(), }; } + +export default getDeviceInfo; diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 43b3fa482dd1..4287d083d8c3 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -25,3 +25,5 @@ declare global { declare module 'react-native-device-info/jest/react-native-device-info-mock'; export {} + + From 660a8a33a302e067aed65e46e2bdf611c8e06db5 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Mon, 25 Sep 2023 12:32:59 +0200 Subject: [PATCH 05/13] Aligned to TS guidelines. --- .../Device/generateDeviceID/index.android.ts | 2 +- .../Device/generateDeviceID/index.desktop.ts | 2 +- .../Device/generateDeviceID/index.ios.ts | 2 +- .../actions/Device/generateDeviceID/index.ts | 26 ++++++++++++++++++- .../Device/generateDeviceID/index.website.ts | 25 ------------------ .../actions/Device/generateDeviceID/types.ts | 1 + .../Device/getDeviceInfo/getBaseInfo.ts | 6 +---- .../getOSAndName/index.native.ts | 2 +- .../getDeviceInfo/getOSAndName/index.ts | 6 ----- .../getDeviceInfo/getOSAndName/types.ts | 5 ++++ .../Device/getDeviceInfo/index.android.ts | 2 +- .../Device/getDeviceInfo/index.desktop.ts | 2 +- .../actions/Device/getDeviceInfo/index.ios.ts | 2 +- .../actions/Device/getDeviceInfo/index.ts | 8 +++--- .../actions/Device/getDeviceInfo/types.ts | 10 +++++++ 15 files changed, 52 insertions(+), 49 deletions(-) delete mode 100644 src/libs/actions/Device/generateDeviceID/index.website.ts create mode 100644 src/libs/actions/Device/generateDeviceID/types.ts create mode 100644 src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts create mode 100644 src/libs/actions/Device/getDeviceInfo/types.ts diff --git a/src/libs/actions/Device/generateDeviceID/index.android.ts b/src/libs/actions/Device/generateDeviceID/index.android.ts index 5e061fd00ab2..23623750a6bb 100644 --- a/src/libs/actions/Device/generateDeviceID/index.android.ts +++ b/src/libs/actions/Device/generateDeviceID/index.android.ts @@ -1,6 +1,6 @@ import DeviceInfo from 'react-native-device-info'; import Str from 'expensify-common/lib/str'; -import {GenerateDeviceID} from "./index"; +import {GenerateDeviceID} from "./types"; const deviceID = DeviceInfo.getDeviceId(); const uniqueID = Str.guid(deviceID); diff --git a/src/libs/actions/Device/generateDeviceID/index.desktop.ts b/src/libs/actions/Device/generateDeviceID/index.desktop.ts index f6f6c482b5b8..99da202de6bf 100644 --- a/src/libs/actions/Device/generateDeviceID/index.desktop.ts +++ b/src/libs/actions/Device/generateDeviceID/index.desktop.ts @@ -1,5 +1,5 @@ import ELECTRON_EVENTS from '../../../../../desktop/ELECTRON_EVENTS'; -import {GenerateDeviceID} from "./index"; +import {GenerateDeviceID} from "./types"; /** * Get the unique ID of the current device. This should remain the same even if the user uninstalls and reinstalls the app. diff --git a/src/libs/actions/Device/generateDeviceID/index.ios.ts b/src/libs/actions/Device/generateDeviceID/index.ios.ts index 40292e5bc010..90fc5025393b 100644 --- a/src/libs/actions/Device/generateDeviceID/index.ios.ts +++ b/src/libs/actions/Device/generateDeviceID/index.ios.ts @@ -1,5 +1,5 @@ import DeviceInfo from 'react-native-device-info'; -import {GenerateDeviceID} from "./index"; +import {GenerateDeviceID} from "./types"; const deviceID = DeviceInfo.getDeviceId(); diff --git a/src/libs/actions/Device/generateDeviceID/index.ts b/src/libs/actions/Device/generateDeviceID/index.ts index 59d3348aa27c..d97423b22cde 100644 --- a/src/libs/actions/Device/generateDeviceID/index.ts +++ b/src/libs/actions/Device/generateDeviceID/index.ts @@ -1 +1,25 @@ -export type GenerateDeviceID = () => Promise; +import Str from 'expensify-common/lib/str'; +import {GenerateDeviceID} from "./types"; + +const uniqueID = Str.guid(); + +/** + * Get the "unique ID of the device". + * Note deviceID is not truly unique but will be a new GUID each time the app runs (we work around this limitation by saving it in Onyx) + * + * This GUID is stored in Onyx under ONYXKEYS.DEVICE_ID and is preserved on logout, such that the deviceID will only change if: + * + * - The user opens the app on a different browser or in an incognito window, OR + * - The user manually clears Onyx data + * + * While this isn't perfect, it's just as good as any other obvious web solution, such as this one https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo/deviceId + * which is also different/reset under the same circumstances + * + * @returns - device ID + */ + +const generateDeviceID: GenerateDeviceID = (): Promise => { + return Promise.resolve(uniqueID); +} + +export default generateDeviceID; diff --git a/src/libs/actions/Device/generateDeviceID/index.website.ts b/src/libs/actions/Device/generateDeviceID/index.website.ts deleted file mode 100644 index 488b6515100d..000000000000 --- a/src/libs/actions/Device/generateDeviceID/index.website.ts +++ /dev/null @@ -1,25 +0,0 @@ -import Str from 'expensify-common/lib/str'; -import {GenerateDeviceID} from "./index"; - -const uniqueID = Str.guid(); - -/** - * Get the "unique ID of the device". - * Note deviceID is not truly unique but will be a new GUID each time the app runs (we work around this limitation by saving it in Onyx) - * - * This GUID is stored in Onyx under ONYXKEYS.DEVICE_ID and is preserved on logout, such that the deviceID will only change if: - * - * - The user opens the app on a different browser or in an incognito window, OR - * - The user manually clears Onyx data - * - * While this isn't perfect, it's just as good as any other obvious web solution, such as this one https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo/deviceId - * which is also different/reset under the same circumstances - * - * @returns - device ID - */ - -const generateDeviceID: GenerateDeviceID = (): Promise => { - return Promise.resolve(uniqueID); -} - -export default generateDeviceID; diff --git a/src/libs/actions/Device/generateDeviceID/types.ts b/src/libs/actions/Device/generateDeviceID/types.ts new file mode 100644 index 000000000000..59d3348aa27c --- /dev/null +++ b/src/libs/actions/Device/generateDeviceID/types.ts @@ -0,0 +1 @@ +export type GenerateDeviceID = () => Promise; diff --git a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts index 21ab4157f4e9..d13180062014 100644 --- a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts +++ b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts @@ -1,10 +1,6 @@ import packageConfig from '../../../../../package.json'; -import {GetBaseInfo} from "./index"; +import {BaseInfo, GetBaseInfo} from "./types"; -export type BaseInfo = { - app_version: string; - timestamp: string; -}; export const getBaseInfo: GetBaseInfo = (): BaseInfo => { return { app_version: packageConfig.version, diff --git a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts index 286d0fe9a6e9..64c082d5c883 100644 --- a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts +++ b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts @@ -1,6 +1,6 @@ import Str from 'expensify-common/lib/str'; import RNDeviceInfo from 'react-native-device-info'; -import {GetOSAndName, OSAndName} from "./index"; +import {GetOSAndName, OSAndName} from "./types"; const getOSAndName: GetOSAndName = (): OSAndName => { const deviceName = RNDeviceInfo.getDeviceNameSync(); diff --git a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts index ffcc5014ddf5..69952b9c4a9e 100644 --- a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts +++ b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts @@ -1,9 +1,3 @@ // Don't import this file with '* as Device'. It's known to make VSCode IntelliSense crash. import {getOSAndName} from 'expensify-common/lib/Device'; - -export type GetOSAndName = () => OSAndName; -export type OSAndName = { - device_name: string; - os_version: string; -} export default getOSAndName; diff --git a/src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts b/src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts new file mode 100644 index 000000000000..19d59fb192c2 --- /dev/null +++ b/src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts @@ -0,0 +1,5 @@ +export type GetOSAndName = () => OSAndName; +export type OSAndName = { + device_name?: string; + os_version?: string; +} diff --git a/src/libs/actions/Device/getDeviceInfo/index.android.ts b/src/libs/actions/Device/getDeviceInfo/index.android.ts index 157053e3ad44..d2fc8696d840 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.android.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.android.ts @@ -1,6 +1,6 @@ import getBaseInfo from './getBaseInfo'; import getOSAndName from './getOSAndName/index.native'; -import {GetDeviceInfo, DeviceInfo} from "./index"; +import {GetDeviceInfo, DeviceInfo} from './types'; const getDeviceInfo: GetDeviceInfo = (): DeviceInfo => { return { diff --git a/src/libs/actions/Device/getDeviceInfo/index.desktop.ts b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts index fb149725dddf..c8309bdd8efa 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.desktop.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts @@ -1,6 +1,6 @@ import getBaseInfo from './getBaseInfo'; import getOSAndName from './getOSAndName/index.native'; -import {GetDeviceInfo, DeviceInfo} from "./index"; +import {GetDeviceInfo, DeviceInfo} from './types'; const getDeviceInfo: GetDeviceInfo = (): DeviceInfo => { return { ...getBaseInfo(), diff --git a/src/libs/actions/Device/getDeviceInfo/index.ios.ts b/src/libs/actions/Device/getDeviceInfo/index.ios.ts index 7a310b8129c1..1f5a5cdbd925 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.ios.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.ios.ts @@ -1,6 +1,6 @@ import getBaseInfo from './getBaseInfo'; import getOSAndName from './getOSAndName/index.native'; -import {GetDeviceInfo, DeviceInfo} from "./index"; +import {GetDeviceInfo, DeviceInfo} from './types'; const getDeviceInfo: GetDeviceInfo = (): DeviceInfo => { return { ...getBaseInfo(), diff --git a/src/libs/actions/Device/getDeviceInfo/index.ts b/src/libs/actions/Device/getDeviceInfo/index.ts index 21951554b98c..d43c957bd925 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.ts @@ -1,9 +1,7 @@ -import getBaseInfo, {BaseInfo} from './getBaseInfo'; -import getOSAndName, {OSAndName} from './getOSAndName/index.native'; +import getBaseInfo from './getBaseInfo'; +import getOSAndName from "./getOSAndName/index"; +import {GetDeviceInfo} from "./types"; -export type GetDeviceInfo = () => DeviceInfo; -export type DeviceInfo = BaseInfo & OSAndName & {os?: string, device_name?: string, device_version?: string}; -export type GetBaseInfo = () => BaseInfo; const getDeviceInfo: GetDeviceInfo = () => { return { ...getBaseInfo(), diff --git a/src/libs/actions/Device/getDeviceInfo/types.ts b/src/libs/actions/Device/getDeviceInfo/types.ts new file mode 100644 index 000000000000..4fc6492693e8 --- /dev/null +++ b/src/libs/actions/Device/getDeviceInfo/types.ts @@ -0,0 +1,10 @@ +import {OSAndName} from "./getOSAndName/types"; + +export type BaseInfo = { + app_version: string; + timestamp: string; +}; + +export type GetDeviceInfo = () => DeviceInfo; +export type DeviceInfo = BaseInfo & OSAndName & {os?: string, device_name?: string, device_version?: string}; +export type GetBaseInfo = () => BaseInfo; From a3cfbf6f43e77631852108a05d8912ef76393f74 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Mon, 25 Sep 2023 13:15:02 +0200 Subject: [PATCH 06/13] Reflected PR comments. --- .../Device/generateDeviceID/index.android.ts | 4 +--- .../Device/generateDeviceID/index.desktop.ts | 6 ++---- .../Device/generateDeviceID/index.ios.ts | 4 +--- .../actions/Device/generateDeviceID/index.ts | 4 +--- .../Device/getDeviceInfo/getBaseInfo.ts | 4 ++-- .../getDeviceInfo/getOSAndName/index.native.ts | 4 ++-- .../Device/getDeviceInfo/getOSAndName/index.ts | 1 + .../Device/getDeviceInfo/index.android.ts | 4 ++-- .../Device/getDeviceInfo/index.desktop.ts | 4 ++-- .../actions/Device/getDeviceInfo/index.ios.ts | 4 ++-- src/libs/actions/Device/index.ts | 6 +++--- src/types/global.d.ts | 10 ---------- src/types/modules/electron.d.ts | 18 ++++++++++++++++++ 13 files changed, 37 insertions(+), 36 deletions(-) create mode 100644 src/types/modules/electron.d.ts diff --git a/src/libs/actions/Device/generateDeviceID/index.android.ts b/src/libs/actions/Device/generateDeviceID/index.android.ts index 23623750a6bb..195d7f0997e6 100644 --- a/src/libs/actions/Device/generateDeviceID/index.android.ts +++ b/src/libs/actions/Device/generateDeviceID/index.android.ts @@ -23,10 +23,8 @@ const uniqueID = Str.guid(deviceID); * * Furthermore, the deviceID prefix is not unique to a specific device, but is likely to change from one type of device to another. * Including this prefix will tell us with a reasonable degree of confidence if the user just uninstalled and reinstalled the app, or if they got a new device. - * - * @returns - deviceID */ -const generateDeviceID: GenerateDeviceID = (): Promise => { +const generateDeviceID: GenerateDeviceID = () => { return Promise.resolve(uniqueID); } diff --git a/src/libs/actions/Device/generateDeviceID/index.desktop.ts b/src/libs/actions/Device/generateDeviceID/index.desktop.ts index 99da202de6bf..4a86e18d30a7 100644 --- a/src/libs/actions/Device/generateDeviceID/index.desktop.ts +++ b/src/libs/actions/Device/generateDeviceID/index.desktop.ts @@ -3,12 +3,10 @@ import {GenerateDeviceID} from "./types"; /** * Get the unique ID of the current device. This should remain the same even if the user uninstalls and reinstalls the app. - * - * @returns - device ID */ -const generateDeviceID: GenerateDeviceID = (): Promise => { - return window.electron.invoke(ELECTRON_EVENTS.REQUEST_DEVICE_ID); +const generateDeviceID: GenerateDeviceID = () => { + return window.electron.invoke(ELECTRON_EVENTS.REQUEST_DEVICE_ID) as Promise; } export default generateDeviceID; diff --git a/src/libs/actions/Device/generateDeviceID/index.ios.ts b/src/libs/actions/Device/generateDeviceID/index.ios.ts index 90fc5025393b..8e8db6361df4 100644 --- a/src/libs/actions/Device/generateDeviceID/index.ios.ts +++ b/src/libs/actions/Device/generateDeviceID/index.ios.ts @@ -5,10 +5,8 @@ const deviceID = DeviceInfo.getDeviceId(); /** * Get the unique ID of the current device. This should remain the same even if the user uninstalls and reinstalls the app. - * - * @returns - device ID */ -const generateDeviceID: GenerateDeviceID = (): Promise => { +const generateDeviceID: GenerateDeviceID = () => { return DeviceInfo.getUniqueId().then((uniqueID: string) => `${deviceID}_${uniqueID}`); } diff --git a/src/libs/actions/Device/generateDeviceID/index.ts b/src/libs/actions/Device/generateDeviceID/index.ts index d97423b22cde..99f4e8c496fc 100644 --- a/src/libs/actions/Device/generateDeviceID/index.ts +++ b/src/libs/actions/Device/generateDeviceID/index.ts @@ -14,11 +14,9 @@ const uniqueID = Str.guid(); * * While this isn't perfect, it's just as good as any other obvious web solution, such as this one https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo/deviceId * which is also different/reset under the same circumstances - * - * @returns - device ID */ -const generateDeviceID: GenerateDeviceID = (): Promise => { +const generateDeviceID: GenerateDeviceID = () => { return Promise.resolve(uniqueID); } diff --git a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts index d13180062014..3ffedda9a91e 100644 --- a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts +++ b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts @@ -1,7 +1,7 @@ import packageConfig from '../../../../../package.json'; -import {BaseInfo, GetBaseInfo} from "./types"; +import {GetBaseInfo} from "./types"; -export const getBaseInfo: GetBaseInfo = (): BaseInfo => { +export const getBaseInfo: GetBaseInfo = () => { return { app_version: packageConfig.version, timestamp: new Date().toISOString().slice(0, 19), diff --git a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts index 64c082d5c883..071a5545cf7e 100644 --- a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts +++ b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts @@ -1,8 +1,8 @@ import Str from 'expensify-common/lib/str'; import RNDeviceInfo from 'react-native-device-info'; -import {GetOSAndName, OSAndName} from "./types"; +import {GetOSAndName} from "./types"; -const getOSAndName: GetOSAndName = (): OSAndName => { +const getOSAndName: GetOSAndName = () => { const deviceName = RNDeviceInfo.getDeviceNameSync(); const prettyName = `${Str.UCFirst(RNDeviceInfo.getManufacturerSync() || '')} ${deviceName}`; return { diff --git a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts index 69952b9c4a9e..29b004412f64 100644 --- a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts +++ b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts @@ -1,3 +1,4 @@ // Don't import this file with '* as Device'. It's known to make VSCode IntelliSense crash. import {getOSAndName} from 'expensify-common/lib/Device'; + export default getOSAndName; diff --git a/src/libs/actions/Device/getDeviceInfo/index.android.ts b/src/libs/actions/Device/getDeviceInfo/index.android.ts index d2fc8696d840..11f1bddad0e4 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.android.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.android.ts @@ -1,8 +1,8 @@ import getBaseInfo from './getBaseInfo'; import getOSAndName from './getOSAndName/index.native'; -import {GetDeviceInfo, DeviceInfo} from './types'; +import {GetDeviceInfo} from './types'; -const getDeviceInfo: GetDeviceInfo = (): DeviceInfo => { +const getDeviceInfo: GetDeviceInfo = () => { return { ...getBaseInfo(), ...getOSAndName(), diff --git a/src/libs/actions/Device/getDeviceInfo/index.desktop.ts b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts index c8309bdd8efa..2b751e04d189 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.desktop.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts @@ -1,7 +1,7 @@ import getBaseInfo from './getBaseInfo'; import getOSAndName from './getOSAndName/index.native'; -import {GetDeviceInfo, DeviceInfo} from './types'; -const getDeviceInfo: GetDeviceInfo = (): DeviceInfo => { +import {GetDeviceInfo} from './types'; +const getDeviceInfo: GetDeviceInfo = () => { return { ...getBaseInfo(), ...getOSAndName(), diff --git a/src/libs/actions/Device/getDeviceInfo/index.ios.ts b/src/libs/actions/Device/getDeviceInfo/index.ios.ts index 1f5a5cdbd925..cc9828f59925 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.ios.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.ios.ts @@ -1,7 +1,7 @@ import getBaseInfo from './getBaseInfo'; import getOSAndName from './getOSAndName/index.native'; -import {GetDeviceInfo, DeviceInfo} from './types'; -const getDeviceInfo: GetDeviceInfo = (): DeviceInfo => { +import {GetDeviceInfo} from './types'; +const getDeviceInfo: GetDeviceInfo = () => { return { ...getBaseInfo(), ...getOSAndName(), diff --git a/src/libs/actions/Device/index.ts b/src/libs/actions/Device/index.ts index 437753c6a5f6..5ed5729f0e07 100644 --- a/src/libs/actions/Device/index.ts +++ b/src/libs/actions/Device/index.ts @@ -1,8 +1,8 @@ import Onyx, {OnyxEntry} from 'react-native-onyx'; import ONYXKEYS from '../../../ONYXKEYS'; import Log from '../../Log'; -import generateDeviceID from './generateDeviceID/index.ios'; -import getDeviceInfo from './getDeviceInfo/index.ios'; +import generateDeviceID from './generateDeviceID/index'; +import getDeviceInfo from './getDeviceInfo/index'; let deviceID: string | null = null; @@ -29,7 +29,7 @@ function getDeviceID(): Promise { /** * Saves a unique deviceID into Onyx. */ -function setDeviceID(): void { +function setDeviceID() { getDeviceID() .then((existingDeviceID) => { if (!existingDeviceID) { diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 4287d083d8c3..1910b5a994b8 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -16,14 +16,4 @@ declare module '*.svg' { export default content; } -declare global { - interface Window { - electron: Electron.IpcRenderer - } -} - declare module 'react-native-device-info/jest/react-native-device-info-mock'; - -export {} - - diff --git a/src/types/modules/electron.d.ts b/src/types/modules/electron.d.ts new file mode 100644 index 000000000000..09e33f29ba38 --- /dev/null +++ b/src/types/modules/electron.d.ts @@ -0,0 +1,18 @@ +// TODO: Move this type to desktop/contextBridge.js once it is converted to TS +type ContextBridgeApi = { + send: (channel: string, data?: unknown) => void; + sendSync: (channel: string, data?: unknown) => unknown; + invoke: (channel: string, ...args: unknown) => Promise; + on: (channel: string, func: () => void) => void; + removeAllListeners: (channel: string) => void; +}; + +declare global { + // eslint-disable-next-line @typescript-eslint/consistent-type-definitions + interface Window { + electron: ContextBridgeApi; + } +} + +// We used the export {} line to mark this file as an external module +export {}; From 02b524ce2b3930a44114b158f829fbe16f7fe574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Fa=C5=82at?= Date: Tue, 26 Sep 2023 10:10:58 +0200 Subject: [PATCH 07/13] Suggested change from code review. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fábio Henriques --- src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts index 3ffedda9a91e..c0bd6bd15add 100644 --- a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts +++ b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts @@ -1,7 +1,7 @@ import packageConfig from '../../../../../package.json'; import {GetBaseInfo} from "./types"; -export const getBaseInfo: GetBaseInfo = () => { +const getBaseInfo: GetBaseInfo = () => { return { app_version: packageConfig.version, timestamp: new Date().toISOString().slice(0, 19), From e87a349647b4723454a065d6580bd2288e7a411a Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Wed, 27 Sep 2023 09:39:59 +0200 Subject: [PATCH 08/13] Applied linter changes and resolved conflicts. --- src/libs/actions/Device/generateDeviceID/index.android.ts | 4 +--- src/libs/actions/Device/generateDeviceID/index.desktop.ts | 4 +--- src/libs/actions/Device/generateDeviceID/index.ios.ts | 4 +--- src/libs/actions/Device/generateDeviceID/index.ts | 4 +--- src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts | 6 ++---- .../Device/getDeviceInfo/getOSAndName/index.native.ts | 2 +- src/libs/actions/Device/getDeviceInfo/index.android.ts | 6 ++---- src/libs/actions/Device/getDeviceInfo/index.desktop.ts | 7 +++---- src/libs/actions/Device/getDeviceInfo/index.ios.ts | 7 +++---- src/libs/actions/Device/getDeviceInfo/index.ts | 6 ++---- src/libs/actions/Device/index.ts | 6 +++--- 11 files changed, 20 insertions(+), 36 deletions(-) diff --git a/src/libs/actions/Device/generateDeviceID/index.android.ts b/src/libs/actions/Device/generateDeviceID/index.android.ts index 195d7f0997e6..92a1587a22b6 100644 --- a/src/libs/actions/Device/generateDeviceID/index.android.ts +++ b/src/libs/actions/Device/generateDeviceID/index.android.ts @@ -24,8 +24,6 @@ const uniqueID = Str.guid(deviceID); * Furthermore, the deviceID prefix is not unique to a specific device, but is likely to change from one type of device to another. * Including this prefix will tell us with a reasonable degree of confidence if the user just uninstalled and reinstalled the app, or if they got a new device. */ -const generateDeviceID: GenerateDeviceID = () => { - return Promise.resolve(uniqueID); -} +const generateDeviceID: GenerateDeviceID = () => Promise.resolve(uniqueID) export default generateDeviceID; diff --git a/src/libs/actions/Device/generateDeviceID/index.desktop.ts b/src/libs/actions/Device/generateDeviceID/index.desktop.ts index 4a86e18d30a7..4a632db755cc 100644 --- a/src/libs/actions/Device/generateDeviceID/index.desktop.ts +++ b/src/libs/actions/Device/generateDeviceID/index.desktop.ts @@ -5,8 +5,6 @@ import {GenerateDeviceID} from "./types"; * Get the unique ID of the current device. This should remain the same even if the user uninstalls and reinstalls the app. */ -const generateDeviceID: GenerateDeviceID = () => { - return window.electron.invoke(ELECTRON_EVENTS.REQUEST_DEVICE_ID) as Promise; -} +const generateDeviceID: GenerateDeviceID = () => window.electron.invoke(ELECTRON_EVENTS.REQUEST_DEVICE_ID) as Promise export default generateDeviceID; diff --git a/src/libs/actions/Device/generateDeviceID/index.ios.ts b/src/libs/actions/Device/generateDeviceID/index.ios.ts index 8e8db6361df4..ff5915ce2c95 100644 --- a/src/libs/actions/Device/generateDeviceID/index.ios.ts +++ b/src/libs/actions/Device/generateDeviceID/index.ios.ts @@ -6,8 +6,6 @@ const deviceID = DeviceInfo.getDeviceId(); /** * Get the unique ID of the current device. This should remain the same even if the user uninstalls and reinstalls the app. */ -const generateDeviceID: GenerateDeviceID = () => { - return DeviceInfo.getUniqueId().then((uniqueID: string) => `${deviceID}_${uniqueID}`); -} +const generateDeviceID: GenerateDeviceID = () => DeviceInfo.getUniqueId().then((uniqueID: string) => `${deviceID}_${uniqueID}`) export default generateDeviceID; diff --git a/src/libs/actions/Device/generateDeviceID/index.ts b/src/libs/actions/Device/generateDeviceID/index.ts index 99f4e8c496fc..4ff7b8e8fd0e 100644 --- a/src/libs/actions/Device/generateDeviceID/index.ts +++ b/src/libs/actions/Device/generateDeviceID/index.ts @@ -16,8 +16,6 @@ const uniqueID = Str.guid(); * which is also different/reset under the same circumstances */ -const generateDeviceID: GenerateDeviceID = () => { - return Promise.resolve(uniqueID); -} +const generateDeviceID: GenerateDeviceID = () => Promise.resolve(uniqueID) export default generateDeviceID; diff --git a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts index c0bd6bd15add..742ca91eb92b 100644 --- a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts +++ b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts @@ -1,11 +1,9 @@ import packageConfig from '../../../../../package.json'; import {GetBaseInfo} from "./types"; -const getBaseInfo: GetBaseInfo = () => { - return { +const getBaseInfo: GetBaseInfo = () => ({ app_version: packageConfig.version, timestamp: new Date().toISOString().slice(0, 19), - }; -} + }); export default getBaseInfo; diff --git a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts index 071a5545cf7e..9cf357e25fc4 100644 --- a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts +++ b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts @@ -9,6 +9,6 @@ const getOSAndName: GetOSAndName = () => { device_name: RNDeviceInfo.isEmulatorSync() ? `Emulator - ${prettyName}` : prettyName, os_version: RNDeviceInfo.getSystemVersion(), }; -} +}; export default getOSAndName; diff --git a/src/libs/actions/Device/getDeviceInfo/index.android.ts b/src/libs/actions/Device/getDeviceInfo/index.android.ts index 11f1bddad0e4..1b9b8e9161a8 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.android.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.android.ts @@ -2,12 +2,10 @@ import getBaseInfo from './getBaseInfo'; import getOSAndName from './getOSAndName/index.native'; import {GetDeviceInfo} from './types'; -const getDeviceInfo: GetDeviceInfo = () => { - return { +const getDeviceInfo: GetDeviceInfo = () => ({ ...getBaseInfo(), ...getOSAndName(), os: 'Android', - }; -} + }); export default getDeviceInfo; diff --git a/src/libs/actions/Device/getDeviceInfo/index.desktop.ts b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts index 2b751e04d189..f97d7e0a41b7 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.desktop.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts @@ -1,12 +1,11 @@ import getBaseInfo from './getBaseInfo'; import getOSAndName from './getOSAndName/index.native'; import {GetDeviceInfo} from './types'; -const getDeviceInfo: GetDeviceInfo = () => { - return { + +const getDeviceInfo: GetDeviceInfo = () => ({ ...getBaseInfo(), ...getOSAndName(), device_name: 'Desktop', - }; -} + }); export default getDeviceInfo; diff --git a/src/libs/actions/Device/getDeviceInfo/index.ios.ts b/src/libs/actions/Device/getDeviceInfo/index.ios.ts index cc9828f59925..730109511de2 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.ios.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.ios.ts @@ -1,12 +1,11 @@ import getBaseInfo from './getBaseInfo'; import getOSAndName from './getOSAndName/index.native'; import {GetDeviceInfo} from './types'; -const getDeviceInfo: GetDeviceInfo = () => { - return { + +const getDeviceInfo: GetDeviceInfo = () => ({ ...getBaseInfo(), ...getOSAndName(), os: 'iOS', - }; -} + }); export default getDeviceInfo; diff --git a/src/libs/actions/Device/getDeviceInfo/index.ts b/src/libs/actions/Device/getDeviceInfo/index.ts index d43c957bd925..0b330c55118e 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.ts @@ -2,11 +2,9 @@ import getBaseInfo from './getBaseInfo'; import getOSAndName from "./getOSAndName/index"; import {GetDeviceInfo} from "./types"; -const getDeviceInfo: GetDeviceInfo = () => { - return { +const getDeviceInfo: GetDeviceInfo = () => ({ ...getBaseInfo(), ...getOSAndName(), - }; -} + }); export default getDeviceInfo; diff --git a/src/libs/actions/Device/index.ts b/src/libs/actions/Device/index.ts index 5ed5729f0e07..e49e7cf97dcc 100644 --- a/src/libs/actions/Device/index.ts +++ b/src/libs/actions/Device/index.ts @@ -17,10 +17,10 @@ function getDeviceID(): Promise { const connectionID = Onyx.connect({ key: ONYXKEYS.DEVICE_ID, - callback: (ID: OnyxEntry) => { + callback: (id: OnyxEntry) => { Onyx.disconnect(connectionID); - deviceID = ID; - return resolve(ID); + deviceID = id; + return resolve(id); }, }); }); From 90773e21c3b2a72ee0ec4b8c8ccfdffab26858b4 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Thu, 28 Sep 2023 10:26:45 +0200 Subject: [PATCH 09/13] Fixed linter issues. --- .../actions/Device/generateDeviceID/index.android.ts | 2 +- .../actions/Device/generateDeviceID/index.desktop.ts | 2 +- .../actions/Device/generateDeviceID/index.ios.ts | 2 +- src/libs/actions/Device/generateDeviceID/index.ts | 2 +- src/libs/actions/Device/generateDeviceID/types.ts | 4 +++- src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts | 2 +- .../getDeviceInfo/getOSAndName/index.native.ts | 4 ++-- .../Device/getDeviceInfo/getOSAndName/types.ts | 10 ++++++---- .../actions/Device/getDeviceInfo/index.desktop.ts | 2 +- src/libs/actions/Device/getDeviceInfo/types.ts | 12 +++++++----- 10 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/libs/actions/Device/generateDeviceID/index.android.ts b/src/libs/actions/Device/generateDeviceID/index.android.ts index 92a1587a22b6..433421040608 100644 --- a/src/libs/actions/Device/generateDeviceID/index.android.ts +++ b/src/libs/actions/Device/generateDeviceID/index.android.ts @@ -1,6 +1,6 @@ import DeviceInfo from 'react-native-device-info'; import Str from 'expensify-common/lib/str'; -import {GenerateDeviceID} from "./types"; +import GenerateDeviceID from "./types"; const deviceID = DeviceInfo.getDeviceId(); const uniqueID = Str.guid(deviceID); diff --git a/src/libs/actions/Device/generateDeviceID/index.desktop.ts b/src/libs/actions/Device/generateDeviceID/index.desktop.ts index 4a632db755cc..d067a8213a9c 100644 --- a/src/libs/actions/Device/generateDeviceID/index.desktop.ts +++ b/src/libs/actions/Device/generateDeviceID/index.desktop.ts @@ -1,5 +1,5 @@ import ELECTRON_EVENTS from '../../../../../desktop/ELECTRON_EVENTS'; -import {GenerateDeviceID} from "./types"; +import GenerateDeviceID from "./types"; /** * Get the unique ID of the current device. This should remain the same even if the user uninstalls and reinstalls the app. diff --git a/src/libs/actions/Device/generateDeviceID/index.ios.ts b/src/libs/actions/Device/generateDeviceID/index.ios.ts index ff5915ce2c95..999dbb333fbb 100644 --- a/src/libs/actions/Device/generateDeviceID/index.ios.ts +++ b/src/libs/actions/Device/generateDeviceID/index.ios.ts @@ -1,5 +1,5 @@ import DeviceInfo from 'react-native-device-info'; -import {GenerateDeviceID} from "./types"; +import GenerateDeviceID from "./types"; const deviceID = DeviceInfo.getDeviceId(); diff --git a/src/libs/actions/Device/generateDeviceID/index.ts b/src/libs/actions/Device/generateDeviceID/index.ts index 4ff7b8e8fd0e..4c34c8826591 100644 --- a/src/libs/actions/Device/generateDeviceID/index.ts +++ b/src/libs/actions/Device/generateDeviceID/index.ts @@ -1,5 +1,5 @@ import Str from 'expensify-common/lib/str'; -import {GenerateDeviceID} from "./types"; +import GenerateDeviceID from "./types"; const uniqueID = Str.guid(); diff --git a/src/libs/actions/Device/generateDeviceID/types.ts b/src/libs/actions/Device/generateDeviceID/types.ts index 59d3348aa27c..43b6b89f6154 100644 --- a/src/libs/actions/Device/generateDeviceID/types.ts +++ b/src/libs/actions/Device/generateDeviceID/types.ts @@ -1 +1,3 @@ -export type GenerateDeviceID = () => Promise; +type GenerateDeviceID = () => Promise; + +export default GenerateDeviceID; diff --git a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts index 742ca91eb92b..43035281e31d 100644 --- a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts +++ b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts @@ -2,7 +2,7 @@ import packageConfig from '../../../../../package.json'; import {GetBaseInfo} from "./types"; const getBaseInfo: GetBaseInfo = () => ({ - app_version: packageConfig.version, + appVersion: packageConfig.version, timestamp: new Date().toISOString().slice(0, 19), }); diff --git a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts index 9cf357e25fc4..bbac82420d86 100644 --- a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts +++ b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts @@ -6,8 +6,8 @@ const getOSAndName: GetOSAndName = () => { const deviceName = RNDeviceInfo.getDeviceNameSync(); const prettyName = `${Str.UCFirst(RNDeviceInfo.getManufacturerSync() || '')} ${deviceName}`; return { - device_name: RNDeviceInfo.isEmulatorSync() ? `Emulator - ${prettyName}` : prettyName, - os_version: RNDeviceInfo.getSystemVersion(), + deviceName: RNDeviceInfo.isEmulatorSync() ? `Emulator - ${prettyName}` : prettyName, + osVersion: RNDeviceInfo.getSystemVersion(), }; }; diff --git a/src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts b/src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts index 19d59fb192c2..8c39940bfbae 100644 --- a/src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts +++ b/src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts @@ -1,5 +1,7 @@ -export type GetOSAndName = () => OSAndName; -export type OSAndName = { - device_name?: string; - os_version?: string; +type GetOSAndName = () => OSAndName; +type OSAndName = { + deviceName?: string; + osVersion?: string; } + +export type {GetOSAndName, OSAndName}; diff --git a/src/libs/actions/Device/getDeviceInfo/index.desktop.ts b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts index f97d7e0a41b7..bef66fdcd760 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.desktop.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts @@ -5,7 +5,7 @@ import {GetDeviceInfo} from './types'; const getDeviceInfo: GetDeviceInfo = () => ({ ...getBaseInfo(), ...getOSAndName(), - device_name: 'Desktop', + deviceName: 'Desktop', }); export default getDeviceInfo; diff --git a/src/libs/actions/Device/getDeviceInfo/types.ts b/src/libs/actions/Device/getDeviceInfo/types.ts index 4fc6492693e8..a5b034eaacd4 100644 --- a/src/libs/actions/Device/getDeviceInfo/types.ts +++ b/src/libs/actions/Device/getDeviceInfo/types.ts @@ -1,10 +1,12 @@ import {OSAndName} from "./getOSAndName/types"; -export type BaseInfo = { - app_version: string; +type BaseInfo = { + appVersion: string; timestamp: string; }; -export type GetDeviceInfo = () => DeviceInfo; -export type DeviceInfo = BaseInfo & OSAndName & {os?: string, device_name?: string, device_version?: string}; -export type GetBaseInfo = () => BaseInfo; +type GetDeviceInfo = () => DeviceInfo; +type DeviceInfo = BaseInfo & OSAndName & {os?: string, deviceName?: string, deviceVersion?: string}; +type GetBaseInfo = () => BaseInfo; + +export type {GetDeviceInfo, DeviceInfo, GetBaseInfo, BaseInfo}; From 686c0ad0efe14eaad5d6d8bb9e42a5f482460974 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Thu, 5 Oct 2023 08:08:30 +0200 Subject: [PATCH 10/13] Resolved linter issues. --- .../actions/Device/generateDeviceID/index.android.ts | 4 ++-- .../actions/Device/generateDeviceID/index.desktop.ts | 4 ++-- src/libs/actions/Device/generateDeviceID/index.ios.ts | 4 ++-- src/libs/actions/Device/generateDeviceID/index.ts | 4 ++-- src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts | 8 ++++---- .../Device/getDeviceInfo/getOSAndName/index.native.ts | 2 +- .../actions/Device/getDeviceInfo/getOSAndName/types.ts | 2 +- src/libs/actions/Device/getDeviceInfo/index.android.ts | 8 ++++---- src/libs/actions/Device/getDeviceInfo/index.desktop.ts | 8 ++++---- src/libs/actions/Device/getDeviceInfo/index.ios.ts | 8 ++++---- src/libs/actions/Device/getDeviceInfo/index.ts | 10 +++++----- src/libs/actions/Device/getDeviceInfo/types.ts | 4 ++-- 12 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/libs/actions/Device/generateDeviceID/index.android.ts b/src/libs/actions/Device/generateDeviceID/index.android.ts index 433421040608..0f6a7140e648 100644 --- a/src/libs/actions/Device/generateDeviceID/index.android.ts +++ b/src/libs/actions/Device/generateDeviceID/index.android.ts @@ -1,6 +1,6 @@ import DeviceInfo from 'react-native-device-info'; import Str from 'expensify-common/lib/str'; -import GenerateDeviceID from "./types"; +import GenerateDeviceID from './types'; const deviceID = DeviceInfo.getDeviceId(); const uniqueID = Str.guid(deviceID); @@ -24,6 +24,6 @@ const uniqueID = Str.guid(deviceID); * Furthermore, the deviceID prefix is not unique to a specific device, but is likely to change from one type of device to another. * Including this prefix will tell us with a reasonable degree of confidence if the user just uninstalled and reinstalled the app, or if they got a new device. */ -const generateDeviceID: GenerateDeviceID = () => Promise.resolve(uniqueID) +const generateDeviceID: GenerateDeviceID = () => Promise.resolve(uniqueID); export default generateDeviceID; diff --git a/src/libs/actions/Device/generateDeviceID/index.desktop.ts b/src/libs/actions/Device/generateDeviceID/index.desktop.ts index d067a8213a9c..a5e1acdc40fd 100644 --- a/src/libs/actions/Device/generateDeviceID/index.desktop.ts +++ b/src/libs/actions/Device/generateDeviceID/index.desktop.ts @@ -1,10 +1,10 @@ import ELECTRON_EVENTS from '../../../../../desktop/ELECTRON_EVENTS'; -import GenerateDeviceID from "./types"; +import GenerateDeviceID from './types'; /** * Get the unique ID of the current device. This should remain the same even if the user uninstalls and reinstalls the app. */ -const generateDeviceID: GenerateDeviceID = () => window.electron.invoke(ELECTRON_EVENTS.REQUEST_DEVICE_ID) as Promise +const generateDeviceID: GenerateDeviceID = () => window.electron.invoke(ELECTRON_EVENTS.REQUEST_DEVICE_ID) as Promise; export default generateDeviceID; diff --git a/src/libs/actions/Device/generateDeviceID/index.ios.ts b/src/libs/actions/Device/generateDeviceID/index.ios.ts index 999dbb333fbb..6567ffffb8d3 100644 --- a/src/libs/actions/Device/generateDeviceID/index.ios.ts +++ b/src/libs/actions/Device/generateDeviceID/index.ios.ts @@ -1,11 +1,11 @@ import DeviceInfo from 'react-native-device-info'; -import GenerateDeviceID from "./types"; +import GenerateDeviceID from './types'; const deviceID = DeviceInfo.getDeviceId(); /** * Get the unique ID of the current device. This should remain the same even if the user uninstalls and reinstalls the app. */ -const generateDeviceID: GenerateDeviceID = () => DeviceInfo.getUniqueId().then((uniqueID: string) => `${deviceID}_${uniqueID}`) +const generateDeviceID: GenerateDeviceID = () => DeviceInfo.getUniqueId().then((uniqueID: string) => `${deviceID}_${uniqueID}`); export default generateDeviceID; diff --git a/src/libs/actions/Device/generateDeviceID/index.ts b/src/libs/actions/Device/generateDeviceID/index.ts index 4c34c8826591..b7011b7bb2d9 100644 --- a/src/libs/actions/Device/generateDeviceID/index.ts +++ b/src/libs/actions/Device/generateDeviceID/index.ts @@ -1,5 +1,5 @@ import Str from 'expensify-common/lib/str'; -import GenerateDeviceID from "./types"; +import GenerateDeviceID from './types'; const uniqueID = Str.guid(); @@ -16,6 +16,6 @@ const uniqueID = Str.guid(); * which is also different/reset under the same circumstances */ -const generateDeviceID: GenerateDeviceID = () => Promise.resolve(uniqueID) +const generateDeviceID: GenerateDeviceID = () => Promise.resolve(uniqueID); export default generateDeviceID; diff --git a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts index 43035281e31d..aa5ef00815d2 100644 --- a/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts +++ b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts @@ -1,9 +1,9 @@ import packageConfig from '../../../../../package.json'; -import {GetBaseInfo} from "./types"; +import {GetBaseInfo} from './types'; const getBaseInfo: GetBaseInfo = () => ({ - appVersion: packageConfig.version, - timestamp: new Date().toISOString().slice(0, 19), - }); + appVersion: packageConfig.version, + timestamp: new Date().toISOString().slice(0, 19), +}); export default getBaseInfo; diff --git a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts index bbac82420d86..bfce98b1c65e 100644 --- a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts +++ b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts @@ -1,6 +1,6 @@ import Str from 'expensify-common/lib/str'; import RNDeviceInfo from 'react-native-device-info'; -import {GetOSAndName} from "./types"; +import {GetOSAndName} from './types'; const getOSAndName: GetOSAndName = () => { const deviceName = RNDeviceInfo.getDeviceNameSync(); diff --git a/src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts b/src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts index 8c39940bfbae..2f1a68a319c0 100644 --- a/src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts +++ b/src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts @@ -2,6 +2,6 @@ type GetOSAndName = () => OSAndName; type OSAndName = { deviceName?: string; osVersion?: string; -} +}; export type {GetOSAndName, OSAndName}; diff --git a/src/libs/actions/Device/getDeviceInfo/index.android.ts b/src/libs/actions/Device/getDeviceInfo/index.android.ts index 1b9b8e9161a8..031fa9800698 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.android.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.android.ts @@ -3,9 +3,9 @@ import getOSAndName from './getOSAndName/index.native'; import {GetDeviceInfo} from './types'; const getDeviceInfo: GetDeviceInfo = () => ({ - ...getBaseInfo(), - ...getOSAndName(), - os: 'Android', - }); + ...getBaseInfo(), + ...getOSAndName(), + os: 'Android', +}); export default getDeviceInfo; diff --git a/src/libs/actions/Device/getDeviceInfo/index.desktop.ts b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts index bef66fdcd760..650a432d6ce9 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.desktop.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts @@ -3,9 +3,9 @@ import getOSAndName from './getOSAndName/index.native'; import {GetDeviceInfo} from './types'; const getDeviceInfo: GetDeviceInfo = () => ({ - ...getBaseInfo(), - ...getOSAndName(), - deviceName: 'Desktop', - }); + ...getBaseInfo(), + ...getOSAndName(), + deviceName: 'Desktop', +}); export default getDeviceInfo; diff --git a/src/libs/actions/Device/getDeviceInfo/index.ios.ts b/src/libs/actions/Device/getDeviceInfo/index.ios.ts index 730109511de2..12b564137a08 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.ios.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.ios.ts @@ -3,9 +3,9 @@ import getOSAndName from './getOSAndName/index.native'; import {GetDeviceInfo} from './types'; const getDeviceInfo: GetDeviceInfo = () => ({ - ...getBaseInfo(), - ...getOSAndName(), - os: 'iOS', - }); + ...getBaseInfo(), + ...getOSAndName(), + os: 'iOS', +}); export default getDeviceInfo; diff --git a/src/libs/actions/Device/getDeviceInfo/index.ts b/src/libs/actions/Device/getDeviceInfo/index.ts index 0b330c55118e..b82aafc56cbe 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.ts @@ -1,10 +1,10 @@ import getBaseInfo from './getBaseInfo'; -import getOSAndName from "./getOSAndName/index"; -import {GetDeviceInfo} from "./types"; +import getOSAndName from './getOSAndName/index'; +import {GetDeviceInfo} from './types'; const getDeviceInfo: GetDeviceInfo = () => ({ - ...getBaseInfo(), - ...getOSAndName(), - }); + ...getBaseInfo(), + ...getOSAndName(), +}); export default getDeviceInfo; diff --git a/src/libs/actions/Device/getDeviceInfo/types.ts b/src/libs/actions/Device/getDeviceInfo/types.ts index a5b034eaacd4..684ef68f1359 100644 --- a/src/libs/actions/Device/getDeviceInfo/types.ts +++ b/src/libs/actions/Device/getDeviceInfo/types.ts @@ -1,4 +1,4 @@ -import {OSAndName} from "./getOSAndName/types"; +import {OSAndName} from './getOSAndName/types'; type BaseInfo = { appVersion: string; @@ -6,7 +6,7 @@ type BaseInfo = { }; type GetDeviceInfo = () => DeviceInfo; -type DeviceInfo = BaseInfo & OSAndName & {os?: string, deviceName?: string, deviceVersion?: string}; +type DeviceInfo = BaseInfo & OSAndName & {os?: string; deviceName?: string; deviceVersion?: string}; type GetBaseInfo = () => BaseInfo; export type {GetDeviceInfo, DeviceInfo, GetBaseInfo, BaseInfo}; From 1008c6cfed67cb13bb81b4c72c683f0a995c89cd Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Mon, 6 Nov 2023 10:38:53 +0100 Subject: [PATCH 11/13] Conflicts resolved, TS-fixes, linter, prettier. --- src/libs/actions/Device/generateDeviceID/index.android.ts | 2 +- src/libs/actions/Device/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Device/generateDeviceID/index.android.ts b/src/libs/actions/Device/generateDeviceID/index.android.ts index 1034fd65c6f2..5fadc63ac3ba 100644 --- a/src/libs/actions/Device/generateDeviceID/index.android.ts +++ b/src/libs/actions/Device/generateDeviceID/index.android.ts @@ -1,6 +1,6 @@ import Str from 'expensify-common/lib/str'; -import GenerateDeviceID from './types'; import DeviceInfo from 'react-native-device-info'; +import GenerateDeviceID from './types'; const deviceID = DeviceInfo.getDeviceId(); const uniqueID = Str.guid(deviceID); diff --git a/src/libs/actions/Device/index.ts b/src/libs/actions/Device/index.ts index 4ec2904ac8be..761e27d95a78 100644 --- a/src/libs/actions/Device/index.ts +++ b/src/libs/actions/Device/index.ts @@ -17,7 +17,7 @@ function getDeviceID(): Promise { const connectionID = Onyx.connect({ key: ONYXKEYS.DEVICE_ID, - callback: (id: OnyxEntry) => { + callback: (id) => { Onyx.disconnect(connectionID); deviceID = id; return resolve(id); From 916208821988f4eab050161376c1f2a5715ddabe Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Mon, 6 Nov 2023 13:17:08 +0100 Subject: [PATCH 12/13] Updated expensify-common lib --- package-lock.json | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index a80022853a24..3b0faf41410f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53,7 +53,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#82bfcd1cb077afd03d1c8c069618c7dd5bd405d8", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#886f90cbd5e83218fdfd7784d8356c308ef05791", "fbjs": "^3.0.2", "htmlparser2": "^7.2.0", "idb-keyval": "^6.2.1", @@ -30346,8 +30346,8 @@ }, "node_modules/expensify-common": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#82bfcd1cb077afd03d1c8c069618c7dd5bd405d8", - "integrity": "sha512-Pvji3XqRyCbhgaKLVPT0HfRl/cazGStQeo8V6tWcU1n3UNiG/6Qey4jAdfN8WQZlfslrSzFiZTWrD7UT0JeRrQ==", + "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#886f90cbd5e83218fdfd7784d8356c308ef05791", + "integrity": "sha512-f+HGB8GZ9NTHT1oI6fhiGfIM3Cd411Qg45Nl0Yd3Te2CU34FhwMNLEkcDa6/zAlYkCeoJUk5XUVmTimjEgS0ig==", "license": "MIT", "dependencies": { "classnames": "2.3.1", @@ -75060,9 +75060,9 @@ } }, "expensify-common": { - "version": "git+ssh://git@github.com/Expensify/expensify-common.git#82bfcd1cb077afd03d1c8c069618c7dd5bd405d8", - "integrity": "sha512-Pvji3XqRyCbhgaKLVPT0HfRl/cazGStQeo8V6tWcU1n3UNiG/6Qey4jAdfN8WQZlfslrSzFiZTWrD7UT0JeRrQ==", - "from": "expensify-common@git+ssh://git@github.com/Expensify/expensify-common.git#82bfcd1cb077afd03d1c8c069618c7dd5bd405d8", + "version": "git+ssh://git@github.com/Expensify/expensify-common.git#886f90cbd5e83218fdfd7784d8356c308ef05791", + "integrity": "sha512-f+HGB8GZ9NTHT1oI6fhiGfIM3Cd411Qg45Nl0Yd3Te2CU34FhwMNLEkcDa6/zAlYkCeoJUk5XUVmTimjEgS0ig==", + "from": "expensify-common@git+ssh://git@github.com/Expensify/expensify-common.git#886f90cbd5e83218fdfd7784d8356c308ef05791", "requires": { "classnames": "2.3.1", "clipboard": "2.0.4", diff --git a/package.json b/package.json index f3462a2b63bb..a5bafd4b9d6d 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#82bfcd1cb077afd03d1c8c069618c7dd5bd405d8", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#886f90cbd5e83218fdfd7784d8356c308ef05791", "fbjs": "^3.0.2", "htmlparser2": "^7.2.0", "idb-keyval": "^6.2.1", From ee562a9ac8c9f1a3efdc0bc3e7318cc9cff04e23 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Thu, 9 Nov 2023 10:24:03 +0100 Subject: [PATCH 13/13] Device lib fixes. --- src/libs/actions/Device/getDeviceInfo/index.android.ts | 2 +- src/libs/actions/Device/getDeviceInfo/index.desktop.ts | 2 +- src/libs/actions/Device/getDeviceInfo/index.ios.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Device/getDeviceInfo/index.android.ts b/src/libs/actions/Device/getDeviceInfo/index.android.ts index 031fa9800698..6d8e9e497145 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.android.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.android.ts @@ -1,5 +1,5 @@ import getBaseInfo from './getBaseInfo'; -import getOSAndName from './getOSAndName/index.native'; +import getOSAndName from './getOSAndName/index'; import {GetDeviceInfo} from './types'; const getDeviceInfo: GetDeviceInfo = () => ({ diff --git a/src/libs/actions/Device/getDeviceInfo/index.desktop.ts b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts index 650a432d6ce9..cb99de08ae93 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.desktop.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts @@ -1,5 +1,5 @@ import getBaseInfo from './getBaseInfo'; -import getOSAndName from './getOSAndName/index.native'; +import getOSAndName from './getOSAndName/index'; import {GetDeviceInfo} from './types'; const getDeviceInfo: GetDeviceInfo = () => ({ diff --git a/src/libs/actions/Device/getDeviceInfo/index.ios.ts b/src/libs/actions/Device/getDeviceInfo/index.ios.ts index 12b564137a08..b91d5236a084 100644 --- a/src/libs/actions/Device/getDeviceInfo/index.ios.ts +++ b/src/libs/actions/Device/getDeviceInfo/index.ios.ts @@ -1,5 +1,5 @@ import getBaseInfo from './getBaseInfo'; -import getOSAndName from './getOSAndName/index.native'; +import getOSAndName from './getOSAndName/index'; import {GetDeviceInfo} from './types'; const getDeviceInfo: GetDeviceInfo = () => ({