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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tapokjs/sdk

v0.1.0

Published

Browser and server SDK for Tapok authentication

Readme

@tapokjs/sdk

Готовый TypeScript SDK для Tapok. Пакет построен на @tapokjs/core и публикует два ESM entry point:

  • @tapokjs/sdk/browser для Base в браузере и навигации Connect;
  • @tapokjs/sdk/server для Connect на сервере и проверки Base identity token.

Полное руководство: tapok.orria.space/docs/sdk.

Установка

bun add @tapokjs/sdk

Не используйте root entry point в прикладном коде. Импортируйте только /browser или /server.

Base в браузере

Сначала разместите Base manifest на production origin. Инструкция и точный формат: Base manifest.

import { createBaseBrowserClient } from "@tapokjs/sdk/browser";

const tapok = createBaseBrowserClient({
  redirectUri: "https://app.example/auth/tapok/callback",
  scopes: ["session", "age:18"],
});

// Страница входа.
await tapok.redirect();

// Страница callback.
const result = await tapok.completeCallback();
if (result.ok) {
  await fetch("/api/session/tapok", {
    method: "POST",
    credentials: "same-origin",
    headers: {
      "content-type": "application/json",
      "x-csrf-token": csrfToken,
    },
    body: JSON.stringify({ identityToken: result.response.identity_token }),
  });
}

Клиент хранит Base transaction в sessionStorage, проверяет state, exact iss и nonce, затем удаляет query callback до exchange. Отправляйте identity token своему серверу same-origin POST с CSRF-защитой. Не делайте сессию прямо в браузере.

На сервере проверьте JWT и атомарно погасите jti:

import { TAPOK_ISSUER } from "@tapokjs/core";
import { verifyAndConsumeBaseIdentityToken } from "@tapokjs/sdk/server";

const verified = await verifyAndConsumeBaseIdentityToken({
  token: body.identityToken,
  expectedIssuer: TAPOK_ISSUER,
  expectedAudience: "origin:https://app.example",
  replayStore: {
    async consume(jti, expiresAt) {
      // Вставьте jti с unique constraint и TTL до expiresAt.
      return await reserveJtiOnce(jti, expiresAt);
    },
  },
});

await createApplicationSession(verified.claims.sub);

verifyAndConsumeBaseIdentityToken() допускает только ES256 и проверяет kid, подпись, issuer, audience, сроки, mode и pairwise_sub. Token живёт 10 минут. Повторный jti должен завершать вход ошибкой.

Для popup доступны openPopup(), completePopupMessage() и postBasePopupCallback(). Проверяйте event.origin и event.source. targetOrigin всегда равен exact origin приложения, не *. Redirect в текущей вкладке остаётся обязательным fallback.

Connect на сервере

Connect требует backend. Не передавайте в браузер client secret, PKCE verifier, authorization code, ID token или access token. Перед началом зарегистрируйте приложение, callback URI, цели scopes и получите secret в Developer portal.

import { createConnectServerClient } from "@tapokjs/sdk/server";

const tapok = createConnectServerClient({
  clientId: process.env.TAPOK_CLIENT_ID!,
  clientSecret: process.env.TAPOK_CLIENT_SECRET!,
  redirectUri: "https://app.example/auth/tapok/callback",
  scopes: ["openid", "email"],
  transactions: transactionStore,
});

// GET /auth/tapok/start
const { authorizationUrl } = await tapok.beginAuthorization();
return Response.redirect(authorizationUrl, 302);

// GET /auth/tapok/callback
const completed = await tapok.completeCallback(request.url);
if (!completed.ok) {
  return Response.redirect("https://app.example/login?error=access_denied", 303);
}

await createApplicationSession(completed.userInfo.sub);
// completed.userInfo.email — технический, недоставляемый адрес, не используйте для связи.
return Response.redirect("https://app.example/account", 303);

transactions должен реализовать контракт:

import type { ConnectTransactionStore } from "@tapokjs/sdk/server";

const transactionStore: ConnectTransactionStore = {
  async save(transaction) {
    // Сохраните в server-side encrypted storage с TTL не больше transaction.expiresAt.
  },
  async consume(state) {
    // Одной атомарной операцией верните и удалите непросроченную transaction.
    return null;
  },
};

SDK формирует client_secret_basic, обменивает code, проверяет ES256 ID token через Tapok JWKS, сверяет nonce, загружает UserInfo и сравнивает его sub с sub ID token. Access token остаётся на сервере. После callback перенаправьте пользователя на allowlisted локальный URL без OAuth query.

Отзыв access token:

await tapok.revoke(accessToken);

createConnectBrowserNavigator() подходит только для открытия вашего /auth/tapok/start из браузера. Он не реализует Connect protocol и не получает секреты или tokens.

Полезные ссылки

Development

cd @tapokjs
bun run --cwd sdk check