From 8600f27a5a3fd3bbacd1e989f75e18eafd3da43c Mon Sep 17 00:00:00 2001 From: Jared Wray Date: Thu, 9 Apr 2026 15:12:17 -0700 Subject: [PATCH] fix: handling buffer with node or browser --- src/index.ts | 11 ++++++++++- tsconfig.json | 1 - 2 files changed, 10 insertions(+), 2 deletions(-) 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,