From ca50280abffbf9f3f929de19aaade34f8a47559a Mon Sep 17 00:00:00 2001 From: Feng Yu Date: Tue, 12 Sep 2023 16:43:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20add=20ncc=20build=20?= =?UTF-8?q?for=20socios-oauth2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- socios-oauth2/.gitignore | 3 +- socios-oauth2/app.js | 34 +++++----- socios-oauth2/package-lock.json | 112 ++++++++++++++++++++++++++++++-- socios-oauth2/package.json | 4 +- 4 files changed, 128 insertions(+), 25 deletions(-) diff --git a/socios-oauth2/.gitignore b/socios-oauth2/.gitignore index 1a1558e37..3eb23a34f 100644 --- a/socios-oauth2/.gitignore +++ b/socios-oauth2/.gitignore @@ -1,2 +1,3 @@ .ENV -node_modules \ No newline at end of file +node_modules +dist/ diff --git a/socios-oauth2/app.js b/socios-oauth2/app.js index 3fab41dfd..13dc36df0 100644 --- a/socios-oauth2/app.js +++ b/socios-oauth2/app.js @@ -1,11 +1,11 @@ import path from "path"; import express from "express"; import { Server } from "@tokenscript/token-negotiator-server"; -import { fileURLToPath } from 'url'; +import { fileURLToPath } from "url"; import bodyParser from "body-parser"; import cookieParser from "cookie-parser"; -import cors from 'cors'; -import 'dotenv/config' +import cors from "cors"; +import "dotenv/config"; const app = express(); const port = 5000; @@ -17,7 +17,7 @@ const __dirname = path.dirname(__filename); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.use(cookieParser()); -app.use(express.static("public")); +app.use(express.static(path.join(__dirname, "public"))); const tokenNegotiatorServer = new Server({ issuers: { @@ -28,23 +28,25 @@ const tokenNegotiatorServer = new Server({ partnerTag: process.env.SOCIOS_PARTNER_TAG, redirectURI: process.env.SOCIOS_REDIRECT_URI, returnToApplicationURL: process.env.SOCIOS_RETURN_TO_APP_URL, - } - } + }, + }, }); -const corsOptions = { origin: process.env.APPLICATION_URL } +const corsOptions = { origin: process.env.APPLICATION_URL }; app.get("/", function (request, response) { response.sendFile(path.join(__dirname, "./public/index.html")); }); app.get("/user-login-callback", async (request, response) => { - - const accessTokenData = await tokenNegotiatorServer.socios.getAccessToken(request.query.code, response); + const accessTokenData = await tokenNegotiatorServer.socios.getAccessToken( + request.query.code, + response + ); tokenNegotiatorServer.utils.setAccessTokenCookie( response, - 'socios', + "socios", accessTokenData ); @@ -53,17 +55,17 @@ app.get("/user-login-callback", async (request, response) => { }); app.get("/user-balance", cors(corsOptions), async (request, response) => { - const output = await tokenNegotiatorServer.socios.getFungibleTokenBalance(request.cookies['tn-oauth2-access-token-socios']); + const output = await tokenNegotiatorServer.socios.getFungibleTokenBalance( + request.cookies["tn-oauth2-access-token-socios"] + ); response.json(output); }); app.get("/user-nfts", cors(corsOptions), async (request, response) => { - const output = await tokenNegotiatorServer.socios.getNonFungibleTokens(request.cookies['tn-oauth2-access-token-socios']); + const output = await tokenNegotiatorServer.socios.getNonFungibleTokens( + request.cookies["tn-oauth2-access-token-socios"] + ); response.json(output); }); app.listen(port, () => console.info(`App listening on port ${port}`)); - - - - diff --git a/socios-oauth2/package-lock.json b/socios-oauth2/package-lock.json index 3bbc23051..6f552c30d 100644 --- a/socios-oauth2/package-lock.json +++ b/socios-oauth2/package-lock.json @@ -20,6 +20,7 @@ "node-fetch": "^3.3.2" }, "devDependencies": { + "@vercel/ncc": "^0.38.0", "nodemon": "^2.0.4" } }, @@ -2389,6 +2390,14 @@ "node": ">=6" } }, + "node_modules/@sentry/core/node_modules/@sentry/types": { + "version": "5.30.0", + "resolved": "https://registry.npmmirror.com/@sentry/types/-/types-5.30.0.tgz", + "integrity": "sha512-R8xOqlSTZ+htqrfteCWU5Nk0CDN5ApUTvrlvBuiH1DyP6czDZ4ktbZB0hAgBlVcK0U+qpD3ag3Tqqpa5Q67rPw==", + "engines": { + "node": ">=6" + } + }, "node_modules/@sentry/core/node_modules/tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -2407,6 +2416,14 @@ "node": ">=6" } }, + "node_modules/@sentry/hub/node_modules/@sentry/types": { + "version": "5.30.0", + "resolved": "https://registry.npmmirror.com/@sentry/types/-/types-5.30.0.tgz", + "integrity": "sha512-R8xOqlSTZ+htqrfteCWU5Nk0CDN5ApUTvrlvBuiH1DyP6czDZ4ktbZB0hAgBlVcK0U+qpD3ag3Tqqpa5Q67rPw==", + "engines": { + "node": ">=6" + } + }, "node_modules/@sentry/hub/node_modules/tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -2425,6 +2442,14 @@ "node": ">=6" } }, + "node_modules/@sentry/minimal/node_modules/@sentry/types": { + "version": "5.30.0", + "resolved": "https://registry.npmmirror.com/@sentry/types/-/types-5.30.0.tgz", + "integrity": "sha512-R8xOqlSTZ+htqrfteCWU5Nk0CDN5ApUTvrlvBuiH1DyP6czDZ4ktbZB0hAgBlVcK0U+qpD3ag3Tqqpa5Q67rPw==", + "engines": { + "node": ">=6" + } + }, "node_modules/@sentry/minimal/node_modules/tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -2449,6 +2474,14 @@ "node": ">=6" } }, + "node_modules/@sentry/node/node_modules/@sentry/types": { + "version": "5.30.0", + "resolved": "https://registry.npmmirror.com/@sentry/types/-/types-5.30.0.tgz", + "integrity": "sha512-R8xOqlSTZ+htqrfteCWU5Nk0CDN5ApUTvrlvBuiH1DyP6czDZ4ktbZB0hAgBlVcK0U+qpD3ag3Tqqpa5Q67rPw==", + "engines": { + "node": ">=6" + } + }, "node_modules/@sentry/node/node_modules/cookie": { "version": "0.4.2", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", @@ -2477,17 +2510,27 @@ "node": ">=6" } }, + "node_modules/@sentry/tracing/node_modules/@sentry/types": { + "version": "5.30.0", + "resolved": "https://registry.npmmirror.com/@sentry/types/-/types-5.30.0.tgz", + "integrity": "sha512-R8xOqlSTZ+htqrfteCWU5Nk0CDN5ApUTvrlvBuiH1DyP6czDZ4ktbZB0hAgBlVcK0U+qpD3ag3Tqqpa5Q67rPw==", + "engines": { + "node": ">=6" + } + }, "node_modules/@sentry/tracing/node_modules/tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" }, "node_modules/@sentry/types": { - "version": "5.30.0", - "resolved": "https://registry.npmjs.org/@sentry/types/-/types-5.30.0.tgz", - "integrity": "sha512-R8xOqlSTZ+htqrfteCWU5Nk0CDN5ApUTvrlvBuiH1DyP6czDZ4ktbZB0hAgBlVcK0U+qpD3ag3Tqqpa5Q67rPw==", + "version": "7.68.0", + "resolved": "https://registry.npmmirror.com/@sentry/types/-/types-7.68.0.tgz", + "integrity": "sha512-5J2pH1Pjx/029zTm3CNY9MaE8Aui81nG7JCtlMp7uEfQ//9Ja4d4Sliz/kV4ARbkIKUZerSgaRAm3xCy5XOXLg==", + "optional": true, + "peer": true, "engines": { - "node": ">=6" + "node": ">=8" } }, "node_modules/@sentry/utils": { @@ -2502,6 +2545,14 @@ "node": ">=6" } }, + "node_modules/@sentry/utils/node_modules/@sentry/types": { + "version": "5.30.0", + "resolved": "https://registry.npmmirror.com/@sentry/types/-/types-5.30.0.tgz", + "integrity": "sha512-R8xOqlSTZ+htqrfteCWU5Nk0CDN5ApUTvrlvBuiH1DyP6czDZ4ktbZB0hAgBlVcK0U+qpD3ag3Tqqpa5Q67rPw==", + "engines": { + "node": ">=6" + } + }, "node_modules/@sentry/utils/node_modules/tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -2888,6 +2939,15 @@ "@types/node": "*" } }, + "node_modules/@vercel/ncc": { + "version": "0.38.0", + "resolved": "https://registry.npmmirror.com/@vercel/ncc/-/ncc-0.38.0.tgz", + "integrity": "sha512-B4YKZMm/EqMptKSFyAq4q2SlgJe+VCmEH6Y8gf/E1pTlWbsUJpuH1ymik2Ex3aYO5mCWwV1kaSYHSQOT8+4vHA==", + "dev": true, + "bin": { + "ncc": "dist/ncc/cli.js" + } + }, "node_modules/@walletconnect/browser-utils": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/@walletconnect/browser-utils/-/browser-utils-1.8.0.tgz", @@ -12076,6 +12136,11 @@ "tslib": "^1.9.3" }, "dependencies": { + "@sentry/types": { + "version": "5.30.0", + "resolved": "https://registry.npmmirror.com/@sentry/types/-/types-5.30.0.tgz", + "integrity": "sha512-R8xOqlSTZ+htqrfteCWU5Nk0CDN5ApUTvrlvBuiH1DyP6czDZ4ktbZB0hAgBlVcK0U+qpD3ag3Tqqpa5Q67rPw==" + }, "tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -12093,6 +12158,11 @@ "tslib": "^1.9.3" }, "dependencies": { + "@sentry/types": { + "version": "5.30.0", + "resolved": "https://registry.npmmirror.com/@sentry/types/-/types-5.30.0.tgz", + "integrity": "sha512-R8xOqlSTZ+htqrfteCWU5Nk0CDN5ApUTvrlvBuiH1DyP6czDZ4ktbZB0hAgBlVcK0U+qpD3ag3Tqqpa5Q67rPw==" + }, "tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -12110,6 +12180,11 @@ "tslib": "^1.9.3" }, "dependencies": { + "@sentry/types": { + "version": "5.30.0", + "resolved": "https://registry.npmmirror.com/@sentry/types/-/types-5.30.0.tgz", + "integrity": "sha512-R8xOqlSTZ+htqrfteCWU5Nk0CDN5ApUTvrlvBuiH1DyP6czDZ4ktbZB0hAgBlVcK0U+qpD3ag3Tqqpa5Q67rPw==" + }, "tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -12133,6 +12208,11 @@ "tslib": "^1.9.3" }, "dependencies": { + "@sentry/types": { + "version": "5.30.0", + "resolved": "https://registry.npmmirror.com/@sentry/types/-/types-5.30.0.tgz", + "integrity": "sha512-R8xOqlSTZ+htqrfteCWU5Nk0CDN5ApUTvrlvBuiH1DyP6czDZ4ktbZB0hAgBlVcK0U+qpD3ag3Tqqpa5Q67rPw==" + }, "cookie": { "version": "0.4.2", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", @@ -12157,6 +12237,11 @@ "tslib": "^1.9.3" }, "dependencies": { + "@sentry/types": { + "version": "5.30.0", + "resolved": "https://registry.npmmirror.com/@sentry/types/-/types-5.30.0.tgz", + "integrity": "sha512-R8xOqlSTZ+htqrfteCWU5Nk0CDN5ApUTvrlvBuiH1DyP6czDZ4ktbZB0hAgBlVcK0U+qpD3ag3Tqqpa5Q67rPw==" + }, "tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -12165,9 +12250,11 @@ } }, "@sentry/types": { - "version": "5.30.0", - "resolved": "https://registry.npmjs.org/@sentry/types/-/types-5.30.0.tgz", - "integrity": "sha512-R8xOqlSTZ+htqrfteCWU5Nk0CDN5ApUTvrlvBuiH1DyP6czDZ4ktbZB0hAgBlVcK0U+qpD3ag3Tqqpa5Q67rPw==" + "version": "7.68.0", + "resolved": "https://registry.npmmirror.com/@sentry/types/-/types-7.68.0.tgz", + "integrity": "sha512-5J2pH1Pjx/029zTm3CNY9MaE8Aui81nG7JCtlMp7uEfQ//9Ja4d4Sliz/kV4ARbkIKUZerSgaRAm3xCy5XOXLg==", + "optional": true, + "peer": true }, "@sentry/utils": { "version": "5.30.0", @@ -12178,6 +12265,11 @@ "tslib": "^1.9.3" }, "dependencies": { + "@sentry/types": { + "version": "5.30.0", + "resolved": "https://registry.npmmirror.com/@sentry/types/-/types-5.30.0.tgz", + "integrity": "sha512-R8xOqlSTZ+htqrfteCWU5Nk0CDN5ApUTvrlvBuiH1DyP6czDZ4ktbZB0hAgBlVcK0U+qpD3ag3Tqqpa5Q67rPw==" + }, "tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -12518,6 +12610,12 @@ "@types/node": "*" } }, + "@vercel/ncc": { + "version": "0.38.0", + "resolved": "https://registry.npmmirror.com/@vercel/ncc/-/ncc-0.38.0.tgz", + "integrity": "sha512-B4YKZMm/EqMptKSFyAq4q2SlgJe+VCmEH6Y8gf/E1pTlWbsUJpuH1ymik2Ex3aYO5mCWwV1kaSYHSQOT8+4vHA==", + "dev": true + }, "@walletconnect/browser-utils": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/@walletconnect/browser-utils/-/browser-utils-1.8.0.tgz", diff --git a/socios-oauth2/package.json b/socios-oauth2/package.json index 94b534829..ba9c64a2c 100644 --- a/socios-oauth2/package.json +++ b/socios-oauth2/package.json @@ -8,7 +8,8 @@ "test": "echo \"Error: no test specified\" && exit 1", "start": "nodemon app.js", "link": "npm link ../token-negotiator", - "unlink": "npm unlink ../token-negotiator" + "unlink": "npm unlink ../token-negotiator", + "build": "ncc build app.js -sm" }, "author": "", "license": "ISC", @@ -24,6 +25,7 @@ "node-fetch": "^3.3.2" }, "devDependencies": { + "@vercel/ncc": "^0.38.0", "nodemon": "^2.0.4" } }