@commercetools-frontend-extensions/operations 0.0.0 → 3.0.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.
Files changed (66) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +81 -72
  3. package/dist/commercetools-frontend-extensions-operations.cjs.dev.js +947 -143
  4. package/dist/commercetools-frontend-extensions-operations.cjs.prod.js +947 -143
  5. package/dist/commercetools-frontend-extensions-operations.esm.js +898 -140
  6. package/dist/declarations/src/@api/file-import-jobs.d.ts +7 -0
  7. package/dist/declarations/src/@api/index.d.ts +1 -0
  8. package/dist/declarations/src/@api/test-fixtures.d.ts +8 -1
  9. package/dist/declarations/src/@api/urls.d.ts +30 -0
  10. package/dist/declarations/src/@components/uploading-modal/uploading-modal.d.ts +3 -2
  11. package/dist/declarations/src/@constants/file-import-job.d.ts +1 -0
  12. package/dist/declarations/src/@constants/import-limits.d.ts +6 -0
  13. package/dist/declarations/src/@constants/index.d.ts +2 -1
  14. package/dist/declarations/src/@errors/index.d.ts +5 -4
  15. package/dist/declarations/src/@errors/polling-aborted-error.d.ts +3 -0
  16. package/dist/declarations/src/@hooks/index.d.ts +3 -0
  17. package/dist/declarations/src/@hooks/use-fetch-file-import-job.d.ts +17 -0
  18. package/dist/declarations/src/@hooks/use-file-import-job-upload.d.ts +18 -0
  19. package/dist/declarations/src/@hooks/use-file-upload.d.ts +28 -0
  20. package/dist/declarations/src/@hooks/use-import-container-upload.d.ts +2 -1
  21. package/dist/declarations/src/@types/export-operation.d.ts +3 -1
  22. package/dist/declarations/src/@types/file-import-job.d.ts +99 -0
  23. package/dist/declarations/src/@types/file-upload-result.d.ts +21 -0
  24. package/dist/declarations/src/@types/file-upload.d.ts +2 -2
  25. package/dist/declarations/src/@types/index.d.ts +2 -0
  26. package/dist/declarations/src/@utils/file-import-job-helpers.d.ts +12 -0
  27. package/dist/declarations/src/@utils/file-upload.d.ts +8 -0
  28. package/dist/declarations/src/@utils/index.d.ts +2 -0
  29. package/dist/declarations/src/@utils/poll-job-until-validated.d.ts +11 -0
  30. package/package.json +19 -20
  31. package/src/@api/fetcher.ts +10 -0
  32. package/src/@api/file-import-jobs.ts +217 -0
  33. package/src/@api/file-upload.spec.ts +4 -2
  34. package/src/@api/index.ts +1 -0
  35. package/src/@api/test-fixtures.ts +127 -5
  36. package/src/@api/urls.ts +77 -1
  37. package/src/@components/uploading-modal/uploading-modal.tsx +7 -5
  38. package/src/@constants/file-import-job.ts +1 -0
  39. package/src/@constants/import-limits.ts +13 -0
  40. package/src/@constants/index.ts +2 -1
  41. package/src/@errors/index.ts +5 -4
  42. package/src/@errors/polling-aborted-error.ts +6 -0
  43. package/src/@hooks/index.ts +3 -0
  44. package/src/@hooks/use-fetch-file-import-job.spec.ts +131 -0
  45. package/src/@hooks/use-fetch-file-import-job.ts +38 -0
  46. package/src/@hooks/use-fetch.spec.ts +1 -9
  47. package/src/@hooks/use-fetch.ts +4 -8
  48. package/src/@hooks/use-file-import-job-upload.spec.ts +273 -0
  49. package/src/@hooks/use-file-import-job-upload.ts +101 -0
  50. package/src/@hooks/use-file-upload.ts +223 -0
  51. package/src/@hooks/use-import-container-upload.spec.ts +16 -13
  52. package/src/@hooks/use-import-container-upload.ts +6 -2
  53. package/src/@types/export-operation.ts +3 -0
  54. package/src/@types/file-import-job.ts +165 -0
  55. package/src/@types/file-upload-result.ts +23 -0
  56. package/src/@types/file-upload.ts +2 -2
  57. package/src/@types/index.ts +2 -0
  58. package/src/@utils/error-mapping.ts +10 -9
  59. package/src/@utils/file-import-job-helpers.spec.ts +147 -0
  60. package/src/@utils/file-import-job-helpers.ts +47 -0
  61. package/src/@utils/file-upload.ts +39 -0
  62. package/src/@utils/index.ts +2 -0
  63. package/src/@utils/poll-job-until-validated.ts +76 -0
  64. package/dist/declarations/src/@constants/upload-limits.d.ts +0 -10
  65. package/src/@constants/upload-limits.ts +0 -11
  66. package/src/@hooks/messages.ts +0 -11
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @commercetools-frontend-extensions/operations
2
2
 
