From a732e7753da8e29f50b5cd222268fd169ce8ed7e Mon Sep 17 00:00:00 2001 From: Jeremy Meng Date: Mon, 27 Apr 2020 13:58:19 -0700 Subject: [PATCH] [Storage] Change browser stub of StorageSharedKeyCredential to class This fixes #8499. The issue was that in `StorageClient.ts` we have the following check and assume that in browser scenario `isNode` would be `false` which would short-circuit the evaluation of `factory instanceof StorageSharedKeyCredential`. So we added an `undefined` const for browser stub of `StorageSharedKeyCredential`. ```typescript if ( (isNode && factory instanceof StorageSharedKeyCredential) || factory instanceof AnonymousCredential || isTokenCredential(factory) ) { this.credential = factory; } `` However, in an Electron + Angular application, `isNode` is `true` but browser files are used. So the condition after `&&` is evaluated and caused an error: ``` TypeError: Right-hand side of 'instanceof' is not an object at DataLakeServiceClient.StorageClient (StorageClient.js:35) at new DataLakeServiceClient (DataLakeServiceClient.js:39) ``` This fix changes the stub of `StorageSharedKeyCredential` to an empty class instead so the condition will not throw but be evaluated to `false` because this credential type is not supported in browser. --- .../src/credentials/StorageSharedKeyCredential.browser.ts | 2 +- .../src/credentials/StorageSharedKeyCredential.browser.ts | 2 +- .../src/credentials/StorageSharedKeyCredential.browser.ts | 2 +- .../src/credentials/StorageSharedKeyCredential.browser.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/storage/storage-blob/src/credentials/StorageSharedKeyCredential.browser.ts b/sdk/storage/storage-blob/src/credentials/StorageSharedKeyCredential.browser.ts index 7eba09a7ad6e..1de8f56d2ac9 100644 --- a/sdk/storage/storage-blob/src/credentials/StorageSharedKeyCredential.browser.ts +++ b/sdk/storage/storage-blob/src/credentials/StorageSharedKeyCredential.browser.ts @@ -1,4 +1,4 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -export const StorageSharedKeyCredential = undefined; +export class StorageSharedKeyCredential {} diff --git a/sdk/storage/storage-file-datalake/src/credentials/StorageSharedKeyCredential.browser.ts b/sdk/storage/storage-file-datalake/src/credentials/StorageSharedKeyCredential.browser.ts index 7eba09a7ad6e..1de8f56d2ac9 100644 --- a/sdk/storage/storage-file-datalake/src/credentials/StorageSharedKeyCredential.browser.ts +++ b/sdk/storage/storage-file-datalake/src/credentials/StorageSharedKeyCredential.browser.ts @@ -1,4 +1,4 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -export const StorageSharedKeyCredential = undefined; +export class StorageSharedKeyCredential {} diff --git a/sdk/storage/storage-file-share/src/credentials/StorageSharedKeyCredential.browser.ts b/sdk/storage/storage-file-share/src/credentials/StorageSharedKeyCredential.browser.ts index 7eba09a7ad6e..1de8f56d2ac9 100644 --- a/sdk/storage/storage-file-share/src/credentials/StorageSharedKeyCredential.browser.ts +++ b/sdk/storage/storage-file-share/src/credentials/StorageSharedKeyCredential.browser.ts @@ -1,4 +1,4 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -export const StorageSharedKeyCredential = undefined; +export class StorageSharedKeyCredential {} diff --git a/sdk/storage/storage-queue/src/credentials/StorageSharedKeyCredential.browser.ts b/sdk/storage/storage-queue/src/credentials/StorageSharedKeyCredential.browser.ts index 7eba09a7ad6e..1de8f56d2ac9 100644 --- a/sdk/storage/storage-queue/src/credentials/StorageSharedKeyCredential.browser.ts +++ b/sdk/storage/storage-queue/src/credentials/StorageSharedKeyCredential.browser.ts @@ -1,4 +1,4 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -export const StorageSharedKeyCredential = undefined; +export class StorageSharedKeyCredential {}