@commercetools-frontend-extensions/operations 3.5.0 → 3.6.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 +6 -0
- package/README.md +2 -0
- package/dist/commercetools-frontend-extensions-operations.cjs.dev.js +3 -1
- package/dist/commercetools-frontend-extensions-operations.cjs.prod.js +3 -1
- package/dist/commercetools-frontend-extensions-operations.esm.js +3 -1
- package/dist/declarations/src/@hooks/use-file-import-job-upload.d.ts +1 -0
- package/dist/declarations/src/@hooks/use-file-upload.d.ts +1 -0
- package/package.json +1 -1
- package/src/@hooks/use-file-import-job-upload.spec.ts +49 -0
- package/src/@hooks/use-file-import-job-upload.ts +5 -1
- package/src/@hooks/use-file-upload.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @commercetools-frontend-extensions/operations
|
|
2
2
|
|
|
3
|
+
## 3.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1734](https://github.com/commercetools/merchant-center-operations/pull/1734) [`59d43ea`](https://github.com/commercetools/merchant-center-operations/commit/59d43ea4a4ffb929a970e3094881777639d6631f) Thanks [@yassinejebli](https://github.com/yassinejebli)! - feat: add optional `fileType` override to `useFileUpload` hook
|
|
8
|
+
|
|
3
9
|
## 3.5.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -40,6 +40,7 @@ const { upload, isUploading, progress, validationProgress } = useFileUpload({
|
|
|
40
40
|
**Upload config options:**
|
|
41
41
|
- `file` (required): The file to upload
|
|
42
42
|
- `resourceType` (required): The resource type
|
|
43
|
+
- `fileType` (optional): File type (`'csv'` or `'json'`) sent to the API.
|
|
43
44
|
- `settings` (optional): Import settings (format, decimal separator...)
|
|
44
45
|
- `autoProcess` (optional): When `true`, the backend automatically starts processing after validation completes (job-based flow only). Default: `false`
|
|
45
46
|
- `skipValidationPolling` (optional): When `true`, skips full validation polling and returns once the job reaches `processing` state. Useful for fire-and-forget uploads with `autoProcess: true` (job-based flow only). Default: `false`
|
|
@@ -63,6 +64,7 @@ const abortController = new AbortController()
|
|
|
63
64
|
await upload({
|
|
64
65
|
file: File,
|
|
65
66
|
resourceType: 'product' | 'category' | ...,
|
|
67
|
+
fileType?: 'csv' | 'json', // override derived file type (job-based flow only)
|
|
66
68
|
settings?: {
|
|
67
69
|
format?: 'CSV' | 'JSON',
|
|
68
70
|
decimalSeparator?: '.' | ',',
|
|
@@ -2989,12 +2989,13 @@ const useFileImportJobUpload = _ref => {
|
|
|
2989
2989
|
} : {}),
|
|
2990
2990
|
projectKey
|
|
2991
2991
|
});
|
|
2992
|
+
const fileType = config.fileType ?? getFileImportJobFileType(config.resourceType);
|
|
2992
2993
|
const jobResponse = await createFileImportJob({
|
|
2993
2994
|
projectKey,
|
|
2994
2995
|
resourceType: config.resourceType,
|
|
2995
2996
|
importContainerKey,
|
|
2996
2997
|
payload: {
|
|
2997
|
-
fileType
|
|
2998
|
+
fileType,
|
|
2998
2999
|
fileName: config.file.name,
|
|
2999
3000
|
file: config.file
|
|
3000
3001
|
},
|
|
@@ -3187,6 +3188,7 @@ const useFileUpload = _ref2 => {
|
|
|
3187
3188
|
await jobUpload.upload({
|
|
3188
3189
|
file: config.file,
|
|
3189
3190
|
resourceType: config.resourceType,
|
|
3191
|
+
fileType: config.fileType,
|
|
3190
3192
|
settings: config.settings,
|
|
3191
3193
|
autoProcess: config.autoProcess,
|
|
3192
3194
|
operationType: config.operationType,
|
|
@@ -2981,12 +2981,13 @@ const useFileImportJobUpload = _ref => {
|
|
|
2981
2981
|
} : {}),
|
|
2982
2982
|
projectKey
|
|
2983
2983
|
});
|
|
2984
|
+
const fileType = config.fileType ?? getFileImportJobFileType(config.resourceType);
|
|
2984
2985
|
const jobResponse = await createFileImportJob({
|
|
2985
2986
|
projectKey,
|
|
2986
2987
|
resourceType: config.resourceType,
|
|
2987
2988
|
importContainerKey,
|
|
2988
2989
|
payload: {
|
|
2989
|
-
fileType
|
|
2990
|
+
fileType,
|
|
2990
2991
|
fileName: config.file.name,
|
|
2991
2992
|
file: config.file
|
|
2992
2993
|
},
|
|
@@ -3179,6 +3180,7 @@ const useFileUpload = _ref2 => {
|
|
|
3179
3180
|
await jobUpload.upload({
|
|
3180
3181
|
file: config.file,
|
|
3181
3182
|
resourceType: config.resourceType,
|
|
3183
|
+
fileType: config.fileType,
|
|
3182
3184
|
settings: config.settings,
|
|
3183
3185
|
autoProcess: config.autoProcess,
|
|
3184
3186
|
operationType: config.operationType,
|
|
@@ -2951,12 +2951,13 @@ const useFileImportJobUpload = _ref => {
|
|
|
2951
2951
|
} : {}),
|
|
2952
2952
|
projectKey
|
|
2953
2953
|
});
|
|
2954
|
+
const fileType = config.fileType ?? getFileImportJobFileType(config.resourceType);
|
|
2954
2955
|
const jobResponse = await createFileImportJob({
|
|
2955
2956
|
projectKey,
|
|
2956
2957
|
resourceType: config.resourceType,
|
|
2957
2958
|
importContainerKey,
|
|
2958
2959
|
payload: {
|
|
2959
|
-
fileType
|
|
2960
|
+
fileType,
|
|
2960
2961
|
fileName: config.file.name,
|
|
2961
2962
|
file: config.file
|
|
2962
2963
|
},
|
|
@@ -3149,6 +3150,7 @@ const useFileUpload = _ref2 => {
|
|
|
3149
3150
|
await jobUpload.upload({
|
|
3150
3151
|
file: config.file,
|
|
3151
3152
|
resourceType: config.resourceType,
|
|
3153
|
+
fileType: config.fileType,
|
|
3152
3154
|
settings: config.settings,
|
|
3153
3155
|
autoProcess: config.autoProcess,
|
|
3154
3156
|
operationType: config.operationType,
|
|
@@ -3,6 +3,7 @@ import type { ExtendedImportContainerDraft } from "../@types/index.js";
|
|
|
3
3
|
export type UseFileImportJobUploadConfig = {
|
|
4
4
|
file: File;
|
|
5
5
|
resourceType: ResourceTypeId;
|
|
6
|
+
fileType?: 'csv' | 'json';
|
|
6
7
|
settings?: ExtendedImportContainerDraft['settings'];
|
|
7
8
|
autoProcess?: boolean;
|
|
8
9
|
operationType?: 'delete';
|
package/package.json
CHANGED
|
@@ -262,6 +262,55 @@ describe('useFileImportJobUpload', () => {
|
|
|
262
262
|
expect(result.current.progress).toBe(100)
|
|
263
263
|
})
|
|
264
264
|
|
|
265
|
+
it('should use explicit fileType override instead of deriving from resourceType', async () => {
|
|
266
|
+
const onSuccess = jest.fn()
|
|
267
|
+
|
|
268
|
+
const { result } = renderHook(() => useFileImportJobUpload({ projectKey }))
|
|
269
|
+
|
|
270
|
+
await act(async () => {
|
|
271
|
+
await result.current.upload({
|
|
272
|
+
file: mockFile,
|
|
273
|
+
resourceType: 'product',
|
|
274
|
+
fileType: 'json',
|
|
275
|
+
onSuccess,
|
|
276
|
+
})
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
expect(mockCreateFileImportJob).toHaveBeenCalledWith(
|
|
280
|
+
expect.objectContaining({
|
|
281
|
+
payload: expect.objectContaining({
|
|
282
|
+
fileType: 'json',
|
|
283
|
+
}),
|
|
284
|
+
})
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
expect(mockGetFileImportJobFileType).not.toHaveBeenCalled()
|
|
288
|
+
expect(onSuccess).toHaveBeenCalledWith('job-123', importContainerKey)
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
it('should fall back to derived fileType when fileType override is not provided', async () => {
|
|
292
|
+
const onSuccess = jest.fn()
|
|
293
|
+
|
|
294
|
+
const { result } = renderHook(() => useFileImportJobUpload({ projectKey }))
|
|
295
|
+
|
|
296
|
+
await act(async () => {
|
|
297
|
+
await result.current.upload({
|
|
298
|
+
file: mockFile,
|
|
299
|
+
resourceType: 'product',
|
|
300
|
+
onSuccess,
|
|
301
|
+
})
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
expect(mockGetFileImportJobFileType).toHaveBeenCalledWith('product')
|
|
305
|
+
expect(mockCreateFileImportJob).toHaveBeenCalledWith(
|
|
306
|
+
expect.objectContaining({
|
|
307
|
+
payload: expect.objectContaining({
|
|
308
|
+
fileType: 'csv',
|
|
309
|
+
}),
|
|
310
|
+
})
|
|
311
|
+
)
|
|
312
|
+
})
|
|
313
|
+
|
|
265
314
|
it('should work without optional settings', async () => {
|
|
266
315
|
const onSuccess = jest.fn()
|
|
267
316
|
|
|
@@ -16,6 +16,7 @@ import type { ExtendedImportContainerDraft } from '../@types'
|
|
|
16
16
|
export type UseFileImportJobUploadConfig = {
|
|
17
17
|
file: File
|
|
18
18
|
resourceType: ResourceTypeId
|
|
19
|
+
fileType?: 'csv' | 'json'
|
|
19
20
|
settings?: ExtendedImportContainerDraft['settings']
|
|
20
21
|
autoProcess?: boolean
|
|
21
22
|
operationType?: 'delete'
|
|
@@ -57,12 +58,15 @@ export const useFileImportJobUpload = ({
|
|
|
57
58
|
projectKey,
|
|
58
59
|
})
|
|
59
60
|
|
|
61
|
+
const fileType =
|
|
62
|
+
config.fileType ?? getFileImportJobFileType(config.resourceType)
|
|
63
|
+
|
|
60
64
|
const jobResponse = await createFileImportJob({
|
|
61
65
|
projectKey,
|
|
62
66
|
resourceType: config.resourceType,
|
|
63
67
|
importContainerKey,
|
|
64
68
|
payload: {
|
|
65
|
-
fileType
|
|
69
|
+
fileType,
|
|
66
70
|
fileName: config.file.name,
|
|
67
71
|
file: config.file,
|
|
68
72
|
},
|
|
@@ -19,6 +19,7 @@ export type ValidationProgress = {
|
|
|
19
19
|
export type FileUploadConfig = {
|
|
20
20
|
file: File
|
|
21
21
|
resourceType: ResourceTypeId
|
|
22
|
+
fileType?: 'csv' | 'json'
|
|
22
23
|
settings?: ExtendedImportContainerDraft['settings']
|
|
23
24
|
autoProcess?: boolean
|
|
24
25
|
skipValidationPolling?: boolean
|
|
@@ -85,6 +86,7 @@ export const useFileUpload = ({
|
|
|
85
86
|
await jobUpload.upload({
|
|
86
87
|
file: config.file,
|
|
87
88
|
resourceType: config.resourceType,
|
|
89
|
+
fileType: config.fileType,
|
|
88
90
|
settings: config.settings,
|
|
89
91
|
autoProcess: config.autoProcess,
|
|
90
92
|
operationType: config.operationType,
|