From 826af74a648a7a4c26b4cbc997bb02ca8d192577 Mon Sep 17 00:00:00 2001 From: Zach foster Date: Sat, 5 Dec 2020 16:45:35 -0500 Subject: [PATCH 01/23] Adds AAD client option --- sdk/cosmosdb/cosmos/package.json | 1 + sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts | 2 ++ sdk/cosmosdb/cosmos/src/auth.ts | 4 ++++ sdk/cosmosdb/cosmos/src/request/RequestHandler.ts | 1 + sdk/cosmosdb/cosmos/test/functional/client.spec.ts | 11 +++++++++++ 5 files changed, 19 insertions(+) diff --git a/sdk/cosmosdb/cosmos/package.json b/sdk/cosmosdb/cosmos/package.json index c70dbca387ef..bc96378d4005 100644 --- a/sdk/cosmosdb/cosmos/package.json +++ b/sdk/cosmosdb/cosmos/package.json @@ -83,6 +83,7 @@ "tsdocFlavor": "AEDoc" }, "dependencies": { + "@azure/identity": "^1.1.0", "@types/debug": "^4.1.4", "debug": "^4.1.1", "fast-json-stable-stringify": "^2.0.0", diff --git a/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts b/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts index 247c7ae4ac62..971da2739c14 100644 --- a/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts +++ b/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts @@ -28,6 +28,8 @@ export interface CosmosClientOptions { * Allows users to generating their own auth tokens, potentially using a separate service */ tokenProvider?: TokenProvider; + /** AAD token from @azure/identity */ + aadToken?: string; /** An array of {@link Permission} objects. */ permissionFeed?: PermissionDefinition[]; /** An instance of {@link ConnectionPolicy} class. diff --git a/sdk/cosmosdb/cosmos/src/auth.ts b/sdk/cosmosdb/cosmos/src/auth.ts index 8f6cf1ffa710..c5f95d5a8c92 100644 --- a/sdk/cosmosdb/cosmos/src/auth.ts +++ b/sdk/cosmosdb/cosmos/src/auth.ts @@ -68,6 +68,10 @@ export async function setAuthorizationHeader( headers[Constants.HttpHeaders.Authorization] = encodeURIComponent( await clientOptions.tokenProvider({ verb, path, resourceId, resourceType, headers }) ); + } else if (clientOptions.aadToken) { + const AUTH_PREFIX = `type=aad&ver=1.0&sig=`; + const authorizationToken = `${AUTH_PREFIX}${clientOptions.aadToken}`; + headers[Constants.HttpHeaders.Authorization] = encodeURIComponent(authorizationToken); } } diff --git a/sdk/cosmosdb/cosmos/src/request/RequestHandler.ts b/sdk/cosmosdb/cosmos/src/request/RequestHandler.ts index 608496921b94..e1495227ce9e 100644 --- a/sdk/cosmosdb/cosmos/src/request/RequestHandler.ts +++ b/sdk/cosmosdb/cosmos/src/request/RequestHandler.ts @@ -52,6 +52,7 @@ async function httpRequest(requestContext: RequestContext) { } try { + console.log(requestContext); response = await fetch(trimSlashes(requestContext.endpoint) + requestContext.path, { method: requestContext.method, headers: requestContext.headers as any, diff --git a/sdk/cosmosdb/cosmos/test/functional/client.spec.ts b/sdk/cosmosdb/cosmos/test/functional/client.spec.ts index e5d805297299..1640035b1872 100644 --- a/sdk/cosmosdb/cosmos/test/functional/client.spec.ts +++ b/sdk/cosmosdb/cosmos/test/functional/client.spec.ts @@ -52,6 +52,17 @@ describe("NodeJS CRUD Tests", function() { it("throws on a bad endpoint", function() { assert.throws(() => new CosmosClient({ endpoint: "asda=asda;asada;" })); }); + it.only("fails to read databases with AAD authentication", async function() { + try { + const client = new CosmosClient({ + endpoint, + aadToken: "faketoken" + }); + await client.databases.readAll().fetchAll(); + } catch (e) { + assert.equal(e.code, 401); + } + }); }); describe("Validate user passed AbortController.signal", function() { it("should throw exception if aborted during the request", async function() { From 008695ab305e440e20d37f7022988fc8556414ad Mon Sep 17 00:00:00 2001 From: Zach foster Date: Mon, 7 Dec 2020 13:59:40 -0500 Subject: [PATCH 02/23] Fixes --- sdk/cosmosdb/cosmos/package.json | 1 - sdk/cosmosdb/cosmos/src/request/RequestHandler.ts | 1 - sdk/cosmosdb/cosmos/test/functional/client.spec.ts | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/sdk/cosmosdb/cosmos/package.json b/sdk/cosmosdb/cosmos/package.json index bc96378d4005..c70dbca387ef 100644 --- a/sdk/cosmosdb/cosmos/package.json +++ b/sdk/cosmosdb/cosmos/package.json @@ -83,7 +83,6 @@ "tsdocFlavor": "AEDoc" }, "dependencies": { - "@azure/identity": "^1.1.0", "@types/debug": "^4.1.4", "debug": "^4.1.1", "fast-json-stable-stringify": "^2.0.0", diff --git a/sdk/cosmosdb/cosmos/src/request/RequestHandler.ts b/sdk/cosmosdb/cosmos/src/request/RequestHandler.ts index e1495227ce9e..608496921b94 100644 --- a/sdk/cosmosdb/cosmos/src/request/RequestHandler.ts +++ b/sdk/cosmosdb/cosmos/src/request/RequestHandler.ts @@ -52,7 +52,6 @@ async function httpRequest(requestContext: RequestContext) { } try { - console.log(requestContext); response = await fetch(trimSlashes(requestContext.endpoint) + requestContext.path, { method: requestContext.method, headers: requestContext.headers as any, diff --git a/sdk/cosmosdb/cosmos/test/functional/client.spec.ts b/sdk/cosmosdb/cosmos/test/functional/client.spec.ts index 1640035b1872..dbd31ed0ebaf 100644 --- a/sdk/cosmosdb/cosmos/test/functional/client.spec.ts +++ b/sdk/cosmosdb/cosmos/test/functional/client.spec.ts @@ -52,7 +52,7 @@ describe("NodeJS CRUD Tests", function() { it("throws on a bad endpoint", function() { assert.throws(() => new CosmosClient({ endpoint: "asda=asda;asada;" })); }); - it.only("fails to read databases with AAD authentication", async function() { + it("fails to read databases with AAD authentication", async function() { try { const client = new CosmosClient({ endpoint, From d2df868afe642e00231ccb6ccc3f671c68f5a07d Mon Sep 17 00:00:00 2001 From: zfoster Date: Thu, 17 Dec 2020 16:16:30 -0500 Subject: [PATCH 03/23] aad --- sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts | 11 +++++++++-- sdk/cosmosdb/cosmos/src/auth.ts | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts b/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts index 971da2739c14..944d8fce73fd 100644 --- a/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts +++ b/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts @@ -28,8 +28,15 @@ export interface CosmosClientOptions { * Allows users to generating their own auth tokens, potentially using a separate service */ tokenProvider?: TokenProvider; - /** AAD token from @azure/identity */ - aadToken?: string; + /** AAD token from @azure/identity + * Obtain a credential object by creating an @azure/identity credential object + * We will then use your credential object and a scope URL (your cosmos db endpoint) + * e.g., https://zfoster-rbactest-1.documents.azure.com/.default + */ + aadCredentials?: { + credentials: any, + scope: string + }; /** An array of {@link Permission} objects. */ permissionFeed?: PermissionDefinition[]; /** An instance of {@link ConnectionPolicy} class. diff --git a/sdk/cosmosdb/cosmos/src/auth.ts b/sdk/cosmosdb/cosmos/src/auth.ts index c5f95d5a8c92..c7424db03cd3 100644 --- a/sdk/cosmosdb/cosmos/src/auth.ts +++ b/sdk/cosmosdb/cosmos/src/auth.ts @@ -68,9 +68,9 @@ export async function setAuthorizationHeader( headers[Constants.HttpHeaders.Authorization] = encodeURIComponent( await clientOptions.tokenProvider({ verb, path, resourceId, resourceType, headers }) ); - } else if (clientOptions.aadToken) { + } else if (clientOptions.aadCredential) { const AUTH_PREFIX = `type=aad&ver=1.0&sig=`; - const authorizationToken = `${AUTH_PREFIX}${clientOptions.aadToken}`; + const authorizationToken = `${AUTH_PREFIX}${clientOptions.aadCredential.token}`; headers[Constants.HttpHeaders.Authorization] = encodeURIComponent(authorizationToken); } } From 2e874bc71e3d82c33a75d6e7d08695fe9a5ed342 Mon Sep 17 00:00:00 2001 From: zfoster Date: Thu, 17 Dec 2020 16:16:36 -0500 Subject: [PATCH 04/23] format --- sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts b/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts index 944d8fce73fd..841fdee1e20c 100644 --- a/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts +++ b/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts @@ -34,8 +34,8 @@ export interface CosmosClientOptions { * e.g., https://zfoster-rbactest-1.documents.azure.com/.default */ aadCredentials?: { - credentials: any, - scope: string + credentials: any; + scope: string; }; /** An array of {@link Permission} objects. */ permissionFeed?: PermissionDefinition[]; From 4f479b9e365c515d8f972569bf43c8436dfac175 Mon Sep 17 00:00:00 2001 From: zfoster Date: Thu, 24 Dec 2020 14:38:29 -0500 Subject: [PATCH 05/23] Fixes AAD initializer and test --- sdk/cosmosdb/cosmos/package.json | 1 + sdk/cosmosdb/cosmos/review/cosmos.api.md | 1 + sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts | 7 ++----- sdk/cosmosdb/cosmos/src/auth.ts | 8 ++++++-- sdk/cosmosdb/cosmos/test/functional/client.spec.ts | 10 +++++++++- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/sdk/cosmosdb/cosmos/package.json b/sdk/cosmosdb/cosmos/package.json index c70dbca387ef..bc96378d4005 100644 --- a/sdk/cosmosdb/cosmos/package.json +++ b/sdk/cosmosdb/cosmos/package.json @@ -83,6 +83,7 @@ "tsdocFlavor": "AEDoc" }, "dependencies": { + "@azure/identity": "^1.1.0", "@types/debug": "^4.1.4", "debug": "^4.1.1", "fast-json-stable-stringify": "^2.0.0", diff --git a/sdk/cosmosdb/cosmos/review/cosmos.api.md b/sdk/cosmosdb/cosmos/review/cosmos.api.md index 122947b7e0dd..4d99f152e5bc 100644 --- a/sdk/cosmosdb/cosmos/review/cosmos.api.md +++ b/sdk/cosmosdb/cosmos/review/cosmos.api.md @@ -487,6 +487,7 @@ export class CosmosClient { // @public (undocumented) export interface CosmosClientOptions { + aadCredentials?: any; agent?: Agent; connectionPolicy?: ConnectionPolicy; consistencyLevel?: keyof typeof ConsistencyLevel; diff --git a/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts b/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts index 841fdee1e20c..7c60cb4a3d84 100644 --- a/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts +++ b/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts @@ -31,12 +31,9 @@ export interface CosmosClientOptions { /** AAD token from @azure/identity * Obtain a credential object by creating an @azure/identity credential object * We will then use your credential object and a scope URL (your cosmos db endpoint) - * e.g., https://zfoster-rbactest-1.documents.azure.com/.default + * to authenticate requests to Cosmos */ - aadCredentials?: { - credentials: any; - scope: string; - }; + aadCredentials?: any; /** An array of {@link Permission} objects. */ permissionFeed?: PermissionDefinition[]; /** An instance of {@link ConnectionPolicy} class. diff --git a/sdk/cosmosdb/cosmos/src/auth.ts b/sdk/cosmosdb/cosmos/src/auth.ts index c7424db03cd3..f6f4ab11cced 100644 --- a/sdk/cosmosdb/cosmos/src/auth.ts +++ b/sdk/cosmosdb/cosmos/src/auth.ts @@ -68,9 +68,13 @@ export async function setAuthorizationHeader( headers[Constants.HttpHeaders.Authorization] = encodeURIComponent( await clientOptions.tokenProvider({ verb, path, resourceId, resourceType, headers }) ); - } else if (clientOptions.aadCredential) { + } else if (clientOptions.aadCredentials) { + if (typeof clientOptions.aadCredentials?.getToken !== 'function') { + throw new Error('Cannot use AAD Credentials without `getToken`. See @azure/identity docs') + } + const token = await clientOptions.aadCredentials.getToken(clientOptions.endpoint) const AUTH_PREFIX = `type=aad&ver=1.0&sig=`; - const authorizationToken = `${AUTH_PREFIX}${clientOptions.aadCredential.token}`; + const authorizationToken = `${AUTH_PREFIX}${token}`; headers[Constants.HttpHeaders.Authorization] = encodeURIComponent(authorizationToken); } } diff --git a/sdk/cosmosdb/cosmos/test/functional/client.spec.ts b/sdk/cosmosdb/cosmos/test/functional/client.spec.ts index dbd31ed0ebaf..18f5aea66270 100644 --- a/sdk/cosmosdb/cosmos/test/functional/client.spec.ts +++ b/sdk/cosmosdb/cosmos/test/functional/client.spec.ts @@ -11,6 +11,7 @@ import { bulkInsertItems } from "../common/TestHelpers"; import AbortController from "node-abort-controller"; +import { UsernamePasswordCredential } from '@azure/identity'; describe("NodeJS CRUD Tests", function() { this.timeout(process.env.MOCHA_TIMEOUT || 20000); @@ -54,12 +55,19 @@ describe("NodeJS CRUD Tests", function() { }); it("fails to read databases with AAD authentication", async function() { try { + const credentials = new UsernamePasswordCredential( + 'fake-tenant-id', + 'fake-client-id', + 'fakeUsername', + 'fakePassword' + ) const client = new CosmosClient({ endpoint, - aadToken: "faketoken" + aadCredentials: credentials }); await client.databases.readAll().fetchAll(); } catch (e) { + console.log(e) assert.equal(e.code, 401); } }); From a86b4ddbbd2d752ec8f0729bbad4d00467aa6f1a Mon Sep 17 00:00:00 2001 From: zfoster Date: Thu, 24 Dec 2020 14:38:34 -0500 Subject: [PATCH 06/23] Format --- sdk/cosmosdb/cosmos/src/auth.ts | 6 +++--- sdk/cosmosdb/cosmos/test/functional/client.spec.ts | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sdk/cosmosdb/cosmos/src/auth.ts b/sdk/cosmosdb/cosmos/src/auth.ts index f6f4ab11cced..ecadd064e892 100644 --- a/sdk/cosmosdb/cosmos/src/auth.ts +++ b/sdk/cosmosdb/cosmos/src/auth.ts @@ -69,10 +69,10 @@ export async function setAuthorizationHeader( await clientOptions.tokenProvider({ verb, path, resourceId, resourceType, headers }) ); } else if (clientOptions.aadCredentials) { - if (typeof clientOptions.aadCredentials?.getToken !== 'function') { - throw new Error('Cannot use AAD Credentials without `getToken`. See @azure/identity docs') + if (typeof clientOptions.aadCredentials?.getToken !== "function") { + throw new Error("Cannot use AAD Credentials without `getToken`. See @azure/identity docs"); } - const token = await clientOptions.aadCredentials.getToken(clientOptions.endpoint) + const token = await clientOptions.aadCredentials.getToken(clientOptions.endpoint); const AUTH_PREFIX = `type=aad&ver=1.0&sig=`; const authorizationToken = `${AUTH_PREFIX}${token}`; headers[Constants.HttpHeaders.Authorization] = encodeURIComponent(authorizationToken); diff --git a/sdk/cosmosdb/cosmos/test/functional/client.spec.ts b/sdk/cosmosdb/cosmos/test/functional/client.spec.ts index 18f5aea66270..fb012fa2285d 100644 --- a/sdk/cosmosdb/cosmos/test/functional/client.spec.ts +++ b/sdk/cosmosdb/cosmos/test/functional/client.spec.ts @@ -11,7 +11,7 @@ import { bulkInsertItems } from "../common/TestHelpers"; import AbortController from "node-abort-controller"; -import { UsernamePasswordCredential } from '@azure/identity'; +import { UsernamePasswordCredential } from "@azure/identity"; describe("NodeJS CRUD Tests", function() { this.timeout(process.env.MOCHA_TIMEOUT || 20000); @@ -56,18 +56,18 @@ describe("NodeJS CRUD Tests", function() { it("fails to read databases with AAD authentication", async function() { try { const credentials = new UsernamePasswordCredential( - 'fake-tenant-id', - 'fake-client-id', - 'fakeUsername', - 'fakePassword' - ) + "fake-tenant-id", + "fake-client-id", + "fakeUsername", + "fakePassword" + ); const client = new CosmosClient({ endpoint, aadCredentials: credentials }); await client.databases.readAll().fetchAll(); } catch (e) { - console.log(e) + console.log(e); assert.equal(e.code, 401); } }); From bd776bba072be29de63e8f40096dd6fb85a24364 Mon Sep 17 00:00:00 2001 From: zfoster Date: Fri, 25 Dec 2020 12:08:54 -0500 Subject: [PATCH 07/23] remove log --- sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts index de8921066926..535984b8abc2 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts @@ -67,7 +67,6 @@ describe("NodeJS CRUD Tests", function() { }); await client.databases.readAll().fetchAll(); } catch (e) { - console.log(e); assert.equal(e.code, 401); } }); From 178ee9d66b971b793edf7369084b4dc0f43ded20 Mon Sep 17 00:00:00 2001 From: zfoster Date: Fri, 25 Dec 2020 12:11:00 -0500 Subject: [PATCH 08/23] Adds type --- sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts b/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts index 7c60cb4a3d84..ee59de01c0b7 100644 --- a/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts +++ b/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. +import { TokenCredential } from '@azure/identity'; import { TokenProvider } from "./auth"; import { PermissionDefinition } from "./client"; import { ConnectionPolicy, ConsistencyLevel } from "./documents"; @@ -33,7 +34,7 @@ export interface CosmosClientOptions { * We will then use your credential object and a scope URL (your cosmos db endpoint) * to authenticate requests to Cosmos */ - aadCredentials?: any; + aadCredentials?: TokenCredential; /** An array of {@link Permission} objects. */ permissionFeed?: PermissionDefinition[]; /** An instance of {@link ConnectionPolicy} class. From f2b5059c4ff4df7158c2c6fdf17aff68c25ef37b Mon Sep 17 00:00:00 2001 From: zfoster Date: Fri, 25 Dec 2020 12:11:07 -0500 Subject: [PATCH 09/23] format --- sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts b/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts index ee59de01c0b7..7f2ac8a4f440 100644 --- a/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts +++ b/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { TokenCredential } from '@azure/identity'; +import { TokenCredential } from "@azure/identity"; import { TokenProvider } from "./auth"; import { PermissionDefinition } from "./client"; import { ConnectionPolicy, ConsistencyLevel } from "./documents"; From cc810e7d70f1dbb0961af3e8e4571bdf5722a77b Mon Sep 17 00:00:00 2001 From: zfoster Date: Sun, 27 Dec 2020 17:45:50 -0500 Subject: [PATCH 10/23] Adds correct aad type --- sdk/cosmosdb/cosmos/CHANGELOG.md | 4 ++++ sdk/cosmosdb/cosmos/review/cosmos.api.md | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sdk/cosmosdb/cosmos/CHANGELOG.md b/sdk/cosmosdb/cosmos/CHANGELOG.md index b123596ab82a..591a5ec97741 100644 --- a/sdk/cosmosdb/cosmos/CHANGELOG.md +++ b/sdk/cosmosdb/cosmos/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History +## 3.10.0 (2020-12-27) + +- FEATURE: Adds AAD authentication via @azure/identity. + ## 3.9.3 (2020-10-19) - BUGFIX: Fixes bulk operations with top level partitionKey values that are undefined or null. diff --git a/sdk/cosmosdb/cosmos/review/cosmos.api.md b/sdk/cosmosdb/cosmos/review/cosmos.api.md index 4d99f152e5bc..ffc09afc0464 100644 --- a/sdk/cosmosdb/cosmos/review/cosmos.api.md +++ b/sdk/cosmosdb/cosmos/review/cosmos.api.md @@ -4,6 +4,8 @@ ```ts +import { TokenCredential } from '@azure/identity'; + // @public (undocumented) export interface Agent { // (undocumented) @@ -487,7 +489,7 @@ export class CosmosClient { // @public (undocumented) export interface CosmosClientOptions { - aadCredentials?: any; + aadCredentials?: TokenCredential; agent?: Agent; connectionPolicy?: ConnectionPolicy; consistencyLevel?: keyof typeof ConsistencyLevel; From 1d4bac875b13f77eb8c1b7bb3428d1101db78faf Mon Sep 17 00:00:00 2001 From: Steve Faulkner Date: Fri, 8 Jan 2021 15:56:53 -0600 Subject: [PATCH 11/23] Test on 3.9 and latest --- sdk/cosmosdb/cosmos/consumer-test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sdk/cosmosdb/cosmos/consumer-test.js b/sdk/cosmosdb/cosmos/consumer-test.js index 906aa2bd00be..3811ada4f9d6 100644 --- a/sdk/cosmosdb/cosmos/consumer-test.js +++ b/sdk/cosmosdb/cosmos/consumer-test.js @@ -1,6 +1,6 @@ const execa = require("execa"); -let versions = ["3.1", "3.2", "3.3", "3.4", "3.5", "3.6"]; +let versions = ["3.9"]; if (!process.env.SKIP_LATEST) { versions.push("latest"); @@ -22,7 +22,9 @@ async function exec(cmd) { console.log("Installing @azure/cosmos as a file dependency"); for (const version of versions) { console.log(`Compling with typescript@${version} - Basic`); - await exec(`npx -p typescript@${version} tsc ./test.ts --allowSyntheticDefaultImports true`); + await exec( + `npx -p typescript@${version} tsc ./test.ts --allowSyntheticDefaultImports true --target ES5` + ); console.log(`Compling with typescript@${version} - Custom lib`); await exec( `npx -p typescript@${version} tsc ./test.ts --allowSyntheticDefaultImports true --lib es2018` From 461956fb530d1da84d07735ef4d2e98f8c667f6f Mon Sep 17 00:00:00 2001 From: Steve Faulkner Date: Fri, 8 Jan 2021 17:15:28 -0600 Subject: [PATCH 12/23] Update CosmosClientOptions.ts --- sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts b/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts index 7f2ac8a4f440..b57f7d6bc141 100644 --- a/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts +++ b/sdk/cosmosdb/cosmos/src/CosmosClientOptions.ts @@ -33,6 +33,7 @@ export interface CosmosClientOptions { * Obtain a credential object by creating an @azure/identity credential object * We will then use your credential object and a scope URL (your cosmos db endpoint) * to authenticate requests to Cosmos + * This feature is in private preview and not yet available for every Cosmos account */ aadCredentials?: TokenCredential; /** An array of {@link Permission} objects. */ From 5a80bb40b28a2c83891f83e96115973a5918bee8 Mon Sep 17 00:00:00 2001 From: Steve Faulkner Date: Mon, 11 Jan 2021 10:46:10 -0600 Subject: [PATCH 13/23] Empty commit From ec228156067349321bc26af0d2ba3da41477cac8 Mon Sep 17 00:00:00 2001 From: Steve Faulkner Date: Sun, 17 Jan 2021 11:47:34 -0600 Subject: [PATCH 14/23] WIP --- sdk/core/abort-controller/package.json | 11 ++++++++++- sdk/cosmosdb/cosmos/consumer-test.js | 4 ++-- sdk/cosmosdb/cosmos/package.json | 3 +-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/sdk/core/abort-controller/package.json b/sdk/core/abort-controller/package.json index 11a3d1584615..0d6d02f434ea 100644 --- a/sdk/core/abort-controller/package.json +++ b/sdk/core/abort-controller/package.json @@ -9,8 +9,9 @@ "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit", "build:es6": "tsc -p tsconfig.json", "build:nodebrowser": "rollup -c 2>&1", + "build:types": "downlevel-dts types/src types/3.1", "build:test": "rollup -c rollup.test.config.js 2>&1", - "build": "npm run build:es6 && npm run build:nodebrowser", + "build": "npm run build:es6 && npm run build:nodebrowser && npm run build:types", "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "clean": "rimraf dist dist-esm dist-test types temp dist-browser/*.js* dist-browser/*.zip statistics.html coverage coverage-browser .nyc_output *.tgz *.log test*.xml TEST*.xml", "execute:samples": "echo skipped", @@ -34,6 +35,13 @@ "docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --mode file --out ./dist/docs ./src" }, "types": "./types/src/index.d.ts", + "typesVersions": { + "<3.6": { + "types/src/*": [ + "types/3.1/*" + ] + } + }, "engine": { "node": ">=8.0.0" }, @@ -82,6 +90,7 @@ "assert": "^1.4.1", "cross-env": "^7.0.2", "delay": "^4.2.0", + "downlevel-dts": "~0.4.0", "eslint": "^7.15.0", "karma": "^5.1.0", "karma-chrome-launcher": "^3.0.0", diff --git a/sdk/cosmosdb/cosmos/consumer-test.js b/sdk/cosmosdb/cosmos/consumer-test.js index 3811ada4f9d6..4ead014f9a56 100644 --- a/sdk/cosmosdb/cosmos/consumer-test.js +++ b/sdk/cosmosdb/cosmos/consumer-test.js @@ -1,6 +1,6 @@ const execa = require("execa"); -let versions = ["3.9"]; +let versions = ["3.1", "3.9"]; if (!process.env.SKIP_LATEST) { versions.push("latest"); @@ -18,7 +18,7 @@ async function exec(cmd) { console.log("Running typescript consumer test againast", versions); await exec("npm init -y"); console.log("Setting up typescript consumer project"); - await exec("npm install --save ./.."); + await exec("npm install --only=production ./.."); console.log("Installing @azure/cosmos as a file dependency"); for (const version of versions) { console.log(`Compling with typescript@${version} - Basic`); diff --git a/sdk/cosmosdb/cosmos/package.json b/sdk/cosmosdb/cosmos/package.json index 496b7ddef911..6a92ad4c92ba 100644 --- a/sdk/cosmosdb/cosmos/package.json +++ b/sdk/cosmosdb/cosmos/package.json @@ -70,7 +70,7 @@ "prebuild": "npm run clean", "test:browser": "npm run unit-test:browser && npm run integration-test:browser", "test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node", - "test-consumer": "node consumer-test.js 2>&1", + "test-consumer": "rimraf consumer-test/node_modules consumer-test/package-lock.json && node consumer-test.js 2>&1", "test": "npm run unit-test && npm run integration-test", "test:signoff": "mocha -r esm -r dotenv/config -r ./test/public/common/setup.js \"./test/internal/**/*.spec.ts\" \"./test/public/**/*.spec.ts\" --timeout 100000 --grep \"#nosignoff\" --invert", "unit-test:browser": "echo skipped", @@ -100,7 +100,6 @@ "uuid": "^8.3.0" }, "devDependencies": { - "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@microsoft/api-extractor": "7.7.11", "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-multi-entry": "^3.0.0", From 2547ec5b91b2c0b03456de7eb1822b10c082be53 Mon Sep 17 00:00:00 2001 From: zfoster Date: Thu, 21 Jan 2021 08:44:38 -0500 Subject: [PATCH 15/23] Adds eslint plugin back --- sdk/cosmosdb/cosmos/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/cosmosdb/cosmos/package.json b/sdk/cosmosdb/cosmos/package.json index a10b8f57fd42..633a68f3f7c9 100644 --- a/sdk/cosmosdb/cosmos/package.json +++ b/sdk/cosmosdb/cosmos/package.json @@ -100,6 +100,7 @@ "uuid": "^8.3.0" }, "devDependencies": { + "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@microsoft/api-extractor": "7.7.11", "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-multi-entry": "^3.0.0", From 700c4e061ca07b8165b4065a71827ad6cfa36f49 Mon Sep 17 00:00:00 2001 From: zfoster Date: Thu, 21 Jan 2021 10:27:04 -0500 Subject: [PATCH 16/23] empty commit From 5f895f26373b2df03bd064dc3073572791cb7508 Mon Sep 17 00:00:00 2001 From: zfoster Date: Thu, 21 Jan 2021 18:00:45 -0500 Subject: [PATCH 17/23] Fix typo --- sdk/cosmosdb/cosmos/consumer-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/cosmosdb/cosmos/consumer-test.js b/sdk/cosmosdb/cosmos/consumer-test.js index 4ead014f9a56..73031d266282 100644 --- a/sdk/cosmosdb/cosmos/consumer-test.js +++ b/sdk/cosmosdb/cosmos/consumer-test.js @@ -15,7 +15,7 @@ async function exec(cmd) { (async () => { try { - console.log("Running typescript consumer test againast", versions); + console.log("Running typescript consumer test against", versions); await exec("npm init -y"); console.log("Setting up typescript consumer project"); await exec("npm install --only=production ./.."); From 33a7e084c907b0f4971edd4a02e9072e12aaac23 Mon Sep 17 00:00:00 2001 From: Zach foster Date: Mon, 25 Jan 2021 16:31:26 -0500 Subject: [PATCH 18/23] fix changelog entries --- sdk/cosmosdb/cosmos/CHANGELOG.md | 2 +- sdk/cosmosdb/cosmos/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/cosmosdb/cosmos/CHANGELOG.md b/sdk/cosmosdb/cosmos/CHANGELOG.md index 88f845dd0d52..b0f287e16184 100644 --- a/sdk/cosmosdb/cosmos/CHANGELOG.md +++ b/sdk/cosmosdb/cosmos/CHANGELOG.md @@ -4,7 +4,7 @@ - FEATURE: Adds AAD authentication via @azure/identity. -## 3.9.5 (2021-01-15) +## 3.9.5 (2021-01-16) - BUGFIX: Throws correct Invalid Continuation Token error when making request with malformed token - BUGFIX: Defaults partitionKeyValue to `'[{}]'` when missing in Read/Delete bulk operations diff --git a/sdk/cosmosdb/cosmos/package.json b/sdk/cosmosdb/cosmos/package.json index fae11c99aa92..3b09e172ec6c 100644 --- a/sdk/cosmosdb/cosmos/package.json +++ b/sdk/cosmosdb/cosmos/package.json @@ -1,6 +1,6 @@ { "name": "@azure/cosmos", - "version": "3.9.6", + "version": "3.10.0", "description": "Microsoft Azure Cosmos DB Service Node.js SDK for SQL API", "sdk-type": "client", "keywords": [ From ab7cc6eec5e5a0ea4de73f259133680d4208b185 Mon Sep 17 00:00:00 2001 From: Steve Faulkner Date: Mon, 25 Jan 2021 19:55:03 -0600 Subject: [PATCH 19/23] Update NPM --- sdk/cosmosdb/cosmos/consumer-test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/cosmosdb/cosmos/consumer-test.js b/sdk/cosmosdb/cosmos/consumer-test.js index 73031d266282..a17297d8387c 100644 --- a/sdk/cosmosdb/cosmos/consumer-test.js +++ b/sdk/cosmosdb/cosmos/consumer-test.js @@ -15,6 +15,7 @@ async function exec(cmd) { (async () => { try { + await exec("npm install -g npm"); console.log("Running typescript consumer test against", versions); await exec("npm init -y"); console.log("Setting up typescript consumer project"); From 206ffbbf9ec14fc5234d1e40cbf39b2ce7fe6280 Mon Sep 17 00:00:00 2001 From: Steve Faulkner Date: Mon, 25 Jan 2021 20:01:19 -0600 Subject: [PATCH 20/23] More robust abort test --- sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts index 535984b8abc2..1d76655e4f8d 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts @@ -72,15 +72,16 @@ describe("NodeJS CRUD Tests", function() { }); }); describe("Validate user passed AbortController.signal", function() { - it("should throw exception if aborted during the request", async function() { + it.only("should throw exception if aborted during the request", async function() { const client = new CosmosClient({ endpoint, key: masterKey }); try { const controller = new AbortController(); const signal = controller.signal; - setTimeout(() => controller.abort(), 5); + setTimeout(() => controller.abort(), 1); await client.getDatabaseAccount({ abortSignal: signal }); assert.fail("Must throw when trying to connect to database"); } catch (err) { + console.log(err); assert.equal(err.name, "AbortError", "client should throw exception"); } }); @@ -112,7 +113,7 @@ describe("NodeJS CRUD Tests", function() { assert.equal(err.name, "AbortError", "client should throw exception"); } }); - it("should not abort if abort signal is never called", async function() { + it.only("should not abort if abort signal is never called", async function() { // Testing the happy path to prevent this bug https://github.com/Azure/azure-sdk-for-js/issues/9510 const client = new CosmosClient({ endpoint, key: masterKey }); try { From 5d559e3387cc3201c9d8166f92cd113148a190c1 Mon Sep 17 00:00:00 2001 From: Steve Faulkner Date: Mon, 25 Jan 2021 21:27:12 -0600 Subject: [PATCH 21/23] More robust abort test --- sdk/cosmosdb/cosmos/consumer-test.js | 4 ---- sdk/cosmosdb/cosmos/consumer-test/test.ts | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/sdk/cosmosdb/cosmos/consumer-test.js b/sdk/cosmosdb/cosmos/consumer-test.js index a17297d8387c..f555960adcf3 100644 --- a/sdk/cosmosdb/cosmos/consumer-test.js +++ b/sdk/cosmosdb/cosmos/consumer-test.js @@ -17,10 +17,6 @@ async function exec(cmd) { try { await exec("npm install -g npm"); console.log("Running typescript consumer test against", versions); - await exec("npm init -y"); - console.log("Setting up typescript consumer project"); - await exec("npm install --only=production ./.."); - console.log("Installing @azure/cosmos as a file dependency"); for (const version of versions) { console.log(`Compling with typescript@${version} - Basic`); await exec( diff --git a/sdk/cosmosdb/cosmos/consumer-test/test.ts b/sdk/cosmosdb/cosmos/consumer-test/test.ts index b63fc13122da..2244b8a5c62c 100644 --- a/sdk/cosmosdb/cosmos/consumer-test/test.ts +++ b/sdk/cosmosdb/cosmos/consumer-test/test.ts @@ -1,3 +1,3 @@ -import * as Cosmos from "@azure/cosmos"; +import * as Cosmos from "../"; console.log(Object.keys(Cosmos)); From 90c42d7e727a6a94fa8ebd48604d372f7d386a33 Mon Sep 17 00:00:00 2001 From: Steve Faulkner Date: Mon, 25 Jan 2021 21:50:47 -0600 Subject: [PATCH 22/23] More --- sdk/cosmosdb/cosmos/consumer-test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/cosmosdb/cosmos/consumer-test.js b/sdk/cosmosdb/cosmos/consumer-test.js index f555960adcf3..f0f59742a244 100644 --- a/sdk/cosmosdb/cosmos/consumer-test.js +++ b/sdk/cosmosdb/cosmos/consumer-test.js @@ -15,7 +15,6 @@ async function exec(cmd) { (async () => { try { - await exec("npm install -g npm"); console.log("Running typescript consumer test against", versions); for (const version of versions) { console.log(`Compling with typescript@${version} - Basic`); From 718c513e06732f8dfe492c40898c5c8033892091 Mon Sep 17 00:00:00 2001 From: Steve Faulkner Date: Mon, 25 Jan 2021 22:29:46 -0600 Subject: [PATCH 23/23] REmove only --- sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts index 1d76655e4f8d..49d408ed7018 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts @@ -72,7 +72,7 @@ describe("NodeJS CRUD Tests", function() { }); }); describe("Validate user passed AbortController.signal", function() { - it.only("should throw exception if aborted during the request", async function() { + it("should throw exception if aborted during the request", async function() { const client = new CosmosClient({ endpoint, key: masterKey }); try { const controller = new AbortController(); @@ -113,7 +113,7 @@ describe("NodeJS CRUD Tests", function() { assert.equal(err.name, "AbortError", "client should throw exception"); } }); - it.only("should not abort if abort signal is never called", async function() { + it("should not abort if abort signal is never called", async function() { // Testing the happy path to prevent this bug https://github.com/Azure/azure-sdk-for-js/issues/9510 const client = new CosmosClient({ endpoint, key: masterKey }); try {