@commercetools-frontend-extensions/operations 0.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 (158) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +169 -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 +2469 -0
  6. package/dist/commercetools-frontend-extensions-operations.cjs.js +7 -0
  7. package/dist/commercetools-frontend-extensions-operations.cjs.prod.js +2461 -0
  8. package/dist/commercetools-frontend-extensions-operations.esm.js +2316 -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-upload.d.ts +3 -0
  12. package/dist/declarations/src/@api/import-containers.d.ts +35 -0
  13. package/dist/declarations/src/@api/import-operations.d.ts +6 -0
  14. package/dist/declarations/src/@api/index.d.ts +8 -0
  15. package/dist/declarations/src/@api/process-file.d.ts +3 -0
  16. package/dist/declarations/src/@api/test-fixtures.d.ts +272 -0
  17. package/dist/declarations/src/@api/urls.d.ts +44 -0
  18. package/dist/declarations/src/@components/file-drop-area/active-drag-drop-area.d.ts +10 -0
  19. package/dist/declarations/src/@components/file-drop-area/disabled-drop-area.d.ts +5 -0
  20. package/dist/declarations/src/@components/file-drop-area/drop-area-wrapper.d.ts +11 -0
  21. package/dist/declarations/src/@components/file-drop-area/enabled-drop-area.d.ts +7 -0
  22. package/dist/declarations/src/@components/file-drop-area/file-drop-area.d.ts +14 -0
  23. package/dist/declarations/src/@components/file-drop-area/file-dropped-area.d.ts +6 -0
  24. package/dist/declarations/src/@components/file-drop-area/index.d.ts +7 -0
  25. package/dist/declarations/src/@components/file-drop-area/styles.d.ts +9 -0
  26. package/dist/declarations/src/@components/icons/file-icon.d.ts +2 -0
  27. package/dist/declarations/src/@components/icons/index.d.ts +2 -0
  28. package/dist/declarations/src/@components/icons/lock-icon.d.ts +2 -0
  29. package/dist/declarations/src/@components/index.d.ts +6 -0
  30. package/dist/declarations/src/@components/info-box/index.d.ts +1 -0
  31. package/dist/declarations/src/@components/info-box/info-box.d.ts +7 -0
  32. package/dist/declarations/src/@components/upload-separator/index.d.ts +1 -0
  33. package/dist/declarations/src/@components/upload-separator/upload-separator.d.ts +12 -0
  34. package/dist/declarations/src/@components/upload-settings/index.d.ts +1 -0
  35. package/dist/declarations/src/@components/upload-settings/upload-settings.d.ts +11 -0
  36. package/dist/declarations/src/@components/uploading-modal/index.d.ts +1 -0
  37. package/dist/declarations/src/@components/uploading-modal/uploading-modal.d.ts +12 -0
  38. package/dist/declarations/src/@constants/delimiters.d.ts +8 -0
  39. package/dist/declarations/src/@constants/import-tags.d.ts +7 -0
  40. package/dist/declarations/src/@constants/index.d.ts +4 -0
  41. package/dist/declarations/src/@constants/resource-links.d.ts +10 -0
  42. package/dist/declarations/src/@constants/upload-limits.d.ts +10 -0
  43. package/dist/declarations/src/@errors/http-error.d.ts +6 -0
  44. package/dist/declarations/src/@errors/index.d.ts +8 -0
  45. package/dist/declarations/src/@errors/invalid-response-error.d.ts +3 -0
  46. package/dist/declarations/src/@errors/no-resources-to-export-error.d.ts +3 -0
  47. package/dist/declarations/src/@errors/project-key-not-available-error.d.ts +3 -0
  48. package/dist/declarations/src/@errors/query-predicate-error.d.ts +4 -0
  49. package/dist/declarations/src/@errors/unexpected-column-error.d.ts +3 -0
  50. package/dist/declarations/src/@errors/unexpected-operation-state-error.d.ts +4 -0
  51. package/dist/declarations/src/@errors/unexpected-resource-type-error.d.ts +3 -0
  52. package/dist/declarations/src/@hooks/index.d.ts +5 -0
  53. package/dist/declarations/src/@hooks/use-fetch-export-operations.d.ts +15 -0
  54. package/dist/declarations/src/@hooks/use-fetch-import-container-details.d.ts +15 -0
  55. package/dist/declarations/src/@hooks/use-fetch-import-operations.d.ts +16 -0
  56. package/dist/declarations/src/@hooks/use-fetch-import-summaries.d.ts +20 -0
  57. package/dist/declarations/src/@hooks/use-import-container-upload.d.ts +18 -0
  58. package/dist/declarations/src/@types/api.d.ts +13 -0
  59. package/dist/declarations/src/@types/basic-error-data-type.d.ts +5 -0
  60. package/dist/declarations/src/@types/export-operation.d.ts +95 -0
  61. package/dist/declarations/src/@types/file-upload.d.ts +63 -0
  62. package/dist/declarations/src/@types/import-container.d.ts +53 -0
  63. package/dist/declarations/src/@types/import-operation.d.ts +13 -0
  64. package/dist/declarations/src/@types/import-states.d.ts +9 -0
  65. package/dist/declarations/src/@types/import-summary.d.ts +15 -0
  66. package/dist/declarations/src/@types/index.d.ts +9 -0
  67. package/dist/declarations/src/@types/shared.d.ts +7 -0
  68. package/dist/declarations/src/@utils/error-mapping.d.ts +19 -0
  69. package/dist/declarations/src/@utils/file-upload.d.ts +46 -0
  70. package/dist/declarations/src/@utils/form.d.ts +1 -0
  71. package/dist/declarations/src/@utils/format.d.ts +5 -0
  72. package/dist/declarations/src/@utils/import-container.d.ts +8 -0
  73. package/dist/declarations/src/@utils/index.d.ts +6 -0
  74. package/dist/declarations/src/@utils/url.d.ts +6 -0
  75. package/dist/declarations/src/index.d.ts +26 -0
  76. package/index.js +1 -0
  77. package/jest.test.config.js +11 -0
  78. package/package.json +63 -0
  79. package/src/@api/export-operations.ts +26 -0
  80. package/src/@api/fetcher.spec.ts +51 -0
  81. package/src/@api/fetcher.ts +127 -0
  82. package/src/@api/file-upload.spec.ts +83 -0
  83. package/src/@api/file-upload.ts +46 -0
  84. package/src/@api/import-containers.ts +256 -0
  85. package/src/@api/import-operations.ts +33 -0
  86. package/src/@api/index.ts +8 -0
  87. package/src/@api/process-file.spec.ts +74 -0
  88. package/src/@api/process-file.ts +53 -0
  89. package/src/@api/test-fixtures.ts +772 -0
  90. package/src/@api/urls.ts +118 -0
  91. package/src/@components/file-drop-area/active-drag-drop-area.tsx +33 -0
  92. package/src/@components/file-drop-area/disabled-drop-area.tsx +17 -0
  93. package/src/@components/file-drop-area/drop-area-wrapper.tsx +38 -0
  94. package/src/@components/file-drop-area/enabled-drop-area.tsx +27 -0
  95. package/src/@components/file-drop-area/file-drop-area.tsx +74 -0
  96. package/src/@components/file-drop-area/file-dropped-area.tsx +29 -0
  97. package/src/@components/file-drop-area/index.ts +7 -0
  98. package/src/@components/file-drop-area/styles.ts +67 -0
  99. package/src/@components/icons/file-icon.tsx +30 -0
  100. package/src/@components/icons/index.ts +2 -0
  101. package/src/@components/icons/lock-icon.tsx +34 -0
  102. package/src/@components/index.ts +6 -0
  103. package/src/@components/info-box/index.ts +1 -0
  104. package/src/@components/info-box/info-box.tsx +23 -0
  105. package/src/@components/upload-separator/index.ts +1 -0
  106. package/src/@components/upload-separator/upload-separator.tsx +61 -0
  107. package/src/@components/upload-settings/index.ts +1 -0
  108. package/src/@components/upload-settings/upload-settings.tsx +36 -0
  109. package/src/@components/uploading-modal/index.ts +1 -0
  110. package/src/@components/uploading-modal/uploading-modal.tsx +64 -0
  111. package/src/@constants/delimiters.ts +14 -0
  112. package/src/@constants/import-tags.ts +9 -0
  113. package/src/@constants/index.ts +4 -0
  114. package/src/@constants/resource-links.ts +61 -0
  115. package/src/@constants/upload-limits.ts +11 -0
  116. package/src/@errors/http-error.ts +17 -0
  117. package/src/@errors/index.ts +8 -0
  118. package/src/@errors/invalid-response-error.ts +6 -0
  119. package/src/@errors/no-resources-to-export-error.ts +6 -0
  120. package/src/@errors/project-key-not-available-error.ts +6 -0
  121. package/src/@errors/query-predicate-error.ts +10 -0
  122. package/src/@errors/unexpected-column-error.ts +6 -0
  123. package/src/@errors/unexpected-operation-state-error.ts +8 -0
  124. package/src/@errors/unexpected-resource-type-error.ts +6 -0
  125. package/src/@hooks/index.ts +5 -0
  126. package/src/@hooks/messages.ts +11 -0
  127. package/src/@hooks/use-fetch-export-operations.ts +34 -0
  128. package/src/@hooks/use-fetch-import-container-details.ts +31 -0
  129. package/src/@hooks/use-fetch-import-operations.ts +42 -0
  130. package/src/@hooks/use-fetch-import-summaries.ts +47 -0
  131. package/src/@hooks/use-fetch.spec.ts +76 -0
  132. package/src/@hooks/use-fetch.ts +80 -0
  133. package/src/@hooks/use-import-container-upload.spec.ts +294 -0
  134. package/src/@hooks/use-import-container-upload.ts +126 -0
  135. package/src/@types/api.ts +14 -0
  136. package/src/@types/basic-error-data-type.ts +5 -0
  137. package/src/@types/export-operation.ts +144 -0
  138. package/src/@types/file-upload.ts +81 -0
  139. package/src/@types/import-container.ts +104 -0
  140. package/src/@types/import-operation.ts +31 -0
  141. package/src/@types/import-states.ts +9 -0
  142. package/src/@types/import-summary.ts +22 -0
  143. package/src/@types/index.ts +9 -0
  144. package/src/@types/shared.ts +52 -0
  145. package/src/@utils/error-mapping.spec.ts +126 -0
  146. package/src/@utils/error-mapping.ts +39 -0
  147. package/src/@utils/file-upload.spec.ts +151 -0
  148. package/src/@utils/file-upload.ts +150 -0
  149. package/src/@utils/form.ts +20 -0
  150. package/src/@utils/format.spec.ts +62 -0
  151. package/src/@utils/format.ts +53 -0
  152. package/src/@utils/import-container.spec.ts +26 -0
  153. package/src/@utils/import-container.ts +34 -0
  154. package/src/@utils/index.ts +6 -0
  155. package/src/@utils/url.spec.ts +75 -0
  156. package/src/@utils/url.ts +18 -0
  157. package/src/index.ts +27 -0
  158. package/tsconfig.json +9 -0