3
+ ## 3.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#1646](https://github.com/commercetools/merchant-center-operations/pull/1646) [`c1c381d`](https://github.com/commercetools/merchant-center-operations/commit/c1c381da4aa5c47c6fcc63940f164defe08170bd) Thanks [@yassinejebli](https://github.com/yassinejebli)! - feat: introduce the new Import job flow
8
+
3
9
  ## 2.0.1
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -4,73 +4,86 @@ Shared functionality for import/export operations across multiple frontend appli
4
4
 
5
5
  ## Hooks
6
6
 
7
- ### `useImportContainerUpload`
7
+ ### `useFileUpload`
8
8
 
9
- Handles file upload to import containers with automatic cleanup on errors.
9
+ A unified hook for file uploads that handles both the old flow (import container) and new flow (file import job).
10
10
 
11
11
  ```typescript
12
- const { upload, abort, isUploading, progress } = useImportContainerUpload({
13
- projectKey: string
12
+ const { upload, isUploading, progress, validationProgress } = useFileUpload({
13
+ projectKey: string,
14
+ useJobBasedFlow?: boolean,
15
+ pollingInterval?: number,
16
+ maxPollingAttempts?: number
14
17
  })
15
18
  ```
16
19
 
17
20
  **Parameters:**
18
21
  - `projectKey` (required): The commercetools project key
22
+ - `useJobBasedFlow` (optional): Whether to use the job-based flow. Default: `false`
23
+ - `pollingInterval` (optional): Polling interval in ms for job-based flow. Default: `5000`
24
+ - `maxPollingAttempts` (optional): Maximum polling attempts. Default: `120`
19
25
 
20
26
  **Returns:**
21
- - `upload`: Function to start file upload
22
- - `abort`: Function to cancel ongoing upload
23
- - `isUploading`: Boolean indicating upload state
24
- - `progress`: Upload progress (0-100)
27
+ - `upload` - Function to start the upload
28
+ - `isUploading` - Whether upload is in progress
29
+ - `progress` - Upload progress (0-100)
30
+ - `validationProgress` - `{ processed: number, isValidating: boolean }` (job-based flow only)
25
31
 
26
32
  **Usage:**
