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

@port-experimental/port-sdk

v0.2.3

Published

Type-safe TypeScript SDK for Port.io API (Backend/Server-Side Only)

Downloads

244

Readme

Port SDK for TypeScript/JavaScript

npm version License TypeScript

Type-safe SDK for the Port.io API. Built for Node.js backend environments.

⚠️ Backend Only

This SDK is for backend/server use only. Do not use in browser applications.

✅ Node.js, Express, NestJS, serverless functions
❌ React, Vue, Angular, browser apps


Installation

npm install @port-experimental/port-sdk

Quick Start

import { PortClient } from '@port-experimental/port-sdk';

// Initialize
const client = new PortClient({
  credentials: {
    clientId: process.env.PORT_CLIENT_ID!,
    clientSecret: process.env.PORT_CLIENT_SECRET!,
  },
});

// Use
const blueprints = await client.blueprints.list();
const entity = await client.entities.create({
  identifier: 'my-service',
  blueprint: 'service',
  title: 'My Service',
  properties: {
    stringProps: { environment: 'production' },
  },
});

API Overview

The SDK provides resource-based access:

client.entities    // Create, read, update, delete entities
client.blueprints  // Manage blueprints
client.actions     // Execute actions
client.teams       // Manage teams
client.users       // Manage users
client.webhooks    // Configure webhooks
client.scorecards  // Work with scorecards
client.audit       // Query audit logs

Common Operations

Entities

// Create
const entity = await client.entities.create({
  identifier: 'my-service',
  blueprint: 'service',
  title: 'My Service',
  properties: {
    stringProps: { environment: 'production' },
  },
});

// Get
const service = await client.entities.get('my-service', 'service');

// Update
await client.entities.update('my-service', 'service', {
  properties: { stringProps: { status: 'active' } },
});

// Search
const results = await client.entities.search({
  combinator: 'and',
  rules: [
    { property: '$blueprint', operator: '=', value: 'service' },
    { property: 'environment', operator: '=', value: 'production' },
  ],
});

// Delete
await client.entities.delete('my-service', 'service');

Blueprints

// List all
const blueprints = await client.blueprints.list();

// Get one
const blueprint = await client.blueprints.get('service');

// Create
await client.blueprints.create({
  identifier: 'microservice',
  title: 'Microservice',
  schema: {
    properties: {
      name: { type: 'string', title: 'Name' },
    },
  },
});

Configuration

Environment Variables

PORT_CLIENT_ID=your_client_id
PORT_CLIENT_SECRET=your_client_secret
PORT_REGION=eu              # Optional: eu or us (default: eu)
PORT_LOG_LEVEL=info        # Optional: error, warn, info, debug, trace

Programmatic

const client = new PortClient({
  credentials: {
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret',
  },
  region: 'eu',           // or 'us'
  timeout: 30000,         // Request timeout in ms
  maxRetries: 3,          // Retry attempts
});

Authentication Methods

// OAuth2 (recommended)
credentials: {
  clientId: process.env.PORT_CLIENT_ID!,
  clientSecret: process.env.PORT_CLIENT_SECRET!,
}

// JWT token
credentials: {
  accessToken: 'your-jwt-token',
}

Error Handling

import {
  PortAuthError,
  PortNotFoundError,
  PortValidationError,
  PortRateLimitError,
} from '@port-experimental/port-sdk';

try {
  await client.entities.get('unknown-id', 'service');
} catch (error) {
  if (error instanceof PortNotFoundError) {
    console.log('Entity not found');
  } else if (error instanceof PortAuthError) {
    console.log('Authentication failed');
  } else if (error instanceof PortRateLimitError) {
    console.log('Rate limited');
  }
}

Examples

See the examples/ directory for complete examples:

  • Basic usage
  • Entity CRUD operations
  • Search and filtering
  • Batch operations
  • Error handling

Run an example:

pnpm tsx examples/01-basic-usage.ts

Troubleshooting

Authentication Issues

Error: PortAuthError: Authentication failed

  • Verify credentials in Port.io Settings
  • Check environment variables: PORT_CLIENT_ID, PORT_CLIENT_SECRET
  • Ensure .env file is loaded correctly

Error: PortAuthError: Token refresh failed

  • Generate new API credentials in your Port account

Network Issues

Error: PortNetworkError: Network request failed

  • Check internet connectivity
  • Verify Port API accessibility: curl https://api.port.io/v1/health
  • Check firewall rules (allow HTTPS port 443)

Error: PortTimeoutError: Request timeout

  • Increase timeout: timeout: 60000 (60 seconds)
  • Check network latency

Rate Limiting

Error: PortRateLimitError: Rate limit exceeded

  • SDK automatically retries with Retry-After header
  • Implement custom rate limiting between requests
  • Use batch operations when available

Entity Operations

Error: PortNotFoundError: Entity not found

  • Verify entity exists: await client.entities.list({ blueprint: 'service' })
  • Check blueprint parameter matches
  • Use search to find entities by partial name

Error: PortValidationError: Validation failed

  • Check blueprint schema: await client.blueprints.get('service')
  • Verify property types match (string, number, boolean, array)
  • Ensure related entities exist before creating relations

Debug Mode

Enable verbose logging:

const client = new PortClient({
  credentials: { /* ... */ },
  logger: {
    level: LogLevel.DEBUG,
    enabled: true,
  },
});

Or set environment variable:

export PORT_LOG_LEVEL=debug

Documentation


Support


Contributing

See CONTRIBUTING.md for guidelines.


License

Apache-2.0