3.14.0 • Published 4 years ago
node-valve v3.14.0
Installation
npm install node-valve
Initialization
import Valve from 'node-valve';
const VALVE_API_TOKEN = '...'
const valve = Valve({ 'token': VALVE_API_TOKEN, })
Usage
const url = await valve.auth({ "app": "github", "user": "12345", })
// ... Redirect the user to the url ...
// Are they authorized?
// authorized is a boolean
const { authorized } = await valve.checkAuth({ "app": "github", "user": "12345" })
// Call an action
valve.call.get_stripe_balance({ user: '1234' })
// =>
// {
// response: 200,
// ...
// json: {
// object: 'balance',
// available: {
// "amount": 0,
// "currency": "usd",
// "source_types": {
// "card": 0
// }
// }
// }
// }
// Get action
valve.getAction.get_stripe_balance({ user: '1234' })
Annotate auths with helpful notes
// "auth" can be called as many times as you want
valve.auth({
app: 'stripe',
user: '1234',
annotation: {
has_paid: true,
},
})
valve.checkAuth({ app: 'stripe', user: '1234' })
// =>
// {
// authorized: true,
// annotation: {
// has_paid: true,
// }
// }
Get nice action metadata
// All apps you've registered
await valve.getApps()
// Get actions that failed
await valve.getErrors()
// Get failed actions for a particular user
await valve.getErrors({ user: 1234 })