2021-02-22 14:43:58 -06:00
|
|
|
import { AuthType } from "./AuthType";
|
2020-08-06 14:03:46 -05:00
|
|
|
import { DatabaseAccount } from "./Contracts/DataModels";
|
2020-11-12 13:35:39 -06:00
|
|
|
import { SubscriptionType } from "./Contracts/SubscriptionType";
|
2020-08-11 18:36:42 -07:00
|
|
|
import { DefaultAccountExperienceType } from "./DefaultAccountExperienceType";
|
2020-08-06 14:03:46 -05:00
|
|
|
|
|
|
|
interface UserContext {
|
2021-02-22 14:43:58 -06:00
|
|
|
authType?: AuthType;
|
2020-08-06 14:03:46 -05:00
|
|
|
masterKey?: string;
|
|
|
|
subscriptionId?: string;
|
|
|
|
resourceGroup?: string;
|
|
|
|
databaseAccount?: DatabaseAccount;
|
|
|
|
endpoint?: string;
|
|
|
|
accessToken?: string;
|
|
|
|
authorizationToken?: string;
|
|
|
|
resourceToken?: string;
|
2020-08-11 18:36:42 -07:00
|
|
|
defaultExperience?: DefaultAccountExperienceType;
|
2020-08-19 16:11:43 -07:00
|
|
|
useSDKOperations?: boolean;
|
2020-11-12 13:35:39 -06:00
|
|
|
subscriptionType?: SubscriptionType;
|
2020-12-16 20:00:39 -06:00
|
|
|
quotaId?: string;
|
2021-03-10 23:02:55 -06:00
|
|
|
// API Type is not yet provided by ARM. You need to manually inspect all the capabilities+kind so we abstract that logic in userContext
|
|
|
|
// This is coming in a future Cosmos ARM API version as a prperty on databaseAccount
|
|
|
|
apiType?: ApiType;
|
2021-03-17 16:02:20 -05:00
|
|
|
isTryCosmosDBSubscription?: boolean;
|
2021-03-17 15:24:21 -05:00
|
|
|
portalEnv?: PortalEnv;
|
2020-08-06 14:03:46 -05:00
|
|
|
}
|
|
|
|
|
2021-03-10 23:02:55 -06:00
|
|
|
type ApiType = "SQL" | "Mongo" | "Gremlin" | "Tables" | "Cassandra";
|
2021-03-17 15:24:21 -05:00
|
|
|
export type PortalEnv = "localhost" | "blackforest" | "fairfax" | "mooncake" | "prod" | "dev";
|
2021-03-10 23:02:55 -06:00
|
|
|
|
2021-03-17 16:02:20 -05:00
|
|
|
const userContext: UserContext = { isTryCosmosDBSubscription: false, portalEnv: "prod" };
|
2020-08-06 14:03:46 -05:00
|
|
|
|
|
|
|
function updateUserContext(newContext: UserContext): void {
|
|
|
|
Object.assign(userContext, newContext);
|
2021-03-10 23:02:55 -06:00
|
|
|
Object.assign(userContext, { apiType: apiType(userContext.databaseAccount) });
|
|
|
|
}
|
|
|
|
|
|
|
|
function apiType(account: DatabaseAccount | undefined): ApiType {
|
|
|
|
if (!account) {
|
|
|
|
return "SQL";
|
|
|
|
}
|
|
|
|
const capabilities = account.properties?.capabilities;
|
|
|
|
if (capabilities) {
|
|
|
|
if (capabilities.find((c) => c.name === "EnableCassandra")) {
|
|
|
|
return "Cassandra";
|
|
|
|
}
|
|
|
|
if (capabilities.find((c) => c.name === "EnableGremlin")) {
|
|
|
|
return "Gremlin";
|
|
|
|
}
|
|
|
|
if (capabilities.find((c) => c.name === "EnableMongo")) {
|
|
|
|
return "Mongo";
|
|
|
|
}
|
|
|
|
if (capabilities.find((c) => c.name === "EnableTable")) {
|
|
|
|
return "Tables";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (account.kind === "MongoDB" || account.kind === "Parse") {
|
|
|
|
return "Mongo";
|
|
|
|
}
|
|
|
|
return "SQL";
|
2020-08-06 14:03:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export { userContext, updateUserContext };
|