bruce-models 4.5.2 → 4.5.4

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
  /**
@@ -125,6 +126,11 @@
125
126
  ESortOrder[ESortOrder["Asc"] = 1] = "Asc";
126
127
  ESortOrder[ESortOrder["Desc"] = -1] = "Desc";
127
128
  })(ESortOrder = Api.ESortOrder || (Api.ESortOrder = {}));
129
+ let ESortOrderStr;
130
+ (function (ESortOrderStr) {
131
+ ESortOrderStr["Asc"] = "ASC";
132
+ ESortOrderStr["Desc"] = "DESC";
133
+ })(ESortOrderStr = Api.ESortOrderStr || (Api.ESortOrderStr = {}));
128
134
  /**
129
135
  * Known response encodings from Nextspace APIs.
130
136
  */
@@ -10744,27 +10750,53 @@
10744
10750
  * @returns
10745
10751
  */
10746
10752
  function IsPermEnabled(params) {
10747
- var _a, _b;
10753
+ var _a, _b, _c, _d, _e, _f;
10748
10754
  let { session, accountId, perm } = params;
10749
10755
  if (!perm) {
10750
10756
  throw ("Perm is required.");
10751
10757
  }
10752
10758
  perm = perm.toLocaleUpperCase();
10753
- 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;
10754
10791
  if (!perms) {
10755
10792
  return false;
10756
10793
  }
10757
- if (!perms.UserGroups) {
10758
- perms.UserGroups = [];
10794
+ const pAccountId = String(perms["ClientAccount.ID"]).toLowerCase();
10795
+ if (pAccountId != accountId) {
10796
+ return false;
10759
10797
  }
10760
- for (let i = 0; i < perms.UserGroups.length; i++) {
10761
- const group = perms.UserGroups[i];
10762
- if (typeof group != "string") {
10763
- const features = group.Features;
10764
- if (features && features.findIndex(x => x.toLocaleUpperCase() == perm) > -1) {
10765
- return true;
10766
- }
10767
- }
10798
+ if ((_f = perms.EnabledFeatures) === null || _f === void 0 ? void 0 : _f.length) {
10799
+ return perms.EnabledFeatures.findIndex(x => x.toLocaleUpperCase() == perm) > -1;
10768
10800
  }
10769
10801
  return false;
10770
10802
  }
@@ -10786,22 +10818,35 @@
10786
10818
  return false;
10787
10819
  }
10788
10820
  perm = perm.toLocaleUpperCase();
10789
- // We'll look for 'HypeportalAccessPermisssions' first.
10790
- if ((_a = session.HypeportalAccessPermisssions) === null || _a === void 0 ? void 0 : _a.EnabledFeatures) {
10791
- const perms = session.HypeportalAccessPermisssions.EnabledFeatures;
10792
- return perms.findIndex(x => x.toLocaleUpperCase() == perm) > -1;
10793
- }
10794
- // Fallback to looking through groups.
10795
- // This is important if the user directly logged into "hypeportal" as the response differs.
10796
- else if ((_c = (_b = session.User) === null || _b === void 0 ? void 0 : _b.AccessPermissions) === null || _c === void 0 ? void 0 : _c.length) {
10797
- const perms = session.User.AccessPermissions.find(x => String(x["ClientAccount.ID"]).toLowerCase() == "hypeportal");
10798
- if ((_d = perms === null || perms === void 0 ? void 0 : perms.UserGroups) === null || _d === void 0 ? void 0 : _d.length) {
10799
- for (let j = 0; j < perms.UserGroups.length; j++) {
10800
- const group = perms.UserGroups[j];
10801
- if (typeof group != "string") {
10802
- const features = group.Features;
10803
- if (features && features.findIndex(x => x.toLocaleUpperCase() == perm) > -1) {
10804
- 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
+ }
10805
10850
  }
10806
10851
  }
10807
10852
  }
@@ -11061,7 +11106,7 @@
11061
11106
  if ((_a = data.AccessPermissions) === null || _a === void 0 ? void 0 : _a.length) {
11062
11107
  for (let i = 0; i < data.AccessPermissions.length; i++) {
11063
11108
  const perm = data.AccessPermissions[i];
11064
- if (!perm["UserGroup.ID"] && perm.UserGroups) {
11109
+ if (!perm["UserGroup.ID"] && perm.UserGroups && typeof perm.UserGroups != "string") {
11065
11110
  perm["UserGroup.ID"] = [];
11066
11111
  for (let j = 0; j < perm.UserGroups.length; j++) {
11067
11112
  perm["UserGroup.ID"].push(perm.UserGroups[j].ID);
@@ -13410,7 +13455,7 @@
13410
13455
  })(exports.DataSource || (exports.DataSource = {}));
13411
13456
 
13412
13457
  // This is updated with the package.json version on build.
13413
- const VERSION = "4.5.2";
13458
+ const VERSION = "4.5.4";
13414
13459
 
13415
13460
  exports.VERSION = VERSION;
13416
13461
  exports.AbstractApi = AbstractApi;