bruce-models 4.5.8 → 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.
@@ -837,767 +837,444 @@
837
837
  GuardianApi.Api = Api$$1;
838
838
  })(exports.GuardianApi || (exports.GuardianApi = {}));
839
839
 
840
- // Some dead accounts that we don't want to show in the UI.
841
- // Some accounts may not be "dead" but instead purposely don't have a NextspaceAPI database so we'll avoid them too.
842
- const ACCOUNT_EXCLUSIONS = ["hyperportal", "hypeportal", "bviewer"];
843
- (function (Account) {
844
- /**
845
- * Known Nextspace applications we store settings for.
846
- */
847
- let EAppId;
848
- (function (EAppId) {
849
- EAppId["BruceApi"] = "BruceAPI";
850
- EAppId["Navigator"] = "Navigator";
851
- EAppId["Operator"] = "BruceClientAdmin";
852
- })(EAppId = Account.EAppId || (Account.EAppId = {}));
853
- /**
854
- * Possible starter content options.
855
- * When creating a new account you can populate it with certain default data.
856
- */
857
- let EStarterContent;
858
- (function (EStarterContent) {
859
- EStarterContent["Default"] = "default";
860
- EStarterContent["None"] = "none";
861
- })(EStarterContent = Account.EStarterContent || (Account.EStarterContent = {}));
840
+ (function (BruceApi) {
862
841
  /**
863
- * Gets a client account record by ID.
864
- * @param params
865
- * @returns
842
+ * This is the request handler for Bruce Api,
843
+ * it should be passed to any method that wants to communicate with this particular api.
866
844
  */
867
- function Get(params) {
868
- return __awaiter(this, void 0, void 0, function* () {
869
- let { api, accountId: id, req: reqParams } = params;
870
- if (!api) {
871
- api = exports.ENVIRONMENT.Api().GetGuardianApi();
872
- }
873
- const cache = yield api.GetCacheItem(GetCacheKey(id), reqParams);
874
- if (cache === null || cache === void 0 ? void 0 : cache.found) {
875
- return cache.data;
845
+ class Api$$1 extends AbstractApi {
846
+ get AccountId() {
847
+ return this.accountId;
848
+ }
849
+ get MessageBroker() {
850
+ return this.messageBroker;
851
+ }
852
+ get ConfigLoadAttempted() {
853
+ return this.configLoadAttempted;
854
+ }
855
+ get Version() {
856
+ return this.version;
857
+ }
858
+ get Loading() {
859
+ return this.loadProm;
860
+ }
861
+ constructor(params) {
862
+ super({
863
+ ssidHeader: "x-sessionid",
864
+ cacheId: `BRUCE_API_${params === null || params === void 0 ? void 0 : params.env}_${params === null || params === void 0 ? void 0 : params.accountId}_`
865
+ });
866
+ // Load cancelled indicates the user set a custom base url.
867
+ // This will stop the regional url from being set if it's still loading.
868
+ this.loadCancelled = false;
869
+ // Indicates if loading the regional configuration was already called.
870
+ this.configLoadAttempted = false;
871
+ let { accountId, env, guardian, loadRegionalBaseUrl, loadConfig, loadWebSocket, dummy } = params;
872
+ this.accountId = accountId;
873
+ this.env = env !== null && env !== void 0 ? env : exports.Api.EEnv.PROD;
874
+ if (!dummy) {
875
+ // Backwards compatibility.
876
+ if (loadRegionalBaseUrl) {
877
+ loadConfig = true;
878
+ }
879
+ if (loadConfig) {
880
+ // Mark it as attempted right away because we don't want any external calls while it gets to that async point.
881
+ this.configLoadAttempted = true;
882
+ }
883
+ this.loadProm = this.init(guardian, loadConfig, loadWebSocket);
876
884
  }
877
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
878
- try {
879
- const data = yield api.GET(`accountbyid/${id}`, reqParams);
880
- // Update the cache by subdomain as well in case it's different to the ID.
881
- if ((data === null || data === void 0 ? void 0 : data.ID) && (reqParams === null || reqParams === void 0 ? void 0 : reqParams.noCache) != false) {
882
- yield api.SetCacheItem({
883
- key: data.Subdomain,
884
- value: prom,
885
- req: reqParams
886
- });
887
- }
888
- res({
889
- account: data
885
+ }
886
+ /**
887
+ * Loads regional base url and sets up message broker.
888
+ * @param guardian Required for loading regional base url.
889
+ * @param loadConfig
890
+ * @returns
891
+ */
892
+ init(guardian, loadConfig, loadWebSocket) {
893
+ return __awaiter(this, void 0, void 0, function* () {
894
+ if (!this.accountId) {
895
+ throw ("accountId is required.");
896
+ }
897
+ // Set using a stable default.
898
+ const domain = this.getDomain();
899
+ this.baseUrl = `https://${this.accountId}.api.${domain}/`;
900
+ // Attempt to load regional configuration.
901
+ if (loadConfig) {
902
+ yield this.LoadConfig({
903
+ guardian: guardian,
904
+ // We marked it as attempted to load outside this method to fight any external calls.
905
+ // So we'll force load it now.
906
+ forceLoad: true
890
907
  });
891
908
  }
892
- catch (e) {
893
- rej(e);
909
+ // Get the version.
910
+ if (this.baseUrl) {
911
+ const full = this.ConstructUrl({
912
+ url: "version"
913
+ });
914
+ const data = yield this.get(full);
915
+ if (data === null || data === void 0 ? void 0 : data["Bruce-API"]) {
916
+ this.version = data["Bruce-API"];
917
+ }
918
+ else {
919
+ this.version = "UNKNOWN";
920
+ }
921
+ }
922
+ // Start web socket connection.
923
+ if (loadWebSocket == true) {
924
+ try {
925
+ const full = this.ConstructUrl();
926
+ this.messageBroker = new exports.MessageBroker.WebSocketBroker(full, this.env);
927
+ }
928
+ catch (e) {
929
+ console.warn("BruceApi: Failed to create message broker.", e);
930
+ }
894
931
  }
895
- }));
896
- yield api.SetCacheItem({
897
- key: GetCacheKey(id),
898
- value: prom,
899
- req: reqParams
900
932
  });
901
- return prom;
902
- });
903
- }
904
- Account.Get = Get;
905
- /**
906
- * Returns a client account record by subdomain or ID.
907
- * @param params
908
- * @returns
909
- */
910
- function GetBySubdomain(params) {
911
- return __awaiter(this, void 0, void 0, function* () {
912
- let { api, subdomain, req: reqParams } = params;
913
- if (!api) {
914
- api = exports.ENVIRONMENT.Api().GetGuardianApi();
915
- }
916
- const cache = yield api.GetCacheItem(GetCacheKey(subdomain), reqParams);
917
- if (cache === null || cache === void 0 ? void 0 : cache.found) {
918
- return cache.data;
933
+ }
934
+ getDomain() {
935
+ const env = this.env.toUpperCase();
936
+ let domain = "nextspace.host";
937
+ switch (env) {
938
+ case exports.Api.EEnv.DEV:
939
+ domain = "nextspace-dev.net";
940
+ break;
941
+ case exports.Api.EEnv.STG:
942
+ domain = "nextspace-stg.net";
943
+ break;
944
+ case exports.Api.EEnv.UAT:
945
+ domain = "nextspace-uat.net";
946
+ break;
947
+ case exports.Api.EEnv.PROD:
948
+ domain = "nextspace.host";
949
+ break;
950
+ default:
951
+ console.error("Specified Environment is not valid. SuppliedEnv=" + env);
919
952
  }
920
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
953
+ return domain;
954
+ }
955
+ /**
956
+ * Loads the regional configuration for the account.
957
+ * If the config is already loaded then this will do nothing.
958
+ */
959
+ LoadConfig(params) {
960
+ return __awaiter(this, void 0, void 0, function* () {
961
+ let { guardian, forceLoad } = (params !== null && params !== void 0 ? params : {});
962
+ if (this.configLoadAttempted && forceLoad != true) {
963
+ return;
964
+ }
965
+ this.configLoadAttempted = true;
921
966
  try {
922
- const data = yield api.GET(`account/${subdomain}`, reqParams);
923
- // Update the cache by ID as well in case it's different to the subdomain.
924
- if ((data === null || data === void 0 ? void 0 : data.ID) && (reqParams === null || reqParams === void 0 ? void 0 : reqParams.noCache) != false) {
925
- yield api.SetCacheItem({
926
- key: data.ID,
927
- value: prom,
928
- req: reqParams
967
+ if (!guardian) {
968
+ guardian = new exports.GuardianApi.Api({
969
+ env: this.env
929
970
  });
930
971
  }
931
- res({
932
- account: data
972
+ const { account } = yield exports.Account.GetBySubdomain({
973
+ subdomain: this.accountId,
974
+ api: guardian
933
975
  });
976
+ if (!this.loadCancelled) {
977
+ // Set the calculated base url.
978
+ // If this is not available then this is considered a critical failure.
979
+ // However I am not crashing here because I want to monitor this in production.
980
+ if (account.URL) {
981
+ const urls = account.URL;
982
+ if (urls === null || urls === void 0 ? void 0 : urls.Base) {
983
+ this.baseUrl = urls.Base;
984
+ }
985
+ if (urls === null || urls === void 0 ? void 0 : urls.CDNEntities) {
986
+ this.EntityCdnUrl = urls.CDNEntities;
987
+ }
988
+ if (urls === null || urls === void 0 ? void 0 : urls.CDNTileset) {
989
+ this.TilesetCdnUrl = urls.CDNTileset;
990
+ }
991
+ if (urls === null || urls === void 0 ? void 0 : urls.CDNLegacyTileset) {
992
+ this.LegacyTilesetCdnUrl = urls.CDNLegacyTileset;
993
+ }
994
+ if (urls === null || urls === void 0 ? void 0 : urls.CDNBase) {
995
+ this.cdnBaseUrl = urls.CDNBase;
996
+ }
997
+ }
998
+ else {
999
+ console.error("BruceApi: Failed to load regional configuration for account.", this.accountId);
1000
+ }
1001
+ }
934
1002
  }
935
1003
  catch (e) {
936
- rej(e);
1004
+ console.error(e);
937
1005
  }
938
- }));
939
- yield api.SetCacheItem({
940
- key: GetCacheKey(subdomain),
941
- value: prom,
942
- req: reqParams
943
1006
  });
944
- return prom;
945
- });
946
- }
947
- Account.GetBySubdomain = GetBySubdomain;
948
- /**
949
- * Gets a list of client accounts related to the current session user.
950
- * @param params
951
- * @returns
952
- */
953
- function GetRelatedList(params) {
954
- return __awaiter(this, void 0, void 0, function* () {
955
- let { api, req: reqParams } = params;
956
- if (!api) {
957
- api = exports.ENVIRONMENT.Api().GetGuardianApi();
958
- }
959
- const cache = yield api.GetCacheItem(GetListCacheKey(api.GetSessionId()), reqParams);
960
- if (cache === null || cache === void 0 ? void 0 : cache.found) {
961
- return cache.data;
962
- }
963
- const req = api.GET("user/relatedClientAccounts", reqParams);
964
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
965
- try {
966
- const data = yield req;
967
- const items = data.Items.filter((x) => !ACCOUNT_EXCLUSIONS.includes(x.ID));
968
- res({
969
- accounts: items
970
- });
971
- }
972
- catch (e) {
973
- rej(e);
1007
+ }
1008
+ /**
1009
+ * Creates a message broker instance and returns it.
1010
+ * If an instance is already created, it will return that one.
1011
+ * @warning This will await the loading promise to avoid using data that isn't ready.
1012
+ */
1013
+ ConnectWebsocket() {
1014
+ return __awaiter(this, void 0, void 0, function* () {
1015
+ yield this.loadProm;
1016
+ if (this.messageBroker) {
1017
+ return this.messageBroker;
974
1018
  }
975
- }));
976
- yield api.SetCacheItem({
977
- key: GetListCacheKey(api.GetSessionId()),
978
- value: prom,
979
- req: reqParams
1019
+ const full = this.ConstructUrl();
1020
+ this.messageBroker = new exports.MessageBroker.WebSocketBroker(full, this.env);
1021
+ return this.messageBroker;
980
1022
  });
981
- return prom;
982
- });
983
- }
984
- Account.GetRelatedList = GetRelatedList;
985
- /**
986
- * Gets application settings for a specific client account.
987
- * @param params
988
- * @returns
989
- */
990
- function GetAppSettings(params) {
991
- return __awaiter(this, void 0, void 0, function* () {
992
- let { api, accountId: id, appId, req: reqParams } = params;
993
- if (!api) {
994
- api = exports.ENVIRONMENT.Api().GetGuardianApi();
1023
+ }
1024
+ /**
1025
+ * Warning: This method does not wait for init to finish loading.
1026
+ * This means the url could be changed once fully initialized.
1027
+ * The url will be valid either way, but the loaded one may be faster as it is region specific.
1028
+ * Await the "Loading" promise if you care about this.
1029
+ * @warning use ConstructUrl instead as the baseUrl may have a query param for the account.
1030
+ * @returns
1031
+ */
1032
+ GetBaseUrl() {
1033
+ return this.baseUrl;
1034
+ }
1035
+ /**
1036
+ * Warning: Wait the "Loading" promise before using this url.
1037
+ * @warning use ConstructUrl instead as the baseUrl may have a query param for the account.
1038
+ * @returns
1039
+ */
1040
+ GetCdnBaseUrl() {
1041
+ return this.cdnBaseUrl;
1042
+ }
1043
+ /**
1044
+ * Returns a url with the provided url appended to the loaded base url.
1045
+ * If the base url is not loaded yet, this will return null.
1046
+ * @param params
1047
+ */
1048
+ ConstructUrl(params) {
1049
+ if (!(params === null || params === void 0 ? void 0 : params.url)) {
1050
+ return null;
995
1051
  }
996
- const cache = yield api.GetCacheItem(GetCacheKey(id, appId), reqParams);
997
- if (cache === null || cache === void 0 ? void 0 : cache.found) {
998
- return cache.data;
1052
+ if ((params === null || params === void 0 ? void 0 : params.cdn) && this.cdnBaseUrl) {
1053
+ return this.ConstructCdnUrl(params.url, params.urlParams);
999
1054
  }
1000
- const req = yield api.GET(`account/${id}?ApplicationID=${appId}`, reqParams);
1001
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
1002
- var _a;
1003
- try {
1004
- const data = yield req;
1005
- const settings = (_a = data === null || data === void 0 ? void 0 : data["Application.Settings"]) !== null && _a !== void 0 ? _a : {};
1006
- res({
1007
- settings: settings
1055
+ const tmp = new URL(this.baseUrl);
1056
+ if (params === null || params === void 0 ? void 0 : params.urlParams) {
1057
+ if (params.urlParams instanceof URLSearchParams) {
1058
+ params.urlParams.forEach((value, key) => {
1059
+ tmp.searchParams.append(key, value);
1008
1060
  });
1009
1061
  }
1010
- catch (e) {
1011
- rej(e);
1062
+ else {
1063
+ for (const key in params.urlParams) {
1064
+ tmp.searchParams.append(key, params.urlParams[key]);
1065
+ }
1012
1066
  }
1013
- }));
1014
- yield api.SetCacheItem({
1015
- key: GetCacheKey(id, appId),
1016
- value: prom,
1017
- req: reqParams
1018
- });
1019
- return prom;
1020
- });
1021
- }
1022
- Account.GetAppSettings = GetAppSettings;
1023
- /**
1024
- * Updates application settings for a specific client account + application.
1025
- * WARNING: Do not update API settings without knowing what you're doing.
1026
- * @param params
1027
- * @returns
1028
- */
1029
- function UpdateAppSettings(params) {
1030
- return __awaiter(this, void 0, void 0, function* () {
1031
- let { api, accountId: id, appId, settings: data, req: reqParams } = params;
1032
- if (!api) {
1033
- api = exports.ENVIRONMENT.Api().GetGuardianApi();
1034
- }
1035
- const res = yield api.POST(`account/${id}/applicationSettings/${appId}`, data, reqParams);
1036
- yield api.Cache.RemoveByStartsWith(exports.Api.ECacheKey.Account + exports.Api.ECacheKey.Id + id);
1037
- return {
1038
- settings: res
1039
- };
1040
- });
1041
- }
1042
- Account.UpdateAppSettings = UpdateAppSettings;
1043
- /**
1044
- * Creates a new Nextspace account using given details.
1045
- * @param params
1046
- * @returns
1047
- */
1048
- function Create(params) {
1049
- return __awaiter(this, void 0, void 0, function* () {
1050
- let { api, accountId: id, name, hostingLocationKey, starterContent, req: reqParams } = params;
1051
- if (!id || !name || !hostingLocationKey) {
1052
- throw new Error("Id, Name and hostingLocationKey are required.");
1053
1067
  }
1054
- if (!api) {
1055
- api = exports.ENVIRONMENT.Api().GetBruceApi();
1068
+ // Ensure the url ends with a slash.
1069
+ if (!tmp.pathname.endsWith("/")) {
1070
+ tmp.pathname += "/";
1056
1071
  }
1057
- if (!starterContent) {
1058
- starterContent = EStarterContent.None;
1072
+ if (params === null || params === void 0 ? void 0 : params.url) {
1073
+ // Ensure the url does not start with a slash.
1074
+ // This is because the base url already has a slash at the end.
1075
+ if (params.url.startsWith("/")) {
1076
+ params.url = params.url.substring(1);
1077
+ }
1078
+ tmp.pathname += params.url;
1059
1079
  }
1060
- const reqData = {
1061
- "Name": name,
1062
- "HostingLocation.Key": hostingLocationKey,
1063
- "StarterContent": starterContent
1064
- };
1065
- const res = yield api.POST(`clientAccount/${id}`, reqData, exports.Api.PrepReqParams(reqParams));
1066
- const resData = {
1067
- account: res
1068
- };
1069
- api.Cache.Remove(GetListCacheKey(api.GetSessionId()));
1070
- return resData;
1071
- });
1072
- }
1073
- Account.Create = Create;
1074
- /**
1075
- * Returns cache identifier for an account by ID.
1076
- * Example: {
1077
- * const api: BruceApi.Api = ...;
1078
- * const key = GetCacheKey(1);
1079
- * api.Cache.Remove(key);
1080
- * }
1081
- * @param accountId
1082
- * @param appSettingsId
1083
- * @returns
1084
- */
1085
- function GetCacheKey(accountId, appSettingsId) {
1086
- if (appSettingsId) {
1087
- return exports.Api.ECacheKey.Account + exports.Api.ECacheKey.Id + accountId + exports.Api.ECacheKey + appSettingsId;
1080
+ return tmp.toString();
1088
1081
  }
1089
- return exports.Api.ECacheKey.Account + exports.Api.ECacheKey.Id + accountId;
1090
- }
1091
- Account.GetCacheKey = GetCacheKey;
1092
- /**
1093
- * Returns cache identifier for a list of accounts by session ID.
1094
- * Example: {
1095
- * const api: BruceApi.Api = ...;
1096
- * const key = GetListCacheKey(api.GetSessionId());
1097
- * api.Cache.Remove(key);
1098
- * }
1099
- * @param ssid
1100
- * @returns
1101
- */
1102
- function GetListCacheKey(ssid) {
1103
- return exports.Api.ECacheKey.Account + exports.Api.ECacheKey.Session + exports.Api.ECacheKey.Id + ssid;
1104
- }
1105
- Account.GetListCacheKey = GetListCacheKey;
1106
- /**
1107
- * Returns cache identifier for a list of database regions.
1108
- * Example: {
1109
- * const api: BruceApi.Api = ...;
1110
- * const key = GetDbRegionListCacheKey();
1111
- * api.Cache.Remove(key);
1112
- * }
1113
- * @returns
1114
- */
1115
- function GetDbRegionListCacheKey() {
1116
- return exports.Api.ECacheKey.DatabaseRegion;
1117
- }
1118
- Account.GetDbRegionListCacheKey = GetDbRegionListCacheKey;
1119
- })(exports.Account || (exports.Account = {}));
1120
-
1121
- (function (HostingLocation) {
1122
- /**
1123
- * Returns a list of hosting locations.
1124
- * @Warning: This will not return the Settings property.
1125
- * @param params
1126
- * @returns
1127
- */
1128
- function GetList(params) {
1129
- return __awaiter(this, void 0, void 0, function* () {
1130
- let { api, req } = params;
1131
- if (!api) {
1132
- api = exports.ENVIRONMENT.Api().GetGuardianApi();
1133
- }
1134
- const res = yield api.GET("hostinglocations", exports.Api.PrepReqParams(req));
1135
- return {
1136
- locations: res.Items
1137
- };
1138
- });
1139
- }
1140
- HostingLocation.GetList = GetList;
1141
- /**
1142
- * Returns a hosting location record by ID.
1143
- * @param params
1144
- * @returns
1145
- */
1146
- function GetById(params) {
1147
- return __awaiter(this, void 0, void 0, function* () {
1148
- let { id, api, req } = params;
1149
- if (!id) {
1150
- throw ("Invalid id");
1082
+ /**
1083
+ * Returns a url routed through the API's CDN.
1084
+ * If the CDN is not enabled for the account, this will return null.
1085
+ * @param url suffix to append to the base url.
1086
+ * @param urlParams
1087
+ * @returns
1088
+ */
1089
+ ConstructCdnUrl(url, urlParams) {
1090
+ if (!this.cdnBaseUrl) {
1091
+ return null;
1151
1092
  }
1152
- if (!api) {
1153
- api = exports.ENVIRONMENT.Api().GetGuardianApi();
1093
+ const tmp = new URL(this.cdnBaseUrl);
1094
+ if (urlParams) {
1095
+ if (urlParams instanceof URLSearchParams) {
1096
+ urlParams.forEach((value, key) => {
1097
+ tmp.searchParams.append(key, value);
1098
+ });
1099
+ }
1100
+ else {
1101
+ for (const key in urlParams) {
1102
+ tmp.searchParams.append(key, urlParams[key]);
1103
+ }
1104
+ }
1154
1105
  }
1155
- const res = yield api.GET(`hostinglocation/id/${id}`, exports.Api.PrepReqParams(req));
1156
- return {
1157
- location: res
1158
- };
1159
- });
1160
- }
1161
- HostingLocation.GetById = GetById;
1162
- /**
1163
- * Returns a hosting location record by key.
1164
- * @param params
1165
- * @returns
1166
- */
1167
- function GetByKey(params) {
1168
- return __awaiter(this, void 0, void 0, function* () {
1169
- let { key, api, req } = params;
1170
- if (!key) {
1171
- throw ("Invalid key");
1106
+ // Ensure the url ends with a slash.
1107
+ if (!tmp.pathname.endsWith("/")) {
1108
+ tmp.pathname += "/";
1172
1109
  }
1173
- if (!api) {
1174
- api = exports.ENVIRONMENT.Api().GetGuardianApi();
1110
+ if (url) {
1111
+ // Ensure the url does not start with a slash.
1112
+ // This is because the base url already has a slash at the end.
1113
+ if (url.startsWith("/")) {
1114
+ url = url.substring(1);
1115
+ }
1116
+ tmp.pathname += url;
1175
1117
  }
1176
- const res = yield api.GET(`hostinglocation/key/${key}`, exports.Api.PrepReqParams(req));
1177
- return {
1178
- location: res
1179
- };
1180
- });
1181
- }
1182
- HostingLocation.GetByKey = GetByKey;
1183
- /**
1184
- * Returns hostingLocationKey from given db url.
1185
- * Some older accounts don't have this set, so we need to guess it.
1186
- * @param params
1187
- * @returns
1188
- */
1189
- function GuessKey(params) {
1190
- const { DBServer: databaseUrl } = params;
1191
- if (databaseUrl.includes("hyperfarm-prod-instance-1")) {
1192
- return "HYPERFARM";
1193
- }
1194
- if (databaseUrl.includes("prod-syd1.nextspace.host")) {
1195
- return "AU-VULTR-FIRST";
1196
- }
1197
- else if (databaseUrl.includes("prod-nyc1.nextspace.host")) {
1198
- return "US-VULTR-FIRST";
1199
- }
1200
- else if (databaseUrl.includes("prod-ams1.nextspace.host")) {
1201
- return "EU-VULTR-FIRST";
1202
- }
1203
- else if (databaseUrl.includes("prod-sing1.nextspace.host")) {
1204
- return "SE-VULTR-FIRST";
1205
- }
1206
- else if (databaseUrl.includes("dev-first")) {
1207
- return "DEV-FIRST";
1208
- }
1209
- else if (databaseUrl.includes(".ap-southeast-1.")) {
1210
- return "SE";
1118
+ return tmp.toString();
1211
1119
  }
1212
- else if (databaseUrl.includes(".us-west-1.")) {
1213
- return "US";
1120
+ /**
1121
+ * Warning: This will cancel the init process.
1122
+ * The init process loads a region specific endpoint.
1123
+ * Setting a base url will stop that process from completing.
1124
+ * @param url
1125
+ */
1126
+ SetBaseUrl(url) {
1127
+ this.baseUrl = url;
1128
+ if (!this.baseUrl.endsWith("/")) {
1129
+ this.baseUrl += "/";
1130
+ }
1131
+ this.loadCancelled = true;
1214
1132
  }
1215
- else if (databaseUrl.includes(".eu-west-3.")) {
1216
- return "EU";
1133
+ /**
1134
+ * Performs an HTTP GET request.
1135
+ * This will prepend the base url to the url.
1136
+ * @param url
1137
+ * @param params
1138
+ * @returns
1139
+ */
1140
+ GET(url, params) {
1141
+ return __awaiter(this, void 0, void 0, function* () {
1142
+ return new Promise((res, rej) => {
1143
+ this.loadProm.then(() => {
1144
+ const full = this.ConstructUrl({
1145
+ url: url
1146
+ });
1147
+ this.get(full, params).then(res).catch(rej);
1148
+ }).catch(rej);
1149
+ });
1150
+ });
1217
1151
  }
1218
- else if (databaseUrl.includes("bruce-prod-au")) {
1219
- return "AU";
1152
+ /**
1153
+ * Performs an HTTP DELETE request.
1154
+ * This will prepend the base url to the url.
1155
+ * @param url
1156
+ * @param params
1157
+ * @returns
1158
+ */
1159
+ DELETE(url, params) {
1160
+ return __awaiter(this, void 0, void 0, function* () {
1161
+ return new Promise((res, rej) => {
1162
+ this.loadProm.then(() => {
1163
+ const full = this.ConstructUrl({
1164
+ url: url
1165
+ });
1166
+ this.delete(full, params).then(res).catch(rej);
1167
+ }).catch(rej);
1168
+ });
1169
+ });
1220
1170
  }
1221
- else if (databaseUrl.includes("bruce-dev")) {
1222
- return "DEV";
1171
+ /**
1172
+ * Performs an HTTP POST request.
1173
+ * This will prepend the base url to the url.
1174
+ * @param url
1175
+ * @param data
1176
+ * @param params
1177
+ * @returns
1178
+ */
1179
+ POST(url, data, params) {
1180
+ return __awaiter(this, void 0, void 0, function* () {
1181
+ return new Promise((res, rej) => {
1182
+ this.loadProm.then(() => {
1183
+ const full = this.ConstructUrl({
1184
+ url: url
1185
+ });
1186
+ this.post(full, data, params).then(res).catch(rej);
1187
+ }).catch(rej);
1188
+ });
1189
+ });
1223
1190
  }
1224
- return null;
1225
- }
1226
- HostingLocation.GuessKey = GuessKey;
1227
- /**
1228
- * Returns a hosting location key by account ID.
1229
- * @param params
1230
- * @returns
1231
- */
1232
- function GetKeyByAccountId(params) {
1233
- return __awaiter(this, void 0, void 0, function* () {
1234
- let { accountId, apiSettings, api, account, req } = params;
1235
- if (!accountId && !apiSettings) {
1236
- throw ("Invalid accountId or apiSettings");
1237
- }
1238
- if (!api) {
1239
- api = exports.ENVIRONMENT.Api().GetGuardianApi();
1240
- }
1241
- // We'll prioritize account record if provided.
1242
- if (accountId && !account) {
1243
- account = (yield exports.Account.Get({
1244
- accountId,
1245
- api,
1246
- req
1247
- })).account;
1248
- }
1249
- if (account === null || account === void 0 ? void 0 : account["HostingLocation.Key"]) {
1250
- return {
1251
- key: account["HostingLocation.Key"],
1252
- isLegacy: false
1253
- };
1254
- }
1255
- // Fallback to settings JSON for older records.
1256
- const settings = apiSettings ? apiSettings : (yield exports.Account.GetAppSettings({
1257
- api,
1258
- accountId,
1259
- appId: exports.Account.EAppId.BruceApi
1260
- })).settings;
1261
- let hostingKey = settings["HostingLocation.Key"];
1262
- let isLegacy = false;
1263
- if (!hostingKey) {
1264
- hostingKey = settings.DBLocation;
1265
- isLegacy = true;
1266
- }
1267
- if (!hostingKey) {
1268
- hostingKey = GuessKey({
1269
- DBServer: settings.DBServer
1191
+ /**
1192
+ * Performs an HTTP PUT request.
1193
+ * This will prepend the base url to the url.
1194
+ * @param url
1195
+ * @param data
1196
+ * @param params
1197
+ * @returns
1198
+ */
1199
+ PUT(url, data, params) {
1200
+ return __awaiter(this, void 0, void 0, function* () {
1201
+ return new Promise((res, rej) => {
1202
+ this.loadProm.then(() => {
1203
+ const full = this.ConstructUrl({
1204
+ url: url
1205
+ });
1206
+ this.put(full, data, params).then(res).catch(rej);
1207
+ }).catch(rej);
1270
1208
  });
1271
- isLegacy = true;
1272
- }
1273
- return {
1274
- key: hostingKey,
1275
- isLegacy
1276
- };
1277
- });
1278
- }
1279
- HostingLocation.GetKeyByAccountId = GetKeyByAccountId;
1280
- /**
1281
- * Returns a hosting location record by account ID.
1282
- * @param params
1283
- * @returns
1284
- */
1285
- function GetByAccountId(params) {
1286
- return __awaiter(this, void 0, void 0, function* () {
1287
- let { accountId, apiSettings, api, req, account } = params;
1288
- if (!api) {
1289
- api = exports.ENVIRONMENT.Api().GetGuardianApi();
1290
- }
1291
- const data = yield GetKeyByAccountId({
1292
- accountId,
1293
- account,
1294
- apiSettings,
1295
- api,
1296
- req
1297
1209
  });
1298
- if (!(data === null || data === void 0 ? void 0 : data.key)) {
1299
- return null;
1300
- }
1301
- const key = yield GetByKey({
1302
- key: data.key,
1303
- api,
1304
- req
1210
+ }
1211
+ /**
1212
+ * Performs a file upload request (HTTP POST).
1213
+ * This will prepend the base url to the url.
1214
+ * @param url
1215
+ * @param blob
1216
+ * @param params
1217
+ * @returns
1218
+ */
1219
+ UPLOAD(url, blob, params) {
1220
+ return __awaiter(this, void 0, void 0, function* () {
1221
+ return new Promise((res, rej) => {
1222
+ this.loadProm.then(() => {
1223
+ const full = this.ConstructUrl({
1224
+ url: url
1225
+ });
1226
+ this.upload(full, blob, params).then(res).catch(rej);
1227
+ }).catch(rej);
1228
+ });
1305
1229
  });
1306
- return key;
1307
- });
1230
+ }
1308
1231
  }
1309
- HostingLocation.GetByAccountId = GetByAccountId;
1310
- })(exports.HostingLocation || (exports.HostingLocation = {}));
1232
+ BruceApi.Api = Api$$1;
1233
+ })(exports.BruceApi || (exports.BruceApi = {}));
1311
1234
 
1312
- (function (BruceApi) {
1313
- /**
1314
- * This is the request handler for Bruce Api,
1315
- * it should be passed to any method that wants to communicate with this particular api.
1316
- */
1235
+ (function (GlobalApi) {
1317
1236
  class Api$$1 extends AbstractApi {
1318
- get AccountId() {
1319
- return this.accountId;
1320
- }
1321
- get MessageBroker() {
1322
- return this.messageBroker;
1323
- }
1324
- get ConfigLoadAttempted() {
1325
- return this.configLoadAttempted;
1326
- }
1327
- get Version() {
1328
- return this.version;
1329
- }
1330
- get Loading() {
1331
- return this.loadProm;
1332
- }
1333
1237
  constructor(params) {
1334
1238
  super({
1335
1239
  ssidHeader: "x-sessionid",
1336
- cacheId: `BRUCE_API_${params === null || params === void 0 ? void 0 : params.env}_${params === null || params === void 0 ? void 0 : params.accountId}_`
1240
+ cacheId: `GLOBAL_API_${params === null || params === void 0 ? void 0 : params.env}_`
1337
1241
  });
1338
- // Load cancelled indicates the user set a custom base url.
1339
- // This will stop the regional url from being set if it's still loading.
1340
- this.loadCancelled = false;
1341
- // Indicates if loading the regional configuration was already called.
1342
- this.configLoadAttempted = false;
1343
- let { accountId, env, guardian, loadRegionalBaseUrl, loadConfig, loadWebSocket, dummy } = params;
1344
- this.accountId = accountId;
1345
- this.env = env !== null && env !== void 0 ? env : exports.Api.EEnv.PROD;
1346
- if (!dummy) {
1347
- // Backwards compatibility.
1348
- if (loadRegionalBaseUrl) {
1349
- loadConfig = true;
1350
- }
1351
- if (loadConfig) {
1352
- // Mark it as attempted right away because we don't want any external calls while it gets to that async point.
1353
- this.configLoadAttempted = true;
1354
- }
1355
- this.loadProm = this.init(guardian, loadConfig, loadWebSocket);
1356
- }
1242
+ this.env = (params === null || params === void 0 ? void 0 : params.env) ? params.env : exports.Api.EEnv.PROD;
1243
+ this.setBaseUrl();
1357
1244
  }
1358
1245
  /**
1359
- * Loads regional base url and sets up message broker.
1360
- * @param guardian Required for loading regional base url.
1361
- * @param loadConfig
1362
- * @returns
1246
+ * Sets the base url for this api.
1363
1247
  */
1364
- init(guardian, loadConfig, loadWebSocket) {
1365
- return __awaiter(this, void 0, void 0, function* () {
1366
- if (!this.accountId) {
1367
- throw ("accountId is required.");
1368
- }
1369
- // Set using a stable default.
1370
- const domain = this.getDomain();
1371
- this.baseUrl = `https://${this.accountId}.api.${domain}/`;
1372
- // Attempt to load regional configuration.
1373
- if (loadConfig) {
1374
- yield this.LoadConfig({
1375
- guardian: guardian,
1376
- // We marked it as attempted to load outside this method to fight any external calls.
1377
- // So we'll force load it now.
1378
- forceLoad: true
1379
- });
1380
- }
1381
- // Get the version.
1382
- if (this.baseUrl) {
1383
- const data = yield this.get(this.baseUrl + "version");
1384
- if (data === null || data === void 0 ? void 0 : data["Bruce-API"]) {
1385
- this.version = data["Bruce-API"];
1386
- }
1387
- else {
1388
- this.version = "UNKNOWN";
1389
- }
1390
- }
1391
- // Start web socket connection.
1392
- if (loadWebSocket == true) {
1393
- try {
1394
- this.messageBroker = new exports.MessageBroker.WebSocketBroker(this.baseUrl, this.env);
1395
- }
1396
- catch (e) {
1397
- console.warn("BruceApi: Failed to create message broker.", e);
1398
- }
1399
- }
1400
- });
1401
- }
1402
- getDomain() {
1248
+ setBaseUrl() {
1249
+ let url;
1403
1250
  const env = this.env.toUpperCase();
1404
- let domain = "nextspace.host";
1405
1251
  switch (env) {
1406
1252
  case exports.Api.EEnv.DEV:
1407
- domain = "nextspace-dev.net";
1253
+ url = "https://bruceglobal.nextspace-dev.net/";
1408
1254
  break;
1409
1255
  case exports.Api.EEnv.STG:
1410
- domain = "nextspace-stg.net";
1256
+ url = "https://bruceglobal.nextspace-stg.net/";
1411
1257
  break;
1412
1258
  case exports.Api.EEnv.UAT:
1413
- domain = "nextspace-uat.net";
1259
+ url = "https://bruceglobal.api.nextspace-uat.net/";
1414
1260
  break;
1415
1261
  case exports.Api.EEnv.PROD:
1416
- domain = "nextspace.host";
1262
+ url = "https://bruceglobal.api.nextspace.host/";
1417
1263
  break;
1418
1264
  default:
1419
- console.error("Specified Environment is not valid. SuppliedEnv=" + env);
1265
+ throw ("Specified Environment is not valid. SuppliedEnv=" + env);
1420
1266
  }
1421
- return domain;
1422
- }
1423
- /**
1424
- * Loads the regional configuration for the account.
1425
- * If the config is already loaded then this will do nothing.
1426
- */
1427
- LoadConfig(params) {
1428
- var _a, _b, _c;
1429
- return __awaiter(this, void 0, void 0, function* () {
1430
- let { guardian, forceLoad } = (params !== null && params !== void 0 ? params : {});
1431
- if (this.configLoadAttempted && forceLoad != true) {
1432
- return;
1433
- }
1434
- this.configLoadAttempted = true;
1435
- try {
1436
- if (!guardian) {
1437
- guardian = new exports.GuardianApi.Api({
1438
- env: this.env
1439
- });
1440
- }
1441
- const { account } = yield exports.Account.GetBySubdomain({
1442
- subdomain: this.accountId,
1443
- api: guardian
1444
- });
1445
- // Precalculated URLs exist.
1446
- // Soon this will be a stable requirement for any account record.
1447
- if (account.URL) {
1448
- if (!this.loadCancelled) {
1449
- const urls = account.URL;
1450
- if (urls === null || urls === void 0 ? void 0 : urls.Base) {
1451
- this.baseUrl = urls.Base;
1452
- }
1453
- if (urls === null || urls === void 0 ? void 0 : urls.CDNEntities) {
1454
- this.EntityCdnUrl = urls.CDNEntities;
1455
- }
1456
- if (urls === null || urls === void 0 ? void 0 : urls.CDNTileset) {
1457
- this.TilesetCdnUrl = urls.CDNTileset;
1458
- }
1459
- if (urls === null || urls === void 0 ? void 0 : urls.CDNLegacyTileset) {
1460
- this.LegacyTilesetCdnUrl = urls.CDNLegacyTileset;
1461
- }
1462
- if (urls === null || urls === void 0 ? void 0 : urls.CDNBase) {
1463
- this.cdnBaseUrl = urls.CDNBase;
1464
- }
1465
- }
1466
- }
1467
- // Deprecated and will eventually stop working at all.
1468
- else {
1469
- const env = this.env.toUpperCase();
1470
- const domain = this.getDomain();
1471
- const host = yield exports.HostingLocation.GetByAccountId({
1472
- accountId: this.accountId,
1473
- api: guardian
1474
- });
1475
- if (host === null || host === void 0 ? void 0 : host.location) {
1476
- const settings = host.location.Settings;
1477
- if (!this.loadCancelled) {
1478
- // Attempt to load regional base url.
1479
- // First try go through settings.
1480
- let urlSet = false;
1481
- if (settings === null || settings === void 0 ? void 0 : settings.BruceAPIURL) {
1482
- let envUrl = settings.BruceAPIURL[env];
1483
- if (envUrl) {
1484
- envUrl = envUrl
1485
- .replace("<ACCOUNTID>", this.accountId)
1486
- .replace("<ACCOUNT>", this.accountId);
1487
- if (envUrl && envUrl.length > 1) {
1488
- this.baseUrl = envUrl;
1489
- urlSet = true;
1490
- }
1491
- }
1492
- }
1493
- // Try go through host location's base url.
1494
- // This may be wrong env which is why it's used as fallback right now.
1495
- if (!urlSet && host.location.BruceAPIURL) {
1496
- const regionalUrl = host.location.BruceAPIURL
1497
- .replace("<ACCOUNTID>", this.accountId)
1498
- .replace("<ACCOUNT>", this.accountId)
1499
- .replace("<DOMAIN>", domain);
1500
- if (regionalUrl && regionalUrl.length > 1) {
1501
- this.baseUrl = regionalUrl;
1502
- urlSet = true;
1503
- }
1504
- }
1505
- }
1506
- // Attempt to load CDN settings.
1507
- if (settings === null || settings === void 0 ? void 0 : settings.CDN) {
1508
- this.EntityCdnUrl = (_a = settings.CDN.entityURL) === null || _a === void 0 ? void 0 : _a[env];
1509
- // We need to fix our configs.
1510
- if (this.EntityCdnUrl) {
1511
- if (this.EntityCdnUrl.includes("entitiesListForCDN")) {
1512
- this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", this.accountId);
1513
- }
1514
- else {
1515
- this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", "entitiesListForCDN/" + this.accountId);
1516
- }
1517
- }
1518
- this.LegacyTilesetCdnUrl = (_b = settings.CDN.legacyTilesetURL) === null || _b === void 0 ? void 0 : _b[env];
1519
- this.TilesetCdnUrl = (_c = settings.CDN.tilesetURL) === null || _c === void 0 ? void 0 : _c[env];
1520
- if (this.TilesetCdnUrl) {
1521
- this.TilesetCdnUrl = this.TilesetCdnUrl.replace("<ACCOUNT>", this.accountId);
1522
- }
1523
- // TilesetCdnUrl example: "https://blah.cloudfront.net/tilesets/<TILESETID>/files/<FILEPATH>?accountId=<ACCOUNT>".
1524
- // Lazy at the moment to go around updating every region we have, I'll interpret the url from tilesetCdnUrl.
1525
- if (this.TilesetCdnUrl) {
1526
- try {
1527
- const url = new URL(this.TilesetCdnUrl);
1528
- this.cdnBaseUrl = `${url.protocol}//${url.hostname}/`;
1529
- }
1530
- catch (e) {
1531
- console.error(e);
1532
- }
1533
- }
1534
- }
1535
- }
1536
- }
1537
- }
1538
- catch (e) {
1539
- console.error(e);
1540
- }
1541
- });
1542
- }
1543
- /**
1544
- * Creates a message broker instance and returns it.
1545
- * If an instance is already created, it will return that one.
1546
- * @warning This will await the loading promise to avoid using data that isn't ready.
1547
- */
1548
- ConnectWebsocket() {
1549
- return __awaiter(this, void 0, void 0, function* () {
1550
- yield this.loadProm;
1551
- if (this.messageBroker) {
1552
- return this.messageBroker;
1553
- }
1554
- this.messageBroker = new exports.MessageBroker.WebSocketBroker(this.baseUrl, this.env);
1555
- return this.messageBroker;
1556
- });
1267
+ this.baseUrl = url;
1557
1268
  }
1558
1269
  /**
1559
- * Warning: This method does not wait for init to finish loading.
1560
- * This means the url could be changed once fully initialized.
1561
- * The url will be valid either way, but the loaded one may be faster as it is region specific.
1562
- * Await the "Loading" promise if you care about this.
1270
+ * Gets the base url for this api.
1563
1271
  * @returns
1564
1272
  */
1565
1273
  GetBaseUrl() {
1566
1274
  return this.baseUrl;
1567
1275
  }
1568
1276
  /**
1569
- * Warning: Wait the "Loading" promise before using this url.
1570
- * @returns
1571
- */
1572
- GetCdnBaseUrl() {
1573
- return this.cdnBaseUrl;
1574
- }
1575
- /**
1576
- * Returns a url routed through the API's CDN.
1577
- * If the CDN is not enabled for the account, this will return null.
1578
- * @param url suffix to append to the base url.
1579
- * @param urlParams
1580
- * @returns
1581
- */
1582
- ConstructCdnUrl(url, urlParams) {
1583
- if (!this.cdnBaseUrl) {
1584
- return null;
1585
- }
1586
- const tmp = new URL(this.cdnBaseUrl);
1587
- if (urlParams && urlParams instanceof URLSearchParams) {
1588
- urlParams.forEach((value, key) => {
1589
- tmp.searchParams.append(key, value);
1590
- });
1591
- }
1592
- if (url) {
1593
- tmp.pathname += url;
1594
- }
1595
- return tmp.toString();
1596
- }
1597
- /**
1598
- * Warning: This will cancel the init process.
1599
- * The init process loads a region specific endpoint.
1600
- * Setting a base url will stop that process from completing.
1277
+ * Sets the base url for this api.
1601
1278
  * @param url
1602
1279
  */
1603
1280
  SetBaseUrl(url) {
@@ -1605,7 +1282,6 @@
1605
1282
  if (!this.baseUrl.endsWith("/")) {
1606
1283
  this.baseUrl += "/";
1607
1284
  }
1608
- this.loadCancelled = true;
1609
1285
  }
1610
1286
  /**
1611
1287
  * Performs an HTTP GET request.
@@ -1616,11 +1292,7 @@
1616
1292
  */
1617
1293
  GET(url, params) {
1618
1294
  return __awaiter(this, void 0, void 0, function* () {
1619
- return new Promise((res, rej) => {
1620
- this.loadProm.then(() => {
1621
- this.get(this.baseUrl + url, params).then(res).catch(rej);
1622
- }).catch(rej);
1623
- });
1295
+ return this.get(this.baseUrl + url, params);
1624
1296
  });
1625
1297
  }
1626
1298
  /**
@@ -1632,11 +1304,7 @@
1632
1304
  */
1633
1305
  DELETE(url, params) {
1634
1306
  return __awaiter(this, void 0, void 0, function* () {
1635
- return new Promise((res, rej) => {
1636
- this.loadProm.then(() => {
1637
- this.delete(this.baseUrl + url, params).then(res).catch(rej);
1638
- }).catch(rej);
1639
- });
1307
+ return this.delete(this.baseUrl + url, params);
1640
1308
  });
1641
1309
  }
1642
1310
  /**
@@ -1649,28 +1317,7 @@
1649
1317
  */
1650
1318
  POST(url, data, params) {
1651
1319
  return __awaiter(this, void 0, void 0, function* () {
1652
- return new Promise((res, rej) => {
1653
- this.loadProm.then(() => {
1654
- this.post(this.baseUrl + url, data, params).then(res).catch(rej);
1655
- }).catch(rej);
1656
- });
1657
- });
1658
- }
1659
- /**
1660
- * Performs an HTTP PUT request.
1661
- * This will prepend the base url to the url.
1662
- * @param url
1663
- * @param data
1664
- * @param params
1665
- * @returns
1666
- */
1667
- PUT(url, data, params) {
1668
- return __awaiter(this, void 0, void 0, function* () {
1669
- return new Promise((res, rej) => {
1670
- this.loadProm.then(() => {
1671
- this.put(this.baseUrl + url, data, params).then(res).catch(rej);
1672
- }).catch(rej);
1673
- });
1320
+ return this.post(this.baseUrl + url, data, params);
1674
1321
  });
1675
1322
  }
1676
1323
  /**
@@ -1683,157 +1330,48 @@
1683
1330
  */
1684
1331
  UPLOAD(url, blob, params) {
1685
1332
  return __awaiter(this, void 0, void 0, function* () {
1686
- return new Promise((res, rej) => {
1687
- this.loadProm.then(() => {
1688
- this.upload(this.baseUrl + url, blob, params).then(res).catch(rej);
1689
- }).catch(rej);
1690
- });
1333
+ return this.upload(this.baseUrl + url, blob, params);
1691
1334
  });
1692
1335
  }
1693
1336
  }
1694
- BruceApi.Api = Api$$1;
1695
- })(exports.BruceApi || (exports.BruceApi = {}));
1337
+ GlobalApi.Api = Api$$1;
1338
+ })(exports.GlobalApi || (exports.GlobalApi = {}));
1696
1339
 
1697
- (function (GlobalApi) {
1698
- class Api$$1 extends AbstractApi {
1699
- constructor(params) {
1700
- super({
1701
- ssidHeader: "x-sessionid",
1702
- cacheId: `GLOBAL_API_${params === null || params === void 0 ? void 0 : params.env}_`
1703
- });
1704
- this.env = (params === null || params === void 0 ? void 0 : params.env) ? params.env : exports.Api.EEnv.PROD;
1705
- this.setBaseUrl();
1706
- }
1707
- /**
1708
- * Sets the base url for this api.
1709
- */
1710
- setBaseUrl() {
1711
- let url;
1712
- const env = this.env.toUpperCase();
1713
- switch (env) {
1714
- case exports.Api.EEnv.DEV:
1715
- url = "https://bruceglobal.nextspace-dev.net/";
1716
- break;
1717
- case exports.Api.EEnv.STG:
1718
- url = "https://bruceglobal.nextspace-stg.net/";
1719
- break;
1720
- case exports.Api.EEnv.UAT:
1721
- url = "https://bruceglobal.api.nextspace-uat.net/";
1722
- break;
1723
- case exports.Api.EEnv.PROD:
1724
- url = "https://bruceglobal.api.nextspace.host/";
1725
- break;
1726
- default:
1727
- throw ("Specified Environment is not valid. SuppliedEnv=" + env);
1728
- }
1729
- this.baseUrl = url;
1730
- }
1731
- /**
1732
- * Gets the base url for this api.
1733
- * @returns
1734
- */
1735
- GetBaseUrl() {
1736
- return this.baseUrl;
1737
- }
1738
- /**
1739
- * Sets the base url for this api.
1740
- * @param url
1741
- */
1742
- SetBaseUrl(url) {
1743
- this.baseUrl = url;
1744
- if (!this.baseUrl.endsWith("/")) {
1745
- this.baseUrl += "/";
1746
- }
1747
- }
1748
- /**
1749
- * Performs an HTTP GET request.
1750
- * This will prepend the base url to the url.
1751
- * @param url
1752
- * @param params
1753
- * @returns
1754
- */
1755
- GET(url, params) {
1756
- return __awaiter(this, void 0, void 0, function* () {
1757
- return this.get(this.baseUrl + url, params);
1758
- });
1759
- }
1760
- /**
1761
- * Performs an HTTP DELETE request.
1762
- * This will prepend the base url to the url.
1763
- * @param url
1764
- * @param params
1765
- * @returns
1766
- */
1767
- DELETE(url, params) {
1768
- return __awaiter(this, void 0, void 0, function* () {
1769
- return this.delete(this.baseUrl + url, params);
1770
- });
1771
- }
1772
- /**
1773
- * Performs an HTTP POST request.
1774
- * This will prepend the base url to the url.
1775
- * @param url
1776
- * @param data
1777
- * @param params
1778
- * @returns
1779
- */
1780
- POST(url, data, params) {
1781
- return __awaiter(this, void 0, void 0, function* () {
1782
- return this.post(this.baseUrl + url, data, params);
1783
- });
1784
- }
1785
- /**
1786
- * Performs a file upload request (HTTP POST).
1787
- * This will prepend the base url to the url.
1788
- * @param url
1789
- * @param blob
1790
- * @param params
1791
- * @returns
1792
- */
1793
- UPLOAD(url, blob, params) {
1794
- return __awaiter(this, void 0, void 0, function* () {
1795
- return this.upload(this.baseUrl + url, blob, params);
1796
- });
1797
- }
1798
- }
1799
- GlobalApi.Api = Api$$1;
1800
- })(exports.GlobalApi || (exports.GlobalApi = {}));
1801
-
1802
- /**
1803
- * Utility for managing multiple API instances.
1804
- * Example: {
1805
- * const api = new ApiGetters({
1806
- * accountId: "123",
1807
- * env: Api.EEnv.PROD
1808
- * });
1809
- *
1810
- * // Returns default API instance specified in constructor.
1811
- * const bruce1 = api.GetBruceApi();
1812
- * // Returns API instance for account 456.
1813
- * const bruce2 = api.GetBruceApi({
1814
- * accountId: "456"
1815
- * });
1816
- *
1817
- * const global = api.GetGlobalApi();
1818
- * const guardian = api.GetGuardianApi();
1819
- * }
1820
- */
1821
- class ApiGetters {
1822
- constructor(params) {
1823
- this.bruce = {};
1824
- this.guardian = {};
1825
- this.global = {};
1826
- this.accountId = params === null || params === void 0 ? void 0 : params.accountId;
1827
- this.env = (params === null || params === void 0 ? void 0 : params.env) ? params.env : exports.Api.EEnv.PROD;
1828
- this.sessionId = params === null || params === void 0 ? void 0 : params.sessionId;
1829
- }
1830
- /**
1831
- * Clears all cache items in all API instances.
1832
- */
1833
- ClearCache() {
1834
- var _a, _b, _c, _d, _e, _f;
1835
- for (const key in this.bruce) {
1836
- (_b = (_a = this.bruce[key]) === null || _a === void 0 ? void 0 : _a.Cache) === null || _b === void 0 ? void 0 : _b.Clear();
1340
+ /**
1341
+ * Utility for managing multiple API instances.
1342
+ * Example: {
1343
+ * const api = new ApiGetters({
1344
+ * accountId: "123",
1345
+ * env: Api.EEnv.PROD
1346
+ * });
1347
+ *
1348
+ * // Returns default API instance specified in constructor.
1349
+ * const bruce1 = api.GetBruceApi();
1350
+ * // Returns API instance for account 456.
1351
+ * const bruce2 = api.GetBruceApi({
1352
+ * accountId: "456"
1353
+ * });
1354
+ *
1355
+ * const global = api.GetGlobalApi();
1356
+ * const guardian = api.GetGuardianApi();
1357
+ * }
1358
+ */
1359
+ class ApiGetters {
1360
+ constructor(params) {
1361
+ this.bruce = {};
1362
+ this.guardian = {};
1363
+ this.global = {};
1364
+ this.accountId = params === null || params === void 0 ? void 0 : params.accountId;
1365
+ this.env = (params === null || params === void 0 ? void 0 : params.env) ? params.env : exports.Api.EEnv.PROD;
1366
+ this.sessionId = params === null || params === void 0 ? void 0 : params.sessionId;
1367
+ }
1368
+ /**
1369
+ * Clears all cache items in all API instances.
1370
+ */
1371
+ ClearCache() {
1372
+ var _a, _b, _c, _d, _e, _f;
1373
+ for (const key in this.bruce) {
1374
+ (_b = (_a = this.bruce[key]) === null || _a === void 0 ? void 0 : _a.Cache) === null || _b === void 0 ? void 0 : _b.Clear();
1837
1375
  }
1838
1376
  for (const key in this.guardian) {
1839
1377
  (_d = (_c = this.guardian[key]) === null || _c === void 0 ? void 0 : _c.Cache) === null || _d === void 0 ? void 0 : _d.Clear();
@@ -4164,17 +3702,7 @@
4164
3702
  let totalCount;
4165
3703
  let entities = [];
4166
3704
  if (analysis || expandRelations || (viaCdn && api.GetCdnBaseUrl())) {
4167
- let url;
4168
- if (analysis) {
4169
- url = new URL(api.GetBaseUrl() + "entities/summary");
4170
- }
4171
- else if (viaCdn && api.GetCdnBaseUrl()) {
4172
- url = new URL(api.ConstructCdnUrl("entities"));
4173
- }
4174
- else {
4175
- url = new URL(api.GetBaseUrl() + "entities");
4176
- }
4177
- const urlParams = url.searchParams;
3705
+ const urlParams = new URLSearchParams();
4178
3706
  urlParams.set("cacheToken", String(viaCdnCacheToken ? viaCdnCacheToken : 0));
4179
3707
  if (body.SortOrder) {
4180
3708
  urlParams.set("SortOrder", body.SortOrder);
@@ -4222,7 +3750,11 @@
4222
3750
  urlParams.set("schema", schemaId);
4223
3751
  }
4224
3752
  urlParams.set("hasMigrated", String(Boolean(migrated)));
4225
- const urlStr = url.toString();
3753
+ const urlStr = api.ConstructUrl({
3754
+ cdn: !analysis && viaCdn,
3755
+ url: analysis ? "entities/summary" : "entities",
3756
+ urlParams: urlParams
3757
+ });
4226
3758
  const data = yield api.get(urlStr, exports.Api.PrepReqParams(reqParams));
4227
3759
  if (!analysis) {
4228
3760
  entities = data.Items;
@@ -4230,8 +3762,7 @@
4230
3762
  totalCount = data.TotalCount;
4231
3763
  }
4232
3764
  else {
4233
- const url = new URL(api.GetBaseUrl() + (analysis ? "entities/summary" : "entities"));
4234
- const urlParams = url.searchParams;
3765
+ const urlParams = new URLSearchParams();
4235
3766
  if (expandRelations) {
4236
3767
  urlParams.append("$expand", "relation");
4237
3768
  }
@@ -4242,7 +3773,11 @@
4242
3773
  urlParams.set("schema", schemaId);
4243
3774
  }
4244
3775
  urlParams.set("hasMigrated", String(Boolean(migrated)));
4245
- const urlStr = url.toString();
3776
+ const urlStr = api.ConstructUrl({
3777
+ cdn: false,
3778
+ url: analysis ? "entities/summary" : "entities",
3779
+ urlParams: urlParams
3780
+ });
4246
3781
  const data = yield api.post(urlStr, body, exports.Api.PrepReqParams(reqParams));
4247
3782
  if (!analysis) {
4248
3783
  entities = data.Items;
@@ -6112,12 +5647,13 @@
6112
5647
  if (!level) {
6113
5648
  level = 0;
6114
5649
  }
6115
- let url = api.GetBaseUrl() + `entity/${entityId}/lod/${categoryId}/${level}`;
6116
- if (strict) {
6117
- url = url + "?strict=true";
6118
- }
6119
5650
  return {
6120
- url: url
5651
+ url: api.ConstructUrl({
5652
+ url: `entity/${entityId}/lod/${categoryId}/${level}`,
5653
+ urlParams: {
5654
+ "strict": strict ? "true" : "false"
5655
+ }
5656
+ })
6121
5657
  };
6122
5658
  }
6123
5659
  EntityLod.GetUrl = GetUrl;
@@ -8275,15 +7811,14 @@
8275
7811
  if (!api) {
8276
7812
  api = exports.ENVIRONMENT.Api().GetBruceApi();
8277
7813
  }
8278
- const urlSuffix = `file/${fileId}`;
8279
- const cdnUrl = viaCdn ? api.ConstructCdnUrl(urlSuffix) : null;
8280
- if (cdnUrl) {
8281
- return cdnUrl;
8282
- }
8283
- let url = `${api.GetBaseUrl()}${urlSuffix}`;
8284
- // Invalidating cache manually because we have a wave of invalid headers now cached across devices.
8285
- url = exports.UrlUtils.AddQueryParam(url, "cc", "1");
8286
- return url;
7814
+ return api.ConstructUrl({
7815
+ cdn: viaCdn,
7816
+ url: `file/${fileId}`,
7817
+ urlParams: {
7818
+ // Invalidating cache manually because we have a wave of invalid headers now cached across devices.
7819
+ cc: "1"
7820
+ }
7821
+ });
8287
7822
  }
8288
7823
  ClientFile.GetUrl = GetUrl;
8289
7824
  /**
@@ -8304,14 +7839,14 @@
8304
7839
  ext = "." + ext;
8305
7840
  }
8306
7841
  const urlSuffix = ext ? `file/${file.ID}${ext}` : `file/${file.ID}`;
8307
- const cdnUrl = viaCdn ? api.ConstructCdnUrl(urlSuffix) : null;
8308
- if (cdnUrl) {
8309
- return cdnUrl;
8310
- }
8311
- let url = `${api.GetBaseUrl()}${urlSuffix}`;
8312
- // Invalidating cache manually because we have a wave of invalid headers now cached across devices.
8313
- url = exports.UrlUtils.AddQueryParam(url, "cc", "1");
8314
- return url;
7842
+ return api.ConstructUrl({
7843
+ cdn: viaCdn,
7844
+ url: urlSuffix,
7845
+ urlParams: {
7846
+ // Invalidating cache manually because we have a wave of invalid headers now cached across devices.
7847
+ cc: "1"
7848
+ }
7849
+ });
8315
7850
  }
8316
7851
  ClientFile.GetUrlWithExt = GetUrlWithExt;
8317
7852
  /**
@@ -9436,23 +8971,13 @@
9436
8971
  if (!file) {
9437
8972
  file = "";
9438
8973
  }
9439
- let url = null;
9440
- const cdnBaseUrl = viaCdn ? api.GetCdnBaseUrl() : null;
9441
- if (cdnBaseUrl) {
9442
- url = `v3/tilesets/${tilesetId}/files/${legacy ? "" : "files/"}${file}`;
9443
- const urlParams = new URLSearchParams();
9444
- if (cacheToken != null) {
9445
- urlParams.append("cacheToken", String(cacheToken));
9446
- }
9447
- url = api.ConstructCdnUrl(url, urlParams);
9448
- }
9449
- else {
9450
- url = api.GetBaseUrl() + `v3/tilesets/${tilesetId}/files/${legacy ? "" : "files/"}${file}`;
9451
- if (cacheToken != null) {
9452
- url += `?cacheToken=${cacheToken}`;
8974
+ return api.ConstructUrl({
8975
+ cdn: viaCdn,
8976
+ url: `v3/tilesets/${tilesetId}/files/${legacy ? "" : "files/"}${file}`,
8977
+ urlParams: {
8978
+ "cacheToken": String(cacheToken ? cacheToken : 0)
9453
8979
  }
9454
- }
9455
- return url;
8980
+ });
9456
8981
  }
9457
8982
  Tileset.GetFileUrl = GetFileUrl;
9458
8983
  /**
@@ -9471,7 +8996,9 @@
9471
8996
  if (!file) {
9472
8997
  file = "";
9473
8998
  }
9474
- return api.GetBaseUrl() + `tileset/getFile/${tilesetId}/src/${file}`;
8999
+ return api.ConstructUrl({
9000
+ url: `tileset/getFile/${tilesetId}/src/${file}`
9001
+ });
9475
9002
  }
9476
9003
  Tileset.GetSrcFileUrl = GetSrcFileUrl;
9477
9004
  /**
@@ -9491,16 +9018,13 @@
9491
9018
  if (!file) {
9492
9019
  file = "";
9493
9020
  }
9494
- const cdnBaseUrl = viaCdn ? api.GetCdnBaseUrl() : null;
9495
- if (cdnBaseUrl) {
9496
- if (!viaCdnCacheToken) {
9497
- viaCdnCacheToken = 0;
9021
+ return api.ConstructUrl({
9022
+ cdn: viaCdn,
9023
+ url: `tileset/file/${tilesetId}/${file}`,
9024
+ urlParams: {
9025
+ "cacheToken": String(viaCdnCacheToken ? viaCdnCacheToken : 0)
9498
9026
  }
9499
- const urlParams = new URLSearchParams();
9500
- urlParams.append("cacheToken", String(viaCdnCacheToken));
9501
- return api.ConstructCdnUrl(`tileset/file/${tilesetId}/${file}`, urlParams);
9502
- }
9503
- return api.GetBaseUrl() + `tileset/file/${tilesetId}/${file}`;
9027
+ });
9504
9028
  }
9505
9029
  Tileset.GetPublicFileUrl = GetPublicFileUrl;
9506
9030
  /**
@@ -9857,293 +9381,823 @@
9857
9381
  }
9858
9382
  MenuItem.CreateFromTypeId = CreateFromTypeId;
9859
9383
  /**
9860
- * Creates a menu item for a tileset.
9861
- * @param tilesetId
9862
- * @param type
9863
- * @returns
9384
+ * Creates a menu item for a tileset.
9385
+ * @param tilesetId
9386
+ * @param type
9387
+ * @returns
9388
+ */
9389
+ function CreateFromTilesetId(tilesetId, type) {
9390
+ if (type === exports.Tileset.EType.Cad) {
9391
+ return {
9392
+ id: exports.ObjectUtils.UId(),
9393
+ Type: EType.CadTileset,
9394
+ Caption: "Generated CAD Menu Item",
9395
+ FlyTo: false,
9396
+ tileset: {
9397
+ TilesetID: tilesetId
9398
+ }
9399
+ };
9400
+ }
9401
+ else if (type == exports.Tileset.EType.EntitiesSet) {
9402
+ return {
9403
+ id: exports.ObjectUtils.UId(),
9404
+ Type: EType.EntityTileset,
9405
+ Caption: "Generated Entities Menu Item",
9406
+ FlyTo: false,
9407
+ tileset: {
9408
+ TilesetID: tilesetId
9409
+ }
9410
+ };
9411
+ }
9412
+ else if (type == exports.Tileset.EType.PointCloud) {
9413
+ return {
9414
+ id: exports.ObjectUtils.UId(),
9415
+ Type: EType.PointCloud,
9416
+ Caption: "Generated Point Cloud Menu Item",
9417
+ FlyTo: false,
9418
+ tileset: {
9419
+ TilesetID: tilesetId
9420
+ }
9421
+ };
9422
+ }
9423
+ else if (type == exports.Tileset.EType.EntitiesMap) {
9424
+ return {
9425
+ id: exports.ObjectUtils.UId(),
9426
+ Type: EType.EntityRaster,
9427
+ Caption: "Generated Entities Menu Item",
9428
+ tileset: {
9429
+ TilesetID: tilesetId
9430
+ }
9431
+ };
9432
+ }
9433
+ throw ("Tileset type not supported.");
9434
+ }
9435
+ MenuItem.CreateFromTilesetId = CreateFromTilesetId;
9436
+ })(exports.MenuItem || (exports.MenuItem = {}));
9437
+
9438
+ (function (ProjectViewBookmark) {
9439
+ // This is the expected default version for the DataVersion value.
9440
+ // This value should NOT be changed without looking at our API and seeing what the default value is.
9441
+ ProjectViewBookmark.DEFAULT_DATA_VERSION = 2;
9442
+ /**
9443
+ * Describes the content of a bookmark.
9444
+ * As part of a deal we've been commissioned to create an alternative bookmark type to embed content.
9445
+ */
9446
+ let EContentType;
9447
+ (function (EContentType) {
9448
+ EContentType["WEB_3D"] = "WEB_3D";
9449
+ EContentType["IFRAME"] = "IFRAME";
9450
+ })(EContentType = ProjectViewBookmark.EContentType || (ProjectViewBookmark.EContentType = {}));
9451
+ /**
9452
+ * Gets a bookmark record.
9453
+ * @param params
9454
+ * @returns
9455
+ */
9456
+ function Get(params) {
9457
+ return __awaiter(this, void 0, void 0, function* () {
9458
+ let { api, viewId, bookmarkId, req: reqParams } = params;
9459
+ if (!viewId || !bookmarkId) {
9460
+ throw ("View ID and Bookmark ID are required.");
9461
+ }
9462
+ if (!api) {
9463
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
9464
+ }
9465
+ const key = GetCacheKey(viewId, bookmarkId);
9466
+ const cache = yield api.GetCacheItem(key, reqParams);
9467
+ if (cache === null || cache === void 0 ? void 0 : cache.found) {
9468
+ return cache.data;
9469
+ }
9470
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
9471
+ try {
9472
+ const data = yield api.GET(`ui.view/${viewId}/slide/${bookmarkId}`, exports.Api.PrepReqParams(reqParams));
9473
+ res({
9474
+ bookmark: data
9475
+ });
9476
+ }
9477
+ catch (e) {
9478
+ rej(e);
9479
+ }
9480
+ }));
9481
+ yield api.SetCacheItem({
9482
+ key,
9483
+ value: prom,
9484
+ req: reqParams
9485
+ });
9486
+ return prom;
9487
+ });
9488
+ }
9489
+ ProjectViewBookmark.Get = Get;
9490
+ /**
9491
+ * Deletes a bookmark record.
9492
+ * @param params
9493
+ */
9494
+ function Delete(params) {
9495
+ return __awaiter(this, void 0, void 0, function* () {
9496
+ let { api, viewId, bookmarkId, req: reqParams } = params;
9497
+ if (!viewId || !bookmarkId) {
9498
+ throw ("View ID and Bookmark ID are required.");
9499
+ }
9500
+ if (!api) {
9501
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
9502
+ }
9503
+ yield api.DELETE(`ui.view/${viewId}/slide/${bookmarkId}`, exports.Api.PrepReqParams(reqParams));
9504
+ api.Cache.Remove(GetCacheKey(viewId, bookmarkId));
9505
+ api.Cache.Remove(GetListCacheKey(viewId));
9506
+ });
9507
+ }
9508
+ ProjectViewBookmark.Delete = Delete;
9509
+ /**
9510
+ * Gets a list of bookmark records.
9511
+ * @param params
9512
+ * @returns
9513
+ */
9514
+ function GetList(params) {
9515
+ return __awaiter(this, void 0, void 0, function* () {
9516
+ let { api, viewId, req: reqParams } = params;
9517
+ if (!viewId) {
9518
+ throw ("View ID is required.");
9519
+ }
9520
+ if (!api) {
9521
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
9522
+ }
9523
+ const cache = yield api.GetCacheItem(GetListCacheKey(viewId), reqParams);
9524
+ if (cache === null || cache === void 0 ? void 0 : cache.found) {
9525
+ return cache.data;
9526
+ }
9527
+ const req = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
9528
+ try {
9529
+ const data = yield api.GET(`ui.view/${viewId}/slides`, exports.Api.PrepReqParams(reqParams));
9530
+ const items = data.Items ? data.Items : [];
9531
+ // Cache individual items.
9532
+ // Maybe better to load list cache when getting 1 slide and seeing if it's in there.
9533
+ // WARNING: Right now the data matches, in the future the list may contain a shortened result.
9534
+ for (let i = 0; i < items.length; i++) {
9535
+ const item = items[i];
9536
+ const prom = new Promise((res) => {
9537
+ res({
9538
+ bookmark: item
9539
+ });
9540
+ });
9541
+ yield api.SetCacheItem({
9542
+ key: GetCacheKey(viewId, item.ID),
9543
+ value: prom,
9544
+ req: reqParams
9545
+ });
9546
+ }
9547
+ res({
9548
+ bookmarks: items
9549
+ });
9550
+ }
9551
+ catch (e) {
9552
+ rej(e);
9553
+ }
9554
+ }));
9555
+ yield api.SetCacheItem({
9556
+ key: GetListCacheKey(viewId),
9557
+ value: req,
9558
+ req: reqParams
9559
+ });
9560
+ return req;
9561
+ });
9562
+ }
9563
+ ProjectViewBookmark.GetList = GetList;
9564
+ /**
9565
+ * Creates or updates a bookmark record.
9566
+ * @param params
9567
+ * @returns
9568
+ */
9569
+ function Update(params) {
9570
+ return __awaiter(this, void 0, void 0, function* () {
9571
+ let { api, viewId, bookmark: data, req: reqParams } = params;
9572
+ if (!api) {
9573
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
9574
+ }
9575
+ if (!(data === null || data === void 0 ? void 0 : data.Title)) {
9576
+ data.Title = data.ID;
9577
+ }
9578
+ const res = yield api.POST(`ui.view/${viewId}/slide/${data.ID ? data.ID : ""}`, data, exports.Api.PrepReqParams(reqParams));
9579
+ api.Cache.Remove(GetCacheKey(viewId, data.ID));
9580
+ api.Cache.Remove(GetListCacheKey(viewId));
9581
+ return {
9582
+ bookmark: res
9583
+ };
9584
+ });
9585
+ }
9586
+ ProjectViewBookmark.Update = Update;
9587
+ /**
9588
+ * Sets the order of bookmarks within a project view.
9589
+ * @param params
9590
+ */
9591
+ function SetOrder(params) {
9592
+ return __awaiter(this, void 0, void 0, function* () {
9593
+ let { api, viewId, bookmarkIds, req: reqParams } = params;
9594
+ if (!api) {
9595
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
9596
+ }
9597
+ const reqData = {
9598
+ "UISlide.ID": bookmarkIds,
9599
+ "DisplayOrder.Start": 0
9600
+ };
9601
+ yield api.POST(`ui.view/${viewId}/slides/setOrder`, reqData, exports.Api.PrepReqParams(reqParams));
9602
+ yield api.Cache.RemoveByStartsWith(GetListCacheKey(viewId));
9603
+ });
9604
+ }
9605
+ ProjectViewBookmark.SetOrder = SetOrder;
9606
+ /**
9607
+ * Returns cache identifier for a bookmark.
9608
+ * Example: {
9609
+ * const api: BruceApi.Api = ...;
9610
+ * const key = GetCacheKey("abc", "def");
9611
+ * api.Cache.Remove(key);
9612
+ * }
9613
+ * @param viewId
9614
+ * @param bookmarkId
9615
+ * @returns
9616
+ */
9617
+ function GetCacheKey(viewId, bookmarkId) {
9618
+ return `${exports.Api.ECacheKey.ProjectViewBookmark}${exports.Api.ECacheKey.Id}${viewId}${exports.Api.ECacheKey.Id}${bookmarkId}`;
9619
+ }
9620
+ ProjectViewBookmark.GetCacheKey = GetCacheKey;
9621
+ /**
9622
+ * Returns cache identifier for a list of bookmarks.
9623
+ * Example: {
9624
+ * const api: BruceApi.Api = ...;
9625
+ * const key = GetListCacheKey("abc");
9626
+ * api.Cache.Remove(key);
9627
+ * }
9628
+ * @param viewId
9629
+ * @returns
9630
+ */
9631
+ function GetListCacheKey(viewId) {
9632
+ return `${exports.Api.ECacheKey.ProjectViewBookmark}${exports.Api.ECacheKey.Id}${viewId}`;
9633
+ }
9634
+ ProjectViewBookmark.GetListCacheKey = GetListCacheKey;
9635
+ })(exports.ProjectViewBookmark || (exports.ProjectViewBookmark = {}));
9636
+
9637
+ (function (ProjectView) {
9638
+ // This is the expected default version for the DataVersion value.
9639
+ // This value should NOT be changed without looking at our API and seeing what the default value is.
9640
+ ProjectView.DEFAULT_DATA_VERSION = 2;
9641
+ // Our Cesium web navigator.
9642
+ ProjectView.TYPE_WEB_3D_NAVIGATOR = "WEB_3D_NAVIGATOR";
9643
+ // Our (currently WIP) 2D web navigator. Also known as our graph viewer.
9644
+ ProjectView.TYPE_WEB_2D_NAVIGATOR = "WEB_2D_NAVIGATOR";
9645
+ // Defaulting to 3D navigator for backwards compatibility.
9646
+ ProjectView.DEFAULT_TYPE = ProjectView.TYPE_WEB_3D_NAVIGATOR;
9647
+ /**
9648
+ * Gets a project view record.
9649
+ * @param params
9650
+ * @returns
9651
+ */
9652
+ function Get(params) {
9653
+ return __awaiter(this, void 0, void 0, function* () {
9654
+ let { api, viewId, req: reqParams } = params;
9655
+ if (!viewId) {
9656
+ throw ("View ID is required.");
9657
+ }
9658
+ if (!api) {
9659
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
9660
+ }
9661
+ const key = GetCacheKey(viewId);
9662
+ const cache = yield api.GetCacheItem(key, reqParams);
9663
+ if (cache === null || cache === void 0 ? void 0 : cache.found) {
9664
+ return cache.data;
9665
+ }
9666
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
9667
+ try {
9668
+ const data = yield api.GET(`ui.view/${viewId}`, exports.Api.PrepReqParams(reqParams));
9669
+ res({
9670
+ view: data
9671
+ });
9672
+ }
9673
+ catch (e) {
9674
+ rej(e);
9675
+ }
9676
+ }));
9677
+ yield api.SetCacheItem({
9678
+ key,
9679
+ value: prom,
9680
+ req: reqParams
9681
+ });
9682
+ return prom;
9683
+ });
9684
+ }
9685
+ ProjectView.Get = Get;
9686
+ /**
9687
+ * Gets a list of project views.
9688
+ * @param params
9689
+ * @returns
9690
+ */
9691
+ function GetList(params) {
9692
+ return __awaiter(this, void 0, void 0, function* () {
9693
+ let { api, req: reqParams, type } = params;
9694
+ if (!api) {
9695
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
9696
+ }
9697
+ const cache = yield api.GetCacheItem(GetListCacheKey(type), reqParams);
9698
+ if (cache === null || cache === void 0 ? void 0 : cache.found) {
9699
+ return cache.data;
9700
+ }
9701
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
9702
+ try {
9703
+ const data = yield api.GET("ui.view/list", exports.Api.PrepReqParams(reqParams));
9704
+ res({
9705
+ views: data.Items
9706
+ });
9707
+ }
9708
+ catch (e) {
9709
+ rej(e);
9710
+ }
9711
+ }));
9712
+ yield api.SetCacheItem({
9713
+ key: GetListCacheKey(type),
9714
+ value: prom,
9715
+ req: reqParams
9716
+ });
9717
+ return prom;
9718
+ });
9719
+ }
9720
+ ProjectView.GetList = GetList;
9721
+ /**
9722
+ * Deletes a project view.
9723
+ * @param params
9724
+ */
9725
+ function Delete(params) {
9726
+ return __awaiter(this, void 0, void 0, function* () {
9727
+ let { api, viewId, req: reqParams } = params;
9728
+ if (!viewId) {
9729
+ throw ("View ID is required.");
9730
+ }
9731
+ if (!api) {
9732
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
9733
+ }
9734
+ yield api.DELETE(`ui.view/${viewId}`, exports.Api.PrepReqParams(reqParams));
9735
+ api.Cache.Remove(GetCacheKey(viewId));
9736
+ api.Cache.RemoveByStartsWith(GetListCacheKey());
9737
+ });
9738
+ }
9739
+ ProjectView.Delete = Delete;
9740
+ /**
9741
+ * Creates or updates a project view.
9742
+ * @param params
9743
+ * @returns
9744
+ */
9745
+ function Update(params) {
9746
+ return __awaiter(this, void 0, void 0, function* () {
9747
+ let { api, view: data, req: reqParams } = params;
9748
+ if (!api) {
9749
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
9750
+ }
9751
+ if (!data) {
9752
+ data = {};
9753
+ }
9754
+ const isNew = !data.ID;
9755
+ if (!data.ID) {
9756
+ // Short ID to keep the URL short.
9757
+ // 8 length = 4,294,967,296 combinations.
9758
+ data.ID = exports.ObjectUtils.UId(8);
9759
+ }
9760
+ if (!data.Name) {
9761
+ data.Name = data.ID;
9762
+ }
9763
+ if (!data.CreatedByUIVersion) {
9764
+ data.CreatedByUIVersion = "-1";
9765
+ }
9766
+ if (isNew) {
9767
+ data = yield api.POST(`ui.view/${data.ID}`, data, exports.Api.PrepReqParams(reqParams));
9768
+ }
9769
+ else {
9770
+ data = yield api.PUT(`ui.view/${data.ID}`, data, exports.Api.PrepReqParams(reqParams));
9771
+ }
9772
+ api.Cache.Remove(GetCacheKey(data.ID));
9773
+ api.Cache.RemoveByStartsWith(GetListCacheKey());
9774
+ return {
9775
+ view: data
9776
+ };
9777
+ });
9778
+ }
9779
+ ProjectView.Update = Update;
9780
+ /**
9781
+ * Returns cache identifier for a project view.
9782
+ * Example: {
9783
+ * const api: BruceApi.Api = ...;
9784
+ * const key = GetCacheKey("abc");
9785
+ * api.Cache.Remove(key);
9786
+ * }
9787
+ * @param viewId
9788
+ * @returns
9789
+ */
9790
+ function GetCacheKey(viewId) {
9791
+ return `${exports.Api.ECacheKey.ProjectView}${exports.Api.ECacheKey.Id}${viewId}`;
9792
+ }
9793
+ ProjectView.GetCacheKey = GetCacheKey;
9794
+ /**
9795
+ * Returns cache identifier for a list of project views.
9796
+ * Example: {
9797
+ * const api: BruceApi.Api = ...;
9798
+ * const key = GetListCacheKey();
9799
+ * api.Cache.Remove(key);
9800
+ * }
9801
+ * @param type optional filter for the type of project view.
9802
+ * @returns
9803
+ */
9804
+ function GetListCacheKey(type) {
9805
+ if (type) {
9806
+ return `${exports.Api.ECacheKey.ProjectView}${exports.Api.ECacheKey.ListId}${type}`;
9807
+ }
9808
+ return `${exports.Api.ECacheKey.ProjectView}${exports.Api.ECacheKey.ListId}`;
9809
+ }
9810
+ ProjectView.GetListCacheKey = GetListCacheKey;
9811
+ })(exports.ProjectView || (exports.ProjectView = {}));
9812
+
9813
+ function getTemplateSettings(apiGetter, reqParams) {
9814
+ var _a;
9815
+ return __awaiter(this, void 0, void 0, function* () {
9816
+ const { view } = yield exports.ProjectView.Get({
9817
+ api: apiGetter.getApi(exports.Api.TEMPLATE_ACCOUNT_ID),
9818
+ viewId: "default",
9819
+ req: reqParams
9820
+ });
9821
+ return (_a = view.Settings) !== null && _a !== void 0 ? _a : {};
9822
+ });
9823
+ }
9824
+ function checkSourceToTemplate(items, templateItem, addIfMissing) {
9825
+ const index = items.findIndex(x => x.Name === templateItem.Name);
9826
+ if (index > -1) {
9827
+ templateItem.IsDefault = true;
9828
+ templateItem.IsEnabled = items[index].IsEnabled;
9829
+ items[index] = templateItem;
9830
+ }
9831
+ else if (addIfMissing) {
9832
+ templateItem.IsDefault = true;
9833
+ items.push(templateItem);
9834
+ }
9835
+ }
9836
+ (function (ProjectViewLegacyTile) {
9837
+ function MergeMapTemplateData(params) {
9838
+ var _a;
9839
+ return __awaiter(this, void 0, void 0, function* () {
9840
+ let { getter, sources: items, addIfMissing, req: reqParams } = params;
9841
+ if (!getter) {
9842
+ getter = exports.ENVIRONMENT.Api().GetBruceGetter();
9843
+ }
9844
+ const settings = yield getTemplateSettings(getter, reqParams);
9845
+ const maps = (_a = settings.CesiumMapSources) !== null && _a !== void 0 ? _a : [];
9846
+ for (let i = 0; i < maps.length; i++) {
9847
+ const mapSource = maps[i];
9848
+ checkSourceToTemplate(items, mapSource, addIfMissing);
9849
+ }
9850
+ return {
9851
+ sources: items
9852
+ };
9853
+ });
9854
+ }
9855
+ ProjectViewLegacyTile.MergeMapTemplateData = MergeMapTemplateData;
9856
+ function MergeTerrainTemplateData(params) {
9857
+ var _a;
9858
+ return __awaiter(this, void 0, void 0, function* () {
9859
+ let { getter, sources: items, addIfMissing, req: reqParams } = params;
9860
+ if (!getter) {
9861
+ getter = exports.ENVIRONMENT.Api().GetBruceGetter();
9862
+ }
9863
+ const settings = yield getTemplateSettings(getter, reqParams);
9864
+ const terrains = (_a = settings.CesiumTerrainSources) !== null && _a !== void 0 ? _a : [];
9865
+ for (let i = 0; i < terrains.length; i++) {
9866
+ const terrainSource = terrains[i];
9867
+ checkSourceToTemplate(items, terrainSource, addIfMissing);
9868
+ }
9869
+ return {
9870
+ sources: items
9871
+ };
9872
+ });
9873
+ }
9874
+ ProjectViewLegacyTile.MergeTerrainTemplateData = MergeTerrainTemplateData;
9875
+ })(exports.ProjectViewLegacyTile || (exports.ProjectViewLegacyTile = {}));
9876
+
9877
+ /**
9878
+ * A tile is an imagery or terrain tileset definition.
9879
+ */
9880
+ (function (ProjectViewTile) {
9881
+ /**
9882
+ * Available imagery defaults.
9883
+ */
9884
+ let EDefaultImagery;
9885
+ (function (EDefaultImagery) {
9886
+ EDefaultImagery["BingMapsAerial"] = "bingmapsaerial";
9887
+ EDefaultImagery["BingMapsAerialWithLabels"] = "bingmapsaerialwithlabels";
9888
+ EDefaultImagery["BingMapsRoads"] = "bingmapsroads";
9889
+ EDefaultImagery["MapboxSatellite"] = "mapboxsatellite";
9890
+ EDefaultImagery["MapBoxStreets"] = "mapboxstreets";
9891
+ EDefaultImagery["MapBoxStreetsClassic"] = "mapboxstreetsclassic";
9892
+ EDefaultImagery["EsriWorldImagery"] = "esriworldimagery";
9893
+ EDefaultImagery["EsriWorldStreetMap"] = "esriworldstreetmap";
9894
+ EDefaultImagery["EsriNationalGeographic"] = "esrinationalgeographic";
9895
+ EDefaultImagery["OpenStreetMap"] = "openstreetmap";
9896
+ EDefaultImagery["LINZ"] = "linz";
9897
+ EDefaultImagery["StamenWaterColor"] = "stamenwatercolor";
9898
+ EDefaultImagery["StamenToner"] = "stamentoner";
9899
+ EDefaultImagery["Grid"] = "grid";
9900
+ EDefaultImagery["ThunderforestCycle"] = "thunderforestcycle";
9901
+ EDefaultImagery["ThunderforestTransport"] = "thunderforesttransport";
9902
+ EDefaultImagery["ThunderforestLandscape"] = "thunderforestlandscape";
9903
+ })(EDefaultImagery = ProjectViewTile.EDefaultImagery || (ProjectViewTile.EDefaultImagery = {}));
9904
+ /**
9905
+ * Prepared array for UI.
9906
+ * TODO: Im not happy with icon urls sitting in the code. I'd prefer we ship these icons in the library as files.
9907
+ */
9908
+ ProjectViewTile.DefaultImagery = [
9909
+ {
9910
+ id: EDefaultImagery.BingMapsAerial,
9911
+ name: "Bing Maps Aerial",
9912
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/bingAerial.png"
9913
+ },
9914
+ {
9915
+ id: EDefaultImagery.BingMapsAerialWithLabels,
9916
+ name: "Bing Maps Aerial with Labels",
9917
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/bingAerialLabels.png"
9918
+ },
9919
+ {
9920
+ id: EDefaultImagery.BingMapsRoads,
9921
+ name: "Bing Maps Roads",
9922
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/bingRoads.png"
9923
+ },
9924
+ {
9925
+ id: EDefaultImagery.MapboxSatellite,
9926
+ name: "Mapbox Satellite",
9927
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/mapboxSatellite.png"
9928
+ },
9929
+ {
9930
+ id: EDefaultImagery.MapBoxStreets,
9931
+ name: "Mapbox Streets",
9932
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/mapboxTerrain.png"
9933
+ },
9934
+ {
9935
+ id: EDefaultImagery.MapBoxStreetsClassic,
9936
+ name: "Mapbox Streets Classic",
9937
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/mapboxStreets.png"
9938
+ },
9939
+ {
9940
+ id: EDefaultImagery.EsriWorldImagery,
9941
+ name: "Esri World Imagery",
9942
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/esriWorldImagery.png"
9943
+ },
9944
+ {
9945
+ id: EDefaultImagery.EsriWorldStreetMap,
9946
+ name: "Esri World Street Map",
9947
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/esriWorldStreetMap.png"
9948
+ },
9949
+ {
9950
+ id: EDefaultImagery.EsriNationalGeographic,
9951
+ name: "Esri National Geographic",
9952
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/esriNationalGeographic.png"
9953
+ },
9954
+ {
9955
+ id: EDefaultImagery.OpenStreetMap,
9956
+ name: "Open Street Map",
9957
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/openStreetMap.png"
9958
+ },
9959
+ {
9960
+ id: EDefaultImagery.LINZ,
9961
+ name: "LINZ",
9962
+ iconUrl: "https://template.ui.nextspace.host/media/linz.jpg"
9963
+ },
9964
+ {
9965
+ id: EDefaultImagery.StamenWaterColor,
9966
+ name: "Stamen Water Color",
9967
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/stamenWatercolor.png"
9968
+ },
9969
+ {
9970
+ id: EDefaultImagery.StamenToner,
9971
+ name: "Stamen Toner",
9972
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/stamenToner.png"
9973
+ },
9974
+ {
9975
+ id: EDefaultImagery.ThunderforestCycle,
9976
+ name: "Thunderforest Cycle"
9977
+ },
9978
+ {
9979
+ id: EDefaultImagery.ThunderforestTransport,
9980
+ name: "Thunderforest Transport"
9981
+ },
9982
+ {
9983
+ id: EDefaultImagery.ThunderforestLandscape,
9984
+ name: "Thunderforest Landscape"
9985
+ },
9986
+ {
9987
+ id: EDefaultImagery.Grid,
9988
+ name: "Grid",
9989
+ iconUrl: "https://template.api.nextspace-uat.net/file/2885d8df-028b-4f5c-80b3-2634f7e7cf69.png"
9990
+ }
9991
+ ];
9992
+ /**
9993
+ * Available terrain defaults.
9864
9994
  */
9865
- function CreateFromTilesetId(tilesetId, type) {
9866
- if (type === exports.Tileset.EType.Cad) {
9867
- return {
9868
- id: exports.ObjectUtils.UId(),
9869
- Type: EType.CadTileset,
9870
- Caption: "Generated CAD Menu Item",
9871
- FlyTo: false,
9872
- tileset: {
9873
- TilesetID: tilesetId
9874
- }
9875
- };
9876
- }
9877
- else if (type == exports.Tileset.EType.EntitiesSet) {
9878
- return {
9879
- id: exports.ObjectUtils.UId(),
9880
- Type: EType.EntityTileset,
9881
- Caption: "Generated Entities Menu Item",
9882
- FlyTo: false,
9883
- tileset: {
9884
- TilesetID: tilesetId
9885
- }
9886
- };
9887
- }
9888
- else if (type == exports.Tileset.EType.PointCloud) {
9889
- return {
9890
- id: exports.ObjectUtils.UId(),
9891
- Type: EType.PointCloud,
9892
- Caption: "Generated Point Cloud Menu Item",
9893
- FlyTo: false,
9894
- tileset: {
9895
- TilesetID: tilesetId
9896
- }
9897
- };
9898
- }
9899
- else if (type == exports.Tileset.EType.EntitiesMap) {
9900
- return {
9901
- id: exports.ObjectUtils.UId(),
9902
- Type: EType.EntityRaster,
9903
- Caption: "Generated Entities Menu Item",
9904
- tileset: {
9905
- TilesetID: tilesetId
9906
- }
9907
- };
9995
+ let EDefaultTerrain;
9996
+ (function (EDefaultTerrain) {
9997
+ EDefaultTerrain["CesiumWorldTerrain"] = "cesiumworldterrain";
9998
+ EDefaultTerrain["FlatTerrain"] = "flatterrain";
9999
+ EDefaultTerrain["LINZ"] = "linz";
10000
+ })(EDefaultTerrain = ProjectViewTile.EDefaultTerrain || (ProjectViewTile.EDefaultTerrain = {}));
10001
+ /**
10002
+ * Prepared array for UI.
10003
+ * TODO: Im not happy with icon urls sitting in the code. I'd prefer we ship these icons in the library as files.
10004
+ */
10005
+ ProjectViewTile.DefaultTerrains = [
10006
+ {
10007
+ id: EDefaultTerrain.CesiumWorldTerrain,
10008
+ name: "Cesium World Terrain",
10009
+ iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/TerrainProviders/CesiumWorldTerrain.png"
10010
+ },
10011
+ {
10012
+ id: EDefaultTerrain.LINZ,
10013
+ name: "LINZ",
10014
+ iconUrl: "https://template.ui.nextspace.host/media/linz.jpg"
10015
+ },
10016
+ {
10017
+ id: EDefaultTerrain.FlatTerrain,
10018
+ name: "Flat Terrain",
9908
10019
  }
9909
- throw ("Tileset type not supported.");
9910
- }
9911
- MenuItem.CreateFromTilesetId = CreateFromTilesetId;
9912
- })(exports.MenuItem || (exports.MenuItem = {}));
10020
+ ];
10021
+ })(exports.ProjectViewTile || (exports.ProjectViewTile = {}));
9913
10022
 
9914
- (function (ProjectViewBookmark) {
9915
- // This is the expected default version for the DataVersion value.
9916
- // This value should NOT be changed without looking at our API and seeing what the default value is.
9917
- ProjectViewBookmark.DEFAULT_DATA_VERSION = 2;
10023
+ /**
10024
+ * Deprecated Project View record.
10025
+ * This was used in the legacy web Navigator.
10026
+ */
10027
+ (function (ProjectViewLegacy) {
10028
+ ProjectViewLegacy.DATA_VERSION = 1;
10029
+ })(exports.ProjectViewLegacy || (exports.ProjectViewLegacy = {}));
10030
+
10031
+ /**
10032
+ * Deprecated Project View Bookmark record.
10033
+ * This was used in the legacy web Navigator.
10034
+ */
10035
+ (function (ProjectViewLegacyBookmark) {
10036
+ ProjectViewLegacyBookmark.DATA_VERSION = 1;
10037
+ })(exports.ProjectViewLegacyBookmark || (exports.ProjectViewLegacyBookmark = {}));
10038
+
10039
+ (function (PendingAction) {
9918
10040
  /**
9919
- * Describes the content of a bookmark.
9920
- * As part of a deal we've been commissioned to create an alternative bookmark type to embed content.
10041
+ * Available pending action statuses.
9921
10042
  */
9922
- let EContentType;
9923
- (function (EContentType) {
9924
- EContentType["WEB_3D"] = "WEB_3D";
9925
- EContentType["IFRAME"] = "IFRAME";
9926
- })(EContentType = ProjectViewBookmark.EContentType || (ProjectViewBookmark.EContentType = {}));
10043
+ let EStatus;
10044
+ (function (EStatus) {
10045
+ EStatus["InProgress"] = "IN_PROGRESS";
10046
+ EStatus["Cancelled"] = "CANCELLED";
10047
+ EStatus["Complete"] = "COMPLETE";
10048
+ EStatus["Failed"] = "FAILED";
10049
+ })(EStatus = PendingAction.EStatus || (PendingAction.EStatus = {}));
9927
10050
  /**
9928
- * Gets a bookmark record.
10051
+ * Available message types.
10052
+ */
10053
+ let EMessageType;
10054
+ (function (EMessageType) {
10055
+ EMessageType["Warn"] = "WARNING";
10056
+ EMessageType["Error"] = "ERROR";
10057
+ EMessageType["Status"] = "STATUS";
10058
+ EMessageType["Info"] = "INFO";
10059
+ })(EMessageType = PendingAction.EMessageType || (PendingAction.EMessageType = {}));
10060
+ /**
10061
+ * Returns a pending action record.
9929
10062
  * @param params
9930
10063
  * @returns
9931
10064
  */
9932
10065
  function Get(params) {
9933
10066
  return __awaiter(this, void 0, void 0, function* () {
9934
- let { api, viewId, bookmarkId, req: reqParams } = params;
9935
- if (!viewId || !bookmarkId) {
9936
- throw ("View ID and Bookmark ID are required.");
10067
+ let { api, actionId, req: reqParams } = params;
10068
+ if (!actionId) {
10069
+ throw ("Action ID is required.");
9937
10070
  }
9938
10071
  if (!api) {
9939
10072
  api = exports.ENVIRONMENT.Api().GetBruceApi();
9940
10073
  }
9941
- const key = GetCacheKey(viewId, bookmarkId);
9942
- const cache = yield api.GetCacheItem(key, reqParams);
9943
- if (cache === null || cache === void 0 ? void 0 : cache.found) {
9944
- return cache.data;
9945
- }
9946
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
9947
- try {
9948
- const data = yield api.GET(`ui.view/${viewId}/slide/${bookmarkId}`, exports.Api.PrepReqParams(reqParams));
9949
- res({
9950
- bookmark: data
9951
- });
9952
- }
9953
- catch (e) {
9954
- rej(e);
9955
- }
9956
- }));
9957
- yield api.SetCacheItem({
9958
- key,
9959
- value: prom,
9960
- req: reqParams
9961
- });
9962
- return prom;
10074
+ const data = yield api.GET(`pendingAction/${actionId}`, exports.Api.PrepReqParams(reqParams));
10075
+ return {
10076
+ action: data
10077
+ };
9963
10078
  });
9964
10079
  }
9965
- ProjectViewBookmark.Get = Get;
10080
+ PendingAction.Get = Get;
9966
10081
  /**
9967
- * Deletes a bookmark record.
10082
+ * Returns a list of pending action records.
9968
10083
  * @param params
10084
+ * @returns
9969
10085
  */
9970
- function Delete(params) {
10086
+ function GetRelevantList(params) {
9971
10087
  return __awaiter(this, void 0, void 0, function* () {
9972
- let { api, viewId, bookmarkId, req: reqParams } = params;
9973
- if (!viewId || !bookmarkId) {
9974
- throw ("View ID and Bookmark ID are required.");
9975
- }
10088
+ let { api, stricter, reqParams } = params;
9976
10089
  if (!api) {
9977
10090
  api = exports.ENVIRONMENT.Api().GetBruceApi();
9978
10091
  }
9979
- yield api.DELETE(`ui.view/${viewId}/slide/${bookmarkId}`, exports.Api.PrepReqParams(reqParams));
9980
- api.Cache.Remove(GetCacheKey(viewId, bookmarkId));
9981
- api.Cache.Remove(GetListCacheKey(viewId));
10092
+ const data = yield api.GET(`pendingActions/important?Update=${Boolean(stricter)}`, exports.Api.PrepReqParams(reqParams));
10093
+ return {
10094
+ actions: data.Items
10095
+ };
9982
10096
  });
9983
10097
  }
9984
- ProjectViewBookmark.Delete = Delete;
10098
+ PendingAction.GetRelevantList = GetRelevantList;
9985
10099
  /**
9986
- * Gets a list of bookmark records.
10100
+ * Returns a list of pending action record messages.
9987
10101
  * @param params
9988
10102
  * @returns
9989
10103
  */
9990
- function GetList(params) {
10104
+ function GetMessages(params) {
9991
10105
  return __awaiter(this, void 0, void 0, function* () {
9992
- let { api, viewId, req: reqParams } = params;
9993
- if (!viewId) {
9994
- throw ("View ID is required.");
9995
- }
10106
+ let { api, actionId, order, startIndex, amount, req: reqParams, types } = params;
9996
10107
  if (!api) {
9997
10108
  api = exports.ENVIRONMENT.Api().GetBruceApi();
9998
10109
  }
9999
- const cache = yield api.GetCacheItem(GetListCacheKey(viewId), reqParams);
10000
- if (cache === null || cache === void 0 ? void 0 : cache.found) {
10001
- return cache.data;
10110
+ if (amount == null) {
10111
+ amount = 500;
10002
10112
  }
10003
- const req = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
10004
- try {
10005
- const data = yield api.GET(`ui.view/${viewId}/slides`, exports.Api.PrepReqParams(reqParams));
10006
- const items = data.Items ? data.Items : [];
10007
- // Cache individual items.
10008
- // Maybe better to load list cache when getting 1 slide and seeing if it's in there.
10009
- // WARNING: Right now the data matches, in the future the list may contain a shortened result.
10010
- for (let i = 0; i < items.length; i++) {
10011
- const item = items[i];
10012
- const prom = new Promise((res) => {
10013
- res({
10014
- bookmark: item
10015
- });
10016
- });
10017
- yield api.SetCacheItem({
10018
- key: GetCacheKey(viewId, item.ID),
10019
- value: prom,
10020
- req: reqParams
10021
- });
10022
- }
10023
- res({
10024
- bookmarks: items
10025
- });
10026
- }
10027
- catch (e) {
10028
- rej(e);
10029
- }
10030
- }));
10031
- yield api.SetCacheItem({
10032
- key: GetListCacheKey(viewId),
10033
- value: req,
10034
- req: reqParams
10035
- });
10036
- return req;
10037
- });
10038
- }
10039
- ProjectViewBookmark.GetList = GetList;
10040
- /**
10041
- * Creates or updates a bookmark record.
10042
- * @param params
10043
- * @returns
10044
- */
10045
- function Update(params) {
10046
- return __awaiter(this, void 0, void 0, function* () {
10047
- let { api, viewId, bookmark: data, req: reqParams } = params;
10048
- if (!api) {
10049
- api = exports.ENVIRONMENT.Api().GetBruceApi();
10113
+ if (startIndex == null) {
10114
+ startIndex = 0;
10115
+ }
10116
+ if (order == null) {
10117
+ order = exports.Api.ESortOrder.Asc;
10050
10118
  }
10051
- if (!(data === null || data === void 0 ? void 0 : data.Title)) {
10052
- data.Title = data.ID;
10119
+ let args = `?SortOrder=${order == exports.Api.ESortOrder.Desc ? "DESC" : "ASC"}&PageSize=${amount}&PageIndex=${startIndex}`;
10120
+ if (types === null || types === void 0 ? void 0 : types.length) {
10121
+ for (let i = 0; i < types.length; i++) {
10122
+ args += `&Type=${types[i]}`;
10123
+ }
10053
10124
  }
10054
- const res = yield api.POST(`ui.view/${viewId}/slide/${data.ID ? data.ID : ""}`, data, exports.Api.PrepReqParams(reqParams));
10055
- api.Cache.Remove(GetCacheKey(viewId, data.ID));
10056
- api.Cache.Remove(GetListCacheKey(viewId));
10125
+ const data = yield api.GET(`pendingAction/${actionId}/progressMessages` + args, exports.Api.PrepReqParams(reqParams));
10057
10126
  return {
10058
- bookmark: res
10127
+ messages: data.Items
10059
10128
  };
10060
10129
  });
10061
10130
  }
10062
- ProjectViewBookmark.Update = Update;
10131
+ PendingAction.GetMessages = GetMessages;
10063
10132
  /**
10064
- * Sets the order of bookmarks within a project view.
10133
+ * Requests to cancel a pending action.
10065
10134
  * @param params
10066
10135
  */
10067
- function SetOrder(params) {
10136
+ function Cancel(params) {
10068
10137
  return __awaiter(this, void 0, void 0, function* () {
10069
- let { api, viewId, bookmarkIds, req: reqParams } = params;
10138
+ let { api, actionId, req: reqParams } = params;
10139
+ if (!actionId) {
10140
+ throw ("Action ID is required.");
10141
+ }
10070
10142
  if (!api) {
10071
10143
  api = exports.ENVIRONMENT.Api().GetBruceApi();
10072
10144
  }
10073
- const reqData = {
10074
- "UISlide.ID": bookmarkIds,
10075
- "DisplayOrder.Start": 0
10076
- };
10077
- yield api.POST(`ui.view/${viewId}/slides/setOrder`, reqData, exports.Api.PrepReqParams(reqParams));
10078
- yield api.Cache.RemoveByStartsWith(GetListCacheKey(viewId));
10145
+ yield api.DELETE(`pendingAction/${actionId}`, exports.Api.PrepReqParams(reqParams));
10079
10146
  });
10080
10147
  }
10081
- ProjectViewBookmark.SetOrder = SetOrder;
10148
+ PendingAction.Cancel = Cancel;
10149
+ })(exports.PendingAction || (exports.PendingAction = {}));
10150
+
10151
+ // Some dead accounts that we don't want to show in the UI.
10152
+ // Some accounts may not be "dead" but instead purposely don't have a NextspaceAPI database so we'll avoid them too.
10153
+ const ACCOUNT_EXCLUSIONS = ["hyperportal", "hypeportal", "bviewer"];
10154
+ (function (Account) {
10082
10155
  /**
10083
- * Returns cache identifier for a bookmark.
10084
- * Example: {
10085
- * const api: BruceApi.Api = ...;
10086
- * const key = GetCacheKey("abc", "def");
10087
- * api.Cache.Remove(key);
10088
- * }
10089
- * @param viewId
10090
- * @param bookmarkId
10091
- * @returns
10156
+ * Known Nextspace applications we store settings for.
10092
10157
  */
10093
- function GetCacheKey(viewId, bookmarkId) {
10094
- return `${exports.Api.ECacheKey.ProjectViewBookmark}${exports.Api.ECacheKey.Id}${viewId}${exports.Api.ECacheKey.Id}${bookmarkId}`;
10095
- }
10096
- ProjectViewBookmark.GetCacheKey = GetCacheKey;
10158
+ let EAppId;
10159
+ (function (EAppId) {
10160
+ EAppId["BruceApi"] = "BruceAPI";
10161
+ EAppId["Navigator"] = "Navigator";
10162
+ EAppId["Operator"] = "BruceClientAdmin";
10163
+ })(EAppId = Account.EAppId || (Account.EAppId = {}));
10097
10164
  /**
10098
- * Returns cache identifier for a list of bookmarks.
10099
- * Example: {
10100
- * const api: BruceApi.Api = ...;
10101
- * const key = GetListCacheKey("abc");
10102
- * api.Cache.Remove(key);
10103
- * }
10104
- * @param viewId
10105
- * @returns
10165
+ * Possible starter content options.
10166
+ * When creating a new account you can populate it with certain default data.
10106
10167
  */
10107
- function GetListCacheKey(viewId) {
10108
- return `${exports.Api.ECacheKey.ProjectViewBookmark}${exports.Api.ECacheKey.Id}${viewId}`;
10109
- }
10110
- ProjectViewBookmark.GetListCacheKey = GetListCacheKey;
10111
- })(exports.ProjectViewBookmark || (exports.ProjectViewBookmark = {}));
10112
-
10113
- (function (ProjectView) {
10114
- // This is the expected default version for the DataVersion value.
10115
- // This value should NOT be changed without looking at our API and seeing what the default value is.
10116
- ProjectView.DEFAULT_DATA_VERSION = 2;
10117
- // Our Cesium web navigator.
10118
- ProjectView.TYPE_WEB_3D_NAVIGATOR = "WEB_3D_NAVIGATOR";
10119
- // Our (currently WIP) 2D web navigator. Also known as our graph viewer.
10120
- ProjectView.TYPE_WEB_2D_NAVIGATOR = "WEB_2D_NAVIGATOR";
10121
- // Defaulting to 3D navigator for backwards compatibility.
10122
- ProjectView.DEFAULT_TYPE = ProjectView.TYPE_WEB_3D_NAVIGATOR;
10168
+ let EStarterContent;
10169
+ (function (EStarterContent) {
10170
+ EStarterContent["Default"] = "default";
10171
+ EStarterContent["None"] = "none";
10172
+ })(EStarterContent = Account.EStarterContent || (Account.EStarterContent = {}));
10123
10173
  /**
10124
- * Gets a project view record.
10174
+ * Gets a client account record by ID.
10125
10175
  * @param params
10126
10176
  * @returns
10127
10177
  */
10128
10178
  function Get(params) {
10129
10179
  return __awaiter(this, void 0, void 0, function* () {
10130
- let { api, viewId, req: reqParams } = params;
10131
- if (!viewId) {
10132
- throw ("View ID is required.");
10133
- }
10180
+ let { api, accountId: id, req: reqParams } = params;
10134
10181
  if (!api) {
10135
- api = exports.ENVIRONMENT.Api().GetBruceApi();
10182
+ api = exports.ENVIRONMENT.Api().GetGuardianApi();
10136
10183
  }
10137
- const key = GetCacheKey(viewId);
10138
- const cache = yield api.GetCacheItem(key, reqParams);
10184
+ const cache = yield api.GetCacheItem(GetCacheKey(id), reqParams);
10139
10185
  if (cache === null || cache === void 0 ? void 0 : cache.found) {
10140
10186
  return cache.data;
10141
10187
  }
10142
10188
  const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
10143
10189
  try {
10144
- const data = yield api.GET(`ui.view/${viewId}`, exports.Api.PrepReqParams(reqParams));
10190
+ const data = yield api.GET(`accountbyid/${id}`, reqParams);
10191
+ // Update the cache by subdomain as well in case it's different to the ID.
10192
+ if ((data === null || data === void 0 ? void 0 : data.ID) && (reqParams === null || reqParams === void 0 ? void 0 : reqParams.noCache) != false) {
10193
+ yield api.SetCacheItem({
10194
+ key: data.Subdomain,
10195
+ value: prom,
10196
+ req: reqParams
10197
+ });
10198
+ }
10145
10199
  res({
10146
- view: data
10200
+ account: data
10147
10201
  });
10148
10202
  }
10149
10203
  catch (e) {
@@ -10151,34 +10205,42 @@
10151
10205
  }
10152
10206
  }));
10153
10207
  yield api.SetCacheItem({
10154
- key,
10208
+ key: GetCacheKey(id),
10155
10209
  value: prom,
10156
10210
  req: reqParams
10157
10211
  });
10158
10212
  return prom;
10159
10213
  });
10160
10214
  }
10161
- ProjectView.Get = Get;
10215
+ Account.Get = Get;
10162
10216
  /**
10163
- * Gets a list of project views.
10217
+ * Returns a client account record by subdomain or ID.
10164
10218
  * @param params
10165
10219
  * @returns
10166
10220
  */
10167
- function GetList(params) {
10221
+ function GetBySubdomain(params) {
10168
10222
  return __awaiter(this, void 0, void 0, function* () {
10169
- let { api, req: reqParams, type } = params;
10223
+ let { api, subdomain, req: reqParams } = params;
10170
10224
  if (!api) {
10171
- api = exports.ENVIRONMENT.Api().GetBruceApi();
10225
+ api = exports.ENVIRONMENT.Api().GetGuardianApi();
10172
10226
  }
10173
- const cache = yield api.GetCacheItem(GetListCacheKey(type), reqParams);
10227
+ const cache = yield api.GetCacheItem(GetCacheKey(subdomain), reqParams);
10174
10228
  if (cache === null || cache === void 0 ? void 0 : cache.found) {
10175
10229
  return cache.data;
10176
10230
  }
10177
10231
  const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
10178
10232
  try {
10179
- const data = yield api.GET("ui.view/list", exports.Api.PrepReqParams(reqParams));
10233
+ const data = yield api.GET(`account/${subdomain}`, reqParams);
10234
+ // Update the cache by ID as well in case it's different to the subdomain.
10235
+ if ((data === null || data === void 0 ? void 0 : data.ID) && (reqParams === null || reqParams === void 0 ? void 0 : reqParams.noCache) != false) {
10236
+ yield api.SetCacheItem({
10237
+ key: data.ID,
10238
+ value: prom,
10239
+ req: reqParams
10240
+ });
10241
+ }
10180
10242
  res({
10181
- views: data.Items
10243
+ account: data
10182
10244
  });
10183
10245
  }
10184
10246
  catch (e) {
@@ -10186,443 +10248,377 @@
10186
10248
  }
10187
10249
  }));
10188
10250
  yield api.SetCacheItem({
10189
- key: GetListCacheKey(type),
10251
+ key: GetCacheKey(subdomain),
10190
10252
  value: prom,
10191
10253
  req: reqParams
10192
10254
  });
10193
10255
  return prom;
10194
10256
  });
10195
10257
  }
10196
- ProjectView.GetList = GetList;
10258
+ Account.GetBySubdomain = GetBySubdomain;
10197
10259
  /**
10198
- * Deletes a project view.
10260
+ * Gets a list of client accounts related to the current session user.
10199
10261
  * @param params
10262
+ * @returns
10200
10263
  */
10201
- function Delete(params) {
10264
+ function GetRelatedList(params) {
10202
10265
  return __awaiter(this, void 0, void 0, function* () {
10203
- let { api, viewId, req: reqParams } = params;
10204
- if (!viewId) {
10205
- throw ("View ID is required.");
10206
- }
10266
+ let { api, req: reqParams } = params;
10207
10267
  if (!api) {
10208
- api = exports.ENVIRONMENT.Api().GetBruceApi();
10268
+ api = exports.ENVIRONMENT.Api().GetGuardianApi();
10209
10269
  }
10210
- yield api.DELETE(`ui.view/${viewId}`, exports.Api.PrepReqParams(reqParams));
10211
- api.Cache.Remove(GetCacheKey(viewId));
10212
- api.Cache.RemoveByStartsWith(GetListCacheKey());
10270
+ const cache = yield api.GetCacheItem(GetListCacheKey(api.GetSessionId()), reqParams);
10271
+ if (cache === null || cache === void 0 ? void 0 : cache.found) {
10272
+ return cache.data;
10273
+ }
10274
+ const req = api.GET("user/relatedClientAccounts", reqParams);
10275
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
10276
+ try {
10277
+ const data = yield req;
10278
+ const items = data.Items.filter((x) => !ACCOUNT_EXCLUSIONS.includes(x.ID));
10279
+ res({
10280
+ accounts: items
10281
+ });
10282
+ }
10283
+ catch (e) {
10284
+ rej(e);
10285
+ }
10286
+ }));
10287
+ yield api.SetCacheItem({
10288
+ key: GetListCacheKey(api.GetSessionId()),
10289
+ value: prom,
10290
+ req: reqParams
10291
+ });
10292
+ return prom;
10213
10293
  });
10214
10294
  }
10215
- ProjectView.Delete = Delete;
10295
+ Account.GetRelatedList = GetRelatedList;
10216
10296
  /**
10217
- * Creates or updates a project view.
10297
+ * Gets application settings for a specific client account.
10218
10298
  * @param params
10219
10299
  * @returns
10220
10300
  */
10221
- function Update(params) {
10301
+ function GetAppSettings(params) {
10222
10302
  return __awaiter(this, void 0, void 0, function* () {
10223
- let { api, view: data, req: reqParams } = params;
10303
+ let { api, accountId: id, appId, req: reqParams } = params;
10224
10304
  if (!api) {
10225
- api = exports.ENVIRONMENT.Api().GetBruceApi();
10226
- }
10227
- if (!data) {
10228
- data = {};
10229
- }
10230
- const isNew = !data.ID;
10231
- if (!data.ID) {
10232
- // Short ID to keep the URL short.
10233
- // 8 length = 4,294,967,296 combinations.
10234
- data.ID = exports.ObjectUtils.UId(8);
10235
- }
10236
- if (!data.Name) {
10237
- data.Name = data.ID;
10238
- }
10239
- if (!data.CreatedByUIVersion) {
10240
- data.CreatedByUIVersion = "-1";
10241
- }
10242
- if (isNew) {
10243
- data = yield api.POST(`ui.view/${data.ID}`, data, exports.Api.PrepReqParams(reqParams));
10305
+ api = exports.ENVIRONMENT.Api().GetGuardianApi();
10244
10306
  }
10245
- else {
10246
- data = yield api.PUT(`ui.view/${data.ID}`, data, exports.Api.PrepReqParams(reqParams));
10307
+ const cache = yield api.GetCacheItem(GetCacheKey(id, appId), reqParams);
10308
+ if (cache === null || cache === void 0 ? void 0 : cache.found) {
10309
+ return cache.data;
10247
10310
  }
10248
- api.Cache.Remove(GetCacheKey(data.ID));
10249
- api.Cache.RemoveByStartsWith(GetListCacheKey());
10250
- return {
10251
- view: data
10252
- };
10311
+ const req = yield api.GET(`account/${id}?ApplicationID=${appId}`, reqParams);
10312
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
10313
+ var _a;
10314
+ try {
10315
+ const data = yield req;
10316
+ const settings = (_a = data === null || data === void 0 ? void 0 : data["Application.Settings"]) !== null && _a !== void 0 ? _a : {};
10317
+ res({
10318
+ settings: settings
10319
+ });
10320
+ }
10321
+ catch (e) {
10322
+ rej(e);
10323
+ }
10324
+ }));
10325
+ yield api.SetCacheItem({
10326
+ key: GetCacheKey(id, appId),
10327
+ value: prom,
10328
+ req: reqParams
10329
+ });
10330
+ return prom;
10253
10331
  });
10254
10332
  }
10255
- ProjectView.Update = Update;
10256
- /**
10257
- * Returns cache identifier for a project view.
10258
- * Example: {
10259
- * const api: BruceApi.Api = ...;
10260
- * const key = GetCacheKey("abc");
10261
- * api.Cache.Remove(key);
10262
- * }
10263
- * @param viewId
10264
- * @returns
10265
- */
10266
- function GetCacheKey(viewId) {
10267
- return `${exports.Api.ECacheKey.ProjectView}${exports.Api.ECacheKey.Id}${viewId}`;
10268
- }
10269
- ProjectView.GetCacheKey = GetCacheKey;
10333
+ Account.GetAppSettings = GetAppSettings;
10270
10334
  /**
10271
- * Returns cache identifier for a list of project views.
10272
- * Example: {
10273
- * const api: BruceApi.Api = ...;
10274
- * const key = GetListCacheKey();
10275
- * api.Cache.Remove(key);
10276
- * }
10277
- * @param type optional filter for the type of project view.
10335
+ * Updates application settings for a specific client account + application.
10336
+ * WARNING: Do not update API settings without knowing what you're doing.
10337
+ * @param params
10278
10338
  * @returns
10279
10339
  */
10280
- function GetListCacheKey(type) {
10281
- if (type) {
10282
- return `${exports.Api.ECacheKey.ProjectView}${exports.Api.ECacheKey.ListId}${type}`;
10283
- }
10284
- return `${exports.Api.ECacheKey.ProjectView}${exports.Api.ECacheKey.ListId}`;
10285
- }
10286
- ProjectView.GetListCacheKey = GetListCacheKey;
10287
- })(exports.ProjectView || (exports.ProjectView = {}));
10288
-
10289
- function getTemplateSettings(apiGetter, reqParams) {
10290
- var _a;
10291
- return __awaiter(this, void 0, void 0, function* () {
10292
- const { view } = yield exports.ProjectView.Get({
10293
- api: apiGetter.getApi(exports.Api.TEMPLATE_ACCOUNT_ID),
10294
- viewId: "default",
10295
- req: reqParams
10296
- });
10297
- return (_a = view.Settings) !== null && _a !== void 0 ? _a : {};
10298
- });
10299
- }
10300
- function checkSourceToTemplate(items, templateItem, addIfMissing) {
10301
- const index = items.findIndex(x => x.Name === templateItem.Name);
10302
- if (index > -1) {
10303
- templateItem.IsDefault = true;
10304
- templateItem.IsEnabled = items[index].IsEnabled;
10305
- items[index] = templateItem;
10306
- }
10307
- else if (addIfMissing) {
10308
- templateItem.IsDefault = true;
10309
- items.push(templateItem);
10310
- }
10311
- }
10312
- (function (ProjectViewLegacyTile) {
10313
- function MergeMapTemplateData(params) {
10314
- var _a;
10340
+ function UpdateAppSettings(params) {
10315
10341
  return __awaiter(this, void 0, void 0, function* () {
10316
- let { getter, sources: items, addIfMissing, req: reqParams } = params;
10317
- if (!getter) {
10318
- getter = exports.ENVIRONMENT.Api().GetBruceGetter();
10319
- }
10320
- const settings = yield getTemplateSettings(getter, reqParams);
10321
- const maps = (_a = settings.CesiumMapSources) !== null && _a !== void 0 ? _a : [];
10322
- for (let i = 0; i < maps.length; i++) {
10323
- const mapSource = maps[i];
10324
- checkSourceToTemplate(items, mapSource, addIfMissing);
10342
+ let { api, accountId: id, appId, settings: data, req: reqParams } = params;
10343
+ if (!api) {
10344
+ api = exports.ENVIRONMENT.Api().GetGuardianApi();
10325
10345
  }
10346
+ const res = yield api.POST(`account/${id}/applicationSettings/${appId}`, data, reqParams);
10347
+ yield api.Cache.RemoveByStartsWith(exports.Api.ECacheKey.Account + exports.Api.ECacheKey.Id + id);
10326
10348
  return {
10327
- sources: items
10349
+ settings: res
10328
10350
  };
10329
10351
  });
10330
10352
  }
10331
- ProjectViewLegacyTile.MergeMapTemplateData = MergeMapTemplateData;
10332
- function MergeTerrainTemplateData(params) {
10333
- var _a;
10353
+ Account.UpdateAppSettings = UpdateAppSettings;
10354
+ /**
10355
+ * Creates a new Nextspace account using given details.
10356
+ * @param params
10357
+ * @returns
10358
+ */
10359
+ function Create(params) {
10334
10360
  return __awaiter(this, void 0, void 0, function* () {
10335
- let { getter, sources: items, addIfMissing, req: reqParams } = params;
10336
- if (!getter) {
10337
- getter = exports.ENVIRONMENT.Api().GetBruceGetter();
10361
+ let { api, accountId: id, name, hostingLocationKey, starterContent, req: reqParams } = params;
10362
+ if (!id || !name || !hostingLocationKey) {
10363
+ throw new Error("Id, Name and hostingLocationKey are required.");
10338
10364
  }
10339
- const settings = yield getTemplateSettings(getter, reqParams);
10340
- const terrains = (_a = settings.CesiumTerrainSources) !== null && _a !== void 0 ? _a : [];
10341
- for (let i = 0; i < terrains.length; i++) {
10342
- const terrainSource = terrains[i];
10343
- checkSourceToTemplate(items, terrainSource, addIfMissing);
10365
+ if (!api) {
10366
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
10344
10367
  }
10345
- return {
10346
- sources: items
10368
+ if (!starterContent) {
10369
+ starterContent = EStarterContent.None;
10370
+ }
10371
+ const reqData = {
10372
+ "Name": name,
10373
+ "HostingLocation.Key": hostingLocationKey,
10374
+ "StarterContent": starterContent
10347
10375
  };
10376
+ const res = yield api.POST(`clientAccount/${id}`, reqData, exports.Api.PrepReqParams(reqParams));
10377
+ const resData = {
10378
+ account: res
10379
+ };
10380
+ api.Cache.Remove(GetListCacheKey(api.GetSessionId()));
10381
+ return resData;
10348
10382
  });
10349
10383
  }
10350
- ProjectViewLegacyTile.MergeTerrainTemplateData = MergeTerrainTemplateData;
10351
- })(exports.ProjectViewLegacyTile || (exports.ProjectViewLegacyTile = {}));
10352
-
10353
- /**
10354
- * A tile is an imagery or terrain tileset definition.
10355
- */
10356
- (function (ProjectViewTile) {
10357
- /**
10358
- * Available imagery defaults.
10359
- */
10360
- let EDefaultImagery;
10361
- (function (EDefaultImagery) {
10362
- EDefaultImagery["BingMapsAerial"] = "bingmapsaerial";
10363
- EDefaultImagery["BingMapsAerialWithLabels"] = "bingmapsaerialwithlabels";
10364
- EDefaultImagery["BingMapsRoads"] = "bingmapsroads";
10365
- EDefaultImagery["MapboxSatellite"] = "mapboxsatellite";
10366
- EDefaultImagery["MapBoxStreets"] = "mapboxstreets";
10367
- EDefaultImagery["MapBoxStreetsClassic"] = "mapboxstreetsclassic";
10368
- EDefaultImagery["EsriWorldImagery"] = "esriworldimagery";
10369
- EDefaultImagery["EsriWorldStreetMap"] = "esriworldstreetmap";
10370
- EDefaultImagery["EsriNationalGeographic"] = "esrinationalgeographic";
10371
- EDefaultImagery["OpenStreetMap"] = "openstreetmap";
10372
- EDefaultImagery["LINZ"] = "linz";
10373
- EDefaultImagery["StamenWaterColor"] = "stamenwatercolor";
10374
- EDefaultImagery["StamenToner"] = "stamentoner";
10375
- EDefaultImagery["Grid"] = "grid";
10376
- EDefaultImagery["ThunderforestCycle"] = "thunderforestcycle";
10377
- EDefaultImagery["ThunderforestTransport"] = "thunderforesttransport";
10378
- EDefaultImagery["ThunderforestLandscape"] = "thunderforestlandscape";
10379
- })(EDefaultImagery = ProjectViewTile.EDefaultImagery || (ProjectViewTile.EDefaultImagery = {}));
10380
- /**
10381
- * Prepared array for UI.
10382
- * TODO: Im not happy with icon urls sitting in the code. I'd prefer we ship these icons in the library as files.
10383
- */
10384
- ProjectViewTile.DefaultImagery = [
10385
- {
10386
- id: EDefaultImagery.BingMapsAerial,
10387
- name: "Bing Maps Aerial",
10388
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/bingAerial.png"
10389
- },
10390
- {
10391
- id: EDefaultImagery.BingMapsAerialWithLabels,
10392
- name: "Bing Maps Aerial with Labels",
10393
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/bingAerialLabels.png"
10394
- },
10395
- {
10396
- id: EDefaultImagery.BingMapsRoads,
10397
- name: "Bing Maps Roads",
10398
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/bingRoads.png"
10399
- },
10400
- {
10401
- id: EDefaultImagery.MapboxSatellite,
10402
- name: "Mapbox Satellite",
10403
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/mapboxSatellite.png"
10404
- },
10405
- {
10406
- id: EDefaultImagery.MapBoxStreets,
10407
- name: "Mapbox Streets",
10408
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/mapboxTerrain.png"
10409
- },
10410
- {
10411
- id: EDefaultImagery.MapBoxStreetsClassic,
10412
- name: "Mapbox Streets Classic",
10413
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/mapboxStreets.png"
10414
- },
10415
- {
10416
- id: EDefaultImagery.EsriWorldImagery,
10417
- name: "Esri World Imagery",
10418
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/esriWorldImagery.png"
10419
- },
10420
- {
10421
- id: EDefaultImagery.EsriWorldStreetMap,
10422
- name: "Esri World Street Map",
10423
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/esriWorldStreetMap.png"
10424
- },
10425
- {
10426
- id: EDefaultImagery.EsriNationalGeographic,
10427
- name: "Esri National Geographic",
10428
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/esriNationalGeographic.png"
10429
- },
10430
- {
10431
- id: EDefaultImagery.OpenStreetMap,
10432
- name: "Open Street Map",
10433
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/openStreetMap.png"
10434
- },
10435
- {
10436
- id: EDefaultImagery.LINZ,
10437
- name: "LINZ",
10438
- iconUrl: "https://template.ui.nextspace.host/media/linz.jpg"
10439
- },
10440
- {
10441
- id: EDefaultImagery.StamenWaterColor,
10442
- name: "Stamen Water Color",
10443
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/stamenWatercolor.png"
10444
- },
10445
- {
10446
- id: EDefaultImagery.StamenToner,
10447
- name: "Stamen Toner",
10448
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/ImageryProviders/stamenToner.png"
10449
- },
10450
- {
10451
- id: EDefaultImagery.ThunderforestCycle,
10452
- name: "Thunderforest Cycle"
10453
- },
10454
- {
10455
- id: EDefaultImagery.ThunderforestTransport,
10456
- name: "Thunderforest Transport"
10457
- },
10458
- {
10459
- id: EDefaultImagery.ThunderforestLandscape,
10460
- name: "Thunderforest Landscape"
10461
- },
10462
- {
10463
- id: EDefaultImagery.Grid,
10464
- name: "Grid",
10465
- iconUrl: "https://template.api.nextspace-uat.net/file/2885d8df-028b-4f5c-80b3-2634f7e7cf69.png"
10466
- }
10467
- ];
10468
- /**
10469
- * Available terrain defaults.
10470
- */
10471
- let EDefaultTerrain;
10472
- (function (EDefaultTerrain) {
10473
- EDefaultTerrain["CesiumWorldTerrain"] = "cesiumworldterrain";
10474
- EDefaultTerrain["FlatTerrain"] = "flatterrain";
10475
- EDefaultTerrain["LINZ"] = "linz";
10476
- })(EDefaultTerrain = ProjectViewTile.EDefaultTerrain || (ProjectViewTile.EDefaultTerrain = {}));
10384
+ Account.Create = Create;
10477
10385
  /**
10478
- * Prepared array for UI.
10479
- * TODO: Im not happy with icon urls sitting in the code. I'd prefer we ship these icons in the library as files.
10386
+ * Returns cache identifier for an account by ID.
10387
+ * Example: {
10388
+ * const api: BruceApi.Api = ...;
10389
+ * const key = GetCacheKey(1);
10390
+ * api.Cache.Remove(key);
10391
+ * }
10392
+ * @param accountId
10393
+ * @param appSettingsId
10394
+ * @returns
10480
10395
  */
10481
- ProjectViewTile.DefaultTerrains = [
10482
- {
10483
- id: EDefaultTerrain.CesiumWorldTerrain,
10484
- name: "Cesium World Terrain",
10485
- iconUrl: "https://template.ui.nextspace.host/Default/media/Cesium/TerrainProviders/CesiumWorldTerrain.png"
10486
- },
10487
- {
10488
- id: EDefaultTerrain.LINZ,
10489
- name: "LINZ",
10490
- iconUrl: "https://template.ui.nextspace.host/media/linz.jpg"
10491
- },
10492
- {
10493
- id: EDefaultTerrain.FlatTerrain,
10494
- name: "Flat Terrain",
10396
+ function GetCacheKey(accountId, appSettingsId) {
10397
+ if (appSettingsId) {
10398
+ return exports.Api.ECacheKey.Account + exports.Api.ECacheKey.Id + accountId + exports.Api.ECacheKey + appSettingsId;
10495
10399
  }
10496
- ];
10497
- })(exports.ProjectViewTile || (exports.ProjectViewTile = {}));
10498
-
10499
- /**
10500
- * Deprecated Project View record.
10501
- * This was used in the legacy web Navigator.
10502
- */
10503
- (function (ProjectViewLegacy) {
10504
- ProjectViewLegacy.DATA_VERSION = 1;
10505
- })(exports.ProjectViewLegacy || (exports.ProjectViewLegacy = {}));
10506
-
10507
- /**
10508
- * Deprecated Project View Bookmark record.
10509
- * This was used in the legacy web Navigator.
10510
- */
10511
- (function (ProjectViewLegacyBookmark) {
10512
- ProjectViewLegacyBookmark.DATA_VERSION = 1;
10513
- })(exports.ProjectViewLegacyBookmark || (exports.ProjectViewLegacyBookmark = {}));
10514
-
10515
- (function (PendingAction) {
10400
+ return exports.Api.ECacheKey.Account + exports.Api.ECacheKey.Id + accountId;
10401
+ }
10402
+ Account.GetCacheKey = GetCacheKey;
10516
10403
  /**
10517
- * Available pending action statuses.
10404
+ * Returns cache identifier for a list of accounts by session ID.
10405
+ * Example: {
10406
+ * const api: BruceApi.Api = ...;
10407
+ * const key = GetListCacheKey(api.GetSessionId());
10408
+ * api.Cache.Remove(key);
10409
+ * }
10410
+ * @param ssid
10411
+ * @returns
10518
10412
  */
10519
- let EStatus;
10520
- (function (EStatus) {
10521
- EStatus["InProgress"] = "IN_PROGRESS";
10522
- EStatus["Cancelled"] = "CANCELLED";
10523
- EStatus["Complete"] = "COMPLETE";
10524
- EStatus["Failed"] = "FAILED";
10525
- })(EStatus = PendingAction.EStatus || (PendingAction.EStatus = {}));
10413
+ function GetListCacheKey(ssid) {
10414
+ return exports.Api.ECacheKey.Account + exports.Api.ECacheKey.Session + exports.Api.ECacheKey.Id + ssid;
10415
+ }
10416
+ Account.GetListCacheKey = GetListCacheKey;
10526
10417
  /**
10527
- * Available message types.
10418
+ * Returns cache identifier for a list of database regions.
10419
+ * Example: {
10420
+ * const api: BruceApi.Api = ...;
10421
+ * const key = GetDbRegionListCacheKey();
10422
+ * api.Cache.Remove(key);
10423
+ * }
10424
+ * @returns
10528
10425
  */
10529
- let EMessageType;
10530
- (function (EMessageType) {
10531
- EMessageType["Warn"] = "WARNING";
10532
- EMessageType["Error"] = "ERROR";
10533
- EMessageType["Status"] = "STATUS";
10534
- EMessageType["Info"] = "INFO";
10535
- })(EMessageType = PendingAction.EMessageType || (PendingAction.EMessageType = {}));
10426
+ function GetDbRegionListCacheKey() {
10427
+ return exports.Api.ECacheKey.DatabaseRegion;
10428
+ }
10429
+ Account.GetDbRegionListCacheKey = GetDbRegionListCacheKey;
10430
+ })(exports.Account || (exports.Account = {}));
10431
+
10432
+ (function (HostingLocation) {
10536
10433
  /**
10537
- * Returns a pending action record.
10434
+ * Returns a list of hosting locations.
10435
+ * @Warning: This will not return the Settings property.
10538
10436
  * @param params
10539
10437
  * @returns
10540
10438
  */
10541
- function Get(params) {
10439
+ function GetList(params) {
10542
10440
  return __awaiter(this, void 0, void 0, function* () {
10543
- let { api, actionId, req: reqParams } = params;
10544
- if (!actionId) {
10545
- throw ("Action ID is required.");
10441
+ let { api, req } = params;
10442
+ if (!api) {
10443
+ api = exports.ENVIRONMENT.Api().GetGuardianApi();
10444
+ }
10445
+ const res = yield api.GET("hostinglocations", exports.Api.PrepReqParams(req));
10446
+ return {
10447
+ locations: res.Items
10448
+ };
10449
+ });
10450
+ }
10451
+ HostingLocation.GetList = GetList;
10452
+ /**
10453
+ * Returns a hosting location record by ID.
10454
+ * @param params
10455
+ * @returns
10456
+ */
10457
+ function GetById(params) {
10458
+ return __awaiter(this, void 0, void 0, function* () {
10459
+ let { id, api, req } = params;
10460
+ if (!id) {
10461
+ throw ("Invalid id");
10546
10462
  }
10547
10463
  if (!api) {
10548
- api = exports.ENVIRONMENT.Api().GetBruceApi();
10464
+ api = exports.ENVIRONMENT.Api().GetGuardianApi();
10549
10465
  }
10550
- const data = yield api.GET(`pendingAction/${actionId}`, exports.Api.PrepReqParams(reqParams));
10466
+ const res = yield api.GET(`hostinglocation/id/${id}`, exports.Api.PrepReqParams(req));
10551
10467
  return {
10552
- action: data
10468
+ location: res
10553
10469
  };
10554
10470
  });
10555
10471
  }
10556
- PendingAction.Get = Get;
10472
+ HostingLocation.GetById = GetById;
10557
10473
  /**
10558
- * Returns a list of pending action records.
10474
+ * Returns a hosting location record by key.
10559
10475
  * @param params
10560
10476
  * @returns
10561
10477
  */
10562
- function GetRelevantList(params) {
10478
+ function GetByKey(params) {
10563
10479
  return __awaiter(this, void 0, void 0, function* () {
10564
- let { api, stricter, reqParams } = params;
10480
+ let { key, api, req } = params;
10481
+ if (!key) {
10482
+ throw ("Invalid key");
10483
+ }
10565
10484
  if (!api) {
10566
- api = exports.ENVIRONMENT.Api().GetBruceApi();
10485
+ api = exports.ENVIRONMENT.Api().GetGuardianApi();
10567
10486
  }
10568
- const data = yield api.GET(`pendingActions/important?Update=${Boolean(stricter)}`, exports.Api.PrepReqParams(reqParams));
10487
+ const res = yield api.GET(`hostinglocation/key/${key}`, exports.Api.PrepReqParams(req));
10569
10488
  return {
10570
- actions: data.Items
10489
+ location: res
10571
10490
  };
10572
10491
  });
10573
10492
  }
10574
- PendingAction.GetRelevantList = GetRelevantList;
10493
+ HostingLocation.GetByKey = GetByKey;
10575
10494
  /**
10576
- * Returns a list of pending action record messages.
10495
+ * Returns hostingLocationKey from given db url.
10496
+ * Some older accounts don't have this set, so we need to guess it.
10577
10497
  * @param params
10578
10498
  * @returns
10579
10499
  */
10580
- function GetMessages(params) {
10500
+ function GuessKey(params) {
10501
+ const { DBServer: databaseUrl } = params;
10502
+ if (databaseUrl.includes("hyperfarm-prod-instance-1")) {
10503
+ return "HYPERFARM";
10504
+ }
10505
+ if (databaseUrl.includes("prod-syd1.nextspace.host")) {
10506
+ return "AU-VULTR-FIRST";
10507
+ }
10508
+ else if (databaseUrl.includes("prod-nyc1.nextspace.host")) {
10509
+ return "US-VULTR-FIRST";
10510
+ }
10511
+ else if (databaseUrl.includes("prod-ams1.nextspace.host")) {
10512
+ return "EU-VULTR-FIRST";
10513
+ }
10514
+ else if (databaseUrl.includes("prod-sing1.nextspace.host")) {
10515
+ return "SE-VULTR-FIRST";
10516
+ }
10517
+ else if (databaseUrl.includes("dev-first")) {
10518
+ return "DEV-FIRST";
10519
+ }
10520
+ else if (databaseUrl.includes(".ap-southeast-1.")) {
10521
+ return "SE";
10522
+ }
10523
+ else if (databaseUrl.includes(".us-west-1.")) {
10524
+ return "US";
10525
+ }
10526
+ else if (databaseUrl.includes(".eu-west-3.")) {
10527
+ return "EU";
10528
+ }
10529
+ else if (databaseUrl.includes("bruce-prod-au")) {
10530
+ return "AU";
10531
+ }
10532
+ else if (databaseUrl.includes("bruce-dev")) {
10533
+ return "DEV";
10534
+ }
10535
+ return null;
10536
+ }
10537
+ HostingLocation.GuessKey = GuessKey;
10538
+ /**
10539
+ * Returns a hosting location key by account ID.
10540
+ * @param params
10541
+ * @returns
10542
+ */
10543
+ function GetKeyByAccountId(params) {
10581
10544
  return __awaiter(this, void 0, void 0, function* () {
10582
- let { api, actionId, order, startIndex, amount, req: reqParams, types } = params;
10545
+ let { accountId, apiSettings, api, account, req } = params;
10546
+ if (!accountId && !apiSettings) {
10547
+ throw ("Invalid accountId or apiSettings");
10548
+ }
10583
10549
  if (!api) {
10584
- api = exports.ENVIRONMENT.Api().GetBruceApi();
10550
+ api = exports.ENVIRONMENT.Api().GetGuardianApi();
10585
10551
  }
10586
- if (amount == null) {
10587
- amount = 500;
10552
+ // We'll prioritize account record if provided.
10553
+ if (accountId && !account) {
10554
+ account = (yield exports.Account.Get({
10555
+ accountId,
10556
+ api,
10557
+ req
10558
+ })).account;
10588
10559
  }
10589
- if (startIndex == null) {
10590
- startIndex = 0;
10560
+ if (account === null || account === void 0 ? void 0 : account["HostingLocation.Key"]) {
10561
+ return {
10562
+ key: account["HostingLocation.Key"],
10563
+ isLegacy: false
10564
+ };
10591
10565
  }
10592
- if (order == null) {
10593
- order = exports.Api.ESortOrder.Asc;
10566
+ // Fallback to settings JSON for older records.
10567
+ const settings = apiSettings ? apiSettings : (yield exports.Account.GetAppSettings({
10568
+ api,
10569
+ accountId,
10570
+ appId: exports.Account.EAppId.BruceApi
10571
+ })).settings;
10572
+ let hostingKey = settings["HostingLocation.Key"];
10573
+ let isLegacy = false;
10574
+ if (!hostingKey) {
10575
+ hostingKey = settings.DBLocation;
10576
+ isLegacy = true;
10594
10577
  }
10595
- let args = `?SortOrder=${order == exports.Api.ESortOrder.Desc ? "DESC" : "ASC"}&PageSize=${amount}&PageIndex=${startIndex}`;
10596
- if (types === null || types === void 0 ? void 0 : types.length) {
10597
- for (let i = 0; i < types.length; i++) {
10598
- args += `&Type=${types[i]}`;
10599
- }
10578
+ if (!hostingKey) {
10579
+ hostingKey = GuessKey({
10580
+ DBServer: settings.DBServer
10581
+ });
10582
+ isLegacy = true;
10600
10583
  }
10601
- const data = yield api.GET(`pendingAction/${actionId}/progressMessages` + args, exports.Api.PrepReqParams(reqParams));
10602
10584
  return {
10603
- messages: data.Items
10585
+ key: hostingKey,
10586
+ isLegacy
10604
10587
  };
10605
10588
  });
10606
10589
  }
10607
- PendingAction.GetMessages = GetMessages;
10590
+ HostingLocation.GetKeyByAccountId = GetKeyByAccountId;
10608
10591
  /**
10609
- * Requests to cancel a pending action.
10592
+ * Returns a hosting location record by account ID.
10610
10593
  * @param params
10594
+ * @returns
10611
10595
  */
10612
- function Cancel(params) {
10596
+ function GetByAccountId(params) {
10613
10597
  return __awaiter(this, void 0, void 0, function* () {
10614
- let { api, actionId, req: reqParams } = params;
10615
- if (!actionId) {
10616
- throw ("Action ID is required.");
10617
- }
10598
+ let { accountId, apiSettings, api, req, account } = params;
10618
10599
  if (!api) {
10619
- api = exports.ENVIRONMENT.Api().GetBruceApi();
10600
+ api = exports.ENVIRONMENT.Api().GetGuardianApi();
10620
10601
  }
10621
- yield api.DELETE(`pendingAction/${actionId}`, exports.Api.PrepReqParams(reqParams));
10602
+ const data = yield GetKeyByAccountId({
10603
+ accountId,
10604
+ account,
10605
+ apiSettings,
10606
+ api,
10607
+ req
10608
+ });
10609
+ if (!(data === null || data === void 0 ? void 0 : data.key)) {
10610
+ return null;
10611
+ }
10612
+ const key = yield GetByKey({
10613
+ key: data.key,
10614
+ api,
10615
+ req
10616
+ });
10617
+ return key;
10622
10618
  });
10623
10619
  }
10624
- PendingAction.Cancel = Cancel;
10625
- })(exports.PendingAction || (exports.PendingAction = {}));
10620
+ HostingLocation.GetByAccountId = GetByAccountId;
10621
+ })(exports.HostingLocation || (exports.HostingLocation = {}));
10626
10622
 
10627
10623
  /**
10628
10624
  * Permissions in Nextspace are arbitrary strings with meaning in specific contexts.
@@ -13080,7 +13076,12 @@
13080
13076
  cacheKey = 0;
13081
13077
  }
13082
13078
  return {
13083
- indexFileUrl: `${api.GetBaseUrl()}ui.plugin/${pluginId}/file/index.jsc?version=${cacheKey}`
13079
+ indexFileUrl: api.ConstructUrl({
13080
+ url: `ui.plugin/${pluginId}/file/index.jsc`,
13081
+ urlParams: {
13082
+ "version": String(cacheKey)
13083
+ }
13084
+ })
13084
13085
  };
13085
13086
  }
13086
13087
  Plugin.GetLoadUrl = GetLoadUrl;
@@ -13462,7 +13463,7 @@
13462
13463
  })(exports.DataSource || (exports.DataSource = {}));
13463
13464
 
13464
13465
  // This is updated with the package.json version on build.
13465
- const VERSION = "4.5.8";
13466
+ const VERSION = "4.5.9";
13466
13467
 
13467
13468
  exports.VERSION = VERSION;
13468
13469
  exports.AbstractApi = AbstractApi;