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

@mojaksebastian/allegro-client

v1.5.1

Published

Klient Allegro REST API z automatycznym odświeżaniem tokenów. Pobiera tokeny z Allegro i udostępnia je użytkownikowi. Obsługuje zarówno środowisko produkcyjne, jak i sandbox.

Readme

@mojaksebastian/allegro-client

Wydajny i skalowalny klient Allegro REST API dla środowiska Node.js, oferujący pełną automatyzację procesu autoryzacji OAuth2 oraz abstrakcję warstwy przechowywania tokenów.

Główne cechy rozwiązania

  • Automatyczna retencja tokenów: System monitoruje czas wygasania sesji i odświeża tokeny przed ich unieważnieniem.
  • Abstrakcja warstwy Storage: Implementacja interfejsu ITokenStorage pozwala na delegowanie zapisu sesji do dowolnego silnika (Redis, SQL, NoSQL, FileSystem).
  • Zgodność ze standardem ESM: Paczka zoptymalizowana pod nowoczesne środowiska Node.js (20+) oraz moduły ECMAScript.
  • Silne typowanie: Kompletne definicje TypeScript dla konfiguracji, strategii oraz interfejsów magazynowania danych.

Instalacja

Paczka jest dostępna w rejestrze NPM. Można ją zainstalować za pomocą preferowanego menedżera pakietów:

npm install @mojaksebastian/allegro-client

Szybki Start

Poniższy przykład prezentuje podstawową konfigurację z wykorzystaniem strategii DeviceFlow oraz domyślnego magazynu plikowego.

import AllegroClient from "@mojaksebastian/allegro-client";

const config = {
  credentials: {
    clientId: process.env.ALLEGRO_CLIENT_ID,
    clientSecret: process.env.ALLEGRO_CLIENT_SECRET,
  },
  userAgent: { // NAGŁÓWEK USER AGENT WYMAGANY PRZEZ ALLEGRO DO KOŃCA CZERWCA 2026 !!!
    name: "AllegroClient", // nazwa aplikacji
    version: "1.0.0", // wersja (w formie x.x.x / x.x / x)
    url: "https://github.com/mojaksebastian/allegro-client", // należy podać URL do strony projektu
  }
  strategy: "DeviceFlow", // Na razie tylko DeviceFlow
  env: "sandbox", // Opcje: "production" | "sandbox"
};

const allegro = new AllegroClient(config);

async function initialize() {
  try {
    const accessToken = await allegro.getAccessToken();
    console.log("Autoryzacja zakończona sukcesem.");
    return accessToken;
  } catch (error) {
    console.error("Błąd autoryzacji:", error.message);
  }
}

initialize();

Implementacja własnego magazynu danych (ITokenStorage) OPCJONALNE

Architektura biblioteki pozwala na wstrzyknięcie własnej klasy zarządzającej danymi sesyjnymi. Jest to rozwiązanie zalecane dla środowisk rozproszonych i bezstanowych (Serverless). Przykład: Integracja z Redis

import { ITokenStorage, IAllegroTokens } from "@mojaksebastian/allegro-client";
import { createClient } from "redis";

export class RedisTokenStorage implements ITokenStorage {
  private client = createClient({ url: "redis://localhost:6379" });

  private async connect() {
    if (!this.client.isOpen) await this.client.connect();
  }

  async save(tokens: IAllegroTokens): Promise<void> {
    await this.connect();
    await this.client.set("allegro_session", JSON.stringify(tokens));
  }

  async read(): Promise<IAllegroTokens | null> {
    await this.connect();
    const data = await this.client.get("allegro_session");
    return data ? JSON.parse(data) : null;
  }

  async clear(): Promise<void> {
    await this.connect();
    await this.client.del("allegro_session");
  }
}

// Inicjalizacja klienta z wykorzystaniem Redis
const allegro = new AllegroClient({
  ...config,
  storage: new RedisTokenStorage(),
});

Specyfikacja techniczna

Interfejs konfiguracji (IAllegroClientConfig)

| Właściwość | Typ | Wymagane | Opis | | :------------ | :----------------- | :------- | :--------------------------------------------------------------------- | | credentials | IAuthCredentials | Tak | Obiekt zawierający clientId oraz clientSecret. | | userAgent | IUserAgent | Tak | Obiekt z metadanymi aplikacji (wymagany nagłówek User-Agent). | | strategy | TStrategy | Tak | Wybrana strategia autoryzacji (np. "DeviceFlow"). | | env | TEnv | Nie | Środowisko Allegro (Domyślnie: "production"). | | storage | ITokenStorage | Nie | Instancja klasy zarządzającej zapisem (Domyślnie: FileTokenStorage). |

Metody klasy AllegroClient

  • getAccessToken(): Promise – Zwraca aktywny token dostępowy. Jeśli token wygasł lub nie istnieje, inicjuje proces odświeżania lub autoryzacji.

  • clearTokens(): Promise – Usuwa token zapisany w pamięci klienta.

  • send(path: string, options: RequestInit): Promise – Metoda pomocnicza do wysyłania żądań HTTP do API Allegro. Automatycznie uwzględnia nagłówki Authorization oraz User-Agent.

Rozwój projektu

Biblioteka wymaga Node.js w wersji 20.x lub wyższej.

# Kompilacja kodu źródłowego (TypeScript -> JavaScript)
npm run build

# Uruchomienie skryptów w trybie deweloperskim
npm run dev

Licencja

Projekt dystrybuowany na warunkach licencji MIT.

Autor: mojaksebastian