@copart/ops-tool-kit 1.13.6 → 1.13.7-alpha.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.
package/changelog.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ### alpha
2
2
 
3
+ File and Blob uploads from an iframe app survive `Origin-Agent-Cluster`. The iframe reads the bytes and the shell builds a file it owns, so Chrome no longer fails the upload with `net::ERR_ACCESS_DENIED`.
4
+
5
+ - A `File` or `Blob` inside `FormData` is sent as bytes (`kind: 'formFile'`). The shell rebuilds a `File` and appends it with the original filename.
6
+ - A `File` or `Blob` passed as the request body is sent the same way (`bodyType: 'blob'`).
7
+ - A `Blob` response, including an error body, is read in the shell and rebuilt in the iframe. `responseType: 'arraybuffer'` is unchanged.
8
+
9
+ ### 1.13.6
10
+
3
11
  FormData requests work in iframe apps, user status apps come from the user record, and the chat window can talk to the lot agent.
4
12
 
5
13
  - `fetcher.post` / `put` / `patch` with a `FormData` body threw `DataCloneError` in iframe apps, because `postMessage` cannot clone a `FormData`. The bridge now sends the entries with `bodyType: 'formData'` and drops the iframe `Content-Type` header. The shell rebuilds the `FormData` so the browser can set the multipart boundary.
@@ -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.6";
52
+ const version$3 = "1.13.7-alpha.1";
53
53
  const main$1 = "dist/ops-tool-kit.js";
54
54
  const style = "dist/ops-tool-kit.css";
