diff --git a/sdk/cosmosdb/cosmos/package.json b/sdk/cosmosdb/cosmos/package.json index 4ba12a282fc6..744e970c94f2 100644 --- a/sdk/cosmosdb/cosmos/package.json +++ b/sdk/cosmosdb/cosmos/package.json @@ -18,7 +18,8 @@ "main": "./dist/index.js", "module": "./dist-esm/index.js", "browser": { - "./dist-esm/request/defaultAgent.js": "./dist-esm/request/defaultAgent.browser.js" + "./dist-esm/request/defaultAgent.js": "./dist-esm/request/defaultAgent.browser.js", + "./dist-esm/utils/atob.js": "./dist-esm/utils/atob.browser.js" }, "files": [ "changelog.md", @@ -72,7 +73,6 @@ "dependencies": { "@azure/cosmos-sign": "^1.0.2", "@types/debug": "^4.1.4", - "atob": "^2.1.2", "binary-search-bounds": "^2.0.3", "crypto-hash": "^1.1.0", "debug": "^4.1.1", diff --git a/sdk/cosmosdb/cosmos/src/session/sessionContainer.ts b/sdk/cosmosdb/cosmos/src/session/sessionContainer.ts index efaf8dfef2de..3a89af16585e 100644 --- a/sdk/cosmosdb/cosmos/src/session/sessionContainer.ts +++ b/sdk/cosmosdb/cosmos/src/session/sessionContainer.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import atob from "atob"; +import atob from "../utils/atob"; import { Constants, getContainerLink, OperationType, ResourceType, trimSlashes } from "../common"; import { CosmosHeaders } from "../queryExecutionContext"; import { SessionContext } from "./SessionContext"; diff --git a/sdk/cosmosdb/cosmos/src/typings/atob.d.ts b/sdk/cosmosdb/cosmos/src/typings/atob.d.ts deleted file mode 100644 index f8e5a8d16505..000000000000 --- a/sdk/cosmosdb/cosmos/src/typings/atob.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. -declare module "atob" { - const _atob: typeof atob; - export = _atob; -} diff --git a/sdk/cosmosdb/cosmos/src/utils/atob.browser.ts b/sdk/cosmosdb/cosmos/src/utils/atob.browser.ts new file mode 100644 index 000000000000..af346b5f4736 --- /dev/null +++ b/sdk/cosmosdb/cosmos/src/utils/atob.browser.ts @@ -0,0 +1,5 @@ +if ("function" === typeof atob) { + throw new Error("Your browser environment is missing the global `atob` function"); +} + +export default atob; diff --git a/sdk/cosmosdb/cosmos/src/utils/atob.ts b/sdk/cosmosdb/cosmos/src/utils/atob.ts new file mode 100644 index 000000000000..befa418b5c23 --- /dev/null +++ b/sdk/cosmosdb/cosmos/src/utils/atob.ts @@ -0,0 +1,3 @@ +export default function atob(str: string) { + return Buffer.from(str, "base64").toString("binary"); +}