Subiekt.Connector.Sdk 1.0.0

dotnet add package Subiekt.Connector.Sdk --version 1.0.0
                    
NuGet\Install-Package Subiekt.Connector.Sdk -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Subiekt.Connector.Sdk" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Subiekt.Connector.Sdk" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Subiekt.Connector.Sdk" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Subiekt.Connector.Sdk --version 1.0.0
                    
#r "nuget: Subiekt.Connector.Sdk, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Subiekt.Connector.Sdk@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Subiekt.Connector.Sdk&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Subiekt.Connector.Sdk&version=1.0.0
                    
Install as a Cake Tool

🐧 Subiekt 123 Connector

.NET 10 connector for Subiekt 123 API v1.1 (InsERT).
Includes: standalone SDK, WebAPI connector, Blazor demo app, integration tests, and Git hooks.


Quick Start

git clone https://github.com/Daemon-Penguins/subiekt-connector
cd subiekt-connector
./setup-hooks.sh   # install git hooks (one-time)
dotnet restore
dotnet build

Projects

Project Type Description
src/Subiekt.Connector.Api WebAPI REST connector β€” exposes Subiekt 123 API via local HTTP endpoints
src/Subiekt.Connector.Sdk Class Library Standalone SDK β€” use directly in any .NET project
demo/Subiekt.Demo Blazor Server Demo app with OAuth login and client/document/product listing
tests/Subiekt.Connector.IntegrationTests xUnit Integration tests β€” auth, token store, PKCE, contract deserialization

Running Tests

# All tests
dotnet test

# With verbose output
dotnet test --verbosity normal

# Specific project
dotnet test tests/Subiekt.Connector.IntegrationTests

# With coverage (requires coverlet)
dotnet test --collect:"XPlat Code Coverage"

Expected result: 14/14 tests passed

Powodzenie! β€” niepowodzenie: 0, powodzenie: 14, pominiΔ™to: 0, Ε‚Δ…cznie: 14

Test categories

Suite Tests What it covers
PkceServiceTests 4 PKCE code_verifier/challenge generation, state uniqueness, auth URL builder
InMemoryTokenStoreTests 5 Token storage, expiry check, refresh token preservation, clear
OAuthStateCacheTests 3 Pending OAuth state set/get/remove
ContractsTests 2 JSON deserialization of ClientDto and DocumentListDto from real API responses

Configuration

WebAPI / Demo app (appsettings.json)

{
  "Subiekt": {
    "ClientId": "twΓ³j-client-id",
    "ClientSecret": "twΓ³j-client-secret",
    "SubscriptionKey": "klucz-subskrypcji-z-portalu",
    "RedirectUri": "https://localhost:5001/hook/callback"
  }
}

SDK (in code)

var sdk = new SubiektClient(new SubiektClientOptions
{
    ClientId     = "twΓ³j-client-id",
    ClientSecret = "twΓ³j-client-secret",
    SubscriptionKey = "klucz-subskrypcji",
    RedirectUri  = "https://twoja-aplikacja.pl/callback"
});

How to get credentials

  1. WejdΕΊ na developers.insert.com.pl
  2. Zarejestruj aplikacjΔ™ β†’ otrzymasz ClientId i ClientSecret
  3. Ustaw redirect_uri na adres Twojej aplikacji (np. /hook/callback)
  4. Subskrybuj API Subiekt 123 β†’ otrzymasz SubscriptionKey

Running the WebAPI

cd src/Subiekt.Connector.Api
dotnet run

Swagger UI: https://localhost:5001/swagger

OAuth flow

  1. GET /auth/login β†’ redirects to InsERT login page
  2. User logs in and authorizes
  3. InsERT redirects to /hook/callback?code=...&state=...
  4. Token stored automatically
  5. GET /auth/status β†’ check if authorized
  6. POST /auth/refresh β†’ manual token refresh
  7. POST /auth/logout β†’ clear token

Running the Blazor Demo

cd demo/Subiekt.Demo
dotnet run

Open https://localhost:5002 β†’ go to Auth β†’ click Zaloguj siΔ™ przez InsERT


Using the SDK

Install as a project reference:

<ProjectReference Include="../src/Subiekt.Connector.Sdk/Subiekt.Connector.Sdk.csproj" />

OAuth 2.0 PKCE flow

var sdk = new SubiektClient(options);

