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/import
Advanced tools
@sanity/import is an npm package designed to facilitate the import of data into a Sanity.io dataset. It allows users to import documents and assets from various sources, making it easier to manage and migrate content within the Sanity content platform.
Import JSON Data
This feature allows you to import JSON data into a specified Sanity dataset. The code sample demonstrates how to read a JSON file and import its contents into Sanity using the @sanity/import package.
const sanityImport = require('@sanity/import');
const fs = require('fs');
const inputStream = fs.createReadStream('path/to/your/data.json');
const options = {
dataset: 'your-dataset-name',
projectId: 'your-project-id',
token: 'your-auth-token',
assetConcurrency: 3,
operation: 'createOrReplace'
};
sanityImport(inputStream, options).then(() => {
console.log('Data import completed!');
}).catch((err) => {
console.error('Import failed: ', err);
});
Import Assets
This feature allows you to import assets (e.g., images, files) into a specified Sanity dataset. The code sample demonstrates how to read a ZIP file containing assets and import them into Sanity using the @sanity/import package.
const sanityImport = require('@sanity/import');
const fs = require('fs');
const inputStream = fs.createReadStream('path/to/your/assets.zip');
const options = {
dataset: 'your-dataset-name',
projectId: 'your-project-id',
token: 'your-auth-token',
assetConcurrency: 3,
operation: 'createOrReplace'
};
sanityImport(inputStream, options).then(() => {
console.log('Assets import completed!');
}).catch((err) => {
console.error('Import failed: ', err);
});
The contentful-import package is used to import data into Contentful, a content management system similar to Sanity. It allows users to import content types, entries, and assets into a Contentful space. Compared to @sanity/import, contentful-import is specific to the Contentful platform and offers similar functionalities for data migration and content management.
Imports documents from an ndjson-stream to a Sanity dataset
npm install --save @sanity/import
const fs = require('fs')
const sanityClient = require('@sanity/client')
const sanityImport = require('@sanity/import')
const client = sanityClient({
projectId: '<your project id>',
dataset: '<your target dataset>',
token: '<token-with-write-perms>',
useCdn: false
})
// Input can either be a stream or an array of documents
const input = fs.createReadStream('my-documents.ndjson')
sanityImport(input, {
client: client,
operation: 'create', // `create`, `createOrReplace` or `createIfNotExists`
}).then(numDocs => {
console.log('Imported %d documents', numDocs)
}).catch(err => {
console.error('Import failed: %s', err.message)
})
This functionality is built in to the @sanity/cli
package as well as a standalone @sanity/import-cli package.
MIT-licensed. See LICENSE.
FAQs
Import documents to a Sanity dataset
The npm package @sanity/import receives a total of 84,807 weekly downloads. As such, @sanity/import popularity was classified as popular.
We found that @sanity/import demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 61 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.