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,527 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.VALUE_FIELD = exports.RECORD_TYPE_DEFAULT = exports.MAX_RECORD_BYTES = exports.CloudKitRestClient = void 0;
7
+ Object.defineProperty(exports, "byteLength", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _bytes.byteLength;
11
+ }
12
+ });
13
+ var _errors = require("../errors.js");
14
+ var _bytes = require("./bytes.js");
15
+ var _timeout = require("./timeout.js");
16
+ /** Default request timeout. Generous, because a large record on a slow link is normal. */
17
+ const DEFAULT_TIMEOUT_MS = 30_000;
18
+
19
+ /**
20
+ * CloudKit Web Services REST client.
21
+ *
22
+ * This is how the `cloudKit` provider reaches a user's PRIVATE database from
23
+ * Android and from the browser, where `CloudKit.framework` does not exist.
24
+ *
25
+ * Why an interactive user token and not a server key: Apple is explicit that a
26
+ * server-to-server key reaches only the *public* database - "Use a
27
+ * server-to-server key to access the public database of a container as the
28
+ * developer who created the key." Sign in with Apple cannot substitute either;
29
+ * per Apple DTS, "The unique user identifiers for Sign in with Apple and
30
+ * CloudKit are not linked." So an interactive `ckWebAuthToken` is not a shortcut
31
+ * this package chose - it is the only mechanism that exists.
32
+ *
33
+ * Deliberately no dependency on CloudKit JS. That library pulls Node's `crypto`
34
+ * for server-to-server signing, which is what killed the last React Native
35
+ * attempt at this (KjellConnelly/react-native-cloudkit pinned v1 because "2.0
36
+ * requires crypto which ... doesn't work with React Native"). The REST API in
37
+ * user-token mode needs no crypto at all: two query parameters on a `fetch`.
38
+ */
39
+
40
+ /**
41
+ * How many operations one `/records/modify` or `/records/lookup` call carries.
42
+ *
43
+ * Apple does not publish a hard maximum, but very large batches are rejected
44
+ * outright and a batch is atomic, so an oversized one fails as a unit. 200
45
+ * matches the page size CloudKit itself uses for query results.
46
+ */
47
+ const MAX_BATCH = 200;
48
+ const RECORD_TYPE_DEFAULT = exports.RECORD_TYPE_DEFAULT = 'KVBlob';
49
+ const VALUE_FIELD = exports.VALUE_FIELD = 'value';
50
+
51
+ /** CloudKit's documented per-record ceiling, excluding assets. */
52
+ const MAX_RECORD_BYTES = exports.MAX_RECORD_BYTES = 1024 * 1024;
53
+ /**
54
+ * CloudKit codes that all mean "the record is already there".
55
+ *
56
+ * `ATOMIC_ERROR` is included because an atomic batch reports a failed operation
57
+ * at the top level rather than per record.
58
+ */
59
+ const EXISTS_CODES = new Set(['EXISTS', 'CONFLICT', 'ATOMIC_ERROR']);
60
+ function isAlreadyExists(e) {
61
+ if (!(e instanceof _errors.CloudSyncError)) return false;
62
+ if (e.serverErrorCode != null) return EXISTS_CODES.has(e.serverErrorCode);
63
+ return e.code === _errors.ErrorCode.CONFLICT;
64
+ }
65
+
66
+ /** How long a reachability answer is reused. See {@link CloudKitRestClient.isReachable}. */
67
+ const REACHABILITY_TTL_MS = 30_000;
68
+
69
+ /** Record name used only to prove the container is reachable and authenticated. */
70
+ const AVAILABILITY_PROBE_RECORD = '__rncs_availability_probe__';
71
+ class CloudKitRestClient {
72
+ reachability = null;
73
+ constructor(config) {
74
+ this.config = config;
75
+ }
76
+ baseUrl() {
77
+ const {
78
+ containerIdentifier,
79
+ environment
80
+ } = this.config;
81
+ return `https://api.apple-cloudkit.com/database/1/${containerIdentifier}/${environment}/private`;
82
+ }
83
+ get fetch() {
84
+ return this.config.fetchImpl ?? globalThis.fetch;
85
+ }
86
+ async requireAuthToken() {
87
+ if (!this.config.apiToken) throw new _errors.CloudSyncError(_errors.ErrorCode.CONTAINER_MISCONFIGURED, '[RNCloudSync] No CloudKit API token configured. Create a Client token in the ' + 'CloudKit Console under API Access and pass it to configureCloudKit().', {
88
+ provider: 'cloudKit'
89
+ });
90
+ const token = await this.config.getAuthToken();
91
+ if (!token) throw new _errors.CloudSyncError(_errors.ErrorCode.NOT_SIGNED_IN, '[RNCloudSync] No CloudKit web auth token. The user must sign in with their ' + 'Apple ID before the private database can be reached.', {
92
+ provider: 'cloudKit'
93
+ });
94
+ return token;
95
+ }
96
+ async handleAuthExpired() {
97
+ await this.config.onAuthExpired?.();
98
+ }
99
+
100
+ /**
101
+ * Maps a CloudKit `serverErrorCode` onto the package's shared vocabulary.
102
+ * Codes are from Apple's CloudKit Web Services error reference.
103
+ */
104
+ async toError(code, reason, retryAfter, serverValue) {
105
+ const message = `[RNCloudSync] CloudKit: ${code ?? 'unknown'}${reason ? ` - ${reason}` : ''}`;
106
+ const provider = 'cloudKit';
107
+ const base = {
108
+ provider,
109
+ serverErrorCode: code
110
+ };
111
+ switch (code) {
112
+ case 'AUTHENTICATION_REQUIRED':
113
+ case 'AUTHENTICATION_FAILED':
114
+ await this.handleAuthExpired();
115
+ return new _errors.CloudSyncError(_errors.ErrorCode.AUTH_EXPIRED, message, base);
116
+ case 'ACCESS_DENIED':
117
+ await this.handleAuthExpired();
118
+ return new _errors.CloudSyncError(_errors.ErrorCode.AUTH_EXPIRED, message, base);
119
+ case 'QUOTA_EXCEEDED':
120
+ return new _errors.CloudSyncError(_errors.ErrorCode.QUOTA_EXCEEDED, message, base);
121
+ case 'THROTTLED':
122
+ case 'TRY_AGAIN_LATER':
123
+ return new _errors.CloudSyncError(_errors.ErrorCode.RATE_LIMITED, message, {
124
+ ...base,
125
+ retryAfterMs: retryAfter != null ? retryAfter * 1000 : undefined
126
+ });
127
+ case 'CONFLICT':
128
+ return new _errors.CloudSyncError(_errors.ErrorCode.CONFLICT, message, {
129
+ ...base,
130
+ serverValue
131
+ });
132
+ case 'BAD_REQUEST':
133
+ case 'ZONE_NOT_FOUND':
134
+ return new _errors.CloudSyncError(_errors.ErrorCode.CONTAINER_MISCONFIGURED, message, base);
135
+ default:
136
+ return new _errors.CloudSyncError(_errors.ErrorCode.UNKNOWN, message, base);
137
+ }
138
+ }
139
+ async post(path, body) {
140
+ const token = await this.requireAuthToken();
141
+ const url = `${this.baseUrl()}${path}` + `?ckAPIToken=${encodeURIComponent(this.config.apiToken)}` + `&ckWebAuthToken=${encodeURIComponent(token)}`;
142
+ let res;
143
+ try {
144
+ res = await (0, _timeout.withTimeout)(this.fetch(url, {
145
+ method: 'POST',
146
+ headers: {
147
+ 'Content-Type': 'application/json'
148
+ },
149
+ body: JSON.stringify(body)
150
+ }), this.config.timeoutMs ?? DEFAULT_TIMEOUT_MS, 'cloudKit');
151
+ } catch (e) {
152
+ // A timeout is already a classified, retryable CloudSyncError; re-wrapping
153
+ // it as a network failure would throw away the distinction.
154
+ if (e instanceof _errors.CloudSyncError) throw e;
155
+ throw new _errors.CloudSyncError(_errors.ErrorCode.NETWORK_UNAVAILABLE, '[RNCloudSync] CloudKit request failed to reach the server.', {
156
+ provider: 'cloudKit',
157
+ cause: e
158
+ });
159
+ }
160
+ const json = await res.json().catch(() => null);
161
+
162
+ // Top-level error dict. This is the branch cryptoc's port could never
163
+ // reach - 421 responses carry no `records`, so an error nested-lookup misses
164
+ // it entirely. Check the root BEFORE looking at per-record results.
165
+ if (json?.serverErrorCode != null) throw await this.toError(json.serverErrorCode, json.reason, json.retryAfter);
166
+ if (!res.ok) {
167
+ // HTTP-level failure with no parseable CloudKit error body.
168
+ if (res.status === 401 || res.status === 421) {
169
+ await this.handleAuthExpired();
170
+ throw new _errors.CloudSyncError(_errors.ErrorCode.AUTH_EXPIRED, `[RNCloudSync] CloudKit returned HTTP ${res.status}; the web auth token is no longer valid.`, {
171
+ provider: 'cloudKit'
172
+ });
173
+ }
174
+ if (res.status === 429 || res.status === 503) throw new _errors.CloudSyncError(_errors.ErrorCode.RATE_LIMITED, `[RNCloudSync] CloudKit returned HTTP ${res.status}.`, {
175
+ provider: 'cloudKit'
176
+ });
177
+ throw new _errors.CloudSyncError(_errors.ErrorCode.UNKNOWN, `[RNCloudSync] CloudKit returned HTTP ${res.status}.`, {
178
+ provider: 'cloudKit'
179
+ });
180
+ }
181
+ return json ?? {};
182
+ }
183
+ async getRecord(recordName, recordType = RECORD_TYPE_DEFAULT) {
184
+ return (await this.getRecordWithMeta(recordName, recordType))?.value ?? null;
185
+ }
186
+
187
+ /**
188
+ * A read that also returns the server's own modification time and the
189
+ * record's change tag.
190
+ *
191
+ * Both come back on a plain lookup whether or not anyone asks, so surfacing
192
+ * them costs nothing - and they are what make {@link resolveByModifiedAt} and
193
+ * conditional writes possible without the app instrumenting its payloads.
194
+ */
195
+ async getRecordWithMeta(recordName, recordType = RECORD_TYPE_DEFAULT) {
196
+ void recordType;
197
+ const json = await this.post('/records/lookup', {
198
+ records: [{
199
+ recordName
200
+ }]
201
+ });
202
+ const record = json.records?.find(r => r.recordName === recordName) ?? json.records?.[0];
203
+ if (record == null) return null;
204
+ if (record.serverErrorCode != null) {
205
+ // A record that simply is not there is a normal outcome, not a failure.
206
+ // Note the real code is NOT_FOUND - `UNKNOWN_ITEM` is a CloudKit
207
+ // *framework* code and never appears in Web Services responses, so
208
+ // matching on it (as cryptoc did) silently misclassifies every miss.
209
+ if (record.serverErrorCode === 'NOT_FOUND') return null;
210
+ throw await this.toError(record.serverErrorCode, record.reason, record.retryAfter);
211
+ }
212
+ const value = record.fields?.[VALUE_FIELD]?.value;
213
+ if (typeof value !== 'string') return null;
214
+ return {
215
+ value,
216
+ modifiedAt: typeof record.modified?.timestamp === 'number' ? record.modified.timestamp : undefined,
217
+ recordChangeTag: record.recordChangeTag
218
+ };
219
+ }
220
+
221
+ /**
222
+ * Reads many records in one request.
223
+ *
224
+ * `/records/lookup` has taken an array of record ids since the API shipped,
225
+ * so reading 200 keys one at a time was 200 round trips for no reason - and
226
+ * 200 chances to be throttled. Results are matched back by `recordName`
227
+ * rather than by position, because CloudKit does not promise the response
228
+ * preserves request order.
229
+ */
230
+ async getRecords(recordNames, recordType = RECORD_TYPE_DEFAULT) {
231
+ void recordType;
232
+ if (recordNames.length === 0) return [];
233
+ const found = new Map();
234
+ for (const batch of chunk(recordNames, MAX_BATCH)) {
235
+ const json = await this.post('/records/lookup', {
236
+ records: batch.map(recordName => ({
237
+ recordName
238
+ }))
239
+ });
240
+ for (const record of json.records ?? []) {
241
+ if (record.recordName == null) continue;
242
+ if (record.serverErrorCode != null) {
243
+ // Absent is absent, per record - one missing key must not fail the
244
+ // whole batch the way an atomic *write* legitimately does.
245
+ if (record.serverErrorCode === 'NOT_FOUND') continue;
246
+ throw await this.toError(record.serverErrorCode, record.reason, record.retryAfter);
247
+ }
248
+ const value = record.fields?.[VALUE_FIELD]?.value;
249
+ if (typeof value === 'string') found.set(record.recordName, value);
250
+ }
251
+ }
252
+ return recordNames.map(name => found.get(name) ?? null);
253
+ }
254
+
255
+ /**
256
+ * Writes many records in one request.
257
+ *
258
+ * Uses `forceUpdate`, which creates or replaces in a single operation, so
259
+ * unlike the single-record path there is no create-then-fall-back-to-update
260
+ * dance to repeat per key.
261
+ *
262
+ * `atomic: false`, deliberately: a batch is a convenience for the caller, not
263
+ * a transaction they asked for, and one oversized record should not silently
264
+ * discard the other 199. Per-record failures are collected and raised
265
+ * together.
266
+ */
267
+ async saveRecords(entries, recordType = RECORD_TYPE_DEFAULT) {
268
+ if (entries.length === 0) return;
269
+ for (const [recordName, value] of entries) {
270
+ const bytes = (0, _bytes.byteLength)(value);
271
+ if (bytes > MAX_RECORD_BYTES) throw new _errors.CloudSyncError(_errors.ErrorCode.PAYLOAD_TOO_LARGE, `[RNCloudSync] '${recordName}' is ${bytes} bytes; CloudKit records are limited to ` + `${MAX_RECORD_BYTES}.`, {
272
+ provider: 'cloudKit',
273
+ limitBytes: MAX_RECORD_BYTES,
274
+ actualBytes: bytes
275
+ });
276
+ }
277
+ for (const batch of chunk(entries, MAX_BATCH)) {
278
+ const json = await this.post('/records/modify', {
279
+ atomic: false,
280
+ operations: batch.map(([recordName, value]) => ({
281
+ operationType: 'forceUpdate',
282
+ record: {
283
+ recordType,
284
+ recordName,
285
+ fields: {
286
+ [VALUE_FIELD]: {
287
+ value
288
+ }
289
+ }
290
+ }
291
+ }))
292
+ });
293
+ for (const record of json.records ?? []) if (record.serverErrorCode != null) throw await this.toError(record.serverErrorCode, record.reason, record.retryAfter);
294
+ }
295
+ }
296
+
297
+ /** Deletes many records in one request, with the same per-record rules. */
298
+ async deleteRecords(recordNames, recordType = RECORD_TYPE_DEFAULT) {
299
+ if (recordNames.length === 0) return;
300
+ for (const batch of chunk(recordNames, MAX_BATCH)) {
301
+ const json = await this.post('/records/modify', {
302
+ atomic: false,
303
+ operations: batch.map(recordName => ({
304
+ operationType: 'forceDelete',
305
+ record: {
306
+ recordType,
307
+ recordName
308
+ }
309
+ }))
310
+ });
311
+ for (const record of json.records ?? []) {
312
+ if (record.serverErrorCode == null) continue;
313
+ // Deleting something that was never there is the end state the caller
314
+ // asked for.
315
+ if (record.serverErrorCode === 'NOT_FOUND') continue;
316
+ throw await this.toError(record.serverErrorCode, record.reason, record.retryAfter);
317
+ }
318
+ }
319
+ }
320
+ async saveRecord(recordName, value, recordType = RECORD_TYPE_DEFAULT) {
321
+ const bytes = (0, _bytes.byteLength)(value);
322
+ if (bytes > MAX_RECORD_BYTES) throw new _errors.CloudSyncError(_errors.ErrorCode.PAYLOAD_TOO_LARGE, `[RNCloudSync] Value is ${bytes} bytes; CloudKit records are limited to ${MAX_RECORD_BYTES}. ` + `Use the store facade with tiering enabled to route large values to a CKAsset.`, {
323
+ provider: 'cloudKit',
324
+ limitBytes: MAX_RECORD_BYTES,
325
+ actualBytes: bytes
326
+ });
327
+ const record = {
328
+ recordType,
329
+ recordName,
330
+ fields: {
331
+ [VALUE_FIELD]: {
332
+ value
333
+ }
334
+ }
335
+ };
336
+
337
+ // `atomic` defaults to true server-side. Setting it explicitly documents the
338
+ // intent and keeps behaviour stable if that default ever changes.
339
+ let created = null;
340
+ try {
341
+ created = await this.post('/records/modify', {
342
+ atomic: true,
343
+ operations: [{
344
+ operationType: 'create',
345
+ record
346
+ }]
347
+ });
348
+ } catch (e) {
349
+ // A create against a record that already exists is the normal path for
350
+ // every write after the first, so it must not surface as an error. With
351
+ // `atomic: true` CloudKit reports that at the top level, which `post`
352
+ // turns into a throw.
353
+ //
354
+ // Only an already-exists response falls through to the update below.
355
+ // Anything else - quota, auth, rate limiting, or a response this package
356
+ // could not classify - is rethrown. Swallowing an unclassified failure
357
+ // here and force-updating anyway would overwrite whatever is on the
358
+ // server on the strength of an error nobody read.
359
+ if (!isAlreadyExists(e)) throw e;
360
+ }
361
+ const createdRecord = created?.records?.[0];
362
+ if (created != null && createdRecord?.serverErrorCode == null) return;
363
+ if (createdRecord?.serverErrorCode != null && !EXISTS_CODES.has(createdRecord.serverErrorCode)) throw await this.toError(createdRecord.serverErrorCode, createdRecord.reason, createdRecord.retryAfter);
364
+
365
+ // Last-write-wins, matching the native provider's `.changedKeys` save policy
366
+ // so both platforms resolve concurrent writes identically.
367
+ const updated = await this.post('/records/modify', {
368
+ atomic: true,
369
+ operations: [{
370
+ operationType: 'forceUpdate',
371
+ record
372
+ }]
373
+ });
374
+ const updatedRecord = updated.records?.[0];
375
+ if (updatedRecord?.serverErrorCode != null) {
376
+ const serverValue = updatedRecord.serverRecord?.fields?.[VALUE_FIELD]?.value;
377
+ throw await this.toError(updatedRecord.serverErrorCode, updatedRecord.reason, updatedRecord.retryAfter, typeof serverValue === 'string' ? serverValue : null);
378
+ }
379
+ }
380
+
381
+ /**
382
+ * A write that fails instead of clobbering, when the server's copy has moved
383
+ * on since `recordChangeTag` was read.
384
+ *
385
+ * The normal `saveRecord` is last-write-wins - the right default for the
386
+ * common case, and what the native provider's `.changedKeys` save policy
387
+ * does, so both platforms agree. But last-write-wins means a genuine
388
+ * concurrent edit is destroyed silently, and `ERR_CONFLICT` carries
389
+ * `serverValue` precisely so an app can merge instead. Without a conditional
390
+ * write, that error could never actually fire and the merge path was
391
+ * unreachable.
392
+ *
393
+ * Read the tag with {@link getRecordWithMeta}, pass it here, and handle
394
+ * `ERR_CONFLICT` by merging `serverValue` and retrying.
395
+ */
396
+ async saveRecordIfUnchanged(recordName, value, recordChangeTag, recordType = RECORD_TYPE_DEFAULT) {
397
+ const bytes = (0, _bytes.byteLength)(value);
398
+ if (bytes > MAX_RECORD_BYTES) throw new _errors.CloudSyncError(_errors.ErrorCode.PAYLOAD_TOO_LARGE, `[RNCloudSync] Value is ${bytes} bytes; CloudKit records are limited to ${MAX_RECORD_BYTES}.`, {
399
+ provider: 'cloudKit',
400
+ limitBytes: MAX_RECORD_BYTES,
401
+ actualBytes: bytes
402
+ });
403
+
404
+ // `update` (rather than `forceUpdate`) is the conditional form: with a
405
+ // change tag present, CloudKit rejects the write if the server's tag has
406
+ // moved on.
407
+ const json = await this.post('/records/modify', {
408
+ atomic: true,
409
+ operations: [{
410
+ operationType: 'update',
411
+ record: {
412
+ recordType,
413
+ recordName,
414
+ recordChangeTag,
415
+ fields: {
416
+ [VALUE_FIELD]: {
417
+ value
418
+ }
419
+ }
420
+ }
421
+ }]
422
+ });
423
+ const result = json.records?.[0];
424
+ if (result?.serverErrorCode == null) return;
425
+ const serverValue = result.serverRecord?.fields?.[VALUE_FIELD]?.value;
426
+ throw await this.toError(result.serverErrorCode, result.reason, result.retryAfter, typeof serverValue === 'string' ? serverValue : null);
427
+ }
428
+ async deleteRecord(recordName, recordType = RECORD_TYPE_DEFAULT) {
429
+ const json = await this.post('/records/modify', {
430
+ atomic: true,
431
+ operations: [{
432
+ operationType: 'forceDelete',
433
+ record: {
434
+ recordType,
435
+ recordName
436
+ }
437
+ }]
438
+ });
439
+ const result = json.records?.[0];
440
+ if (result?.serverErrorCode == null) return;
441
+ // Deleting something that was never there is a success from the caller's
442
+ // point of view - the desired end state already holds.
443
+ if (result.serverErrorCode === 'NOT_FOUND') return;
444
+ throw await this.toError(result.serverErrorCode, result.reason, result.retryAfter);
445
+ }
446
+ async queryRecordNames(recordType = RECORD_TYPE_DEFAULT) {
447
+ const names = [];
448
+ const seenMarkers = new Set();
449
+ let continuationMarker;
450
+
451
+ // `/records/query` caps a response at 200 records and hands back a
452
+ // continuation marker for the rest. Taking only the first page silently
453
+ // truncated `getAllKeys()`, and `migrate()` is built on `getAllKeys()` - so
454
+ // it showed up as a migration that quietly copied part of the data and
455
+ // reported success.
456
+ do {
457
+ const json = await this.post('/records/query', {
458
+ query: {
459
+ recordType
460
+ },
461
+ ...(continuationMarker != null ? {
462
+ continuationMarker
463
+ } : {})
464
+ });
465
+ for (const record of json.records ?? []) if (typeof record.recordName === 'string') names.push(record.recordName);
466
+ continuationMarker = json.continuationMarker;
467
+ // A server that repeats a marker would loop forever; stop instead.
468
+ if (continuationMarker != null) {
469
+ if (seenMarkers.has(continuationMarker)) break;
470
+ seenMarkers.add(continuationMarker);
471
+ }
472
+ } while (continuationMarker != null);
473
+ return names;
474
+ }
475
+
476
+ /**
477
+ * Cheap reachability check backing the provider's `isAvailable()`.
478
+ *
479
+ * The probe itself is a network round trip, but `isAvailable()` is documented
480
+ * as safe on a render path and the store calls it before every provider read -
481
+ * so unmemoised, each `getItem` on Android or web cost two requests instead of
482
+ * one. Held briefly: long enough to collapse that pair, short enough that a
483
+ * token expiring mid-session is noticed.
484
+ */
485
+ async isReachable() {
486
+ const now = Date.now();
487
+ if (this.reachability != null && now - this.reachability.at < REACHABILITY_TTL_MS) return this.reachability.ok;
488
+ let ok;
489
+ try {
490
+ // A `null` result and a NOT_FOUND both mean reachable and authenticated;
491
+ // only a thrown auth/network/config error means unavailable.
492
+ await this.getRecord(AVAILABILITY_PROBE_RECORD);
493
+ ok = true;
494
+ } catch {
495
+ ok = false;
496
+ }
497
+ this.reachability = {
498
+ at: now,
499
+ ok
500
+ };
501
+ return ok;
502
+ }
503
+
504
+ /**
505
+ * Drops the memoised reachability answer.
506
+ *
507
+ * Called on an account switch: that answer was recorded for the previous
508
+ * user's web auth token and says nothing about the new one.
509
+ */
510
+ clearCache() {
511
+ this.reachability = null;
512
+ }
513
+ }
514
+
515
+ /** Splits `items` into runs of at most `size`. */
516
+ exports.CloudKitRestClient = CloudKitRestClient;
517
+ function chunk(items, size) {
518
+ if (items.length <= size) return [items];
519
+ const out = [];
520
+ for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
521
+ return out;
522
+ }
523
+
524
+ // Re-exported from its own module so the tiering and key-validation paths can
525
+ // use it without importing a REST client. Kept exported here because it has
526
+ // been part of this module's surface since the first release.
527
+ //# sourceMappingURL=cloudKitRest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_errors","require","_bytes","_timeout","DEFAULT_TIMEOUT_MS","MAX_BATCH","RECORD_TYPE_DEFAULT","exports","VALUE_FIELD","MAX_RECORD_BYTES","EXISTS_CODES","Set","isAlreadyExists","e","CloudSyncError","serverErrorCode","has","code","ErrorCode","CONFLICT","REACHABILITY_TTL_MS","AVAILABILITY_PROBE_RECORD","CloudKitRestClient","reachability","constructor","config","baseUrl","containerIdentifier","environment","fetch","fetchImpl","globalThis","requireAuthToken","apiToken","CONTAINER_MISCONFIGURED","provider","token","getAuthToken","NOT_SIGNED_IN","handleAuthExpired","onAuthExpired","toError","reason","retryAfter","serverValue","message","base","AUTH_EXPIRED","QUOTA_EXCEEDED","RATE_LIMITED","retryAfterMs","undefined","UNKNOWN","post","path","body","url","encodeURIComponent","res","withTimeout","method","headers","JSON","stringify","timeoutMs","NETWORK_UNAVAILABLE","cause","json","catch","ok","status","getRecord","recordName","recordType","getRecordWithMeta","value","records","record","find","r","fields","modifiedAt","modified","timestamp","recordChangeTag","getRecords","recordNames","length","found","Map","batch","chunk","map","set","name","get","saveRecords","entries","bytes","byteLength","PAYLOAD_TOO_LARGE","limitBytes","actualBytes","atomic","operations","operationType","deleteRecords","saveRecord","created","createdRecord","updated","updatedRecord","serverRecord","saveRecordIfUnchanged","result","deleteRecord","queryRecordNames","names","seenMarkers","continuationMarker","query","push","add","isReachable","now","Date","at","clearCache","items","size","out","i","slice"],"sourceRoot":"../../../src","sources":["internal/cloudKitRest.ts"],"mappings":";;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA;AACA,MAAMG,kBAAkB,GAAG,MAAM;;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAoCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG,GAAG;AAEd,MAAMC,mBAAmB,GAAAC,OAAA,CAAAD,mBAAA,GAAG,QAAQ;AACpC,MAAME,WAAW,GAAAD,OAAA,CAAAC,WAAA,GAAG,OAAO;;AAElC;AACO,MAAMC,gBAAgB,GAAAF,OAAA,CAAAE,gBAAA,GAAG,IAAI,GAAG,IAAI;AAqC3C;AACA;AACA;AACA;AACA;AACA;AAC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C,GAAG,CAAC,EAAEA,CAAC,GAAGH,KAAK,CAACzC,MAAM,EAAE4C,CAAC,IAAIF,IAAI,EAAEC,GAAG,CAACT,IAAI,CAACO,KAAK,CAACI,KAAK,CAACD,CAAC,EAAEA,CAAC,GAAGF,IAAI,CAAC,CAAC;EAC/E,OAAOC,GAAG;AACZ;;AAEA;AACA;AACA","ignoreList":[]}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toAccountStatus = toAccountStatus;
7
+ exports.toChangeReason = toChangeReason;
8
+ const ACCOUNT_STATUSES = ['available', 'noAccount', 'restricted', 'temporarilyUnavailable', 'couldNotDetermine'];
9
+ const CHANGE_REASONS = ['serverChange', 'initialSync', 'quotaViolation', 'accountChange', 'unknown'];
10
+
11
+ /**
12
+ * Codegen has no string-union type, so enums cross the bridge as plain strings.
13
+ * Validate on the way in rather than casting - an unrecognised value from a
14
+ * newer native build should degrade to a known-safe member, not corrupt an
15
+ * exhaustive switch downstream.
16
+ */
17
+ function toAccountStatus(raw) {
18
+ return ACCOUNT_STATUSES.includes(raw) ? raw : 'couldNotDetermine';
19
+ }
20
+ function toChangeReason(raw) {
21
+ return CHANGE_REASONS.includes(raw) ? raw : 'unknown';
22
+ }
23
+ //# sourceMappingURL=enums.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ACCOUNT_STATUSES","CHANGE_REASONS","toAccountStatus","raw","includes","toChangeReason"],"sourceRoot":"../../../src","sources":["internal/enums.ts"],"mappings":";;;;;;;AAEA,MAAMA,gBAA0C,GAAG,CACjD,WAAW,EACX,WAAW,EACX,YAAY,EACZ,wBAAwB,EACxB,mBAAmB,CACpB;AAED,MAAMC,cAAuC,GAAG,CAC9C,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,SAAS,CACV;;AAED;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,eAAeA,CAACC,GAAW,EAAiB;EAC1D,OAAQH,gBAAgB,CAAuBI,QAAQ,CAACD,GAAG,CAAC,GACvDA,GAAG,GACJ,mBAAmB;AACzB;AAEO,SAASE,cAAcA,CAACF,GAAW,EAAgB;EACxD,OAAQF,cAAc,CAAuBG,QAAQ,CAACD,GAAG,CAAC,GACrDA,GAAG,GACJ,SAAS;AACf","ignoreList":[]}