bruce-models 4.5.3 → 4.5.5

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.
@@ -90,6 +90,7 @@
90
90
  Api.DEFAULT_CACHE_DURATION = 60 * 1000;
91
91
  // The template client account is a container for default settings to reference.
92
92
  Api.TEMPLATE_ACCOUNT_ID = "template";
93
+ Api.SUPER_ACCOUNT_ID = "hypeportal";
93
94
  // Default session token header.
94
95
  Api.ACCESS_TOKEN_HEADER = "X-Access-Token";
95
96
  /**
@@ -10749,27 +10750,53 @@
10749
10750
  * @returns
10750
10751
  */
10751
10752
  function IsPermEnabled(params) {
10752
- var _a, _b;
10753
+ var _a, _b, _c, _d, _e, _f;
10753
10754
  let { session, accountId, perm } = params;
10754
10755
  if (!perm) {
10755
10756
  throw ("Perm is required.");
10756
10757
  }
10757
10758
  perm = perm.toLocaleUpperCase();
10758
- const perms = (_b = (_a = session === null || session === void 0 ? void 0 : session.User) === null || _a === void 0 ? void 0 : _a.AccessPermissions) === null || _b === void 0 ? void 0 : _b.find(x => x["ClientAccount.ID"] == accountId);
10759
+ accountId = accountId.toLowerCase();
10760
+ // First we'll scan the user object for the account ID.
10761
+ if ((_b = (_a = session === null || session === void 0 ? void 0 : session.User) === null || _a === void 0 ? void 0 : _a.AccessPermissions) === null || _b === void 0 ? void 0 : _b.length) {
10762
+ for (let i = 0; i < session.User.AccessPermissions.length; i++) {
10763
+ const aPerms = session.User.AccessPermissions[i];
10764
+ const permsAccountId = String(aPerms["ClientAccount.ID"]).toLowerCase();
10765
+ // Found account, woo.
10766
+ if (permsAccountId == accountId) {
10767
+ // Check against the loaded perm array.
10768
+ // In newer version this always exists, but in some legacy versions it MIGHT not,
10769
+ //therefor we also do a group check after..
10770
+ if ((_c = aPerms.EnabledFeatures) === null || _c === void 0 ? void 0 : _c.length) {
10771
+ return aPerms.EnabledFeatures.findIndex(x => x.toLocaleUpperCase() == perm) > -1;
10772
+ }
10773
+ // Fallback to group check.
10774
+ if (((_d = aPerms.UserGroups) === null || _d === void 0 ? void 0 : _d.length) && typeof aPerms.UserGroups[0] != "string") {
10775
+ for (let j = 0; j < aPerms.UserGroups.length; j++) {
10776
+ const group = aPerms.UserGroups[j];
10777
+ if ((_e = group === null || group === void 0 ? void 0 : group.Features) === null || _e === void 0 ? void 0 : _e.length) {
10778
+ const gPerms = group.Features;
10779
+ if (gPerms && gPerms.findIndex(x => x.toLocaleUpperCase() == perm) > -1) {
10780
+ return true;
10781
+ }
10782
+ }
10783
+ }
10784
+ }
10785
+ }
10786
+ }
10787
+ }
10788
+ // Fallback to the session perm info.
10789
+ // This is deprecated and old as it's only for one account.
10790
+ const perms = session === null || session === void 0 ? void 0 : session.AccessPermissions;
10759
10791
  if (!perms) {
10760
10792
  return false;
10761
10793
  }
10762
- if (!perms.UserGroups) {
10763
- perms.UserGroups = [];
10794
+ const pAccountId = String(perms["ClientAccount.ID"]).toLowerCase();
10795
+ if (pAccountId != accountId) {
10796
+ return false;
10764
10797
  }
10765
- for (let i = 0; i < perms.UserGroups.length; i++) {
10766
- const group = perms.UserGroups[i];
10767
- if (typeof group != "string") {
10768
- const features = group.Features;
10769
- if (features && features.findIndex(x => x.toLocaleUpperCase() == perm) > -1) {
10770
- return true;
10771
- }
10772
- }
10798
+ if ((_f = perms.EnabledFeatures) === null || _f === void 0 ? void 0 : _f.length) {
10799
+ return perms.EnabledFeatures.findIndex(x => x.toLocaleUpperCase() == perm) > -1;
10773
10800
  }
10774
10801
  return false;
10775
10802
  }
@@ -10791,22 +10818,35 @@
10791
10818
  return false;
10792
10819
  }
10793
10820
  perm = perm.toLocaleUpperCase();
10794
- // We'll look for 'HypeportalAccessPermisssions' first.
10795
- if ((_a = session.HypeportalAccessPermisssions) === null || _a === void 0 ? void 0 : _a.EnabledFeatures) {
10796
- const perms = session.HypeportalAccessPermisssions.EnabledFeatures;
10797
- return perms.findIndex(x => x.toLocaleUpperCase() == perm) > -1;
10798
- }
10799
- // Fallback to looking through groups.
10800
- // This is important if the user directly logged into "hypeportal" as the response differs.
10801
- else if ((_c = (_b = session.User) === null || _b === void 0 ? void 0 : _b.AccessPermissions) === null || _c === void 0 ? void 0 : _c.length) {
10802
- const perms = session.User.AccessPermissions.find(x => String(x["ClientAccount.ID"]).toLowerCase() == "hypeportal");
10803
- if ((_d = perms === null || perms === void 0 ? void 0 : perms.UserGroups) === null || _d === void 0 ? void 0 : _d.length) {
10804
- for (let j = 0; j < perms.UserGroups.length; j++) {
10805
- const group = perms.UserGroups[j];
10806
- if (typeof group != "string") {
10807
- const features = group.Features;
10808
- if (features && features.findIndex(x => x.toLocaleUpperCase() == perm) > -1) {
10809
- return true;
10821
+ // First we'll scan the included super perms.
10822
+ const superPerms = session.HypeportalAccessPermisssions;
10823
+ if ((_a = superPerms === null || superPerms === void 0 ? void 0 : superPerms.EnabledFeatures) === null || _a === void 0 ? void 0 : _a.length) {
10824
+ return superPerms.EnabledFeatures.findIndex(x => x.toLocaleUpperCase() == perm) > -1;
10825
+ }
10826
+ // Now we'll fallback to digging through group to find the super group.
10827
+ if ((_c = (_b = session === null || session === void 0 ? void 0 : session.User) === null || _b === void 0 ? void 0 : _b.AccessPermissions) === null || _c === void 0 ? void 0 : _c.length) {
10828
+ for (let i = 0; i < session.User.AccessPermissions.length; i++) {
10829
+ const perms = session.User.AccessPermissions[i];
10830
+ // Newer API versions always specify accountId in the collections.
10831
+ // If it's set we can do a super account check early.
10832
+ if (perms["ClientAccount.ID"] != null) {
10833
+ const pAccountId = String(perms["ClientAccount.ID"]).toLowerCase();
10834
+ if (pAccountId != exports.Api.SUPER_ACCOUNT_ID) {
10835
+ continue;
10836
+ }
10837
+ }
10838
+ if ((_d = perms === null || perms === void 0 ? void 0 : perms.UserGroups) === null || _d === void 0 ? void 0 : _d.length) {
10839
+ for (let j = 0; j < perms.UserGroups.length; j++) {
10840
+ const group = perms.UserGroups[j];
10841
+ if (typeof group != "string") {
10842
+ const gAccountId = String(group["ClientAccount.ID"]).toLowerCase();
10843
+ if (gAccountId != exports.Api.SUPER_ACCOUNT_ID) {
10844
+ continue;
10845
+ }
10846
+ const features = group.Features;
10847
+ if (features && features.findIndex(x => x.toLocaleUpperCase() == perm) > -1) {
10848
+ return true;
10849
+ }
10810
10850
  }
10811
10851
  }
10812
10852
  }
@@ -11066,7 +11106,7 @@
11066
11106
  if ((_a = data.AccessPermissions) === null || _a === void 0 ? void 0 : _a.length) {
11067
11107
  for (let i = 0; i < data.AccessPermissions.length; i++) {
11068
11108
  const perm = data.AccessPermissions[i];
11069
- if (!perm["UserGroup.ID"] && perm.UserGroups) {
11109
+ if (!perm["UserGroup.ID"] && perm.UserGroups && typeof perm.UserGroups != "string") {
11070
11110
  perm["UserGroup.ID"] = [];
11071
11111
  for (let j = 0; j < perm.UserGroups.length; j++) {
11072
11112
  perm["UserGroup.ID"].push(perm.UserGroups[j].ID);
@@ -13415,7 +13455,7 @@
13415
13455
  })(exports.DataSource || (exports.DataSource = {}));
13416
13456
 
13417
13457
  // This is updated with the package.json version on build.
13418
- const VERSION = "4.5.3";
13458
+ const VERSION = "4.5.5";
13419
13459
 
13420
13460
  exports.VERSION = VERSION;
13421
13461
  exports.AbstractApi = AbstractApi;