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

Add getEtchPacket and downloadDocuments Methods #26

Merged
merged 19 commits into from
Oct 15, 2020
Merged

Conversation

Winggo
Copy link
Contributor

@Winggo Winggo commented Oct 1, 2020

Description of the change

Having the getEtchPacket method in the client would be extremely helpful for API users to be able to get their etch packet details. Because currently the only time API users are able to get etch packet details is right after they have created it. Also needed for building the signatures API example.

The downloadDocuments method hits our /api/document-group/:documentGroupEid.zip route specifically for client API Zip document downloads. Gives an easy abstracted solution for users to download their documents.

getEtchPacket use cases:

  • get packet data for the /packet/:packetEid route in example
  • etchPacket documentGroup status checks

downloadDocuments use cases:

  • download zip documents button at end of signature workflow
  • user doesn't have to deal with finding the downloadZipURL, the client.downloadDocuments() method takes care of that

Added:

  • get-etch-packet.js example script
  • download-documents.js example script
  • docs

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Related issues

Checklists

Development

  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development
  • No previous tests unrelated to the changed code fail in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached.
  • At least one reviewer has been requested
  • Changes have been reviewed by at least one other engineer
  • The relevant project board has been selected in Projects to auto-link to this pull request

@Winggo Winggo requested review from benogle and newhouse October 1, 2020 23:56
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/graphql/queries/etchPacket.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
@Winggo Winggo requested a review from newhouse October 6, 2020 21:36
@Winggo Winggo changed the title Add getEtchPacket Query Add getEtchPacket and downloadDocuments Methods Oct 9, 2020
Copy link
Contributor

@newhouse newhouse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks sweet! Had some minor comments in the code that don't necessarily require anything to happen before I would approve.

But, there are no tests. Can you add some simple tests for these? There are some patterns for each already in the /tests directory, and I'm happy to help you with them, too.

data.on('error', reject)
writeStream.on('finish', resolve)
})
console.log(statusCode, data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We sure we want to write this data to the console? It would be a lot of blah blah blah, no?

And below, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@@ -3,24 +3,28 @@ const defaultResponseQuery = `{
id
eid
name
detailsURL
Copy link
Contributor

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.

Copy link
Contributor Author

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.

src/index.js Outdated
return this.requestREST(
`/api/document-group/${documentGroupEid}.zip`,
{ method: 'GET' },
{ dataType: DATA_TYPE_STREAM })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why default to Stream here vs Buffer (which is the default for fillPDF? And why not allow it to be overridden to be the other type (Buffer in this case)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 stream and buffer, following the approach of fillPDF with buffer being the default.

Copy link
Contributor

@newhouse newhouse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just 1 small comment, and some tests and this baby is ready to go. Will approve to keep from slowing you down.

Nice!

README.md Outdated
* Returns a `Promise` that resolves to an `Object`
* `statusCode` (Number) - the HTTP status code, `200` is success
* `response` (Object) - the Response object resulting from the client's request to the Anvil app
* `data` (object) - a PassThrough Stream object containing the document group's data in Zip file format
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update!

@Winggo Winggo self-assigned this Oct 15, 2020
Copy link
Contributor

@newhouse newhouse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super minor comments and then just merge it!

README.md Outdated
* Returns a `Promise` that resolves to an `Object`
* `statusCode` (Number) - the HTTP status code, `200` is success
* `response` (Object) - the Response object resulting from the client's request to the Anvil app
* `data` (Buffer | Stream) - The raw binary data of the downloaded document if success. Will be in the format of either a Buffer or a Stream, depending on `dataType` option supplied to the request.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `data` (Buffer | Stream) - The raw binary data of the downloaded document if success. Will be in the format of either a Buffer or a Stream, depending on `dataType` option supplied to the request.
* `data` (Buffer | Stream) - The raw binary data of the downloaded documents if success. Will be in the format of either a Buffer or a Stream, depending on `dataType` option supplied to the request.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe even refer to the fact that they're zipped?

})

context('unsupported options', function () {
it('returns data as buffer', async function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('returns data as buffer', async function () {
it('raises appropriate error', async function () {

@Winggo Winggo merged commit f12ea90 into master Oct 15, 2020
@Winggo Winggo deleted the wt/getEtchPacket branch October 15, 2020 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants