@appzung/react-native-code-push 10.1.1 → 10.2.1

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 (195) hide show
  1. package/android/app/src/main/java/com/appzung/codepush/react/CodePushConstants.java +2 -0
  2. package/android/app/src/main/java/com/appzung/codepush/react/CodePushNativeModule.java +62 -0
  3. package/ios/CodePush/CodePush.h +2 -0
  4. package/ios/CodePush/CodePush.m +28 -0
  5. package/ios/CodePush/CodePushConfig.m +50 -0
  6. package/lib/commonjs/CodePush.js +5 -0
  7. package/lib/commonjs/CodePush.js.map +1 -1
  8. package/lib/commonjs/allowRestart.js +4 -2
  9. package/lib/commonjs/allowRestart.js.map +1 -1
  10. package/lib/commonjs/checkForUpdates.js +3 -2
  11. package/lib/commonjs/checkForUpdates.js.map +1 -1
  12. package/lib/commonjs/clearUpdates.js +4 -2
  13. package/lib/commonjs/clearUpdates.js.map +1 -1
  14. package/lib/commonjs/dataTransmission.js +28 -0
  15. package/lib/commonjs/dataTransmission.js.map +1 -0
  16. package/lib/commonjs/disallowRestart.js +4 -2
  17. package/lib/commonjs/disallowRestart.js.map +1 -1
  18. package/lib/commonjs/enums/LogLevel.enum.js +17 -0
  19. package/lib/commonjs/enums/LogLevel.enum.js.map +1 -0
  20. package/lib/commonjs/index.js +60 -0
  21. package/lib/commonjs/index.js.map +1 -1
  22. package/lib/commonjs/internals/CodePushApiSdk.js +23 -1
  23. package/lib/commonjs/internals/CodePushApiSdk.js.map +1 -1
  24. package/lib/commonjs/internals/CodePushApiSdk.types.js.map +1 -1
  25. package/lib/commonjs/internals/RemotePackageImplementation.js +2 -1
  26. package/lib/commonjs/internals/RemotePackageImplementation.js.map +1 -1
  27. package/lib/commonjs/internals/logger.js +51 -0
  28. package/lib/commonjs/internals/logger.js.map +1 -0
  29. package/lib/commonjs/internals/shouldUpdateBeIgnored.js +6 -5
  30. package/lib/commonjs/internals/shouldUpdateBeIgnored.js.map +1 -1
  31. package/lib/commonjs/internals/utils/log.js +10 -3
  32. package/lib/commonjs/internals/utils/log.js.map +1 -1
  33. package/lib/commonjs/internals/utils/requestFetchAdapter.js +5 -0
  34. package/lib/commonjs/internals/utils/requestFetchAdapter.js.map +1 -1
  35. package/lib/commonjs/internals/version.js +1 -1
  36. package/lib/commonjs/logLevel.js +15 -0
  37. package/lib/commonjs/logLevel.js.map +1 -0
  38. package/lib/commonjs/logger.js +19 -0
  39. package/lib/commonjs/logger.js.map +1 -0
  40. package/lib/commonjs/notifyAppReady.js +17 -8
  41. package/lib/commonjs/notifyAppReady.js.map +1 -1
  42. package/lib/commonjs/restartApp.js +2 -2
  43. package/lib/commonjs/restartApp.js.map +1 -1
  44. package/lib/commonjs/sync.js +32 -27
  45. package/lib/commonjs/sync.js.map +1 -1
  46. package/lib/commonjs/telemetry.js +28 -0
  47. package/lib/commonjs/telemetry.js.map +1 -0
  48. package/lib/module/CodePush.js +5 -0
  49. package/lib/module/CodePush.js.map +1 -1
  50. package/lib/module/allowRestart.js +3 -1
  51. package/lib/module/allowRestart.js.map +1 -1
  52. package/lib/module/checkForUpdates.js +3 -2
  53. package/lib/module/checkForUpdates.js.map +1 -1
  54. package/lib/module/clearUpdates.js +3 -1
  55. package/lib/module/clearUpdates.js.map +1 -1
  56. package/lib/module/dataTransmission.js +24 -0
  57. package/lib/module/dataTransmission.js.map +1 -0
  58. package/lib/module/disallowRestart.js +3 -1
  59. package/lib/module/disallowRestart.js.map +1 -1
  60. package/lib/module/enums/LogLevel.enum.js +13 -0
  61. package/lib/module/enums/LogLevel.enum.js.map +1 -0
  62. package/lib/module/index.js +5 -0
  63. package/lib/module/index.js.map +1 -1
  64. package/lib/module/internals/CodePushApiSdk.js +23 -1
  65. package/lib/module/internals/CodePushApiSdk.js.map +1 -1
  66. package/lib/module/internals/CodePushApiSdk.types.js.map +1 -1
  67. package/lib/module/internals/RemotePackageImplementation.js +2 -1
  68. package/lib/module/internals/RemotePackageImplementation.js.map +1 -1
  69. package/lib/module/internals/logger.js +44 -0
  70. package/lib/module/internals/logger.js.map +1 -0
  71. package/lib/module/internals/shouldUpdateBeIgnored.js +6 -5
  72. package/lib/module/internals/shouldUpdateBeIgnored.js.map +1 -1
  73. package/lib/module/internals/utils/log.js +11 -3
  74. package/lib/module/internals/utils/log.js.map +1 -1
  75. package/lib/module/internals/utils/requestFetchAdapter.js +5 -0
  76. package/lib/module/internals/utils/requestFetchAdapter.js.map +1 -1
  77. package/lib/module/internals/version.js +1 -1
  78. package/lib/module/logLevel.js +9 -0
  79. package/lib/module/logLevel.js.map +1 -0
  80. package/lib/module/logger.js +4 -0
  81. package/lib/module/logger.js.map +1 -0
  82. package/lib/module/notifyAppReady.js +17 -8
  83. package/lib/module/notifyAppReady.js.map +1 -1
  84. package/lib/module/restartApp.js +2 -2
  85. package/lib/module/restartApp.js.map +1 -1
  86. package/lib/module/sync.js +32 -27
  87. package/lib/module/sync.js.map +1 -1
  88. package/lib/module/telemetry.js +24 -0
  89. package/lib/module/telemetry.js.map +1 -0
  90. package/lib/typescript/commonjs/src/CodePush.d.ts.map +1 -1
  91. package/lib/typescript/commonjs/src/allowRestart.d.ts +1 -1
  92. package/lib/typescript/commonjs/src/allowRestart.d.ts.map +1 -1
  93. package/lib/typescript/commonjs/src/checkForUpdates.d.ts.map +1 -1
  94. package/lib/typescript/commonjs/src/clearUpdates.d.ts +1 -1
  95. package/lib/typescript/commonjs/src/clearUpdates.d.ts.map +1 -1
  96. package/lib/typescript/commonjs/src/dataTransmission.d.ts +13 -0
  97. package/lib/typescript/commonjs/src/dataTransmission.d.ts.map +1 -0
  98. package/lib/typescript/commonjs/src/disallowRestart.d.ts +1 -1
  99. package/lib/typescript/commonjs/src/disallowRestart.d.ts.map +1 -1
  100. package/lib/typescript/commonjs/src/enums/LogLevel.enum.d.ts +10 -0
  101. package/lib/typescript/commonjs/src/enums/LogLevel.enum.d.ts.map +1 -0
  102. package/lib/typescript/commonjs/src/index.d.ts +5 -0
  103. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  104. package/lib/typescript/commonjs/src/internals/CodePushApiSdk.d.ts +3 -1
  105. package/lib/typescript/commonjs/src/internals/CodePushApiSdk.d.ts.map +1 -1
  106. package/lib/typescript/commonjs/src/internals/CodePushApiSdk.types.d.ts +2 -0
  107. package/lib/typescript/commonjs/src/internals/CodePushApiSdk.types.d.ts.map +1 -1
  108. package/lib/typescript/commonjs/src/internals/RNAppZungCodePushModuleSpec.d.ts +4 -0
  109. package/lib/typescript/commonjs/src/internals/RNAppZungCodePushModuleSpec.d.ts.map +1 -1
  110. package/lib/typescript/commonjs/src/internals/RemotePackageImplementation.d.ts.map +1 -1
  111. package/lib/typescript/commonjs/src/internals/logger.d.ts +33 -0
  112. package/lib/typescript/commonjs/src/internals/logger.d.ts.map +1 -0
  113. package/lib/typescript/commonjs/src/internals/shouldUpdateBeIgnored.d.ts.map +1 -1
  114. package/lib/typescript/commonjs/src/internals/utils/log.d.ts +2 -1
  115. package/lib/typescript/commonjs/src/internals/utils/log.d.ts.map +1 -1
  116. package/lib/typescript/commonjs/src/internals/utils/requestFetchAdapter.d.ts.map +1 -1
  117. package/lib/typescript/commonjs/src/internals/version.d.ts +1 -1
  118. package/lib/typescript/commonjs/src/logLevel.d.ts +4 -0
  119. package/lib/typescript/commonjs/src/logLevel.d.ts.map +1 -0
  120. package/lib/typescript/commonjs/src/logger.d.ts +3 -0
  121. package/lib/typescript/commonjs/src/logger.d.ts.map +1 -0
  122. package/lib/typescript/commonjs/src/notifyAppReady.d.ts +2 -0
  123. package/lib/typescript/commonjs/src/notifyAppReady.d.ts.map +1 -1
  124. package/lib/typescript/commonjs/src/restartApp.d.ts.map +1 -1
  125. package/lib/typescript/commonjs/src/sync.d.ts +2 -0
  126. package/lib/typescript/commonjs/src/sync.d.ts.map +1 -1
  127. package/lib/typescript/commonjs/src/telemetry.d.ts +13 -0
  128. package/lib/typescript/commonjs/src/telemetry.d.ts.map +1 -0
  129. package/lib/typescript/module/src/CodePush.d.ts.map +1 -1
  130. package/lib/typescript/module/src/allowRestart.d.ts +1 -1
  131. package/lib/typescript/module/src/allowRestart.d.ts.map +1 -1
  132. package/lib/typescript/module/src/checkForUpdates.d.ts.map +1 -1
  133. package/lib/typescript/module/src/clearUpdates.d.ts +1 -1
  134. package/lib/typescript/module/src/clearUpdates.d.ts.map +1 -1
  135. package/lib/typescript/module/src/dataTransmission.d.ts +13 -0
  136. package/lib/typescript/module/src/dataTransmission.d.ts.map +1 -0
  137. package/lib/typescript/module/src/disallowRestart.d.ts +1 -1
  138. package/lib/typescript/module/src/disallowRestart.d.ts.map +1 -1
  139. package/lib/typescript/module/src/enums/LogLevel.enum.d.ts +10 -0
  140. package/lib/typescript/module/src/enums/LogLevel.enum.d.ts.map +1 -0
  141. package/lib/typescript/module/src/index.d.ts +5 -0
  142. package/lib/typescript/module/src/index.d.ts.map +1 -1
  143. package/lib/typescript/module/src/internals/CodePushApiSdk.d.ts +3 -1
  144. package/lib/typescript/module/src/internals/CodePushApiSdk.d.ts.map +1 -1
  145. package/lib/typescript/module/src/internals/CodePushApiSdk.types.d.ts +2 -0
  146. package/lib/typescript/module/src/internals/CodePushApiSdk.types.d.ts.map +1 -1
  147. package/lib/typescript/module/src/internals/RNAppZungCodePushModuleSpec.d.ts +4 -0
  148. package/lib/typescript/module/src/internals/RNAppZungCodePushModuleSpec.d.ts.map +1 -1
  149. package/lib/typescript/module/src/internals/RemotePackageImplementation.d.ts.map +1 -1
  150. package/lib/typescript/module/src/internals/logger.d.ts +33 -0
  151. package/lib/typescript/module/src/internals/logger.d.ts.map +1 -0
  152. package/lib/typescript/module/src/internals/shouldUpdateBeIgnored.d.ts.map +1 -1
  153. package/lib/typescript/module/src/internals/utils/log.d.ts +2 -1
  154. package/lib/typescript/module/src/internals/utils/log.d.ts.map +1 -1
  155. package/lib/typescript/module/src/internals/utils/requestFetchAdapter.d.ts.map +1 -1
  156. package/lib/typescript/module/src/internals/version.d.ts +1 -1
  157. package/lib/typescript/module/src/logLevel.d.ts +4 -0
  158. package/lib/typescript/module/src/logLevel.d.ts.map +1 -0
  159. package/lib/typescript/module/src/logger.d.ts +3 -0
  160. package/lib/typescript/module/src/logger.d.ts.map +1 -0
  161. package/lib/typescript/module/src/notifyAppReady.d.ts +2 -0
  162. package/lib/typescript/module/src/notifyAppReady.d.ts.map +1 -1
  163. package/lib/typescript/module/src/restartApp.d.ts.map +1 -1
  164. package/lib/typescript/module/src/sync.d.ts +2 -0
  165. package/lib/typescript/module/src/sync.d.ts.map +1 -1
  166. package/lib/typescript/module/src/telemetry.d.ts +13 -0
  167. package/lib/typescript/module/src/telemetry.d.ts.map +1 -0
  168. package/package.json +23 -14
  169. package/scripts/generateBundledResourcesHash.js +73 -68
  170. package/scripts/getFilesInFolder.js +12 -12
  171. package/scripts/recordFilesBeforeBundleCommand.js +19 -20
  172. package/src/CodePush.tsx +6 -0
  173. package/src/allowRestart.ts +3 -1
  174. package/src/checkForUpdates.ts +3 -2
  175. package/src/clearUpdates.ts +3 -1
  176. package/src/dataTransmission.ts +21 -0
  177. package/src/disallowRestart.ts +3 -1
  178. package/src/enums/LogLevel.enum.ts +9 -0
  179. package/src/index.ts +5 -0
  180. package/src/internals/CodePushApiSdk.ts +27 -0
  181. package/src/internals/CodePushApiSdk.types.ts +2 -0
  182. package/src/internals/RNAppZungCodePushModuleSpec.ts +6 -0
  183. package/src/internals/RemotePackageImplementation.ts +2 -1
  184. package/src/internals/logger.ts +46 -0
  185. package/src/internals/shouldUpdateBeIgnored.ts +6 -5
  186. package/src/internals/utils/log.ts +13 -3
  187. package/src/internals/utils/requestFetchAdapter.ts +8 -0
  188. package/src/internals/version.ts +1 -1
  189. package/src/logLevel.ts +9 -0
  190. package/src/logger.ts +2 -0
  191. package/src/notifyAppReady.ts +19 -7
  192. package/src/restartApp.ts +2 -2
  193. package/src/sync.ts +38 -26
  194. package/src/telemetry.ts +21 -0
  195. package/typedoc.json +0 -9
