From 93efc09192b007ba0d3095112c081dcdc0bd7247 Mon Sep 17 00:00:00 2001 From: Regan Langford Date: Thu, 16 Aug 2018 10:15:20 +1200 Subject: [PATCH 1/2] EDIT replace lodash with lodash.result, add no cache params to fectch and make country optional an optional param in iOS --- package.json | 2 +- src/fetcher.js | 7 ++++++- src/versionChecker.ios.js | 7 ++++--- yarn.lock | 6 +++--- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 88858d6..acde6cd 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "react-native": "*" }, "dependencies": { - "lodash": "^4.17.4" + "lodash.result": "^4.5.2" }, "bugs": { "url": "https://github.com/master-atul/react-native-appstore-version-checker/issues" diff --git a/src/fetcher.js b/src/fetcher.js index 1e88b0d..b577123 100644 --- a/src/fetcher.js +++ b/src/fetcher.js @@ -12,7 +12,12 @@ export const get = (url) => { const config = { method: 'GET', credentials: 'include', - mode: 'no-cors' + mode: 'no-cors', + headers: { + 'Cache-Control': 'no-cache, no-store, must-revalidate', + 'Pragma': 'no-cache', + 'Expires': 0 + } }; return fetch(url, config).then((response) => { if (response.status === 200) { diff --git a/src/versionChecker.ios.js b/src/versionChecker.ios.js index f04c6a3..aa14e7c 100644 --- a/src/versionChecker.ios.js +++ b/src/versionChecker.ios.js @@ -1,10 +1,11 @@ -import result from 'lodash/result'; +import _result from 'lodash.result'; import {get, parseJson} from './fetcher'; const getAppstoreAppVersion = (identifier, options = { typeOfId: 'id', country: 'us' }) => { - const url = `https://itunes.apple.com/lookup?${options.typeOfId}=${identifier}&country=${options.country}`; + const country = options.country ? `&country=${options.country}` : ''; + const url = `https://itunes.apple.com/lookup?${options.typeOfId}=${identifier}${country}`; return get(url).then(parseJson).then((d) => { - const version = result(d, 'data.results[0].version'); + const version = _result(d, 'data.results[0].version'); if (!version) { throw new Error('App not found!'); } diff --git a/yarn.lock b/yarn.lock index 3552a40..6569198 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,6 @@ # yarn lockfile v1 -lodash@^4.17.4: - version "4.17.4" - resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" +lodash.result@^4.5.2: + version "4.5.2" + resolved "https://registry.yarnpkg.com/lodash.result/-/lodash.result-4.5.2.tgz#cb45b27fb914eaa8d8ee6f0ce7b2870b87cb70aa" \ No newline at end of file From e3ead00e101d17995a368bb0231ad3ef30e7cc58 Mon Sep 17 00:00:00 2001 From: Regan Langford Date: Thu, 16 Aug 2018 10:26:30 +1200 Subject: [PATCH 2/2] EDIT remove default country from options --- src/versionChecker.ios.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/versionChecker.ios.js b/src/versionChecker.ios.js index aa14e7c..c83efbb 100644 --- a/src/versionChecker.ios.js +++ b/src/versionChecker.ios.js @@ -1,7 +1,7 @@ import _result from 'lodash.result'; import {get, parseJson} from './fetcher'; -const getAppstoreAppVersion = (identifier, options = { typeOfId: 'id', country: 'us' }) => { +const getAppstoreAppVersion = (identifier, options = { typeOfId: 'id' }) => { const country = options.country ? `&country=${options.country}` : ''; const url = `https://itunes.apple.com/lookup?${options.typeOfId}=${identifier}${country}`; return get(url).then(parseJson).then((d) => {