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.
@@ -85,6 +85,7 @@ var Api;
85
85
  Api.DEFAULT_CACHE_DURATION = 60 * 1000;
86
86
  // The template client account is a container for default settings to reference.
87
87
  Api.TEMPLATE_ACCOUNT_ID = "template";
88
+ Api.SUPER_ACCOUNT_ID = "hypeportal";
88
89
  // Default session token header.
89
90
  Api.ACCESS_TOKEN_HEADER = "X-Access-Token";
90
91
  /**
@@ -120,6 +121,11 @@ var Api;
120
121
  ESortOrder[ESortOrder["Asc"] = 1] = "Asc";
121
122
  ESortOrder[ESortOrder["Desc"] = -1] = "Desc";
122
123
  })(ESortOrder = Api.ESortOrder || (Api.ESortOrder = {}));
124
+ let ESortOrderStr;
125
+ (function (ESortOrderStr) {
126
+ ESortOrderStr["Asc"] = "ASC";
127
+ ESortOrderStr["Desc"] = "DESC";
128
+ })(ESortOrderStr = Api.ESortOrderStr || (Api.ESortOrderStr = {}));
123
129
  /**
124
130
  * Known response encodings from Nextspace APIs.
125
131
  */
@@ -10967,27 +10973,53 @@ var Session;
10967
10973
  * @returns
10968
10974
  */
10969
10975
  function IsPermEnabled(params) {
10970
- var _a, _b;
10976
+ var _a, _b, _c, _d, _e, _f;
10971
10977
  let { session, accountId, perm } = params;
10972
10978
  if (!perm) {
10973
10979
  throw ("Perm is required.");
10974
10980
  }
10975
10981
  perm = perm.toLocaleUpperCase();
10976
- 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);
10982
+ accountId = accountId.toLowerCase();
10983
+ // First we'll scan the user object for the account ID.
10984
+ 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) {
10985
+ for (let i = 0; i < session.User.AccessPermissions.length; i++) {
10986
+ const aPerms = session.User.AccessPermissions[i];
10987
+ const permsAccountId = String(aPerms["ClientAccount.ID"]).toLowerCase();
10988
+ // Found account, woo.
10989
+ if (permsAccountId == accountId) {
10990
+ // Check against the loaded perm array.
10991
+ // In newer version this always exists, but in some legacy versions it MIGHT not,
10992
+ //therefor we also do a group check after..
10993
+ if ((_c = aPerms.EnabledFeatures) === null || _c === void 0 ? void 0 : _c.length) {
10994
+ return aPerms.EnabledFeatures.findIndex(x => x.toLocaleUpperCase() == perm) > -1;
10995
+ }
10996
+ // Fallback to group check.
10997
+ if (((_d = aPerms.UserGroups) === null || _d === void 0 ? void 0 : _d.length) && typeof aPerms.UserGroups[0] != "string") {
10998
+ for (let j = 0; j < aPerms.UserGroups.length; j++) {
10999
+ const group = aPerms.UserGroups[j];
11000
+ if ((_e = group === null || group === void 0 ? void 0 : group.Features) === null || _e === void 0 ? void 0 : _e.length) {
11001
+ const gPerms = group.Features;
11002
+ if (gPerms && gPerms.findIndex(x => x.toLocaleUpperCase() == perm) > -1) {
11003
+ return true;
11004
+ }
11005
+ }
11006
+ }
11007
+ }
11008
+ }
11009
+ }
11010
+ }
11011
+ // Fallback to the session perm info.
11012
+ // This is deprecated and old as it's only for one account.
11013
+ const perms = session === null || session === void 0 ? void 0 : session.AccessPermissions;
10977
11014
  if (!perms) {
10978
11015
  return false;
10979
11016
  }
10980
- if (!perms.UserGroups) {
10981
- perms.UserGroups = [];
11017
+ const pAccountId = String(perms["ClientAccount.ID"]).toLowerCase();
11018
+ if (pAccountId != accountId) {
11019
+ return false;
10982
11020
  }
10983
- for (let i = 0; i < perms.UserGroups.length; i++) {
10984
- const group = perms.UserGroups[i];
10985
- if (typeof group != "string") {
10986
- const features = group.Features;
10987
- if (features && features.findIndex(x => x.toLocaleUpperCase() == perm) > -1) {
10988
- return true;
10989
- }
10990
- }
11021
+ if ((_f = perms.EnabledFeatures) === null || _f === void 0 ? void 0 : _f.length) {
11022
+ return perms.EnabledFeatures.findIndex(x => x.toLocaleUpperCase() == perm) > -1;
10991
11023
  }
10992
11024
  return false;
10993
11025
  }
@@ -11009,22 +11041,35 @@ var Session;
11009
11041
  return false;
11010
11042
  }
11011
11043
  perm = perm.toLocaleUpperCase();
