Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@sanity/export
Advanced tools
@sanity/export is a utility for exporting data from a Sanity.io dataset. It allows you to export documents, assets, and other data from your Sanity project into a JSON file, which can be useful for backups, migrations, or transferring data between projects.
Exporting all documents
This feature allows you to export all documents from a specified dataset in your Sanity project. The exported data is saved to a JSON file.
const sanityClient = require('@sanity/client');
const exportDataset = require('@sanity/export');
const client = sanityClient({
projectId: 'your-project-id',
dataset: 'your-dataset-name',
token: 'your-auth-token',
useCdn: false
});
const options = {
outputPath: './exported-data.json',
dataset: 'your-dataset-name',
client: client
};
exportDataset(options).then(() => {
console.log('Export complete!');
}).catch((err) => {
console.error('Export failed:', err);
});
Exporting specific document types
This feature allows you to export only specific types of documents from your dataset. In this example, only documents of type 'post' and 'author' are exported.
const sanityClient = require('@sanity/client');
const exportDataset = require('@sanity/export');
const client = sanityClient({
projectId: 'your-project-id',
dataset: 'your-dataset-name',
token: 'your-auth-token',
useCdn: false
});
const options = {
outputPath: './exported-data.json',
dataset: 'your-dataset-name',
client: client,
types: ['post', 'author']
};
exportDataset(options).then(() => {
console.log('Export complete!');
}).catch((err) => {
console.error('Export failed:', err);
});
Exporting with a query
This feature allows you to export documents based on a specific query. In this example, only published posts are exported.
const sanityClient = require('@sanity/client');
const exportDataset = require('@sanity/export');
const client = sanityClient({
projectId: 'your-project-id',
dataset: 'your-dataset-name',
token: 'your-auth-token',
useCdn: false
});
const options = {
outputPath: './exported-data.json',
dataset: 'your-dataset-name',
client: client,
query: '*[_type == "post" && published == true]'
};
exportDataset(options).then(() => {
console.log('Export complete!');
}).catch((err) => {
console.error('Export failed:', err);
});
contentful-export is a utility for exporting data from a Contentful space. It allows you to export content types, entries, assets, and locales into a JSON file. Similar to @sanity/export, it is used for backups, migrations, and data transfers. However, it is specific to Contentful, whereas @sanity/export is specific to Sanity.io.
strapi-plugin-import-export-content is a plugin for Strapi that allows you to import and export content types, entries, and assets. It provides similar functionality to @sanity/export but is designed for use with Strapi, a different headless CMS.
Exports documents and assets from a Sanity dataset
npm install --save @sanity/export
const exportDataset = require('@sanity/export')
exportDataset({
// Instance of @sanity/client configured to correct project ID and dataset
client: someInstantiatedSanityClientInstance,
// Name of dataset to export
dataset: 'myDataset',
// Path to write tar.gz-archive file to, or `-` for stdout
outputPath: '/home/your-user/myDataset.tar.gz',
// Whether or not to export assets. Note that this operation is currently slightly lossy;
// metadata stored on the asset document itself (original filename, for instance) might be lost
// Default: `true`
assets: false,
// Exports documents only, without downloading or rewriting asset references
// Default: `false`
raw: true,
// Whether or not to export drafts
// Default: `true`
drafts: true,
// Export only given document types (`_type`)
// Optional, default: all types
types: ['products', 'shops'],
// Run 12 concurrent asset downloads
assetConcurrency: 12
})
filename (<num>).ext
)This functionality is built in to the @sanity/cli
package as sanity dataset export
MIT-licensed. See LICENSE.
FAQs
Export Sanity documents and assets
The npm package @sanity/export receives a total of 75,021 weekly downloads. As such, @sanity/export popularity was classified as popular.
We found that @sanity/export demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 55 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.