diff --git a/sdk/cosmosdb/cosmos/CHANGELOG.md b/sdk/cosmosdb/cosmos/CHANGELOG.md index 4b790b1934dd..07fdc52fe5e9 100644 --- a/sdk/cosmosdb/cosmos/CHANGELOG.md +++ b/sdk/cosmosdb/cosmos/CHANGELOG.md @@ -1,8 +1,9 @@ # Release History -## 3.6.4 (Unreleased) +## 3.7.0 (Unreleased) -- FEATURE: Allows string value `partitionKey` parameter when creating containers. +- FEATURE: Allows string value `partitionKey` parameter when creating containers +- BUGFIX: Support crypto functions in Internet Explorer browser The following result in the same behavior: @@ -67,7 +68,7 @@ Based on customer feedback, we identified scenarios where it still makes sense t ## 3.5.3 (2020-1-06) - BUG FIX: maxDegreeOfParallelism was defaulting to 1 and should default to the number of partitions of the collection -- BUF FIX: maxItemCount was defaulting to 10 and should default to undefined +- BUG FIX: maxItemCount was defaulting to 10 and should default to undefined - Set default TLS version to 1.2 (#6761) - Use tslib 1.10.0 (#6710) - Add partition key to code sample (#6612) diff --git a/sdk/cosmosdb/cosmos/package.json b/sdk/cosmosdb/cosmos/package.json index 19eadc77a62a..45d396b2fcb9 100644 --- a/sdk/cosmosdb/cosmos/package.json +++ b/sdk/cosmosdb/cosmos/package.json @@ -1,6 +1,6 @@ { "name": "@azure/cosmos", - "version": "3.6.4", + "version": "3.7.0", "description": "Microsoft Azure Cosmos DB Service Node.js SDK for SQL API", "sdk-type": "client", "keywords": [ diff --git a/sdk/cosmosdb/cosmos/src/utils/digest.browser.ts b/sdk/cosmosdb/cosmos/src/utils/digest.browser.ts index 0ab348a270bf..e079e1bd49b5 100644 --- a/sdk/cosmosdb/cosmos/src/utils/digest.browser.ts +++ b/sdk/cosmosdb/cosmos/src/utils/digest.browser.ts @@ -1,14 +1,9 @@ import { encodeUTF8 } from "./encode"; - -const globalThis = typeof self === "undefined" ? window : self; +import { globalCrypto } from "./globalCrypto"; export async function digest(str: string) { - if (!globalThis || !globalThis.crypto || !globalThis.crypto.subtle) { - throw new Error("Browser does not support cryptography functions"); - } - const data = encodeUTF8(str); - const hash = await globalThis.crypto.subtle.digest("SHA-256", data); + const hash = await globalCrypto.subtle.digest("SHA-256", data); return bufferToHex(hash); } diff --git a/sdk/cosmosdb/cosmos/src/utils/globalCrypto.ts b/sdk/cosmosdb/cosmos/src/utils/globalCrypto.ts new file mode 100644 index 000000000000..71a0e478ce76 --- /dev/null +++ b/sdk/cosmosdb/cosmos/src/utils/globalCrypto.ts @@ -0,0 +1,13 @@ +const globalRef: any = typeof self === "undefined" ? window : self; + +if (!globalThis) { + throw new Error("Could not find global"); +} + +const globalCrypto: Crypto = globalRef.crypto || globalRef.msCrypto; + +if (!globalCrypto || !globalCrypto.subtle) { + throw new Error("Browser does not support cryptography functions"); +} + +export { globalCrypto }; diff --git a/sdk/cosmosdb/cosmos/src/utils/hmac.browser.ts b/sdk/cosmosdb/cosmos/src/utils/hmac.browser.ts index 804eadadaaeb..d7ec726837da 100644 --- a/sdk/cosmosdb/cosmos/src/utils/hmac.browser.ts +++ b/sdk/cosmosdb/cosmos/src/utils/hmac.browser.ts @@ -1,25 +1,17 @@ import { encodeUTF8, encodeBase64 } from "./encode"; import atob from "./atob"; - -const globalThis = typeof self === "undefined" ? window : self; +import { globalCrypto } from "./globalCrypto"; export async function hmac(key: string, message: string) { - if (!globalThis || !globalThis.crypto || !globalThis.crypto.subtle) { - throw new Error("Browser does not support cryptography functions"); - } const importParams: HmacImportParams = { name: "HMAC", hash: { name: "SHA-256" } }; const encodedMessage = new Uint8Array( [...unescape(encodeURIComponent(message))].map((c) => c.charCodeAt(0)) ); const encodedKey = encodeUTF8(atob(key)); - const cryptoKey = await globalThis.crypto.subtle.importKey( - "raw", - encodedKey, - importParams, - false, - ["sign"] - ); - const signature = await globalThis.crypto.subtle.sign(importParams, cryptoKey, encodedMessage); + const cryptoKey = await globalCrypto.subtle.importKey("raw", encodedKey, importParams, false, [ + "sign" + ]); + const signature = await globalCrypto.subtle.sign(importParams, cryptoKey, encodedMessage); return encodeBase64(signature); }