I’m attempting to utilize the JavaScript SDK, namely version 114 of the NPM package purecloud-platform-client-v2, in the context of a Create-React-App TypeScript application.
I’m importing like so…
import platformClient from "purecloud-platform-client-v2";
then getting the client like so…
const client = platformClient.ApiClient.instance;
which compiles OK, but throws an error at runtime…
Cannot read property 'instance' of undefined
I’m wondering if it has something to do with the library’s typings (index.d.ts) which causes CRA to generate incorrect javascript.
I notice at the top of the typings file…
import platformClient = require('purecloud-platform-client-v2');
import Configuration from './src/purecloud-platform-client-v2/configuration';
that platformClient is imported but not exported. ApiClient is exported but it’s a class and not an object instance.
I’ve tried some other ways of importing, to no avail.
My typescript compiler options are like so:
"compilerOptions": {
"outDir": "./dist",
"target": "ES2020",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"skipLibCheck": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"noImplicitAny": true, // changed to false to work around issue (see below)
"removeComments": true,
"declaration": true,
"jsx": "react-jsx",
"noFallthroughCasesInSwitch": true,
"emitBOM": false
}
And I'm using typescript 4.3.2.
PS: Some other issues (minor):
• Configuration is imported in the typings but itself has no typings, which fails if noImplicitAny=true
• PureCloudRegionHosts isn’t included in the typings