@copart/ops-tool-kit 1.13.4 → 1.13.5-alpha.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.
package/changelog.md CHANGED
@@ -1,3 +1,14 @@
1
+ ### 1.13.5-alpha.0
2
+
3
+ Iframe storage now matches the portal store the embedded app used to share.
4
+
5
+ - The shell init payload is the full `localStorage` and `sessionStorage` snapshot (`result.local` / `result.session`). Any key an app saved is readable again on the next open. Named duplicate fields (`login`, `config`, `userEmail`, and the rest) are no longer sent.
6
+ - `getLocalItem` / `getSessionItem` / `getItem` return `{}` for a missing key, the same as standalone storage. A removed key does not come back from the page-load copy. `getItem('config')` reads only `${APP_NAME}:config`.
7
+ - `false`, `0`, and `""` are saved and read back. `null` and `undefined` are still not written.
8
+ - Another browser tab's `localStorage` changes are applied in the open iframe. `sessionStorage` stays per-tab.
9
+ - `storage.logout()` inside an embedded app does nothing. The portal shell still owns logout.
10
+ - `location.assign` and `location.replace` of a shell route go through the shell. Reloads, external redirects, and same-origin Angular navigation are unchanged.
11
+
1
12
  ### 1.12.10
2
13
 
3
14
  - Added support for user status visibility by app via `storage.coreConfig?.checkUserStatusByApp` flag and `showUserStatus` property in app tile configurations.
@@ -49,7 +49,7 @@ var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
49
49
  var ReactRouterDOM__namespace = /*#__PURE__*/_interopNamespace(ReactRouterDOM);
50
50
 
51
51
  const name$1 = "@copart/ops-tool-kit";
52
- const version$3 = "1.13.4";
52
+ const version$3 = "1.13.5-alpha.0";
53
53
  const main$1 = "dist/ops-tool-kit.js";
54
54
  const style = "dist/ops-tool-kit.css";
