From 298067ab65d526bcf35aa62a3426515078ea07e3 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Tue, 15 Jun 2021 18:40:35 -0400 Subject: [PATCH] Update react-native-cookies & react-native-webview + always use defaultDataStore (#5452) Co-authored-by: Mattermod --- app/init/global_event_handler.js | 2 +- app/screens/sso/sso_with_webview.tsx | 15 +++---------- app/utils/security.js | 2 +- ios/Podfile.lock | 16 +++++++------- package-lock.json | 28 +++++++++++++----------- package.json | 4 ++-- patches/react-native-webview+7.0.1.patch | 13 ----------- test/setup.js | 2 +- 8 files changed, 31 insertions(+), 51 deletions(-) delete mode 100644 patches/react-native-webview+7.0.1.patch diff --git a/app/init/global_event_handler.js b/app/init/global_event_handler.js index 30d3b478c..d8e9b30b8 100644 --- a/app/init/global_event_handler.js +++ b/app/init/global_event_handler.js @@ -3,7 +3,7 @@ import {AppState, Dimensions, Linking, Platform} from 'react-native'; import AsyncStorage from '@react-native-community/async-storage'; -import CookieManager from 'react-native-cookies'; +import CookieManager from '@react-native-cookies/cookies'; import DeviceInfo from 'react-native-device-info'; import {getLocales} from 'react-native-localize'; import RNFetchBlob from 'rn-fetch-blob'; diff --git a/app/screens/sso/sso_with_webview.tsx b/app/screens/sso/sso_with_webview.tsx index 0b8e5b702..76226e974 100644 --- a/app/screens/sso/sso_with_webview.tsx +++ b/app/screens/sso/sso_with_webview.tsx @@ -1,10 +1,10 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +import CookieManager, {Cookies} from '@react-native-cookies/cookies'; import React from 'react'; import {intlShape} from 'react-intl'; import {Alert, Text, View} from 'react-native'; -import CookieManager from 'react-native-cookies'; import {SafeAreaView} from 'react-native-safe-area-context'; import {WebView} from 'react-native-webview'; import {WebViewErrorEvent, WebViewMessageEvent, WebViewNavigation, WebViewNavigationEvent} from 'react-native-webview/lib/WebViewTypes'; @@ -67,15 +67,6 @@ interface SSOWithWebViewProps { theme: Theme } -type CookieResponseType = { - MMAUTHTOKEN: string | { - value: string - }; - MMCSRF: string | { - value: string - }; -} - function SSOWithWebView({completeUrlPath, intl, loginError, loginUrl, onCSRFToken, onMMToken, serverUrl, ssoType, theme}: SSOWithWebViewProps) { const style = getStyleSheet(theme); @@ -105,7 +96,7 @@ function SSOWithWebView({completeUrlPath, intl, loginError, loginUrl, onCSRFToke const url = `${parsedUrl.origin}${parsedUrl.pathname}`; Client4.setUrl(url); - CookieManager.get(url, true).then((res: CookieResponseType) => { + CookieManager.get(url, true).then((res: Cookies) => { const mmtoken = res.MMAUTHTOKEN; const csrf = res.MMCSRF; const token = typeof mmtoken === 'object' ? mmtoken.value : mmtoken; @@ -200,7 +191,7 @@ function SSOWithWebView({completeUrlPath, intl, loginError, loginUrl, onCSRFToke return ( { diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 14badc6e2..d1d23d84c 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -236,8 +236,8 @@ PODS: - React-jsinspector (0.64.1) - react-native-cameraroll (4.0.4): - React-Core - - react-native-cookies (3.2.0): - - React + - react-native-cookies (6.0.7): + - React-Core - react-native-document-picker (5.0.3): - React-Core - react-native-hw-keyboard-event (0.0.4): @@ -266,8 +266,8 @@ PODS: - react-native-video/Video (= 5.1.1) - react-native-video/Video (5.1.1): - React-Core - - react-native-webview (7.0.1): - - React + - react-native-webview (11.6.2): + - React-Core - React-perflogger (0.64.1) - React-RCTActionSheet (0.64.1): - React-Core/RCTActionSheetHeaders (= 0.64.1) @@ -461,7 +461,7 @@ DEPENDENCIES: - React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`) - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`) - "react-native-cameraroll (from `../node_modules/@react-native-community/cameraroll`)" - - react-native-cookies (from `../node_modules/react-native-cookies/ios`) + - "react-native-cookies (from `../node_modules/@react-native-cookies/cookies`)" - react-native-document-picker (from `../node_modules/react-native-document-picker`) - react-native-hw-keyboard-event (from `../node_modules/react-native-hw-keyboard-event`) - react-native-image-picker (from `../node_modules/react-native-image-picker`) @@ -580,7 +580,7 @@ EXTERNAL SOURCES: react-native-cameraroll: :path: "../node_modules/@react-native-community/cameraroll" react-native-cookies: - :path: "../node_modules/react-native-cookies/ios" + :path: "../node_modules/@react-native-cookies/cookies" react-native-document-picker: :path: "../node_modules/react-native-document-picker" react-native-hw-keyboard-event: @@ -710,7 +710,7 @@ SPEC CHECKSUMS: React-jsiexecutor: 124e8f99992490d0d13e0649d950d3e1aae06fe9 React-jsinspector: 500a59626037be5b3b3d89c5151bc3baa9abf1a9 react-native-cameraroll: 7c6c7ca84844f93b3dac9a87670bbad6541684ec - react-native-cookies: 854d59c4135c70b92a02ca4930e68e4e2eb58150 + react-native-cookies: 6004d512ffc6f2c498c5b70cda0bc040350c0585 react-native-document-picker: d2b8fa4d9b268a316515b1f631236f7a87813df6 react-native-hw-keyboard-event: b517cefb8d5c659a38049c582de85ff43337dc53 react-native-image-picker: 32d1ad2c0024ca36161ae0d5c2117e2d6c441f11 @@ -723,7 +723,7 @@ SPEC CHECKSUMS: react-native-safe-area-context: e471852c5ed67eea4b10c5d9d43c1cebae3b231d react-native-startup-time: c4c433fcf7ccac3c622f5d522e4ef18fb3bb0c9c react-native-video: 1574074179ecaf6a9dd067116c8f31bf9fec15c8 - react-native-webview: 0d1c2b4e7ffb0543a74fa0512f2f8dc5fb0e49e2 + react-native-webview: 1f56115845c98f0a59dfbbac685797c014a821be React-perflogger: aad6d4b4a267936b3667260d1f649b6f6069a675 React-RCTActionSheet: fc376be462c9c8d6ad82c0905442fd77f82a9d2a React-RCTAnimation: ba0a1c3a2738be224a08092fa7f1b444ab77d309 diff --git a/package-lock.json b/package-lock.json index e099279d9..af1cfb8d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3126,6 +3126,14 @@ "resolved": "https://registry.npmjs.org/@react-native-community/netinfo/-/netinfo-6.0.0.tgz", "integrity": "sha512-Z9M8VGcF2IZVOo2x+oUStvpCW/8HjIRi4+iQCu5n+PhC7OqCQX58KYAzdBr///alIfRXiu6oMb+lK+rXQH1FvQ==" }, + "@react-native-cookies/cookies": { + "version": "6.0.7", + "resolved": "https://registry.npmjs.org/@react-native-cookies/cookies/-/cookies-6.0.7.tgz", + "integrity": "sha512-XKhSAexFfSJJSON9JQqiA23LsZbFWS0If29AxeQSVpzrlnUJoTq/Feenf9e8piMT9Q4VhkDVrLw+AKhDRsbsPQ==", + "requires": { + "invariant": "^2.2.4" + } + }, "@react-native/assets": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@react-native/assets/-/assets-1.0.0.tgz", @@ -21322,13 +21330,6 @@ "nullthrows": "^1.1.1" } }, - "react-native-cookies": { - "version": "github:mattermost/react-native-cookies#b35bafc388ae09c83bd875e887daf6a0755e0b40", - "from": "github:mattermost/react-native-cookies#b35bafc388ae09c83bd875e887daf6a0755e0b40", - "requires": { - "invariant": "^2.1.0" - } - }, "react-native-dev-menu": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/react-native-dev-menu/-/react-native-dev-menu-4.0.2.tgz", @@ -21929,17 +21930,18 @@ } }, "react-native-webview": { - "version": "github:mattermost/react-native-webview#b5e22940a613869d3999feac9451ee65352f4fbe", - "from": "github:mattermost/react-native-webview#b5e22940a613869d3999feac9451ee65352f4fbe", + "version": "11.6.2", + "resolved": "https://registry.npmjs.org/react-native-webview/-/react-native-webview-11.6.2.tgz", + "integrity": "sha512-7e5ltLBgqt1mX0gdTTS2nFPIjfS6y300wqJ4rLWqU71lDO+8ZeayfsF5qo83qxo2Go74CtLnSeWae4pdGwUqYw==", "requires": { - "escape-string-regexp": "1.0.5", + "escape-string-regexp": "2.0.0", "invariant": "2.2.4" }, "dependencies": { "escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", + "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==" } } }, diff --git a/package.json b/package.json index e8b4cf6b2..e56aa9c32 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "private": true, "dependencies": { "@babel/runtime": "7.14.0", + "@react-native-cookies/cookies": "6.0.7", "@react-native-community/async-storage": "1.12.1", "@react-native-community/cameraroll": "4.0.4", "@react-native-community/clipboard": "1.5.1", @@ -37,7 +38,6 @@ "react-native-animatable": "1.3.3", "react-native-button": "3.0.1", "react-native-calendars": "1.1260.0", - "react-native-cookies": "github:mattermost/react-native-cookies#b35bafc388ae09c83bd875e887daf6a0755e0b40", "react-native-device-info": "8.1.3", "react-native-document-picker": "5.0.3", "react-native-elements": "3.4.1", @@ -71,7 +71,7 @@ "react-native-svg": "12.1.1", "react-native-vector-icons": "8.1.0", "react-native-video": "5.1.1", - "react-native-webview": "github:mattermost/react-native-webview#b5e22940a613869d3999feac9451ee65352f4fbe", + "react-native-webview": "11.6.2", "react-native-youtube": "2.0.1", "react-redux": "7.2.4", "redux": "4.1.0", diff --git a/patches/react-native-webview+7.0.1.patch b/patches/react-native-webview+7.0.1.patch deleted file mode 100644 index 3771655bf..000000000 --- a/patches/react-native-webview+7.0.1.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/node_modules/react-native-webview/android/build.gradle b/node_modules/react-native-webview/android/build.gradle -index a30ab0a..2d02677 100644 ---- a/node_modules/react-native-webview/android/build.gradle -+++ b/node_modules/react-native-webview/android/build.gradle -@@ -29,7 +29,7 @@ android { - compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') - buildToolsVersion getExtOrDefault('buildToolsVersion') - defaultConfig { -- minSdkVersion 16 -+ minSdkVersion rootProject.hasProperty('minSdkVersion') ? rootProject.minSdkVersion : 16 - targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') - versionCode 1 - versionName "1.0" diff --git a/test/setup.js b/test/setup.js index 98f173509..e5229df7b 100644 --- a/test/setup.js +++ b/test/setup.js @@ -191,7 +191,7 @@ jest.mock('react-native-localize', () => ({ ]), })); -jest.mock('react-native-cookies', () => ({ +jest.mock('@react-native-cookies/cookies', () => ({ addEventListener: jest.fn(), removeEventListener: jest.fn(), openURL: jest.fn(),