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

perspectapi-ts-sdk

v7.4.0

Published

TypeScript SDK for PerspectAPI - Cloudflare Workers compatible

Readme

PerspectAPI TypeScript SDK

TypeScript SDK for the Perspect public API. The current API and SDK surface is v2.

v1 Is Deprecated

Do not use /api/v1, PerspectApiClient, createPerspectApiClient, or src/client/* for new code.

The v1 API and SDK surface sunsets on 2026-06-01. New integrations must use /api/v2 through PerspectApiV2Client or createPerspectApiV2Client.

Historical v1 examples have been moved to docs/v1-deprecated/sdk-readme.md for migration reference only.

Installation

npm install perspectapi-ts-sdk

Quick Start

Use the v2 subpath when you want the import itself to make the version explicit:

import { createPerspectApiV2Client } from 'perspectapi-ts-sdk/v2';

const client = createPerspectApiV2Client({
  baseUrl: 'https://api.perspect.com',
  apiKey: process.env.PERSPECTAPI_API_KEY!,
});

const site = await client.sites.get('my-site');
console.log(site.id, site.name);

The top-level package also exports v2:

import { createPerspectApiV2Client } from 'perspectapi-ts-sdk';

Common Resources

const content = await client.content.list('my-site', {
  type: 'post',
  status: 'publish',
  limit: 10,
});

const products = await client.products.list('my-site', {
  published: true,
  limit: 20,
});

const contacts = await client.contacts.list('my-site', {
  limit: 20,
});

Email & Newsletters

Send raw or template-based transactional email, and manage email templates, newsletter campaigns, series, and statistics — matching the MCP tool surface.

// Raw send
await client.email.send('my-site', {
  to: '[email protected]',
  subject: 'Hello',
  html: '<p>Hi there</p>',
});

// Template-based send (renders the published `customer_support` template).
// Provide every variable the template references — including any used in its
// subject line. A blank rendered subject is rejected; pass `subject` to
// override, and `strict: true` to fail fast on any missing variable.
await client.email.send('my-site', {
  to: '[email protected]',
  template_type: 'customer_support',
  subject: 'Re: your request',
  variables: {
    support_subject: 'Re: your request',
    support_message_html: '<p>How can we help?</p>',
    support_message_text: 'How can we help?',
  },
  strict: true,
});

// Author and publish an email template
const draft = await client.emailTemplates.create('my-site', {
  template_type: 'newsletter',
  template_name: 'Monthly digest',
  subject_template: '{{campaign_subject}}',
  html_template: '<main>{{{campaign_content_html}}}</main>',
  text_template: '{{campaign_content_text}}',
});
await client.emailTemplates.publish('my-site', draft.id);

// Create and schedule a newsletter campaign.
// Scheduling requires the newsletter plan entitlement AND a key with the
// `newsletters.publish` permission; a plain draft only needs `newsletters.create`.
const campaign = await client.newsletter.createCampaign('my-site', {
  campaign_name: 'July update',
  subject: 'What shipped in July',
  markdown_content: '# Highlights\n\n- ...',
  status: 'scheduled',
  scheduled_at: '2026-07-01T09:00',
  list_ids: ['nll_...'],
});

const stats = await client.newsletter.getStatistics('my-site');

Error Handling

import { PerspectV2Error } from 'perspectapi-ts-sdk/v2';

try {
  await client.products.get('my-site', 'prod_missing');
} catch (error) {
  if (error instanceof PerspectV2Error) {
    console.error(error.type, error.code, error.message);
  }
}

Caching

import {
  createPerspectApiV2Client,
  InMemoryCacheAdapter,
} from 'perspectapi-ts-sdk';

const client = createPerspectApiV2Client({
  baseUrl: process.env.PERSPECTAPI_BASE_URL!,
  apiKey: process.env.PERSPECTAPI_API_KEY!,
  cache: {
    adapter: new InMemoryCacheAdapter(),
    defaultTtlSeconds: 300,
  },
});

API Reference

  • Current SDK entry point: perspectapi-ts-sdk/v2
  • Current REST base path: /api/v2
  • Public docs: https://perspect.com/docs/sdk/typescript/v2-client
  • LLM docs: https://perspect.com/llms.txt

Migration

If you are maintaining existing v1 code, migrate it before 2026-06-01. v1 runtime responses include Deprecation, Sunset, Warning, Link, and X-Perspect-Deprecation-Notice headers, and v1 SDK constructors emit a warning.