@appzung/react-native-code-push 10.1.0 → 10.1.2

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.
Files changed (186) hide show
  1. package/android/app/src/main/java/com/appzung/codepush/react/CodePush.java +3 -0
  2. package/ios/CodePush/CodePushConfig.m +4 -0
  3. package/lib/commonjs/CodePush.js +5 -0
  4. package/lib/commonjs/CodePush.js.map +1 -1
  5. package/lib/commonjs/checkForUpdates.js +25 -26
  6. package/lib/commonjs/checkForUpdates.js.map +1 -1
  7. package/lib/commonjs/enums/LogLevel.enum.js +14 -0
  8. package/lib/commonjs/enums/LogLevel.enum.js.map +1 -0
  9. package/lib/commonjs/index.js +30 -9
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/internals/CodePushApiSdk.errors.js +26 -0
  12. package/lib/commonjs/internals/CodePushApiSdk.errors.js.map +1 -0
  13. package/lib/commonjs/internals/CodePushApiSdk.js +100 -0
  14. package/lib/commonjs/internals/CodePushApiSdk.js.map +1 -0
  15. package/lib/commonjs/{enums/DeploymentStatus.enum.js → internals/CodePushApiSdk.types.js} +3 -2
  16. package/lib/commonjs/internals/CodePushApiSdk.types.js.map +1 -0
  17. package/lib/commonjs/internals/RemotePackageImplementation.js +7 -5
  18. package/lib/commonjs/internals/RemotePackageImplementation.js.map +1 -1
  19. package/lib/commonjs/internals/shouldUpdateBeIgnored.js +6 -5
  20. package/lib/commonjs/internals/shouldUpdateBeIgnored.js.map +1 -1
  21. package/lib/commonjs/internals/utils/fetchRetry.js +59 -0
  22. package/lib/commonjs/internals/utils/fetchRetry.js.map +1 -0
  23. package/lib/commonjs/internals/utils/log.js +6 -1
  24. package/lib/commonjs/internals/utils/log.js.map +1 -1
  25. package/lib/commonjs/internals/utils/queryStringify.js +25 -0
  26. package/lib/commonjs/internals/utils/queryStringify.js.map +1 -0
  27. package/lib/commonjs/internals/utils/requestFetchAdapter.js +38 -0
  28. package/lib/commonjs/internals/utils/requestFetchAdapter.js.map +1 -0
  29. package/lib/commonjs/internals/version.js +1 -1
  30. package/lib/commonjs/logLevel.js +15 -0
  31. package/lib/commonjs/logLevel.js.map +1 -0
  32. package/lib/commonjs/notifyAppReady.js +22 -15
  33. package/lib/commonjs/notifyAppReady.js.map +1 -1
  34. package/lib/commonjs/sync.js +27 -24
  35. package/lib/commonjs/sync.js.map +1 -1
  36. package/lib/module/CodePush.js +5 -0
  37. package/lib/module/CodePush.js.map +1 -1
  38. package/lib/module/checkForUpdates.js +25 -26
  39. package/lib/module/checkForUpdates.js.map +1 -1
  40. package/lib/module/enums/LogLevel.enum.js +10 -0
  41. package/lib/module/enums/LogLevel.enum.js.map +1 -0
  42. package/lib/module/index.js +3 -1
  43. package/lib/module/index.js.map +1 -1
  44. package/lib/module/internals/CodePushApiSdk.errors.js +20 -0
  45. package/lib/module/internals/CodePushApiSdk.errors.js.map +1 -0
  46. package/lib/module/internals/CodePushApiSdk.js +96 -0
  47. package/lib/module/internals/CodePushApiSdk.js.map +1 -0
  48. package/lib/module/{enums/DeploymentStatus.enum.js → internals/CodePushApiSdk.types.js} +2 -1
  49. package/lib/module/internals/CodePushApiSdk.types.js.map +1 -0
  50. package/lib/module/internals/RemotePackageImplementation.js +7 -5
  51. package/lib/module/internals/RemotePackageImplementation.js.map +1 -1
  52. package/lib/module/internals/shouldUpdateBeIgnored.js +6 -5
  53. package/lib/module/internals/shouldUpdateBeIgnored.js.map +1 -1
  54. package/lib/module/internals/utils/fetchRetry.js +55 -0
  55. package/lib/module/internals/utils/fetchRetry.js.map +1 -0
  56. package/lib/module/internals/utils/log.js +7 -1
  57. package/lib/module/internals/utils/log.js.map +1 -1
  58. package/lib/module/internals/utils/queryStringify.js +21 -0
  59. package/lib/module/internals/utils/queryStringify.js.map +1 -0
  60. package/lib/module/internals/utils/requestFetchAdapter.js +34 -0
  61. package/lib/module/internals/utils/requestFetchAdapter.js.map +1 -0
  62. package/lib/module/internals/version.js +1 -1
  63. package/lib/module/logLevel.js +9 -0
  64. package/lib/module/logLevel.js.map +1 -0
  65. package/lib/module/notifyAppReady.js +22 -15
  66. package/lib/module/notifyAppReady.js.map +1 -1
  67. package/lib/module/sync.js +27 -24
  68. package/lib/module/sync.js.map +1 -1
  69. package/lib/typescript/commonjs/src/CodePush.d.ts.map +1 -1
  70. package/lib/typescript/commonjs/src/checkForUpdates.d.ts.map +1 -1
  71. package/lib/typescript/commonjs/src/enums/LogLevel.enum.d.ts +7 -0
  72. package/lib/typescript/commonjs/src/enums/LogLevel.enum.d.ts.map +1 -0
  73. package/lib/typescript/commonjs/src/index.d.ts +3 -1
  74. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  75. package/lib/typescript/commonjs/src/internals/CodePushApiSdk.d.ts +13 -0
  76. package/lib/typescript/commonjs/src/internals/CodePushApiSdk.d.ts.map +1 -0
  77. package/lib/typescript/commonjs/src/internals/CodePushApiSdk.errors.d.ts +9 -0
  78. package/lib/typescript/commonjs/src/internals/CodePushApiSdk.errors.d.ts.map +1 -0
  79. package/lib/typescript/commonjs/src/internals/CodePushApiSdk.types.d.ts +101 -0
  80. package/lib/typescript/commonjs/src/internals/CodePushApiSdk.types.d.ts.map +1 -0
  81. package/lib/typescript/commonjs/src/internals/RemotePackageImplementation.d.ts +2 -2
  82. package/lib/typescript/commonjs/src/internals/RemotePackageImplementation.d.ts.map +1 -1
  83. package/lib/typescript/commonjs/src/internals/shouldUpdateBeIgnored.d.ts.map +1 -1
  84. package/lib/typescript/commonjs/src/internals/types.d.ts +2 -2
  85. package/lib/typescript/commonjs/src/internals/types.d.ts.map +1 -1
  86. package/lib/typescript/commonjs/src/internals/utils/fetchRetry.d.ts +9 -0
  87. package/lib/typescript/commonjs/src/internals/utils/fetchRetry.d.ts.map +1 -0
  88. package/lib/typescript/commonjs/src/internals/utils/log.d.ts +2 -1
  89. package/lib/typescript/commonjs/src/internals/utils/log.d.ts.map +1 -1
  90. package/lib/typescript/commonjs/src/internals/utils/queryStringify.d.ts +4 -0
  91. package/lib/typescript/commonjs/src/internals/utils/queryStringify.d.ts.map +1 -0
  92. package/lib/typescript/commonjs/src/internals/utils/requestFetchAdapter.d.ts +3 -0
  93. package/lib/typescript/commonjs/src/internals/utils/requestFetchAdapter.d.ts.map +1 -0
  94. package/lib/typescript/commonjs/src/internals/version.d.ts +1 -1
  95. package/lib/typescript/commonjs/src/logLevel.d.ts +4 -0
  96. package/lib/typescript/commonjs/src/logLevel.d.ts.map +1 -0
  97. package/lib/typescript/commonjs/src/notifyAppReady.d.ts.map +1 -1
  98. package/lib/typescript/commonjs/src/sync.d.ts.map +1 -1
  99. package/lib/typescript/commonjs/src/types.d.ts +4 -3
  100. package/lib/typescript/commonjs/src/types.d.ts.map +1 -1
  101. package/lib/typescript/module/src/CodePush.d.ts.map +1 -1
  102. package/lib/typescript/module/src/checkForUpdates.d.ts.map +1 -1
  103. package/lib/typescript/module/src/enums/LogLevel.enum.d.ts +7 -0
  104. package/lib/typescript/module/src/enums/LogLevel.enum.d.ts.map +1 -0
  105. package/lib/typescript/module/src/index.d.ts +3 -1
  106. package/lib/typescript/module/src/index.d.ts.map +1 -1
  107. package/lib/typescript/module/src/internals/CodePushApiSdk.d.ts +13 -0
  108. package/lib/typescript/module/src/internals/CodePushApiSdk.d.ts.map +1 -0
  109. package/lib/typescript/module/src/internals/CodePushApiSdk.errors.d.ts +9 -0
  110. package/lib/typescript/module/src/internals/CodePushApiSdk.errors.d.ts.map +1 -0
  111. package/lib/typescript/module/src/internals/CodePushApiSdk.types.d.ts +101 -0
  112. package/lib/typescript/module/src/internals/CodePushApiSdk.types.d.ts.map +1 -0
  113. package/lib/typescript/module/src/internals/RemotePackageImplementation.d.ts +2 -2
  114. package/lib/typescript/module/src/internals/RemotePackageImplementation.d.ts.map +1 -1
  115. package/lib/typescript/module/src/internals/shouldUpdateBeIgnored.d.ts.map +1 -1
  116. package/lib/typescript/module/src/internals/types.d.ts +2 -2
  117. package/lib/typescript/module/src/internals/types.d.ts.map +1 -1
  118. package/lib/typescript/module/src/internals/utils/fetchRetry.d.ts +9 -0
  119. package/lib/typescript/module/src/internals/utils/fetchRetry.d.ts.map +1 -0
  120. package/lib/typescript/module/src/internals/utils/log.d.ts +2 -1
  121. package/lib/typescript/module/src/internals/utils/log.d.ts.map +1 -1
  122. package/lib/typescript/module/src/internals/utils/queryStringify.d.ts +4 -0
  123. package/lib/typescript/module/src/internals/utils/queryStringify.d.ts.map +1 -0
  124. package/lib/typescript/module/src/internals/utils/requestFetchAdapter.d.ts +3 -0
  125. package/lib/typescript/module/src/internals/utils/requestFetchAdapter.d.ts.map +1 -0
  126. package/lib/typescript/module/src/internals/version.d.ts +1 -1
  127. package/lib/typescript/module/src/logLevel.d.ts +4 -0
  128. package/lib/typescript/module/src/logLevel.d.ts.map +1 -0
  129. package/lib/typescript/module/src/notifyAppReady.d.ts.map +1 -1
  130. package/lib/typescript/module/src/sync.d.ts.map +1 -1
  131. package/lib/typescript/module/src/types.d.ts +4 -3
  132. package/lib/typescript/module/src/types.d.ts.map +1 -1
  133. package/package.json +3 -3
  134. package/src/CodePush.tsx +6 -0
  135. package/src/checkForUpdates.ts +26 -24
  136. package/src/enums/LogLevel.enum.ts +6 -0
  137. package/src/index.ts +3 -1
  138. package/src/internals/CodePushApiSdk.errors.ts +22 -0
  139. package/src/internals/CodePushApiSdk.ts +133 -0
  140. package/src/internals/CodePushApiSdk.types.ts +115 -0
  141. package/src/internals/RemotePackageImplementation.ts +9 -7
  142. package/src/internals/shouldUpdateBeIgnored.ts +6 -5
  143. package/src/internals/types.ts +2 -2
  144. package/src/internals/utils/fetchRetry.ts +72 -0
  145. package/src/internals/utils/log.ts +9 -1
  146. package/src/internals/utils/queryStringify.ts +22 -0
  147. package/src/internals/utils/requestFetchAdapter.ts +36 -0
  148. package/src/internals/version.ts +1 -1
  149. package/src/logLevel.ts +9 -0
  150. package/src/notifyAppReady.ts +25 -18
  151. package/src/sync.ts +33 -23
  152. package/src/types.ts +2 -3
  153. package/lib/commonjs/enums/DeploymentStatus.enum.js.map +0 -1
  154. package/lib/commonjs/internals/AcquisitionSdk.js +0 -9
  155. package/lib/commonjs/internals/AcquisitionSdk.js.map +0 -1
  156. package/lib/commonjs/internals/getPromisifiedSdk.js +0 -49
  157. package/lib/commonjs/internals/getPromisifiedSdk.js.map +0 -1
  158. package/lib/commonjs/internals/utils/request-fetch-adapter.js +0 -50
  159. package/lib/commonjs/internals/utils/request-fetch-adapter.js.map +0 -1
  160. package/lib/module/enums/DeploymentStatus.enum.js.map +0 -1
  161. package/lib/module/internals/AcquisitionSdk.js +0 -5
  162. package/lib/module/internals/AcquisitionSdk.js.map +0 -1
  163. package/lib/module/internals/getPromisifiedSdk.js +0 -45
  164. package/lib/module/internals/getPromisifiedSdk.js.map +0 -1
  165. package/lib/module/internals/utils/request-fetch-adapter.js +0 -46
  166. package/lib/module/internals/utils/request-fetch-adapter.js.map +0 -1
  167. package/lib/typescript/commonjs/src/enums/DeploymentStatus.enum.d.ts +0 -14
  168. package/lib/typescript/commonjs/src/enums/DeploymentStatus.enum.d.ts.map +0 -1
  169. package/lib/typescript/commonjs/src/internals/AcquisitionSdk.d.ts +0 -3
  170. package/lib/typescript/commonjs/src/internals/AcquisitionSdk.d.ts.map +0 -1
  171. package/lib/typescript/commonjs/src/internals/getPromisifiedSdk.d.ts +0 -13
  172. package/lib/typescript/commonjs/src/internals/getPromisifiedSdk.d.ts.map +0 -1
  173. package/lib/typescript/commonjs/src/internals/utils/request-fetch-adapter.d.ts +0 -3
  174. package/lib/typescript/commonjs/src/internals/utils/request-fetch-adapter.d.ts.map +0 -1
  175. package/lib/typescript/module/src/enums/DeploymentStatus.enum.d.ts +0 -14
  176. package/lib/typescript/module/src/enums/DeploymentStatus.enum.d.ts.map +0 -1
  177. package/lib/typescript/module/src/internals/AcquisitionSdk.d.ts +0 -3
  178. package/lib/typescript/module/src/internals/AcquisitionSdk.d.ts.map +0 -1
  179. package/lib/typescript/module/src/internals/getPromisifiedSdk.d.ts +0 -13
  180. package/lib/typescript/module/src/internals/getPromisifiedSdk.d.ts.map +0 -1
  181. package/lib/typescript/module/src/internals/utils/request-fetch-adapter.d.ts +0 -3
  182. package/lib/typescript/module/src/internals/utils/request-fetch-adapter.d.ts.map +0 -1
  183. package/src/enums/DeploymentStatus.enum.ts +0 -14
  184. package/src/internals/AcquisitionSdk.ts +0 -3
  185. package/src/internals/getPromisifiedSdk.ts +0 -72
  186. package/src/internals/utils/request-fetch-adapter.ts +0 -58