// Step 1: generate auth URL
var (url, state) = sdk.Auth.BuildAuthorizationUrl();
// Store state (e.g. in session) β€” needed for step 2
// Redirect user to url

// Step 2: on callback (code + state from query string)
var token = await sdk.Auth.ExchangeCodeAsync(code, state);
sdk.SetToken(token);

Clients

// List (paged, with filters)
var clients = await sdk.Clients.ListAsync(
    pageNumber: 1,
    pageSize: 25,
    filters: new[] { "name~Kowalski" }   // name contains "Kowalski"
);

// Get by ID
var client = await sdk.Clients.GetAsync(clientId);

// Create
var result = await sdk.Clients.CreateAsync(new CreateClientDto(
    Name: "Testowa Firma Sp. z o.o.",
    Kind: ClientKind.Company,
    Tin: "1234567890",
    TinKind: TinKind.Nip
));

// Update (requires ETag from previous GET response header)
await sdk.Clients.UpdateAsync(id, updateDto, etag);

// Delete
await sdk.Clients.DeleteAsync(id);

Documents

// List with date filter
var docs = await sdk.Documents.ListAsync(
    filters: new[] { "issueDate_From=2024-01-01", "issueDate_To=2024-12-31" }
);

// Get full document
var doc = await sdk.Documents.GetAsync(documentId);

// Print (returns PDF bytes)
byte[] pdf = await sdk.Documents.PrintAsync(documentId, ecoMode: false);
File.WriteAllBytes("faktura.pdf", pdf);

Products

// List goods only
var products = await sdk.Products.ListAsync(
    filters: new[] { "kind=Good" },
    orderBy: "name:asc"
);

var product = await sdk.Products.GetAsync(productId);

Supported filter operators

Operator Meaning Example
= Exact match kind=Company
~ Contains name~Kowalski

Clients filter fields: name, kind, group, nip

Documents filter fields: documentNumber, client, issueDate_From, issueDate_To

Products filter fields: name, kind, group


Git Hooks

After cloning, install hooks once:

./setup-hooks.sh
Hook Trigger Action
pre-commit git commit dotnet format --verify-no-changes β€” blocks commit if code is not formatted
pre-push git push dotnet build + dotnet test β€” blocks push on failure

Format code before committing:

dotnet format
git add .
git commit -m "..."

Skip hooks if needed:

git commit --no-verify
git push --no-verify

CI/CD

GitHub Actions runs on every push to main:

  • dotnet restore
  • dotnet build --configuration Release
  • dotnet test --configuration Release
  • Uploads test results as .trx artifacts

See Actions.


API Reference

Subiekt 123 API v1.1 β€” developers.insert.com.pl

Base URL: https://api.subiekt123.pl/1.1
Auth: OAuth 2.0 PKCE via https://kontoapi.insert.com.pl

Note: All IDs in v1.1 are Guid (not int as in v1.0).
Contracts are auto-generated from the official OpenAPI spec.


Project Structure

subiekt-connector/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ Subiekt.Connector.Api/          # WebAPI connector
β”‚   β”‚   β”œβ”€β”€ Auth/                       # OAuth services (PKCE, TokenStore, StateCache)
β”‚   β”‚   β”œβ”€β”€ Contracts/                  # Auto-generated DTOs from OpenAPI v1.1
β”‚   β”‚   β”œβ”€β”€ Controllers/                # Auth, Hook, Clients, Documents, Products
β”‚   β”‚   └── Services/                   # SubiektApiClient (HttpClient wrapper)
β”‚   └── Subiekt.Connector.Sdk/          # Standalone SDK
β”‚       β”œβ”€β”€ Auth/                       # PkceHelper, SubiektAuthClient, TokenInfo
β”‚       β”œβ”€β”€ Models/                     # Auto-generated models from OpenAPI v1.1
β”‚       └── Resources/                  # ClientsResource, DocumentsResource, ProductsResource
β”œβ”€β”€ demo/
β”‚   └── Subiekt.Demo/                   # Blazor Server demo
β”œβ”€β”€ tests/
β”‚   └── Subiekt.Connector.IntegrationTests/  # xUnit tests
β”œβ”€β”€ .githooks/                          # Git hooks (pre-commit, pre-push)
β”œβ”€β”€ setup-hooks.sh                      # One-time hook installer
└── Subiekt.Connector.sln
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 235 3/28/2026