bruce-models 3.5.8 → 3.5.9

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.
@@ -1297,6 +1297,9 @@ var BruceApi;
1297
1297
  get MessageBroker() {
1298
1298
  return this.messageBroker;
1299
1299
  }
1300
+ get ConfigLoadAttempted() {
1301
+ return this.configLoadAttempted;
1302
+ }
1300
1303
  get Loading() {
1301
1304
  return this.loadProm;
1302
1305
  }
@@ -1308,16 +1311,18 @@ var BruceApi;
1308
1311
  // Load cancelled indicates the user set a custom base url.
1309
1312
  // This will stop the regional url from being set if it's still loading.
1310
1313
  this.loadCancelled = false;
1314
+ // Indicates if loading the regional configuration was already called.
1315
+ this.configLoadAttempted = false;
1311
1316
  let { accountId, env, guardian, loadRegionalBaseUrl, loadConfig, loadWebSocket } = params;
1312
1317
  this.accountId = accountId;
1313
1318
  this.env = env !== null && env !== void 0 ? env : Api.EEnv.PROD;
1319
+ // Backwards compatibility.
1314
1320
  if (loadRegionalBaseUrl) {
1315
1321
  loadConfig = true;
1316
1322
  }
1317
- if (!guardian && loadConfig) {
1318
- guardian = new GuardianApi.Api({
1319
- env: this.env
1320
- });
1323
+ if (loadConfig) {
1324
+ // Mark it as attempted right away because we don't want any external calls while it gets to that async point.
1325
+ this.configLoadAttempted = true;
1321
1326
  }
1322
1327
  this.loadProm = this.init(guardian, loadConfig, loadWebSocket);
1323
1328
  }
@@ -1328,110 +1333,142 @@ var BruceApi;
1328
1333
  * @returns
1329
1334
  */
