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