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 🙏

© 2025 – Pkg Stats / Ryan Hefner

pdnd-js-client

v0.1.1

Published

Client JavaScript/TypeScript per autenticazione e interazione con le API della Piattaforma Digitale Nazionale Dati (PDND).

Readme

pdnd-js-client

Client JavaScript/TypeScript per autenticazione e interazione con le API della Piattaforma Digitale Nazionale Dati (PDND).

Basato sugli esempi dei client Ruby e Python, questo package fornisce:

  • utilità per generare JWT firmati: src/JWTGenerator.ts
  • gestione token locale: src/TokenManager.ts
  • client HTTP per lo scambio JWT → access token e per chiamare le API: src/Client.ts
  • CLI per uso da riga di comando: src/cli.ts

Link rapidi

  • Codice sorgente: src/JWTGenerator.ts, src/TokenManager.ts, src/Client.ts, src/Config.ts
  • CLI: src/cli.ts
  • Test di esempio: test/jwt.test.ts
  • Config di esempio: configs/sample.json
  • Package: package.json

Linguaggi e strumenti

  • Linguaggi: TypeScript e JavaScript
  • Runtime: Node.js (>= 18)
  • Transpilazione: TypeScript (tsc)
  • Test runner: Vitest
  • Gestione pacchetti: npm

Requisiti

  • Node.js >= 18
  • TypeScript (dev dependency)

Installazione

  1. Clona il repository.
  2. Installa le dipendenze:
    npm install

Compilazione (build)
- Il progetto usa TypeScript: compila con tsc.
```sh
node build

Esecuzione test

  • Test eseguiti con Vitest.
node test

Uso CLI Il CLI è avviabile direttamente (shebang in src/cli.ts). Esempio base (usa configs/sample.json se non ne fornisci uno):

node cli -- --env collaudo --config configs/sample.json --status-url https://api.example/status

Opzioni CLI (tutte)

  • --config : File di configurazione JSON
  • --env : Ambiente — "collaudo" o "produzione"
  • --status-url : URL di status da richiamare
  • --api-url : API URL da chiamare
  • --api-url-filters : Filtri query string (formato key1=val1&key2=val2)
  • --token-file : File token (default: tmp/pdnd_token.json)
  • --debug : Mostra messaggi di debug (DebugLogger)
  • --pretty : Output JSON formattato
  • --no-verify-ssl : Disabilita verifica SSL per le chiamate HTTP
  • --save : Salva il token (usando TokenManager)

Esempi d'uso CLI completi

Richiesta status (output compatto)

node src/cli.ts --env collaudo --config configs/sample.json --status-url https://api.example/status

Chiamata API con filtri e output formattato

node src/cli.ts --env produzione --config configs/prod.json --api-url https://api.example/resource --api-url-filters "q=term&limit=10" --pretty

Disabilitare verify SSL e salvare il token

node src/cli.ts --env collaudo --config configs/sample.json --api-url https://api.example/resource --no-verify-ssl --save

Formato di configurazione La funzione loadEnvConfig (src/Config.ts) carica un file JSON con la struttura per ciascun ambiente. Ogni ambiente (collaudo/produzione) deve contenere:

  • kid
  • issuer
  • clientId
  • purposeId
  • privKeyPath

Esempio:

{
  "collaudo": {
    "kid": "kid",
    "issuer": "issuer",
    "clientId": "clientId",
    "purposeId": "purposeId",
    "privKeyPath": "/tmp/key.pem"
  },
  "produzione": { }
}

API programmatica

  • Generare JWT:
    • funzione: src/JWTGenerator.ts → generateJwt
    • genera un JWT RS256 firmato partendo da una chiave privata PEM
  • Scambiare JWT per un access token:
    • metodo: src/Client.ts → getAccessToken
    • invia POST a endpoint token con grant_type client_credentials e ritorna token ed expiry
  • Gestione token persistente:
    • classe: src/TokenManager.ts
    • supporta load(), save(token, exp) e valid(exp) per riutilizzare token salvati in tmp/pdnd_token.json (o percorso custom)

Integrazione in un progetto

  • Installazione come dipendenza:

    • Se il pacchetto è pubblicato su npm:
      npm install pdnd-js-client
    • Direttamente da GitHub:
      npm install github:isprambiente/pdnd-js-client
    • Da percorso locale (se lavori sul repository):
      # all'interno del progetto che consumerà la libreria
      npm install ../path/to/js-client
  • Import e utilizzo (ESM / TypeScript)

    • Import dei moduli principali:
      import { generateJwt } from 'pdnd-js-client';
      import { Client } from 'pdnd-js-client';
      import { TokenManager } from 'pdnd-js-client';
    • Esempio d'uso semplificato:
      // genera jwt usando la config dell'ambiente
      const jwt = await generateJwt({
        issuer: 'https://issuer.example',
        clientId: 'client-id',
        purposeId: 'purpose-id',
        privKeyPath: '/path/to/key.pem',
        kid: 'key-id'
      });
      
      const client = new Client({ tokenEndpoint: 'https://api.example/token' });
      const tokenResponse = await client.getAccessToken(jwt);
      
      // gestione persistente
      const tm = new TokenManager({ file: './tmp/pdnd_token.json' });
      if (!tm.valid(tokenResponse.expires_at)) {
        tm.save(tokenResponse.access_token, tokenResponse.expires_at);
      }
  • Import CommonJS

    const { generateJwt, Client, TokenManager } = require('pdnd-js-client');

Test Un test di esempio per la generazione JWT è presente in test/jwt.test.ts. Esegui i test locali con:

node test

Contribuire PR e issue sono benvenuti. Assicurati che i test passino e segui gli standard del progetto:

node test
node lint

Licenza La licenza è presente nel file LICENSE del repository. Controlla lì per i termini specifici.

Contribuire

Le pull request sono benvenute! Per problemi o suggerimenti, apri una issue.