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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@jwork-space/strapi-sdk

v1.0.6

Published

SDK para Strapi con soporte para React Query y TypeScript

Readme

@jwork-space/strapi-sdk

SDK para Strapi con soporte completo para TypeScript y React Query.
Permite realizar operaciones CRUD, manejar paginación, relaciones y personalizar requests fácilmente.


Instalación

# Usando pnpm
pnpm add @jwork-space/strapi-sdk

# Usando npm
npm install @jwork-space/strapi-sdk

Importación

import {
  StrapiSDK,
  type PaginationResponse,
  type RequestOptions,
  type SerializeOptions,
  type StrapiConfig,
} from "@jwork-space/strapi-sdk";

Definición de las interfaces

Para definir las interfaces de tus modelos, puedes usar los autocompletados de TypeScript de los populate y filters:

interface Section {
  id: number;
  name: string;
}

interface Category {
  id: number;
  name: string;
}

interface Stock {
  id: number;
  name: string;
  section?: Section | null;
}

interface Product {
  id: number;
  name: string;
  description?: string;
  price: number;
  category?: Category[] | null;
  stocks?: Stock | null;
}

Configuración básica

Antes de usar el SDK, puedes configurar los parámetros de conexión y comportamiento:

const productStrapiApiConfig: StrapiConfig = {
  /* set only in case of no user proxy */
  baseURL: "http://localhost:1337",
  /* on case use proxy prefix */
  prefix:
    "strapi-api-v2" /* ouput: http://localhost:1337/strapi-api-v2/api/products */,
  /* in case of use uid on create model product */
  onCreate: {
    generateUID: false,
    keyUID: "strapiUID",
  },
  /* default jwr */
  tokenKey: "jwt-strapi",
  /* default on save/update/list-all { body: { data } } */
  wrapBodyInData: false,
  /* remember that is use on response list */
  transformResponse: false,
  /* page size por default when user method listAll, default 15 */
  pageSize: 40,
  defaultQueriesInvalidations: {
    /* default this model (products), buy you can add others: example ['users', 'stocks'] */
    destroy: ["stocks"],
    update: ["stocks"],
    save: ["stocks"],
  },
};

Ejemplo básico de uso

export const productAPI = new StrapiSDK<Product>(
  "products",
  productStrapiApiConfig
);

/* example usave method */

const requestOptions: RequestOptions<Product> = {
  /* default sort by id:desc */
  sort: "createdAt:desc",
  fields: ["id", "name", "price"],
  populate: {
    category: true,
    stocks: {
      populate: {
        section: true,
      },
      filters: {
        section: {
          id: {
            $eq: 1,
          },
        },
      },
    },
  },
};

export const exampleUsage = async () => {
  const id = 1;

  /* retornar lista de productos paginados */
  const { data: _data, pagination: _pagination } = await productAPI.listAll(
    requestOptions
  );
  
  /* retornar todos de productos de la base de datos y sin paginación */
  const { data: _data, pagination: _pagination } = await productAPI.getAllData(
    requestOptions
  );

  const requestOptionsOnActions: RequestOptions<Product> = {
    populate: {
      category: true,
      stocks: {
        populate: {
          section: true,
        },
      },
    },
  };

  const serializeOptionsOnSaveAndUpdate: SerializeOptions = {
    onlyIdForRelations: true,
    preserveRelations: ["stocks"],
  };

  const _productSaved = await productAPI.save(
    {
      id: 0 /* use cero for create new */,
      name: "product-name",
      description: "product-description",
      price: 100,
      category: [{ id: 1, name: "category-name" }],
      stocks: { id: 1, name: "stock-name" },
    },
    requestOptionsOnActions,
    serializeOptionsOnSaveAndUpdate
  );

  const _productUpdated = await productAPI.update(
    id,
    {
      id,
      name: "product-name",
      description: "product-description",
      price: 100,
      category: [{ id: 1, name: "category-name" }],
      stocks: { id: 1, name: "stock-name" },
    },
    requestOptionsOnActions,
    serializeOptionsOnSaveAndUpdate
  );

  /* return boolean */
  const hasDeleted = await productAPI.destroy(id);
};

Ejemplo extendido: Métodos personalizados

Puedes extender el SDK para agregar métodos custom o sobreescribir los existentes:

/* example extends SDK Methods */
class ProductAPI extends StrapiSDK<Product> {
  constructor() {
    super("products", productStrapiApiConfig);
  }

  /* override default method */
  listAll = async (options?: RequestOptions<Product>) => {
    /* raw response type return:
    data: Product[]
      pagination: {
        page: number
        pageSize: number
        total: number
        totalPages: number
        nextPage: number
        prevPage: number
      }
    */
    return await this.getCall<PaginationResponse<Product>>("products", options);
  };

  /* exmplay override method save */
  save = async (
    entity: Product,
    requestOptions?: RequestOptions<Product>,
    serializeOptions?: SerializeOptions
  ): Promise<Product> => {
    /* or set your own settings to create */
    if (!entity.id) {
      entity.name = `NEW-${entity.name}`;
    }
    // Llamamos al save original
    return await this.save(entity, requestOptions, serializeOptions);
  };

  /* exmplay create method save custom */
  saveCustom = async (
    entity: Product,
    requestOptions?: RequestOptions<Product>,
    serializeOptions?: SerializeOptions
  ): Promise<Product> => {
    /* or set your own settings to create */
    if (!entity.id) {
      entity.category = [{ id: 1, name: "category-name" }];
      entity.name = `NEW-${entity.name}`;
    }
    /* you can use methods hhtp */
    /* example */
    return await this.postCall<Product>("products", {
      /* auth default true, (if is false, no send token to backend) */
      auth: false,
      body: entity,
      headers: {
        "Content-Type": "application/json",
        Accept: "application/json",
        /* on case no use default token */
        "Bearer token": "your-token",
      },
      responseType: "json", // default json || 'blob'
      query: {
        extraQuery: {
          "your-query-key": "your-query-value",
        },
      },
    });
    // Llamamos al save original
    return await this.save(entity, requestOptions, serializeOptions);
  };

  /* new method  */
  listAllCustom = async (options?: RequestOptions<Product>) => {
    /* raw response type return:
    data: Product[]
    meta: {
      pagination: {
        page: number
        pageSize: number
        total: number
        totalPages: number
        nextPage: number
        prevPage: number
      }
    }
    */

    /* the options can be the that  */
    return await this.getCall<PaginationResponse<Product>>("products", options);
  };
}

export const productAPIExtended = new ProductAPI();

/* example usage methods SDK Methods Custom */
await productAPIExtended.listAll();
await productAPIExtended.saveCustom({
  id: 0,
  name: "product-name",
  price: 100,
});