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.
@@ -727,158 +727,6 @@
727
727
  }
728
728
  }
729
729
 
730
- const ACCOUNT_EXCLUSIONS = ["hyperportal", "hypeportal", "bviewer"];
731
- (function (Account) {
732
- function GetCacheKey(accountId, appSettingsId) {
733
- if (appSettingsId) {
734
- return exports.Api.ECacheKey.Account + exports.Api.ECacheKey.Id + accountId + exports.Api.ECacheKey + appSettingsId;
735
- }
736
- return exports.Api.ECacheKey.Account + exports.Api.ECacheKey.Id + accountId;
737
- }
738
- Account.GetCacheKey = GetCacheKey;
739
- function GetListCacheKey(ssid) {
740
- return exports.Api.ECacheKey.Account + exports.Api.ECacheKey.Session + exports.Api.ECacheKey.Id + ssid;
741
- }
742
- Account.GetListCacheKey = GetListCacheKey;
743
- function GetDbRegionListCacheKey() {
744
- return exports.Api.ECacheKey.DatabaseRegion;
745
- }
746
- Account.GetDbRegionListCacheKey = GetDbRegionListCacheKey;
747
- let EAppId;
748
- (function (EAppId) {
749
- EAppId["BruceApi"] = "BruceAPI";
750
- EAppId["Navigator"] = "Navigator";
751
- })(EAppId = Account.EAppId || (Account.EAppId = {}));
752
- let EStarterContent;
753
- (function (EStarterContent) {
754
- EStarterContent["Default"] = "default";
755
- EStarterContent["None"] = "none";
756
- })(EStarterContent = Account.EStarterContent || (Account.EStarterContent = {}));
757
- function Get(params) {
758
- return __awaiter(this, void 0, void 0, function* () {
759
- const { api, accountId: id, req: reqParams } = params;
760
- const cacheData = yield api.GetCacheItem(GetCacheKey(id), reqParams);
761
- if (cacheData) {
762
- return cacheData;
763
- }
764
- const req = yield api.GET(`account/${id}`, reqParams);
765
- const resData = {
766
- account: req
767
- };
768
- yield api.SetCacheItem({
769
- key: GetCacheKey(id),
770
- value: resData,
771
- req: reqParams
772
- });
773
- return resData;
774
- });
775
- }
776
- Account.Get = Get;
777
- function GetRelatedList(params) {
778
- return __awaiter(this, void 0, void 0, function* () {
779
- const { api, req: reqParams } = params;
780
- const cacheData = yield api.GetCacheItem(GetListCacheKey(api.GetSessionId()), reqParams);
781
- if (cacheData) {
782
- return cacheData;
783
- }
784
- const req = api.GET("user/relatedClientAccounts", reqParams);
785
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
786
- try {
787
- const data = yield req;
788
- const items = data.Items.filter((x) => !ACCOUNT_EXCLUSIONS.includes(x.ID));
789
- res({
790
- accounts: items
791
- });
792
- }
793
- catch (e) {
794
- rej(e);
795
- }
796
- }));
797
- yield api.SetCacheItem({
798
- key: GetListCacheKey(api.GetSessionId()),
799
- value: prom,
800
- req: reqParams
801
- });
802
- return prom;
803
- });
804
- }
805
- Account.GetRelatedList = GetRelatedList;
806
- function GetAppSettings(params) {
807
- return __awaiter(this, void 0, void 0, function* () {
808
- const { api, accountId: id, appId, req: reqParams } = params;
809
- const cacheData = yield api.GetCacheItem(GetCacheKey(id, appId), reqParams);
810
- if (cacheData) {
811
- return cacheData;
812
- }
813
- const req = yield api.GET(`account/${id}?ApplicationID=${appId}`, reqParams);
814
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
815
- var _a;
816
- try {
817
- const data = yield req;
818
- const settings = (_a = data === null || data === void 0 ? void 0 : data["Application.Settings"]) !== null && _a !== void 0 ? _a : {};
819
- res({
820
- settings: settings
821
- });
822
- }
823
- catch (e) {
824
- rej(e);
825
- }
826
- }));
827
- yield api.SetCacheItem({
828
- key: GetCacheKey(id, appId),
829
- value: prom,
830
- req: reqParams
831
- });
832
- return prom;
833
- });
834
- }
835
- Account.GetAppSettings = GetAppSettings;
836
- /**
837
- * WARNING: Do not update API settings without knowing what you're doing.
838
- * @param params
839
- * @returns
840
- */
841
- function UpdateAppSettings(params) {
842
- return __awaiter(this, void 0, void 0, function* () {
843
- const { api, accountId: id, appId, settings: data, req: reqParams } = params;
844
- const res = yield api.POST(`account/${id}/applicationSettings/${appId}`, data, reqParams);
845
- yield api.Cache.RemoveByStartsWith(exports.Api.ECacheKey.Account + exports.Api.ECacheKey.Id + id);
846
- return {
847
- settings: res
848
- };
849
- });
850
- }
851
- Account.UpdateAppSettings = UpdateAppSettings;
852
- /**
853
- * Creates a new Bruce account using given details.
854
- * @param params
855
- * @returns
856
- */
857
- function Create(params) {
858
- return __awaiter(this, void 0, void 0, function* () {
859
- let { api, accountId: id, name, hostingLocationKey, starterContent, req: reqParams } = params;
860
- if (!id || !name || !hostingLocationKey) {
861
- throw new Error("Id, Name and hostingLocationKey are required.");
862
- }
863
- if (!starterContent) {
864
- starterContent = EStarterContent.None;
865
- }
866
- const reqData = {
867
- "Name": name,
868
- "HostingLocation.Key": hostingLocationKey,
869
- "StarterContent": starterContent
870
- };
871
- const res = yield api.POST(`clientAccount/${id}`, reqData, exports.Api.PrepReqParams(reqParams));
872
- const resData = {
873
- account: res
874
- };
875
- api.Cache.Remove(GetListCacheKey(api.GetSessionId()));
876
- return resData;
877
- });
878
- }
879
- Account.Create = Create;
880
- })(exports.Account || (exports.Account = {}));
881
-
882
730
  (function (MessageBroker) {
883
731
  let EAction;
884
732
  (function (EAction) {
@@ -1081,6 +929,158 @@
1081
929
  GuardianApi.Api = Api$$1;
1082
930
  })(exports.GuardianApi || (exports.GuardianApi = {}));
1083
931
 
932
+ const ACCOUNT_EXCLUSIONS = ["hyperportal", "hypeportal", "bviewer"];
933
+ (function (Account) {
934
+ function GetCacheKey(accountId, appSettingsId) {
935
+ if (appSettingsId) {
936
+ return exports.Api.ECacheKey.Account + exports.Api.ECacheKey.Id + accountId + exports.Api.ECacheKey + appSettingsId;
937
+ }
938
+ return exports.Api.ECacheKey.Account + exports.Api.ECacheKey.Id + accountId;
939
+ }
940
+ Account.GetCacheKey = GetCacheKey;
941
+ function GetListCacheKey(ssid) {
942
+ return exports.Api.ECacheKey.Account + exports.Api.ECacheKey.Session + exports.Api.ECacheKey.Id + ssid;
943
+ }
944
+ Account.GetListCacheKey = GetListCacheKey;
945
+ function GetDbRegionListCacheKey() {
946
+ return exports.Api.ECacheKey.DatabaseRegion;
947
+ }
948
+ Account.GetDbRegionListCacheKey = GetDbRegionListCacheKey;
949
+ let EAppId;
950
+ (function (EAppId) {
951
+ EAppId["BruceApi"] = "BruceAPI";
952
+ EAppId["Navigator"] = "Navigator";
953
+ })(EAppId = Account.EAppId || (Account.EAppId = {}));
954
+ let EStarterContent;
955
+ (function (EStarterContent) {
956
+ EStarterContent["Default"] = "default";
957
+ EStarterContent["None"] = "none";
958
+ })(EStarterContent = Account.EStarterContent || (Account.EStarterContent = {}));
959
+ function Get(params) {
960
+ return __awaiter(this, void 0, void 0, function* () {
961
+ const { api, accountId: id, req: reqParams } = params;
962
+ const cacheData = yield api.GetCacheItem(GetCacheKey(id), reqParams);
963
+ if (cacheData) {
964
+ return cacheData;
965
+ }
966
+ const req = yield api.GET(`account/${id}`, reqParams);
967
+ const resData = {
968
+ account: req
969
+ };
970
+ yield api.SetCacheItem({
971
+ key: GetCacheKey(id),
972
+ value: resData,
973
+ req: reqParams
974
+ });
975
+ return resData;
976
+ });
977
+ }
978
+ Account.Get = Get;
979
+ function GetRelatedList(params) {
980
+ return __awaiter(this, void 0, void 0, function* () {
981
+ const { api, req: reqParams } = params;
982
+ const cacheData = yield api.GetCacheItem(GetListCacheKey(api.GetSessionId()), reqParams);
983
+ if (cacheData) {
984
+ return cacheData;
985
+ }
986
+ const req = api.GET("user/relatedClientAccounts", reqParams);
987
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
988
+ try {
989
+ const data = yield req;
990
+ const items = data.Items.filter((x) => !ACCOUNT_EXCLUSIONS.includes(x.ID));
991
+ res({
992
+ accounts: items
993
+ });
994
+ }
995
+ catch (e) {
996
+ rej(e);
997
+ }
998
+ }));
999
+ yield api.SetCacheItem({
1000
+ key: GetListCacheKey(api.GetSessionId()),
1001
+ value: prom,
1002
+ req: reqParams
1003
+ });
1004
+ return prom;
1005
+ });
1006
+ }
1007
+ Account.GetRelatedList = GetRelatedList;
1008
+ function GetAppSettings(params) {
1009
+ return __awaiter(this, void 0, void 0, function* () {
1010
+ const { api, accountId: id, appId, req: reqParams } = params;
1011
+ const cacheData = yield api.GetCacheItem(GetCacheKey(id, appId), reqParams);
1012
+ if (cacheData) {
1013
+ return cacheData;
1014
+ }
1015
+ const req = yield api.GET(`account/${id}?ApplicationID=${appId}`, reqParams);
1016
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
1017
+ var _a;
1018
+ try {
1019
+ const data = yield req;
1020
+ const settings = (_a = data === null || data === void 0 ? void 0 : data["Application.Settings"]) !== null && _a !== void 0 ? _a : {};
1021
+ res({
1022
+ settings: settings
1023
+ });
1024
+ }
1025
+ catch (e) {
1026
+ rej(e);
1027
+ }
1028
+ }));
1029
+ yield api.SetCacheItem({
1030
+ key: GetCacheKey(id, appId),
1031
+ value: prom,
1032
+ req: reqParams
1033
+ });
1034
+ return prom;
1035
+ });
1036
+ }
1037
+ Account.GetAppSettings = GetAppSettings;
1038
+ /**
1039
+ * WARNING: Do not update API settings without knowing what you're doing.
1040
+ * @param params
1041
+ * @returns
1042
+ */
1043
+ function UpdateAppSettings(params) {
1044
+ return __awaiter(this, void 0, void 0, function* () {
1045
+ const { api, accountId: id, appId, settings: data, req: reqParams } = params;
1046
+ const res = yield api.POST(`account/${id}/applicationSettings/${appId}`, data, reqParams);
1047
+ yield api.Cache.RemoveByStartsWith(exports.Api.ECacheKey.Account + exports.Api.ECacheKey.Id + id);
1048
+ return {
1049
+ settings: res
1050
+ };
1051
+ });
1052
+ }
1053
+ Account.UpdateAppSettings = UpdateAppSettings;
1054
+ /**
1055
+ * Creates a new Bruce account using given details.
1056
+ * @param params
1057
+ * @returns
1058
+ */
1059
+ function Create(params) {
1060
+ return __awaiter(this, void 0, void 0, function* () {
1061
+ let { api, accountId: id, name, hostingLocationKey, starterContent, req: reqParams } = params;
1062
+ if (!id || !name || !hostingLocationKey) {
1063
+ throw new Error("Id, Name and hostingLocationKey are required.");
1064
+ }
1065
+ if (!starterContent) {
1066
+ starterContent = EStarterContent.None;
1067
+ }
1068
+ const reqData = {
1069
+ "Name": name,
1070
+ "HostingLocation.Key": hostingLocationKey,
1071
+ "StarterContent": starterContent
1072
+ };
1073
+ const res = yield api.POST(`clientAccount/${id}`, reqData, exports.Api.PrepReqParams(reqParams));
1074
+ const resData = {
1075
+ account: res
1076
+ };
1077
+ api.Cache.Remove(GetListCacheKey(api.GetSessionId()));
1078
+ return resData;
1079
+ });
1080
+ }
1081
+ Account.Create = Create;
1082
+ })(exports.Account || (exports.Account = {}));
1083
+
1084
1084
  (function (HostingLocation) {
1085
1085
  /**
1086
1086
  * @Warning: This will not return the Settings property.
@@ -1262,70 +1262,80 @@
1262
1262
  * @returns
1263
1263
  */
1264
1264
  init(guardian, loadConfig) {
1265
- var _a, _b, _c, _d;
1265
+ var _a, _b;
1266
1266
  return __awaiter(this, void 0, void 0, function* () {
1267
1267
  if (!this.accountId) {
1268
1268
  throw ("accountId is required.");
1269
1269
  }
1270
- // Set using a stable default.
1271
- const prefix = `https://${this.accountId}.api.nextspace`;
1272
- let url;
1273
1270
  const env = this.env.toUpperCase();
1271
+ let domain = "nextspace.host";
1274
1272
  switch (env) {
1275
1273
  case exports.Api.EEnv.DEV:
1276
- url = prefix + "-dev.net/";
1274
+ domain = "nextspace-dev.net";
1277
1275
  break;
1278
1276
  case exports.Api.EEnv.STG:
1279
- url = prefix + "-stg.net/";
1277
+ domain = "nextspace-stg.net";
1280
1278
  break;
1281
1279
  case exports.Api.EEnv.UAT:
1282
- url = prefix + "-uat.net/";
1280
+ domain = "nextspace-uat.net";
1283
1281
  break;
1284
1282
  case exports.Api.EEnv.PROD:
1285
- url = prefix + ".host/";
1283
+ domain = "nextspace.host";
1286
1284
  break;
1287
1285
  default:
1288
- throw ("Specified Environment is not valid. SuppliedEnv=" + env);
1286
+ console.error("Specified Environment is not valid. SuppliedEnv=" + env);
1289
1287
  }
1290
- this.baseUrl = url;
1288
+ // Set using a stable default.
1289
+ this.baseUrl = `https://${this.accountId}.api.${domain}/`;
1291
1290
  if (guardian && loadConfig) {
1292
- // Attempt to load an account specific base url.
1293
- // This could be one with a region specific endpoint.
1294
1291
  try {
1295
- const settings = (yield exports.Account.GetAppSettings({
1296
- api: guardian,
1297
- accountId: this.accountId,
1298
- appId: exports.Account.EAppId.BruceApi
1299
- })).settings;
1300
- if (this.loadCancelled) {
1301
- console.warn("BruceApi: Loading was cancelled due to SetBaseUrl being called, not setting regional base url.");
1302
- return;
1303
- }
1304
- let endpoint = (_a = settings.BruceAPIURL) === null || _a === void 0 ? void 0 : _a[env];
1305
- if (typeof endpoint == "string") {
1306
- if (!endpoint.endsWith("/")) {
1307
- endpoint += "/";
1308
- }
1309
- this.baseUrl = endpoint;
1310
- }
1311
1292
  const host = yield exports.HostingLocation.GetByAccountId({
1312
1293
  accountId: this.accountId,
1313
- apiSettings: settings,
1314
1294
  api: guardian
1315
1295
  });
1316
- const hostSettings = (_b = host === null || host === void 0 ? void 0 : host.location) === null || _b === void 0 ? void 0 : _b.Settings;
1317
- if (hostSettings === null || hostSettings === void 0 ? void 0 : hostSettings.CDN) {
1318
- this.EntityCdnUrl = (_c = hostSettings.CDN.entityURL) === null || _c === void 0 ? void 0 : _c[env];
1319
- // We need to fix our configs.
1320
- if (this.EntityCdnUrl) {
1321
- if (this.EntityCdnUrl.includes("entitiesListForCDN")) {
1322
- this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", this.accountId);
1296
+ if (host === null || host === void 0 ? void 0 : host.location) {
1297
+ const settings = host.location.Settings;
1298
+ // Attempt to load regional base url.
1299
+ // First try go through settings.
1300
+ let urlSet = false;
1301
+ if (settings === null || settings === void 0 ? void 0 : settings.BruceAPIURL) {
1302
+ let envUrl = settings.BruceAPIURL[env];
1303
+ if (envUrl) {
1304
+ envUrl = envUrl
1305
+ .replace("<ACCOUNTID>", this.accountId)
1306
+ .replace("<ACCOUNT>", this.accountId);
1307
+ if (envUrl && envUrl.length > 1) {
1308
+ this.baseUrl = envUrl;
1309
+ urlSet = true;
1310
+ }
1311
+ }
1312
+ }
1313
+ // Try go through host location's base url.
1314
+ // This may be wrong env which is why it's used as fallback right now.
1315
+ if (!urlSet && host.location.BruceAPIURL) {
1316
+ const regionalUrl = host.location.BruceAPIURL
1317
+ .replace("<ACCOUNTID>", this.accountId)
1318
+ .replace("<ACCOUNT>", this.accountId)
1319
+ .replace("<DOMAIN>", domain);
1320
+ if (regionalUrl && regionalUrl.length > 1) {
1321
+ this.baseUrl = regionalUrl;
1322
+ urlSet = true;
1323
1323
  }
1324
- else {
1325
- this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", "entitiesListForCDN/" + this.accountId);
1324
+ }
1325
+ // Attempt to load CDN settings.
1326
+ if (settings === null || settings === void 0 ? void 0 : settings.CDN) {
1327
+ this.EntityCdnUrl = (_a = settings.CDN.entityURL) === null || _a === void 0 ? void 0 : _a[env];
1328
+ // We need to fix our configs.
1329
+ if (this.EntityCdnUrl) {
1330
+ if (this.EntityCdnUrl.includes("entitiesListForCDN")) {
1331
+ this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", this.accountId);
1332
+ }
1333
+ else {
1334
+ this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", "entitiesListForCDN/" + this.accountId);
1335
+ }
1326
1336
  }
1337
+ this.LegacyTilesetCdnUrl = (_b = settings.CDN.legacyTilesetURL) === null || _b === void 0 ? void 0 : _b[env];
1327
1338
  }
1328
- this.LegacyTilesetCdnUrl = (_d = hostSettings.CDN.legacyTilesetURL) === null || _d === void 0 ? void 0 : _d[env];
1329
1339
  }
1330
1340
  }
1331
1341
  catch (e) {