Registry / crm-productivity / contentful-batch-libs

contentful-batch-libs

JSON →
library11.0.0jsnpmunverified

This library provides core modules and shared methods utilized by Contentful's batch utility CLI tools, specifically for `contentful-import` and `contentful-export`. It offers low-level programmatic access to operations such as getting source content from a space, pushing changes (including deletions, creations, and publishing/unpublishing) to a destination space, and various content transformations. It also includes utilities for creating Contentful clients and error handling. The current stable version is 11.0.0. The project uses `semantic-release`, indicating a release cadence of frequent patch/minor versions and major versions only for breaking changes. Its key differentiator lies in providing granular, batch-oriented control over Contentful space manipulation, acting as a foundational layer for more complex data migration and synchronization workflows between Contentful environments.

npm install contentful-batch-libs
INSTALL
IMPORT
SIG · CONTENTFUL-BATCH-L
C
contentful-batch-libs
crm-productivityjavascriptv11.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createClients
import { createClients } from 'contentful-batch-libs';
const { createClients } = require('contentful-batch-libs');
The library is primarily designed for ESM usage since v11 due to Node.js v22+ requirement, though older versions might have supported CommonJS.
getSourceSpace
import { getSourceSpace } from 'contentful-batch-libs';
Used to retrieve content from a Contentful space for further manipulation or copying.
pushToSpace
import { pushToSpace } from 'contentful-batch-libs';
This function is central for applying batch changes, including creations, updates, deletions, and publishing, to a target Contentful space.

This quickstart demonstrates how to initialize Contentful clients, fetch all content from a source space, and then push that content (or transformed content) back to a target space using `contentful-batch-libs`.

import { createClients, getSourceSpace, pushToSpace } from 'contentful-batch-libs'; const SPACE_ID = process.env.CONTENTFUL_SOURCE_SPACE_ID ?? ''; const MANAGEMENT_TOKEN = process.env.CONTENTFUL_MANAGEMENT_TOKEN ?? ''; const DELIVERY_TOKEN = process.env.CONTENTFUL_DELIVERY_TOKEN ?? ''; const ENVIRONMENT_ID = process.env.CONTENTFUL_ENVIRONMENT_ID ?? 'master'; if (!SPACE_ID || !MANAGEMENT_TOKEN || !DELIVERY_TOKEN) { console.error('Environment variables CONTENTFUL_SOURCE_SPACE_ID, CONTENTFUL_MANAGEMENT_TOKEN, and CONTENTFUL_DELIVERY_TOKEN must be set.'); process.exit(1); } async function runBatchOperation() { try { // 1. Create Contentful client instances const { managementClient, deliveryClient } = createClients({ spaceId: SPACE_ID, managementToken: MANAGEMENT_TOKEN, accessToken: DELIVERY_TOKEN, environmentId: ENVIRONMENT_ID, }); console.log('Contentful clients created successfully.'); // 2. Get content from the source space console.log(`Fetching content from space '${SPACE_ID}'...`); const sourceContent = await getSourceSpace({ managementClient, deliveryClient, spaceId: SPACE_ID, environmentId: ENVIRONMENT_ID, // You might want to specify content types, entries, assets, etc. to fetch // For example: query: { 'content_type': 'blogPost' } }); console.log(`Fetched ${sourceContent.entries.length} entries and ${sourceContent.assets.length} assets.`); // 3. (Optional) Transform content here if needed // const transformedContent = transformSpace(sourceContent, /* transformers */); // 4. Push transformed or original content to a destination space (example uses the same space ID for simplicity) // In a real scenario, you'd likely have a separate destination space ID and clients. console.log(`Pushing content back to space '${SPACE_ID}'...`); await pushToSpace({ sourceContent, managementClient, spaceId: SPACE_ID, environmentId: ENVIRONMENT_ID, // Optional: publish: false, contentModelOnly: true, etc. }); console.log('Batch operation completed successfully.'); } catch (error) { console.error('An error occurred during the batch operation:', error); process.exit(1); } } runBatchOperation();
Debug
Known issues
breakingNode.js versions older than 22 are no longer supported. The `engines.node` minimum has been raised to `>=22` starting with v11.0.0. Ensure your runtime environment meets this requirement before upgrading.
fix
Upgrade your Node.js environment to version 22 or higher. For example, use `nvm install 22 && nvm use 22`.
affects: >=11.0.0
breakingVersion `v10.1.7` contained the Node.js 22 breaking change but was mistakenly released as a patch version. It should have been a major release. This was corrected in `v11.0.0`. Do not upgrade directly from `v10.1.6` to `v10.1.7` without verifying Node.js version.
fix
Avoid `v10.1.7`. Upgrade directly to `v11.0.0` or later, ensuring Node.js `>=22` is in use.
affects: 10.1.7
gotchaThis library is primarily designed for ESM (ECMAScript Module) usage, especially from v11 onwards, aligning with modern Node.js practices. Attempting to `require()` it in a CommonJS context without proper transpilation or configuration can lead to import errors.
fix
Use ESM `import` statements (e.g., `import { createClients } from 'contentful-batch-libs';`) in an environment configured for ESM (e.g., `"type": "module"` in `package.json` for Node.js projects).
affects: >=11.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module ... from ... not supported.
Attempting to use `require()` to import a module from `contentful-batch-libs` in a CommonJS context when the library is published as an ESM module.
fix
Convert your project or the specific file to use ESM imports: `import { createClients } from 'contentful-batch-libs';`. Ensure your `package.json` has `"type": "module"` if running in Node.js, or use a bundler that handles ESM correctly.
Error: Node.js vX.Y.Z is not supported. Please upgrade to Node.js >=22.
Running `contentful-batch-libs` on a Node.js version older than the minimum required version (Node.js 22+ since v11.0.0).
fix
Upgrade your Node.js installation to version 22 or newer. Use a tool like `nvm` to manage Node.js versions: `nvm install 22 && nvm use 22`.
Upgrade
Version history
11.0.0latest on npm
Audit
Dependencies
contentful-managementrequiredRequired for programmatic interaction with the Contentful Management API to perform batch operations.
contentfulrequiredRequired for programmatic interaction with the Contentful Delivery API.
Agent activity
42 hits · last 30 days
node
38
OpenAI (training)
1
Resources
contentful-batch-libs — npm install contentful-batch-libs · libregistry