0.1.10 • Published 2 months ago

@quyx/fetch v0.1.10

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 months ago

Installation

Install the latest version with npm:

npm install @quyx/fetch

or with yarn:

yarn add @quyx/fetch

Getting Started

1. Instantiate the class

// index.ts
import { Quyx } from "@quyx/fetch";
import dotenv from "dotenv";

dotenv.config();

/**
 * Props: {
 *  apiKey?:  string;
 *  clientId?:  string;
 *  accessToken?:  string;
 *  refreshToken?:  string;
 * }
 * apiKey - Quyx apiKey can be gotten from https://dev.quyx.xyz
 * clientId - Quyx clientId can be gotten from https://dev.quyx.xyz
 * accessToken & refreshToken - To store info about the user, always gotten after calling the 'login' method
 **/
const quyx = new Quyx({ apiKey: process.env.QUYX_API_KEY });

2. Methods on the class

MethodDescriptionPropsResponse
initprepares the SIWE (Sign In With Ethereum) message to be signed by an EOA (Externally Owned Account), to prove ownership before gaining accessQuyxInitPropsSiweMessage
siwechecks and ensures that the wallet connected is the signer of the initialized messageQuyxSIWEPropsQuyxResponse<TokensProps>
whoami (protected)gets the info of the current logged in user--QuyxResponse<QuyxSDKUser>
cards (protected)gets all the cards of the current logged in userPagingPropsQuyxPaginationResponse<QuyxCard[]>
import (protected)updates the card imported by the user (i.e. the user preferred card){_id:string}QuyxResponse<undefined>
findUsergets the info of a user on your Quyx app from their address{address:string}QuyxResponse<QuyxSDKUser>>
allUsersreturns all the users registered on your appPagingPropsQuyxPaginationResponse<QuyxSDKUser[]>
disconnect (protected)*be carefully when calling this method as it will delete the user account off your app--QuyxResponse<undefined>
logout (protected)destroys the current session of the user--QuyxResponse<undefined>

💡 NOTE: for routes with the protected badge, the user accessToken and refreshToken must be passed when creating an instance of the class for this to work

3. Code Examples

// index.ts
import { Quyx } from "@quyx/fetch";
import dotenv from "dotenv";
import { SiweMessage } from "siwe";

dotenv.config();
const apiKey = process.env.QUYX_API_KEY;

/**
 * Props: {
 *  apiKey?:  string;
 *  clientId?:  string;
 *  accessToken?:  string;
 *  refreshToken?:  string;
 * }
 * apiKey - Quyx apiKey can be gotten from https://dev.quyx.xyz
 * clientId - Quyx clientId can be gotten from https://dev.quyx.xyz
 * accessToken & refreshToken - To store info about the user, always gotten after calling the 'login' method
 **/
const quyx = new Quyx({ apiKey });

// init
quyx
  .init({ address: "0x...", chainId: 1 })
  .then((e) => console.log(e))
  .catch((e) => console.error(e));

// siwe
quyx
  .siwe({ address: "0x...", message: new SiweMessage({}), signature: "0x..." })
  .then((e) => console.log(e))
  .catch((e) => console.error(e));

// gotten after calling siwe
let accessToken = "ACCESS_TOKEN_HERE";
let refreshToken = "REFRESH_TOKEN_HERE";

const quyxWithAuth = new Quyx({ apiKey, accessToken, refreshToken });

// whoami
quyx
  .whoami()
  .then((e) => console.log(e))
  .catch((e) => console.error(e));

// .....other methods (refer to documentation for more implemetations)

To run code run this in terminal:

ts-node index.ts

Ensure you have ts-node installed globally inorder for this to work, to install ts-node globally run

npm i -g ts-node
0.1.10

2 months ago

0.1.8

2 months ago

0.1.9

2 months ago

0.1.7

2 months ago

0.1.6

2 months ago

0.1.4

2 months ago

0.1.5

2 months ago

0.1.3

2 months ago

0.1.2

2 months ago

0.1.1

2 months ago