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

@portaidentity/sdk

v1.2.1

Published

Universal TypeScript SDK for the Porta Admin API

Readme

@portaidentity/sdk

Universal TypeScript SDK for the Porta Admin API — works in browsers, Node.js, and AI agents.

Features

  • Transport abstractionBrowserTransport (CSRF cookies) and NodeTransport (Bearer tokens) with pluggable auth
  • 19 domain namespaces — Organizations, Applications, Clients, Users, Roles, Permissions, Custom Claims, Config, Keys, Audit, Stats, Sessions, Bulk, Branding, Exports, Two-Factor, Imports, User Roles, User Claims
  • Full TypeScript types — SDK-owned type definitions for all entities, inputs, and responses
  • Pagination helperslistAll() auto-pagination and cursor-based support
  • Error hierarchy — Typed errors (PortaNotFoundError, PortaConflictError, etc.) with HTTP status mapping
  • AI agent integration — Tool definitions and executeTool() dispatcher for MCP/LLM integration
  • Zero runtime dependencies — Uses only fetch (built into Node 22+ and browsers)

Installation

# From the Porta project root (workspace dependency)
yarn add @portaidentity/sdk

# Or reference as file dependency
"@portaidentity/sdk": "file:../packages/porta-sdk"

Quick Start

Browser (Admin GUI / BFF)

import { createPortaClient, createBrowserTransport } from '@portaidentity/sdk/browser';

const transport = createBrowserTransport({
  baseUrl: '/api/admin',    // BFF proxy path
  csrfCookieName: '_csrf',  // CSRF cookie name
  csrfHeaderName: 'x-csrf-token',
  on401: () => window.location.href = '/login',
});

const client = createPortaClient(transport);

// List organizations
const orgs = await client.organizations.list({ page: 1, pageSize: 20 });

// Create a user
const user = await client.users.create('org-id', {
  email: '[email protected]',
  givenName: 'Jane',
  familyName: 'Doe',
});

Node.js (Automation / CLI)

import { createPortaClient, createNodeTransport, createTokenAuth } from '@portaidentity/sdk/node';

const auth = createTokenAuth('your-bearer-token');

const transport = createNodeTransport({
  baseUrl: 'https://porta.local:3443/api/admin',
  auth,
});

const client = createPortaClient(transport);

// List all organizations (auto-pagination)
const allOrgs = await client.organizations.listAll();

// Suspend a user
await client.users.suspend('org-id', 'user-id');

// Assign a role
await client.userRoles.assign('org-id', 'user-id', { roleId: 'role-id' });

Client Credentials (Server-to-Server)

import { createPortaClient, createNodeTransport, createClientCredentialsAuth } from '@portaidentity/sdk/node';

const auth = createClientCredentialsAuth({
  tokenUrl: 'https://porta.local:3443/super-admin/oidc/token',
  clientId: 'my-service',
  clientSecret: 'my-secret',
  scope: 'openid',
});

const transport = createNodeTransport({
  baseUrl: 'https://porta.local:3443/api/admin',
  auth,
});

const client = createPortaClient(transport);

AI Agent Integration

import { createPortaClient, getToolDefinitions, executeTool } from '@portaidentity/sdk/agent';
import { createNodeTransport, createTokenAuth } from '@portaidentity/sdk/node';

// Get tool definitions for LLM function calling
const tools = getToolDefinitions();
// → [{ name: 'organizations.list', description: '...', parameters: [...] }, ...]

// Execute a tool call from an AI agent
const client = createPortaClient(
  createNodeTransport({ baseUrl: '...', auth: createTokenAuth('...') })
);

const result = await executeTool(client, 'organizations.list', { page: 1 });

Domain Namespaces

| Namespace | Methods | Description | |-----------|---------|-------------| | organizations | 12 | CRUD, status lifecycle, slug validation, history | | applications | 13 | CRUD, status, modules management, history | | clients | 12 | CRUD, status, secret management, history | | users | 19 | CRUD, 6 status transitions, password, email, export, purge | | roles | 9 | CRUD, archive, permission assignment | | permissions | 6 | CRUD, archive | | userRoles | 3 | List, assign, remove role assignments | | userClaims | 3 | List, set, remove claim values | | customClaims | 6 | Claim definitions CRUD, archive | | config | 3 | System configuration get/set/list | | keys | 3 | Signing key list/generate/rotate | | audit | 1 | Audit log listing with filters | | stats | 1 | Dashboard statistics | | sessions | 3 | Session listing and revocation | | bulk | 1 | Bulk status operations | | branding | 5 | Org branding settings and asset management | | exports | 1 | CSV/JSON data export | | twoFactor | 3 | 2FA status, disable, reset | | imports | 1 | Declarative provisioning |

Auth Providers

| Provider | Use Case | |----------|----------| | createTokenAuth(token) | Static Bearer token (scripts, testing) | | createClientCredentialsAuth(opts) | Server-to-server OAuth2 (with caching and concurrent dedup) | | createCliAuth(opts) | CLI credentials file (~/.porta/credentials.json) with auto-refresh |

Error Handling

import { PortaNotFoundError, PortaConflictError, PortaHttpError } from '@portaidentity/sdk';

try {
  await client.organizations.get('nonexistent');
} catch (err) {
  if (err instanceof PortaNotFoundError) {
    console.log('Not found:', err.message);
  } else if (err instanceof PortaConflictError) {
    console.log('Conflict — ETag mismatch?');
  } else if (err instanceof PortaHttpError) {
    console.log(`HTTP ${err.status}:`, err.details);
  }
}

Pagination

// Manual pagination
const page1 = await client.users.list('org-id', { page: 1, pageSize: 50 });
// → { data: User[], total: number, page: number, pageSize: number }

// Auto-pagination (fetches all pages)
const allUsers = await client.users.listAll('org-id');
// → User[]

Architecture

@portaidentity/sdk
├── transport/          # HTTP abstraction layer
│   ├── types.ts        # HttpTransport, TransportRequest, TransportResponse
│   ├── browser-transport.ts  # Fetch + CSRF cookies + 401 redirect
│   └── node-transport.ts     # Fetch + Bearer auth + 401 retry
├── auth/               # Authentication providers
│   ├── token-auth.ts   # Static token
│   ├── client-credentials-auth.ts  # OAuth2 client_credentials
│   └── cli-auth.ts     # File-based CLI credentials
├── types/              # SDK-owned entity type definitions
├── domains/            # 19 domain API namespaces
├── errors/             # Typed error hierarchy
├── pagination/         # Pagination types and helpers
├── agent/              # AI agent tool definitions + executor
├── client.ts           # createPortaClient() factory
├── index.ts            # Main entrypoint
├── browser.ts          # Browser-specific entrypoint
├── node.ts             # Node.js-specific entrypoint
└── agent.ts            # Agent-specific entrypoint

Entrypoints

| Import Path | Includes | Excludes | |------------|----------|----------| | @portaidentity/sdk | Types, errors, pagination, client factory | Transport, auth (bring your own) | | @portaidentity/sdk/browser | + BrowserTransport | NodeTransport, auth providers | | @portaidentity/sdk/node | + NodeTransport, all auth providers | BrowserTransport | | @portaidentity/sdk/agent | + Tool definitions, executeTool | Transports, auth |

Testing

# Run all SDK tests (352 tests)
cd packages/porta-sdk && yarn test

# Type checking
yarn typecheck

# Full verify (lint + typecheck + test + build)
yarn verify

License

MIT — See LICENSE for details.