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,620 @@
1
+ "use strict";
2
+
3
+ import { CloudSyncError, ErrorCode } from "../errors.js";
4
+ import { throwIfAborted, withTimeout } from "./timeout.js";
5
+
6
+ /**
7
+ * Google Drive `appDataFolder` REST client.
8
+ *
9
+ * `appDataFolder` is a hidden per-app, per-Google-account folder: nothing shows
10
+ * up in the user's visible Drive, and the data survives an app uninstall because
11
+ * it is tied to the account rather than the install.
12
+ *
13
+ * Auth is deliberately injected rather than owned. The library does not depend
14
+ * on `@react-native-google-signin/google-signin` (or any other sign-in library),
15
+ * so the host app keeps control of the consent flow, and the same client works
16
+ * unchanged in a browser where that library does not apply.
17
+ */
18
+
19
+ const FILES_URL = 'https://www.googleapis.com/drive/v3/files';
20
+ const UPLOAD_URL = 'https://www.googleapis.com/upload/drive/v3/files';
21
+ const ABOUT_URL = 'https://www.googleapis.com/drive/v3/about';
22
+ const CHANGES_URL = 'https://www.googleapis.com/drive/v3/changes';
23
+ const DEFAULT_CHUNK_BYTES = 8 * 1024 * 1024;
24
+ const DEFAULT_TIMEOUT_MS = 60_000;
25
+
26
+ /** A local file `uploadFile` reads from, in fixed-size pieces. */
27
+
28
+ /** A local file `downloadFile` writes into, one piece at a time. */
29
+
30
+ /**
31
+ * Local file I/O for `googleDriveFiles`, supplied by the host app rather than
32
+ * this package depending on a filesystem library.
33
+ *
34
+ * base64 in and out - not a stream or a byte array - because that is the
35
+ * primitive RN filesystem libraries actually expose for a chunked read/write
36
+ * (`expo-file-system`'s `readAsStringAsync`/`writeAsStringAsync` with
37
+ * `EncodingType.Base64` and `position`/`length`/`append`), so the adapter
38
+ * mirrors that rather than inventing an abstraction nothing implements
39
+ * natively. `googleDriveFiles` does the base64 <-> bytes conversion at the
40
+ * boundary; a chunk is capped at `chunkBytes` (8 MiB default), so the base64
41
+ * string is never larger than that either.
42
+ */
43
+
44
+ /** The `fields` mask every listing uses, so a read also learns modification time. */
45
+ const FILE_FIELDS = 'id,name,modifiedTime,version';
46
+
47
+ /** True for the 404 the client tags when a file id no longer resolves. */
48
+ function isNotFound(e) {
49
+ return e instanceof CloudSyncError && e.serverErrorCode === 'NOT_FOUND';
50
+ }
51
+
52
+ /** True for a transfer failure worth retrying after re-querying the real offset. */
53
+ function isRetryableTransfer(e) {
54
+ return e instanceof CloudSyncError && (e.code === ErrorCode.NETWORK_UNAVAILABLE || e.code === ErrorCode.RATE_LIMITED);
55
+ }
56
+ export class GoogleDriveClient {
57
+ /**
58
+ * name -> fileId.
59
+ *
60
+ * Drive has no "get by name" endpoint, so every read would otherwise cost a
61
+ * list query. react-native-cloud-storage's Drive backend does exactly that and
62
+ * additionally lists the *whole* drive before filtering client-side, which its
63
+ * users measured in minutes (kuatsu#49) and which can loop forever (kuatsu#39).
64
+ * A scoped `q=` query plus this cache keeps a read to one request, usually zero.
65
+ */
66
+ idCache = new Map();
67
+ /**
68
+ * name -> the metadata the last listing reported.
69
+ *
70
+ * Kept beside the id cache so `getItemWithMeta` does not need a second round
71
+ * trip to learn a modification time the `q=` query already returned.
72
+ */
73
+ metaCache = new Map();
74
+ constructor(config) {
75
+ this.config = config;
76
+ this.chunkBytes = config.chunkBytes ?? DEFAULT_CHUNK_BYTES;
77
+ }
78
+ get fetch() {
79
+ return this.config.fetchImpl ?? globalThis.fetch;
80
+ }
81
+ async requireToken() {
82
+ const token = await this.config.getAccessToken();
83
+ if (!token) throw new CloudSyncError(ErrorCode.NOT_SIGNED_IN, '[RNCloudSync] No Google Drive access token. Connect a Google account first.', {
84
+ provider: 'googleDrive'
85
+ });
86
+ return token;
87
+ }
88
+
89
+ /**
90
+ * `extraOkStatuses` is for the resumable-upload protocol, where 308 ("Resume
91
+ * Incomplete") is an expected, successful outcome rather than an error - the
92
+ * caller inspects the response itself rather than getting a thrown rejection.
93
+ */
94
+ async request(url, init, extraOkStatuses = []) {
95
+ const token = await this.requireToken();
96
+ const headers = new Headers(init.headers);
97
+ headers.set('Authorization', `Bearer ${token}`);
98
+ let res;
99
+ try {
100
+ res = await withTimeout(this.fetch(url, {
101
+ ...init,
102
+ headers
103
+ }), this.config.timeoutMs ?? DEFAULT_TIMEOUT_MS, 'googleDrive');
104
+ } catch (e) {
105
+ // A timeout is already classified and retryable; re-wrapping it as a
106
+ // network failure would throw the distinction away.
107
+ if (e instanceof CloudSyncError) throw e;
108
+ throw new CloudSyncError(ErrorCode.NETWORK_UNAVAILABLE, '[RNCloudSync] Google Drive request failed to reach the server.', {
109
+ provider: 'googleDrive',
110
+ cause: e
111
+ });
112
+ }
113
+ if (res.ok || extraOkStatuses.includes(res.status)) return res;
114
+ if (res.status === 401 || res.status === 403) {
115
+ await this.config.onAuthExpired?.();
116
+ throw new CloudSyncError(ErrorCode.AUTH_EXPIRED, `[RNCloudSync] Google Drive returned HTTP ${res.status}; the access token is not valid.`, {
117
+ provider: 'googleDrive'
118
+ });
119
+ }
120
+ if (res.status === 429) {
121
+ const retryAfter = Number(res.headers.get('Retry-After'));
122
+ throw new CloudSyncError(ErrorCode.RATE_LIMITED, '[RNCloudSync] Google Drive rate limited the request.', {
123
+ provider: 'googleDrive',
124
+ retryAfterMs: Number.isFinite(retryAfter) ? retryAfter * 1000 : undefined
125
+ });
126
+ }
127
+ if (res.status === 507) throw new CloudSyncError(ErrorCode.QUOTA_EXCEEDED, '[RNCloudSync] Google Drive storage quota exceeded.', {
128
+ provider: 'googleDrive'
129
+ });
130
+ // Tagged so callers can tell "this file id is gone" from a generic failure.
131
+ // Without the tag a stale memoised id was indistinguishable from a real
132
+ // error, so it could never be recovered from.
133
+ if (res.status === 404) throw new CloudSyncError(ErrorCode.UNKNOWN, '[RNCloudSync] Google Drive has no file with that id.', {
134
+ provider: 'googleDrive',
135
+ serverErrorCode: 'NOT_FOUND'
136
+ });
137
+ throw new CloudSyncError(ErrorCode.UNKNOWN, `[RNCloudSync] Google Drive returned HTTP ${res.status}.`, {
138
+ provider: 'googleDrive'
139
+ });
140
+ }
141
+
142
+ /**
143
+ * Resolves a file name to its id within appDataFolder, or null if absent.
144
+ *
145
+ * Pass `refresh` to bypass the memo after a cached id turned out to be stale.
146
+ */
147
+ async findFileId(name, refresh = false) {
148
+ if (!refresh) {
149
+ const cached = this.idCache.get(name);
150
+ if (cached != null) return cached;
151
+ }
152
+ this.idCache.delete(name);
153
+
154
+ // Scope the query server-side. Escaping matters: an apostrophe in a key
155
+ // would otherwise terminate the quoted literal and produce a malformed query.
156
+ const q = encodeURIComponent(`name='${name.replace(/'/g, '\\\'')}' and trashed=false`);
157
+ const url = `${FILES_URL}?spaces=appDataFolder&q=${q}&fields=files(${FILE_FIELDS})&pageSize=10`;
158
+ const res = await this.request(url, {
159
+ method: 'GET'
160
+ });
161
+ const json = await res.json();
162
+ const matches = (json.files ?? []).filter(f => f.name === name);
163
+ if (matches.length === 0) {
164
+ this.metaCache.delete(name);
165
+ return null;
166
+ }
167
+ const file = matches.length === 1 ? matches[0] : this.pickAmongDuplicates(name, matches);
168
+ this.remember(file);
169
+ return file.id;
170
+ }
171
+
172
+ /**
173
+ * Chooses between several files that share a name.
174
+ *
175
+ * Deterministically, and that is the whole point: the list order Drive
176
+ * returns is unspecified, so picking the first match lets two devices settle
177
+ * on two different files for the same key and diverge forever, silently.
178
+ * Ordering by modification time - newest first, ties broken by id - gives
179
+ * every device the same answer.
180
+ */
181
+ pickAmongDuplicates(name, matches) {
182
+ if (this.config.onDuplicateName === 'error') throw new CloudSyncError(ErrorCode.CONFLICT, `[RNCloudSync] Google Drive holds ${matches.length} files named '${name}'. ` + `Reconcile them, or configure onDuplicateName: 'newest' to always take the ` + `most recently modified.`, {
183
+ provider: 'googleDrive',
184
+ serverErrorCode: 'DUPLICATE_NAME'
185
+ });
186
+ return [...matches].sort((a, b) => {
187
+ const at = a.modifiedTime == null ? 0 : Date.parse(a.modifiedTime);
188
+ const bt = b.modifiedTime == null ? 0 : Date.parse(b.modifiedTime);
189
+ if (bt !== at) return bt - at;
190
+ // Same timestamp: id is stable and unique, so this still agrees across
191
+ // devices rather than depending on response order.
192
+ return a.id < b.id ? -1 : 1;
193
+ })[0];
194
+ }
195
+
196
+ /** Records what a listing told us about a file, ids and metadata together. */
197
+ remember(file) {
198
+ this.idCache.set(file.name, file.id);
199
+ const parsed = file.modifiedTime == null ? Number.NaN : Date.parse(file.modifiedTime);
200
+ this.metaCache.set(file.name, {
201
+ modifiedAt: Number.isNaN(parsed) ? undefined : parsed,
202
+ version: file.version
203
+ });
204
+ }
205
+ async getItem(name) {
206
+ const id = await this.findFileId(name);
207
+ if (id == null) return null;
208
+ try {
209
+ const res = await this.request(`${FILES_URL}/${id}?alt=media`, {
210
+ method: 'GET'
211
+ });
212
+ return await res.text();
213
+ } catch (e) {
214
+ if (!isNotFound(e)) throw e;
215
+ }
216
+
217
+ // The memoised id pointed at a file that is no longer there - another device
218
+ // deleted it. Look the name up again rather than throwing off a stale memo
219
+ // forever, and report a genuine absence as absent.
220
+ const fresh = await this.findFileId(name, true);
221
+ if (fresh == null) return null;
222
+ const res = await this.request(`${FILES_URL}/${fresh}?alt=media`, {
223
+ method: 'GET'
224
+ });
225
+ return await res.text();
226
+ }
227
+
228
+ /**
229
+ * A read that also reports Drive's own `modifiedTime`.
230
+ *
231
+ * Free: resolving a name to an id is already a listing, and asking that
232
+ * listing for `modifiedTime` costs nothing extra. Surfacing it is what lets
233
+ * {@link resolveByModifiedAt} order copies without the app embedding a
234
+ * timestamp in its payload.
235
+ */
236
+ async getItemWithMeta(name) {
237
+ const value = await this.getItem(name);
238
+ if (value == null) return null;
239
+ const meta = this.metaCache.get(name);
240
+ return {
241
+ value,
242
+ modifiedAt: meta?.modifiedAt,
243
+ version: meta?.version
244
+ };
245
+ }
246
+
247
+ /**
248
+ * Storage usage for the whole Google account.
249
+ *
250
+ * Note this is the account's total, not the `appDataFolder`'s share of it -
251
+ * Drive reports no per-folder usage. Still the number a "you are running out
252
+ * of space" prompt needs, because that is the limit a write will actually hit.
253
+ * `limit` is absent for unlimited (Workspace pooled) accounts.
254
+ */
255
+ async getQuota() {
256
+ const res = await this.request(`${ABOUT_URL}?fields=storageQuota`, {
257
+ method: 'GET'
258
+ });
259
+ const json = await res.json();
260
+ const usage = Number(json.storageQuota?.usage);
261
+ const limit = Number(json.storageQuota?.limit);
262
+ return {
263
+ usedBytes: Number.isFinite(usage) ? usage : undefined,
264
+ totalBytes: Number.isFinite(limit) ? limit : undefined
265
+ };
266
+ }
267
+ async setItem(name, value) {
268
+ const id = await this.findFileId(name);
269
+ if (id != null) try {
270
+ await this.request(`${UPLOAD_URL}/${id}?uploadType=media`, {
271
+ method: 'PATCH',
272
+ headers: {
273
+ 'Content-Type': 'application/json'
274
+ },
275
+ body: value
276
+ });
277
+ return;
278
+ } catch (e) {
279
+ // Same stale-memo case. Fall through and create the file again instead
280
+ // of failing every future write to this key.
281
+ if (!isNotFound(e)) throw e;
282
+ this.idCache.delete(name);
283
+ this.metaCache.delete(name);
284
+ }
285
+
286
+ // Multipart create: metadata part pins the file into appDataFolder, second
287
+ // part carries the content.
288
+ const boundary = `rncs-${Math.random().toString(36).slice(2)}`;
289
+ const metadata = JSON.stringify({
290
+ name,
291
+ parents: ['appDataFolder']
292
+ });
293
+ const body = `--${boundary}\r\n` + `Content-Type: application/json; charset=UTF-8\r\n\r\n${metadata}\r\n` + `--${boundary}\r\n` + `Content-Type: application/json\r\n\r\n${value}\r\n` + `--${boundary}--`;
294
+ const res = await this.request(`${UPLOAD_URL}?uploadType=multipart&fields=${FILE_FIELDS}`, {
295
+ method: 'POST',
296
+ headers: {
297
+ 'Content-Type': `multipart/related; boundary=${boundary}`
298
+ },
299
+ body
300
+ });
301
+ const json = await res.json();
302
+ // Remember what the create returned so the next read does not have to list.
303
+ if (json.id != null) this.remember({
304
+ ...json,
305
+ id: json.id,
306
+ name
307
+ });
308
+ }
309
+
310
+ /**
311
+ * Uploads `source` as `name`, using Drive's resumable protocol instead of
312
+ * `setItem`'s single-request multipart body.
313
+ *
314
+ * Two things a whole-file `setItem(name, base64OfEverything)` cannot do at
315
+ * a few hundred MB: hold the payload in memory as one JS string, and recover
316
+ * from a dropped connection without starting over. Reading happens in fixed
317
+ * chunks through `source.read`, so peak memory is one chunk rather than the
318
+ * whole file, and a chunk that fails mid-flight is retried - by asking Drive
319
+ * how many bytes it actually has and resuming from there - rather than
320
+ * restarting the transfer.
321
+ *
322
+ * That resumability is scoped to this call: the session lives only in
323
+ * memory, so if the process dies mid-upload, the next call to `uploadFile`
324
+ * starts a fresh session from byte 0. Persisting the session URI so a
325
+ * restart can resume it too is future scope, not something callers should
326
+ * assume works today.
327
+ */
328
+ async uploadFile(name, source, onProgress, signal) {
329
+ throwIfAborted(signal, 'googleDrive');
330
+ const existingId = await this.findFileId(name);
331
+ const sessionUrl = await this.startResumableSession(name, existingId);
332
+ let offset = 0;
333
+ let newId;
334
+ const total = source.size;
335
+
336
+ // A zero-byte file still needs one request to actually create it.
337
+ do {
338
+ // Checked between chunks rather than only up front: a cancel during a
339
+ // multi-hundred-megabyte transfer has to take effect while it is running,
340
+ // which is the entire point of being able to cancel one.
341
+ throwIfAborted(signal, 'googleDrive');
342
+ const length = Math.min(this.chunkBytes, total - offset);
343
+ const step = await this.putChunkWithRetry(sessionUrl, source, offset, length, total, onProgress);
344
+ offset = step.nextOffset;
345
+ if (step.id != null) newId = step.id;
346
+ } while (offset < total);
347
+
348
+ // A create only learns its id from the final response; an update already
349
+ // had one via `existingId`.
350
+ if (newId != null) this.idCache.set(name, newId);
351
+ onProgress?.(total, total);
352
+ }
353
+ async startResumableSession(name, existingId) {
354
+ const url = existingId != null ? `${UPLOAD_URL}/${existingId}?uploadType=resumable` : `${UPLOAD_URL}?uploadType=resumable&fields=id`;
355
+ const metadata = existingId != null ? {} : {
356
+ name,
357
+ parents: ['appDataFolder']
358
+ };
359
+ const res = await this.request(url, {
360
+ method: existingId != null ? 'PATCH' : 'POST',
361
+ headers: {
362
+ 'Content-Type': 'application/json; charset=UTF-8'
363
+ },
364
+ body: JSON.stringify(metadata)
365
+ });
366
+ const location = res.headers.get('Location');
367
+ if (location == null) throw new CloudSyncError(ErrorCode.UNKNOWN, '[RNCloudSync] Google Drive did not return a resumable session URI.', {
368
+ provider: 'googleDrive'
369
+ });
370
+ return location;
371
+ }
372
+
373
+ /** One chunk, with a single retry that re-queries the server's real offset first. */
374
+ async putChunkWithRetry(sessionUrl, source, offset, length, total, onProgress) {
375
+ try {
376
+ return await this.putChunk(sessionUrl, source, offset, length, total, onProgress);
377
+ } catch (e) {
378
+ if (!isRetryableTransfer(e)) throw e;
379
+ const resumeFrom = await this.queryUploadOffset(sessionUrl, total);
380
+ const retryLength = Math.min(this.chunkBytes, total - resumeFrom);
381
+ return await this.putChunk(sessionUrl, source, resumeFrom, retryLength, total, onProgress);
382
+ }
383
+ }
384
+ async putChunk(sessionUrl, source, offset, length, total, onProgress) {
385
+ const bytes = await source.read(offset, length);
386
+ const range = total === 0 ? 'bytes */0' : `bytes ${offset}-${offset + bytes.length - 1}/${total}`;
387
+ const res = await this.request(sessionUrl, {
388
+ method: 'PUT',
389
+ headers: {
390
+ 'Content-Range': range
391
+ },
392
+ // TS's DOM lib types BodyInit's BufferSource as Uint8Array<ArrayBuffer>
393
+ // specifically, which a plain Uint8Array read doesn't structurally
394
+ // match even though every fetch implementation accepts it at runtime.
395
+ body: bytes
396
+ }, [308]);
397
+ const nextOffset = offset + bytes.length;
398
+ if (res.status === 308) {
399
+ onProgress?.(nextOffset, total);
400
+ return {
401
+ nextOffset
402
+ };
403
+ }
404
+
405
+ // 200/201: the file is complete.
406
+ const json = await res.json().catch(() => null);
407
+ return {
408
+ nextOffset: total,
409
+ id: json?.id
410
+ };
411
+ }
412
+
413
+ /** Asks Drive how much of an in-flight resumable session it actually has. */
414
+ async queryUploadOffset(sessionUrl, total) {
415
+ const res = await this.request(sessionUrl, {
416
+ method: 'PUT',
417
+ headers: {
418
+ 'Content-Range': `bytes */${total}`
419
+ }
420
+ }, [308]);
421
+ if (res.status !== 308) return total; // already complete, unexpectedly
422
+
423
+ const range = res.headers.get('Range'); // "bytes=0-8388607"
424
+ if (range == null) return 0;
425
+ const match = /bytes=0-(\d+)/.exec(range);
426
+ return match ? Number(match[1]) + 1 : 0;
427
+ }
428
+
429
+ /**
430
+ * Downloads `name` into `sink`, in the same fixed-size chunks `uploadFile`
431
+ * writes in - so a restore never holds the whole file in memory either.
432
+ * Resolves `false` when no such file exists, `true` once every chunk has
433
+ * been handed to the sink.
434
+ */
435
+ async downloadFile(name, sink, onProgress, signal) {
436
+ throwIfAborted(signal, 'googleDrive');
437
+ const id = await this.findFileId(name);
438
+ if (id == null) return false;
439
+ const total = await this.fileSize(id);
440
+ if (total === 0) {
441
+ await sink.write(new Uint8Array(0), true);
442
+ onProgress?.(0, 0);
443
+ return true;
444
+ }
445
+ let offset = 0;
446
+ let isFirstChunk = true;
447
+ while (offset < total) {
448
+ throwIfAborted(signal, 'googleDrive');
449
+ const end = Math.min(offset + this.chunkBytes, total) - 1;
450
+ const res = await this.request(`${FILES_URL}/${id}?alt=media`, {
451
+ method: 'GET',
452
+ headers: {
453
+ Range: `bytes=${offset}-${end}`
454
+ }
455
+ });
456
+ const bytes = new Uint8Array(await res.arrayBuffer());
457
+ await sink.write(bytes, isFirstChunk);
458
+ isFirstChunk = false;
459
+ offset += bytes.length;
460
+ onProgress?.(offset, total);
461
+ }
462
+ return true;
463
+ }
464
+ async fileSize(id) {
465
+ const res = await this.request(`${FILES_URL}/${id}?fields=size`, {
466
+ method: 'GET'
467
+ });
468
+ const json = await res.json();
469
+ return json.size != null ? Number(json.size) : 0;
470
+ }
471
+ async removeItem(name) {
472
+ const id = await this.findFileId(name);
473
+ // Already absent is the desired end state, not a failure.
474
+ if (id == null) return;
475
+ try {
476
+ await this.request(`${FILES_URL}/${id}`, {
477
+ method: 'DELETE'
478
+ });
479
+ } catch (e) {
480
+ // Deleted from under us: the end state the caller asked for already holds.
481
+ if (!isNotFound(e)) throw e;
482
+ } finally {
483
+ this.idCache.delete(name);
484
+ this.metaCache.delete(name);
485
+ }
486
+ }
487
+ async getAllKeys() {
488
+ const names = [];
489
+ let pageToken;
490
+
491
+ // Paginate rather than assuming one page holds everything.
492
+ do {
493
+ const params = new URLSearchParams({
494
+ spaces: 'appDataFolder',
495
+ q: 'trashed=false',
496
+ fields: `nextPageToken,files(${FILE_FIELDS})`,
497
+ pageSize: '100'
498
+ });
499
+ if (pageToken != null) params.set('pageToken', pageToken);
500
+ const res = await this.request(`${FILES_URL}?${params.toString()}`, {
501
+ method: 'GET'
502
+ });
503
+ const json = await res.json();
504
+ for (const f of json.files ?? []) {
505
+ names.push(f.name);
506
+ this.remember(f);
507
+ }
508
+ pageToken = json.nextPageToken;
509
+ } while (pageToken != null);
510
+ return names;
511
+ }
512
+
513
+ /**
514
+ * A cursor marking "everything up to now", for {@link pollChanges}.
515
+ *
516
+ * Drive's change feed is cursor-based rather than time-based, so a watcher
517
+ * has to take a starting cursor before it can ask what changed since.
518
+ */
519
+ async getStartPageToken() {
520
+ const res = await this.request(`${CHANGES_URL}/startPageToken?spaces=appDataFolder`, {
521
+ method: 'GET'
522
+ });
523
+ const json = await res.json();
524
+ if (json.startPageToken == null) throw new CloudSyncError(ErrorCode.UNKNOWN, '[RNCloudSync] Google Drive did not return a change cursor.', {
525
+ provider: 'googleDrive'
526
+ });
527
+ return json.startPageToken;
528
+ }
529
+
530
+ /**
531
+ * What changed in `appDataFolder` since `pageToken`, and the cursor to use
532
+ * next time.
533
+ *
534
+ * This is how a non-Apple platform learns that another device wrote something
535
+ * - CloudKit gets `NSUbiquitousKeyValueStore` notifications and `CKAccountChanged`
536
+ * for free, but Drive has no push channel without a server to receive its
537
+ * webhooks, so the honest equivalent is a cursor the app polls. Cheap: a poll
538
+ * with nothing to report is one request returning an empty list.
539
+ *
540
+ * Deletions are included - `removed` entries and trashed files both surface,
541
+ * because "another device deleted this key" is exactly as important as
542
+ * "another device changed it".
543
+ */
544
+ async pollChanges(pageToken) {
545
+ const names = new Set();
546
+ let token = pageToken;
547
+ let nextToken;
548
+ for (;;) {
549
+ const params = new URLSearchParams({
550
+ pageToken: token,
551
+ spaces: 'appDataFolder',
552
+ includeRemoved: 'true',
553
+ fields: 'newStartPageToken,nextPageToken,changes(fileId,removed,file(id,name,trashed))'
554
+ });
555
+ const res = await this.request(`${CHANGES_URL}?${params.toString()}`, {
556
+ method: 'GET'
557
+ });
558
+ const json = await res.json();
559
+ for (const change of json.changes ?? []) {
560
+ const name = change.file?.name;
561
+ if (name != null) {
562
+ names.add(name);
563
+ // A file that went away must not keep answering reads from the id
564
+ // cache, and one that changed must be re-read rather than served
565
+ // from a stale memo.
566
+ if (change.removed === true || change.file?.trashed === true) {
567
+ this.idCache.delete(name);
568
+ this.metaCache.delete(name);
569
+ }
570
+ continue;
571
+ }
572
+
573
+ // Drive omits `file` for a change the caller can no longer see. All we
574
+ // have is the id, so drop whichever cached name points at it.
575
+ if (change.fileId != null) this.forgetById(change.fileId);
576
+ }
577
+
578
+ // `nextPageToken` means more pages of the same batch; `newStartPageToken`
579
+ // means this was the last page and is the cursor for next time.
580
+ if (json.nextPageToken != null) {
581
+ token = json.nextPageToken;
582
+ continue;
583
+ }
584
+ nextToken = json.newStartPageToken ?? token;
585
+ break;
586
+ }
587
+ return {
588
+ names: [...names],
589
+ nextToken
590
+ };
591
+ }
592
+
593
+ /** Drops whatever name currently memoises this file id. */
594
+ forgetById(fileId) {
595
+ for (const [name, id] of this.idCache) if (id === fileId) {
596
+ this.idCache.delete(name);
597
+ this.metaCache.delete(name);
598
+ return;
599
+ }
600
+ }
601
+
602
+ /**
603
+ * Whether an access token can currently be obtained, without making a network
604
+ * request. Backs the provider's `isAvailable()` probe.
605
+ */
606
+ async hasToken() {
607
+ try {
608
+ return (await this.config.getAccessToken()) != null;
609
+ } catch {
610
+ return false;
611
+ }
612
+ }
613
+
614
+ /** Drops memoised file ids. Call after an account switch. */
615
+ clearCache() {
616
+ this.idCache.clear();
617
+ this.metaCache.clear();
618
+ }
619
+ }
620
+ //# sourceMappingURL=googleDriveRest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CloudSyncError","ErrorCode","throwIfAborted","withTimeout","FILES_URL","UPLOAD_URL","ABOUT_URL","CHANGES_URL","DEFAULT_CHUNK_BYTES","DEFAULT_TIMEOUT_MS","FILE_FIELDS","isNotFound","e","serverErrorCode","isRetryableTransfer","code","NETWORK_UNAVAILABLE","RATE_LIMITED","GoogleDriveClient","idCache","Map","metaCache","constructor","config","chunkBytes","fetch","fetchImpl","globalThis","requireToken","token","getAccessToken","NOT_SIGNED_IN","provider","request","url","init","extraOkStatuses","headers","Headers","set","res","timeoutMs","cause","ok","includes","status","onAuthExpired","AUTH_EXPIRED","retryAfter","Number","get","retryAfterMs","isFinite","undefined","QUOTA_EXCEEDED","UNKNOWN","findFileId","name","refresh","cached","delete","q","encodeURIComponent","replace","method","json","matches","files","filter","f","length","file","pickAmongDuplicates","remember","id","onDuplicateName","CONFLICT","sort","a","b","at","modifiedTime","Date","parse","bt","parsed","NaN","modifiedAt","isNaN","version","getItem","text","fresh","getItemWithMeta","value","meta","getQuota","usage","storageQuota","limit","usedBytes","totalBytes","setItem","body","boundary","Math","random","toString","slice","metadata","JSON","stringify","parents","uploadFile","source","onProgress","signal","existingId","sessionUrl","startResumableSession","offset","newId","total","size","min","step","putChunkWithRetry","nextOffset","location","putChunk","resumeFrom","queryUploadOffset","retryLength","bytes","read","range","catch","match","exec","downloadFile","sink","fileSize","write","Uint8Array","isFirstChunk","end","Range","arrayBuffer","removeItem","getAllKeys","names","pageToken","params","URLSearchParams","spaces","fields","pageSize","push","nextPageToken","getStartPageToken","startPageToken","pollChanges","Set","nextToken","includeRemoved","change","changes","add","removed","trashed","fileId","forgetById","newStartPageToken","hasToken","clearCache","clear"],"sourceRoot":"../../../src","sources":["internal/googleDriveRest.ts"],"mappings":";;AAAA,SAASA,cAAc,EAAEC,SAAS,QAAQ,cAAW;AACrD,SAASC,cAAc,EAAEC,WAAW,QAAwB,cAAW;;AAEvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA6CA,MAAMC,SAAS,GAAG,2CAA2C;AAC7D,MAAMC,UAAU,GAAG,kDAAkD;AACrE,MAAMC,SAAS,GAAG,2CAA2C;AAC7D,MAAMC,WAAW,GAAG,6CAA6C;AACjE,MAAMC,mBAAmB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI;AAC3C,MAAMC,kBAAkB,GAAG,MAAM;;AAEjC;;AAMA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAqBA;AACA,MAAMC,WAAW,GAAG,8BAA8B;;AAElD;AACA,S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