npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@commercetools-frontend-extensions/operations

v3.6.0

Published

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

Readme

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 unified hook for file uploads that handles both the old flow (import container) and new flow (file import job).

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

Parameters:

  • projectKey (required): The commercetools project key
  • useJobBasedFlow (optional): Whether to use the job-based flow. Default: false
  • pollingInterval (optional): Polling interval in ms for job-based flow. 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 } (job-based flow only)
    • 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 (job-based flow only). 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 (job-based flow only). 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 (job-based flow only)

Usage:

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

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

const abortController = new AbortController()

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

// 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: queuedprocessingvalidatedinitialisingready


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
  }
})