-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5f43011
add getEtchPacket query
Winggo 225f44a
review changes
Winggo cc7aedd
add providerConfig to getEtchPacket to access org slug, rename genera…
Winggo a5220e4
add signer status in defaultResponseQuery
Winggo cd6e6e2
remove providerConfig from defaultResponseQueries
Winggo 03ea442
add etchPacketDetailsURL resolver
Winggo 176a0d4
add downloadZipURL resolver to defaultResponseQuery
Winggo 368b0aa
rename detailsURL
Winggo 2c76dc4
add signActionType to defaultResponseQuery
Winggo c11e046
add downloadDocumentGroup method
Winggo 507d622
fix downloadDocuments method
Winggo 33809da
downloadDocuments docs
Winggo 6326dd3
update downloadDocuments route
Winggo 7c6a970
update route
Winggo 7d6e00e
some tiny text fixes
Winggo 760ea4b
add options to downloadDocuments
Winggo 34e3a67
add -s flag in downloadDocuments usage
Winggo dec02fb
tests for downloadDocuments, generateEtchSignUrl, getEtchPacket
Winggo 7384c0a
minor fixes
Winggo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.DS_STORE | ||
*.log | ||
*.zip | ||
|
||
node_modules | ||
package-lock.json | ||
|
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
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,57 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const Anvil = require('../../src/index') | ||
const argv = require('yargs') | ||
.usage('Usage: $0 apiKey documentGroupEid [-s]') | ||
.option('stream', { | ||
alias: 's', | ||
type: 'boolean', | ||
description: 'Return the data as a stream (default is buffer)', | ||
}) | ||
.demandCommand(2).argv | ||
|
||
const [apiKey, documentGroupEid] = argv._ | ||
const returnAStream = argv.stream | ||
|
||
async function main () { | ||
const clientOptions = { | ||
apiKey, | ||
} | ||
|
||
const client = new Anvil(clientOptions) | ||
|
||
const downloadOptions = {} | ||
if (returnAStream) downloadOptions.dataType = 'stream' | ||
|
||
const { statusCode, response, data, errors } = await client.downloadDocuments(documentGroupEid, downloadOptions) | ||
if (statusCode === 200) { | ||
const contentDisposition = response.headers.get('content-disposition') | ||
const fileTitle = contentDisposition.split('"')[1] | ||
const scriptDir = __dirname | ||
const outputFilePath = path.join(scriptDir, fileTitle) | ||
|
||
if (returnAStream) { | ||
const writeStream = fs.createWriteStream(outputFilePath, { encoding: null }) | ||
await new Promise((resolve, reject) => { | ||
data.pipe(writeStream) | ||
data.on('error', reject) | ||
writeStream.on('finish', resolve) | ||
}) | ||
} else { | ||
fs.writeFileSync(outputFilePath, data, { encoding: null }) | ||
} | ||
|
||
console.log(statusCode) | ||
} else { | ||
console.log(statusCode, JSON.stringify(errors, null, 2)) | ||
} | ||
} | ||
|
||
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
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) | ||
}) |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
const mutations = require('./mutations') | ||
const queries = require('./queries') | ||
|
||
module.exports = { | ||
mutations, | ||
queries, | ||
} |
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
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,34 @@ | ||
const defaultResponseQuery = `{ | ||
id | ||
eid | ||
name | ||
detailsURL | ||
documentGroup { | ||
id | ||
eid | ||
status | ||
files | ||
signers { | ||
id | ||
eid | ||
aliasId | ||
routingOrder | ||
name | ||
status | ||
signActionType | ||
} | ||
} | ||
}` | ||
|
||
module.exports = { | ||
generateQuery: (responseQuery = defaultResponseQuery) => ` | ||
query GetEtchPacket ( | ||
$eid: String!, | ||
) { | ||
etchPacket ( | ||
eid: $eid, | ||
) ${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 queryName = fileName.slice(0, fileName.length - 3) | ||
acc[queryName] = require(`./${queryName}`) | ||
return acc | ||
}, {}) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed and thanks for pointing that out. I'm taking
downloadZipURL
out as I don't see it being necessary.