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

absin-points-sdk

v1.0.5

Published

The `PointsSDK` is a TypeScript library for managing points and events for users. This SDK allows clients to issue points for their users, providing the ultimate flexibility to issue points for off-chain actions.

Downloads

3

Readme

PointsSDK

The PointsSDK is a TypeScript library for managing points and events for users. This SDK allows clients to issue points for their users, providing the ultimate flexibility to issue points for off-chain actions.

Features

  • Register for an API key
  • Initialize the points client with an API key and a unique identifier for a campaign
  • Distribute points to a specific address
  • Get points for a specific address
  • Get points for a specific address filtered by event name
  • Update and get event metadata

Installation

Install the required dependencies:

npm install

Usage

Initialization

First, initialize the PointsSDK with your PostgreSQL configuration:

import PointsSDK from './PointsSDK';
import { PoolConfig } from 'pg';

const poolConfig: PoolConfig = {
  user: 'yourDatabaseUser',
  host: 'yourDatabaseHost',
  database: 'yourDatabaseName',
  password: 'yourDatabasePassword',
  port: 5432,
};

const pointsSDK = new PointsSDK(poolConfig);

Register for an API Key

Register a new API key:

const { apiKey } = await pointsSDK.registerApiKey();
console.log('New API Key:', apiKey);

Register a Project

Register a new project with an API key:

const { apiKey, campaignId } = await pointsSDK.registerProject(apiKey);
console.log('API Key:', apiKey);
console.log('Campaign ID:', campaignId);

Distribute Points

Distribute points to a specific address:

const pointsData = { points: 100, address: '0xYourEVMAddress' };
await pointsSDK.distribute(apiKey, 'eventName', pointsData);
console.log('Points distributed successfully');

Get Points for an Address

Retrieve points for a specific address:

const points = await pointsSDK.getPoints('0xYourEVMAddress');
console.log('Points:', points);

Get Points for an Address by Event

Retrieve points for a specific address filtered by event name:

const points = await pointsSDK.getPointsByEvent('0xYourEVMAddress', 'eventName');
console.log('Points by Event:', points);

Update Event Metadata

Update the metadata for an event:

const eventData = { timestamp: Date.now(), metadata: 'Sample metadata' };
await pointsSDK.updateEventMetadata(apiKey, 'eventName', eventData);
console.log('Event metadata updated successfully');

Get Event Metadata

Retrieve the metadata for an event:

const eventMetadata = await pointsSDK.getEventMetadata('eventName');
console.log('Event Metadata:', eventMetadata);

Tables Schema

To create the required tables in PostgreSQL, use the following schema:

CREATE TABLE apikey_table (
  api_key VARCHAR(24) PRIMARY KEY
);

CREATE TABLE project_table (
  api_key VARCHAR(24) REFERENCES apikey_table(api_key),
  campaign_id VARCHAR(16) NOT NULL,
  PRIMARY KEY (api_key, campaign_id)
);

CREATE TABLE point_table (
  api_key VARCHAR(24) REFERENCES project_table(api_key),
  event_name VARCHAR NOT NULL,
  points INT NOT NULL CHECK (points > 0),
  address VARCHAR(42) NOT NULL,
  PRIMARY KEY (api_key, event_name, address)
);

CREATE TABLE event_table (
  api_key VARCHAR(24) REFERENCES project_table(api_key),
  event_name VARCHAR NOT NULL,
  timestamp BIGINT NOT NULL,
  metadata TEXT NOT NULL,
  PRIMARY KEY (api_key, event_name)
);

Sample Data

To insert sample data into the tables:

INSERT INTO apikey_table (api_key) VALUES ('sampleApiKey');

INSERT INTO project_table (api_key, campaign_id) VALUES ('sampleApiKey', 'sampleCampaignId');

INSERT INTO point_table (api_key, event_name, points, address) VALUES ('sampleApiKey', 'sampleEvent', 100, '0xSampleAddress');

INSERT INTO event_table (api_key, event_name, timestamp, metadata) VALUES ('sampleApiKey', 'sampleEvent', 1627885442, 'Sample metadata for event');

Error Handling

The SDK methods throw errors when operations fail. Use try-catch blocks to handle these errors gracefully:

try {
  const { apiKey } = await pointsSDK.registerApiKey();
  console.log('New API Key:', apiKey);
} catch (err) {
  console.error('Error:', err.message);
}

Deployed Test Backend

Absin Backend

Deployed Test Frontend

Absin Frontend