From 992b288e0ec41642547f22ba44b3ffaebaad3d24 Mon Sep 17 00:00:00 2001 From: Am-Coder Date: Mon, 28 Feb 2022 22:13:54 +0530 Subject: [PATCH] naas client test --- .npmignore | 1 - package.json | 12 +- src/client/onec-client.js | 183 ++++++++++++++++++++++++++ src/index.js | 2 +- src/{ => web}/AuthUtils/WalletAuth.js | 2 +- webpack.config.js | 4 +- 6 files changed, 195 insertions(+), 9 deletions(-) create mode 100644 src/client/onec-client.js rename src/{ => web}/AuthUtils/WalletAuth.js (99%) diff --git a/.npmignore b/.npmignore index 16a112b..775d564 100644 --- a/.npmignore +++ b/.npmignore @@ -1,5 +1,4 @@ node_modules/ -src # Ignore files with sensitive environment variables .env .env.test diff --git a/package.json b/package.json index 9a94d31..2ed293a 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,12 @@ { - "name": "onec-sdk", - "version": "0.1.5", - "description": "Onec Client NPM Package", - "main": "./dist/onec-client.bundle.js", + "name": "ceno-test", + "version": "0.3.1", + "description": "ceno Client NPM Package", + "main": "./dist/onec-sdk.bundle.js", + "exports": { + ".": "./dist/onec-sdk.bundle.js", + "./client": "./src/client/onec-client.js" + }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "webpack --mode=development", diff --git a/src/client/onec-client.js b/src/client/onec-client.js new file mode 100644 index 0000000..01c62f2 --- /dev/null +++ b/src/client/onec-client.js @@ -0,0 +1,183 @@ +var constants = require("../constants"); +var axios = require('axios'); + +const ONEC_AUTH_USERS_BASE_URL = constants.ONEC_NAAS_BASE_URL + +class naas { + constructor(api_key) { + this.api_key = api_key; + } + + async mintNFT(data) { + const url = `${ONEC_AUTH_USERS_BASE_URL}mintNFT/` + const resData = await axios.post(url, data, { + headers: { + "Content-Type": "application/json", + "NAAS-APIKEY": this.api_key + } + }) + .then((response) => { + return response.data; + }) + + return resData + } + + async mintRefNFT(data) { + const url = `${ONEC_AUTH_USERS_BASE_URL}mintRefNFT/` + const resData = await axios.post(url, data, { + headers: { + "Content-Type": "application/json", + "NAAS-APIKEY": this.api_key + } + }) + .then((response) => { + return response.data; + }) + + return resData + } + + async checkMintStatus(txn_tracker) { + const url = `${ONEC_AUTH_USERS_BASE_URL}checkMintStatus/${txn_tracker}/` + const resData = await axios.get(url, { + headers: { + "Content-Type": "application/json", + "NAAS-APIKEY": this.api_key + } + }) + .then((response) => { + return response.data; + }) + + return resData + } + + async fetchTokenID(nft_id) { + const url = `${ONEC_AUTH_USERS_BASE_URL}fetchTokenId/${nft_id}/` + const resData = await axios.get(url, { + headers: { + "Content-Type": "application/json", + "NAAS-APIKEY": this.api_key + } + }) + .then((response) => { + return response.data; + }) + + return resData + } + + async fetchRefTokenID(refnft_id) { + const url = `${ONEC_AUTH_USERS_BASE_URL}fetchRefTokenId/${refnft_id}/` + const resData = await axios.get(url, { + headers: { + "Content-Type": "application/json", + "NAAS-APIKEY": this.api_key + } + }) + .then((response) => { + return response.data; + }) + + return resData + } + + async getTokenMetadataHash(token_id) { + const url = `${ONEC_AUTH_USERS_BASE_URL}getTokenMetadataHash/${token_id}/` + const resData = await axios.get(url, { + headers: { + "Content-Type": "application/json", + "NAAS-APIKEY": this.api_key + } + }) + .then((response) => { + return response.data; + }) + + return resData + } + + async getRefNFTs(parent_id) { + const url = `${ONEC_AUTH_USERS_BASE_URL}getRefNFTs/${parent_id}/` + const resData = await axios.get(url, { + headers: { + "Content-Type": "application/json", + "NAAS-APIKEY": this.api_key + } + }) + .then((response) => { + return response.data; + }) + + return resData + } + + async getIpfsFiles() { + const url = `${ONEC_AUTH_USERS_BASE_URL}ipfsFile/` + const resData = await axios.get(url, { + headers: { + "Content-Type": "application/json", + "NAAS-APIKEY": this.api_key + } + }) + .then((response) => { + return response.data; + }) + + return resData + } + + async uploadIpfsFiles(files) { + const url = `${ONEC_AUTH_USERS_BASE_URL}ipfsFile/` + const resData = await axios.post(url, files, { + headers: { + "Content-Type": "multipart/form-data", + "NAAS-APIKEY": this.api_key + } + }) + .then((response) => { + return response.data; + }) + + return resData + } + + async getIpfsMetaData() { + const url = `${ONEC_AUTH_USERS_BASE_URL}ipfsMetaData/` + const resData = await axios.get(url, { + headers: { + "Content-Type": "application/json", + "NAAS-APIKEY": this.api_key + } + }) + .then((response) => { + return response.data; + }) + + return resData + } + + async uploadIpfsMetaData(data) { + const url = `${ONEC_AUTH_USERS_BASE_URL}ipfsMetaData/` + const resData = await axios.post(url, data, { + headers: { + "Content-Type": "application/json", + "NAAS-APIKEY": this.api_key + } + }) + .then((response) => { + return response.data; + }) + + return resData + } + + verifyKey() { + return this.api_key + } +} + +module.exports = { + naas +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 46b35aa..39e91c5 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import { withWalletConnect, withMetamask } from "./AuthUtils/WalletAuth"; +import { withWalletConnect, withMetamask } from "./web/AuthUtils/WalletAuth"; const auth = { withMetamask, diff --git a/src/AuthUtils/WalletAuth.js b/src/web/AuthUtils/WalletAuth.js similarity index 99% rename from src/AuthUtils/WalletAuth.js rename to src/web/AuthUtils/WalletAuth.js index 84cf94b..caf64f6 100644 --- a/src/AuthUtils/WalletAuth.js +++ b/src/web/AuthUtils/WalletAuth.js @@ -2,7 +2,7 @@ import MetaMaskOnboarding from '@metamask/onboarding'; import WalletConnect from "@walletconnect/client"; import QRCodeModal from "@walletconnect/qrcode-modal"; import axios, { AxiosResponse, AxiosError } from 'axios'; -import * as constants from "../constants" +import * as constants from "../../constants" let ONEC_AUTH_USERS_BASE_URL = constants.ONEC_NAAS_BASE_URL; let _mmConnector = null; diff --git a/webpack.config.js b/webpack.config.js index 0e8060d..bc45772 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -6,9 +6,9 @@ module.exports = { output: { path: path.resolve(__dirname, 'dist'), clean: true, - filename: 'onec-client.bundle.js', + filename: 'onec-sdk.bundle.js', library: { - name: 'onec', + name: 'onec-sdk', type: 'umd', umdNamedDefine: true, export: 'default',