@copart/ops-tool-kit 1.13.6 → 1.13.7-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,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.0";
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,
@@ -70065,21 +70065,124 @@ function isAllowedOrigin(origin) {
70065
70065
  }
70066
70066
 
70067
70067
  // 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.
70068
+ // cannot clone a FormData (DataCloneError). Strings clone fine. A File cloned from the
70069
+ // iframe is not safe to upload from the shell: prod Chrome reads that blob and fails the
70070
+ // XHR with net::ERR_ACCESS_DENIED before any HTTP status. Read the bytes in the iframe,
70071
+ // where the file is local, and send those bytes so the shell can build a File it owns.
70070
70072
  var FORM_DATA_BODY_TYPE = 'formData';
70073
+ var BLOB_BODY_TYPE = 'blob';
70074
+ var FORM_FILE_ENTRY = 'formFile';
70071
70075
  function isFormData(value) {
70072
70076
  return typeof FormData !== 'undefined' && value instanceof FormData;
70073
70077
  }
70078
+ function isBlob(value) {
70079
+ return typeof Blob !== 'undefined' && value instanceof Blob;
70080
+ }
70081
+
70082
+ // Bytes the shell can turn back into a File or Blob it owns.
70083
+ function serializeBlob(_x) {
70084
+ return _serializeBlob.apply(this, arguments);
70085
+ }
70086
+ function _serializeBlob() {
70087
+ _serializeBlob = _asyncToGenerator$1(/*#__PURE__*/_regenerator().m(function _callee(value) {
70088
+ var _t, _t2, _t3, _t4, _t5;
70089
+ return _regenerator().w(function (_context) {
70090
+ while (1) switch (_context.n) {
70091
+ case 0:
70092
+ _t = FORM_FILE_ENTRY;
70093
+ _t2 = value.name || 'blob';
70094
+ _t3 = value.type || '';
70095
+ _t4 = value.lastModified || Date.now();
70096
+ _context.n = 1;
70097
+ return value.arrayBuffer();
70098
+ case 1:
70099
+ _t5 = _context.v;
70100
+ return _context.a(2, {
70101
+ kind: _t,
70102
+ name: _t2,
70103
+ type: _t3,
70104
+ lastModified: _t4,
70105
+ buffer: _t5
70106
+ });
70107
+ }
70108
+ }, _callee);
70109
+ }));
70110
+ return _serializeBlob.apply(this, arguments);
70111
+ }
70112
+ function materializeBlob(value) {
70113
+ if (!value || value.kind !== FORM_FILE_ENTRY || !(value.buffer instanceof ArrayBuffer)) return null;
70114
+ if (typeof File !== 'undefined' && value.name && value.name !== 'blob') {
70115
+ return new File([value.buffer], value.name, {
70116
+ type: value.type || '',
70117
+ lastModified: value.lastModified
70118
+ });
70119
+ }
70120
+ return new Blob([value.buffer], {
70121
+ type: value.type || ''
70122
+ });
70123
+ }
70074
70124
 
70075
70125
  // [[name, value], ...] in append order; duplicate names are kept.
