-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add getEtchPacket and downloadDocuments Methods #26
Changes from 15 commits
5f43011
225f44a
cc7aedd
a5220e4
cd6e6e2
03ea442
176a0d4
368b0aa
2c76dc4
c11e046
507d622
33809da
6326dd3
7c6a970
7d6e00e
760ea4b
34e3a67
dec02fb
7384c0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.DS_STORE | ||
*.log | ||
*.zip | ||
|
||
node_modules | ||
package-lock.json | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const Anvil = require('../../src/index') | ||
const argv = require('yargs') | ||
.usage('Usage: $0 apiKey documentGroupEid') | ||
.demandCommand(2).argv | ||
|
||
const [apiKey, documentGroupEid] = argv._ | ||
|
||
async function main () { | ||
const clientOptions = { | ||
apiKey, | ||
} | ||
|
||
const client = new Anvil(clientOptions) | ||
|
||
const { statusCode, response, data, errors } = await client.downloadDocuments(documentGroupEid) | ||
if (statusCode === 200) { | ||
const contentDisposition = response.headers.get('content-disposition') | ||
const fileTitle = contentDisposition.split('"')[1] | ||
const scriptDir = __dirname | ||
const outputFilePath = path.join(scriptDir, fileTitle) | ||
const writeStream = fs.createWriteStream(outputFilePath, { encoding: null }) | ||
await new Promise((resolve, reject) => { | ||
data.pipe(writeStream) | ||
data.on('error', reject) | ||
writeStream.on('finish', resolve) | ||
}) | ||
console.log(statusCode, data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We sure we want to write this And below, too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be a PassThrough stream object, but I agree it's not necessary. I'll take that out. |
||
} else { | ||
console.log(statusCode, JSON.stringify(errors || data, null, 2)) | ||
} | ||
} | ||
|
||
main() | ||
.then(() => { | ||
process.exit(0) | ||
}) | ||
.catch((err) => { | ||
console.log(err.stack || err.message) | ||
process.exit(1) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const Anvil = require('../../src/index') | ||
const argv = require('yargs') | ||
.usage('Usage: $0 apiKey etchPacketEid') | ||
.demandCommand(2).argv | ||
|
||
const [apiKey, etchPacketEid] = argv._ | ||
|
||
async function main () { | ||
const clientOptions = { | ||
apiKey, | ||
} | ||
|
||
const client = new Anvil(clientOptions) | ||
|
||
const variables = { | ||
eid: etchPacketEid, | ||
} | ||
|
||
const { statusCode, data, errors } = await client.getEtchPacket({ variables }) | ||
console.log( | ||
JSON.stringify({ | ||
statusCode, | ||
data, | ||
errors, | ||
}, null, 2), | ||
) | ||
} | ||
|
||
main() | ||
.then(() => { | ||
process.exit(0) | ||
}) | ||
.catch((err) => { | ||
console.log(err.stack || err.message) | ||
process.exit(1) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
const mutations = require('./mutations') | ||
const queries = require('./queries') | ||
|
||
module.exports = { | ||
mutations, | ||
queries, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,24 +3,28 @@ const defaultResponseQuery = `{ | |
id | ||
eid | ||
name | ||
detailsURL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's be mindful of what's added here that may be to satisfy your example repo usage vs. what should truly be sensible defaults. If there's something you think might not reasonably belong in a default response query then let's leave it out...and if your app needs it, then it can pass its own custom response query. I think that these are all fine in that regard, and no need to change them, but let's be mindful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed and thanks for pointing that out. I'm taking |
||
documentGroup { | ||
id | ||
eid | ||
status | ||
files | ||
downloadZipURL | ||
signers { | ||
id | ||
eid | ||
aliasId | ||
routingOrder | ||
name | ||
status | ||
signActionType | ||
} | ||
} | ||
}` | ||
|
||
module.exports = { | ||
getMutation: (responseQuery = defaultResponseQuery) => ` | ||
generateMutation: (responseQuery = defaultResponseQuery) => ` | ||
mutation CreateEtchPacket ( | ||
$name: String, | ||
$files: [EtchFile!], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const defaultResponseQuery = `{ | ||
id | ||
eid | ||
name | ||
detailsURL | ||
documentGroup { | ||
id | ||
eid | ||
status | ||
files | ||
downloadZipURL | ||
signers { | ||
id | ||
eid | ||
aliasId | ||
routingOrder | ||
name | ||
status | ||
signActionType | ||
} | ||
} | ||
}` | ||
|
||
module.exports = { | ||
generateQuery: (responseQuery = defaultResponseQuery) => ` | ||
query GetEtchPacket ( | ||
$eid: String!, | ||
) { | ||
etchPacket ( | ||
eid: $eid, | ||
) ${responseQuery} | ||
} | ||
`, | ||
} |
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 queryName = fileName.slice(0, fileName.length - 3) | ||
acc[queryName] = require(`./${queryName}`) | ||
return acc | ||
}, {}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,15 @@ const { version, description } = require('../package.json') | |
const { | ||
mutations: { | ||
createEtchPacket: { | ||
getMutation: getCreateEtchPacketMutation, | ||
generateMutation: generateCreateEtchPacketMutation, | ||
}, | ||
generateEtchSignUrl: { | ||
getMutation: getGenerateEtchSignUrlMutation, | ||
generateMutation: generateEtchSignUrlMutation, | ||
}, | ||
}, | ||
queries: { | ||
etchPacket: { | ||
generateQuery: generateEtchPacketQuery, | ||
}, | ||
}, | ||
} = require('./graphql') | ||
|
@@ -111,7 +116,17 @@ class Anvil { | |
createEtchPacket ({ variables, responseQuery, mutation }) { | ||
return this.requestGraphQL( | ||
{ | ||
query: mutation || getCreateEtchPacketMutation(responseQuery), | ||
query: mutation || generateCreateEtchPacketMutation(responseQuery), | ||
variables, | ||
}, | ||
{ dataType: DATA_TYPE_JSON }, | ||
) | ||
} | ||
|
||
getEtchPacket ({ variables, responseQuery }) { | ||
return this.requestGraphQL( | ||
{ | ||
query: generateEtchPacketQuery(responseQuery), | ||
variables, | ||
}, | ||
{ dataType: DATA_TYPE_JSON }, | ||
|
@@ -121,7 +136,7 @@ class Anvil { | |
async generateEtchSignUrl ({ variables }) { | ||
const { statusCode, data, errors } = await this.requestGraphQL( | ||
{ | ||
query: getGenerateEtchSignUrlMutation(), | ||
query: generateEtchSignUrlMutation(), | ||
variables, | ||
}, | ||
{ dataType: DATA_TYPE_JSON }, | ||
|
@@ -134,6 +149,13 @@ class Anvil { | |
} | ||
} | ||
|
||
downloadDocuments (documentGroupEid) { | ||
return this.requestREST( | ||
`/api/document-group/${documentGroupEid}.zip`, | ||
{ method: 'GET' }, | ||
{ dataType: DATA_TYPE_STREAM }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why default to Stream here vs Buffer (which is the default for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defaulted to stream since it was how I used the API in the example repo. But I've just added the option to choose between |
||
} | ||
|
||
async requestGraphQL ({ query, variables = {} }, clientOptions) { | ||
// Some helpful resources on how this came to be: | ||
// https://github.com/jaydenseric/graphql-upload/issues/125#issuecomment-440853538 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should update this to be more in-line with what's now actually going to happen: buffer of stream. Probably worth following the pattern of
fillPDF
and/or updating both.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update!