react-native-cloud-sync 0.1.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.
Files changed (268) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +360 -0
  3. package/app.plugin.js +3 -0
  4. package/ios/CloudSyncError.swift +144 -0
  5. package/ios/CloudSyncImpl.swift +1263 -0
  6. package/ios/RNCloudSync.h +25 -0
  7. package/ios/RNCloudSync.mm +477 -0
  8. package/jest-mock.js +136 -0
  9. package/lib/commonjs/config.js +85 -0
  10. package/lib/commonjs/config.js.map +1 -0
  11. package/lib/commonjs/errors.js +244 -0
  12. package/lib/commonjs/errors.js.map +1 -0
  13. package/lib/commonjs/hooks.js +257 -0
  14. package/lib/commonjs/hooks.js.map +1 -0
  15. package/lib/commonjs/index.js +244 -0
  16. package/lib/commonjs/index.js.map +1 -0
  17. package/lib/commonjs/internal/autoFlush.js +65 -0
  18. package/lib/commonjs/internal/autoFlush.js.map +1 -0
  19. package/lib/commonjs/internal/base64.js +58 -0
  20. package/lib/commonjs/internal/base64.js.map +1 -0
  21. package/lib/commonjs/internal/bytes.js +32 -0
  22. package/lib/commonjs/internal/bytes.js.map +1 -0
  23. package/lib/commonjs/internal/cloudKitRest.js +527 -0
  24. package/lib/commonjs/internal/cloudKitRest.js.map +1 -0
  25. package/lib/commonjs/internal/enums.js +23 -0
  26. package/lib/commonjs/internal/enums.js.map +1 -0
  27. package/lib/commonjs/internal/googleDriveRest.js +624 -0
  28. package/lib/commonjs/internal/googleDriveRest.js.map +1 -0
  29. package/lib/commonjs/internal/keys.js +139 -0
  30. package/lib/commonjs/internal/keys.js.map +1 -0
  31. package/lib/commonjs/internal/logger.js +29 -0
  32. package/lib/commonjs/internal/logger.js.map +1 -0
  33. package/lib/commonjs/internal/nativeModule.js +125 -0
  34. package/lib/commonjs/internal/nativeModule.js.map +1 -0
  35. package/lib/commonjs/internal/timeout.js +72 -0
  36. package/lib/commonjs/internal/timeout.js.map +1 -0
  37. package/lib/commonjs/package.json +1 -0
  38. package/lib/commonjs/providers/cloudKit.js +398 -0
  39. package/lib/commonjs/providers/cloudKit.js.map +1 -0
  40. package/lib/commonjs/providers/cloudKitBackup.js +86 -0
  41. package/lib/commonjs/providers/cloudKitBackup.js.map +1 -0
  42. package/lib/commonjs/providers/cloudKitEncrypted.js +150 -0
  43. package/lib/commonjs/providers/cloudKitEncrypted.js.map +1 -0
  44. package/lib/commonjs/providers/googleDrive.js +219 -0
  45. package/lib/commonjs/providers/googleDrive.js.map +1 -0
  46. package/lib/commonjs/providers/googleDriveFiles.js +68 -0
  47. package/lib/commonjs/providers/googleDriveFiles.js.map +1 -0
  48. package/lib/commonjs/providers/icloudDocuments.js +121 -0
  49. package/lib/commonjs/providers/icloudDocuments.js.map +1 -0
  50. package/lib/commonjs/providers/icloudKV.js +171 -0
  51. package/lib/commonjs/providers/icloudKV.js.map +1 -0
  52. package/lib/commonjs/providers/icloudKV.web.js +42 -0
  53. package/lib/commonjs/providers/icloudKV.web.js.map +1 -0
  54. package/lib/commonjs/providers/memory.js +201 -0
  55. package/lib/commonjs/providers/memory.js.map +1 -0
  56. package/lib/commonjs/resolvers.js +128 -0
  57. package/lib/commonjs/resolvers.js.map +1 -0
  58. package/lib/commonjs/specs/NativeRNCloudSync.js +14 -0
  59. package/lib/commonjs/specs/NativeRNCloudSync.js.map +1 -0
  60. package/lib/commonjs/store.js +1064 -0
  61. package/lib/commonjs/store.js.map +1 -0
  62. package/lib/commonjs/testing.js +32 -0
  63. package/lib/commonjs/testing.js.map +1 -0
  64. package/lib/commonjs/types.js +86 -0
  65. package/lib/commonjs/types.js.map +1 -0
  66. package/lib/module/config.js +72 -0
  67. package/lib/module/config.js.map +1 -0
  68. package/lib/module/errors.js +231 -0
  69. package/lib/module/errors.js.map +1 -0
  70. package/lib/module/hooks.js +250 -0
  71. package/lib/module/hooks.js.map +1 -0
  72. package/lib/module/index.js +46 -0
  73. package/lib/module/index.js.map +1 -0
  74. package/lib/module/internal/autoFlush.js +62 -0
  75. package/lib/module/internal/autoFlush.js.map +1 -0
  76. package/lib/module/internal/base64.js +53 -0
  77. package/lib/module/internal/base64.js.map +1 -0
  78. package/lib/module/internal/bytes.js +28 -0
  79. package/lib/module/internal/bytes.js.map +1 -0
  80. package/lib/module/internal/cloudKitRest.js +518 -0
  81. package/lib/module/internal/cloudKitRest.js.map +1 -0
  82. package/lib/module/internal/enums.js +18 -0
  83. package/lib/module/internal/enums.js.map +1 -0
  84. package/lib/module/internal/googleDriveRest.js +620 -0
  85. package/lib/module/internal/googleDriveRest.js.map +1 -0
  86. package/lib/module/internal/keys.js +134 -0
  87. package/lib/module/internal/keys.js.map +1 -0
  88. package/lib/module/internal/logger.js +23 -0
  89. package/lib/module/internal/logger.js.map +1 -0
  90. package/lib/module/internal/nativeModule.js +117 -0
  91. package/lib/module/internal/nativeModule.js.map +1 -0
  92. package/lib/module/internal/timeout.js +67 -0
  93. package/lib/module/internal/timeout.js.map +1 -0
  94. package/lib/module/package.json +1 -0
  95. package/lib/module/providers/cloudKit.js +392 -0
  96. package/lib/module/providers/cloudKit.js.map +1 -0
  97. package/lib/module/providers/cloudKitBackup.js +82 -0
  98. package/lib/module/providers/cloudKitBackup.js.map +1 -0
  99. package/lib/module/providers/cloudKitEncrypted.js +146 -0
  100. package/lib/module/providers/cloudKitEncrypted.js.map +1 -0
  101. package/lib/module/providers/googleDrive.js +214 -0
  102. package/lib/module/providers/googleDrive.js.map +1 -0
  103. package/lib/module/providers/googleDriveFiles.js +64 -0
  104. package/lib/module/providers/googleDriveFiles.js.map +1 -0
  105. package/lib/module/providers/icloudDocuments.js +117 -0
  106. package/lib/module/providers/icloudDocuments.js.map +1 -0
  107. package/lib/module/providers/icloudKV.js +165 -0
  108. package/lib/module/providers/icloudKV.js.map +1 -0
  109. package/lib/module/providers/icloudKV.web.js +36 -0
  110. package/lib/module/providers/icloudKV.web.js.map +1 -0
  111. package/lib/module/providers/memory.js +197 -0
  112. package/lib/module/providers/memory.js.map +1 -0
  113. package/lib/module/resolvers.js +120 -0
  114. package/lib/module/resolvers.js.map +1 -0
  115. package/lib/module/specs/NativeRNCloudSync.js +12 -0
  116. package/lib/module/specs/NativeRNCloudSync.js.map +1 -0
  117. package/lib/module/store.js +1061 -0
  118. package/lib/module/store.js.map +1 -0
  119. package/lib/module/testing.js +17 -0
  120. package/lib/module/testing.js.map +1 -0
  121. package/lib/module/types.js +82 -0
  122. package/lib/module/types.js.map +1 -0
  123. package/lib/typescript/commonjs/config.d.ts +33 -0
  124. package/lib/typescript/commonjs/config.d.ts.map +1 -0
  125. package/lib/typescript/commonjs/errors.d.ts +140 -0
  126. package/lib/typescript/commonjs/errors.d.ts.map +1 -0
  127. package/lib/typescript/commonjs/hooks.d.ts +109 -0
  128. package/lib/typescript/commonjs/hooks.d.ts.map +1 -0
  129. package/lib/typescript/commonjs/index.d.ts +37 -0
  130. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  131. package/lib/typescript/commonjs/internal/autoFlush.d.ts +45 -0
  132. package/lib/typescript/commonjs/internal/autoFlush.d.ts.map +1 -0
  133. package/lib/typescript/commonjs/internal/base64.d.ts +12 -0
  134. package/lib/typescript/commonjs/internal/base64.d.ts.map +1 -0
  135. package/lib/typescript/commonjs/internal/bytes.d.ts +12 -0
  136. package/lib/typescript/commonjs/internal/bytes.d.ts.map +1 -0
  137. package/lib/typescript/commonjs/internal/cloudKitRest.d.ts +149 -0
  138. package/lib/typescript/commonjs/internal/cloudKitRest.d.ts.map +1 -0
  139. package/lib/typescript/commonjs/internal/enums.d.ts +10 -0
  140. package/lib/typescript/commonjs/internal/enums.d.ts.map +1 -0
  141. package/lib/typescript/commonjs/internal/googleDriveRest.d.ts +232 -0
  142. package/lib/typescript/commonjs/internal/googleDriveRest.d.ts.map +1 -0
  143. package/lib/typescript/commonjs/internal/keys.d.ts +28 -0
  144. package/lib/typescript/commonjs/internal/keys.d.ts.map +1 -0
  145. package/lib/typescript/commonjs/internal/logger.d.ts +10 -0
  146. package/lib/typescript/commonjs/internal/logger.d.ts.map +1 -0
  147. package/lib/typescript/commonjs/internal/nativeModule.d.ts +29 -0
  148. package/lib/typescript/commonjs/internal/nativeModule.d.ts.map +1 -0
  149. package/lib/typescript/commonjs/internal/timeout.d.ts +36 -0
  150. package/lib/typescript/commonjs/internal/timeout.d.ts.map +1 -0
  151. package/lib/typescript/commonjs/package.json +1 -0
  152. package/lib/typescript/commonjs/providers/cloudKit.d.ts +86 -0
  153. package/lib/typescript/commonjs/providers/cloudKit.d.ts.map +1 -0
  154. package/lib/typescript/commonjs/providers/cloudKitBackup.d.ts +65 -0
  155. package/lib/typescript/commonjs/providers/cloudKitBackup.d.ts.map +1 -0
  156. package/lib/typescript/commonjs/providers/cloudKitEncrypted.d.ts +37 -0
  157. package/lib/typescript/commonjs/providers/cloudKitEncrypted.d.ts.map +1 -0
  158. package/lib/typescript/commonjs/providers/googleDrive.d.ts +35 -0
  159. package/lib/typescript/commonjs/providers/googleDrive.d.ts.map +1 -0
  160. package/lib/typescript/commonjs/providers/googleDriveFiles.d.ts +59 -0
  161. package/lib/typescript/commonjs/providers/googleDriveFiles.d.ts.map +1 -0
  162. package/lib/typescript/commonjs/providers/icloudDocuments.d.ts +101 -0
  163. package/lib/typescript/commonjs/providers/icloudDocuments.d.ts.map +1 -0
  164. package/lib/typescript/commonjs/providers/icloudKV.d.ts +26 -0
  165. package/lib/typescript/commonjs/providers/icloudKV.d.ts.map +1 -0
  166. package/lib/typescript/commonjs/providers/icloudKV.web.d.ts +12 -0
  167. package/lib/typescript/commonjs/providers/icloudKV.web.d.ts.map +1 -0
  168. package/lib/typescript/commonjs/providers/memory.d.ts +90 -0
  169. package/lib/typescript/commonjs/providers/memory.d.ts.map +1 -0
  170. package/lib/typescript/commonjs/resolvers.d.ts +60 -0
  171. package/lib/typescript/commonjs/resolvers.d.ts.map +1 -0
  172. package/lib/typescript/commonjs/specs/NativeRNCloudSync.d.ts +133 -0
  173. package/lib/typescript/commonjs/specs/NativeRNCloudSync.d.ts.map +1 -0
  174. package/lib/typescript/commonjs/store.d.ts +118 -0
  175. package/lib/typescript/commonjs/store.d.ts.map +1 -0
  176. package/lib/typescript/commonjs/testing.d.ts +16 -0
  177. package/lib/typescript/commonjs/testing.d.ts.map +1 -0
  178. package/lib/typescript/commonjs/types.d.ts +367 -0
  179. package/lib/typescript/commonjs/types.d.ts.map +1 -0
  180. package/lib/typescript/module/config.d.ts +33 -0
  181. package/lib/typescript/module/config.d.ts.map +1 -0
  182. package/lib/typescript/module/errors.d.ts +140 -0
  183. package/lib/typescript/module/errors.d.ts.map +1 -0
  184. package/lib/typescript/module/hooks.d.ts +109 -0
  185. package/lib/typescript/module/hooks.d.ts.map +1 -0
  186. package/lib/typescript/module/index.d.ts +37 -0
  187. package/lib/typescript/module/index.d.ts.map +1 -0
  188. package/lib/typescript/module/internal/autoFlush.d.ts +45 -0
  189. package/lib/typescript/module/internal/autoFlush.d.ts.map +1 -0
  190. package/lib/typescript/module/internal/base64.d.ts +12 -0
  191. package/lib/typescript/module/internal/base64.d.ts.map +1 -0
  192. package/lib/typescript/module/internal/bytes.d.ts +12 -0
  193. package/lib/typescript/module/internal/bytes.d.ts.map +1 -0
  194. package/lib/typescript/module/internal/cloudKitRest.d.ts +149 -0
  195. package/lib/typescript/module/internal/cloudKitRest.d.ts.map +1 -0
  196. package/lib/typescript/module/internal/enums.d.ts +10 -0
  197. package/lib/typescript/module/internal/enums.d.ts.map +1 -0
  198. package/lib/typescript/module/internal/googleDriveRest.d.ts +232 -0
  199. package/lib/typescript/module/internal/googleDriveRest.d.ts.map +1 -0
  200. package/lib/typescript/module/internal/keys.d.ts +28 -0
  201. package/lib/typescript/module/internal/keys.d.ts.map +1 -0
  202. package/lib/typescript/module/internal/logger.d.ts +10 -0
  203. package/lib/typescript/module/internal/logger.d.ts.map +1 -0
  204. package/lib/typescript/module/internal/nativeModule.d.ts +29 -0
  205. package/lib/typescript/module/internal/nativeModule.d.ts.map +1 -0
  206. package/lib/typescript/module/internal/timeout.d.ts +36 -0
  207. package/lib/typescript/module/internal/timeout.d.ts.map +1 -0
  208. package/lib/typescript/module/package.json +1 -0
  209. package/lib/typescript/module/providers/cloudKit.d.ts +86 -0
  210. package/lib/typescript/module/providers/cloudKit.d.ts.map +1 -0
  211. package/lib/typescript/module/providers/cloudKitBackup.d.ts +65 -0
  212. package/lib/typescript/module/providers/cloudKitBackup.d.ts.map +1 -0
  213. package/lib/typescript/module/providers/cloudKitEncrypted.d.ts +37 -0
  214. package/lib/typescript/module/providers/cloudKitEncrypted.d.ts.map +1 -0
  215. package/lib/typescript/module/providers/googleDrive.d.ts +35 -0
  216. package/lib/typescript/module/providers/googleDrive.d.ts.map +1 -0
  217. package/lib/typescript/module/providers/googleDriveFiles.d.ts +59 -0
  218. package/lib/typescript/module/providers/googleDriveFiles.d.ts.map +1 -0
  219. package/lib/typescript/module/providers/icloudDocuments.d.ts +101 -0
  220. package/lib/typescript/module/providers/icloudDocuments.d.ts.map +1 -0
  221. package/lib/typescript/module/providers/icloudKV.d.ts +26 -0
  222. package/lib/typescript/module/providers/icloudKV.d.ts.map +1 -0
  223. package/lib/typescript/module/providers/icloudKV.web.d.ts +12 -0
  224. package/lib/typescript/module/providers/icloudKV.web.d.ts.map +1 -0
  225. package/lib/typescript/module/providers/memory.d.ts +90 -0
  226. package/lib/typescript/module/providers/memory.d.ts.map +1 -0
  227. package/lib/typescript/module/resolvers.d.ts +60 -0
  228. package/lib/typescript/module/resolvers.d.ts.map +1 -0
  229. package/lib/typescript/module/specs/NativeRNCloudSync.d.ts +133 -0
  230. package/lib/typescript/module/specs/NativeRNCloudSync.d.ts.map +1 -0
  231. package/lib/typescript/module/store.d.ts +118 -0
  232. package/lib/typescript/module/store.d.ts.map +1 -0
  233. package/lib/typescript/module/testing.d.ts +16 -0
  234. package/lib/typescript/module/testing.d.ts.map +1 -0
  235. package/lib/typescript/module/types.d.ts +367 -0
  236. package/lib/typescript/module/types.d.ts.map +1 -0
  237. package/package.json +186 -0
  238. package/plugin/build/index.d.ts +45 -0
  239. package/plugin/build/index.js +93 -0
  240. package/react-native-cloud-sync.podspec +48 -0
  241. package/src/config.ts +94 -0
  242. package/src/errors.ts +263 -0
  243. package/src/hooks.ts +337 -0
  244. package/src/index.ts +113 -0
  245. package/src/internal/autoFlush.ts +87 -0
  246. package/src/internal/base64.ts +63 -0
  247. package/src/internal/bytes.ts +28 -0
  248. package/src/internal/cloudKitRest.ts +654 -0
  249. package/src/internal/enums.ts +35 -0
  250. package/src/internal/googleDriveRest.ts +765 -0
  251. package/src/internal/keys.ts +160 -0
  252. package/src/internal/logger.ts +23 -0
  253. package/src/internal/nativeModule.ts +149 -0
  254. package/src/internal/timeout.ts +83 -0
  255. package/src/providers/cloudKit.ts +510 -0
  256. package/src/providers/cloudKitBackup.ts +124 -0
  257. package/src/providers/cloudKitEncrypted.ts +175 -0
  258. package/src/providers/googleDrive.ts +251 -0
  259. package/src/providers/googleDriveFiles.ts +117 -0
  260. package/src/providers/icloudDocuments.ts +175 -0
  261. package/src/providers/icloudKV.ts +206 -0
  262. package/src/providers/icloudKV.web.ts +41 -0
  263. package/src/providers/memory.ts +302 -0
  264. package/src/resolvers.ts +133 -0
  265. package/src/specs/NativeRNCloudSync.ts +184 -0
  266. package/src/store.ts +1288 -0
  267. package/src/testing.ts +22 -0
  268. package/src/types.ts +426 -0
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config_plugins_1 = require("@expo/config-plugins");
4
+ const pkg = require('../../package.json');
5
+ /**
6
+ * Adds the iCloud entitlements this package needs.
7
+ *
8
+ * Entirely optional: the entitlements are four plist keys, and plenty of
9
+ * projects (including bare workflows with a committed `ios/` directory) prefer
10
+ * to manage that file by hand. The README documents the raw keys for exactly
11
+ * that case - a config plugin should not be the only documented path.
12
+ */
13
+ const withCloudSync = (config, options) => {
14
+ var _a, _b, _c;
15
+ const opts = options !== null && options !== void 0 ? options : {};
16
+ const keyValueStore = (_a = opts.keyValueStore) !== null && _a !== void 0 ? _a : true;
17
+ const cloudKit = (_b = opts.cloudKit) !== null && _b !== void 0 ? _b : true;
18
+ const iCloudDocuments = (_c = opts.iCloudDocuments) !== null && _c !== void 0 ? _c : false;
19
+ const withEntitlements = (0, config_plugins_1.withEntitlementsPlist)(config, (mod) => {
20
+ var _a, _b, _c, _d, _e, _f, _g;
21
+ const bundleId = (_b = (_a = mod.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier) !== null && _b !== void 0 ? _b : (_c = config.ios) === null || _c === void 0 ? void 0 : _c.bundleIdentifier;
22
+ const containerIdentifier = (_d = opts.containerIdentifier) !== null && _d !== void 0 ? _d : (bundleId != null ? `iCloud.${bundleId}` : undefined);
23
+ if (containerIdentifier == null)
24
+ throw new Error('[react-native-cloud-sync] Cannot derive an iCloud container identifier. Set '
25
+ + 'ios.bundleIdentifier in app config, or pass containerIdentifier to the plugin.');
26
+ const entitlements = mod.modResults;
27
+ if (cloudKit || iCloudDocuments) {
28
+ // Merge rather than overwrite, for both keys: a project may already
29
+ // declare a second container, or CloudDocuments for an unrelated feature.
30
+ // Assigning the container list outright silently dropped every container
31
+ // the app already had, which breaks that other feature at runtime with no
32
+ // build error to point at.
33
+ const containers = new Set((_e = entitlements['com.apple.developer.icloud-container-identifiers']) !== null && _e !== void 0 ? _e : []);
34
+ containers.add(containerIdentifier);
35
+ entitlements['com.apple.developer.icloud-container-identifiers'] = [...containers];
36
+ const services = new Set((_f = entitlements['com.apple.developer.icloud-services']) !== null && _f !== void 0 ? _f : []);
37
+ if (cloudKit)
38
+ services.add('CloudKit');
39
+ // The `icloudDocuments` provider writes to the ubiquity container's
40
+ // Documents directory, which needs this service. Without it the container
41
+ // URL resolves to nil at runtime and every call fails with
42
+ // ERR_CONTAINER_MISCONFIGURED.
43
+ if (iCloudDocuments)
44
+ services.add('CloudDocuments');
45
+ entitlements['com.apple.developer.icloud-services'] = [...services];
46
+ if (iCloudDocuments) {
47
+ // Required alongside the service for document-scope access. Merged for
48
+ // the same reason as the list above.
49
+ const ubiquity = new Set((_g = entitlements['com.apple.developer.ubiquity-container-identifiers']) !== null && _g !== void 0 ? _g : []);
50
+ ubiquity.add(containerIdentifier);
51
+ entitlements['com.apple.developer.ubiquity-container-identifiers'] = [...ubiquity];
52
+ }
53
+ }
54
+ if (keyValueStore)
55
+ // The token form is what Xcode writes; it resolves at build time and
56
+ // avoids hardcoding the team prefix into source control.
57
+ entitlements['com.apple.developer.ubiquity-kvstore-identifier']
58
+ = '$(TeamIdentifierPrefix)$(CFBundleIdentifier)';
59
+ return mod;
60
+ });
61
+ if (!iCloudDocuments)
62
+ return withEntitlements;
63
+ // Entitlements alone get the folder syncing but leave it invisible. Files.app
64
+ // only shows a container that declares `NSUbiquitousContainers` with
65
+ // `NSUbiquitousContainerIsDocumentScopePublic` - which is the whole reason an
66
+ // app reaches for this provider instead of a CKAsset, so writing one without
67
+ // the other would ship a feature that silently does not do its job.
68
+ return (0, config_plugins_1.withInfoPlist)(withEntitlements, (mod) => {
69
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
70
+ const bundleId = (_b = (_a = mod.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier) !== null && _b !== void 0 ? _b : (_c = config.ios) === null || _c === void 0 ? void 0 : _c.bundleIdentifier;
71
+ const containerIdentifier = (_d = opts.containerIdentifier) !== null && _d !== void 0 ? _d : (bundleId != null ? `iCloud.${bundleId}` : undefined);
72
+ if (containerIdentifier == null)
73
+ return mod;
74
+ // Merged, not replaced: an app may already declare a second container here
75
+ // for an unrelated document feature, and overwriting the map would break it
76
+ // at runtime with nothing in the build to point at.
77
+ const existing = (_e = mod.modResults.NSUbiquitousContainers) !== null && _e !== void 0 ? _e : {};
78
+ const containers = {
79
+ ...existing,
80
+ [containerIdentifier]: {
81
+ NSUbiquitousContainerIsDocumentScopePublic: (_f = opts.documentsVisibleInFiles) !== null && _f !== void 0 ? _f : true,
82
+ NSUbiquitousContainerName: (_j = (_h = (_g = opts.documentsFolderName) !== null && _g !== void 0 ? _g : mod.name) !== null && _h !== void 0 ? _h : config.name) !== null && _j !== void 0 ? _j : 'Documents',
83
+ NSUbiquitousContainerSupportedFolderLevels: 'Any',
84
+ },
85
+ };
86
+ // `modResults` is typed as a plist of `JSONValue`, which does not admit an
87
+ // index-signature object even though a nested dictionary is exactly what
88
+ // this key holds.
89
+ mod.modResults.NSUbiquitousContainers = containers;
90
+ return mod;
91
+ });
92
+ };
93
+ exports.default = (0, config_plugins_1.createRunOncePlugin)(withCloudSync, pkg.name, pkg.version);
@@ -0,0 +1,48 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
6
+
7
+ Pod::Spec.new do |s|
8
+ s.name = package['name'].split('/').last
9
+ s.version = package['version']
10
+ s.summary = package['description']
11
+ s.description = package['description']
12
+ s.homepage = package['repository']['url']
13
+ s.license = package['license']
14
+ s.author = package['author']
15
+ s.source = { git: 'https://github.com/kesha-antonov/react-native-cloud-sync.git', tag: "v#{s.version}" }
16
+
17
+ # iOS only as a declared platform - Mac Catalyst builds from this same slice
18
+ # (SUPPORTS_MACCATALYST), it is not a separate platform entry. 15.1 matches
19
+ # the floor the consuming apps already use.
20
+ s.platform = :ios, '15.1'
21
+
22
+ s.source_files = 'ios/**/*.{h,m,mm,swift}'
23
+
24
+ # CloudKit for records/assets/zones; Foundation carries
25
+ # NSUbiquitousKeyValueStore. Both are available under Mac Catalyst.
26
+ s.frameworks = 'CloudKit', 'Foundation'
27
+
28
+ # React Native core dependency, codegen wiring and the new-arch flags.
29
+ install_modules_dependencies(s)
30
+
31
+ # Built up locally and assigned once: `pod_target_xcconfig` is a writer on
32
+ # Pod::Specification with no matching reader, so it cannot be read back and
33
+ # merged into.
34
+ xcconfig = {
35
+ # Required so the generated `react_native_cloud_sync-Swift.h` exists for
36
+ # the Objective-C++ bridge to import.
37
+ 'DEFINES_MODULE' => 'YES',
38
+ 'SWIFT_VERSION' => '5.0'
39
+ }
40
+
41
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1'
42
+ s.compiler_flags = folly_compiler_flags + ' -DRCT_NEW_ARCH_ENABLED=1'
43
+ xcconfig['HEADER_SEARCH_PATHS'] = "\"$(PODS_ROOT)/boost\""
44
+ xcconfig['CLANG_CXX_LANGUAGE_STANDARD'] = 'c++17'
45
+ end
46
+
47
+ s.pod_target_xcconfig = xcconfig
48
+ end
package/src/config.ts ADDED
@@ -0,0 +1,94 @@
1
+ import type { CloudKitRestConfig } from './internal/cloudKitRest'
2
+ import { CloudKitRestClient } from './internal/cloudKitRest'
3
+ import type { GoogleDriveConfig, GoogleDriveFileAdapter } from './internal/googleDriveRest'
4
+ import { GoogleDriveClient } from './internal/googleDriveRest'
5
+ import { CloudSyncError, ErrorCode } from './errors'
6
+
7
+ let cloudKitClient: CloudKitRestClient | null = null
8
+ let driveClient: GoogleDriveClient | null = null
9
+ let driveFileAdapter: GoogleDriveFileAdapter | null = null
10
+
11
+ /**
12
+ * Supplies the credentials the CloudKit REST path needs.
13
+ *
14
+ * Only required on Android and web. On iOS the native provider authenticates
15
+ * implicitly through the device's signed-in iCloud account and needs none of
16
+ * this.
17
+ */
18
+ export function configureCloudKit(config: CloudKitRestConfig): void {
19
+ cloudKitClient = new CloudKitRestClient(config)
20
+ }
21
+
22
+ export function getCloudKitClient(): CloudKitRestClient {
23
+ if (cloudKitClient == null)
24
+ throw new CloudSyncError(
25
+ ErrorCode.CONTAINER_MISCONFIGURED,
26
+ '[RNCloudSync] CloudKit is not configured on this platform. Call configureCloudKit({ '
27
+ + 'containerIdentifier, apiToken, environment, getAuthToken }) before using the cloudKit '
28
+ + 'provider on Android or web.',
29
+ { provider: 'cloudKit' }
30
+ )
31
+
32
+ return cloudKitClient
33
+ }
34
+
35
+ export function isCloudKitConfigured(): boolean {
36
+ return cloudKitClient != null
37
+ }
38
+
39
+ /** Supplies the OAuth token the Drive provider uses. Required on every platform. */
40
+ export function configureGoogleDrive(config: GoogleDriveConfig): void {
41
+ driveClient = new GoogleDriveClient(config)
42
+ }
43
+
44
+ export function getGoogleDriveClient(): GoogleDriveClient {
45
+ if (driveClient == null)
46
+ throw new CloudSyncError(
47
+ ErrorCode.CONTAINER_MISCONFIGURED,
48
+ '[RNCloudSync] Google Drive is not configured. Call configureGoogleDrive({ '
49
+ + 'getAccessToken }) before using the googleDrive provider.',
50
+ { provider: 'googleDrive' }
51
+ )
52
+
53
+ return driveClient
54
+ }
55
+
56
+ export function isGoogleDriveConfigured(): boolean {
57
+ return driveClient != null
58
+ }
59
+
60
+ /**
61
+ * Supplies local file I/O for `googleDriveFiles` - large binaries that go
62
+ * through Drive's resumable upload/download rather than `googleDrive`'s
63
+ * whole-value-as-a-string path.
64
+ *
65
+ * Separate from `configureGoogleDrive` because most apps never touch a file
66
+ * that large and shouldn't need to think about filesystem access to use
67
+ * `googleDrive`/the store facade. Only required for `googleDriveFiles`.
68
+ */
69
+ export function configureGoogleDriveFiles(adapter: GoogleDriveFileAdapter): void {
70
+ driveFileAdapter = adapter
71
+ }
72
+
73
+ export function getGoogleDriveFileAdapter(): GoogleDriveFileAdapter {
74
+ if (driveFileAdapter == null)
75
+ throw new CloudSyncError(
76
+ ErrorCode.CONTAINER_MISCONFIGURED,
77
+ '[RNCloudSync] googleDriveFiles needs a file adapter. Call configureGoogleDriveFiles({ '
78
+ + 'statSize, readChunk, writeChunk, appendChunk }) before saving or fetching a file.',
79
+ { provider: 'googleDrive' }
80
+ )
81
+
82
+ return driveFileAdapter
83
+ }
84
+
85
+ export function isGoogleDriveFilesConfigured(): boolean {
86
+ return driveFileAdapter != null
87
+ }
88
+
89
+ /** Test seam - drops all configured clients. */
90
+ export function __resetConfig(): void {
91
+ cloudKitClient = null
92
+ driveClient = null
93
+ driveFileAdapter = null
94
+ }
package/src/errors.ts ADDED
@@ -0,0 +1,263 @@
1
+ /**
2
+ * The error vocabulary shared verbatim by iOS (Swift), Android (Kotlin), the
3
+ * REST clients and the web build.
4
+ *
5
+ * Why this exists at all: every React Native cloud library surveyed before this
6
+ * one collapses distinct failures into `null` or into a bare `false`, and two of
7
+ * them go further and report a *failed write as a success*. That is not a
8
+ * hypothetical - it is the single most repeated defect in this problem space:
9
+ *
10
+ * - jacobp100/react-native-cloudkit-storage's `setItem` checks the enclosing
11
+ * `error` variable instead of the operation's own `operationError`, so a
12
+ * quota-exceeded or not-signed-in write resolves successfully.
13
+ * - cryptoc's in-app CloudKit module discarded the `Result` handed to
14
+ * `modifyRecordsResultBlock` entirely, with the same outcome.
15
+ *
16
+ * The rule that prevents both, and that every provider in this package obeys:
17
+ *
18
+ * `null` is returned for exactly one condition - the key genuinely does not
19
+ * exist. Every other outcome rejects with a `CloudSyncError` carrying a
20
+ * stable `code`.
21
+ */
22
+
23
+ /**
24
+ * Stable, cross-platform failure codes.
25
+ *
26
+ * These strings are duplicated in `ios/CloudSyncError.swift` - the only other
27
+ * place that raises them, since Android and web reach CloudKit and Drive over
28
+ * REST from this same TypeScript. They are part of the public API: apps branch
29
+ * on them, so treat a change here as a breaking change.
30
+ */
31
+ export const ErrorCode = {
32
+ /** No iCloud/Drive account is signed in on the device. */
33
+ NOT_SIGNED_IN: 'ERR_NOT_SIGNED_IN',
34
+ /** An account exists but is restricted (parental controls, MDM). */
35
+ ACCOUNT_RESTRICTED: 'ERR_ACCOUNT_RESTRICTED',
36
+ /** CloudKit reported `.temporarilyUnavailable` - retry later. */
37
+ ACCOUNT_UNAVAILABLE: 'ERR_ACCOUNT_UNAVAILABLE',
38
+ /** CloudKit could not determine account status. Not the same as signed out. */
39
+ ACCOUNT_UNDETERMINED: 'ERR_ACCOUNT_UNDETERMINED',
40
+ /** A previously valid credential expired. On Android CloudKit this is routine: */
41
+ /** a `ckWebAuthToken` lives 30 minutes, or 2 weeks if the user ticked */
42
+ /** "Keep me signed in". There is no documented refresh - re-auth is required. */
43
+ AUTH_EXPIRED: 'ERR_AUTH_EXPIRED',
44
+ /** Device is offline, or the request could not reach the server. */
45
+ NETWORK_UNAVAILABLE: 'ERR_NETWORK_UNAVAILABLE',
46
+ /** The user's iCloud/Drive storage is full. */
47
+ QUOTA_EXCEEDED: 'ERR_QUOTA_EXCEEDED',
48
+ /** Server asked us to back off. Carries `retryAfterMs` when the server said so. */
49
+ RATE_LIMITED: 'ERR_RATE_LIMITED',
50
+ /** Value exceeds the backing store's limit. Carries `limitBytes`/`actualBytes`. */
51
+ PAYLOAD_TOO_LARGE: 'ERR_PAYLOAD_TOO_LARGE',
52
+ /**
53
+ * The key cannot round-trip through the configured providers - illegal
54
+ * characters, too long, or a reserved prefix. Raised before the request, so
55
+ * it never reaches the server as a confusing `BAD_REQUEST`.
56
+ */
57
+ INVALID_KEY: 'ERR_INVALID_KEY',
58
+ /** The operation ran longer than the configured timeout. */
59
+ TIMEOUT: 'ERR_TIMEOUT',
60
+ /** A concurrent write won. Carries `serverValue` so the app can merge. */
61
+ CONFLICT: 'ERR_CONFLICT',
62
+ /** Entitlements, container identifier or API token are missing or wrong. */
63
+ CONTAINER_MISCONFIGURED: 'ERR_CONTAINER_MISCONFIGURED',
64
+ /** This provider has no implementation on the current platform. */
65
+ UNSUPPORTED_PLATFORM: 'ERR_UNSUPPORTED_PLATFORM',
66
+ /** The operation was cancelled by the caller. */
67
+ CANCELLED: 'ERR_CANCELLED',
68
+ /** Anything the native layer could not classify. `cause` holds the original. */
69
+ UNKNOWN: 'ERR_UNKNOWN',
70
+ } as const
71
+
72
+ export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode]
73
+
74
+ const ALL_CODES: readonly string[] = Object.values(ErrorCode)
75
+
76
+ export interface CloudSyncErrorInfo {
77
+ /** Milliseconds to wait before retrying. Set on {@link ErrorCode.RATE_LIMITED}. */
78
+ retryAfterMs?: number
79
+ /** The store's size limit in bytes. Set on {@link ErrorCode.PAYLOAD_TOO_LARGE}. */
80
+ limitBytes?: number
81
+ /** The rejected payload's size in bytes. Set on {@link ErrorCode.PAYLOAD_TOO_LARGE}. */
82
+ actualBytes?: number
83
+ /** The value currently on the server. Set on {@link ErrorCode.CONFLICT}. */
84
+ serverValue?: string | null
85
+ /** Which provider raised this. */
86
+ provider?: string
87
+ /**
88
+ * The backend's own error code, when there was one - e.g. CloudKit Web
89
+ * Services' `EXISTS` or `ATOMIC_ERROR`. Useful for diagnosing a response
90
+ * that this package classified as `ERR_UNKNOWN`.
91
+ */
92
+ serverErrorCode?: string
93
+ /** The underlying native or network error, when there was one. */
94
+ cause?: unknown
95
+ }
96
+
97
+ /**
98
+ * The single error type every operation in this package rejects with.
99
+ *
100
+ * `instanceof` is deliberately not the recommended check - a rejected promise
101
+ * crossing the React Native bridge arrives as a plain object on some paths, so
102
+ * {@link isCloudSyncError} tests the shape instead.
103
+ */
104
+ export class CloudSyncError extends Error implements CloudSyncErrorInfo {
105
+ readonly code: ErrorCode
106
+ readonly retryAfterMs?: number
107
+ readonly limitBytes?: number
108
+ readonly actualBytes?: number
109
+ readonly serverValue?: string | null
110
+ readonly provider?: string
111
+ readonly serverErrorCode?: string
112
+ readonly cause?: unknown
113
+
114
+ constructor(code: ErrorCode, message: string, info: CloudSyncErrorInfo = {}) {
115
+ super(message)
116
+ this.name = 'CloudSyncError'
117
+ this.code = code
118
+ this.retryAfterMs = info.retryAfterMs
119
+ this.limitBytes = info.limitBytes
120
+ this.actualBytes = info.actualBytes
121
+ this.serverValue = info.serverValue
122
+ this.provider = info.provider
123
+ this.serverErrorCode = info.serverErrorCode
124
+ this.cause = info.cause
125
+
126
+ // Restore the prototype chain: TypeScript's ES5 downlevel of `extends Error`
127
+ // otherwise leaves `instanceof CloudSyncError` false.
128
+ Object.setPrototypeOf(this, CloudSyncError.prototype)
129
+ }
130
+ }
131
+
132
+ /** Narrowing guard that works on both real instances and bridged plain objects. */
133
+ export function isCloudSyncError(e: unknown): e is CloudSyncError {
134
+ if (e == null || typeof e !== 'object') return false
135
+ const code = (e as { code?: unknown }).code
136
+ return typeof code === 'string' && ALL_CODES.includes(code)
137
+ }
138
+
139
+ /**
140
+ * True when retrying the same call later could plausibly succeed.
141
+ *
142
+ * TIMEOUT is in this set because running out of time says nothing about whether
143
+ * the operation is possible - only that this attempt took too long.
144
+ */
145
+ export function isRetryable(e: unknown): boolean {
146
+ if (!isCloudSyncError(e)) return false
147
+ switch (e.code) {
148
+ case ErrorCode.NETWORK_UNAVAILABLE:
149
+ case ErrorCode.RATE_LIMITED:
150
+ case ErrorCode.ACCOUNT_UNAVAILABLE:
151
+ case ErrorCode.ACCOUNT_UNDETERMINED:
152
+ case ErrorCode.TIMEOUT:
153
+ return true
154
+ default:
155
+ return false
156
+ }
157
+ }
158
+
159
+ /** True when the user must take an action (sign in, free up space) to proceed. */
160
+ export function requiresUserAction(e: unknown): boolean {
161
+ if (!isCloudSyncError(e)) return false
162
+ switch (e.code) {
163
+ case ErrorCode.NOT_SIGNED_IN:
164
+ case ErrorCode.AUTH_EXPIRED:
165
+ case ErrorCode.QUOTA_EXCEEDED:
166
+ case ErrorCode.ACCOUNT_RESTRICTED:
167
+ return true
168
+ default:
169
+ return false
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Normalises whatever the native layer rejected with into a `CloudSyncError`.
175
+ *
176
+ * React Native's bridge turns `reject(code, message, nativeError)` into an Error
177
+ * whose `code` is the string we chose natively, so the common path is a simple
178
+ * re-wrap. Anything unrecognised becomes {@link ErrorCode.UNKNOWN} rather than
179
+ * being swallowed.
180
+ */
181
+ export function normalizeError(e: unknown, provider?: string): CloudSyncError {
182
+ if (e instanceof CloudSyncError) return e
183
+
184
+ if (isCloudSyncError(e)) {
185
+ const raw = e as unknown as CloudSyncErrorInfo & { message?: string; userInfo?: unknown }
186
+ const nested = nestedInfo(raw.userInfo)
187
+ return new CloudSyncError(e.code, raw.message ?? e.code, {
188
+ retryAfterMs: numeric(raw.retryAfterMs ?? nested.retryAfterMs),
189
+ limitBytes: numeric(raw.limitBytes ?? nested.limitBytes),
190
+ actualBytes: numeric(raw.actualBytes ?? nested.actualBytes),
191
+ serverValue: raw.serverValue ?? nested.serverValue,
192
+ provider: raw.provider ?? nested.provider ?? provider,
193
+ serverErrorCode: raw.serverErrorCode ?? nested.serverErrorCode,
194
+ cause: e,
195
+ })
196
+ }
197
+
198
+ const message = e instanceof Error ? e.message : String(e)
199
+ return new CloudSyncError(ErrorCode.UNKNOWN, message, { provider, cause: e })
200
+ }
201
+
202
+ /**
203
+ * The extra fields a native rejection carries, which live one level down.
204
+ *
205
+ * React Native builds the JS error from `reject(code, message, nsError)` with
206
+ * `Object.assign(new Error(message), errorData)`, and `errorData` keeps the
207
+ * `NSError`'s dictionary intact under a nested `userInfo` key rather than
208
+ * spreading it. So everything `CloudSyncError.asNSError` attaches on iOS -
209
+ * `retryAfterMs`, `limitBytes`, `actualBytes`, `serverValue` - arrives as
210
+ * `e.userInfo.limitBytes`, never as `e.limitBytes`.
211
+ *
212
+ * Reading only the top level is why CloudKit's `retryAfter` hint never reached
213
+ * the outbox's backoff, and why a CONFLICT's `serverValue` - documented as the
214
+ * thing that lets an app merge - was always undefined on iOS.
215
+ */
216
+ function nestedInfo(userInfo: unknown): CloudSyncErrorInfo {
217
+ if (userInfo == null || typeof userInfo !== 'object') return {}
218
+ return userInfo
219
+ }
220
+
221
+ /**
222
+ * The bridge stringifies numbers on some paths (`userInfo` dictionaries on iOS
223
+ * arrive as strings), so coerce rather than trusting the declared type.
224
+ */
225
+ function numeric(v: unknown): number | undefined {
226
+ if (typeof v === 'number' && Number.isFinite(v)) return v
227
+ if (typeof v === 'string') {
228
+ const n = Number(v)
229
+ if (Number.isFinite(n)) return n
230
+ }
231
+ return undefined
232
+ }
233
+
234
+ /**
235
+ * True when the caller asked for this - a cancelled operation is not a fault to
236
+ * report, and a UI that shows an error toast for one is wrong.
237
+ */
238
+ export function isCancelled(e: unknown): boolean {
239
+ return isCloudSyncError(e) && e.code === ErrorCode.CANCELLED
240
+ }
241
+
242
+ /** The rejection an aborted operation produces. */
243
+ export function cancelled(provider?: string, detail = 'The operation was cancelled.'): CloudSyncError {
244
+ return new CloudSyncError(ErrorCode.CANCELLED, `[RNCloudSync] ${detail}`, { provider })
245
+ }
246
+
247
+ /** The rejection a timed-out operation produces. */
248
+ export function timedOut(ms: number, provider?: string): CloudSyncError {
249
+ return new CloudSyncError(
250
+ ErrorCode.TIMEOUT,
251
+ `[RNCloudSync] The request did not complete within ${ms}ms.`,
252
+ { provider }
253
+ )
254
+ }
255
+
256
+ /** Convenience constructor for the platform-capability guards. */
257
+ export function unsupportedPlatform(provider: string, detail: string): CloudSyncError {
258
+ return new CloudSyncError(
259
+ ErrorCode.UNSUPPORTED_PLATFORM,
260
+ `[RNCloudSync] ${provider} is not available on this platform: ${detail}`,
261
+ { provider }
262
+ )
263
+ }