@commercetools-frontend-extensions/operations 2.0.1 → 3.1.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 +20 -0
- package/README.md +138 -71
- package/dist/commercetools-frontend-extensions-operations.cjs.dev.js +979 -143
- package/dist/commercetools-frontend-extensions-operations.cjs.prod.js +979 -143
- package/dist/commercetools-frontend-extensions-operations.esm.js +929 -140
- package/dist/declarations/src/@api/file-import-jobs.d.ts +7 -0
- package/dist/declarations/src/@api/index.d.ts +1 -0
- package/dist/declarations/src/@api/test-fixtures.d.ts +8 -1
- package/dist/declarations/src/@api/urls.d.ts +30 -0
- package/dist/declarations/src/@components/uploading-modal/uploading-modal.d.ts +3 -2
- package/dist/declarations/src/@constants/file-import-job.d.ts +1 -0
- package/dist/declarations/src/@constants/import-limits.d.ts +6 -0
- package/dist/declarations/src/@constants/index.d.ts +2 -1
- package/dist/declarations/src/@errors/index.d.ts +5 -4
- package/dist/declarations/src/@errors/polling-aborted-error.d.ts +3 -0
- package/dist/declarations/src/@hooks/index.d.ts +4 -0
- package/dist/declarations/src/@hooks/use-fetch-file-import-job-records.d.ts +18 -0
- package/dist/declarations/src/@hooks/use-fetch-file-import-job.d.ts +17 -0
- package/dist/declarations/src/@hooks/use-file-import-job-upload.d.ts +18 -0
- package/dist/declarations/src/@hooks/use-file-upload.d.ts +29 -0
- package/dist/declarations/src/@hooks/use-import-container-upload.d.ts +2 -1
- package/dist/declarations/src/@types/export-operation.d.ts +3 -1
- package/dist/declarations/src/@types/file-import-job.d.ts +99 -0
- package/dist/declarations/src/@types/file-upload-result.d.ts +21 -0
- package/dist/declarations/src/@types/file-upload.d.ts +2 -2
- package/dist/declarations/src/@types/index.d.ts +2 -0
- package/dist/declarations/src/@utils/file-import-job-helpers.d.ts +12 -0
- package/dist/declarations/src/@utils/file-upload.d.ts +8 -0
- package/dist/declarations/src/@utils/index.d.ts +2 -0
- package/dist/declarations/src/@utils/poll-job-until-validated.d.ts +11 -0
- package/package.json +12 -13
- package/src/@api/fetcher.ts +10 -0
- package/src/@api/file-import-jobs.ts +217 -0
- package/src/@api/file-upload.spec.ts +4 -2
- package/src/@api/index.ts +1 -0
- package/src/@api/test-fixtures.ts +127 -5
- package/src/@api/urls.ts +77 -1
- package/src/@components/uploading-modal/uploading-modal.tsx +7 -5
- package/src/@constants/file-import-job.ts +1 -0
- package/src/@constants/import-limits.ts +13 -0
- package/src/@constants/index.ts +2 -1
- package/src/@errors/index.ts +5 -4
- package/src/@errors/polling-aborted-error.ts +6 -0
- package/src/@hooks/index.ts +4 -0
- package/src/@hooks/use-fetch-file-import-job-records.ts +58 -0
- package/src/@hooks/use-fetch-file-import-job.spec.ts +131 -0
- package/src/@hooks/use-fetch-file-import-job.ts +38 -0
- package/src/@hooks/use-fetch.spec.ts +1 -9
- package/src/@hooks/use-fetch.ts +4 -8
- package/src/@hooks/use-file-import-job-upload.spec.ts +273 -0
- package/src/@hooks/use-file-import-job-upload.ts +101 -0
- package/src/@hooks/use-file-upload.ts +231 -0
- package/src/@hooks/use-import-container-upload.spec.ts +16 -13
- package/src/@hooks/use-import-container-upload.ts +6 -2
- package/src/@types/export-operation.ts +3 -0
- package/src/@types/file-import-job.ts +165 -0
- package/src/@types/file-upload-result.ts +23 -0
- package/src/@types/file-upload.ts +2 -2
- package/src/@types/index.ts +2 -0
- package/src/@utils/error-mapping.ts +10 -9
- package/src/@utils/file-import-job-helpers.spec.ts +147 -0
- package/src/@utils/file-import-job-helpers.ts +47 -0
- package/src/@utils/file-upload.ts +39 -0
- package/src/@utils/index.ts +2 -0
- package/src/@utils/poll-job-until-validated.ts +76 -0
- package/dist/declarations/src/@constants/upload-limits.d.ts +0 -10
- package/src/@constants/upload-limits.ts +0 -11
- package/src/@hooks/messages.ts +0 -11
|
@@ -18,8 +18,8 @@ import _inherits from '@babel/runtime-corejs3/helpers/esm/inherits';
|
|
|
18
18
|
import _wrapNativeSuper from '@babel/runtime-corejs3/helpers/esm/wrapNativeSuper';
|
|
19
19
|
import { MC_API_PROXY_TARGETS } from '@commercetools-frontend/constants';
|
|
20
20
|
import _everyInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/every';
|
|
21
|
-
import { plural } from 'pluralize';
|
|
22
21
|
import _Array$isArray from '@babel/runtime-corejs3/core-js-stable/array/is-array';
|
|
22
|
+
import { plural } from 'pluralize';
|
|
23
23
|
import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
|
|
24
24
|
import _flatMapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/flat-map';
|
|
25
25
|
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
|
@@ -27,108 +27,113 @@ import _Promise from '@babel/runtime-corejs3/core-js-stable/promise';
|
|
|
27
27
|
import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
|
|
28
28
|
import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
|
|
29
29
|
import _someInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/some';
|
|
30
|
+
import _Set from '@babel/runtime-corejs3/core-js-stable/set';
|
|
31
|
+
import _findIndexInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find-index';
|
|
32
|
+
import _trimInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/trim';
|
|
33
|
+
import _bindInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/bind';
|
|
30
34
|
import Papa from 'papaparse';
|
|
31
35
|
import _sliceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/slice';
|
|
32
36
|
import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
|
|
33
|
-
import _bindInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/bind';
|
|
34
37
|
import _startsWithInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/starts-with';
|
|
38
|
+
import _setTimeout from '@babel/runtime-corejs3/core-js-stable/set-timeout';
|
|
39
|
+
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
35
40
|
import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
|
|
36
41
|
import _URLSearchParams from '@babel/runtime-corejs3/core-js-stable/url-search-params';
|
|
37
42
|
import _Object$entries from '@babel/runtime-corejs3/core-js-stable/object/entries';
|
|
38
|
-
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
39
43
|
import { Spacings, Text, Link, PaperclipIcon, Constraints, SecondaryButton, customProperties, ContentNotification, SelectField, CheckboxInput, ProgressBar } from '@commercetools-frontend/ui-kit';
|
|
40
44
|
import React from 'react';
|
|
41
45
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
42
46
|
import { css } from '@emotion/react';
|
|
43
47
|
import _styled from '@emotion/styled/base';
|
|
44
48
|
import { useDropzone } from 'react-dropzone';
|
|
45
|
-
import { useIntl, defineMessages } from 'react-intl';
|
|
46
49
|
import { InfoDialog } from '@commercetools-frontend/application-components';
|
|
47
50
|
import _setInterval from '@babel/runtime-corejs3/core-js-stable/set-interval';
|
|
48
51
|
import { reportErrorToSentry } from '@commercetools-frontend/sentry';
|
|
49
52
|
|
|
53
|
+
function _callSuper$8(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$8() ? _Reflect$construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
54
|
+
function _isNativeReflectConstruct$8() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$8 = function () { return !!t; })(); }
|
|
55
|
+
let HttpError = /*#__PURE__*/function (_Error) {
|
|
56
|
+
function HttpError(statusCode, statusText, errorData) {
|
|
57
|
+
var _this;
|
|
58
|
+
_classCallCheck(this, HttpError);
|
|
59
|
+
_this = _callSuper$8(this, HttpError, [`HTTP Error! Status code: ${statusCode}, message: "${statusText ? statusText : ''}"`]);
|
|
60
|
+
_this.statusCode = void 0;
|
|
61
|
+
_this.errorData = void 0;
|
|
62
|
+
_this.name = 'HttpError';
|
|
63
|
+
_this.statusCode = statusCode;
|
|
64
|
+
_this.errorData = errorData;
|
|
65
|
+
return _this;
|
|
66
|
+
}
|
|
67
|
+
_inherits(HttpError, _Error);
|
|
68
|
+
return _createClass(HttpError);
|
|
69
|
+
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
70
|
+
|
|
50
71
|
function _callSuper$7(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$7() ? _Reflect$construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
51
72
|
function _isNativeReflectConstruct$7() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$7 = function () { return !!t; })(); }
|
|
52
|
-
let
|
|
53
|
-
function
|
|
73
|
+
let InvalidResponseError = /*#__PURE__*/function (_Error) {
|
|
74
|
+
function InvalidResponseError(message) {
|
|
54
75
|
var _this;
|
|
55
|
-
_classCallCheck(this,
|
|
56
|
-
_this = _callSuper$7(this,
|
|
57
|
-
_this.name = '
|
|
76
|
+
_classCallCheck(this, InvalidResponseError);
|
|
77
|
+
_this = _callSuper$7(this, InvalidResponseError, [message]);
|
|
78
|
+
_this.name = 'InvalidResponseError';
|
|
58
79
|
return _this;
|
|
59
80
|
}
|
|
60
|
-
_inherits(
|
|
61
|
-
return _createClass(
|
|
81
|
+
_inherits(InvalidResponseError, _Error);
|
|
82
|
+
return _createClass(InvalidResponseError);
|
|
62
83
|
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
63
84
|
|
|
64
85
|
function _callSuper$6(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$6() ? _Reflect$construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
65
86
|
function _isNativeReflectConstruct$6() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$6 = function () { return !!t; })(); }
|
|
66
|
-
let
|
|
67
|
-
function
|
|
87
|
+
let NoResourcesToExportError = /*#__PURE__*/function (_Error) {
|
|
88
|
+
function NoResourcesToExportError() {
|
|
68
89
|
var _this;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
_this
|
|
90
|
+
let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'There are no resources to export.';
|
|
91
|
+
_classCallCheck(this, NoResourcesToExportError);
|
|
92
|
+
_this = _callSuper$6(this, NoResourcesToExportError, [message]);
|
|
93
|
+
_this.name = 'NoResourcesToExportError';
|
|
72
94
|
return _this;
|
|
73
95
|
}
|
|
74
|
-
_inherits(
|
|
75
|
-
return _createClass(
|
|
96
|
+
_inherits(NoResourcesToExportError, _Error);
|
|
97
|
+
return _createClass(NoResourcesToExportError);
|
|
76
98
|
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
77
99
|
|
|
78
100
|
function _callSuper$5(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$5() ? _Reflect$construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
79
101
|
function _isNativeReflectConstruct$5() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$5 = function () { return !!t; })(); }
|
|
80
|
-
let
|
|
81
|
-
function
|
|
102
|
+
let PollingAbortedError = /*#__PURE__*/function (_Error) {
|
|
103
|
+
function PollingAbortedError() {
|
|
82
104
|
var _this;
|
|
83
|
-
_classCallCheck(this,
|
|
84
|
-
_this = _callSuper$5(this,
|
|
85
|
-
_this.name = '
|
|
105
|
+
_classCallCheck(this, PollingAbortedError);
|
|
106
|
+
_this = _callSuper$5(this, PollingAbortedError, ['Polling was aborted']);
|
|
107
|
+
_this.name = 'PollingAbortedError';
|
|
86
108
|
return _this;
|
|
87
109
|
}
|
|
88
|
-
_inherits(
|
|
89
|
-
return _createClass(
|
|
110
|
+
_inherits(PollingAbortedError, _Error);
|
|
111
|
+
return _createClass(PollingAbortedError);
|
|
90
112
|
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
91
113
|
|
|
92
114
|
function _callSuper$4(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$4() ? _Reflect$construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
93
115
|
function _isNativeReflectConstruct$4() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$4 = function () { return !!t; })(); }
|
|
94
|
-
let
|
|
95
|
-
function
|
|
116
|
+
let ProjectKeyNotAvailableError = /*#__PURE__*/function (_Error) {
|
|
117
|
+
function ProjectKeyNotAvailableError() {
|
|
96
118
|
var _this;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
_this
|
|
100
|
-
_this.
|
|
101
|
-
_this.name = 'HttpError';
|
|
102
|
-
_this.statusCode = statusCode;
|
|
103
|
-
_this.errorData = errorData;
|
|
119
|
+
let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Project key is not available';
|
|
120
|
+
_classCallCheck(this, ProjectKeyNotAvailableError);
|
|
121
|
+
_this = _callSuper$4(this, ProjectKeyNotAvailableError, [message]);
|
|
122
|
+
_this.name = 'ProjectKeyNotAvailableError';
|
|
104
123
|
return _this;
|
|
105
124
|
}
|
|
106
|
-
_inherits(
|
|
107
|
-
return _createClass(
|
|
125
|
+
_inherits(ProjectKeyNotAvailableError, _Error);
|
|
126
|
+
return _createClass(ProjectKeyNotAvailableError);
|
|
108
127
|
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
109
128
|
|
|
110
129
|
function _callSuper$3(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$3() ? _Reflect$construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
111
130
|
function _isNativeReflectConstruct$3() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$3 = function () { return !!t; })(); }
|
|
112
|
-
let InvalidResponseError = /*#__PURE__*/function (_Error) {
|
|
113
|
-
function InvalidResponseError(message) {
|
|
114
|
-
var _this;
|
|
115
|
-
_classCallCheck(this, InvalidResponseError);
|
|
116
|
-
_this = _callSuper$3(this, InvalidResponseError, [message]);
|
|
117
|
-
_this.name = 'InvalidResponseError';
|
|
118
|
-
return _this;
|
|
119
|
-
}
|
|
120
|
-
_inherits(InvalidResponseError, _Error);
|
|
121
|
-
return _createClass(InvalidResponseError);
|
|
122
|
-
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
123
|
-
|
|
124
|
-
function _callSuper$2(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$2() ? _Reflect$construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
125
|
-
function _isNativeReflectConstruct$2() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$2 = function () { return !!t; })(); }
|
|
126
131
|
let QueryPredicateError = /*#__PURE__*/function (_Error) {
|
|
127
132
|
function QueryPredicateError() {
|
|
128
133
|
var _this;
|
|
129
134
|
let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'There is an error with the query predicate. Make sure the syntax is correct.';
|
|
130
135
|
_classCallCheck(this, QueryPredicateError);
|
|
131
|
-
_this = _callSuper$
|
|
136
|
+
_this = _callSuper$3(this, QueryPredicateError, [message]);
|
|
132
137
|
_this.field = 'queryPredicate';
|
|
133
138
|
_this.name = 'QueryPredicateError';
|
|
134
139
|
return _this;
|
|
@@ -137,38 +142,50 @@ let QueryPredicateError = /*#__PURE__*/function (_Error) {
|
|
|
137
142
|
return _createClass(QueryPredicateError);
|
|
138
143
|
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
139
144
|
|
|
145
|
+
function _callSuper$2(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$2() ? _Reflect$construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
146
|
+
function _isNativeReflectConstruct$2() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$2 = function () { return !!t; })(); }
|
|
147
|
+
let UnexpectedColumnError = /*#__PURE__*/function (_Error) {
|
|
148
|
+
function UnexpectedColumnError(columnName) {
|
|
149
|
+
var _this;
|
|
150
|
+
_classCallCheck(this, UnexpectedColumnError);
|
|
151
|
+
_this = _callSuper$2(this, UnexpectedColumnError, [`Unexpected column "${columnName}"`]);
|
|
152
|
+
_this.name = 'UnexpectedColumnError';
|
|
153
|
+
return _this;
|
|
154
|
+
}
|
|
155
|
+
_inherits(UnexpectedColumnError, _Error);
|
|
156
|
+
return _createClass(UnexpectedColumnError);
|
|
157
|
+
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
158
|
+
|
|
140
159
|
function _callSuper$1(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$1() ? _Reflect$construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
141
160
|
function _isNativeReflectConstruct$1() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$1 = function () { return !!t; })(); }
|
|
142
|
-
let
|
|
143
|
-
function
|
|
161
|
+
let UnexpectedOperationStateError = /*#__PURE__*/function (_Error) {
|
|
162
|
+
function UnexpectedOperationStateError(state) {
|
|
144
163
|
var _this;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
_this =
|
|
148
|
-
_this.name = 'NoResourcesToExportError';
|
|
164
|
+
_classCallCheck(this, UnexpectedOperationStateError);
|
|
165
|
+
_this = _callSuper$1(this, UnexpectedOperationStateError, [`Unexpected operation state "${state}"`]);
|
|
166
|
+
_this.name = 'UnexpectedOperationStateError';
|
|
149
167
|
return _this;
|
|
150
168
|
}
|
|
151
|
-
_inherits(
|
|
152
|
-
return _createClass(
|
|
169
|
+
_inherits(UnexpectedOperationStateError, _Error);
|
|
170
|
+
return _createClass(UnexpectedOperationStateError);
|
|
153
171
|
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
154
172
|
|
|
155
173
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? _Reflect$construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
156
174
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
|
|
157
|
-
let
|
|
158
|
-
function
|
|
175
|
+
let UnexpectedResourceTypeError = /*#__PURE__*/function (_Error) {
|
|
176
|
+
function UnexpectedResourceTypeError(resourceType) {
|
|
159
177
|
var _this;
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
_this =
|
|
163
|
-
_this.name = 'ProjectKeyNotAvailableError';
|
|
178
|
+
_classCallCheck(this, UnexpectedResourceTypeError);
|
|
179
|
+
_this = _callSuper(this, UnexpectedResourceTypeError, [`Unexpected resource type "${resourceType}"`]);
|
|
180
|
+
_this.name = 'UnexpectedResourceTypeError';
|
|
164
181
|
return _this;
|
|
165
182
|
}
|
|
166
|
-
_inherits(
|
|
167
|
-
return _createClass(
|
|
183
|
+
_inherits(UnexpectedResourceTypeError, _Error);
|
|
184
|
+
return _createClass(UnexpectedResourceTypeError);
|
|
168
185
|
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
169
186
|
|
|
170
|
-
function ownKeys$
|
|
171
|
-
function _objectSpread$
|
|
187
|
+
function ownKeys$9(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
188
|
+
function _objectSpread$9(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context2 = ownKeys$9(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context3 = ownKeys$9(Object(t))).call(_context3, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
172
189
|
const addProxyPrefixToUrl = (uri, proxy) => {
|
|
173
190
|
return proxy ? `/proxy/${proxy}${uri}` : uri;
|
|
174
191
|
};
|
|
@@ -177,7 +194,7 @@ const fetcher = async _ref => {
|
|
|
177
194
|
payload = _ref.payload,
|
|
178
195
|
config = _ref.config;
|
|
179
196
|
const data = await executeHttpClientRequest(async options => {
|
|
180
|
-
const res = await fetch(buildApiUrl(addProxyPrefixToUrl(url, config?.proxy)), _objectSpread$
|
|
197
|
+
const res = await fetch(buildApiUrl(addProxyPrefixToUrl(url, config?.proxy)), _objectSpread$9(_objectSpread$9({}, options), {}, {
|
|
181
198
|
method: config?.method,
|
|
182
199
|
body: payload,
|
|
183
200
|
signal: config?.abortSignal
|
|
@@ -193,7 +210,7 @@ const fetcher = async _ref => {
|
|
|
193
210
|
getHeader: key => res.headers.get(key)
|
|
194
211
|
};
|
|
195
212
|
}, {
|
|
196
|
-
headers: _objectSpread$
|
|
213
|
+
headers: _objectSpread$9({
|
|
197
214
|
'Content-Type': 'application/json'
|
|
198
215
|
}, config?.headers)
|
|
199
216
|
});
|
|
@@ -207,7 +224,7 @@ const fetchUsingXhr = _ref2 => {
|
|
|
207
224
|
onSuccess = _ref2.onSuccess,
|
|
208
225
|
onError = _ref2.onError;
|
|
209
226
|
const options = createHttpClientOptions({
|
|
210
|
-
headers: _objectSpread$
|
|
227
|
+
headers: _objectSpread$9({
|
|
211
228
|
'Content-Type': 'application/json'
|
|
212
229
|
}, config?.headers)
|
|
213
230
|
});
|
|
@@ -249,6 +266,15 @@ const fetchUsingXhr = _ref2 => {
|
|
|
249
266
|
xhr.onabort = function () {
|
|
250
267
|
onError(new DOMException('Aborted', 'AbortError'));
|
|
251
268
|
};
|
|
269
|
+
if (config.abortSignal) {
|
|
270
|
+
if (config.abortSignal.aborted) {
|
|
271
|
+
xhr.abort();
|
|
272
|
+
} else {
|
|
273
|
+
config.abortSignal.addEventListener('abort', () => xhr.abort(), {
|
|
274
|
+
once: true
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}
|
|
252
278
|
xhr.send(payload);
|
|
253
279
|
return xhr;
|
|
254
280
|
};
|
|
@@ -288,6 +314,34 @@ function assertExportOperationsDownloadFileResponse(maybeExportOperationDownload
|
|
|
288
314
|
throw new Error('Invalid response');
|
|
289
315
|
}
|
|
290
316
|
|
|
317
|
+
function assertFileImportJob(maybeJob) {
|
|
318
|
+
const requiredFields = ['id', 'fileName', 'importContainerKey', 'state'];
|
|
319
|
+
if (hasRequiredFields(maybeJob, requiredFields)) return;
|
|
320
|
+
throw new Error('Invalid File Import Job response');
|
|
321
|
+
}
|
|
322
|
+
function assertFileImportJobRecordsResponse(maybeRecords) {
|
|
323
|
+
const requiredFields = ['results', 'total', 'limit', 'offset', 'count'];
|
|
324
|
+
if (!hasRequiredFields(maybeRecords, requiredFields)) {
|
|
325
|
+
throw new Error('Invalid File Import Job records response: missing required fields');
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function assertProcessFileImportJobResponse(maybeResponse) {
|
|
329
|
+
const requiredFields = ['message'];
|
|
330
|
+
if (hasRequiredFields(maybeResponse, requiredFields)) return;
|
|
331
|
+
throw new Error('Invalid Process File Import Job response');
|
|
332
|
+
}
|
|
333
|
+
function assertListFileImportJobsResponse(maybeResponse) {
|
|
334
|
+
if (!_Array$isArray(maybeResponse)) {
|
|
335
|
+
throw new Error('Invalid List File Import Jobs response: expected an array');
|
|
336
|
+
}
|
|
337
|
+
if (maybeResponse.length > 0) {
|
|
338
|
+
const requiredFields = ['id', 'fileName', 'importContainerKey', 'state'];
|
|
339
|
+
if (!hasRequiredFields(maybeResponse[0], requiredFields)) {
|
|
340
|
+
throw new Error('Invalid List File Import Jobs response: missing required fields');
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
291
345
|
function assertImportContainerPagedResponse(maybeImportContainerPagedResponse) {
|
|
292
346
|
const requiredFields = ['count', 'results'];
|
|
293
347
|
if (hasRequiredFields(maybeImportContainerPagedResponse, requiredFields)) return;
|
|
@@ -336,24 +390,24 @@ let ImportStates = /*#__PURE__*/function (ImportStates) {
|
|
|
336
390
|
return ImportStates;
|
|
337
391
|
}({});
|
|
338
392
|
|
|
339
|
-
function ownKeys$7(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
340
|
-
function _objectSpread$7(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context2 = ownKeys$7(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context3 = ownKeys$7(Object(t))).call(_context3, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
341
393
|
function getFileUploadErrorsCount(errors) {
|
|
342
394
|
if (!errors || !_Array$isArray(errors)) return 0;
|
|
343
395
|
return _reduceInstanceProperty(errors).call(errors, (acc, curr) => acc += curr.errors.length, 0);
|
|
344
396
|
}
|
|
397
|
+
|
|
398
|
+
// TODO: After fully migrating to new flow, remove `row` and only use `index`
|
|
345
399
|
function mapUploadFileErrorsResponseToUploadFileErrorRows(uploadFileErrorsResponse) {
|
|
346
400
|
if (!uploadFileErrorsResponse || !_Array$isArray(uploadFileErrorsResponse)) return [];
|
|
347
401
|
let idCounter = 1;
|
|
348
402
|
return _flatMapInstanceProperty(uploadFileErrorsResponse).call(uploadFileErrorsResponse, rowErrorsResponse => {
|
|
349
403
|
var _context;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
404
|
+
// TODO: use `row` if available, otherwise fall back to `index`
|
|
405
|
+
// Old flow uses `row`, new flow uses `index`
|
|
406
|
+
const rowNumber = rowErrorsResponse.row ?? rowErrorsResponse.index;
|
|
407
|
+
return _mapInstanceProperty(_context = rowErrorsResponse.errors).call(_context, rowError => ({
|
|
408
|
+
id: String(idCounter++),
|
|
409
|
+
row: rowNumber,
|
|
410
|
+
index: rowNumber,
|
|
357
411
|
field: rowError.field,
|
|
358
412
|
code: rowError.code,
|
|
359
413
|
validationMessage: rowError.message
|
|
@@ -361,8 +415,40 @@ function mapUploadFileErrorsResponseToUploadFileErrorRows(uploadFileErrorsRespon
|
|
|
361
415
|
});
|
|
362
416
|
}
|
|
363
417
|
|
|
364
|
-
function
|
|
365
|
-
|
|
418
|
+
function getFileImportJobFileType(resourceType) {
|
|
419
|
+
return resourceType === 'custom-object' ? 'json' : 'csv';
|
|
420
|
+
}
|
|
421
|
+
function toImportApiResourceType(resourceType) {
|
|
422
|
+
return resourceType === 'product' ? 'product-draft' : resourceType;
|
|
423
|
+
}
|
|
424
|
+
function isImportJobQueued(job) {
|
|
425
|
+
return job?.state === 'queued';
|
|
426
|
+
}
|
|
427
|
+
function isImportJobProcessing(job) {
|
|
428
|
+
return job?.state === 'processing';
|
|
429
|
+
}
|
|
430
|
+
function isImportJobValidated(job) {
|
|
431
|
+
return job?.state === 'validated';
|
|
432
|
+
}
|
|
433
|
+
function isImportJobInitializing(job) {
|
|
434
|
+
return job?.state === 'initialising';
|
|
435
|
+
}
|
|
436
|
+
function isImportJobReady(job) {
|
|
437
|
+
return job?.state === 'ready';
|
|
438
|
+
}
|
|
439
|
+
function isImportJobRejected(job) {
|
|
440
|
+
return job?.state === 'rejected';
|
|
441
|
+
}
|
|
442
|
+
function isImportJobTerminal(job) {
|
|
443
|
+
return isImportJobValidated(job) || isImportJobRejected(job);
|
|
444
|
+
}
|
|
445
|
+
function shouldContinuePollingForImportValidation(job) {
|
|
446
|
+
if (!job) return true;
|
|
447
|
+
return isImportJobQueued(job) || isImportJobProcessing(job);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function ownKeys$8(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
451
|
+
function _objectSpread$8(e) { for (var r = 1; r < arguments.length; r++) { var _context6, _context7; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context6 = ownKeys$8(Object(t), !0)).call(_context6, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context7 = ownKeys$8(Object(t))).call(_context7, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
366
452
|
|
|
367
453
|
/**
|
|
368
454
|
* Convert megabytes to bytes
|
|
@@ -481,6 +567,44 @@ const countJsonFileItems = async file => {
|
|
|
481
567
|
}
|
|
482
568
|
};
|
|
483
569
|
|
|
570
|
+
/**
|
|
571
|
+
* Count unique resources in a CSV file by counting unique values in the "key" column.
|
|
572
|
+
* A single resource can span multiple rows (when it has array fields like variants, assets...),
|
|
573
|
+
* so we count unique keys rather than rows.
|
|
574
|
+
* @param file The CSV file to process
|
|
575
|
+
* @returns A promise that resolves to the number of unique resources
|
|
576
|
+
*/
|
|
577
|
+
const countUniqueResourcesInCsv = file => {
|
|
578
|
+
return new _Promise(resolve => {
|
|
579
|
+
const uniqueKeys = new _Set();
|
|
580
|
+
let keyColumnIndex = -1;
|
|
581
|
+
let isFirstRow = true;
|
|
582
|
+
Papa.parse(file, {
|
|
583
|
+
step: _ref2 => {
|
|
584
|
+
var _context4, _context5;
|
|
585
|
+
let data = _ref2.data;
|
|
586
|
+
if (!_Array$isArray(data)) return;
|
|
587
|
+
if (isFirstRow) {
|
|
588
|
+
keyColumnIndex = _findIndexInstanceProperty(data).call(data, col => {
|
|
589
|
+
var _context2, _context3;
|
|
590
|
+
return ((_context2 = col?.toLowerCase()) == null ? void 0 : _bindInstanceProperty(_context3 = Function.call).call(_context3, _trimInstanceProperty(_context2), _context2))?.() === 'key';
|
|
591
|
+
});
|
|
592
|
+
isFirstRow = false;
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
if (keyColumnIndex === -1) return;
|
|
596
|
+
const keyValue = ((_context4 = data[keyColumnIndex]) == null ? void 0 : _bindInstanceProperty(_context5 = Function.call).call(_context5, _trimInstanceProperty(_context4), _context4))?.();
|
|
597
|
+
if (keyValue) {
|
|
598
|
+
uniqueKeys.add(keyValue);
|
|
599
|
+
}
|
|
600
|
+
},
|
|
601
|
+
complete: () => {
|
|
602
|
+
resolve(uniqueKeys.size);
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
});
|
|
606
|
+
};
|
|
607
|
+
|
|
484
608
|
/**
|
|
485
609
|
* Map file upload errors to upload file error rows with unique IDs
|
|
486
610
|
* @param uploadFileErrors Array of file upload errors
|
|
@@ -488,13 +612,13 @@ const countJsonFileItems = async file => {
|
|
|
488
612
|
*/
|
|
489
613
|
const mapFileUploadErrorsToUploadFileErrorRows = uploadFileErrors => {
|
|
490
614
|
let idCounter = 1;
|
|
491
|
-
return _mapInstanceProperty(uploadFileErrors).call(uploadFileErrors, uploadFileError => _objectSpread$
|
|
615
|
+
return _mapInstanceProperty(uploadFileErrors).call(uploadFileErrors, uploadFileError => _objectSpread$8(_objectSpread$8({}, uploadFileError), {}, {
|
|
492
616
|
id: String(idCounter++)
|
|
493
617
|
}));
|
|
494
618
|
};
|
|
495
619
|
|
|
496
|
-
function ownKeys$
|
|
497
|
-
function _objectSpread$
|
|
620
|
+
function ownKeys$7(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
621
|
+
function _objectSpread$7(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys$7(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys$7(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
498
622
|
const mapFormikErrors = error => {
|
|
499
623
|
if (typeof error === 'string') {
|
|
500
624
|
return {
|
|
@@ -502,7 +626,7 @@ const mapFormikErrors = error => {
|
|
|
502
626
|
};
|
|
503
627
|
}
|
|
504
628
|
if (_Array$isArray(error)) {
|
|
505
|
-
return _reduceInstanceProperty(error).call(error, (errorAggregator, currentError) => _objectSpread$
|
|
629
|
+
return _reduceInstanceProperty(error).call(error, (errorAggregator, currentError) => _objectSpread$7(_objectSpread$7({}, errorAggregator), {}, {
|
|
506
630
|
[currentError]: true
|
|
507
631
|
}), {});
|
|
508
632
|
}
|
|
@@ -571,6 +695,54 @@ const decodeFileNameFromImportContainerKey = importContainerKey => {
|
|
|
571
695
|
}
|
|
572
696
|
};
|
|
573
697
|
|
|
698
|
+
const pollJobUntilValidated = async _ref => {
|
|
699
|
+
let projectKey = _ref.projectKey,
|
|
700
|
+
jobId = _ref.jobId,
|
|
701
|
+
importContainerKey = _ref.importContainerKey,
|
|
702
|
+
_ref$pollingInterval = _ref.pollingInterval,
|
|
703
|
+
pollingInterval = _ref$pollingInterval === void 0 ? 5000 : _ref$pollingInterval,
|
|
704
|
+
_ref$maxAttempts = _ref.maxAttempts,
|
|
705
|
+
maxAttempts = _ref$maxAttempts === void 0 ? 120 : _ref$maxAttempts,
|
|
706
|
+
onJobUpdate = _ref.onJobUpdate,
|
|
707
|
+
abortSignal = _ref.abortSignal;
|
|
708
|
+
let attempts = 0;
|
|
709
|
+
while (attempts < maxAttempts) {
|
|
710
|
+
if (abortSignal?.aborted) {
|
|
711
|
+
throw new PollingAbortedError();
|
|
712
|
+
}
|
|
713
|
+
const job = await getFileImportJob({
|
|
714
|
+
projectKey,
|
|
715
|
+
importContainerKey,
|
|
716
|
+
jobId
|
|
717
|
+
});
|
|
718
|
+
if (abortSignal?.aborted) {
|
|
719
|
+
throw new PollingAbortedError();
|
|
720
|
+
}
|
|
721
|
+
onJobUpdate?.(job);
|
|
722
|
+
if (isImportJobTerminal(job)) {
|
|
723
|
+
return job;
|
|
724
|
+
}
|
|
725
|
+
await new _Promise((resolve, reject) => {
|
|
726
|
+
let timeoutId;
|
|
727
|
+
const onAbort = () => {
|
|
728
|
+
clearTimeout(timeoutId);
|
|
729
|
+
reject(new PollingAbortedError());
|
|
730
|
+
};
|
|
731
|
+
if (abortSignal?.aborted) {
|
|
732
|
+
reject(new PollingAbortedError());
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
timeoutId = _setTimeout(() => {
|
|
736
|
+
abortSignal?.removeEventListener('abort', onAbort);
|
|
737
|
+
resolve();
|
|
738
|
+
}, pollingInterval);
|
|
739
|
+
abortSignal?.addEventListener('abort', onAbort);
|
|
740
|
+
});
|
|
741
|
+
attempts++;
|
|
742
|
+
}
|
|
743
|
+
throw new Error(`Job validation timeout after ${maxAttempts} attempts (${maxAttempts * pollingInterval / 1000}s)`);
|
|
744
|
+
};
|
|
745
|
+
|
|
574
746
|
/**
|
|
575
747
|
* Formats an object into a URL query string
|
|
576
748
|
* @param queryParams - Object containing query parameters
|
|
@@ -649,6 +821,42 @@ function getExportOperationsURL(_ref0) {
|
|
|
649
821
|
const queryString = formatQueryString(queryParams);
|
|
650
822
|
return `/${projectKey}/export-operations${queryString}`;
|
|
651
823
|
}
|
|
824
|
+
function getFileImportJobsURL(_ref1) {
|
|
825
|
+
let projectKey = _ref1.projectKey,
|
|
826
|
+
resourceType = _ref1.resourceType,
|
|
827
|
+
importContainerKey = _ref1.importContainerKey;
|
|
828
|
+
return `/${projectKey}/${plural(toImportApiResourceType(resourceType))}/import-containers/${importContainerKey}/file-import-jobs`;
|
|
829
|
+
}
|
|
830
|
+
function getFileImportJobByIdURL(_ref10) {
|
|
831
|
+
let projectKey = _ref10.projectKey,
|
|
832
|
+
importContainerKey = _ref10.importContainerKey,
|
|
833
|
+
jobId = _ref10.jobId;
|
|
834
|
+
return `/${projectKey}/import-containers/${importContainerKey}/file-import-jobs/${jobId}`;
|
|
835
|
+
}
|
|
836
|
+
function getFileImportJobRecordsURL(_ref11) {
|
|
837
|
+
let projectKey = _ref11.projectKey,
|
|
838
|
+
importContainerKey = _ref11.importContainerKey,
|
|
839
|
+
jobId = _ref11.jobId;
|
|
840
|
+
return `/${projectKey}/import-containers/${importContainerKey}/file-import-jobs/${jobId}/records`;
|
|
841
|
+
}
|
|
842
|
+
function getFileImportJobProcessURL(_ref12) {
|
|
843
|
+
let projectKey = _ref12.projectKey,
|
|
844
|
+
resourceType = _ref12.resourceType,
|
|
845
|
+
importContainerKey = _ref12.importContainerKey,
|
|
846
|
+
jobId = _ref12.jobId;
|
|
847
|
+
return `/${projectKey}/${plural(toImportApiResourceType(resourceType))}/import-containers/${importContainerKey}/file-import-jobs/${jobId}/process`;
|
|
848
|
+
}
|
|
849
|
+
function getFileImportJobDeleteURL(_ref13) {
|
|
850
|
+
let projectKey = _ref13.projectKey,
|
|
851
|
+
importContainerKey = _ref13.importContainerKey,
|
|
852
|
+
jobId = _ref13.jobId;
|
|
853
|
+
return `/${projectKey}/import-containers/${importContainerKey}/file-import-jobs/${jobId}`;
|
|
854
|
+
}
|
|
855
|
+
function getFileImportJobsListURL(_ref14) {
|
|
856
|
+
let projectKey = _ref14.projectKey,
|
|
857
|
+
importContainerKey = _ref14.importContainerKey;
|
|
858
|
+
return `/${projectKey}/import-containers/${importContainerKey}/file-import-jobs`;
|
|
859
|
+
}
|
|
652
860
|
|
|
653
861
|
function uploadFileForImport(_ref) {
|
|
654
862
|
let projectKey = _ref.projectKey,
|
|
@@ -688,8 +896,181 @@ function assertFileUploadResponse(maybeFileUploadResponse) {
|
|
|
688
896
|
throw new Error('Invalid response');
|
|
689
897
|
}
|
|
690
898
|
|
|
691
|
-
function
|
|
692
|
-
|
|
899
|
+
function createFileImportJob(_ref) {
|
|
900
|
+
let projectKey = _ref.projectKey,
|
|
901
|
+
resourceType = _ref.resourceType,
|
|
902
|
+
importContainerKey = _ref.importContainerKey,
|
|
903
|
+
payload = _ref.payload,
|
|
904
|
+
onProgress = _ref.onProgress,
|
|
905
|
+
abortSignal = _ref.abortSignal;
|
|
906
|
+
const url = getFileImportJobsURL({
|
|
907
|
+
projectKey,
|
|
908
|
+
resourceType,
|
|
909
|
+
importContainerKey
|
|
910
|
+
});
|
|
911
|
+
if ('fileType' in payload) {
|
|
912
|
+
return new _Promise((resolve, reject) => {
|
|
913
|
+
const formData = new FormData();
|
|
914
|
+
formData.append('fileType', payload.fileType);
|
|
915
|
+
formData.append('fileName', payload.fileName);
|
|
916
|
+
formData.append('file', payload.file, payload.fileName);
|
|
917
|
+
fetchUsingXhr({
|
|
918
|
+
url,
|
|
919
|
+
payload: formData,
|
|
920
|
+
config: {
|
|
921
|
+
proxy: MC_API_PROXY_TARGETS.IMPORT,
|
|
922
|
+
method: 'POST',
|
|
923
|
+
headers: {
|
|
924
|
+
'Content-Type': null
|
|
925
|
+
},
|
|
926
|
+
abortSignal
|
|
927
|
+
},
|
|
928
|
+
onProgress: onProgress || (() => {}),
|
|
929
|
+
onSuccess: response => {
|
|
930
|
+
assertFileImportJob(response);
|
|
931
|
+
resolve(response);
|
|
932
|
+
},
|
|
933
|
+
onError: reject
|
|
934
|
+
});
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
return fetcher({
|
|
938
|
+
url,
|
|
939
|
+
payload: _JSON$stringify(payload),
|
|
940
|
+
config: {
|
|
941
|
+
proxy: MC_API_PROXY_TARGETS.IMPORT,
|
|
942
|
+
method: 'POST',
|
|
943
|
+
headers: {
|
|
944
|
+
accept: 'application/json',
|
|
945
|
+
'Content-Type': 'application/json'
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
}).then(response => {
|
|
949
|
+
assertFileImportJob(response);
|
|
950
|
+
return response;
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
async function getFileImportJob(_ref2) {
|
|
954
|
+
let projectKey = _ref2.projectKey,
|
|
955
|
+
importContainerKey = _ref2.importContainerKey,
|
|
956
|
+
jobId = _ref2.jobId;
|
|
957
|
+
const url = getFileImportJobByIdURL({
|
|
958
|
+
projectKey,
|
|
959
|
+
importContainerKey,
|
|
960
|
+
jobId
|
|
961
|
+
});
|
|
962
|
+
const response = await fetcher({
|
|
963
|
+
url,
|
|
964
|
+
config: {
|
|
965
|
+
proxy: MC_API_PROXY_TARGETS.IMPORT,
|
|
966
|
+
method: 'GET'
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
assertFileImportJob(response);
|
|
970
|
+
return response;
|
|
971
|
+
}
|
|
972
|
+
async function getFileImportJobRecords(_ref3) {
|
|
973
|
+
let projectKey = _ref3.projectKey,
|
|
974
|
+
importContainerKey = _ref3.importContainerKey,
|
|
975
|
+
jobId = _ref3.jobId,
|
|
976
|
+
limit = _ref3.limit,
|
|
977
|
+
offset = _ref3.offset,
|
|
978
|
+
isValid = _ref3.isValid;
|
|
979
|
+
const baseUrl = getFileImportJobRecordsURL({
|
|
980
|
+
projectKey,
|
|
981
|
+
importContainerKey,
|
|
982
|
+
jobId
|
|
983
|
+
});
|
|
984
|
+
const queryString = formatQueryString({
|
|
985
|
+
limit,
|
|
986
|
+
offset,
|
|
987
|
+
isValid
|
|
988
|
+
});
|
|
989
|
+
const url = `${baseUrl}${queryString}`;
|
|
990
|
+
const response = await fetcher({
|
|
991
|
+
url,
|
|
992
|
+
config: {
|
|
993
|
+
proxy: MC_API_PROXY_TARGETS.IMPORT,
|
|
994
|
+
method: 'GET'
|
|
995
|
+
}
|
|
996
|
+
});
|
|
997
|
+
assertFileImportJobRecordsResponse(response);
|
|
998
|
+
return response;
|
|
999
|
+
}
|
|
1000
|
+
async function processFileImportJob(_ref4) {
|
|
1001
|
+
let projectKey = _ref4.projectKey,
|
|
1002
|
+
resourceType = _ref4.resourceType,
|
|
1003
|
+
importContainerKey = _ref4.importContainerKey,
|
|
1004
|
+
jobId = _ref4.jobId,
|
|
1005
|
+
action = _ref4.action;
|
|
1006
|
+
const url = getFileImportJobProcessURL({
|
|
1007
|
+
projectKey,
|
|
1008
|
+
resourceType,
|
|
1009
|
+
importContainerKey,
|
|
1010
|
+
jobId
|
|
1011
|
+
});
|
|
1012
|
+
const payload = action ? {
|
|
1013
|
+
action
|
|
1014
|
+
} : {};
|
|
1015
|
+
const response = await fetcher({
|
|
1016
|
+
url,
|
|
1017
|
+
payload: _JSON$stringify(payload),
|
|
1018
|
+
config: {
|
|
1019
|
+
proxy: MC_API_PROXY_TARGETS.IMPORT,
|
|
1020
|
+
method: 'POST',
|
|
1021
|
+
headers: {
|
|
1022
|
+
accept: 'application/json',
|
|
1023
|
+
'Content-Type': 'application/json'
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
assertProcessFileImportJobResponse(response);
|
|
1028
|
+
return response;
|
|
1029
|
+
}
|
|
1030
|
+
async function deleteFileImportJob(_ref5) {
|
|
1031
|
+
let projectKey = _ref5.projectKey,
|
|
1032
|
+
importContainerKey = _ref5.importContainerKey,
|
|
1033
|
+
jobId = _ref5.jobId;
|
|
1034
|
+
const url = getFileImportJobDeleteURL({
|
|
1035
|
+
projectKey,
|
|
1036
|
+
importContainerKey,
|
|
1037
|
+
jobId
|
|
1038
|
+
});
|
|
1039
|
+
await fetcher({
|
|
1040
|
+
url,
|
|
1041
|
+
config: {
|
|
1042
|
+
proxy: MC_API_PROXY_TARGETS.IMPORT,
|
|
1043
|
+
method: 'DELETE'
|
|
1044
|
+
}
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
async function listFileImportJobs(_ref6) {
|
|
1048
|
+
let projectKey = _ref6.projectKey,
|
|
1049
|
+
importContainerKey = _ref6.importContainerKey,
|
|
1050
|
+
limit = _ref6.limit,
|
|
1051
|
+
offset = _ref6.offset;
|
|
1052
|
+
const baseUrl = getFileImportJobsListURL({
|
|
1053
|
+
projectKey,
|
|
1054
|
+
importContainerKey
|
|
1055
|
+
});
|
|
1056
|
+
const queryString = formatQueryString({
|
|
1057
|
+
limit,
|
|
1058
|
+
offset
|
|
1059
|
+
});
|
|
1060
|
+
const url = `${baseUrl}${queryString}`;
|
|
1061
|
+
const response = await fetcher({
|
|
1062
|
+
url,
|
|
1063
|
+
config: {
|
|
1064
|
+
proxy: MC_API_PROXY_TARGETS.IMPORT,
|
|
1065
|
+
method: 'GET'
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
assertListFileImportJobsResponse(response);
|
|
1069
|
+
return response;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
function ownKeys$6(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
1073
|
+
function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context2 = ownKeys$6(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context3 = ownKeys$6(Object(t))).call(_context3, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
693
1074
|
function getImportState(importSummary) {
|
|
694
1075
|
const processing = importSummary.states.processing > 0;
|
|
695
1076
|
if (processing) return ImportStates.Processing;
|
|
@@ -714,7 +1095,7 @@ function createImportContainerForFileUpload(_ref) {
|
|
|
714
1095
|
url: getCreateImportContainerURL({
|
|
715
1096
|
projectKey
|
|
716
1097
|
}),
|
|
717
|
-
payload: _JSON$stringify(_objectSpread$
|
|
1098
|
+
payload: _JSON$stringify(_objectSpread$6({
|
|
718
1099
|
retentionPolicy: {
|
|
719
1100
|
strategy: 'ttl',
|
|
720
1101
|
config: {
|
|
@@ -948,6 +1329,21 @@ const DELIMITERS = {
|
|
|
948
1329
|
};
|
|
949
1330
|
const COLUMN_DELIMITERS = [DELIMITERS.COMMA, DELIMITERS.SEMICOLON, DELIMITERS.PIPE, DELIMITERS.TAB];
|
|
950
1331
|
|
|
1332
|
+
const FILE_IMPORT_JOB_POLLING_INTERVAL = 2000;
|
|
1333
|
+
|
|
1334
|
+
const IMPORT_MAX_FILE_SIZE_MB = 200;
|
|
1335
|
+
const IMPORT_MAX_ITEM_COUNT = 500_000;
|
|
1336
|
+
|
|
1337
|
+
// =============================================================================
|
|
1338
|
+
// Legacy constants (old flow) - Remove after testing and migration is complete
|
|
1339
|
+
// =============================================================================
|
|
1340
|
+
|
|
1341
|
+
/** @deprecated Use IMPORT_MAX_FILE_SIZE_MB instead. Remove after migration. */
|
|
1342
|
+
const IMPORT_LEGACY_MAX_FILE_SIZE_MB = 35;
|
|
1343
|
+
|
|
1344
|
+
/** @deprecated Use IMPORT_MAX_ITEM_COUNT instead. Remove after migration. */
|
|
1345
|
+
const IMPORT_LEGACY_MAX_ROW_COUNT = 80_000;
|
|
1346
|
+
|
|
951
1347
|
const IMPORT_TAG_KEYS = {
|
|
952
1348
|
source: 'source'
|
|
953
1349
|
};
|
|
@@ -991,18 +1387,6 @@ const RESOURCE_TYPE_DOCUMENTATION_LINKS = {
|
|
|
991
1387
|
'business-unit': 'https://docs.commercetools.com/merchant-center/import-business-units#supported-headers-and-values'
|
|
992
1388
|
};
|
|
993
1389
|
|
|
994
|
-
/**
|
|
995
|
-
* Maximum file size for imports.
|
|
996
|
-
* Recommended by backend, enforced in frontend validation.
|
|
997
|
-
*/
|
|
998
|
-
const MAX_FILE_SIZE_MB = 35;
|
|
999
|
-
|
|
1000
|
-
/**
|
|
1001
|
-
* Maximum row count for imports.
|
|
1002
|
-
* Recommended by backend, enforced in frontend validation.
|
|
1003
|
-
*/
|
|
1004
|
-
const MAX_ROW_COUNT = 80_000;
|
|
1005
|
-
|
|
1006
1390
|
const automatedImportContainerKey = 'automated-container-key';
|
|
1007
1391
|
const fileUploadImportContainerKey = 'eyJ0aW1lc3RhbXAiOiAxNzA1MDc0MzIxODY4LCAiZmlsZU5hbWUiOiAiZmlsZS11cGxvYWQtY29udGFpbmVyLWtleS5jc3YifQ';
|
|
1008
1392
|
const manualImports = [{
|
|
@@ -1255,8 +1639,8 @@ const validFileUploadResponse = {
|
|
|
1255
1639
|
itemsCount: 2,
|
|
1256
1640
|
rowsCount: 2,
|
|
1257
1641
|
columnsCount: 11,
|
|
1258
|
-
|
|
1259
|
-
|
|
1642
|
+
fields: ['id', 'lastModifiedAt', 'key', 'name.en', 'name.de', 'slug.en', 'slug.de', 'orderHint', 'externalId', 'description.en', 'description.de'],
|
|
1643
|
+
ignoredFields: ['id', 'lastModifiedAt']
|
|
1260
1644
|
};
|
|
1261
1645
|
const invalidFileUploadResponse = {
|
|
1262
1646
|
invalid: 2,
|
|
@@ -1265,8 +1649,8 @@ const invalidFileUploadResponse = {
|
|
|
1265
1649
|
itemsCount: 2,
|
|
1266
1650
|
rowsCount: 2,
|
|
1267
1651
|
columnsCount: 11,
|
|
1268
|
-
|
|
1269
|
-
|
|
1652
|
+
fields: ['key', 'externalId2', 'orderHint', 'name.de2', 'description.de2', 'slug.RU', 'name.enn', 'description.en', 'slug.RU', 'test1', 'test2'],
|
|
1653
|
+
ignoredFields: [],
|
|
1270
1654
|
results: [{
|
|
1271
1655
|
row: 1,
|
|
1272
1656
|
errors: [{
|
|
@@ -1649,10 +2033,101 @@ const exportOperationsProcessing = [{
|
|
|
1649
2033
|
fields: ['id'],
|
|
1650
2034
|
locales: ['en']
|
|
1651
2035
|
}];
|
|
2036
|
+
const validFileImportJobQueued = {
|
|
2037
|
+
id: 'job-uuid-12345',
|
|
2038
|
+
fileName: 'categories.csv',
|
|
2039
|
+
importContainerKey: 'container-key',
|
|
2040
|
+
state: 'queued',
|
|
2041
|
+
summary: {
|
|
2042
|
+
total: 0,
|
|
2043
|
+
valid: 0,
|
|
2044
|
+
invalid: 0,
|
|
2045
|
+
fieldsCount: 0,
|
|
2046
|
+
fields: [],
|
|
2047
|
+
ignoredFields: []
|
|
2048
|
+
}
|
|
2049
|
+
};
|
|
2050
|
+
const validFileImportJobProcessing = {
|
|
2051
|
+
id: 'job-uuid-12345',
|
|
2052
|
+
fileName: 'categories.csv',
|
|
2053
|
+
importContainerKey: 'container-key',
|
|
2054
|
+
state: 'processing',
|
|
2055
|
+
summary: {
|
|
2056
|
+
total: 0,
|
|
2057
|
+
valid: 0,
|
|
2058
|
+
invalid: 0,
|
|
2059
|
+
fieldsCount: 0,
|
|
2060
|
+
fields: [],
|
|
2061
|
+
ignoredFields: []
|
|
2062
|
+
}
|
|
2063
|
+
};
|
|
2064
|
+
const validFileImportJobValidated = {
|
|
2065
|
+
id: 'job-uuid-12345',
|
|
2066
|
+
fileName: 'categories.csv',
|
|
2067
|
+
importContainerKey: 'container-key',
|
|
2068
|
+
state: 'validated',
|
|
2069
|
+
summary: {
|
|
2070
|
+
total: 2,
|
|
2071
|
+
valid: 2,
|
|
2072
|
+
invalid: 0,
|
|
2073
|
+
fieldsCount: 2,
|
|
2074
|
+
fields: ['key', 'name.en'],
|
|
2075
|
+
ignoredFields: ['id', 'lastModifiedAt']
|
|
2076
|
+
}
|
|
2077
|
+
};
|
|
2078
|
+
const invalidFileImportJobValidated = {
|
|
2079
|
+
id: 'job-uuid-12345',
|
|
2080
|
+
fileName: 'categories.csv',
|
|
2081
|
+
importContainerKey: 'container-key',
|
|
2082
|
+
state: 'validated',
|
|
2083
|
+
summary: {
|
|
2084
|
+
total: 2,
|
|
2085
|
+
valid: 0,
|
|
2086
|
+
invalid: 2,
|
|
2087
|
+
fieldsCount: 11,
|
|
2088
|
+
fields: ['key', 'externalId2', 'orderHint', 'name.de2', 'description.de2', 'slug.RU', 'name.enn', 'description.en', 'slug.RU', 'test1', 'test2'],
|
|
2089
|
+
ignoredFields: []
|
|
2090
|
+
}
|
|
2091
|
+
};
|
|
2092
|
+
const validFileImportJobRecordsResponse = {
|
|
2093
|
+
results: [],
|
|
2094
|
+
total: 0,
|
|
2095
|
+
limit: 20,
|
|
2096
|
+
offset: 0,
|
|
2097
|
+
count: 0
|
|
2098
|
+
};
|
|
2099
|
+
const invalidFileImportJobRecordsResponse = {
|
|
2100
|
+
results: [{
|
|
2101
|
+
index: 1,
|
|
2102
|
+
errors: [{
|
|
2103
|
+
code: 'InvalidField',
|
|
2104
|
+
message: '"externalId2" is not allowed',
|
|
2105
|
+
field: 'externalId2'
|
|
2106
|
+
}, {
|
|
2107
|
+
code: 'InvalidField',
|
|
2108
|
+
message: '"orderHint" is not allowed',
|
|
2109
|
+
field: 'orderHint'
|
|
2110
|
+
}]
|
|
2111
|
+
}, {
|
|
2112
|
+
index: 2,
|
|
2113
|
+
errors: [{
|
|
2114
|
+
code: 'InvalidField',
|
|
2115
|
+
message: '"name.de2" is not allowed',
|
|
2116
|
+
field: 'name.de2'
|
|
2117
|
+
}]
|
|
2118
|
+
}],
|
|
2119
|
+
total: 2,
|
|
2120
|
+
limit: 20,
|
|
2121
|
+
offset: 0,
|
|
2122
|
+
count: 2
|
|
2123
|
+
};
|
|
2124
|
+
const processFileImportJobResponse = {
|
|
2125
|
+
message: 'acknowledged'
|
|
2126
|
+
};
|
|
1652
2127
|
|
|
1653
|
-
function ownKeys$
|
|
1654
|
-
function _objectSpread$
|
|
1655
|
-
const FileIcon = props => /*#__PURE__*/jsxs("svg", _objectSpread$
|
|
2128
|
+
function ownKeys$5(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2129
|
+
function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys$5(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys$5(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2130
|
+
const FileIcon = props => /*#__PURE__*/jsxs("svg", _objectSpread$5(_objectSpread$5({
|
|
1656
2131
|
width: "32",
|
|
1657
2132
|
height: "32",
|
|
1658
2133
|
viewBox: "0 0 32 32",
|
|
@@ -1754,9 +2229,9 @@ const ActiveDragDropArea = _ref => {
|
|
|
1754
2229
|
});
|
|
1755
2230
|
};
|
|
1756
2231
|
|
|
1757
|
-
function ownKeys$
|
|
1758
|
-
function _objectSpread$
|
|
1759
|
-
const LockIcon = props => /*#__PURE__*/jsxs("svg", _objectSpread$
|
|
2232
|
+
function ownKeys$4(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2233
|
+
function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys$4(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys$4(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2234
|
+
const LockIcon = props => /*#__PURE__*/jsxs("svg", _objectSpread$4(_objectSpread$4({
|
|
1760
2235
|
width: "87px",
|
|
1761
2236
|
height: "118px",
|
|
1762
2237
|
viewBox: "0 0 87 118",
|
|
@@ -1860,8 +2335,8 @@ function getDefaultDropWrapperStyles(_dropAreaState) {
|
|
|
1860
2335
|
return /*#__PURE__*/css(process.env.NODE_ENV === "production" ? "" : ";label:getDefaultDropWrapperStyles;");
|
|
1861
2336
|
}
|
|
1862
2337
|
|
|
1863
|
-
function ownKeys$
|
|
1864
|
-
function _objectSpread$
|
|
2338
|
+
function ownKeys$3(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2339
|
+
function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var _context7, _context8; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context7 = ownKeys$3(Object(t), !0)).call(_context7, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context8 = ownKeys$3(Object(t))).call(_context8, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
1865
2340
|
const FileDropArea = _ref => {
|
|
1866
2341
|
let onDrop = _ref.onDrop,
|
|
1867
2342
|
disabled = _ref.disabled,
|
|
@@ -1894,11 +2369,11 @@ const FileDropArea = _ref => {
|
|
|
1894
2369
|
getInputProps = _useDropzone.getInputProps,
|
|
1895
2370
|
isDragActive = _useDropzone.isDragActive;
|
|
1896
2371
|
const dropAreaState = getDropAreaState(isDragActive);
|
|
1897
|
-
return /*#__PURE__*/jsxs(DropAreaWrapper, _objectSpread$
|
|
2372
|
+
return /*#__PURE__*/jsxs(DropAreaWrapper, _objectSpread$3(_objectSpread$3({
|
|
1898
2373
|
role: "presentation"
|
|
1899
2374
|
}, getRootProps()), {}, {
|
|
1900
2375
|
dropAreaState: dropAreaState,
|
|
1901
|
-
children: [/*#__PURE__*/jsx("input", _objectSpread$
|
|
2376
|
+
children: [/*#__PURE__*/jsx("input", _objectSpread$3({
|
|
1902
2377
|
"data-testid": "file-input"
|
|
1903
2378
|
}, getInputProps())), /*#__PURE__*/jsx(Constraints.Horizontal, {
|
|
1904
2379
|
children: children(dropAreaState)
|
|
@@ -2003,8 +2478,8 @@ const UploadingModal = _ref => {
|
|
|
2003
2478
|
progress = _ref.progress,
|
|
2004
2479
|
cancelLabel = _ref.cancelLabel,
|
|
2005
2480
|
onCancel = _ref.onCancel,
|
|
2006
|
-
onClose = _ref.onClose
|
|
2007
|
-
|
|
2481
|
+
onClose = _ref.onClose,
|
|
2482
|
+
statusMessage = _ref.statusMessage;
|
|
2008
2483
|
return /*#__PURE__*/jsx(InfoDialog, {
|
|
2009
2484
|
size: 16,
|
|
2010
2485
|
isOpen: isOpen,
|
|
@@ -2028,7 +2503,7 @@ const UploadingModal = _ref => {
|
|
|
2028
2503
|
})
|
|
2029
2504
|
}), /*#__PURE__*/jsxs(Text.Body, {
|
|
2030
2505
|
tone: "secondary",
|
|
2031
|
-
children: ["(",
|
|
2506
|
+
children: ["(", convertFileSizeToKB(fileSize).toLocaleString(), " KB)"]
|
|
2032
2507
|
})]
|
|
2033
2508
|
}), /*#__PURE__*/jsx(SecondaryButton, {
|
|
2034
2509
|
tone: "secondary",
|
|
@@ -2040,22 +2515,16 @@ const UploadingModal = _ref => {
|
|
|
2040
2515
|
barWidth: "scale",
|
|
2041
2516
|
height: "10",
|
|
2042
2517
|
progress: progress
|
|
2043
|
-
}), /*#__PURE__*/jsx(
|
|
2518
|
+
}), statusMessage && /*#__PURE__*/jsx(Text.Detail, {
|
|
2519
|
+
tone: "tertiary",
|
|
2520
|
+
children: statusMessage
|
|
2521
|
+
})]
|
|
2044
2522
|
})
|
|
2045
2523
|
});
|
|
2046
2524
|
};
|
|
2047
2525
|
|
|
2048
|
-
var messages = defineMessages({
|
|
2049
|
-
unexpectedError: {
|
|
2050
|
-
id: 'operations.fetch.unexpectedError',
|
|
2051
|
-
description: 'Generic error message displayed when an unexpected error occurs during data fetching',
|
|
2052
|
-
defaultMessage: 'An unexpected error occurred while fetching the data. Please try again. If the problem persists, please contact support.'
|
|
2053
|
-
}
|
|
2054
|
-
});
|
|
2055
|
-
|
|
2056
2526
|
const useFetch = function (fetchFunction) {
|
|
2057
2527
|
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2058
|
-
const intl = useIntl();
|
|
2059
2528
|
const _React$useState = React.useState(null),
|
|
2060
2529
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
2061
2530
|
data = _React$useState2[0],
|
|
@@ -2094,10 +2563,9 @@ const useFetch = function (fetchFunction) {
|
|
|
2094
2563
|
}
|
|
2095
2564
|
}
|
|
2096
2565
|
} catch (err) {
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
setError(new Error(intl.formatMessage(messages.unexpectedError)));
|
|
2566
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
2567
|
+
setError(error);
|
|
2568
|
+
if (!(err instanceof HttpError)) {
|
|
2101
2569
|
reportErrorToSentry(new Error('An unexpected error occurred in the `useFetch` hook'), {
|
|
2102
2570
|
extra: {
|
|
2103
2571
|
error: err
|
|
@@ -2119,7 +2587,7 @@ const useFetch = function (fetchFunction) {
|
|
|
2119
2587
|
setError(null);
|
|
2120
2588
|
setIsLoading(false);
|
|
2121
2589
|
};
|
|
2122
|
-
}, [fetchFunction, refetchCount,
|
|
2590
|
+
}, [fetchFunction, refetchCount, config.pollingInterval, config.shouldContinuePolling]);
|
|
2123
2591
|
return {
|
|
2124
2592
|
data,
|
|
2125
2593
|
error,
|
|
@@ -2149,6 +2617,61 @@ const useFetchExportOperations = _ref => {
|
|
|
2149
2617
|
});
|
|
2150
2618
|
};
|
|
2151
2619
|
|
|
2620
|
+
const useFetchFileImportJob = _ref => {
|
|
2621
|
+
let projectKey = _ref.projectKey,
|
|
2622
|
+
importContainerKey = _ref.importContainerKey,
|
|
2623
|
+
jobId = _ref.jobId,
|
|
2624
|
+
pollingInterval = _ref.pollingInterval,
|
|
2625
|
+
shouldContinuePolling = _ref.shouldContinuePolling;
|
|
2626
|
+
const fetchData = React.useCallback(() => {
|
|
2627
|
+
if (!projectKey) {
|
|
2628
|
+
return _Promise.reject(new ProjectKeyNotAvailableError());
|
|
2629
|
+
}
|
|
2630
|
+
return getFileImportJob({
|
|
2631
|
+
projectKey,
|
|
2632
|
+
importContainerKey,
|
|
2633
|
+
jobId
|
|
2634
|
+
});
|
|
2635
|
+
}, [projectKey, importContainerKey, jobId]);
|
|
2636
|
+
return useFetch(fetchData, {
|
|
2637
|
+
pollingInterval,
|
|
2638
|
+
shouldContinuePolling
|
|
2639
|
+
});
|
|
2640
|
+
};
|
|
2641
|
+
|
|
2642
|
+
const EMPTY_RESPONSE = {
|
|
2643
|
+
results: [],
|
|
2644
|
+
total: 0,
|
|
2645
|
+
limit: 0,
|
|
2646
|
+
offset: 0,
|
|
2647
|
+
count: 0
|
|
2648
|
+
};
|
|
2649
|
+
const useFetchFileImportJobRecords = _ref => {
|
|
2650
|
+
let projectKey = _ref.projectKey,
|
|
2651
|
+
importContainerKey = _ref.importContainerKey,
|
|
2652
|
+
jobId = _ref.jobId,
|
|
2653
|
+
limit = _ref.limit,
|
|
2654
|
+
offset = _ref.offset,
|
|
2655
|
+
isValid = _ref.isValid,
|
|
2656
|
+
_ref$skip = _ref.skip,
|
|
2657
|
+
skip = _ref$skip === void 0 ? false : _ref$skip;
|
|
2658
|
+
const shouldSkip = skip || !projectKey || !importContainerKey || !jobId;
|
|
2659
|
+
const fetchData = React.useCallback(() => {
|
|
2660
|
+
if (shouldSkip) {
|
|
2661
|
+
return _Promise.resolve(EMPTY_RESPONSE);
|
|
2662
|
+
}
|
|
2663
|
+
return getFileImportJobRecords({
|
|
2664
|
+
projectKey: projectKey,
|
|
2665
|
+
importContainerKey: importContainerKey,
|
|
2666
|
+
jobId: jobId,
|
|
2667
|
+
limit,
|
|
2668
|
+
offset,
|
|
2669
|
+
isValid
|
|
2670
|
+
});
|
|
2671
|
+
}, [shouldSkip, projectKey, importContainerKey, jobId, limit, offset, isValid]);
|
|
2672
|
+
return useFetch(fetchData);
|
|
2673
|
+
};
|
|
2674
|
+
|
|
2152
2675
|
const useFetchImportContainerDetails = _ref => {
|
|
2153
2676
|
let projectKey = _ref.projectKey,
|
|
2154
2677
|
importContainerKey = _ref.importContainerKey,
|
|
@@ -2217,8 +2740,78 @@ const useFetchImportSummaries = _ref => {
|
|
|
2217
2740
|
});
|
|
2218
2741
|
};
|
|
2219
2742
|
|
|
2220
|
-
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2221
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2743
|
+
function ownKeys$2(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2744
|
+
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys$2(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys$2(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2745
|
+
const useFileImportJobUpload = _ref => {
|
|
2746
|
+
let projectKey = _ref.projectKey;
|
|
2747
|
+
const _React$useState = React.useState(false),
|
|
2748
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
2749
|
+
isUploading = _React$useState2[0],
|
|
2750
|
+
setIsUploading = _React$useState2[1];
|
|
2751
|
+
const _React$useState3 = React.useState(0),
|
|
2752
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
2753
|
+
progress = _React$useState4[0],
|
|
2754
|
+
setProgress = _React$useState4[1];
|
|
2755
|
+
const upload = React.useCallback(async config => {
|
|
2756
|
+
if (!projectKey) {
|
|
2757
|
+
throw new ProjectKeyNotAvailableError();
|
|
2758
|
+
}
|
|
2759
|
+
setIsUploading(true);
|
|
2760
|
+
setProgress(0);
|
|
2761
|
+
const importContainerKey = encodeFileNameWithTimestampToContainerKey(config.file.name);
|
|
2762
|
+
try {
|
|
2763
|
+
await createImportContainerForFileUpload({
|
|
2764
|
+
importContainerDraft: _objectSpread$2({
|
|
2765
|
+
key: importContainerKey,
|
|
2766
|
+
resourceType: config.resourceType,
|
|
2767
|
+
tags: [TAG_KEY_SOURCE_FILE_UPLOAD]
|
|
2768
|
+
}, config.settings ? {
|
|
2769
|
+
settings: config.settings
|
|
2770
|
+
} : {}),
|
|
2771
|
+
projectKey
|
|
2772
|
+
});
|
|
2773
|
+
const jobResponse = await createFileImportJob({
|
|
2774
|
+
projectKey,
|
|
2775
|
+
resourceType: config.resourceType,
|
|
2776
|
+
importContainerKey,
|
|
2777
|
+
payload: {
|
|
2778
|
+
fileType: getFileImportJobFileType(config.resourceType),
|
|
2779
|
+
fileName: config.file.name,
|
|
2780
|
+
file: config.file
|
|
2781
|
+
},
|
|
2782
|
+
onProgress: uploadProgress => {
|
|
2783
|
+
setProgress(uploadProgress);
|
|
2784
|
+
config.onProgress?.(uploadProgress);
|
|
2785
|
+
},
|
|
2786
|
+
abortSignal: config.abortSignal
|
|
2787
|
+
});
|
|
2788
|
+
setIsUploading(false);
|
|
2789
|
+
setProgress(100);
|
|
2790
|
+
config.onSuccess(jobResponse.id, importContainerKey);
|
|
2791
|
+
} catch (error) {
|
|
2792
|
+
try {
|
|
2793
|
+
await deleteImportContainer({
|
|
2794
|
+
projectKey,
|
|
2795
|
+
importContainerKey
|
|
2796
|
+
});
|
|
2797
|
+
} catch {
|
|
2798
|
+
// Ignore cleanup errors - container will be cleaned up by TTL retention policy
|
|
2799
|
+
// Cleanup errors are unlikely unless there is a network issue or container was removed externally
|
|
2800
|
+
}
|
|
2801
|
+
setIsUploading(false);
|
|
2802
|
+
setProgress(0);
|
|
2803
|
+
config.onError?.(error);
|
|
2804
|
+
}
|
|
2805
|
+
}, [projectKey]);
|
|
2806
|
+
return {
|
|
2807
|
+
upload,
|
|
2808
|
+
isUploading,
|
|
2809
|
+
progress
|
|
2810
|
+
};
|
|
2811
|
+
};
|
|
2812
|
+
|
|
2813
|
+
function ownKeys$1(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2814
|
+
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys$1(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys$1(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2222
2815
|
const useImportContainerUpload = _ref => {
|
|
2223
2816
|
let projectKey = _ref.projectKey;
|
|
2224
2817
|
const _React$useState = React.useState(false),
|
|
@@ -2236,7 +2829,8 @@ const useImportContainerUpload = _ref => {
|
|
|
2236
2829
|
settings = _ref2.settings,
|
|
2237
2830
|
onSuccess = _ref2.onSuccess,
|
|
2238
2831
|
onError = _ref2.onError,
|
|
2239
|
-
onProgress = _ref2.onProgress
|
|
2832
|
+
onProgress = _ref2.onProgress,
|
|
2833
|
+
abortSignal = _ref2.abortSignal;
|
|
2240
2834
|
if (!projectKey) {
|
|
2241
2835
|
throw new ProjectKeyNotAvailableError();
|
|
2242
2836
|
}
|
|
@@ -2245,7 +2839,7 @@ const useImportContainerUpload = _ref => {
|
|
|
2245
2839
|
const importContainerKey = encodeFileNameWithTimestampToContainerKey(file.name);
|
|
2246
2840
|
try {
|
|
2247
2841
|
await createImportContainerForFileUpload({
|
|
2248
|
-
importContainerDraft: _objectSpread({
|
|
2842
|
+
importContainerDraft: _objectSpread$1({
|
|
2249
2843
|
key: importContainerKey,
|
|
2250
2844
|
resourceType,
|
|
2251
2845
|
tags: [TAG_KEY_SOURCE_FILE_UPLOAD]
|
|
@@ -2259,6 +2853,7 @@ const useImportContainerUpload = _ref => {
|
|
|
2259
2853
|
importContainerKey,
|
|
2260
2854
|
resourceType,
|
|
2261
2855
|
file,
|
|
2856
|
+
abortSignal,
|
|
2262
2857
|
onSuccess: response => {
|
|
2263
2858
|
setIsUploading(false);
|
|
2264
2859
|
setProgress(100);
|
|
@@ -2297,7 +2892,8 @@ const useImportContainerUpload = _ref => {
|
|
|
2297
2892
|
}
|
|
2298
2893
|
setIsUploading(false);
|
|
2299
2894
|
setProgress(0);
|
|
2300
|
-
|
|
2895
|
+
onError?.(error);
|
|
2896
|
+
return undefined;
|
|
2301
2897
|
}
|
|
2302
2898
|
};
|
|
2303
2899
|
const abort = () => {
|
|
@@ -2313,4 +2909,197 @@ const useImportContainerUpload = _ref => {
|
|
|
2313
2909
|
};
|
|
2314
2910
|
};
|
|
2315
2911
|
|
|
2316
|
-
|
|
2912
|
+
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2913
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2914
|
+
const safeDeleteContainer = async _ref => {
|
|
2915
|
+
let projectKey = _ref.projectKey,
|
|
2916
|
+
containerKey = _ref.containerKey;
|
|
2917
|
+
try {
|
|
2918
|
+
await deleteImportContainer({
|
|
2919
|
+
projectKey,
|
|
2920
|
+
importContainerKey: containerKey
|
|
2921
|
+
});
|
|
2922
|
+
} catch {}
|
|
2923
|
+
};
|
|
2924
|
+
const useFileUpload = _ref2 => {
|
|
2925
|
+
let projectKey = _ref2.projectKey,
|
|
2926
|
+
_ref2$useJobBasedFlow = _ref2.useJobBasedFlow,
|
|
2927
|
+
useJobBasedFlow = _ref2$useJobBasedFlow === void 0 ? false : _ref2$useJobBasedFlow,
|
|
2928
|
+
_ref2$pollingInterval = _ref2.pollingInterval,
|
|
2929
|
+
pollingInterval = _ref2$pollingInterval === void 0 ? 5000 : _ref2$pollingInterval,
|
|
2930
|
+
_ref2$maxPollingAttem = _ref2.maxPollingAttempts,
|
|
2931
|
+
maxPollingAttempts = _ref2$maxPollingAttem === void 0 ? 120 : _ref2$maxPollingAttem;
|
|
2932
|
+
const _React$useState = React.useState(false),
|
|
2933
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
2934
|
+
isUploading = _React$useState2[0],
|
|
2935
|
+
setIsUploading = _React$useState2[1];
|
|
2936
|
+
const _React$useState3 = React.useState(0),
|
|
2937
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
2938
|
+
progress = _React$useState4[0],
|
|
2939
|
+
setProgress = _React$useState4[1];
|
|
2940
|
+
const _React$useState5 = React.useState({
|
|
2941
|
+
processed: 0,
|
|
2942
|
+
total: 0,
|
|
2943
|
+
isValidating: false
|
|
2944
|
+
}),
|
|
2945
|
+
_React$useState6 = _slicedToArray(_React$useState5, 2),
|
|
2946
|
+
validationProgress = _React$useState6[0],
|
|
2947
|
+
setValidationProgress = _React$useState6[1];
|
|
2948
|
+
const containerUpload = useImportContainerUpload({
|
|
2949
|
+
projectKey
|
|
2950
|
+
});
|
|
2951
|
+
const jobUpload = useFileImportJobUpload({
|
|
2952
|
+
projectKey
|
|
2953
|
+
});
|
|
2954
|
+
const resetState = React.useCallback(() => {
|
|
2955
|
+
setIsUploading(false);
|
|
2956
|
+
setProgress(0);
|
|
2957
|
+
setValidationProgress({
|
|
2958
|
+
processed: 0,
|
|
2959
|
+
total: 0,
|
|
2960
|
+
isValidating: false
|
|
2961
|
+
});
|
|
2962
|
+
}, []);
|
|
2963
|
+
const upload = React.useCallback(async config => {
|
|
2964
|
+
setIsUploading(true);
|
|
2965
|
+
setProgress(0);
|
|
2966
|
+
try {
|
|
2967
|
+
if (useJobBasedFlow) {
|
|
2968
|
+
const totalResources = await countUniqueResourcesInCsv(config.file);
|
|
2969
|
+
await jobUpload.upload({
|
|
2970
|
+
file: config.file,
|
|
2971
|
+
resourceType: config.resourceType,
|
|
2972
|
+
settings: config.settings,
|
|
2973
|
+
abortSignal: config.abortSignal,
|
|
2974
|
+
onSuccess: async (jobId, containerKey) => {
|
|
2975
|
+
try {
|
|
2976
|
+
setValidationProgress({
|
|
2977
|
+
processed: 0,
|
|
2978
|
+
total: totalResources,
|
|
2979
|
+
isValidating: true
|
|
2980
|
+
});
|
|
2981
|
+
const validatedJob = await pollJobUntilValidated({
|
|
2982
|
+
projectKey,
|
|
2983
|
+
jobId,
|
|
2984
|
+
importContainerKey: containerKey,
|
|
2985
|
+
pollingInterval,
|
|
2986
|
+
maxAttempts: maxPollingAttempts,
|
|
2987
|
+
abortSignal: config.abortSignal,
|
|
2988
|
+
onJobUpdate: job => {
|
|
2989
|
+
const processed = job.summary?.total ?? 0;
|
|
2990
|
+
setValidationProgress({
|
|
2991
|
+
processed,
|
|
2992
|
+
total: totalResources,
|
|
2993
|
+
isValidating: true
|
|
2994
|
+
});
|
|
2995
|
+
config.onValidationProgress?.(job);
|
|
2996
|
+
}
|
|
2997
|
+
});
|
|
2998
|
+
|
|
2999
|
+
// Handle rejected job with jobError for the new flow (like MissingCsvFieldIdentifier error)
|
|
3000
|
+
// We wrap it in HttpError to reuse existing error handling (for the old flow) in consumers until BE supports this error type
|
|
3001
|
+
if (validatedJob.jobError) {
|
|
3002
|
+
throw new HttpError(400, validatedJob.jobError.message, validatedJob.jobError);
|
|
3003
|
+
}
|
|
3004
|
+
if (validatedJob.summary.invalid > 0) {
|
|
3005
|
+
await safeDeleteContainer({
|
|
3006
|
+
projectKey,
|
|
3007
|
+
containerKey
|
|
3008
|
+
});
|
|
3009
|
+
}
|
|
3010
|
+
const result = {
|
|
3011
|
+
containerKey,
|
|
3012
|
+
summary: _objectSpread(_objectSpread({}, validatedJob.summary), {}, {
|
|
3013
|
+
// TODO: Remove this once the old flow is fully removed
|
|
3014
|
+
results: []
|
|
3015
|
+
}),
|
|
3016
|
+
jobId,
|
|
3017
|
+
job: validatedJob
|
|
3018
|
+
};
|
|
3019
|
+
setIsUploading(false);
|
|
3020
|
+
setValidationProgress({
|
|
3021
|
+
processed: 0,
|
|
3022
|
+
total: 0,
|
|
3023
|
+
isValidating: false
|
|
3024
|
+
});
|
|
3025
|
+
config.onSuccess(result);
|
|
3026
|
+
} catch (error) {
|
|
3027
|
+
await safeDeleteContainer({
|
|
3028
|
+
projectKey,
|
|
3029
|
+
containerKey
|
|
3030
|
+
});
|
|
3031
|
+
resetState();
|
|
3032
|
+
if (!(error instanceof PollingAbortedError)) {
|
|
3033
|
+
config.onError?.(error);
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
3036
|
+
},
|
|
3037
|
+
onProgress: prog => {
|
|
3038
|
+
setProgress(prog);
|
|
3039
|
+
config.onProgress?.(prog);
|
|
3040
|
+
},
|
|
3041
|
+
onError: error => {
|
|
3042
|
+
resetState();
|
|
3043
|
+
config.onError?.(error);
|
|
3044
|
+
}
|
|
3045
|
+
});
|
|
3046
|
+
} else {
|
|
3047
|
+
await containerUpload.upload({
|
|
3048
|
+
file: config.file,
|
|
3049
|
+
resourceType: config.resourceType,
|
|
3050
|
+
settings: config.settings,
|
|
3051
|
+
abortSignal: config.abortSignal,
|
|
3052
|
+
onSuccess: async (fileUploadResponse, containerKey) => {
|
|
3053
|
+
if (config.abortSignal?.aborted) {
|
|
3054
|
+
await safeDeleteContainer({
|
|
3055
|
+
projectKey,
|
|
3056
|
+
containerKey
|
|
3057
|
+
});
|
|
3058
|
+
resetState();
|
|
3059
|
+
return;
|
|
3060
|
+
}
|
|
3061
|
+
if (fileUploadResponse.invalid > 0) {
|
|
3062
|
+
await safeDeleteContainer({
|
|
3063
|
+
projectKey,
|
|
3064
|
+
containerKey
|
|
3065
|
+
});
|
|
3066
|
+
}
|
|
3067
|
+
const result = {
|
|
3068
|
+
containerKey,
|
|
3069
|
+
summary: {
|
|
3070
|
+
total: fileUploadResponse.itemsCount,
|
|
3071
|
+
valid: fileUploadResponse.valid,
|
|
3072
|
+
invalid: fileUploadResponse.invalid,
|
|
3073
|
+
fieldsCount: fileUploadResponse.columnsCount,
|
|
3074
|
+
fields: fileUploadResponse.fields || [],
|
|
3075
|
+
ignoredFields: fileUploadResponse.ignoredFields || [],
|
|
3076
|
+
results: fileUploadResponse.results || []
|
|
3077
|
+
}
|
|
3078
|
+
};
|
|
3079
|
+
setIsUploading(false);
|
|
3080
|
+
config.onSuccess(result);
|
|
3081
|
+
},
|
|
3082
|
+
onProgress: prog => {
|
|
3083
|
+
setProgress(prog);
|
|
3084
|
+
config.onProgress?.(prog);
|
|
3085
|
+
},
|
|
3086
|
+
onError: error => {
|
|
3087
|
+
resetState();
|
|
3088
|
+
config.onError?.(error);
|
|
3089
|
+
}
|
|
3090
|
+
});
|
|
3091
|
+
}
|
|
3092
|
+
} catch (error) {
|
|
3093
|
+
resetState();
|
|
3094
|
+
config.onError?.(error);
|
|
3095
|
+
}
|
|
3096
|
+
}, [projectKey, useJobBasedFlow, pollingInterval, maxPollingAttempts, containerUpload, jobUpload]);
|
|
3097
|
+
return {
|
|
3098
|
+
upload,
|
|
3099
|
+
isUploading,
|
|
3100
|
+
progress,
|
|
3101
|
+
validationProgress
|
|
3102
|
+
};
|
|
3103
|
+
};
|
|
3104
|
+
|
|
3105
|
+
export { ActiveDragDropArea, COLUMN_DELIMITERS, CT_API_DOCS_URL, DELIMITERS, DisabledDropArea, DropAreaWrapper, EnabledDropArea, FILE_IMPORT_JOB_POLLING_INTERVAL, FileDropArea, FileDroppedArea, FileIcon, HttpError, IMPORT_LEGACY_MAX_FILE_SIZE_MB, IMPORT_LEGACY_MAX_ROW_COUNT, IMPORT_MAX_FILE_SIZE_MB, IMPORT_MAX_ITEM_COUNT, IMPORT_TAG_KEYS, IMPORT_TAG_VALUES, ImportStates, InfoBox, InvalidResponseError, LockIcon, NoResourcesToExportError, PollingAbortedError, ProjectKeyNotAvailableError, QueryPredicateError, RESOURCE_TYPE_DOCUMENTATION_LINKS, RESOURCE_TYPE_TEMPLATE_DOWNLOAD_LINKS, TAG_KEY_SOURCE_FILE_UPLOAD, UnexpectedColumnError, UnexpectedOperationStateError, UnexpectedResourceTypeError, UploadSeparator, UploadSettings, UploadingModal, allAutomatedImportOperations, allAutomatedImportOperationsResponse, allFileUploadImportOperations, allFileUploadImportOperationsResponse, appendCsvOrJsonExtensionIfAbsent, assertCancelContainerResponse, assertExportOperationsDownloadFileResponse, assertFileImportJob, assertFileImportJobRecordsResponse, assertFileUploadResponse, assertImportContainer, assertImportContainerPagedResponse, assertImportOperationPagedResponse, assertImportSummary, assertListFileImportJobsResponse, assertPaginatedExportOperationResponse, assertProcessFileImportJobResponse, assertProcessFileResponse, assertResourceType, automatedImportContainerKey, automatedImports, cancelImportContainerByKey, checkIfFileUploadImport, convertFileSizeToKB, countJsonFileItems, countUniqueResourcesInCsv, createFileImportJob, createImportContainerForFileUpload, decodeFileNameFromImportContainerKey, deleteFileImportJob, deleteImportContainer, dropAreaStyles, encodeFileNameWithTimestampToContainerKey, exportOperationsCompleted, exportOperationsProcessing, extractErrorDescriptionFromValidationMessage, fetchExportOperations, fetchImportContainerByKey, fetchImportContainerDetails, fetchImportContainers, fetchImportOperations, fetchImportSummaries, fetchImportSummary, fetchUsingXhr, fetcher, fileUploadImportContainerKey, fileUploadMissingKeysResponse, formatErrorCode, formatKeys, formatQueryString, getCreateImportContainerURL, getDeleteImportContainerURL, getExportOperationsURL, getFileImportJob, getFileImportJobByIdURL, getFileImportJobDeleteURL, getFileImportJobFileType, getFileImportJobProcessURL, getFileImportJobRecords, getFileImportJobRecordsURL, getFileImportJobsListURL, getFileImportJobsURL, getFileUploadErrorsCount, getFileUploadURL, getImportContainerByKeyURL, getImportContainerTasksURL, getImportContainersURL, getImportOperationsURL, getImportState, getImportSummaryURL, getMissingRequiredFields, getProccessFileURL, getRowCount, getValidatedColumns, hasOwnProperty, hasRequiredFields, hasSingleKeyColumn, importContainers, importStatesMap, importsSummaries, invalidFileImportJobRecordsResponse, invalidFileImportJobValidated, invalidFileUploadResponse, isAbortError, isError, isImportJobInitializing, isImportJobProcessing, isImportJobQueued, isImportJobReady, isImportJobRejected, isImportJobTerminal, isImportJobValidated, isResourceType, listFileImportJobs, manualImports, mapFileUploadErrorsToUploadFileErrorRows, mapFormikErrors, mapUploadFileErrorsResponseToUploadFileErrorRows, pollJobUntilValidated, processFileImportJob, processFileImportJobResponse, processUploadedFile, shouldContinuePollingForImportValidation, successfulAutomatedImportOperations, successfulAutomatedImportOperationsResponse, successfulFileUploadImportOperations, successfulFileUploadImportOperationsResponse, toBytes, toImportApiResourceType, uploadFileForImport, useFetchExportOperations, useFetchFileImportJob, useFetchFileImportJobRecords, useFetchImportContainerDetails, useFetchImportOperations, useFetchImportSummaries, useFileImportJobUpload, useFileUpload, useImportContainerUpload, validFileImportJobProcessing, validFileImportJobQueued, validFileImportJobRecordsResponse, validFileImportJobValidated, validFileUploadResponse, validProcessFileResponse, validateDelimiter };
|