From caa0dd674b04aa2f3e8def557e600d016cea380d Mon Sep 17 00:00:00 2001 From: Maciej Walaszczyk Date: Sun, 31 Jul 2022 22:47:32 +0200 Subject: [PATCH] v1.0.0-alpha.4 --- package-lock.json | 14 +++++------ package.json | 4 +-- src/lib/obtain-auth-data.js | 49 +++++++++++++++++-------------------- 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/package-lock.json b/package-lock.json index c6dadfd..0e6fdae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "boxen": "^6.2.1", "configstore": "^6.0.0", "gradient-string": "^2.0.0", - "micro": "9.4.0", + "micro": "9.4.1", "node-fetch": "^3.2.3", "open": "^8.4.0", "ora": "^6.1.0", @@ -4069,9 +4069,9 @@ "dev": true }, "node_modules/micro": { - "version": "9.4.0", - "resolved": "https://registry.npmjs.org/micro/-/micro-9.4.0.tgz", - "integrity": "sha512-F3uh5Ob+0896E1skflRvcY6Cpq6/sA0RB7exMl/IhQ2wbwL79aF+mDAyjDcKNhXKkJVEXhKZrPqOEFLXkJW9og==", + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/micro/-/micro-9.4.1.tgz", + "integrity": "sha512-Lpjcbp6Y9GJIfewxDfTmu9eW0rt0MGo+Gs1d3yJLFa7mhErtKkCngGhDbA/O1gqUjEwsHh+jWPg8BJ0Bx4AgFA==", "dependencies": { "arg": "4.1.0", "content-type": "1.0.4", @@ -8204,9 +8204,9 @@ "dev": true }, "micro": { - "version": "9.4.0", - "resolved": "https://registry.npmjs.org/micro/-/micro-9.4.0.tgz", - "integrity": "sha512-F3uh5Ob+0896E1skflRvcY6Cpq6/sA0RB7exMl/IhQ2wbwL79aF+mDAyjDcKNhXKkJVEXhKZrPqOEFLXkJW9og==", + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/micro/-/micro-9.4.1.tgz", + "integrity": "sha512-Lpjcbp6Y9GJIfewxDfTmu9eW0rt0MGo+Gs1d3yJLFa7mhErtKkCngGhDbA/O1gqUjEwsHh+jWPg8BJ0Bx4AgFA==", "requires": { "arg": "4.1.0", "content-type": "1.0.4", diff --git a/package.json b/package.json index ff8c642..02b3220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@livechat/dev-cli", - "version": "1.0.0-alpha.3", + "version": "1.0.0-alpha.4", "description": "This project exposes LiveChat Developer Console capabilities in form of easy to use CLI application.", "publishConfig": { "access": "public" @@ -16,7 +16,7 @@ "boxen": "^6.2.1", "configstore": "^6.0.0", "gradient-string": "^2.0.0", - "micro": "9.4.0", + "micro": "9.4.1", "node-fetch": "^3.2.3", "open": "^8.4.0", "ora": "^6.1.0", diff --git a/src/lib/obtain-auth-data.js b/src/lib/obtain-auth-data.js index bef2989..22f6792 100644 --- a/src/lib/obtain-auth-data.js +++ b/src/lib/obtain-auth-data.js @@ -1,36 +1,34 @@ import open from 'open' -import http from 'http' import micro, { send } from 'micro' import { config } from './config' import { AccountsService } from '../services/accounts' export async function obtainAuthData() { return new Promise((resolve, reject) => { - const server = http.Server( - micro(async (req, res) => { - const { searchParams } = new URL(`${config.webServerUrl}${req.url}`) - if (searchParams.has('code')) { - try { - const data = await AccountsService.codeGrant({ code: searchParams.get('code').replace('%3A', ':') }) - server.close((error) => { - if (error) { - reject(error) - } else { - resolve(data) - } - }) - } catch (error) { - server.close(() => { + const server = micro(async (req, res) => { + const { searchParams } = new URL(`${config.webServerUrl}${req.url}`) + if (searchParams.has('code')) { + try { + const data = await AccountsService.codeGrant({ code: searchParams.get('code').replace('%3A', ':') }) + server.close((error) => { + if (error) { reject(error) - }) - return - } + } else { + resolve(data) + } + }) + } catch (error) { + server.close(() => { + reject(error) + }) + return } + } - send( - res, - 200, - ` + send( + res, + 200, + `