27
33
  ```typescript
28
- const projectKey = useApplicationContext((context) => context.project?.key)
29
- const { upload, isUploading, progress } = useImportContainerUpload({
30
- projectKey: projectKey!
34
+ import { useFileUpload } from '@commercetools-frontend-extensions/operations'
35
+
36
+ const { upload, isUploading, progress, validationProgress } = useFileUpload({
37
+ projectKey,
38
+ useJobBasedFlow: isFeatureFlagEnabled
31
39
  })
32
40
 
41
+ const abortController = new AbortController()
42
+
33
43
  await upload({
34
44
  file: File,
35
45
  resourceType: 'product' | 'category' | ...,
36
46
  settings?: {
37
47
  format?: 'CSV' | 'JSON',
38
48
  decimalSeparator?: '.' | ',',
39
- resourceType?: string, // example: 'product-draft' for products
49
+ resourceType?: 'product-draft' | 'category' | ...,
40
50
  options?: {
41
- publishAllChanges?: boolean, // product-specific
42
- unpublishAllChanges?: boolean // product-specific
51
+ publishAllChanges?: boolean,
52
+ unpublishAllChanges?: boolean
43
53
  }
44
54
  },
45
- onSuccess: (response, containerKey) => { /* ... */ },
55
+ abortSignal: abortController.signal,
56
+ onSuccess: (result) => {
57
+ // result.containerKey - Import container key
58
+ // result.summary - { total, valid, invalid, fields, ignoredFields, results }
59
+ // result.jobId - Job ID (job-based flow only)
60
+ // result.job - Full job object (job-based flow only)
61
+ },
46
62
  onError: (error) => { /* ... */ },
47
- onProgress: (progress) => { /* ... */ }
63
+ onProgress: (progress) => { /* 0-100 */ },
64
+ onValidationProgress: (job) => { /* job-based flow only */ }
48
65
  })
66
+
67
+ // To cancel:
68
+ abortController.abort()
49
69
  ```
50
70
 
51
71
  ---
52
72
 
53
73
  ### `useFetchImportOperations`
54
74
 
55
- Fetches import operations for a specific container with optional polling.
75
+ Fetches import operations for a container with optional polling.
56
76
 
57
77
  ```typescript
58
- const { data, error, isLoading, refetch, lastFetchTime } = useFetchImportOperations({
59
- projectKey: string,
60
- importContainerKey: string,
61
- queryParams?: ImportOperationQueryParams,
78
+ const { data, error, isLoading, refetch } = useFetchImportOperations({
79
+ projectKey,
80
+ importContainerKey,
81
+ queryParams?: { limit, offset, ... },
62
82
  pollingInterval?: number,
63
83
  shouldContinuePolling?: (data) => boolean
64
84
  })
65
85
  ```
66
86
 
67
- **Parameters:**
68
- - `projectKey` (required): The commercetools project key
69
- - `importContainerKey` (required): The import container key
70
- - `queryParams`: Optional query parameters (limit, offset, etc.)
71
- - `pollingInterval`: Polling interval in milliseconds
72
- - `shouldContinuePolling`: Function to determine if polling should continue
73
-
74
87
  ---
75
88
 
76
89
  ### `useFetchImportSummaries`
@@ -78,41 +91,29 @@ const { data, error, isLoading, refetch, lastFetchTime } = useFetchImportOperati
78
91
  Fetches import summaries (containers) with optional polling.
79
92
 
80
93
  ```typescript
81
- const { data, error, isLoading, refetch, lastFetchTime } = useFetchImportSummaries({
82
- projectKey: string,
83
- queryParams?: ImportContainerQueryParams,
94
+ const { data, error, isLoading, refetch } = useFetchImportSummaries({
95
+ projectKey,
96
+ queryParams?: { limit, offset, states, ... },
84
97
  pollingInterval?: number,
85
98
  shouldContinuePolling?: (data) => boolean
86
99
  })
87
100
  ```
88
101
 
89
- **Parameters:**
90
- - `projectKey` (required): The commercetools project key
91
- - `queryParams`: Optional query parameters (limit, offset, states, etc.)
92
- - `pollingInterval`: Polling interval in milliseconds
93
- - `shouldContinuePolling`: Function to determine if polling should continue
94
-
95
102
  ---
96
103
 
97
104
  ### `useFetchImportContainerDetails`
98
105
 
99
- Fetches details for a specific import container with optional polling.
106
+ Fetches details for a specific import container.
100
107
 
101
108
  ```typescript
102
- const { data, error, isLoading, refetch, lastFetchTime } = useFetchImportContainerDetails({
103
- projectKey: string,
104
- importContainerKey: string,
109
+ const { data, error, isLoading, refetch } = useFetchImportContainerDetails({
110
+ projectKey,
111
+ importContainerKey,
105
112
  pollingInterval?: number,
106
113
  shouldContinuePolling?: (data) => boolean
107
114
  })
108
115
  ```
