@commercetools-frontend-extensions/operations 0.0.0-canary-20251209161906

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 (180) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +178 -0
  3. package/babel.config.js +6 -0
  4. package/dist/commercetools-frontend-extensions-operations.cjs.d.ts +2 -0
  5. package/dist/commercetools-frontend-extensions-operations.cjs.dev.js +3273 -0
  6. package/dist/commercetools-frontend-extensions-operations.cjs.js +7 -0
  7. package/dist/commercetools-frontend-extensions-operations.cjs.prod.js +3265 -0
  8. package/dist/commercetools-frontend-extensions-operations.esm.js +3074 -0
  9. package/dist/declarations/src/@api/export-operations.d.ts +5 -0
  10. package/dist/declarations/src/@api/fetcher.d.ts +17 -0
  11. package/dist/declarations/src/@api/file-import-jobs.d.ts +7 -0
  12. package/dist/declarations/src/@api/file-upload.d.ts +3 -0
  13. package/dist/declarations/src/@api/import-containers.d.ts +35 -0
  14. package/dist/declarations/src/@api/import-operations.d.ts +6 -0
  15. package/dist/declarations/src/@api/index.d.ts +9 -0
  16. package/dist/declarations/src/@api/process-file.d.ts +3 -0
  17. package/dist/declarations/src/@api/test-fixtures.d.ts +279 -0
  18. package/dist/declarations/src/@api/urls.d.ts +74 -0
  19. package/dist/declarations/src/@components/file-drop-area/active-drag-drop-area.d.ts +10 -0
  20. package/dist/declarations/src/@components/file-drop-area/disabled-drop-area.d.ts +5 -0
  21. package/dist/declarations/src/@components/file-drop-area/drop-area-wrapper.d.ts +11 -0
  22. package/dist/declarations/src/@components/file-drop-area/enabled-drop-area.d.ts +7 -0
  23. package/dist/declarations/src/@components/file-drop-area/file-drop-area.d.ts +14 -0
  24. package/dist/declarations/src/@components/file-drop-area/file-dropped-area.d.ts +6 -0
  25. package/dist/declarations/src/@components/file-drop-area/index.d.ts +7 -0
  26. package/dist/declarations/src/@components/file-drop-area/styles.d.ts +9 -0
  27. package/dist/declarations/src/@components/icons/file-icon.d.ts +2 -0
  28. package/dist/declarations/src/@components/icons/index.d.ts +2 -0
  29. package/dist/declarations/src/@components/icons/lock-icon.d.ts +2 -0
  30. package/dist/declarations/src/@components/index.d.ts +6 -0
  31. package/dist/declarations/src/@components/info-box/index.d.ts +1 -0
  32. package/dist/declarations/src/@components/info-box/info-box.d.ts +7 -0
  33. package/dist/declarations/src/@components/upload-separator/index.d.ts +1 -0
  34. package/dist/declarations/src/@components/upload-separator/upload-separator.d.ts +12 -0
  35. package/dist/declarations/src/@components/upload-settings/index.d.ts +1 -0
  36. package/dist/declarations/src/@components/upload-settings/upload-settings.d.ts +11 -0
  37. package/dist/declarations/src/@components/uploading-modal/index.d.ts +1 -0
  38. package/dist/declarations/src/@components/uploading-modal/uploading-modal.d.ts +13 -0
  39. package/dist/declarations/src/@constants/delimiters.d.ts +8 -0
  40. package/dist/declarations/src/@constants/file-import-job.d.ts +1 -0
  41. package/dist/declarations/src/@constants/import-limits.d.ts +6 -0
  42. package/dist/declarations/src/@constants/import-tags.d.ts +7 -0
  43. package/dist/declarations/src/@constants/index.d.ts +5 -0
  44. package/dist/declarations/src/@constants/resource-links.d.ts +10 -0
  45. package/dist/declarations/src/@errors/http-error.d.ts +6 -0
  46. package/dist/declarations/src/@errors/index.d.ts +9 -0
  47. package/dist/declarations/src/@errors/invalid-response-error.d.ts +3 -0
  48. package/dist/declarations/src/@errors/no-resources-to-export-error.d.ts +3 -0
  49. package/dist/declarations/src/@errors/polling-aborted-error.d.ts +3 -0
  50. package/dist/declarations/src/@errors/project-key-not-available-error.d.ts +3 -0
  51. package/dist/declarations/src/@errors/query-predicate-error.d.ts +4 -0
  52. package/dist/declarations/src/@errors/unexpected-column-error.d.ts +3 -0
  53. package/dist/declarations/src/@errors/unexpected-operation-state-error.d.ts +4 -0
  54. package/dist/declarations/src/@errors/unexpected-resource-type-error.d.ts +3 -0
  55. package/dist/declarations/src/@hooks/index.d.ts +8 -0
  56. package/dist/declarations/src/@hooks/use-fetch-export-operations.d.ts +15 -0
  57. package/dist/declarations/src/@hooks/use-fetch-file-import-job.d.ts +17 -0
  58. package/dist/declarations/src/@hooks/use-fetch-import-container-details.d.ts +15 -0
  59. package/dist/declarations/src/@hooks/use-fetch-import-operations.d.ts +16 -0
  60. package/dist/declarations/src/@hooks/use-fetch-import-summaries.d.ts +20 -0
  61. package/dist/declarations/src/@hooks/use-file-import-job-upload.d.ts +18 -0
  62. package/dist/declarations/src/@hooks/use-file-upload.d.ts +28 -0
  63. package/dist/declarations/src/@hooks/use-import-container-upload.d.ts +19 -0
  64. package/dist/declarations/src/@types/api.d.ts +13 -0
  65. package/dist/declarations/src/@types/basic-error-data-type.d.ts +5 -0
  66. package/dist/declarations/src/@types/export-operation.d.ts +97 -0
  67. package/dist/declarations/src/@types/file-import-job.d.ts +99 -0
  68. package/dist/declarations/src/@types/file-upload-result.d.ts +21 -0
  69. package/dist/declarations/src/@types/file-upload.d.ts +63 -0
  70. package/dist/declarations/src/@types/import-container.d.ts +53 -0
  71. package/dist/declarations/src/@types/import-operation.d.ts +13 -0
  72. package/dist/declarations/src/@types/import-states.d.ts +9 -0
  73. package/dist/declarations/src/@types/import-summary.d.ts +15 -0
  74. package/dist/declarations/src/@types/index.d.ts +11 -0
  75. package/dist/declarations/src/@types/shared.d.ts +7 -0
  76. package/dist/declarations/src/@utils/error-mapping.d.ts +19 -0
  77. package/dist/declarations/src/@utils/file-import-job-helpers.d.ts +12 -0
  78. package/dist/declarations/src/@utils/file-upload.d.ts +54 -0
  79. package/dist/declarations/src/@utils/form.d.ts +1 -0
  80. package/dist/declarations/src/@utils/format.d.ts +5 -0
  81. package/dist/declarations/src/@utils/import-container.d.ts +8 -0
  82. package/dist/declarations/src/@utils/index.d.ts +8 -0
  83. package/dist/declarations/src/@utils/poll-job-until-validated.d.ts +11 -0
  84. package/dist/declarations/src/@utils/url.d.ts +6 -0
  85. package/dist/declarations/src/index.d.ts +26 -0
  86. package/index.js +1 -0
  87. package/jest.test.config.js +11 -0
  88. package/package.json +62 -0
  89. package/src/@api/export-operations.ts +26 -0
  90. package/src/@api/fetcher.spec.ts +51 -0
  91. package/src/@api/fetcher.ts +137 -0
  92. package/src/@api/file-import-jobs.ts +217 -0
  93. package/src/@api/file-upload.spec.ts +85 -0
  94. package/src/@api/file-upload.ts +46 -0
  95. package/src/@api/import-containers.ts +256 -0
  96. package/src/@api/import-operations.ts +33 -0
  97. package/src/@api/index.ts +9 -0
  98. package/src/@api/process-file.spec.ts +74 -0
  99. package/src/@api/process-file.ts +53 -0
  100. package/src/@api/test-fixtures.ts +894 -0
  101. package/src/@api/urls.ts +194 -0
  102. package/src/@components/file-drop-area/active-drag-drop-area.tsx +33 -0
  103. package/src/@components/file-drop-area/disabled-drop-area.tsx +17 -0
  104. package/src/@components/file-drop-area/drop-area-wrapper.tsx +38 -0
  105. package/src/@components/file-drop-area/enabled-drop-area.tsx +27 -0
  106. package/src/@components/file-drop-area/file-drop-area.tsx +74 -0
  107. package/src/@components/file-drop-area/file-dropped-area.tsx +29 -0
  108. package/src/@components/file-drop-area/index.ts +7 -0
  109. package/src/@components/file-drop-area/styles.ts +67 -0
  110. package/src/@components/icons/file-icon.tsx +30 -0
  111. package/src/@components/icons/index.ts +2 -0
  112. package/src/@components/icons/lock-icon.tsx +34 -0
  113. package/src/@components/index.ts +6 -0
  114. package/src/@components/info-box/index.ts +1 -0
  115. package/src/@components/info-box/info-box.tsx +23 -0
  116. package/src/@components/upload-separator/index.ts +1 -0
  117. package/src/@components/upload-separator/upload-separator.tsx +61 -0
  118. package/src/@components/upload-settings/index.ts +1 -0
  119. package/src/@components/upload-settings/upload-settings.tsx +36 -0
  120. package/src/@components/uploading-modal/index.ts +1 -0
  121. package/src/@components/uploading-modal/uploading-modal.tsx +66 -0
  122. package/src/@constants/delimiters.ts +14 -0
  123. package/src/@constants/file-import-job.ts +1 -0
  124. package/src/@constants/import-limits.ts +13 -0
  125. package/src/@constants/import-tags.ts +9 -0
  126. package/src/@constants/index.ts +5 -0
  127. package/src/@constants/resource-links.ts +61 -0
  128. package/src/@errors/http-error.ts +17 -0
  129. package/src/@errors/index.ts +9 -0
  130. package/src/@errors/invalid-response-error.ts +6 -0
  131. package/src/@errors/no-resources-to-export-error.ts +6 -0
  132. package/src/@errors/polling-aborted-error.ts +6 -0
  133. package/src/@errors/project-key-not-available-error.ts +6 -0
  134. package/src/@errors/query-predicate-error.ts +10 -0
  135. package/src/@errors/unexpected-column-error.ts +6 -0
  136. package/src/@errors/unexpected-operation-state-error.ts +8 -0
  137. package/src/@errors/unexpected-resource-type-error.ts +6 -0
  138. package/src/@hooks/index.ts +8 -0
  139. package/src/@hooks/use-fetch-export-operations.ts +34 -0
  140. package/src/@hooks/use-fetch-file-import-job.spec.ts +131 -0
  141. package/src/@hooks/use-fetch-file-import-job.ts +38 -0
  142. package/src/@hooks/use-fetch-import-container-details.ts +31 -0
  143. package/src/@hooks/use-fetch-import-operations.ts +42 -0
  144. package/src/@hooks/use-fetch-import-summaries.ts +47 -0
  145. package/src/@hooks/use-fetch.spec.ts +68 -0
  146. package/src/@hooks/use-fetch.ts +76 -0
  147. package/src/@hooks/use-file-import-job-upload.spec.ts +273 -0
  148. package/src/@hooks/use-file-import-job-upload.ts +101 -0
  149. package/src/@hooks/use-file-upload.ts +223 -0
  150. package/src/@hooks/use-import-container-upload.spec.ts +297 -0
  151. package/src/@hooks/use-import-container-upload.ts +130 -0
  152. package/src/@types/api.ts +14 -0
  153. package/src/@types/basic-error-data-type.ts +5 -0
  154. package/src/@types/export-operation.ts +147 -0
  155. package/src/@types/file-import-job.ts +165 -0
  156. package/src/@types/file-upload-result.ts +23 -0
  157. package/src/@types/file-upload.ts +81 -0
  158. package/src/@types/import-container.ts +104 -0
  159. package/src/@types/import-operation.ts +31 -0
  160. package/src/@types/import-states.ts +9 -0
  161. package/src/@types/import-summary.ts +22 -0
  162. package/src/@types/index.ts +11 -0
  163. package/src/@types/shared.ts +52 -0
  164. package/src/@utils/error-mapping.spec.ts +126 -0
  165. package/src/@utils/error-mapping.ts +40 -0
  166. package/src/@utils/file-import-job-helpers.spec.ts +147 -0
  167. package/src/@utils/file-import-job-helpers.ts +47 -0
  168. package/src/@utils/file-upload.spec.ts +151 -0
  169. package/src/@utils/file-upload.ts +189 -0
  170. package/src/@utils/form.ts +20 -0
  171. package/src/@utils/format.spec.ts +62 -0
  172. package/src/@utils/format.ts +53 -0
  173. package/src/@utils/import-container.spec.ts +26 -0
  174. package/src/@utils/import-container.ts +34 -0
  175. package/src/@utils/index.ts +8 -0
  176. package/src/@utils/poll-job-until-validated.ts +76 -0
  177. package/src/@utils/url.spec.ts +75 -0
  178. package/src/@utils/url.ts +18 -0
  179. package/src/index.ts +27 -0
  180. package/tsconfig.json +9 -0