70076
- function serializeFormData(formData) {
70077
- return Array.from(formData.entries());
70126
+ // File and Blob values become { kind, name, type, lastModified, buffer }.
70127
+ function serializeFormData(_x2) {
70128
+ return _serializeFormData.apply(this, arguments);
70078
70129
  }
70079
70130
 
70080
70131
  // The iframe app sets Content-Type: multipart/form-data with no boundary. The browser
70081
70132
  // adds the boundary only when it sends a FormData itself, so that header must not be
70082
70133
  // forwarded. Axios 0.18 also drops Content-Type when the body is a FormData.
70134
+ function _serializeFormData() {
70135
+ _serializeFormData = _asyncToGenerator$1(/*#__PURE__*/_regenerator().m(function _callee2(formData) {
70136
+ var entries, _iterator, _step, _step$value, name, value, _t6, _t7, _t8, _t9;
70137
+ return _regenerator().w(function (_context2) {
70138
+ while (1) switch (_context2.p = _context2.n) {
70139
+ case 0:
70140
+ entries = [];
70141
+ _iterator = _createForOfIteratorHelper(formData.entries());
70142
+ _context2.p = 1;
70143
+ _iterator.s();
70144
+ case 2:
70145
+ if ((_step = _iterator.n()).done) {
70146
+ _context2.n = 6;
70147
+ break;
70148
+ }
70149
+ _step$value = _slicedToArray(_step.value, 2), name = _step$value[0], value = _step$value[1];
70150
+ if (!isBlob(value)) {
70151
+ _context2.n = 4;
70152
+ break;
70153
+ }
70154
+ _t6 = entries;
70155
+ _t7 = name;
70156
+ _context2.n = 3;
70157
+ return serializeBlob(value);
70158
+ case 3:
70159
+ _t8 = _context2.v;
70160
+ _t6.push.call(_t6, [_t7, _t8]);
70161
+ _context2.n = 5;
70162
+ break;
70163
+ case 4:
70164
+ entries.push([name, value]);
70165
+ case 5:
70166
+ _context2.n = 2;
70167
+ break;
70168
+ case 6:
70169
+ _context2.n = 8;
70170
+ break;
70171
+ case 7:
70172
+ _context2.p = 7;
70173
+ _t9 = _context2.v;
70174
+ _iterator.e(_t9);
70175
+ case 8:
70176
+ _context2.p = 8;
70177
+ _iterator.f();
70178
+ return _context2.f(8);
70179
+ case 9:
70180
+ return _context2.a(2, entries);
70181
+ }
70182
+ }, _callee2, null, [[1, 7, 8, 9]]);
70183
+ }));
70184
+ return _serializeFormData.apply(this, arguments);
70185
+ }
70083
70186
  function headersForFormData(headers) {
70084
70187
  if (!headers || _typeof$1(headers) !== 'object') return headers;
70085
70188
  var next = _objectSpread2({}, headers);
@@ -70503,17 +70606,18 @@ function handleMessage(event) {
70503
70606
  switch (data.eventType) {
70504
70607
  case IFRAME_EVENTS.FETCH_RESPONSE:
70505
70608
  if ('error' in eventProps) {
70506
- var _eventProps$error, _eventProps$error2, _eventProps$error3, _eventProps$error4, _eventProps$error5;
70609
+ var _eventProps$error, _eventProps$error2, _eventProps$error3, _eventProps$error4, _eventProps$error5, _eventProps$error6, _eventProps$error7, _eventProps$error8;
70507
70610
  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
70611
+ 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;
70612
+ err.response = ((_eventProps$error6 = eventProps.error) === null || _eventProps$error6 === void 0 ? void 0 : _eventProps$error6.status) != null ? {
70613
+ data: errorBody,
70614
+ status: (_eventProps$error7 = eventProps.error) === null || _eventProps$error7 === void 0 ? void 0 : _eventProps$error7.status,
70615
+ headers: (_eventProps$error8 = eventProps.error) === null || _eventProps$error8 === void 0 ? void 0 : _eventProps$error8.headers
70512
70616
  } : eventProps.error;
70513
70617
  reject(err);
70514
70618
  } else {
70515
- var _eventProps$result;
70516
- var resultData = (_eventProps$result = eventProps.result) === null || _eventProps$result === void 0 ? void 0 : _eventProps$result.data;
70619
+ var result = eventProps.result || {};
70620
+ var resultData = result.data;
70517
70621
  if (pendingResponseType === 'arraybuffer') {
70518
70622
  if (!(resultData instanceof ArrayBuffer)) {
70519
70623
  console.warn("".concat(LOG_PREFIX, " FETCH_RESPONSE expected ArrayBuffer but got non-binary"), {
@@ -70523,7 +70627,14 @@ function handleMessage(event) {
70523
70627
  });
70524
70628
  }
70525
70629
  }
70526
- resolve(eventProps.result);
70630
+ if (result.bodyType === BLOB_BODY_TYPE) {
70631
+ var blob = materializeBlob(resultData);
70632
+ resolve(blob ? _objectSpread2(_objectSpread2({}, result), {}, {
70633
+ data: blob
70634
+ }) : result);
70635
+ } else {
70636
+ resolve(result);
70637
+ }
70527
70638
  }
70528
70639
  break;
70529
70640
  case IFRAME_EVENTS.STORAGE_RESPONSE:
@@ -70543,13 +70654,6 @@ if (typeof window !== 'undefined') {
70543
70654
  function sendFetchRequest(payload) {
70544
70655
  var signal = payload.signal,
70545
70656
  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
70657
  return new Promise(function (resolve, reject) {
70554
70658
  if (signal !== null && signal !== void 0 && signal.aborted) {
70555
70659
  reject(new DOMException('Request aborted', 'AbortError'));
@@ -70580,22 +70684,48 @@ function sendFetchRequest(payload) {
70580
70684
  pending.delete(id);
70581
70685
  if (signal && onAbort) signal.removeEventListener('abort', onAbort);
70582
70686
  };
70583
- var sent;
70584
- try {
70585
- sent = post(IFRAME_EVENTS.FETCH_REQUEST, _objectSpread2(_objectSpread2({}, restPayload), {}, {
70586
- requestId: id
70687
+ var postRequest = function postRequest(restPayload) {
70688
+ if (!pending.has(id)) return;
70689
+ var sent;
70690
+ try {
70691
+ sent = post(IFRAME_EVENTS.FETCH_REQUEST, _objectSpread2(_objectSpread2({}, restPayload), {}, {
70692
+ requestId: id
70693
+ }));
70694
+ } catch (error) {
70695
+ // postMessage throws DataCloneError for any body the structured clone cannot copy.
70696
+ // Without this the request stays in `pending` forever.
70697
+ dropPending();
70698
+ reject(error);
70699
+ return;
70700
+ }
70701
+ if (!sent) {
70702
+ dropPending();
70703
+ reject(new Error('iframe-bridge: FETCH_REQUEST blocked — shell origin not pinned'));
70704
+ }
70705
+ };
70706
+
70707
+ // A FormData or Blob cannot be posted for the shell to upload as-is (see ./formData.js).
70708
+ // Read the bytes here, where the file is local. The shell builds a body it owns.
70709
+ var sendOwnedBody = function sendOwnedBody(data, bodyType) {
70710
+ postRequest(_objectSpread2(_objectSpread2({}, rest), {}, {
70711
+ data: data,
70712
+ bodyType: bodyType,
70713
+ headers: headersForFormData(rest.headers)
70587
70714
  }));
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);
70715
+ };
70716
+ if (!isFormData(rest.data) && !isBlob(rest.data)) {
70717
+ postRequest(rest);
70593
70718
  return;
70594
70719
  }
70595
- if (!sent) {
70720
+ var pendingBody = isFormData(rest.data) ? serializeFormData(rest.data).then(function (entries) {
70721
+ return sendOwnedBody(entries, FORM_DATA_BODY_TYPE);
70722
+ }) : serializeBlob(rest.data).then(function (entry) {
70723
+ return sendOwnedBody(entry, BLOB_BODY_TYPE);
70724
+ });
70725
+ pendingBody.catch(function (error) {
70596
70726
  dropPending();
70597
- reject(new Error('iframe-bridge: FETCH_REQUEST blocked — shell origin not pinned'));
70598
- }
70727
+ reject(error);
70728
+ });
70599
70729
  });
70600
70730
  }
70601
70731
  function sendStorageGet(payload) {