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

@sofya-sdk/qr

v2.0.0

Published

Canal and EventRooms utilities for Sofya SDK

Downloads

21

Readme

@sofya-sdk/qr

QR code generation, backend contract helpers, and parsing utilities for Sofya SDK.

Installation

pnpm add @sofya-sdk/qr

Usage

Backend Integration (Contract Helpers)

Receptor (Desktop) Flow

import {
  createCanalSession,
  buildEventRoomsConnection,
  getQrCodeUrlFromContract,
  getQrCodeAssetLinkFromContract,
} from '@sofya-sdk/qr';

const canal = await createCanalSession({
  baseUrl: 'https://api.your-backend.com',
});

const qrCodeForPwa =
  canal.qrCodeUrl ?? getQrCodeUrlFromContract(canal.contract);

const qrCodeImage =
  canal.qrCodeBucketLink ?? getQrCodeAssetLinkFromContract(canal.contract);

const eventRooms = buildEventRoomsConnection(canal.contract, 'desktop');
// eventRooms = { url: 'wss://host/ws', canalId: 'CANAL123', role: 'desktop' }

Emissor (PWA) Flow

import { fetchCanalConfiguration, buildEventRoomsConnection } from '@sofya-sdk/qr';
import { parseCanalFromQR, parseApiKeyFromQR } from '@sofya-sdk/qr';

const canalId = parseCanalFromQR(window.location.href);

const config = await fetchCanalConfiguration({
  canalId: canalId ?? '',
  baseUrl: 'https://api.your-backend.com',
});

const eventRooms = buildEventRoomsConnection(config.contract, 'mic');
// Connect using eventRooms.url + config.canalId

Emissor Flow with API Key from QR Code

import { fetchCanalConfiguration, buildEventRoomsConnection } from '@sofya-sdk/qr';
import { parseCanalFromQR, parseApiKeyFromQR } from '@sofya-sdk/qr';

// Extract both canal ID and API key from the QR code URL
// URL format: https://emissor.com/?x-api-key=123456&room_id=id
const canalId = parseCanalFromQR(window.location.href);
const apiKey = parseApiKeyFromQR(window.location.href);

const config = await fetchCanalConfiguration({
  canalId: canalId ?? '',
  baseUrl: 'https://api.your-backend.com',
  apiKey: apiKey ?? 'fallback-api-key', // Use extracted API key from QR
});

const eventRooms = buildEventRoomsConnection(config.contract, 'mic');
// Connect using eventRooms.url + config.canalId

Generate QR Code (Data URL)

import { generateQRCode } from '@sofya-sdk/qr';

const dataUrl = await generateQRCode('https://pwa.sofya.app?canal=123456', {
  width: 256,
  margin: 4,
  errorCorrectionLevel: 'M',
  color: {
    dark: '#000000',
    light: '#FFFFFF',
  },
});

// Use in img tag
<img src={dataUrl} alt="QR Code" />

Generate QR Code (SVG)

import { generateQRCodeSVG } from '@sofya-sdk/qr';

const svg = await generateQRCodeSVG('https://pwa.sofya.app?canal=123456');

Generate QR Code (Canvas)

import { generateQRCodeCanvas } from '@sofya-sdk/qr';

const canvas = document.getElementById('canvas') as HTMLCanvasElement;
await generateQRCodeCanvas('https://pwa.sofya.app?canal=123456', canvas);

Parse Canal from QR Code

import { parseCanalFromQR } from '@sofya-sdk/qr';

const canalId = parseCanalFromQR('https://pwa.sofya.app?room_id=123456');
// Returns: "123456"

Parse API Key from QR Code

import { parseApiKeyFromQR } from '@sofya-sdk/qr';

const apiKey = parseApiKeyFromQR('https://emissor.com/?x-api-key=secret-key&room_id=123456');
// Returns: "secret-key"

Parse Both Canal ID and API Key from QR Code

import { parseCanalFromQR, parseApiKeyFromQR } from '@sofya-sdk/qr';

const url = 'https://emissor.com/?x-api-key=secret-key&room_id=canal-123';

const canalId = parseCanalFromQR(url);
// Returns: "canal-123"

const apiKey = parseApiKeyFromQR(url);
// Returns: "secret-key"

Build PWA URL

import { buildPWAUrl } from '@sofya-sdk/qr';

const url = buildPWAUrl('https://pwa.sofya.app', '123456');
// Returns: "https://pwa.sofya.app?canal=123456"

API

generateQRCode(url, options?)

Generate QR code as a data URL (base64 PNG).

Returns: Promise<string>

generateQRCodeSVG(url, options?)

Generate QR code as SVG string.

Returns: Promise<string>

generateQRCodeCanvas(url, canvas, options?)

Generate QR code on a canvas element (browser only).

Returns: Promise<void>

parseCanalFromQR(url)

Extract canal ID from QR code URL.

Returns: string | null

parseApiKeyFromQR(url)

Extract API key from QR code URL.

Returns: string | null

buildPWAUrl(pwaBaseUrl, canalId)

Build PWA URL with canal parameter.

Returns: string

createCanalSession(options)

Create a canal through the backend contract and return normalized data (Receptor).

Returns: Promise<CreateCanalResponse>

fetchCanalConfiguration(options)

Fetch canal configuration from the backend contract (Emissor).

Returns: Promise<CanalConfig>

buildEventRoomsConnection(contract, role)

Derive EventRooms connection parameters (WebSocket URL, canalId, role) from the returned contract.

Returns: EventRoomsConnectionParams | null

getQrCodeUrlFromContract(contract)

Resolve the best URL encoded in the QR code (typically the PWA URL).

Returns: string | null

getQrCodeAssetLinkFromContract(contract)

Resolve the best QR code asset URL (PNG/SVG) from the contract.

Returns: string | null

Options

interface QRCodeOptions {
  errorCorrectionLevel?: 'L' | 'M' | 'Q' | 'H'; // default: 'M'
  width?: number; // default: 256
  margin?: number; // default: 4
  color?: {
    dark?: string; // default: '#000000'
    light?: string; // default: '#FFFFFF'
  };
}

License

ISC