diff --git a/src/index.ts b/src/index.ts index b434078..20aeb5b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -514,9 +514,18 @@ export class Toggle extends Hookified { public getOrgIdFromPublicKey(publicKey: string): string | undefined { try { const keyWithoutPrefix = publicKey.replace(/^public_/, ""); + // Browsers / modern runtimes expose `atob`; fall back to Node's + // `Buffer` without depending on @types/node globally. + const nodeBuffer = ( + globalThis as typeof globalThis & { + Buffer?: { + from(input: string, encoding: string): { toString(): string }; + }; + } + ).Buffer; const decoded = globalThis.atob ? globalThis.atob(keyWithoutPrefix) - : Buffer.from(keyWithoutPrefix, "base64").toString(); + : (nodeBuffer?.from(keyWithoutPrefix, "base64").toString() ?? ""); const [orgId] = decoded.split(":"); const isValidOrgId = /^[a-zA-Z0-9_-]+$/.test(orgId); return isValidOrgId ? orgId : undefined; diff --git a/tsconfig.json b/tsconfig.json index d41b22d..db23a66 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,6 @@ "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "skipLibCheck": true, - "types": ["node"], "outDir": "./dist", "rootDir": "./src", "resolveJsonModule": true,