@@ -11,16 +11,16 @@
11
11
  * manifest to generate the final hash, which is saved to the APK's assets directory.
12
12
  */
13
13
 
14
- var crypto = require("crypto");
15
- var fs = require("fs");
16
- var path = require("path");
14
+ var crypto = require('crypto');
15
+ var fs = require('fs');
16
+ var path = require('path');
17
17
 
18
- var getFilesInFolder = require("./getFilesInFolder");
18
+ var getFilesInFolder = require('./getFilesInFolder');
19
19
 
20
- var CODE_PUSH_FOLDER_PREFIX = "CodePush";
21
- var CODE_PUSH_HASH_FILE_NAME = "CodePushHash";
22
- var CODE_PUSH_HASH_OLD_FILE_NAME = "CodePushHash.json";
23
- var HASH_ALGORITHM = "sha256";
20
+ var CODE_PUSH_FOLDER_PREFIX = 'CodePush';
21
+ var CODE_PUSH_HASH_FILE_NAME = 'CodePushHash';
22
+ var CODE_PUSH_HASH_OLD_FILE_NAME = 'CodePushHash.json';
23
+ var HASH_ALGORITHM = 'sha256';
24
24
 
25
25
  var resourcesDir = process.argv[2];
26
26
  var jsBundleFilePath = process.argv[3];
