bruce-models 0.6.9 → 0.7.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.
@@ -631,6 +631,211 @@ var AbstractApi = /** @class */ (function () {
631
631
  return AbstractApi;
632
632
  }());
633
633
 
634
+ var ACCOUNT_EXCLUSIONS = ["hyperportal", "hypeportal", "bviewer"];
635
+ /**
636
+ * Describes the "Client Account" concept within Bruce.
637
+ * A client account is a database instance that holds one or many users.
638
+ */
639
+ var Account;
640
+ (function (Account) {
641
+ function GetCacheKey(accountId, appSettingsId) {
642
+ if (appSettingsId) {
643
+ return Api.ECacheKey.Account + Api.ECacheKey.Id + accountId + Api.ECacheKey + appSettingsId;
644
+ }
645
+ return Api.ECacheKey.Account + Api.ECacheKey.Id + accountId;
646
+ }
647
+ Account.GetCacheKey = GetCacheKey;
648
+ function GetListCacheKey(ssid) {
649
+ return Api.ECacheKey.Account + Api.ECacheKey.Session + Api.ECacheKey.Id + ssid;
650
+ }
651
+ Account.GetListCacheKey = GetListCacheKey;
652
+ var EDbRegion;
653
+ (function (EDbRegion) {
654
+ EDbRegion["USA"] = "US";
655
+ EDbRegion["Paris"] = "EU";
656
+ EDbRegion["Singapore"] = "SE";
657
+ EDbRegion["Australia"] = "AU";
658
+ })(EDbRegion = Account.EDbRegion || (Account.EDbRegion = {}));
659
+ var EAppId;
660
+ (function (EAppId) {
661
+ EAppId["BruceApi"] = "BruceAPI";
662
+ })(EAppId = Account.EAppId || (Account.EAppId = {}));
663
+ var EStarterContent;
664
+ (function (EStarterContent) {
665
+ EStarterContent["Default"] = "default";
666
+ EStarterContent["None"] = "none";
667
+ })(EStarterContent = Account.EStarterContent || (Account.EStarterContent = {}));
668
+ Account.DbRegions = [
669
+ {
670
+ name: "North California, USA",
671
+ value: EDbRegion.USA
672
+ },
673
+ {
674
+ name: "Paris, France",
675
+ value: EDbRegion.Paris
676
+ },
677
+ {
678
+ name: "Singapore",
679
+ value: EDbRegion.Singapore
680
+ },
681
+ {
682
+ name: "Sydney, Australia",
683
+ value: EDbRegion.Australia
684
+ }
685
+ ];
686
+ function Get(api, id) {
687
+ return __awaiter(this, void 0, void 0, function () {
688
+ var cacheData, req;
689
+ return __generator(this, function (_a) {
690
+ switch (_a.label) {
691
+ case 0:
692
+ cacheData = api.Cache.Get(GetCacheKey(id));
693
+ if (cacheData) {
694
+ return [2 /*return*/, cacheData];
695
+ }
696
+ return [4 /*yield*/, api.GET("account/" + id)];
697
+ case 1:
698
+ req = _a.sent();
699
+ api.Cache.Set(GetCacheKey(id), req, Api.DEFAULT_CACHE_DURATION);
700
+ return [2 /*return*/, req];
701
+ }
702
+ });
703
+ });
704
+ }
705
+ Account.Get = Get;
706
+ function GetRelatedList(api) {
707
+ return __awaiter(this, void 0, void 0, function () {
708
+ var cacheData, req, prom;
709
+ var _this = this;
710
+ return __generator(this, function (_a) {
711
+ cacheData = api.Cache.Get(GetListCacheKey(api.GetSessionId()));
712
+ if (cacheData) {
713
+ return [2 /*return*/, cacheData];
714
+ }
715
+ req = api.GET("user/relatedClientAccounts");
716
+ prom = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
717
+ var data, items, e_1;
718
+ return __generator(this, function (_a) {
719
+ switch (_a.label) {
720
+ case 0:
721
+ _a.trys.push([0, 2, , 3]);
722
+ return [4 /*yield*/, req];
723
+ case 1:
724
+ data = _a.sent();
725
+ items = data.Items.filter(function (x) { return !ACCOUNT_EXCLUSIONS.includes(x.ID); });
726
+ res(items);
727
+ return [3 /*break*/, 3];
728
+ case 2:
729
+ e_1 = _a.sent();
730
+ rej(e_1);
731
+ return [3 /*break*/, 3];
732
+ case 3: return [2 /*return*/];
733
+ }
734
+ });
735
+ }); });
736
+ api.Cache.Set(GetListCacheKey(api.GetSessionId()), prom, Api.DEFAULT_CACHE_DURATION);
737
+ return [2 /*return*/, prom];
738
+ });
739
+ });
740
+ }
741
+ Account.GetRelatedList = GetRelatedList;
742
+ function GetAppSettings(api, id, appId) {
743
+ return __awaiter(this, void 0, void 0, function () {
744
+ var cacheData, req, prom;
745
+ var _this = this;
746
+ return __generator(this, function (_a) {
747
+ switch (_a.label) {
748
+ case 0:
749
+ cacheData = api.Cache.Get(GetCacheKey(id, appId));
750
+ if (cacheData) {
751
+ return [2 /*return*/, cacheData];
752
+ }
753
+ return [4 /*yield*/, api.GET("account/" + id + "?ApplicationID=" + appId)];
754
+ case 1:
755
+ req = _a.sent();
756
+ prom = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
757
+ var data, settings, e_2;
758
+ var _a;
759
+ return __generator(this, function (_b) {
760
+ switch (_b.label) {
761
+ case 0:
762
+ _b.trys.push([0, 2, , 3]);
763
+ return [4 /*yield*/, req];
764
+ case 1:
765
+ data = _b.sent();
766
+ settings = (_a = data === null || data === void 0 ? void 0 : data["Application.Settings"]) !== null && _a !== void 0 ? _a : {};
767
+ res(settings);
768
+ return [3 /*break*/, 3];
769
+ case 2:
770
+ e_2 = _b.sent();
771
+ rej(e_2);
772
+ return [3 /*break*/, 3];
773
+ case 3: return [2 /*return*/];
774
+ }
775
+ });
776
+ }); });
777
+ api.Cache.Set(GetCacheKey(id, appId), prom, Api.DEFAULT_CACHE_DURATION);
778
+ return [2 /*return*/, prom];
779
+ }
780
+ });
781
+ });
782
+ }
783
+ Account.GetAppSettings = GetAppSettings;
784
+ /**
785
+ * WARNING: Do not update API settings without knowing what you're doing.
786
+ * @param api
787
+ * @param id
788
+ * @param appId
789
+ * @param data
790
+ * @returns
791
+ */
792
+ function UpdateAppSettings(api, id, appId, data) {
793
+ return __awaiter(this, void 0, void 0, function () {
794
+ return __generator(this, function (_a) {
795
+ switch (_a.label) {
796
+ case 0: return [4 /*yield*/, api.POST("account/" + id + "/applicationSettings/" + appId, data)];
797
+ case 1:
798
+ data = _a.sent();
799
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.Account + Api.ECacheKey.Id + id);
800
+ return [2 /*return*/, data];
801
+ }
802
+ });
803
+ });
804
+ }
805
+ Account.UpdateAppSettings = UpdateAppSettings;
806
+ /**
807
+ * Creates a new Bruce account using given details.
808
+ * @param api
809
+ * @param id
810
+ * @param name
811
+ * @param region
812
+ * @param starterContent
813
+ * @returns
814
+ */
815
+ function Create(api, id, name, region, starterContent) {
816
+ return __awaiter(this, void 0, void 0, function () {
817
+ var reqData, res;
818
+ return __generator(this, function (_a) {
819
+ if (!id || !name || !region) {
820
+ throw new Error("Id, Name and Region are required.");
821
+ }
822
+ if (!starterContent) {
823
+ starterContent = EStarterContent.None;
824
+ }
825
+ reqData = {
826
+ "Name": name,
827
+ "DBLocation": region,
828
+ "StarterContent": starterContent
829
+ };
830
+ res = api.POST("clientAccount/" + id, reqData, Api.PrepReqParams());
831
+ api.Cache.Remove(GetListCacheKey(api.GetSessionId()));
832
+ return [2 /*return*/, res];
833
+ });
834
+ });
835
+ }
836
+ Account.Create = Create;
837
+ })(Account || (Account = {}));
838
+
634
839
  /**
635
840
  * This is the request handler for Cam Api,
636
841
  * it should be passed to any method that wants to communicate with this particular api.
@@ -711,7 +916,7 @@ var CamApi;
711
916
  })(CamApi || (CamApi = {}));
712
917
 
713
918
  var BruceApi;
714
- (function (BruceApi$$1) {
919
+ (function (BruceApi) {
715
920
  /**
716
921
  * This is the request handler for Bruce Api,
717
922
  * it should be passed to any method that wants to communicate with this particular api.
@@ -854,7 +1059,7 @@ var BruceApi;
854
1059
  };
855
1060
  return Api$$1;
856
1061
  }(AbstractApi));
857
- BruceApi$$1.Api = Api$$1;
1062
+ BruceApi.Api = Api$$1;
858
1063
  })(BruceApi || (BruceApi = {}));
859
1064
 
860
1065
  var IdmApi;
@@ -4009,7 +4214,7 @@ var ClientFile;
4009
4214
  clientFileId: clientFileId,
4010
4215
  destinationFormat: ext,
4011
4216
  operations: []
4012
- }, Api.PrepReqParams())];
4217
+ })];
4013
4218
  });
4014
4219
  });
4015
4220
  }
@@ -5899,211 +6104,6 @@ var User;
5899
6104
  })(AccessToken = User.AccessToken || (User.AccessToken = {}));
5900
6105
  })(User || (User = {}));
5901
6106
 
5902
- var ACCOUNT_EXCLUSIONS = ["hyperportal", "hypeportal", "bviewer"];
5903
- /**
5904
- * Describes the "Client Account" concept within Bruce.
5905
- * A client account is a database instance that holds one or many users.
5906
- */
5907
- var Account;
5908
- (function (Account) {
5909
- function GetCacheKey(accountId, appSettingsId) {
5910
- if (appSettingsId) {
5911
- return Api.ECacheKey.Account + Api.ECacheKey.Id + accountId + Api.ECacheKey + appSettingsId;
5912
- }
5913
- return Api.ECacheKey.Account + Api.ECacheKey.Id + accountId;
5914
- }
5915
- Account.GetCacheKey = GetCacheKey;
5916
- function GetListCacheKey(ssid) {
5917
- return Api.ECacheKey.Account + Api.ECacheKey.Session + Api.ECacheKey.Id + ssid;
5918
- }
5919
- Account.GetListCacheKey = GetListCacheKey;
5920
- var EDbRegion;
5921
- (function (EDbRegion) {
5922
- EDbRegion["USA"] = "US";
5923
- EDbRegion["Paris"] = "EU";
5924
- EDbRegion["Singapore"] = "SE";
5925
- EDbRegion["Australia"] = "AU";
5926
- })(EDbRegion = Account.EDbRegion || (Account.EDbRegion = {}));
5927
- var EAppId;
5928
- (function (EAppId) {
5929
- EAppId["BruceApi"] = "BruceAPI";
5930
- })(EAppId = Account.EAppId || (Account.EAppId = {}));
5931
- var EStarterContent;
5932
- (function (EStarterContent) {
5933
- EStarterContent["Default"] = "default";
5934
- EStarterContent["None"] = "none";
5935
- })(EStarterContent = Account.EStarterContent || (Account.EStarterContent = {}));
5936
- Account.DbRegions = [
5937
- {
5938
- name: "North California, USA",
5939
- value: EDbRegion.USA
5940
- },
5941
- {
5942
- name: "Paris, France",
5943
- value: EDbRegion.Paris
5944
- },
5945
- {
5946
- name: "Singapore",
5947
- value: EDbRegion.Singapore
5948
- },
5949
- {
5950
- name: "Sydney, Australia",
5951
- value: EDbRegion.Australia
5952
- }
5953
- ];
5954
- function Get(api, id) {
5955
- return __awaiter(this, void 0, void 0, function () {
5956
- var cacheData, req;
5957
- return __generator(this, function (_a) {
5958
- switch (_a.label) {
5959
- case 0:
5960
- cacheData = api.Cache.Get(GetCacheKey(id));
5961
- if (cacheData) {
5962
- return [2 /*return*/, cacheData];
5963
- }
5964
- return [4 /*yield*/, api.GET("account/" + id)];
5965
- case 1:
5966
- req = _a.sent();
5967
- api.Cache.Set(GetCacheKey(id), req, Api.DEFAULT_CACHE_DURATION);
5968
- return [2 /*return*/, req];
5969
- }
5970
- });
5971
- });
5972
- }
5973
- Account.Get = Get;
5974
- function GetRelatedList(api) {
5975
- return __awaiter(this, void 0, void 0, function () {
5976
- var cacheData, req, prom;
5977
- var _this = this;
5978
- return __generator(this, function (_a) {
5979
- cacheData = api.Cache.Get(GetListCacheKey(api.GetSessionId()));
5980
- if (cacheData) {
5981
- return [2 /*return*/, cacheData];
5982
- }
5983
- req = api.GET("user/relatedClientAccounts");
5984
- prom = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
5985
- var data, items, e_1;
5986
- return __generator(this, function (_a) {
5987
- switch (_a.label) {
5988
- case 0:
5989
- _a.trys.push([0, 2, , 3]);
5990
- return [4 /*yield*/, req];
5991
- case 1:
5992
- data = _a.sent();
5993
- items = data.Items.filter(function (x) { return !ACCOUNT_EXCLUSIONS.includes(x.ID); });
5994
- res(items);
5995
- return [3 /*break*/, 3];
5996
- case 2:
5997
- e_1 = _a.sent();
5998
- rej(e_1);
5999
- return [3 /*break*/, 3];
6000
- case 3: return [2 /*return*/];
6001
- }
6002
- });
6003
- }); });
6004
- api.Cache.Set(GetListCacheKey(api.GetSessionId()), prom, Api.DEFAULT_CACHE_DURATION);
6005
- return [2 /*return*/, prom];
6006
- });
6007
- });
6008
- }
6009
- Account.GetRelatedList = GetRelatedList;
6010
- function GetAppSettings(api, id, appId) {
6011
- return __awaiter(this, void 0, void 0, function () {
6012
- var cacheData, req, prom;
6013
- var _this = this;
6014
- return __generator(this, function (_a) {
6015
- switch (_a.label) {
6016
- case 0:
6017
- cacheData = api.Cache.Get(GetCacheKey(id, appId));
6018
- if (cacheData) {
6019
- return [2 /*return*/, cacheData];
6020
- }
6021
- return [4 /*yield*/, api.GET("account/" + id + "?ApplicationID=" + appId)];
6022
- case 1:
6023
- req = _a.sent();
6024
- prom = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
6025
- var data, settings, e_2;
6026
- var _a;
6027
- return __generator(this, function (_b) {
6028
- switch (_b.label) {
6029
- case 0:
6030
- _b.trys.push([0, 2, , 3]);
6031
- return [4 /*yield*/, req];
6032
- case 1:
6033
- data = _b.sent();
6034
- settings = (_a = data === null || data === void 0 ? void 0 : data["Application.Settings"]) !== null && _a !== void 0 ? _a : {};
6035
- res(settings);
6036
- return [3 /*break*/, 3];
6037
- case 2:
6038
- e_2 = _b.sent();
6039
- rej(e_2);
6040
- return [3 /*break*/, 3];
6041
- case 3: return [2 /*return*/];
6042
- }
6043
- });
6044
- }); });
6045
- api.Cache.Set(GetCacheKey(id, appId), prom, Api.DEFAULT_CACHE_DURATION);
6046
- return [2 /*return*/, prom];
6047
- }
6048
- });
6049
- });
6050
- }
6051
- Account.GetAppSettings = GetAppSettings;
6052
- /**
6053
- * WARNING: Do not update API settings without knowing what you're doing.
6054
- * @param api
6055
- * @param id
6056
- * @param appId
6057
- * @param data
6058
- * @returns
6059
- */
6060
- function UpdateAppSettings(api, id, appId, data) {
6061
- return __awaiter(this, void 0, void 0, function () {
6062
- return __generator(this, function (_a) {
6063
- switch (_a.label) {
6064
- case 0: return [4 /*yield*/, api.POST("account/" + id + "/applicationSettings/" + appId, data)];
6065
- case 1:
6066
- data = _a.sent();
6067
- api.Cache.RemoveByStartsWith(Api.ECacheKey.Account + Api.ECacheKey.Id + id);
6068
- return [2 /*return*/, data];
6069
- }
6070
- });
6071
- });
6072
- }
6073
- Account.UpdateAppSettings = UpdateAppSettings;
6074
- /**
6075
- * Creates a new Bruce account using given details.
6076
- * @param api
6077
- * @param id
6078
- * @param name
6079
- * @param region
6080
- * @param starterContent
6081
- * @returns
6082
- */
6083
- function Create(api, id, name, region, starterContent) {
6084
- return __awaiter(this, void 0, void 0, function () {
6085
- var reqData, res;
6086
- return __generator(this, function (_a) {
6087
- if (!id || !name || !region) {
6088
- throw new Error("Id, Name and Region are required.");
6089
- }
6090
- if (!starterContent) {
6091
- starterContent = EStarterContent.None;
6092
- }
6093
- reqData = {
6094
- "Name": name,
6095
- "DBLocation": region,
6096
- "StarterContent": starterContent
6097
- };
6098
- res = api.POST("clientAccount/" + id, reqData, Api.PrepReqParams());
6099
- api.Cache.Remove(GetListCacheKey(api.GetSessionId()));
6100
- return [2 /*return*/, res];
6101
- });
6102
- });
6103
- }
6104
- Account.Create = Create;
6105
- })(Account || (Account = {}));
6106
-
6107
6107
  var EncryptUtils;
6108
6108
  (function (EncryptUtils) {
6109
6109
  // https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript