Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

amazon-drive

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amazon-drive

Amazon Drive API client

  • 2.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Amazon Drive Node.js Client

Simple rest client based on the cloud drive API:
https://developer.amazon.com/public/apis/experience/cloud-drive/content/restful-api-getting-started

This is a Promise based API.

js-standard-style

Authentication

Amazon Drive uses the "Login with Amazon" to authenticate. It is an OAuth workflow that requires visiting an Amazon login page. This means we need to jump through some hoops to get started. The good news is that you'll get an acceess_token and a refresh_token-- which allows us to renew the credentials programmatically.

The auth object

In the examples you will see request('./auth.json'). This file contains the auth object return from a successful OAuth response. It will look like this:

{
  "access_token": "Atza|<really_long_string_of_characters>",
  "refresh_token": "Atzr|<really_long_string_of_characters>",
  "token_type": "bearer",
  "expires_in": 3600
}

The basics

The javascript API matches the REST API the best it can.

let urlsCache
const drive = require('amazon-drive')({
  cacheUrls: (urls) => {
    // urls passed in: save them
    if (urls) urlsCache = urls
    return Promise.resolve(urlsCache)
  },
  refresh: () => {
    // When this OAuth token expires (401 returned) this will be called.
    // You will need to refresh the token and return an updated auth object.
    // See: examples/refresh.js
  }
})

// get the urls for your account and cache them
drive.getUrls()
.then((urls) => {
  console.log(urls.metadataUrl)
  console.log(urls.contentUrl)
})
.catch(console.error)

API

Account

drive.getUrls()

All endpoints will call this internally to retrieve the account's endpoints. If they are retrieved from the Amazon Drive API, it will call cacheUrls(urls) for you to cache them somewhere. Amazon requests that they be cached for 3 to 5 days.

drive.account.endpoint()

This is what drive.getUrls() calls- but without caching.

drive.account.info()
drive.account.quota()
drive.account.usage()

Nodes (Files & Folders)

drive.nodes.upload(fullpath, metadata = {}, suppress = false)
drive.nodes.overwrite(id, fullpath)
drive.nodes.download(id)
drive.nodes.create(name, metadata = {})

Creates a folder

drive.nodes.get(id, options = undefined)
drive.nodes.patch(id, properties)
drive.nodes.list(options)
drive.nodes.list.all(filters = undefined)
drive.nodes.children.add(parent, child)
drive.nodes.children.move(child, oldParent, newParent)
drive.nodes.children.delete(parent, child)
drive.nodes.children.list(parent, options = undefined)
drive.nodes.properties.add(id, owner, key, value)
drive.nodes.properties.get(id, owner, key)
drive.nodes.properties.delete(id, owner, key)
drive.nodes.properties.list(id, owner)

Trash

drive.trash.add(id)
drive.trash.list(options = undefined)
drive.trash.restore(id)

Changes

drive.changes(options = undefined)

Credits

Thanks to @alex-phillips for the work on node-clouddrive. I used hints in his code and leveraged the authentication server he hosts to help get me started.

See:

License

MIT Copyright (c) William Kapke

Keywords

FAQs

Package last updated on 21 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc