@scanupload/qr-code-generator-core
v0.2.1
Published
Framework-agnostic core for the ScanUpload QR Code Generator — SignalR session management, state, and types.
Downloads
82
Maintainers
Readme
@scanupload/qr-code-generator-core
Framework-agnostic runtime for the ScanUpload QR Code Generator. Handles session creation, SignalR connection management, upload state, and the typed primitives needed to build framework adapters.
Install
npm install @scanupload/qr-code-generator-coreBackend contract
The browser calls one endpoint directly — the hub authenticates from the browser's Origin header, so no token is required.
| Endpoint | Method | Description |
| ------------ | ------ | ------------------------------------------------------------------------------------------ |
| sessionUrl | POST | Creates a ScanUpload session. Returns { sessionId, deviceLoginUrl, hubUrl, ttlSeconds }. |
Quick start
import { QrCodeGeneratorCore, browserStorageAdapter } from '@scanupload/qr-code-generator-core';
const core = new QrCodeGeneratorCore({
sessionUrl: '/api/front-end/session',
clientId: 'your-tenant-id', // optional
storage: browserStorageAdapter // optional, defaults to localStorage
});
const unsubscribe = core.subscribe(() => {
const state = core.getState();
console.log({
deviceLoginUrl: state.deviceLoginUrl,
secondsRemaining: state.secondsRemaining,
files: state.uploadedFiles
});
});
await core.start();
// Update at runtime — the core reconnects automatically
await core.setOptions({ sessionUrl: '/api/new-session' });
// Tear down
unsubscribe();
core.dispose();API
new QrCodeGeneratorCore(options)
| Field | Type | Required | Description |
| --------------- | ---------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| sessionUrl | string | Yes | Endpoint that creates a ScanUpload session. |
| clientId | string | No | Optional tenant / Keycloak client_id sent in the request body. |
| storage | StorageAdapter | No | Defaults to localStorage via browserStorageAdapter. |
| autoResession | boolean | true | Automatically create a fresh session at TTL expiry. Framework UI wrappers default this to false so their disconnected state and Reload action remain visible. |
State
interface QrCodeGeneratorState {
loading: boolean; // true while the session is being created
isConnected: boolean; // SignalR connection status
retry: boolean; // true when the last session create failed
deviceLoginUrl: string; // URL encoded into the QR code
uploadedFiles: UploadedFile[];
expiresAt: number | null; // absolute expiry (ms since epoch)
secondsRemaining: number | null;
errorCode: number | null; // 409 (tenant limit) / 429 (rate limit) / null
sessionId: string | null; // active session id
}UploadedFile
interface UploadedFile {
id: string;
name: string;
size: number;
type: string;
progress: number;
status: 'added' | 'uploading' | 'success' | 'error';
error?: string;
url?: string; // signed download URL — used by DownloadButton
thumbnailBase64?: string;
}Methods
start()— create the session and open the SignalR connectionsetOptions({ sessionUrl?, clientId? })— update at runtime; reconnects automaticallyretrySession()— tear down the current session and create a new onegetState()/subscribe(listener)— reactive statedispose()— clean up
Exports
QrCodeGeneratorCorebrowserStorageAdaptertriggerBrowserDownload(blob, filename)— browser-only DOM helperpostData,deleteData,ApiErrorisNullOrEmpty,debounce,debounceAsync,isExpired,truncateWithDotsSessionResponse,UploadedFile,QrCodeGeneratorStateStorageAdapter,QrCodeGeneratorCoreOptions,QrCodeGeneratorCoreSetOptions
License
MIT © Donald Asante
