react-native-update 10.9.0 → 10.10.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.9.0",
3
+ "version": "10.10.0",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/context.ts CHANGED
@@ -14,6 +14,7 @@ export const defaultContext = {
14
14
  downloadUpdate: asyncNoop,
15
15
  downloadAndInstallApk: asyncNoop,
16
16
  getCurrentVersionInfo: () => Promise.resolve({}),
17
+ parseTestPayload: () => Promise.resolve(false),
17
18
  currentHash: '',
18
19
  packageVersion: '',
19
20
  };
@@ -31,6 +32,7 @@ export const PushyContext = createContext<{
31
32
  description?: string;
32
33
  metaInfo?: string;
33
34
  }>;
35
+ parseTestPayload: (code: string) => Promise<boolean>;
34
36
  currentHash: string;
35
37
  packageVersion: string;
36
38
  client?: Pushy;
package/src/provider.tsx CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  packageVersion,
20
20
  getCurrentVersionInfo,
21
21
  } from './core';
22
- import { CheckResult, ProgressData } from './type';
22
+ import { CheckResult, ProgressData, PushyTestPayload } from './type';
23
23
  import { PushyContext } from './context';
24
24
 
25
25
  export const PushyProvider = ({
@@ -262,6 +262,25 @@ export const PushyProvider = ({
262
262
  };
263
263
  }, [checkUpdate, options, dismissError, markSuccess]);
264
264
 
265
+ const parseTestPayload = useCallback(
266
+ async (code: string) => {
267
+ let payload: PushyTestPayload;
268
+ try {
269
+ payload = JSON.parse(code);
270
+ } catch {
271
+ return false;
272
+ }
273
+ if (payload && payload.type) {
274
+ if (payload.type === '__rnPushyVersionHash') {
275
+ await checkUpdate({ toHash: payload.data });
276
+ return true;
277
+ }
278
+ }
279
+ return false;
280
+ },
281
+ [checkUpdate],
282
+ );
283
+
265
284
  return (
266
285
  <PushyContext.Provider
267
286
  value={{
@@ -279,6 +298,7 @@ export const PushyProvider = ({
279
298
  progress,
280
299
  downloadAndInstallApk,
281
300
  getCurrentVersionInfo,
301
+ parseTestPayload,
282
302
  }}>
283
303
  {children}
284
304
  </PushyContext.Provider>
package/src/type.ts CHANGED
@@ -81,3 +81,8 @@ export interface PushyOptions {
81
81
  debug?: boolean;
82
82
  throwError?: boolean;
83
83
  }
84
+
85
+ export interface PushyTestPayload {
86
+ type: '__rnPushyVersionHash';
87
+ data: any;
88
+ }