bruce-models 2.0.0 → 2.0.2

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.
@@ -916,6 +916,44 @@ var Account;
916
916
  });
917
917
  }
918
918
  Account.GetDbRegions = GetDbRegions;
919
+ function GuessDbLocation(params) {
920
+ const { DBServer: databaseUrl } = params;
921
+ if (databaseUrl.includes("hyperfarm-prod-instance-1")) {
922
+ return "HYPERFARM";
923
+ }
924
+ if (databaseUrl.includes("prod-syd1.nextspace.host")) {
925
+ return "AU-VULTR-FIRST";
926
+ }
927
+ else if (databaseUrl.includes("prod-nyc1.nextspace.host")) {
928
+ return "US-VULTR-FIRST";
929
+ }
930
+ else if (databaseUrl.includes("prod-ams1.nextspace.host")) {
931
+ return "EU-VULTR-FIRST";
932
+ }
933
+ else if (databaseUrl.includes("prod-sing1.nextspace.host")) {
934
+ return "SE-VULTR-FIRST";
935
+ }
936
+ else if (databaseUrl.includes("dev-first")) {
937
+ return "DEV-FIRST";
938
+ }
939
+ else if (databaseUrl.includes(".ap-southeast-1.")) {
940
+ return "SE";
941
+ }
942
+ else if (databaseUrl.includes(".us-west-1.")) {
943
+ return "US";
944
+ }
945
+ else if (databaseUrl.includes(".eu-west-3.")) {
946
+ return "EU";
947
+ }
948
+ else if (databaseUrl.includes("bruce-prod-au")) {
949
+ return "AU";
950
+ }
951
+ else if (databaseUrl.includes("bruce-dev")) {
952
+ return "DEV";
953
+ }
954
+ return null;
955
+ }
956
+ Account.GuessDbLocation = GuessDbLocation;
919
957
  })(Account || (Account = {}));
920
958
 
921
959
  /**
@@ -1218,31 +1256,41 @@ var BruceApi;
1218
1256
  }
1219
1257
  this.baseUrl = endpoint;
1220
1258
  }
1221
- const api = new BruceApi.Api({
1222
- accountId: this.accountId,
1223
- cam: cam,
1224
- env: this.env,
1225
- // Must be false.
1226
- // Else we get stuck in nested init loop.
1227
- loadConfig: false
1228
- });
1229
- // CDN urls.
1230
- const region = (yield Account.GetDbRegions({
1231
- api,
1232
- key: settings.DBServer
1233
- })).regions[0];
1234
- if (region === null || region === void 0 ? void 0 : region.CDN) {
1235
- this.EntityCdnUrl = (_b = region.CDN.entityURL) === null || _b === void 0 ? void 0 : _b[env];
1236
- // We need to fix our configs.
1237
- if (this.EntityCdnUrl) {
1238
- if (this.EntityCdnUrl.includes("entitiesListForCDN")) {
1239
- this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", this.accountId);
1240
- }
1241
- else {
1242
- this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", "entitiesListForCDN/" + this.accountId);
1259
+ let dbLocation = settings.DBLocation;
1260
+ if (!dbLocation) {
1261
+ dbLocation = Account.GuessDbLocation({
1262
+ DBServer: settings.DBServer,
1263
+ });
1264
+ }
1265
+ if (dbLocation) {
1266
+ dbLocation = dbLocation.trim();
1267
+ const api = new BruceApi.Api({
1268
+ accountId: this.accountId,
1269
+ cam: cam,
1270
+ env: this.env,
1271
+ // Must be false.
1272
+ // Else we get stuck in nested init loop.
1273
+ loadConfig: false
1274
+ });
1275
+ // CDN urls.
1276
+ const regions = (yield Account.GetDbRegions({
1277
+ api,
1278
+ key: dbLocation
1279
+ })).regions;
1280
+ const region = regions.find(x => { var _a; return ((_a = x.key) === null || _a === void 0 ? void 0 : _a.trim()) == dbLocation; });
1281
+ if (region === null || region === void 0 ? void 0 : region.CDN) {
1282
+ this.EntityCdnUrl = (_b = region.CDN.entityURL) === null || _b === void 0 ? void 0 : _b[env];
1283
+ // We need to fix our configs.
1284
+ if (this.EntityCdnUrl) {
1285
+ if (this.EntityCdnUrl.includes("entitiesListForCDN")) {
1286
+ this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", this.accountId);
1287
+ }
1288
+ else {
1289
+ this.EntityCdnUrl = this.EntityCdnUrl.replace("<ACCOUNT>", "entitiesListForCDN/" + this.accountId);
1290
+ }
1243
1291
  }
1292
+ this.LegacyTilesetCdnUrl = (_c = region.CDN.legacyTilesetURL) === null || _c === void 0 ? void 0 : _c[env];
1244
1293
  }
1245
- this.LegacyTilesetCdnUrl = (_c = region.CDN.legacyTilesetURL) === null || _c === void 0 ? void 0 : _c[env];
1246
1294
  }
1247
1295
  }
1248
1296
  catch (e) {