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

strapi-js

v2.1.0

Published

A nodejs/browser/edge javascript SDK for Strapi headless CMS; type-safe with typescript.

Downloads

51

Readme

strapi-js

Build package.json version (main branch) npm Codecov

A nodejs/browser typescript/javascript sdk for Strapi headless CMS. You can use it to communicate with Strapi-CMS in client-side applications (such as a Vue.js SPA) or server-side applications (such as an SSR server like Nuxt or other NodeJs based applications).

Features

  • 📦 TypeScript & Fully Typed APIs
  • ✔️ based on Ofetch and Works with Node.js / Browser / Edge
  • ⚡️ Fast Build System Vite, pnpm, esbuild
  • ⚙️ Unit Testing with Vitest and high test coverage.

🚀 Quick Start

Install:

# npm
npm i strapi-js

# pnpm
pnpm add strapi-js

# yarn
yarn add strapi-js

Import & Simple Usage:

import { newStrapiSdk } from 'strapi-js'
// CommonJS: const { newStrapiSdk } = require('strapi-js')

// Usage: 1) provide config (the default configuration)
const config = {
  url: 'http://localhost:1337/',
  prefix: '/api',
  version: 'v4',
  logType: 'auto',
  retry: 0, // Number of auto retries for requests that have encountered an error
}

// Usage: 2) obtain sdk instance
const sdk = newStrapiSdk (config)

// Usage: 3) use it
const { user, jwt } = sdk.auth.login ({
  identifier: '[email protected]',
  password: 'pass123'
})

sdk.auth.changePassword({
  currentPassword: 'pass123',
  password: 'pass123456',
  passwordConfirmation: 'pass123456'
})

Docs

Auth Sdk

This sdk i.e. sdk.auth contains APIs of Strapi related to path /api/auth for login, register, change-pass etc:

  • login: login into strapi providing identifier (username/email) and password
  • register: registers new user providing username, email and password
  • emailConfirmation: confirms user's account with confirmation code
  • sendEmailConfirmation: resends the activation email
  • changePassword: changes user's password providing jwt-token, current-password and new-password
  • forgotPassword: initiates a password reset request for a user's account using a registered email address
  • resetPassword: sets new password using a code received with email
  • utilGetCurrentUser: a utility function to get logged-in user info using the jwt-token (equal to sdk.users.me())

Users Sdk

This sdk i.e. sdk.users contains APIs of Strapi related to path /api/users for getting and setting users:

  • me: gets logged-in user's info using the jwt-token
  • getUsers: gets a list of registered users
  • getUserById: gets user's data by user's id
  • updateUserById: updates user's data by user's id
  • deleteUserById: deletes a user by user's id

Upload Sdk

This sdk i.e. sdk.upload contains APIs of Strapi related to path /api/upload for working with files/media:

  • upload: uploads a file and simultaneously links it to a field in an entity
  • getFiles: gets a list of uploaded files
  • getFileById: gets details of a file using the file's id
  • deleteFileById: deletes a file using the file's id

Content Sdk (Collection Type)

This sdk i.e. sdk.content contains APIs of Strapi related to path /api/:pluralApiId and /api/:pluralApiId/:documentId for working with collection type:

  • find: gets a list of entries stored in this pluralApiId.
  • create: creates a new entry.
  • fineOne: gets details of an entry using the entry's id
  • update: updates details of an entry using the entry's id
  • deleteFileById: deletes an entry using the entry's id