bruce-models 2.3.0 → 2.3.2

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.
@@ -1285,70 +1285,80 @@ var BruceApi;
1285
1285
  * @returns
1286
1286
  */
1287
1287
  init(guardian, loadConfig) {
1288
- var _a, _b, _c, _d;
1288
+ var _a, _b;
1289
1289
  return __awaiter(this, void 0, void 0, function* () {
1290
1290
  if (!this.accountId) {
1291
1291
  throw ("accountId is required.");
1292
1292
  }
1293
- // Set using a stable default.
1294
- const prefix = `https://${this.accountId}.api.nextspace`;
1295
- let url;
1296
1293
  const env = this.env.toUpperCase();
1294
+ let domain = "nextspace.host";
1297
1295
  switch (env) {
1298
1296
  case Api.EEnv.DEV:
1299
- url = prefix + "-dev.net/";
1297
+ domain = "nextspace-dev.net";
1300
1298
  break;
1301
1299
  case Api.EEnv.STG:
1302
- url = prefix + "-stg.net/";
1300
+ domain = "nextspace-stg.net";
1303
1301
  break;
1304
1302
  case Api.EEnv.UAT:
1305
- url = prefix + "-uat.net/";
1303
+ domain = "nextspace-uat.net";
1306
1304
  break;
1307
1305
  case Api.EEnv.PROD:
1308
- url = prefix + ".host/";
1306
+ domain = "nextspace.host";
1309
1307
  break;
1310
1308
  default:
1311
- throw ("Specified Environment is not valid. SuppliedEnv=" + env);
1309
+ console.error("Specified Environment is not valid. SuppliedEnv=" + env);
1312
1310
  }
1313
- this.baseUrl = url;
1311
+ // Set using a stable default.
1312
+ this.baseUrl = `https://${this.accountId}.api.${domain}/`;
1314
1313
  if (guardian && loadConfig) {
1315
- // Attempt to load an account specific base url.
1316
- // This could be one with a region specific endpoint.
1317
1314
  try {
1318
- const settings = (yield Account.GetAppSettings({
1319
- api: guardian,
1320
- accountId: this.accountId,
1321
- appId: Account.EAppId.BruceApi
1322
- })).settings;
1323
- if (this.loadCancelled) {
1324
- console.warn("BruceApi: Loading was cancelled due to SetBaseUrl being called, not setting regional base url.");
1325
- return;
1326
- }
1327
- let endpoint = (_a = settings.BruceAPIURL) === null || _a === void 0 ? void 0 : _a[env];
1328
- if (typeof endpoint == "string") {
1329
- if (!endpoint.endsWith("/")) {
1330
- endpoint += "/";
1331
- }
1332
- this.baseUrl = endpoint;
1333
- }
1334
1315
  const host = yield HostingLocation.GetByAccountId({
1335
1316
  accountId: this.accountId,
1336
- apiSettings: settings,
1337
1317
  api: guardian
1338
1318
  });
1339
- const hostSettings = (_b = host === null || host === void 0 ? void 0 : host.location) === null || _b === void 0 ? void 0 : _b.Settings;
1340
- if (hostSettings === null || hostSettings === void 0 ? void 0 : hostSettings.CDN) {
1341
- this.EntityCdnUrl = (_c = hostSettings.CDN.entityURL) === null || _c === void 0 ? void 0 : _c[env];
1342
- // We need to fix our configs.
1343
- if (this.EntityCdnUrl) {
1344
- if (this.EntityCdnUrl.includes("entitiesListForCDN")) {
1345
- this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", this.accountId);
1319
+ if (host === null || host === void 0 ? void 0 : host.location) {
1320
+ const settings = host.location.Settings;
1321
+ // Attempt to load regional base url.
1322
+ // First try go through settings.
1323
+ let urlSet = false;
1324
+ if (settings === null || settings === void 0 ? void 0 : settings.BruceAPIURL) {
1325
+ let envUrl = settings.BruceAPIURL[env];
1326
+ if (envUrl) {
1327
+ envUrl = envUrl
1328
+ .replace("<ACCOUNTID>", this.accountId)
1329
+ .replace("<ACCOUNT>", this.accountId);
1330
+ if (envUrl && envUrl.length > 1) {
1331
+ this.baseUrl = envUrl;
1332
+ urlSet = true;
1333
+ }
1346
1334
  }
1347
- else {
1348
- this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", "entitiesListForCDN/" + this.accountId);
1335
+ }
1336
+ // Try go through host location's base url.
1337
+ // This may be wrong env which is why it's used as fallback right now.
1338
+ if (!urlSet && host.location.BruceAPIURL) {
1339
+ const regionalUrl = host.location.BruceAPIURL
1340
+ .replace("<ACCOUNTID>", this.accountId)
1341
+ .replace("<ACCOUNT>", this.accountId)
1342
+ .replace("<DOMAIN>", domain);
1343
+ if (regionalUrl && regionalUrl.length > 1) {
1344
+ this.baseUrl = regionalUrl;
1345
+ urlSet = true;
1346
+ }
1347
+ }
1348
+ // Attempt to load CDN settings.
1349
+ if (settings === null || settings === void 0 ? void 0 : settings.CDN) {
1350
+ this.EntityCdnUrl = (_a = settings.CDN.entityURL) === null || _a === void 0 ? void 0 : _a[env];
1351
+ // We need to fix our configs.
1352
+ if (this.EntityCdnUrl) {
1353
+ if (this.EntityCdnUrl.includes("entitiesListForCDN")) {
1354
+ this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", this.accountId);
1355
+ }
1356
+ else {
1357
+ this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", "entitiesListForCDN/" + this.accountId);
1358
+ }
1349
1359
  }
1360
+ this.LegacyTilesetCdnUrl = (_b = settings.CDN.legacyTilesetURL) === null || _b === void 0 ? void 0 : _b[env];
1350
1361
  }
1351
- this.LegacyTilesetCdnUrl = (_d = hostSettings.CDN.legacyTilesetURL) === null || _d === void 0 ? void 0 : _d[env];
1352
1362
  }
1353
1363
  }
1354
1364
  catch (e) {