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,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';
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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aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,UAAU,SAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBrF,UAAU,CACd,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,UAAU,SAAsB,GAC/B,OAAO,CAAC,IAAI,CAAC;IAkEhB;;;;;;;;;;;;;;OAcG;IACG,qBAAqB,CACzB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,eAAe,EAAE,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,SAAS,CAAA"}
@@ -0,0 +1,10 @@
1
+ import type { AccountStatus, ChangeReason } from '../types';
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,UAAU,CAAA;AAkB3D;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAI1D;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAIxD"}
@@ -0,0 +1,232 @@
1
+ import { type AbortLike } from './timeout';
2
+ /**
3
+ * Google Drive `appDataFolder` REST client.
4
+ *
5
+ * `appDataFolder` is a hidden per-app, per-Google-account folder: nothing shows
6
+ * up in the user's visible Drive, and the data survives an app uninstall because
7
+ * it is tied to the account rather than the install.
8
+ *
9
+ * Auth is deliberately injected rather than owned. The library does not depend
10
+ * on `@react-native-google-signin/google-signin` (or any other sign-in library),
11
+ * so the host app keeps control of the consent flow, and the same client works
12
+ * unchanged in a browser where that library does not apply.
13
+ */
14
+ export interface GoogleDriveConfig {
15
+ /**
16
+ * Returns a valid OAuth access token with the `drive.appdata` scope, or null
17
+ * if the user is not connected. Called before every request, so implementers
18
+ * should refresh silently here rather than caching a stale token.
19
+ */
20
+ getAccessToken: () => Promise<string | null> | string | null;
21
+ /** Called when Drive rejects the token, so the host can prompt for reconnect. */
22
+ onAuthExpired?: () => Promise<void> | void;
23
+ fetchImpl?: typeof fetch;
24
+ /**
25
+ * Bytes per chunk for `uploadFile`/`downloadFile`. Default 8 MiB.
26
+ *
27
+ * Must be a multiple of 256 KiB (262144) - Google's resumable upload
28
+ * protocol requires that for every chunk but the last. Lowered in tests to
29
+ * exercise the multi-chunk path without a multi-MB fixture.
30
+ */
31
+ chunkBytes?: number;
32
+ /**
33
+ * What to do when `appDataFolder` holds more than one file with the same
34
+ * name. Default `'newest'`.
35
+ *
36
+ * Drive names are not unique - it is a file store with ids, not a key-value
37
+ * store - so two devices creating the same key while both are offline
38
+ * genuinely produce two files. Picking whichever the API happened to list
39
+ * first is the worst option: the choice is unspecified, so two devices can
40
+ * settle on different files and diverge permanently with no error anywhere.
41
+ *
42
+ * `'newest'` picks the most recently modified, which every device agrees on.
43
+ * `'error'` raises {@link ErrorCode.CONFLICT} instead, for apps that would
44
+ * rather reconcile explicitly than have one copy quietly win.
45
+ */
46
+ onDuplicateName?: 'newest' | 'error';
47
+ /**
48
+ * Abandon a request that has not answered in this long. Default 60000.
49
+ *
50
+ * Longer than the CloudKit client's because one "request" here can be a whole
51
+ * 8 MiB chunk on a slow connection. `fetch` in React Native has no timeout of
52
+ * its own, so without this a dead socket hangs the transfer forever.
53
+ */
54
+ timeoutMs?: number;
55
+ }
56
+ /** A local file `uploadFile` reads from, in fixed-size pieces. */
57
+ export interface DriveChunkSource {
58
+ size: number;
59
+ read: (start: number, length: number) => Promise<Uint8Array>;
60
+ }
61
+ /** A local file `downloadFile` writes into, one piece at a time. */
62
+ export interface DriveChunkSink {
63
+ write: (bytes: Uint8Array, isFirstChunk: boolean) => Promise<void>;
64
+ }
65
+ /**
66
+ * Local file I/O for `googleDriveFiles`, supplied by the host app rather than
67
+ * this package depending on a filesystem library.
68
+ *
69
+ * base64 in and out - not a stream or a byte array - because that is the
70
+ * primitive RN filesystem libraries actually expose for a chunked read/write
71
+ * (`expo-file-system`'s `readAsStringAsync`/`writeAsStringAsync` with
72
+ * `EncodingType.Base64` and `position`/`length`/`append`), so the adapter
73
+ * mirrors that rather than inventing an abstraction nothing implements
74
+ * natively. `googleDriveFiles` does the base64 <-> bytes conversion at the
75
+ * boundary; a chunk is capped at `chunkBytes` (8 MiB default), so the base64
76
+ * string is never larger than that either.
77
+ */
78
+ export interface GoogleDriveFileAdapter {
79
+ /** Size in bytes of the local file at `uri`. */
80
+ statSize: (uri: string) => Promise<number>;
81
+ /** Reads `length` bytes starting at `position` from the local file at `uri`, base64-encoded. */
82
+ readChunk: (uri: string, position: number, length: number) => Promise<string>;
83
+ /** Creates (or overwrites) the local file at `uri` with these base64-encoded bytes. */
84
+ writeChunk: (uri: string, base64: string) => Promise<void>;
85
+ /** Appends base64-encoded bytes to a file `writeChunk` already created. */
86
+ appendChunk: (uri: string, base64: string) => Promise<void>;
87
+ }
88
+ export declare class GoogleDriveClient {
89
+ private readonly config;
90
+ /**
91
+ * name -> fileId.
92
+ *
93
+ * Drive has no "get by name" endpoint, so every read would otherwise cost a
94
+ * list query. react-native-cloud-storage's Drive backend does exactly that and
95
+ * additionally lists the *whole* drive before filtering client-side, which its
96
+ * users measured in minutes (kuatsu#49) and which can loop forever (kuatsu#39).
97
+ * A scoped `q=` query plus this cache keeps a read to one request, usually zero.
98
+ */
99
+ private readonly idCache;
100
+ /**
101
+ * name -> the metadata the last listing reported.
102
+ *
103
+ * Kept beside the id cache so `getItemWithMeta` does not need a second round
104
+ * trip to learn a modification time the `q=` query already returned.
105
+ */
106
+ private readonly metaCache;
107
+ private readonly chunkBytes;
108
+ constructor(config: GoogleDriveConfig);
109
+ private get fetch();
110
+ private requireToken;
111
+ /**
112
+ * `extraOkStatuses` is for the resumable-upload protocol, where 308 ("Resume
113
+ * Incomplete") is an expected, successful outcome rather than an error - the
114
+ * caller inspects the response itself rather than getting a thrown rejection.
115
+ */
116
+ private request;
117
+ /**
118
+ * Resolves a file name to its id within appDataFolder, or null if absent.
119
+ *
120
+ * Pass `refresh` to bypass the memo after a cached id turned out to be stale.
121
+ */
122
+ private findFileId;
123
+ /**
124
+ * Chooses between several files that share a name.
125
+ *
126
+ * Deterministically, and that is the whole point: the list order Drive
127
+ * returns is unspecified, so picking the first match lets two devices settle
128
+ * on two different files for the same key and diverge forever, silently.
129
+ * Ordering by modification time - newest first, ties broken by id - gives
130
+ * every device the same answer.
131
+ */
132
+ private pickAmongDuplicates;
133
+ /** Records what a listing told us about a file, ids and metadata together. */
134
+ private remember;
135
+ getItem(name: string): Promise<string | null>;
136
+ /**
137
+ * A read that also reports Drive's own `modifiedTime`.
138
+ *
139
+ * Free: resolving a name to an id is already a listing, and asking that
140
+ * listing for `modifiedTime` costs nothing extra. Surfacing it is what lets
141
+ * {@link resolveByModifiedAt} order copies without the app embedding a
142
+ * timestamp in its payload.
143
+ */
144
+ getItemWithMeta(name: string): Promise<{
145
+ value: string;
146
+ modifiedAt?: number;
147
+ version?: string;
148
+ } | null>;
149
+ /**
150
+ * Storage usage for the whole Google account.
151
+ *
152
+ * Note this is the account's total, not the `appDataFolder`'s share of it -
153
+ * Drive reports no per-folder usage. Still the number a "you are running out
154
+ * of space" prompt needs, because that is the limit a write will actually hit.
155
+ * `limit` is absent for unlimited (Workspace pooled) accounts.
156
+ */
157
+ getQuota(): Promise<{
158
+ usedBytes?: number;
159
+ totalBytes?: number;
160
+ }>;
161
+ setItem(name: string, value: string): Promise<void>;
162
+ /**
163
+ * Uploads `source` as `name`, using Drive's resumable protocol instead of
164
+ * `setItem`'s single-request multipart body.
165
+ *
166
+ * Two things a whole-file `setItem(name, base64OfEverything)` cannot do at
167
+ * a few hundred MB: hold the payload in memory as one JS string, and recover
168
+ * from a dropped connection without starting over. Reading happens in fixed
169
+ * chunks through `source.read`, so peak memory is one chunk rather than the
170
+ * whole file, and a chunk that fails mid-flight is retried - by asking Drive
171
+ * how many bytes it actually has and resuming from there - rather than
172
+ * restarting the transfer.
173
+ *
174
+ * That resumability is scoped to this call: the session lives only in
175
+ * memory, so if the process dies mid-upload, the next call to `uploadFile`
176
+ * starts a fresh session from byte 0. Persisting the session URI so a
177
+ * restart can resume it too is future scope, not something callers should
178
+ * assume works today.
179
+ */
180
+ uploadFile(name: string, source: DriveChunkSource, onProgress?: (bytesTransferred: number, bytesTotal: number) => void, signal?: AbortLike): Promise<void>;
181
+ private startResumableSession;
182
+ /** One chunk, with a single retry that re-queries the server's real offset first. */
183
+ private putChunkWithRetry;
184
+ private putChunk;
185
+ /** Asks Drive how much of an in-flight resumable session it actually has. */
186
+ private queryUploadOffset;
187
+ /**
188
+ * Downloads `name` into `sink`, in the same fixed-size chunks `uploadFile`
189
+ * writes in - so a restore never holds the whole file in memory either.
190
+ * Resolves `false` when no such file exists, `true` once every chunk has
191
+ * been handed to the sink.
192
+ */
193
+ downloadFile(name: string, sink: DriveChunkSink, onProgress?: (bytesTransferred: number, bytesTotal: number) => void, signal?: AbortLike): Promise<boolean>;
194
+ private fileSize;
195
+ removeItem(name: string): Promise<void>;
196
+ getAllKeys(): Promise<string[]>;
197
+ /**
198
+ * A cursor marking "everything up to now", for {@link pollChanges}.
199
+ *
200
+ * Drive's change feed is cursor-based rather than time-based, so a watcher
201
+ * has to take a starting cursor before it can ask what changed since.
202
+ */
203
+ getStartPageToken(): Promise<string>;
204
+ /**
205
+ * What changed in `appDataFolder` since `pageToken`, and the cursor to use
206
+ * next time.
207
+ *
208
+ * This is how a non-Apple platform learns that another device wrote something
209
+ * - CloudKit gets `NSUbiquitousKeyValueStore` notifications and `CKAccountChanged`
210
+ * for free, but Drive has no push channel without a server to receive its
211
+ * webhooks, so the honest equivalent is a cursor the app polls. Cheap: a poll
212
+ * with nothing to report is one request returning an empty list.
213
+ *
214
+ * Deletions are included - `removed` entries and trashed files both surface,
215
+ * because "another device deleted this key" is exactly as important as
216
+ * "another device changed it".
217
+ */
218
+ pollChanges(pageToken: string): Promise<{
219
+ names: string[];
220
+ nextToken: string;
221
+ }>;
222
+ /** Drops whatever name currently memoises this file id. */
223
+ private forgetById;
224
+ /**
225
+ * Whether an access token can currently be obtained, without making a network
226
+ * request. Backs the provider's `isAvailable()` probe.
227
+ */
228
+ hasToken(): Promise<boolean>;
229
+ /** Drops memoised file ids. Call after an account switch. */
230
+ clearCache(): void;
231
+ }
232
+ //# sourceMappingURL=googleDriveRest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"googleDriveRest.d.ts","sourceRoot":"","sources":["../../../../src/internal/googleDriveRest.ts"],"names":[],"mappings":"AACA,OAAO,EAA+B,KAAK,SAAS,EAAE,MAAM,WAAW,CAAA;AAEvE;;;;;;;;;;;GAWG;AAEH,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,MAAM,GAAG,IAAI,CAAA;IAC5D,iFAAiF;IACjF,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IAC1C,SAAS,CAAC,EAAE,OAAO,KAAK,CAAA;IACxB;;;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E,UAAU,EAAE,MAAM,KAAK,IAAI,EACnE,MAAM,CAAC,EAAE,SAAS,GACjB,OAAO,CAAC,OAAO,CAAC;YAgCL,QAAQ;IAMhB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBvC,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IA2BrC;;;;;OAKG;IACG,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAgB1C;;;;;;;;;;;;;OAaG;IACG,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAuDrF,2DAA2D;IAC3D,OAAO,CAAC,UAAU;IASlB;;;OAGG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IASlC,6DAA6D;IAC7D,UAAU,IAAI,IAAI;CAInB"}
@@ -0,0 +1,28 @@
1
+ import type { ProviderName } from '../types';
2
+ export interface KeyRule {
3
+ /** Human-readable statement of what was violated. */
4
+ reason: string;
5
+ /** The provider whose limit this is, or null when every provider shares it. */
6
+ provider: ProviderName | null;
7
+ }
8
+ /**
9
+ * The first rule `key` breaks for this set of providers, or null when it is
10
+ * usable everywhere.
11
+ *
12
+ * Provider-aware on purpose: the 64-byte ceiling is the key-value store's
13
+ * alone, and rejecting a 100-character key for an app that only configured
14
+ * Drive would be a false alarm.
15
+ */
16
+ export declare function checkKey(key: string, providers: readonly ProviderName[]): KeyRule | null;
17
+ /** Throws {@link ErrorCode.INVALID_KEY} when `key` is unusable. */
18
+ export declare function assertKey(key: string, providers: readonly ProviderName[]): void;
19
+ /**
20
+ * Rewrites an arbitrary string into a key that passes {@link checkKey}.
21
+ *
22
+ * For callers whose keys come from somewhere they do not control - a file name,
23
+ * a user-entered label, an id from another system. Illegal characters become
24
+ * `-`, and anything too long is truncated and suffixed with a short hash of the
25
+ * original so two different long keys cannot collide.
26
+ */
27
+ export declare function sanitizeKey(raw: string, maxBytes?: number): string;
28
+ //# sourceMappingURL=keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../../src/internal/keys.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAkD5C,MAAM,WAAW,OAAO;IACtB,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAA;IACd,+EAA+E;IAC/E,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAA;CAC9B;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,YAAY,EAAE,GAAG,OAAO,GAAG,IAAI,CA8CxF;AAED,mEAAmE;AACnE,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,YAAY,EAAE,GAAG,IAAI,CAS/E;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,SAAmB,GAAG,MAAM,CAe5E"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Toggles verbose logging in both JS and the native layer.
3
+ *
4
+ * Off by default: a storage library logging every read on a hot path is noise,
5
+ * and cloud payloads can contain user data that should not land in a device log.
6
+ */
7
+ export declare function setLogsEnabled(value: boolean): void;
8
+ export declare function isLogsEnabled(): boolean;
9
+ export declare function log(...args: unknown[]): void;
10
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../../src/internal/logger.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAGnD;AAED,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED,wBAAgB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAG5C"}
@@ -0,0 +1,29 @@
1
+ import type { Spec } from '../specs/NativeRNCloudSync';
2
+ import type { Unsubscribe } from '../types';
3
+ /**
4
+ * Resolves the native module lazily.
5
+ *
6
+ * New arch exposes it through TurboModuleRegistry; old arch through the
7
+ * NativeModules proxy. Resolution is deferred rather than done at import time
8
+ * so that merely importing this package on a platform without the native module
9
+ * (web, or Android for the iCloud provider) does not throw at bundle-evaluation
10
+ * time - which is exactly the crash cryptoc had to work around with a
11
+ * `Platform.OS === 'ios' ? requireNativeModule(...) : null` guard.
12
+ */
13
+ export declare function getNativeModule(): Spec | null;
14
+ /** Like {@link getNativeModule} but throws a diagnostic instead of returning null. */
15
+ export declare function requireNativeModule(): Spec;
16
+ export declare function hasNativeModule(): boolean;
17
+ /**
18
+ * Event names differ per architecture.
19
+ *
20
+ * Codegen's EventEmitter properties must be named `onSomething`, while the old
21
+ * architecture's `supportedEvents` list uses the bare name. Rather than leak
22
+ * that split into every call site, subscribe through this helper.
23
+ * (react-native-background-downloader carries the same `onDownloadBegin` vs
24
+ * `downloadBegin` split for the same reason.)
25
+ */
26
+ export declare function subscribeNativeEvent<T>(newArchName: 'onRemoteChange' | 'onAccountChange' | 'onAssetProgress', legacyName: 'remoteChange' | 'accountChange' | 'assetProgress', listener: (e: T) => void): Unsubscribe;
27
+ /** Exposed for tests and diagnostics only. */
28
+ export declare function __resetNativeModuleCache(): void;
29
+ //# sourceMappingURL=nativeModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nativeModule.d.ts","sourceRoot":"","sources":["../../../../src/internal/nativeModule.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAA;AAEtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAsB3C;;;;;;;;;GASG;AACH,wBAAgB,eAAe,IAAI,IAAI,GAAG,IAAI,CAuC7C;AAED,sFAAsF;AACtF,wBAAgB,mBAAmB,IAAI,IAAI,CAW1C;AAED,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAgBD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,WAAW,EAAE,gBAAgB,GAAG,iBAAiB,GAAG,iBAAiB,EACrE,UAAU,EAAE,cAAc,GAAG,eAAe,GAAG,eAAe,EAC9D,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GACvB,WAAW,CAkBb;AAED,8CAA8C;AAC9C,wBAAgB,wBAAwB,IAAI,IAAI,CAK/C"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Rejects with {@link ErrorCode.TIMEOUT} if `promise` has not settled in time.
3
+ *
4
+ * React Native's `fetch` has no default timeout, and neither does CloudKit's
5
+ * native stack, so an unanswered socket hangs an operation forever. That is
6
+ * worse than an error: the store calls `isAvailable()` before every operation,
7
+ * so one hung probe stalls reads and writes that would otherwise have fallen
8
+ * through to a working provider.
9
+ *
10
+ * The underlying work is *not* cancelled - a promise cannot be. This only stops
11
+ * the caller waiting on it, which is why the timeout error is classified as
12
+ * retryable rather than as a failure.
13
+ */
14
+ export declare function withTimeout<T>(promise: Promise<T>, ms: number, provider?: string): Promise<T>;
15
+ /**
16
+ * The subset of `AbortSignal` this package needs.
17
+ *
18
+ * Typed structurally rather than as the DOM `AbortSignal` so a caller can pass
19
+ * one from any polyfill, and so the package does not require `lib.dom` to be in
20
+ * a consumer's `tsconfig`.
21
+ */
22
+ export interface AbortLike {
23
+ readonly aborted: boolean;
24
+ addEventListener: (type: 'abort', listener: () => void) => void;
25
+ removeEventListener: (type: 'abort', listener: () => void) => void;
26
+ }
27
+ /** Throws {@link ErrorCode.CANCELLED} if the signal is already aborted. */
28
+ export declare function throwIfAborted(signal: AbortLike | undefined, provider?: string): void;
29
+ /**
30
+ * Races `promise` against an abort signal.
31
+ *
32
+ * Used by the chunked transfer paths, where "cancel" has to take effect between
33
+ * chunks rather than only once the whole multi-hundred-megabyte file has moved.
34
+ */
35
+ export declare function withAbort<T>(promise: Promise<T>, signal: AbortLike | undefined, provider?: string): Promise<T>;
36
+ //# sourceMappingURL=timeout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../../../src/internal/timeout.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAiB7F;AAED;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,gBAAgB,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;IAC/D,mBAAmB,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;CACnE;AAED,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAErF;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACzB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,MAAM,EAAE,SAAS,GAAG,SAAS,EAC7B,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,CAAC,CAAC,CAoBZ"}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,86 @@
1
+ import { type CloudKitRestConfig } from '../internal/cloudKitRest';
2
+ import type { AssetProgressEvent, CloudProvider, ProviderName, Unsubscribe } from '../types';
3
+ export declare const cloudKit: CloudProvider;
4
+ /**
5
+ * A CloudKit provider with its own REST credentials and its own name.
6
+ *
7
+ * `configureCloudKit` sets one client for the whole process. That is right for
8
+ * a normal app, but leaves no way to reach two containers at once - a staging
9
+ * container beside production, or a migration that copies between them - and no
10
+ * way for two tests to hold different configurations.
11
+ *
12
+ * REST only, and that is not a limitation that can be lifted: the native path
13
+ * authenticates as whatever iCloud account the *device* is signed into, so
14
+ * "another set of credentials" has no meaning there. On iOS this therefore
15
+ * still talks to CloudKit Web Services rather than to `CloudKit.framework`.
16
+ */
17
+ export declare function createCloudKitProvider(config: CloudKitRestConfig & {
18
+ name?: ProviderName;
19
+ }): CloudProvider;
20
+ /** Custom zones. Native only - the REST client uses the default zone. */
21
+ export declare const zones: {
22
+ create: (zoneName: string) => Promise<void>;
23
+ remove: (zoneName: string) => Promise<void>;
24
+ list: () => Promise<string[]>;
25
+ };
26
+ /**
27
+ * Binary assets (`CKAsset`).
28
+ *
29
+ * Native only. CloudKit Web Services does expose an asset upload flow, but it
30
+ * is a separate multi-step protocol (request an upload URL, POST the bytes,
31
+ * then reference the returned token in a record) that this package does not
32
+ * implement yet - so on Android and web these reject with
33
+ * `ERR_UNSUPPORTED_PLATFORM` rather than appearing to work.
34
+ *
35
+ * Assets are deliberately an explicit API rather than something the store
36
+ * facade routes to automatically: the caller passes a file path, not a string,
37
+ * so there is no way to infer the intent from a `setItem` call.
38
+ */
39
+ export declare const assets: {
40
+ /**
41
+ * Uploads a local file as a field on a record.
42
+ *
43
+ * Progress is reported per record through {@link onProgress}; a CKAsset is
44
+ * streamed from disk, so a large file does not have to be held in memory the
45
+ * way a base64 round trip would.
46
+ */
47
+ save: (options: {
48
+ recordName: string;
49
+ fieldName: string;
50
+ /** `file://` URL or a plain path. */
51
+ fileUri: string;
52
+ recordType?: string;
53
+ zoneName?: string | null;
54
+ }) => Promise<void>;
55
+ /**
56
+ * Downloads an asset field and resolves a local file path, or `null` when the
57
+ * record or field does not exist.
58
+ *
59
+ * Pass `destinationUri` for anything the user is going to keep or hand to a
60
+ * share sheet. Without it the file lands in the app's temporary directory
61
+ * under a name derived from the record, and iOS may reclaim that at any
62
+ * time - fine for restoring straight back into the app, wrong for an export.
63
+ * Parent directories are created if they do not exist.
64
+ */
65
+ fetch: (options: {
66
+ recordName: string;
67
+ fieldName: string;
68
+ zoneName?: string | null;
69
+ destinationUri?: string;
70
+ }) => Promise<string | null>;
71
+ /**
72
+ * Cancels an in-flight {@link save} or {@link fetch}, rejecting that call
73
+ * with `ERR_CANCELLED`. Resolves true when there was a transfer to cancel.
74
+ *
75
+ * Identified by record and field rather than by a handle, because that is
76
+ * what identifies a transfer everywhere else in this API - `onProgress`
77
+ * reports the same pair, so a UI already has it.
78
+ */
79
+ cancel: (options: {
80
+ recordName: string;
81
+ fieldName: string;
82
+ }) => Promise<boolean>;
83
+ /** Upload/download progress for asset transfers. Native only. */
84
+ onProgress: (listener: (e: AssetProgressEvent) => void) => Unsubscribe;
85
+ };
86
+ //# sourceMappingURL=cloudKit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudKit.d.ts","sourceRoot":"","sources":["../../../../src/providers/cloudKit.ts"],"names":[],"mappings":"AAIA,OAAO,EAAsB,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAGtF,OAAO,KAAK,EAGV,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,WAAW,EACZ,MAAM,UAAU,CAAA;AAiCjB,eAAO,MAAM,QAAQ,EAAE,aAoMtB,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,kBAAkB,GAAG;IAAE,IAAI,CAAC,EAAE,YAAY,CAAA;CAAE,GACnD,aAAa,CA8Ff;AAED,yEAAyE;AACzE,eAAO,MAAM,KAAK;uBACS,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;uBAQtB,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;gBAQ/B,OAAO,CAAC,MAAM,EAAE,CAAC;CAQlC,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,MAAM;IACjB;;;;;;OAMG;oB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