Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Cosmos Explorer",
"main": "index.js",
"dependencies": {
"@azure/cosmos": "3.6.3",
"@azure/cosmos": "3.7.0",
"@azure/cosmos-language-service": "0.0.4",
"@jupyterlab/services": "4.2.0",
"@jupyterlab/terminal": "1.2.1",
Expand Down
14 changes: 9 additions & 5 deletions src/Common/CosmosClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ const _global = typeof self === "undefined" ? window : self;
export const tokenProvider = async (requestInfo: RequestInfo) => {
const { verb, resourceId, resourceType, headers } = requestInfo;
if (config.platform === Platform.Emulator) {
// TODO Remove any. SDK expects a return value for tokenProvider, but we are mutating the header object instead.
return setAuthorizationTokenHeaderUsingMasterKey(verb, resourceId, resourceType, headers, EmulatorMasterKey) as any;
// TODO This SDK method mutates the headers object. Find a better one or fix the SDK.
await setAuthorizationTokenHeaderUsingMasterKey(verb, resourceId, resourceType, headers, EmulatorMasterKey);
return decodeURIComponent(headers.authorization);
}

if (_masterKey) {
// TODO Remove any. SDK expects a return value for tokenProvider, but we are mutating the header object instead.
return setAuthorizationTokenHeaderUsingMasterKey(verb, resourceId, resourceType, headers, _masterKey) as any;
// TODO This SDK method mutates the headers object. Find a better one or fix the SDK.
await setAuthorizationTokenHeaderUsingMasterKey(verb, resourceId, resourceType, headers, EmulatorMasterKey);
return decodeURIComponent(headers.authorization);
}

if (_resourceToken) {
Expand All @@ -47,7 +49,9 @@ export const requestPlugin: Cosmos.Plugin<any> = async (requestContext, next) =>

export const endpoint = () => {
if (config.platform === Platform.Emulator) {
return config.EMULATOR_ENDPOINT || window.parent.location.origin;
// In worker scope, _global(self).parent does not exist
const location = _global.parent ? _global.parent.location : _global.location;
return config.EMULATOR_ENDPOINT || location.origin;
}
return _endpoint || (_databaseAccount && _databaseAccount.properties && _databaseAccount.properties.documentEndpoint);
};
Expand Down
3 changes: 2 additions & 1 deletion src/Explorer/Tree/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import DocumentId from "./DocumentId";
import StoredProcedure from "./StoredProcedure";
import Trigger from "./Trigger";
import UserDefinedFunction from "./UserDefinedFunction";
import { config } from "../../Config";

export default class Collection implements ViewModels.Collection {
public nodeKind: string;
Expand Down Expand Up @@ -1416,7 +1417,7 @@ export default class Collection implements ViewModels.Collection {
masterKey: CosmosClient.masterKey(),
endpoint: CosmosClient.endpoint(),
accessToken: CosmosClient.accessToken(),
platform: window.dataExplorerPlatform,
platform: config.platform,
databaseAccount: CosmosClient.databaseAccount()
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/workers/upload/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DatabaseAccount } from "../../Contracts/DataModels";
import { PlatformType } from "../../PlatformType";
import { Platform } from "../../Config";

export interface StartUploadMessageParams {
files: FileList;
Expand All @@ -12,7 +12,7 @@ export interface DocumentClientParams {
masterKey: string;
endpoint: string;
accessToken: string;
platform: PlatformType;
platform: Platform;
databaseAccount: DatabaseAccount;
}

Expand Down
7 changes: 4 additions & 3 deletions src/workers/upload/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "babel-polyfill";
import { DocumentClientParams, UploadDetailsRecord, UploadDetails } from "./definitions";
import { CosmosClient } from "../../Common/CosmosClient";
import { config } from "../../Config";

let numUploadsSuccessful = 0;
let numUploadsFailed = 0;
Expand Down Expand Up @@ -33,8 +34,7 @@ onmessage = (event: MessageEvent) => {
CosmosClient.endpoint(clientParams.endpoint);
CosmosClient.accessToken(clientParams.accessToken);
CosmosClient.databaseAccount(clientParams.databaseAccount);
self.dataExplorerPlatform = clientParams.platform;
console.log(event);
config.platform = clientParams.platform;
if (!!files && files.length > 0) {
numFiles = files.length;
for (let i = 0; i < numFiles; i++) {
Expand Down Expand Up @@ -87,7 +87,7 @@ function createDocumentsFromFile(fileName: string, documentContent: string): voi
numUploadsSuccessful++;
})
.catch(error => {
console.log(error);
console.error(error);
recordUploadDetailErrorForFile(fileName, JSON.stringify(error));
numUploadsFailed++;
})
Expand All @@ -106,6 +106,7 @@ function createDocumentsFromFile(fileName: string, documentContent: string): voi
triggerCreateDocument(content);
}
} catch (e) {
console.log(e);
recordUploadDetailErrorForFile(fileName, e.message);
transmitResultIfUploadComplete();
}
Expand Down