bruce-models 1.7.7 → 1.7.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.
@@ -460,12 +460,18 @@
460
460
  }
461
461
  }
462
462
 
463
+ // TODO: Currently checks for CSV vs json specifically,
464
+ // Need to see if our api is generally good at setting content-type headers.
465
+ // Make it less specific to CSV.
463
466
  function parseResult(data) {
464
467
  return __awaiter(this, void 0, void 0, function* () {
465
468
  if (data.status == 200) {
469
+ let type = data.headers.get("Content-Type");
470
+ if (type) {
471
+ type = type.trim().toLowerCase();
472
+ }
466
473
  let encoding = "";
467
- const type = data.headers.get("Content-Type");
468
- const charset = type ? type.split(";").find((x) => x.trim().toLowerCase().startsWith("charset=")) : "";
474
+ const charset = type ? type.split(";").find((x) => x.startsWith("charset=")) : "";
469
475
  if (charset && charset.includes("=")) {
470
476
  encoding = charset.split("=")[1];
471
477
  encoding = encoding.toLowerCase();
@@ -479,11 +485,18 @@
479
485
  if (!text || !text.trim()) {
480
486
  return null;
481
487
  }
488
+ if (type && type.includes("text/csv")) {
489
+ return text;
490
+ }
482
491
  return JSON.parse(text);
483
492
  }
484
493
  else {
485
494
  const buffer = yield data.arrayBuffer();
486
- return JSON.parse(new TextDecoder(encoding).decode(buffer));
495
+ const text = new TextDecoder(encoding).decode(buffer);
496
+ if (type && type.includes("text/csv")) {
497
+ return text;
498
+ }
499
+ return JSON.parse(text);
487
500
  }
488
501
  }
489
502
  else {
@@ -1057,15 +1070,18 @@
1057
1070
  ssidHeader: "x-sessionid"
1058
1071
  });
1059
1072
  this.loadCancelled = false;
1060
- let { accountId, env, cam, loadRegionalBaseUrl } = params;
1073
+ let { accountId, env, cam, loadRegionalBaseUrl, loadConfig } = params;
1061
1074
  this.accountId = accountId;
1062
1075
  this.env = env !== null && env !== void 0 ? env : exports.Api.EEnv.PROD;
1063
- if (loadRegionalBaseUrl && !cam) {
1076
+ if (loadRegionalBaseUrl) {
1077
+ loadConfig = true;
1078
+ }
1079
+ if (!cam && loadConfig) {
1064
1080
  cam = new exports.CamApi.Api({
1065
1081
  env: this.env
1066
1082
  });
1067
1083
  }
1068
- this.loadProm = this.init(cam, loadRegionalBaseUrl);
1084
+ this.loadProm = this.init(cam, loadConfig);
1069
1085
  }
1070
1086
  get MessageBroker() {
1071
1087
  return this.messageBroker;
@@ -1078,11 +1094,11 @@
1078
1094
  /**
1079
1095
  * Loads regional base url and sets up message broker.
1080
1096
  * @param cam Required for loading regional base url.
1081
- * @param loadRegionalUrl
1097
+ * @param loadConfig
1082
1098
  * @returns
1083
1099
  */
1084
- init(cam, loadRegionalUrl) {
1085
- var _a;
1100
+ init(cam, loadConfig) {
1101
+ var _a, _b, _c;
1086
1102
  return __awaiter(this, void 0, void 0, function* () {
1087
1103
  if (!this.accountId) {
1088
1104
  throw ("accountId is required.");
@@ -1108,32 +1124,47 @@
1108
1124
  throw ("Specified Environment is not valid. SuppliedEnv=" + env);
1109
1125
  }
1110
1126
  this.baseUrl = url;
1111
- if (cam) {
1112
- if (loadRegionalUrl) {
1113
- // Attempt to load an account specific base url.
1114
- // This could be one with a region specific endpoint.
1115
- try {
1116
- const settings = (yield exports.Account.GetAppSettings({
1117
- api: cam,
1118
- accountId: this.accountId,
1119
- appId: exports.Account.EAppId.BruceApi
1120
- })).settings;
1121
- if (this.loadCancelled) {
1122
- console.warn("BruceApi: Loading was cancelled due to SetBaseUrl being called, not setting regional base url.");
1123
- return;
1124
- }
1125
- let endpoint = (_a = settings.BruceAPIURL) === null || _a === void 0 ? void 0 : _a[env];
1126
- if (typeof endpoint == "string") {
1127
- if (!endpoint.endsWith("/")) {
1128
- endpoint += "/";
1129
- }
1130
- this.baseUrl = endpoint;
1127
+ if (cam && loadConfig) {
1128
+ // Attempt to load an account specific base url.
1129
+ // This could be one with a region specific endpoint.
1130
+ try {
1131
+ const settings = (yield exports.Account.GetAppSettings({
1132
+ api: cam,
1133
+ accountId: this.accountId,
1134
+ appId: exports.Account.EAppId.BruceApi
1135
+ })).settings;
1136
+ if (this.loadCancelled) {
1137
+ console.warn("BruceApi: Loading was cancelled due to SetBaseUrl being called, not setting regional base url.");
1138
+ return;
1139
+ }
1140
+ let endpoint = (_a = settings.BruceAPIURL) === null || _a === void 0 ? void 0 : _a[env];
1141
+ if (typeof endpoint == "string") {
1142
+ if (!endpoint.endsWith("/")) {
1143
+ endpoint += "/";
1131
1144
  }
1145
+ this.baseUrl = endpoint;
1132
1146
  }
1133
- catch (e) {
1134
- console.error(e);
1147
+ const api = new BruceApi.Api({
1148
+ accountId: this.accountId,
1149
+ cam: cam,
1150
+ env: this.env,
1151
+ // Must be false.
1152
+ // Else we get stuck in nested init loop.
1153
+ loadConfig: false
1154
+ });
1155
+ // CDN urls.
1156
+ const region = (yield exports.Account.GetDbRegions({
1157
+ api,
1158
+ key: settings.DBServer
1159
+ })).regions[0];
1160
+ if (region === null || region === void 0 ? void 0 : region.CDN) {
1161
+ this.EntityCdnUrl = (_b = region.CDN.entityURL) === null || _b === void 0 ? void 0 : _b[env];
1162
+ this.LegacyTilesetCdnUrl = (_c = region.CDN.legacyTilesetURL) === null || _c === void 0 ? void 0 : _c[env];
1135
1163
  }
1136
1164
  }
1165
+ catch (e) {
1166
+ console.error(e);
1167
+ }
1137
1168
  }
1138
1169
  try {
1139
1170
  this.messageBroker = new exports.MessageBroker.WebSocketBroker(this.baseUrl, this.env);