@bringg/dashboard-sdk 9.91.1-pre → 9.92.0-pre.0

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.
@@ -3433,6 +3433,19 @@ var BringgDashboardSDK = /** @class */ (function () {
3433
3433
  });
3434
3434
  });
3435
3435
  };
3436
+ BringgDashboardSDK.prototype.getSamlSignOutUrl = function () {
3437
+ return this.session.getSamlSignOutUrl();
3438
+ };
3439
+ BringgDashboardSDK.prototype.samlSignOut = function () {
3440
+ return __awaiter(this, void 0, void 0, function () {
3441
+ return __generator(this, function (_a) {
3442
+ switch (_a.label) {
3443
+ case 0: return [4 /*yield*/, this.session.samlSignOut()];
3444
+ case 1: return [2 /*return*/, _a.sent()];
3445
+ }
3446
+ });
3447
+ });
3448
+ };
3436
3449
  BringgDashboardSDK.resendConfirmationEmail = function (params) {
3437
3450
  return __awaiter(this, void 0, void 0, function () {
3438
3451
  var authService, email, password, merchant_uuid, recaptchaToken, recaptcha_qa_token;
@@ -23363,7 +23376,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23363
23376
  return (mod && mod.__esModule) ? mod : { "default": mod };
23364
23377
  };
23365
23378
  Object.defineProperty(exports, "__esModule", ({ value: true }));
23366
- exports.SEND_OTP_MAIL_ROUTE = exports.OTP_CREATE_TOKEN_ROUTE = exports.RESEND_CONFIRMATION_EMAIL_ROUTE = exports.UNWIND_ROUTE = exports.IMPERSONATE_BY_TEAM_ROUTE = exports.IMPERSONATE_ROUTE = exports.SWITCH_ROUTE = exports.LOGOUT_ROUTE = exports.GET_USER_ROUTE = exports.CREATE_TOKEN_ONE_TIME_CODE_ROUTE = exports.CREATE_TOKEN_ROUTE = void 0;
23379
+ exports.SAML_SIGN_OUT_ROUTE = exports.SEND_OTP_MAIL_ROUTE = exports.OTP_CREATE_TOKEN_ROUTE = exports.RESEND_CONFIRMATION_EMAIL_ROUTE = exports.UNWIND_ROUTE = exports.IMPERSONATE_BY_TEAM_ROUTE = exports.IMPERSONATE_ROUTE = exports.SWITCH_ROUTE = exports.LOGOUT_ROUTE = exports.GET_USER_ROUTE = exports.CREATE_TOKEN_ONE_TIME_CODE_ROUTE = exports.CREATE_TOKEN_ROUTE = void 0;
23367
23380
  var lodash_1 = __webpack_require__(96486);
23368
23381
  var sha1_1 = __importDefault(__webpack_require__(18738));
23369
23382
  var BringgDashboardSDK_1 = __webpack_require__(5655);
@@ -23385,6 +23398,7 @@ exports.UNWIND_ROUTE = new Route_1.Route('/tokens/unwind_impersonate', 1 /* Http
23385
23398
  exports.RESEND_CONFIRMATION_EMAIL_ROUTE = new Route_1.Route('/tokens/resend_confirmation_email', 1 /* HttpMethod.POST */);
23386
23399
  exports.OTP_CREATE_TOKEN_ROUTE = new Route_1.Route('/otp', 1 /* HttpMethod.POST */);
23387
23400
  exports.SEND_OTP_MAIL_ROUTE = new Route_1.Route('/otp/send', 1 /* HttpMethod.POST */);
23401
+ exports.SAML_SIGN_OUT_ROUTE = new Route_1.Route('/users/saml/idp_sign_out', 0 /* HttpMethod.GET */);
23388
23402
  var AuthService = /** @class */ (function () {
23389
23403
  function AuthService(clientId, endpoint) {
23390
23404
  this.clientId = clientId;
@@ -23551,6 +23565,32 @@ var AuthService = /** @class */ (function () {
23551
23565
  });
23552
23566
  });
23553
23567
  };
23568
+ AuthService.prototype.getSamlSignOutUrl = function (authToken, merchantUuid) {
23569
+ var query = new URLSearchParams({ merchant_uuid: merchantUuid, token: authToken });
23570
+ return "".concat(this.endpoint.encode()).concat(exports.SAML_SIGN_OUT_ROUTE.uri, "?").concat(query);
23571
+ };
23572
+ AuthService.prototype.samlSignOut = function (authToken, merchantUuid) {
23573
+ return __awaiter(this, void 0, void 0, function () {
23574
+ return __generator(this, function (_a) {
23575
+ switch (_a.label) {
23576
+ case 0: return [4 /*yield*/, new ServiceRequest_1.AnonymousServiceRequest(this.clientId)
23577
+ .invoke(this.endpoint, exports.SAML_SIGN_OUT_ROUTE, null, {
23578
+ merchant_uuid: merchantUuid,
23579
+ token: authToken
23580
+ })
23581
+ .handle(function (response) {
23582
+ var data = response.data, status = response.status;
23583
+ if (status !== Enums_1.HttpStatusCode.OK) {
23584
+ (0, ServiceRequest_1.logErrorResponse)(response);
23585
+ throw new BringgException_1.BringgException(ExceptionReason_1.ExceptionReason.fromHttpStatusCode(status), 'Unable to sign out of SAML');
23586
+ }
23587
+ return data === null || data === void 0 ? void 0 : data.redirect_url;
23588
+ })];
23589
+ case 1: return [2 /*return*/, _a.sent()];
23590
+ }
23591
+ });
23592
+ });
23593
+ };
23554
23594
  AuthService.prototype.switchAccounts = function (authToken) {
23555
23595
  return __awaiter(this, void 0, void 0, function () {
23556
23596
  return __generator(this, function (_a) {
@@ -24040,6 +24080,47 @@ var Session = /** @class */ (function () {
24040
24080
  });
24041
24081
  });
24042
24082
  };
24083
+ /**
24084
+ * Whether the user signed in through SAML, read from the `aut` claim of the authentication token.
24085
+ * @returns false when the token cannot be read
24086
+ */
24087
+ Session.prototype.isSamlUser = function () {
24088
+ try {
24089
+ var payload = this.user.authentication_token.split('.')[1];
24090
+ return JSON.parse(atob(payload.replace(/-/g, '+').replace(/_/g, '/'))).aut === 'saml';
24091
+ }
24092
+ catch (_a) {
24093
+ return false;
24094
+ }
24095
+ };
24096
+ /**
24097
+ * Url that signs a SAML user out of the identity provider when the browser navigates to it.
24098
+ * @returns undefined for users who did not sign in through SAML, or before the merchant is loaded
24099
+ */
24100
+ Session.prototype.getSamlSignOutUrl = function () {
24101
+ var _a;
24102
+ if (!this.isSamlUser() || !((_a = this.merchant) === null || _a === void 0 ? void 0 : _a.uuid)) {
24103
+ return undefined;
24104
+ }
24105
+ return AuthService_1.default.init(this.user.region).getSamlSignOutUrl(this.user.authentication_token, this.merchant.uuid);
24106
+ };
24107
+ /**
24108
+ * Signs a SAML user out of the identity provider and returns where to send the browser next.
24109
+ * Only for users with `sso_logout_redirect_on_frontend`; without it the server answers with a redirect,
24110
+ * so navigate to `getSamlSignOutUrl()` instead.
24111
+ * @returns the url to send the browser to, or undefined when the server has none
24112
+ * @throws {BringgException} When the server rejects the token
24113
+ */
24114
+ Session.prototype.samlSignOut = function () {
24115
+ return __awaiter(this, void 0, void 0, function () {
24116
+ return __generator(this, function (_a) {
24117
+ switch (_a.label) {
24118
+ case 0: return [4 /*yield*/, AuthService_1.default.init(this.user.region).samlSignOut(this.user.authentication_token, this.merchant.uuid)];
24119
+ case 1: return [2 /*return*/, _a.sent()];
24120
+ }
24121
+ });
24122
+ });
24123
+ };
24043
24124
  Session.prototype.switchAccounts = function () {
24044
24125
  return __awaiter(this, void 0, void 0, function () {
24045
24126
  var _a, _b;
@@ -24784,7 +24865,7 @@ var BringgException_1 = __webpack_require__(43605);
24784
24865
  var client_page_1 = __webpack_require__(16573);
24785
24866
  var Logger_1 = __importDefault(__webpack_require__(55860));
24786
24867
  var abort_1 = __webpack_require__(34179);
24787
- var version = '9.91.1-pre';
24868
+ var version = '9.92.0-pre.0';
24788
24869
  function logErrorResponse(response) {
24789
24870
  var data = response.data, status = response.status;
24790
24871
  try {
@@ -34707,6 +34788,17 @@ var vehicle_realtime_subscriptions_1 = __importDefault(__webpack_require__(25240
34707
34788
  var vehicles_service_1 = __importDefault(__webpack_require__(87386));
34708
34789
  // How long a vehicle id the server did not return stays out of `batch_get` requests.
34709
34790
  exports.MISSING_VEHICLES_CACHE_TTL = 1000 * 60 * 10; // 10 minutes
34791
+ var MAX_VEHICLES_CHUNK_SIZE = 500;
34792
+ var SERVER_DEFAULT_VEHICLES_CHUNK_SIZE = 50;
34793
+ var getSafeChunkSize = function (chunkSize) {
34794
+ if ((0, lodash_1.isNil)(chunkSize) || chunkSize > MAX_VEHICLES_CHUNK_SIZE) {
34795
+ return MAX_VEHICLES_CHUNK_SIZE;
34796
+ }
34797
+ if (chunkSize <= 0) {
34798
+ return SERVER_DEFAULT_VEHICLES_CHUNK_SIZE;
34799
+ }
34800
+ return chunkSize;
34801
+ };
34710
34802
  var VehiclesApi = /** @class */ (function () {
34711
34803
  function VehiclesApi(session) {
34712
34804
  var _this = this;
@@ -34732,16 +34824,16 @@ var VehiclesApi = /** @class */ (function () {
34732
34824
  return this.storableDataService.loadAll('loadAllByTeam', function () { return _this.vehiclesService.loadAllByTeam(teamId); }, __assign(__assign({}, options), { groupType: Vehicle_consts_1.VehicleGroup.Team, groupValue: teamId }));
34733
34825
  };
34734
34826
  // Suppression assumes an id absent from the response is ones the backend can not return for the current user.
34735
- // Note! Items dropped by the backend because ids.length is greater than limit hardcoded on the backend side
34736
- // also fall in this bucket.
34827
+ // Note! Items dropped by the server because of limit / chunkSize also fall in this bucket.
34737
34828
  VehiclesApi.prototype.loadMany = function (ids, options) {
34738
34829
  if (options === void 0) { options = data_entity_1.DEFAULT_OPTIONS; }
34739
34830
  return __awaiter(this, void 0, void 0, function () {
34740
34831
  var optionsWithDefaults, chunkSize;
34741
34832
  var _this = this;
34742
34833
  return __generator(this, function (_a) {
34743
- optionsWithDefaults = (0, lodash_1.defaults)({}, options, __assign(__assign({}, data_entity_1.DEFAULT_OPTIONS), { chunkSize: 500 }));
34744
- chunkSize = optionsWithDefaults.chunkSize;
34834
+ optionsWithDefaults = (0, lodash_1.defaults)({}, options, __assign({}, data_entity_1.DEFAULT_OPTIONS));
34835
+ chunkSize = getSafeChunkSize(optionsWithDefaults.chunkSize);
34836
+ optionsWithDefaults.chunkSize = chunkSize;
34745
34837
  return [2 /*return*/, this.storableDataService.loadMany('batchGet', function (idsToLoad) {
34746
34838
  if (idsToLoad.length === 0) {
34747
34839
  return Promise.resolve([]);
@@ -37363,7 +37455,7 @@ exports["default"] = withPromiseCache;
37363
37455
  /***/ }),
37364
37456
 
37365
37457
  /***/ 2521:
37366
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
37458
+ /***/ (function(__unused_webpack_module, exports) {
37367
37459
 
37368
37460
  "use strict";
37369
37461
 
@@ -37403,12 +37495,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37403
37495
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
37404
37496
  }
37405
37497
  };
37406
- var __importDefault = (this && this.__importDefault) || function (mod) {
37407
- return (mod && mod.__esModule) ? mod : { "default": mod };
37408
- };
37409
37498
  Object.defineProperty(exports, "__esModule", ({ value: true }));
37410
37499
  exports.DEFAULT_NEGATIVE_CACHE_MAX_SIZE = void 0;
37411
- var Logger_1 = __importDefault(__webpack_require__(55860));
37412
37500
  exports.DEFAULT_NEGATIVE_CACHE_MAX_SIZE = 5000;
37413
37501
  var instanceCaches = new WeakMap();
37414
37502
  var getCache = function (instance) {
@@ -37422,7 +37510,7 @@ var getCache = function (instance) {
37422
37510
  // Entries are only ever added by the decorated method, so sweeping on call covers every growth path
37423
37511
  // without a timer that would pin the instance and defeat the WeakMap. An entry recorded just after a
37424
37512
  // sweep survives until the sweep after next, so worst-case lifetime is ~2x ttlMs.
37425
- var sweep = function (cache, ttlMs, now, logScope) {
37513
+ var sweep = function (cache, ttlMs, now) {
37426
37514
  if (now - cache.lastSweptAt < ttlMs) {
37427
37515
  return;
37428
37516
  }
@@ -37434,14 +37522,11 @@ var sweep = function (cache, ttlMs, now, logScope) {
37434
37522
  });
37435
37523
  expired.forEach(function (id) { return cache.misses.delete(id); });
37436
37524
  cache.lastSweptAt = now;
37437
- if (expired.length) {
37438
- Logger_1.default.info("".concat(logScope, ": swept expired"), expired.length, 'remaining', cache.misses.size);
37439
- }
37440
37525
  };
37441
37526
  // A burst of distinct misses inside one ttl window has nothing to sweep - drop oldest first.
37442
37527
  // Map keeps insertion order and entries are inserted at miss time, so the front is the oldest.
37443
37528
  // Runs AFTER recording, so a single call that overshoots the cap is trimmed by that same call.
37444
- var enforceCap = function (cache, maxSize, logScope) {
37529
+ var enforceCap = function (cache, maxSize) {
37445
37530
  if (cache.misses.size <= maxSize) {
37446
37531
  return;
37447
37532
  }
@@ -37450,7 +37535,6 @@ var enforceCap = function (cache, maxSize, logScope) {
37450
37535
  for (var i = 0; i < overflow; i++) {
37451
37536
  cache.misses.delete(oldestFirst.next().value);
37452
37537
  }
37453
- Logger_1.default.info("".concat(logScope, ": dropped oldest over ").concat(maxSize, " cap"), overflow);
37454
37538
  };
37455
37539
  /**
37456
37540
  * Suppresses ids the server repeatedly fails to return.
@@ -37468,10 +37552,9 @@ function withNegativeCache(_a) {
37468
37552
  var ttlMs = _a.ttlMs, hasItem = _a.hasItem, _b = _a.maxSize, maxSize = _b === void 0 ? exports.DEFAULT_NEGATIVE_CACHE_MAX_SIZE : _b;
37469
37553
  return function (target, propertyName, propertyDescriptor) {
37470
37554
  var method = propertyDescriptor.value;
37471
- var logScope = "".concat(propertyName, " negative cache");
37472
37555
  propertyDescriptor.value = function (ids, options) {
37473
37556
  return __awaiter(this, void 0, void 0, function () {
37474
- var instanceCache, cache, bypassed, expired, held, suppressed, idsToLoad, items, returnedIds, now, missed, resolved;
37557
+ var instanceCache, cache, idsToLoad, items, returnedIds, now;
37475
37558
  var _this = this;
37476
37559
  return __generator(this, function (_a) {
37477
37560
  switch (_a.label) {
@@ -37483,44 +37566,22 @@ function withNegativeCache(_a) {
37483
37566
  }
37484
37567
  instanceCache = getCache(this);
37485
37568
  cache = instanceCache.misses;
37486
- sweep(instanceCache, ttlMs, Date.now(), logScope);
37569
+ sweep(instanceCache, ttlMs, Date.now());
37487
37570
  if ((options === null || options === void 0 ? void 0 : options.useCache) === false) {
37488
- bypassed = ids.filter(function (id) { return cache.delete(id); });
37489
- if (bypassed.length) {
37490
- Logger_1.default.info("".concat(logScope, ": evicted on useCache=false"), bypassed);
37491
- }
37571
+ ids.forEach(function (id) { return cache.delete(id); });
37492
37572
  }
37493
- expired = [];
37494
- held = [];
37495
- suppressed = [];
37496
37573
  idsToLoad = ids.filter(function (id) {
37497
37574
  var missedAt = cache.get(id);
37498
37575
  if (missedAt === undefined) {
37499
37576
  return true;
37500
37577
  }
37501
37578
  // Expired, or the item showed up by another route - either way it is requestable again.
37502
- if (Date.now() - missedAt >= ttlMs) {
37503
- cache.delete(id);
37504
- expired.push(id);
37505
- return true;
37506
- }
37507
- if (hasItem(_this, id)) {
37579
+ if (Date.now() - missedAt >= ttlMs || hasItem(_this, id)) {
37508
37580
  cache.delete(id);
37509
- held.push(id);
37510
37581
  return true;
37511
37582
  }
37512
- suppressed.push(id);
37513
37583
  return false;
37514
37584
  });
37515
- if (expired.length) {
37516
- Logger_1.default.info("".concat(logScope, ": evicted after ").concat(ttlMs, "ms ttl"), expired);
37517
- }
37518
- if (held.length) {
37519
- Logger_1.default.info("".concat(logScope, ": evicted, now held by the instance"), held);
37520
- }
37521
- if (suppressed.length) {
37522
- Logger_1.default.info("".concat(logScope, ": suppressed"), suppressed);
37523
- }
37524
37585
  if (!idsToLoad.length) {
37525
37586
  return [2 /*return*/, []];
37526
37587
  }
@@ -37529,25 +37590,8 @@ function withNegativeCache(_a) {
37529
37590
  items = _a.sent();
37530
37591
  returnedIds = new Set(items.map(function (item) { return item.id; }));
37531
37592
  now = Date.now();
37532
- missed = [];
37533
- resolved = [];
37534
- idsToLoad.forEach(function (id) {
37535
- if (returnedIds.has(id)) {
37536
- if (cache.delete(id)) {
37537
- resolved.push(id);
37538
- }
37539
- return;
37540
- }
37541
- cache.set(id, now);
37542
- missed.push(id);
37543
- });
37544
- if (resolved.length) {
37545
- Logger_1.default.info("".concat(logScope, ": evicted, returned by the server"), resolved);
37546
- }
37547
- if (missed.length) {
37548
- Logger_1.default.info("".concat(logScope, ": recorded as missing"), missed, 'cache size', cache.size);
37549
- }
37550
- enforceCap(instanceCache, maxSize, logScope);
37593
+ idsToLoad.forEach(function (id) { return (returnedIds.has(id) ? cache.delete(id) : cache.set(id, now)); });
37594
+ enforceCap(instanceCache, maxSize);
37551
37595
  return [2 /*return*/, items];
37552
37596
  }
37553
37597
  });