Socket
Socket
Sign inDemoInstall

freshbooks-classic

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

freshbooks-classic - npm Package Compare versions

Comparing version 0.0.0 to 0.0.1

src/api/client.js

4

package.json
{
"name": "freshbooks-classic",
"description": "FreshBooks Classic API wrapper",
"version": "0.0.0",
"version": "0.0.1",
"author": "Leonardo Dino",

@@ -29,3 +29,3 @@ "scripts": {

"@babel/runtime": "^7.0.0-beta.42",
"ava": "^0.25.0",
"ava": "^1.0.0-beta.3",
"concurrently": "^3.5.1",

@@ -32,0 +32,0 @@ "nyc": "^11.6.0"

@@ -30,9 +30,6 @@ # freshbooks-classic

invoice.get(invoice_id, function(err, invoice){
if(err){
//returns if an error has occured, ie invoice_id doesn't exist.
return console.log(err)
}
console.log(`Invoice Number: ${invoice.number}`)
})
(async () => {
const {number} = await invoice.get(invoice_id)
console.log(`Invoice Number: ${number}`)
})()
```

@@ -42,2 +39,3 @@

- no native modules.
- `async`/`await` friendly.
- must work on `browser`, `aws-lambda`, and `node v6`+.

@@ -52,3 +50,3 @@

- [ ] `FreshBooks.category`
- [ ] `FreshBooks.client`
- [x] `FreshBooks.client`
- [x] `FreshBooks.estimate`

@@ -55,0 +53,0 @@ - [ ] `FreshBooks.expense`

@@ -30,2 +30,8 @@ import Endpoint from '../Endpoint'

}
const filter = {
client_id: 'string',
folder: 'string',
date_from: 'string',
date_to: 'string',
}
const methods = {

@@ -36,6 +42,3 @@ create: [{schema: true, required: 'client_id', wrap: true, result: key}],

delete: [{select: true, result: true}],
list: [
{paginate},
{client_id: 'string', folder: 'string', date_from: 'string', date_to: 'string'},
],
list: [{paginate}, filter],
sendByEmail: [

@@ -42,0 +45,0 @@ {select: true, result: true},

import FreshBooksFetch from './utils/fetch'
export default class FreshBooks {
class FreshBooks {
constructor(url, token){

@@ -8,3 +8,3 @@ const http = new FreshBooksFetch({url, token})

// this.category = require('./api/Category')({http})
// this.client = require('./api/Client')({http})
this.client = require('./api/client')({http})
this.estimate = require('./api/estimate')({http})

@@ -25,1 +25,4 @@ // this.expense = require('./api/Expense')({http})

}
exports.default = FreshBooks
module.exports = exports['default']

@@ -42,3 +42,3 @@ import {Buffer} from 'safe-buffer'

if(obj.status === 'ok') return resolve(obj)
const err = new Error(obj.error)
const err = new Error(obj.error || 'invalid freshbooks response')
err.code = obj.code

@@ -45,0 +45,0 @@ throw err

@@ -9,4 +9,10 @@ import _ from 'lodash'

const sum_lines = (total, line) => total + (line.unit_cost * line.quantity)
const lines = [
{name: 'Test', unit_cost: 5, quantity: 5},
{name: 'Test Big', unit_cost: 15, quantity: 3},
]
const amount = 70
test.serial('estimate.create', async t => {
test.serial('create', async t => {
const {estimate} = new FreshBooks(url, token)

@@ -17,3 +23,3 @@ estimate_id = await estimate.create({client_id})

test.serial('estimate.update', async t => {
test.serial('update', async t => {
const {estimate} = new FreshBooks(url, token)

@@ -24,3 +30,3 @@ const result = await estimate.update({estimate_id, notes: 'Lorem Ipsum'})

test.serial('estimate.get', async t => {
test.serial('get', async t => {
const {estimate} = new FreshBooks(url, token)

@@ -41,4 +47,10 @@ const result = await estimate.get({estimate_id})

test.serial('estimate.get (direct selection)', async t => {
test.serial('update lines', async t => {
const {estimate} = new FreshBooks(url, token)
const result = await estimate.update({estimate_id, lines})
t.true(result, 'returns true')
})
test.serial('get (direct selection)', async t => {
const {estimate} = new FreshBooks(url, token)
const result = await estimate.get(estimate_id)

@@ -50,5 +62,7 @@

t.is(result.notes, 'Lorem Ipsum', 'matches provided notes')
t.true(_.isArray(result.lines), 'lines is array')
t.true(_.isMatch(result.lines, lines), 'lines match with provided')
t.true(_.isString(result.date), 'has date')
t.not(new Date(result.date).toString(), 'Invalid Date', 'date is valid')
t.true(_.isFinite(result.amount), 'has finite amount')
t.is(amount, result.amount, 'amount matches with lines')
t.true(_.isFinite(result.discount), 'has finite discount')

@@ -59,3 +73,3 @@ t.true(_.isString(result.links.view), 'has links.view')

test.serial('estimate.sendByEmail', async t => {
test.serial('sendByEmail', async t => {
const {estimate} = new FreshBooks(url, token)

@@ -66,3 +80,3 @@ const result = await estimate.sendByEmail({estimate_id})

test.serial('estimate.markAsSent', async t => {
test.serial('markAsSent', async t => {
const {estimate} = new FreshBooks(url, token)

@@ -73,3 +87,3 @@ const result = await estimate.markAsSent({estimate_id})

test.serial('estimate.accept', async t => {
test.serial('accept', async t => {
const {estimate} = new FreshBooks(url, token)

@@ -80,3 +94,3 @@ const result = await estimate.accept({estimate_id})

test.serial('estimate.getPDF', async t => {
test.serial('getPDF', async t => {
const {estimate} = new FreshBooks(url, token)

@@ -89,3 +103,3 @@ const result = await estimate.getPDF({estimate_id})

test.serial('estimate.list', async t => {
test.serial('list', async t => {
const {estimate} = new FreshBooks(url, token)

@@ -100,3 +114,3 @@ const result = await estimate.list()

test.serial('estimate.delete', async t => {
test.serial('delete', async t => {
const {estimate} = new FreshBooks(url, token)

@@ -107,3 +121,3 @@ const result = await estimate.delete({estimate_id})

test.serial('estimate.listAll', async t => {
test.serial('listAll', async t => {
const {estimate} = new FreshBooks(url, token)

@@ -114,1 +128,17 @@ const result = await estimate.listAll()

})
test.serial('throw failures', async t => {
const {estimate} = new FreshBooks(url, token)
await Promise.all([
async () => {
const fn = () => estimate.get('')
const e = await t.throws(fn, `Missing required field: 'estimate_id'.`)
t.is(e.code, 40040)
},
async () => {
const fn = () => estimate.get('a')
const e = await t.throws(fn, `'estimate_id' not found. Estimate not found.`)
t.is(e.code, 50010)
},
].map(fn => fn()))
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc