# pingencom/pingen2-sdk-js architecture

> Architecture diagram of the GitHub repository pingencom/pingen2-sdk-js, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pingencom/pingen2-sdk-js
- Repository: https://github.com/pingencom/pingen2-sdk-js

## Overview

pingen2-sdk-js is a typed client for the Pingen REST API. The main workflow is an application calling a resource method, optionally uploading a file through a signed URL, then creating or managing a Pingen resource and decoding its JSON:API response. Separate branches cover letters, batches, electronic deliverables, organisations/users, events, and webhook management and verification. The sampled sources establish request, upload, response, and resource calls; some resource wiring is represented by README capabilities because its implementations were not sampled.

Main entry points: [`src/requestor.ts`](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/requestor.ts) (HTTP requestor), [`src/resources/letters/letters.ts`](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/letters/letters.ts) (Letters), [`src/resources/batches/batches.ts`](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/batches/batches.ts) (Batches), [`src/common/response.ts`](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/common/response.ts) (Typed responses)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client and transport"]
  node_client_factory["Client factory<br/>[client.ts]"]
  node_oauth["OAuth tokens<br/>[oauth.ts]"]
  node_requestor["HTTP requestor<br/>[requestor.ts]"]
  node_errors["Error mapping<br/>[errors.ts]"]
  node_retry["Retry policy<br/>[retry.ts]"]
end

subgraph group_delivery["Delivery resources"]
  node_upload_base["Upload workflow<br/>[base.ts]"]
  node_file_upload["Signed upload<br/>[file-upload.ts]"]
  node_letters["Letters<br/>[letters.ts]"]
  node_batches["Batches<br/>[batches.ts]"]
  node_ebills["E-bills<br/>[ebills.ts]"]
  node_emails["Emails<br/>[emails.ts]"]
end

subgraph group_account["Account and events"]
  node_orgs["Organisations<br/>[organisations.ts]"]
  node_users["Users<br/>[users.ts]"]
  node_events["Delivery events"]
  node_webhooks["Webhook management<br/>[webhooks.ts]"]
  node_webhook_verify["Webhook verification<br/>[webhook.ts]"]
end

subgraph group_contracts["API contracts"]
  node_payload["JSON:API payloads<br/>[payload.ts]"]
  node_response["Typed responses<br/>[response.ts]"]
  node_list_params["List parameters<br/>[list-params.ts]"]
  node_json_api["JSON:API types<br/>[json-api.ts]"]
  node_relationships["Relationships<br/>[relationships.ts]"]
  node_preset["Preset links<br/>[preset.ts]"]
end

node_app(("Application"))
node_pingen["Pingen API"]

node_app -->|"creates client"| node_client_factory
node_client_factory -->|"configures auth"| node_oauth
node_client_factory -->|"creates requestor"| node_requestor
node_oauth -->|"fetches token"| node_pingen
node_requestor -.->|"refreshes token"| node_oauth
node_requestor -->|"sends API calls"| node_pingen
node_requestor -->|"uses retry policy"| node_retry
node_requestor -->|"maps failures"| node_errors
node_requestor -->|"returns response"| node_response
node_app -->|"calls resource"| node_letters
node_app -->|"calls resource"| node_batches
node_app -->|"calls resource"| node_ebills
node_app -->|"calls resource"| node_emails
node_app -->|"calls resource"| node_orgs
node_app -->|"queries events"| node_events
node_app -->|"manages hooks"| node_webhooks
node_app -->|"verifies event"| node_webhook_verify
node_letters -->|"uploads then creates"| node_upload_base
node_batches -->|"uploads then creates"| node_upload_base
node_ebills -->|"uploads then creates"| node_upload_base
node_emails -->|"uploads then creates"| node_upload_base
node_upload_base -->|"requests upload"| node_file_upload
node_file_upload -.->|"PUTs file"| node_requestor
node_letters -->|"requests endpoints"| node_requestor
node_batches -->|"requests endpoints"| node_requestor
node_webhooks -->|"requests endpoints"| node_requestor
node_letters -->|"builds payload"| node_payload
node_batches -->|"builds payload"| node_payload
node_webhooks -->|"builds payload"| node_payload
node_letters -->|"returns API response"| node_response
node_batches -->|"returns API response"| node_response
node_webhooks -->|"returns API response"| node_response
node_response -->|"validates documents"| node_json_api
node_response -->|"throws parse error"| node_errors
node_requestor -->|"serializes queries"| node_list_params
node_letters -->|"accepts query options"| node_list_params
node_batches -->|"accepts query options"| node_list_params
node_webhooks -->|"accepts query options"| node_list_params
node_events -.->|"queries endpoints"| node_requestor
node_users -.->|"uses API client"| node_requestor
node_orgs -.->|"uses API client"| node_requestor
node_webhook_verify -->|"raises signature error"| node_errors
node_letters -.->|"accepts preset"| node_preset
node_batches -->|"accepts preset"| node_preset
node_ebills -.->|"accepts preset"| node_preset
node_emails -.->|"accepts preset"| node_preset
node_response -->|"exposes relationships"| node_relationships

