Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use module.exports instead of import/export #10

Merged
merged 2 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .babelrc

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.DS_STORE
*.log

lib/
node_modules
package-lock.json
example/script/*.pdf
Expand Down
2 changes: 0 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
test/
src/
example/
yarn.lock
.babelrc
.eslintrc.js
4 changes: 2 additions & 2 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Usage example:

```sh
# Fills a PDF then opens it in preview
yarn babel-node example/script/fill-pdf.js <pdfEID> <apiKey> <inputJSONFile>
yarn node example/script/fill-pdf.js <pdfTemplateID> <apiKey> <inputJSONFile>

# An example
yarn babel-node example/script/fill-pdf.js eidabc123 apiKeydef345 ./payload.json && open example/script/fill.output.pdf
yarn node example/script/fill-pdf.js idabc123 apiKeydef345 ./payload.json && open example/script/fill.output.pdf
```

`payload.json` is a json file with the JSON data used to fill the PDF. e.g.
Expand Down
12 changes: 0 additions & 12 deletions example/script/env.js

This file was deleted.

37 changes: 17 additions & 20 deletions example/script/fill-pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
// Usage example:
//
// # Fills a PDF then opens it in preview
// yarn babel-node example/script/fill-pdf.js <pdfEID> <apiKey> <inputJSONFile>
// yarn node example/script/fill-pdf.js <pdfTemplateID> <apiKey> <inputJSONFile>
//
// # An example
// yarn babel-node example/script/fill-pdf.js eidabc123 apiKeydef345 ./payload.json && open example/script/fill.output.pdf
// yarn node example/script/fill-pdf.js idabc123 apiKeydef345 ./payload.json && open example/script/fill.output.pdf
//
// `payload.json` is a json file with the JSON data used to fill the PDF. e.g.
//
Expand All @@ -20,25 +20,15 @@
// }
// }

import fs from 'fs'
import path from 'path'

import { run } from './env'
import Anvil from '../../src/index'

const fs = require('fs')
const path = require('path')
const Anvil = require('../../src/index')
const argv = require('yargs')
.usage('Usage: $0 [-e local|production] castEid token jsonPath.json')
.alias('e', 'endpoint')
.usage('Usage: $0 pdfTemplateID apiKey jsonPath.json')
.demandCommand(3).argv

const endpoints = {
local: 'http://localhost:3000',
production: 'https://app.useanvil.com',
}

const { endpoint: endpointKey } = argv
const [eid, apiKey, jsonPath] = argv._
const baseURL = endpoints[endpointKey || 'production']
const baseURL = 'https://app.useanvil.com'
const exampleData = JSON.parse(fs.readFileSync(jsonPath, { encoding: 'utf8' }))

async function main () {
Expand All @@ -47,12 +37,19 @@ async function main () {
const { statusCode, data, errors } = await client.fillPDF(eid, exampleData)

if (statusCode === 200) {
const testDir = __dirname
const outputFilePath = path.join(testDir, 'fill.output.pdf')
const scriptDir =
const outputFilePath = path.join(scriptDir, 'fill.output.pdf')
fs.writeFileSync(outputFilePath, data, { encoding: null })
} else {
console.log(statusCode, JSON.stringify(errors || data, null, 2))
}
}

run(main)
main()
.then(() => {
process.exit(0)
})
.catch((err) => {
console.log(err.stack || err.message)
process.exit(1)
})
15 changes: 4 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
"name": "@anvilco/anvil",
"version": "1.0.3",
"description": "Anvil API Client",
"main": "lib/index.js",
"main": "src/index.js",
"scripts": {
"test": "mocha --require test/environment.js 'test/**/*.test.js'",
"test:watch": "nodemon --signal SIGINT --watch test --watch src -x 'yarn test'",
"build": "babel src --out-dir lib",
"prepare": "yarn build"
"test:watch": "nodemon --signal SIGINT --watch test --watch src -x 'yarn test'"
},
"repository": {
"type": "git",
Expand All @@ -29,11 +27,6 @@
"@anvilco:registry": "https://registry.npmjs.org"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.7",
"@babel/node": "^7.8.4",
"@babel/preset-env": "^7.8.4",
"@babel/register": "^7.8.3",
"babel-eslint": "^10.0.3",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
Expand All @@ -49,8 +42,8 @@
"eslint-plugin-standard": "^4.0.1",
"mocha": "^7.1.1",
"nodemon": "^2.0.2",
"sinon": "^8.1.1",
"sinon-chai": "^3.4.0",
"sinon": "^9.0.1",
"sinon-chai": "^3.5.0",
"yargs": "^15.1.0"
},
"dependencies": {
Expand Down
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import request from 'request'
import { RateLimiter } from 'limiter'
const request = require('request')
const RateLimiter = require('limiter').RateLimiter

const defaultOptions = {
baseURL: 'https://app.useanvil.com',
}

const failBufferMS = 50

export default class Anvil {
class Anvil {
// {
// apiKey: <yourAPIKey>,
// accessToken: <yourAPIKey>, // OR oauth access token
Expand Down Expand Up @@ -50,7 +50,6 @@ export default class Anvil {
const { response, data } = await this.requestPromise(optionsWithURL)
const statusCode = response.statusCode
if (statusCode === 429) {
// console.log('Retrying in ms:', getRetryMS(response.headers['retry-after']))
return retry(getRetryMS(response.headers['retry-after']))
}
if (statusCode >= 300) {
Expand Down Expand Up @@ -109,3 +108,5 @@ function sleep (ms) {
setTimeout(resolve, ms)
})
}

module.exports = Anvil
12 changes: 4 additions & 8 deletions test/environment.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
require('@babel/register')({
ignore: [/node_modules/],
})

var sinon = require('sinon')
var chai = require('chai')
var sinonChai = require('sinon-chai')
var chaiAsPromised = require('chai-as-promised')
const sinon = require('sinon')
const chai = require('chai')
const sinonChai = require('sinon-chai')
const chaiAsPromised = require('chai-as-promised')

chai.use(sinonChai)
chai.use(chaiAsPromised)
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Anvil from '../src/index'
const Anvil = require('../src/index')

describe('Anvil API Client', function () {
describe('constructor', function () {
Expand Down
Loading