bruce-models 1.3.1 → 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,6 +54,7 @@ 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";
@@ -5580,6 +5581,10 @@ var User;
5580
5581
  return Api.ECacheKey.User + Api.ECacheKey.UserEmail + email + Api.ECacheKey.Id + accountId;
5581
5582
  }
5582
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;
5583
5588
  let EType;
5584
5589
  (function (EType) {
5585
5590
  EType["User"] = "LOGIN_USER";
@@ -5617,6 +5622,59 @@ var User;
5617
5622
  });
5618
5623
  }
5619
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;
5620
5678
  function GetUsernameAvailable(api, username, reqParams) {
5621
5679
  return __awaiter(this, void 0, void 0, function* () {
5622
5680
  if (!username) {