click node_client_factory "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/client.ts"
click node_oauth "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/oauth.ts"
click node_requestor "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/requestor.ts"
click node_errors "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/errors.ts"
click node_retry "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/utils/retry.ts"
click node_upload_base "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/base.ts"
click node_file_upload "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/file-upload.ts"
click node_letters "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/letters/letters.ts"
click node_batches "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/batches/batches.ts"
click node_ebills "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/ebills/ebills.ts"
click node_emails "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/emails/emails.ts"
click node_orgs "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/organisations/organisations.ts"
click node_users "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/users/users.ts"
click node_events "https://github.com/pingencom/pingen2-sdk-js/tree/main/src/resources/events"
click node_webhooks "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/webhooks/webhooks.ts"
click node_webhook_verify "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/webhook.ts"
click node_payload "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/utils/payload.ts"
click node_response "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/common/response.ts"
click node_list_params "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/common/list-params.ts"
click node_json_api "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/common/json-api.ts"
click node_relationships "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/common/relationships.ts"
click node_preset "https://github.com/pingencom/pingen2-sdk-js/blob/main/src/common/preset.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client_factory,node_oauth,node_requestor,node_errors,node_retry toneBlue
class node_upload_base,node_file_upload,node_letters,node_batches,node_ebills,node_emails toneAmber
class node_orgs,node_users,node_events,node_webhooks,node_webhook_verify,node_pingen toneMint
class node_payload,node_response,node_list_params,node_json_api,node_relationships,node_preset toneRose
class node_app toneIndigo
```

## Components

### Client and transport

- [Client factory](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/client.ts): `src/client.ts`
- [OAuth tokens](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/oauth.ts): `src/oauth.ts`
- [HTTP requestor](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/requestor.ts): `src/requestor.ts`
- [Error mapping](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/errors.ts): `src/errors.ts`
- [Retry policy](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/utils/retry.ts): `src/utils/retry.ts`

### Delivery resources

- [Upload workflow](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/base.ts): `src/resources/base.ts`
- [Signed upload](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/file-upload.ts): `src/resources/file-upload.ts`
- [Letters](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/letters/letters.ts): `src/resources/letters/letters.ts`
- [Batches](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/batches/batches.ts): `src/resources/batches/batches.ts`
- [E-bills](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/ebills/ebills.ts): `src/resources/ebills/ebills.ts`
- [Emails](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/emails/emails.ts): `src/resources/emails/emails.ts`

### Account and events

- [Organisations](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/organisations/organisations.ts): `src/resources/organisations/organisations.ts`
- [Users](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/users/users.ts): `src/resources/users/users.ts`
- [Delivery events](https://github.com/pingencom/pingen2-sdk-js/tree/main/src/resources/events): `src/resources/events`
- [Webhook management](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/resources/webhooks/webhooks.ts): `src/resources/webhooks/webhooks.ts`
- [Webhook verification](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/webhook.ts): `src/webhook.ts`

### API contracts

- [JSON:API payloads](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/utils/payload.ts): `src/utils/payload.ts`
- [Typed responses](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/common/response.ts): `src/common/response.ts`
- [List parameters](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/common/list-params.ts): `src/common/list-params.ts`
- [JSON:API types](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/common/json-api.ts): `src/common/json-api.ts`
- [Relationships](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/common/relationships.ts): `src/common/relationships.ts`
- [Preset links](https://github.com/pingencom/pingen2-sdk-js/blob/main/src/common/preset.ts): `src/common/preset.ts`

### Other components

- **Application**
- **Pingen API**

## Connections

- Application → Client factory: creates client (evidence: `src/client.ts`)
- Client factory → OAuth tokens: configures auth (evidence: `src/client.ts`)
- Client factory → HTTP requestor: creates requestor (evidence: `src/client.ts`)
- OAuth tokens → Pingen API: fetches token (evidence: `src/oauth.ts`)
- HTTP requestor → OAuth tokens: refreshes token
- HTTP requestor → Pingen API: sends API calls (evidence: `src/requestor.ts`)
- HTTP requestor → Retry policy: uses retry policy (evidence: `src/requestor.ts`)
- HTTP requestor → Error mapping: maps failures (evidence: `src/requestor.ts`)
- HTTP requestor → Typed responses: returns response (evidence: `src/requestor.ts`)
- Application → Letters: calls resource (evidence: `README.md`)
- Application → Batches: calls resource (evidence: `README.md`)
- Application → E-bills: calls resource (evidence: `README.md`)
- Application → Emails: calls resource (evidence: `README.md`)
- Application → Organisations: calls resource (evidence: `README.md`)
- Application → Delivery events: queries events (evidence: `README.md`)
- Application → Webhook management: manages hooks (evidence: `README.md`)
- Application → Webhook verification: verifies event (evidence: `README.md`)
- Letters → Upload workflow: uploads then creates (evidence: `src/resources/letters/letters.ts`)
- Batches → Upload workflow: uploads then creates (evidence: `src/resources/batches/batches.ts`)
- E-bills → Upload workflow: uploads then creates (evidence: `src/resources/ebills/ebills.ts`)
- Emails → Upload workflow: uploads then creates (evidence: `src/resources/emails/emails.ts`)
- Upload workflow → Signed upload: requests upload (evidence: `src/resources/base.ts`)
- Signed upload → HTTP requestor: PUTs file
- Letters → HTTP requestor: requests endpoints (evidence: `src/resources/letters/letters.ts`)
- Batches → HTTP requestor: requests endpoints (evidence: `src/resources/batches/batches.ts`)
- Webhook management → HTTP requestor: requests endpoints (evidence: `src/resources/webhooks/webhooks.ts`)
- Letters → JSON:API payloads: builds payload (evidence: `src/resources/letters/letters.ts`)
- Batches → JSON:API payloads: builds payload (evidence: `src/resources/batches/batches.ts`)
- Webhook management → JSON:API payloads: builds payload (evidence: `src/resources/webhooks/webhooks.ts`)
- Letters → Typed responses: returns API response (evidence: `src/resources/letters/letters.ts`)
- Batches → Typed responses: returns API response (evidence: `src/resources/batches/batches.ts`)
- Webhook management → Typed responses: returns API response (evidence: `src/resources/webhooks/webhooks.ts`)
- Typed responses → JSON:API types: validates documents (evidence: `src/common/response.ts`)
- Typed responses → Error mapping: throws parse error (evidence: `src/common/response.ts`)
- HTTP requestor → List parameters: serializes queries (evidence: `src/requestor.ts`)
- Letters → List parameters: accepts query options (evidence: `src/resources/letters/letters.ts`)
- Batches → List parameters: accepts query options (evidence: `src/resources/batches/batches.ts`)
- Webhook management → List parameters: accepts query options (evidence: `src/resources/webhooks/webhooks.ts`)
- Delivery events → HTTP requestor: queries endpoints
- Users → HTTP requestor: uses API client
- Organisations → HTTP requestor: uses API client
- Webhook verification → Error mapping: raises signature error (evidence: `src/webhook.ts`)
- Letters → Preset links: accepts preset
- Batches → Preset links: accepts preset (evidence: `src/resources/batches/batches.ts`)
- E-bills → Preset links: accepts preset
- Emails → Preset links: accepts preset
- Typed responses → Relationships: exposes relationships (evidence: `src/common/response.ts`)
