@commercetools-frontend-extensions/operations

中文文档
5.5.0发布于 2026/11/02ProprietaryTypeScriptESM + CJS近 30 天下载 6687
原始使用文档
文档目录11 节
  1. Installation
  2. Hooks
  3. useFileUpload
  4. useFetchImportOperations
  5. useFetchImportSummaries
  6. useFetchImportContainerDetails
  7. useFetchExportOperations
  8. useFetchFileImportJob
  9. useFetchFileImportJobRecords
  10. Helper Functions
  11. Polling Example

Shared operations package

Shared functionality for import/export operations across multiple frontend applications and extensions.

Installation

pnpm add @commercetools-frontend-extensions/operations

Hooks

useFileUpload

A hook for file uploads using the job-based import flow (create container → create file import job → poll until validated).

const { upload, isUploading, progress, validationProgress } = useFileUpload({
  projectKey: string,
  pollingInterval?: number,
  maxPollingAttempts?: number
})

Parameters:

  • projectKey (required): The commercetools project key
  • pollingInterval (optional): Polling interval in ms. Default: 5000
  • maxPollingAttempts (optional): Maximum polling attempts. Default: 200

Returns:

  • upload - Function to start the upload
  • isUploading - Whether upload is in progress
  • progress - Upload progress (0-100)
  • validationProgress - { processed: number, isValidating: boolean }
    • processed: Number of resources validated so far (from backend)
    • isValidating: Whether validation is in progress

Upload config options:

  • file (required): The file to upload
  • resourceType (required): The resource type
  • fileType (optional): File type ('csv' or 'json') sent to the API.
  • settings (optional): Import settings (format, decimal separator...)
  • autoProcess (optional): When true, the backend automatically starts processing after validation completes. Default: false
  • 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. Default: false
  • abortSignal (optional): AbortSignal for cancellation
  • onSuccess (required): Callback when upload completes
  • onError (optional): Callback for errors
  • onProgress (optional): Callback for upload progress (0-100)
  • onValidationProgress (optional): Callback for validation progress

Usage:

import { useFileUpload } from '@commercetools-frontend-extensions/operations'

const { upload, isUploading, progress, validationProgress } = useFileUpload({
  projectKey,
})

const abortController = new AbortController()

await upload({
  file: File,
  resourceType: 'product' | 'category' | ...,
  fileType?: 'csv' | 'json', // override derived file type
  settings?: {
    format?: 'CSV' | 'JSON',
    decimalSeparator?: '.' | ',',
    resourceType?: 'product-draft' | 'category' | ...,
    options?: {
      publishAllChanges?: boolean,
      unpublishAllChanges?: boolean
    }
  },
  autoProcess?: boolean, // default: false
  skipValidationPolling?: boolean, // default: false
  abortSignal: abortController.signal,
  onSuccess: (result) => {
    // result.containerKey - Import container key
    // result.summary - { total, valid, invalid, fields, ignoredFields, results }
    // result.jobId - Job ID
    // result.job - Full job object
  },
  onError: (error) => { /* ... */ },
  onProgress: (progress) => { /* 0-100 */ },
  onValidationProgress: (job) => { /* ... */ }
})

// To cancel:
abortController.abort()

useFetchImportOperations

Fetches import operations for a container with optional polling.

const { data, error, isLoading, refetch } = useFetchImportOperations({
  projectKey,
  importContainerKey,
  queryParams?: { limit, offset, ... },
  pollingInterval?: number,
  shouldContinuePolling?: (data) => boolean
})

useFetchImportSummaries

Fetches import summaries (containers) with optional polling.

const { data, error, isLoading, refetch } = useFetchImportSummaries({
  projectKey,
  queryParams?: { limit, offset, states, ... },
  pollingInterval?: number,
  shouldContinuePolling?: (data) => boolean
})

useFetchImportContainerDetails

Fetches details for a specific import container.

const { data, error, isLoading, refetch } = useFetchImportContainerDetails({
  projectKey,
  importContainerKey,
  pollingInterval?: number,
  shouldContinuePolling?: (data) => boolean
})

useFetchExportOperations

Fetches export operations with optional polling.

const { data, error, isLoading, refetch } = useFetchExportOperations({
  projectKey,
  queryParams?: { limit, offset, resourceTypes, ... },
  pollingInterval?: number,
  shouldContinuePolling?: (data) => boolean
})

useFetchFileImportJob

