Fix lint script and linter errors
This commit is contained in:
parent
33958dd84c
commit
c2343d5ddf
|
@ -17,6 +17,7 @@
|
|||
no-shadow: 0
|
||||
import/no-unresolved: 0
|
||||
import/extensions: 0
|
||||
import/prefer-default-export: 1
|
||||
require-yield: 0
|
||||
no-param-reassign: 0
|
||||
comma-dangle: 0
|
||||
|
@ -44,6 +45,13 @@
|
|||
strict:
|
||||
- 2
|
||||
- global
|
||||
arrow-parens:
|
||||
- 2
|
||||
- always
|
||||
arrow-parens: 0
|
||||
arrow-body-style: 0
|
||||
class-methods-use-this: 0
|
||||
consistent-return: 1
|
||||
no-useless-constructor: 0
|
||||
no-unused-vars: 1
|
||||
no-console: 0
|
||||
padded-blocks: 0
|
||||
prefer-template: 1
|
||||
no-undef: 1 # https://github.com/typescript-eslint/typescript-eslint/issues/342
|
||||
|
|
12
app/api.ts
12
app/api.ts
|
@ -1,10 +1,10 @@
|
|||
import * as express from 'express'
|
||||
import * as cors from 'cors'
|
||||
import IndexRoute from "./routes/index"
|
||||
import MastodonUsernameLookupRoute from "./routes/accounts/mastodon/username_lookup"
|
||||
import MastodonInvoicesRoute from "./routes/accounts/mastodon/invoices"
|
||||
import MastodonRegistrationsRoute from "./routes/accounts/mastodon/registrations"
|
||||
import MastodonBtcPayHookRoute from "./routes/accounts/mastodon/btcpay_hook"
|
||||
import IndexRoute from './routes/index'
|
||||
import MastodonUsernameLookupRoute from './routes/accounts/mastodon/username_lookup'
|
||||
import MastodonInvoicesRoute from './routes/accounts/mastodon/invoices'
|
||||
import MastodonRegistrationsRoute from './routes/accounts/mastodon/registrations'
|
||||
import MastodonBtcPayHookRoute from './routes/accounts/mastodon/btcpay_hook'
|
||||
|
||||
require('dotenv').config()
|
||||
|
||||
|
@ -17,7 +17,7 @@ class API {
|
|||
this.routes()
|
||||
}
|
||||
|
||||
public config() {
|
||||
public config () {
|
||||
this.express.use(express.json())
|
||||
this.express.use(cors())
|
||||
this.express.set('etag', false)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import * as http from 'http'
|
||||
import API from './api'
|
||||
|
||||
const port = process.env.PORT || 3200
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
class DerivationPath {
|
||||
|
||||
shortNotation: string
|
||||
method: string
|
||||
network: string
|
||||
|
||||
constructor(shortNotation: string, opts?: { method?: string, network?: string }) {
|
||||
if (typeof opts == 'undefined') { opts = {} }
|
||||
this.shortNotation = shortNotation
|
||||
this.method = opts.method || 'BIP44'
|
||||
this.network = opts.network || 'testnet'
|
||||
}
|
||||
|
||||
toArray(): number[] {
|
||||
let path
|
||||
const derivation = this.shortNotation.split('/')
|
||||
.slice(1)
|
||||
.map(i => parseInt(i))
|
||||
|
||||
switch(this.network) {
|
||||
case 'testnet':
|
||||
path = [2147483692, 2147483649, 2147483648].concat(derivation)
|
||||
break
|
||||
default:
|
||||
throw Error('not implemented')
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
static toArray(shortNotation: string, opts?: object) {
|
||||
const path = new DerivationPath(shortNotation, opts)
|
||||
return path.toArray()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default DerivationPath
|
|
@ -1,8 +1,10 @@
|
|||
require('dotenv').config()
|
||||
const BtcPay = require('btcpay')
|
||||
|
||||
const privkey = Buffer.from(process.env.BTCPAY_PRIVKEY, 'hex')
|
||||
const keypair = BtcPay.crypto.load_keypair(privkey)
|
||||
const client = new BtcPay.BTCPayClient(process.env.BTCPAY_URL, keypair,
|
||||
{ merchant: process.env.BTCPAY_MERCHANT })
|
||||
export default client
|
||||
const client = new BtcPay.BTCPayClient(process.env.BTCPAY_URL, keypair, {
|
||||
merchant: process.env.BTCPAY_MERCHANT
|
||||
})
|
||||
|
||||
export default client
|
||||
|
|
|
@ -17,7 +17,7 @@ interface Message {
|
|||
|
||||
export const sendMail = (object: Message) => {
|
||||
const message = {
|
||||
from: "accounts@kosmos.org",
|
||||
from: 'accounts@kosmos.org',
|
||||
to: object.recipient,
|
||||
subject: object.subject,
|
||||
text: object.content
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
import { inspect } from 'util'
|
||||
import { Request, Response, Router } from 'express'
|
||||
import { BaseRoute } from '../../base'
|
||||
import BaseRoute from '../../base'
|
||||
import btcPayClient from '../../../lib/btcpay/client'
|
||||
import { sendMail } from '../../../lib/nodemailer'
|
||||
|
||||
class MastodonBtcPayHookRoute extends BaseRoute {
|
||||
constructor() { super() }
|
||||
constructor () { super() }
|
||||
|
||||
public static create(router: Router) {
|
||||
public static create (router: Router) {
|
||||
router.post('/accounts/mastodon/btcpay_hook', (req, res) => {
|
||||
new MastodonBtcPayHookRoute().receive(req, res)
|
||||
})
|
||||
}
|
||||
|
||||
public async receive(req: Request, res: Response) {
|
||||
public async receive (req: Request, res: Response) {
|
||||
console.log(inspect(req.body))
|
||||
if (req.body.status !== 'confirmed') return res.status(200)
|
||||
|
||||
|
@ -22,18 +22,18 @@ class MastodonBtcPayHookRoute extends BaseRoute {
|
|||
const message = this.createMessage(invite.code)
|
||||
|
||||
sendMail({
|
||||
recipient: recipient,
|
||||
recipient,
|
||||
subject: 'Your invite',
|
||||
content: message
|
||||
}).then(result => { return res.status(200) })
|
||||
}).then(() => res.status(200))
|
||||
.catch(err => this.handleError(res, err))
|
||||
}
|
||||
|
||||
private createMessage (inviteCode: String) {
|
||||
const inviteUrl = `${process.env.MASTODON_HOST}/invite/${inviteCode}`
|
||||
const message = "Here's your invite link for creating an account on kosmos.social:"
|
||||
+ "\n\n" + inviteUrl + "\n\n"
|
||||
+ "Thanks a lot for supporting community service providers!"
|
||||
const message = 'Here\'s your invite link for creating an account on kosmos.social:'
|
||||
+ `\n\n${inviteUrl}\n\n`
|
||||
+ 'Thanks a lot for supporting community service providers!'
|
||||
return message
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { Request, Response, Router } from 'express'
|
||||
import { BaseRoute } from '../../base'
|
||||
import BaseRoute from '../../base'
|
||||
import btcPayClient from '../../../lib/btcpay/client'
|
||||
|
||||
class MastodonInvoicesRoute extends BaseRoute {
|
||||
constructor() { super() }
|
||||
constructor () { super() }
|
||||
|
||||
public static create(router: Router) {
|
||||
public static create (router: Router) {
|
||||
router.post('/accounts/mastodon/invoices', (req, res) => {
|
||||
new MastodonInvoicesRoute().create(req, res)
|
||||
})
|
||||
|
@ -14,16 +14,16 @@ class MastodonInvoicesRoute extends BaseRoute {
|
|||
})
|
||||
}
|
||||
|
||||
public async create(req: Request, res: Response) {
|
||||
public async create (req: Request, res: Response) {
|
||||
const { email, price, currency } = req.body
|
||||
const hookUrl = process.env.BTCPAY_WEBHOOK_HOST +
|
||||
'/accounts/mastodon/btcpay_hook'
|
||||
//TODO validate input
|
||||
// TODO validate input
|
||||
|
||||
btcPayClient.create_invoice({
|
||||
buyerEmail: email,
|
||||
price: price,
|
||||
currency: currency,
|
||||
price,
|
||||
currency,
|
||||
transactionSpeed: 'high',
|
||||
itemDesc: 'Mastodon account (1 year)',
|
||||
itemCode: 'mastodon-signup-donation',
|
||||
|
@ -33,7 +33,7 @@ class MastodonInvoicesRoute extends BaseRoute {
|
|||
.catch(err => this.handleError(res, err))
|
||||
}
|
||||
|
||||
public async show(req: Request, res: Response) {
|
||||
public async show (req: Request, res: Response) {
|
||||
const invoiceId = req.params.invoice_id
|
||||
|
||||
btcPayClient.get_invoice(invoiceId)
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
import { Request, Response, Router } from 'express'
|
||||
import { BaseRoute } from '../../base'
|
||||
import { inspect } from 'util'
|
||||
import BaseRoute from '../../base'
|
||||
|
||||
class MastodonRegistrationsRoute extends BaseRoute {
|
||||
constructor() { super() }
|
||||
constructor () { super() }
|
||||
|
||||
public static create(router: Router) {
|
||||
public static create (router: Router) {
|
||||
router.post('/accounts/mastodon/registration', (req, res) => {
|
||||
new MastodonRegistrationsRoute().signup(req, res)
|
||||
})
|
||||
}
|
||||
|
||||
public async signup(req: Request, res: Response) {
|
||||
public async signup (req: Request, res: Response) {
|
||||
const { username, email, password } = req.body
|
||||
// if (typeof username !== 'string') {
|
||||
// return res.status(422).json({
|
||||
|
@ -21,9 +20,9 @@ class MastodonRegistrationsRoute extends BaseRoute {
|
|||
const axios = this.createMastodonClient()
|
||||
|
||||
axios.post('/accounts', {
|
||||
username: username,
|
||||
email: email,
|
||||
password: password,
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
agreement: true,
|
||||
locale: 'en'
|
||||
})
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
import { Request, Response, Router } from 'express'
|
||||
import { BaseRoute } from '../../base'
|
||||
import { inspect } from 'util'
|
||||
import BaseRoute from '../../base'
|
||||
|
||||
class MastodonUsernameLookupRoute extends BaseRoute {
|
||||
constructor() { super() }
|
||||
constructor () { super() }
|
||||
|
||||
public static create(router: Router) {
|
||||
public static create (router: Router) {
|
||||
router.get('/accounts/mastodon/username_lookup', (req, res) => {
|
||||
new MastodonUsernameLookupRoute().lookup(req, res)
|
||||
})
|
||||
}
|
||||
|
||||
public async lookup(req: Request, res: Response) {
|
||||
public async lookup (req: Request, res: Response) {
|
||||
const username = req.query.q
|
||||
if (typeof username !== 'string') {
|
||||
return res.status(422).json({
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { Request, Response } from 'express'
|
||||
import * as colors from 'colors/safe'
|
||||
import axios from 'axios'
|
||||
import { inspect } from 'util'
|
||||
|
||||
export class BaseRoute {
|
||||
export default class {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
public handleError(res: Response, err: { message: string, stack: any }) {
|
||||
console.log(colors.red("Encountered an error, aborting request (500):"))
|
||||
public handleError (res: Response, err: { message: string, stack: any }) {
|
||||
console.log(colors.red('Encountered an error, aborting request (500):'))
|
||||
console.log(colors.gray(err.stack))
|
||||
res.sendStatus(500)
|
||||
}
|
||||
|
@ -19,7 +15,7 @@ export class BaseRoute {
|
|||
const authToken = process.env.MASTODON_AUTH_TOKEN
|
||||
const client = axios.create()
|
||||
axios.defaults.baseURL = `${host}/api/v1`
|
||||
axios.defaults.headers.common['Authorization'] = `Bearer ${authToken}`
|
||||
axios.defaults.headers.common.Authorization = `Bearer ${authToken}`
|
||||
return client
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
import { Request, Response, Router } from "express";
|
||||
import { BaseRoute } from "./base";
|
||||
import { Request, Response, Router } from 'express'
|
||||
import BaseRoute from './base'
|
||||
|
||||
class IndexRoute extends BaseRoute {
|
||||
|
||||
constructor() { super() }
|
||||
constructor () { super() }
|
||||
|
||||
public static create(router: Router) {
|
||||
router.get("/", (req: Request, res: Response) => {
|
||||
public static create (router: Router) {
|
||||
router.get('/', (req: Request, res: Response) => {
|
||||
new IndexRoute().index(req, res)
|
||||
})
|
||||
}
|
||||
|
||||
public index(req: Request, res: Response) {
|
||||
public index (req: Request, res: Response) {
|
||||
res.json({ message: 'Hello blockchain!' })
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
https://lusaxweb.github.io/vuesax/components/slider.html
|
||||
https://bitpay.com/api#reference-Webhook%20Notification%20Codes
|
||||
https://bitpay.com/api#resource-Invoices
|
||||
https://github.com/btcpayserver/node-btcpay
|
||||
https://docs.btcpayserver.org/integrations/customintegration
|
||||
|
||||
https://nodemailer.com/about/
|
|
@ -5,12 +5,9 @@
|
|||
"main": "dist/app/index.js",
|
||||
"scripts": {
|
||||
"dev": "tsc --watch & nodemon dist/app",
|
||||
"lint": "eslint app/ --ext ts",
|
||||
"start": "npm run dev",
|
||||
"test": "rm -rf dist/spec/ && tsc && mocha -s 300 --recursive dist/spec/",
|
||||
"lint": "eslint src --ext ts",
|
||||
"start": "tsc && ./scripts/start.sh",
|
||||
"stop": "./scripts/stop.sh",
|
||||
"deploy:5apps": "git subtree push --prefix public/ 5apps master",
|
||||
"webhooks:server": "node scripts/webhook-demo.js",
|
||||
"webhooks:ngrok": "ngrok http -region=eu 3200"
|
||||
},
|
||||
"keywords": [],
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
'use strict'
|
||||
|
||||
require('dotenv').config()
|
||||
const BtcPay = require('btcpay')
|
||||
|
||||
const keypair = BtcPay.crypto.load_keypair(new Buffer.from(process.env.BTCPAY_PRIVKEY, 'hex'))
|
||||
const client = new BtcPay.BTCPayClient(process.env.BTCPAY_URL, keypair,
|
||||
{ merchant: process.env.BTCPAY_MERCHANT })
|
||||
|
||||
client.get_rates('BTC_USD', process.env.BTCPAY_STORE_ID)
|
||||
.then(rates => console.log(rates))
|
||||
.catch(err => console.log(err))
|
|
@ -0,0 +1,4 @@
|
|||
BTCPAY_URL=https://btcpay.kosmos.org \
|
||||
BTCPAY_KEY=62579d9b5877f3fcd95dfec78703c554da56132da8bb1a0bf974b5ee6223c57f \
|
||||
BTCPAY_PAIRCODE=aADUXkv \
|
||||
node -e "const btcpay=require('btcpay'); new btcpay.BTCPayClient(process.env.BTCPAY_URL, btcpay.crypto.load_keypair(Buffer.from(process.env.BTCPAY_KEY, 'hex'))).pair_client(process.env.BTCPAY_PAIRCODE).then(console.log).catch(console.error)"
|
Reference in New Issue