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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@team-plain/typescript-sdk

v4.2.2

Published

Typescript SDK for Plain's Core GraphQL API

Downloads

15,392

Readme

@team-plain/typescript-sdk

Changelog

Plain Client

This is the typescript/node SDK for Plain.com's Core GraphQL API. It makes it easy to make common API calls in just a few lines of code.

If you run into any issues please open an issue or get in touch with us at [email protected].

Basic example

import { PlainClient } from '@team-plain/typescript-sdk';

const client = new PlainClient({
  apiKey: 'plainApiKey__tmRD_xF5qiMH0657LkbLCC1maN4hLsBIbyOgjqEP4w',
});

const result = await client.getCustomerById({ customerId: 'c_01GHC4A88A9D49Q30AAWR3BN7P' });

if (result.error) {
  console.log(result.error);
} else {
  console.log(result.data.fullName);
}

You can find out how to make an API key in our documentation: https://docs.plain.com/core-api/authentication

Documentation

Every method in the SDK corresponds to a graphql query or mutation.

You can find the generated documentation here:

Documentation

If you would like to add a query or mutation please open an issue and we can add it for you.

Error handling

Every SDK method will return an object with either data or an error.

You will either receive an error or data, never both.

Here is an example:

const client = new PlainClient({
  apiKey: 'plainApiKey__tmRD_xF5qiMH0667LkbLCC1maN2hLsBIbyOgjqEP4w',
});

function doThing() {
  const result = await client.getCustomerById({ customerId: 'c_01GHC4A88A9D49Q30AAWR3BN7P' });

  if (result.error) {
    console.log(result.error);
  } else {
    console.log(result.data.fullName);
  }
}

An error can be one of the below:

MutationError

(view source) This is the richest error type. It is called MutationError since it maps to the MutationError type in our GraphQL schema and is returned as part of every mutation in our API.

You can view the full details of this error under errorDetails.

Every mutation error will contain:

  • message: an English technical description of the error. This error is usually meant to be read by a developer and not an end user.
  • type: one of VALIDATION, FORBIDDEN, INTERNAL. See MutationErrorType for a description of each value.
  • code: a unique error code for each type of error returned. This code can be used to provide a localized or user-friendly error message. You can find the list of error codes in our docs .
  • fields: an array containing all the fields that errored. Each field:
    • field: the name of the input field the error is for
    • message: an English technical description of the error. This error is usually meant to be read by a developer and not an end user. type: one of VALIDATION, REQUIRED, NOT_FOUND. See Error codes in our docs for a description of each value.
BadRequestError

(view source) Equivalent to a 400 response. If you are using typescript it's unlikely you will run into this since types will prevent this but if you are using javascript this likely means you are providing a wrong input/argument to a query or mutation.

ForbiddenError

(view source) Equivalent to a 401 or 403 response. Normally means your API key doesn't exist or that you are trying to query something that you do not have permissions for.

InternalServerError

(view source) Equivalent to a 500 response. If this happens something unexpected within Plain happened.

UnknownError

(view source) Fallback error type when something unexpected happens.

Webhooks

This package also provides functionality to validate our Webhook payloads.

import { parsePlainWebhook } from '@team-plain/typescript-sdk';

const payload = { ... };

if(parsePlainWebhook(payload)) {
  // payload is now typed!
  doYourThing(payload);
}

Contributing

When submitting a PR, remember to run pnpm changeset and provide an easy to understand description of the changes you're making so that the changelog is populated.

When a PR with a changelog is merged a separate PR will be automatically raised which rolls up any merged changes and handles assigning a new version for release and publishing to NPM.