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

cbay-sdk

v0.1.59

Published

cbay sdk 4 browsers

Downloads

14

Readme

cbay-sdk

js sdk 4 interactin' with the official cbay api

installation

npm i cbay-sdk

usage

prelude

import cbay from "cbay-sdk"

imports the sdk factory

const sdk = cbay(opts)

factors a new sdk configurable with opts, particularly:

{
  api: "string", // api base url - default https://api.cbay.nugget.digital/v0
  infura: "string", // infura endpoint - required if usin' sdk.pay(product)
  accessToken: "string", // cognito access token - tokens required 4 post
  refreshToken: "string", // cognito refresh token
  getCognitoUser() {}, // as per amazon-cognito-identity-js
  storeTokens(accessToken, refreshToken) {} // should store fresh tokens
}

getCognitoUser() and storeTokens() may be async

example

import cbay from "cbay-sdk"
const sdk = cbay(/* opts */)

const id = await sdk.post(product)

creates a new product listing

params

product object with the following properties:

{
    category,    // string - c below for valid categories
    title        // string
    description, // string
    units,       // number - u16 > 0
    currency,    // string - symbol - c below for valid currencies
    price,       // number - float - unit price
    payee,       // string - ethereum address or ens name
    contact,     // string - off-chain contact - fx telegram handle
    media        // File[] - optional pics
}

resolves

id string - product id - 8 char lowercase hex string

🗑️ all products+pics are deleted from storage after 7 days

🏁 product posts are rate limited to 1 request per minute and source ip

const products = await sdk.list(category[, since][, limit])

lists the latest product offers in given category - from new 2 old

params

category string c below for valid values

since sth like "2021-10-24T10:55:47.185Z" - from Date#toISOString()

limit uint number

resolves

products product[] c below for particular props of a product

const product = await sdk.get(id)

gets a single product

params

id string - product id - 8 char lowercase hex string

resolves

product c below

list and get return (a) product(s) in the following format:

{
    category,    // string
    title        // string
    description, // string
    units,       // number - u16 > 0
    currency,    // string - symbol
    price,       // number - float - unit price
    payee,       // string - ethereum address or ens name
    contact,     // string - off-chain contact - fx telegram handle
    media,       // string[] - maybe - media object urls pointin' 2 s3
    modifiedAt,  // string - 2021-10-24T10:55:47.185Z
    expiry       // number - timestamp (milliseconds) 4 db auto deletion
}

const bool = sdk.postable(rawProduct)

validates given object for product essentials

const { tx, block } = await sdk.pay(product, units)

pay given product with a transfer of Ethereum or an ERC20 coin

params

product std sdk product

units number - purchase count - int gt 0 and lt 65536

resolves

tx string - tx hash of the corresponding transfer

block number - block height at tx inclusion

await sdk.refresh()

refreshes the internal access token

auto called once after encountering 401 responses while postin' products

await sdk.subscribe(email)

subscribe to the cbay newsletter

params

email user email address

const chains = sdk.Chains

static list of supported blockchain networks (Ethereum only for now)

[
  "mainnet",
  "rinkeby"
]

const cats = sdk.Categories

static list of valid cbay categories

[
  "electronics",
  "vehicles",
  "fashion",
  "home-and-garden",
  "collectibles-and-art",
  "sports",
  "toys",
  "music",
  "business-and-industrial",
  "other"
]

const symbols = sdk.Currencies

static list of valid cbay currencies

[
  "ETH",
  "WETH",
  "DAI",
  "USDC",
  "USDT"
]

const registry = sdk.ERC20Registry

maps symbols of sdk.Currencies to their sdk.Chains erc20 contract addresses incl. token decimals

{
  WETH: {
    mainnet: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
    rinkeby: "0xc778417e063141139fce010982780140aa0cd5ab",
    decimals: 18
  },
  DAI: {
    mainnet: "0x6b175474e89094c44da98b954eedeac495271d0f",
    rinkeby: "0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea",
    decimals: 18
  },
  USDT: {
    mainnet: "0xdac17f958d2ee523a2206206994597c13d831ec7",
    rinkeby: "0x3b00ef435fa4fcff5c209a37d1f3dcff37c705ad",
    decimals: 6
  },
  USDC: {
    mainnet: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
    rinkeby: "0xeb8f08a975ab53e34d8a0330e0d34de942c95926",
    decimals: 6
  }
}

const abi = sdk.ERC20TransferAbi

erc20 transfer function abi

[
  {
    name: "transfer",
    type: "function",
    constant: false,
    payable: false,
    stateMutability: "nonpayable",
    inputs: [
      {
        name: "_to",
        type: "address"
      },
      {
        name: "_value",
        type: "uint256"
      }
    ],
    outputs: [
      {
        name: "",
        type: "bool"
      }
    ]
  }
]

license

MIT