bruce-models 2.2.9 → 2.3.1

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.
@@ -733,163 +733,6 @@ class AbstractApi {
733
733
  }
734
734
  }
735
735
 
736
- const ACCOUNT_EXCLUSIONS = ["hyperportal", "hypeportal", "bviewer"];
737
- /**
738
- * Describes the "Client Account" concept within Bruce.
739
- * A client account is a database instance that holds one or many users.
740
- */
741
- var Account;
742
- (function (Account) {
743
- function GetCacheKey(accountId, appSettingsId) {
744
- if (appSettingsId) {
745
- return Api.ECacheKey.Account + Api.ECacheKey.Id + accountId + Api.ECacheKey + appSettingsId;
746
- }
747
- return Api.ECacheKey.Account + Api.ECacheKey.Id + accountId;
748
- }
749
- Account.GetCacheKey = GetCacheKey;
750
- function GetListCacheKey(ssid) {
751
- return Api.ECacheKey.Account + Api.ECacheKey.Session + Api.ECacheKey.Id + ssid;
752
- }
753
- Account.GetListCacheKey = GetListCacheKey;
754
- function GetDbRegionListCacheKey() {
755
- return Api.ECacheKey.DatabaseRegion;
756
- }
757
- Account.GetDbRegionListCacheKey = GetDbRegionListCacheKey;
758
- let EAppId;
759
- (function (EAppId) {
760
- EAppId["BruceApi"] = "BruceAPI";
761
- EAppId["Navigator"] = "Navigator";
762
- })(EAppId = Account.EAppId || (Account.EAppId = {}));
763
- let EStarterContent;
764
- (function (EStarterContent) {
765
- EStarterContent["Default"] = "default";
766
- EStarterContent["None"] = "none";
767
- })(EStarterContent = Account.EStarterContent || (Account.EStarterContent = {}));
768
- function Get(params) {
769
- return __awaiter(this, void 0, void 0, function* () {
770
- const { api, accountId: id, req: reqParams } = params;
771
- const cacheData = yield api.GetCacheItem(GetCacheKey(id), reqParams);
772
- if (cacheData) {
773
- return cacheData;
774
- }
775
- const req = yield api.GET(`account/${id}`, reqParams);
776
- const resData = {
777
- account: req
778
- };
779
- yield api.SetCacheItem({
780
- key: GetCacheKey(id),
781
- value: resData,
782
- req: reqParams
783
- });
784
- return resData;
785
- });
786
- }
787
- Account.Get = Get;
788
- function GetRelatedList(params) {
789
- return __awaiter(this, void 0, void 0, function* () {
790
- const { api, req: reqParams } = params;
791
- const cacheData = yield api.GetCacheItem(GetListCacheKey(api.GetSessionId()), reqParams);
792
- if (cacheData) {
793
- return cacheData;
794
- }
795
- const req = api.GET("user/relatedClientAccounts", reqParams);
796
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
797
- try {
798
- const data = yield req;
799
- const items = data.Items.filter((x) => !ACCOUNT_EXCLUSIONS.includes(x.ID));
800
- res({
801
- accounts: items
802
- });
803
- }
804
- catch (e) {
805
- rej(e);
806
- }
807
- }));
808
- yield api.SetCacheItem({
809
- key: GetListCacheKey(api.GetSessionId()),
810
- value: prom,
811
- req: reqParams
812
- });
813
- return prom;
814
- });
815
- }
816
- Account.GetRelatedList = GetRelatedList;
817
- function GetAppSettings(params) {
818
- return __awaiter(this, void 0, void 0, function* () {
819
- const { api, accountId: id, appId, req: reqParams } = params;
820
- const cacheData = yield api.GetCacheItem(GetCacheKey(id, appId), reqParams);
821
- if (cacheData) {
822
- return cacheData;
823
- }
824
- const req = yield api.GET(`account/${id}?ApplicationID=${appId}`, reqParams);
825
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
826
- var _a;
827
- try {
828
- const data = yield req;
829
- const settings = (_a = data === null || data === void 0 ? void 0 : data["Application.Settings"]) !== null && _a !== void 0 ? _a : {};
830
- res({
831
- settings: settings
832
- });
833
- }
834
- catch (e) {
835
- rej(e);
836
- }
837
- }));
838
- yield api.SetCacheItem({
839
- key: GetCacheKey(id, appId),
840
- value: prom,
841
- req: reqParams
842
- });
843
- return prom;
844
- });
845
- }
846
- Account.GetAppSettings = GetAppSettings;
847
- /**
848
- * WARNING: Do not update API settings without knowing what you're doing.
849
- * @param params
850
- * @returns
851
- */
852
- function UpdateAppSettings(params) {
853
- return __awaiter(this, void 0, void 0, function* () {
854
- const { api, accountId: id, appId, settings: data, req: reqParams } = params;
855
- const res = yield api.POST(`account/${id}/applicationSettings/${appId}`, data, reqParams);
856
- yield api.Cache.RemoveByStartsWith(Api.ECacheKey.Account + Api.ECacheKey.Id + id);
857
- return {
858
- settings: res
859
- };
860
- });
861
- }
862
- Account.UpdateAppSettings = UpdateAppSettings;
863
- /**
864
- * Creates a new Bruce account using given details.
865
- * @param params
866
- * @returns
867
- */
868
- function Create(params) {
869
- return __awaiter(this, void 0, void 0, function* () {
870
- let { api, accountId: id, name, hostingLocationKey, starterContent, req: reqParams } = params;
871
- if (!id || !name || !hostingLocationKey) {
872
- throw new Error("Id, Name and hostingLocationKey are required.");
873
- }
874
- if (!starterContent) {
875
- starterContent = EStarterContent.None;
876
- }
877
- const reqData = {
878
- "Name": name,
879
- "HostingLocation.Key": hostingLocationKey,
880
- "StarterContent": starterContent
881
- };
882
- const res = yield api.POST(`clientAccount/${id}`, reqData, Api.PrepReqParams(reqParams));
883
- const resData = {
884
- account: res
885
- };
886
- api.Cache.Remove(GetListCacheKey(api.GetSessionId()));
887
- return resData;
888
- });
889
- }
890
- Account.Create = Create;
891
- })(Account || (Account = {}));
892
-
893
736
  var MessageBroker;
