Giter Site home page Giter Site logo

watanabeyu / react-native-store-version Goto Github PK

View Code? Open in Web Editor NEW
126.0 4.0 21.0 1.32 MB

This module check an app's version on google playstore or ios app store.

License: MIT License

JavaScript 22.92% TypeScript 77.08%
react-native expo version appstore playstore

react-native-store-version's Introduction

react-native-store-version

This module check an app's version on google playstore or ios app store.
By writing code successfully, you can make a forced update.

I've only been updating occasionally, but I'd be happy to sponsor you to keep me motivated. https://github.com/sponsors/watanabeyu

Installation

$ npm install --save react-native-store-version

CHANGELOG

v1.4.0

v1.3.0

  • if failed, throw an error.
  • add result detail.

Usage

import checkVersion from 'react-native-store-version';

export default function App() {
  useEffect(() => {
    const init = async () => {
      try {
        const check = await checkVersion({
          version: '1.0.0', // app local version
          iosStoreURL: 'ios app store url',
          androidStoreURL: 'android app store url',
          country: 'jp', // default value is 'jp'
        });

        if (check.result === 'new') {
          // if app store version is new
        }
      } catch (e) {
        console.log(e);
      }
    };

    init();
  }, []);
}

Return value

// correct
{
  local: "1.0.0",
  remote: "1.1.0",
  result: "new", // "new" | "old" | "equal"
  detail: "remote > local", // "remote > local" | "remote < local" | "remote === local"
}

// catch error
{
  message: "string",
}

result compare from a local to remote.
If local(1.0.0) and remote(1.1.0), result is new.

Example

Check out example on snack

react-native-store-version's People

Contributors

dependabot[bot] avatar magrinj avatar tsuk29 avatar watanabeyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-native-store-version's Issues

Can you explain results what does new old equal mean

Can you explain that results are. It may be worth updating the docs

New means there is a new version available on the remote side
Old means that the version installed is old and out of date (if correct there would serve like new right)
Equal means that the local and remote version are the same

Is this correct

Delay in recognising new ios version

I release a new version to the app store, it takes about an hour or so to actually appear in the app store (and on the page linked to by iosStoreURL), that's normal and Apple's fault - but even when it does eventually appear in the app store, this package is still not picking up that new version for some time afterwards (best guess is a few additional hours. I'll try to narrow that down).

This is impacting our ability to rely on this package for informing iOS users about an upgrade. On Android it works immediately.

Version Comparison Issue?

Hello again. :)

I was just testing a new version of an app on my iOS simulator and discovered a bug with the version checks.

{ error: false, local: '1.1.0', remote: '1.0.3', result: 'new' }

My local version is '1.1.0', but the App Store version is '1.0.3'. The result is 'new' so my code is prompting me to upgrade. Shouldn't it report back 'old' per your example?

"If local(1.0.0) and remote(1.1.0), result is new."

Also for reference, I have used this module in the past for easy version comparisons.
https://www.npmjs.com/package/compare-versions

Issue with non-JP Apps

Thank you so much for creating this. I just wanted to let you know of an issue when trying to get the version of an app not supported in JP.