55
55
  const files = [
@@ -3029,7 +3029,7 @@ function isFile(val) {
3029
3029
  * @param {Object} val The value to test
3030
3030
  * @returns {boolean} True if value is a Blob, otherwise false
3031
3031
  */
3032
- function isBlob(val) {
3032
+ function isBlob$1(val) {
3033
3033
  return toString$6.call(val) === '[object Blob]';
3034
3034
  }
3035
3035
 
@@ -3194,7 +3194,7 @@ var utils = {
3194
3194
  isUndefined: isUndefined,
3195
3195
  isDate: isDate,
3196
3196
  isFile: isFile,
3197
- isBlob: isBlob,
3197
+ isBlob: isBlob$1,
3198
3198
  isFunction: isFunction$1,
3199
3199
  isStream: isStream,
3200
3200
  isURLSearchParams: isURLSearchParams,
@@ -22512,13 +22512,15 @@ var ProfileDetails = function ProfileDetails(_ref3) {
22512
22512
  currentTileName = _ref3$currentTileName === void 0 ? '' : _ref3$currentTileName,
22513
22513
  onUserStatusUpdate = _ref3.onUserStatusUpdate,
22514
22514
  _ref3$selfManaged = _ref3.selfManaged,
22515
- selfManaged = _ref3$selfManaged === void 0 ? true : _ref3$selfManaged;
22515
+ selfManaged = _ref3$selfManaged === void 0 ? false : _ref3$selfManaged;
22516
22516
  var _useState1 = React.useState(null),
22517
22517
  _useState10 = _slicedToArray(_useState1, 2),
22518
22518
  draftAppNames = _useState10[0],
22519
22519
  setDraftAppNames = _useState10[1];
22520
22520
  var appsHidden = isUserStatusAppsHidden();
22521
22521
  var showApps = !appsHidden && Array.isArray(statusApps) && statusApps.length > 0;
22522
+ // Socket omits selfManaged when it is false. Only an explicit true unlocks app selection.
22523
+ var canManageApps = selfManaged === true;
22522
22524
  var activeAppNames = draftAppNames == null ? selectedAppNames : draftAppNames;
22523
22525
  var currentApp = findStatusAppForTile(statusApps, currentTileName);
22524
22526
  var statusLocked = showApps && Boolean(currentTileName) && !isStatusAppSelected(currentApp, activeAppNames);
@@ -22672,7 +22674,7 @@ var ProfileDetails = function ProfileDetails(_ref3) {
22672
22674
  selectedAppNames: selectedAppNames,
22673
22675
  onApply: handleAppsApply,
22674
22676
  onDraftChange: setDraftAppNames,
22675
- disabled: selfManaged === false
22677
+ disabled: !canManageApps
22676
22678
  })), showStatus && showApps && selectedApps.length > 0 && /*#__PURE__*/React__default["default"].createElement("div", {
22677
22679
  className: "utilities_ops-app-frame_AppBarComponent_Settings_ProfileDetails_ProfileDetails--appTagsRow"
22678
22680
  }, /*#__PURE__*/React__default["default"].createElement(StatusAppsHint, null), /*#__PURE__*/React__default["default"].createElement(SelectedAppChips, {
@@ -31129,7 +31131,12 @@ function startWebSocketConnection(updateNotifications, updateAllNotificationsLis
31129
31131
  return;
31130
31132
  }
31131
31133
  if (updateUserStatus && messageData.userAvailability) {
31132
- updateUserStatus(messageData.userAvailability);
31134
+ // selfManaged and appNames are omitted when the user is not self-managed.
31135
+ updateUserStatus({
31136
+ userAvailability: messageData.userAvailability,
31137
+ selfManaged: messageData.selfManaged === true,
31138
+ appNames: Array.isArray(messageData.appNames) ? messageData.appNames : undefined
31139
+ });
31133
31140
  }
31134
31141
  return;
31135
31142
  }
@@ -31810,6 +31817,7 @@ var AppBar = function AppBar(_ref) {
31810
31817
  _useState26 = _slicedToArray(_useState25, 2),
31811
31818
  selfManaged = _useState26[0],
31812
31819
  setSelfManaged = _useState26[1];
31820
+ var statusAppsRef = React.useRef(statusApps);
31813
31821
  var _useState27 = React.useState(false),
31814
31822
  _useState28 = _slicedToArray(_useState27, 2),
31815
31823
  showSystemOfflineDialog = _useState28[0],
@@ -31820,6 +31828,9 @@ var AppBar = function AppBar(_ref) {
31820
31828
  React.useEffect(function () {
31821
31829
  notificationsRef.current = notifications;
31822
31830
  }, [notifications]);
31831
+ React.useEffect(function () {
31832
+ statusAppsRef.current = statusApps;
31833
+ }, [statusApps]);
31823
31834
  var updateNotifications = function updateNotifications(newNotifications) {
31824
31835
  if (newNotifications.length) {
31825
31836
  setNotifications(function (notifications) {
@@ -31956,9 +31967,26 @@ var AppBar = function AppBar(_ref) {
31956
31967
  return _ref5.apply(this, arguments);
31957
31968
  };
31958
31969
  }();
31959
- var updateUserStatusFromWebSocket = function updateUserStatusFromWebSocket(newStatus) {
31960
- setCurrentUserStatus(newStatus);
31961
- storage$2.setLocalItem('dashboard', newStatus, 'userAvailability');
31970
+ var updateUserStatusFromWebSocket = function updateUserStatusFromWebSocket(payload) {
31971
+ var newStatus = typeof payload === 'string' ? payload : payload === null || payload === void 0 ? void 0 : payload.userAvailability;
31972
+ if (newStatus) {
31973
+ setCurrentUserStatus(newStatus);
31974
+ storage$2.setLocalItem('dashboard', newStatus, 'userAvailability');
31975
+ }
31976
+ if (!payload || typeof payload === 'string') return;
31977
+
31978
+ // Key is omitted when the user is not self-managed.
31979
+ setSelfManaged(payload.selfManaged === true);
31980
+ if (!isUserStatusAppsHidden() && Array.isArray(payload.appNames)) {
31981
+ var apps = statusAppsRef.current || [];
31982
+ var resolved = [];
31983
+ payload.appNames.forEach(function (name) {
31984
+ var match = findStatusAppForTile(apps, name);
31985
+ var code = (match === null || match === void 0 ? void 0 : match.code) || name;
31986
+ if (code && !resolved.includes(code)) resolved.push(code);
31987
+ });
31988
+ setSelectedAppNames(resolved);
31989
+ }
31962
31990
  };
31963
31991
  React.useEffect(function () {
31964
31992
  if (isSystemMarkedOffline(currentUserStatus) && !isUserStatusHidden()) {
@@ -70065,21 +70093,124 @@ function isAllowedOrigin(origin) {
70065
70093
  }
70066
70094
 
70067
70095
  // window.parent.postMessage copies its payload with the structured clone algorithm, which
70068
- // cannot clone a FormData (DataCloneError). Its entries can be cloned: strings, File and
70069
- // Blob values all survive, so the bridge sends the entries and the shell rebuilds the FormData.
70096
+ // cannot clone a FormData (DataCloneError). Strings clone fine. A File cloned from the
70097
+ // iframe is not safe to upload from the shell: prod Chrome reads that blob and fails the
70098
+ // XHR with net::ERR_ACCESS_DENIED before any HTTP status. Read the bytes in the iframe,
70099
+ // where the file is local, and send those bytes so the shell can build a File it owns.
70070
70100
  var FORM_DATA_BODY_TYPE = 'formData';
70101
+ var BLOB_BODY_TYPE = 'blob';
70102
+ var FORM_FILE_ENTRY = 'formFile';
70071
70103
  function isFormData(value) {
70072
70104
  return typeof FormData !== 'undefined' && value instanceof FormData;
70073
70105
  }
70106
+ function isBlob(value) {
70107
+ return typeof Blob !== 'undefined' && value instanceof Blob;
70108
+ }
70109
+
70110
+ // Bytes the shell can turn back into a File or Blob it owns.
70111
+ function serializeBlob(_x) {
70112
+ return _serializeBlob.apply(this, arguments);
70113
+ }
70114
+ function _serializeBlob() {
70115
+ _serializeBlob = _asyncToGenerator$1(/*#__PURE__*/_regenerator().m(function _callee(value) {
70116
+ var _t, _t2, _t3, _t4, _t5;
70117
+ return _regenerator().w(function (_context) {
70118
+ while (1) switch (_context.n) {
70119
+ case 0:
70120
+ _t = FORM_FILE_ENTRY;
70121
+ _t2 = value.name || 'blob';
70122
+ _t3 = value.type || '';
70123
+ _t4 = value.lastModified || Date.now();
70124
+ _context.n = 1;
70125
+ return value.arrayBuffer();
70126
+ case 1:
70127
+ _t5 = _context.v;
70128
+ return _context.a(2, {
70129
+ kind: _t,
70130
+ name: _t2,
70131
+ type: _t3,
70132
+ lastModified: _t4,
70133
+ buffer: _t5
70134
+ });
70135
+ }
70136
+ }, _callee);
70137
+ }));
70138
+ return _serializeBlob.apply(this, arguments);
70139
+ }
70140
+ function materializeBlob(value) {
70141
+ if (!value || value.kind !== FORM_FILE_ENTRY || !(value.buffer instanceof ArrayBuffer)) return null;
70142
+ if (typeof File !== 'undefined' && value.name && value.name !== 'blob') {
70143
+ return new File([value.buffer], value.name, {
70144
+ type: value.type || '',
70145
+ lastModified: value.lastModified
70146
+ });
70147
+ }
70148
+ return new Blob([value.buffer], {
70149
+ type: value.type || ''
70150
+ });
70151
+ }
70074
70152
 
70075
70153
  // [[name, value], ...] in append order; duplicate names are kept.
70076
- function serializeFormData(formData) {
70077
- return Array.from(formData.entries());
70154
+ // File and Blob values become { kind, name, type, lastModified, buffer }.
70155
+ function serializeFormData(_x2) {
70156
+ return _serializeFormData.apply(this, arguments);
70078
70157
  }
70079
70158
 
70080
70159
  // The iframe app sets Content-Type: multipart/form-data with no boundary. The browser
70081
70160
  // adds the boundary only when it sends a FormData itself, so that header must not be
70082
70161
  // forwarded. Axios 0.18 also drops Content-Type when the body is a FormData.
70162
+ function _serializeFormData() {
70163
+ _serializeFormData = _asyncToGenerator$1(/*#__PURE__*/_regenerator().m(function _callee2(formData) {
70164
+ var entries, _iterator, _step, _step$value, name, value, _t6, _t7, _t8, _t9;
70165
+ return _regenerator().w(function (_context2) {
70166
+ while (1) switch (_context2.p = _context2.n) {
70167
+ case 0:
70168
+ entries = [];
70169
+ _iterator = _createForOfIteratorHelper(formData.entries());
70170
+ _context2.p = 1;
70171
+ _iterator.s();
70172
+ case 2:
70173
+ if ((_step = _iterator.n()).done) {
70174
+ _context2.n = 6;
70175
+ break;
70176
+ }
70177
+ _step$value = _slicedToArray(_step.value, 2), name = _step$value[0], value = _step$value[1];
70178
+ if (!isBlob(value)) {
70179
+ _context2.n = 4;
70180
+ break;
70181
+ }
70182
+ _t6 = entries;
70183
+ _t7 = name;
70184
+ _context2.n = 3;
70185
+ return serializeBlob(value);
70186
+ case 3:
70187
+ _t8 = _context2.v;
70188
+ _t6.push.call(_t6, [_t7, _t8]);
70189
+ _context2.n = 5;
70190
+ break;
70191
+ case 4:
70192
+ entries.push([name, value]);
70193
+ case 5:
70194
+ _context2.n = 2;
70195
+ break;
70196
+ case 6:
70197
+ _context2.n = 8;
70198
+ break;
70199
+ case 7:
70200
+ _context2.p = 7;
70201
+ _t9 = _context2.v;
70202
+ _iterator.e(_t9);
70203
+ case 8:
70204
+ _context2.p = 8;
70205
+ _iterator.f();
70206
+ return _context2.f(8);
70207
+ case 9:
70208
+ return _context2.a(2, entries);
70209
+ }
70210
+ }, _callee2, null, [[1, 7, 8, 9]]);
70211
+ }));
70212
+ return _serializeFormData.apply(this, arguments);
70213
+ }
70083
70214
  function headersForFormData(headers) {
70084
70215
  if (!headers || _typeof$1(headers) !== 'object') return headers;
70085
70216
  var next = _objectSpread2({}, headers);
@@ -70503,17 +70634,18 @@ function handleMessage(event) {
70503
70634
  switch (data.eventType) {
70504
70635
  case IFRAME_EVENTS.FETCH_RESPONSE:
70505
70636
  if ('error' in eventProps) {
70506
- var _eventProps$error, _eventProps$error2, _eventProps$error3, _eventProps$error4, _eventProps$error5;
70637
+ var _eventProps$error, _eventProps$error2, _eventProps$error3, _eventProps$error4, _eventProps$error5, _eventProps$error6, _eventProps$error7, _eventProps$error8;
70507
70638
  var err = new Error(((_eventProps$error = eventProps.error) === null || _eventProps$error === void 0 ? void 0 : _eventProps$error.message) || 'Fetch failed');
70508
- err.response = ((_eventProps$error2 = eventProps.error) === null || _eventProps$error2 === void 0 ? void 0 : _eventProps$error2.status) != null ? {
70509
- data: (_eventProps$error3 = eventProps.error) === null || _eventProps$error3 === void 0 ? void 0 : _eventProps$error3.data,
70510
- status: (_eventProps$error4 = eventProps.error) === null || _eventProps$error4 === void 0 ? void 0 : _eventProps$error4.status,
70511
- headers: (_eventProps$error5 = eventProps.error) === null || _eventProps$error5 === void 0 ? void 0 : _eventProps$error5.headers
70639
+ var errorBody = ((_eventProps$error2 = eventProps.error) === null || _eventProps$error2 === void 0 ? void 0 : _eventProps$error2.bodyType) === BLOB_BODY_TYPE ? materializeBlob((_eventProps$error3 = eventProps.error) === null || _eventProps$error3 === void 0 ? void 0 : _eventProps$error3.data) || ((_eventProps$error4 = eventProps.error) === null || _eventProps$error4 === void 0 ? void 0 : _eventProps$error4.data) : (_eventProps$error5 = eventProps.error) === null || _eventProps$error5 === void 0 ? void 0 : _eventProps$error5.data;
70640
+ err.response = ((_eventProps$error6 = eventProps.error) === null || _eventProps$error6 === void 0 ? void 0 : _eventProps$error6.status) != null ? {
70641
+ data: errorBody,
70642
+ status: (_eventProps$error7 = eventProps.error) === null || _eventProps$error7 === void 0 ? void 0 : _eventProps$error7.status,
70643
+ headers: (_eventProps$error8 = eventProps.error) === null || _eventProps$error8 === void 0 ? void 0 : _eventProps$error8.headers
70512
70644
  } : eventProps.error;
70513
70645
  reject(err);
70514
70646
  } else {
70515
- var _eventProps$result;
70516
- var resultData = (_eventProps$result = eventProps.result) === null || _eventProps$result === void 0 ? void 0 : _eventProps$result.data;
70647
+ var result = eventProps.result || {};
70648
+ var resultData = result.data;
70517
70649
  if (pendingResponseType === 'arraybuffer') {
70518
70650
  if (!(resultData instanceof ArrayBuffer)) {
70519
70651
  console.warn("".concat(LOG_PREFIX, " FETCH_RESPONSE expected ArrayBuffer but got non-binary"), {
@@ -70523,7 +70655,14 @@ function handleMessage(event) {
70523
70655
  });
70524
70656
  }
70525
70657
  }
70526
- resolve(eventProps.result);
70658
+ if (result.bodyType === BLOB_BODY_TYPE) {
70659
+ var blob = materializeBlob(resultData);
70660
+ resolve(blob ? _objectSpread2(_objectSpread2({}, result), {}, {
70661
+ data: blob
70662
+ }) : result);
70663
+ } else {
70664
+ resolve(result);
70665
+ }
70527
70666
  }
70528
70667
  break;
70529
70668
  case IFRAME_EVENTS.STORAGE_RESPONSE:
@@ -70543,13 +70682,6 @@ if (typeof window !== 'undefined') {
70543
70682
  function sendFetchRequest(payload) {
70544
70683
  var signal = payload.signal,
70545
70684
  rest = _objectWithoutProperties(payload, _excluded$1);
70546
- // A FormData body cannot be posted to the shell as-is (see ./formData.js). It is sent as
70547
- // its entries, flagged with bodyType so the shell knows to rebuild it.
70548
- var restPayload = isFormData(rest.data) ? _objectSpread2(_objectSpread2({}, rest), {}, {
70549
- data: serializeFormData(rest.data),
70550
- bodyType: FORM_DATA_BODY_TYPE,
70551
- headers: headersForFormData(rest.headers)
70552
- }) : rest;
70553
70685
  return new Promise(function (resolve, reject) {
70554
70686
  if (signal !== null && signal !== void 0 && signal.aborted) {
70555
70687
  reject(new DOMException('Request aborted', 'AbortError'));
@@ -70580,22 +70712,48 @@ function sendFetchRequest(payload) {
70580
70712
  pending.delete(id);
70581
70713
  if (signal && onAbort) signal.removeEventListener('abort', onAbort);
70582
70714
  };
70583
- var sent;
70584
- try {
70585
- sent = post(IFRAME_EVENTS.FETCH_REQUEST, _objectSpread2(_objectSpread2({}, restPayload), {}, {
70586
- requestId: id
70715
+ var postRequest = function postRequest(restPayload) {
70716
+ if (!pending.has(id)) return;
70717
+ var sent;
70718
+ try {
70719
+ sent = post(IFRAME_EVENTS.FETCH_REQUEST, _objectSpread2(_objectSpread2({}, restPayload), {}, {
70720
+ requestId: id
70721
+ }));
70722
+ } catch (error) {
70723
+ // postMessage throws DataCloneError for any body the structured clone cannot copy.
70724
+ // Without this the request stays in `pending` forever.
70725
+ dropPending();
70726
+ reject(error);
70727
+ return;
70728
+ }
70729
+ if (!sent) {
70730
+ dropPending();
70731
+ reject(new Error('iframe-bridge: FETCH_REQUEST blocked — shell origin not pinned'));
70732
+ }
70733
+ };
70734
+
70735
+ // A FormData or Blob cannot be posted for the shell to upload as-is (see ./formData.js).
70736
+ // Read the bytes here, where the file is local. The shell builds a body it owns.
70737
+ var sendOwnedBody = function sendOwnedBody(data, bodyType) {
70738
+ postRequest(_objectSpread2(_objectSpread2({}, rest), {}, {
70739
+ data: data,
70740
+ bodyType: bodyType,
70741
+ headers: headersForFormData(rest.headers)
70587
70742
  }));
70588
- } catch (error) {
70589
- // postMessage throws DataCloneError for any body the structured clone cannot copy.
70590
- // Without this the request stays in `pending` forever.
70591
- dropPending();
70592
- reject(error);
70743
+ };
70744
+ if (!isFormData(rest.data) && !isBlob(rest.data)) {
70745
+ postRequest(rest);
70593
70746
  return;
70594
70747
  }
70595
- if (!sent) {
70748
+ var pendingBody = isFormData(rest.data) ? serializeFormData(rest.data).then(function (entries) {
70749
+ return sendOwnedBody(entries, FORM_DATA_BODY_TYPE);
70750
+ }) : serializeBlob(rest.data).then(function (entry) {
70751
+ return sendOwnedBody(entry, BLOB_BODY_TYPE);
70752
+ });
70753
+ pendingBody.catch(function (error) {
70596
70754
  dropPending();
70597
- reject(new Error('iframe-bridge: FETCH_REQUEST blocked — shell origin not pinned'));
70598
- }
70755
+ reject(error);
70756
+ });
70599
70757
  });
70600
70758
  }
70601
70759
  function sendStorageGet(payload) {