Polls a File Import Job for status updates.

const { data, error, isLoading, refetch } = useFetchFileImportJob({
  projectKey,
  importContainerKey,
  jobId,
  pollingInterval?: number,
  shouldContinuePolling?: (job) => boolean
})

Job states: queued → processing → validated → initializing → ready


useFetchFileImportJobRecords

Fetches records (errors or valid entries) from a File Import Job with pagination support. Keeps previous data visible while loading new pages.

const { data, error, isLoading, refetch } = useFetchFileImportJobRecords({
  projectKey,
  importContainerKey,
  jobId,
  limit?: number,
  offset?: number,
  isValid?: boolean,
  skip?: boolean
})

Parameters:

  • projectKey: The commercetools project key
  • importContainerKey: The import container key
  • jobId: The file import job ID
  • limit (optional): Number of records to fetch per page
  • offset (optional): Offset for pagination
  • isValid (optional): Filter by valid (true) or invalid (false) records
  • skip (optional): Skip fetching (useful for conditional fetching)

Returns:

  • data - { results, total, limit, offset, count } or null
  • error - Error object if fetch failed
  • isLoading - Whether fetch is in progress
  • refetch - Function to manually trigger a refetch

Usage example (paginated error table):

const pagination = usePaginationState()
const offset = (pagination.page.value - 1) * pagination.perPage.value

const { data, isLoading } = useFetchFileImportJobRecords({
  projectKey,
  importContainerKey: containerKey,
  jobId,
  offset,
  limit: pagination.perPage.value,
  isValid: false, // Fetch only invalid records (errors)
})


Helper Functions

import {
  isImportJobQueued,
  isImportJobProcessing,
  isImportJobValidated,
  isImportJobInitializing,
  isImportJobReady,
  shouldContinuePollingForImportValidation
} from '@commercetools-frontend-extensions/operations'

Polling Example

const { data, isLoading } = useFetchImportOperations({
  projectKey,
  importContainerKey,
  pollingInterval: 5000,
  shouldContinuePolling: (data) => {
    return data?.results?.some(op => op.state === 'processing') ?? false
  }
})

版本与发布记录

@commercetools-frontend-extensions/operations 共发布 110 个版本,首次发布于 2025/11/24;过去 12 个月发布了 110 个版本。

版本发布日期距今
5.5.0latest2026/11/028 天前
5.4.12026/10/2120 天前
5.4.02026/10/1922 天前
5.3.22026/10/021 个月前
5.3.12026/09/301 个月前
5.3.02026/09/291 个月前

其他发布通道:canary → 0.0.0-canary-20260918105445。

关于 @commercetools-frontend-extensions/operations 的常见问题

如何安装 @commercetools-frontend-extensions/operations?

在项目目录运行 npm install @commercetools-frontend-extensions/operations,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(17.x || 19.x)、react-intl(6.x || 7.x)、@emotion/react(11.x)、@emotion/styled(11.x)、@commercetools-frontend/i18n(24.x || 25.x || 27.x)、@commercetools-frontend/sentry(24.x || 25.x || 27.x)、@commercetools-frontend/ui-kit(19.x || 20.x)、@commercetools-frontend/constants(24.x || 25.x || 27.x)、@commercetools-frontend/fullstory(2.x || 3.x || 4.x)、@commercetools-frontend/permissions(24.x || 25.x || 27.x)、@commercetools-frontend/actions-global(24.x || 25.x || 27.x)、@commercetools-frontend/application-shell(24.x || 25.x || 27.x)、@commercetools-frontend/application-components(24.x || 25.x || 27.x)、@commercetools-frontend/application-shell-connectors(24.x || 25.x || 27.x)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@commercetools-frontend-extensions/operations 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@commercetools-frontend-extensions/operations 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@commercetools-frontend-extensions/operations 可以商用吗?

@commercetools-frontend-extensions/operations 使用 Proprietary 许可。声明的许可为 Proprietary,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@commercetools-frontend-extensions/operations 的下载量有多少?

根据 npm 官方下载统计,@commercetools-frontend-extensions/operations 在 2026/10/11 – 2026/11/09 这 30 天内被下载 6,687 次,日均约 223 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@commercetools-frontend-extensions/operations 还在维护吗?

最新版本 5.5.0 发布于 2026/11/02(8 天前);至今共发布 110 个版本,其中过去 12 个月发布了 110 个;首次发布于 2025/11/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。