894
737
  (function (MessageBroker) {
895
738
  let EAction;
@@ -1098,6 +941,163 @@ var GuardianApi;
1098
941
  GuardianApi.Api = Api$$1;
1099
942
  })(GuardianApi || (GuardianApi = {}));
1100
943
 
944
+ const ACCOUNT_EXCLUSIONS = ["hyperportal", "hypeportal", "bviewer"];
945
+ /**
946
+ * Describes the "Client Account" concept within Bruce.
947
+ * A client account is a database instance that holds one or many users.
948
+ */
949
+ var Account;
950
+ (function (Account) {
951
+ function GetCacheKey(accountId, appSettingsId) {
952
+ if (appSettingsId) {
953
+ return Api.ECacheKey.Account + Api.ECacheKey.Id + accountId + Api.ECacheKey + appSettingsId;
954
+ }
955
+ return Api.ECacheKey.Account + Api.ECacheKey.Id + accountId;
956
+ }
957
+ Account.GetCacheKey = GetCacheKey;
958
+ function GetListCacheKey(ssid) {
959
+ return Api.ECacheKey.Account + Api.ECacheKey.Session + Api.ECacheKey.Id + ssid;
960
+ }
961
+ Account.GetListCacheKey = GetListCacheKey;
962
+ function GetDbRegionListCacheKey() {
963
+ return Api.ECacheKey.DatabaseRegion;
964
+ }
965
+ Account.GetDbRegionListCacheKey = GetDbRegionListCacheKey;
966
+ let EAppId;
967
+ (function (EAppId) {
968
+ EAppId["BruceApi"] = "BruceAPI";
969
+ EAppId["Navigator"] = "Navigator";
970
+ })(EAppId = Account.EAppId || (Account.EAppId = {}));
971
+ let EStarterContent;
972
+ (function (EStarterContent) {
973
+ EStarterContent["Default"] = "default";
974
+ EStarterContent["None"] = "none";
975
+ })(EStarterContent = Account.EStarterContent || (Account.EStarterContent = {}));
976
+ function Get(params) {
977
+ return __awaiter(this, void 0, void 0, function* () {
978
+ const { api, accountId: id, req: reqParams } = params;
979
+ const cacheData = yield api.GetCacheItem(GetCacheKey(id), reqParams);
980
+ if (cacheData) {
981
+ return cacheData;
982
+ }
983
+ const req = yield api.GET(`account/${id}`, reqParams);
984
+ const resData = {
985
+ account: req
986
+ };
987
+ yield api.SetCacheItem({
988
+ key: GetCacheKey(id),
989
+ value: resData,
990
+ req: reqParams
991
+ });
992
+ return resData;
993
+ });
994
+ }
995
+ Account.Get = Get;
996
+ function GetRelatedList(params) {
997
+ return __awaiter(this, void 0, void 0, function* () {
998
+ const { api, req: reqParams } = params;
999
+ const cacheData = yield api.GetCacheItem(GetListCacheKey(api.GetSessionId()), reqParams);
1000
+ if (cacheData) {
1001
+ return cacheData;
1002
+ }
1003
+ const req = api.GET("user/relatedClientAccounts", reqParams);
1004
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
1005
+ try {
1006
+ const data = yield req;
1007
+ const items = data.Items.filter((x) => !ACCOUNT_EXCLUSIONS.includes(x.ID));
1008
+ res({
1009
+ accounts: items
1010
+ });
1011
+ }
1012
+ catch (e) {
1013
+ rej(e);
1014
+ }
1015
+ }));
1016
+ yield api.SetCacheItem({
1017
+ key: GetListCacheKey(api.GetSessionId()),
1018
+ value: prom,
1019
+ req: reqParams
1020
+ });
1021
+ return prom;
1022
+ });
1023
+ }
1024
+ Account.GetRelatedList = GetRelatedList;
1025
+ function GetAppSettings(params) {
1026
+ return __awaiter(this, void 0, void 0, function* () {
1027
+ const { api, accountId: id, appId, req: reqParams } = params;
1028
+ const cacheData = yield api.GetCacheItem(GetCacheKey(id, appId), reqParams);
1029
+ if (cacheData) {
1030
+ return cacheData;
1031
+ }
1032
+ const req = yield api.GET(`account/${id}?ApplicationID=${appId}`, reqParams);
1033
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
1034
+ var _a;
1035
+ try {
1036
+ const data = yield req;
1037
+ const settings = (_a = data === null || data === void 0 ? void 0 : data["Application.Settings"]) !== null && _a !== void 0 ? _a : {};
1038
+ res({
1039
+ settings: settings
1040
+ });
1041
+ }
1042
+ catch (e) {
1043
+ rej(e);
1044
+ }
1045
+ }));
1046
+ yield api.SetCacheItem({
1047
+ key: GetCacheKey(id, appId),
1048
+ value: prom,
1049
+ req: reqParams
1050
+ });
1051
+ return prom;
1052
+ });
1053
+ }
1054
+ Account.GetAppSettings = GetAppSettings;
1055
+ /**
1056
+ * WARNING: Do not update API settings without knowing what you're doing.
1057
+ * @param params
1058
+ * @returns
1059
+ */
1060
+ function UpdateAppSettings(params) {
1061
+ return __awaiter(this, void 0, void 0, function* () {
1062
+ const { api, accountId: id, appId, settings: data, req: reqParams } = params;
1063
+ const res = yield api.POST(`account/${id}/applicationSettings/${appId}`, data, reqParams);
1064
+ yield api.Cache.RemoveByStartsWith(Api.ECacheKey.Account + Api.ECacheKey.Id + id);
1065
+ return {
1066
+ settings: res
1067
+ };
1068
+ });
1069
+ }
1070
+ Account.UpdateAppSettings = UpdateAppSettings;
1071
+ /**
1072
+ * Creates a new Bruce account using given details.
1073
+ * @param params
1074
+ * @returns
1075
+ */
1076
+ function Create(params) {
1077
+ return __awaiter(this, void 0, void 0, function* () {
1078
+ let { api, accountId: id, name, hostingLocationKey, starterContent, req: reqParams } = params;
1079
+ if (!id || !name || !hostingLocationKey) {
1080
+ throw new Error("Id, Name and hostingLocationKey are required.");
1081
+ }
1082
+ if (!starterContent) {
1083
+ starterContent = EStarterContent.None;
1084
+ }
1085
+ const reqData = {
1086
+ "Name": name,
1087
+ "HostingLocation.Key": hostingLocationKey,
1088
+ "StarterContent": starterContent
1089
+ };
1090
+ const res = yield api.POST(`clientAccount/${id}`, reqData, Api.PrepReqParams(reqParams));
1091
+ const resData = {
1092
+ account: res
1093
+ };
1094
+ api.Cache.Remove(GetListCacheKey(api.GetSessionId()));
1095
+ return resData;
1096
+ });
1097
+ }
1098
+ Account.Create = Create;
1099
+ })(Account || (Account = {}));
1100
+
1101
1101
  /**
1102
1102
  * A hosting location is a record for a possible bruce-api server configuration.
1103
1103
  * A hosting location will have one or many database servers as well, this is an additional setting.
@@ -1188,7 +1188,7 @@ var HostingLocation;
1188
1188
  return null;
1189
1189
  }
1190
1190
  HostingLocation.GuessKey = GuessKey;
1191
- function GetByAccountId(params) {
1191
+ function GetKeyByAccountId(params) {
1192
1192
  return __awaiter(this, void 0, void 0, function* () {
1193
1193
  const { accountId, apiSettings, api, req } = params;
1194
1194
  if (!accountId && !apiSettings) {
@@ -1200,23 +1200,42 @@ var HostingLocation;
1200
1200
  appId: Account.EAppId.BruceApi
1201
1201
  })).settings;
1202
1202
  let hostingKey = settings["HostingLocation.Key"];
1203
+ let isLegacy = false;
1203
1204
  if (!hostingKey) {
1204
1205
  hostingKey = settings.DBLocation;
1206
+ isLegacy = true;
1205
1207
  }
1206
1208
  if (!hostingKey) {
1207
1209
  hostingKey = GuessKey({
1208
1210
  DBServer: settings.DBServer
1209
1211
  });
1212
+ isLegacy = true;
1210
1213
  }
1211
- if (!hostingKey) {
1214
+ return {
1215
+ key: hostingKey,
1216
+ isLegacy
1217
+ };
1218
+ });
1219
+ }
1220
+ HostingLocation.GetKeyByAccountId = GetKeyByAccountId;
1221
+ function GetByAccountId(params) {
1222
+ return __awaiter(this, void 0, void 0, function* () {
1223
+ const { accountId, apiSettings, api, req } = params;
1224
+ const data = yield GetKeyByAccountId({
1225
+ accountId,
1226
+ apiSettings,
1227
+ api,
1228
+ req
1229
+ });
1230
+ if (!(data === null || data === void 0 ? void 0 : data.key)) {
1212
1231
  return null;
1213
1232
  }
1214
- const data = yield GetByKey({
1215
- key: hostingKey,
1233
+ const key = yield GetByKey({
1234
+ key: data.key,
1216
1235
  api,
1217
1236
  req
1218
1237
  });
1219
- return data;
1238
+ return key;
1220
1239
  });
1221
1240
  }
1222
1241
  HostingLocation.GetByAccountId = GetByAccountId;
@@ -1266,70 +1285,60 @@ var BruceApi;
1266
1285
  * @returns
1267
1286
  */
