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 🙏

© 2024 – Pkg Stats / Ryan Hefner

payload-plugin-import-export

v0.1.1

Published

Payload CMS plugin to export and import data from csv and json files

Downloads

554

Readme

Payload Plugin Import / Export

A plugin for Payload CMS to import and export JSON and CSV files. You can use this to change data for many records e.g. translate content... from collections.

All parsing and transformations are done on the client keeping the load from the server.

Installation

npm i "payload-plugin-import-export"
yarn add "payload-plugin-import-export"
pnpm add "payload-plugin-import-export"
import importExportPlugin  from 'payload-plugin-import-export';
import type { User } from "payload/generated-types";

export const config = buildConfig({
  serverUrl: process.env.PAYLOAD_PUBLIC_SERVER_URL //Required!
  plugins: [
    importExportPlugin({
      enabled: true,
      excludeCollections: ["users"],
      redirectAfterImport: true,
      // import User type from your payload-types.ts
      canImport: (user:User) => user.roles.includes("admin")
    }),
  ]
});

Config

| PROP | TYPE | DEFAULT | DESCRIPTION | |---------------------|----------------------------|-------------|-----------------------------------------------------| | enabled | boolean | true | Enable/disable plugin | | excludeCollections | string[] | undefined | List of collection slugs to not display the buttons | | redirectAfterImport | boolean | true | Redirect back to collection after import | | canImport | (user:unknown) => boolean | () => true | Restrict access to import. You have access to the user. |

How to use

Update data or create new items - and you can download csv or json with the failed items. Items fail usually due to permission issues or that required fields are not set.

Selecting fields

On import and export you can select fields.

Filter and sorting exports

The filters set on the collections will also be used for exporting items.

Access control

This plugin obeys all access control rules, so exports will only include the fields with read access. On import missing permission on field level will not result in an error. The fields will just be ignored.

Localization

If localization is configured imports and export will be done in current selected locale. Caution: If field is not localized the "global" value will be overwritten.

File formats

JSON

When importing / exporting JSON the data will be shaped like via the REST API.

CSV

For CSV exports the data will be "flattened" for any field type which contains nested data (arrays,rows,tabs). e.g.:

[{
  "id": "65e",
  "title": "Foo",
  "array": [
    {
      "title_array": "Bar",
    },
    {
      "title_array": "Baz",
    },
  ],
  "tab": {
      "title_tab": "Boz",
  },
}]

will become |id|title|array.0.title_array|array.1.title_array|tab.title_tab| |--|-----|-------------------|-------------------|-------------| |65e|Foo|Bar|Baz|Boz|

When importing the data will get "unflattened". Make sure to not change any header names.

License

MIT