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

@smile/strapi-client

v1.1.0

Published

An HTTP client for Strapi focused on content and media creation (for mass data migration from another CMS/datasource)

Downloads

223

Readme

strapi-client

NPM version

An HTTP client for Strapi focused on content and media creation (for mass data migration from another CMS/datasource).

While other clients may exist, this one is focused on content and media creation with possibility to create Media directories and moving media in directories.

Usage

In your migration project.

Add the dependency

npm i -D @smile/strapi-client

Create an HTTP client instance

import {StrapiClient} from '@smile/strapi-client';
const strapiClient = new StrapiClient('http://127.0.0.1:1337', 'token', 'admin_token');
  • 'token' is an API token that you must create in Strapi. The token must have enough access (e.g.: "Full access") to be able to create the required content.
  • 'admin_token' is optional (for creating media folders and moving media in the Media Library and for publisher plugins) and must be a JWT token (check in your browser local storage after authenticating to Strapi admin). The user associated to that JWT token must have enough rights to manage the Media Library.

Use the API

Examples below are based on FoodAdvisor Strapi demo.

Create an entry

const creationResponse = await strapiClient.createEntry('articles', {
    title: '5 Famous Restaurants You Have to Visit in Paris',
    ckeditor_content: `<div class="entry-content">
<h3>As one of the top food destinations in the world, there’s no shortage of famous restaurants in Paris.</h3>
<p>From historic addresses to those made famous by celebrity diners, here we round up some of the most iconic Paris restaurants that are actually worth a visit.&nbsp;</p>`
});

Create a media

const mediaCreationResponse = await strapiClient.addMediaAsset('https://assets2.devourtours.com/wp-content/uploads/famous-restaurants-in-paris-1.png', 'Some of the most famous restaurants in Paris have gotten quite touristy and aren\'t really worth your time. Here are five that fortunately manage to stay authentic in the face of mass tourism.', 'Photo Credit: Hirama for Tour d’Argent');

Create a media folder

Requires adminToken.

const mediaFolderCreationResponse = await strapiClient.createMediaFolder('Famous restaurants');

Move media to a folder

Requires adminToken.

await strapiClient.moveMedia(mediaFolderCreationResponse.data.id, [mediaCreationResponse[0].id]);

Update an entry

await strapiClient.updateEntry('articles', creationResponse.data.id, {
  publicationState: 'In review',
  image: mediaCreationResponse[0].id
});

Set a publish / unpublish date

Requires:

You first need to tell the Strapi client which plugin you're using with:

strapiClient.configureScheduler('strapi-plugin-publisher');
// Or
strapiClient.configureScheduler('@webbio-strapi-plugin-scheduler');

Then, set a publish date with:

const in10Days = new Date(new Date().setDate(new Date().getDate() + 10));
await strapiClient.addPublishDate('article', creationResponse.data.id, in10Days);

and an unpublish date with:

const in30Days = new Date(new Date().setDate(new Date().getDate() + 30));
await strapiClient.addUnpublishDate('article', creationResponse.data.id, in30Days);