109
116
 
110
- **Parameters:**
111
- - `projectKey` (required): The commercetools project key
112
- - `importContainerKey` (required): The import container key
113
- - `pollingInterval`: Polling interval in milliseconds
114
- - `shouldContinuePolling`: Function to determine if polling should continue
115
-
116
117
  ---
117
118
 
118
119
  ### `useFetchExportOperations`
@@ -120,50 +121,58 @@ const { data, error, isLoading, refetch, lastFetchTime } = useFetchImportContain
120
121
  Fetches export operations with optional polling.
121
122
 
122
123
  ```typescript
123
- const { data, error, isLoading, refetch, lastFetchTime } = useFetchExportOperations({
124
- projectKey: string,
125
- queryParams?: ExportOperationQueryParams,
124
+ const { data, error, isLoading, refetch } = useFetchExportOperations({
125
+ projectKey,
126
+ queryParams?: { limit, offset, resourceTypes, ... },
126
127
  pollingInterval?: number,
127
128
  shouldContinuePolling?: (data) => boolean
128
129
  })
129
130
  ```
130
131
 
131
- **Parameters:**
132
- - `projectKey` (required): The commercetools project key
133
- - `queryParams`: Optional query parameters (limit, offset, resourceTypes, etc.)
134
- - `pollingInterval`: Polling interval in milliseconds
135
- - `shouldContinuePolling`: Function to determine if polling should continue
136
-
137
132
  ---
138
133
 
139
- ## Notes
134
+ ### `useFetchFileImportJob`
140
135
 
141
- - **All hooks require `projectKey`** to be passed explicitly (retrieved from `useApplicationContext`)
142
- - **Polling is opt-in** via `pollingInterval` parameter
143
- - **Standard return structure**: All fetch hooks return `{ data, error, isLoading, refetch, lastFetchTime }`
144
- - **Automatic cleanup**: `useImportContainerUpload` automatically cleans up containers on upload errors
145
- - **File upload limits**: The package exports backend-recommended limits enforced in frontend validation:
146
- - `MAX_FILE_SIZE_MB` (35 MB)
147
- - `MAX_ROW_COUNT` (80,000)
148
- - **Internal use only**: This package also exports additional components, utilities, types, and API functions that are intended for internal use within the operations repository (operations app and frontend extensions). Only the hooks documented above are considered stable public API for external consumption.
136
+ Polls a File Import Job for status updates.
149
137
 
150
- ---
138
+ ```typescript
139
+ const { data, error, isLoading, refetch } = useFetchFileImportJob({
140
+ projectKey,
141
+ importContainerKey,
142
+ jobId,
143
+ pollingInterval?: number,
144
+ shouldContinuePolling?: (job) => boolean
145
+ })
146
+ ```
151
147
 
152
- ## Common patterns
148
+ **Job states:** `queued` → `processing` → `validated` → `initialising` → `ready`
153
149
 
154
- ### Polling example
150
+ ---
151
+
152
+ ## Helper Functions
155
153
 
156
154
  ```typescript
157
- const POLL_INTERVAL = 5000 // 5 seconds
155
+ import {
156
+ isImportJobQueued,
157
+ isImportJobProcessing,
158
+ isImportJobValidated,
159
+ isImportJobInitializing,
160
+ isImportJobReady,
161
+ shouldContinuePollingForImportValidation
162
+ } from '@commercetools-frontend-extensions/operations'
163
+ ```
158
164
 
165
+ ---
166
+
167
+ ## Polling Example
168
+
169
+ ```typescript
159
170
  const { data, isLoading } = useFetchImportOperations({
160
171
  projectKey,
161
172
  importContainerKey,
162
- pollingInterval: POLL_INTERVAL,
173
+ pollingInterval: 5000,
163
174
  shouldContinuePolling: (data) => {
164
- // Stop polling when all operations are completed
165
175
  return data?.results?.some(op => op.state === 'processing') ?? false
166
176
  }
167
177
  })
168
178
  ```
169
-