@@ -30,8 +30,8 @@ var tempFileName = process.argv[5];
30
30
  var oldFileToModifiedTimeMap = {};
31
31
  var tempFileLocalPath = null;
32
32
  if (tempFileName) {
33
- tempFileLocalPath = path.join(require("os").tmpdir(), tempFileName);
34
- oldFileToModifiedTimeMap = require(tempFileLocalPath);
33
+ tempFileLocalPath = path.join(require('os').tmpdir(), tempFileName);
34
+ oldFileToModifiedTimeMap = require(tempFileLocalPath);
35
35
  }
36
36
  var resourceFiles = [];
37
37
 
@@ -39,87 +39,92 @@ getFilesInFolder(resourcesDir, resourceFiles);
39
39
 
40
40
  var newFileToModifiedTimeMap = {};
41
41
 
42
- resourceFiles.forEach(function(resourceFile) {
43
- newFileToModifiedTimeMap[resourceFile.path.substring(resourcesDir.length)] = resourceFile.mtime;
42
+ resourceFiles.forEach(function (resourceFile) {
43
+ newFileToModifiedTimeMap[resourceFile.path.substring(resourcesDir.length)] = resourceFile.mtime;
44
44
  });
45
45
 
46
46
  var bundleGeneratedAssetFiles = [];
47
47
 
48
48
  for (var newFilePath in newFileToModifiedTimeMap) {
49
- if (!oldFileToModifiedTimeMap[newFilePath] || oldFileToModifiedTimeMap[newFilePath] < newFileToModifiedTimeMap[newFilePath].getTime()) {
50
- bundleGeneratedAssetFiles.push(newFilePath);
51
- }
49
+ if (
50
+ !oldFileToModifiedTimeMap[newFilePath] ||
51
+ oldFileToModifiedTimeMap[newFilePath] < newFileToModifiedTimeMap[newFilePath].getTime()
52
+ ) {
53
+ bundleGeneratedAssetFiles.push(newFilePath);
54
+ }
52
55
  }
53
56
 
54
57
  var manifest = [];
55
58
 
56
59
  if (bundleGeneratedAssetFiles.length) {
57
- bundleGeneratedAssetFiles.forEach(function(assetFile) {
58
- // Generate hash for each asset file
59
- addFileToManifest(resourcesDir, assetFile, manifest, function() {
60
- if (manifest.length === bundleGeneratedAssetFiles.length) {
61
- addJsBundleAndMetaToManifest();
62
- }
63
- });
60
+ bundleGeneratedAssetFiles.forEach(function (assetFile) {
61
+ // Generate hash for each asset file
62
+ addFileToManifest(resourcesDir, assetFile, manifest, function () {
63
+ if (manifest.length === bundleGeneratedAssetFiles.length) {
64
+ addJsBundleAndMetaToManifest();
65
+ }
64
66
  });
67
+ });
65
68
  } else {
66
- addJsBundleAndMetaToManifest();
69
+ addJsBundleAndMetaToManifest();
67
70
  }
68
71
 
69
72
  function addJsBundleAndMetaToManifest() {
70
- addFileToManifest(path.dirname(jsBundleFilePath), path.basename(jsBundleFilePath), manifest, function() {
71
- var jsBundleMetaFilePath = jsBundleFilePath + ".meta";
72
- addFileToManifest(path.dirname(jsBundleMetaFilePath), path.basename(jsBundleMetaFilePath), manifest, function() {
73
- manifest = manifest.sort();
74
- var finalHash = crypto.createHash(HASH_ALGORITHM)
75
- .update(JSON.stringify(manifest))
76
- .digest("hex");
77
-
78
- console.log(finalHash);
79
-
80
- var savedResourcesManifestPath = assetsDir + "/" + CODE_PUSH_HASH_FILE_NAME;
81
- fs.writeFileSync(savedResourcesManifestPath, finalHash);
82
-
83
- // "CodePushHash.json" file name breaks flow type checking.
84
- // To fix the issue we need to delete "CodePushHash.json" file and
85
- // use "CodePushHash" file name instead to store the hash value.
86
- // Relates to https://github.com/microsoft/react-native-code-push/issues/577
87
- var oldSavedResourcesManifestPath = assetsDir + "/" + CODE_PUSH_HASH_OLD_FILE_NAME;
88
- if (fs.existsSync(oldSavedResourcesManifestPath)) {
89
- fs.unlinkSync(oldSavedResourcesManifestPath);
90
- }
91
- });
73
+ addFileToManifest(path.dirname(jsBundleFilePath), path.basename(jsBundleFilePath), manifest, function () {
74
+ var jsBundleMetaFilePath = jsBundleFilePath + '.meta';
75
+ addFileToManifest(path.dirname(jsBundleMetaFilePath), path.basename(jsBundleMetaFilePath), manifest, function () {
76
+ manifest = manifest.sort();
77
+ var finalHash = crypto.createHash(HASH_ALGORITHM).update(JSON.stringify(manifest)).digest('hex');
78
+
79
+ console.log(finalHash);
80
+
81
+ var savedResourcesManifestPath = assetsDir + '/' + CODE_PUSH_HASH_FILE_NAME;
82
+ fs.writeFileSync(savedResourcesManifestPath, finalHash);
83
+
84
+ // "CodePushHash.json" file name breaks flow type checking.
85
+ // To fix the issue we need to delete "CodePushHash.json" file and
86
+ // use "CodePushHash" file name instead to store the hash value.
87
+ // Relates to https://github.com/microsoft/react-native-code-push/issues/577
88
+ var oldSavedResourcesManifestPath = assetsDir + '/' + CODE_PUSH_HASH_OLD_FILE_NAME;
89
+ if (fs.existsSync(oldSavedResourcesManifestPath)) {
90
+ fs.unlinkSync(oldSavedResourcesManifestPath);
91
+ }
92
92
  });
93
+ });
93
94
  }
94
95
 
95
96
  function addFileToManifest(folder, assetFile, manifest, done) {
96
- var fullFilePath = path.join(folder, assetFile);
97
- if (!fileExists(fullFilePath)) {
98
- done();
99
- return;
100
- }
101
-
102
- var readStream = fs.createReadStream(path.join(folder, assetFile));
103
- var hashStream = crypto.createHash(HASH_ALGORITHM);
104
-
105
- readStream.pipe(hashStream)
106
- .on("error", function(error) {
107
- throw error;
108
- })
109
- .on("finish", function() {
110
- hashStream.end();
111
- var buffer = hashStream.read();
112
- var fileHash = buffer.toString("hex");
113
- manifest.push(path.join(CODE_PUSH_FOLDER_PREFIX, assetFile).replace(/\\/g, "/") + ":" + fileHash);
114
- done();
115
- });
97
+ var fullFilePath = path.join(folder, assetFile);
98
+ if (!fileExists(fullFilePath)) {
99
+ done();
100
+ return;
101
+ }
102
+
103
+ var readStream = fs.createReadStream(path.join(folder, assetFile));
104
+ var hashStream = crypto.createHash(HASH_ALGORITHM);
105
+
106
+ readStream
107
+ .pipe(hashStream)
108
+ .on('error', function (error) {
109
+ throw error;
110
+ })
111
+ .on('finish', function () {
112
+ hashStream.end();
113
+ var buffer = hashStream.read();
114
+ var fileHash = buffer.toString('hex');
115
+ manifest.push(path.join(CODE_PUSH_FOLDER_PREFIX, assetFile).replace(/\\/g, '/') + ':' + fileHash);
116
+ done();
117
+ });
116
118
  }
117
119
 
118
120
  function fileExists(file) {
119
- try { return fs.statSync(file).isFile(); }
120
- catch (e) { return false; }
121
+ try {
122
+ return fs.statSync(file).isFile();
123
+ } catch {
124
+ return false;
125
+ }
121
126
  }
122
127
 
123
128
  if (tempFileLocalPath) {
124
- fs.unlinkSync(tempFileLocalPath);
129
+ fs.unlinkSync(tempFileLocalPath);
125
130
  }
@@ -1,19 +1,19 @@
1
- var fs = require("fs");
2
- var path = require("path");
1
+ var fs = require('fs');
2
+ var path = require('path');
3
3
 
4
4
  // Utility function that collects the stats of every file in a directory
5
5
  // as well as in its subdirectories.
6
6
  function getFilesInFolder(folderName, fileList) {
7
- var folderFiles = fs.readdirSync(folderName);
8
- folderFiles.forEach(function(file) {
9
- var fileStats = fs.statSync(path.join(folderName, file));
10
- if (fileStats.isDirectory()) {
11
- getFilesInFolder(path.join(folderName, file), fileList);
12
- } else {
13
- fileStats.path = path.join(folderName, file);
14
- fileList.push(fileStats);
15
- }
16
- });
7
+ var folderFiles = fs.readdirSync(folderName);
8
+ folderFiles.forEach(function (file) {
9
+ var fileStats = fs.statSync(path.join(folderName, file));
10
+ if (fileStats.isDirectory()) {
11
+ getFilesInFolder(path.join(folderName, file), fileList);
12
+ } else {
13
+ fileStats.path = path.join(folderName, file);
14
+ fileList.push(fileStats);
15
+ }
16
+ });
17
17
  }
18
18
 
19
19
  module.exports = getFilesInFolder;
@@ -1,41 +1,40 @@
1
1
  /*
2
2
  * This script creates a snapshot of the contents in the resource directory
3
3
  * by creating a map with the modified time of all the files in the directory
4
- * and saving it to a temp file. This snapshot is later referenced in
4
+ * and saving it to a temp file. This snapshot is later referenced in
5
5
  * "generatePackageHash.js" to figure out which files have changed or were
6
6
  * newly generated by the "react-native bundle" command.
7
7
  */
8
8
 
9
- var fs = require("fs");
10
- var path = require("path");
11
-
12
- var getFilesInFolder = require("./getFilesInFolder");
9
+ var fs = require('fs');
10
+ var path = require('path');
13
11
 
12
+ var getFilesInFolder = require('./getFilesInFolder');
14
13
 
15
14
  var resourcesDir = process.argv[2];
16
15
  var tempFileName = process.argv[3];
17
16
 
18
- var tempFileLocalPath = path.join(require("os").tmpdir(), tempFileName);
17
+ var tempFileLocalPath = path.join(require('os').tmpdir(), tempFileName);
19
18
  var resourceFiles = [];
20
19
 
21
20
  try {
22
- getFilesInFolder(resourcesDir, resourceFiles);
23
- } catch(error) {
24
- var targetPathNotFoundExceptionMessage = "\nResources directory path does not exist.\n";
25
- targetPathNotFoundExceptionMessage += "Unable to find '" + resourcesDir;
26
- targetPathNotFoundExceptionMessage += "' directory. Please check version of Android Plugin for Gradle.";
27
- error.message += targetPathNotFoundExceptionMessage;
28
- throw error;
21
+ getFilesInFolder(resourcesDir, resourceFiles);
22
+ } catch (error) {
23
+ var targetPathNotFoundExceptionMessage = '\nResources directory path does not exist.\n';
24
+ targetPathNotFoundExceptionMessage += "Unable to find '" + resourcesDir;
25
+ targetPathNotFoundExceptionMessage += "' directory. Please check version of Android Plugin for Gradle.";
26
+ error.message += targetPathNotFoundExceptionMessage;
27
+ throw error;
29
28
  }
30
29
 
31
30
  var fileToModifiedTimeMap = {};
32
31
 
33
- resourceFiles.forEach(function(resourceFile) {
34
- fileToModifiedTimeMap[resourceFile.path.substring(resourcesDir.length)] = resourceFile.mtime.getTime();
32
+ resourceFiles.forEach(function (resourceFile) {
33
+ fileToModifiedTimeMap[resourceFile.path.substring(resourcesDir.length)] = resourceFile.mtime.getTime();
35
34
  });
36
35
 
37
- fs.writeFile(tempFileLocalPath, JSON.stringify(fileToModifiedTimeMap), function(err) {
38
- if (err) {
39
- throw err;
40
- }
41
- });
36
+ fs.writeFile(tempFileLocalPath, JSON.stringify(fileToModifiedTimeMap), function (err) {
37
+ if (err) {
38
+ throw err;
39
+ }
40
+ });
package/src/CodePush.tsx CHANGED
@@ -2,6 +2,8 @@ import hoistStatics from 'hoist-non-react-statics';
2
2
  import React from 'react';
3
3
  import { AppState } from 'react-native';
4
4
  import { CheckFrequency } from './enums/CheckFrequency.enum';
5
+ import { LogLevel } from './enums/LogLevel.enum';
6
+ import { log } from './internals/utils/log';
5
7
  import { notifyAppReady } from './notifyAppReady';
6
8
  import { sync } from './sync';
7
9
  import type {
@@ -54,6 +56,8 @@ export function withCodePush<P extends object>(optionsOrComponent: CodePushOptio
54
56
  }
55
57
 
56
58
  componentDidMount() {
59
+ log(LogLevel.DEBUG, `withCodePush ${JSON.stringify(options)}`);
60
+
57
61
  if (options.checkFrequency === CheckFrequency.MANUAL) {
58
62
  notifyAppReady();
59
63
  } else {
@@ -75,11 +79,13 @@ export function withCodePush<P extends object>(optionsOrComponent: CodePushOptio
75
79
  rootComponentInstance.codePushOnBinaryVersionMismatch.bind(rootComponentInstance);
76
80
  }
77
81
 
82
+ log(LogLevel.DEBUG, `sync on mount`);
78
83
  sync(options, syncStatusCallback, downloadProgressCallback, handleBinaryVersionMismatchCallback);
79
84
 
80
85
  if (options.checkFrequency === CheckFrequency.ON_APP_RESUME) {
81
86
  AppState.addEventListener('change', (newState: string) => {
82
87
  if (newState === 'active') {
88
+ log(LogLevel.DEBUG, `sync on active appState`);
83
89
  sync(options, syncStatusCallback, downloadProgressCallback);
84
90
  }
85
91
  });
@@ -5,4 +5,6 @@ import { NativeRNAppZungCodePushModule } from './internals/NativeRNAppZungCodePu
5
5
  *
6
6
  * This is an advanced API and is only necessary if your app explicitly disallowed restarts via the `disallowRestart` method.
7
7
  */
8
- export const allowRestart: () => void = NativeRNAppZungCodePushModule.allow;
8
+ export function allowRestart() {
9
+ return NativeRNAppZungCodePushModule.allow();
10
+ }
@@ -1,4 +1,5 @@
1
1
  import { Platform } from 'react-native';
2
+ import { LogLevel } from './enums/LogLevel.enum';
2
3
  import { CodePushApiSdk } from './internals/CodePushApiSdk';
3
4
  import type { ApiSdkQueryUpdatePackageInfo } from './internals/CodePushApiSdk.types';
4
5
  import { NativeRNAppZungCodePushModule } from './internals/NativeRNAppZungCodePushModule';
@@ -38,7 +39,7 @@ export async function checkForUpdate(
38
39
  * release channels (e.g. an early access release channel for insiders).
39
40
  */
40
41
  const config: Configuration = releaseChannelPublicId ? { ...nativeConfig, releaseChannelPublicId } : nativeConfig;
41
- const sdk = new CodePushApiSdk(requestFetchAdapter, config);
42
+ const sdk = new CodePushApiSdk(requestFetchAdapter, log, config);
42
43
 
43
44
  const localPackage = await getCurrentPackage();
44
45
 
@@ -84,7 +85,7 @@ export async function checkForUpdate(
84
85
  throw new Error('updateAppVersion should never be false');
85
86
  }
86
87
 
87
- log('An update is available but it is not targeting the binary version of your app.');
88
+ log(LogLevel.INFO, 'An update is available but it is not targeting the binary version of your app.');
88
89
  handleBinaryVersionMismatchCallback?.(update);
89
90
 
90
91
  return null;
@@ -7,4 +7,6 @@ import { NativeRNAppZungCodePushModule } from './internals/NativeRNAppZungCodePu
7
7
  * Note: we don’t recommend using this method in scenarios other than that (CodePush will call
8
8
  * this method automatically when needed in other cases) as it could lead to unpredictable behavior.
9
9
  */
10
- export const clearUpdates: () => void = NativeRNAppZungCodePushModule.clearUpdates;
10
+ export function clearUpdates() {
11
+ return NativeRNAppZungCodePushModule.clearUpdates();
12
+ }
@@ -0,0 +1,21 @@
1
+ import { NativeRNAppZungCodePushModule } from './internals/NativeRNAppZungCodePushModule';
2
+ import { reloadCachedConfiguration } from './internals/getConfiguration';
3
+
4
+ /**
5
+ * Controls data transmission for CodePush. This may be used for privacy optIn.
6
+ *
7
+ * @param enabled - When false, disables all external API calls to CodePush servers. Checking for updates will be disabled.
8
+ */
9
+ export async function setDataTransmissionEnabled(enabled: boolean): Promise<void> {
10
+ await NativeRNAppZungCodePushModule.setDataTransmissionEnabled(enabled);
11
+ await reloadCachedConfiguration();
12
+ }
13
+
14
+ /**
15
+ * Gets the current data transmission status.
16
+ *
17
+ * When setDataTransmissionEnabled has never been called, returns the default value set in your configuration.
18
+ */
19
+ export function getDataTransmissionEnabled(): Promise<boolean> {
20
+ return NativeRNAppZungCodePushModule.getDataTransmissionEnabled();
21
+ }
@@ -5,4 +5,6 @@ import { NativeRNAppZungCodePushModule } from './internals/NativeRNAppZungCodePu
5
5
  *
6
6
  * This is an advanced API, and is useful when a component within your app (for example an onboarding process) needs to ensure that no end-user interruptions can occur during its lifetime.
7
7
  */
8
- export const disallowRestart: () => void = NativeRNAppZungCodePushModule.disallow;
8
+ export function disallowRestart() {
9
+ return NativeRNAppZungCodePushModule.disallow();
10
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Used to categorize log messages by their severity and importance.
3
+ */
4
+ export enum LogLevel {
5
+ DEBUG,
6
+ INFO,
7
+ WARN,
8
+ ERROR,
9
+ }
package/src/index.ts CHANGED
@@ -10,6 +10,10 @@ export * from './restartApp';
10
10
  export * from './sync';
11
11
  export * from './getClientUniqueId';
12
12
  export * from './resetClientUniqueId';
13
+ export * from './logLevel';
14
+ export * from './logger';
15
+ export * from './telemetry';
16
+ export * from './dataTransmission';
13
17
 
14
18
  export * from './types';
15
19
 
@@ -18,3 +22,4 @@ export * from './enums/InstallMode.enum';
18
22
  export * from './enums/UpdateState.enum';
19
23
  export { DeploymentStatus } from './internals/CodePushApiSdk.types';
20
24
  export * from './enums/CheckFrequency.enum';
25
+ export * from './enums/LogLevel.enum';
@@ -1,3 +1,4 @@
1
+ import { LogLevel } from '../enums/LogLevel.enum';
1
2
  import { CodePushError, CodePushHttpError } from './CodePushApiSdk.errors';
2
3
  import {
3
4
  type ApiSdkConfiguration,
@@ -22,6 +23,7 @@ export class CodePushApiSdk {
22
23
 
23
24
  constructor(
24
25
  private readonly httpRequester: Http.Requester,
26
+ private readonly log: (level: LogLevel, message: string) => void,
25
27
  configuration: ApiSdkConfiguration,
26
28
  ) {
27
29
  this.configuration = { ...configuration };
@@ -34,6 +36,11 @@ export class CodePushApiSdk {
34
36
  async queryUpdateWithCurrentPackage(
35
37
  currentPackageInfo: ApiSdkQueryUpdatePackageInfo,
36
38
  ): Promise<ApiSdkRemotePackage | ApiSdkNativeUpdateNotification | null> {
39
+ if (!this.configuration.dataTransmissionEnabled) {
40
+ this.log(LogLevel.DEBUG, 'Skipped querying for update because data transmission is disabled');
41
+ return null;
42
+ }
43
+
37
44
  const query: CheckUpdateRequestInput = {
38
45
  deployment_key: this.configuration.releaseChannelPublicId,
39
46
  app_version: currentPackageInfo.appVersion,
@@ -86,6 +93,16 @@ export class CodePushApiSdk {
86
93
  previousLabelOrAppVersion: string | null,
87
94
  previousDeploymentKey: string | null,
88
95
  ): Promise<void> {
96
+ if (!this.configuration.dataTransmissionEnabled) {
97
+ this.log(LogLevel.DEBUG, 'Skipped reporting deploy status because data transmission is disabled');
98
+ return;
99
+ }
100
+
101
+ if (!this.configuration.telemetryEnabled) {
102
+ this.log(LogLevel.DEBUG, 'Skipped reporting deploy status because telemetry is disabled');
103
+ return;
104
+ }
105
+
89
106
  const requestBody: ReportDeployInput = {
90
107
  app_version: this.configuration.appVersion,
91
108
  deployment_key: this.configuration.releaseChannelPublicId,
@@ -116,6 +133,16 @@ export class CodePushApiSdk {
116
133
  }
117
134
 
118
135
  async reportStatusDownload(downloadedPackage: ApiSdkDownloadReportPackageInfo): Promise<void> {
136
+ if (!this.configuration.dataTransmissionEnabled) {
137
+ this.log(LogLevel.DEBUG, 'Skipped reporting download because data transmission is disabled');
138
+ return;
139
+ }
140
+
141
+ if (!this.configuration.telemetryEnabled) {
142
+ this.log(LogLevel.DEBUG, 'Skipped reporting download because telemetry is disabled');
143
+ return;
144
+ }
145
+
119
146
  const requestBody: ReportDownloadInput = {
120
147
  client_unique_id: this.configuration.clientUniqueId,
121
148
  deployment_key: this.configuration.releaseChannelPublicId,
@@ -45,6 +45,8 @@ export interface ApiSdkConfiguration {
45
45
  clientUniqueId: string;
46
46
  releaseChannelPublicId: string;
47
47
  serverUrl: string;
48
+ dataTransmissionEnabled: boolean;
49
+ telemetryEnabled: boolean;
48
50
  ignoreAppVersion?: boolean;
49
51
  }
50
52
 
@@ -52,4 +52,10 @@ export interface Spec extends TurboModule {
52
52
 
53
53
  isFirstRun(packageHash: string): Promise<boolean>;
54
54
  isFailedUpdate(packageHash: string): Promise<boolean>;
55
+
56
+ setTelemetryEnabled(enabled: boolean): Promise<void>;
57
+ getTelemetryEnabled(): Promise<boolean>;
58
+
59
+ setDataTransmissionEnabled(enabled: boolean): Promise<void>;
60
+ getDataTransmissionEnabled(): Promise<boolean>;
55
61
  }
@@ -1,4 +1,5 @@
1
1
  import { NativeEventEmitter } from 'react-native';
2
+ import { LogLevel } from '../enums/LogLevel.enum';
2
3
  import type { DownloadProgressCallback, LocalPackage, RemotePackage } from '../types';
3
4
  import type { ApiSdkDownloadReportPackageInfo } from './CodePushApiSdk.types';
4
5
  import { LocalPackageImplementation } from './LocalPackageImplementation';
@@ -42,7 +43,7 @@ export class RemotePackageImpl implements RemotePackage {
42
43
  const reportPromise = reportStatusDownload({
43
44
  label: this.label,
44
45
  }).catch((error) => {
45
- log(`Report download status failed: ${error}`);
46
+ log(LogLevel.ERROR, `Report download status failed: ${error}`);
46
47
  });
47
48
  await Promise.race([timeoutPromise, reportPromise]);
48
49
  }
@@ -0,0 +1,46 @@
1
+ import type { LogLevel } from '../enums/LogLevel.enum';
2
+
3
+ export type LoggerFunction = (level: LogLevel, message: string) => void;
4
+
5
+ const defaultLogger: LoggerFunction = (_level: LogLevel, message: string): void => {
6
+ console.log(`[CodePush] ${message}`);
7
+ };
8
+
9
+ let currentLogger: LoggerFunction = defaultLogger;
10
+
11
+ /**
12
+ * Set a custom logger function to handle all CodePush logs
13
+ *
14
+ * @param logger A function that takes a log level and message and handles the logging
15
+ * @example
16
+ * ```
17
+ * import { setLogger, LogLevel } from '@appzung/react-native-code-push';
18
+ *
19
+ * // Custom logger that sends critical logs to a crash reporting service
20
+ * setLogger((level, message) => {
21
+ * // Always log to console
22
+ * console.log(`[CodePush] ${message}`);
23
+ *
24
+ * // Send error logs to crash reporting
25
+ * if (level === LogLevel.ERROR) {
26
+ * MyCrashReportingService.log(`CodePush error: ${message}`);
27
+ * }
28
+ * });
29
+ * ```
30
+ */
31
+ export const setLogger = (logger: LoggerFunction): void => {
32
+ currentLogger = logger;
33
+ };
34
+
35
+ /**
36
+ * Get the current logger function
37
+ * @returns The current logger function
38
+ */
39
+ export const getLogger = (): LoggerFunction => currentLogger;
40
+
41
+ /**
42
+ * Reset the logger to the default implementation
43
+ */
44
+ export const resetLogger = (): void => {
45
+ currentLogger = defaultLogger;
46
+ };
@@ -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,4 +1,14 @@
1
- /* Logs messages to console with the [CodePush] prefix */
2
- export function log(message: string): void {
3
- console.log(`[CodePush] ${message}`);
1
+ import type { LogLevel } from '../../enums/LogLevel.enum';
2
+ import { getLogLevel } from '../../logLevel';
3
+ import { getLogger } from '../logger';
4
+
5
+ /* Logs messages using the configured logger */
6
+ export function log(level: LogLevel, message: string): void {
7
+ const currentLogLevel = getLogLevel();
8
+ if (level < currentLogLevel) {
9
+ return;
10
+ }
11
+
12
+ const logger = getLogger();
13
+ logger(level, message);
4
14
  }
@@ -1,6 +1,8 @@
1
+ import { LogLevel } from '../../enums/LogLevel.enum';
1
2
  import type { Http } from '../CodePushApiSdk.types';
2
3
  import { version } from '../version';
3
4
  import { fetchRetry } from './fetchRetry';
5
+ import { log } from './log';
4
6
 
5
7
  export const requestFetchAdapter: Http.Requester = {
6
8
  async request(method, url, requestBody) {
@@ -15,6 +17,9 @@ export const requestFetchAdapter: Http.Requester = {
15
17
  requestBody = JSON.stringify(requestBody);
16
18
  }
17
19
 
20
+ const requestId = Math.round(Math.random() * 10000);
21
+ log(LogLevel.DEBUG, `[${requestId}] Will fetch ${method} ${url}`);
22
+
18
23
  const response = await fetchRetry(url, {
19
24
  method,
20
25
  headers,
@@ -22,6 +27,9 @@ export const requestFetchAdapter: Http.Requester = {
22
27
  });
23
28
 
24
29
  const statusCode = response.status;
30
+
31
+ log(LogLevel.DEBUG, `[${requestId}] Done fetching with status code ${statusCode}`);
32
+
25
33
  const body = await response.text();
26
34
  return { statusCode, body };
27
35
  },
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '10.1.1';
2
+ export const version = '10.2.1';