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

vonage-wrapper

v0.0.5

Published

A wrapper for the Vonage API

Downloads

5

Readme

⚡ Vonage Wrapper

  1. This is a simple wrapper around the official Vonage Server SDK
  2. Conversation API methods are supported
  3. 🚧 under construction

Installation

pnpm add vonage-wrapper
npm i vonage-wrapper
yarn add vonage-wrapper

Usage

Initialize

import { vonage } from "vonage-wrapper";

const {} = vonage(
  {
    applicationId: "...",
    privateKey: "...",
  },
  options
);

Logger

You can pass your own logger

const options = {
  logger: (level: Level, message: string, details: object) => void
}
type Level = "error" | "fatal" | "warn" | "info" | "debug" | "trace";

...

Or use the default logger

const options = {
  logger: true
}

...

The wrapper takes the same type of arguments that @vonage/server-sdk takes.

const {} = vonage(
  {
    auth: {}, // `@vonage/auth` new Vonage(<...>) arguments
    client: {}, // `@vonage/server-sdk` new Auth(<...>) arguments

    baseUrl: "", // in case you want to use a different vonage server
  },
  options
);

Supported Models

  • Conversation
    • Member
    • Event
  • User
    • Session
    • Conversation
  • Leg

"Only allowed methods were implemented, with a small tweak and defaults"

every supported model has some of the following methods:

// create a single resource
create(...): Promise<...>;

// create multiple resources
createMany(...): Promise<...>;

// get a single resource
find(...): Promise<...>;

// get multiple resources
findMany(...): Promise<...>;

// update a single resource
update(...): Promise<...>;

// update multiple resources
updateMany(...): Promise<...>;

// delete a single resource
delete(...): Promise<...>;

// delete multiple resources
deleteMany(...): Promise<...>;

Every supported model returns a method called run(...) that abstract the API call with validation on the request input and response output in a context of that model and current instance of vonage(...).

you need to pass zod schema for the input and output though.

const customCreate = async (url: string, args: unknown) => {
  // do something with the url and args

  return await conversation.run({
    inputSchema, // set to `z.any()` if you don't want to validate
    outputSchema, // set to `z.any()` if you don't want to validate,
    method: "POST", // or any other HTTP method that vonage allows
    input: args,
    runName: "customCreate", // used for logging, default to "unknown"
    /**
        `url`: string; you can pass a relative url "Ex: /v0.3/conversations", if you do so, the base url will be added automatically, or you can pass a full url "Ex: https://api.nexmo.com/v0.3/conversations"
    */
    url: url,
    token: "", // if you want to pass the token yourself
  });
};

// A little better version of
/**
const customCreate = await fetch(url, {
    method: "POST",
    headers: {
        "Content-Type": "application/json",
        Authorization: token,
    },
    body: JSON.stringify(args)
})
*/

// `customCreate`: z.infer<typeof outputSchema>

interface RunArgs {
  inputSchema: z.ZodTypeAny;
  outputSchema: z.ZodTypeAny;
  url: string;
  input?: unknown;
  method?: HttpMethod;
  runName?: string;
  token?: string;
}

Examples

  • Access nested models
const data = await conversation.member.findMany();
  • Provide token for 'Authorization' header yourself
const { getToken, conversation } = vonage(...);

// You can cache the token or do whatever you want
const token = await getToken();

const data = await conversation.find(..., token);
  • Use the original Vonage client and Auth instances
const { client, auth } = vonage(...);

const newMessage = await client.sms.send({...});

// `newMessage`: SendSMSResponse type coming from @vonage/server-sdk


const hash = await auth.createSignatureHash({...});

// `hash`: AuthSignedParams type coming from @vonage/auth