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