1330
1335
  init(guardian, loadConfig, loadWebSocket) {
1331
- var _a, _b, _c;
1332
1336
  return __awaiter(this, void 0, void 0, function* () {
1333
1337
  if (!this.accountId) {
1334
1338
  throw ("accountId is required.");
1335
1339
  }
1336
- const env = this.env.toUpperCase();
1337
- let domain = "nextspace.host";
1338
- switch (env) {
1339
- case Api.EEnv.DEV:
1340
- domain = "nextspace-dev.net";
1341
- break;
1342
- case Api.EEnv.STG:
1343
- domain = "nextspace-stg.net";
1344
- break;
1345
- case Api.EEnv.UAT:
1346
- domain = "nextspace-uat.net";
1347
- break;
1348
- case Api.EEnv.PROD:
1349
- domain = "nextspace.host";
1350
- break;
1351
- default:
1352
- console.error("Specified Environment is not valid. SuppliedEnv=" + env);
1353
- }
1354
1340
  // Set using a stable default.
1341
+ const domain = this.getDomain();
1355
1342
  this.baseUrl = `https://${this.accountId}.api.${domain}/`;
1356
- if (guardian && loadConfig) {
1343
+ // Attempt to load regional configuration.
1344
+ if (loadConfig) {
1345
+ yield this.LoadConfig({
1346
+ guardian: guardian,
1347
+ // We marked it as attempted to load outside this method to fight any external calls.
1348
+ // So we'll force load it now.
1349
+ forceLoad: true
1350
+ });
1351
+ }
1352
+ // Start web socket connection.
1353
+ if (loadWebSocket != false) {
1357
1354
  try {
1358
- const host = yield HostingLocation.GetByAccountId({
1359
- accountId: this.accountId,
1360
- api: guardian
1355
+ this.messageBroker = new MessageBroker.WebSocketBroker(this.baseUrl, this.env);
1356
+ }
1357
+ catch (e) {
1358
+ console.warn("BruceApi: Failed to create message broker.", e);
1359
+ }
1360
+ }
1361
+ });
1362
+ }
1363
+ getDomain() {
1364
+ const env = this.env.toUpperCase();
1365
+ let domain = "nextspace.host";
1366
+ switch (env) {
1367
+ case Api.EEnv.DEV:
1368
+ domain = "nextspace-dev.net";
1369
+ break;
1370
+ case Api.EEnv.STG:
1371
+ domain = "nextspace-stg.net";
1372
+ break;
1373
+ case Api.EEnv.UAT:
1374
+ domain = "nextspace-uat.net";
1375
+ break;
1376
+ case Api.EEnv.PROD:
1377
+ domain = "nextspace.host";
1378
+ break;
1379
+ default:
1380
+ console.error("Specified Environment is not valid. SuppliedEnv=" + env);
1381
+ }
1382
+ return domain;
1383
+ }
1384
+ /**
1385
+ * Loads the regional configuration for the account.
1386
+ * If the config is already loaded then this will do nothing.
1387
+ */
1388
+ LoadConfig(params) {
1389
+ var _a, _b, _c;
1390
+ return __awaiter(this, void 0, void 0, function* () {
1391
+ let { guardian, forceLoad } = (params !== null && params !== void 0 ? params : {});
1392
+ if (this.configLoadAttempted && forceLoad != true) {
1393
+ return;
1394
+ }
1395
+ this.configLoadAttempted = true;
1396
+ try {
1397
+ if (!guardian) {
1398
+ guardian = new GuardianApi.Api({
1399
+ env: this.env
1361
1400
  });
1362
- if (host === null || host === void 0 ? void 0 : host.location) {
1363
- const settings = host.location.Settings;
1364
- if (!this.loadCancelled) {
1365
- // Attempt to load regional base url.
1366
- // First try go through settings.
1367
- let urlSet = false;
1368
- if (settings === null || settings === void 0 ? void 0 : settings.BruceAPIURL) {
1369
- let envUrl = settings.BruceAPIURL[env];
1370
- if (envUrl) {
1371
- envUrl = envUrl
1372
- .replace("<ACCOUNTID>", this.accountId)
1373
- .replace("<ACCOUNT>", this.accountId);
1374
- if (envUrl && envUrl.length > 1) {
1375
- this.baseUrl = envUrl;
1376
- urlSet = true;
1377
- }
1378
- }
1379
- }
1380
- // Try go through host location's base url.
1381
- // This may be wrong env which is why it's used as fallback right now.
1382
- if (!urlSet && host.location.BruceAPIURL) {
1383
- const regionalUrl = host.location.BruceAPIURL
1401
+ }
1402
+ const env = this.env.toUpperCase();
1403
+ const domain = this.getDomain();
1404
+ const host = yield HostingLocation.GetByAccountId({
1405
+ accountId: this.accountId,
1406
+ api: guardian
1407
+ });
1408
+ if (host === null || host === void 0 ? void 0 : host.location) {
1409
+ const settings = host.location.Settings;
1410
+ if (!this.loadCancelled) {
1411
+ // Attempt to load regional base url.
1412
+ // First try go through settings.
1413
+ let urlSet = false;
1414
+ if (settings === null || settings === void 0 ? void 0 : settings.BruceAPIURL) {
1415
+ let envUrl = settings.BruceAPIURL[env];
1416
+ if (envUrl) {
1417
+ envUrl = envUrl
1384
1418
  .replace("<ACCOUNTID>", this.accountId)
1385
- .replace("<ACCOUNT>", this.accountId)
1386
- .replace("<DOMAIN>", domain);
1387
- if (regionalUrl && regionalUrl.length > 1) {
1388
- this.baseUrl = regionalUrl;
1419
+ .replace("<ACCOUNT>", this.accountId);
1420
+ if (envUrl && envUrl.length > 1) {
1421
+ this.baseUrl = envUrl;
1389
1422
  urlSet = true;
1390
1423
  }
1391
1424
  }
1392
1425
  }
1393
- // Attempt to load CDN settings.
1394
- if (settings === null || settings === void 0 ? void 0 : settings.CDN) {
1395
- this.EntityCdnUrl = (_a = settings.CDN.entityURL) === null || _a === void 0 ? void 0 : _a[env];
1396
- // We need to fix our configs.
1397
- if (this.EntityCdnUrl) {
1398
- if (this.EntityCdnUrl.includes("entitiesListForCDN")) {
1399
- this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", this.accountId);
1400
- }
1401
- else {
1402
- this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", "entitiesListForCDN/" + this.accountId);
1403
- }
1426
+ // Try go through host location's base url.
1427
+ // This may be wrong env which is why it's used as fallback right now.
1428
+ if (!urlSet && host.location.BruceAPIURL) {
1429
+ const regionalUrl = host.location.BruceAPIURL
1430
+ .replace("<ACCOUNTID>", this.accountId)
1431
+ .replace("<ACCOUNT>", this.accountId)
1432
+ .replace("<DOMAIN>", domain);
1433
+ if (regionalUrl && regionalUrl.length > 1) {
1434
+ this.baseUrl = regionalUrl;
1435
+ urlSet = true;
1436
+ }
1437
+ }
1438
+ }
1439
+ // Attempt to load CDN settings.
1440
+ if (settings === null || settings === void 0 ? void 0 : settings.CDN) {
1441
+ this.EntityCdnUrl = (_a = settings.CDN.entityURL) === null || _a === void 0 ? void 0 : _a[env];
1442
+ // We need to fix our configs.
1443
+ if (this.EntityCdnUrl) {
1444
+ if (this.EntityCdnUrl.includes("entitiesListForCDN")) {
1445
+ this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", this.accountId);
1404
1446
  }
1405
- this.LegacyTilesetCdnUrl = (_b = settings.CDN.legacyTilesetURL) === null || _b === void 0 ? void 0 : _b[env];
1406
- this.TilesetCdnUrl = (_c = settings.CDN.tilesetURL) === null || _c === void 0 ? void 0 : _c[env];
1407
- if (this.TilesetCdnUrl) {
1408
- this.TilesetCdnUrl = this.TilesetCdnUrl.replace("<ACCOUNT>", this.accountId);
1447
+ else {
1448
+ this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", "entitiesListForCDN/" + this.accountId);
1409
1449
  }
1410
- // TilesetCdnUrl example: "https://blah.cloudfront.net/tilesets/<TILESETID>/files/<FILEPATH>?accountId=<ACCOUNT>".
1411
- // Lazy at the moment to go around updating every region we have, I'll interpret the url from tilesetCdnUrl.
1412
- if (this.TilesetCdnUrl) {
1413
- try {
1414
- const url = new URL(this.TilesetCdnUrl);
1415
- this.cdnBaseUrl = `${url.protocol}//${url.hostname}/`;
1416
- }
1417
- catch (e) {
1418
- console.error(e);
1419
- }
1450
+ }
1451
+ this.LegacyTilesetCdnUrl = (_b = settings.CDN.legacyTilesetURL) === null || _b === void 0 ? void 0 : _b[env];
1452
+ this.TilesetCdnUrl = (_c = settings.CDN.tilesetURL) === null || _c === void 0 ? void 0 : _c[env];
1453
+ if (this.TilesetCdnUrl) {
1454
+ this.TilesetCdnUrl = this.TilesetCdnUrl.replace("<ACCOUNT>", this.accountId);
1455
+ }
1456
+ // TilesetCdnUrl example: "https://blah.cloudfront.net/tilesets/<TILESETID>/files/<FILEPATH>?accountId=<ACCOUNT>".
1457
+ // Lazy at the moment to go around updating every region we have, I'll interpret the url from tilesetCdnUrl.
1458
+ if (this.TilesetCdnUrl) {
1459
+ try {
1460
+ const url = new URL(this.TilesetCdnUrl);
1461
+ this.cdnBaseUrl = `${url.protocol}//${url.hostname}/`;
1462
+ }
1463
+ catch (e) {
1464
+ console.error(e);
1420
1465
  }
1421
1466
  }
1422
1467
  }
1423
1468
  }
1424
- catch (e) {
1425
- console.error(e);
1426
- }
1427
1469
  }
1428
- if (loadWebSocket != false) {
1429
- try {
1430
- this.messageBroker = new MessageBroker.WebSocketBroker(this.baseUrl, this.env);
1431
- }
1432
- catch (e) {
1433
- console.warn("BruceApi: Failed to create message broker.", e);
1434
- }
1470
+ catch (e) {
1471
+ console.error(e);
1435
1472
  }
1436
1473
  });
1437
1474
  }
@@ -1746,6 +1783,17 @@ class ApiGetters {
1746
1783
  */
1747
1784
  SetAccountId(accountId) {
1748
1785
  this.accountId = accountId;
1786
+ // Queue load of regional config in case an instance was made earlier without it.
1787
+ // We want the default account to always go through the fastest regional endpoint.
1788
+ const api = this.GetBruceApi({
1789
+ accountId: accountId,
1790
+ loadConfig: true
1791
+ });
1792
+ api.LoadConfig({
1793
+ guardian: this.GetGuardianApi({
1794
+ env: this.env
1795
+ })
1796
+ });
1749
1797
  }
1750
1798
  /**
1751
1799
  * Returns the default account ID to use when one is unspecified.
@@ -1810,7 +1858,9 @@ class ApiGetters {
1810
1858
  this.bruce[key] = new BruceApi.Api({
1811
1859
  accountId,
1812
1860
  env,
1813
- loadConfig: loadConfig,
1861
+ // We'll load regional config if the accountId matches the default accountId.
1862
+ // We'll also load if it no default is known.
1863
+ loadConfig: loadConfig != null ? loadConfig : (this.accountId == accountId || !this.accountId),
1814
1864
  loadWebSocket: loadWebSocket,
1815
1865
  guardian: this.GetGuardianApi({
1816
1866
  env
@@ -1834,8 +1884,9 @@ class ApiGetters {
1834
1884
  return this.GetBruceApi({
1835
1885
  accountId,
1836
1886
  env,
1837
- loadWebSocket: this.accountId == accountId,
1838
- loadConfig: this.accountId == accountId
1887
+ // We'll load regional config if the accountId matches the default accountId.
1888
+ // We'll also load if it no default is known.
1889
+ loadConfig: this.accountId == accountId || !this.accountId
1839
1890
  });
1840
1891
  }
1841
1892
  };
@@ -4028,7 +4079,7 @@ var Calculator;
4028
4079
  str: value,
4029
4080
  entity: entity
4030
4081
  });
4031
- const isJsEval = typeof value == "string" && value.startsWith("JS:");
4082
+ const isJsEval = value.startsWith("JS:");
4032
4083
  const MATH_REGEX = /(\d+\.?\d*|\.\d+)([+\-*/])(\d+\.?\d*|\.\d+)/;
4033
4084
  const isMathEval = isJsEval || MATH_REGEX.test(value);
4034
4085
  if (isJsEval || isMathEval) {
@@ -10892,7 +10943,7 @@ var DataSource;
10892
10943
  })(DataSource || (DataSource = {}));
10893
10944
 
10894
10945
  // This is updated with the package.json version on build.
10895
- const VERSION = "3.5.8";
10946
+ const VERSION = "3.5.9";
10896
10947
 
10897
10948
  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 };
10898
10949
  //# sourceMappingURL=bruce-models.es5.js.map