bruce-models 3.2.5 → 3.2.7

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.
@@ -1142,13 +1142,28 @@ var HostingLocation;
1142
1142
  */
1143
1143
  function GetKeyByAccountId(params) {
1144
1144
  return __awaiter(this, void 0, void 0, function* () {
1145
- let { accountId, apiSettings, api, req } = params;
1145
+ let { accountId, apiSettings, api, account, req } = params;
1146
1146
  if (!accountId && !apiSettings) {
1147
1147
  throw ("Invalid accountId or apiSettings");
1148
1148
  }
1149
1149
  if (!api) {
1150
1150
  api = ENVIRONMENT.Api().GetGuardianApi();
1151
1151
  }
1152
+ // We'll prioritize account record if provided.
1153
+ if (accountId && !account) {
1154
+ account = (yield Account.Get({
1155
+ accountId,
1156
+ api,
1157
+ req
1158
+ })).account;
1159
+ }
1160
+ if (account === null || account === void 0 ? void 0 : account["HostingLocation.Key"]) {
1161
+ return {
1162
+ key: account["HostingLocation.Key"],
1163
+ isLegacy: false
1164
+ };
1165
+ }
1166
+ // Fallback to settings JSON for older records.
1152
1167
  const settings = apiSettings ? apiSettings : (yield Account.GetAppSettings({
1153
1168
  api,
1154
1169
  accountId,
@@ -1180,12 +1195,13 @@ var HostingLocation;
1180
1195
  */
1181
1196
  function GetByAccountId(params) {
1182
1197
  return __awaiter(this, void 0, void 0, function* () {
1183
- let { accountId, apiSettings, api, req } = params;
1198
+ let { accountId, apiSettings, api, req, account } = params;
1184
1199
  if (!api) {
1185
1200
  api = ENVIRONMENT.Api().GetGuardianApi();
1186
1201
  }
1187
1202
  const data = yield GetKeyByAccountId({
1188
1203
  accountId,
1204
+ account,
1189
1205
  apiSettings,
1190
1206
  api,
1191
1207
  req
@@ -1376,6 +1392,25 @@ var BruceApi;
1376
1392
  GetCdnBaseUrl() {
1377
1393
  return this.cdnBaseUrl;
1378
1394
  }
1395
+ /**
1396
+ * Returns a url routed through the API's CDN.
1397
+ * If the CDN is not enabled for the account, this will return null.
1398
+ * @param url suffix to append to the base url.
1399
+ * @param urlParams
1400
+ * @returns
1401
+ */
1402
+ ConstructCdnUrl(url, urlParams) {
1403
+ if (!this.cdnBaseUrl) {
1404
+ return null;
1405
+ }
1406
+ let cdnUrl = this.cdnBaseUrl + url;
1407
+ if (!urlParams) {
1408
+ urlParams = new URLSearchParams();
1409
+ }
1410
+ urlParams.set("accountId", this.accountId);
1411
+ cdnUrl += "?" + urlParams.toString();
1412
+ return cdnUrl;
1413
+ }
1379
1414
  /**
1380
1415
  * Warning: This will cancel the init process.
1381
1416
  * The init process loads a region specific endpoint.
@@ -1689,7 +1724,7 @@ class ApiGetters {
1689
1724
  if (!params) {
1690
1725
  params = {};
1691
1726
  }
1692
- let { accountId, env } = params;
1727
+ let { accountId, env, loadConfig, loadWebSocket } = params;
1693
1728
  accountId = accountId ? accountId : this.accountId;
1694
1729
  env = env ? env : this.env;
1695
1730
  const key = `${accountId}-${env}`;
@@ -1697,7 +1732,11 @@ class ApiGetters {
1697
1732
  this.bruce[key] = new BruceApi.Api({
1698
1733
  accountId,
1699
1734
  env,
1700
- loadRegionalBaseUrl: true
1735
+ loadConfig: loadConfig,
1736
+ loadWebSocket: loadWebSocket,
1737
+ guardian: this.GetGuardianApi({
1738
+ env
1739
+ }),
1701
1740
  });
1702
1741
  this.bruce[key].SetSessionId(this.sessionId);
1703
1742
  }
@@ -1714,7 +1753,12 @@ class ApiGetters {
1714
1753
  accountId: this.accountId,
1715
1754
  env: this.env,
1716
1755
  getApi: (accountId, env) => {
1717
- return this.GetBruceApi({ accountId, env });
1756
+ return this.GetBruceApi({
1757
+ accountId,
1758
+ env,
1759
+ loadWebSocket: this.accountId == accountId,
1760
+ loadConfig: this.accountId == accountId
1761
+ });
1718
1762
  }
1719
1763
  };
1720
1764
  }
@@ -2933,6 +2977,27 @@ var Entity;
2933
2977
  return null;
2934
2978
  }
2935
2979
  Entity.GetValue = GetValue;
2980
+ /**
2981
+ * Removes a value from an entity.
2982
+ * This will mutate the entity record and run "delete" on the object property.
2983
+ * @param params
2984
+ */
2985
+ function RemoveValue(params) {
2986
+ const { entity: data, path } = params;
2987
+ let curData = data;
2988
+ for (let i = 0; i < path.length; i++) {
2989
+ const step = path[i];
2990
+ if (!curData[step]) {
2991
+ return;
2992
+ }
2993
+ if (i >= path.length - 1) {
2994
+ delete curData[step];
2995
+ return;
2996
+ }
2997
+ curData = curData[step];
2998
+ }
2999
+ }
3000
+ Entity.RemoveValue = RemoveValue;
2936
3001
  /**
2937
3002
  * Calculates an entity's name based on attribute priority set in the type.
2938
3003
  * @param params
@@ -6188,6 +6253,69 @@ var EntityAttribute;
6188
6253
  return GetAttribute(item.Structure, path.slice(1));
6189
6254
  }
6190
6255
  EntityAttribute.GetAttribute = GetAttribute;
6256
+ /**
6257
+ * Removes an attribute from a provided hierarchy of attributes.
6258
+ * Eg: Use the path: ["Bruce", "ID"] to remove the "ID" attribute.
6259
+ * This will mutate the items array.
6260
+ * @param items
6261
+ * @param path
6262
+ */
6263
+ function RemoveAttribute(items, path) {
6264
+ if (!items || !path || !path.length) {
6265
+ return;
6266
+ }
6267
+ const key = path[0];
6268
+ if (path.length === 1) {
6269
+ // If we're at the last key in the path, remove the item from the items array.
6270
+ const index = items.findIndex((i) => i.Key === key);
6271
+ if (index !== -1) {
6272
+ items.splice(index, 1);
6273
+ }
6274
+ return;
6275
+ }
6276
+ // If we're not at the end of the path, dig further.
6277
+ const item = items.find((i) => i.Key === key);
6278
+ if (item && item.Structure) {
6279
+ RemoveAttribute(item.Structure, path.slice(1));
6280
+ }
6281
+ }
6282
+ EntityAttribute.RemoveAttribute = RemoveAttribute;
6283
+ /**
6284
+ * Adds an attribute to a provided hierarchy of attributes.
6285
+ * Eg: Use the path: ["Bruce", "ID"] to add the "ID" attribute.
6286
+ * This will mutate the items array.
6287
+ * This requires the path to be valid and for a parent attribute to exist.
6288
+ * @param items
6289
+ * @param path
6290
+ * @param attribute
6291
+ */
6292
+ function AddAttribute(items, path, attribute) {
6293
+ const key = path[0];
6294
+ if (path.length === 1) {
6295
+ // If we're at the last key in the path, add the attribute to the items array.
6296
+ const index = items.findIndex((i) => i.Key === key);
6297
+ if (index !== -1) {
6298
+ // Overwrite existing attribute if it already exists.
6299
+ items[index] = attribute;
6300
+ }
6301
+ else {
6302
+ // Add new attribute if it doesn't exist.
6303
+ items.push(attribute);
6304
+ }
6305
+ return;
6306
+ }
6307
+ // If we're not at the end of the path, dig further.
6308
+ let item = items.find((i) => i.Key === key);
6309
+ if (!item) {
6310
+ item = { Key: key, Structure: [] };
6311
+ items.push(item);
6312
+ }
6313
+ if (!item.Structure) {
6314
+ item.Structure = [];
6315
+ }
6316
+ AddAttribute(item.Structure, path.slice(1), attribute);
6317
+ }
6318
+ EntityAttribute.AddAttribute = AddAttribute;
6191
6319
  })(EntityAttribute || (EntityAttribute = {}));
6192
6320
 
6193
6321
  /**
@@ -6296,11 +6424,16 @@ var ClientFile;
6296
6424
  * @returns
6297
6425
  */
6298
6426
  function GetUrl(params) {
6299
- let { api, fileId } = params;
6427
+ let { api, fileId, viaCdn } = params;
6300
6428
  if (!api) {
6301
6429
  api = ENVIRONMENT.Api().GetBruceApi();
6302
6430
  }
6303
- return `${api.GetBaseUrl()}file/${fileId}`;
6431
+ const urlSuffix = `file/${fileId}`;
6432
+ const cdnUrl = viaCdn ? api.ConstructCdnUrl(urlSuffix) : null;
6433
+ if (cdnUrl) {
6434
+ return cdnUrl;
6435
+ }
6436
+ return `${api.GetBaseUrl()}${urlSuffix}`;
6304
6437
  }
6305
6438
  ClientFile.GetUrl = GetUrl;
6306
6439
  /**
@@ -6309,11 +6442,16 @@ var ClientFile;
6309
6442
  * @returns
6310
6443
  */
6311
6444
  function GetUrlWithExt(params) {
6312
- let { api, file } = params;
6445
+ let { api, file, viaCdn } = params;
6313
6446
  if (!api) {
6314
6447
  api = ENVIRONMENT.Api().GetBruceApi();
6315
6448
  }
6316
- return `${api.GetBaseUrl()}file/${file.ID}${file.FileExt ? file.FileExt : ""}`;
6449
+ const urlSuffix = file.FileExt ? `file/${file.ID}${file.FileExt}` : `file/${file.ID}`;
6450
+ const cdnUrl = viaCdn ? api.ConstructCdnUrl(urlSuffix) : null;
6451
+ if (cdnUrl) {
6452
+ return cdnUrl;
6453
+ }
6454
+ return `${api.GetBaseUrl()}${urlSuffix}`;
6317
6455
  }
6318
6456
  ClientFile.GetUrlWithExt = GetUrlWithExt;
6319
6457
  /**
@@ -10482,7 +10620,7 @@ var DataSource;
10482
10620
  DataSource.GetList = GetList;
10483
10621
  })(DataSource || (DataSource = {}));
10484
10622
 
10485
- const VERSION = "3.2.5";
10623
+ const VERSION = "3.2.7";
10486
10624
 
10487
10625
  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, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, ProjectViewLegacyTile, ProjectViewTile, ProjectViewLegacy, ProjectViewLegacyBookmark, PendingAction, MessageBroker, HostingLocation, Style, Tileset, Permission, Session, UserGroup, User, Account, AccountInvite, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils, DataLab, ImportCad, ImportCsv, ImportJson, ImportKml, ImportedFile, Markup, Uploader, Plugin, ENVIRONMENT, DataSource };
10488
10626
  //# sourceMappingURL=bruce-models.es5.js.map