@mojaksebastian/allegro-client 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @mojaksebastian/allegro-client might be problematic. Click here for more details.

Files changed (2) hide show
  1. package/README.md +71 -48
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,49 +1,57 @@
1
1
  @mojaksebastian/allegro-client
2
2
 
3
- A lightweight and flexible Allegro REST API client for Node.js. It features automatic OAuth2 token management and a pluggable storage system for tokens (Redis, Database, File System, etc.).
4
- Key Features
3
+ 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.
4
+ Główne cechy rozwiązania
5
5
 
6
- Automatic Token Refresh: No more manual handling of access_token expiration. The client automatically refreshes tokens before they expire.
6
+ Automatyczna retencja tokenów: System monitoruje czas wygasania sesji i odświeża tokeny przed ich unieważnieniem.
7
7
 
8
- Device Flow Support: Built-in strategy for DeviceFlow, ideal for CLI tools, scripts, and server-side applications.
8
+ Abstrakcja warstwy Storage: Implementacja interfejsu ITokenStorage pozwala na delegowanie zapisu sesji do dowolnego silnika (Redis, SQL, NoSQL, FileSystem).
9
9
 
10
- Pluggable Storage: Use the ITokenStorage interface to persist tokens wherever you want.
10
+ Zgodność ze standardem ESM: Paczka zoptymalizowana pod nowoczesne środowiska Node.js (20+) oraz moduły ECMAScript.
11
11
 
12
- First-class TypeScript Support: Fully typed configuration and responses for a seamless developer experience.
12
+ Silne typowanie: Kompletne definicje TypeScript dla konfiguracji, strategii oraz interfejsów magazynowania danych.
13
13
 
14
- Sandbox & Production: Easy switching between environments with a single flag.
14
+ Instalacja
15
15
 
16
- Installation
16
+ Paczka jest dostępna w rejestrze NPM. Można ją zainstalować za pomocą preferowanego menedżera pakietów:
17
17
  Bash
18
18
 
19
19
  npm install @mojaksebastian/allegro-client
20
20
 
21
- Quick Start (DeviceFlow + Default FileStorage)
21
+ Szybki Start
22
+
23
+ Poniższy przykład prezentuje podstawową konfigurację z wykorzystaniem strategii DeviceFlow oraz domyślnego magazynu plikowego.
22
24
  TypeScript
23
25
 
24
26
  import AllegroClient from "@mojaksebastian/allegro-client";
25
27
 
26
- const client = new AllegroClient({
28
+ const config = {
27
29
  credentials: {
28
- clientId: "YOUR_CLIENT_ID",
29
- clientSecret: "YOUR_CLIENT_SECRET",
30
+ clientId: process.env.ALLEGRO_CLIENT_ID,
31
+ clientSecret: process.env.ALLEGRO_CLIENT_SECRET,
30
32
  },
31
33
  strategy: "DeviceFlow",
32
- env: "sandbox" // or "production"
33
- });
34
-
35
- async function run() {
36
- // Automatically reads from file or initiates Device Flow if needed
37
- const token = await client.getAccessToken();
38
- console.log("Your access token:", token);
34
+ env: "sandbox" // Opcje: "production" | "sandbox"
35
+ };
36
+
37
+ const allegro = new AllegroClient(config);
38
+
39
+ async function initialize() {
40
+ try {
41
+ const accessToken = await allegro.getAccessToken();
42
+ console.log("Autoryzacja zakończona sukcesem.");
43
+ return accessToken;
44
+ } catch (error) {
45
+ console.error("Błąd autoryzacji:", error.message);
46
+ }
39
47
  }
40
48
 
41
- run();
49
+ initialize();
42
50
 
43
- Advanced: Custom Storage (e.g., Redis)
51
+ Implementacja własnego magazynu danych (ITokenStorage)
44
52
 
45
- You can implement the ITokenStorage interface to store tokens in a production-grade database. This is essential for serverless environments (like AWS Lambda or Vercel) where the file system is ephemeral.
46
- Redis Implementation Example
53
+ 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).
54
+ Przykład: Integracja z Redis
47
55
  TypeScript
48
56
 
49
57
  import { ITokenStorage, IAllegroTokens } from "@mojaksebastian/allegro-client";