@@ -0,0 +1,3 @@
1
+ export declare class UnexpectedColumnError extends Error {
2
+ constructor(columnName: string);
3
+ }
@@ -0,0 +1,4 @@
1
+ import { ProcessingState } from '@commercetools/importapi-sdk';
2
+ export declare class UnexpectedOperationStateError extends Error {
3
+ constructor(state: ProcessingState);
4
+ }
@@ -0,0 +1,3 @@
1
+ export declare class UnexpectedResourceTypeError extends Error {
2
+ constructor(resourceType: string);
3
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./use-fetch-export-operations.js";
2
+ export * from "./use-fetch-import-container-details.js";
3
+ export * from "./use-fetch-import-operations.js";
4
+ export * from "./use-fetch-import-summaries.js";
5
+ export * from "./use-import-container-upload.js";
@@ -0,0 +1,15 @@
1
+ import type { PaginatedExportOperationResponse, ExportOperationQueryParams } from "../@types/index.js";
2
+ type UseFetchExportOperationsConfig = {
3
+ projectKey: string;
4
+ queryParams: ExportOperationQueryParams;
5
+ pollingInterval?: number;
6
+ shouldContinuePolling?: (data: PaginatedExportOperationResponse) => boolean;
7
+ };
8
+ export declare const useFetchExportOperations: ({ projectKey, queryParams, pollingInterval, shouldContinuePolling, }: UseFetchExportOperationsConfig) => {
9
+ data: PaginatedExportOperationResponse | null;
10
+ error: Error | null;
11
+ isLoading: boolean;
12
+ refetch: () => void;
13
+ lastFetchTime: Date;
14
+ };
15
+ export {};
@@ -0,0 +1,15 @@
1
+ import { type ImportContainerDetails } from "../@types/index.js";
2
+ type UseFetchImportContainerDetailsConfig = {
3
+ projectKey: string;
4
+ importContainerKey: string;
5
+ pollingInterval?: number;
6
+ shouldContinuePolling?: (data: ImportContainerDetails) => boolean;
7
+ };
8
+ export declare const useFetchImportContainerDetails: ({ projectKey, importContainerKey, pollingInterval, shouldContinuePolling, }: UseFetchImportContainerDetailsConfig) => {
9
+ data: ImportContainerDetails | null;
10
+ error: Error | null;
11
+ isLoading: boolean;
12
+ refetch: () => void;
13
+ lastFetchTime: Date;
14
+ };
15
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { ExtendedImportOperationPagedResponse, ImportOperationQueryParams } from "../@types/index.js";
2
+ type UseFetchImportOperationsConfig = {
3
+ projectKey: string;
4
+ importContainerKey: string;
5
+ queryParams: ImportOperationQueryParams;
6
+ pollingInterval?: number;
7
+ shouldContinuePolling?: (data: ExtendedImportOperationPagedResponse) => boolean;
8
+ };
9
+ export declare const useFetchImportOperations: ({ projectKey, importContainerKey, queryParams, pollingInterval, shouldContinuePolling, }: UseFetchImportOperationsConfig) => {
10
+ data: ExtendedImportOperationPagedResponse | null;
11
+ error: Error | null;
12
+ isLoading: boolean;
13
+ refetch: () => void;
14
+ lastFetchTime: Date;
15
+ };
16
+ export {};
@@ -0,0 +1,20 @@
1
+ import type { ImportContainerQueryParams, ImportContainerDetails } from "../@types/index.js";
2
+ export type ImportSummariesResult = {
3
+ results: ImportContainerDetails[];
4
+ count: number;
5
+ total: number;
6
+ };
7
+ type UseFetchImportSummariesConfig = {
8
+ projectKey: string;
9
+ queryParams: ImportContainerQueryParams;
10
+ pollingInterval?: number;
11
+ shouldContinuePolling?: (data: ImportSummariesResult) => boolean;
12
+ };
13
+ export declare const useFetchImportSummaries: ({ projectKey, queryParams, pollingInterval, shouldContinuePolling, }: UseFetchImportSummariesConfig) => {
14
+ data: ImportSummariesResult | null;
15
+ error: Error | null;
16
+ isLoading: boolean;
17
+ refetch: () => void;
18
+ lastFetchTime: Date;
19
+ };
20
+ export {};
@@ -0,0 +1,18 @@
1
+ import type { ResourceTypeId } from '@commercetools/importapi-sdk';
2
+ import type { FileUploadResponse, ExtendedImportContainerDraft } from "../@types/index.js";
3
+ export type UseImportContainerUploadConfig = {
4
+ file: File;
5
+ resourceType: ResourceTypeId;
6
+ settings?: ExtendedImportContainerDraft['settings'];
7
+ onSuccess: (response: FileUploadResponse, importContainerKey: string) => void;
8
+ onError?: (error: unknown) => void;
9
+ onProgress?: (progress: number) => void;
10
+ };
11
+ export declare const useImportContainerUpload: ({ projectKey, }: {
12
+ projectKey: string;
13
+ }) => {
14
+ upload: ({ file, resourceType, settings, onSuccess, onError, onProgress, }: UseImportContainerUploadConfig) => Promise<XMLHttpRequest>;
15
+ abort: () => void;
16
+ isUploading: boolean;
17
+ progress: number;
18
+ };
@@ -0,0 +1,13 @@
1
+ type METHOD = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
2
+ export type ApiConfig = {
3
+ headers?: Record<string, string | null>;
4
+ method?: METHOD;
5
+ proxy?: string;
6
+ abortSignal?: AbortSignal;
7
+ };
8
+ export type Fetcher = {
9
+ url: string;
10
+ payload?: BodyInit;
11
+ config?: ApiConfig;
12
+ };
13
+ export {};
@@ -0,0 +1,5 @@
1
+ export interface BasicErrorDataType {
2
+ message: string;
3
+ code: string;
4
+ [key: string]: unknown;
5
+ }
@@ -0,0 +1,95 @@
1
+ import type { ResourceTypeId } from '@commercetools/importapi-sdk';
2
+ export type ExportOperationState = 'processing' | 'completed' | 'failed' | 'queued';
3
+ export type ResourceType = ResourceTypeId;
4
+ export type FileFormat = 'json' | 'csv';
5
+ export type Separator = {
6
+ columns?: string;
7
+ arrayValues?: string;
8
+ decimal?: string;
9
+ };
10
+ export type ExportOperation = {
11
+ id: string;
12
+ fileName: string;
13
+ createdAt: string;
14
+ resourceType: ResourceType;
15
+ state: ExportOperationState;
16
+ completedPercentage: number;
17
+ resourceCount: number;
18
+ fileFormat: FileFormat;
19
+ fields: string[];
20
+ locales: string[];
21
+ query?: string;
22
+ filters?: {
23
+ filters: string[];
24
+ fullText?: {
25
+ text: string;
26
+ locale: string;
27
+ };
28
+ };
29
+ fillRows?: boolean;
30
+ excelCompatible?: boolean;
31
+ dryRun?: boolean;
32
+ separator?: Separator;
33
+ };
34
+ export interface PaginatedExportOperationResponse {
35
+ results: ExportOperation[];
36
+ limit: number;
37
+ offset: number;
38
+ total: number;
39
+ count: number;
40
+ }
41
+ export type DownloadFile = {
42
+ uri: string;
43
+ };
44
+ export type ExportOperationQueryParams = {
45
+ limit: number;
46
+ offset: number;
47
+ };
48
+ export declare function assertPaginatedExportOperationResponse(maybePaginatedExportOperationResponseOrExportOperationsResponse: unknown): asserts maybePaginatedExportOperationResponseOrExportOperationsResponse is PaginatedExportOperationResponse;
49
+ export declare function assertExportOperationsDownloadFileResponse(maybeExportOperationDownloadFileResponse: unknown): asserts maybeExportOperationDownloadFileResponse is DownloadFile;
50
+ export type QueryFilter = {
51
+ query?: Record<string, unknown>;
52
+ };
53
+ export type SearchFilter = {
54
+ filters?: string[];
55
+ fullText?: {
56
+ text: string;
57
+ locale: string;
58
+ };
59
+ };
60
+ export interface ExportApiRequest {
61
+ projectKey: string;
62
+ resourceType: string;
63
+ fileName: string;
64
+ fileFormat: string;
65
+ fields: string[];
66
+ locales?: string[];
67
+ filters?: QueryFilter | SearchFilter;
68
+ where?: string;
69
+ fullText?: {
70
+ text: string;
71
+ locale: string;
72
+ };
73
+ fillRows?: boolean;
74
+ excelCompatible?: boolean;
75
+ separator?: Separator;
76
+ }
77
+ export interface ExportApiSuccessResponse {
78
+ id: string;
79
+ state: string;
80
+ resourceType: string;
81
+ resourceCount: number;
82
+ createdAt: string;
83
+ }
84
+ export interface ExportApiErrorResponse {
85
+ statusCode: number;
86
+ error: string;
87
+ errors: ValidationError[];
88
+ message: string;
89
+ }
90
+ export type ValidationErrorCode = 'DuplicateFields' | 'NotSupportedField' | 'FieldDefinitionNotFound' | 'AttributeDefinitionNotFound' | 'LocalizedFieldWithoutLocale' | 'IncompleteField';
91
+ export type ValidationError = {
92
+ code: ValidationErrorCode;
93
+ message: string;
94
+ field?: string;
95
+ };
@@ -0,0 +1,63 @@
1
+ import type { ResourceTypeId } from '@commercetools/importapi-sdk';
2
+ export type FileUploadError = {
3
+ title: string;
4
+ description: string;
5
+ };
6
+ export type UploadFileErrorRow = {
7
+ id: string;
8
+ row?: number;
9
+ index?: number;
10
+ code: string;
11
+ field: string;
12
+ validationMessage: string;
13
+ };
14
+ export type RowError = {
15
+ code: string;
16
+ message: string;
17
+ field: string;
18
+ };
19
+ export type RowErrorsResponse = {
20
+ row?: number;
21
+ index?: number;
22
+ errors: Array<RowError>;
23
+ };
24
+ export type FileUploadResponse = {
25
+ results: Array<RowErrorsResponse>;
26
+ invalid: number;
27
+ valid: number;
28
+ fileName: string;
29
+ itemsCount: number;
30
+ rowsCount: number;
31
+ columnsCount: number;
32
+ columns: Array<string>;
33
+ ignoredColumns: Array<string>;
34
+ };
35
+ export interface FileUploadRequestParameters {
36
+ projectKey: string;
37
+ importContainerKey: string;
38
+ resourceType: ResourceTypeId;
39
+ file: File;
40
+ abortSignal?: AbortSignal;
41
+ onSuccess: (data: FileUploadResponse) => void;
42
+ onProgress: (progress: number) => void;
43
+ onError: (error: Error) => void;
44
+ }
45
+ export interface ProcessUploadedFileRequestParameters {
46
+ projectKey: string;
47
+ importContainerKey: string;
48
+ resourceType: ResourceTypeId;
49
+ action?: 'delete';
50
+ }
51
+ export type ProcessFileResponse = {
52
+ message: string;
53
+ };
54
+ export type MissingCsvFieldIdentifierError = {
55
+ code: string;
56
+ message: string;
57
+ rowValue: Record<string, unknown>;
58
+ metadata: {
59
+ row: number;
60
+ };
61
+ };
62
+ export type DecimalSeparator = '.' | ',';
63
+ export type DropAreaState = 'default' | 'active-drag' | 'ready-for-drop' | 'file-dropped' | 'disabled' | 'invalid' | 'is-parsing';
@@ -0,0 +1,53 @@
1
+ import type { ImportContainerPagedResponse, ImportContainer, ImportContainerDraft } from '@commercetools/importapi-sdk';
2
+ import { type DecimalSeparator } from "./file-upload.js";
3
+ import { type ExtendedImportSummary, type ImportSummary } from "./import-summary.js";
4
+ import { type ImportStates } from "./import-states.js";
5
+ export declare function assertImportContainerPagedResponse(maybeImportContainerPagedResponse: unknown): asserts maybeImportContainerPagedResponse is ImportContainerPagedResponse;
6
+ export declare function assertImportSummary(maybeImportSummary: unknown): asserts maybeImportSummary is ExtendedImportSummary;
7
+ export declare function assertImportContainer(maybeImportContainerResponse: unknown): asserts maybeImportContainerResponse is ImportContainer;
8
+ export type CancelContainerResponse = {
9
+ message: string;
10
+ };
11
+ export declare function assertCancelContainerResponse(maybeCancelContainerResponse: unknown): asserts maybeCancelContainerResponse is CancelContainerResponse;
12
+ export type ImportContainerQueryParams = {
13
+ limit?: number;
14
+ offset?: number;
15
+ sort?: string;
16
+ tags?: string;
17
+ };
18
+ export interface ExtendedImportContainer extends ImportContainer {
19
+ settings?: {
20
+ resourceType?: string;
21
+ format?: string;
22
+ decimalSeparator?: DecimalSeparator;
23
+ options?: {
24
+ publishAllChanges?: boolean;
25
+ unpublishAllChanges?: boolean;
26
+ };
27
+ };
28
+ tags?: string[];
29
+ }
30
+ export interface ExtendedImportContainerDraft extends ImportContainerDraft {
31
+ settings?: {
32
+ resourceType?: string;
33
+ format?: string;
34
+ decimalSeparator?: DecimalSeparator;
35
+ options?: {
36
+ publishAllChanges?: boolean;
37
+ unpublishAllChanges?: boolean;
38
+ };
39
+ };
40
+ tags?: string[];
41
+ }
42
+ export type ImportContainerDetails = {
43
+ importContainer: ExtendedImportContainer;
44
+ importState: ImportStates;
45
+ importSummary: ImportSummary;
46
+ isFileUploadImport: boolean;
47
+ };
48
+ export type ImportSummaries = {
49
+ results: Array<Promise<ImportContainerDetails>>;
50
+ count: number;
51
+ total: number;
52
+ queryParams: ImportContainerQueryParams;
53
+ };
@@ -0,0 +1,13 @@
1
+ import type { ImportOperation, ImportOperationPagedResponse } from '@commercetools/importapi-sdk';
2
+ export type ImportOperationQueryParams = {
3
+ limit?: number;
4
+ offset?: number;
5
+ state?: string | string[];
6
+ };
7
+ export interface ExtendedImportOperation extends ImportOperation {
8
+ tags?: string[];
9
+ }
10
+ export interface ExtendedImportOperationPagedResponse extends ImportOperationPagedResponse {
11
+ results: ExtendedImportOperation[];
12
+ }
13
+ export declare function assertImportOperationPagedResponse(maybeImportOperationPagedResponse: unknown): asserts maybeImportOperationPagedResponse is ExtendedImportOperationPagedResponse;
@@ -0,0 +1,9 @@
1
+ export declare 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,15 @@
1
+ import type { OperationStates, ImportSummary } from '@commercetools/importapi-sdk';
2
+ interface ExtendedOperationStates extends OperationStates {
3
+ /**
4
+ * The number of resources in the `canceled` state.
5
+ */
6
+ readonly canceled: number;
7
+ /**
8
+ * The number of resources in the `deleted` state.
9
+ */
10
+ readonly deleted: number;
11
+ }
12
+ export interface ExtendedImportSummary extends ImportSummary {
13
+ readonly states: ExtendedOperationStates;
14
+ }
15
+ export { type ExtendedImportSummary as ImportSummary };
@@ -0,0 +1,9 @@
1
+ export * from "./api.js";
2
+ export * from "./basic-error-data-type.js";
3
+ export * from "./export-operation.js";
4
+ export * from "./file-upload.js";
5
+ export * from "./import-container.js";
6
+ export * from "./import-operation.js";
7
+ export * from "./import-states.js";
8
+ export * from "./import-summary.js";
9
+ export * from "./shared.js";
@@ -0,0 +1,7 @@
1
+ export declare function hasOwnProperty<X extends {}, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown>;
2
+ export declare function hasRequiredFields(maybeValidObject: unknown, requiredFields: Array<string>): boolean;
3
+ export declare function getMissingRequiredFields(maybeValidObject: unknown, requiredFields: Array<string>): string[] | false;
4
+ export declare function isError(maybeError: unknown): maybeError is Error;
5
+ export declare function isAbortError(error: unknown): error is DOMException;
6
+ export declare function isResourceType<T extends string>(maybeResourceType: unknown): maybeResourceType is T;
7
+ export declare function assertResourceType<T extends string>(maybeResourceType: unknown): asserts maybeResourceType is T;
@@ -0,0 +1,19 @@
1
+ export declare function getFileUploadErrorsCount(errors?: Array<{
2
+ errors: Array<unknown>;
3
+ }>): number;
4
+ export declare function mapUploadFileErrorsResponseToUploadFileErrorRows(uploadFileErrorsResponse?: Array<{
5
+ row?: number;
6
+ index?: number;
7
+ errors: Array<{
8
+ field: string;
9
+ code: string;
10
+ message: string;
11
+ }>;
12
+ }>): Array<{
13
+ id: string;
14
+ row?: number;
15
+ index?: number;
16
+ field: string;
17
+ code: string;
18
+ validationMessage: string;
19
+ }>;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Convert megabytes to bytes
3
+ */
4
+ export declare const toBytes: (megabytes: number) => number;
5
+ /**
6
+ * Returns the number of rows in a CSV file excluding the header
7
+ * @param file The CSV file to process
8
+ * @returns A promise that resolves to the number of rows
9
+ */
10
+ export declare const getRowCount: (file: File) => Promise<number>;
11
+ /**
12
+ * Check if a CSV file has a single key column
13
+ * @param file The CSV file to check
14
+ * @returns A promise that resolves to true if the file has only one column named 'key'
15
+ */
16
+ export declare const hasSingleKeyColumn: (file: File) => Promise<boolean>;
17
+ /**
18
+ * Validate delimiter in a CSV file
19
+ * @param file The CSV file to validate
20
+ * @param allowedDelimiters Array of allowed delimiters
21
+ * @returns A promise that resolves to false if delimiter is invalid
22
+ */
23
+ export declare const validateDelimiter: (file: File, allowedDelimiters: string[]) => Promise<boolean>;
24
+ /**
25
+ * Returns columns from the provided `columns` excluding those specified in the `ignoredColumns`
26
+ */
27
+ export declare const getValidatedColumns: (columns: string[], ignoredColumns: string[]) => string[];
28
+ /**
29
+ * Count items in a JSON file
30
+ * @param file The JSON file to process
31
+ * @returns Object with isValid flag and optional itemsCount
32
+ */
33
+ export declare const countJsonFileItems: (file: File) => Promise<{
34
+ isValid: false;
35
+ } | {
36
+ isValid: true;
37
+ itemsCount: number;
38
+ }>;
39
+ /**
40
+ * Map file upload errors to upload file error rows with unique IDs
41
+ * @param uploadFileErrors Array of file upload errors
42
+ * @returns Array of upload file errors with unique id field
43
+ */
44
+ export declare const mapFileUploadErrorsToUploadFileErrorRows: <T extends Record<string, unknown>>(uploadFileErrors: T[]) => (T & {
45
+ id: string;
46
+ })[];
@@ -0,0 +1 @@
1
+ export declare const mapFormikErrors: (error: string | string[] | undefined | Record<string, boolean>) => Record<string, boolean>;
@@ -0,0 +1,5 @@
1
+ export declare function formatErrorCode(code: string): string;
2
+ export declare function extractErrorDescriptionFromValidationMessage(message: string): string | undefined;
3
+ export declare function formatKeys(obj: Record<string, unknown>, conjunction?: string): string;
4
+ export declare function appendCsvOrJsonExtensionIfAbsent(fileName: string, fileFormat: 'csv' | 'json'): string;
5
+ export declare function convertFileSizeToKB(sizeInBytes: number): number;
@@ -0,0 +1,8 @@
1
+ export declare const encodeFileNameWithTimestampToContainerKey: (fileName: string) => string;
2
+ /**
3
+ * Check if an import container is a file upload import
4
+ * @param tags - Array of tags from the import container
5
+ * @returns True if the tags indicate this is a file upload import
6
+ */
7
+ export declare const checkIfFileUploadImport: (tags?: string[]) => boolean;
8
+ export declare const decodeFileNameFromImportContainerKey: (importContainerKey: string) => string;
@@ -0,0 +1,6 @@
1
+ export * from "./error-mapping.js";
2
+ export * from "./file-upload.js";
3
+ export * from "./form.js";
4
+ export * from "./format.js";
5
+ export * from "./import-container.js";
6
+ export * from "./url.js";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Formats an object into a URL query string
3
+ * @param queryParams - Object containing query parameters
4
+ * @returns Formatted query string with leading '?' or empty string
5
+ */
6
+ export declare function formatQueryString(queryParams?: Record<string, unknown>): string;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Shared package for operations
3
+ *
4
+ * This package provides shared functionality for import/export operations across:
5
+ * - application-operations
6
+ * - import-resources-modal
7
+ * - export-resources-modal
8
+ * - delete-resources-modal
9
+ * - unpublish-products-modal
10
+ *
11
+ * Public API includes:
12
+ * - Hooks: useImportContainerUpload, useFetch*, etc.
13
+ * - Components: FileDropArea, UploadingModal, UploadSettings, etc.
14
+ * - Utils: File validation, error mapping, formatting, etc.
15
+ * - Constants: Delimiters, upload limits, resource links, etc.
16
+ * - Types: All TypeScript types and interfaces
17
+ * - Errors: Custom error classes
18
+ * - API: Functions for interacting with import/export APIs
19
+ */
20
+ export * from "./@api/index.js";
21
+ export * from "./@components/index.js";
22
+ export * from "./@constants/index.js";
23
+ export * from "./@errors/index.js";
24
+ export * from "./@hooks/index.js";
25
+ export * from "./@types/index.js";
26
+ export * from "./@utils/index.js";
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './src'
@@ -0,0 +1,11 @@
1
+ process.env.ENABLE_NEW_JSX_TRANSFORM = 'true'
2
+
3
+ const basePreset = require('@commercetools-frontend/jest-preset-mc-app/typescript')
4
+
5
+ /** @type {import('jest').Config} */
6
+ const jestPreset = {
7
+ ...basePreset,
8
+ displayName: '@commercetools-frontend-extensions/operations',
9
+ }
10
+
11
+ module.exports = jestPreset
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@commercetools-frontend-extensions/operations",
3
+ "version": "0.0.0",
4
+ "license": "Proprietary",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "main": "dist/commercetools-frontend-extensions-operations.cjs.js",
9
+ "module": "dist/commercetools-frontend-extensions-operations.esm.js",
10
+ "types": "dist/commercetools-frontend-extensions-operations.cjs.d.ts",
11
+ "scripts": {
12
+ "build": "rimraf dist && preconstruct build",
13
+ "test": "jest --config jest.test.config.js",
14
+ "test:watch": "jest --config jest.test.config.js --watch",
15
+ "typecheck": "tsc --noEmit"
16
+ },
17
+ "dependencies": {
18
+ "@babel/core": "^7.21.0",
19
+ "@babel/runtime": "7.28.4",
20
+ "@babel/runtime-corejs3": "7.28.4",
21
+ "@commercetools/importapi-sdk": "5.20.0",
22
+ "papaparse": "5.5.3",
23
+ "pluralize": "8.0.0",
24
+ "react-dropzone": "14.3.8"
25
+ },
26
+ "devDependencies": {
27
+ "@commercetools-frontend/actions-global": "24.9.0",
28
+ "@commercetools-frontend/application-components": "24.9.0",
29
+ "@commercetools-frontend/application-shell": "24.9.0",
30
+ "@commercetools-frontend/application-shell-connectors": "24.9.0",
31
+ "@commercetools-frontend/constants": "24.9.0",
32
+ "@commercetools-frontend/jest-preset-mc-app": "24.9.0",
33
+ "@commercetools-frontend/permissions": "24.9.0",
34
+ "@commercetools-frontend/sentry": "24.9.0",
35
+ "@commercetools-frontend/ui-kit": "20.3.0",
36
+ "@emotion/react": "11.14.0",
37
+ "@emotion/styled": "11.14.1",
38
+ "@testing-library/react": "16.1.0",
39
+ "@types/jest": "29.5.14",
40
+ "@types/papaparse": "5.3.16",
41
+ "@types/pluralize": "0.0.33",
42
+ "@types/react": "19.2.0",
43
+ "msw": "1.3.5",
44
+ "react": "19.2.0",
45
+ "react-intl": "7.1.4",
46
+ "rimraf": "6.0.1",
47
+ "typescript": "5.2.2"
48
+ },
49
+ "peerDependencies": {
50
+ "@commercetools-frontend/actions-global": "23.x || 24.x",
51
+ "@commercetools-frontend/application-components": "23.x || 24.x",
52
+ "@commercetools-frontend/application-shell": "23.x || 24.x",
53
+ "@commercetools-frontend/application-shell-connectors": "23.x || 24.x",
54
+ "@commercetools-frontend/constants": "23.x || 24.x",
55
+ "@commercetools-frontend/permissions": "23.x || 24.x",
56
+ "@commercetools-frontend/sentry": "23.x || 24.x",
57
+ "@commercetools-frontend/ui-kit": "19.x || 20.x",
58
+ "@emotion/react": "11.x",
59
+ "@emotion/styled": "11.x",
60
+ "react": "17.x || 19.x",
61
+ "react-intl": "6.x || 7.x"
62
+ }
63
+ }
@@ -0,0 +1,26 @@
1
+ import { MC_API_PROXY_TARGETS } from '@commercetools-frontend/constants'
2
+ import {
3
+ assertPaginatedExportOperationResponse,
4
+ type PaginatedExportOperationResponse,
5
+ type ExportOperationQueryParams,
6
+ } from '../@types'
7
+ import { fetcher } from './fetcher'
8
+ import { getExportOperationsURL } from './urls'
9
+
10
+ export async function fetchExportOperations({
11
+ projectKey,
12
+ queryParams,
13
+ }: {
14
+ projectKey: string
15
+ queryParams: ExportOperationQueryParams
16
+ }): Promise<PaginatedExportOperationResponse> {
17
+ const exportOperations = await fetcher<PaginatedExportOperationResponse>({
18
+ url: getExportOperationsURL({ projectKey, queryParams }),
19
+ config: {
20
+ proxy: MC_API_PROXY_TARGETS.EXPORT,
21
+ method: 'GET',
22
+ },
23
+ })
24
+ assertPaginatedExportOperationResponse(exportOperations)
25
+ return exportOperations
26
+ }