react-native-cloud-sync 0.3.0 → 0.5.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/README.md +116 -58
- package/ios/CloudSyncError.swift +21 -0
- package/ios/CloudSyncImpl.swift +515 -95
- package/ios/RNCloudSync.mm +73 -1
- package/jest-mock.js +1 -0
- package/lib/commonjs/hooks.js +309 -3
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/commonjs/internal/autoFlush.js +10 -1
- package/lib/commonjs/internal/autoFlush.js.map +1 -1
- package/lib/commonjs/internal/base64.js +25 -5
- package/lib/commonjs/internal/base64.js.map +1 -1
- package/lib/commonjs/internal/cloudKitRest.js +91 -15
- package/lib/commonjs/internal/cloudKitRest.js.map +1 -1
- package/lib/commonjs/internal/googleDriveRest.js +304 -38
- package/lib/commonjs/internal/googleDriveRest.js.map +1 -1
- package/lib/commonjs/internal/keys.js +34 -17
- package/lib/commonjs/internal/keys.js.map +1 -1
- package/lib/commonjs/internal/records.js +48 -0
- package/lib/commonjs/internal/records.js.map +1 -0
- package/lib/commonjs/providers/cloudKit.js +85 -17
- package/lib/commonjs/providers/cloudKit.js.map +1 -1
- package/lib/commonjs/providers/cloudKitEncrypted.js +30 -7
- package/lib/commonjs/providers/cloudKitEncrypted.js.map +1 -1
- package/lib/commonjs/providers/googleDrive.js +37 -2
- package/lib/commonjs/providers/googleDrive.js.map +1 -1
- package/lib/commonjs/providers/icloudDocuments.js +27 -0
- package/lib/commonjs/providers/icloudDocuments.js.map +1 -1
- package/lib/commonjs/providers/icloudKV.js +13 -3
- package/lib/commonjs/providers/icloudKV.js.map +1 -1
- package/lib/commonjs/providers/icloudKV.web.js +8 -1
- package/lib/commonjs/providers/icloudKV.web.js.map +1 -1
- package/lib/commonjs/providers/memory.js +10 -0
- package/lib/commonjs/providers/memory.js.map +1 -1
- package/lib/commonjs/resolvers.js +27 -13
- package/lib/commonjs/resolvers.js.map +1 -1
- package/lib/commonjs/specs/NativeRNCloudSync.js +3 -0
- package/lib/commonjs/specs/NativeRNCloudSync.js.map +1 -1
- package/lib/commonjs/store.js +360 -173
- package/lib/commonjs/store.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/hooks.js +307 -3
- package/lib/module/hooks.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/internal/autoFlush.js +10 -1
- package/lib/module/internal/autoFlush.js.map +1 -1
- package/lib/module/internal/base64.js +25 -5
- package/lib/module/internal/base64.js.map +1 -1
- package/lib/module/internal/cloudKitRest.js +89 -13
- package/lib/module/internal/cloudKitRest.js.map +1 -1
- package/lib/module/internal/googleDriveRest.js +304 -38
- package/lib/module/internal/googleDriveRest.js.map +1 -1
- package/lib/module/internal/keys.js +33 -17
- package/lib/module/internal/keys.js.map +1 -1
- package/lib/module/internal/records.js +41 -0
- package/lib/module/internal/records.js.map +1 -0
- package/lib/module/providers/cloudKit.js +86 -18
- package/lib/module/providers/cloudKit.js.map +1 -1
- package/lib/module/providers/cloudKitEncrypted.js +31 -8
- package/lib/module/providers/cloudKitEncrypted.js.map +1 -1
- package/lib/module/providers/googleDrive.js +37 -2
- package/lib/module/providers/googleDrive.js.map +1 -1
- package/lib/module/providers/icloudDocuments.js +28 -1
- package/lib/module/providers/icloudDocuments.js.map +1 -1
- package/lib/module/providers/icloudKV.js +13 -3
- package/lib/module/providers/icloudKV.js.map +1 -1
- package/lib/module/providers/icloudKV.web.js +8 -1
- package/lib/module/providers/icloudKV.web.js.map +1 -1
- package/lib/module/providers/memory.js +10 -0
- package/lib/module/providers/memory.js.map +1 -1
- package/lib/module/resolvers.js +27 -12
- package/lib/module/resolvers.js.map +1 -1
- package/lib/module/specs/NativeRNCloudSync.js +4 -0
- package/lib/module/specs/NativeRNCloudSync.js.map +1 -1
- package/lib/module/store.js +360 -173
- package/lib/module/store.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/commonjs/errors.d.ts +16 -16
- package/lib/typescript/commonjs/errors.d.ts.map +1 -1
- package/lib/typescript/commonjs/hooks.d.ts +68 -0
- package/lib/typescript/commonjs/hooks.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +2 -2
- package/lib/typescript/commonjs/internal/autoFlush.d.ts.map +1 -1
- package/lib/typescript/commonjs/internal/base64.d.ts.map +1 -1
- package/lib/typescript/commonjs/internal/cloudKitRest.d.ts +20 -0
- package/lib/typescript/commonjs/internal/cloudKitRest.d.ts.map +1 -1
- package/lib/typescript/commonjs/internal/googleDriveRest.d.ts +19 -0
- package/lib/typescript/commonjs/internal/googleDriveRest.d.ts.map +1 -1
- package/lib/typescript/commonjs/internal/keys.d.ts +18 -3
- package/lib/typescript/commonjs/internal/keys.d.ts.map +1 -1
- package/lib/typescript/commonjs/internal/records.d.ts +24 -0
- package/lib/typescript/commonjs/internal/records.d.ts.map +1 -0
- package/lib/typescript/commonjs/providers/cloudKit.d.ts +1 -1
- package/lib/typescript/commonjs/providers/cloudKit.d.ts.map +1 -1
- package/lib/typescript/commonjs/providers/cloudKitBackup.d.ts +1 -1
- package/lib/typescript/commonjs/providers/cloudKitBackup.d.ts.map +1 -1
- package/lib/typescript/commonjs/providers/cloudKitEncrypted.d.ts.map +1 -1
- package/lib/typescript/commonjs/providers/googleDrive.d.ts.map +1 -1
- package/lib/typescript/commonjs/providers/googleDriveFiles.d.ts.map +1 -1
- package/lib/typescript/commonjs/providers/icloudDocuments.d.ts +1 -1
- package/lib/typescript/commonjs/providers/icloudDocuments.d.ts.map +1 -1
- package/lib/typescript/commonjs/providers/icloudKV.d.ts.map +1 -1
- package/lib/typescript/commonjs/providers/icloudKV.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/providers/memory.d.ts.map +1 -1
- package/lib/typescript/commonjs/resolvers.d.ts +6 -3
- package/lib/typescript/commonjs/resolvers.d.ts.map +1 -1
- package/lib/typescript/commonjs/specs/NativeRNCloudSync.d.ts +12 -3
- package/lib/typescript/commonjs/specs/NativeRNCloudSync.d.ts.map +1 -1
- package/lib/typescript/commonjs/store.d.ts.map +1 -1
- package/lib/typescript/commonjs/types.d.ts +31 -3
- package/lib/typescript/commonjs/types.d.ts.map +1 -1
- package/lib/typescript/module/errors.d.ts +16 -16
- package/lib/typescript/module/errors.d.ts.map +1 -1
- package/lib/typescript/module/hooks.d.ts +68 -0
- package/lib/typescript/module/hooks.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +2 -2
- package/lib/typescript/module/internal/autoFlush.d.ts.map +1 -1
- package/lib/typescript/module/internal/base64.d.ts.map +1 -1
- package/lib/typescript/module/internal/cloudKitRest.d.ts +20 -0
- package/lib/typescript/module/internal/cloudKitRest.d.ts.map +1 -1
- package/lib/typescript/module/internal/googleDriveRest.d.ts +19 -0
- package/lib/typescript/module/internal/googleDriveRest.d.ts.map +1 -1
- package/lib/typescript/module/internal/keys.d.ts +18 -3
- package/lib/typescript/module/internal/keys.d.ts.map +1 -1
- package/lib/typescript/module/internal/records.d.ts +24 -0
- package/lib/typescript/module/internal/records.d.ts.map +1 -0
- package/lib/typescript/module/providers/cloudKit.d.ts +1 -1
- package/lib/typescript/module/providers/cloudKit.d.ts.map +1 -1
- package/lib/typescript/module/providers/cloudKitBackup.d.ts +1 -1
- package/lib/typescript/module/providers/cloudKitBackup.d.ts.map +1 -1
- package/lib/typescript/module/providers/cloudKitEncrypted.d.ts.map +1 -1
- package/lib/typescript/module/providers/googleDrive.d.ts.map +1 -1
- package/lib/typescript/module/providers/googleDriveFiles.d.ts.map +1 -1
- package/lib/typescript/module/providers/icloudDocuments.d.ts +1 -1
- package/lib/typescript/module/providers/icloudDocuments.d.ts.map +1 -1
- package/lib/typescript/module/providers/icloudKV.d.ts.map +1 -1
- package/lib/typescript/module/providers/icloudKV.web.d.ts.map +1 -1
- package/lib/typescript/module/providers/memory.d.ts.map +1 -1
- package/lib/typescript/module/resolvers.d.ts +6 -3
- package/lib/typescript/module/resolvers.d.ts.map +1 -1
- package/lib/typescript/module/specs/NativeRNCloudSync.d.ts +12 -3
- package/lib/typescript/module/specs/NativeRNCloudSync.d.ts.map +1 -1
- package/lib/typescript/module/store.d.ts.map +1 -1
- package/lib/typescript/module/types.d.ts +31 -3
- package/lib/typescript/module/types.d.ts.map +1 -1
- package/package.json +36 -23
- package/plugin/build/index.js +45 -13
- package/react-native-cloud-sync.podspec +10 -3
- package/src/hooks.ts +357 -3
- package/src/index.ts +2 -2
- package/src/internal/autoFlush.ts +10 -1
- package/src/internal/base64.ts +26 -5
- package/src/internal/cloudKitRest.ts +103 -14
- package/src/internal/googleDriveRest.ts +338 -37
- package/src/internal/keys.ts +42 -16
- package/src/internal/records.ts +38 -0
- package/src/providers/cloudKit.ts +96 -20
- package/src/providers/cloudKitEncrypted.ts +37 -8
- package/src/providers/googleDrive.ts +38 -2
- package/src/providers/icloudDocuments.ts +40 -2
- package/src/providers/icloudKV.ts +13 -3
- package/src/providers/icloudKV.web.ts +8 -2
- package/src/providers/memory.ts +8 -0
- package/src/resolvers.ts +28 -13
- package/src/specs/NativeRNCloudSync.ts +16 -2
- package/src/store.ts +433 -190
- package/src/types.ts +32 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CloudSyncError, ErrorCode, timedOut } from '../errors'
|
|
2
2
|
import { byteLength } from './bytes'
|
|
3
|
+
import { clampRetryAfterMs } from './records'
|
|
3
4
|
import { withTimeout } from './timeout'
|
|
4
5
|
|
|
5
6
|
/** Default request timeout. Generous, because a large record on a slow link is normal. */
|
|
@@ -105,6 +106,17 @@ export interface CloudKitAssetDescriptor {
|
|
|
105
106
|
const MAX_BATCH = 200
|
|
106
107
|
|
|
107
108
|
export const RECORD_TYPE_DEFAULT = 'KVBlob'
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Record-name prefix for `cloudKitEncrypted`.
|
|
112
|
+
*
|
|
113
|
+
* CloudKit record names are unique per zone regardless of record type, so
|
|
114
|
+
* without it the encrypted and plain providers addressed the same record for
|
|
115
|
+
* the same key: a write to one collided with the other's schema, and a delete
|
|
116
|
+
* through one removed the other's data. The plain `cloudKit` provider rejects
|
|
117
|
+
* keys that start with it, so the two namespaces cannot overlap.
|
|
118
|
+
*/
|
|
119
|
+
export const ENCRYPTED_RECORD_PREFIX = 'rncs-enc.'
|
|
108
120
|
export const VALUE_FIELD = 'value'
|
|
109
121
|
|
|
110
122
|
/** CloudKit's documented per-record ceiling, excluding assets. */
|
|
@@ -112,6 +124,7 @@ export const MAX_RECORD_BYTES = 1024 * 1024
|
|
|
112
124
|
|
|
113
125
|
interface CloudKitRecordResult {
|
|
114
126
|
recordName?: string
|
|
127
|
+
recordType?: string
|
|
115
128
|
fields?: Record<string, { value?: unknown }>
|
|
116
129
|
serverErrorCode?: string
|
|
117
130
|
reason?: string
|
|
@@ -177,7 +190,8 @@ export class CloudKitRestClient {
|
|
|
177
190
|
|
|
178
191
|
private baseUrl(): string {
|
|
179
192
|
const { containerIdentifier, environment } = this.config
|
|
180
|
-
return `https://api.apple-cloudkit.com/database/1/${containerIdentifier}
|
|
193
|
+
return `https://api.apple-cloudkit.com/database/1/${encodeURIComponent(containerIdentifier)}/`
|
|
194
|
+
+ `${encodeURIComponent(environment)}/private`
|
|
181
195
|
}
|
|
182
196
|
|
|
183
197
|
private get fetch(): typeof fetch {
|
|
@@ -229,15 +243,18 @@ export class CloudKitRestClient {
|
|
|
229
243
|
await this.handleAuthExpired()
|
|
230
244
|
return new CloudSyncError(ErrorCode.AUTH_EXPIRED, message, base)
|
|
231
245
|
case 'ACCESS_DENIED':
|
|
232
|
-
|
|
233
|
-
|
|
246
|
+
// A permission failure, not a dead token: CloudKit sends it when the
|
|
247
|
+
// authenticated user lacks rights to the record type, zone or database
|
|
248
|
+
// (security roles set up wrong in the CloudKit Console). Treating it as
|
|
249
|
+
// expired auth signed the user out, and re-signing in changes nothing.
|
|
250
|
+
return new CloudSyncError(ErrorCode.CONTAINER_MISCONFIGURED, message, base)
|
|
234
251
|
case 'QUOTA_EXCEEDED':
|
|
235
252
|
return new CloudSyncError(ErrorCode.QUOTA_EXCEEDED, message, base)
|
|
236
253
|
case 'THROTTLED':
|
|
237
254
|
case 'TRY_AGAIN_LATER':
|
|
238
255
|
return new CloudSyncError(ErrorCode.RATE_LIMITED, message, {
|
|
239
256
|
...base,
|
|
240
|
-
retryAfterMs: retryAfter
|
|
257
|
+
retryAfterMs: typeof retryAfter === 'number' ? clampRetryAfterMs(retryAfter * 1000) : undefined,
|
|
241
258
|
})
|
|
242
259
|
case 'CONFLICT':
|
|
243
260
|
return new CloudSyncError(ErrorCode.CONFLICT, message, { ...base, serverValue })
|
|
@@ -338,12 +355,11 @@ export class CloudKitRestClient {
|
|
|
338
355
|
recordName: string,
|
|
339
356
|
recordType = RECORD_TYPE_DEFAULT
|
|
340
357
|
): Promise<{ value: string; modifiedAt?: number; recordChangeTag?: string } | null> {
|
|
341
|
-
void recordType
|
|
342
358
|
const json = await this.post('/records/lookup', {
|
|
343
359
|
records: [{ recordName }],
|
|
344
360
|
})
|
|
345
361
|
|
|
346
|
-
const record = json
|
|
362
|
+
const record = lookupResult(json, recordName)
|
|
347
363
|
if (record == null) return null
|
|
348
364
|
|
|
349
365
|
if (record.serverErrorCode != null) {
|
|
@@ -354,6 +370,7 @@ export class CloudKitRestClient {
|
|
|
354
370
|
if (record.serverErrorCode === 'NOT_FOUND') return null
|
|
355
371
|
throw await this.toError(record.serverErrorCode, record.reason, record.retryAfter)
|
|
356
372
|
}
|
|
373
|
+
assertRecordType(record, recordType)
|
|
357
374
|
|
|
358
375
|
const value = record.fields?.[VALUE_FIELD]?.value
|
|
359
376
|
if (typeof value !== 'string') return null
|
|
@@ -380,10 +397,21 @@ export class CloudKitRestClient {
|
|
|
380
397
|
recordNames: string[],
|
|
381
398
|
recordType = RECORD_TYPE_DEFAULT
|
|
382
399
|
): Promise<(string | null)[]> {
|
|
383
|
-
|
|
400
|
+
return (await this.getRecordsWithMeta(recordNames, recordType)).map(r => r?.value ?? null)
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* {@link getRecords} plus each record's server modification time and change
|
|
405
|
+
* tag - the batch form of {@link getRecordWithMeta}. Free for the same
|
|
406
|
+
* reason: `/records/lookup` returns both whether or not anyone asks.
|
|
407
|
+
*/
|
|
408
|
+
async getRecordsWithMeta(
|
|
409
|
+
recordNames: string[],
|
|
410
|
+
recordType = RECORD_TYPE_DEFAULT
|
|
411
|
+
): Promise<({ value: string; modifiedAt?: number; recordChangeTag?: string } | null)[]> {
|
|
384
412
|
if (recordNames.length === 0) return []
|
|
385
413
|
|
|
386
|
-
const found = new Map<string, string>()
|
|
414
|
+
const found = new Map<string, { value: string; modifiedAt?: number; recordChangeTag?: string }>()
|
|
387
415
|
|
|
388
416
|
for (const batch of chunk(recordNames, MAX_BATCH)) {
|
|
389
417
|
const json = await this.post('/records/lookup', {
|
|
@@ -398,8 +426,16 @@ export class CloudKitRestClient {
|
|
|
398
426
|
if (record.serverErrorCode === 'NOT_FOUND') continue
|
|
399
427
|
throw await this.toError(record.serverErrorCode, record.reason, record.retryAfter)
|
|
400
428
|
}
|
|
429
|
+
assertRecordType(record, recordType)
|
|
401
430
|
const value = record.fields?.[VALUE_FIELD]?.value
|
|
402
|
-
if (typeof value === 'string')
|
|
431
|
+
if (typeof value === 'string')
|
|
432
|
+
found.set(record.recordName, {
|
|
433
|
+
value,
|
|
434
|
+
modifiedAt: typeof record.modified?.timestamp === 'number'
|
|
435
|
+
? record.modified.timestamp
|
|
436
|
+
: undefined,
|
|
437
|
+
recordChangeTag: record.recordChangeTag,
|
|
438
|
+
})
|
|
403
439
|
}
|
|
404
440
|
}
|
|
405
441
|
|
|
@@ -603,20 +639,26 @@ export class CloudKitRestClient {
|
|
|
603
639
|
onProgress?: (bytesTransferred: number, bytesTotal: number) => void,
|
|
604
640
|
recordType = RECORD_TYPE_DEFAULT
|
|
605
641
|
): Promise<Uint8Array | null> {
|
|
606
|
-
void recordType
|
|
607
642
|
const json = await this.post('/records/lookup', { records: [{ recordName }] })
|
|
608
|
-
const record = json
|
|
643
|
+
const record = lookupResult(json, recordName)
|
|
609
644
|
if (record == null) return null
|
|
610
645
|
|
|
611
646
|
if (record.serverErrorCode != null) {
|
|
612
647
|
if (record.serverErrorCode === 'NOT_FOUND') return null
|
|
613
648
|
throw await this.toError(record.serverErrorCode, record.reason, record.retryAfter)
|
|
614
649
|
}
|
|
650
|
+
assertRecordType(record, recordType)
|
|
615
651
|
|
|
616
652
|
const asset = record.fields?.[fieldName]?.value as CloudKitAssetDescriptor | undefined
|
|
617
653
|
if (asset?.downloadURL == null) return null
|
|
618
654
|
|
|
619
|
-
|
|
655
|
+
// CloudKit Web Services hands back the download URL as a template with a
|
|
656
|
+
// literal `${f}` where the file name goes; the client is expected to fill
|
|
657
|
+
// it in. Requesting the template verbatim asks for a path that does not
|
|
658
|
+
// exist.
|
|
659
|
+
if (typeof asset.downloadURL !== 'string') return null
|
|
660
|
+
const downloadUrl = asset.downloadURL.replace('${f}', encodeURIComponent(fieldName))
|
|
661
|
+
return await this.fetchAssetBytes(assertHttpsUrl(downloadUrl, 'download'), onProgress)
|
|
620
662
|
}
|
|
621
663
|
|
|
622
664
|
private async requestAssetUploadUrl(
|
|
@@ -627,14 +669,14 @@ export class CloudKitRestClient {
|
|
|
627
669
|
})
|
|
628
670
|
|
|
629
671
|
const url = json.tokens?.[0]?.url
|
|
630
|
-
if (url
|
|
672
|
+
if (typeof url !== 'string')
|
|
631
673
|
throw new CloudSyncError(
|
|
632
674
|
ErrorCode.UNKNOWN,
|
|
633
675
|
'[RNCloudSync] CloudKit did not return an asset upload URL.',
|
|
634
676
|
{ provider: 'cloudKit' }
|
|
635
677
|
)
|
|
636
678
|
|
|
637
|
-
return url
|
|
679
|
+
return assertHttpsUrl(url, 'upload')
|
|
638
680
|
}
|
|
639
681
|
|
|
640
682
|
private get xhr(): () => XMLHttpRequest {
|
|
@@ -826,6 +868,9 @@ export class CloudKitRestClient {
|
|
|
826
868
|
do {
|
|
827
869
|
const json: CloudKitResponse = await this.post('/records/query', {
|
|
828
870
|
query: { recordType },
|
|
871
|
+
// Names only. Without this every page carries every record's full
|
|
872
|
+
// value - up to 200 records of up to 1 MB each - just to read names.
|
|
873
|
+
desiredKeys: [],
|
|
829
874
|
...(continuationMarker != null ? { continuationMarker } : {}),
|
|
830
875
|
})
|
|
831
876
|
|
|
@@ -883,6 +928,50 @@ export class CloudKitRestClient {
|
|
|
883
928
|
}
|
|
884
929
|
}
|
|
885
930
|
|
|
931
|
+
/**
|
|
932
|
+
* The lookup result for `recordName`.
|
|
933
|
+
*
|
|
934
|
+
* A result naming a *different* record is never taken as this one's: serving
|
|
935
|
+
* it would hand key B's value back as key A's. Only an entry with no
|
|
936
|
+
* `recordName` at all - the shape of a per-record error - may stand in for the
|
|
937
|
+
* requested one.
|
|
938
|
+
*/
|
|
939
|
+
function lookupResult(json: CloudKitResponse, recordName: string): CloudKitRecordResult | undefined {
|
|
940
|
+
const records = json.records ?? []
|
|
941
|
+
return records.find(r => r.recordName === recordName)
|
|
942
|
+
?? records.find(r => r.recordName == null)
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* Record names are unique across record types, so a lookup by name can return
|
|
947
|
+
* a record of another type - one another provider (or another app sharing the
|
|
948
|
+
* container) wrote. Reading it as this type would serve foreign data under
|
|
949
|
+
* this key, so a mismatch is an error, as it is on the native path.
|
|
950
|
+
*/
|
|
951
|
+
function assertRecordType(record: CloudKitRecordResult, recordType: string): void {
|
|
952
|
+
if (record.recordType != null && record.recordType !== recordType)
|
|
953
|
+
throw new CloudSyncError(
|
|
954
|
+
ErrorCode.INVALID_KEY,
|
|
955
|
+
`[RNCloudSync] Record "${record.recordName ?? ''}" is a ${record.recordType}, not a ${recordType}.`,
|
|
956
|
+
{ provider: 'cloudKit' }
|
|
957
|
+
)
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* Asset bytes travel to and from URLs the server hands out, not ones this
|
|
962
|
+
* client builds. Plain HTTP would put the user's file on the wire unencrypted
|
|
963
|
+
* (and let anything on-path substitute the download), so only HTTPS is used.
|
|
964
|
+
*/
|
|
965
|
+
function assertHttpsUrl(url: string, kind: 'upload' | 'download'): string {
|
|
966
|
+
if (!/^https:\/\/[^/?#]+/i.test(url))
|
|
967
|
+
throw new CloudSyncError(
|
|
968
|
+
ErrorCode.UNKNOWN,
|
|
969
|
+
`[RNCloudSync] CloudKit returned a non-HTTPS asset ${kind} URL; refusing to use it.`,
|
|
970
|
+
{ provider: 'cloudKit', serverErrorCode: 'UNTRUSTED_URL' }
|
|
971
|
+
)
|
|
972
|
+
return url
|
|
973
|
+
}
|
|
974
|
+
|
|
886
975
|
/** Splits `items` into runs of at most `size`. */
|
|
887
976
|
function chunk<T>(items: T[], size: number): T[][] {
|
|
888
977
|
if (items.length <= size) return [items]
|