-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from anvilco/newhouse/createEtchPacket
Add support for GraphQL API, starting with createEtchPacket
- Loading branch information
Showing
14 changed files
with
1,009 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ node_modules | |
package-lock.json | ||
example/script/*.pdf | ||
example/script/*.json | ||
|
||
scratch/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
const path = require('path') | ||
const Anvil = require('../../src/index') | ||
const argv = require('yargs') | ||
.usage('Usage: $0 apiKey orgEid castEid, fileName') | ||
.demandCommand(4).argv | ||
|
||
const [apiKey, orgEid, castEid, fileName] = argv._ | ||
const pathToFile = path.resolve(__dirname, fileName) | ||
|
||
async function main () { | ||
const clientOptions = { | ||
apiKey, | ||
} | ||
|
||
const client = new Anvil(clientOptions) | ||
|
||
// Example where pathToFile will be used to create a new Stream. Can also | ||
// pass an existing Stream or Buffer | ||
const streamFile = Anvil.prepareGraphQLFile(pathToFile) | ||
|
||
const variables = { | ||
organizationEid: orgEid, | ||
send: false, | ||
isTest: true, | ||
signatureEmailSubject: 'Test Create Packet', | ||
signers: [ | ||
{ | ||
id: 'signerOne', | ||
name: 'Sally Signer', | ||
email: 'sally@example.com', | ||
fields: [ | ||
{ | ||
fileId: 'fileUpload', | ||
fieldId: 'aDateField', | ||
}, | ||
{ | ||
fileId: 'fileUpload', | ||
fieldId: 'aSignatureField', | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'signerTwo', | ||
name: 'Scotty Signer', | ||
email: 'scotty@example.com', | ||
fields: [ | ||
{ | ||
fileId: 'fileUpload', | ||
fieldId: 'anotherSignatureField', | ||
}, | ||
{ | ||
fileId: 'preExistingCastReference', | ||
fieldId: 'signature1', | ||
}, | ||
{ | ||
fileId: 'preExistingCastReference', | ||
fieldId: 'signatureDate1', | ||
}, | ||
], | ||
}, | ||
], | ||
fillPayload: { | ||
payloads: { | ||
fileUpload: { | ||
textColor: '#CC0000', | ||
data: { | ||
myShortText: 'Something Filled', | ||
}, | ||
}, | ||
preExistingCastReference: { | ||
textColor: '#00CC00', | ||
data: { | ||
name: { | ||
firstName: 'Robin', | ||
lastName: 'Smith', | ||
}, | ||
dateOfBirth: '2020-09-01', | ||
socialSecurityNumber: '456454567', | ||
primaryPhone: { | ||
num: '5554443333', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
files: [ | ||
{ | ||
id: 'fileUpload', | ||
title: 'Important PDF One', | ||
file: streamFile, | ||
fields: [ | ||
{ | ||
id: 'myShortText', | ||
type: 'shortText', | ||
pageNum: 0, | ||
rect: { | ||
x: 20, | ||
y: 100, | ||
width: 100, | ||
height: 30, | ||
}, | ||
}, | ||
{ | ||
id: 'aDateField', | ||
type: 'signatureDate', | ||
pageNum: 1, | ||
name: 'Some Date', | ||
rect: { | ||
x: 200, | ||
y: 170, | ||
width: 100, | ||
height: 30, | ||
}, | ||
}, | ||
{ | ||
id: 'aSignatureField', | ||
type: 'signature', | ||
name: 'Some Sig', | ||
pageNum: 1, | ||
rect: { | ||
x: 200, | ||
y: 120, | ||
width: 100, | ||
height: 30, | ||
}, | ||
}, | ||
{ | ||
id: 'anotherSignatureField', | ||
type: 'signature', | ||
name: 'Another Sig', | ||
pageNum: 1, | ||
rect: { | ||
x: 200, | ||
y: 400, | ||
width: 100, | ||
height: 30, | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'preExistingCastReference', | ||
castEid: castEid, | ||
}, | ||
], | ||
} | ||
|
||
const { statusCode, data, errors } = await client.createEtchPacket({ variables }) | ||
console.log( | ||
JSON.stringify({ | ||
statusCode, | ||
data, | ||
errors, | ||
}), | ||
) | ||
} | ||
|
||
main() | ||
.then(() => { | ||
process.exit(0) | ||
}) | ||
.catch((err) => { | ||
console.log(err.stack || err.message) | ||
process.exit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const mutations = require('./mutations') | ||
|
||
module.exports = { | ||
mutations, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
const defaultResponseQuery = `{ | ||
id | ||
eid | ||
name | ||
documentGroup { | ||
id | ||
eid | ||
files | ||
signers { | ||
id | ||
eid | ||
name | ||
} | ||
} | ||
}` | ||
|
||
module.exports = { | ||
getMutation: (responseQuery = defaultResponseQuery) => ` | ||
mutation CreateEtchPacket ( | ||
$name: String, | ||
$organizationEid: String!, | ||
$files: [EtchFile!], | ||
$send: Boolean, | ||
$isTest: Boolean, | ||
$signatureEmailSubject: String, | ||
$signatureEmailBody: String, | ||
$signaturePageOptions: JSON, | ||
$signers: [JSON!], | ||
$fillPayload: JSON, | ||
) { | ||
createEtchPacket ( | ||
name: $name, | ||
organizationEid: $organizationEid, | ||
files: $files, | ||
send: $send, | ||
isTest: $isTest, | ||
signatureEmailSubject: $signatureEmailSubject, | ||
signatureEmailBody: $signatureEmailBody, | ||
signaturePageOptions: $signaturePageOptions, | ||
signers: $signers, | ||
fillPayload: $fillPayload | ||
) ${responseQuery} | ||
}`, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const fs = require('fs') | ||
|
||
const IGNORE_FILES = ['index.js'] | ||
|
||
module.exports = fs.readdirSync(__dirname) | ||
.filter((fileName) => (fileName.endsWith('.js') && !fileName.startsWith('.') && !IGNORE_FILES.includes(fileName))) | ||
.reduce((acc, fileName) => { | ||
const mutationName = fileName.slice(0, fileName.length - 3) | ||
acc[mutationName] = require(`./${mutationName}`) | ||
return acc | ||
}, {}) |
Oops, something went wrong.