diff options
| -rw-r--r-- | biome.json | 14 | ||||
| -rw-r--r-- | hooks.js | 4 | ||||
| -rw-r--r-- | lib/app.js | 10 | ||||
| -rw-r--r-- | lib/auth.js | 14 | ||||
| -rw-r--r-- | lib/countries.js | 2 | ||||
| -rw-r--r-- | lib/db.js | 6 | ||||
| -rw-r--r-- | lib/invoices.js | 6 | ||||
| -rw-r--r-- | lib/lightning.js | 2 | ||||
| -rw-r--r-- | lib/locations.js | 4 | ||||
| -rw-r--r-- | lib/mail.js | 12 | ||||
| -rw-r--r-- | lib/nostr.js | 16 | ||||
| -rw-r--r-- | lib/notifications.js | 2 | ||||
| -rw-r--r-- | lib/payments.js | 10 | ||||
| -rw-r--r-- | lib/rates.js | 6 | ||||
| -rw-r--r-- | lib/register.js | 4 | ||||
| -rw-r--r-- | lib/rpc.js | 12 | ||||
| -rw-r--r-- | lib/sockets.js | 2 | ||||
| -rw-r--r-- | lib/store.js | 2 | ||||
| -rw-r--r-- | lib/upload.js | 2 | ||||
| -rw-r--r-- | lib/utils.js | 2 | ||||
| -rw-r--r-- | lib/webhooks.js | 4 | ||||
| -rw-r--r-- | lib/whitelist.js | 2 | ||||
| -rw-r--r-- | loader.js | 24 | ||||
| -rw-r--r-- | package.json | 3 | ||||
| -rw-r--r-- | routes/email.js | 18 | ||||
| -rw-r--r-- | routes/info.js | 4 | ||||
| -rw-r--r-- | routes/invoices.js | 8 | ||||
| -rw-r--r-- | routes/lnurl.js | 14 | ||||
| -rw-r--r-- | routes/locations.js | 2 | ||||
| -rw-r--r-- | routes/nostr.js | 28 | ||||
| -rw-r--r-- | routes/payments.js | 25 | ||||
| -rw-r--r-- | routes/rates.js | 2 | ||||
| -rw-r--r-- | routes/requests.js | 10 | ||||
| -rw-r--r-- | routes/shopify.js | 8 | ||||
| -rw-r--r-- | routes/users.js | 26 | ||||
| -rw-r--r-- | sampledata/index.js | 4 |
36 files changed, 157 insertions, 157 deletions
@@ -1,12 +1,10 @@ { "formatter": { - "enabled": true, - "indentStyle": "space", - "indentWidth": 2 + "indentStyle": "space" }, - "javascript": { - "formatter": { - "trailingComma": "none" - } - } + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": true + } } @@ -1,2 +1,2 @@ -import { register } from 'node:module'; -register('./loader.js', import.meta.url); +import { register } from "node:module"; +register("./loader.js", import.meta.url); @@ -16,11 +16,11 @@ import { socketServer } from "$lib/sockets"; const app = fastify({ logger: pino(), disableRequestLogging: true, - maxParamLength: 500 + maxParamLength: 500, }); app.register(fastifySecureSession, { - key: Buffer.from(config.jwt, "hex") + key: Buffer.from(config.jwt, "hex"), }); app.register(fastifyPassport.initialize()); @@ -32,18 +32,18 @@ app.register(fastifyMultipart); app.register(fastifyStatic, { root: path.join("/app/data/uploads"), - prefix: "/public/" + prefix: "/public/", }); app.register(fastifyWs, { errorHandler: (err, conn, req, reply) => { console.log("socket error", err); conn.destroy(err); - } + }, }); await app.register(cors, { - origin: true + origin: true, }); app.register(socketServer); diff --git a/lib/auth.js b/lib/auth.js index 0e96218a..575d826e 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -9,15 +9,15 @@ export const optional = { { session: false }, function (req, res, err, user, info) { req.user = user; - } - ) + }, + ), }; export const auth = { preValidation: fastifyPassport.authenticate("jwt", { authInfo: false, - session: false - }) + session: false, + }), }; export const requirePin = async ({ body, user }) => { @@ -29,9 +29,9 @@ export const jwtStrategy = new jwt.Strategy( { jwtFromRequest: jwt.ExtractJwt.fromExtractors([ jwt.ExtractJwt.fromAuthHeaderAsBearerToken(), - (req) => (req.cookies ? req.cookies.token : null) + (req) => (req.cookies ? req.cookies.token : null), ]), - secretOrKey: config.jwt + secretOrKey: config.jwt, }, async (payload, next) => { let user; @@ -41,5 +41,5 @@ export const jwtStrategy = new jwt.Strategy( } next(null, user); - } + }, ); diff --git a/lib/countries.js b/lib/countries.js index cfebc573..0d201c06 100644 --- a/lib/countries.js +++ b/lib/countries.js @@ -244,5 +244,5 @@ export default { VN: "VNM", YE: "YEM", ZM: "ZMB", - ZW: "ZWE" + ZW: "ZWE", }; @@ -30,15 +30,15 @@ return {ok = 'ok'} let debit = defineScript({ NUMBER_OF_KEYS: 2, SCRIPT, - transformArguments: (...args) => args.map((a) => a.toString()) + transformArguments: (...args) => args.map((a) => a.toString()), }); export let db = createClient({ url: config.db, scripts: { debit }, socket: { - reconnectStrategy: (retries) => Math.min(retries * 50, 5000) - } + reconnectStrategy: (retries) => Math.min(retries * 50, 5000), + }, }); async function connectWithRetry() { diff --git a/lib/invoices.js b/lib/invoices.js index 1a1adda2..0cf2d72b 100644 --- a/lib/invoices.js +++ b/lib/invoices.js @@ -21,7 +21,7 @@ export let generate = async ({ invoice, user, sender, memo }) => { prompt, type, webhook, - secret + secret, } = invoice; amount = parseInt(amount || 0); @@ -45,7 +45,7 @@ export let generate = async ({ invoice, user, sender, memo }) => { label: id, description: memo || "", expiry: expiry || 60 * 60 * 24 * 30, - deschashonly: true + deschashonly: true, }); hash = r.bolt11; @@ -76,7 +76,7 @@ export let generate = async ({ invoice, user, sender, memo }) => { tip, type, uid: user.id, - webhook + webhook, }; l(type, "invoice", user.username, amount); diff --git a/lib/lightning.js b/lib/lightning.js index d4664458..8bde9633 100644 --- a/lib/lightning.js +++ b/lib/lightning.js @@ -16,7 +16,7 @@ export async function listenForLightning() { pay_index, status, amount_received_msat, - payment_preimage: preimage + payment_preimage: preimage, } = inv; await s("pay_index", pay_index); diff --git a/lib/locations.js b/lib/locations.js index dc2c9d54..72bc20b5 100644 --- a/lib/locations.js +++ b/lib/locations.js @@ -7,14 +7,14 @@ import { fields, pick } from "$lib/utils"; export let getLocations = async () => { try { let locations = await got( - "https://api.btcmap.org/v2/elements?updated_since=2022-09-19T00:00:00Z" + "https://api.btcmap.org/v2/elements?updated_since=2022-09-19T00:00:00Z", ).json(); locations = locations.filter( (l) => l["osm_json"].tags && l["osm_json"].tags["payment:coinos"] === "yes" && - l["osm_json"]["type"] === "node" + l["osm_json"]["type"] === "node", ); for await (let l of locations) { diff --git a/lib/mail.js b/lib/mail.js index bda50bec..586de5c7 100644 --- a/lib/mail.js +++ b/lib/mail.js @@ -11,7 +11,7 @@ let Charset = "UTF-8"; export let templates = { verifyEmail: "templates/payments/verify.html", paymentReceived: "templates/payments/received.html", - passwordReset: "templates/payments/reset.html" + passwordReset: "templates/payments/reset.html", }; export let mail = async (user, subject, template, params) => { @@ -27,16 +27,16 @@ export let mail = async (user, subject, template, params) => { await client.send( new SendEmailCommand({ Destination: { - ToAddresses: [user.email] + ToAddresses: [user.email], }, Message: { Body: { - Html: { Charset, Data: html } + Html: { Charset, Data: html }, }, - Subject: { Charset, Data: subject } + Subject: { Charset, Data: subject }, }, - Source: config.support - }) + Source: config.support, + }), ); } catch (e) { console.log(e); diff --git a/lib/nostr.js b/lib/nostr.js index 4dd14a0e..64009168 100644 --- a/lib/nostr.js +++ b/lib/nostr.js @@ -64,7 +64,7 @@ export let fillPool = () => { user = { ...user, ...content, - updated: ev.created_at + updated: ev.created_at, }; await s(`user:${pubkey}`, JSON.stringify(user)); @@ -103,7 +103,7 @@ let timeouts = {}; export let q = async ( sub, query, - { timeout = 20000, since = 3600, eager = 200 } + { timeout = 20000, since = 3600, eager = 200 }, ) => new Promise(async (r, j) => { let start = Date.now(); @@ -149,7 +149,7 @@ export let q = async ( rejected = true; }, timeout); }, - timer: undefined + timer: undefined, }; timeouts[sub].extend(); @@ -176,7 +176,7 @@ let getUser = async (pubkey) => { user || { username: pubkey.substr(0, 6), pubkey, - anon: true + anon: true, } ); }; @@ -219,7 +219,7 @@ export async function handleZap(invoice) { } let ptags = zapreq.tags.filter( - (t) => t && t.length && t.length >= 2 && t[0] === "p" + (t) => t && t.length && t.length >= 2 && t[0] === "p", ); if (ptags.length !== 1) { @@ -227,7 +227,7 @@ export async function handleZap(invoice) { } let etags = zapreq.tags.filter( - (t) => t && t.length && t.length >= 2 && t[0] === "e" + (t) => t && t.length && t.length >= 2 && t[0] === "e", ); if (!(etags.length === 0 || etags.length === 1)) { @@ -235,7 +235,7 @@ export async function handleZap(invoice) { } let relays_tag = zapreq.tags.find( - (t) => t && t.length && t.length >= 2 && t[0] === "relays" + (t) => t && t.length && t.length >= 2 && t[0] === "relays", ); if (!relays_tag) { @@ -263,5 +263,5 @@ export async function handleZap(invoice) { l("sending receipt"); - await Promise.allSettled(relays.map(r => send(ev, r))); + await Promise.allSettled(relays.map((r) => send(ev, r))); } diff --git a/lib/notifications.js b/lib/notifications.js index 8f092c5c..af47a6d7 100644 --- a/lib/notifications.js +++ b/lib/notifications.js @@ -5,7 +5,7 @@ if (config.vapid) { webpush.setVapidDetails( config.vapid.url, config.vapid.publicKey, - config.vapid.privateKey + config.vapid.privateKey, ); } diff --git a/lib/payments.js b/lib/payments.js index 82a26824..20429864 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -32,7 +32,7 @@ export let debit = async ( memo, user, type = types.internal, - id = v4() + id = v4(), ) => { let ref; let { id: uid, currency, username } = user; @@ -70,7 +70,7 @@ export let debit = async ( amount || 0, tip || 0, fee || 0, - ourfee || 0 + ourfee || 0, ); if (r !== "ok") fail("Insufficient funds"); @@ -187,7 +187,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { sats: "⚡️" + new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format( - p.amount + p.amount, ), link: `${process.env.URL}/payment/${p.id}`, }); @@ -195,12 +195,12 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { mqtt1.publish( username, - `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}` + `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}`, ); mqtt2.publish( username, - `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}` + `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}`, ); return p; diff --git a/lib/rates.js b/lib/rates.js index d1cbb92b..1172d202 100644 --- a/lib/rates.js +++ b/lib/rates.js @@ -49,12 +49,12 @@ export let getRates = async () => { date = Date.now(); try { let r = await got( - `http://data.fixer.io/api/latest?access_key=${config.fixer}` + `http://data.fixer.io/api/latest?access_key=${config.fixer}`, ).json(); let { rates: fx } = r; - let USD = fx['USD']; + let USD = fx["USD"]; - Object.keys(fx).map(k => { + Object.keys(fx).map((k) => { fx[k] = fx[k] / USD; }); diff --git a/lib/register.js b/lib/register.js index 2459d3a8..487413a8 100644 --- a/lib/register.js +++ b/lib/register.js @@ -28,9 +28,9 @@ export default async (user, ip, requireChallenge) => { if (config.ipregistry) { try { let { - location: { country: { code } } + location: { country: { code } }, } = await got( - `https://api.ipregistry.co/${ip}?key=${config.ipregistry}&fields=location.country.code` + `https://api.ipregistry.co/${ip}?key=${config.ipregistry}&fields=location.country.code`, ).json(); user.currency = countries[code]; @@ -13,16 +13,16 @@ export default ({ host, port, wallet, username, password }) => .post(url, { json: { method, - params + params, }, headers: { authorization: `Basic ${Buffer.from( - `${username}:${password}` - ).toString("base64")}` - } + `${username}:${password}`, + ).toString("base64")}`, + }, }) .json() .then(({ result }) => result); - })(prop.toLowerCase(), ...params) - } + })(prop.toLowerCase(), ...params), + }, ); diff --git a/lib/sockets.js b/lib/sockets.js index 948c419d..c1a704c9 100644 --- a/lib/sockets.js +++ b/lib/sockets.js @@ -107,7 +107,7 @@ export async function socketServer(app) { ws.send(JSON.stringify({ type: "logout" })); setTimeout( () => ws && ws.close(code, `closing due to error ${e.message}`), - 1000 + 1000, ); } break; diff --git a/lib/store.js b/lib/store.js index bf71219e..4c86761c 100644 --- a/lib/store.js +++ b/lib/store.js @@ -18,5 +18,5 @@ export default { last: {}, payments: [], fetching: {}, - timeouts: {} + timeouts: {}, }; diff --git a/lib/upload.js b/lib/upload.js index 39c4a07f..9bc41388 100644 --- a/lib/upload.js +++ b/lib/upload.js @@ -28,7 +28,7 @@ async function getSha256Hash(stream) { export default async (req, res) => { let { - params: { type } + params: { type }, } = req; let width = type === "banner" ? 1920 : 240; diff --git a/lib/utils.js b/lib/utils.js index a1612483..1e12214b 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -53,7 +53,7 @@ export const fields = [ "haspin", "profile", "prompt", - "banner" + "banner", ]; export const getUser = async (username) => { diff --git a/lib/webhooks.js b/lib/webhooks.js index e5403b51..5d9113d0 100644 --- a/lib/webhooks.js +++ b/lib/webhooks.js @@ -21,8 +21,8 @@ export const callWebhook = async (invoice, payment) => { memo, received, text, - secret - } + secret, + }, }); return res; } diff --git a/lib/whitelist.js b/lib/whitelist.js index a1a48223..4debb2ad 100644 --- a/lib/whitelist.js +++ b/lib/whitelist.js @@ -33,5 +33,5 @@ export default [ "username", "verified", "shopifyStore", - "shopifyToken" + "shopifyToken", ]; @@ -1,22 +1,22 @@ -import path from 'path' -import fs from 'fs' +import path from "path"; +import fs from "fs"; -export function resolve (specifier, context, nextResolve) { +export function resolve(specifier, context, nextResolve) { const { parentURL = null } = context; - if (specifier.startsWith('$')) { - if (specifier.startsWith('$config')) { - specifier = 'file://' + path.resolve('.') + "/config.js"; - } - else if (specifier.startsWith('$')) { - specifier = specifier.replace(/^\$/, 'file://' + path.resolve('.') + '/') + '.js'; + if (specifier.startsWith("$")) { + if (specifier.startsWith("$config")) { + specifier = "file://" + path.resolve(".") + "/config.js"; + } else if (specifier.startsWith("$")) { + specifier = + specifier.replace(/^\$/, "file://" + path.resolve(".") + "/") + ".js"; } return { shortCircuit: true, - url: new URL(specifier).href + url: new URL(specifier).href, }; - } + } - return nextResolve(specifier, context) + return nextResolve(specifier, context); } diff --git a/package.json b/package.json index e1d6401a..4433aedb 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "private": true, "scripts": { "start": "node index.js", - "dev": "nodemon index.js" + "dev": "nodemon index.js", + "format": "biome format *.js **/*.js --write" }, "dependencies": { "@aws-sdk/client-ses": "^3.449.0", diff --git a/routes/email.js b/routes/email.js index ac2fd721..63c88ab0 100644 --- a/routes/email.js +++ b/routes/email.js @@ -17,8 +17,8 @@ export default { .post("https://www.google.com/recaptcha/api/siteverify", { form: { secret, - response - } + response, + }, }) .json(); @@ -31,23 +31,23 @@ export default { new SendEmailCommand({ Destination: { CcAddresses: [], - ToAddresses: [config.support] + ToAddresses: [config.support], }, Message: { Body: { Html: { Charset, Data: message.replace(/\n/g, "<br>") }, - Text: { Charset, Data: message } + Text: { Charset, Data: message }, }, Subject: { Charset, Data: body.subject || - "Support Request" + (username ? " From " + username : "") - } + "Support Request" + (username ? " From " + username : ""), + }, }, ReplyToAddresses: [email], - Source: config.support - }) + Source: config.support, + }), ); res.send({ ok: true }); @@ -57,5 +57,5 @@ export default { } catch (e) { console.log(e); } - } + }, }; diff --git a/routes/info.js b/routes/info.js index ae347b56..13b1de57 100644 --- a/routes/info.js +++ b/routes/info.js @@ -18,9 +18,9 @@ export default { const info = { lnchannel, lnwallet, - total + total, }; res.send(info); - } + }, }; diff --git a/routes/invoices.js b/routes/invoices.js index 329f163d..898938dd 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -19,7 +19,7 @@ export default { "banner", "currency", "username", - "pubkey" + "pubkey", ]); } else if (config.classic) { invoice = await got(`${config.classic}/invoice/${id}`).json(); @@ -49,11 +49,11 @@ export default { .post(`${config.classic}/invoice`, { json: { invoice: { amount: 0, network: "lightning" }, - user: { username } - } + user: { username }, + }, }) .json(); res.send(invoice); - } + }, }; diff --git a/routes/lnurl.js b/routes/lnurl.js index 011db286..a1e7dde8 100644 --- a/routes/lnurl.js +++ b/routes/lnurl.js @@ -36,7 +36,7 @@ export default { async decode({ query: { text } }, res) { try { let url = Buffer.from( - bech32.fromWords(bech32.decode(text, 20000).words) + bech32.fromWords(bech32.decode(text, 20000).words), ).toString(); res.send(await got(url).json()); @@ -51,7 +51,7 @@ export default { let metadata = JSON.stringify([ ["text/plain", `Paying ${username}@${host}`], - ["text/identifier", `${username}@${host}`] + ["text/identifier", `${username}@${host}`], ]); let id = v4(); @@ -64,7 +64,7 @@ export default { metadata, nostrPubkey, callback: `${URL}/api/lnurl/${id}`, - tag: "payRequest" + tag: "payRequest", }); } catch (e) { warn("problem generating lnurlp request", e.message); @@ -82,7 +82,7 @@ export default { let metadata = JSON.stringify([ ["text/plain", `Paying ${username}@${host}`], - ["text/identifier", `${username}@${host}`] + ["text/identifier", `${username}@${host}`], ]); if (nostr) { @@ -99,12 +99,12 @@ export default { let { text: pr } = await generate({ invoice: { amount: Math.round(amount / 1000), - type: types.lightning + type: types.lightning, }, memo: metadata, - user + user, }); res.send({ pr, routes: [] }); - } + }, }; diff --git a/routes/locations.js b/routes/locations.js index 0f71fde9..e9a6843c 100644 --- a/routes/locations.js +++ b/routes/locations.js @@ -4,5 +4,5 @@ export default { async list(req, res) { let locations = await g("locations"); res.send({ locations }); - } + }, }; diff --git a/routes/nostr.js b/routes/nostr.js index 5c22fa7b..990317a9 100644 --- a/routes/nostr.js +++ b/routes/nostr.js @@ -15,7 +15,7 @@ export default { pubkey, anon: true, follows: [], - followers: [] + followers: [], }; res.send(event); @@ -31,12 +31,12 @@ export default { pubkey, anon: true, follows: [], - followers: [] + followers: [], }; let params = { kinds: [1], - authors: [pubkey] + authors: [pubkey], }, opts = { since: 0 }; @@ -54,7 +54,7 @@ export default { async messages({ params: { pubkey, since = 0 } }, res) { let params = { kinds: [4], - authors: [pubkey] + authors: [pubkey], }; let opts = { since }; @@ -63,7 +63,7 @@ export default { params = { kinds: [4], - "#p": [pubkey] + "#p": [pubkey], }; await q(`${pubkey}:messages`, params, opts).catch(nada); @@ -81,7 +81,7 @@ export default { m.recipient = await g(`user:${rid}`); return m; - }) + }), ); res.send(messages); @@ -98,7 +98,7 @@ export default { params = { limit: 1, kinds: [3], - authors: [pubkey] + authors: [pubkey], }, opts = { timeout: 60000, eager: 60000 }; @@ -114,7 +114,7 @@ export default { q(`${pubkey}:profile:f1`, { limit: 1, kinds: [0], - authors: [pubkey] + authors: [pubkey], }).catch(nada); let uid = await g(`user:${pubkey}`); @@ -124,7 +124,7 @@ export default { user = { username: pubkey.substr(0, 6), pubkey, - anon: true + anon: true, }; follows.push(user); @@ -139,7 +139,7 @@ export default { async followers({ params: { pubkey } }, res) { try { let pubkeys = [ - ...new Set([...(await db.sMembers(`${pubkey}:followers`))]) + ...new Set([...(await db.sMembers(`${pubkey}:followers`))]), ]; let followers = []; @@ -147,7 +147,7 @@ export default { q( `${pubkey}:followers`, { kinds: [3], "#p": [pubkey] }, - { timeout: 60000, eager: 60000 } + { timeout: 60000, eager: 60000 }, ).catch(nada); for (let pubkey of pubkeys) { @@ -157,7 +157,7 @@ export default { await q(`${pubkey}:profile:f2`, { limit: 1, kinds: [0], - authors: [pubkey] + authors: [pubkey], }).catch(nada); uid = await g(`user:${pubkey}`); @@ -168,7 +168,7 @@ export default { user = { username: pubkey.substr(0, 6), pubkey, - anon: true + anon: true, }; followers.push(user); @@ -193,5 +193,5 @@ export default { } res.send({ names }); - } + }, }; diff --git a/routes/payments.js b/routes/payments.js index bbbcf9d2..2b332221 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -44,8 +44,9 @@ export default { if (typeof amount !== "undefined") { amount = parseInt(amount); - if (amount < 0 || amount > SATS || isNaN(amount)) fail("Invalid amount"); - } + if (amount < 0 || amount > SATS || isNaN(amount)) + fail("Invalid amount"); + } await requirePin({ body, user }); @@ -98,7 +99,7 @@ export default { if (p.created < start || p.created > end) return; if (p.type === types.internal) p.with = await g(`user:${p.ref}`); return p; - }) + }), ) ) .filter((p) => p) @@ -124,7 +125,7 @@ export default { ).toFixed(2), }, }), - {} + {}, ); if (limit) payments = payments.slice(offset, offset + limit); @@ -168,7 +169,7 @@ export default { payments = await Promise.all(payments.map((hash) => g(`payment:${hash}`))); await Promise.all( - payments.map(async (p) => (p.user = await g(`user:${p.uid}`))) + payments.map(async (p) => (p.user = await g(`user:${p.uid}`))), ); payments = payments.filter((p) => p); @@ -235,7 +236,7 @@ export default { sats(amount), "", `${txid}:${vout}`, - types.bitcoin + types.bitcoin, ); } else if (confirmations >= 1) { await confirm(address, txid, vout); @@ -250,7 +251,7 @@ export default { } }, - async fee({ body: { amount, address, feeRate, subtract }, user }, res) { + async fee({ body: { amount, address, feeRate, subtract }, user }, res) { try { let ourfee = Math.round(amount * config.fee); let credit = await g(`credit:bitcoin:${user.id}`); @@ -268,10 +269,10 @@ export default { let fee = sats(tx.fee); - if (amount + fee + ourfee > await g(`balance:${user.id}`)) { + if (amount + fee + ourfee > (await g(`balance:${user.id}`))) { tx = await bc.fundRawTransaction(raw, { replaceable: true, - subtractFeeFromOutputs: [0] + subtractFeeFromOutputs: [0], }); } @@ -485,12 +486,12 @@ export default { mqtt1.publish( username, - `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}` + `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}`, ); mqtt2.publish( username, - `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}` + `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}`, ); res.send({ ok: true }); @@ -507,7 +508,7 @@ export default { let maxfee = 5000; let [username, domain] = lnaddress.split("@"); let { minSendable, maxSendable, callback, metadata } = await got( - `https://${domain}/.well-known/lnurlp/${username}` + `https://${domain}/.well-known/lnurlp/${username}`, ).json(); let memo = metadata["text/plain"] || ""; diff --git a/routes/rates.js b/routes/rates.js index c36c7ae8..08b604bb 100644 --- a/routes/rates.js +++ b/routes/rates.js @@ -7,5 +7,5 @@ export default { async index(req, res) { res.send(store.rates); - } + }, }; diff --git a/routes/requests.js b/routes/requests.js index ccc7d739..a0d55739 100644 --- a/routes/requests.js +++ b/routes/requests.js @@ -26,7 +26,7 @@ export default { r.requester = await g(`user:${r.requester_id}`); r.recipient = await g(`user:${r.recipient_id}`); return r; - }) + }), ); let sent = requests.filter((r) => r.requester_id === id); @@ -56,9 +56,9 @@ export default { async create( { body: { recipient, ...params }, - user: { id: requester_id, username, profile } + user: { id: requester_id, username, profile }, }, - res + res, ) { let recipient_id = await g(`user:${recipient}`); @@ -67,7 +67,7 @@ export default { id, recipient_id, requester_id, - ...params + ...params, }; await s(`request:${id}`, request); @@ -81,5 +81,5 @@ export default { async destroy({ body: { request_id }, user: { id } }, res) { await db.lrem(`user:${id}:requests`, request_id); res.send(); - } + }, }; diff --git a/routes/shopify.js b/routes/shopify.js index cdfbedba..bcb60ea3 100644 --- a/routes/shopify.js +++ b/routes/shopify.js @@ -24,13 +24,13 @@ export default async ({ body: { hash }, params: { id } }, res) => { { headers: { "Content-Type": "application/json", - "X-Shopify-Access-Token": user.shopifyToken + "X-Shopify-Access-Token": user.shopifyToken, }, json: { query, - variables: { input: { id: `gid://shopify/Order/${id}` } } - } - } + variables: { input: { id: `gid://shopify/Order/${id}` } }, + }, + }, ) .json(); diff --git a/routes/users.js b/routes/users.js index ebcbbc85..432908e9 100644 --- a/routes/users.js +++ b/routes/users.js @@ -9,7 +9,7 @@ import { wait, bail, fail, - getUser + getUser, } from "$lib/utils"; import bcrypt from "bcrypt"; import jwt from "jsonwebtoken"; @@ -99,7 +99,7 @@ export default { username: key, display: key.substr(0, 6), pubkey: key, - anon: true + anon: true, }; } @@ -117,7 +117,7 @@ export default { "pubkey", "display", "prompt", - "id" + "id", ]; if (user.pubkey) @@ -142,7 +142,7 @@ export default { pubkey, password, username, - salt + salt, }; user = await register(user, ip, false); @@ -195,7 +195,7 @@ export default { newpin, username, shopifyToken, - shopifyStore + shopifyStore, } = body; if (user.pin && !(pin === user.pin)) throw new Error("Pin required"); @@ -239,7 +239,7 @@ export default { "tokens", "twofa", "shopifyToken", - "shopifyStore" + "shopifyStore", ]; for (let a of attributes) { @@ -254,7 +254,7 @@ export default { await s(`user:${user.pubkey}`, user.id); await s( `user:${user.username.toLowerCase().replace(/\s/g, "")}`, - user.id + user.id, ); await s(`user:${user.id}`, user); @@ -319,7 +319,7 @@ export default { if (!subscriptions) subscriptions = []; if ( !subscriptions.find( - (s) => JSON.stringify(s) === JSON.stringify(subscription) + (s) => JSON.stringify(s) === JSON.stringify(subscription), ) ) subscriptions.push(subscription); @@ -364,7 +364,7 @@ export default { for (let { ref } of ( await Promise.all( - payments.reverse().map(async (id) => await g(`payment:${id}`)) + payments.reverse().map(async (id) => await g(`payment:${id}`)), ) ).filter((p) => p.type === types.internal && p.ref)) { let i = contacts.findIndex((c) => c && c.id === ref); @@ -385,7 +385,7 @@ export default { return res.code(401).send("unauthorized"); let { id, pubkey } = await g( - `user:${await g(`user:${username.replace(/\s/g, "").toLowerCase()}`)}` + `user:${await g(`user:${username.replace(/\s/g, "").toLowerCase()}`)}`, ); let invoices = await db.lRange(`${id}:invoices`, 0, -1); let payments = await db.lRange(`${id}:payments`, 0, -1); @@ -470,7 +470,7 @@ export default { await mail(user, subject, templates.verifyEmail, { username, - link + link, }); res.send({ ok: true }); @@ -507,7 +507,7 @@ export default { await mail(user, "Password reset", templates.passwordReset, { ...user, - link + link, }); } @@ -515,5 +515,5 @@ export default { } catch (e) { bail(res, e.message); } - } + }, }; diff --git a/sampledata/index.js b/sampledata/index.js index 8fcb0a6f..a2f2e259 100644 --- a/sampledata/index.js +++ b/sampledata/index.js @@ -10,7 +10,7 @@ export default { username: "admin1", password: "123", network: "regtest", - port: 18443 + port: 18443, }, - lightning: "/app/config/lightning/regtest/lightning-rpc" + lightning: "/app/config/lightning/regtest/lightning-rpc", }; |
