diff --git a/package-lock.json b/package-lock.json index 56d9dc64a62a..f8d00de85bf8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -52,7 +52,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#a055da6a339383da825f353d5c0da72a26285007", + "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", @@ -30317,8 +30317,8 @@ }, "node_modules/expensify-common": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#a055da6a339383da825f353d5c0da72a26285007", - "integrity": "sha512-3szmT0160oahs8DMBT7kBBhz/FKofRfZ59q9E2/0ktBAeP4wx+zp13aUenGueabq7S/BPAidBni7tUrKpF0SIA==", + "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#886f90cbd5e83218fdfd7784d8356c308ef05791", + "integrity": "sha512-f+HGB8GZ9NTHT1oI6fhiGfIM3Cd411Qg45Nl0Yd3Te2CU34FhwMNLEkcDa6/zAlYkCeoJUk5XUVmTimjEgS0ig==", "license": "MIT", "dependencies": { "classnames": "2.3.1", @@ -75000,9 +75000,9 @@ } }, "expensify-common": { - "version": "git+ssh://git@github.com/Expensify/expensify-common.git#a055da6a339383da825f353d5c0da72a26285007", - "integrity": "sha512-3szmT0160oahs8DMBT7kBBhz/FKofRfZ59q9E2/0ktBAeP4wx+zp13aUenGueabq7S/BPAidBni7tUrKpF0SIA==", - "from": "expensify-common@git+ssh://git@github.com/Expensify/expensify-common.git#a055da6a339383da825f353d5c0da72a26285007", + "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 beab596bcbb4..ff9d19cce971 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#a055da6a339383da825f353d5c0da72a26285007", + "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", diff --git a/src/libs/actions/Device/generateDeviceID/index.android.js b/src/libs/actions/Device/generateDeviceID/index.android.ts similarity index 92% rename from src/libs/actions/Device/generateDeviceID/index.android.js rename to src/libs/actions/Device/generateDeviceID/index.android.ts index 41fc946839b7..5fadc63ac3ba 100644 --- a/src/libs/actions/Device/generateDeviceID/index.android.js +++ b/src/libs/actions/Device/generateDeviceID/index.android.ts @@ -1,5 +1,6 @@ import Str from 'expensify-common/lib/str'; import DeviceInfo from 'react-native-device-info'; +import GenerateDeviceID from './types'; const deviceID = DeviceInfo.getDeviceId(); const uniqueID = Str.guid(deviceID); @@ -22,11 +23,7 @@ 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} */ -function generateDeviceID() { - return Promise.resolve(uniqueID); -} +const generateDeviceID: GenerateDeviceID = () => Promise.resolve(uniqueID); export default generateDeviceID; diff --git a/src/libs/actions/Device/generateDeviceID/index.desktop.js b/src/libs/actions/Device/generateDeviceID/index.desktop.ts similarity index 58% rename from src/libs/actions/Device/generateDeviceID/index.desktop.js rename to src/libs/actions/Device/generateDeviceID/index.desktop.ts index 26de25e326e8..a5e1acdc40fd 100644 --- a/src/libs/actions/Device/generateDeviceID/index.desktop.js +++ b/src/libs/actions/Device/generateDeviceID/index.desktop.ts @@ -1,12 +1,10 @@ import ELECTRON_EVENTS from '../../../../../desktop/ELECTRON_EVENTS'; +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 {Promise} */ -function generateDeviceID() { - return window.electron.invoke(ELECTRON_EVENTS.REQUEST_DEVICE_ID); -} + +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.js b/src/libs/actions/Device/generateDeviceID/index.ios.ts similarity index 60% rename from src/libs/actions/Device/generateDeviceID/index.ios.js rename to src/libs/actions/Device/generateDeviceID/index.ios.ts index 6836edf1fcee..6567ffffb8d3 100644 --- a/src/libs/actions/Device/generateDeviceID/index.ios.js +++ b/src/libs/actions/Device/generateDeviceID/index.ios.ts @@ -1,14 +1,11 @@ import DeviceInfo from 'react-native-device-info'; +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. - * - * @returns {Promise} */ -function generateDeviceID() { - return DeviceInfo.getUniqueId().then((uniqueID) => `${deviceID}_${uniqueID}`); -} +const generateDeviceID: GenerateDeviceID = () => 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.ts similarity index 87% rename from src/libs/actions/Device/generateDeviceID/index.website.js rename to src/libs/actions/Device/generateDeviceID/index.ts index b8abc4734134..b7011b7bb2d9 100644 --- a/src/libs/actions/Device/generateDeviceID/index.website.js +++ b/src/libs/actions/Device/generateDeviceID/index.ts @@ -1,4 +1,5 @@ import Str from 'expensify-common/lib/str'; +import GenerateDeviceID from './types'; const uniqueID = Str.guid(); @@ -13,11 +14,8 @@ 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} */ -function generateDeviceID() { - return Promise.resolve(uniqueID); -} + +const generateDeviceID: GenerateDeviceID = () => 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..43b6b89f6154 --- /dev/null +++ b/src/libs/actions/Device/generateDeviceID/types.ts @@ -0,0 +1,3 @@ +type GenerateDeviceID = () => Promise; + +export default GenerateDeviceID; 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..aa5ef00815d2 --- /dev/null +++ b/src/libs/actions/Device/getDeviceInfo/getBaseInfo.ts @@ -0,0 +1,9 @@ +import packageConfig from '../../../../../package.json'; +import {GetBaseInfo} from './types'; + +const getBaseInfo: GetBaseInfo = () => ({ + 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 bb9eb572570e..bfce98b1c65e 100644 --- a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts +++ b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts @@ -1,17 +1,13 @@ 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(); const prettyName = `${Str.UCFirst(RNDeviceInfo.getManufacturerSync() || '')} ${deviceName}`; return { - // Parameter names are predefined and we don't choose it here - // eslint-disable-next-line @typescript-eslint/naming-convention - device_name: RNDeviceInfo.isEmulatorSync() ? `Emulator - ${prettyName}` : prettyName, - // Parameter names are predefined and we don't choose it here - // eslint-disable-next-line @typescript-eslint/naming-convention - os_version: RNDeviceInfo.getSystemVersion(), + deviceName: RNDeviceInfo.isEmulatorSync() ? `Emulator - ${prettyName}` : prettyName, + osVersion: RNDeviceInfo.getSystemVersion(), }; }; diff --git a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts index d63c2fedc51d..29b004412f64 100644 --- a/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts +++ b/src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts @@ -1,12 +1,4 @@ -import {getOSAndName as libGetOSAndName} from 'expensify-common/lib/Device'; -import GetOSAndName from './types'; +// Don't import this file with '* as Device'. It's known to make VSCode IntelliSense crash. +import {getOSAndName} from 'expensify-common/lib/Device'; -const getOSAndName: GetOSAndName = () => { - // Parameter names are predefined and we don't choose it here - // eslint-disable-next-line @typescript-eslint/naming-convention - const {device_name, os_version} = libGetOSAndName(); - // Parameter names are predefined and we don't choose it here - // eslint-disable-next-line @typescript-eslint/naming-convention - return {device_name, os_version}; -}; export default getOSAndName; diff --git a/src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts b/src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts index 2ca67c3c59c3..2f1a68a319c0 100644 --- a/src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts +++ b/src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts @@ -1,4 +1,7 @@ -// Parameter names are predefined and we don't choose it here -// eslint-disable-next-line @typescript-eslint/naming-convention -type GetOSAndName = () => {device_name: string | undefined; os_version: string | undefined}; -export default GetOSAndName; +type GetOSAndName = () => OSAndName; +type OSAndName = { + deviceName?: string; + osVersion?: string; +}; + +export type {GetOSAndName, OSAndName}; 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..6d8e9e497145 --- /dev/null +++ b/src/libs/actions/Device/getDeviceInfo/index.android.ts @@ -0,0 +1,11 @@ +import getBaseInfo from './getBaseInfo'; +import getOSAndName from './getOSAndName/index'; +import {GetDeviceInfo} from './types'; + +const getDeviceInfo: GetDeviceInfo = () => ({ + ...getBaseInfo(), + ...getOSAndName(), + os: 'Android', +}); + +export default getDeviceInfo; 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..cb99de08ae93 --- /dev/null +++ b/src/libs/actions/Device/getDeviceInfo/index.desktop.ts @@ -0,0 +1,11 @@ +import getBaseInfo from './getBaseInfo'; +import getOSAndName from './getOSAndName/index'; +import {GetDeviceInfo} from './types'; + +const getDeviceInfo: GetDeviceInfo = () => ({ + ...getBaseInfo(), + ...getOSAndName(), + deviceName: 'Desktop', +}); + +export default getDeviceInfo; 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..b91d5236a084 --- /dev/null +++ b/src/libs/actions/Device/getDeviceInfo/index.ios.ts @@ -0,0 +1,11 @@ +import getBaseInfo from './getBaseInfo'; +import getOSAndName from './getOSAndName/index'; +import {GetDeviceInfo} from './types'; + +const getDeviceInfo: GetDeviceInfo = () => ({ + ...getBaseInfo(), + ...getOSAndName(), + os: 'iOS', +}); + +export default getDeviceInfo; 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..b82aafc56cbe --- /dev/null +++ b/src/libs/actions/Device/getDeviceInfo/index.ts @@ -0,0 +1,10 @@ +import getBaseInfo from './getBaseInfo'; +import getOSAndName from './getOSAndName/index'; +import {GetDeviceInfo} from './types'; + +const getDeviceInfo: GetDeviceInfo = () => ({ + ...getBaseInfo(), + ...getOSAndName(), +}); + +export default getDeviceInfo; diff --git a/src/libs/actions/Device/getDeviceInfo/types.ts b/src/libs/actions/Device/getDeviceInfo/types.ts new file mode 100644 index 000000000000..684ef68f1359 --- /dev/null +++ b/src/libs/actions/Device/getDeviceInfo/types.ts @@ -0,0 +1,12 @@ +import {OSAndName} from './getOSAndName/types'; + +type BaseInfo = { + appVersion: string; + timestamp: string; +}; + +type GetDeviceInfo = () => DeviceInfo; +type DeviceInfo = BaseInfo & OSAndName & {os?: string; deviceName?: string; deviceVersion?: string}; +type GetBaseInfo = () => BaseInfo; + +export type {GetDeviceInfo, DeviceInfo, GetBaseInfo, BaseInfo}; diff --git a/src/libs/actions/Device/index.js b/src/libs/actions/Device/index.ts similarity index 79% rename from src/libs/actions/Device/index.js rename to src/libs/actions/Device/index.ts index 8394bf226b12..761e27d95a78 100644 --- a/src/libs/actions/Device/index.js +++ b/src/libs/actions/Device/index.ts @@ -4,12 +4,12 @@ import ONYXKEYS from '@src/ONYXKEYS'; import generateDeviceID from './generateDeviceID'; import getDeviceInfo from './getDeviceInfo'; -let deviceID; +let deviceID: string | null = null; /** - * @returns {Promise} + * @returns - device ID string or null in case of failure */ -function getDeviceID() { +function getDeviceID(): Promise { return new Promise((resolve) => { if (deviceID) { return resolve(deviceID); @@ -17,10 +17,10 @@ function getDeviceID() { const connectionID = Onyx.connect({ key: ONYXKEYS.DEVICE_ID, - callback: (ID) => { + callback: (id) => { Onyx.disconnect(connectionID); - deviceID = ID; - return resolve(ID); + 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(