diff --git a/android/app/src/main/java/com/expensify/chat/MainApplication.kt b/android/app/src/main/java/com/expensify/chat/MainApplication.kt index 89c47fdfa86d..987a3d9b7d7c 100644 --- a/android/app/src/main/java/com/expensify/chat/MainApplication.kt +++ b/android/app/src/main/java/com/expensify/chat/MainApplication.kt @@ -14,7 +14,6 @@ import androidx.multidex.MultiDexApplication import com.expensify.chat.bootsplash.BootSplashPackage import com.expensify.chat.navbar.NavBarManagerPackage import com.expensify.chat.shortcutManagerModule.ShortcutManagerPackage -import com.margelo.nitro.nitrofetch.AutoPrefetcher import com.facebook.react.PackageList import com.facebook.react.ReactApplication import com.facebook.react.ReactHost @@ -80,12 +79,6 @@ class MainApplication : MultiDexApplication(), ReactApplication { // Install certificate pinning for React Native's shared OkHttp client (covers fetch(), // react-native-blob-util, etc.). Must run before any networking starts. CertificatePinning.install() - // This is the entrypoint for prefetching with `react-native-nitro-fetch`. - try { - AutoPrefetcher.prefetchOnStart(this) - } catch (_: Throwable) { - System.err.println("Error initializing Nitro `AutoPrefetcher`") - } loadReactNative(this) diff --git a/index.js b/index.js index cf005180666d..978a5ffc7cfd 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,6 @@ * @format */ // import of polyfills should always be first -import './src/polyfills/NitroFetch'; import './src/polyfills/PromiseWithResolvers'; import './src/polyfills/requestIdleCallback'; import {AppRegistry} from 'react-native'; diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 1dbb9063b48a..500ed780bb20 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -405,37 +405,7 @@ PODS: - nanopb/encode (= 3.30910.0) - nanopb/decode (3.30910.0) - nanopb/encode (3.30910.0) - - NitroFetch (1.4.3-alpha.1): - - boost - - DoubleConversion - - fast_float - - fmt - - glog - - hermes-engine - - NitroModules - - RCT-Folly - - RCT-Folly/Fabric - - RCTRequired - - RCTTypeSafety - - React-callinvoker - - React-Core - - React-debug - - React-Fabric - - React-featureflags - - React-graphics - - React-ImageManager - - React-jsi - - React-NativeModulesApple - - React-RCTFabric - - React-renderercss - - React-rendererdebug - - React-utils - - ReactCodegen - - ReactCommon/turbomodule/bridging - - ReactCommon/turbomodule/core - - SocketRocket - - Yoga - - NitroModules (0.35.9): + - NitroModules (0.35.0): - boost - DoubleConversion - fast_float @@ -4339,7 +4309,6 @@ DEPENDENCIES: - GzipSwift - hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`) - lottie-react-native (from `../node_modules/lottie-react-native`) - - NitroFetch (from `../node_modules/react-native-nitro-fetch`) - NitroModules (from `../node_modules/react-native-nitro-modules`) - "onfido-react-native-sdk (from `../node_modules/@onfido/react-native-sdk`)" - "pusher-websocket-react-native (from `../node_modules/@pusher/pusher-websocket-react-native`)" @@ -4568,8 +4537,6 @@ EXTERNAL SOURCES: :tag: hermes-v250829098.0.4 lottie-react-native: :path: "../node_modules/lottie-react-native" - NitroFetch: - :path: "../node_modules/react-native-nitro-fetch" NitroModules: :path: "../node_modules/react-native-nitro-modules" onfido-react-native-sdk: @@ -4823,7 +4790,7 @@ SPEC CHECKSUMS: DoubleConversion: cb417026b2400c8f53ae97020b2be961b59470cb EXConstants: dadbeba983acc30f855a919658a2b34fbd86615d expensify-react-native-background-task: 03c640e1f5649692d058cba48c0a138f024a6dd3 - ExpensifyNitroUtils: b7225649e39a31eab926dc8551c9c64e15b98d47 + ExpensifyNitroUtils: 86109fe1ab88351ed63ffe11b760d537c70019d7 Expo: ab7a622b0c0fb7bc85791632994da7ba67d4293b ExpoAsset: afaa23466e93da462b918bff8d6a9fe15c646dc8 ExpoAudio: 14c5909ec48267bfc514bb44c546fcf6fac93837 @@ -4869,8 +4836,7 @@ SPEC CHECKSUMS: MapboxMaps: f87023cf0d72b180b40ea0b6fb4b2d7db6b73b71 MapboxMobileEvents: d044b9edbe0ec7df60f6c2c9634fe9a7f449266b nanopb: fad817b59e0457d11a5dfbde799381cd727c1275 - NitroFetch: f660637ce0da45a9e5cc0f4a1aefe81c7095aab6 - NitroModules: d2d7b8a417d5f498ef5affa78d82113ad8c35c59 + NitroModules: f8c2cc3025e4550aee15ff77c525622bf98e774a NWWebSocket: b4741420f1976e1dff4da3edad00c401e4f1d769 Onfido: 65454f91d10758193c857fd149417f6efbea84c5 onfido-react-native-sdk: bb8cfd9198e2e97978461d969497d18b37e45ca7 diff --git a/jest/setup.ts b/jest/setup.ts index 72256c7efa57..c4d09ed07c61 100644 --- a/jest/setup.ts +++ b/jest/setup.ts @@ -313,15 +313,6 @@ jest.mock('react-native-nitro-sqlite', () => ({ open: jest.fn(), })); -jest.mock('react-native-nitro-fetch', () => ({ - __esModule: true, - fetch: (...args: Parameters) => globalThis.fetch(...args), - prefetchOnAppStart: jest.fn(() => Promise.resolve()), - registerTokenRefresh: jest.fn(), - clearTokenRefresh: jest.fn(), - removeFromAutoPrefetch: jest.fn(() => Promise.resolve()), -})); - jest.mock('@shopify/react-native-skia', () => ({ useFont: jest.fn(() => null), matchFont: jest.fn(() => null), diff --git a/modules/ExpensifyNitroUtils/nitrogen/generated/android/ExpensifyNitroUtilsOnLoad.cpp b/modules/ExpensifyNitroUtils/nitrogen/generated/android/ExpensifyNitroUtilsOnLoad.cpp index ba0c3e861922..f328c82635bd 100644 --- a/modules/ExpensifyNitroUtils/nitrogen/generated/android/ExpensifyNitroUtilsOnLoad.cpp +++ b/modules/ExpensifyNitroUtils/nitrogen/generated/android/ExpensifyNitroUtilsOnLoad.cpp @@ -28,17 +28,17 @@ int initialize(JavaVM* vm) { } struct JHybridContactsModuleSpecImpl: public jni::JavaClass { - static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/utils/HybridContactsModule;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/utils/HybridContactsModule;"; static std::shared_ptr create() { - static const auto constructorFn = javaClassStatic()->getConstructor(); + static auto constructorFn = javaClassStatic()->getConstructor(); jni::local_ref javaPart = javaClassStatic()->newObject(constructorFn); return javaPart->getJHybridContactsModuleSpec(); } }; struct JHybridAppStartTimeModuleSpecImpl: public jni::JavaClass { - static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/utils/HybridAppStartTimeModule;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/utils/HybridAppStartTimeModule;"; static std::shared_ptr create() { - static const auto constructorFn = javaClassStatic()->getConstructor(); + static auto constructorFn = javaClassStatic()->getConstructor(); jni::local_ref javaPart = javaClassStatic()->newObject(constructorFn); return javaPart->getJHybridAppStartTimeModuleSpec(); } diff --git a/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JContact.hpp b/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JContact.hpp index bcaa90160b67..2dccb42fa544 100644 --- a/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JContact.hpp +++ b/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JContact.hpp @@ -25,7 +25,7 @@ namespace margelo::nitro::utils { */ struct JContact final: public jni::JavaClass { public: - static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/utils/Contact;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/utils/Contact;"; public: /** diff --git a/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JContactFields.hpp b/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JContactFields.hpp index 8252d90ad4ef..1ed3380932ce 100644 --- a/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JContactFields.hpp +++ b/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JContactFields.hpp @@ -19,7 +19,7 @@ namespace margelo::nitro::utils { */ struct JContactFields final: public jni::JavaClass { public: - static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/utils/ContactFields;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/utils/ContactFields;"; public: /** diff --git a/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JHybridAppStartTimeModuleSpec.hpp b/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JHybridAppStartTimeModuleSpec.hpp index 3a332f45b6f8..91fc411edbd0 100644 --- a/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JHybridAppStartTimeModuleSpec.hpp +++ b/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JHybridAppStartTimeModuleSpec.hpp @@ -21,11 +21,11 @@ namespace margelo::nitro::utils { class JHybridAppStartTimeModuleSpec: public virtual HybridAppStartTimeModuleSpec, public virtual JHybridObject { public: struct JavaPart: public jni::JavaClass { - static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/utils/HybridAppStartTimeModuleSpec;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/utils/HybridAppStartTimeModuleSpec;"; std::shared_ptr getJHybridAppStartTimeModuleSpec(); }; struct CxxPart: public jni::HybridClass { - static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/utils/HybridAppStartTimeModuleSpec$CxxPart;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/utils/HybridAppStartTimeModuleSpec$CxxPart;"; static jni::local_ref initHybrid(jni::alias_ref jThis); static void registerNatives(); using HybridBase::HybridBase; diff --git a/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JHybridContactsModuleSpec.hpp b/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JHybridContactsModuleSpec.hpp index 36a9aee8047d..b140e3c9f376 100644 --- a/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JHybridContactsModuleSpec.hpp +++ b/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JHybridContactsModuleSpec.hpp @@ -21,11 +21,11 @@ namespace margelo::nitro::utils { class JHybridContactsModuleSpec: public virtual HybridContactsModuleSpec, public virtual JHybridObject { public: struct JavaPart: public jni::JavaClass { - static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/utils/HybridContactsModuleSpec;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/utils/HybridContactsModuleSpec;"; std::shared_ptr getJHybridContactsModuleSpec(); }; struct CxxPart: public jni::HybridClass { - static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/utils/HybridContactsModuleSpec$CxxPart;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/utils/HybridContactsModuleSpec$CxxPart;"; static jni::local_ref initHybrid(jni::alias_ref jThis); static void registerNatives(); using HybridBase::HybridBase; diff --git a/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JStringHolder.hpp b/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JStringHolder.hpp index a26b81bdbe47..11b563d2b695 100644 --- a/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JStringHolder.hpp +++ b/modules/ExpensifyNitroUtils/nitrogen/generated/android/c++/JStringHolder.hpp @@ -21,7 +21,7 @@ namespace margelo::nitro::utils { */ struct JStringHolder final: public jni::JavaClass { public: - static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/utils/StringHolder;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/utils/StringHolder;"; public: /** diff --git a/modules/ExpensifyNitroUtils/nitrogen/generated/android/kotlin/com/margelo/nitro/utils/Contact.kt b/modules/ExpensifyNitroUtils/nitrogen/generated/android/kotlin/com/margelo/nitro/utils/Contact.kt index 816608d30d71..ca037de30643 100644 --- a/modules/ExpensifyNitroUtils/nitrogen/generated/android/kotlin/com/margelo/nitro/utils/Contact.kt +++ b/modules/ExpensifyNitroUtils/nitrogen/generated/android/kotlin/com/margelo/nitro/utils/Contact.kt @@ -9,7 +9,6 @@ package com.margelo.nitro.utils import androidx.annotation.Keep import com.facebook.proguard.annotations.DoNotStrip -import java.util.Objects /** @@ -36,26 +35,6 @@ data class Contact( ) { /* primary constructor */ - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is Contact) return false - return Objects.deepEquals(this.firstName, other.firstName) - && Objects.deepEquals(this.lastName, other.lastName) - && Objects.deepEquals(this.phoneNumbers, other.phoneNumbers) - && Objects.deepEquals(this.emailAddresses, other.emailAddresses) - && Objects.deepEquals(this.imageData, other.imageData) - } - - override fun hashCode(): Int { - return arrayOf( - firstName, - lastName, - phoneNumbers, - emailAddresses, - imageData - ).contentDeepHashCode() - } - companion object { /** * Constructor called from C++ diff --git a/modules/ExpensifyNitroUtils/nitrogen/generated/android/kotlin/com/margelo/nitro/utils/StringHolder.kt b/modules/ExpensifyNitroUtils/nitrogen/generated/android/kotlin/com/margelo/nitro/utils/StringHolder.kt index abe48e289f4e..accaebee2968 100644 --- a/modules/ExpensifyNitroUtils/nitrogen/generated/android/kotlin/com/margelo/nitro/utils/StringHolder.kt +++ b/modules/ExpensifyNitroUtils/nitrogen/generated/android/kotlin/com/margelo/nitro/utils/StringHolder.kt @@ -9,7 +9,6 @@ package com.margelo.nitro.utils import androidx.annotation.Keep import com.facebook.proguard.annotations.DoNotStrip -import java.util.Objects /** @@ -24,18 +23,6 @@ data class StringHolder( ) { /* primary constructor */ - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is StringHolder) return false - return Objects.deepEquals(this.value, other.value) - } - - override fun hashCode(): Int { - return arrayOf( - value - ).contentDeepHashCode() - } - companion object { /** * Constructor called from C++ diff --git a/modules/ExpensifyNitroUtils/nitrogen/generated/ios/ExpensifyNitroUtils+autolinking.rb b/modules/ExpensifyNitroUtils/nitrogen/generated/ios/ExpensifyNitroUtils+autolinking.rb index c72938ed02d8..78c2c451cd92 100644 --- a/modules/ExpensifyNitroUtils/nitrogen/generated/ios/ExpensifyNitroUtils+autolinking.rb +++ b/modules/ExpensifyNitroUtils/nitrogen/generated/ios/ExpensifyNitroUtils+autolinking.rb @@ -56,7 +56,5 @@ def add_nitrogen_files(spec) "SWIFT_OBJC_INTEROP_MODE" => "objcxx", # Enables stricter modular headers "DEFINES_MODULE" => "YES", - # Disable auto-generated ObjC header for Swift (Static linkage on Xcode 26.4 breaks here) - "SWIFT_INSTALL_OBJC_HEADER" => "NO", }) end diff --git a/package-lock.json b/package-lock.json index b67f8c8e9358..a2702dd151bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -120,8 +120,7 @@ "react-native-keyboard-controller": "1.21.0-beta.1", "react-native-launch-arguments": "^4.1.0", "react-native-localize": "^3.5.4", - "react-native-nitro-fetch": "1.4.3-alpha.1", - "react-native-nitro-modules": "0.35.9", + "react-native-nitro-modules": "0.35.0", "react-native-nitro-sqlite": "9.6.0", "react-native-onyx": "3.0.88", "react-native-pager-view": "8.0.0", @@ -271,7 +270,7 @@ "link": "^2.1.1", "memfs": "^4.6.0", "mini-css-extract-plugin": "^2.9.4", - "nitrogen": "0.35.5", + "nitrogen": "0.35.0", "onchange": "^7.1.0", "openai": "^6.16.0", "oxfmt": "^0.55.0", @@ -34089,14 +34088,14 @@ "license": "MIT" }, "node_modules/nitrogen": { - "version": "0.35.5", - "resolved": "https://registry.npmjs.org/nitrogen/-/nitrogen-0.35.5.tgz", - "integrity": "sha512-Ofl4aTW2rd44+hBcUwLXu01ViHikn2SDI7zOYc+6NcKSpnhoj42k1FwyvRj1QZPDMUT64Bwlb0DYw7Hrfd3BfQ==", + "version": "0.35.0", + "resolved": "https://registry.npmjs.org/nitrogen/-/nitrogen-0.35.0.tgz", + "integrity": "sha512-K8/4h9bCQahi3qEheWZx5joLFsAW3QjK0dVSC3gNLlQhlSJN42UFmffAouOZXYjg9rBDpVlrVo+Hsja45swsJQ==", "dev": true, "license": "MIT", "dependencies": { "chalk": "^5.3.0", - "react-native-nitro-modules": "^0.35.5", + "react-native-nitro-modules": "^0.35.0", "ts-morph": "^27.0.0", "yargs": "^18.0.0", "zod": "^4.0.5" @@ -36483,47 +36482,10 @@ } } }, - "node_modules/react-native-nitro-fetch": { - "version": "1.4.3-alpha.1", - "resolved": "https://registry.npmjs.org/react-native-nitro-fetch/-/react-native-nitro-fetch-1.4.3-alpha.1.tgz", - "integrity": "sha512-MGK/47iQ89wBlKTZzzSa8fjxeXFXxHe8ja2mXAmXbRnA3/4n9NTctWvgoqv/OY/VS+wFHsxHR2h7fLr75m2HpQ==", - "license": "MIT", - "workspaces": [ - "example" - ], - "dependencies": { - "web-streams-polyfill": "^4.2.0" - }, - "peerDependencies": { - "react": "*", - "react-native": "*", - "react-native-nitro-modules": "^0.35.2", - "react-native-worklets": ">=0.8.0" - }, - "peerDependenciesMeta": { - "react-native-worklets": { - "optional": true - } - } - }, - "node_modules/react-native-nitro-fetch/node_modules/web-streams-polyfill": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.3.0.tgz", - "integrity": "sha512-/Gnggvj9oSrEvJbDyyPtAnxBt5fGQM2iWOKQNu7ie1OxDgK40iZpyV3TKaRiEzVj1oA1UxKnEy9XPXh6PW3eVw==", - "license": "MIT", - "workspaces": [ - "test/benchmark-test", - "test/rollup-test", - "test/webpack-test" - ], - "engines": { - "node": ">= 8" - } - }, "node_modules/react-native-nitro-modules": { - "version": "0.35.9", - "resolved": "https://registry.npmjs.org/react-native-nitro-modules/-/react-native-nitro-modules-0.35.9.tgz", - "integrity": "sha512-yCO6eJ85SPPUo4a4an7H5oj6wPCSIT72fbjr5WZ/20n6zswaJ2gNNpnWtg2We0AZwkAOjSqkOJ0Vjc05p6kGiA==", + "version": "0.35.0", + "resolved": "https://registry.npmjs.org/react-native-nitro-modules/-/react-native-nitro-modules-0.35.0.tgz", + "integrity": "sha512-Eho1yEcLbsteGpBFn2XZOp5FIptnEciWzuYBW49S0jo41Un2LeyesIO/MqYLY/c5o7D9Fw9th4pxGtV7OAb0+g==", "license": "MIT", "peerDependencies": { "react": "*", diff --git a/package.json b/package.json index 6b34ad52e662..75c76433a200 100644 --- a/package.json +++ b/package.json @@ -194,8 +194,7 @@ "react-native-keyboard-controller": "1.21.0-beta.1", "react-native-launch-arguments": "^4.1.0", "react-native-localize": "^3.5.4", - "react-native-nitro-fetch": "1.4.3-alpha.1", - "react-native-nitro-modules": "0.35.9", + "react-native-nitro-modules": "0.35.0", "react-native-nitro-sqlite": "9.6.0", "react-native-onyx": "3.0.88", "react-native-pager-view": "8.0.0", @@ -345,7 +344,7 @@ "link": "^2.1.1", "memfs": "^4.6.0", "mini-css-extract-plugin": "^2.9.4", - "nitrogen": "0.35.5", + "nitrogen": "0.35.0", "onchange": "^7.1.0", "openai": "^6.16.0", "oxfmt": "^0.55.0", diff --git a/server/stubs/react-native-nitro-fetch.ts b/server/stubs/react-native-nitro-fetch.ts index 704ff3387e20..6824519e84a0 100644 --- a/server/stubs/react-native-nitro-fetch.ts +++ b/server/stubs/react-native-nitro-fetch.ts @@ -2,10 +2,6 @@ function clearTokenRefresh() {} function prefetchOnAppStart() {} -function registerTokenRefresh() {} - -function removeFromAutoPrefetch() {} - -export {clearTokenRefresh, prefetchOnAppStart, registerTokenRefresh, removeFromAutoPrefetch}; +export {clearTokenRefresh, prefetchOnAppStart}; export default {}; diff --git a/src/CONST/index.ts b/src/CONST/index.ts index 6d1d3d7e0e16..d3c9818f78b0 100644 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -2388,9 +2388,6 @@ const CONST = { GATEWAY_TIMEOUT: 504, UNKNOWN_ERROR: 520, }, - HTTP_HEADER_NAMES: { - AUTH_TOKEN: 'authToken', - }, ERROR: { XHR_FAILED: 'xhrFailed', THROTTLED: 'throttled', diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 7f4da61c9720..b7c7713847ea 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -10,8 +10,6 @@ import type * as Parameters from './parameters'; import type SignInUserParams from './parameters/SignInUserParams'; import type UpdateBeneficialOwnersForBankAccountParams from './parameters/UpdateBeneficialOwnersForBankAccountParams'; -const AUTHENTICATION_COMMAND = 'Authenticate' as const; - type ApiRequestType = ValueOf; const WRITE_COMMANDS = { @@ -1594,7 +1592,7 @@ type SideEffectRequestCommandParameters = { type ApiRequestCommandParameters = WriteCommandParameters & ReadCommandParameters & SideEffectRequestCommandParameters; -export {WRITE_COMMANDS, READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, AUTHENTICATION_COMMAND}; +export {WRITE_COMMANDS, READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS}; type ApiCommand = WriteCommand | ReadCommand | SideEffectRequestCommand; type CommandOfType = TRequestType extends typeof CONST.API_REQUEST_TYPE.WRITE diff --git a/src/libs/HttpUtils.ts b/src/libs/HttpUtils.ts index a1a6ba298c04..6324b4aa130c 100644 --- a/src/libs/HttpUtils.ts +++ b/src/libs/HttpUtils.ts @@ -5,7 +5,6 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {RequestType} from '@src/types/onyx/Request'; import type Response from '@src/types/onyx/Response'; -import type {fetch as nitroFetch} from 'react-native-nitro-fetch'; import type {OnyxKey} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; @@ -17,8 +16,6 @@ import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from './API import {getCommandURL} from './ApiUtils'; import HttpsError from './Errors/HttpsError'; import {setLoadTestParameters} from './Network/LoadTestState'; -import preparePrefetchRequest from './Prefetch/preparePrefetchRequest'; -import registerPrefetchOnAppStart from './Prefetch/registerPrefetchOnAppStart'; import prepareRequestPayload from './prepareRequestPayload'; import markAppStartupNetworkRequestEnd from './telemetry/markAppStartupNetworkRequestEnd'; @@ -81,24 +78,17 @@ function processHTTPRequest( const command = url.match(APICommandRegex)?.[1]; - const {prefetchKey, prefetchHeaders} = preparePrefetchRequest(command); - - const fetchParams: NonNullable[1]> = { + return fetch(url, { // We hook requests to the same Controller signal, so we can cancel them all at once signal: abortSignal, method, body, - headers: prefetchHeaders, // On Web fetch already defaults to 'omit' for credentials, but it seems that this is not the case for the ReactNative implementation // so to avoid sending cookies with the request we set it to 'omit' explicitly // this avoids us sending specially the expensifyWeb cookie, which makes a CSRF token required // more on that here: https://stackoverflowteams.com/c/expensify/questions/93 credentials: 'omit', - }; - - registerPrefetchOnAppStart({prefetchKey, fetchParams, command, url}); - - return fetch(url, fetchParams) + }) .then((response) => { if (response.headers) { setLoadTestParameters(response.headers.get('X-Load-Test')); diff --git a/src/libs/Network/enhanceParameters.ts b/src/libs/Network/enhanceParameters.ts index a6f7de574105..4e397d44d742 100644 --- a/src/libs/Network/enhanceParameters.ts +++ b/src/libs/Network/enhanceParameters.ts @@ -1,4 +1,3 @@ -import {AUTHENTICATION_COMMAND} from '@libs/API/types'; import * as Environment from '@libs/Environment/Environment'; import getPlatform from '@libs/getPlatform'; @@ -51,38 +50,34 @@ Onyx.connectWithoutView({ * Does this command require an authToken? */ function isAuthTokenRequired(command: string): boolean { - return !['Log', AUTHENTICATION_COMMAND, 'BeginSignIn', 'SetPassword'].includes(command); -} - -/** - * Returns request metadata shared by every API call (including Authenticate). - */ -function getBaseRequestParameters(email?: unknown) { - return { - referer: CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER, - platform: getPlatform(), - // This application does not save its authToken in cookies like the classic Expensify app. - // Setting api_setCookie to false will ensure that the Expensify API doesn't set any cookies - // and prevents interfering with the cookie authToken that Expensify classic uses. - // eslint-disable-next-line @typescript-eslint/naming-convention - api_setCookie: false, - // Include current user's email in every request and the server logs - email: email ?? getCurrentUserEmail(), - isFromDevEnv: Environment.isDevelopment(), - appversion: pkg.version, - }; + return !['Log', 'Authenticate', 'BeginSignIn', 'SetPassword'].includes(command); } /** * Adds default values to our request data */ export default function enhanceParameters(command: string, parameters: Record): Record { - const finalParameters: Record = {...parameters, ...getBaseRequestParameters(parameters.email)}; + const finalParameters = {...parameters}; if (isAuthTokenRequired(command) && !parameters.authToken) { finalParameters.authToken = getAuthToken() ?? null; } + finalParameters.referer = CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER; + + // In addition to the referer (ecash), we pass the platform to help differentiate what device type + // is sending the request. + finalParameters.platform = getPlatform(); + + // This application does not save its authToken in cookies like the classic Expensify app. + // Setting api_setCookie to false will ensure that the Expensify API doesn't set any cookies + // and prevents interfering with the cookie authToken that Expensify classic uses. + finalParameters.api_setCookie = false; + + // Include current user's email in every request and the server logs + finalParameters.email = parameters.email ?? getCurrentUserEmail(); + finalParameters.isFromDevEnv = Environment.isDevelopment(); + finalParameters.appversion = pkg.version; finalParameters.clientUpdateID = lastUpdateIDAppliedToClient; if (delegate) { finalParameters.delegate = delegate; @@ -93,5 +88,3 @@ export default function enhanceParameters(command: string, parameters: Record([WRITE_COMMANDS.RECONNECT_APP]); - -export default PrefetchQueries; diff --git a/src/libs/Prefetch/PrefetchQueries/index.ts b/src/libs/Prefetch/PrefetchQueries/index.ts deleted file mode 100644 index da26d587fbc3..000000000000 --- a/src/libs/Prefetch/PrefetchQueries/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Native-only prefetching via `react-native-nitro-fetch` is unavailable on web, so no commands are prefetched. - * Keeping this empty also prevents the `prefetchKey` request header from being added on web, which would otherwise - * trigger a CORS preflight on cross-origin requests. - */ -const PrefetchQueries = new Set(); - -export default PrefetchQueries; diff --git a/src/libs/Prefetch/clearPrefetchOnAppStart/index.ts b/src/libs/Prefetch/clearPrefetchOnAppStart/index.ts deleted file mode 100644 index bf9d53d5c758..000000000000 --- a/src/libs/Prefetch/clearPrefetchOnAppStart/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -import Log from '@libs/Log'; -import PrefetchQueries from '@libs/Prefetch/PrefetchQueries'; - -import {clearTokenRefresh, removeFromAutoPrefetch} from 'react-native-nitro-fetch'; - -import type ClearPrefetchOnAppStart from './types'; - -const clearPrefetchOnAppStart: ClearPrefetchOnAppStart = () => { - clearTokenRefresh('fetch'); - - for (const command of PrefetchQueries) { - removeFromAutoPrefetch(command).catch((error) => { - Log.warn(`[HttpUtils] removeFromAutoPrefetch failed for ${command}`, {error}); - }); - } -}; - -export default clearPrefetchOnAppStart; diff --git a/src/libs/Prefetch/clearPrefetchOnAppStart/index.web.ts b/src/libs/Prefetch/clearPrefetchOnAppStart/index.web.ts deleted file mode 100644 index 15bd103ee1e4..000000000000 --- a/src/libs/Prefetch/clearPrefetchOnAppStart/index.web.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type ClearPrefetchOnAppStart from './types'; - -const clearPrefetchOnAppStart: ClearPrefetchOnAppStart = () => {}; - -export default clearPrefetchOnAppStart; diff --git a/src/libs/Prefetch/clearPrefetchOnAppStart/types.ts b/src/libs/Prefetch/clearPrefetchOnAppStart/types.ts deleted file mode 100644 index 567735ad2adc..000000000000 --- a/src/libs/Prefetch/clearPrefetchOnAppStart/types.ts +++ /dev/null @@ -1,3 +0,0 @@ -type ClearPrefetchOnAppStart = () => void; - -export default ClearPrefetchOnAppStart; diff --git a/src/libs/Prefetch/preparePrefetchRequest/index.ts b/src/libs/Prefetch/preparePrefetchRequest/index.ts deleted file mode 100644 index 4e3f478d938a..000000000000 --- a/src/libs/Prefetch/preparePrefetchRequest/index.ts +++ /dev/null @@ -1,22 +0,0 @@ -import PrefetchQueries from '@libs/Prefetch/PrefetchQueries'; - -import type PreparePrefetchRequest from './types'; - -const preparePrefetchRequest: PreparePrefetchRequest = (command) => { - // Prefetch the request on next app start if the prefetch key is present in the headers - // This allows to fetch the request natively before the JS bundle is loaded. Once the request with this prefetch key is made, it will already be cached and served from the cache. - const prefetchKey = command && PrefetchQueries.has(command) ? command : undefined; - - const prefetchHeaders = prefetchKey - ? { - prefetchKey, - } - : undefined; - - return { - prefetchKey, - prefetchHeaders, - }; -}; - -export default preparePrefetchRequest; diff --git a/src/libs/Prefetch/preparePrefetchRequest/index.web.ts b/src/libs/Prefetch/preparePrefetchRequest/index.web.ts deleted file mode 100644 index 07d3f41f8d63..000000000000 --- a/src/libs/Prefetch/preparePrefetchRequest/index.web.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type PreparePrefetchRequest from './types'; - -const NOOP: PreparePrefetchRequest = () => ({}); - -const preparePrefetchRequest = NOOP; - -export default preparePrefetchRequest; diff --git a/src/libs/Prefetch/preparePrefetchRequest/types.ts b/src/libs/Prefetch/preparePrefetchRequest/types.ts deleted file mode 100644 index fded935a40ca..000000000000 --- a/src/libs/Prefetch/preparePrefetchRequest/types.ts +++ /dev/null @@ -1,8 +0,0 @@ -type PreparePrefetchRequestResult = { - prefetchKey?: string; - prefetchHeaders?: Record; -}; - -type PreparePrefetchRequest = (command: string | undefined) => PreparePrefetchRequestResult; - -export default PreparePrefetchRequest; diff --git a/src/libs/Prefetch/registerPrefetchOnAppStart/index.ts b/src/libs/Prefetch/registerPrefetchOnAppStart/index.ts deleted file mode 100644 index b6b4d1434213..000000000000 --- a/src/libs/Prefetch/registerPrefetchOnAppStart/index.ts +++ /dev/null @@ -1,80 +0,0 @@ -import {AUTHENTICATION_COMMAND} from '@libs/API/types'; -import {getApiRoot} from '@libs/ApiUtils'; -import Log from '@libs/Log'; -import {getBaseRequestParameters} from '@libs/Network/enhanceParameters'; -import {getCredentials} from '@libs/Network/NetworkStore'; -import {getPartnerCredentials} from '@libs/SessionUtils'; - -import CONST from '@src/CONST'; -import type Credentials from '@src/types/onyx/Credentials'; - -import {clearTokenRefresh, prefetchOnAppStart, registerTokenRefresh} from 'react-native-nitro-fetch'; - -import type RegisterPrefetchOnAppStart from './types'; - -const CONTENT_TYPE_HEADER = 'Content-Type'; - -function buildAuthenticateBody(credentials: Credentials): string { - // NitroFetch token refresh runs outside the JS request pipeline, so we must serialize the - // Authenticate body here instead of going through Request.post() and enhanceParameters(). - const {partnerName, partnerPassword} = getPartnerCredentials(credentials.autoGeneratedLogin); - // eslint-disable-next-line @typescript-eslint/naming-convention - const {referer, platform, api_setCookie, isFromDevEnv, appversion} = getBaseRequestParameters(); - - const body = new URLSearchParams(); - body.append('useExpensifyLogin', 'false'); - body.append('partnerName', partnerName); - body.append('partnerPassword', partnerPassword); - body.append('partnerUserID', credentials.autoGeneratedLogin ?? ''); - body.append('partnerUserSecret', credentials.autoGeneratedPassword ?? ''); - body.append('shouldRetry', 'false'); - body.append('forceNetworkRequest', 'true'); - body.append('email', credentials.login ?? ''); - body.append('appversion', appversion); - body.append('referer', referer); - body.append('platform', platform); - body.append('api_setCookie', String(api_setCookie)); - body.append('isFromDevEnv', String(isFromDevEnv)); - - return body.toString(); -} - -function registerPrefetchTokenRefresh(): void { - const credentials = getCredentials(); - - clearTokenRefresh('fetch'); - - if (!credentials?.autoGeneratedLogin || !credentials.autoGeneratedPassword) { - return; - } - - const authenticateURL = `${getApiRoot()}api/${AUTHENTICATION_COMMAND}?`; - - registerTokenRefresh({ - target: 'fetch', - url: authenticateURL, - method: 'POST', - headers: { - [CONTENT_TYPE_HEADER]: 'application/x-www-form-urlencoded', - }, - body: buildAuthenticateBody(credentials), - responseType: 'json', - formDataMappings: [{jsonPath: CONST.HTTP_HEADER_NAMES.AUTH_TOKEN, field: CONST.HTTP_HEADER_NAMES.AUTH_TOKEN}], - onFailure: 'useStoredHeaders', - }); - - Log.info('[NitroFetchTokenRefresh] Registered token refresh for startup prefetch', false); -} - -const registerPrefetchOnAppStart: RegisterPrefetchOnAppStart = ({prefetchKey, fetchParams, command, url}) => { - if (!prefetchKey) { - return; - } - - registerPrefetchTokenRefresh(); - prefetchOnAppStart(url, fetchParams).catch((error) => { - Log.warn(`[HttpUtils] prefetchOnAppStart failed for ${command}`, {error, fetchParams, url}); - }); -}; - -export default registerPrefetchOnAppStart; diff --git a/src/libs/Prefetch/registerPrefetchOnAppStart/index.web.ts b/src/libs/Prefetch/registerPrefetchOnAppStart/index.web.ts deleted file mode 100644 index 273beecee833..000000000000 --- a/src/libs/Prefetch/registerPrefetchOnAppStart/index.web.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type RegisterPrefetchOnAppStart from './types'; - -const NOOP: RegisterPrefetchOnAppStart = () => {}; - -const registerPrefetchOnAppStart: RegisterPrefetchOnAppStart = NOOP; - -export default registerPrefetchOnAppStart; diff --git a/src/libs/Prefetch/registerPrefetchOnAppStart/types.ts b/src/libs/Prefetch/registerPrefetchOnAppStart/types.ts deleted file mode 100644 index 1e503b27115f..000000000000 --- a/src/libs/Prefetch/registerPrefetchOnAppStart/types.ts +++ /dev/null @@ -1,10 +0,0 @@ -type RegisterPrefetchOnAppStartParams = { - prefetchKey: string | undefined; - command: string | undefined; - url: string; - fetchParams: RequestInit; -}; - -type RegisterPrefetchOnAppStart = (params: RegisterPrefetchOnAppStartParams) => void; - -export default RegisterPrefetchOnAppStart; diff --git a/src/libs/Reauthentication.ts b/src/libs/Reauthentication.ts index 25c80aaef9fa..3d0dd96c1b3f 100644 --- a/src/libs/Reauthentication.ts +++ b/src/libs/Reauthentication.ts @@ -1,3 +1,4 @@ +import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Account} from '@src/types/onyx'; @@ -12,14 +13,13 @@ import {isConnectedAsDelegate, restoreDelegateSession} from './actions/Delegate' import clearShortLivedAuthState from './actions/Session/clearShortLivedAuthState'; import updateSessionAuthTokens from './actions/Session/updateSessionAuthTokens'; import redirectToSignIn from './actions/SignInRedirect'; -import {AUTHENTICATION_COMMAND} from './API/types'; import HttpsError from './Errors/HttpsError'; import {getAuthenticateErrorMessage, getErrorMessage} from './ErrorUtils'; import Log from './Log'; import {post} from './Network'; import {getCredentials, hasReadRequiredDataFromStorage, setAuthToken, setIsAuthenticating} from './Network/NetworkStore'; import requireParameters from './requireParameters'; -import {checkIfShouldUseNewPartnerName, getPartnerCredentials} from './SessionUtils'; +import {checkIfShouldUseNewPartnerName} from './SessionUtils'; import trackAuthenticationError from './telemetry/trackAuthenticationError'; type Parameters = { @@ -69,7 +69,7 @@ Onyx.connectWithoutView({ }); function Authenticate(parameters: Parameters): Promise | void> { - const commandName = AUTHENTICATION_COMMAND; + const commandName = 'Authenticate'; try { requireParameters(['partnerName', 'partnerPassword', 'partnerUserID', 'partnerUserSecret'], parameters, commandName); @@ -78,7 +78,7 @@ function Authenticate(parameters: Parameters): Promise { return hasReadRequiredDataFromStorage().then(() => { const credentials = getCredentials(); - const {partnerName, partnerPassword} = getPartnerCredentials(credentials?.autoGeneratedLogin); + const shouldUseNewPartnerName = checkIfShouldUseNewPartnerName(credentials?.autoGeneratedLogin); + + const partnerName = shouldUseNewPartnerName ? CONFIG.EXPENSIFY.PARTNER_NAME : CONFIG.EXPENSIFY.LEGACY_PARTNER_NAME; + const partnerPassword = shouldUseNewPartnerName ? CONFIG.EXPENSIFY.PARTNER_PASSWORD : CONFIG.EXPENSIFY.LEGACY_PARTNER_PASSWORD; if (account?.isSAMLRequired) { Log.info(`[Reauthenticate] Redirecting to Sign In because SAML is required`); @@ -187,7 +190,7 @@ function reauthenticate(command = ''): Promise { return false; } - Log.info(`[Reauthenticate] Re-authenticating with ${checkIfShouldUseNewPartnerName(credentials?.autoGeneratedLogin) ? 'new' : 'old'} partner name`); + Log.info(`[Reauthenticate] Re-authenticating with ${shouldUseNewPartnerName ? 'new' : 'old'} partner name`); Log.hmmm('[Reauthenticate] Starting authentication process', { command, diff --git a/src/libs/Request.ts b/src/libs/Request.ts index bff8f9c5c837..892da8aad0b0 100644 --- a/src/libs/Request.ts +++ b/src/libs/Request.ts @@ -19,11 +19,7 @@ function makeXHR(request: Request): Promise(request: Request, isFromSequentialQueue = false): Promise | void> { - let result = makeXHR(request); - for (const middleware of middlewares) { - result = middleware(result, request, isFromSequentialQueue); - } - return result; + return middlewares.reduce((last, middleware) => middleware(last, request, isFromSequentialQueue), makeXHR(request)); } function addMiddleware(middleware: Middleware) { diff --git a/src/libs/SessionUtils.ts b/src/libs/SessionUtils.ts index 8f362ab48aed..4700bae5228b 100644 --- a/src/libs/SessionUtils.ts +++ b/src/libs/SessionUtils.ts @@ -110,15 +110,6 @@ function checkIfShouldUseNewPartnerName(partnerUserID?: string): boolean { return false; } -function getPartnerCredentials(autoGeneratedLogin?: string) { - const useNewPartnerName = checkIfShouldUseNewPartnerName(autoGeneratedLogin); - - return { - partnerName: useNewPartnerName ? CONFIG.EXPENSIFY.PARTNER_NAME : CONFIG.EXPENSIFY.LEGACY_PARTNER_NAME, - partnerPassword: useNewPartnerName ? CONFIG.EXPENSIFY.PARTNER_PASSWORD : CONFIG.EXPENSIFY.LEGACY_PARTNER_PASSWORD, - }; -} - const AGENT_EMAIL_REGEX = /^agent_\d+@expensify\.ai$/i; function isAgentEmail(email?: string): boolean { @@ -133,13 +124,4 @@ function useIsAgentAccount(): boolean { return isAgentEmail(sessionEmail); } -export { - isLoggingInAsNewUser, - didUserLogInDuringSession, - resetDidUserLogInDuringSession, - checkIfShouldUseNewPartnerName, - getPartnerCredentials, - isLoggingInAsDelegate, - isAgentEmail, - useIsAgentAccount, -}; +export {isLoggingInAsNewUser, didUserLogInDuringSession, resetDidUserLogInDuringSession, checkIfShouldUseNewPartnerName, isLoggingInAsDelegate, isAgentEmail, useIsAgentAccount}; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 9e681e294926..4d7b4862c9f3 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -33,12 +33,11 @@ import * as MainQueue from '@libs/Network/MainQueue'; import * as NetworkStore from '@libs/Network/NetworkStore'; import {getCurrentUserEmail} from '@libs/Network/NetworkStore'; import * as SequentialQueue from '@libs/Network/SequentialQueue'; -import clearPrefetchOnAppStart from '@libs/Prefetch/clearPrefetchOnAppStart'; import Pusher from '@libs/Pusher'; import reauthenticate from '@libs/Reauthentication'; import {getReportIDFromLink} from '@libs/ReportUtils'; import * as SessionUtils from '@libs/SessionUtils'; -import {getPartnerCredentials, resetDidUserLogInDuringSession} from '@libs/SessionUtils'; +import {checkIfShouldUseNewPartnerName, resetDidUserLogInDuringSession} from '@libs/SessionUtils'; import {clearSoundAssetsCache} from '@libs/Sound'; import Timers from '@libs/Timers'; @@ -255,18 +254,14 @@ function signInWithSupportAuthToken(authToken: string) { */ function signOut(params: {autoGeneratedLogin?: string; signedInWithSAML?: boolean; authToken?: string} = {}): Promise> { Log.info('Flushing logs before signing out', true, {}, true); - const {partnerName, partnerPassword} = getPartnerCredentials(params.autoGeneratedLogin); - - // When the user signs out, clear native startup prefetch state so the next cold start cannot replay - // a queued ReconnectApp request built with the previous session's auth token. - clearPrefetchOnAppStart(); + const shouldUseNewPartnerName = checkIfShouldUseNewPartnerName(params.autoGeneratedLogin); const logOutParams: LogOutParams = { // Send current authToken because we will immediately clear it once triggering this command authToken: params.authToken ?? null, partnerUserID: params.autoGeneratedLogin ?? '', - partnerName, - partnerPassword, + partnerName: shouldUseNewPartnerName ? CONFIG.EXPENSIFY.PARTNER_NAME : CONFIG.EXPENSIFY.LEGACY_PARTNER_NAME, + partnerPassword: shouldUseNewPartnerName ? CONFIG.EXPENSIFY.PARTNER_PASSWORD : CONFIG.EXPENSIFY.LEGACY_PARTNER_PASSWORD, shouldRetry: false, skipReauthentication: true, }; diff --git a/src/libs/telemetry/trackAuthenticationError.ts b/src/libs/telemetry/trackAuthenticationError.ts index 0ec4a1da8ee5..ec3e09ff1c24 100644 --- a/src/libs/telemetry/trackAuthenticationError.ts +++ b/src/libs/telemetry/trackAuthenticationError.ts @@ -1,10 +1,8 @@ -import type {AUTHENTICATION_COMMAND} from '@libs/API/types'; - import CONST from '@src/CONST'; import * as Sentry from '@sentry/react-native'; -type AuthenticationFunction = typeof AUTHENTICATION_COMMAND | 'reauthenticate'; +type AuthenticationFunction = 'Authenticate' | 'reauthenticate'; type AuthenticationErrorType = 'missing_params' | 'network_retry' | 'auth_failure' | 'unexpected_error'; type AuthenticationErrorContext = { diff --git a/src/polyfills/NitroFetch.ts b/src/polyfills/NitroFetch.ts deleted file mode 100644 index 62c3c4c30f3a..000000000000 --- a/src/polyfills/NitroFetch.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Use Nitro's fetch implementation for every bare `fetch(...)` on native. - * On web, NitroFetch still uses the vanilla global fetch implementation. - */ -import {fetch as nitroFetch, Headers as NitroHeaders, Request as NitroRequest, Response as NitroResponse} from 'react-native-nitro-fetch'; - -globalThis.fetch = nitroFetch; -globalThis.Headers = NitroHeaders; -globalThis.Request = NitroRequest; -globalThis.Response = NitroResponse; diff --git a/src/polyfills/NitroFetch.web.ts b/src/polyfills/NitroFetch.web.ts deleted file mode 100644 index de04469c65ee..000000000000 --- a/src/polyfills/NitroFetch.web.ts +++ /dev/null @@ -1 +0,0 @@ -// On web, we don't use NitroFetch, so no polyfill needed diff --git a/src/types/onyx/Session.ts b/src/types/onyx/Session.ts index 5b687b7d2b08..93b310b50a9c 100644 --- a/src/types/onyx/Session.ts +++ b/src/types/onyx/Session.ts @@ -13,7 +13,7 @@ type Session = { email?: string; /** Currently logged in user authToken */ - [CONST.HTTP_HEADER_NAMES.AUTH_TOKEN]?: string; + authToken?: string; /** Currently logged in user authToken type */ authTokenType?: ValueOf; diff --git a/tests/actions/SessionTest.ts b/tests/actions/SessionTest.ts index 9ca3447bbd9b..984a2ba9c7a2 100644 --- a/tests/actions/SessionTest.ts +++ b/tests/actions/SessionTest.ts @@ -29,7 +29,6 @@ import type {Credentials, Session} from '@src/types/onyx'; import type {OnyxEntry} from 'react-native-onyx'; import {openAuthSessionAsync} from 'expo-web-browser'; -import {clearTokenRefresh, removeFromAutoPrefetch} from 'react-native-nitro-fetch'; import Onyx from 'react-native-onyx'; import * as TestHelper from '../utils/TestHelper'; @@ -336,20 +335,6 @@ describe('Session', () => { expect(getAllPersistedRequests().length).toBe(0); }); - test('SignOut should clear native startup prefetch state', async () => { - await TestHelper.signInWithTestUser(); - setHasRadio(false); - await waitForBatchedUpdates(); - - await SessionUtil.signOut({authToken: 'testAuthToken'}); - - expect(clearTokenRefresh).toHaveBeenCalledWith('fetch'); - expect(removeFromAutoPrefetch).toHaveBeenCalledWith(WRITE_COMMANDS.RECONNECT_APP); - - setHasRadio(true); - await waitForBatchedUpdates(); - }); - describe('SignOutAndRedirectToSignIn', () => { test('SignOutAndRedirectToSignIn should redirect to OldDot when LogOut returns truthy hasOldDotAuthCookies', async () => { await TestHelper.signInWithTestUser(); diff --git a/tests/unit/APITest.ts b/tests/unit/APITest.ts index 5dc409c09d07..52a2215f194c 100644 --- a/tests/unit/APITest.ts +++ b/tests/unit/APITest.ts @@ -1,6 +1,5 @@ import {initReconnect} from '@libs/actions/Reconnect'; import type {EnablePolicyFeatureCommand} from '@libs/actions/RequestConflictUtils'; -import {AUTHENTICATION_COMMAND} from '@libs/API/types'; import type {ApiRequestCommandParameters, ReadCommand, WriteCommand} from '@libs/API/types'; import CONST from '@src/CONST'; @@ -341,7 +340,7 @@ describe('APITests', () => { const [commandName2] = call2; const [commandName3] = call3; expect(commandName1).toBe('Mock'); - expect(commandName2).toBe(AUTHENTICATION_COMMAND); + expect(commandName2).toBe('Authenticate'); expect(commandName3).toBe('Mock'); }) ); @@ -492,7 +491,7 @@ describe('APITests', () => { // Third command should be the call to Authenticate const [thirdCommand] = xhr.mock.calls.at(2) ?? []; - expect(thirdCommand).toBe(AUTHENTICATION_COMMAND); + expect(thirdCommand).toBe('Authenticate'); const [fourthCommand] = xhr.mock.calls.at(3) ?? []; expect(fourthCommand).toBe('MockCommand'); diff --git a/tests/unit/NetworkTest.tsx b/tests/unit/NetworkTest.tsx index 38762c2ffeb9..0a779dfef6e4 100644 --- a/tests/unit/NetworkTest.tsx +++ b/tests/unit/NetworkTest.tsx @@ -1,6 +1,5 @@ import {reconnectApp} from '@libs/actions/App'; import * as Reconnect from '@libs/actions/Reconnect'; -import {AUTHENTICATION_COMMAND} from '@libs/API/types'; import {reset as resetFailureTracker} from '@libs/FailureTracker'; import {resetReauthentication} from '@libs/Middleware/Reauthentication'; @@ -120,7 +119,7 @@ describe('NetworkTests', () => { // Verify: // 1. We attempted to authenticate twice (first failed, retry succeeded) // 2. The session has the new auth token (user wasn't logged out) - const callsToAuthenticate = (HttpUtils.xhr as jest.Mock).mock.calls.filter(([command]) => command === AUTHENTICATION_COMMAND); + const callsToAuthenticate = (HttpUtils.xhr as jest.Mock).mock.calls.filter(([command]) => command === 'Authenticate'); expect(callsToAuthenticate.length).toBe(2); expect(sessionState?.authToken).toBe(NEW_AUTH_TOKEN); }); @@ -183,7 +182,7 @@ describe('NetworkTests', () => { // 5. Authentication Start - Verify authenticate was triggered await waitForBatchedUpdates(); const secondCall = mockedXhr.mock.calls.at(1) as [string, Record]; - expect(secondCall[0]).toBe(AUTHENTICATION_COMMAND); + expect(secondCall[0]).toBe('Authenticate'); // 6. Network State Change - Set offline and back online while authenticate is pending setHasRadio(false); @@ -248,7 +247,7 @@ describe('NetworkTests', () => { .then(() => { // Verify: 3 calls to the API, 1 authenticate call, and reconnect was triggered const callsToOpenPublicProfilePage = (HttpUtils.xhr as jest.Mock).mock.calls.filter(([command]) => command === 'OpenPublicProfilePage'); - const callsToAuthenticate = (HttpUtils.xhr as jest.Mock).mock.calls.filter(([command]) => command === AUTHENTICATION_COMMAND); + const callsToAuthenticate = (HttpUtils.xhr as jest.Mock).mock.calls.filter(([command]) => command === 'Authenticate'); expect(callsToOpenPublicProfilePage.length).toBe(3); expect(callsToAuthenticate.length).toBe(1); expect(reconnectSpy).toHaveBeenCalled(); diff --git a/tests/unit/SessionUtilsTest.ts b/tests/unit/SessionUtilsTest.ts index c1d71e5bcbe8..3dae53dbebf4 100644 --- a/tests/unit/SessionUtilsTest.ts +++ b/tests/unit/SessionUtilsTest.ts @@ -1,4 +1,4 @@ -import {checkIfShouldUseNewPartnerName, getPartnerCredentials, isAgentEmail, isLoggingInAsDelegate} from '@src/libs/SessionUtils'; +import {checkIfShouldUseNewPartnerName, isAgentEmail, isLoggingInAsDelegate} from '@src/libs/SessionUtils'; function mockHybridAppConfig(isHybridApp: boolean): () => void { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment @@ -69,30 +69,6 @@ describe('SessionUtils', () => { }); }); - describe('getPartnerCredentials', () => { - test.each([ - ['should return new partner credentials when not in HybridApp', false, 'any-user-id'], - ['should return new partner credentials for expensify.cash- prefix when in HybridApp', true, 'expensify.cash-12345'], - ['should return legacy partner credentials for legacy partnerUserID when in HybridApp', true, 'legacy-user-12345'], - ])('%s', (_description, isHybridApp, partnerUserID) => { - const cleanup = mockHybridAppConfig(isHybridApp); - - try { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const CONFIG = require('@src/CONFIG'); - const useNewPartnerName = checkIfShouldUseNewPartnerName(partnerUserID); - const {partnerName, partnerPassword} = getPartnerCredentials(partnerUserID); - - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - expect(partnerName).toBe(useNewPartnerName ? CONFIG.default.EXPENSIFY.PARTNER_NAME : CONFIG.default.EXPENSIFY.LEGACY_PARTNER_NAME); - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - expect(partnerPassword).toBe(useNewPartnerName ? CONFIG.default.EXPENSIFY.PARTNER_PASSWORD : CONFIG.default.EXPENSIFY.LEGACY_PARTNER_PASSWORD); - } finally { - cleanup(); - } - }); - }); - describe('isLoggingInAsDelegate', () => { test.each([ ['should return false when transitionURL is undefined', undefined, false],