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,33 @@
1
+ import type { CloudKitRestConfig } from './internal/cloudKitRest.js';
2
+ import { CloudKitRestClient } from './internal/cloudKitRest.js';
3
+ import type { GoogleDriveConfig, GoogleDriveFileAdapter } from './internal/googleDriveRest.js';
4
+ import { GoogleDriveClient } from './internal/googleDriveRest.js';
5
+ /**
6
+ * Supplies the credentials the CloudKit REST path needs.
7
+ *
8
+ * Only required on Android and web. On iOS the native provider authenticates
9
+ * implicitly through the device's signed-in iCloud account and needs none of
10
+ * this.
11
+ */
12
+ export declare function configureCloudKit(config: CloudKitRestConfig): void;
13
+ export declare function getCloudKitClient(): CloudKitRestClient;
14
+ export declare function isCloudKitConfigured(): boolean;
15
+ /** Supplies the OAuth token the Drive provider uses. Required on every platform. */
16
+ export declare function configureGoogleDrive(config: GoogleDriveConfig): void;
17
+ export declare function getGoogleDriveClient(): GoogleDriveClient;
18
+ export declare function isGoogleDriveConfigured(): boolean;
19
+ /**
20
+ * Supplies local file I/O for `googleDriveFiles` - large binaries that go
21
+ * through Drive's resumable upload/download rather than `googleDrive`'s
22
+ * whole-value-as-a-string path.
23
+ *
24
+ * Separate from `configureGoogleDrive` because most apps never touch a file
25
+ * that large and shouldn't need to think about filesystem access to use
26
+ * `googleDrive`/the store facade. Only required for `googleDriveFiles`.
27
+ */
28
+ export declare function configureGoogleDriveFiles(adapter: GoogleDriveFileAdapter): void;
29
+ export declare function getGoogleDriveFileAdapter(): GoogleDriveFileAdapter;
30
+ export declare function isGoogleDriveFilesConfigured(): boolean;
31
+ /** Test seam - drops all configured clients. */
32
+ export declare function __resetConfig(): void;
33
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAAyB,CAAA;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAAyB,CAAA;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,+BAA4B,CAAA;AAC3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA4B,CAAA;AAO9D;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI,CAElE;AAED,wBAAgB,iBAAiB,IAAI,kBAAkB,CAWtD;AAED,wBAAgB,oBAAoB,IAAI,OAAO,CAE9C;AAED,oFAAoF;AACpF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAEpE;AAED,wBAAgB,oBAAoB,IAAI,iBAAiB,CAUxD;AAED,wBAAgB,uBAAuB,IAAI,OAAO,CAEjD;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,sBAAsB,GAAG,IAAI,CAE/E;AAED,wBAAgB,yBAAyB,IAAI,sBAAsB,CAUlE;AAED,wBAAgB,4BAA4B,IAAI,OAAO,CAEtD;AAED,gDAAgD;AAChD,wBAAgB,aAAa,IAAI,IAAI,CAIpC"}
@@ -0,0 +1,140 @@
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
+ * Stable, cross-platform failure codes.
24
+ *
25
+ * These strings are duplicated in `ios/CloudSyncError.swift` - the only other
26
+ * place that raises them, since Android and web reach CloudKit and Drive over
27
+ * REST from this same TypeScript. They are part of the public API: apps branch
28
+ * on them, so treat a change here as a breaking change.
29
+ */
30
+ export declare const ErrorCode: {
31
+ /** No iCloud/Drive account is signed in on the device. */
32
+ readonly NOT_SIGNED_IN: "ERR_NOT_SIGNED_IN";
33
+ /** An account exists but is restricted (parental controls, MDM). */
34
+ readonly ACCOUNT_RESTRICTED: "ERR_ACCOUNT_RESTRICTED";
35
+ /** CloudKit reported `.temporarilyUnavailable` - retry later. */
36
+ readonly ACCOUNT_UNAVAILABLE: "ERR_ACCOUNT_UNAVAILABLE";
37
+ /** CloudKit could not determine account status. Not the same as signed out. */
38
+ readonly ACCOUNT_UNDETERMINED: "ERR_ACCOUNT_UNDETERMINED";
39
+ /** A previously valid credential expired. On Android CloudKit this is routine: */
40
+ /** a `ckWebAuthToken` lives 30 minutes, or 2 weeks if the user ticked */
41
+ /** "Keep me signed in". There is no documented refresh - re-auth is required. */
42
+ readonly AUTH_EXPIRED: "ERR_AUTH_EXPIRED";
43
+ /** Device is offline, or the request could not reach the server. */
44
+ readonly NETWORK_UNAVAILABLE: "ERR_NETWORK_UNAVAILABLE";
45
+ /** The user's iCloud/Drive storage is full. */
46
+ readonly QUOTA_EXCEEDED: "ERR_QUOTA_EXCEEDED";
47
+ /** Server asked us to back off. Carries `retryAfterMs` when the server said so. */
48
+ readonly RATE_LIMITED: "ERR_RATE_LIMITED";
49
+ /** Value exceeds the backing store's limit. Carries `limitBytes`/`actualBytes`. */
50
+ readonly PAYLOAD_TOO_LARGE: "ERR_PAYLOAD_TOO_LARGE";
51
+ /**
52
+ * The key cannot round-trip through the configured providers - illegal
53
+ * characters, too long, or a reserved prefix. Raised before the request, so
54
+ * it never reaches the server as a confusing `BAD_REQUEST`.
55
+ */
56
+ readonly INVALID_KEY: "ERR_INVALID_KEY";
57
+ /** The operation ran longer than the configured timeout. */
58
+ readonly TIMEOUT: "ERR_TIMEOUT";
59
+ /** A concurrent write won. Carries `serverValue` so the app can merge. */
60
+ readonly CONFLICT: "ERR_CONFLICT";
61
+ /** Entitlements, container identifier or API token are missing or wrong. */
62
+ readonly CONTAINER_MISCONFIGURED: "ERR_CONTAINER_MISCONFIGURED";
63
+ /** This provider has no implementation on the current platform. */
64
+ readonly UNSUPPORTED_PLATFORM: "ERR_UNSUPPORTED_PLATFORM";
65
+ /** The operation was cancelled by the caller. */
66
+ readonly CANCELLED: "ERR_CANCELLED";
67
+ /** Anything the native layer could not classify. `cause` holds the original. */
68
+ readonly UNKNOWN: "ERR_UNKNOWN";
69
+ };
70
+ export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
71
+ export interface CloudSyncErrorInfo {
72
+ /** Milliseconds to wait before retrying. Set on {@link ErrorCode.RATE_LIMITED}. */
73
+ retryAfterMs?: number;
74
+ /** The store's size limit in bytes. Set on {@link ErrorCode.PAYLOAD_TOO_LARGE}. */
75
+ limitBytes?: number;
76
+ /** The rejected payload's size in bytes. Set on {@link ErrorCode.PAYLOAD_TOO_LARGE}. */
77
+ actualBytes?: number;
78
+ /** The value currently on the server. Set on {@link ErrorCode.CONFLICT}. */
79
+ serverValue?: string | null;
80
+ /** Which provider raised this. */
81
+ provider?: string;
82
+ /**
83
+ * The backend's own error code, when there was one - e.g. CloudKit Web
84
+ * Services' `EXISTS` or `ATOMIC_ERROR`. Useful for diagnosing a response
85
+ * that this package classified as `ERR_UNKNOWN`.
86
+ */
87
+ serverErrorCode?: string;
88
+ /** The underlying native or network error, when there was one. */
89
+ cause?: unknown;
90
+ }
91
+ /**
92
+ * The single error type every operation in this package rejects with.
93
+ *
94
+ * `instanceof` is deliberately not the recommended check - a rejected promise
95
+ * crossing the React Native bridge arrives as a plain object on some paths, so
96
+ * {@link isCloudSyncError} tests the shape instead.
97
+ */
98
+ export declare class CloudSyncError extends Error implements CloudSyncErrorInfo {
99
+ readonly code: ErrorCode;
100
+ readonly retryAfterMs?: number;
101
+ readonly limitBytes?: number;
102
+ readonly actualBytes?: number;
103
+ readonly serverValue?: string | null;
104
+ readonly provider?: string;
105
+ readonly serverErrorCode?: string;
106
+ readonly cause?: unknown;
107
+ constructor(code: ErrorCode, message: string, info?: CloudSyncErrorInfo);
108
+ }
109
+ /** Narrowing guard that works on both real instances and bridged plain objects. */
110
+ export declare function isCloudSyncError(e: unknown): e is CloudSyncError;
111
+ /**
112
+ * True when retrying the same call later could plausibly succeed.
113
+ *
114
+ * TIMEOUT is in this set because running out of time says nothing about whether
115
+ * the operation is possible - only that this attempt took too long.
116
+ */
117
+ export declare function isRetryable(e: unknown): boolean;
118
+ /** True when the user must take an action (sign in, free up space) to proceed. */
119
+ export declare function requiresUserAction(e: unknown): boolean;
120
+ /**
121
+ * Normalises whatever the native layer rejected with into a `CloudSyncError`.
122
+ *
123
+ * React Native's bridge turns `reject(code, message, nativeError)` into an Error
124
+ * whose `code` is the string we chose natively, so the common path is a simple
125
+ * re-wrap. Anything unrecognised becomes {@link ErrorCode.UNKNOWN} rather than
126
+ * being swallowed.
127
+ */
128
+ export declare function normalizeError(e: unknown, provider?: string): CloudSyncError;
129
+ /**
130
+ * True when the caller asked for this - a cancelled operation is not a fault to
131
+ * report, and a UI that shows an error toast for one is wrong.
132
+ */
133
+ export declare function isCancelled(e: unknown): boolean;
134
+ /** The rejection an aborted operation produces. */
135
+ export declare function cancelled(provider?: string, detail?: string): CloudSyncError;
136
+ /** The rejection a timed-out operation produces. */
137
+ export declare function timedOut(ms: number, provider?: string): CloudSyncError;
138
+ /** Convenience constructor for the platform-capability guards. */
139
+ export declare function unsupportedPlatform(provider: string, detail: string): CloudSyncError;
140
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS;IACpB,0DAA0D;;IAE1D,oEAAoE;;IAEpE,iEAAiE;;IAEjE,+EAA+E;;IAE/E,kFAAkF;IAClF,yEAAyE;IACzE,iFAAiF;;IAEjF,oEAAoE;;IAEpE,+CAA+C;;IAE/C,mFAAmF;;IAEnF,mFAAmF;;IAEnF;;;;OAIG;;IAEH,4DAA4D;;IAE5D,0EAA0E;;IAE1E,4EAA4E;;IAE5E,mEAAmE;;IAEnE,iDAAiD;;IAEjD,gFAAgF;;CAExE,CAAA;AAEV,MAAM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B,kBAAkB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAWtD;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,cAAc,CAmB5E;AAkCD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAE/C;AAED,mDAAmD;AACnD,wBAAgB,SAAS,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,SAAiC,GAAG,cAAc,CAEpG;AAED,oDAAoD;AACpD,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,cAAc,CAMtE;AAED,kEAAkE;AAClE,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CAMpF"}
@@ -0,0 +1,109 @@
1
+ import type { CloudStore } from './store.js';
2
+ import { type CloudSyncError } from './errors.js';
3
+ import type { AccountStatus, CloudProvider, OutboxEntry, RemoteChangeEvent } from './types.js';
4
+ /**
5
+ * React bindings.
6
+ *
7
+ * A separate entry point (`react-native-cloud-sync/hooks`) so the main one
8
+ * stays free of a React import - the store is usable from a saga, a background
9
+ * task or a plain module, and none of those should pull in a renderer.
10
+ *
11
+ * These exist because every app was writing the same three of them, and each
12
+ * one has the same two bugs: a response that arrives after the key changed
13
+ * overwrites the newer one, and a `setState` after unmount. Both are handled
14
+ * here once.
15
+ */
16
+ export interface UseCloudItemResult<T> {
17
+ value: T | null;
18
+ /** True until the first read settles, and during an explicit `refresh()`. */
19
+ loading: boolean;
20
+ /** The last read or write failure, or null. Cleared by the next success. */
21
+ error: CloudSyncError | null;
22
+ /** Writes through to the store and updates local state optimistically. */
23
+ setValue: (next: T) => Promise<void>;
24
+ remove: () => Promise<void>;
25
+ /** Re-reads from the store. */
26
+ refresh: () => Promise<void>;
27
+ }
28
+ export interface UseCloudItemOptions<T> {
29
+ /** Returned while loading, and when the key does not exist. Default null. */
30
+ initialValue?: T | null;
31
+ /**
32
+ * How the stored string becomes a `T`. Defaults to `JSON.parse`.
33
+ *
34
+ * Pass identity functions for a plain string value.
35
+ */
36
+ parse?: (raw: string) => T;
37
+ serialize?: (value: T) => string;
38
+ /**
39
+ * Re-read when another device changes this key. Default true.
40
+ *
41
+ * This is the whole reason the store exposes `onRemoteChange`: without it a
42
+ * screen shows whatever it read when it mounted, and the second device's edit
43
+ * appears only after a manual pull-to-refresh.
44
+ */
45
+ watch?: boolean;
46
+ }
47
+ /**
48
+ * Binds one key to component state.
49
+ *
50
+ * ```tsx
51
+ * const { value, setValue, loading } = useCloudItem<Settings>(store, 'settings')
52
+ * ```
53
+ */
54
+ export declare function useCloudItem<T = unknown>(store: CloudStore, key: string, options?: UseCloudItemOptions<T>): UseCloudItemResult<T>;
55
+ export interface UseAccountStatusResult {
56
+ status: AccountStatus | null;
57
+ /**
58
+ * True once a *different* identity has signed in since this hook mounted.
59
+ *
60
+ * The signal to drop user-scoped caches. Latched rather than momentary, so a
61
+ * screen that mounts just after the event still sees it.
62
+ */
63
+ identityChanged: boolean;
64
+ error: CloudSyncError | null;
65
+ refresh: () => Promise<void>;
66
+ }
67
+ /**
68
+ * Tracks a provider's account state, including the identity-switch event.
69
+ *
70
+ * ```tsx
71
+ * const { status, identityChanged } = useAccountStatus(icloudKV)
72
+ * if (status === 'noAccount') return <SignInPrompt />
73
+ * ```
74
+ */
75
+ export declare function useAccountStatus(provider: CloudProvider): UseAccountStatusResult;
76
+ export interface UsePendingWritesResult {
77
+ pending: OutboxEntry[];
78
+ /** Runs a flush now and refreshes the list. */
79
+ flush: () => Promise<void>;
80
+ /** Abandons queued writes, then refreshes the list. */
81
+ discard: (filter?: (e: OutboxEntry) => boolean) => void;
82
+ }
83
+ /**
84
+ * Drives a "pending sync" indicator.
85
+ *
86
+ * `pendingWrites()` is a synchronous read of a small JSON blob, so polling it
87
+ * is cheap - and there is no event to subscribe to, because entries are added
88
+ * from whichever call site failed rather than from one place that could emit.
89
+ */
90
+ export declare function usePendingWrites(store: CloudStore, pollIntervalMs?: number): UsePendingWritesResult;
91
+ /**
92
+ * Subscribes to remote-change events for the life of the component.
93
+ *
94
+ * The listener is held in a ref, so passing an inline arrow function does not
95
+ * tear down and rebuild the subscription on every render.
96
+ */
97
+ export declare function useRemoteChange(store: CloudStore, listener: (e: RemoteChangeEvent) => void): void;
98
+ /**
99
+ * Per-provider storage usage, refreshed on demand.
100
+ *
101
+ * Not polled: `getQuota` is a network round trip per provider, and a number
102
+ * that moves this slowly does not need watching.
103
+ */
104
+ export declare function useQuota(store: CloudStore): {
105
+ quota: Awaited<ReturnType<CloudStore['getQuota']>>;
106
+ loading: boolean;
107
+ refresh: () => Promise<void>;
108
+ };
109
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/hooks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAS,CAAA;AACzC,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,aAAU,CAAA;AAC9D,OAAO,KAAK,EAEV,aAAa,EACb,aAAa,EACb,WAAW,EACX,iBAAiB,EAClB,MAAM,YAAS,CAAA;AAEhB;;;;;;;;;;;GAWG;AAEH,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACnC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;IACf,6EAA6E;IAC7E,OAAO,EAAE,OAAO,CAAA;IAChB,4EAA4E;IAC5E,KAAK,EAAE,cAAc,GAAG,IAAI,CAAA;IAC5B,0EAA0E;IAC1E,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACpC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3B,+BAA+B;IAC/B,OAAO,EAAE,MAAM,OAAO,CAA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AK,EAAE,UAAU,EACjB,QAAQ,EAAE,CAAC,CAAC,EAAE,iBAAiB,KAAK,IAAI,GACvC,IAAI,CAKN;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG;IAC3C,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;IAClD,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B,CAyBA"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * react-native-cloud-sync
3
+ *
4
+ * iCloud key-value store, CloudKit and Google Drive behind one API, on iOS,
5
+ * Android and the web, on both React Native architectures.
6
+ */
7
+ export { icloudKV, getAllItems as icloudKVGetAllItems, sync as icloudKVSync } from './providers/icloudKV';
8
+ export { cloudKit, createCloudKitProvider, zones as cloudKitZones, assets as cloudKitAssets } from './providers/cloudKit.js';
9
+ export { cloudKitBackup } from './providers/cloudKitBackup.js';
10
+ export { cloudKitEncrypted } from './providers/cloudKitEncrypted.js';
11
+ export { icloudDocuments } from './providers/icloudDocuments.js';
12
+ export { googleDrive, createGoogleDriveProvider } from './providers/googleDrive.js';
13
+ export { googleDriveFiles } from './providers/googleDriveFiles.js';
14
+ export { createMemoryProvider } from './providers/memory.js';
15
+ export { createCloudStore, type CloudStore, type FlushResult, type MigrateOptions, type MigrateResult, type OutboxStorage } from './store.js';
16
+ export { resolveByTimestamp, resolveByModifiedAt, resolveByPreferenceOrder, resolveFirstOf } from './resolvers.js';
17
+ export { checkKey, sanitizeKey } from './internal/keys.js';
18
+ /**
19
+ * The abort-signal shape the cancellable APIs accept.
20
+ *
21
+ * Structural rather than the DOM `AbortSignal`, so any polyfill satisfies it
22
+ * and consumers do not need `lib.dom` in their tsconfig.
23
+ */
24
+ export type { AbortLike } from './internal/timeout.js';
25
+ export { configureCloudKit, configureGoogleDrive, configureGoogleDriveFiles, isCloudKitConfigured, isGoogleDriveConfigured, isGoogleDriveFilesConfigured } from './config.js';
26
+ export type { CloudKitRestConfig } from './internal/cloudKitRest.js';
27
+ export type { GoogleDriveConfig, GoogleDriveFileAdapter } from './internal/googleDriveRest.js';
28
+ export { base64ToBytes, bytesToBase64 } from './internal/base64.js';
29
+ export { CloudSyncError, ErrorCode, isCancelled, isCloudSyncError, isRetryable, requiresUserAction } from './errors.js';
30
+ export type { CloudSyncErrorInfo } from './errors.js';
31
+ export type { BackupOptions, BackupProgressEvent } from './providers/cloudKitBackup.js';
32
+ export type { DocumentEntry, DocumentFetchOptions } from './providers/icloudDocuments.js';
33
+ export type { DriveFileFetchOptions, DriveFileProgressEvent, DriveFileSaveOptions } from './providers/googleDriveFiles.js';
34
+ export type { AccountChangeEvent, AccountStatus, AssetProgressEvent, AutoFlushConfig, BuiltInProviderName, ChangeReason, CloudProvider, CloudStoreOptions, DropReason, DroppedWrite, ItemWithMeta, OutboxEntry, ProviderName, QuotaInfo, RemoteChangeEvent, ResolveCandidate, ResolveFn, TieringConfig, Unsubscribe, ValueCodec, WriteMode } from './types.js';
35
+ export { DEFAULT_TIERING } from './types.js';
36
+ export { setLogsEnabled } from './internal/logger.js';
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,QAAQ,EACR,WAAW,IAAI,mBAAmB,EAClC,IAAI,IAAI,YAAY,EACrB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,QAAQ,EACR,sBAAsB,EACtB,KAAK,IAAI,aAAa,EACtB,MAAM,IAAI,cAAc,EACzB,MAAM,yBAAsB,CAAA;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA4B,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAA+B,CAAA;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM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AEvH,YAAY,EACV,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACV,MAAM,YAAS,CAAA;AAChB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAS,CAAA;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAmB,CAAA"}
@@ -0,0 +1,45 @@
1
+ import type { Unsubscribe } from '../types.js';
2
+ /**
3
+ * When the store should try to drain its outbox by itself.
4
+ *
5
+ * A durable queue with no trigger is only half a feature: every retryable
6
+ * failure is captured correctly and then sits there until the app remembers to
7
+ * call `flushOutbox()`. Most apps wire that to the same two moments, so the
8
+ * store can do it for them.
9
+ *
10
+ * Deliberately *not* network-aware. Detecting a reconnect needs
11
+ * `@react-native-community/netinfo`, and taking a dependency on it to save one
12
+ * line in the host app is a bad trade - it would be installed for every user of
13
+ * this package whether or not they wanted it. Call `flushOutbox()` from your
14
+ * own NetInfo listener for that; foreground plus a slow interval already covers
15
+ * the common case, since an app that regained connectivity is nearly always
16
+ * about to be foregrounded anyway.
17
+ */
18
+ export interface AutoFlushConfig {
19
+ /**
20
+ * Flush when the app returns to the foreground. Default true.
21
+ *
22
+ * The single highest-value trigger: a write queued offline is most likely to
23
+ * succeed the next time the user opens the app.
24
+ */
25
+ onForeground?: boolean;
26
+ /**
27
+ * Also flush on this interval while the app is in the foreground. Default
28
+ * 60000. Set 0 to disable.
29
+ *
30
+ * Backoff already governs *whether* an individual entry is retried, so this
31
+ * only decides how often the queue is looked at; a tick with nothing due is
32
+ * a synchronous read of a small JSON blob and no network at all.
33
+ */
34
+ intervalMs?: number;
35
+ }
36
+ /**
37
+ * Wires `flush` to app foreground and to a timer. Returns an unsubscribe.
38
+ *
39
+ * Failures are swallowed on purpose: this is a background retry nobody is
40
+ * waiting on, and the store already reports every failure through `onError`
41
+ * and `onDropped`. Letting a rejection escape a timer callback would surface as
42
+ * an unhandled rejection warning for something the app deliberately deferred.
43
+ */
44
+ export declare function attachAutoFlush(flush: () => Promise<unknown>, config?: AutoFlushConfig): Unsubscribe;
45
+ //# sourceMappingURL=autoFlush.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autoFlush.d.ts","sourceRoot":"","sources":["../../../../src/internal/autoFlush.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAU,CAAA;AAE3C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAID;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAC7B,MAAM,GAAE,eAAoB,GAC3B,WAAW,CAkCb"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Base64 encode/decode for the Drive binary-file path.
3
+ *
4
+ * Hand-rolled rather than `Buffer` or `atob`/`btoa`: neither is guaranteed to
5
+ * exist in a Hermes runtime, and this package ships with zero runtime
6
+ * dependencies (see `googleDriveFiles` for why - the file adapter itself is
7
+ * injected, in base64, for the same reason). A chunk is a few MB at most, so a
8
+ * lookup-table implementation is fast enough without needing a native module.
9
+ */
10
+ export declare function bytesToBase64(bytes: Uint8Array): string;
11
+ export declare function base64ToBytes(base64: string): Uint8Array;
12
+ //# sourceMappingURL=base64.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../../../src/internal/base64.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAWH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAoBvD;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAqBxD"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * UTF-8 byte length.
3
+ *
4
+ * `String.length` counts UTF-16 code units, which under-reports for any
5
+ * non-ASCII payload - the exact way a "just under the limit" value turns into a
6
+ * server-side rejection.
7
+ *
8
+ * Lives in its own module because both the size-tiering path and the key
9
+ * validator need it, and neither should have to import a REST client to get it.
10
+ */
11
+ export declare function byteLength(s: string): number;
12
+ //# sourceMappingURL=bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../../src/internal/bytes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAiB5C"}
@@ -0,0 +1,149 @@
1
+ /**
2
+ * CloudKit Web Services REST client.
3
+ *
4
+ * This is how the `cloudKit` provider reaches a user's PRIVATE database from
5
+ * Android and from the browser, where `CloudKit.framework` does not exist.
6
+ *
7
+ * Why an interactive user token and not a server key: Apple is explicit that a
8
+ * server-to-server key reaches only the *public* database - "Use a
9
+ * server-to-server key to access the public database of a container as the
10
+ * developer who created the key." Sign in with Apple cannot substitute either;
11
+ * per Apple DTS, "The unique user identifiers for Sign in with Apple and
12
+ * CloudKit are not linked." So an interactive `ckWebAuthToken` is not a shortcut
13
+ * this package chose - it is the only mechanism that exists.
14
+ *
15
+ * Deliberately no dependency on CloudKit JS. That library pulls Node's `crypto`
16
+ * for server-to-server signing, which is what killed the last React Native
17
+ * attempt at this (KjellConnelly/react-native-cloudkit pinned v1 because "2.0
18
+ * requires crypto which ... doesn't work with React Native"). The REST API in
19
+ * user-token mode needs no crypto at all: two query parameters on a `fetch`.
20
+ */
21
+ export interface CloudKitRestConfig {
22
+ /** e.g. `iCloud.com.example.app`. Must match the app's entitlement exactly. */
23
+ containerIdentifier: string;
24
+ /**
25
+ * A CloudKit Console **Client** API token, not a server-to-server key.
26
+ *
27
+ * A client token grants only what the authenticated user could already do, so
28
+ * it is safe to ship in an app binary. A server-to-server private key is not.
29
+ */
30
+ apiToken: string;
31
+ environment: 'development' | 'production';
32
+ /** Returns the stored `ckWebAuthToken`, or null when the user has not signed in. */
33
+ getAuthToken: () => Promise<string | null> | string | null;
34
+ /**
35
+ * Called when CloudKit reports the token is no longer usable, so the host can
36
+ * clear it and prompt for re-auth.
37
+ *
38
+ * This fires more often than you might expect: a `ckWebAuthToken` expires
39
+ * after 30 minutes, or 2 weeks if the user ticked "Keep me signed in" during
40
+ * sign-in. Apple documents no refresh mechanism.
41
+ */
42
+ onAuthExpired?: () => Promise<void> | void;
43
+ /** Overridable for tests. Defaults to global `fetch`. */
44
+ fetchImpl?: typeof fetch;
45
+ /**
46
+ * Abandon a request that has not answered in this long. Default 30000.
47
+ *
48
+ * React Native's `fetch` has no timeout of its own, so without this a socket
49
+ * that never answers hangs the operation forever - and `isReachable()` is on
50
+ * the path of every read, so one hung probe stalls the whole store.
51
+ */
52
+ timeoutMs?: number;
53
+ }
54
+ export declare const RECORD_TYPE_DEFAULT = "KVBlob";
55
+ export declare const VALUE_FIELD = "value";
56
+ /** CloudKit's documented per-record ceiling, excluding assets. */
57
+ export declare const MAX_RECORD_BYTES: number;
58
+ export declare class CloudKitRestClient {
59
+ private readonly config;
60
+ private reachability;
61
+ constructor(config: CloudKitRestConfig);
62
+ private baseUrl;
63
+ private get fetch();
64
+ private requireAuthToken;
65
+ private handleAuthExpired;
66
+ /**
67
+ * Maps a CloudKit `serverErrorCode` onto the package's shared vocabulary.
68
+ * Codes are from Apple's CloudKit Web Services error reference.
69
+ */
70
+ private toError;
71
+ private post;
72
+ getRecord(recordName: string, recordType?: string): Promise<string | null>;
73
+ /**
74
+ * A read that also returns the server's own modification time and the
75
+ * record's change tag.
76
+ *
77
+ * Both come back on a plain lookup whether or not anyone asks, so surfacing
78
+ * them costs nothing - and they are what make {@link resolveByModifiedAt} and
79
+ * conditional writes possible without the app instrumenting its payloads.
80
+ */
81
+ getRecordWithMeta(recordName: string, recordType?: string): Promise<{
82
+ value: string;
83
+ modifiedAt?: number;
84
+ recordChangeTag?: string;
85
+ } | null>;
86
+ /**
87
+ * Reads many records in one request.
88
+ *
89
+ * `/records/lookup` has taken an array of record ids since the API shipped,
90
+ * so reading 200 keys one at a time was 200 round trips for no reason - and
91
+ * 200 chances to be throttled. Results are matched back by `recordName`
92
+ * rather than by position, because CloudKit does not promise the response
93
+ * preserves request order.
94
+ */
95
+ getRecords(recordNames: string[], recordType?: string): Promise<(string | null)[]>;
96
+ /**
97
+ * Writes many records in one request.
98
+ *
99
+ * Uses `forceUpdate`, which creates or replaces in a single operation, so
100
+ * unlike the single-record path there is no create-then-fall-back-to-update
101
+ * dance to repeat per key.
102
+ *
103
+ * `atomic: false`, deliberately: a batch is a convenience for the caller, not
104
+ * a transaction they asked for, and one oversized record should not silently
105
+ * discard the other 199. Per-record failures are collected and raised
106
+ * together.
107
+ */
108
+ saveRecords(entries: [string, string][], recordType?: string): Promise<void>;
109
+ /** Deletes many records in one request, with the same per-record rules. */
110
+ deleteRecords(recordNames: string[], recordType?: string): Promise<void>;
111
+ saveRecord(recordName: string, value: string, recordType?: string): Promise<void>;
112
+ /**
113
+ * A write that fails instead of clobbering, when the server's copy has moved
114
+ * on since `recordChangeTag` was read.
115
+ *
116
+ * The normal `saveRecord` is last-write-wins - the right default for the
117
+ * common case, and what the native provider's `.changedKeys` save policy
118
+ * does, so both platforms agree. But last-write-wins means a genuine
119
+ * concurrent edit is destroyed silently, and `ERR_CONFLICT` carries
120
+ * `serverValue` precisely so an app can merge instead. Without a conditional
121
+ * write, that error could never actually fire and the merge path was
122
+ * unreachable.
123
+ *
124
+ * Read the tag with {@link getRecordWithMeta}, pass it here, and handle
125
+ * `ERR_CONFLICT` by merging `serverValue` and retrying.
126
+ */
127
+ saveRecordIfUnchanged(recordName: string, value: string, recordChangeTag: string, recordType?: string): Promise<void>;
128
+ deleteRecord(recordName: string, recordType?: string): Promise<void>;
129
+ queryRecordNames(recordType?: string): Promise<string[]>;
130
+ /**
131
+ * Cheap reachability check backing the provider's `isAvailable()`.
132
+ *
133
+ * The probe itself is a network round trip, but `isAvailable()` is documented
134
+ * as safe on a render path and the store calls it before every provider read -
135
+ * so unmemoised, each `getItem` on Android or web cost two requests instead of
136
+ * one. Held briefly: long enough to collapse that pair, short enough that a
137
+ * token expiring mid-session is noticed.
138
+ */
139
+ isReachable(): Promise<boolean>;
140
+ /**
141
+ * Drops the memoised reachability answer.
142
+ *
143
+ * Called on an account switch: that answer was recorded for the previous
144
+ * user's web auth token and says nothing about the new one.
145
+ */
146
+ clearCache(): void;
147
+ }
148
+ export { byteLength } from './bytes.js';
149
+ //# sourceMappingURL=cloudKitRest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudKitRest.d.ts","sourceRoot":"","sources":["../../../../src/internal/cloudKitRest.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,WAAW,kBAAkB;IACjC,+EAA+E;IAC/E,mBAAmB,EAAE,MAAM,CAAA;IAC3B;;;;;OAKG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,aAAa,GAAG,YAAY,CAAA;IACzC,oFAAoF;IACpF,YAAY,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,MAAM,GAAG,IAAI,CAAA;IAC1D;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IAC1C,yDAAyD;IACzD,SAAS,CAAC,EAAE,OAAO,KAAK,CAAA;IACxB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAWD,eAAO,MAAM,mBAAmB,WAAW,CAAA;AAC3C,eAAO,MAAM,WAAW,UAAU,CAAA;AAElC,kEAA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E,MAAM,EACvB,UAAU,SAAsB,GAC/B,OAAO,CAAC,IAAI,CAAC;IAqCV,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,SAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAejF,gBAAgB,CAAC,UAAU,SAAsB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA8B3E;;;;;;;;OAQG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAoBrC;;;;;OAKG;IACH,UAAU,IAAI,IAAI;CAGnB;AAaD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAS,CAAA"}
@@ -0,0 +1,10 @@
1
+ import type { AccountStatus, ChangeReason } from '../types.js';
2
+ /**
3
+ * Codegen has no string-union type, so enums cross the bridge as plain strings.
4
+ * Validate on the way in rather than casting - an unrecognised value from a
5
+ * newer native build should degrade to a known-safe member, not corrupt an
6
+ * exhaustive switch downstream.
7
+ */
8
+ export declare function toAccountStatus(raw: string): AccountStatus;
9
+ export declare function toChangeReason(raw: string): ChangeReason;
10
+ //# sourceMappingURL=enums.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../../../../src/internal/enums.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAU,CAAA;AAkB3D;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAI1D;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAIxD"}