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

senler-sdk

v1.0.0

Published

SDK for Senler API

Downloads

118

Readme

Senler SDK

Tests workflow Build status npm version npm downloads install size

Description

`SenlerSDK' is a TypeScript library for easy interaction with the Senler API. It provides a modular structure for working with various Senler resources, such as subscribers, mailing lists, messages, etc.

Installation

npm

npm install senler-sdk

Usage examples

Initializing the client API

To work with the API, you will need the access_token and vk_group_id of your VKontakte community.

import { SenlerApiClient } from "senler-sdk"

const client = new SenlerApiClient({
  accessToken: "YOUR_ACCESS_TOKEN",
  vkGroupId: "YOUR_VK_GROUP_ID",
})

Get subscribers

client.subscribers.get().then((res) => console.log(res))

Integration with passport

Installation

npm i passport passport-senler

Use api client for get subscribers with received access token

import express from 'express';
import passport from 'passport';
import { SenlerStrategy } from 'passport-senler';

passport.use(
  new SenlerStrategy({
    clientID: 'YOUR_CLIENT_ID',
    clientSecret: 'YOUR_CLIENT_SECRET',
    callbackURL: 'https://yourapp.com/auth/senler/callback',
  })
);

const app = express();


app.get('/auth/senler', passport.authenticate('senler'));


app.get(
  '/auth/senler/callback',
  passport.authenticate('senler', {
    failureRedirect: '/auth/senler/error',
    session: false, // Disable session (senler does not used it)
  }),

  async (req, res) => {
    const client = new SenlerApiClient({
      accessToken: req.accessToken,
      vkGroupId: "YOUR_VK_GROUP_ID",
    })

    res.json(await client.subscribers.get())
  }
);

app.listen(3000, () => {
  console.log('Server is starting on port: 3000');
});

Error handling

To handle errors correctly, use try-catch blocks or .catch() methods.


const client = new SenlerApiClient({
  accessToken: "YOUR_TOKEN",
  vkGroupId: "YOUR_VK_GROUP_ID",
})

const app = express();

app.get('/get', async (_req, res) => {
  try {
    res.json(await client.subscribers.get())
  }
  catch (error: any) {
    res.send(error.message)
  }
});

Errors implemented via success, error_code and error_message (docs) are converted and throws out as an ApiError with the corresponding message.

Logging

Logging is based on pino, you can overwrite the default configuration.

Example:

const loggingConfig = {
  level: 'info',
  destination: pino.destination("./log.log"),
  base: { pid: false },
  transport: {
    target: 'pino-pretty',
    options: {
      colorize: true,
      indent: 4
    }
  }
}
const client = new SenlerApiClient(apiConfig, loggingConfig, retryConfig, cacheConfig);

Retrying

Retrying is based on axios-retry, you can overwrite the default configuration.

Example:

const retryConfig = {
  retries: 3,
  retryDelay(retryCount, error): number {
    return axiosRetry.exponentialDelay(retryCount, error, 100);
  }
}
const client = new SenlerApiClient(apiConfig, loggingConfig, retryConfig, cacheConfig);

Caching

Caching is based on cache-manager:

const cacheConfig = {
  enabled: true,
  manager: createCache({ ttl: 10_000 })
}
const client = new SenlerApiClient(apiConfig, loggingConfig, retryConfig, cacheConfig);

You can also provide custom cache config in any routes:

await client.subscribers.get({count: 30}, cacheConfig)

License

This project is licensed under the MIT license. See LICENSE for details.