11012
- // We'll look for 'HypeportalAccessPermisssions' first.
11013
- if ((_a = session.HypeportalAccessPermisssions) === null || _a === void 0 ? void 0 : _a.EnabledFeatures) {
11014
- const perms = session.HypeportalAccessPermisssions.EnabledFeatures;
11015
- return perms.findIndex(x => x.toLocaleUpperCase() == perm) > -1;
11016
- }
11017
- // Fallback to looking through groups.
11018
- // This is important if the user directly logged into "hypeportal" as the response differs.
11019
- else if ((_c = (_b = session.User) === null || _b === void 0 ? void 0 : _b.AccessPermissions) === null || _c === void 0 ? void 0 : _c.length) {
11020
- const perms = session.User.AccessPermissions.find(x => String(x["ClientAccount.ID"]).toLowerCase() == "hypeportal");
11021
- if ((_d = perms === null || perms === void 0 ? void 0 : perms.UserGroups) === null || _d === void 0 ? void 0 : _d.length) {
11022
- for (let j = 0; j < perms.UserGroups.length; j++) {
11023
- const group = perms.UserGroups[j];
11024
- if (typeof group != "string") {
11025
- const features = group.Features;
11026
- if (features && features.findIndex(x => x.toLocaleUpperCase() == perm) > -1) {
11027
- return true;
11044
+ // First we'll scan the included super perms.
11045
+ const superPerms = session.HypeportalAccessPermisssions;
11046
+ if ((_a = superPerms === null || superPerms === void 0 ? void 0 : superPerms.EnabledFeatures) === null || _a === void 0 ? void 0 : _a.length) {
11047
+ return superPerms.EnabledFeatures.findIndex(x => x.toLocaleUpperCase() == perm) > -1;
11048
+ }
11049
+ // Now we'll fallback to digging through group to find the super group.
11050
+ 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) {
11051
+ for (let i = 0; i < session.User.AccessPermissions.length; i++) {
11052
+ const perms = session.User.AccessPermissions[i];
11053
+ // Newer API versions always specify accountId in the collections.
11054
+ // If it's set we can do a super account check early.
11055
+ if (perms["ClientAccount.ID"] != null) {
11056
+ const pAccountId = String(perms["ClientAccount.ID"]).toLowerCase();
11057
+ if (pAccountId != Api.SUPER_ACCOUNT_ID) {
11058
+ continue;
11059
+ }
11060
+ }
11061
+ if ((_d = perms === null || perms === void 0 ? void 0 : perms.UserGroups) === null || _d === void 0 ? void 0 : _d.length) {
11062
+ for (let j = 0; j < perms.UserGroups.length; j++) {
11063
+ const group = perms.UserGroups[j];
11064
+ if (typeof group != "string") {
11065
+ const gAccountId = String(group["ClientAccount.ID"]).toLowerCase();
11066
+ if (gAccountId != Api.SUPER_ACCOUNT_ID) {
11067
+ continue;
11068
+ }
11069
+ const features = group.Features;
11070
+ if (features && features.findIndex(x => x.toLocaleUpperCase() == perm) > -1) {
11071
+ return true;
11072
+ }
11028
11073
  }
11029
11074
  }
11030
11075
  }
@@ -11297,7 +11342,7 @@ var User;
11297
11342
  if ((_a = data.AccessPermissions) === null || _a === void 0 ? void 0 : _a.length) {
11298
11343
  for (let i = 0; i < data.AccessPermissions.length; i++) {
11299
11344
  const perm = data.AccessPermissions[i];
11300
- if (!perm["UserGroup.ID"] && perm.UserGroups) {
11345
+ if (!perm["UserGroup.ID"] && perm.UserGroups && typeof perm.UserGroups != "string") {
11301
11346
  perm["UserGroup.ID"] = [];
11302
11347
  for (let j = 0; j < perm.UserGroups.length; j++) {
11303
11348
  perm["UserGroup.ID"].push(perm.UserGroups[j].ID);
@@ -13681,7 +13726,7 @@ var DataSource;
13681
13726
  })(DataSource || (DataSource = {}));
13682
13727
 
13683
13728
  // This is updated with the package.json version on build.
13684
- const VERSION = "4.5.2";
13729
+ const VERSION = "4.5.4";
13685
13730
 
13686
13731
  export { VERSION, AnnDocument, CustomForm, AbstractApi, Api, BruceApi, GlobalApi, GuardianApi, ApiGetters, Calculator, Bounds, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, BruceVariable, LRUCache, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityLodCategory, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityCoords, EntityTypeVisualSettings, EntityAttribute, EntityHistoricData, EntityTableView, Comment, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, ProjectViewLegacyTile, ProjectViewTile, ProjectViewLegacy, ProjectViewLegacyBookmark, PendingAction, MessageBroker, HostingLocation, Style, Tileset, Permission, Session, UserGroup, User, Account, AccountInvite, AccountFeatures, AccountLimits, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils, DataLab, ImportCad, ImportCsv, ImportJson, ImportKml, ImportedFile, Markup, Uploader, Plugin, ENVIRONMENT, DataSource };
13687
13732
  //# sourceMappingURL=bruce-models.es5.js.map