bruce-models 4.5.7 → 4.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -841,782 +841,455 @@ var GuardianApi;
841
841
  GuardianApi.Api = Api$$1;
842
842
  })(GuardianApi || (GuardianApi = {}));
843
843
 
844
- // Some dead accounts that we don't want to show in the UI.
845
- // Some accounts may not be "dead" but instead purposely don't have a NextspaceAPI database so we'll avoid them too.
846
- const ACCOUNT_EXCLUSIONS = ["hyperportal", "hypeportal", "bviewer"];
847
844
  /**
848
- * Describes the "Client Account" concept within Nextspace.
849
- * A client account is a database instance that holds one or many users.
845
+ * The primary API for communication with Nextspace.
846
+ * This API is used to manage your data.
850
847
  */
851
- var Account;
852
- (function (Account) {
853
- /**
854
- * Known Nextspace applications we store settings for.
855
- */
856
- let EAppId;
857
- (function (EAppId) {
858
- EAppId["BruceApi"] = "BruceAPI";
859
- EAppId["Navigator"] = "Navigator";
860
- EAppId["Operator"] = "BruceClientAdmin";
861
- })(EAppId = Account.EAppId || (Account.EAppId = {}));
862
- /**
863
- * Possible starter content options.
864
- * When creating a new account you can populate it with certain default data.
865
- */
866
- let EStarterContent;
867
- (function (EStarterContent) {
868
- EStarterContent["Default"] = "default";
869
- EStarterContent["None"] = "none";
870
- })(EStarterContent = Account.EStarterContent || (Account.EStarterContent = {}));
848
+ var BruceApi;
849
+ (function (BruceApi$$1) {
871
850
  /**
872
- * Gets a client account record by ID.
873
- * @param params
874
- * @returns
851
+ * This is the request handler for Bruce Api,
852
+ * it should be passed to any method that wants to communicate with this particular api.
875
853
  */
876
- function Get(params) {
877
- return __awaiter(this, void 0, void 0, function* () {
878
- let { api, accountId: id, req: reqParams } = params;
879
- if (!api) {
880
- api = ENVIRONMENT.Api().GetGuardianApi();
881
- }
882
- const cache = yield api.GetCacheItem(GetCacheKey(id), reqParams);
883
- if (cache === null || cache === void 0 ? void 0 : cache.found) {
884
- return cache.data;
854
+ class Api$$1 extends AbstractApi {
855
+ get AccountId() {
856
+ return this.accountId;
857
+ }
858
+ get MessageBroker() {
859
+ return this.messageBroker;
860
+ }
861
+ get ConfigLoadAttempted() {
862
+ return this.configLoadAttempted;
863
+ }
864
+ get Version() {
865
+ return this.version;
866
+ }
867
+ get Loading() {
868
+ return this.loadProm;
869
+ }
870
+ constructor(params) {
871
+ super({
872
+ ssidHeader: "x-sessionid",
873
+ cacheId: `BRUCE_API_${params === null || params === void 0 ? void 0 : params.env}_${params === null || params === void 0 ? void 0 : params.accountId}_`
874
+ });
875
+ // Load cancelled indicates the user set a custom base url.
876
+ // This will stop the regional url from being set if it's still loading.
877
+ this.loadCancelled = false;
878
+ // Indicates if loading the regional configuration was already called.
879
+ this.configLoadAttempted = false;
880
+ let { accountId, env, guardian, loadRegionalBaseUrl, loadConfig, loadWebSocket, dummy } = params;
881
+ this.accountId = accountId;
882
+ this.env = env !== null && env !== void 0 ? env : Api.EEnv.PROD;
883
+ if (!dummy) {
884
+ // Backwards compatibility.
885
+ if (loadRegionalBaseUrl) {
886
+ loadConfig = true;
887
+ }
888
+ if (loadConfig) {
889
+ // Mark it as attempted right away because we don't want any external calls while it gets to that async point.
890
+ this.configLoadAttempted = true;
891
+ }
892
+ this.loadProm = this.init(guardian, loadConfig, loadWebSocket);
885
893
  }
886
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
887
- try {
888
- const data = yield api.GET(`accountbyid/${id}`, reqParams);
889
- // Update the cache by subdomain as well in case it's different to the ID.
890
- if ((data === null || data === void 0 ? void 0 : data.ID) && (reqParams === null || reqParams === void 0 ? void 0 : reqParams.noCache) != false) {
891
- yield api.SetCacheItem({
892
- key: data.Subdomain,
893
- value: prom,
894
- req: reqParams
895
- });
896
- }
897
- res({
898
- account: data
894
+ }
895
+ /**
896
+ * Loads regional base url and sets up message broker.
897
+ * @param guardian Required for loading regional base url.
898
+ * @param loadConfig
899
+ * @returns
900
+ */
901
+ init(guardian, loadConfig, loadWebSocket) {
902
+ return __awaiter(this, void 0, void 0, function* () {
903
+ if (!this.accountId) {
904
+ throw ("accountId is required.");
905
+ }
906
+ // Set using a stable default.
907
+ const domain = this.getDomain();
908
+ this.baseUrl = `https://${this.accountId}.api.${domain}/`;
909
+ // Attempt to load regional configuration.
910
+ if (loadConfig) {
911
+ yield this.LoadConfig({
912
+ guardian: guardian,
913
+ // We marked it as attempted to load outside this method to fight any external calls.
914
+ // So we'll force load it now.
915
+ forceLoad: true
899
916
  });
900
917
  }
901
- catch (e) {
902
- rej(e);
918
+ // Get the version.
919
+ if (this.baseUrl) {
920
+ const full = this.ConstructUrl({
921
+ url: "version"
922
+ });
923
+ const data = yield this.get(full);
924
+ if (data === null || data === void 0 ? void 0 : data["Bruce-API"]) {
925
+ this.version = data["Bruce-API"];
926
+ }
927
+ else {
928
+ this.version = "UNKNOWN";
929
+ }
930
+ }
931
+ // Start web socket connection.
932
+ if (loadWebSocket == true) {
933
+ try {
934
+ const full = this.ConstructUrl();
935
+ this.messageBroker = new MessageBroker.WebSocketBroker(full, this.env);
936
+ }
937
+ catch (e) {
938
+ console.warn("BruceApi: Failed to create message broker.", e);
939
+ }
903
940
  }
904
- }));
905
- yield api.SetCacheItem({
906
- key: GetCacheKey(id),
907
- value: prom,
908
- req: reqParams
909
941
  });
910
- return prom;
911
- });
912
- }
913
- Account.Get = Get;
914
- /**
915
- * Returns a client account record by subdomain or ID.
916
- * @param params
917
- * @returns
918
- */
919
- function GetBySubdomain(params) {
920
- return __awaiter(this, void 0, void 0, function* () {
921
- let { api, subdomain, req: reqParams } = params;
922
- if (!api) {
923
- api = ENVIRONMENT.Api().GetGuardianApi();
924
- }
925
- const cache = yield api.GetCacheItem(GetCacheKey(subdomain), reqParams);
926
- if (cache === null || cache === void 0 ? void 0 : cache.found) {
927
- return cache.data;
942
+ }
943
+ getDomain() {
944
+ const env = this.env.toUpperCase();
945
+ let domain = "nextspace.host";
946
+ switch (env) {
947
+ case Api.EEnv.DEV:
948
+ domain = "nextspace-dev.net";
949
+ break;
950
+ case Api.EEnv.STG:
951
+ domain = "nextspace-stg.net";
952
+ break;
953
+ case Api.EEnv.UAT:
954
+ domain = "nextspace-uat.net";
955
+ break;
956
+ case Api.EEnv.PROD:
957
+ domain = "nextspace.host";
958
+ break;
959
+ default:
960
+ console.error("Specified Environment is not valid. SuppliedEnv=" + env);
928
961
  }
929
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
962
+ return domain;
963
+ }
964
+ /**
965
+ * Loads the regional configuration for the account.
966
+ * If the config is already loaded then this will do nothing.
967
+ */
968
+ LoadConfig(params) {
969
+ return __awaiter(this, void 0, void 0, function* () {
970
+ let { guardian, forceLoad } = (params !== null && params !== void 0 ? params : {});
971
+ if (this.configLoadAttempted && forceLoad != true) {
972
+ return;
973
+ }
974
+ this.configLoadAttempted = true;
930
975
  try {
931
- const data = yield api.GET(`account/${subdomain}`, reqParams);
932
- // Update the cache by ID as well in case it's different to the subdomain.
933
- if ((data === null || data === void 0 ? void 0 : data.ID) && (reqParams === null || reqParams === void 0 ? void 0 : reqParams.noCache) != false) {
934
- yield api.SetCacheItem({
935
- key: data.ID,
936
- value: prom,
937
- req: reqParams
976
+ if (!guardian) {
977
+ guardian = new GuardianApi.Api({
978
+ env: this.env
938
979
  });
939
980
  }
940
- res({
941
- account: data
981
+ const { account } = yield Account.GetBySubdomain({
982
+ subdomain: this.accountId,
983
+ api: guardian
942
984
  });
985
+ if (!this.loadCancelled) {
986
+ // Set the calculated base url.
987
+ // If this is not available then this is considered a critical failure.
988
+ // However I am not crashing here because I want to monitor this in production.
989
+ if (account.URL) {
990
+ const urls = account.URL;
991
+ if (urls === null || urls === void 0 ? void 0 : urls.Base) {
992
+ this.baseUrl = urls.Base;
993
+ }
994
+ if (urls === null || urls === void 0 ? void 0 : urls.CDNEntities) {
995
+ this.EntityCdnUrl = urls.CDNEntities;
996
+ }
997
+ if (urls === null || urls === void 0 ? void 0 : urls.CDNTileset) {
998
+ this.TilesetCdnUrl = urls.CDNTileset;
999
+ }
1000
+ if (urls === null || urls === void 0 ? void 0 : urls.CDNLegacyTileset) {
1001
+ this.LegacyTilesetCdnUrl = urls.CDNLegacyTileset;
1002
+ }
1003
+ if (urls === null || urls === void 0 ? void 0 : urls.CDNBase) {
1004
+ this.cdnBaseUrl = urls.CDNBase;
1005
+ }
1006
+ }
1007
+ else {
1008
+ console.error("BruceApi: Failed to load regional configuration for account.", this.accountId);
1009
+ }
1010
+ }
943
1011
  }
944
1012
  catch (e) {
945
- rej(e);
1013
+ console.error(e);
946
1014
  }
947
- }));
948
- yield api.SetCacheItem({
949
- key: GetCacheKey(subdomain),
950
- value: prom,
951
- req: reqParams
952
1015
  });
953
- return prom;
954
- });
955
- }
956
- Account.GetBySubdomain = GetBySubdomain;
957
- /**
958
- * Gets a list of client accounts related to the current session user.
959
- * @param params
960
- * @returns
961
- */
962
- function GetRelatedList(params) {
963
- return __awaiter(this, void 0, void 0, function* () {
964
- let { api, req: reqParams } = params;
965
- if (!api) {
966
- api = ENVIRONMENT.Api().GetGuardianApi();
967
- }
968
- const cache = yield api.GetCacheItem(GetListCacheKey(api.GetSessionId()), reqParams);
969
- if (cache === null || cache === void 0 ? void 0 : cache.found) {
970
- return cache.data;
971
- }
972
- const req = api.GET("user/relatedClientAccounts", reqParams);
973
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
974
- try {
975
- const data = yield req;
976
- const items = data.Items.filter((x) => !ACCOUNT_EXCLUSIONS.includes(x.ID));
977
- res({
978
- accounts: items
979
- });
980
- }
981
- catch (e) {
982
- rej(e);
1016
+ }
1017
+ /**
1018
+ * Creates a message broker instance and returns it.
1019
+ * If an instance is already created, it will return that one.
1020
+ * @warning This will await the loading promise to avoid using data that isn't ready.
1021
+ */
1022
+ ConnectWebsocket() {
1023
+ return __awaiter(this, void 0, void 0, function* () {
1024
+ yield this.loadProm;
1025
+ if (this.messageBroker) {
1026
+ return this.messageBroker;
983
1027
  }
984
- }));
985
- yield api.SetCacheItem({
986
- key: GetListCacheKey(api.GetSessionId()),
987
- value: prom,
988
- req: reqParams
1028
+ const full = this.ConstructUrl();
1029
+ this.messageBroker = new MessageBroker.WebSocketBroker(full, this.env);
1030
+ return this.messageBroker;
989
1031
  });
990
- return prom;
991
- });
992
- }
993
- Account.GetRelatedList = GetRelatedList;
994
- /**
995
- * Gets application settings for a specific client account.
996
- * @param params
997
- * @returns
998
- */
999
- function GetAppSettings(params) {
1000
- return __awaiter(this, void 0, void 0, function* () {
1001
- let { api, accountId: id, appId, req: reqParams } = params;
1002
- if (!api) {
1003
- api = ENVIRONMENT.Api().GetGuardianApi();
1032
+ }
1033
+ /**
1034
+ * Warning: This method does not wait for init to finish loading.
1035
+ * This means the url could be changed once fully initialized.
1036
+ * The url will be valid either way, but the loaded one may be faster as it is region specific.
1037
+ * Await the "Loading" promise if you care about this.
1038
+ * @warning use ConstructUrl instead as the baseUrl may have a query param for the account.
1039
+ * @returns
1040
+ */
1041
+ GetBaseUrl() {
1042
+ return this.baseUrl;
1043
+ }
1044
+ /**
1045
+ * Warning: Wait the "Loading" promise before using this url.
1046
+ * @warning use ConstructUrl instead as the baseUrl may have a query param for the account.
1047
+ * @returns
1048
+ */
1049
+ GetCdnBaseUrl() {
1050
+ return this.cdnBaseUrl;
1051
+ }
1052
+ /**
1053
+ * Returns a url with the provided url appended to the loaded base url.
1054
+ * If the base url is not loaded yet, this will return null.
1055
+ * @param params
1056
+ */
1057
+ ConstructUrl(params) {
1058
+ if (!(params === null || params === void 0 ? void 0 : params.url)) {
1059
+ return null;
1004
1060
  }
1005
- const cache = yield api.GetCacheItem(GetCacheKey(id, appId), reqParams);
1006
- if (cache === null || cache === void 0 ? void 0 : cache.found) {
1007
- return cache.data;
1061
+ if ((params === null || params === void 0 ? void 0 : params.cdn) && this.cdnBaseUrl) {
1062
+ return this.ConstructCdnUrl(params.url, params.urlParams);
1008
1063
  }
1009
- const req = yield api.GET(`account/${id}?ApplicationID=${appId}`, reqParams);
1010
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
1011
- var _a;
1012
- try {
1013
- const data = yield req;
1014
- const settings = (_a = data === null || data === void 0 ? void 0 : data["Application.Settings"]) !== null && _a !== void 0 ? _a : {};
1015
- res({
1016
- settings: settings
1064
+ const tmp = new URL(this.baseUrl);
1065
+ if (params === null || params === void 0 ? void 0 : params.urlParams) {
1066
+ if (params.urlParams instanceof URLSearchParams) {
1067
+ params.urlParams.forEach((value, key) => {
1068
+ tmp.searchParams.append(key, value);
1017
1069
  });
1018
1070
  }
1019
- catch (e) {
1020
- rej(e);
1071
+ else {
1072
+ for (const key in params.urlParams) {
1073
+ tmp.searchParams.append(key, params.urlParams[key]);
1074
+ }
1021
1075
  }
1022
- }));
1023
- yield api.SetCacheItem({
1024
- key: GetCacheKey(id, appId),
1025
- value: prom,
1026
- req: reqParams
1027
- });
1028
- return prom;
1029
- });
1030
- }
1031
- Account.GetAppSettings = GetAppSettings;
1032
- /**
1033
- * Updates application settings for a specific client account + application.
1034
- * WARNING: Do not update API settings without knowing what you're doing.
1035
- * @param params
1036
- * @returns
1037
- */
1038
- function UpdateAppSettings(params) {
1039
- return __awaiter(this, void 0, void 0, function* () {
1040
- let { api, accountId: id, appId, settings: data, req: reqParams } = params;
1041
- if (!api) {
1042
- api = ENVIRONMENT.Api().GetGuardianApi();
1043
- }
1044
- const res = yield api.POST(`account/${id}/applicationSettings/${appId}`, data, reqParams);
1045
- yield api.Cache.RemoveByStartsWith(Api.ECacheKey.Account + Api.ECacheKey.Id + id);
1046
- return {
1047
- settings: res
1048
- };
1049
- });
1050
- }
1051
- Account.UpdateAppSettings = UpdateAppSettings;
1052
- /**
1053
- * Creates a new Nextspace account using given details.
1054
- * @param params
1055
- * @returns
1056
- */
1057
- function Create(params) {
1058
- return __awaiter(this, void 0, void 0, function* () {
1059
- let { api, accountId: id, name, hostingLocationKey, starterContent, req: reqParams } = params;
1060
- if (!id || !name || !hostingLocationKey) {
1061
- throw new Error("Id, Name and hostingLocationKey are required.");
1062
1076
  }
1063
- if (!api) {
1064
- api = ENVIRONMENT.Api().GetBruceApi();
1077
+ // Ensure the url ends with a slash.
1078
+ if (!tmp.pathname.endsWith("/")) {
1079
+ tmp.pathname += "/";
1065
1080
  }
1066
- if (!starterContent) {
1067
- starterContent = EStarterContent.None;
1081
+ if (params === null || params === void 0 ? void 0 : params.url) {
1082
+ // Ensure the url does not start with a slash.
1083
+ // This is because the base url already has a slash at the end.
1084
+ if (params.url.startsWith("/")) {
1085
+ params.url = params.url.substring(1);
1086
+ }
1087
+ tmp.pathname += params.url;
1068
1088
  }
1069
- const reqData = {
1070
- "Name": name,
1071
- "HostingLocation.Key": hostingLocationKey,
1072
- "StarterContent": starterContent
1073
- };
1074
- const res = yield api.POST(`clientAccount/${id}`, reqData, Api.PrepReqParams(reqParams));
1075
- const resData = {
1076
- account: res
1077
- };
1078
- api.Cache.Remove(GetListCacheKey(api.GetSessionId()));
1079
- return resData;
1080
- });
1081
- }
1082
- Account.Create = Create;
1083
- /**
1084
- * Returns cache identifier for an account by ID.
1085
- * Example: {
1086
- * const api: BruceApi.Api = ...;
1087
- * const key = GetCacheKey(1);
1088
- * api.Cache.Remove(key);
1089
- * }
1090
- * @param accountId
1091
- * @param appSettingsId
1092
- * @returns
1093
- */
1094
- function GetCacheKey(accountId, appSettingsId) {
1095
- if (appSettingsId) {
1096
- return Api.ECacheKey.Account + Api.ECacheKey.Id + accountId + Api.ECacheKey + appSettingsId;
1089
+ return tmp.toString();
1097
1090
  }
1098
- return Api.ECacheKey.Account + Api.ECacheKey.Id + accountId;
1099
- }
1100
- Account.GetCacheKey = GetCacheKey;
1101
- /**
1102
- * Returns cache identifier for a list of accounts by session ID.
1103
- * Example: {
1104
- * const api: BruceApi.Api = ...;
1105
- * const key = GetListCacheKey(api.GetSessionId());
1106
- * api.Cache.Remove(key);
1107
- * }
1108
- * @param ssid
1109
- * @returns
1110
- */
1111
- function GetListCacheKey(ssid) {
1112
- return Api.ECacheKey.Account + Api.ECacheKey.Session + Api.ECacheKey.Id + ssid;
1113
- }
1114
- Account.GetListCacheKey = GetListCacheKey;
1115
- /**
1116
- * Returns cache identifier for a list of database regions.
1117
- * Example: {
1118
- * const api: BruceApi.Api = ...;
1119
- * const key = GetDbRegionListCacheKey();
1120
- * api.Cache.Remove(key);
1121
- * }
1122
- * @returns
1123
- */
1124
- function GetDbRegionListCacheKey() {
1125
- return Api.ECacheKey.DatabaseRegion;
1126
- }
1127
- Account.GetDbRegionListCacheKey = GetDbRegionListCacheKey;
1128
- })(Account || (Account = {}));
1129
-
1130
- /**
1131
- * A hosting location is a record for a possible bruce-api server configuration.
1132
- * A hosting location will have one or many database servers as well, this is an additional setting.
1133
- */
1134
- var HostingLocation;
1135
- (function (HostingLocation) {
1136
- /**
1137
- * Returns a list of hosting locations.
1138
- * @Warning: This will not return the Settings property.
1139
- * @param params
1140
- * @returns
1141
- */
1142
- function GetList(params) {
1143
- return __awaiter(this, void 0, void 0, function* () {
1144
- let { api, req } = params;
1145
- if (!api) {
1146
- api = ENVIRONMENT.Api().GetGuardianApi();
1091
+ /**
1092
+ * Returns a url routed through the API's CDN.
1093
+ * If the CDN is not enabled for the account, this will return null.
1094
+ * @param url suffix to append to the base url.
1095
+ * @param urlParams
1096
+ * @returns
1097
+ */
1098
+ ConstructCdnUrl(url, urlParams) {
1099
+ if (!this.cdnBaseUrl) {
1100
+ return null;
1147
1101
  }
1148
- const res = yield api.GET("hostinglocations", Api.PrepReqParams(req));
1149
- return {
1150
- locations: res.Items
1151
- };
1152
- });
1153
- }
1154
- HostingLocation.GetList = GetList;
1155
- /**
1156
- * Returns a hosting location record by ID.
1157
- * @param params
1158
- * @returns
1159
- */
1160
- function GetById(params) {
1161
- return __awaiter(this, void 0, void 0, function* () {
1162
- let { id, api, req } = params;
1163
- if (!id) {
1164
- throw ("Invalid id");
1102
+ const tmp = new URL(this.cdnBaseUrl);
1103
+ if (urlParams) {
1104
+ if (urlParams instanceof URLSearchParams) {
1105
+ urlParams.forEach((value, key) => {
1106
+ tmp.searchParams.append(key, value);
1107
+ });
1108
+ }
1109
+ else {
1110
+ for (const key in urlParams) {
1111
+ tmp.searchParams.append(key, urlParams[key]);
1112
+ }
1113
+ }
1165
1114
  }
1166
- if (!api) {
1167
- api = ENVIRONMENT.Api().GetGuardianApi();
1115
+ // Ensure the url ends with a slash.
1116
+ if (!tmp.pathname.endsWith("/")) {
1117
+ tmp.pathname += "/";
1168
1118
  }
1169
- const res = yield api.GET(`hostinglocation/id/${id}`, Api.PrepReqParams(req));
1170
- return {
1171
- location: res
1172
- };
1173
- });
1174
- }
1175
- HostingLocation.GetById = GetById;
1176
- /**
1177
- * Returns a hosting location record by key.
1178
- * @param params
1179
- * @returns
1180
- */
1181
- function GetByKey(params) {
1182
- return __awaiter(this, void 0, void 0, function* () {
1183
- let { key, api, req } = params;
1184
- if (!key) {
1185
- throw ("Invalid key");
1119
+ if (url) {
1120
+ // Ensure the url does not start with a slash.
1121
+ // This is because the base url already has a slash at the end.
1122
+ if (url.startsWith("/")) {
1123
+ url = url.substring(1);
1124
+ }
1125
+ tmp.pathname += url;
1186
1126
  }
1187
- if (!api) {
1188
- api = ENVIRONMENT.Api().GetGuardianApi();
1189
- }
1190
- const res = yield api.GET(`hostinglocation/key/${key}`, Api.PrepReqParams(req));
1191
- return {
1192
- location: res
1193
- };
1194
- });
1195
- }
1196
- HostingLocation.GetByKey = GetByKey;
1197
- /**
1198
- * Returns hostingLocationKey from given db url.
1199
- * Some older accounts don't have this set, so we need to guess it.
1200
- * @param params
1201
- * @returns
1202
- */
1203
- function GuessKey(params) {
1204
- const { DBServer: databaseUrl } = params;
1205
- if (databaseUrl.includes("hyperfarm-prod-instance-1")) {
1206
- return "HYPERFARM";
1207
- }
1208
- if (databaseUrl.includes("prod-syd1.nextspace.host")) {
1209
- return "AU-VULTR-FIRST";
1210
- }
1211
- else if (databaseUrl.includes("prod-nyc1.nextspace.host")) {
1212
- return "US-VULTR-FIRST";
1213
- }
1214
- else if (databaseUrl.includes("prod-ams1.nextspace.host")) {
1215
- return "EU-VULTR-FIRST";
1216
- }
1217
- else if (databaseUrl.includes("prod-sing1.nextspace.host")) {
1218
- return "SE-VULTR-FIRST";
1219
- }
1220
- else if (databaseUrl.includes("dev-first")) {
1221
- return "DEV-FIRST";
1222
- }
1223
- else if (databaseUrl.includes(".ap-southeast-1.")) {
1224
- return "SE";
1127
+ return tmp.toString();
1225
1128
  }
1226
- else if (databaseUrl.includes(".us-west-1.")) {
1227
- return "US";
1129
+ /**
1130
+ * Warning: This will cancel the init process.
1131
+ * The init process loads a region specific endpoint.
1132
+ * Setting a base url will stop that process from completing.
1133
+ * @param url
1134
+ */
1135
+ SetBaseUrl(url) {
1136
+ this.baseUrl = url;
1137
+ if (!this.baseUrl.endsWith("/")) {
1138
+ this.baseUrl += "/";
1139
+ }
1140
+ this.loadCancelled = true;
1228
1141
  }
1229
- else if (databaseUrl.includes(".eu-west-3.")) {
1230
- return "EU";
1142
+ /**
1143
+ * Performs an HTTP GET request.
1144
+ * This will prepend the base url to the url.
1145
+ * @param url
1146
+ * @param params
1147
+ * @returns
1148
+ */
1149
+ GET(url, params) {
1150
+ return __awaiter(this, void 0, void 0, function* () {
1151
+ return new Promise((res, rej) => {
1152
+ this.loadProm.then(() => {
1153
+ const full = this.ConstructUrl({
1154
+ url: url
1155
+ });
1156
+ this.get(full, params).then(res).catch(rej);
1157
+ }).catch(rej);
1158
+ });
1159
+ });
1231
1160
  }
1232
- else if (databaseUrl.includes("bruce-prod-au")) {
1233
- return "AU";
1161
+ /**
1162
+ * Performs an HTTP DELETE request.
1163
+ * This will prepend the base url to the url.
1164
+ * @param url
1165
+ * @param params
1166
+ * @returns
1167
+ */
1168
+ DELETE(url, params) {
1169
+ return __awaiter(this, void 0, void 0, function* () {
1170
+ return new Promise((res, rej) => {
1171
+ this.loadProm.then(() => {
1172
+ const full = this.ConstructUrl({
1173
+ url: url
1174
+ });
1175
+ this.delete(full, params).then(res).catch(rej);
1176
+ }).catch(rej);
1177
+ });
1178
+ });
1234
1179
  }
1235
- else if (databaseUrl.includes("bruce-dev")) {
1236
- return "DEV";
1180
+ /**
1181
+ * Performs an HTTP POST request.
1182
+ * This will prepend the base url to the url.
1183
+ * @param url
1184
+ * @param data
1185
+ * @param params
1186
+ * @returns
1187
+ */
1188
+ POST(url, data, params) {
1189
+ return __awaiter(this, void 0, void 0, function* () {
1190
+ return new Promise((res, rej) => {
1191
+ this.loadProm.then(() => {
1192
+ const full = this.ConstructUrl({
1193
+ url: url
1194
+ });
1195
+ this.post(full, data, params).then(res).catch(rej);
1196
+ }).catch(rej);
1197
+ });
1198
+ });
1237
1199
  }
1238
- return null;
1239
- }
1240
- HostingLocation.GuessKey = GuessKey;
1241
- /**
1242
- * Returns a hosting location key by account ID.
1243
- * @param params
1244
- * @returns
1245
- */
1246
- function GetKeyByAccountId(params) {
1247
- return __awaiter(this, void 0, void 0, function* () {
1248
- let { accountId, apiSettings, api, account, req } = params;
1249
- if (!accountId && !apiSettings) {
1250
- throw ("Invalid accountId or apiSettings");
1251
- }
1252
- if (!api) {
1253
- api = ENVIRONMENT.Api().GetGuardianApi();
1254
- }
1255
- // We'll prioritize account record if provided.
1256
- if (accountId && !account) {
1257
- account = (yield Account.Get({
1258
- accountId,
1259
- api,
1260
- req
1261
- })).account;
1262
- }
1263
- if (account === null || account === void 0 ? void 0 : account["HostingLocation.Key"]) {
1264
- return {
1265
- key: account["HostingLocation.Key"],
1266
- isLegacy: false
1267
- };
1268
- }
1269
- // Fallback to settings JSON for older records.
1270
- const settings = apiSettings ? apiSettings : (yield Account.GetAppSettings({
1271
- api,
1272
- accountId,
1273
- appId: Account.EAppId.BruceApi
1274
- })).settings;
1275
- let hostingKey = settings["HostingLocation.Key"];
1276
- let isLegacy = false;
1277
- if (!hostingKey) {
1278
- hostingKey = settings.DBLocation;
1279
- isLegacy = true;
1280
- }
1281
- if (!hostingKey) {
1282
- hostingKey = GuessKey({
1283
- DBServer: settings.DBServer
1200
+ /**
1201
+ * Performs an HTTP PUT request.
1202
+ * This will prepend the base url to the url.
1203
+ * @param url
1204
+ * @param data
1205
+ * @param params
1206
+ * @returns
1207
+ */
1208
+ PUT(url, data, params) {
1209
+ return __awaiter(this, void 0, void 0, function* () {
1210
+ return new Promise((res, rej) => {
1211
+ this.loadProm.then(() => {
1212
+ const full = this.ConstructUrl({
1213
+ url: url
1214
+ });
1215
+ this.put(full, data, params).then(res).catch(rej);
1216
+ }).catch(rej);
1284
1217
  });
1285
- isLegacy = true;
1286
- }
1287
- return {
1288
- key: hostingKey,
1289
- isLegacy
1290
- };
1291
- });
1292
- }
1293
- HostingLocation.GetKeyByAccountId = GetKeyByAccountId;
1294
- /**
1295
- * Returns a hosting location record by account ID.
1296
- * @param params
1297
- * @returns
1298
- */
1299
- function GetByAccountId(params) {
1300
- return __awaiter(this, void 0, void 0, function* () {
1301
- let { accountId, apiSettings, api, req, account } = params;
1302
- if (!api) {
1303
- api = ENVIRONMENT.Api().GetGuardianApi();
1304
- }
1305
- const data = yield GetKeyByAccountId({
1306
- accountId,
1307
- account,
1308
- apiSettings,
1309
- api,
1310
- req
1311
1218
  });
1312
- if (!(data === null || data === void 0 ? void 0 : data.key)) {
1313
- return null;
1314
- }
1315
- const key = yield GetByKey({
1316
- key: data.key,
1317
- api,
1318
- req
1219
+ }
1220
+ /**
1221
+ * Performs a file upload request (HTTP POST).
1222
+ * This will prepend the base url to the url.
1223
+ * @param url
1224
+ * @param blob
1225
+ * @param params
1226
+ * @returns
1227
+ */
1228
+ UPLOAD(url, blob, params) {
1229
+ return __awaiter(this, void 0, void 0, function* () {
1230
+ return new Promise((res, rej) => {
1231
+ this.loadProm.then(() => {
1232
+ const full = this.ConstructUrl({
1233
+ url: url
1234
+ });
1235
+ this.upload(full, blob, params).then(res).catch(rej);
1236
+ }).catch(rej);
1237
+ });
1319
1238
  });
1320
- return key;
1321
- });
1239
+ }
1322
1240
  }
1323
- HostingLocation.GetByAccountId = GetByAccountId;
1324
- })(HostingLocation || (HostingLocation = {}));
1241
+ BruceApi$$1.Api = Api$$1;
1242
+ })(BruceApi || (BruceApi = {}));
1325
1243
 
1326
1244
  /**
1327
- * The primary API for communication with Nextspace.
1328
- * This API is used to manage your data.
1245
+ * This is the request handler for Global Api,
1246
+ * The global api is used to store information that is higher level than client accounts.
1247
+ * For example it will store usage records, client account group settings, data sharing settings, etc.
1329
1248
  */
1330
- var BruceApi;
1331
- (function (BruceApi$$1) {
1332
- /**
1333
- * This is the request handler for Bruce Api,
1334
- * it should be passed to any method that wants to communicate with this particular api.
1335
- */
1249
+ var GlobalApi;
1250
+ (function (GlobalApi) {
1336
1251
  class Api$$1 extends AbstractApi {
1337
- get AccountId() {
1338
- return this.accountId;
1339
- }
1340
- get MessageBroker() {
1341
- return this.messageBroker;
1342
- }
1343
- get ConfigLoadAttempted() {
1344
- return this.configLoadAttempted;
1345
- }
1346
- get Version() {
1347
- return this.version;
1348
- }
1349
- get Loading() {
1350
- return this.loadProm;
1351
- }
1352
1252
  constructor(params) {
1353
1253
  super({
1354
1254
  ssidHeader: "x-sessionid",
1355
- cacheId: `BRUCE_API_${params === null || params === void 0 ? void 0 : params.env}_${params === null || params === void 0 ? void 0 : params.accountId}_`
1255
+ cacheId: `GLOBAL_API_${params === null || params === void 0 ? void 0 : params.env}_`
1356
1256
  });
1357
- // Load cancelled indicates the user set a custom base url.
1358
- // This will stop the regional url from being set if it's still loading.
1359
- this.loadCancelled = false;
1360
- // Indicates if loading the regional configuration was already called.
1361
- this.configLoadAttempted = false;
1362
- let { accountId, env, guardian, loadRegionalBaseUrl, loadConfig, loadWebSocket, dummy } = params;
1363
- this.accountId = accountId;
1364
- this.env = env !== null && env !== void 0 ? env : Api.EEnv.PROD;
1365
- if (!dummy) {
1366
- // Backwards compatibility.
1367
- if (loadRegionalBaseUrl) {
1368
- loadConfig = true;
1369
- }
1370
- if (loadConfig) {
1371
- // Mark it as attempted right away because we don't want any external calls while it gets to that async point.
1372
- this.configLoadAttempted = true;
1373
- }
1374
- this.loadProm = this.init(guardian, loadConfig, loadWebSocket);
1375
- }
1257
+ this.env = (params === null || params === void 0 ? void 0 : params.env) ? params.env : Api.EEnv.PROD;
1258
+ this.setBaseUrl();
1376
1259
  }
1377
1260
  /**
1378
- * Loads regional base url and sets up message broker.
1379
- * @param guardian Required for loading regional base url.
1380
- * @param loadConfig
1381
- * @returns
1261
+ * Sets the base url for this api.
1382
1262
  */
1383
- init(guardian, loadConfig, loadWebSocket) {
1384
- return __awaiter(this, void 0, void 0, function* () {
1385
- if (!this.accountId) {
1386
- throw ("accountId is required.");
1387
- }
1388
- // Set using a stable default.
1389
- const domain = this.getDomain();
1390
- this.baseUrl = `https://${this.accountId}.api.${domain}/`;
1391
- // Attempt to load regional configuration.
1392
- if (loadConfig) {
1393
- yield this.LoadConfig({
1394
- guardian: guardian,
1395
- // We marked it as attempted to load outside this method to fight any external calls.
1396
- // So we'll force load it now.
1397
- forceLoad: true
1398
- });
1399
- }
1400
- // Get the version.
1401
- if (this.baseUrl) {
1402
- const data = yield this.get(this.baseUrl + "version");
1403
- if (data === null || data === void 0 ? void 0 : data["Bruce-API"]) {
1404
- this.version = data["Bruce-API"];
1405
- }
1406
- else {
1407
- this.version = "UNKNOWN";
1408
- }
1409
- }
1410
- // Start web socket connection.
1411
- if (loadWebSocket == true) {
1412
- try {
1413
- this.messageBroker = new MessageBroker.WebSocketBroker(this.baseUrl, this.env);
1414
- }
1415
- catch (e) {
1416
- console.warn("BruceApi: Failed to create message broker.", e);
1417
- }
1418
- }
1419
- });
1420
- }
1421
- getDomain() {
1263
+ setBaseUrl() {
1264
+ let url;
1422
1265
  const env = this.env.toUpperCase();
1423
- let domain = "nextspace.host";
1424
1266
  switch (env) {
1425
1267
  case Api.EEnv.DEV:
1426
- domain = "nextspace-dev.net";
1268
+ url = "https://bruceglobal.nextspace-dev.net/";
1427
1269
  break;
1428
1270
  case Api.EEnv.STG:
1429
- domain = "nextspace-stg.net";
1271
+ url = "https://bruceglobal.nextspace-stg.net/";
1430
1272
  break;
1431
1273
  case Api.EEnv.UAT:
1432
- domain = "nextspace-uat.net";
1274
+ url = "https://bruceglobal.api.nextspace-uat.net/";
1433
1275
  break;
1434
1276
  case Api.EEnv.PROD:
1435
- domain = "nextspace.host";
1277
+ url = "https://bruceglobal.api.nextspace.host/";
1436
1278
  break;
1437
1279
  default:
1438
- console.error("Specified Environment is not valid. SuppliedEnv=" + env);
1280
+ throw ("Specified Environment is not valid. SuppliedEnv=" + env);
1439
1281
  }
1440
- return domain;
1441
- }
1442
- /**
1443
- * Loads the regional configuration for the account.
1444
- * If the config is already loaded then this will do nothing.
1445
- */
1446
- LoadConfig(params) {
1447
- var _a, _b, _c;
1448
- return __awaiter(this, void 0, void 0, function* () {
1449
- let { guardian, forceLoad } = (params !== null && params !== void 0 ? params : {});
1450
- if (this.configLoadAttempted && forceLoad != true) {
1451
- return;
1452
- }
1453
- this.configLoadAttempted = true;
1454
- try {
1455
- if (!guardian) {
1456
- guardian = new GuardianApi.Api({
1457
- env: this.env
1458
- });
1459
- }
1460
- const { account } = yield Account.GetBySubdomain({
1461
- subdomain: this.accountId,
1462
- api: guardian
1463
- });
1464
- // Precalculated URLs exist.
1465
- // Soon this will be a stable requirement for any account record.
1466
- if (account.URL) {
1467
- if (!this.loadCancelled) {
1468
- const urls = account.URL;
1469
- if (urls === null || urls === void 0 ? void 0 : urls.Base) {
1470
- this.baseUrl = urls.Base;
1471
- }
1472
- if (urls === null || urls === void 0 ? void 0 : urls.CDNEntities) {
1473
- this.EntityCdnUrl = urls.CDNEntities;
1474
- }
1475
- if (urls === null || urls === void 0 ? void 0 : urls.CDNTileset) {
1476
- this.TilesetCdnUrl = urls.CDNTileset;
1477
- }
1478
- if (urls === null || urls === void 0 ? void 0 : urls.CDNLegacyTileset) {
1479
- this.LegacyTilesetCdnUrl = urls.CDNLegacyTileset;
1480
- }
1481
- if (urls === null || urls === void 0 ? void 0 : urls.CDNBase) {
1482
- this.cdnBaseUrl = urls.CDNBase;
1483
- }
1484
- }
1485
- }
1486
- // Deprecated and will eventually stop working at all.
1487
- else {
1488
- const env = this.env.toUpperCase();
1489
- const domain = this.getDomain();
1490
- const host = yield HostingLocation.GetByAccountId({
1491
- accountId: this.accountId,
1492
- api: guardian
1493
- });
1494
- if (host === null || host === void 0 ? void 0 : host.location) {
1495
- const settings = host.location.Settings;
1496
- if (!this.loadCancelled) {
1497
- // Attempt to load regional base url.
1498
- // First try go through settings.
1499
- let urlSet = false;
1500
- if (settings === null || settings === void 0 ? void 0 : settings.BruceAPIURL) {
1501
- let envUrl = settings.BruceAPIURL[env];
1502
- if (envUrl) {
1503
- envUrl = envUrl
1504
- .replace("<ACCOUNTID>", this.accountId)
1505
- .replace("<ACCOUNT>", this.accountId);
1506
- if (envUrl && envUrl.length > 1) {
1507
- this.baseUrl = envUrl;
1508
- urlSet = true;
1509
- }
1510
- }
1511
- }
1512
- // Try go through host location's base url.
1513
- // This may be wrong env which is why it's used as fallback right now.
1514
- if (!urlSet && host.location.BruceAPIURL) {
1515
- const regionalUrl = host.location.BruceAPIURL
1516
- .replace("<ACCOUNTID>", this.accountId)
1517
- .replace("<ACCOUNT>", this.accountId)
1518
- .replace("<DOMAIN>", domain);
1519
- if (regionalUrl && regionalUrl.length > 1) {
1520
- this.baseUrl = regionalUrl;
1521
- urlSet = true;
1522
- }
1523
- }
1524
- }
1525
- // Attempt to load CDN settings.
1526
- if (settings === null || settings === void 0 ? void 0 : settings.CDN) {
1527
- this.EntityCdnUrl = (_a = settings.CDN.entityURL) === null || _a === void 0 ? void 0 : _a[env];
1528
- // We need to fix our configs.
1529
- if (this.EntityCdnUrl) {
1530
- if (this.EntityCdnUrl.includes("entitiesListForCDN")) {
1531
- this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", this.accountId);
1532
- }
1533
- else {
1534
- this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", "entitiesListForCDN/" + this.accountId);
1535
- }
1536
- }
1537
- this.LegacyTilesetCdnUrl = (_b = settings.CDN.legacyTilesetURL) === null || _b === void 0 ? void 0 : _b[env];
1538
- this.TilesetCdnUrl = (_c = settings.CDN.tilesetURL) === null || _c === void 0 ? void 0 : _c[env];
1539
- if (this.TilesetCdnUrl) {
1540
- this.TilesetCdnUrl = this.TilesetCdnUrl.replace("<ACCOUNT>", this.accountId);
1541
- }
1542
- // TilesetCdnUrl example: "https://blah.cloudfront.net/tilesets/<TILESETID>/files/<FILEPATH>?accountId=<ACCOUNT>".
1543
- // Lazy at the moment to go around updating every region we have, I'll interpret the url from tilesetCdnUrl.
1544
- if (this.TilesetCdnUrl) {
1545
- try {
1546
- const url = new URL(this.TilesetCdnUrl);
1547
- this.cdnBaseUrl = `${url.protocol}//${url.hostname}/`;
1548
- }
1549
- catch (e) {
1550
- console.error(e);
1551
- }
1552
- }
1553
- }
1554
- }
1555
- }
1556
- }
1557
- catch (e) {
1558
- console.error(e);
1559
- }
1560
- });
1561
- }
1562
- /**
1563
- * Creates a message broker instance and returns it.
1564
- * If an instance is already created, it will return that one.
1565
- * @warning This will await the loading promise to avoid using data that isn't ready.
1566
- */
1567
- ConnectWebsocket() {
1568
- return __awaiter(this, void 0, void 0, function* () {
1569
- yield this.loadProm;
1570
- if (this.messageBroker) {
1571
- return this.messageBroker;
1572
- }
1573
- this.messageBroker = new MessageBroker.WebSocketBroker(this.baseUrl, this.env);
1574
- return this.messageBroker;
1575
- });
1282
+ this.baseUrl = url;
1576
1283
  }
1577
1284
  /**
1578
- * Warning: This method does not wait for init to finish loading.
1579
- * This means the url could be changed once fully initialized.
1580
- * The url will be valid either way, but the loaded one may be faster as it is region specific.
1581
- * Await the "Loading" promise if you care about this.
1285
+ * Gets the base url for this api.
1582
1286
  * @returns
1583
1287
  */
1584
1288
  GetBaseUrl() {
1585
1289
  return this.baseUrl;
1586
1290
  }
1587
1291
  /**
1588
- * Warning: Wait the "Loading" promise before using this url.
1589
- * @returns
1590
- */
1591
- GetCdnBaseUrl() {
1592
- return this.cdnBaseUrl;
1593
- }
1594
- /**
1595
- * Returns a url routed through the API's CDN.
1596
- * If the CDN is not enabled for the account, this will return null.
1597
- * @param url suffix to append to the base url.
1598
- * @param urlParams
1599
- * @returns
1600
- */
1601
- ConstructCdnUrl(url, urlParams) {
1602
- if (!this.cdnBaseUrl) {
1603
- return null;
1604
- }
1605
- const tmp = new URL(this.cdnBaseUrl);
1606
- if (urlParams && urlParams instanceof URLSearchParams) {
1607
- urlParams.forEach((value, key) => {
1608
- tmp.searchParams.append(key, value);
1609
- });
1610
- }
1611
- if (url) {
1612
- tmp.pathname += url;
1613
- }
1614
- return tmp.toString();
1615
- }
1616
- /**
1617
- * Warning: This will cancel the init process.
1618
- * The init process loads a region specific endpoint.
1619
- * Setting a base url will stop that process from completing.
1292
+ * Sets the base url for this api.
1620
1293
  * @param url
1621
1294
  */
1622
1295
  SetBaseUrl(url) {
@@ -1624,7 +1297,6 @@ var BruceApi;
1624
1297
  if (!this.baseUrl.endsWith("/")) {
1625
1298
  this.baseUrl += "/";
1626
1299
  }
1627
- this.loadCancelled = true;
1628
1300
  }
1629
1301
  /**
1630
1302
  * Performs an HTTP GET request.
@@ -1635,11 +1307,7 @@ var BruceApi;
1635
1307
  */
1636
1308
  GET(url, params) {
1637
1309
  return __awaiter(this, void 0, void 0, function* () {
1638
- return new Promise((res, rej) => {
1639
- this.loadProm.then(() => {
1640
- this.get(this.baseUrl + url, params).then(res).catch(rej);
1641
- }).catch(rej);
1642
- });
1310
+ return this.get(this.baseUrl + url, params);
1643
1311
  });
1644
1312
  }
1645
1313
  /**
@@ -1651,11 +1319,7 @@ var BruceApi;
1651
1319
  */
1652
1320
  DELETE(url, params) {
1653
1321
  return __awaiter(this, void 0, void 0, function* () {
1654
- return new Promise((res, rej) => {
1655
- this.loadProm.then(() => {
1656
- this.delete(this.baseUrl + url, params).then(res).catch(rej);
1657
- }).catch(rej);
1658
- });
1322
+ return this.delete(this.baseUrl + url, params);
1659
1323
  });
1660
1324
  }
1661
1325
  /**
@@ -1668,28 +1332,7 @@ var BruceApi;
1668
1332
  */
1669
1333
  POST(url, data, params) {
1670
1334
  return __awaiter(this, void 0, void 0, function* () {
1671
- return new Promise((res, rej) => {
1672
- this.loadProm.then(() => {
1673
- this.post(this.baseUrl + url, data, params).then(res).catch(rej);
1674
- }).catch(rej);
1675
- });
1676
- });
1677
- }
1678
- /**
1679
- * Performs an HTTP PUT request.
1680
- * This will prepend the base url to the url.
1681
- * @param url
1682
- * @param data
1683
- * @param params
1684
- * @returns
1685
- */
1686
- PUT(url, data, params) {
1687
- return __awaiter(this, void 0, void 0, function* () {
1688
- return new Promise((res, rej) => {
1689
- this.loadProm.then(() => {
1690
- this.put(this.baseUrl + url, data, params).then(res).catch(rej);
1691
- }).catch(rej);
1692
- });
1335
+ return this.post(this.baseUrl + url, data, params);
1693
1336
  });
1694
1337
  }
1695
1338
  /**
@@ -1702,146 +1345,31 @@ var BruceApi;
1702
1345
  */
1703
1346
  UPLOAD(url, blob, params) {
1704
1347
  return __awaiter(this, void 0, void 0, function* () {
1705
- return new Promise((res, rej) => {
1706
- this.loadProm.then(() => {
1707
- this.upload(this.baseUrl + url, blob, params).then(res).catch(rej);
1708
- }).catch(rej);
1709
- });
1348
+ return this.upload(this.baseUrl + url, blob, params);
1710
1349
  });
1711
1350
  }
1712
1351
  }
1713
- BruceApi$$1.Api = Api$$1;
1714
- })(BruceApi || (BruceApi = {}));
1352
+ GlobalApi.Api = Api$$1;
1353
+ })(GlobalApi || (GlobalApi = {}));
1715
1354
 
1716
1355
  /**
1717
- * This is the request handler for Global Api,
1718
- * The global api is used to store information that is higher level than client accounts.
1719
- * For example it will store usage records, client account group settings, data sharing settings, etc.
1720
- */
1721
- var GlobalApi;
1722
- (function (GlobalApi) {
1723
- class Api$$1 extends AbstractApi {
1724
- constructor(params) {
1725
- super({
1726
- ssidHeader: "x-sessionid",
1727
- cacheId: `GLOBAL_API_${params === null || params === void 0 ? void 0 : params.env}_`
1728
- });
1729
- this.env = (params === null || params === void 0 ? void 0 : params.env) ? params.env : Api.EEnv.PROD;
1730
- this.setBaseUrl();
1731
- }
1732
- /**
1733
- * Sets the base url for this api.
1734
- */
1735
- setBaseUrl() {
1736
- let url;
1737
- const env = this.env.toUpperCase();
1738
- switch (env) {
1739
- case Api.EEnv.DEV:
1740
- url = "https://bruceglobal.nextspace-dev.net/";
1741
- break;
1742
- case Api.EEnv.STG:
1743
- url = "https://bruceglobal.nextspace-stg.net/";
1744
- break;
1745
- case Api.EEnv.UAT:
1746
- url = "https://bruceglobal.api.nextspace-uat.net/";
1747
- break;
1748
- case Api.EEnv.PROD:
1749
- url = "https://bruceglobal.api.nextspace.host/";
1750
- break;
1751
- default:
1752
- throw ("Specified Environment is not valid. SuppliedEnv=" + env);
1753
- }
1754
- this.baseUrl = url;
1755
- }
1756
- /**
1757
- * Gets the base url for this api.
1758
- * @returns
1759
- */
1760
- GetBaseUrl() {
1761
- return this.baseUrl;
1762
- }
1763
- /**
1764
- * Sets the base url for this api.
1765
- * @param url
1766
- */
1767
- SetBaseUrl(url) {
1768
- this.baseUrl = url;
1769
- if (!this.baseUrl.endsWith("/")) {
1770
- this.baseUrl += "/";
1771
- }
1772
- }
1773
- /**
1774
- * Performs an HTTP GET request.
1775
- * This will prepend the base url to the url.
1776
- * @param url
1777
- * @param params
1778
- * @returns
1779
- */
1780
- GET(url, params) {
1781
- return __awaiter(this, void 0, void 0, function* () {
1782
- return this.get(this.baseUrl + url, params);
1783
- });
1784
- }
1785
- /**
1786
- * Performs an HTTP DELETE request.
1787
- * This will prepend the base url to the url.
1788
- * @param url
1789
- * @param params
1790
- * @returns
1791
- */
1792
- DELETE(url, params) {
1793
- return __awaiter(this, void 0, void 0, function* () {
1794
- return this.delete(this.baseUrl + url, params);
1795
- });
1796
- }
1797
- /**
1798
- * Performs an HTTP POST request.
1799
- * This will prepend the base url to the url.
1800
- * @param url
1801
- * @param data
1802
- * @param params
1803
- * @returns
1804
- */
1805
- POST(url, data, params) {
1806
- return __awaiter(this, void 0, void 0, function* () {
1807
- return this.post(this.baseUrl + url, data, params);
1808
- });
1809
- }
1810
- /**
1811
- * Performs a file upload request (HTTP POST).
1812
- * This will prepend the base url to the url.
1813
- * @param url
1814
- * @param blob
1815
- * @param params
1816
- * @returns
1817
- */
1818
- UPLOAD(url, blob, params) {
1819
- return __awaiter(this, void 0, void 0, function* () {
1820
- return this.upload(this.baseUrl + url, blob, params);
1821
- });
1822
- }
1823
- }
1824
- GlobalApi.Api = Api$$1;
1825
- })(GlobalApi || (GlobalApi = {}));
1826
-
1827
- /**
1828
- * Utility for managing multiple API instances.
1829
- * Example: {
1830
- * const api = new ApiGetters({
1831
- * accountId: "123",
1832
- * env: Api.EEnv.PROD
1833
- * });
1834
- *
1835
- * // Returns default API instance specified in constructor.
1836
- * const bruce1 = api.GetBruceApi();
1837
- * // Returns API instance for account 456.
1838
- * const bruce2 = api.GetBruceApi({
1839
- * accountId: "456"
1840
- * });
1841
- *
1842
- * const global = api.GetGlobalApi();
1843
- * const guardian = api.GetGuardianApi();
1844
- * }
1356
+ * Utility for managing multiple API instances.
1357
+ * Example: {
1358
+ * const api = new ApiGetters({
1359
+ * accountId: "123",
1360
+ * env: Api.EEnv.PROD
1361
+ * });
1362
+ *
1363
+ * // Returns default API instance specified in constructor.
1364
+ * const bruce1 = api.GetBruceApi();
1365
+ * // Returns API instance for account 456.
1366
+ * const bruce2 = api.GetBruceApi({
1367
+ * accountId: "456"
1368
+ * });
1369
+ *
1370
+ * const global = api.GetGlobalApi();
1371
+ * const guardian = api.GetGuardianApi();
1372
+ * }
1845
1373
  */
1846
1374
  class ApiGetters {
1847
1375
  constructor(params) {
@@ -4219,17 +3747,7 @@ var Entity;
4219
3747
  let totalCount;
4220
3748
  let entities = [];
4221
3749
  if (analysis || expandRelations || (viaCdn && api.GetCdnBaseUrl())) {
4222
- let url;
4223
- if (analysis) {
4224
- url = new URL(api.GetBaseUrl() + "entities/summary");
4225
- }
4226
- else if (viaCdn && api.GetCdnBaseUrl()) {
4227
- url = new URL(api.ConstructCdnUrl("entities"));
4228
- }
4229
- else {
4230
- url = new URL(api.GetBaseUrl() + "entities");
4231
- }
4232
- const urlParams = url.searchParams;
3750
+ const urlParams = new URLSearchParams();
4233
3751
  urlParams.set("cacheToken", String(viaCdnCacheToken ? viaCdnCacheToken : 0));
4234
3752
  if (body.SortOrder) {
4235
3753
  urlParams.set("SortOrder", body.SortOrder);
@@ -4277,7 +3795,11 @@ var Entity;
4277
3795
  urlParams.set("schema", schemaId);
4278
3796
  }
4279
3797
  urlParams.set("hasMigrated", String(Boolean(migrated)));
4280
- const urlStr = url.toString();
3798
+ const urlStr = api.ConstructUrl({
3799
+ cdn: !analysis && viaCdn,
3800
+ url: analysis ? "entities/summary" : "entities",
3801
+ urlParams: urlParams
3802
+ });
4281
3803
  const data = yield api.get(urlStr, Api.PrepReqParams(reqParams));
4282
3804
  if (!analysis) {
4283
3805
  entities = data.Items;
@@ -4285,8 +3807,7 @@ var Entity;
4285
3807
  totalCount = data.TotalCount;
4286
3808
  }
4287
3809
  else {
4288
- const url = new URL(api.GetBaseUrl() + (analysis ? "entities/summary" : "entities"));
4289
- const urlParams = url.searchParams;
3810
+ const urlParams = new URLSearchParams();
4290
3811
  if (expandRelations) {
4291
3812
  urlParams.append("$expand", "relation");
4292
3813
  }
@@ -4297,7 +3818,11 @@ var Entity;
4297
3818
  urlParams.set("schema", schemaId);
4298
3819
  }
4299
3820
  urlParams.set("hasMigrated", String(Boolean(migrated)));
4300
- const urlStr = url.toString();
3821
+ const urlStr = api.ConstructUrl({
3822
+ cdn: false,
3823
+ url: analysis ? "entities/summary" : "entities",
3824
+ urlParams: urlParams
3825
+ });
4301
3826
  const data = yield api.post(urlStr, body, Api.PrepReqParams(reqParams));
4302
3827
  if (!analysis) {
4303
3828
  entities = data.Items;
@@ -6215,12 +5740,13 @@ var EntityLod;
6215
5740
  if (!level) {
6216
5741
  level = 0;
6217
5742
  }
6218
- let url = api.GetBaseUrl() + `entity/${entityId}/lod/${categoryId}/${level}`;
6219
- if (strict) {
6220
- url = url + "?strict=true";
6221
- }
6222
5743
  return {
6223
- url: url
5744
+ url: api.ConstructUrl({
5745
+ url: `entity/${entityId}/lod/${categoryId}/${level}`,
5746
+ urlParams: {
5747
+ "strict": strict ? "true" : "false"
5748
+ }
5749
+ })
6224
5750
  };
6225
5751
  }
6226
5752
  EntityLod.GetUrl = GetUrl;
@@ -8424,13 +7950,13 @@ var Uploader;
8424
7950
  * A client file is a record of a file uploaded to Bruce.
8425
7951
  */
8426
7952
  var ClientFile;
8427
- (function (ClientFile$$1) {
7953
+ (function (ClientFile) {
8428
7954
  let EPurpose;
8429
7955
  (function (EPurpose) {
8430
7956
  // Use this purpose for uploading bookmark thumbnail images.
8431
7957
  // This will allow lower level privileges to upload (small) bookmark thumbnails.
8432
7958
  EPurpose["BookmarkThumbnail"] = "Bookmark Thumbnail";
8433
- })(EPurpose = ClientFile$$1.EPurpose || (ClientFile$$1.EPurpose = {}));
7959
+ })(EPurpose = ClientFile.EPurpose || (ClientFile.EPurpose = {}));
8434
7960
  /**
8435
7961
  * Returns the URL for a client file.
8436
7962
  * @param params
@@ -8441,17 +7967,16 @@ var ClientFile;
8441
7967
  if (!api) {
8442
7968
  api = ENVIRONMENT.Api().GetBruceApi();
8443
7969
  }
8444
- const urlSuffix = `file/${fileId}`;
8445
- const cdnUrl = viaCdn ? api.ConstructCdnUrl(urlSuffix) : null;
8446
- if (cdnUrl) {
8447
- return cdnUrl;
8448
- }
8449
- let url = `${api.GetBaseUrl()}${urlSuffix}`;
8450
- // Invalidating cache manually because we have a wave of invalid headers now cached across devices.
8451
- url = UrlUtils.AddQueryParam(url, "cc", "1");
8452
- return url;
7970
+ return api.ConstructUrl({
7971
+ cdn: viaCdn,
7972
+ url: `file/${fileId}`,
7973
+ urlParams: {
7974
+ // Invalidating cache manually because we have a wave of invalid headers now cached across devices.
7975
+ cc: "1"
7976
+ }
7977
+ });
8453
7978
  }
8454
- ClientFile$$1.GetUrl = GetUrl;
7979
+ ClientFile.GetUrl = GetUrl;
8455
7980
  /**
8456
7981
  * Returns the URL for a client file with the extension.
8457
7982
  * @param params
@@ -8470,16 +7995,16 @@ var ClientFile;
8470
7995
  ext = "." + ext;
8471
7996
  }
8472
7997
  const urlSuffix = ext ? `file/${file.ID}${ext}` : `file/${file.ID}`;
8473
- const cdnUrl = viaCdn ? api.ConstructCdnUrl(urlSuffix) : null;
8474
- if (cdnUrl) {
8475
- return cdnUrl;
8476
- }
8477
- let url = `${api.GetBaseUrl()}${urlSuffix}`;
8478
- // Invalidating cache manually because we have a wave of invalid headers now cached across devices.
8479
- url = UrlUtils.AddQueryParam(url, "cc", "1");
8480
- return url;
7998
+ return api.ConstructUrl({
7999
+ cdn: viaCdn,
8000
+ url: urlSuffix,
8001
+ urlParams: {
8002
+ // Invalidating cache manually because we have a wave of invalid headers now cached across devices.
8003
+ cc: "1"
8004
+ }
8005
+ });
8481
8006
  }
8482
- ClientFile$$1.GetUrlWithExt = GetUrlWithExt;
8007
+ ClientFile.GetUrlWithExt = GetUrlWithExt;
8483
8008
  /**
8484
8009
  * Returns a client file record by ID.
8485
8010
  * @param params
@@ -8518,7 +8043,7 @@ var ClientFile;
8518
8043
  return prom;
8519
8044
  });
8520
8045
  }
8521
- ClientFile$$1.Get = Get;
8046
+ ClientFile.Get = Get;
8522
8047
  /**
8523
8048
  * Deletes one or many client file records by IDs.
8524
8049
  * @param params
@@ -8542,7 +8067,7 @@ var ClientFile;
8542
8067
  }
8543
8068
  });
8544
8069
  }
8545
- ClientFile$$1.Delete = Delete;
8070
+ ClientFile.Delete = Delete;
8546
8071
  /**
8547
8072
  * Uploads a file and creates a new client file record.
8548
8073
  * @param params
@@ -8605,7 +8130,7 @@ var ClientFile;
8605
8130
  };
8606
8131
  });
8607
8132
  }
8608
- ClientFile$$1.Upload = Upload;
8133
+ ClientFile.Upload = Upload;
8609
8134
  /**
8610
8135
  * Updates the purpose of a client file.
8611
8136
  * @param params
@@ -8626,7 +8151,7 @@ var ClientFile;
8626
8151
  api.Cache.RemoveByContains(cacheKey);
8627
8152
  });
8628
8153
  }
8629
- ClientFile$$1.UpdatePurpose = UpdatePurpose;
8154
+ ClientFile.UpdatePurpose = UpdatePurpose;
8630
8155
  /**
8631
8156
  * Uploads a temp file.
8632
8157
  * This will return a temp file ID.
@@ -8676,7 +8201,7 @@ var ClientFile;
8676
8201
  };
8677
8202
  });
8678
8203
  }
8679
- ClientFile$$1.UploadTemp = UploadTemp;
8204
+ ClientFile.UploadTemp = UploadTemp;
8680
8205
  /**
8681
8206
  * Returns a dictionary of purpose counts for client files.
8682
8207
  * @param params
@@ -8715,7 +8240,7 @@ var ClientFile;
8715
8240
  return prom;
8716
8241
  });
8717
8242
  }
8718
- ClientFile$$1.GetCountsPurpose = GetCountsPurpose;
8243
+ ClientFile.GetCountsPurpose = GetCountsPurpose;
8719
8244
  /**
8720
8245
  * Returns a dictionary of MIME type counts for client files.
8721
8246
  * @param params
@@ -8754,7 +8279,7 @@ var ClientFile;
8754
8279
  return prom;
8755
8280
  });
8756
8281
  }
8757
- ClientFile$$1.GetCountsExtension = GetCountsExtension;
8282
+ ClientFile.GetCountsExtension = GetCountsExtension;
8758
8283
  /**
8759
8284
  * Returns a dictionary of MIME type counts for client files.
8760
8285
  * @param params
@@ -8793,7 +8318,7 @@ var ClientFile;
8793
8318
  return prom;
8794
8319
  });
8795
8320
  }
8796
- ClientFile$$1.GetCountsMIMEType = GetCountsMIMEType;
8321
+ ClientFile.GetCountsMIMEType = GetCountsMIMEType;
8797
8322
  /**
8798
8323
  * Returns a dictionary of user counts for client files.
8799
8324
  * @param params
@@ -8832,7 +8357,7 @@ var ClientFile;
8832
8357
  return prom;
8833
8358
  });
8834
8359
  }
8835
- ClientFile$$1.GetCountsUser = GetCountsUser;
8360
+ ClientFile.GetCountsUser = GetCountsUser;
8836
8361
  /**
8837
8362
  * Filter definitions for requesting a list of client files.
8838
8363
  */
@@ -8858,7 +8383,7 @@ var ClientFile;
8858
8383
  ERowOperator["AND"] = "AND";
8859
8384
  ERowOperator["OR"] = "OR";
8860
8385
  })(ERowOperator = Filter.ERowOperator || (Filter.ERowOperator = {}));
8861
- })(Filter = ClientFile$$1.Filter || (ClientFile$$1.Filter = {}));
8386
+ })(Filter = ClientFile.Filter || (ClientFile.Filter = {}));
8862
8387
  /**
8863
8388
  * Returns a list of client files matching the filter.
8864
8389
  * @param params
@@ -8877,7 +8402,7 @@ var ClientFile;
8877
8402
  };
8878
8403
  });
8879
8404
  }
8880
- ClientFile$$1.GetList = GetList;
8405
+ ClientFile.GetList = GetList;
8881
8406
  /**
8882
8407
  * Deletes a list of client files matching the filter.
8883
8408
  * @param params
@@ -8899,7 +8424,7 @@ var ClientFile;
8899
8424
  };
8900
8425
  });
8901
8426
  }
8902
- ClientFile$$1.DeleteList = DeleteList;
8427
+ ClientFile.DeleteList = DeleteList;
8903
8428
  /**
8904
8429
  * Utility for processing client files.
8905
8430
  * Commonly used to convert a file to a different format. Eg: FBX to GLB.
@@ -8936,7 +8461,7 @@ var ClientFile;
8936
8461
  });
8937
8462
  }
8938
8463
  Processor.ConvertFormat = ConvertFormat;
8939
- })(Processor = ClientFile$$1.Processor || (ClientFile$$1.Processor = {}));
8464
+ })(Processor = ClientFile.Processor || (ClientFile.Processor = {}));
8940
8465
  /**
8941
8466
  * Returns cache identifier for a client file by ID.
8942
8467
  * Example: {
@@ -8950,23 +8475,23 @@ var ClientFile;
8950
8475
  function GetCacheKey(fileId) {
8951
8476
  return `${Api.ECacheKey.ClientFile}${Api.ECacheKey.Id}${fileId}`;
8952
8477
  }
8953
- ClientFile$$1.GetCacheKey = GetCacheKey;
8478
+ ClientFile.GetCacheKey = GetCacheKey;
8954
8479
  function GetCountsPurposeCacheKey() {
8955
8480
  return `${Api.ECacheKey.ClientFile}${Api.ECacheKey.ClientFileCountsPurpose}`;
8956
8481
  }
8957
- ClientFile$$1.GetCountsPurposeCacheKey = GetCountsPurposeCacheKey;
8482
+ ClientFile.GetCountsPurposeCacheKey = GetCountsPurposeCacheKey;
8958
8483
  function GetCountsExtensionCacheKey() {
8959
8484
  return `${Api.ECacheKey.ClientFile}${Api.ECacheKey.ClientFileCountsExtension}`;
8960
8485
  }
8961
- ClientFile$$1.GetCountsExtensionCacheKey = GetCountsExtensionCacheKey;
8486
+ ClientFile.GetCountsExtensionCacheKey = GetCountsExtensionCacheKey;
8962
8487
  function GetCountsMIMETypeCacheKey() {
8963
8488
  return `${Api.ECacheKey.ClientFile}${Api.ECacheKey.ClientFileCountsMIMEType}`;
8964
8489
  }
8965
- ClientFile$$1.GetCountsMIMETypeCacheKey = GetCountsMIMETypeCacheKey;
8490
+ ClientFile.GetCountsMIMETypeCacheKey = GetCountsMIMETypeCacheKey;
8966
8491
  function GetCountsUserCacheKey() {
8967
8492
  return `${Api.ECacheKey.ClientFile}${Api.ECacheKey.ClientFileCountsUser}`;
8968
8493
  }
8969
- ClientFile$$1.GetCountsUserCacheKey = GetCountsUserCacheKey;
8494
+ ClientFile.GetCountsUserCacheKey = GetCountsUserCacheKey;
8970
8495
  })(ClientFile || (ClientFile = {}));
8971
8496
 
8972
8497
  /**
@@ -8988,6 +8513,10 @@ var ProgramKey;
8988
8513
  EProgramId["Mapbox"] = "Mapbox";
8989
8514
  // Google Maps key. Used for Google Maps 3D tileset for CesiumJS and Unreal.
8990
8515
  EProgramId["Google"] = "Google";
8516
+ // Stadiamaps key. Used for watercolor and toner
8517
+ EProgramId["StadiaMaps"] = "StadiaMaps";
8518
+ // Thunderforest key, Used for cycle and transport and landscape
8519
+ EProgramId["Thunderforest"] = "Thunderforest";
8991
8520
  })(EProgramId = ProgramKey.EProgramId || (ProgramKey.EProgramId = {}));
8992
8521
  /**
8993
8522
  * Returns a program key record.
@@ -9614,23 +9143,13 @@ var Tileset;
9614
9143
  if (!file) {
9615
9144
  file = "";
9616
9145
  }
9617
- let url = null;
9618
- const cdnBaseUrl = viaCdn ? api.GetCdnBaseUrl() : null;
9619
- if (cdnBaseUrl) {
9620
- url = `v3/tilesets/${tilesetId}/files/${legacy ? "" : "files/"}${file}`;
9621
- const urlParams = new URLSearchParams();
9622
- if (cacheToken != null) {
9623
- urlParams.append("cacheToken", String(cacheToken));
9624
- }
9625
- url = api.ConstructCdnUrl(url, urlParams);
9626
- }
9627
- else {
9628
- url = api.GetBaseUrl() + `v3/tilesets/${tilesetId}/files/${legacy ? "" : "files/"}${file}`;
9629
- if (cacheToken != null) {
9630
- url += `?cacheToken=${cacheToken}`;
9146
+ return api.ConstructUrl({
9147
+ cdn: viaCdn,
9148
+ url: `v3/tilesets/${tilesetId}/files/${legacy ? "" : "files/"}${file}`,
9149
+ urlParams: {
9150
+ "cacheToken": String(cacheToken ? cacheToken : 0)
9631
9151
  }
9632
- }
9633
- return url;
9152
+ });
9634
9153
  }
9635
9154
  Tileset$$1.GetFileUrl = GetFileUrl;
9636
9155
  /**
@@ -9649,7 +9168,9 @@ var Tileset;
9649
9168
  if (!file) {
9650
9169
  file = "";
9651
9170
  }
9652
- return api.GetBaseUrl() + `tileset/getFile/${tilesetId}/src/${file}`;
9171
+ return api.ConstructUrl({
9172
+ url: `tileset/getFile/${tilesetId}/src/${file}`
9173
+ });
9653
9174
  }
9654
9175
  Tileset$$1.GetSrcFileUrl = GetSrcFileUrl;
9655
9176
  /**
@@ -9669,16 +9190,13 @@ var Tileset;
9669
9190
  if (!file) {
9670
9191
  file = "";
9671
9192
  }
9672
- const cdnBaseUrl = viaCdn ? api.GetCdnBaseUrl() : null;
9673
- if (cdnBaseUrl) {
9674
- if (!viaCdnCacheToken) {
9675
- viaCdnCacheToken = 0;
9193
+ return api.ConstructUrl({
9194
+ cdn: viaCdn,
9195
+ url: `tileset/file/${tilesetId}/${file}`,
9196
+ urlParams: {
9197
+ "cacheToken": String(viaCdnCacheToken ? viaCdnCacheToken : 0)
9676
9198
  }
9677
- const urlParams = new URLSearchParams();
9678
- urlParams.append("cacheToken", String(viaCdnCacheToken));
9679
- return api.ConstructCdnUrl(`tileset/file/${tilesetId}/${file}`, urlParams);
9680
- }
9681
- return api.GetBaseUrl() + `tileset/file/${tilesetId}/${file}`;
9199
+ });
9682
9200
  }
9683
9201
  Tileset$$1.GetPublicFileUrl = GetPublicFileUrl;
9684
9202
  /**
@@ -10016,203 +9534,881 @@ var MenuItem;
10016
9534
  }
10017
9535
  MenuItem.CreateFromEntityId = CreateFromEntityId;
10018
9536
  /**
10019
- * Creates a menu item for an entity type.
10020
- * @param typeId
10021
- * @param styleId
10022
- * @returns
9537
+ * Creates a menu item for an entity type.
9538
+ * @param typeId
9539
+ * @param styleId
9540
+ * @returns
9541
+ */
9542
+ function CreateFromTypeId(typeId, styleId) {
9543
+ return {
9544
+ id: ObjectUtils.UId(),
9545
+ Type: EType.Entities,
9546
+ Caption: "Generated Entity Type Menu Item",
9547
+ BruceEntity: {
9548
+ "EntityType.ID": typeId
9549
+ },
9550
+ CameraZoomSettings: [
9551
+ {
9552
+ DisplayType: ZoomControl.EDisplayType.Model3D,
9553
+ MaxZoom: 100000,
9554
+ MinZoom: 0,
9555
+ StyleID: styleId
9556
+ }
9557
+ ]
9558
+ };
9559
+ }
9560
+ MenuItem.CreateFromTypeId = CreateFromTypeId;
9561
+ /**
9562
+ * Creates a menu item for a tileset.
9563
+ * @param tilesetId
9564
+ * @param type
9565
+ * @returns
9566
+ */
9567
+ function CreateFromTilesetId(tilesetId, type) {
9568
+ if (type === Tileset.EType.Cad) {
9569
+ return {
9570
+ id: ObjectUtils.UId(),
9571
+ Type: EType.CadTileset,
9572
+ Caption: "Generated CAD Menu Item",
9573
+ FlyTo: false,
9574
+ tileset: {
9575
+ TilesetID: tilesetId
9576
+ }
9577
+ };
9578
+ }
9579
+ else if (type == Tileset.EType.EntitiesSet) {
9580
+ return {
9581
+ id: ObjectUtils.UId(),
9582
+ Type: EType.EntityTileset,
9583
+ Caption: "Generated Entities Menu Item",
9584
+ FlyTo: false,
9585
+ tileset: {
9586
+ TilesetID: tilesetId
9587
+ }
9588
+ };
9589
+ }
9590
+ else if (type == Tileset.EType.PointCloud) {
9591
+ return {
9592
+ id: ObjectUtils.UId(),
9593
+ Type: EType.PointCloud,
9594
+ Caption: "Generated Point Cloud Menu Item",
9595
+ FlyTo: false,
9596
+ tileset: {
9597
+ TilesetID: tilesetId
9598
+ }
9599
+ };
9600
+ }
9601
+ else if (type == Tileset.EType.EntitiesMap) {
9602
+ return {
9603
+ id: ObjectUtils.UId(),
9604
+ Type: EType.EntityRaster,
9605
+ Caption: "Generated Entities Menu Item",
9606
+ tileset: {
9607
+ TilesetID: tilesetId
9608
+ }
9609
+ };
9610
+ }
9611
+ throw ("Tileset type not supported.");
9612
+ }
9613
+ MenuItem.CreateFromTilesetId = CreateFromTilesetId;
9614
+ })(MenuItem || (MenuItem = {}));
9615
+
9616
+ /**
9617
+ * Describe the "Project View Bookmark" concept within Nextspace.
9618
+ * This is referred to as "slides" in older code.
9619
+ *
9620
+ * A bookmark is a snapshot of what should be displayed and how in a particular project view.
9621
+ */
9622
+ var ProjectViewBookmark;
9623
+ (function (ProjectViewBookmark) {
9624
+ // This is the expected default version for the DataVersion value.
9625
+ // This value should NOT be changed without looking at our API and seeing what the default value is.
9626
+ ProjectViewBookmark.DEFAULT_DATA_VERSION = 2;
9627
+ /**
9628
+ * Describes the content of a bookmark.
9629
+ * As part of a deal we've been commissioned to create an alternative bookmark type to embed content.
9630
+ */
9631
+ let EContentType;
9632
+ (function (EContentType) {
9633
+ EContentType["WEB_3D"] = "WEB_3D";
9634
+ EContentType["IFRAME"] = "IFRAME";
9635
+ })(EContentType = ProjectViewBookmark.EContentType || (ProjectViewBookmark.EContentType = {}));
9636
+ /**
9637
+ * Gets a bookmark record.
9638
+ * @param params
9639
+ * @returns
9640
+ */
9641
+ function Get(params) {
9642
+ return __awaiter(this, void 0, void 0, function* () {
9643
+ let { api, viewId, bookmarkId, req: reqParams } = params;
9644
+ if (!viewId || !bookmarkId) {
9645
+ throw ("View ID and Bookmark ID are required.");
9646
+ }
9647
+ if (!api) {
9648
+ api = ENVIRONMENT.Api().GetBruceApi();
9649
+ }
9650
+ const key = GetCacheKey(viewId, bookmarkId);
9651
+ const cache = yield api.GetCacheItem(key, reqParams);
9652
+ if (cache === null || cache === void 0 ? void 0 : cache.found) {
9653
+ return cache.data;
9654
+ }
9655
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
9656
+ try {
9657
+ const data = yield api.GET(`ui.view/${viewId}/slide/${bookmarkId}`, Api.PrepReqParams(reqParams));
9658
+ res({
9659
+ bookmark: data
9660
+ });
9661
+ }
9662
+ catch (e) {
9663
+ rej(e);
9664
+ }
9665
+ }));
9666
+ yield api.SetCacheItem({
9667
+ key,
9668
+ value: prom,
9669
+ req: reqParams
9670
+ });
9671
+ return prom;
9672
+ });
9673
+ }
9674
+ ProjectViewBookmark.Get = Get;
9675
+ /**
9676
+ * Deletes a bookmark record.
9677
+ * @param params
9678
+ */
9679
+ function Delete(params) {
9680
+ return __awaiter(this, void 0, void 0, function* () {
9681
+ let { api, viewId, bookmarkId, req: reqParams } = params;
9682
+ if (!viewId || !bookmarkId) {
9683
+ throw ("View ID and Bookmark ID are required.");
9684
+ }
9685
+ if (!api) {
9686
+ api = ENVIRONMENT.Api().GetBruceApi();
9687
+ }
9688
+ yield api.DELETE(`ui.view/${viewId}/slide/${bookmarkId}`, Api.PrepReqParams(reqParams));
9689
+ api.Cache.Remove(GetCacheKey(viewId, bookmarkId));
9690
+ api.Cache.Remove(GetListCacheKey(viewId));
9691
+ });
9692
+ }
9693
+ ProjectViewBookmark.Delete = Delete;
9694
+ /**
9695
+ * Gets a list of bookmark records.
9696
+ * @param params
9697
+ * @returns
9698
+ */
9699
+ function GetList(params) {
9700
+ return __awaiter(this, void 0, void 0, function* () {
9701
+ let { api, viewId, req: reqParams } = params;
9702
+ if (!viewId) {
9703
+ throw ("View ID is required.");
9704
+ }
9705
+ if (!api) {
9706
+ api = ENVIRONMENT.Api().GetBruceApi();
9707
+ }
9708
+ const cache = yield api.GetCacheItem(GetListCacheKey(viewId), reqParams);
9709
+ if (cache === null || cache === void 0 ? void 0 : cache.found) {
9710
+ return cache.data;
9711
+ }
9712
+ const req = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
9713
+ try {
9714
+ const data = yield api.GET(`ui.view/${viewId}/slides`, Api.PrepReqParams(reqParams));
9715
+ const items = data.Items ? data.Items : [];
9716
+ // Cache individual items.
9717
+ // Maybe better to load list cache when getting 1 slide and seeing if it's in there.
9718
+ // WARNING: Right now the data matches, in the future the list may contain a shortened result.
9719
+ for (let i = 0; i < items.length; i++) {
9720
+ const item = items[i];
9721
+ const prom = new Promise((res) => {
9722
+ res({
9723
+ bookmark: item
9724
+ });
9725
+ });
9726
+ yield api.SetCacheItem({
9727
+ key: GetCacheKey(viewId, item.ID),
9728
+ value: prom,
9729
+ req: reqParams
9730
+ });
9731
+ }
9732
+ res({
9733
+ bookmarks: items
9734
+ });
9735
+ }
9736
+ catch (e) {
9737
+ rej(e);
9738
+ }
9739
+ }));
9740
+ yield api.SetCacheItem({
9741
+ key: GetListCacheKey(viewId),
9742
+ value: req,
9743
+ req: reqParams
9744
+ });
9745
+ return req;
9746
+ });
9747
+ }
9748
+ ProjectViewBookmark.GetList = GetList;
9749
+ /**
9750
+ * Creates or updates a bookmark record.
9751
+ * @param params
9752
+ * @returns
9753
+ */
9754
+ function Update(params) {
9755
+ return __awaiter(this, void 0, void 0, function* () {
9756
+ let { api, viewId, bookmark: data, req: reqParams } = params;
9757
+ if (!api) {
9758
+ api = ENVIRONMENT.Api().GetBruceApi();
9759
+ }
9760
+ if (!(data === null || data === void 0 ? void 0 : data.Title)) {
9761
+ data.Title = data.ID;
9762
+ }
9763
+ const res = yield api.POST(`ui.view/${viewId}/slide/${data.ID ? data.ID : ""}`, data, Api.PrepReqParams(reqParams));
9764
+ api.Cache.Remove(GetCacheKey(viewId, data.ID));
9765
+ api.Cache.Remove(GetListCacheKey(viewId));
9766
+ return {
9767
+ bookmark: res
9768
+ };
9769
+ });
9770
+ }
9771
+ ProjectViewBookmark.Update = Update;
9772
+ /**
9773
+ * Sets the order of bookmarks within a project view.
9774
+ * @param params
9775
+ */
9776
+ function SetOrder(params) {
9777
+ return __awaiter(this, void 0, void 0, function* () {
9778
+ let { api, viewId, bookmarkIds, req: reqParams } = params;
9779
+ if (!api) {
9780
+ api = ENVIRONMENT.Api().GetBruceApi();
9781
+ }
9782
+ const reqData = {
9783
+ "UISlide.ID": bookmarkIds,
9784
+ "DisplayOrder.Start": 0
9785
+ };
9786
+ yield api.POST(`ui.view/${viewId}/slides/setOrder`, reqData, Api.PrepReqParams(reqParams));
9787
+ yield api.Cache.RemoveByStartsWith(GetListCacheKey(viewId));
9788
+ });
9789
+ }
9790
+ ProjectViewBookmark.SetOrder = SetOrder;
9791
+ /**
9792
+ * Returns cache identifier for a bookmark.
9793
+ * Example: {
9794
+ * const api: BruceApi.Api = ...;
9795
+ * const key = GetCacheKey("abc", "def");
9796
+ * api.Cache.Remove(key);
9797
+ * }
9798
+ * @param viewId
9799
+ * @param bookmarkId
9800
+ * @returns
9801
+ */
9802
+ function GetCacheKey(viewId, bookmarkId) {
9803
+ return `${Api.ECacheKey.ProjectViewBookmark}${Api.ECacheKey.Id}${viewId}${Api.ECacheKey.Id}${bookmarkId}`;
9804
+ }
9805
+ ProjectViewBookmark.GetCacheKey = GetCacheKey;
9806
+ /**
9807
+ * Returns cache identifier for a list of bookmarks.
9808
+ * Example: {
9809
+ * const api: BruceApi.Api = ...;
9810
+ * const key = GetListCacheKey("abc");
9811
+ * api.Cache.Remove(key);
9812
+ * }
9813
+ * @param viewId
9814
+ * @returns
9815
+ */
9816
+ function GetListCacheKey(viewId) {
9817
+ return `${Api.ECacheKey.ProjectViewBookmark}${Api.ECacheKey.Id}${viewId}`;
9818
+ }
9819
+ ProjectViewBookmark.GetListCacheKey = GetListCacheKey;
9820
+ })(ProjectViewBookmark || (ProjectViewBookmark = {}));
9821
+
9822
+ /**
9823
+ * Describes the "Project View" concept within Nextspace.
9824
+ * A project view is a collection of settings for a visualization application we support.
9825
+ * It will describe what panels to show and how, it will also describe all possible ways data can be displayed.
9826
+ */
9827
+ var ProjectView;
9828
+ (function (ProjectView) {
9829
+ // This is the expected default version for the DataVersion value.
9830
+ // This value should NOT be changed without looking at our API and seeing what the default value is.
9831
+ ProjectView.DEFAULT_DATA_VERSION = 2;
9832
+ // Our Cesium web navigator.
9833
+ ProjectView.TYPE_WEB_3D_NAVIGATOR = "WEB_3D_NAVIGATOR";
9834
+ // Our (currently WIP) 2D web navigator. Also known as our graph viewer.
9835
+ ProjectView.TYPE_WEB_2D_NAVIGATOR = "WEB_2D_NAVIGATOR";
9836
+ // Defaulting to 3D navigator for backwards compatibility.
9837
+ ProjectView.DEFAULT_TYPE = ProjectView.TYPE_WEB_3D_NAVIGATOR;
9838
+ /**
9839
+ * Gets a project view record.
9840
+ * @param params
9841
+ * @returns
9842
+ */
9843
+ function Get(params) {
9844
+ return __awaiter(this, void 0, void 0, function* () {
9845
+ let { api, viewId, req: reqParams } = params;
9846
+ if (!viewId) {
9847
+ throw ("View ID is required.");
9848
+ }
9849
+ if (!api) {
9850
+ api = ENVIRONMENT.Api().GetBruceApi();
9851
+ }
9852
+ const key = GetCacheKey(viewId);
9853
+ const cache = yield api.GetCacheItem(key, reqParams);
9854
+ if (cache === null || cache === void 0 ? void 0 : cache.found) {
9855
+ return cache.data;
9856
+ }
9857
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
9858
+ try {
9859
+ const data = yield api.GET(`ui.view/${viewId}`, Api.PrepReqParams(reqParams));
9860
+ res({
9861
+ view: data
9862
+ });
9863
+ }
9864
+ catch (e) {
9865
+ rej(e);
9866
+ }
9867
+ }));
9868
+ yield api.SetCacheItem({
9869
+ key,
9870
+ value: prom,
9871
+ req: reqParams
9872
+ });
9873
+ return prom;
9874
+ });
9875
+ }
9876
+ ProjectView.Get = Get;
9877
+ /**
9878
+ * Gets a list of project views.
9879
+ * @param params
9880
+ * @returns
9881
+ */
9882
+ function GetList(params) {
9883
+ return __awaiter(this, void 0, void 0, function* () {
9884
+ let { api, req: reqParams, type } = params;
9885
+ if (!api) {
9886
+ api = ENVIRONMENT.Api().GetBruceApi();
9887
+ }
9888
+ const cache = yield api.GetCacheItem(GetListCacheKey(type), reqParams);
9889
+ if (cache === null || cache === void 0 ? void 0 : cache.found) {
9890
+ return cache.data;
9891
+ }
9892
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
9893
+ try {
9894
+ const data = yield api.GET("ui.view/list", Api.PrepReqParams(reqParams));
9895
+ res({
9896
+ views: data.Items
9897
+ });
9898
+ }
9899
+ catch (e) {
9900
+ rej(e);
9901
+ }
9902
+ }));
9903
+ yield api.SetCacheItem({
9904
+ key: GetListCacheKey(type),
9905
+ value: prom,
9906
+ req: reqParams
9907
+ });
9908
+ return prom;
9909
+ });
9910
+ }
9911
+ ProjectView.GetList = GetList;
9912
+ /**
9913
+ * Deletes a project view.
9914
+ * @param params
9915
+ */
9916
+ function Delete(params) {
9917
+ return __awaiter(this, void 0, void 0, function* () {
9918
+ let { api, viewId, req: reqParams } = params;
9919
+ if (!viewId) {
9920
+ throw ("View ID is required.");
9921
+ }
9922
+ if (!api) {
9923
+ api = ENVIRONMENT.Api().GetBruceApi();
9924
+ }
9925
+ yield api.DELETE(`ui.view/${viewId}`, Api.PrepReqParams(reqParams));
9926
+ api.Cache.Remove(GetCacheKey(viewId));
9927
+ api.Cache.RemoveByStartsWith(GetListCacheKey());
9928
+ });
9929
+ }
9930
+ ProjectView.Delete = Delete;
9931
+ /**
9932
+ * Creates or updates a project view.
9933
+ * @param params
9934
+ * @returns
9935
+ */
9936
+ function Update(params) {
9937
+ return __awaiter(this, void 0, void 0, function* () {
9938
+ let { api, view: data, req: reqParams } = params;
9939
+ if (!api) {
9940
+ api = ENVIRONMENT.Api().GetBruceApi();
9941
+ }
9942
+ if (!data) {
9943
+ data = {};
9944
+ }
9945
+ const isNew = !data.ID;
9946
+ if (!data.ID) {
9947
+ // Short ID to keep the URL short.
9948
+ // 8 length = 4,294,967,296 combinations.
9949
+ data.ID = ObjectUtils.UId(8);
9950
+ }
9951
+ if (!data.Name) {
9952
+ data.Name = data.ID;
9953
+ }
9954
+ if (!data.CreatedByUIVersion) {
9955
+ data.CreatedByUIVersion = "-1";
9956
+ }
9957
+ if (isNew) {
9958
+ data = yield api.POST(`ui.view/${data.ID}`, data, Api.PrepReqParams(reqParams));
9959
+ }
9960
+ else {
9961
+ data = yield api.PUT(`ui.view/${data.ID}`, data, Api.PrepReqParams(reqParams));
9962
+ }
9963
+ api.Cache.Remove(GetCacheKey(data.ID));
9964
+ api.Cache.RemoveByStartsWith(GetListCacheKey());
9965
+ return {
9966
+ view: data
9967
+ };
9968
+ });
9969
+ }
9970
+ ProjectView.Update = Update;
9971
+ /**
9972
+ * Returns cache identifier for a project view.
9973
+ * Example: {
9974
+ * const api: BruceApi.Api = ...;
9975
+ * const key = GetCacheKey("abc");
9976
+ * api.Cache.Remove(key);
9977
+ * }
9978
+ * @param viewId
9979
+ * @returns
9980
+ */
9981
+ function GetCacheKey(viewId) {
9982
+ return `${Api.ECacheKey.ProjectView}${Api.ECacheKey.Id}${viewId}`;
9983
+ }
9984
+ ProjectView.GetCacheKey = GetCacheKey;
9985
+ /**
9986
+ * Returns cache identifier for a list of project views.
9987
+ * Example: {
9988
+ * const api: BruceApi.Api = ...;
9989
+ * const key = GetListCacheKey();
9990
+ * api.Cache.Remove(key);
9991
+ * }
9992
+ * @param type optional filter for the type of project view.
9993
+ * @returns
9994
+ */
9995
+ function GetListCacheKey(type) {
9996
+ if (type) {
9997
+ return `${Api.ECacheKey.ProjectView}${Api.ECacheKey.ListId}${type}`;
9998
+ }
9999
+ return `${Api.ECacheKey.ProjectView}${Api.ECacheKey.ListId}`;
10000
+ }
10001
+ ProjectView.GetListCacheKey = GetListCacheKey;
10002
+ })(ProjectView || (ProjectView = {}));
10003
+
10004
+ function getTemplateSettings(apiGetter, reqParams) {
10005
+ var _a;
10006
+ return __awaiter(this, void 0, void 0, function* () {
10007
+ const { view } = yield ProjectView.Get({
10008
+ api: apiGetter.getApi(Api.TEMPLATE_ACCOUNT_ID),
10009
+ viewId: "default",
10010
+ req: reqParams
10011
+ });
10012
+ return (_a = view.Settings) !== null && _a !== void 0 ? _a : {};
10013
+ });
10014
+ }
10015
+ function checkSourceToTemplate(items, templateItem, addIfMissing) {
10016
+ const index = items.findIndex(x => x.Name === templateItem.Name);
10017
+ if (index > -1) {
10018
+ templateItem.IsDefault = true;
10019
+ templateItem.IsEnabled = items[index].IsEnabled;
10020
+ items[index] = templateItem;
10021
+ }
10022
+ else if (addIfMissing) {
10023
+ templateItem.IsDefault = true;
10024
+ items.push(templateItem);
10025
+ }
10026
+ }
10027
+ /**
10028
+ * Describes a terrain or map source that are found in project view records.
10029
+ * This is a concept we want to trash as we're moving towards storing tileset ids instead.
10030
+ * This will help at least understand and manage this dying concept.
10031
+ */
10032
+ var ProjectViewLegacyTile;
10033
+ (function (ProjectViewLegacyTile) {
10034
+ function MergeMapTemplateData(params) {
10035
+ var _a;
10036
+ return __awaiter(this, void 0, void 0, function* () {
10037
+ let { getter, sources: items, addIfMissing, req: reqParams } = params;
10038
+ if (!getter) {
10039
+ getter = ENVIRONMENT.Api().GetBruceGetter();
10040
+ }
10041
+ const settings = yield getTemplateSettings(getter, reqParams);
10042
+ const maps = (_a = settings.CesiumMapSources) !== null && _a !== void 0 ? _a : [];
10043
+ for (let i = 0; i < maps.length; i++) {
10044
+ const mapSource = maps[i];
10045
+ checkSourceToTemplate(items, mapSource, addIfMissing);
10046
+ }
10047
+ return {
10048
+ sources: items
10049
+ };
10050
+ });
10051
+ }
10052
+ ProjectViewLegacyTile.MergeMapTemplateData = MergeMapTemplateData;
10053
+ function MergeTerrainTemplateData(params) {
10054
+ var _a;
10055
+ return __awaiter(this, void 0, void 0, function* () {
10056
+ let { getter, sources: items, addIfMissing, req: reqParams } = params;
10057
+ if (!getter) {
10058
+ getter = ENVIRONMENT.Api().GetBruceGetter();
10059
+ }
10060
+ const settings = yield getTemplateSettings(getter, reqParams);
10061
+ const terrains = (_a = settings.CesiumTerrainSources) !== null && _a !== void 0 ? _a : [];
10062
+ for (let i = 0; i < terrains.length; i++) {
10063
+ const terrainSource = terrains[i];
10064
+ checkSourceToTemplate(items, terrainSource, addIfMissing);
10065
+ }
10066
+ return {
10067
+ sources: items
10068
+ };
10069
+ });
10070
+ }
10071
+ ProjectViewLegacyTile.MergeTerrainTemplateData = MergeTerrainTemplateData;
10072
+ })(ProjectViewLegacyTile || (ProjectViewLegacyTile = {}));
10073
+
10074
+ /**
10075
+ * A tile is an imagery or terrain tileset definition.
10076
+ */
10077
+ var ProjectViewTile;
10078
+ (function (ProjectViewTile) {
10079
+ /**
10080
+ * Available imagery defaults.
10081
+ */
10082
+ let EDefaultImagery;
10083
+ (function (EDefaultImagery) {
10084
+ EDefaultImagery["BingMapsAerial"] = "bingmapsaerial";
10085
+ EDefaultImagery["BingMapsAerialWithLabels"] = "bingmapsaerialwithlabels";
10086
+ EDefaultImagery["BingMapsRoads"] = "bingmapsroads";
10087
+ EDefaultImagery["MapboxSatellite"] = "mapboxsatellite";
10088
+ EDefaultImagery["MapBoxStreets"] = "mapboxstreets";
10089
+ EDefaultImagery["MapBoxStreetsClassic"] = "mapboxstreetsclassic";
10090
+ EDefaultImagery["EsriWorldImagery"] = "esriworldimagery";
10091
+ EDefaultImagery["EsriWorldStreetMap"] = "esriworldstreetmap";
10092
+ EDefaultImagery["EsriNationalGeographic"] = "esrinationalgeographic";
10093
+ EDefaultImagery["OpenStreetMap"] = "openstreetmap";
10094
+ EDefaultImagery["LINZ"] = "linz";
10095
+ EDefaultImagery["StamenWaterColor"] = "stamenwatercolor";
10096
+ EDefaultImagery["StamenToner"] = "stamentoner";
10097
+ EDefaultImagery["Grid"] = "grid";
10098
+ EDefaultImagery["ThunderforestCycle"] = "thunderforestcycle";
10099
+ EDefaultImagery["ThunderforestTransport"] = "thunderforesttransport";
10100
+ EDefaultImagery["ThunderforestLandscape"] = "thunderforestlandscape";
10101
+ })(EDefaultImagery = ProjectViewTile.EDefaultImagery || (ProjectViewTile.EDefaultImagery = {}));
10102
+ /**
10103
+ * Prepared array for UI.
10104
+ * TODO: Im not happy with icon urls sitting in the code. I'd prefer we ship these icons in the library as files.
10105
+ */
10106
+ ProjectViewTile.DefaultImagery = [
10107
+ {
10108
+ id: EDefaultImagery.BingMapsAerial,
10109
+ name: "Bing Maps Aerial",
10110
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/bingAerial.png"
10111
+ },
10112
+ {
10113
+ id: EDefaultImagery.BingMapsAerialWithLabels,
10114
+ name: "Bing Maps Aerial with Labels",
10115
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/bingAerialLabels.png"
10116
+ },
10117
+ {
10118
+ id: EDefaultImagery.BingMapsRoads,
10119
+ name: "Bing Maps Roads",
10120
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/bingRoads.png"
10121
+ },
10122
+ {
10123
+ id: EDefaultImagery.MapboxSatellite,
10124
+ name: "Mapbox Satellite",
10125
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/mapboxSatellite.png"
10126
+ },
10127
+ {
10128
+ id: EDefaultImagery.MapBoxStreets,
10129
+ name: "Mapbox Streets",
10130
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/mapboxTerrain.png"
10131
+ },
10132
+ {
10133
+ id: EDefaultImagery.MapBoxStreetsClassic,
10134
+ name: "Mapbox Streets Classic",
10135
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/mapboxStreets.png"
10136
+ },
10137
+ {
10138
+ id: EDefaultImagery.EsriWorldImagery,
10139
+ name: "Esri World Imagery",
10140
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/esriWorldImagery.png"
10141
+ },
10142
+ {
10143
+ id: EDefaultImagery.EsriWorldStreetMap,
10144
+ name: "Esri World Street Map",
10145
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/esriWorldStreetMap.png"
10146
+ },
10147
+ {
10148
+ id: EDefaultImagery.EsriNationalGeographic,
10149
+ name: "Esri National Geographic",
10150
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/esriNationalGeographic.png"
10151
+ },
10152
+ {
10153
+ id: EDefaultImagery.OpenStreetMap,
10154
+ name: "Open Street Map",
10155
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/openStreetMap.png"
10156
+ },
10157
+ {
10158
+ id: EDefaultImagery.LINZ,
10159
+ name: "LINZ",
10160
+ iconUrl: "https://template.ui.nextspace.host/media/linz.jpg"
10161
+ },
10162
+ {
10163
+ id: EDefaultImagery.StamenWaterColor,
10164
+ name: "Stamen Water Color",
10165
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/stamenWatercolor.png"
10166
+ },
10167
+ {
10168
+ id: EDefaultImagery.StamenToner,
10169
+ name: "Stamen Toner",
10170
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/stamenToner.png"
10171
+ },
10172
+ {
10173
+ id: EDefaultImagery.ThunderforestCycle,
10174
+ name: "Thunderforest Cycle"
10175
+ },
10176
+ {
10177
+ id: EDefaultImagery.ThunderforestTransport,
10178
+ name: "Thunderforest Transport"
10179
+ },
10180
+ {
10181
+ id: EDefaultImagery.ThunderforestLandscape,
10182
+ name: "Thunderforest Landscape"
10183
+ },
10184
+ {
10185
+ id: EDefaultImagery.Grid,
10186
+ name: "Grid",
10187
+ iconUrl: "https://template.api.nextspace-uat.net/file/2885d8df-028b-4f5c-80b3-2634f7e7cf69.png"
10188
+ }
10189
+ ];
10190
+ /**
10191
+ * Available terrain defaults.
10192
+ */
10193
+ let EDefaultTerrain;
10194
+ (function (EDefaultTerrain) {
10195
+ EDefaultTerrain["CesiumWorldTerrain"] = "cesiumworldterrain";
10196
+ EDefaultTerrain["FlatTerrain"] = "flatterrain";
10197
+ EDefaultTerrain["LINZ"] = "linz";
10198
+ })(EDefaultTerrain = ProjectViewTile.EDefaultTerrain || (ProjectViewTile.EDefaultTerrain = {}));
10199
+ /**
10200
+ * Prepared array for UI.
10201
+ * TODO: Im not happy with icon urls sitting in the code. I'd prefer we ship these icons in the library as files.
10202
+ */
10203
+ ProjectViewTile.DefaultTerrains = [
10204
+ {
10205
+ id: EDefaultTerrain.CesiumWorldTerrain,
10206
+ name: "Cesium World Terrain",
10207
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/TerrainProviders/CesiumWorldTerrain.png"
10208
+ },
10209
+ {
10210
+ id: EDefaultTerrain.LINZ,
10211
+ name: "LINZ",
10212
+ iconUrl: "https://template.ui.nextspace.host/media/linz.jpg"
10213
+ },
10214
+ {
10215
+ id: EDefaultTerrain.FlatTerrain,
10216
+ name: "Flat Terrain",
10217
+ }
10218
+ ];
10219
+ })(ProjectViewTile || (ProjectViewTile = {}));
10220
+
10221
+ /**
10222
+ * Deprecated Project View record.
10223
+ * This was used in the legacy web Navigator.
10224
+ */
10225
+ var ProjectViewLegacy;
10226
+ (function (ProjectViewLegacy) {
10227
+ ProjectViewLegacy.DATA_VERSION = 1;
10228
+ })(ProjectViewLegacy || (ProjectViewLegacy = {}));
10229
+
10230
+ /**
10231
+ * Deprecated Project View Bookmark record.
10232
+ * This was used in the legacy web Navigator.
10233
+ */
10234
+ var ProjectViewLegacyBookmark;
10235
+ (function (ProjectViewLegacyBookmark) {
10236
+ ProjectViewLegacyBookmark.DATA_VERSION = 1;
10237
+ })(ProjectViewLegacyBookmark || (ProjectViewLegacyBookmark = {}));
10238
+
10239
+ /**
10240
+ * Describes the "Pending Action" concept within Nextspace.
10241
+ * A pending action is a record of a server-side background process.
10242
+ * This record is used to monitor its progress and completion state.
10243
+ */
10244
+ var PendingAction;
10245
+ (function (PendingAction) {
10246
+ /**
10247
+ * Available pending action statuses.
10248
+ */
10249
+ let EStatus;
10250
+ (function (EStatus) {
10251
+ EStatus["InProgress"] = "IN_PROGRESS";
10252
+ EStatus["Cancelled"] = "CANCELLED";
10253
+ EStatus["Complete"] = "COMPLETE";
10254
+ EStatus["Failed"] = "FAILED";
10255
+ })(EStatus = PendingAction.EStatus || (PendingAction.EStatus = {}));
10256
+ /**
10257
+ * Available message types.
10023
10258
  */
10024
- function CreateFromTypeId(typeId, styleId) {
10025
- return {
10026
- id: ObjectUtils.UId(),
10027
- Type: EType.Entities,
10028
- Caption: "Generated Entity Type Menu Item",
10029
- BruceEntity: {
10030
- "EntityType.ID": typeId
10031
- },
10032
- CameraZoomSettings: [
10033
- {
10034
- DisplayType: ZoomControl.EDisplayType.Model3D,
10035
- MaxZoom: 100000,
10036
- MinZoom: 0,
10037
- StyleID: styleId
10038
- }
10039
- ]
10040
- };
10041
- }
10042
- MenuItem.CreateFromTypeId = CreateFromTypeId;
10259
+ let EMessageType;
10260
+ (function (EMessageType) {
10261
+ EMessageType["Warn"] = "WARNING";
10262
+ EMessageType["Error"] = "ERROR";
10263
+ EMessageType["Status"] = "STATUS";
10264
+ EMessageType["Info"] = "INFO";
10265
+ })(EMessageType = PendingAction.EMessageType || (PendingAction.EMessageType = {}));
10043
10266
  /**
10044
- * Creates a menu item for a tileset.
10045
- * @param tilesetId
10046
- * @param type
10267
+ * Returns a pending action record.
10268
+ * @param params
10047
10269
  * @returns
10048
10270
  */
10049
- function CreateFromTilesetId(tilesetId, type) {
10050
- if (type === Tileset.EType.Cad) {
10051
- return {
10052
- id: ObjectUtils.UId(),
10053
- Type: EType.CadTileset,
10054
- Caption: "Generated CAD Menu Item",
10055
- FlyTo: false,
10056
- tileset: {
10057
- TilesetID: tilesetId
10058
- }
10059
- };
10060
- }
10061
- else if (type == Tileset.EType.EntitiesSet) {
10062
- return {
10063
- id: ObjectUtils.UId(),
10064
- Type: EType.EntityTileset,
10065
- Caption: "Generated Entities Menu Item",
10066
- FlyTo: false,
10067
- tileset: {
10068
- TilesetID: tilesetId
10069
- }
10070
- };
10071
- }
10072
- else if (type == Tileset.EType.PointCloud) {
10073
- return {
10074
- id: ObjectUtils.UId(),
10075
- Type: EType.PointCloud,
10076
- Caption: "Generated Point Cloud Menu Item",
10077
- FlyTo: false,
10078
- tileset: {
10079
- TilesetID: tilesetId
10080
- }
10081
- };
10082
- }
10083
- else if (type == Tileset.EType.EntitiesMap) {
10271
+ function Get(params) {
10272
+ return __awaiter(this, void 0, void 0, function* () {
10273
+ let { api, actionId, req: reqParams } = params;
10274
+ if (!actionId) {
10275
+ throw ("Action ID is required.");
10276
+ }
10277
+ if (!api) {
10278
+ api = ENVIRONMENT.Api().GetBruceApi();
10279
+ }
10280
+ const data = yield api.GET(`pendingAction/${actionId}`, Api.PrepReqParams(reqParams));
10084
10281
  return {
10085
- id: ObjectUtils.UId(),
10086
- Type: EType.EntityRaster,
10087
- Caption: "Generated Entities Menu Item",
10088
- tileset: {
10089
- TilesetID: tilesetId
10090
- }
10282
+ action: data
10091
10283
  };
10092
- }
10093
- throw ("Tileset type not supported.");
10284
+ });
10094
10285
  }
10095
- MenuItem.CreateFromTilesetId = CreateFromTilesetId;
10096
- })(MenuItem || (MenuItem = {}));
10097
-
10098
- /**
10099
- * Describe the "Project View Bookmark" concept within Nextspace.
10100
- * This is referred to as "slides" in older code.
10101
- *
10102
- * A bookmark is a snapshot of what should be displayed and how in a particular project view.
10103
- */
10104
- var ProjectViewBookmark;
10105
- (function (ProjectViewBookmark) {
10106
- // This is the expected default version for the DataVersion value.
10107
- // This value should NOT be changed without looking at our API and seeing what the default value is.
10108
- ProjectViewBookmark.DEFAULT_DATA_VERSION = 2;
10286
+ PendingAction.Get = Get;
10109
10287
  /**
10110
- * Describes the content of a bookmark.
10111
- * As part of a deal we've been commissioned to create an alternative bookmark type to embed content.
10288
+ * Returns a list of pending action records.
10289
+ * @param params
10290
+ * @returns
10112
10291
  */
10113
- let EContentType;
10114
- (function (EContentType) {
10115
- EContentType["WEB_3D"] = "WEB_3D";
10116
- EContentType["IFRAME"] = "IFRAME";
10117
- })(EContentType = ProjectViewBookmark.EContentType || (ProjectViewBookmark.EContentType = {}));
10292
+ function GetRelevantList(params) {
10293
+ return __awaiter(this, void 0, void 0, function* () {
10294
+ let { api, stricter, reqParams } = params;
10295
+ if (!api) {
10296
+ api = ENVIRONMENT.Api().GetBruceApi();
10297
+ }
10298
+ const data = yield api.GET(`pendingActions/important?Update=${Boolean(stricter)}`, Api.PrepReqParams(reqParams));
10299
+ return {
10300
+ actions: data.Items
10301
+ };
10302
+ });
10303
+ }
10304
+ PendingAction.GetRelevantList = GetRelevantList;
10118
10305
  /**
10119
- * Gets a bookmark record.
10306
+ * Returns a list of pending action record messages.
10120
10307
  * @param params
10121
10308
  * @returns
10122
10309
  */
10123
- function Get(params) {
10310
+ function GetMessages(params) {
10124
10311
  return __awaiter(this, void 0, void 0, function* () {
10125
- let { api, viewId, bookmarkId, req: reqParams } = params;
10126
- if (!viewId || !bookmarkId) {
10127
- throw ("View ID and Bookmark ID are required.");
10128
- }
10312
+ let { api, actionId, order, startIndex, amount, req: reqParams, types } = params;
10129
10313
  if (!api) {
10130
10314
  api = ENVIRONMENT.Api().GetBruceApi();
10131
10315
  }
10132
- const key = GetCacheKey(viewId, bookmarkId);
10133
- const cache = yield api.GetCacheItem(key, reqParams);
10134
- if (cache === null || cache === void 0 ? void 0 : cache.found) {
10135
- return cache.data;
10316
+ if (amount == null) {
10317
+ amount = 500;
10136
10318
  }
10137
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
10138
- try {
10139
- const data = yield api.GET(`ui.view/${viewId}/slide/${bookmarkId}`, Api.PrepReqParams(reqParams));
10140
- res({
10141
- bookmark: data
10142
- });
10143
- }
10144
- catch (e) {
10145
- rej(e);
10319
+ if (startIndex == null) {
10320
+ startIndex = 0;
10321
+ }
10322
+ if (order == null) {
10323
+ order = Api.ESortOrder.Asc;
10324
+ }
10325
+ let args = `?SortOrder=${order == Api.ESortOrder.Desc ? "DESC" : "ASC"}&PageSize=${amount}&PageIndex=${startIndex}`;
10326
+ if (types === null || types === void 0 ? void 0 : types.length) {
10327
+ for (let i = 0; i < types.length; i++) {
10328
+ args += `&Type=${types[i]}`;
10146
10329
  }
10147
- }));
10148
- yield api.SetCacheItem({
10149
- key,
10150
- value: prom,
10151
- req: reqParams
10152
- });
10153
- return prom;
10330
+ }
10331
+ const data = yield api.GET(`pendingAction/${actionId}/progressMessages` + args, Api.PrepReqParams(reqParams));
10332
+ return {
10333
+ messages: data.Items
10334
+ };
10154
10335
  });
10155
10336
  }
10156
- ProjectViewBookmark.Get = Get;
10337
+ PendingAction.GetMessages = GetMessages;
10157
10338
  /**
10158
- * Deletes a bookmark record.
10339
+ * Requests to cancel a pending action.
10159
10340
  * @param params
10160
10341
  */
10161
- function Delete(params) {
10342
+ function Cancel(params) {
10162
10343
  return __awaiter(this, void 0, void 0, function* () {
10163
- let { api, viewId, bookmarkId, req: reqParams } = params;
10164
- if (!viewId || !bookmarkId) {
10165
- throw ("View ID and Bookmark ID are required.");
10344
+ let { api, actionId, req: reqParams } = params;
10345
+ if (!actionId) {
10346
+ throw ("Action ID is required.");
10166
10347
  }
10167
10348
  if (!api) {
10168
10349
  api = ENVIRONMENT.Api().GetBruceApi();
10169
10350
  }
10170
- yield api.DELETE(`ui.view/${viewId}/slide/${bookmarkId}`, Api.PrepReqParams(reqParams));
10171
- api.Cache.Remove(GetCacheKey(viewId, bookmarkId));
10172
- api.Cache.Remove(GetListCacheKey(viewId));
10351
+ yield api.DELETE(`pendingAction/${actionId}`, Api.PrepReqParams(reqParams));
10173
10352
  });
10174
10353
  }
10175
- ProjectViewBookmark.Delete = Delete;
10354
+ PendingAction.Cancel = Cancel;
10355
+ })(PendingAction || (PendingAction = {}));
10356
+
10357
+ // Some dead accounts that we don't want to show in the UI.
10358
+ // Some accounts may not be "dead" but instead purposely don't have a NextspaceAPI database so we'll avoid them too.
10359
+ const ACCOUNT_EXCLUSIONS = ["hyperportal", "hypeportal", "bviewer"];
10360
+ /**
10361
+ * Describes the "Client Account" concept within Nextspace.
10362
+ * A client account is a database instance that holds one or many users.
10363
+ */
10364
+ var Account;
10365
+ (function (Account) {
10176
10366
  /**
10177
- * Gets a list of bookmark records.
10367
+ * Known Nextspace applications we store settings for.
10368
+ */
10369
+ let EAppId;
10370
+ (function (EAppId) {
10371
+ EAppId["BruceApi"] = "BruceAPI";
10372
+ EAppId["Navigator"] = "Navigator";
10373
+ EAppId["Operator"] = "BruceClientAdmin";
10374
+ })(EAppId = Account.EAppId || (Account.EAppId = {}));
10375
+ /**
10376
+ * Possible starter content options.
10377
+ * When creating a new account you can populate it with certain default data.
10378
+ */
10379
+ let EStarterContent;
10380
+ (function (EStarterContent) {
10381
+ EStarterContent["Default"] = "default";
10382
+ EStarterContent["None"] = "none";
10383
+ })(EStarterContent = Account.EStarterContent || (Account.EStarterContent = {}));
10384
+ /**
10385
+ * Gets a client account record by ID.
10178
10386
  * @param params
10179
10387
  * @returns
10180
10388
  */
10181
- function GetList(params) {
10389
+ function Get(params) {
10182
10390
  return __awaiter(this, void 0, void 0, function* () {
10183
- let { api, viewId, req: reqParams } = params;
10184
- if (!viewId) {
10185
- throw ("View ID is required.");
10186
- }
10391
+ let { api, accountId: id, req: reqParams } = params;
10187
10392
  if (!api) {
10188
- api = ENVIRONMENT.Api().GetBruceApi();
10393
+ api = ENVIRONMENT.Api().GetGuardianApi();
10189
10394
  }
10190
- const cache = yield api.GetCacheItem(GetListCacheKey(viewId), reqParams);
10395
+ const cache = yield api.GetCacheItem(GetCacheKey(id), reqParams);
10191
10396
  if (cache === null || cache === void 0 ? void 0 : cache.found) {
10192
10397
  return cache.data;
10193
10398
  }
10194
- const req = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
10399
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
10195
10400
  try {
10196
- const data = yield api.GET(`ui.view/${viewId}/slides`, Api.PrepReqParams(reqParams));
10197
- const items = data.Items ? data.Items : [];
10198
- // Cache individual items.
10199
- // Maybe better to load list cache when getting 1 slide and seeing if it's in there.
10200
- // WARNING: Right now the data matches, in the future the list may contain a shortened result.
10201
- for (let i = 0; i < items.length; i++) {
10202
- const item = items[i];
10203
- const prom = new Promise((res) => {
10204
- res({
10205
- bookmark: item
10206
- });
10207
- });
10401
+ const data = yield api.GET(`accountbyid/${id}`, reqParams);
10402
+ // Update the cache by subdomain as well in case it's different to the ID.
10403
+ if ((data === null || data === void 0 ? void 0 : data.ID) && (reqParams === null || reqParams === void 0 ? void 0 : reqParams.noCache) != false) {
10208
10404
  yield api.SetCacheItem({
10209
- key: GetCacheKey(viewId, item.ID),
10405
+ key: data.Subdomain,
10210
10406
  value: prom,
10211
10407
  req: reqParams
10212
10408
  });
10213
10409
  }
10214
10410
  res({
10215
- bookmarks: items
10411
+ account: data
10216
10412
  });
10217
10413
  }
10218
10414
  catch (e) {
@@ -10220,127 +10416,42 @@ var ProjectViewBookmark;
10220
10416
  }
10221
10417
  }));
10222
10418
  yield api.SetCacheItem({
10223
- key: GetListCacheKey(viewId),
10224
- value: req,
10419
+ key: GetCacheKey(id),
10420
+ value: prom,
10225
10421
  req: reqParams
10226
10422
  });
10227
- return req;
10228
- });
10229
- }
10230
- ProjectViewBookmark.GetList = GetList;
10231
- /**
10232
- * Creates or updates a bookmark record.
10233
- * @param params
10234
- * @returns
10235
- */
10236
- function Update(params) {
10237
- return __awaiter(this, void 0, void 0, function* () {
10238
- let { api, viewId, bookmark: data, req: reqParams } = params;
10239
- if (!api) {
10240
- api = ENVIRONMENT.Api().GetBruceApi();
10241
- }
10242
- if (!(data === null || data === void 0 ? void 0 : data.Title)) {
10243
- data.Title = data.ID;
10244
- }
10245
- const res = yield api.POST(`ui.view/${viewId}/slide/${data.ID ? data.ID : ""}`, data, Api.PrepReqParams(reqParams));
10246
- api.Cache.Remove(GetCacheKey(viewId, data.ID));
10247
- api.Cache.Remove(GetListCacheKey(viewId));
10248
- return {
10249
- bookmark: res
10250
- };
10251
- });
10252
- }
10253
- ProjectViewBookmark.Update = Update;
10254
- /**
10255
- * Sets the order of bookmarks within a project view.
10256
- * @param params
10257
- */
10258
- function SetOrder(params) {
10259
- return __awaiter(this, void 0, void 0, function* () {
10260
- let { api, viewId, bookmarkIds, req: reqParams } = params;
10261
- if (!api) {
10262
- api = ENVIRONMENT.Api().GetBruceApi();
10263
- }
10264
- const reqData = {
10265
- "UISlide.ID": bookmarkIds,
10266
- "DisplayOrder.Start": 0
10267
- };
10268
- yield api.POST(`ui.view/${viewId}/slides/setOrder`, reqData, Api.PrepReqParams(reqParams));
10269
- yield api.Cache.RemoveByStartsWith(GetListCacheKey(viewId));
10423
+ return prom;
10270
10424
  });
10271
10425
  }
10272
- ProjectViewBookmark.SetOrder = SetOrder;
10273
- /**
10274
- * Returns cache identifier for a bookmark.
10275
- * Example: {
10276
- * const api: BruceApi.Api = ...;
10277
- * const key = GetCacheKey("abc", "def");
10278
- * api.Cache.Remove(key);
10279
- * }
10280
- * @param viewId
10281
- * @param bookmarkId
10282
- * @returns
10283
- */
10284
- function GetCacheKey(viewId, bookmarkId) {
10285
- return `${Api.ECacheKey.ProjectViewBookmark}${Api.ECacheKey.Id}${viewId}${Api.ECacheKey.Id}${bookmarkId}`;
10286
- }
10287
- ProjectViewBookmark.GetCacheKey = GetCacheKey;
10288
- /**
10289
- * Returns cache identifier for a list of bookmarks.
10290
- * Example: {
10291
- * const api: BruceApi.Api = ...;
10292
- * const key = GetListCacheKey("abc");
10293
- * api.Cache.Remove(key);
10294
- * }
10295
- * @param viewId
10296
- * @returns
10297
- */
10298
- function GetListCacheKey(viewId) {
10299
- return `${Api.ECacheKey.ProjectViewBookmark}${Api.ECacheKey.Id}${viewId}`;
10300
- }
10301
- ProjectViewBookmark.GetListCacheKey = GetListCacheKey;
10302
- })(ProjectViewBookmark || (ProjectViewBookmark = {}));
10303
-
10304
- /**
10305
- * Describes the "Project View" concept within Nextspace.
10306
- * A project view is a collection of settings for a visualization application we support.
10307
- * It will describe what panels to show and how, it will also describe all possible ways data can be displayed.
10308
- */
10309
- var ProjectView;
10310
- (function (ProjectView) {
10311
- // This is the expected default version for the DataVersion value.
10312
- // This value should NOT be changed without looking at our API and seeing what the default value is.
10313
- ProjectView.DEFAULT_DATA_VERSION = 2;
10314
- // Our Cesium web navigator.
10315
- ProjectView.TYPE_WEB_3D_NAVIGATOR = "WEB_3D_NAVIGATOR";
10316
- // Our (currently WIP) 2D web navigator. Also known as our graph viewer.
10317
- ProjectView.TYPE_WEB_2D_NAVIGATOR = "WEB_2D_NAVIGATOR";
10318
- // Defaulting to 3D navigator for backwards compatibility.
10319
- ProjectView.DEFAULT_TYPE = ProjectView.TYPE_WEB_3D_NAVIGATOR;
10426
+ Account.Get = Get;
10320
10427
  /**
10321
- * Gets a project view record.
10428
+ * Returns a client account record by subdomain or ID.
10322
10429
  * @param params
10323
10430
  * @returns
10324
10431
  */
10325
- function Get(params) {
10432
+ function GetBySubdomain(params) {
10326
10433
  return __awaiter(this, void 0, void 0, function* () {
10327
- let { api, viewId, req: reqParams } = params;
10328
- if (!viewId) {
10329
- throw ("View ID is required.");
10330
- }
10434
+ let { api, subdomain, req: reqParams } = params;
10331
10435
  if (!api) {
10332
- api = ENVIRONMENT.Api().GetBruceApi();
10436
+ api = ENVIRONMENT.Api().GetGuardianApi();
10333
10437
  }
10334
- const key = GetCacheKey(viewId);
10335
- const cache = yield api.GetCacheItem(key, reqParams);
10438
+ const cache = yield api.GetCacheItem(GetCacheKey(subdomain), reqParams);
10336
10439
  if (cache === null || cache === void 0 ? void 0 : cache.found) {
10337
10440
  return cache.data;
10338
10441
  }
10339
10442
  const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
10340
10443
  try {
10341
- const data = yield api.GET(`ui.view/${viewId}`, Api.PrepReqParams(reqParams));
10444
+ const data = yield api.GET(`account/${subdomain}`, reqParams);
10445
+ // Update the cache by ID as well in case it's different to the subdomain.
10446
+ if ((data === null || data === void 0 ? void 0 : data.ID) && (reqParams === null || reqParams === void 0 ? void 0 : reqParams.noCache) != false) {
10447
+ yield api.SetCacheItem({
10448
+ key: data.ID,
10449
+ value: prom,
10450
+ req: reqParams
10451
+ });
10452
+ }
10342
10453
  res({
10343
- view: data
10454
+ account: data
10344
10455
  });
10345
10456
  }
10346
10457
  catch (e) {
@@ -10348,34 +10459,36 @@ var ProjectView;
10348
10459
  }
10349
10460
  }));
10350
10461
  yield api.SetCacheItem({
10351
- key,
10462
+ key: GetCacheKey(subdomain),
10352
10463
  value: prom,
10353
10464
  req: reqParams
10354
10465
  });
10355
10466
  return prom;
10356
10467
  });
10357
10468
  }
10358
- ProjectView.Get = Get;
10469
+ Account.GetBySubdomain = GetBySubdomain;
10359
10470
  /**
10360
- * Gets a list of project views.
10471
+ * Gets a list of client accounts related to the current session user.
10361
10472
  * @param params
10362
10473
  * @returns
10363
10474
  */
10364
- function GetList(params) {
10475
+ function GetRelatedList(params) {
10365
10476
  return __awaiter(this, void 0, void 0, function* () {
10366
- let { api, req: reqParams, type } = params;
10477
+ let { api, req: reqParams } = params;
10367
10478
  if (!api) {
10368
- api = ENVIRONMENT.Api().GetBruceApi();
10479
+ api = ENVIRONMENT.Api().GetGuardianApi();
10369
10480
  }
10370
- const cache = yield api.GetCacheItem(GetListCacheKey(type), reqParams);
10481
+ const cache = yield api.GetCacheItem(GetListCacheKey(api.GetSessionId()), reqParams);
10371
10482
  if (cache === null || cache === void 0 ? void 0 : cache.found) {
10372
10483
  return cache.data;
10373
10484
  }
10485
+ const req = api.GET("user/relatedClientAccounts", reqParams);
10374
10486
  const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
10375
10487
  try {
10376
- const data = yield api.GET("ui.view/list", Api.PrepReqParams(reqParams));
10488
+ const data = yield req;
10489
+ const items = data.Items.filter((x) => !ACCOUNT_EXCLUSIONS.includes(x.ID));
10377
10490
  res({
10378
- views: data.Items
10491
+ accounts: items
10379
10492
  });
10380
10493
  }
10381
10494
  catch (e) {
@@ -10383,458 +10496,345 @@ var ProjectView;
10383
10496
  }
10384
10497
  }));
10385
10498
  yield api.SetCacheItem({
10386
- key: GetListCacheKey(type),
10499
+ key: GetListCacheKey(api.GetSessionId()),
10387
10500
  value: prom,
10388
10501
  req: reqParams
10389
10502
  });
10390
10503
  return prom;
10391
10504
  });
10392
10505
  }
10393
- ProjectView.GetList = GetList;
10394
- /**
10395
- * Deletes a project view.
10396
- * @param params
10397
- */
10398
- function Delete(params) {
10399
- return __awaiter(this, void 0, void 0, function* () {
10400
- let { api, viewId, req: reqParams } = params;
10401
- if (!viewId) {
10402
- throw ("View ID is required.");
10403
- }
10404
- if (!api) {
10405
- api = ENVIRONMENT.Api().GetBruceApi();
10406
- }
10407
- yield api.DELETE(`ui.view/${viewId}`, Api.PrepReqParams(reqParams));
10408
- api.Cache.Remove(GetCacheKey(viewId));
10409
- api.Cache.RemoveByStartsWith(GetListCacheKey());
10410
- });
10411
- }
10412
- ProjectView.Delete = Delete;
10506
+ Account.GetRelatedList = GetRelatedList;
10413
10507
  /**
10414
- * Creates or updates a project view.
10508
+ * Gets application settings for a specific client account.
10415
10509
  * @param params
10416
10510
  * @returns
10417
10511
  */
10418
- function Update(params) {
10512
+ function GetAppSettings(params) {
10419
10513
  return __awaiter(this, void 0, void 0, function* () {
10420
- let { api, view: data, req: reqParams } = params;
10514
+ let { api, accountId: id, appId, req: reqParams } = params;
10421
10515
  if (!api) {
10422
- api = ENVIRONMENT.Api().GetBruceApi();
10423
- }
10424
- if (!data) {
10425
- data = {};
10426
- }
10427
- const isNew = !data.ID;
10428
- if (!data.ID) {
10429
- // Short ID to keep the URL short.
10430
- // 8 length = 4,294,967,296 combinations.
10431
- data.ID = ObjectUtils.UId(8);
10432
- }
10433
- if (!data.Name) {
10434
- data.Name = data.ID;
10435
- }
10436
- if (!data.CreatedByUIVersion) {
10437
- data.CreatedByUIVersion = "-1";
10438
- }
10439
- if (isNew) {
10440
- data = yield api.POST(`ui.view/${data.ID}`, data, Api.PrepReqParams(reqParams));
10516
+ api = ENVIRONMENT.Api().GetGuardianApi();
10441
10517
  }
10442
- else {
10443
- data = yield api.PUT(`ui.view/${data.ID}`, data, Api.PrepReqParams(reqParams));
10518
+ const cache = yield api.GetCacheItem(GetCacheKey(id, appId), reqParams);
10519
+ if (cache === null || cache === void 0 ? void 0 : cache.found) {
10520
+ return cache.data;
10444
10521
  }
10445
- api.Cache.Remove(GetCacheKey(data.ID));
10446
- api.Cache.RemoveByStartsWith(GetListCacheKey());
10447
- return {
10448
- view: data
10449
- };
10450
- });
10451
- }
10452
- ProjectView.Update = Update;
10453
- /**
10454
- * Returns cache identifier for a project view.
10455
- * Example: {
10456
- * const api: BruceApi.Api = ...;
10457
- * const key = GetCacheKey("abc");
10458
- * api.Cache.Remove(key);
10459
- * }
10460
- * @param viewId
10461
- * @returns
10462
- */
10463
- function GetCacheKey(viewId) {
10464
- return `${Api.ECacheKey.ProjectView}${Api.ECacheKey.Id}${viewId}`;
10465
- }
10466
- ProjectView.GetCacheKey = GetCacheKey;
10467
- /**
10468
- * Returns cache identifier for a list of project views.
10469
- * Example: {
10470
- * const api: BruceApi.Api = ...;
10471
- * const key = GetListCacheKey();
10472
- * api.Cache.Remove(key);
10473
- * }
10474
- * @param type optional filter for the type of project view.
10475
- * @returns
10476
- */
10477
- function GetListCacheKey(type) {
10478
- if (type) {
10479
- return `${Api.ECacheKey.ProjectView}${Api.ECacheKey.ListId}${type}`;
10480
- }
10481
- return `${Api.ECacheKey.ProjectView}${Api.ECacheKey.ListId}`;
10482
- }
10483
- ProjectView.GetListCacheKey = GetListCacheKey;
10484
- })(ProjectView || (ProjectView = {}));
10485
-
10486
- function getTemplateSettings(apiGetter, reqParams) {
10487
- var _a;
10488
- return __awaiter(this, void 0, void 0, function* () {
10489
- const { view } = yield ProjectView.Get({
10490
- api: apiGetter.getApi(Api.TEMPLATE_ACCOUNT_ID),
10491
- viewId: "default",
10492
- req: reqParams
10522
+ const req = yield api.GET(`account/${id}?ApplicationID=${appId}`, reqParams);
10523
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
10524
+ var _a;
10525
+ try {
10526
+ const data = yield req;
10527
+ const settings = (_a = data === null || data === void 0 ? void 0 : data["Application.Settings"]) !== null && _a !== void 0 ? _a : {};
10528
+ res({
10529
+ settings: settings
10530
+ });
10531
+ }
10532
+ catch (e) {
10533
+ rej(e);
10534
+ }
10535
+ }));
10536
+ yield api.SetCacheItem({
10537
+ key: GetCacheKey(id, appId),
10538
+ value: prom,
10539
+ req: reqParams
10540
+ });
10541
+ return prom;
10493
10542
  });
10494
- return (_a = view.Settings) !== null && _a !== void 0 ? _a : {};
10495
- });
10496
- }
10497
- function checkSourceToTemplate(items, templateItem, addIfMissing) {
10498
- const index = items.findIndex(x => x.Name === templateItem.Name);
10499
- if (index > -1) {
10500
- templateItem.IsDefault = true;
10501
- templateItem.IsEnabled = items[index].IsEnabled;
10502
- items[index] = templateItem;
10503
- }
10504
- else if (addIfMissing) {
10505
- templateItem.IsDefault = true;
10506
- items.push(templateItem);
10507
10543
  }
10508
- }
10509
- /**
10510
- * Describes a terrain or map source that are found in project view records.
10511
- * This is a concept we want to trash as we're moving towards storing tileset ids instead.
10512
- * This will help at least understand and manage this dying concept.
10513
- */
10514
- var ProjectViewLegacyTile;
10515
- (function (ProjectViewLegacyTile) {
10516
- function MergeMapTemplateData(params) {
10517
- var _a;
10544
+ Account.GetAppSettings = GetAppSettings;
10545
+ /**
10546
+ * Updates application settings for a specific client account + application.
10547
+ * WARNING: Do not update API settings without knowing what you're doing.
10548
+ * @param params
10549
+ * @returns
10550
+ */
10551
+ function UpdateAppSettings(params) {
10518
10552
  return __awaiter(this, void 0, void 0, function* () {
10519
- let { getter, sources: items, addIfMissing, req: reqParams } = params;
10520
- if (!getter) {
10521
- getter = ENVIRONMENT.Api().GetBruceGetter();
10522
- }
10523
- const settings = yield getTemplateSettings(getter, reqParams);
10524
- const maps = (_a = settings.CesiumMapSources) !== null && _a !== void 0 ? _a : [];
10525
- for (let i = 0; i < maps.length; i++) {
10526
- const mapSource = maps[i];
10527
- checkSourceToTemplate(items, mapSource, addIfMissing);
10553
+ let { api, accountId: id, appId, settings: data, req: reqParams } = params;
10554
+ if (!api) {
10555
+ api = ENVIRONMENT.Api().GetGuardianApi();
10528
10556
  }
10557
+ const res = yield api.POST(`account/${id}/applicationSettings/${appId}`, data, reqParams);
10558
+ yield api.Cache.RemoveByStartsWith(Api.ECacheKey.Account + Api.ECacheKey.Id + id);
10529
10559
  return {
10530
- sources: items
10560
+ settings: res
10531
10561
  };
10532
10562
  });
10533
10563
  }
10534
- ProjectViewLegacyTile.MergeMapTemplateData = MergeMapTemplateData;
10535
- function MergeTerrainTemplateData(params) {
10536
- var _a;
10564
+ Account.UpdateAppSettings = UpdateAppSettings;
10565
+ /**
10566
+ * Creates a new Nextspace account using given details.
10567
+ * @param params
10568
+ * @returns
10569
+ */
10570
+ function Create(params) {
10537
10571
  return __awaiter(this, void 0, void 0, function* () {
10538
- let { getter, sources: items, addIfMissing, req: reqParams } = params;
10539
- if (!getter) {
10540
- getter = ENVIRONMENT.Api().GetBruceGetter();
10572
+ let { api, accountId: id, name, hostingLocationKey, starterContent, req: reqParams } = params;
10573
+ if (!id || !name || !hostingLocationKey) {
10574
+ throw new Error("Id, Name and hostingLocationKey are required.");
10541
10575
  }
10542
- const settings = yield getTemplateSettings(getter, reqParams);
10543
- const terrains = (_a = settings.CesiumTerrainSources) !== null && _a !== void 0 ? _a : [];
10544
- for (let i = 0; i < terrains.length; i++) {
10545
- const terrainSource = terrains[i];
10546
- checkSourceToTemplate(items, terrainSource, addIfMissing);
10576
+ if (!api) {
10577
+ api = ENVIRONMENT.Api().GetBruceApi();
10547
10578
  }
10548
- return {
10549
- sources: items
10579
+ if (!starterContent) {
10580
+ starterContent = EStarterContent.None;
10581
+ }
10582
+ const reqData = {
10583
+ "Name": name,
10584
+ "HostingLocation.Key": hostingLocationKey,
10585
+ "StarterContent": starterContent
10586
+ };
10587
+ const res = yield api.POST(`clientAccount/${id}`, reqData, Api.PrepReqParams(reqParams));
10588
+ const resData = {
10589
+ account: res
10550
10590
  };
10591
+ api.Cache.Remove(GetListCacheKey(api.GetSessionId()));
10592
+ return resData;
10551
10593
  });
10552
10594
  }
10553
- ProjectViewLegacyTile.MergeTerrainTemplateData = MergeTerrainTemplateData;
10554
- })(ProjectViewLegacyTile || (ProjectViewLegacyTile = {}));
10555
-
10556
- /**
10557
- * A tile is an imagery or terrain tileset definition.
10558
- */
10559
- var ProjectViewTile;
10560
- (function (ProjectViewTile) {
10561
- /**
10562
- * Available imagery defaults.
10563
- */
10564
- let EDefaultImagery;
10565
- (function (EDefaultImagery) {
10566
- EDefaultImagery["BingMapsAerial"] = "bingmapsaerial";
10567
- EDefaultImagery["BingMapsAerialWithLabels"] = "bingmapsaerialwithlabels";
10568
- EDefaultImagery["BingMapsRoads"] = "bingmapsroads";
10569
- EDefaultImagery["MapboxSatellite"] = "mapboxsatellite";
10570
- EDefaultImagery["MapBoxStreets"] = "mapboxstreets";
10571
- EDefaultImagery["MapBoxStreetsClassic"] = "mapboxstreetsclassic";
10572
- EDefaultImagery["EsriWorldImagery"] = "esriworldimagery";
10573
- EDefaultImagery["EsriWorldStreetMap"] = "esriworldstreetmap";
10574
- EDefaultImagery["EsriNationalGeographic"] = "esrinationalgeographic";
10575
- EDefaultImagery["OpenStreetMap"] = "openstreetmap";
10576
- EDefaultImagery["LINZ"] = "linz";
10577
- EDefaultImagery["StamenWaterColor"] = "stamenwatercolor";
10578
- EDefaultImagery["StamenToner"] = "stamentoner";
10579
- EDefaultImagery["Grid"] = "grid";
10580
- EDefaultImagery["ThunderforestCycle"] = "thunderforestcycle";
10581
- EDefaultImagery["ThunderforestTransport"] = "thunderforesttransport";
10582
- EDefaultImagery["ThunderforestLandscape"] = "thunderforestlandscape";
10583
- })(EDefaultImagery = ProjectViewTile.EDefaultImagery || (ProjectViewTile.EDefaultImagery = {}));
10595
+ Account.Create = Create;
10584
10596
  /**
10585
- * Prepared array for UI.
10586
- * TODO: Im not happy with icon urls sitting in the code. I'd prefer we ship these icons in the library as files.
10597
+ * Returns cache identifier for an account by ID.
10598
+ * Example: {
10599
+ * const api: BruceApi.Api = ...;
10600
+ * const key = GetCacheKey(1);
10601
+ * api.Cache.Remove(key);
10602
+ * }
10603
+ * @param accountId
10604
+ * @param appSettingsId
10605
+ * @returns
10587
10606
  */
10588
- ProjectViewTile.DefaultImagery = [
10589
- {
10590
- id: EDefaultImagery.BingMapsAerial,
10591
- name: "Bing Maps Aerial",
10592
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/bingAerial.png"
10593
- },
10594
- {
10595
- id: EDefaultImagery.BingMapsAerialWithLabels,
10596
- name: "Bing Maps Aerial with Labels",
10597
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/bingAerialLabels.png"
10598
- },
10599
- {
10600
- id: EDefaultImagery.BingMapsRoads,
10601
- name: "Bing Maps Roads",
10602
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/bingRoads.png"
10603
- },
10604
- {
10605
- id: EDefaultImagery.MapboxSatellite,
10606
- name: "Mapbox Satellite",
10607
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/mapboxSatellite.png"
10608
- },
10609
- {
10610
- id: EDefaultImagery.MapBoxStreets,
10611
- name: "Mapbox Streets",
10612
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/mapboxTerrain.png"
10613
- },
10614
- {
10615
- id: EDefaultImagery.MapBoxStreetsClassic,
10616
- name: "Mapbox Streets Classic",
10617
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/mapboxStreets.png"
10618
- },
10619
- {
10620
- id: EDefaultImagery.EsriWorldImagery,
10621
- name: "Esri World Imagery",
10622
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/esriWorldImagery.png"
10623
- },
10624
- {
10625
- id: EDefaultImagery.EsriWorldStreetMap,
10626
- name: "Esri World Street Map",
10627
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/esriWorldStreetMap.png"
10628
- },
10629
- {
10630
- id: EDefaultImagery.EsriNationalGeographic,
10631
- name: "Esri National Geographic",
10632
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/esriNationalGeographic.png"
10633
- },
10634
- {
10635
- id: EDefaultImagery.OpenStreetMap,
10636
- name: "Open Street Map",
10637
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/openStreetMap.png"
10638
- },
10639
- {
10640
- id: EDefaultImagery.LINZ,
10641
- name: "LINZ",
10642
- iconUrl: "https://template.ui.nextspace.host/media/linz.jpg"
10643
- },
10644
- {
10645
- id: EDefaultImagery.StamenWaterColor,
10646
- name: "Stamen Water Color",
10647
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/stamenWatercolor.png"
10648
- },
10649
- {
10650
- id: EDefaultImagery.StamenToner,
10651
- name: "Stamen Toner",
10652
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/stamenToner.png"
10653
- },
10654
- {
10655
- id: EDefaultImagery.ThunderforestCycle,
10656
- name: "Thunderforest Cycle"
10657
- },
10658
- {
10659
- id: EDefaultImagery.ThunderforestTransport,
10660
- name: "Thunderforest Transport"
10661
- },
10662
- {
10663
- id: EDefaultImagery.ThunderforestLandscape,
10664
- name: "Thunderforest Landscape"
10665
- },
10666
- {
10667
- id: EDefaultImagery.Grid,
10668
- name: "Grid",
10669
- iconUrl: "https://template.api.nextspace-uat.net/file/2885d8df-028b-4f5c-80b3-2634f7e7cf69.png"
10607
+ function GetCacheKey(accountId, appSettingsId) {
10608
+ if (appSettingsId) {
10609
+ return Api.ECacheKey.Account + Api.ECacheKey.Id + accountId + Api.ECacheKey + appSettingsId;
10670
10610
  }
10671
- ];
10611
+ return Api.ECacheKey.Account + Api.ECacheKey.Id + accountId;
10612
+ }
10613
+ Account.GetCacheKey = GetCacheKey;
10672
10614
  /**
10673
- * Available terrain defaults.
10615
+ * Returns cache identifier for a list of accounts by session ID.
10616
+ * Example: {
10617
+ * const api: BruceApi.Api = ...;
10618
+ * const key = GetListCacheKey(api.GetSessionId());
10619
+ * api.Cache.Remove(key);
10620
+ * }
10621
+ * @param ssid
10622
+ * @returns
10674
10623
  */
10675
- let EDefaultTerrain;
10676
- (function (EDefaultTerrain) {
10677
- EDefaultTerrain["CesiumWorldTerrain"] = "cesiumworldterrain";
10678
- EDefaultTerrain["FlatTerrain"] = "flatterrain";
10679
- EDefaultTerrain["LINZ"] = "linz";
10680
- })(EDefaultTerrain = ProjectViewTile.EDefaultTerrain || (ProjectViewTile.EDefaultTerrain = {}));
10624
+ function GetListCacheKey(ssid) {
10625
+ return Api.ECacheKey.Account + Api.ECacheKey.Session + Api.ECacheKey.Id + ssid;
10626
+ }
10627
+ Account.GetListCacheKey = GetListCacheKey;
10681
10628
  /**
10682
- * Prepared array for UI.
10683
- * TODO: Im not happy with icon urls sitting in the code. I'd prefer we ship these icons in the library as files.
10629
+ * Returns cache identifier for a list of database regions.
10630
+ * Example: {
10631
+ * const api: BruceApi.Api = ...;
10632
+ * const key = GetDbRegionListCacheKey();
10633
+ * api.Cache.Remove(key);
10634
+ * }
10635
+ * @returns
10684
10636
  */
10685
- ProjectViewTile.DefaultTerrains = [
10686
- {
10687
- id: EDefaultTerrain.CesiumWorldTerrain,
10688
- name: "Cesium World Terrain",
10689
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/TerrainProviders/CesiumWorldTerrain.png"
10690
- },
10691
- {
10692
- id: EDefaultTerrain.LINZ,
10693
- name: "LINZ",
10694
- iconUrl: "https://template.ui.nextspace.host/media/linz.jpg"
10695
- },
10696
- {
10697
- id: EDefaultTerrain.FlatTerrain,
10698
- name: "Flat Terrain",
10699
- }
10700
- ];
10701
- })(ProjectViewTile || (ProjectViewTile = {}));
10702
-
10703
- /**
10704
- * Deprecated Project View record.
10705
- * This was used in the legacy web Navigator.
10706
- */
10707
- var ProjectViewLegacy;
10708
- (function (ProjectViewLegacy) {
10709
- ProjectViewLegacy.DATA_VERSION = 1;
10710
- })(ProjectViewLegacy || (ProjectViewLegacy = {}));
10711
-
10712
- /**
10713
- * Deprecated Project View Bookmark record.
10714
- * This was used in the legacy web Navigator.
10715
- */
10716
- var ProjectViewLegacyBookmark;
10717
- (function (ProjectViewLegacyBookmark) {
10718
- ProjectViewLegacyBookmark.DATA_VERSION = 1;
10719
- })(ProjectViewLegacyBookmark || (ProjectViewLegacyBookmark = {}));
10637
+ function GetDbRegionListCacheKey() {
10638
+ return Api.ECacheKey.DatabaseRegion;
10639
+ }
10640
+ Account.GetDbRegionListCacheKey = GetDbRegionListCacheKey;
10641
+ })(Account || (Account = {}));
10720
10642
 
10721
10643
  /**
10722
- * Describes the "Pending Action" concept within Nextspace.
10723
- * A pending action is a record of a server-side background process.
10724
- * This record is used to monitor its progress and completion state.
10644
+ * A hosting location is a record for a possible bruce-api server configuration.
10645
+ * A hosting location will have one or many database servers as well, this is an additional setting.
10725
10646
  */
10726
- var PendingAction;
10727
- (function (PendingAction) {
10728
- /**
10729
- * Available pending action statuses.
10730
- */
10731
- let EStatus;
10732
- (function (EStatus) {
10733
- EStatus["InProgress"] = "IN_PROGRESS";
10734
- EStatus["Cancelled"] = "CANCELLED";
10735
- EStatus["Complete"] = "COMPLETE";
10736
- EStatus["Failed"] = "FAILED";
10737
- })(EStatus = PendingAction.EStatus || (PendingAction.EStatus = {}));
10647
+ var HostingLocation;
10648
+ (function (HostingLocation) {
10738
10649
  /**
10739
- * Available message types.
10650
+ * Returns a list of hosting locations.
10651
+ * @Warning: This will not return the Settings property.
10652
+ * @param params
10653
+ * @returns
10740
10654
  */
10741
- let EMessageType;
10742
- (function (EMessageType) {
10743
- EMessageType["Warn"] = "WARNING";
10744
- EMessageType["Error"] = "ERROR";
10745
- EMessageType["Status"] = "STATUS";
10746
- EMessageType["Info"] = "INFO";
10747
- })(EMessageType = PendingAction.EMessageType || (PendingAction.EMessageType = {}));
10655
+ function GetList(params) {
10656
+ return __awaiter(this, void 0, void 0, function* () {
10657
+ let { api, req } = params;
10658
+ if (!api) {
10659
+ api = ENVIRONMENT.Api().GetGuardianApi();
10660
+ }
10661
+ const res = yield api.GET("hostinglocations", Api.PrepReqParams(req));
10662
+ return {
10663
+ locations: res.Items
10664
+ };
10665
+ });
10666
+ }
10667
+ HostingLocation.GetList = GetList;
10748
10668
  /**
10749
- * Returns a pending action record.
10669
+ * Returns a hosting location record by ID.
10750
10670
  * @param params
10751
10671
  * @returns
10752
10672
  */
10753
- function Get(params) {
10673
+ function GetById(params) {
10754
10674
  return __awaiter(this, void 0, void 0, function* () {
10755
- let { api, actionId, req: reqParams } = params;
10756
- if (!actionId) {
10757
- throw ("Action ID is required.");
10675
+ let { id, api, req } = params;
10676
+ if (!id) {
10677
+ throw ("Invalid id");
10758
10678
  }
10759
10679
  if (!api) {
10760
- api = ENVIRONMENT.Api().GetBruceApi();
10680
+ api = ENVIRONMENT.Api().GetGuardianApi();
10761
10681
  }
10762
- const data = yield api.GET(`pendingAction/${actionId}`, Api.PrepReqParams(reqParams));
10682
+ const res = yield api.GET(`hostinglocation/id/${id}`, Api.PrepReqParams(req));
10763
10683
  return {
10764
- action: data
10684
+ location: res
10765
10685
  };
10766
10686
  });
10767
10687
  }
10768
- PendingAction.Get = Get;
10688
+ HostingLocation.GetById = GetById;
10769
10689
  /**
10770
- * Returns a list of pending action records.
10690
+ * Returns a hosting location record by key.
10771
10691
  * @param params
10772
10692
  * @returns
10773
10693
  */
10774
- function GetRelevantList(params) {
10694
+ function GetByKey(params) {
10775
10695
  return __awaiter(this, void 0, void 0, function* () {
10776
- let { api, stricter, reqParams } = params;
10696
+ let { key, api, req } = params;
10697
+ if (!key) {
10698
+ throw ("Invalid key");
10699
+ }
10777
10700
  if (!api) {
10778
- api = ENVIRONMENT.Api().GetBruceApi();
10701
+ api = ENVIRONMENT.Api().GetGuardianApi();
10779
10702
  }
10780
- const data = yield api.GET(`pendingActions/important?Update=${Boolean(stricter)}`, Api.PrepReqParams(reqParams));
10703
+ const res = yield api.GET(`hostinglocation/key/${key}`, Api.PrepReqParams(req));
10781
10704
  return {
10782
- actions: data.Items
10705
+ location: res
10783
10706
  };
10784
10707
  });
10785
10708
  }
10786
- PendingAction.GetRelevantList = GetRelevantList;
10709
+ HostingLocation.GetByKey = GetByKey;
10787
10710
  /**
10788
- * Returns a list of pending action record messages.
10711
+ * Returns hostingLocationKey from given db url.
10712
+ * Some older accounts don't have this set, so we need to guess it.
10789
10713
  * @param params
10790
10714
  * @returns
10791
10715
  */
10792
- function GetMessages(params) {
10716
+ function GuessKey(params) {
10717
+ const { DBServer: databaseUrl } = params;
10718
+ if (databaseUrl.includes("hyperfarm-prod-instance-1")) {
10719
+ return "HYPERFARM";
10720
+ }
10721
+ if (databaseUrl.includes("prod-syd1.nextspace.host")) {
10722
+ return "AU-VULTR-FIRST";
10723
+ }
10724
+ else if (databaseUrl.includes("prod-nyc1.nextspace.host")) {
10725
+ return "US-VULTR-FIRST";
10726
+ }
10727
+ else if (databaseUrl.includes("prod-ams1.nextspace.host")) {
10728
+ return "EU-VULTR-FIRST";
10729
+ }
10730
+ else if (databaseUrl.includes("prod-sing1.nextspace.host")) {
10731
+ return "SE-VULTR-FIRST";
10732
+ }
10733
+ else if (databaseUrl.includes("dev-first")) {
10734
+ return "DEV-FIRST";
10735
+ }
10736
+ else if (databaseUrl.includes(".ap-southeast-1.")) {
10737
+ return "SE";
10738
+ }
10739
+ else if (databaseUrl.includes(".us-west-1.")) {
10740
+ return "US";
10741
+ }
10742
+ else if (databaseUrl.includes(".eu-west-3.")) {
10743
+ return "EU";
10744
+ }
10745
+ else if (databaseUrl.includes("bruce-prod-au")) {
10746
+ return "AU";
10747
+ }
10748
+ else if (databaseUrl.includes("bruce-dev")) {
10749
+ return "DEV";
10750
+ }
10751
+ return null;
10752
+ }
10753
+ HostingLocation.GuessKey = GuessKey;
10754
+ /**
10755
+ * Returns a hosting location key by account ID.
10756
+ * @param params
10757
+ * @returns
10758
+ */
10759
+ function GetKeyByAccountId(params) {
10793
10760
  return __awaiter(this, void 0, void 0, function* () {
10794
- let { api, actionId, order, startIndex, amount, req: reqParams, types } = params;
10761
+ let { accountId, apiSettings, api, account, req } = params;
10762
+ if (!accountId && !apiSettings) {
10763
+ throw ("Invalid accountId or apiSettings");
10764
+ }
10795
10765
  if (!api) {
10796
- api = ENVIRONMENT.Api().GetBruceApi();
10766
+ api = ENVIRONMENT.Api().GetGuardianApi();
10797
10767
  }
10798
- if (amount == null) {
10799
- amount = 500;
10768
+ // We'll prioritize account record if provided.
10769
+ if (accountId && !account) {
10770
+ account = (yield Account.Get({
10771
+ accountId,
10772
+ api,
10773
+ req
10774
+ })).account;
10800
10775
  }
10801
- if (startIndex == null) {
10802
- startIndex = 0;
10776
+ if (account === null || account === void 0 ? void 0 : account["HostingLocation.Key"]) {
10777
+ return {
10778
+ key: account["HostingLocation.Key"],
10779
+ isLegacy: false
10780
+ };
10803
10781
  }
10804
- if (order == null) {
10805
- order = Api.ESortOrder.Asc;
10782
+ // Fallback to settings JSON for older records.
10783
+ const settings = apiSettings ? apiSettings : (yield Account.GetAppSettings({
10784
+ api,
10785
+ accountId,
10786
+ appId: Account.EAppId.BruceApi
10787
+ })).settings;
10788
+ let hostingKey = settings["HostingLocation.Key"];
10789
+ let isLegacy = false;
10790
+ if (!hostingKey) {
10791
+ hostingKey = settings.DBLocation;
10792
+ isLegacy = true;
10806
10793
  }
10807
- let args = `?SortOrder=${order == Api.ESortOrder.Desc ? "DESC" : "ASC"}&PageSize=${amount}&PageIndex=${startIndex}`;
10808
- if (types === null || types === void 0 ? void 0 : types.length) {
10809
- for (let i = 0; i < types.length; i++) {
10810
- args += `&Type=${types[i]}`;
10811
- }
10794
+ if (!hostingKey) {
10795
+ hostingKey = GuessKey({
10796
+ DBServer: settings.DBServer
10797
+ });
10798
+ isLegacy = true;
10812
10799
  }
10813
- const data = yield api.GET(`pendingAction/${actionId}/progressMessages` + args, Api.PrepReqParams(reqParams));
10814
10800
  return {
10815
- messages: data.Items
10801
+ key: hostingKey,
10802
+ isLegacy
10816
10803
  };
10817
10804
  });
10818
10805
  }
10819
- PendingAction.GetMessages = GetMessages;
10806
+ HostingLocation.GetKeyByAccountId = GetKeyByAccountId;
10820
10807
  /**
10821
- * Requests to cancel a pending action.
10808
+ * Returns a hosting location record by account ID.
10822
10809
  * @param params
10810
+ * @returns
10823
10811
  */
10824
- function Cancel(params) {
10812
+ function GetByAccountId(params) {
10825
10813
  return __awaiter(this, void 0, void 0, function* () {
10826
- let { api, actionId, req: reqParams } = params;
10827
- if (!actionId) {
10828
- throw ("Action ID is required.");
10829
- }
10814
+ let { accountId, apiSettings, api, req, account } = params;
10830
10815
  if (!api) {
10831
- api = ENVIRONMENT.Api().GetBruceApi();
10816
+ api = ENVIRONMENT.Api().GetGuardianApi();
10832
10817
  }
10833
- yield api.DELETE(`pendingAction/${actionId}`, Api.PrepReqParams(reqParams));
10818
+ const data = yield GetKeyByAccountId({
10819
+ accountId,
10820
+ account,
10821
+ apiSettings,
10822
+ api,
10823
+ req
10824
+ });
10825
+ if (!(data === null || data === void 0 ? void 0 : data.key)) {
10826
+ return null;
10827
+ }
10828
+ const key = yield GetByKey({
10829
+ key: data.key,
10830
+ api,
10831
+ req
10832
+ });
10833
+ return key;
10834
10834
  });
10835
10835
  }
10836
- PendingAction.Cancel = Cancel;
10837
- })(PendingAction || (PendingAction = {}));
10836
+ HostingLocation.GetByAccountId = GetByAccountId;
10837
+ })(HostingLocation || (HostingLocation = {}));
10838
10838
 
10839
10839
  /**
10840
10840
  * Permissions in Nextspace are arbitrary strings with meaning in specific contexts.
@@ -13346,7 +13346,12 @@ var Plugin;
13346
13346
  cacheKey = 0;
13347
13347
  }
13348
13348
  return {
13349
- indexFileUrl: `${api.GetBaseUrl()}ui.plugin/${pluginId}/file/index.jsc?version=${cacheKey}`
13349
+ indexFileUrl: api.ConstructUrl({
13350
+ url: `ui.plugin/${pluginId}/file/index.jsc`,
13351
+ urlParams: {
13352
+ "version": String(cacheKey)
13353
+ }
13354
+ })
13350
13355
  };
13351
13356
  }
13352
13357
  Plugin.GetLoadUrl = GetLoadUrl;
@@ -13729,7 +13734,7 @@ var DataSource;
13729
13734
  })(DataSource || (DataSource = {}));
13730
13735
 
13731
13736
  // This is updated with the package.json version on build.
13732
- const VERSION = "4.5.7";
13737
+ const VERSION = "4.5.9";
13733
13738
 
13734
13739
  export { VERSION, AnnDocument, CustomForm, AbstractApi, Api, BruceApi, GlobalApi, GuardianApi, ApiGetters, Calculator, Bounds, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, BruceVariable, LRUCache, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityLodCategory, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityCoords, EntityTypeVisualSettings, EntityAttribute, EntityHistoricData, EntityTableView, Comment, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, ProjectViewLegacyTile, ProjectViewTile, ProjectViewLegacy, ProjectViewLegacyBookmark, PendingAction, MessageBroker, HostingLocation, Style, Tileset, Permission, Session, UserGroup, User, Account, AccountInvite, AccountFeatures, AccountLimits, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils, DataLab, ImportCad, ImportCsv, ImportJson, ImportKml, ImportedFile, Markup, Uploader, Plugin, ENVIRONMENT, DataSource };
13735
13740
  //# sourceMappingURL=bruce-models.es5.js.map