typescriptlibs / tsl-apple-cloudkit

TypeScript Library for Apple CloudKit JS
https://typescriptlibs.org/tsl-apple-cloudkit/
MIT License
23 stars 4 forks source link

CloudKit.configure => Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'ArrayBuffer') #18

Closed cegrnd closed 2 years ago

cegrnd commented 2 years ago

Hi,

I am getting the following error in the vsCode console when trying to create a CloudKit instance (see below). Any suggestions? Thanks

Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'ArrayBuffer') at (..../node_modules/tsl-apple-cloudkit/index.js:13:5004) at (..../node_modules/tsl-apple-cloudkit/index.js:13:5045) at t2 (..../node_modules/tsl-apple-cloudkit/index.js:12:417) at (..../node_modules/tsl-apple-cloudkit/index.js:13:4512) at t2 (..../node_modules/tsl-apple-cloudkit/index.js:12:417) at (..../node_modules/tsl-apple-cloudkit/index.js:13:945) at t2 (..../node_modules/tsl-apple-cloudkit/index.js:12:417) ...


import * as CloudKit from 'tsl-apple-cloudkit';

const ckContainerConfig: CloudKit.ContainerConfigLike = { containerIdentifier: 'xxxxx', apiTokenAuth: { apiToken: 'xxxxx', persist: false, signInButton: { id: 'apple-sign-in-button', theme: 'black' }, signOutButton: { id: 'apple-sign-out-button', theme: 'black' } }, environment: 'development' } const ckConfig: CloudKit.CloudKitConfig = { containers: [ ckContainerConfig ] }; const ck = CloudKit.configure(ckConfig);

cegrnd commented 2 years ago

doesn't error out when specifying services:

const ckConfig: CloudKit.CloudKitConfig = { services: { fetch: fetch }, containers: [ ckContainerConfig ] };

sophiebremer commented 2 years ago

Hello @cegrnd! Thank you for the report and the solution. So I assume that window.fetch was not present in the setup.

cegrnd commented 2 years ago

Exactly right. I am new to js/ts so it didn't quite make sense initially but adding fetch to services in the cloudkit config was enough to confirm there was nothing wrong with tsl-apple-cloudkit. Thanks for putting that type library together BTW, looks great. Not sure why Apple couldn't release something like that (their recent cktool js does support typescript).

Sharing some sample code with a basic setup in case it helps others exploring PWA as an alternative to native apps:

------ global.d.ts file in src/types

import * as CloudKit from 'tsl-apple-cloudkit';

export { };

declare global { interface Window { ck: CloudKit.CloudKit; } }

----- index.html

inside body:

----- app-index.ts

import "./types/global.d.ts";

const ckDefaultContainer = window.ck.getDefaultContainer() const db = ckDefaultContainer.privateCloudDatabase console.log(db.containerIdentifier)

sophiebremer commented 2 years ago

Thanks! Maybe Apple will provide TypeScript declarations with version 3 of CloudKit JS. It would be good to have something official.