ios.ts
const response = await fetch(https://itunes.apple.com/jp/lookup?id=${appID[1]}).then(r => r.text()).then(r => JSON.parse(r));

Since /jp/ is hard-coded as the country, if the app is only designed for another country (i.e. US), the 'jp' needs to be replaced with that country. You can probably pull this easily form the App Store URL itself and take whatever the user enters as default. Just a thought.

Only try to JSON.parse from iTunes API when it's a successful response

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Sometimes when using the iTunes API, I was getting a 400 error, which would get thrown only when trying to parse the JSON, which meant that the content returned by the API was not a proper JSON. In order to get a more clear error message, would be great to return a different message.

I was not able to find the proper API documentation for the iTunes API (specially what is returned in a 400 / 404/, but I have decided to add a header 'Accept': 'application/json', to make sure we always get JSON returned.

Ideally, we could also extend the errors from this library to contain an enum that identify what went wrong, e.g. AppNotFound, ApiRequestFailed, NoConnection, etc. If @watanabeyu thinks this would be useful, I can create a Pull Request ๐Ÿ˜„

Here is the diff from patch-package that solved my problem:

diff --git a/node_modules/react-native-store-version/dist/ios.js b/node_modules/react-native-store-version/dist/ios.js
index 59098da..1fec82e 100644
--- a/node_modules/react-native-store-version/dist/ios.js
+++ b/node_modules/react-native-store-version/dist/ios.js
@@ -3,16 +3,20 @@ export const getIOSVersion = async (storeURL = '', country = 'jp') => {
     if (!appID) {
         throw new Error('iosStoreURL is invalid.');
     }
-    const response = await fetch(`https://itunes.apple.com/lookup?id=${appID[1]}&country=${country}&${new Date().getTime()}`, {
+    const response = await fetch(`https://itunes.apple.com/lookup?id=${appID[1]}&country=${country}`, {
         headers: {
+            'Accept': 'application/json',
             'cache-control': 'no-cache',
         },
     })
-        .then((r) => r.text())
-        .then((r) => JSON.parse(r));
-    if (response.results.length === 0) {
+    if (response.status !== 200) {
+        throw new Error(`iTunes API returned an error with code: ${response.status}`);
+    }
+    const results = (await response.json()).results
+
+    if (results.length === 0) {
         throw new Error(`appID(${appID[1]}) is not released.`);
     }
-    return response.results[0].version;
+    return results[0].version;
 };

This issue body was partially generated by patch-package.

Adds version number to iOS version number when archiving

When I install the react-native-store-version package, the package version number is appended to the version of my App.

When I define 2.0.13 for my App and the version of react-native-store-version is 1.4.0 then after archiving I get as App version 2.0.13 ^1.4.0(1). This can not be submitted to App Store connect.

Any suggestions?

Bildschirmfoto 2022-09-20 um 22 25 52

New form version from App Store

Hello, i am using your package and recently received this
Error: Invalid argument not valid semver ('40 (1.0.7)' received)
this is happening because app store passes the version value in the new form
like this
'40 (1.0.7)'
i fix this add some regEx checks
const matches = response.results[0].version.match(/\(([^)]+)\)/); if (!matches) { throw new Error("can't get ios app version."); } return matches[1];
just like at android version check

Getting `403` Error for androidStoreURL in checkVersion()

I am using react-native-store-version to check the version of my application on the play store:

           import checkVersion from 'react-native-store-version';

           const check = await checkVersion({
                version: currentAppVersion, // app local version
                iosStoreURL: 'https://apps.apple.com/us/app/servr/id1473118642?ls=1',
                androidStoreURL: 'https://play.google.com/store/apps/details?id=com.servr',
                country: 'pk', // default value is 'jp'
            });

But I am getting the following error 403 Forbidden on androidStoreURL

image

issue with Android Play store Version fetching

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-store-version/dist/android.js b/node_modules/react-native-store-version/dist/android.js
index 469615f..ad10a8f 100644
--- a/node_modules/react-native-store-version/dist/android.js
+++ b/node_modules/react-native-store-version/dist/android.js
@@ -8,7 +8,7 @@ export const getAndroidVersion = async (storeURL = '') => {
         }
         throw new Error('androidStoreURL is invalid.');
     });
-    const matches = response.match(/<span class="htlgb"><div class="IQ1z0d"><span class="htlgb">([0-9]+\.?[0-9]*\.?[0-9]*)<\/span><\/div><\/span>/);
+    const matches = response.match(/\[\[\[['"]((\d+\.)+\d+)['"]\]\],/);
     if (!matches) {
         throw new Error('can\'t get android app version.');
     }

This issue body was partially generated by patch-package.

Error: JSON Parse error: Unexpected token: <

I am intermittently seeing an exception when calling "checkVersion". The exception happens about 25% of the time. im calling the function as follows:

    let check = await checkVersion({
        version: versionLocal, // app local version
        iosStoreURL: updateConfig.urls.ios.check,
        androidStoreURL: updateConfig.urls.android.check,
        country: 'us',
    });

where variables are (expect i am using my real id# and app name) :

    ios: {
        check: 'https://apps.apple.com/us/app/yachtwave/id1234567890',
    },
    android: {
        check: 'https://play.google.com/store/apps/details?id=com.myapp.app',

Hoping you can help find the issue as it is affecting version checks - thanks!

How do I mock the checkVersion function in jest tests?

I've tried:

jest.mock('react-native-store-version', () => ({
  checkVersion: jest.fn().mockResolvedValue({result: 'new', remote: '1.0.83'})
}));

But it's throwing error TypeError: (0 , react_native_store_version_1.default) is not a function

in Android it works fine but in iOS I have errors

Thanks for this, great job.

It's perfect for Android, everything works great, but in iOS the version of my app doesn't conform to Android (it's a bit behind), so how does it handle the 2 outputs independently, Thanks

outdated android store version pattern matching

The regex inside .getAndroidVersion() from android.js of this package may be outdated such that it can not find the android app version from the pattern matching. I don't know is there any fix for it.

image

Android gives CORS error

 try {
        const check = await checkVersion({
          version: '1.0.0',
          androidStoreURL: 'https://play.google.com/store/apps/details?id=com.dzango.hq',
        });

       console.log(check)
      } catch (e) {
        console.log(e);
      }

that gives error

[Thu Jan 11 2024 19:20:21.839]  GET https://play.google.com/store/apps/details?id=com.dzango.hq net::ERR_FAILED 403 (Forbidden)

On other app request for 'https://play.google.com/store/apps/details?id=${myPackageName}' gives CORS Error
how can I solve it?

Version Yarn : v1.22.21
Version React Native: v0.71.7
Version react-native-store-version : v1.4.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.