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

@tokenscript/token-negotiator-server

v0.2.1

Published

A package for the server side implementation of token negotiator.

Downloads

7

Readme

token-negotiator-server

The Token Negotiator provides the client gateway to connect user digital tokens from on or off chain sources, enabling developers to create bespoke tokenised web experiences.

The Token Negotiator Server extends the capabilities of Token Negotiator for Web Applications Server Side.

Usage

​	​
// Server Side Configuration

import { Server } from "@tokenscript/token-negotiator-server";

const negotiatorServer = new Server({
  issuers: {
    socios: {
      collectionID: string, // to match the client configs collectionID
      consumerKey: string, // your socios API consumer key
      consumerSecret: string, // your socios API consumer secret 
      partnerTag: string, // your socios API partner tag
      redirectURI: string, // your socios API application redirect_uri
      returnToApplicationURL: string, // re-direct on Oauth2 success
    }
  }
});

// example redirectURI configuration end point
app.get("/user-login-callback", async (request, response) => { 

    // retrieve access token
    const accessTokenData = await tokenNegotiatorServer.socios.getAccessToken(request.query.code, response);

    // set token
    tokenNegotiatorServer.utils.setAccessTokenCookie(
      response,
      'socios',
      accessTokenData
    );

    // navigate back to the application page including the wallet provider details.
    response.redirect(`${process.env.SOCIOS_RETURN_TO_APP_URL}`);
});

// example user-balance configuration end point
app.get("/user-balance", cors(), async (request, response) => {
  const output = await tokenNegotiatorServer.socios.getFungibleTokenBalance(request.cookies['tn-oauth2-access-token-socios']);
  response.json(output);
});

// example user-nfts configuration end point
app.get("/user-nfts", cors(), async (request, response) =>{
  const output = await tokenNegotiatorServer.socios.getNonFungibleTokens(request.cookies['tn-oauth2-access-token-socios']);
  response.json(output);
});
​
// Client Side Configuration

import { Client } from "@tokenscript/token-negotiator";

const negotiatorClient = new Client({
  type: "active", // active mode is required to connect to the Socios Wallet
  issuers: [
    onChain: true, // set onChain to true (blockchain tokens via API, Oauth2 flow)
    fungible: true, // set to true / false based on the collection
    chain: "eth", // set to 'eth' for Socios (current version)
    blockchain: "evm", // set to 'evm' for Socios (current version)
    collectionID: "socios", // chose a unique name in your applications issuers to identfiy the tokens from
    contract: "0x3506424F91fD33084466F402d5D97f05F8e3b4AF", // Chiliz Smart Contract
    oAuth2options: {
      consumerKey: "...", // your Socios API consumer key
      redirectURI: "http://localhost:5000/user-login-callback", // your Socios API redirect URI
      partnerTag: "smarttokenlabs", // your Socios API partner tag name
      returnToApplicationURL: "/index.html", // re-direct on Oauth2 success
      endpoints: { // end points to your web application. 
        redirectURI: {
          path: "http://localhost:5000/user-login-callback", // end point to your defined redirect URI (to complete the Oauth2 verification)
          params: {}
        },
        userBalance: {
          path: 'http://localhost:5000/user-balance', // end point to check a users balance
          params: {}
        },
        userNfts: {
          path: 'http://localhost:5000/user-nfts', // end point to check the users NFT balance
          params: {}
        },
        userLogout: {
          path: 'http://localhost:5000/user-logout', // end point to log a user out
          params: {}
        }
      }
    }
  ],
  uiOptions: {
    openingHeading:
      "Open a new world of perks, benefits and opportunities with your Socios tokens.",
    issuerHeading: "Get discount with Socios Tokens",
    repeatAction: "try again",
    position: "top-right"
  }
});

negotiatorClient.negotiate();

negotiatorClient.on("tokens-selected", (tokens) => {
  console.log("tokens-selected", tokens);
});

Documentation

See https://tokenscript.gitbook.io/token-negotiator/