@@ -0,0 +1,147 @@
1
+ import type { ResourceTypeId } from '@commercetools/importapi-sdk'
2
+ import { hasRequiredFields } from './shared'
3
+
4
+ export type ExportOperationState =
5
+ | 'processing'
6
+ | 'completed'
7
+ | 'failed'
8
+ | 'queued'
9
+
10
+ export type ResourceType = ResourceTypeId
11
+
12
+ export type FileFormat = 'json' | 'csv'
13
+
14
+ export type Separator = {
15
+ columns?: string
16
+ arrayValues?: string
17
+ decimal?: string
18
+ }
19
+
20
+ export type ExportOperation = {
21
+ id: string
22
+ fileName: string
23
+ createdAt: string
24
+ resourceType: ResourceType
25
+ state: ExportOperationState
26
+ completedPercentage: number
27
+ resourceCount: number
28
+ fileFormat: FileFormat
29
+ fields: string[]
30
+ locales: string[]
31
+ query?: string
32
+ filters?: {
33
+ filters: string[]
34
+ fullText?: {
35
+ text: string
36
+ locale: string
37
+ }
38
+ }
39
+ fillRows?: boolean
40
+ excelCompatible?: boolean
41
+ dryRun?: boolean
42
+ separator?: Separator
43
+ }
44
+
45
+ export interface PaginatedExportOperationResponse {
46
+ results: ExportOperation[]
47
+ limit: number
48
+ offset: number
49
+ total: number
50
+ count: number
51
+ }
52
+
53
+ export type DownloadFile = {
54
+ uri: string
55
+ }
56
+
57
+ export type ExportOperationQueryParams = {
58
+ limit: number
59
+ offset: number
60
+ }
61
+
62
+ export function assertPaginatedExportOperationResponse(
63
+ maybePaginatedExportOperationResponseOrExportOperationsResponse: unknown
64
+ ): asserts maybePaginatedExportOperationResponseOrExportOperationsResponse is PaginatedExportOperationResponse {
65
+ const requiredFields = ['results', 'total']
66
+ if (
67
+ hasRequiredFields(
68
+ maybePaginatedExportOperationResponseOrExportOperationsResponse,
69
+ requiredFields
70
+ )
71
+ )
72
+ return
73
+ throw new Error('Invalid response')
74
+ }
75
+
76
+ export function assertExportOperationsDownloadFileResponse(
77
+ maybeExportOperationDownloadFileResponse: unknown
78
+ ): asserts maybeExportOperationDownloadFileResponse is DownloadFile {
79
+ const requiredFields = ['uri']
80
+ if (
81
+ hasRequiredFields(maybeExportOperationDownloadFileResponse, requiredFields)
82
+ )
83
+ return
84
+ throw new Error('Invalid response')
85
+ }
86
+
87
+ export type QueryFilter = {
88
+ query?: Record<string, unknown>
89
+ }
90
+
91
+ export type SearchFilter = {
92
+ filters?: string[]
93
+ fullText?: {
94
+ text: string
95
+ locale: string
96
+ }
97
+ }
98
+
99
+ export interface ExportApiRequest {
100
+ projectKey: string
101
+ resourceType: string
102
+ fileName: string
103
+ fileFormat: string
104
+ fields: string[]
105
+ locales?: string[]
106
+ filters?: QueryFilter | SearchFilter
107
+ where?: string
108
+ fullText?: {
109
+ text: string
110
+ locale: string
111
+ }
112
+ fillRows?: boolean
113
+ excelCompatible?: boolean
114
+ separator?: Separator
115
+ }
116
+
117
+ export interface ExportApiSuccessResponse {
118
+ id: string
119
+ state: string
120
+ resourceType: string
121
+ resourceCount: number
122
+ createdAt: string
123
+ }
124
+
125
+ export interface ExportApiErrorResponse {
126
+ statusCode: number
127
+ error: string
128
+ errors: ValidationError[]
129
+ message: string
130
+ }
131
+
132
+ export type ValidationErrorCode =
133
+ | 'DuplicateFields'
134
+ | 'NotSupportedField'
135
+ | 'FieldDefinitionNotFound'
136
+ | 'AttributeDefinitionNotFound'
137
+ | 'LocalizedFieldWithoutLocale'
138
+ | 'IncompleteField'
139
+ | 'AttributeLevelMismatch'
140
+
141
+ export type ValidationError = {
142
+ code: ValidationErrorCode
143
+ message: string
144
+ field?: string
145
+ requestedLevel?: string
146
+ actualLevel?: string
147
+ }
@@ -0,0 +1,165 @@
1
+ import { hasRequiredFields } from './shared'
2
+
3
+ export type FileImportJobState =
4
+ | 'queued'
5
+ | 'processing'
6
+ | 'validated'
7
+ | 'initialising'
8
+ | 'ready'
9
+ | 'rejected'
10
+
11
+ export interface FileImportJobSummary {
12
+ total: number
13
+ invalid: number
14
+ valid: number
15
+ fieldsCount: number
16
+ fields: string[]
17
+ ignoredFields: string[]
18
+ }
19
+
20
+ export interface FileImportJobValidationError {
21
+ code: string
22
+ message: string
23
+ rowValue?: Record<string, string>
24
+ metadata?: {
25
+ row?: number
26
+ }
27
+ }
28
+
29
+ export interface FileImportJob {
30
+ id: string
31
+ fileName: string
32
+ importContainerKey: string
33
+ state: FileImportJobState
34
+ summary: FileImportJobSummary
35
+ jobError?: FileImportJobValidationError | null
36
+ }
37
+
38
+ export interface CreateFileImportJobWithStreamPayload {
39
+ fileType: 'csv' | 'json'
40
+ fileName: string
41
+ file: File
42
+ }
43
+
44
+ export interface CreateFileImportJobWithReferencePayload {
45
+ payloadType: 'fileReference'
46
+ fileName: string
47
+ fileUrl: string
48
+ }
49
+
50
+ export type CreateFileImportJobPayload =
51
+ | CreateFileImportJobWithStreamPayload
52
+ | CreateFileImportJobWithReferencePayload
53
+
54
+ export interface CreateFileImportJobParameters {
55
+ projectKey: string
56
+ resourceType: string
57
+ importContainerKey: string
58
+ payload: CreateFileImportJobPayload
59
+ onProgress?: (progress: number) => void
60
+ abortSignal?: AbortSignal
61
+ }
62
+
63
+ export interface GetFileImportJobParameters {
64
+ projectKey: string
65
+ importContainerKey: string
66
+ jobId: string
67
+ }
68
+
69
+ export interface FileImportJobError {
70
+ code: string
71
+ message: string
72
+ field: string
73
+ }
74
+
75
+ export interface FileImportJobErrorRecord {
76
+ index: number
77
+ errors: FileImportJobError[]
78
+ }
79
+
80
+ export interface FileImportJobRecordsResponse {
81
+ results: FileImportJobErrorRecord[]
82
+ total: number
83
+ limit: number
84
+ offset: number
85
+ count: number
86
+ }
87
+
88
+ export interface GetFileImportJobRecordsParameters {
89
+ projectKey: string
90
+ importContainerKey: string
91
+ jobId: string
92
+ limit?: number
93
+ offset?: number
94
+ isValid?: boolean
95
+ }
96
+
97
+ export interface ProcessFileImportJobParameters {
98
+ projectKey: string
99
+ resourceType: string
100
+ importContainerKey: string
101
+ jobId: string
102
+ action?: 'delete'
103
+ }
104
+
105
+ export interface ProcessFileImportJobResponse {
106
+ message: string
107
+ }
108
+
109
+ export interface DeleteFileImportJobParameters {
110
+ projectKey: string
111
+ importContainerKey: string
112
+ jobId: string
113
+ }
114
+
115
+ export interface ListFileImportJobsParameters {
116
+ projectKey: string
117
+ importContainerKey: string
118
+ limit?: number
119
+ offset?: number
120
+ }
121
+
122
+ export type ListFileImportJobsResponse = FileImportJob[]
123
+
124
+ export function assertFileImportJob(
125
+ maybeJob: unknown
126
+ ): asserts maybeJob is FileImportJob {
127
+ const requiredFields = ['id', 'fileName', 'importContainerKey', 'state']
128
+ if (hasRequiredFields(maybeJob, requiredFields)) return
129
+ throw new Error('Invalid File Import Job response')
130
+ }
131
+
132
+ export function assertFileImportJobRecordsResponse(
133
+ maybeRecords: unknown
134
+ ): asserts maybeRecords is FileImportJobRecordsResponse {
135
+ const requiredFields = ['results', 'total', 'limit', 'offset', 'count']
136
+ if (!hasRequiredFields(maybeRecords, requiredFields)) {
137
+ throw new Error(
138
+ 'Invalid File Import Job records response: missing required fields'
139
+ )
140
+ }
141
+ }
142
+
143
+ export function assertProcessFileImportJobResponse(
144
+ maybeResponse: unknown
145
+ ): asserts maybeResponse is ProcessFileImportJobResponse {
146
+ const requiredFields = ['message']
147
+ if (hasRequiredFields(maybeResponse, requiredFields)) return
148
+ throw new Error('Invalid Process File Import Job response')
149
+ }
150
+
151
+ export function assertListFileImportJobsResponse(
152
+ maybeResponse: unknown
153
+ ): asserts maybeResponse is ListFileImportJobsResponse {
154
+ if (!Array.isArray(maybeResponse)) {
155
+ throw new Error('Invalid List File Import Jobs response: expected an array')
156
+ }
157
+ if (maybeResponse.length > 0) {
158
+ const requiredFields = ['id', 'fileName', 'importContainerKey', 'state']
159
+ if (!hasRequiredFields(maybeResponse[0], requiredFields)) {
160
+ throw new Error(
161
+ 'Invalid List File Import Jobs response: missing required fields'
162
+ )
163
+ }
164
+ }
165
+ }
@@ -0,0 +1,23 @@
1
+ import type { FileImportJob } from './file-import-job'
2
+ import type { RowErrorsResponse } from './file-upload'
3
+
4
+ export interface FileUploadResult {
5
+ containerKey: string
6
+ summary: {
7
+ total: number
8
+ valid: number
9
+ invalid: number
10
+ fieldsCount: number
11
+ fields: string[]
12
+ ignoredFields: string[]
13
+ /**
14
+ * Validation errors. Format is compatible between old and new flows:
15
+ * - Old flow: { row?: number, index?: number, errors: RowError[] }
16
+ * - New flow: { index: number, errors: FileImportJobError[] }
17
+ */
18
+ results: Array<RowErrorsResponse>
19
+ }
20
+ // new job based flow-specific fields
21
+ jobId?: string
22
+ job?: FileImportJob
23
+ }
@@ -0,0 +1,81 @@
1
+ import type { ResourceTypeId } from '@commercetools/importapi-sdk'
2
+
3
+ export type FileUploadError = {
4
+ title: string
5
+ description: string
6
+ }
7
+
8
+ export type UploadFileErrorRow = {
9
+ id: string
10
+ row?: number
11
+ index?: number
12
+ code: string
13
+ field: string
14
+ validationMessage: string
15
+ }
16
+
17
+ export type RowError = {
18
+ code: string
19
+ message: string
20
+ field: string
21
+ }
22
+
23
+ export type RowErrorsResponse = {
24
+ row?: number
25
+ index?: number
26
+ errors: Array<RowError>
27
+ }
28
+
29
+ export type FileUploadResponse = {
30
+ results: Array<RowErrorsResponse>
31
+ invalid: number
32
+ valid: number
33
+ fileName: string
34
+ itemsCount: number
35
+ rowsCount: number
36
+ columnsCount: number
37
+ fields: Array<string>
38
+ ignoredFields: Array<string>
39
+ }
40
+
41
+ export interface FileUploadRequestParameters {
42
+ projectKey: string
43
+ importContainerKey: string
44
+ resourceType: ResourceTypeId
45
+ file: File
46
+ abortSignal?: AbortSignal
47
+ onSuccess: (data: FileUploadResponse) => void
48
+ onProgress: (progress: number) => void
49
+ onError: (error: Error) => void
50
+ }
51
+
52
+ export interface ProcessUploadedFileRequestParameters {
53
+ projectKey: string
54
+ importContainerKey: string
55
+ resourceType: ResourceTypeId
56
+ action?: 'delete' // Currently only 'delete' action is supported
57
+ }
58
+
59
+ export type ProcessFileResponse = {
60
+ message: string
61
+ }
62
+
63
+ export type MissingCsvFieldIdentifierError = {
64
+ code: string
65
+ message: string
66
+ rowValue: Record<string, unknown>
67
+ metadata: {
68
+ row: number
69
+ }
70
+ }
71
+
72
+ export type DecimalSeparator = '.' | ','
73
+
74
+ export type DropAreaState =
75
+ | 'default'
76
+ | 'active-drag'
77
+ | 'ready-for-drop'
78
+ | 'file-dropped'
79
+ | 'disabled'
80
+ | 'invalid'
81
+ | 'is-parsing'
@@ -0,0 +1,104 @@
1
+ import type {
2
+ ImportContainerPagedResponse,
3
+ ImportContainer,
4
+ ImportContainerDraft,
5
+ } from '@commercetools/importapi-sdk'
6
+ import { hasRequiredFields } from './shared'
7
+ import { type DecimalSeparator } from './file-upload'
8
+ import {
9
+ type ExtendedImportSummary,
10
+ type ImportSummary,
11
+ } from './import-summary'
12
+ import { type ImportStates } from './import-states'
13
+
14
+ export function assertImportContainerPagedResponse(
15
+ maybeImportContainerPagedResponse: unknown
16
+ ): asserts maybeImportContainerPagedResponse is ImportContainerPagedResponse {
17
+ const requiredFields = ['count', 'results']
18
+ if (hasRequiredFields(maybeImportContainerPagedResponse, requiredFields))
19
+ return
20
+ throw new Error('Invalid response')
21
+ }
22
+
23
+ export function assertImportSummary(
24
+ maybeImportSummary: unknown
25
+ ): asserts maybeImportSummary is ExtendedImportSummary {
26
+ const requiredFields = ['states', 'total']
27
+ if (hasRequiredFields(maybeImportSummary, requiredFields)) return
28
+ throw new Error('Invalid response')
29
+ }
30
+
31
+ export function assertImportContainer(
32
+ maybeImportContainerResponse: unknown
33
+ ): asserts maybeImportContainerResponse is ImportContainer {
34
+ const requiredFields = ['key', 'version']
35
+ if (hasRequiredFields(maybeImportContainerResponse, requiredFields)) return
36
+ throw new Error('Invalid response')
37
+ }
38
+
39
+ export type CancelContainerResponse = {
40
+ message: string
41
+ }
42
+
43
+ export function assertCancelContainerResponse(
44
+ maybeCancelContainerResponse: unknown
45
+ ): asserts maybeCancelContainerResponse is CancelContainerResponse {
46
+ if (
47
+ typeof maybeCancelContainerResponse === 'object' &&
48
+ maybeCancelContainerResponse !== null
49
+ ) {
50
+ const responseData = maybeCancelContainerResponse as Record<string, unknown>
51
+ if (typeof responseData.message === 'string') {
52
+ return
53
+ }
54
+ }
55
+ throw new Error('Invalid response')
56
+ }
57
+
58
+ export type ImportContainerQueryParams = {
59
+ limit?: number
60
+ offset?: number
61
+ sort?: string
62
+ tags?: string
63
+ }
64
+
65
+ // Extended types to support settings that aren't in the base SDK yet
66
+ export interface ExtendedImportContainer extends ImportContainer {
67
+ settings?: {
68
+ resourceType?: string
69
+ format?: string
70
+ decimalSeparator?: DecimalSeparator
71
+ options?: {
72
+ publishAllChanges?: boolean
73
+ unpublishAllChanges?: boolean
74
+ }
75
+ }
76
+ tags?: string[]
77
+ }
78
+
79
+ export interface ExtendedImportContainerDraft extends ImportContainerDraft {
80
+ settings?: {
81
+ resourceType?: string
82
+ format?: string
83
+ decimalSeparator?: DecimalSeparator
84
+ options?: {
85
+ publishAllChanges?: boolean
86
+ unpublishAllChanges?: boolean
87
+ }
88
+ }
89
+ tags?: string[]
90
+ }
91
+
92
+ export type ImportContainerDetails = {
93
+ importContainer: ExtendedImportContainer
94
+ importState: ImportStates
95
+ importSummary: ImportSummary
96
+ isFileUploadImport: boolean
97
+ }
98
+
99
+ export type ImportSummaries = {
100
+ results: Array<Promise<ImportContainerDetails>>
101
+ count: number
102
+ total: number
103
+ queryParams: ImportContainerQueryParams
104
+ }
@@ -0,0 +1,31 @@
1
+ import type {
2
+ ImportOperation,
3
+ ImportOperationPagedResponse,
4
+ } from '@commercetools/importapi-sdk'
5
+ import { hasRequiredFields } from './shared'
6
+
7
+ export type ImportOperationQueryParams = {
8
+ limit?: number
9
+ offset?: number
10
+ state?: string | string[]
11
+ }
12
+
13
+ // TODO: Remove the temporarily extended ImportOperation when the SDK is updated
14
+ export interface ExtendedImportOperation extends ImportOperation {
15
+ tags?: string[]
16
+ }
17
+
18
+ // TODO: Remove the temporarily extended ImportOperationPagedResponse when the SDK is updated
19
+ export interface ExtendedImportOperationPagedResponse
20
+ extends ImportOperationPagedResponse {
21
+ results: ExtendedImportOperation[]
22
+ }
23
+
24
+ export function assertImportOperationPagedResponse(
25
+ maybeImportOperationPagedResponse: unknown
26
+ ): asserts maybeImportOperationPagedResponse is ExtendedImportOperationPagedResponse {
27
+ const requiredFields = ['count', 'total', 'results']
28
+ if (hasRequiredFields(maybeImportOperationPagedResponse, requiredFields))
29
+ return
30
+ throw new Error('Invalid response')
31
+ }
@@ -0,0 +1,9 @@
1
+ export enum ImportStates {
2
+ Processing = 'processing',
3
+ WaitForUnresolvedReferences = 'wait-for-unresolved-references',
4
+ PartiallyCompleted = 'partially-completed',
5
+ Failed = 'failed',
6
+ SuccessfullyCompleted = 'successfully-completed',
7
+ NoRunningImports = 'no-running-imports',
8
+ Canceled = 'canceled',
9
+ }
@@ -0,0 +1,22 @@
1
+ import type {
2
+ OperationStates,
3
+ ImportSummary,
4
+ } from '@commercetools/importapi-sdk'
5
+
6
+ interface ExtendedOperationStates extends OperationStates {
7
+ /**
8
+ * The number of resources in the `canceled` state.
9
+ */
10
+ readonly canceled: number
11
+ /**
12
+ * The number of resources in the `deleted` state.
13
+ */
14
+ readonly deleted: number
15
+ }
16
+
17
+ export interface ExtendedImportSummary extends ImportSummary {
18
+ readonly states: ExtendedOperationStates
19
+ }
20
+
21
+ // Re-export as ImportSummary for convenience
22
+ export { type ExtendedImportSummary as ImportSummary }
@@ -0,0 +1,11 @@
1
+ export * from './api'
2
+ export * from './basic-error-data-type'
3
+ export * from './export-operation'
4
+ export * from './file-upload'
5
+ export * from './file-upload-result'
6
+ export * from './file-import-job'
7
+ export * from './import-container'
8
+ export * from './import-operation'
9
+ export * from './import-states'
10
+ export * from './import-summary'
11
+ export * from './shared'
@@ -0,0 +1,52 @@
1
+ export function hasOwnProperty<X extends {}, Y extends PropertyKey>(
2
+ obj: X,
3
+ prop: Y
4
+ ): obj is X & Record<Y, unknown> {
5
+ return typeof obj === 'object' && obj !== null && obj.hasOwnProperty(prop)
6
+ }
7
+
8
+ export function hasRequiredFields(
9
+ maybeValidObject: unknown,
10
+ requiredFields: Array<string>
11
+ ): boolean {
12
+ return (
13
+ typeof maybeValidObject === 'object' &&
14
+ maybeValidObject !== null &&
15
+ requiredFields.every((property) =>
16
+ hasOwnProperty(maybeValidObject, property)
17
+ )
18
+ )
19
+ }
20
+
21
+ export function getMissingRequiredFields(
22
+ maybeValidObject: unknown,
23
+ requiredFields: Array<string>
24
+ ): string[] | false {
25
+ return (
26
+ typeof maybeValidObject === 'object' &&
27
+ maybeValidObject !== null &&
28
+ requiredFields.filter((property) => !(property in maybeValidObject))
29
+ )
30
+ }
31
+
32
+ export function isError(maybeError: unknown): maybeError is Error {
33
+ if (maybeError instanceof Error) return true
34
+ return false
35
+ }
36
+
37
+ export function isAbortError(error: unknown): error is DOMException {
38
+ return error instanceof DOMException && error.name === 'AbortError'
39
+ }
40
+
41
+ export function isResourceType<T extends string>(
42
+ maybeResourceType: unknown
43
+ ): maybeResourceType is T {
44
+ return typeof maybeResourceType === 'string'
45
+ }
46
+
47
+ export function assertResourceType<T extends string>(
48
+ maybeResourceType: unknown
49
+ ): asserts maybeResourceType is T {
50
+ if (typeof maybeResourceType === 'string') return
51
+ throw new Error(`Invalid value: ${maybeResourceType}`)
52
+ }