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

osl-kustomer-archiver

v1.1.0

Published

Remove old conversations from Kustomer. Preserve stats to Google Sheets. Records an event log

Downloads

6

Readme

osl-kustomer-archiver

Remove old conversations from Kustomer. Preserves stats to Google Sheets. Keeps an event log of what was done.

Prerequisites

  • Node.js v16.15.0 or later
  • npm v8.5.5 or later (included with Node.js)

Setup

Kustomer API:

  • API Key with the following 4 roles:
    • org.permission.conversation.delete
    • org.permission.conversation.read
    • org.permission.search_execution.create
    • org.permission.tag.read

Kustomer Saved Search:

  • Make a Saved Search, and remember to make it publicly viewable in it's settings. Note it's ID (taken from the URL when you edit it) which is used in the config.json

Google API:

  • Setup a new Google Project and create a "Service account", with this guide:

Google Developers Console

image

https://theoephraim.github.io/node-google-spreadsheet/#/getting-started/authentication?id=service-account

image

Google Sheets

  • Create a new Google Sheet
  • Name one of the sheet tabs to "import", and another to "event_log":

image

If you protect the sheets, make sure to give the Google Service Account permission to edit!

  • On the "import" sheet tab, set columns B, E & F to be a datetime format of your choice
  • On the "event_log" sheet tab, set column B to be a datetime format of your choice
  • Share the google sheet with the Service Account email address as per the Google API Guide

Node.js

In your Node.js working directory install the package:

npm -i osl-kustomer-archiver

Copy ./config/config.template.json file to ./config/config.json and edit the values.

Most are self-explanatory.

Firstly, set ENVIRONMENT.NAME accordingly.

If there is an unexpected error, setting DEBUG_MODE to true will show some verbose variable information in the terminal output.

To execute a saved-search in Kustomer, you need to aquire a CSRF token from the frontend request when testing the saved search, since they are not accisible directly through the API. This can easily be aquired using devtools, and looking for the "/execute" request

The SHEET_ID is simply the id in the URL when you open the google sheet: https://docs.google.com/spreadsheets/d/ THIS_PART_HERE /edit

{
  "ENVIRONMENT": {
    "NAME": "My Environment",
    "DEBUG_MODE": false
  },
  "KUSTOMER": {
    "API_KEY": "Get from Kustomer settings",
    "HEADER_CSRF_TOKEN": "Copy from frontend request",
    "COOKIE_CSRF_TOKEN": "Copy from frontend request",
    "SAVED_SEARCH_ID": "Get from the URL when editing a Saved Search"
  },
  "GOOGLE": {
    "SERVICE_ACCOUNT_EMAIL": "copied from service account credentials generated by google",
    "PRIVATE_KEY": "copied from service account credentials generated by google",
    "SHEET_ID": "the long ID in the sheets URL"
  }
}

Included Dependancies:

Usage

Run manually:

node index.js

OR

npm start

Run periodically:

  • Open crontab
$ crontab -e

Every Hour

0 * * * * node /path/to/this/repo/index.js >/dev/null 2>&1

2pm Every Day

0 14 * * * node /path/to/this/repo/index.js >/dev/null 2>&1