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 functionality to download a file #65

Open
3 tasks
edif2008 opened this issue Jul 15, 2022 · 1 comment
Open
3 tasks

Add functionality to download a file #65

edif2008 opened this issue Jul 15, 2022 · 1 comment

Comments

@edif2008
Copy link
Member

Summary

Starting with Connect 1.3.0, the users can get files that are stored in an Item. Connect Node SDK should enable the users to do that.

In this issue, we will enable the user to download a file stored in 1Password.

Tasks to be done

  • Implement downloadFile function in the Items class in src/lib/resources.ts. The API endpoint that this function needs to call is v1/vaults/vaultId/items/itemId/files/fileId/content. You'll have to figure out the object type the promise expects.
    /**
     * Download an Item's File in the provided path.
     *
     * @param {string} vaultId
     * @param {string} itemQuery
     * @param {string} fileId
     * @param {string} targetDirectory
     * @param {boolean} overwrite
     * @returns {Promise<string>}
     * @private
     */
    private async getFileContent(
             vaultId: string,
             itemQuery: string,
             fileId: string,
             targetDirectory: string,
             overwrite: boolean,
         ): Promise<string> {
         // functionality
    }
    Note: Feel free to place this functionality in a separate class (e.g. Files) if you feel it's more suitable. This is just a suggested approach.
  • Implement downloadFile function in OPConnect class in src/lib/op-connect.ts:
    /**
     * Download an Item's File in the provided path.
     *
     * @param {string} vaultId
     * @param {string} itemQuery
     * @param {string} fileId
     * @returns {Promise<string>}
     */
    public async downloadFile(vaultId: string, itemQuery: string, fileId: string. targetDirectory: string, overwrite: boolean): Promise<string> {
          return await this.items.getFileContent(vaultId, itemQuery, fileId, targetDirectory, overwrite);
    }
  • Add a test for the new function in __test__/op-connect.test.ts. This may be a tricky one.
    test("downloadFile", async () => {
        // actual test here
    }
@edif2008
Copy link
Member Author

This issue is blocked by #62

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

No branches or pull requests

1 participant