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

@cbm-common/item-repository

v0.0.1

Published

This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 20.1.0.

Readme

ItemRepository

This project was generated using Angular CLI version 20.1.0.

Code scaffolding

Angular CLI includes powerful code scaffolding tools. To generate a new component, run:

ng generate component component-name

For a complete list of available schematics (such as components, directives, or pipes), run:

ng generate --help

Building

To build the library, run:

Cbm Item Repository — Documentación (español)

Descripción

item-repository es una librería Angular que proporciona un cliente HTTP tipado para el recurso "Item" de la API del sistema. Exporta un módulo de configuración, una implementación de servicio con todas las operaciones REST comunes y un repositorio inyectable que actúa como fachada (adapter) para el servicio.

Visión general de los artefactos públicos

  • CbmItemModule — Módulo para configurar la librería mediante forRoot(config) (inyecta configuración como token ITEM_MODULE_CONFIG).
  • CbmItemService — Servicio que implementa la lógica HTTP (proporcionado en root).
  • CbmItemRepository — Wrapper/injectable que expone la interfaz ICbmItemRepository y delega al servicio.
  • CbmItemModel — Namespace con tipos y modelos TypeScript usados por el servicio y repositorio.

Instalación / integración

  1. Añade la librería al proyecto (si la publicas en npm) o configura tsconfig.paths para resolverla localmente (ej.: "item-repository": ["./dist/item-repository", "projects/item-repository/src/public-api.ts"]).

  2. Registrar la configuración del módulo en tu aplicación (ejemplo en AppModule):

// app.module.ts (fragmento)
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
import { CbmItemModule } from 'item-repository';

@NgModule({
   imports: [BrowserModule, HttpClientModule],
   providers: [
      // Registrar configuración global para la librería
      CbmItemModule.forRoot({ baseUrl: 'https://api.example.com/items' }),
   ],
})
export class AppModule {}

Nota: CbmItemModule.forRoot devuelve un Provider que se añade normalmente al arreglo providers del módulo raíz.

Uso básico en componentes o servicios

La librería expone el repositorio inyectable CbmItemRepository que implementa ICbmItemRepository. Ejemplo de uso en un componente:

import { Component, OnInit, DestroyRef, signal } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { firstValueFrom } from 'rxjs';
import { CbmItemRepository, CbmItemModel } from 'item-repository';

@Component({/* ... */})
export class MiComponente implements OnInit {
   constructor(private repo: CbmItemRepository, private destroyRef: DestroyRef) {}

   listData = signal<CbmItemModel.ListResponse | {}>({});

   async ngOnInit() {
      const list$ = this.repo.list({ page: 1, size: 20 }).pipe(takeUntilDestroyed(this.destroyRef));
      const res = await firstValueFrom(list$);
      this.listData.set(res);
   }
}

API principal (métodos expuestos)

Todas las firmas usan tipos declarados en CbmItemModel.

  • list(params: CbmItemModel.ListParams): Observable<CbmItemModel.ListResponse>

    • Recupera una lista paginada de items.
  • getOne(id: string): Observable<CbmItemModel.GetOneResponse>

    • Obtiene un item por su id.
  • getOneByCode(code: string): Observable<CbmItemModel.GetOneByCodeResponse>

    • Obtiene un item por su código.
  • save(data: CbmItemModel.SaveBody): Observable<CbmItemModel.ConfirmResponse>

    • Crea un nuevo item.
  • update(id: string, data: CbmItemModel.UpdateBody): Observable<CbmItemModel.ConfirmResponse>

    • Actualiza un item existente.
  • changeStatus(id: string, data: CbmItemModel.ChangeStatusBody): Observable<CbmItemModel.ConfirmResponse>

    • Cambia el estado (habilitado/deshabilitado) de un item.
  • delete(id: string): Observable<CbmItemModel.ConfirmResponse>

    • Elimina un item.
  • downloadExcelCreateTemplate(): Observable<HttpResponse>

    • Descarga plantilla Excel para creación masiva.
  • importExcelCreate(formData: FormData): Observable<HttpResponse>

    • Importa un Excel para crear items en lote.
  • listWithStock(params: CbmItemModel.ListWithStockParams): Observable<CbmItemModel.ListWithStockResponse>

    • Lista items incluyendo información de stock (input-output).
  • refreshStock(params: CbmItemModel.RefreshStockParams.Warehouse, request: CbmItemModel.RefreshStockParams.ItemsId): Observable<CbmItemModel.RefreshStockResponse>

    • Refresca stock en bloque para un almacén y conjunto de items.
  • validate(id: string): Observable<CbmItemModel.ResponseValidation>

    • Valida reglas/estado del item indicado.

Tipos y modelos

Los tipos principales están en CbmItemModel (archivo src/lib/item.model.ts). Entre ellos:

  • ListParams, ListResponse — para paginación y listado.
  • GetOneResponse — estructura al obtener un solo item.
  • SaveBody, UpdateBody, ConfirmResponse — request/response para creación/actualización.
  • ListWithStockParams, RefreshStockParams — para operaciones de stock.

Importante: importa los tipos desde la librería item-repository (ej.: import { CbmItemModel } from 'item-repository'). Evita usar any para mantener tipado estricto.

Build y publicación

Para compilar la librería en un workspace Angular monorepo:

ng build item-repository

Los artefactos se colocan en dist/item-repository.

Para publicar en npm (opcional):

cd dist/item-repository
npm publish

Resolución de tipos en el editor / problemas comunes

  • Error: "No se permiten rutas de acceso no relativas si no se ha establecido 'baseUrl'" — solución: añadir "baseUrl": "." en el compilerOptions del tsconfig.json raíz.
  • Error: imports tipo item-repository no resueltos en el editor — solución: en tsconfig.json añadir en paths una entrada como:
"item-repository": [
   "./dist/item-repository",
   "projects/item-repository/src/public-api.ts"
]

Esto permite que el IDE/TypeScript encuentre los tipos desde la fuente sin compilar la librería.

Pruebas

Si la librería incluye tests, puedes ejecutar:

ng test item-repository

Problemas y depuración

  • Si las llamadas HTTP devuelven errores 401/403, revisa tus interceptores de autenticación.
  • Si necesita cabeceras adicionales o control avanzado de solicitudes, se recomienda usar HttpInterceptors a nivel de app.

Contacto / Contribución

Si necesitas ampliar la librería (nuevos endpoints, ajustes de modelos o tests), crea un branch, añade cambios en src/lib y actualiza public-api.ts si exportas nuevos símbolos. Luego prueba con ng build item-repository.

Licencia

Revisa el LICENSE del repositorio principal para las condiciones de uso.


Archivo(s) relevantes

  • projects/item-repository/src/lib/item.module.ts — configuración del módulo y token ITEM_MODULE_CONFIG.
  • projects/item-repository/src/lib/item.service.ts — implementación HTTP con HttpClient.
  • projects/item-repository/src/lib/item.repository.ts — fachada/repository inyectable.
  • projects/item-repository/src/lib/item.model.ts — modelos y tipos.

Si quieres, puedo añadir ejemplos de consumo más avanzados (p. ej. cómo mockear en tests, o un pequeño sample app que use la librería).