1268
1287
  init(guardian, loadConfig) {
1269
- var _a, _b, _c, _d;
1288
+ var _a, _b;
1270
1289
  return __awaiter(this, void 0, void 0, function* () {
1271
1290
  if (!this.accountId) {
1272
1291
  throw ("accountId is required.");
1273
1292
  }
1274
- // Set using a stable default.
1275
- const prefix = `https://${this.accountId}.api.nextspace`;
1276
- let url;
1277
1293
  const env = this.env.toUpperCase();
1294
+ let domain = "nextspace.host";
1278
1295
  switch (env) {
1279
1296
  case Api.EEnv.DEV:
1280
- url = prefix + "-dev.net/";
1297
+ domain = "nextspace-dev.net";
1281
1298
  break;
1282
1299
  case Api.EEnv.STG:
1283
- url = prefix + "-stg.net/";
1300
+ domain = "nextspace-stg.net";
1284
1301
  break;
1285
1302
  case Api.EEnv.UAT:
1286
- url = prefix + "-uat.net/";
1303
+ domain = "nextspace-uat.net";
1287
1304
  break;
1288
1305
  case Api.EEnv.PROD:
1289
- url = prefix + ".host/";
1306
+ domain = "nextspace.host";
1290
1307
  break;
1291
1308
  default:
1292
- throw ("Specified Environment is not valid. SuppliedEnv=" + env);
1309
+ console.error("Specified Environment is not valid. SuppliedEnv=" + env);
1293
1310
  }
1294
- this.baseUrl = url;
1311
+ // Set using a stable default.
1312
+ this.baseUrl = `https://${this.accountId}.api.${domain}/`;
1295
1313
  if (guardian && loadConfig) {
1296
- // Attempt to load an account specific base url.
1297
- // This could be one with a region specific endpoint.
1298
1314
  try {
1299
- const settings = (yield Account.GetAppSettings({
1300
- api: guardian,
1301
- accountId: this.accountId,
1302
- appId: Account.EAppId.BruceApi
1303
- })).settings;
1304
- if (this.loadCancelled) {
1305
- console.warn("BruceApi: Loading was cancelled due to SetBaseUrl being called, not setting regional base url.");
1306
- return;
1307
- }
1308
- let endpoint = (_a = settings.BruceAPIURL) === null || _a === void 0 ? void 0 : _a[env];
1309
- if (typeof endpoint == "string") {
1310
- if (!endpoint.endsWith("/")) {
1311
- endpoint += "/";
1312
- }
1313
- this.baseUrl = endpoint;
1314
- }
1315
1315
  const host = yield HostingLocation.GetByAccountId({
1316
1316
  accountId: this.accountId,
1317
- apiSettings: settings,
1318
1317
  api: guardian
1319
1318
  });
1320
- const hostSettings = (_b = host === null || host === void 0 ? void 0 : host.location) === null || _b === void 0 ? void 0 : _b.Settings;
1321
- if (hostSettings === null || hostSettings === void 0 ? void 0 : hostSettings.CDN) {
1322
- this.EntityCdnUrl = (_c = hostSettings.CDN.entityURL) === null || _c === void 0 ? void 0 : _c[env];
1323
- // We need to fix our configs.
1324
- if (this.EntityCdnUrl) {
1325
- if (this.EntityCdnUrl.includes("entitiesListForCDN")) {
1326
- this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", this.accountId);
1319
+ if (host === null || host === void 0 ? void 0 : host.location) {
1320
+ // Attempt to load regional base url.
1321
+ if (host.location.BruceAPIURL) {
1322
+ const regionalUrl = host.location.BruceAPIURL.replace("<ACCOUNT>", this.accountId).replace("<DOMAIN>", domain);
1323
+ if (regionalUrl && regionalUrl.length > 1) {
1324
+ this.baseUrl = regionalUrl;
1327
1325
  }
1328
- else {
1329
- this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", "entitiesListForCDN/" + this.accountId);
1326
+ }
1327
+ // Attempt to load CDN settings.
1328
+ const settings = host.location.Settings;
1329
+ if (settings === null || settings === void 0 ? void 0 : settings.CDN) {
1330
+ this.EntityCdnUrl = (_a = settings.CDN.entityURL) === null || _a === void 0 ? void 0 : _a[env];
1331
+ // We need to fix our configs.
1332
+ if (this.EntityCdnUrl) {
1333
+ if (this.EntityCdnUrl.includes("entitiesListForCDN")) {
1334
+ this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", this.accountId);
1335
+ }
1336
+ else {
1337
+ this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", "entitiesListForCDN/" + this.accountId);
1338
+ }
1330
1339
  }
1340
+ this.LegacyTilesetCdnUrl = (_b = settings.CDN.legacyTilesetURL) === null || _b === void 0 ? void 0 : _b[env];
1331
1341
  }
1332
- this.LegacyTilesetCdnUrl = (_d = hostSettings.CDN.legacyTilesetURL) === null || _d === void 0 ? void 0 : _d[env];
1333
1342
  }
1334
1343
  }
1335
1344
  catch (e) {