bruce-models 1.4.9 → 1.5.1

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.
@@ -476,11 +476,14 @@ function parseResult(data) {
476
476
  encoding = charset.split("=")[1];
477
477
  encoding = encoding.toLowerCase();
478
478
  }
479
+ if (!encoding) {
480
+ return null;
481
+ }
479
482
  // Our API has a very specific utf-16 encoding.
480
483
  if (encoding == "utf-16") {
481
484
  encoding = Api.EEncoding.UTF16;
482
485
  }
483
- if (!encoding || encoding == "utf-8") {
486
+ if (encoding == "utf-8") {
484
487
  return data.json();
485
488
  }
486
489
  else {
@@ -498,10 +501,20 @@ function parseResult(data) {
498
501
  * This is a base class for communication with an arbitrary Bruce Api.
499
502
  */
500
503
  class AbstractApi {
501
- constructor(ssidHeader) {
504
+ constructor(params) {
502
505
  this.ssid = "";
506
+ this.baseUrl = "";
503
507
  this.Cache = new CacheControl();
504
- this.ssidHeader = ssidHeader;
508
+ this.ssidHeader = params === null || params === void 0 ? void 0 : params.ssidHeader;
509
+ }
510
+ GetBaseUrl() {
511
+ return this.baseUrl;
512
+ }
513
+ SetBaseUrl(url) {
514
+ this.baseUrl = url;
515
+ if (!this.baseUrl.endsWith("/")) {
516
+ this.baseUrl += "/";
517
+ }
505
518
  }
506
519
  GetCacheItem(key, reqParams) {
507
520
  let noCache = reqParams === null || reqParams === void 0 ? void 0 : reqParams.noCache;
@@ -975,17 +988,17 @@ var BruceApi;
975
988
  */
976
989
  class Api$$1 extends AbstractApi {
977
990
  /**
978
- * @param accountId
979
- * @param env (Optional) environment to use, this will default to PROD.
980
- * @param cam (Optional) cam instance to use for loading the regional base url.
991
+ * @param params
981
992
  */
982
- constructor(accountId, env, cam) {
983
- super("x-sessionid");
984
- this.baseUrl = "";
993
+ constructor(params) {
994
+ super({
995
+ ssidHeader: "x-sessionid"
996
+ });
985
997
  this.loadCancelled = false;
998
+ const { accountId, env, cam, loadRegionalBaseUrl } = params;
986
999
  this.accountId = accountId;
987
1000
  this.env = env !== null && env !== void 0 ? env : Api.EEnv.PROD;
988
- this.loadProm = this.init(cam);
1001
+ this.loadProm = this.init(cam, loadRegionalBaseUrl);
989
1002
  }
990
1003
  get MessageBroker() {
991
1004
  return this.messageBroker;
@@ -998,11 +1011,15 @@ var BruceApi;
998
1011
  /**
999
1012
  * Loads regional base url and sets up message broker.
1000
1013
  * @param cam Required for loading regional base url.
1014
+ * @param loadRegionalUrl
1001
1015
  * @returns
1002
1016
  */
1003
- init(cam) {
1017
+ init(cam, loadRegionalUrl) {
1004
1018
  var _a;
1005
1019
  return __awaiter(this, void 0, void 0, function* () {
1020
+ if (!this.accountId) {
1021
+ throw ("accountId is required.");
1022
+ }
1006
1023
  // Set using a stable default.
1007
1024
  const prefix = `https://${this.accountId}.api.nextspace`;
1008
1025
  let url;
@@ -1024,7 +1041,7 @@ var BruceApi;
1024
1041
  throw ("Specified Environment is not valid. SuppliedEnv=" + env);
1025
1042
  }
1026
1043
  this.baseUrl = url;
1027
- if (cam) {
1044
+ if (cam && loadRegionalUrl) {
1028
1045
  // Attempt to load an account specific base url.
1029
1046
  // This could be one with a region specific endpoint.
1030
1047
  try {
@@ -1136,10 +1153,11 @@ var BruceApi;
1136
1153
  var CamApi;
1137
1154
  (function (CamApi) {
1138
1155
  class Api$$1 extends AbstractApi {
1139
- constructor(env) {
1140
- super("SSID");
1141
- this.baseUrl = "";
1142
- this.env = env !== null && env !== void 0 ? env : Api.EEnv.PROD;
1156
+ constructor(params) {
1157
+ super({
1158
+ ssidHeader: "SSID"
1159
+ });
1160
+ this.env = (params === null || params === void 0 ? void 0 : params.env) ? params.env : Api.EEnv.PROD;
1143
1161
  this.setBaseUrl();
1144
1162
  }
1145
1163
  setBaseUrl() {
@@ -1204,10 +1222,11 @@ var IdmApi;
1204
1222
  * it should be passed to any method that wants to communicate with this particular api.
1205
1223
  */
1206
1224
  class Api$$1 extends AbstractApi {
1207
- constructor(env) {
1208
- super("SSID");
1209
- this.baseUrl = "";
1210
- this.env = env !== null && env !== void 0 ? env : Api.EEnv.PROD;
1225
+ constructor(params) {
1226
+ super({
1227
+ ssidHeader: "SSID"
1228
+ });
1229
+ this.env = (params === null || params === void 0 ? void 0 : params.env) ? params.env : Api.EEnv.PROD;
1211
1230
  this.setBaseUrl();
1212
1231
  }
1213
1232
  setBaseUrl() {
@@ -1272,10 +1291,11 @@ var GlobalApi;
1272
1291
  * it should be passed to any method that wants to communicate with this particular api.
1273
1292
  */
1274
1293
  class Api$$1 extends AbstractApi {
1275
- constructor(env) {
1276
- super("x-sessionid");
1277
- this.baseUrl = "";
1278
- this.env = env !== null && env !== void 0 ? env : Api.EEnv.PROD;
1294
+ constructor(params) {
1295
+ super({
1296
+ ssidHeader: "x-sessionid"
1297
+ });
1298
+ this.env = (params === null || params === void 0 ? void 0 : params.env) ? params.env : Api.EEnv.PROD;
1279
1299
  this.setBaseUrl();
1280
1300
  }
1281
1301
  setBaseUrl() {