1Password/connect-sdk-js

Add functionality to get an item's files

edif2008 opened this issue · 0 comments

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 get the list of files that are in an Item.

Since the File object doesn't exist in this SDK yet, we will also create the File object in this issue, according to the API spec.

Tasks to be done

  • Create a new file named itemFile.ts and implement the ItemFile class. As an inspiration, you can take a look at how ItemURLs is implemented.
  • Implement listFiles 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.
    /**
     * Lists all files an Item contains.
     *
     * @param {string} vaultId
     * @param {string} itemQuery
     * @returns {Promise<ItemFile[]>}
     * @private
     */
    private async listFiles(
             vaultId: string,
             itemQuery: string,
         ): Promise<ItemFile[]> {
         // 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 listFiles function in OPConnect class in src/lib/op-connect.ts:
    /**
     * Get a list of files an Item contains.
     *
     * @param {string} vaultId
     * @param {string} itemQuery
     * @returns {Promise<ItemFile[]>}
     */
    public async listFiles(vaultId: string, itemQuery: string): Promise<ItemFile[]> {
          return await this.items.listFiles(vaultId, itemQuery);
    }
  • Add a test for the new function in __test__/op-connect.test.ts:
    test("list files", async () => {
        // actual test here
    }