@@ -0,0 +1,115 @@
1
+ export interface ApiSdkQueryUpdatePackageInfo {
2
+ appVersion: string;
3
+ label?: string;
4
+ packageHash?: string;
5
+ }
6
+
7
+ export interface ApiSdkDeployReportPackageInfo {
8
+ label: string;
9
+ appVersion: string;
10
+ }
11
+
12
+ export interface ApiSdkDownloadReportPackageInfo {
13
+ label: string;
14
+ }
15
+
16
+ export interface ApiSdkRemotePackage {
17
+ releaseChannelPublicId: string;
18
+ label: string;
19
+ appVersion: string;
20
+ description: string;
21
+ isMandatory: boolean;
22
+ packageSize: number;
23
+ packageHash: string;
24
+ downloadUrl: string;
25
+ }
26
+
27
+ export interface ApiSdkNativeUpdateNotification {
28
+ updateAppVersion: true;
29
+ appVersion: string;
30
+ }
31
+
32
+ export namespace Http {
33
+ export interface Response {
34
+ statusCode: number;
35
+ body?: string;
36
+ }
37
+
38
+ export interface Requester {
39
+ request(verb: 'GET' | 'POST', url: string, requestBody?: string | object | null): Promise<Response>;
40
+ }
41
+ }
42
+
43
+ export interface ApiSdkConfiguration {
44
+ appVersion: string;
45
+ clientUniqueId: string;
46
+ releaseChannelPublicId: string;
47
+ serverUrl: string;
48
+ ignoreAppVersion?: boolean;
49
+ }
50
+
51
+ /**
52
+ * Indicates the status of a deployment (after installing and restarting).
53
+ */
54
+ export enum DeploymentStatus {
55
+ /**
56
+ * The deployment failed (and was rolled back).
57
+ */
58
+ FAILED = 'DeploymentFailed',
59
+
60
+ /**
61
+ * The deployment succeeded.
62
+ */
63
+ SUCCEEDED = 'DeploymentSucceeded',
64
+ }
65
+
66
+ export interface ReportDeployInput {
67
+ deployment_key: string;
68
+ app_version: string;
69
+ status?: DeploymentStatus;
70
+ label?: string;
71
+ client_unique_id?: string;
72
+ previous_label_or_app_version?: string;
73
+ previous_deployment_key?: string;
74
+ }
75
+
76
+ export interface ReportDownloadInput {
77
+ deployment_key: string;
78
+ label: string;
79
+ client_unique_id?: string;
80
+ }
81
+
82
+ export interface CheckUpdateRequestInput {
83
+ deployment_key: string;
84
+ app_version: string;
85
+ package_hash?: string;
86
+ label?: string;
87
+ client_unique_id?: string;
88
+ is_companion?: boolean;
89
+ previous_label_or_app_version?: string;
90
+ previous_deployment_key?: string;
91
+ }
92
+
93
+ export interface CheckUpdateResponse {
94
+ update_info:
95
+ | {
96
+ is_available: true;
97
+ target_binary_range: string;
98
+ description: string;
99
+ is_disabled: boolean;
100
+ is_mandatory: boolean;
101
+ rollout: number;
102
+ download_url: string;
103
+ package_size: number;
104
+ package_hash: string;
105
+ label: string;
106
+ should_run_binary_version: boolean;
107
+ update_app_version: boolean;
108
+ }
109
+ | {
110
+ is_available: false;
111
+ should_run_binary_version: boolean;
112
+ target_binary_range: string;
113
+ update_app_version?: boolean;
114
+ };
115
+ }
@@ -1,6 +1,7 @@
1
- import type { Package } from 'code-push/script/acquisition-sdk';
2
1
  import { NativeEventEmitter } from 'react-native';
