diff --git a/package-lock.json b/package-lock.json index deb465e..1ac6a1a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,10 @@ "": { "name": "@anam-ai/js-sdk", "version": "0.0.0-automated", - "license": "ISC", + "license": "MIT", + "dependencies": { + "buffer": "^6.0.3" + }, "devDependencies": { "@commitlint/cli": "^19.3.0", "@commitlint/config-conventional": "^19.2.2", @@ -1399,6 +1402,25 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, "node_modules/binary-extensions": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", @@ -1465,6 +1487,29 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -3128,6 +3173,25 @@ "url": "https://github.com/sponsors/typicode" } }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, "node_modules/ignore": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", diff --git a/package.json b/package.json index 5048b24..9a1e2b0 100644 --- a/package.json +++ b/package.json @@ -62,5 +62,8 @@ "typescript-eslint": "^7.9.0", "webpack": "^5.91.0", "webpack-cli": "^5.1.4" + }, + "dependencies": { + "buffer": "^6.0.3" } } diff --git a/src/AnamClient.ts b/src/AnamClient.ts index 59d2c97..e9b7607 100644 --- a/src/AnamClient.ts +++ b/src/AnamClient.ts @@ -16,7 +16,7 @@ import { StartSessionResponse, } from './types'; import { TalkMessageStream } from './types/TalkMessageStream'; - +import { Buffer } from 'buffer'; export default class AnamClient { private publicEventEmitter: PublicEventEmitter; private internalEventEmitter: InternalEventEmitter; @@ -68,7 +68,10 @@ export default class AnamClient { private decodeJwt(token: string): any { try { const base64Payload = token.split('.')[1]; - const payload = JSON.parse(atob(base64Payload)); + const payloadString = Buffer.from(base64Payload, 'base64').toString( + 'utf8', + ); + const payload = JSON.parse(payloadString); return payload; } catch (error) { throw new Error('Invalid session token format'); diff --git a/src/index.ts b/src/index.ts index 2267578..3fee0fa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,4 +36,5 @@ const unsafe_createClientWithApiKey = ( }; export { createClient, unsafe_createClientWithApiKey }; -export type { AnamClient, PersonaConfig, AnamPublicClientOptions }; +export type { AnamClient }; +export * from './types'; diff --git a/webpack.config.js b/webpack.config.js index 3ba28f0..4fdb6d9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -24,5 +24,13 @@ module.exports = { }, resolve: { extensions: ['.ts', '.js', '.json'], + fallback: { + buffer: require.resolve('buffer/'), + }, }, + plugins: [ + new webpack.ProvidePlugin({ + Buffer: ['buffer', 'Buffer'], + }), + ], };