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

constant-contact-v3

v1.0.4

Published

Constant Contact v3 API client

Downloads

7

Readme

constant-contact-v3

Constant Contact API v3 client for server JavaScript. Requires Node >= 18, or any runtime that supports fetch and either Buffer or btoa. Fully typed with TypeScript, based on Constant Contact's OpenAPI spec. Initially generated using swagger-typescript-api, then modified to add authentication support.

This library will automatically handle refreshing tokens as long as the token remains in memory. You can also provide a callback function to persist the token.

Installation

npm install constant-contact-v3

yarn install constant-contact-v3

pnpm install constant-contact-v3

Options

clientId - Your Constant Contact API key. clientSecret - Your Constant Contact API secret. token - Optional. An existing token to use for authentication. Token is in the format ConstantContactToken. onTokenUpdate - Optional. A callback function that will be called when the token is updated. This is useful for persisting the token. enableThrows - Optional. If true, the client will throw an error when the API returns an error. If false, the client will return the error as part of the response object. The default is false.

export type ConstantContactOptions = {
  clientId: string;
  clientSecret: string;
  token?: ConstantContactToken;
  onTokenUpdate?: (token: ConstantContactToken) => void;
  enableThrows?: boolean;
};

Usage

Before using any of the main routes, you need to acquire an access token. constant-contact-v3 provides all the functions needed for the Authorization Code Flow. Other flows are not currently supported, but would be trivial to add if you are so inclined.

import { ConstantContact } from 'constant-contact-v3';

const api = new ConstantContact({
  clientId: 'YOUR_CLIENT_ID',
  clientSecret: 'YOUR_CLIENT_SECRET',
  onTokenUpdate: token => saveToken(token),
});

const uri = api.oAuth.getAuthorizationURL({
  redirectUri: 'http://localhost:3000/callback',
  state: 'some-state',
  responseType: 'code',
  scope: [
    'account_read',
    'account_update',
    'campaign_data',
    'contact_data',
    'offline_access',
  ],
});

// then redirect the user to the uri. upon return, you will have a code that you can use to get a token.
const code = 'YOUR_CODE';

const tokenRes = await api.oAuth.exchangeAuthorizationCode(
  code,
  environment.constantContact.redirectUri,
);
if (!tokenRes.ok) throw new Error('Failed to exchange code for token');

// then you are ready to go!

constant-contact-v3 will automatically refresh the token as needed. It is saved in the class instance of ConstantContact, so you must create multiple to handle multiple users.

Future Work

  • Add support for other OAuth flows.