diff --git a/web/database/utils/constants.js b/web/database/utils/constants.js --- a/web/database/utils/constants.js +++ b/web/database/utils/constants.js @@ -6,3 +6,18 @@ export const CURRENT_USER_ID_KEY = 'current_user_id'; export const DB_PERSIST_THROTTLE_WAIT_MS = 300; + +export const DB_SUPPORTED_OS: $ReadOnlyArray = [ + 'Windows 10', + 'Linux', + 'Mac OS', +]; + +export const DB_SUPPORTED_BROWSERS: $ReadOnlyArray = [ + 'edge', + 'edge-chromium', + 'chrome', + 'safari', + 'firefox', + 'opera', +]; diff --git a/web/database/utils/db-utils.js b/web/database/utils/db-utils.js --- a/web/database/utils/db-utils.js +++ b/web/database/utils/db-utils.js @@ -1,7 +1,13 @@ // @flow +import { detect as detectBrowser } from 'detect-browser'; import type { QueryExecResult } from 'sql.js'; +import { isStaff } from 'lib/shared/user-utils.js'; +import { isDev } from 'lib/utils/dev-utils.js'; + +import { DB_SUPPORTED_BROWSERS, DB_SUPPORTED_OS } from './constants.js'; + function parseSQLiteQueryResult(result: QueryExecResult): T[] { const { columns, values } = result; return values.map(rowResult => { @@ -24,4 +30,19 @@ ); } -export { parseMultiStatementSQLiteResult }; +function isSQLiteSupported(currentLoggedInUserID: ?string): boolean { + if (!currentLoggedInUserID) { + return false; + } + const canUseSqlite = + isDev || (currentLoggedInUserID && isStaff(currentLoggedInUserID)); + + const browser = detectBrowser(); + const isSupportedBrowser = + DB_SUPPORTED_OS.includes(browser.os) && + DB_SUPPORTED_BROWSERS.includes(browser.name); + + return canUseSqlite && isSupportedBrowser; +} + +export { parseMultiStatementSQLiteResult, isSQLiteSupported };