@parrotnavy/rn-native-updates 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/NativeUpdatesBridge.m +1 -1
- package/ios/NativeUpdatesModule.swift +15 -3
- package/lib/module/NativeNativeUpdates.js +10 -0
- package/lib/module/NativeNativeUpdates.js.map +1 -0
- package/lib/module/NativeUpdatesModule.js +27 -4
- package/lib/module/NativeUpdatesModule.js.map +1 -1
- package/lib/typescript/src/NativeNativeUpdates.d.ts +36 -0
- package/lib/typescript/src/NativeNativeUpdates.d.ts.map +1 -0
- package/lib/typescript/src/NativeUpdatesModule.d.ts.map +1 -1
- package/package.json +9 -1
- package/rn-native-updates.podspec +7 -1
- package/src/NativeNativeUpdates.ts +47 -0
- package/src/NativeUpdatesModule.ts +33 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#import <React/RCTBridgeModule.h>
|
|
2
2
|
|
|
3
|
-
@interface
|
|
3
|
+
@interface RCT_EXTERN_REMAP_MODULE(NativeUpdates, NativeUpdatesModule, NSObject)
|
|
4
4
|
|
|
5
5
|
RCT_EXTERN_METHOD(getAppStoreVersion:(NSString *)country
|
|
6
6
|
forceRefresh:(BOOL)forceRefresh
|
|
@@ -14,15 +14,27 @@ public class NativeUpdatesModule: NSObject, RCTBridgeModule {
|
|
|
14
14
|
return false
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
@objc func constantsToExport() -> [AnyHashable: Any]! {
|
|
17
|
+
@objc public func constantsToExport() -> [AnyHashable: Any]! {
|
|
18
|
+
return getConstants()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@objc public func getConstants() -> [AnyHashable: Any]! {
|
|
18
22
|
return [
|
|
19
23
|
"currentVersion": Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "0.0.0",
|
|
20
24
|
"buildNumber": Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "0",
|
|
21
25
|
"packageName": Bundle.main.bundleIdentifier ?? "",
|
|
22
|
-
"country":
|
|
26
|
+
"country": getCountryCode()
|
|
23
27
|
]
|
|
24
28
|
}
|
|
25
29
|
|
|
30
|
+
private func getCountryCode() -> String {
|
|
31
|
+
if #available(iOS 16, *) {
|
|
32
|
+
return Locale.current.region?.identifier ?? "US"
|
|
33
|
+
} else {
|
|
34
|
+
return Locale.current.regionCode ?? "US"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
26
38
|
@objc func getAppStoreVersion(_ country: String?, forceRefresh: Bool, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
27
39
|
Task {
|
|
28
40
|
do {
|
|
@@ -38,7 +50,7 @@ public class NativeUpdatesModule: NSObject, RCTBridgeModule {
|
|
|
38
50
|
throw AppStoreError.invalidBundleId
|
|
39
51
|
}
|
|
40
52
|
|
|
41
|
-
let countryCode = country ??
|
|
53
|
+
let countryCode = country ?? getCountryCode()
|
|
42
54
|
let timestamp = Int(Date().timeIntervalSince1970)
|
|
43
55
|
let urlString = "https://itunes.apple.com/lookup?bundleId=\(bundleId)&country=\(countryCode)&date=\(timestamp)"
|
|
44
56
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Codegen spec for New Architecture support
|
|
5
|
+
* This file defines the TurboModule interface for rn-native-updates
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
9
|
+
export default TurboModuleRegistry.getEnforcing('NativeUpdates');
|
|
10
|
+
//# sourceMappingURL=NativeNativeUpdates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeNativeUpdates.ts"],"mappings":";;AAAA;AACA;AACA;AACA;;AAGA,SAASA,mBAAmB,QAAQ,cAAc;AAwClD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,eAAe,CAAC","ignoreList":[]}
|
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { NativeModules } from 'react-native';
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const LINKING_ERROR = '[@parrotnavy/rn-native-updates] NativeUpdates module is not available. ' + 'Make sure the library is properly linked. ' + 'For bare React Native: run `npx pod-install` (iOS) after installing. ' + 'For Expo: use a development build (`npx expo run:ios` or `npx expo run:android`).';
|
|
5
|
+
|
|
6
|
+
// Try to load via TurboModuleRegistry first (New Architecture)
|
|
7
|
+
// Fall back to NativeModules (Old Architecture)
|
|
8
|
+
let NativeUpdates = null;
|
|
9
|
+
try {
|
|
10
|
+
// Attempt to use TurboModule (New Architecture)
|
|
11
|
+
// Use dynamic import to avoid compile errors on older RN versions
|
|
12
|
+
// biome-ignore lint/suspicious/noExplicitAny: global.__turboModuleProxy is not typed
|
|
13
|
+
const isTurboModuleEnabled = global.__turboModuleProxy != null;
|
|
14
|
+
if (isTurboModuleEnabled) {
|
|
15
|
+
try {
|
|
16
|
+
const NativeNativeUpdates = require('./NativeNativeUpdates').default;
|
|
17
|
+
NativeUpdates = NativeNativeUpdates;
|
|
18
|
+
} catch {
|
|
19
|
+
// TurboModule not available, will fall back to NativeModules
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
} catch {
|
|
23
|
+
// TurboModuleRegistry not available
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Fall back to NativeModules (Old Architecture)
|
|
27
|
+
if (!NativeUpdates) {
|
|
28
|
+
NativeUpdates = NativeModules.NativeUpdates;
|
|
29
|
+
}
|
|
7
30
|
if (!NativeUpdates) {
|
|
8
|
-
throw new Error(
|
|
31
|
+
throw new Error(LINKING_ERROR);
|
|
9
32
|
}
|
|
10
33
|
export const NativeUpdatesModule = NativeUpdates;
|
|
11
34
|
//# sourceMappingURL=NativeUpdatesModule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","NativeUpdates","Error","NativeUpdatesModule"],"sourceRoot":"../../src","sources":["NativeUpdatesModule.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,cAAc;AAI5C,MAAM;
|
|
1
|
+
{"version":3,"names":["NativeModules","LINKING_ERROR","NativeUpdates","isTurboModuleEnabled","global","__turboModuleProxy","NativeNativeUpdates","require","default","Error","NativeUpdatesModule"],"sourceRoot":"../../src","sources":["NativeUpdatesModule.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,cAAc;AAI5C,MAAMC,aAAa,GACjB,yEAAyE,GACzE,4CAA4C,GAC5C,uEAAuE,GACvE,mFAAmF;;AAErF;AACA;AACA,IAAIC,aAA6C,GAAG,IAAI;AAExD,IAAI;EACF;EACA;EACA;EACA,MAAMC,oBAAoB,GAAIC,MAAM,CAASC,kBAAkB,IAAI,IAAI;EAEvE,IAAIF,oBAAoB,EAAE;IACxB,IAAI;MACF,MAAMG,mBAAmB,GAAGC,OAAO,CAAC,uBAAuB,CAAC,CAACC,OAAO;MACpEN,aAAa,GAAGI,mBAAmB;IACrC,CAAC,CAAC,MAAM;MACN;IAAA;EAEJ;AACF,CAAC,CAAC,MAAM;EACN;AAAA;;AAGF;AACA,IAAI,CAACJ,aAAa,EAAE;EAClBA,aAAa,GAAGF,aAAa,CAACE,aAAa;AAC7C;AAEA,IAAI,CAACA,aAAa,EAAE;EAClB,MAAM,IAAIO,KAAK,CAACR,aAAa,CAAC;AAChC;AAEA,OAAO,MAAMS,mBAAmB,GAAGR,aAAwC","ignoreList":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codegen spec for New Architecture support
|
|
3
|
+
* This file defines the TurboModule interface for rn-native-updates
|
|
4
|
+
*/
|
|
5
|
+
import type { TurboModule } from 'react-native';
|
|
6
|
+
export interface Spec extends TurboModule {
|
|
7
|
+
getConstants(): {
|
|
8
|
+
currentVersion: string;
|
|
9
|
+
buildNumber: string;
|
|
10
|
+
packageName: string;
|
|
11
|
+
country: string;
|
|
12
|
+
};
|
|
13
|
+
getAppStoreVersion(country: string | null, forceRefresh: boolean): Promise<{
|
|
14
|
+
version: string;
|
|
15
|
+
trackId: number;
|
|
16
|
+
trackViewUrl: string;
|
|
17
|
+
currentVersionReleaseDate: string;
|
|
18
|
+
releaseNotes: string | null;
|
|
19
|
+
minimumOsVersion: string;
|
|
20
|
+
}>;
|
|
21
|
+
checkPlayStoreUpdate(): Promise<{
|
|
22
|
+
updateAvailability: number;
|
|
23
|
+
availableVersionCode: number | null;
|
|
24
|
+
isFlexibleUpdateAllowed: boolean;
|
|
25
|
+
isImmediateUpdateAllowed: boolean;
|
|
26
|
+
clientVersionStalenessDays: number | null;
|
|
27
|
+
updatePriority: number;
|
|
28
|
+
totalBytesToDownload: number;
|
|
29
|
+
packageName: string;
|
|
30
|
+
}>;
|
|
31
|
+
startUpdate(updateType: number): Promise<void>;
|
|
32
|
+
completeUpdate(): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
declare const _default: Spec;
|
|
35
|
+
export default _default;
|
|
36
|
+
//# sourceMappingURL=NativeNativeUpdates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeNativeUpdates.d.ts","sourceRoot":"","sources":["../../../src/NativeNativeUpdates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IAEvC,YAAY,IAAI;QACd,cAAc,EAAE,MAAM,CAAC;QACvB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IAGF,kBAAkB,CAChB,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,YAAY,EAAE,OAAO,GACpB,OAAO,CAAC;QACT,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,yBAAyB,EAAE,MAAM,CAAC;QAClC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC,CAAC;IAGH,oBAAoB,IAAI,OAAO,CAAC;QAC9B,kBAAkB,EAAE,MAAM,CAAC;QAC3B,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;QACpC,uBAAuB,EAAE,OAAO,CAAC;QACjC,wBAAwB,EAAE,OAAO,CAAC;QAClC,0BAA0B,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1C,cAAc,EAAE,MAAM,CAAC;QACvB,oBAAoB,EAAE,MAAM,CAAC;QAC7B,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC,CAAC;IAEH,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC;;AAED,wBAAuE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeUpdatesModule.d.ts","sourceRoot":"","sources":["../../../src/NativeUpdatesModule.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"NativeUpdatesModule.d.ts","sourceRoot":"","sources":["../../../src/NativeUpdatesModule.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAuCvD,eAAO,MAAM,mBAAmB,EAAoB,uBAAuB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parrotnavy/rn-native-updates",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "React Native app update checker with hooks support. Uses Play Core for Android and iTunes Lookup API for iOS.",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -91,5 +91,13 @@
|
|
|
91
91
|
}
|
|
92
92
|
]
|
|
93
93
|
]
|
|
94
|
+
},
|
|
95
|
+
"codegenConfig": {
|
|
96
|
+
"name": "RNNativeUpdatesSpec",
|
|
97
|
+
"type": "modules",
|
|
98
|
+
"jsSrcsDir": "src",
|
|
99
|
+
"android": {
|
|
100
|
+
"javaPackageName": "com.parrotnavy.rnnativeupdates"
|
|
101
|
+
}
|
|
94
102
|
}
|
|
95
103
|
}
|
|
@@ -16,5 +16,11 @@ Pod::Spec.new do |s|
|
|
|
16
16
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
17
17
|
s.public_header_files = "ios/**/*.h"
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
20
|
+
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
21
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
22
|
+
install_modules_dependencies(s)
|
|
23
|
+
else
|
|
24
|
+
s.dependency "React-Core"
|
|
25
|
+
end
|
|
20
26
|
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codegen spec for New Architecture support
|
|
3
|
+
* This file defines the TurboModule interface for rn-native-updates
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { TurboModule } from 'react-native';
|
|
7
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
8
|
+
|
|
9
|
+
export interface Spec extends TurboModule {
|
|
10
|
+
// Get constants (replaces readonly properties)
|
|
11
|
+
getConstants(): {
|
|
12
|
+
currentVersion: string;
|
|
13
|
+
buildNumber: string;
|
|
14
|
+
packageName: string;
|
|
15
|
+
country: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// iOS Methods
|
|
19
|
+
getAppStoreVersion(
|
|
20
|
+
country: string | null,
|
|
21
|
+
forceRefresh: boolean
|
|
22
|
+
): Promise<{
|
|
23
|
+
version: string;
|
|
24
|
+
trackId: number;
|
|
25
|
+
trackViewUrl: string;
|
|
26
|
+
currentVersionReleaseDate: string;
|
|
27
|
+
releaseNotes: string | null;
|
|
28
|
+
minimumOsVersion: string;
|
|
29
|
+
}>;
|
|
30
|
+
|
|
31
|
+
// Android Methods
|
|
32
|
+
checkPlayStoreUpdate(): Promise<{
|
|
33
|
+
updateAvailability: number;
|
|
34
|
+
availableVersionCode: number | null;
|
|
35
|
+
isFlexibleUpdateAllowed: boolean;
|
|
36
|
+
isImmediateUpdateAllowed: boolean;
|
|
37
|
+
clientVersionStalenessDays: number | null;
|
|
38
|
+
updatePriority: number;
|
|
39
|
+
totalBytesToDownload: number;
|
|
40
|
+
packageName: string;
|
|
41
|
+
}>;
|
|
42
|
+
|
|
43
|
+
startUpdate(updateType: number): Promise<void>;
|
|
44
|
+
completeUpdate(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('NativeUpdates');
|
|
@@ -2,15 +2,41 @@ import { NativeModules } from 'react-native';
|
|
|
2
2
|
|
|
3
3
|
import type { NativeUpdatesModuleType } from './types';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const LINKING_ERROR =
|
|
6
|
+
'[@parrotnavy/rn-native-updates] NativeUpdates module is not available. ' +
|
|
7
|
+
'Make sure the library is properly linked. ' +
|
|
8
|
+
'For bare React Native: run `npx pod-install` (iOS) after installing. ' +
|
|
9
|
+
'For Expo: use a development build (`npx expo run:ios` or `npx expo run:android`).';
|
|
10
|
+
|
|
11
|
+
// Try to load via TurboModuleRegistry first (New Architecture)
|
|
12
|
+
// Fall back to NativeModules (Old Architecture)
|
|
13
|
+
let NativeUpdates: NativeUpdatesModuleType | null = null;
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
// Attempt to use TurboModule (New Architecture)
|
|
17
|
+
// Use dynamic import to avoid compile errors on older RN versions
|
|
18
|
+
// biome-ignore lint/suspicious/noExplicitAny: global.__turboModuleProxy is not typed
|
|
19
|
+
const isTurboModuleEnabled = (global as any).__turboModuleProxy != null;
|
|
20
|
+
|
|
21
|
+
if (isTurboModuleEnabled) {
|
|
22
|
+
try {
|
|
23
|
+
const NativeNativeUpdates = require('./NativeNativeUpdates').default;
|
|
24
|
+
NativeUpdates = NativeNativeUpdates;
|
|
25
|
+
} catch {
|
|
26
|
+
// TurboModule not available, will fall back to NativeModules
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
} catch {
|
|
30
|
+
// TurboModuleRegistry not available
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Fall back to NativeModules (Old Architecture)
|
|
34
|
+
if (!NativeUpdates) {
|
|
35
|
+
NativeUpdates = NativeModules.NativeUpdates;
|
|
36
|
+
}
|
|
6
37
|
|
|
7
38
|
if (!NativeUpdates) {
|
|
8
|
-
throw new Error(
|
|
9
|
-
'[@parrotnavy/rn-native-updates] NativeUpdates module is not available. ' +
|
|
10
|
-
'Make sure the library is properly linked. ' +
|
|
11
|
-
'For bare React Native: run `npx pod-install` (iOS) after installing. ' +
|
|
12
|
-
'For Expo: use a development build (`npx expo run:ios` or `npx expo run:android`).',
|
|
13
|
-
);
|
|
39
|
+
throw new Error(LINKING_ERROR);
|
|
14
40
|
}
|
|
15
41
|
|
|
16
42
|
export const NativeUpdatesModule = NativeUpdates as NativeUpdatesModuleType;
|