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