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,398 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cloudKit = exports.assets = void 0;
7
+ exports.createCloudKitProvider = createCloudKitProvider;
8
+ exports.zones = void 0;
9
+ var _reactNative = require("react-native");
10
+ var _nativeModule = require("../internal/nativeModule.js");
11
+ var _config = require("../config.js");
12
+ var _cloudKitRest = require("../internal/cloudKitRest.js");
13
+ var _errors = require("../errors.js");
14
+ var _enums = require("../internal/enums.js");
15
+ const NAME = 'cloudKit';
16
+
17
+ /**
18
+ * CloudKit private database.
19
+ *
20
+ * The only provider here that reaches the *same* data on every platform:
21
+ *
22
+ * iOS / macOS -> CloudKit.framework, natively, no configuration
23
+ * Android -> CloudKit Web Services REST (see configureCloudKit)
24
+ * Web -> the same REST client
25
+ *
26
+ * On Android and web the user must sign in with an Apple ID to mint a
27
+ * `ckWebAuthToken`, and that token lives 30 minutes - or 2 weeks if they ticked
28
+ * "Keep me signed in" - with no documented refresh. Treat those platforms as
29
+ * suited to a deliberate import/export ("bring my iPhone data over"), not to a
30
+ * silent always-on backup. `googleDrive` is the better continuous backend there.
31
+ */
32
+
33
+ /** True when this platform talks to CloudKit natively rather than over REST. */
34
+ function isNative() {
35
+ // `Platform?.OS` rather than `Platform.OS`: on a react-native-web build served
36
+ // by a bundler that does not resolve platform extensions, this module is what
37
+ // loads, and it has to answer 'not native' rather than throw.
38
+ const os = _reactNative.Platform?.OS;
39
+ return (os === 'ios' || os === 'macos') && (0, _nativeModule.hasNativeModule)();
40
+ }
41
+ const cloudKit = exports.cloudKit = {
42
+ name: NAME,
43
+ isAvailable: async () => {
44
+ if (isNative()) try {
45
+ return await (0, _nativeModule.requireNativeModule)().isAvailable();
46
+ } catch {
47
+ return false;
48
+ }
49
+ if (!(0, _config.isCloudKitConfigured)()) return false;
50
+ try {
51
+ // Memoised inside the client: the store asks before every provider read,
52
+ // and an unmemoised probe made each read cost two network round trips.
53
+ return await (0, _config.getCloudKitClient)().isReachable();
54
+ } catch {
55
+ return false;
56
+ }
57
+ },
58
+ getAccountStatus: async () => {
59
+ if (isNative()) try {
60
+ return (0, _enums.toAccountStatus)(await (0, _nativeModule.requireNativeModule)().getAccountStatus());
61
+ } catch (e) {
62
+ throw (0, _errors.normalizeError)(e, NAME);
63
+ }
64
+
65
+ // Over REST there is no account-status endpoint; possession of a usable web
66
+ // auth token is the closest equivalent signal.
67
+ return (0, _config.isCloudKitConfigured)() ? 'available' : 'noAccount';
68
+ },
69
+ getItem: async key => {
70
+ try {
71
+ if (isNative()) return await (0, _nativeModule.requireNativeModule)().ckGetRecord('KVBlob', key, null, false);
72
+ return await (0, _config.getCloudKitClient)().getRecord(key);
73
+ } catch (e) {
74
+ throw (0, _errors.normalizeError)(e, NAME);
75
+ }
76
+ },
77
+ /**
78
+ * Server modification time, over REST only.
79
+ *
80
+ * CloudKit returns `modified.timestamp` on every lookup, so the REST path
81
+ * gets it for free. The native path would need a new bridge method and a
82
+ * second field on every response for a value only the resolver uses, so it
83
+ * reports no timestamp and falls back to preference order - which is what
84
+ * {@link resolveByModifiedAt} is built to handle.
85
+ */
86
+ getItemWithMeta: async key => {
87
+ if (isNative()) {
88
+ const value = await cloudKit.getItem(key);
89
+ return value == null ? null : {
90
+ value
91
+ };
92
+ }
93
+ try {
94
+ return await (0, _config.getCloudKitClient)().getRecordWithMeta(key);
95
+ } catch (e) {
96
+ throw (0, _errors.normalizeError)(e, NAME);
97
+ }
98
+ },
99
+ /**
100
+ * Reads many records in one request, over REST.
101
+ *
102
+ * `/records/lookup` takes an array, so this is the difference between one
103
+ * round trip and N - and between one rate-limit budget and N.
104
+ */
105
+ multiGet: async keys => {
106
+ if (isNative()) {
107
+ const out = [];
108
+ for (const key of keys) out.push(await (0, _nativeModule.requireNativeModule)().ckGetRecord('KVBlob', key, null, false));
109
+ return out;
110
+ }
111
+ try {
112
+ return await (0, _config.getCloudKitClient)().getRecords(keys);
113
+ } catch (e) {
114
+ throw (0, _errors.normalizeError)(e, NAME);
115
+ }
116
+ },
117
+ multiSet: async entries => {
118
+ if (isNative()) {
119
+ for (const [key, value] of entries) await (0, _nativeModule.requireNativeModule)().ckSaveRecord('KVBlob', key, value, null, false);
120
+ return;
121
+ }
122
+ try {
123
+ await (0, _config.getCloudKitClient)().saveRecords(entries);
124
+ } catch (e) {
125
+ throw (0, _errors.normalizeError)(e, NAME);
126
+ }
127
+ },
128
+ multiRemove: async keys => {
129
+ if (isNative()) {
130
+ for (const key of keys) await (0, _nativeModule.requireNativeModule)().ckDeleteRecord(key, null);
131
+ return;
132
+ }
133
+ try {
134
+ await (0, _config.getCloudKitClient)().deleteRecords(keys);
135
+ } catch (e) {
136
+ throw (0, _errors.normalizeError)(e, NAME);
137
+ }
138
+ },
139
+ clearCaches: () => {
140
+ // The memoised reachability answer was recorded for the previous account's
141
+ // web auth token and says nothing about the new one.
142
+ if (!isNative() && (0, _config.isCloudKitConfigured)()) (0, _config.getCloudKitClient)().clearCache();
143
+ },
144
+ setItem: async (key, value) => {
145
+ try {
146
+ if (isNative()) {
147
+ await (0, _nativeModule.requireNativeModule)().ckSaveRecord('KVBlob', key, value, null, false);
148
+ return;
149
+ }
150
+ await (0, _config.getCloudKitClient)().saveRecord(key, value);
151
+ } catch (e) {
152
+ throw (0, _errors.normalizeError)(e, NAME);
153
+ }
154
+ },
155
+ removeItem: async key => {
156
+ try {
157
+ if (isNative()) {
158
+ await (0, _nativeModule.requireNativeModule)().ckDeleteRecord(key, null);
159
+ return;
160
+ }
161
+ await (0, _config.getCloudKitClient)().deleteRecord(key);
162
+ } catch (e) {
163
+ throw (0, _errors.normalizeError)(e, NAME);
164
+ }
165
+ },
166
+ getAllKeys: async () => {
167
+ try {
168
+ if (isNative()) return await (0, _nativeModule.requireNativeModule)().ckQueryRecordNames('KVBlob', null);
169
+ return await (0, _config.getCloudKitClient)().queryRecordNames();
170
+ } catch (e) {
171
+ throw (0, _errors.normalizeError)(e, NAME);
172
+ }
173
+ },
174
+ /**
175
+ * Deliberately absent, rather than present and silent.
176
+ *
177
+ * This provider used to expose `onRemoteChange`, and it could never fire: the
178
+ * only `remoteChange` the native layer emits comes from
179
+ * `NSUbiquitousKeyValueStore.didChangeExternallyNotification` and is tagged
180
+ * `icloudKV`, so the filter here never matched. A subscription that accepts a
181
+ * listener and never calls it is worse than no method at all - the caller has
182
+ * no way to tell it apart from "nothing has changed yet".
183
+ *
184
+ * Implementing it properly is not a small gap to paper over. CloudKit reports
185
+ * record changes through `CKFetchRecordZoneChangesOperation` with a server
186
+ * change token, and that only works in a **custom zone** - the default zone,
187
+ * which this provider uses so that record names stay addressable from the
188
+ * REST client, does not support change tokens at all. The alternatives are a
189
+ * `CKDatabaseSubscription` delivered over APNs, which needs push entitlements
190
+ * and a silent-notification handler in the host app. Either is a real feature
191
+ * with a schema or entitlement cost, not a missing line.
192
+ *
193
+ * Until then: `cloudKit.onRemoteChange == null` is checkable, `icloudKV` and
194
+ * `googleDrive` both report changes, and `onAccountChange` below does fire.
195
+ */
196
+
197
+ onAccountChange: listener => {
198
+ if ((0, _nativeModule.getNativeModule)() == null) return () => undefined;
199
+ return (0, _nativeModule.subscribeNativeEvent)('onAccountChange', 'accountChange', e => {
200
+ listener({
201
+ status: (0, _enums.toAccountStatus)(e.status),
202
+ identityChanged: e.identityChanged,
203
+ provider: NAME
204
+ });
205
+ });
206
+ }
207
+ };
208
+
209
+ /**
210
+ * A CloudKit provider with its own REST credentials and its own name.
211
+ *
212
+ * `configureCloudKit` sets one client for the whole process. That is right for
213
+ * a normal app, but leaves no way to reach two containers at once - a staging
214
+ * container beside production, or a migration that copies between them - and no
215
+ * way for two tests to hold different configurations.
216
+ *
217
+ * REST only, and that is not a limitation that can be lifted: the native path
218
+ * authenticates as whatever iCloud account the *device* is signed into, so
219
+ * "another set of credentials" has no meaning there. On iOS this therefore
220
+ * still talks to CloudKit Web Services rather than to `CloudKit.framework`.
221
+ */
222
+ function createCloudKitProvider(config) {
223
+ const client = new _cloudKitRest.CloudKitRestClient(config);
224
+ const name = config.name ?? NAME;
225
+ return {
226
+ name,
227
+ isAvailable: async () => {
228
+ try {
229
+ return await client.isReachable();
230
+ } catch {
231
+ return false;
232
+ }
233
+ },
234
+ getAccountStatus: () => Promise.resolve('available'),
235
+ getItem: async key => {
236
+ try {
237
+ return await client.getRecord(key);
238
+ } catch (e) {
239
+ throw (0, _errors.normalizeError)(e, name);
240
+ }
241
+ },
242
+ getItemWithMeta: async key => {
243
+ try {
244
+ return await client.getRecordWithMeta(key);
245
+ } catch (e) {
246
+ throw (0, _errors.normalizeError)(e, name);
247
+ }
248
+ },
249
+ setItem: async (key, value) => {
250
+ try {
251
+ await client.saveRecord(key, value);
252
+ } catch (e) {
253
+ throw (0, _errors.normalizeError)(e, name);
254
+ }
255
+ },
256
+ removeItem: async key => {
257
+ try {
258
+ await client.deleteRecord(key);
259
+ } catch (e) {
260
+ throw (0, _errors.normalizeError)(e, name);
261
+ }
262
+ },
263
+ getAllKeys: async () => {
264
+ try {
265
+ return await client.queryRecordNames();
266
+ } catch (e) {
267
+ throw (0, _errors.normalizeError)(e, name);
268
+ }
269
+ },
270
+ multiGet: async keys => {
271
+ try {
272
+ return await client.getRecords(keys);
273
+ } catch (e) {
274
+ throw (0, _errors.normalizeError)(e, name);
275
+ }
276
+ },
277
+ multiSet: async entries => {
278
+ try {
279
+ await client.saveRecords(entries);
280
+ } catch (e) {
281
+ throw (0, _errors.normalizeError)(e, name);
282
+ }
283
+ },
284
+ multiRemove: async keys => {
285
+ try {
286
+ await client.deleteRecords(keys);
287
+ } catch (e) {
288
+ throw (0, _errors.normalizeError)(e, name);
289
+ }
290
+ },
291
+ clearCaches: () => {
292
+ client.clearCache();
293
+ }
294
+ };
295
+ }
296
+
297
+ /** Custom zones. Native only - the REST client uses the default zone. */
298
+ const zones = exports.zones = {
299
+ create: async zoneName => {
300
+ try {
301
+ await (0, _nativeModule.requireNativeModule)().ckCreateZone(zoneName);
302
+ } catch (e) {
303
+ throw (0, _errors.normalizeError)(e, NAME);
304
+ }
305
+ },
306
+ remove: async zoneName => {
307
+ try {
308
+ await (0, _nativeModule.requireNativeModule)().ckDeleteZone(zoneName);
309
+ } catch (e) {
310
+ throw (0, _errors.normalizeError)(e, NAME);
311
+ }
312
+ },
313
+ list: async () => {
314
+ try {
315
+ return await (0, _nativeModule.requireNativeModule)().ckListZones();
316
+ } catch (e) {
317
+ throw (0, _errors.normalizeError)(e, NAME);
318
+ }
319
+ }
320
+ };
321
+
322
+ /**
323
+ * Binary assets (`CKAsset`).
324
+ *
325
+ * Native only. CloudKit Web Services does expose an asset upload flow, but it
326
+ * is a separate multi-step protocol (request an upload URL, POST the bytes,
327
+ * then reference the returned token in a record) that this package does not
328
+ * implement yet - so on Android and web these reject with
329
+ * `ERR_UNSUPPORTED_PLATFORM` rather than appearing to work.
330
+ *
331
+ * Assets are deliberately an explicit API rather than something the store
332
+ * facade routes to automatically: the caller passes a file path, not a string,
333
+ * so there is no way to infer the intent from a `setItem` call.
334
+ */
335
+ const assets = exports.assets = {
336
+ /**
337
+ * Uploads a local file as a field on a record.
338
+ *
339
+ * Progress is reported per record through {@link onProgress}; a CKAsset is
340
+ * streamed from disk, so a large file does not have to be held in memory the
341
+ * way a base64 round trip would.
342
+ */
343
+ save: async options => {
344
+ if (!isNative()) throw (0, _errors.unsupportedPlatform)(NAME, 'CKAsset upload is implemented natively only. On Android and web, store the file ' + 'with the googleDrive provider instead.');
345
+ try {
346
+ await (0, _nativeModule.requireNativeModule)().ckSaveAsset(options.recordType ?? 'KVBlob', options.recordName, options.fieldName, options.fileUri, options.zoneName ?? null);
347
+ } catch (e) {
348
+ throw (0, _errors.normalizeError)(e, NAME);
349
+ }
350
+ },
351
+ /**
352
+ * Downloads an asset field and resolves a local file path, or `null` when the
353
+ * record or field does not exist.
354
+ *
355
+ * Pass `destinationUri` for anything the user is going to keep or hand to a
356
+ * share sheet. Without it the file lands in the app's temporary directory
357
+ * under a name derived from the record, and iOS may reclaim that at any
358
+ * time - fine for restoring straight back into the app, wrong for an export.
359
+ * Parent directories are created if they do not exist.
360
+ */
361
+ fetch: async options => {
362
+ if (!isNative()) throw (0, _errors.unsupportedPlatform)(NAME, 'CKAsset download is implemented natively only.');
363
+ try {
364
+ return await (0, _nativeModule.requireNativeModule)().ckFetchAsset(options.recordName, options.fieldName, options.zoneName ?? null, options.destinationUri ?? null);
365
+ } catch (e) {
366
+ throw (0, _errors.normalizeError)(e, NAME);
367
+ }
368
+ },
369
+ /**
370
+ * Cancels an in-flight {@link save} or {@link fetch}, rejecting that call
371
+ * with `ERR_CANCELLED`. Resolves true when there was a transfer to cancel.
372
+ *
373
+ * Identified by record and field rather than by a handle, because that is
374
+ * what identifies a transfer everywhere else in this API - `onProgress`
375
+ * reports the same pair, so a UI already has it.
376
+ */
377
+ cancel: async options => {
378
+ if (!isNative()) return false;
379
+ try {
380
+ return await (0, _nativeModule.requireNativeModule)().ckCancelAsset(options.recordName, options.fieldName);
381
+ } catch (e) {
382
+ throw (0, _errors.normalizeError)(e, NAME);
383
+ }
384
+ },
385
+ /** Upload/download progress for asset transfers. Native only. */
386
+ onProgress: listener => {
387
+ if ((0, _nativeModule.getNativeModule)() == null) return () => undefined;
388
+ return (0, _nativeModule.subscribeNativeEvent)('onAssetProgress', 'assetProgress', e => {
389
+ listener({
390
+ recordName: e.recordName,
391
+ fieldName: e.fieldName,
392
+ bytesTransferred: e.bytesTransferred,
393
+ bytesTotal: e.bytesTotal
394
+ });
395
+ });
396
+ }
397
+ };
398
+ //# sourceMappingURL=cloudKit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","_nativeModule","_config","_cloudKitRest","_errors","_enums","NAME","isNative","os","Platform","OS","hasNativeModule","cloudKit","exports","name","isAvailable","requireNativeModule","isCloudKitConfigured","getCloudKitClient","isReachable","getAccountStatus","toAccountStatus","e","normalizeError","getItem","key","ckGetRecord","getRecord","getItemWithMeta","value","getRecordWithMeta","multiGet","keys","out","push","getRecords","multiSet","entries","ckSaveRecord","saveRecords","multiRemove","ckDeleteRecord","deleteRecords","clearCaches","clearCache","setItem","saveRecord","removeItem","deleteRecord","getAllKeys","ckQueryRecordNames","queryRecordNames","onAccountChange","listener","getNativeModule","undefined","subscribeNativeEvent","status","identityChanged","provider","createCloudKitProvider","config","client","CloudKitRestClient","Promise","resolve","zones","create","zoneName","ckCreateZone","remove","ckDeleteZone","list","ckListZones","assets","save","options","unsupportedPlatform","ckSaveAsset","recordType","recordName","fieldName","fileUri","fetch","ckFetchAsset","destinationUri","cancel","ckCancelAsset","onProgress","bytesTransferred","bytesTotal"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gF,MAAM,EAAE,MACNV,OAAkD,IAC7B;IACrB,IAAI,CAACrE,QAAQ,CAAC,CAAC,EAAE,OAAO,KAAK;IAC7B,IAAI;MACF,OAAO,MAAM,IAAAS,iCAAmB,EAAC,CAAC,CAACuE,aAAa,CAACX,OAAO,CAACI,UAAU,EAAEJ,OAAO,CAACK,SAAS,CAAC;IACzF,CAAC,CACD,OAAO3D,CAAC,EAAE;MACR,MAAM,IAAAC,sBAAc,EAACD,CAAC,EAAEhB,IAAI,CAAC;IAC/B;EACF,CAAC;EAED;EACAkF,UAAU,EAAGnC,QAAyC,IAAkB;IACtE,IAAI,IAAAC,6BAAe,EAAC,CAAC,IAAI,IAAI,EAAE,OAAO,MAAMC,SAAS;IACrD,OAAO,IAAAC,kCAAoB,EACzB,iBAAiB,EACjB,eAAe,EACdlC,CAAC,IAAK;MACL+B,QAAQ,CAAC;QACP2B,UAAU,EAAE1D,CAAC,CAAC0D,UAAU;QACxBC,SAAS,EAAE3D,CAAC,CAAC2D,SAAS;QACtBQ,gBAAgB,EAAEnE,CAAC,CAACmE,gBAAgB;QACpCC,UAAU,EAAEpE,CAAC,CAACoE;MAChB,CAAC,CAAC;IACJ,CACF,CAAC;EACH;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cloudKitBackup = void 0;
7
+ var _cloudKit = require("./cloudKit.js");
8
+ const DEFAULT_RECORD_NAME = 'backup';
9
+ const DEFAULT_FIELD_NAME = 'file';
10
+ /**
11
+ * Backup/restore built on {@link assets} (`CKAsset`), for a single named blob -
12
+ * a database export, an archive, anything too big for a `CKRecord` field.
13
+ *
14
+ * `cloudKitAssets.onProgress` is a global feed shared by every asset transfer
15
+ * in the app, keyed by `recordName`/`fieldName`, so a caller backing up one
16
+ * file would otherwise have to filter it and manage the subscription by hand.
17
+ * This scopes that to the single transfer each call makes, and unsubscribes
18
+ * when it settles - including on failure.
19
+ *
20
+ * Native only, same as `cloudKitAssets` - rejects with `ERR_UNSUPPORTED_PLATFORM`
21
+ * on Android and web.
22
+ */
23
+ const cloudKitBackup = exports.cloudKitBackup = {
24
+ /**
25
+ * Uploads `fileUri` as this backup's CKAsset, overwriting whatever was there.
26
+ */
27
+ save: async (fileUri, options = {}) => {
28
+ const recordName = options.recordName ?? DEFAULT_RECORD_NAME;
29
+ const fieldName = options.fieldName ?? DEFAULT_FIELD_NAME;
30
+ const unsubscribe = subscribeScoped(recordName, fieldName, options.onProgress);
31
+ try {
32
+ await _cloudKit.assets.save({
33
+ recordName,
34
+ fieldName,
35
+ fileUri,
36
+ zoneName: options.zoneName
37
+ });
38
+ } finally {
39
+ unsubscribe();
40
+ }
41
+ },
42
+ /**
43
+ * Downloads the backup to a local file path, or resolves `null` when none
44
+ * has been saved yet.
45
+ */
46
+ restore: async (options = {}) => {
47
+ const recordName = options.recordName ?? DEFAULT_RECORD_NAME;
48
+ const fieldName = options.fieldName ?? DEFAULT_FIELD_NAME;
49
+ const unsubscribe = subscribeScoped(recordName, fieldName, options.onProgress);
50
+ try {
51
+ return await _cloudKit.assets.fetch({
52
+ recordName,
53
+ fieldName,
54
+ zoneName: options.zoneName,
55
+ destinationUri: options.destinationUri
56
+ });
57
+ } finally {
58
+ unsubscribe();
59
+ }
60
+ },
61
+ /**
62
+ * Cancels a `save` or `restore` in progress, rejecting that call with
63
+ * `ERR_CANCELLED`. Resolves true when there was one to cancel.
64
+ *
65
+ * A backup is the transfer users are most likely to want to stop - it is the
66
+ * biggest, and it is the one they start by accident. Takes the same
67
+ * `recordName`/`fieldName` defaults as the call it cancels, so cancelling the
68
+ * default backup is `cloudKitBackup.cancel()`.
69
+ */
70
+ cancel: async (options = {}) => await _cloudKit.assets.cancel({
71
+ recordName: options.recordName ?? DEFAULT_RECORD_NAME,
72
+ fieldName: options.fieldName ?? DEFAULT_FIELD_NAME
73
+ })
74
+ };
75
+ function subscribeScoped(recordName, fieldName, onProgress) {
76
+ if (onProgress == null) return () => undefined;
77
+ return _cloudKit.assets.onProgress(e => {
78
+ if (e.recordName !== recordName || e.fieldName !== fieldName) return;
79
+ onProgress({
80
+ bytesTransferred: e.bytesTransferred,
81
+ bytesTotal: e.bytesTotal,
82
+ fraction: e.bytesTotal > 0 ? e.bytesTransferred / e.bytesTotal : 0
83
+ });
84
+ });
85
+ }
86
+ //# sourceMappingURL=cloudKitBackup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_cloudKit","require","DEFAULT_RECORD_NAME","DEFAULT_FIELD_NAME","cloudKitBackup","exports","save","fileUri","options","recordName","fieldName","unsubscribe","subscribeScoped","onProgress","assets","zoneName","restore","fetch","destinationUri","cancel","undefined","e","bytesTransferred","bytesTotal","fraction"],"sourceRoot":"../../../src","sources":["providers/cloudKitBackup.ts"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAGA,MAAMC,mBAAmB,GAAG,QAAQ;AACpC,MAAMC,kBAAkB,GAAG,MAAM;AAkCjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG;EAC5B;AACF;AACA;EACEE,IAAI,EAAE,MAAAA,CAAOC,OAAe,EAAEC,OAAsB,GAAG,CAAC,CAAC,KAAoB;IAC3E,MAAMC,UAAU,GAAGD,OAAO,CAACC,UAAU,IAAIP,mBAAmB;IAC5D,MAAMQ,SAAS,GAAGF,OAAO,CAACE,SAAS,IAAIP,kBAAkB;IAEzD,MAAMQ,WAAW,GAAGC,eAAe,CAACH,UAAU,EAAEC,SAAS,EAAEF,OAAO,CAACK,UAAU,CAAC;IAC9E,IAAI;MACF,MAAMC,gBAAM,CAACR,IAAI,CAAC;QAAEG,UAAU;QAAEC,SAAS;QAAEH,OAAO;QAAEQ,QAAQ,EAAEP,OAAO,CAACO;MAAS,CAAC,CAAC;IACnF,CAAC,SACO;MACNJ,WAAW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AAG,CAAC,GAAGF,CAAC,CAACC,gBAAgB,GAAGD,CAAC,CAACE,UAAU,GAAG;IACnE,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cloudKitEncrypted = void 0;
7
+ var _reactNative = require("react-native");
8
+ var _nativeModule = require("../internal/nativeModule.js");
9
+ var _errors = require("../errors.js");
10
+ var _enums = require("../internal/enums.js");
11
+ const NAME = 'cloudKitEncrypted';
12
+
13
+ /**
14
+ * A record type of its own, deliberately.
15
+ *
16
+ * CloudKit records encryption in the *schema*: a field is encrypted or plain,
17
+ * never both. Writing an encrypted `value` onto the same `KVBlob` type that
18
+ * `cloudKit` uses for a plain one is a field-type conflict the server rejects,
19
+ * so the two providers must not share a record type.
20
+ */
21
+ const RECORD_TYPE = 'EncryptedKVBlob';
22
+ function isNative() {
23
+ const os = _reactNative.Platform?.OS;
24
+ return (os === 'ios' || os === 'macos') && (0, _nativeModule.hasNativeModule)();
25
+ }
26
+ function assertNative() {
27
+ if (!isNative()) throw (0, _errors.unsupportedPlatform)(NAME, 'CloudKit end-to-end encryption is not a feature this package could add over REST. The key ' + 'lives in the user\'s iCloud Keychain and never reaches Apple\'s servers, so CloudKit Web ' + 'Services - the Android and web path - has nothing to decrypt with. Use the store facade ' + 'with a `codec` for cross-platform encryption you hold the key to.');
28
+ }
29
+
30
+ /**
31
+ * CloudKit's own end-to-end encryption, via `CKRecord.encryptedValues`.
32
+ *
33
+ * The genuinely native answer to "can I store sensitive data here". Values
34
+ * written through this provider are encrypted on device with a key from the
35
+ * user's iCloud Keychain; Apple stores ciphertext and cannot read it, whether
36
+ * or not the user has turned on Advanced Data Protection. Nothing to configure,
37
+ * no key for you to manage, no passphrase for the user to lose.
38
+ *
39
+ * What it costs, and none of these are avoidable:
40
+ *
41
+ * - **Apple platforms only.** The decryption key is in the iCloud Keychain,
42
+ * which CloudKit Web Services cannot reach, so a value written here is
43
+ * permanently unreadable from Android and web. Not a gap to be closed
44
+ * later - it is what end-to-end means. Reach for the store facade's
45
+ * `codec` if the same data has to be readable off-Apple.
46
+ * - **Not queryable.** CloudKit cannot index an encrypted field, so no
47
+ * server-side filtering or sorting on the value. `getAllKeys()` still
48
+ * works, because it queries record *names*, which are not encrypted.
49
+ * - **Record names are not encrypted either.** Your keys are visible to
50
+ * Apple; only values are protected. Do not put anything sensitive in a key.
51
+ * - **Its own record type** (`EncryptedKVBlob`), so it can coexist with
52
+ * `cloudKit` rather than colliding with its schema.
53
+ *
54
+ * Usable through the facade like any other provider, as long as every provider
55
+ * in the list can actually serve the data:
56
+ *
57
+ * ```ts
58
+ * const secrets = createCloudStore({ providers: ['cloudKitEncrypted'] })
59
+ * ```
60
+ *
61
+ * Mixing it with `googleDrive` in one store is almost always a mistake - the
62
+ * Drive copy would be plaintext, which quietly undoes the encryption.
63
+ */
64
+ const cloudKitEncrypted = exports.cloudKitEncrypted = {
65
+ name: NAME,
66
+ isAvailable: async () => {
67
+ // Not an error on Android or web: `isAvailable` is the method callers use
68
+ // to branch without a try/catch, and this provider genuinely is not
69
+ // available there.
70
+ if (!isNative()) return false;
71
+ try {
72
+ return await (0, _nativeModule.requireNativeModule)().isAvailable();
73
+ } catch {
74
+ return false;
75
+ }
76
+ },
77
+ getAccountStatus: async () => {
78
+ if (!isNative()) return 'couldNotDetermine';
79
+ try {
80
+ const m = (0, _nativeModule.getNativeModule)();
81
+ if (m == null) return 'couldNotDetermine';
82
+ return (0, _enums.toAccountStatus)(await m.getAccountStatus());
83
+ } catch (e) {
84
+ throw (0, _errors.normalizeError)(e, NAME);
85
+ }
86
+ },
87
+ getItem: async key => {
88
+ assertNative();
89
+ try {
90
+ return await (0, _nativeModule.requireNativeModule)().ckGetRecord(RECORD_TYPE, key, null, true);
91
+ } catch (e) {
92
+ throw (0, _errors.normalizeError)(e, NAME);
93
+ }
94
+ },
95
+ setItem: async (key, value) => {
96
+ assertNative();
97
+ try {
98
+ await (0, _nativeModule.requireNativeModule)().ckSaveRecord(RECORD_TYPE, key, value, null, true);
99
+ } catch (e) {
100
+ throw (0, _errors.normalizeError)(e, NAME);
101
+ }
102
+ },
103
+ removeItem: async key => {
104
+ assertNative();
105
+ try {
106
+ await (0, _nativeModule.requireNativeModule)().ckDeleteRecord(key, null);
107
+ } catch (e) {
108
+ throw (0, _errors.normalizeError)(e, NAME);
109
+ }
110
+ },
111
+ /**
112
+ * Record names, which CloudKit does not encrypt - so listing works even
113
+ * though the values cannot be queried.
114
+ */
115
+ getAllKeys: async () => {
116
+ assertNative();
117
+ try {
118
+ return await (0, _nativeModule.requireNativeModule)().ckQueryRecordNames(RECORD_TYPE, null);
119
+ } catch (e) {
120
+ throw (0, _errors.normalizeError)(e, NAME);
121
+ }
122
+ },
123
+ multiGet: async keys => {
124
+ assertNative();
125
+ try {
126
+ const out = [];
127
+ for (const key of keys) out.push(await (0, _nativeModule.requireNativeModule)().ckGetRecord(RECORD_TYPE, key, null, true));
128
+ return out;
129
+ } catch (e) {
130
+ throw (0, _errors.normalizeError)(e, NAME);
131
+ }
132
+ },
133
+ multiSet: async entries => {
134
+ assertNative();
135
+ try {
136
+ for (const [key, value] of entries) await (0, _nativeModule.requireNativeModule)().ckSaveRecord(RECORD_TYPE, key, value, null, true);
137
+ } catch (e) {
138
+ throw (0, _errors.normalizeError)(e, NAME);
139
+ }
140
+ },
141
+ multiRemove: async keys => {
142
+ assertNative();
143
+ try {
144
+ for (const key of keys) await (0, _nativeModule.requireNativeModule)().ckDeleteRecord(key, null);
145
+ } catch (e) {
146
+ throw (0, _errors.normalizeError)(e, NAME);
147
+ }
148
+ }
149
+ };
150
+ //# sourceMappingURL=cloudKitEncrypted.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","_nativeModule","_errors","_enums","NAME","RECORD_TYPE","isNative","os","Platform","OS","hasNativeModule","assertNative","unsupportedPlatform","cloudKitEncrypted","exports","name","isAvailable","requireNativeModule","getAccountStatus","m","getNativeModule","toAccountStatus","e","normalizeError","getItem","key","ckGetRecord","setItem","value","ckSaveRecord","removeItem","ckDeleteRecord","getAllKeys","ckQueryRecordNames","multiGet","keys","out","push","multiSet","entries","multiRemove"],"sourceRoot":"../../../src","sources":["providers/cloudKitEncrypted.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAGA,MAAMI,IAAI,GAAG,mBAA4B;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAG,iBAAiB;AAErC,SAASC,QAAQA,CAAA,EAAY;EAC3B,MAAMC,EAAsB,GAAGC,qBAAQ,EAAEC,EAAE;EAC3C,OAAO,CAACF,EAAE,KAAK,KAAK,IAAIA,EAAE,KAAK,OAAO,KAAK,IAAAG,6BAAe,EAAC,CAAC;AAC9D;AAEA,SAASC,YAAYA,CAAA,EAAS;EAC5B,IAAI,CAACL,QAAQ,CAAC,CAAC,EACb,MAAM,IAAAM,2BAAmB,EACvBR,IAAI,EACJ,4FAA4F,GAC1F,2FAA2F,GAC3F,0FAA0F,GAC1F,mEACJ,CAAC;AACL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMS,iBAAgC,GAAAC,OAAA,CAAAD,iBAAA,GAAG;EAC9CE,IAAI,EAAEX,IAAI;EAEVY,WAAW,EAAE,MAAAA,CAAA,KAAY;IACvB;IACA;IACA;IACA,IAAI,CAACV,QAAQ,CAAC,CAAC,EAAE,OAAO,KAAK;IAC7B,IAAI;MACF,OAAO,MAAM,IAAAW,iCAAmB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