55
55
  const files = [
@@ -2501,13 +2501,27 @@ function notifyStorageChanged(detail) {
2501
2501
 
2502
2502
  emitStorageEvents('local');
2503
2503
  emitStorageEvents('session');
2504
+
2505
+ // Missing and JSON null become {}. false, 0, and "" are kept — `|| {}` used to erase them.
2506
+ var readStored = function readStored(raw) {
2507
+ if (raw == null) return {};
2508
+ var parsed = parse$1(raw);
2509
+ return parsed == null ? {} : parsed;
2510
+ };
2511
+ var readStoredPath = function readStoredPath(raw, path) {
2512
+ var data = readStored(raw);
2513
+ if (!path) return data;
2514
+ if (_typeof$1(data) !== 'object') return undefined;
2515
+ return getValue$1(data, path);
2516
+ };
2504
2517
  var getLocalItem$1 = function getLocalItem(key, path) {
2505
- var data = parse$1(localStorage[key]) || {};
2506
- return path ? getValue$1(data, path) : data;
2518
+ return readStoredPath(localStorage[key], path);
2507
2519
  };
2508
2520
  var getSessionItem$1 = function getSessionItem(key, path) {
2509
- var data = parse$1(sessionStorage[key]) || {};
2510
- return path ? getValue$1(data, path) : data;
2521
+ return readStoredPath(sessionStorage[key], path);
2522
+ };
2523
+ var canStore = function canStore(value) {
2524
+ return value !== undefined && value !== null;
2511
2525
  };
2512
2526
 
2513
2527
  /** Resolve path + notify flag. 3rd arg is path (string) or `{ notify: false }`. */
@@ -2528,8 +2542,10 @@ var setLocalItem$1 = function setLocalItem(key, value, pathOrOptions, maybeOptio
2528
2542
  var _resolveWriteOptions = resolveWriteOptions(pathOrOptions, maybeOptions),
2529
2543
  path = _resolveWriteOptions.path,
2530
2544
  notify = _resolveWriteOptions.notify;
2531
- if (value) {
2532
- localStorage[key] = stringify$1(path ? setValue(getLocalItem$1(key), path, value) : value);
2545
+ if (canStore(value)) {
2546
+ var current = path ? getLocalItem$1(key) : undefined;
2547
+ var base = current && _typeof$1(current) === 'object' ? current : {};
2548
+ localStorage[key] = stringify$1(path ? setValue(base, path, value) : value);
2533
2549
  if (notify) {
2534
2550
  notifyStorageChanged({
2535
2551
  scope: 'local',
@@ -2545,8 +2561,10 @@ var setSessionItem$1 = function setSessionItem(key, value, pathOrOptions, maybeO
2545
2561
  var _resolveWriteOptions2 = resolveWriteOptions(pathOrOptions, maybeOptions),
2546
2562
  path = _resolveWriteOptions2.path,
2547
2563
  notify = _resolveWriteOptions2.notify;
2548
- if (value) {
2549
- sessionStorage[key] = stringify$1(path ? setValue(getSessionItem$1(key), path, value) : value);
2564
+ if (canStore(value)) {
2565
+ var current = path ? getSessionItem$1(key) : undefined;
2566
+ var base = current && _typeof$1(current) === 'object' ? current : {};
2567
+ sessionStorage[key] = stringify$1(path ? setValue(base, path, value) : value);
2550
2568
  if (notify) {
2551
2569
  notifyStorageChanged({
2552
2570
  scope: 'session',
@@ -65297,6 +65315,34 @@ var getDefaultSelection = function getDefaultSelection(navItems, depth) {
65297
65315
  var defaultRedirect = function defaultRedirect(addr) {
65298
65316
  window.open('http://localhost.copart.com' + addr, '_blank');
65299
65317
  };
65318
+ var readNavFlag = function readNavFlag(value) {
65319
+ if (typeof value !== 'function') return value;
65320
+ try {
65321
+ return value();
65322
+ } catch (e) {
65323
+ return false;
65324
+ }
65325
+ };
65326
+
65327
+ // Identity of the menu the shell should show. Settings save reloads the iframe and
65328
+ // posts a new list (country filters change the routes). A fresh array with the same
65329
+ // routes must not reset selection — AppFrame parents often rebuild navItems each render.
65330
+ var navStructureKey = function navStructureKey(items) {
65331
+ if (!Array.isArray(items)) return '';
65332
+ var _walk = function walk(list) {
65333
+ return list.map(function (item) {
65334
+ return {
65335
+ name: item && item.name,
65336
+ route: item && item.route,
65337
+ icon: item && typeof item.icon === 'string' ? item.icon : undefined,
65338
+ disabled: readNavFlag(item && item.disabled),
65339
+ hidden: readNavFlag(item && item.hidden),
65340
+ subMenuItems: item && item.subMenuItems ? _walk(item.subMenuItems) : undefined
65341
+ };
65342
+ });
65343
+ };
65344
+ return JSON.stringify(_walk(items));
65345
+ };
65300
65346
  var NavigationBar = function NavigationBar(_ref2) {
65301
65347
  var navItems = _ref2.navItems,
65302
65348
  navigateTo = _ref2.navigateTo,
@@ -65340,6 +65386,9 @@ var NavigationBar = function NavigationBar(_ref2) {
65340
65386
  _useState10 = _slicedToArray(_useState1, 2),
65341
65387
  withCounts = _useState10[0],
65342
65388
  setWithCounts = _useState10[1];
65389
+ var navItemsKey = React.useMemo(function () {
65390
+ return navStructureKey(navItems);
65391
+ }, [navItems]);
65343
65392
  React.useEffect(function () {
65344
65393
  if (Array.isArray(navItems)) {
65345
65394
  var isValid = _validateConfig(navItems, 3, showLevel3Navigation);
@@ -65351,7 +65400,9 @@ var NavigationBar = function NavigationBar(_ref2) {
65351
65400
  activeMenuItem = _getDefaultSelection.activeMenuItem;
65352
65401
  setConfigValid(true);
65353
65402
  setNavItemsModified(updatedNavItems);
65354
- setSelected(selectedItem);
65403
+ // Only apply an explicit landing selection. Clearing here would wipe the
65404
+ // highlight the URL effect already set, including after a country-driven nav refresh.
65405
+ if (selectedItem) setSelected(selectedItem);
65355
65406
  if (activeMenuItem) setActiveSubmenu(function (menuItems) {
65356
65407
  return allowMultipleNavItemsOpen ? [].concat(_toConsumableArray(menuItems), [activeMenuItem]) : [activeMenuItem];
65357
65408
  });
@@ -65363,7 +65414,11 @@ var NavigationBar = function NavigationBar(_ref2) {
65363
65414
  } else {
65364
65415
  setConfigValid(false);
65365
65416
  }
65366
- }, [showLevel3Navigation]);
65417
+ // navItemsKey changes when routes/names/disabled/hidden change (yard/country settings).
65418
+ // navItems itself is read from that render; depending on the array identity re-runs
65419
+ // this on every parent render and resets the open menu.
65420
+ // eslint-disable-next-line react-hooks/exhaustive-deps
65421
+ }, [navItemsKey, showLevel3Navigation]);
65367
65422
  React.useEffect(function () {
65368
65423
  setShowNavigationCounts(withCounts);
65369
65424
  }, [withCounts]);
@@ -70072,6 +70127,8 @@ function _getInitData() {
70072
70127
  attempt,
70073
70128
  allowWildcardHandshake,
70074
70129
  result,
70130
+ login,
70131
+ accessToken,
70075
70132
  _args = arguments;
70076
70133
  return _regenerator().w(function (_context) {
70077
70134
  while (1) switch (_context.n) {
@@ -70106,11 +70163,13 @@ function _getInitData() {
70106
70163
  _context.n = 3;
70107
70164
  break;
70108
70165
  }
70166
+ login = result.login || result.local && result.local.login;
70167
+ accessToken = result.accessToken || login && login.userData && login.userData.access_token;
70109
70168
  console.info("".concat(LOG_PREFIX, " handshake success"), {
70110
70169
  attempt: attempt,
70111
70170
  shellOrigin: trustedParentOrigin,
70112
- hasLogin: !!(result && result.login),
70113
- hasAccessToken: !!(result && result.accessToken)
70171
+ hasLogin: !!login,
70172
+ hasAccessToken: !!accessToken
70114
70173
  });
70115
70174
  return _context.a(2, result);
70116
70175
  case 3:
@@ -70530,10 +70589,10 @@ var cache = {
70530
70589
  };
70531
70590
  function setInitCache(initData) {
70532
70591
  if (!initData) return;
70533
- cache = _objectSpread2({
70534
- local: {},
70535
- session: {}
70536
- }, initData);
70592
+ cache = _objectSpread2(_objectSpread2({}, initData), {}, {
70593
+ local: _objectSpread2({}, initData.local),
70594
+ session: _objectSpread2({}, initData.session)
70595
+ });
70537
70596
  if (initData.login != null) cache.local.login = initData.login;
70538
70597
  if (initData.settings != null) cache.local.settings = initData.settings;
70539
70598
  if (initData.dashboard != null) cache.session.dashboard = initData.dashboard;
@@ -70564,14 +70623,16 @@ function getInitDataForBootstrap() {
70564
70623
  return getInitData();
70565
70624
  }
70566
70625
  function getLocalItem(key, path) {
70567
- var value = nullishCoalesce(cache.local[key], cache[key]);
70568
- var out = path ? getByPath(value, path) : value;
70569
- if (out !== undefined) return out;
70570
- if (key === 'login') return cache.login;
70571
- if (key === 'settings') return cache.settings;
70572
- return undefined;
70626
+ // Only the local snapshot. Top-level init copies (cache.config, cache.login, …)
70627
+ // are not a fallback: a removed key must not come back, and getLocalItem('config')
70628
+ // must not return the portal config.
70629
+ var value = cache.local[key];
70630
+ if (value == null) return path ? undefined : {};
70631
+ if (!path) return value;
70632
+ return getByPath(value, path);
70573
70633
  }
70574
70634
  function setLocalItem(key, value, path) {
70635
+ if (value == null) return;
70575
70636
  sendStorageSet({
70576
70637
  op: 'setLocalItem',
70577
70638
  key: key,
@@ -70579,8 +70640,9 @@ function setLocalItem(key, value, path) {
70579
70640
  path: path
70580
70641
  });
70581
70642
  if (path) {
70582
- var existing = nullishCoalesce(cache.local[key], nullishCoalesce(cache[key], {}));
70583
- cache.local[key] = setByPath(_objectSpread2({}, existing), path, value);
70643
+ var existing = cache.local[key];
70644
+ var base = existing && _typeof$1(existing) === 'object' ? existing : {};
70645
+ cache.local[key] = setByPath(_objectSpread2({}, base), path, value);
70584
70646
  } else {
70585
70647
  cache.local[key] = value;
70586
70648
  if (key === 'login') cache.login = value;
@@ -70588,13 +70650,13 @@ function setLocalItem(key, value, path) {
70588
70650
  }
70589
70651
  }
70590
70652
  function getSessionItem(key, path) {
70591
- var value = nullishCoalesce(cache.session[key], cache[key]);
70592
- var out = path ? getByPath(value, path) : value;
70593
- if (out !== undefined) return out;
70594
- if (key === 'dashboard') return cache.dashboard;
70595
- return undefined;
70653
+ var value = cache.session[key];
70654
+ if (value == null) return path ? undefined : {};
70655
+ if (!path) return value;
70656
+ return getByPath(value, path);
70596
70657
  }
70597
70658
  function setSessionItem(key, value, path) {
70659
+ if (value == null) return;
70598
70660
  sendStorageSet({
70599
70661
  op: 'setSessionItem',
70600
70662
  key: key,
@@ -70602,8 +70664,9 @@ function setSessionItem(key, value, path) {
70602
70664
  path: path
70603
70665
  });
70604
70666
  if (path) {
70605
- var existing = nullishCoalesce(cache.session[key], nullishCoalesce(cache[key], {}));
70606
- cache.session[key] = setByPath(_objectSpread2({}, existing), path, value);
70667
+ var existing = cache.session[key];
70668
+ var base = existing && _typeof$1(existing) === 'object' ? existing : {};
70669
+ cache.session[key] = setByPath(_objectSpread2({}, base), path, value);
70607
70670
  } else {
70608
70671
  cache.session[key] = value;
70609
70672
  if (key === 'dashboard') cache.dashboard = value;
@@ -70633,6 +70696,17 @@ function applyStorageChanged() {
70633
70696
  key = eventProps.key,
70634
70697
  path = eventProps.path,
70635
70698
  value = eventProps.value;
70699
+ if (op === 'clear') {
70700
+ if (scope === 'session') {
70701
+ cache.session = {};
70702
+ delete cache.dashboard;
70703
+ } else {
70704
+ cache.local = {};
70705
+ delete cache.login;
70706
+ delete cache.settings;
70707
+ }
70708
+ return;
70709
+ }
70636
70710
  if (op === 'remove') {
70637
70711
  if (scope === 'session') {
70638
70712
  removeSessionItemFromCache(key);
@@ -70662,19 +70736,24 @@ function applyStorageChanged() {
70662
70736
  }
70663
70737
  function removeLocalItemFromCache(key) {
70664
70738
  delete cache.local[key];
70739
+ // cache.local / cache.session are the snapshots themselves. Never delete those.
70740
+ if (key !== 'local' && key !== 'session') delete cache[key];
70665
70741
  if (key === 'login') delete cache.login;
70666
70742
  if (key === 'settings') delete cache.settings;
70667
70743
  }
70668
70744
  function removeSessionItemFromCache(key) {
70669
70745
  delete cache.session[key];
70746
+ if (key !== 'local' && key !== 'session') delete cache[key];
70670
70747
  if (key === 'dashboard') delete cache.dashboard;
70671
70748
  }
70672
70749
  function getItem$1(key) {
70673
70750
  var APP_NAME = getAppName();
70674
70751
  var namespaced = "".concat(APP_NAME, ":").concat(key);
70675
- return nullishCoalesce(cache.local[namespaced], cache[key]);
70752
+ var value = cache.local[namespaced];
70753
+ return value == null ? {} : value;
70676
70754
  }
70677
70755
  function setItem(key, value) {
70756
+ if (value == null) return value;
70678
70757
  var APP_NAME = getAppName();
70679
70758
  var namespaced = "".concat(APP_NAME, ":").concat(key);
70680
70759
  sendStorageSet({
@@ -70683,7 +70762,6 @@ function setItem(key, value) {
70683
70762
  value: value
70684
70763
  });
70685
70764
  cache.local[namespaced] = value;
70686
- cache[key] = value;
70687
70765
  return value;
70688
70766
  }
70689
70767
  function setAppContext() {
@@ -70893,9 +70971,9 @@ var storage$1 = {
70893
70971
  clear: function clear() {
70894
70972
  return clearStorage();
70895
70973
  },
70974
+ // Embedded apps must not sign the user out. The portal shell owns logout.
70896
70975
  logout: function logout() {
70897
- clearStorage();
70898
- window.location.assign('/logout');
70976
+ console.error('[iframe-bridge/storage] storage.logout() is ignored inside an embedded app. Sign out from the portal.');
70899
70977
  }
70900
70978
  };
70901
70979
  if (typeof window !== 'undefined') {
@@ -71879,6 +71957,7 @@ function AppLink(_ref) {
71879
71957
  * 1. Raw <a href> clicks (any anchor, added anytime) — capture-phase listener.
71880
71958
  * 2. window.open(url, '_self'/'_top'/'_parent') — wrapped.
71881
71959
  * 3. <form> submits with a navigating action — capture-phase submit listener.
71960
+ * 4. location.assign / location.replace of a shell route — wrapped.
71882
71961
  *
71883
71962
  * Policy (shared with AppLink via classifyHref):
71884
71963
  * - internal (same origin as shell) → drive the shell router (postUpdateUri),
@@ -71889,9 +71968,10 @@ function AppLink(_ref) {
71889
71968
  *
71890
71969
  * Call once, after bootstrap. Idempotent. Returns an uninstall function.
71891
71970
  *
71892
- * NOTE: this is defense-in-depth, not a security boundary. See LIMITATIONS at
71893
- * the bottom for the vectors it cannot cover (location.assign, meta-refresh,
71894
- * server redirects), which must be handled by CSP + the shell heartbeat.
71971
+ * Left to the browser on purpose: external assign/replace (OAuth and other
71972
+ * intentional redirects), location.href, location.reload, meta refresh,
71973
+ * window.top.location (cross-origin; apps use it to move the portal), and
71974
+ * any navigation while this document is same-origin with the shell.
71895
71975
  */
71896
71976
 
71897
71977
  var installed = false;
@@ -71994,15 +72074,88 @@ function installNavigationGuard() {
71994
72074
  // internal form navigation is left to the app's own router/handling.
71995
72075
  };
71996
72076
  document.addEventListener('submit', onSubmit, true);
72077
+
72078
+ // --- 4. location.assign / location.replace of a shell route ---------------
72079
+ // Only cross-origin embeds. Same-origin apps (legacy /embedded, Angular)
72080
+ // keep native navigation. External URLs and the app's own host stay native
72081
+ // so OAuth, location.replace(location.href), and location.reload() are unchanged.
72082
+ var restoreLocation = installLocationMethodGuard(routeInternal);
71997
72083
  return function uninstall() {
71998
72084
  document.removeEventListener('click', onClick, true);
71999
72085
  document.removeEventListener('submit', onSubmit, true);
72000
72086
  try {
72001
72087
  window.open = nativeOpen;
72002
72088
  } catch (_) {}
72089
+ restoreLocation();
72003
72090
  installed = false;
72004
72091
  };
72005
72092
  }
72093
+ function isSchemeUrl(href) {
72094
+ return /^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith('//');
72095
+ }
72096
+ function shellRouteFromLocationCall(url) {
72097
+ if (url == null) return null;
72098
+ var shellOrigin = getShellOrigin();
72099
+ if (!shellOrigin || shellOrigin === window.location.origin) return null;
72100
+ var href = String(url);
72101
+ if (isSchemeUrl(href)) {
72102
+ var parsed;
72103
+ try {
72104
+ parsed = new URL(href, window.location.href);
72105
+ } catch (_) {
72106
+ return null;
72107
+ }
72108
+ if (parsed.origin === window.location.origin) return null;
72109
+ if (parsed.href === window.location.href) return null;
72110
+ } else if (!href.startsWith('/')) {
72111
+ // Query-only ("?a=1") and dot-relative stay in this document.
72112
+ return null;
72113
+ }
72114
+ var result = classifyHref(href);
72115
+ if (result.kind !== 'internal' || !result.shellPath) return null;
72116
+ return result.shellPath;
72117
+ }
72118
+ function installLocationMethodGuard(routeInternal) {
72119
+ var proto;
72120
+ try {
72121
+ proto = window.Location ? window.Location.prototype : Location.prototype;
72122
+ } catch (_) {
72123
+ return function () {};
72124
+ }
72125
+ if (!proto || typeof proto.assign !== 'function' || typeof proto.replace !== 'function') {
72126
+ return function () {};
72127
+ }
72128
+ var nativeAssign = proto.assign;
72129
+ var nativeReplace = proto.replace;
72130
+ var wrap = function wrap(nativeFn) {
72131
+ return function locationNavigation(url) {
72132
+ var shellPath = shellRouteFromLocationCall(url);
72133
+ if (shellPath) {
72134
+ routeInternal(shellPath, false);
72135
+ return;
72136
+ }
72137
+ return nativeFn.call(this, url);
72138
+ };
72139
+ };
72140
+ try {
72141
+ proto.assign = wrap(nativeAssign);
72142
+ proto.replace = wrap(nativeReplace);
72143
+ } catch (_) {
72144
+ try {
72145
+ proto.assign = nativeAssign;
72146
+ } catch (e) {/* keep native if the wrap did not stick */}
72147
+ try {
72148
+ proto.replace = nativeReplace;
72149
+ } catch (e) {/* keep native if the wrap did not stick */}
72150
+ return function () {};
72151
+ }
72152
+ return function restoreLocation() {
72153
+ try {
72154
+ proto.assign = nativeAssign;
72155
+ proto.replace = nativeReplace;
72156
+ } catch (_) {}
72157
+ };
72158
+ }
72006
72159
 
72007
72160
  var iframeFacade = {
72008
72161
  AppFrame: AppFrame,