2
+ import { LogLevel } from '../enums/LogLevel.enum';
3
3
  import type { DownloadProgressCallback, LocalPackage, RemotePackage } from '../types';
4
+ import type { ApiSdkDownloadReportPackageInfo } from './CodePushApiSdk.types';
4
5
  import { LocalPackageImplementation } from './LocalPackageImplementation';
5
6
  import { NativeRNAppZungCodePushModule } from './NativeRNAppZungCodePushModule';
6
7
  import { log } from './utils/log';
@@ -8,7 +9,7 @@ import { log } from './utils/log';
8
9
  export class RemotePackageImpl implements RemotePackage {
9
10
  constructor(
10
11
  remotePackageData: Omit<RemotePackage, 'download'>,
11
- reportStatusDownload?: (downloadedPackage: Package) => Promise<void>,
12
+ reportStatusDownload: (downloadedPackage: ApiSdkDownloadReportPackageInfo) => Promise<void>,
12
13
  ) {
13
14
  Object.assign(this, remotePackageData);
14
15
 
@@ -38,12 +39,13 @@ export class RemotePackageImpl implements RemotePackage {
38
39
  );
39
40
 
40
41
  if (reportStatusDownload) {
41
- reportStatusDownload({
42
- ...this,
43
- deploymentKey: this.releaseChannelPublicId,
44
- }).catch((err) => {
45
- log(`Report download status failed: ${err}`);
42
+ const timeoutPromise = new Promise<void>((resolve) => setTimeout(resolve, 250));
43
+ const reportPromise = reportStatusDownload({
44
+ label: this.label,
45
+ }).catch((error) => {
46
+ log(LogLevel.ERROR, `Report download status failed: ${error}`);
46
47
  });
48
+ await Promise.race([timeoutPromise, reportPromise]);
47
49
  }
48
50
 
49
51
  return new LocalPackageImplementation(downloadedPackage);
@@ -1,3 +1,4 @@
1
+ import { LogLevel } from '../enums/LogLevel.enum';
1
2
  import type { RemotePackage, RollbackRetryOptions, SyncOptions } from '../types';
2
3
  import { NativeRNAppZungCodePushModule } from './NativeRNAppZungCodePushModule';
3
4
  import type { LatestRollbackInfo } from './types';
@@ -20,17 +21,17 @@ function validateLatestRollbackInfo(latestRollbackInfo: LatestRollbackInfo, pack
20
21
 
21
22
  function validateRollbackRetryOptions(rollbackRetryOptions: RollbackRetryOptions) {
22
23
  if (typeof rollbackRetryOptions.delayInHours !== 'number') {
23
- log("The 'delayInHours' rollback retry parameter must be a number.");
24
+ log(LogLevel.ERROR, "The 'delayInHours' rollback retry parameter must be a number.");
24
25
  return false;
25
26
  }
26
27
 
27
28
  if (typeof rollbackRetryOptions.maxRetryAttempts !== 'number') {
28
- log("The 'maxRetryAttempts' rollback retry parameter must be a number.");
29
+ log(LogLevel.ERROR, "The 'maxRetryAttempts' rollback retry parameter must be a number.");
29
30
  return false;
30
31
  }
31
32
 
32
33
  if (rollbackRetryOptions.maxRetryAttempts < 1) {
33
- log("The 'maxRetryAttempts' rollback retry parameter cannot be less then 1.");
34
+ log(LogLevel.ERROR, "The 'maxRetryAttempts' rollback retry parameter cannot be less then 1.");
34
35
  return false;
35
36
  }
36
37
 
@@ -61,14 +62,14 @@ export async function shouldUpdateBeIgnored(remotePackage: RemotePackage | null
61
62
 
62
63
  const latestRollbackInfo = await NativeRNAppZungCodePushModule.getLatestRollbackInfo();
63
64
  if (!validateLatestRollbackInfo(latestRollbackInfo, remotePackage.packageHash)) {
64
- log('The latest rollback info is not valid.');
65
+ log(LogLevel.ERROR, 'The latest rollback info is not valid.');
65
66
  return true;
66
67
  }
67
68
 
68
69
  const { delayInHours, maxRetryAttempts } = rollbackRetryOptions;
69
70
  const hoursSinceLatestRollback = (Date.now() - latestRollbackInfo.time) / (1000 * 60 * 60);
70
71
  if (hoursSinceLatestRollback >= delayInHours && maxRetryAttempts >= latestRollbackInfo.count) {
71
- log('Previous rollback should be ignored due to rollback retry options.');
72
+ log(LogLevel.INFO, 'Previous rollback should be ignored due to rollback retry options.');
72
73
  return false;
73
74
  }
74
75
 
@@ -1,6 +1,6 @@
1
- import type { Configuration as BaseConfiguration } from 'code-push/script/acquisition-sdk';
1
+ import type { ApiSdkConfiguration } from './CodePushApiSdk.types';
2
2
 
3
- export interface Configuration extends BaseConfiguration {
3
+ export interface Configuration extends ApiSdkConfiguration {
4
4
  releaseChannelPublicId: string;
5
5
  packageHash?: string;
6
6
  }
@@ -0,0 +1,72 @@
1
+ export async function fetchRetry(url: string, options: FetchRetryOptions = {}, attempt = 0): Promise<Response> {
2
+ const {
3
+ maxRetries = 3,
4
+ initialBackoff = 1000,
5
+ backoffMultiplier = 2,
6
+ maxRetryDelay = 30000,
7
+ ...fetchOptions
8
+ } = options;
9
+
10
+ try {
11
+ const response = await fetch(url, fetchOptions);
12
+ if (response.ok || !(response.status === 429 || response.status >= 500)) {
13
+ return response;
14
+ }
15
+
16
+ if (attempt >= maxRetries) {
17
+ return response;
18
+ }
19
+
20
+ const retryAfter = parseRetryAfterHeader(response);
21
+ if (retryAfter && retryAfter > maxRetryDelay) {
22
+ return response;
23
+ }
24
+
25
+ const delay = retryAfter ?? addJitter(initialBackoff * Math.pow(backoffMultiplier, attempt));
26
+
27
+ await new Promise((resolve) => setTimeout(resolve, delay));
28
+
29
+ return fetchRetry(url, options, attempt + 1);
30
+ } catch (error) {
31
+ if (attempt >= maxRetries) {
32
+ throw error;
33
+ }
34
+
35
+ const delay = addJitter(initialBackoff * Math.pow(backoffMultiplier, attempt));
36
+
37
+ await new Promise((resolve) => setTimeout(resolve, delay));
38
+
39
+ return fetchRetry(url, options, attempt + 1);
40
+ }
41
+ }
42
+
43
+ interface FetchRetryOptions extends RequestInit {
44
+ maxRetries?: number;
45
+ initialBackoff?: number;
46
+ backoffMultiplier?: number;
47
+ maxRetryDelay?: number;
48
+ }
49
+
50
+ function parseRetryAfterHeader(response: Response): number | null {
51
+ const retryAfter = response.headers.get('Retry-After');
52
+ if (!retryAfter) {
53
+ return null;
54
+ }
55
+
56
+ if (!isNaN(Number(retryAfter))) {
57
+ return parseInt(retryAfter, 10) * 1000;
58
+ }
59
+
60
+ try {
61
+ const retryDate = new Date(retryAfter).getTime();
62
+ const now = Date.now();
63
+ return retryDate > now ? retryDate - now : 0;
64
+ } catch (e) {
65
+ return null;
66
+ }
67
+ }
68
+
69
+ function addJitter(delay: number): number {
70
+ const jitterFactor = 0.5 + Math.random() * 0.5;
71
+ return Math.floor(delay * jitterFactor);
72
+ }
@@ -1,4 +1,12 @@
1
+ import type { LogLevel } from '../../enums/LogLevel.enum';
2
+ import { getLogLevel } from '../../logLevel';
3
+
1
4
  /* Logs messages to console with the [CodePush] prefix */
2
- export function log(message: string): void {
5
+ export function log(level: LogLevel, message: string): void {
6
+ const currentLogLevel = getLogLevel();
7
+ if (level < currentLogLevel) {
8
+ return;
9
+ }
10
+
3
11
  console.log(`[CodePush] ${message}`);
4
12
  }
@@ -0,0 +1,22 @@
1
+ export function queryStringify(object: { [key: string]: any }): string {
2
+ let queryString = '';
3
+ let isFirst = true;
4
+
5
+ for (const property in object) {
6
+ if (object.hasOwnProperty(property)) {
7
+ const value = object[property];
8
+ if (value !== null && typeof value !== 'undefined') {
9
+ if (!isFirst) {
10
+ queryString += '&';
11
+ }
12
+
13
+ queryString += encodeURIComponent(property) + '=';
14
+ queryString += encodeURIComponent(value);
15
+ }
16
+
17
+ isFirst = false;
18
+ }
19
+ }
20
+
21
+ return queryString;
22
+ }
@@ -0,0 +1,36 @@
1
+ import { LogLevel } from '../../enums/LogLevel.enum';
2
+ import type { Http } from '../CodePushApiSdk.types';
3
+ import { version } from '../version';
4
+ import { fetchRetry } from './fetchRetry';
5
+ import { log } from './log';
6
+
7
+ export const requestFetchAdapter: Http.Requester = {
8
+ async request(method, url, requestBody) {
9
+ const headers = {
10
+ Accept: 'application/json',
11
+ 'Content-Type': 'application/json',
12
+ 'X-CodePush-Plugin-Name': '@appzung/react-native-code-push',
13
+ 'X-CodePush-Plugin-Version': version,
14
+ };
15
+
16
+ if (requestBody && typeof requestBody === 'object') {
17
+ requestBody = JSON.stringify(requestBody);
18
+ }
19
+
20
+ const requestId = Math.round(Math.random() * 10000);
21
+ log(LogLevel.DEBUG, `[${requestId}] Will fetch ${method} ${url}`);
22
+
23
+ const response = await fetchRetry(url, {
24
+ method,
25
+ headers,
26
+ body: requestBody,
27
+ });
28
+
29
+ const statusCode = response.status;
30
+
31
+ log(LogLevel.DEBUG, `[${requestId}] Done fetching with status code ${statusCode}`);
32
+
33
+ const body = await response.text();
34
+ return { statusCode, body };
35
+ },
36
+ };
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '10.1.0';
2
+ export const version = '10.1.2';
@@ -0,0 +1,9 @@
1
+ import { LogLevel } from './enums/LogLevel.enum';
2
+
3
+ let logLevel = LogLevel.INFO;
4
+
5
+ export const setLogLevel = (level: LogLevel) => {
6
+ logLevel = level;
7
+ };
8
+
9
+ export const getLogLevel = () => logLevel;
@@ -1,9 +1,10 @@
1
1
  import { AppState, type NativeEventSubscription } from 'react-native';
2
+ import { LogLevel } from './enums/LogLevel.enum';
3
+ import { CodePushApiSdk } from './internals/CodePushApiSdk';
2
4
  import { NativeRNAppZungCodePushModule } from './internals/NativeRNAppZungCodePushModule';
3
5
  import { getConfiguration } from './internals/getConfiguration';
4
- import { getPromisifiedSdk } from './internals/getPromisifiedSdk';
5
6
  import { log } from './internals/utils/log';
6
- import { requestFetchAdapter } from './internals/utils/request-fetch-adapter';
7
+ import { requestFetchAdapter } from './internals/utils/requestFetchAdapter';
7
8
  import type { StatusReport } from './types';
8
9
 
9
10
  /**
@@ -26,32 +27,35 @@ export const notifyAppReady = (() => {
26
27
  })();
27
28
 
28
29
  async function notifyApplicationReadyInternal() {
30
+ log(LogLevel.DEBUG, 'notifyApplicationReady');
31
+
29
32
  await NativeRNAppZungCodePushModule.notifyApplicationReady();
30
33
  const statusReport = await NativeRNAppZungCodePushModule.getNewStatusReport();
31
- statusReport && tryReportStatus(statusReport); // Don't wait for this to complete.
34
+ if (statusReport) {
35
+ log(LogLevel.DEBUG, `tryReportStatus ${statusReport.status || '(no update)'}`);
36
+
37
+ tryReportStatus(statusReport); // Don't wait for this to complete.
38
+ } else {
39
+ log(LogLevel.DEBUG, `Nothing to report`);
40
+ }
32
41
 
33
42
  return statusReport;
34
43
  }
35
44
 
36
45
  async function tryReportStatus(statusReport: StatusReport, retryOnAppResume?: NativeEventSubscription) {
37
46
  const config = await getConfiguration();
38
- const previousLabelOrAppVersion = statusReport.previousLabelOrAppVersion;
47
+ const previousLabelOrAppVersion = statusReport.previousLabelOrAppVersion ?? null;
39
48
  const previousReleaseChannelPublicId = statusReport.previousReleaseChannelPublicId || config.releaseChannelPublicId;
40
49
  try {
41
50
  if (statusReport.appVersion) {
42
- log(`Reporting binary update (${statusReport.appVersion})`);
51
+ log(LogLevel.INFO, `Reporting binary update (${statusReport.appVersion})`);
43
52
 
44
53
  if (!config.releaseChannelPublicId) {
45
54
  throw new Error('Release channel is missing');
46
55
  }
47
56
 
48
- const sdk = getPromisifiedSdk(requestFetchAdapter, config);
49
- await sdk.reportStatusDeploy(
50
- /* deployedPackage */ undefined,
51
- /* status */ undefined,
52
- previousLabelOrAppVersion,
53
- previousReleaseChannelPublicId,
54
- );
57
+ const sdk = new CodePushApiSdk(requestFetchAdapter, config);
58
+ await sdk.reportStatusDeploy(null, previousLabelOrAppVersion, previousReleaseChannelPublicId);
55
59
  } else {
56
60
  if (!statusReport.package) {
57
61
  throw new Error('Missing package in status report');
@@ -59,17 +63,19 @@ async function tryReportStatus(statusReport: StatusReport, retryOnAppResume?: Na
59
63
 
60
64
  const label = statusReport.package.label;
61
65
  if (statusReport.status === 'DeploymentSucceeded') {
62
- log(`Reporting CodePush update success (${label})`);
66
+ log(LogLevel.INFO, `Reporting CodePush update success (${label})`);
63
67
  } else {
64
- log(`Reporting CodePush update rollback (${label})`);
68
+ log(LogLevel.INFO, `Reporting CodePush update rollback (${label})`);
65
69
  await NativeRNAppZungCodePushModule.setLatestRollbackInfo(statusReport.package.packageHash);
66
70
  }
67
71
 
68
72
  config.releaseChannelPublicId = statusReport.package.releaseChannelPublicId;
69
- const sdk = getPromisifiedSdk(requestFetchAdapter, config);
73
+ const sdk = new CodePushApiSdk(requestFetchAdapter, config);
70
74
  await sdk.reportStatusDeploy(
71
- { ...statusReport.package, deploymentKey: statusReport.package.releaseChannelPublicId },
72
- statusReport.status,
75
+ {
76
+ package: statusReport.package,
77
+ status: statusReport.status,
78
+ },
73
79
  previousLabelOrAppVersion,
74
80
  previousReleaseChannelPublicId,
75
81
  );
@@ -78,7 +84,7 @@ async function tryReportStatus(statusReport: StatusReport, retryOnAppResume?: Na
78
84
  NativeRNAppZungCodePushModule.recordStatusReported(statusReport);
79
85
  retryOnAppResume && retryOnAppResume.remove();
80
86
  } catch (e) {
81
- log(`Report status failed: ${JSON.stringify(statusReport)}`);
87
+ log(LogLevel.WARN, `Report status failed: ${JSON.stringify(statusReport)}`);
82
88
  NativeRNAppZungCodePushModule.saveStatusReportForRetry(statusReport);
83
89
  // Try again when the app resumes
84
90
  if (!retryOnAppResume) {
@@ -86,6 +92,7 @@ async function tryReportStatus(statusReport: StatusReport, retryOnAppResume?: Na
86
92
  if (newState !== 'active') return;
87
93
  const refreshedStatusReport = await NativeRNAppZungCodePushModule.getNewStatusReport();
88
94
  if (refreshedStatusReport) {
95
+ log(LogLevel.DEBUG, `tryReportStatus on active appState ${statusReport.status || '(no update)'}`);
89
96
  tryReportStatus(refreshedStatusReport, resumeListener);
90
97
  } else {
91
98
  resumeListener && resumeListener.remove();
package/src/sync.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Alert, type AlertButton, Platform } from 'react-native';
2
2
  import { checkForUpdate } from './checkForUpdates';
3
3
  import { InstallMode } from './enums/InstallMode.enum';
4
+ import { LogLevel } from './enums/LogLevel.enum';
4
5
  import { SyncStatus } from './enums/SyncStatus.enum';
5
6
  import { getCurrentPackage } from './internals/getCurrentPackage';
6
7
  import { shouldUpdateBeIgnored } from './internals/shouldUpdateBeIgnored';
@@ -62,38 +63,39 @@ async function syncInternal(
62
63
  : (syncStatus: SyncStatus) => {
63
64
  switch (syncStatus) {
64
65
  case SyncStatus.CHECKING_FOR_UPDATE:
65
- log('Checking for update.');
66
+ log(LogLevel.INFO, 'Checking for update.');
66
67
  break;
67
68
  case SyncStatus.AWAITING_USER_ACTION:
68
- log('Awaiting user action.');
69
+ log(LogLevel.INFO, 'Awaiting user action.');
69
70
  break;
70
71
  case SyncStatus.DOWNLOADING_PACKAGE:
71
- log('Downloading package.');
72
+ log(LogLevel.INFO, 'Downloading package.');
72
73
  break;
73
74
  case SyncStatus.INSTALLING_UPDATE:
74
- log('Installing update.');
75
+ log(LogLevel.INFO, 'Installing update.');
75
76
  break;
76
77
  case SyncStatus.UP_TO_DATE:
77
- log('App is up to date.');
78
+ log(LogLevel.INFO, 'App is up to date.');
78
79
  break;
79
80
  case SyncStatus.UPDATE_IGNORED:
80
- log('User cancelled the update.');
81
+ log(LogLevel.INFO, 'User cancelled the update.');
81
82
  break;
82
83
  case SyncStatus.UPDATE_INSTALLED:
83
84
  if (resolvedInstallMode == InstallMode.ON_NEXT_RESTART) {
84
- log('Update is installed and will be run on the next app restart.');
85
+ log(LogLevel.INFO, 'Update is installed and will be run on the next app restart.');
85
86
  } else if (resolvedInstallMode == InstallMode.ON_NEXT_RESUME) {
86
87
  if (!!syncOptions.minimumBackgroundDuration) {
87
88
  log(
89
+ LogLevel.INFO,
88
90
  `Update is installed and will be run after the app has been in the background for at least ${syncOptions.minimumBackgroundDuration} seconds.`,
89
91
  );
90
92
  } else {
91
- log('Update is installed and will be run when the app next resumes.');
93
+ log(LogLevel.INFO, 'Update is installed and will be run when the app next resumes.');
92
94
  }
93
95
  }
94
96
  break;
95
97
  case SyncStatus.UNKNOWN_ERROR:
96
- log('An unknown error occurred.');
98
+ log(LogLevel.ERROR, 'An unknown error occurred.');
97
99
  break;
98
100
  }
99
101
  };
@@ -127,7 +129,10 @@ async function syncInternal(
127
129
 
128
130
  if (!remotePackage || updateShouldBeIgnored) {
129
131
  if (updateShouldBeIgnored) {
130
- log('An update is available, but it is being ignored due to having been previously rolled back.');
132
+ log(
133
+ LogLevel.INFO,
134
+ 'An update is available, but it is being ignored due to having been previously rolled back.',
135
+ );
131
136
  }
132
137
 
133
138
  const currentPackage = await getCurrentPackage();
@@ -195,6 +200,7 @@ async function syncInternal(
195
200
  } catch (error) {
196
201
  syncStatusChangeCallback(SyncStatus.UNKNOWN_ERROR);
197
202
  log(
203
+ LogLevel.ERROR,
198
204
  error != null && typeof error === 'object' && 'message' in error && typeof error.message === 'string'
199
205
  ? error.message
200
206
  : 'Unknown',
@@ -228,25 +234,29 @@ export const sync = (() => {
228
234
  downloadProgressCallback?: DownloadProgressCallback,
229
235
  handleBinaryVersionMismatchCallback?: HandleBinaryVersionMismatchCallback,
230
236
  ): Promise<SyncStatus> => {
231
- let syncStatusCallbackWithTryCatch: SyncStatusChangedCallback | undefined;
232
- let downloadProgressCallbackWithTryCatch: DownloadProgressCallback | undefined;
237
+ log(LogLevel.DEBUG, `sync start`);
233
238
 
234
- if (typeof syncStatusChangedCallback === 'function') {
235
- syncStatusCallbackWithTryCatch = (...args) => {
236
- try {
237
- syncStatusChangedCallback(...args);
238
- } catch (error) {
239
- log(`An error has occurred : ${error instanceof Error ? error.stack : 'unknown'}`);
240
- }
241
- };
242
- }
239
+ let syncStatusCallbackWithTryCatch: SyncStatusChangedCallback = (status) => {
240
+ log(LogLevel.DEBUG, `sync status ${SyncStatus[status]}`);
243
241
 
242
+ if (typeof syncStatusChangedCallback !== 'function') {
243
+ return;
244
+ }
245
+
246
+ try {
247
+ syncStatusChangedCallback(status);
248
+ } catch (error) {
249
+ log(LogLevel.ERROR, `An error has occurred : ${error instanceof Error ? error.stack : 'unknown'}`);
250
+ }
251
+ };
252
+
253
+ let downloadProgressCallbackWithTryCatch: DownloadProgressCallback | undefined;
244
254
  if (typeof downloadProgressCallback === 'function') {
245
255
  downloadProgressCallbackWithTryCatch = (...args) => {
246
256
  try {
247
257
  downloadProgressCallback(...args);
248
258
  } catch (error) {
249
- log(`An error has occurred: ${error instanceof Error ? error.stack : 'unknown'}`);
259
+ log(LogLevel.ERROR, `An error has occurred: ${error instanceof Error ? error.stack : 'unknown'}`);
250
260
  }
251
261
  };
252
262
  }
@@ -254,7 +264,7 @@ export const sync = (() => {
254
264
  if (syncInProgress) {
255
265
  typeof syncStatusCallbackWithTryCatch === 'function'
256
266
  ? syncStatusCallbackWithTryCatch(SyncStatus.SYNC_IN_PROGRESS)
257
- : log('Sync already in progress.');
267
+ : log(LogLevel.WARN, 'Sync already in progress.');
258
268
  return Promise.resolve(SyncStatus.SYNC_IN_PROGRESS);
259
269
  }
260
270
 
package/src/types.ts CHANGED
@@ -1,7 +1,6 @@
1
- import type { NativeUpdateNotification } from 'code-push/script/acquisition-sdk';
2
- import type { DeploymentStatus } from './enums/DeploymentStatus.enum';
3
1
  import type { InstallMode } from './enums/InstallMode.enum';
4
2
  import type { SyncStatus } from './enums/SyncStatus.enum';
3
+ import { DeploymentStatus } from './internals/CodePushApiSdk.types';
5
4
 
6
5
  export interface UpdateDialog {
7
6
  /**
@@ -78,7 +77,7 @@ export type SyncStatusChangedCallback = (status: SyncStatus) => void;
78
77
  /**
79
78
  * Called when there are any binary update available.
80
79
  */
81
- export type HandleBinaryVersionMismatchCallback = (update: NativeUpdateNotification) => void;
80
+ export type HandleBinaryVersionMismatchCallback = (update: { appVersion: string }) => void;
82
81
 
83
82
  export interface DownloadProgress {
84
83
  /**
@@ -1 +0,0 @@
1
- {"version":3,"names":["DeploymentStatus","exports"],"sourceRoot":"../../../src","sources":["enums/DeploymentStatus.enum.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AAFA,IAGYA,gBAAgB,GAAAC,OAAA,CAAAD,gBAAA,0BAAhBA,gBAAgB;EAC1B;AACF;AACA;EAHYA,gBAAgB;EAM1B;AACF;AACA;EARYA,gBAAgB;EAAA,OAAhBA,gBAAgB;AAAA","ignoreList":[]}
@@ -1,9 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.AcquisitionSdk = void 0;
7
- var _acquisitionSdk = require("code-push/script/acquisition-sdk");
8
- const AcquisitionSdk = exports.AcquisitionSdk = _acquisitionSdk.AcquisitionManager;
9
- //# sourceMappingURL=AcquisitionSdk.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_acquisitionSdk","require","AcquisitionSdk","exports","AcquisitionManager"],"sourceRoot":"../../../src","sources":["internals/AcquisitionSdk.ts"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAEO,MAAMC,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAGE,kCAAkB","ignoreList":[]}