@@ -52,44 +60,59 @@ import { createClient } from "redis";
52
60
  export class RedisTokenStorage implements ITokenStorage {
53
61
  private client = createClient({ url: 'redis://localhost:6379' });
54
62
 
55
- async save(tokens: IAllegroTokens) {
63
+ private async connect() {
56
64
  if (!this.client.isOpen) await this.client.connect();
57
- await this.client.set("allegro_tokens", JSON.stringify(tokens));
58
65
  }
59
66
 
60
- async read() {
61
- if (!this.client.isOpen) await this.client.connect();
62
- const data = await this.client.get("allegro_tokens");
67
+ async save(tokens: IAllegroTokens): Promise<void> {
68
+ await this.connect();
69
+ await this.client.set("allegro_session", JSON.stringify(tokens));
70
+ }
71
+
72
+ async read(): Promise<IAllegroTokens | null> {
73
+ await this.connect();
74
+ const data = await this.client.get("allegro_session");
63
75
  return data ? JSON.parse(data) : null;
64
76
  }
65
77
 
66
- async clear() {
67
- if (!this.client.isOpen) await this.client.connect();
68
- await this.client.del("allegro_tokens");
78
+ async clear(): Promise<void> {
79
+ await this.connect();
80
+ await this.client.del("allegro_session");
69
81
  }
70
82
  }
71
83
 
72
- // Usage:
73
- const client = new AllegroClient({
74
- credentials: { clientId: "...", clientSecret: "..." },
75
- storage: new RedisTokenStorage(),
76
- strategy: "DeviceFlow"
84
+ // Inicjalizacja klienta z wykorzystaniem Redis
85
+ const allegro = new AllegroClient({
86
+ ...config,
87
+ storage: new RedisTokenStorage()
77
88
  });
78
89
 
79
- Configuration (IAllegroClientConfig)
80
- | Property | Type | Description |
81
- | :--- | :--- | :--- |
82
- | `credentials` | `IAuthCredentials` | Object containing `clientId` and `clientSecret`. |
83
- | `strategy` | `Tstrategy` | Authentication strategy. Supported: `"DeviceFlow"`. |
84
- | `env` | `"production" \| "sandbox"` | Target environment (defaults to `"production"`). |
85
- | `storage` | `ITokenStorage` | (Optional) Custom storage instance. Defaults to `FileTokenStorage`. |
90
+ Specyfikacja techniczna
91
+ Interfejs konfiguracji (IAllegroClientConfig)
92
+ Właściwość Typ Wymagane Opis
93
+ credentials IAuthCredentials Tak Obiekt zawierający clientId oraz clientSecret.
94
+ strategy Tstrategy Tak Wybrana strategia autoryzacji (np. "DeviceFlow").
95
+ env "production" | "sandbox" Nie Środowisko Allegro (Domyślnie: "production").
96
+ storage ITokenStorage Nie Instancja klasy zarządzającej zapisem (Domyślnie: FileTokenStorage).
97
+ Metody klasy AllegroClient
98
+
99
+ getAccessToken(): Promise<string> – Zwraca aktywny token dostępowy. Jeśli token wygasł lub nie istnieje, inicjuje proces odświeżania lub autoryzacji.
100
+
101
+ clearSession(): Promise<void> – Usuwa dane sesyjne z przypisanego magazynu.
86
102
 
87
- This package uses ESM and requires Node.js v20 or higher.
103
+ Rozwój projektu
104
+
105
+ Biblioteka wymaga Node.js w wersji 20.x lub wyższej.
88
106
  Bash
89
107
 
90
- npm run build # Compiles TS to JS (dist folder)
91
- npm run dev # Runs the project in development mode
108
+ # Kompilacja kodu źródłowego (TypeScript -> JavaScript)
109
+ npm run build
110
+
111
+ # Uruchomienie skryptów w trybie deweloperskim
112
+ npm run dev
113
+
114
+ Licencja
92
115
 
93
- License
116
+ Projekt dystrybuowany na warunkach licencji MIT. Szczegóły znajdują się w pliku LICENSE.
94
117
 
95
- MIT
118
+ Autor: mojaksebastian
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojaksebastian/allegro-client",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Allegro REST API Client with automatic token refresh. Fetches tokens from allegro and serves them to the user. Supports both the production and sandbox enviroments",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",