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