bruce-models 1.3.0 → 1.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.
@@ -54,10 +54,12 @@ var Api;
54
54
  ECacheKey["Style"] = "style";
55
55
  ECacheKey["PublishTileset"] = "publishtileset";
56
56
  ECacheKey["User"] = "user";
57
+ ECacheKey["UserSettings"] = "usersettings";
57
58
  ECacheKey["UserEmail"] = "useremail";
58
59
  ECacheKey["AccessToken"] = "accesstoken";
59
60
  ECacheKey["UserGroup"] = "usergroup";
60
61
  ECacheKey["Account"] = "account";
62
+ ECacheKey["DatabaseRegion"] = "databaseregion";
61
63
  ECacheKey["CustomForm"] = "customform";
62
64
  ECacheKey["ImportedFile"] = "importedfile";
63
65
  })(ECacheKey = Api.ECacheKey || (Api.ECacheKey = {}));
@@ -637,6 +639,10 @@ var Account;
637
639
  return Api.ECacheKey.Account + Api.ECacheKey.Session + Api.ECacheKey.Id + ssid;
638
640
  }
639
641
  Account.GetListCacheKey = GetListCacheKey;
642
+ function GetDbRegionListCacheKey() {
643
+ return Api.ECacheKey.DatabaseRegion;
644
+ }
645
+ Account.GetDbRegionListCacheKey = GetDbRegionListCacheKey;
640
646
  let EDbRegion;
641
647
  (function (EDbRegion) {
642
648
  EDbRegion["USA"] = "US";
@@ -653,24 +659,6 @@ var Account;
653
659
  EStarterContent["Default"] = "default";
654
660
  EStarterContent["None"] = "none";
655
661
  })(EStarterContent = Account.EStarterContent || (Account.EStarterContent = {}));
656
- Account.DbRegions = [
657
- {
658
- name: "North California, USA",
659
- value: EDbRegion.USA
660
- },
661
- {
662
- name: "Paris, France",
663
- value: EDbRegion.Paris
664
- },
665
- {
666
- name: "Singapore",
667
- value: EDbRegion.Singapore
668
- },
669
- {
670
- name: "Sydney, Australia",
671
- value: EDbRegion.Australia
672
- }
673
- ];
674
662
  function Get(api, id, reqParams) {
675
663
  return __awaiter(this, void 0, void 0, function* () {
676
664
  const cacheData = api.GetCacheItem(GetCacheKey(id), reqParams);
@@ -774,6 +762,26 @@ var Account;
774
762
  });
775
763
  }
776
764
  Account.Create = Create;
765
+ function GetDbRegions(api, reqParams) {
766
+ return __awaiter(this, void 0, void 0, function* () {
767
+ const cacheData = api.GetCacheItem(GetDbRegionListCacheKey(), reqParams);
768
+ if (cacheData) {
769
+ return cacheData;
770
+ }
771
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
772
+ try {
773
+ const data = yield api.GET("config/regions", Api.PrepReqParams(reqParams));
774
+ res(data.regions);
775
+ }
776
+ catch (e) {
777
+ rej(e);
778
+ }
779
+ }));
780
+ api.Cache.Set(GetDbRegionListCacheKey(), prom, Api.DEFAULT_CACHE_DURATION);
781
+ return prom;
782
+ });
783
+ }
784
+ Account.GetDbRegions = GetDbRegions;
777
785
  })(Account || (Account = {}));
778
786
 
779
787
  var MessageBroker;
@@ -5573,6 +5581,10 @@ var User;
5573
5581
  return Api.ECacheKey.User + Api.ECacheKey.UserEmail + email + Api.ECacheKey.Id + accountId;
5574
5582
  }
5575
5583
  User.GetEmailCacheKey = GetEmailCacheKey;
5584
+ function GetSettingsCacheKey(userId, appId) {
5585
+ return Api.ECacheKey.User + Api.ECacheKey.UserSettings + userId + Api.ECacheKey.Id + appId;
5586
+ }
5587
+ User.GetSettingsCacheKey = GetSettingsCacheKey;
5576
5588
  let EType;
5577
5589
  (function (EType) {
5578
5590
  EType["User"] = "LOGIN_USER";
@@ -5610,6 +5622,59 @@ var User;
5610
5622
  });
5611
5623
  }
5612
5624
  User.Update = Update;
5625
+ /**
5626
+ * Loads settings for a given user + app.
5627
+ * The session's account id is used to separate settings between accounts.
5628
+ * @param params
5629
+ */
5630
+ function GetSettings(params) {
5631
+ return __awaiter(this, void 0, void 0, function* () {
5632
+ const { api, userId, appId, req } = params;
5633
+ if (!userId || !appId) {
5634
+ throw ("UserId and appId are required.");
5635
+ }
5636
+ const cacheData = api.GetCacheItem(GetSettingsCacheKey(userId, appId), req);
5637
+ if (cacheData) {
5638
+ return cacheData;
5639
+ }
5640
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
5641
+ try {
5642
+ const data = yield api.GET(`user/${userId}/application/${appId}/settings`);
5643
+ const settings = (data === null || data === void 0 ? void 0 : data.Settings) ? data.Settings : {};
5644
+ res(settings);
5645
+ }
5646
+ catch (e) {
5647
+ rej(e);
5648
+ }
5649
+ }));
5650
+ api.Cache.Set(GetSettingsCacheKey(userId, appId), prom, Api.DEFAULT_CACHE_DURATION);
5651
+ return prom;
5652
+ });
5653
+ }
5654
+ User.GetSettings = GetSettings;
5655
+ /**
5656
+ * Updates settings for a given accId + user + app.
5657
+ * The settings update will replace the existing record, please ensure to merge with existing settings.
5658
+ * @param params
5659
+ */
5660
+ function UpdateSettings(params) {
5661
+ return __awaiter(this, void 0, void 0, function* () {
5662
+ const { api, accId, userId, appId, settings, req } = params;
5663
+ if (!accId || !userId || !appId) {
5664
+ throw ("accId, userId and appId are required.");
5665
+ }
5666
+ const postBody = {
5667
+ Settings: settings == null ? {} : settings,
5668
+ Application: appId,
5669
+ ClientAccountID: accId,
5670
+ UserID: userId
5671
+ };
5672
+ const prom = api.POST(`user/${userId}/application/${appId}/settings`, postBody, req);
5673
+ api.Cache.Remove(GetSettingsCacheKey(userId, appId));
5674
+ return prom;
5675
+ });
5676
+ }
5677
+ User.UpdateSettings = UpdateSettings;
5613
5678
  function GetUsernameAvailable(api, username, reqParams) {
5614
5679
  return __awaiter(this, void 0, void 0, function* () {
5615
5680
  if (!username) {