npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

onedrive-api-memento

v0.4.1

Published

OneDrive module for communicating with oneDrive API. Built using functional programming pattern

Downloads

5

Readme

onedrive-api

CircleCI

OneDrive API module for Node.js. It's built with pure functional programing, there are no unnecessary objects.

It's built for internal project so it supports only basic CRUD operations needed for project (for now). I will accept any pull requests.

Install

npm install onedrive-api

API

Items

Examples

Require module

var oneDriveAPI = require('onedrive-api');
oneDriveAPI.items.listChildren({
    accessToken: accessToken,
    itemId: 'root',
    drive: 'me', // 'me' | 'user' | 'drive' | 'group' | 'site'
    driveId: '' // BLANK | {user_id} | {drive_id} | {group_id} | {sharepoint_site_id}
  }).then((childrens) => {
  // list all children of given root directory
  //
  // console.log(childrens);
  // returns body of https://dev.onedrive.com/items/list.htm#response
  })

items.createFolder

Create Folder

Returns: Object - folder object

| Param | Type | Default | Description | | --- | --- | --- | --- | | params | Object | | | | params.accessToken | String | | OneDrive access token | | [params.rootItemId] | String | root | Item id | | params.name | String | | New folder name | | params.shared | Boolean | false | A flag to indicated whether this files is owned by the user or shared from another user. If true params.user has to be set. | | params.user | String | | The user who shared the file. Must be set if params.shared is true. |

oneDriveAPI.items.createFolder({
  accessToken: accessToken,
  rootItemId: "root",
  name: "Folder name"
}).then((item) => {
// console.log(item)
// returns body of https://dev.onedrive.com/items/create.htm#response
})

items.delete

Delete item (file or folder)

Returns: undefined - (204 No content)

| Param | Type | Description | | --- | --- | --- | | params | Object | | | params.accessToken | String | OneDrive access token | | params.itemId | String | Item id | | params.shared | Boolean | false | A flag to indicated whether this files is owned by the user or shared from another user. If true params.user has to be set. | | params.user | String | | The user who shared the file. Must be set if params.shared is true. |

oneDriveAPI.items.delete({
  accessToken: accessToken,
  itemId: createdFolder.id
}).then(() => {
})

items.download

Download item content

Returns: Object - Readable stream with item's content

| Param | Type | Description | | --- | --- | --- | | params | Object | | | params.accessToken | String | OneDrive access token | | params.itemId | String | item id | | params.shared | Boolean | false | A flag to indicated whether this files is owned by the user or shared from another user. If true params.user has to be set. | | params.user | String | | The user who shared the file. Must be set if params.shared is true. |

var fileStream = oneDriveAPI.items.download({
  accessToken: accessToken,
  itemId: createdFolder.id
});
fileStream.pipe(SomeWritableStream);

items.customEndpoint

Call custom endpoint

Returns: Object - Readable stream with item's content

| Param | Type | Description | | --- | --- | --- | | params | Object | | | params.accessToken | String | OneDrive access token | | params.url | String | Endpoint url. Ex. 'groups/{groupId}/drives' | | params.body | Object | false | Optional body | | params.method | String | Optional method |

oneDriveAPI.items.customEndpoint({
  accessToken: accessToken,
  url: 'me/drive/special/cameraroll',
  // method: 'GET',
  // body: {}
}).then(r => {
  console.log(r)
}).catch(e => {
  console.log(e)
})

items.sync

Sync changes

Returns: Array - Changes since last sync

| Param | Type | Description | | --- | --- | --- | | params | Object | | | params.accessToken | String | OneDrive access token | | params.next | String | nextLink (or deltaLink returned from last session). |

oneDriveAPI.items.sync({
  accessToken: accessToken,
  next: 'https://graph.microsoft.com/v1.0/me/drive/delta(token=1230919asd190410jlka)'
}).then((item) => {
  // console.log(item);
  // returns body of https://docs.microsoft.com/nb-no/onedrive/developer/rest-api/api/driveitem_delta?view=odsp-graph-online#response
})

items.getMetadata

Get items metadata (file or folder)

Returns: Object - Item's metadata

| Param | Type | Description | | --- | --- | --- | | params | Object | | | params.accessToken | String | OneDrive access token | | params.itemId | String | Item id | | params.shared | Boolean | false | A flag to indicated whether this files is owned by the user or shared from another user. If true params.user has to be set. | | params.user | String | | The user who shared the file. Must be set if params.shared is true. |

oneDriveAPI.items.getMetadata({
  accessToken: accessToken,
  itemId: createdFolder.id
}).then((item) => {
  // console.log(item);
  // returns body of https://dev.onedrive.com/items/update.htm#response
})

items.listChildren

List childrens

Returns: Array - object of children items

| Param | Type | Default | Description | | --- | --- | --- | --- | | params | Object | | | | params.accessToken | String | | OneDrive access token | | [params.itemId] | String | root | Item id | | params.shared | Boolean | false | A flag to indicated whether this files is owned by the user or shared from another user. If true params.user has to be set. | | params.user | String | | The user who shared the file. Must be set if params.shared is true. |

oneDriveAPI.items.listChildren({
  accessToken: accessToken,
  itemId: createdFolder.id
}).then((childrens) => {
// console.log(childrens);
// returns body of https://dev.onedrive.com/items/list.htm#response
})

items.update

Update item metadata

Returns: Object - Item object

| Param | Type | Description | | --- | --- | --- | | params | Object | | | params.accessToken | String | OneDrive access token | | params.itemId | String | Item id | | params.toUpdate | Object | Object to update | | params.shared | Boolean | false | A flag to indicated whether this files is owned by the user or shared from another user. If true params.user has to be set. | | params.user | String | | The user who shared the file. Must be set if params.shared is true. |

oneDriveAPI.items.update({
  accessToken: accessToken,
  itemId: createdFolder.id,
  toUpdate: {
        name: "newFolderName"
      }
}).then((item) => {
// console.log(item);
// returns body of https://dev.onedrive.com/items/update.htm#response
})

items.uploadSimple

Create file with simple upload

Returns: Object - Item

| Param | Type | Default | Description | | --- | --- | --- | --- | | params | Object | | | | params.accessToken | String | | OneDrive access token | | params.filename | String | | File name | | [params.parentId] | String | root | Parent id | | [params.parentPath] | String | | Parent path (if parentPath is defined, than parentId is ignored) | | params.readableStream | Object | | Readable Stream with file's content | | params.shared | Boolean | false | A flag to indicated whether this files is owned by the user or shared from another user. If true params.user has to be set. | | params.user | String | | The user who shared the file. Must be set if params.shared is true. |

oneDriveAPI.items.uploadSimple({
  accessToken: accessToken,
  filename: filename,
  readableStream: readableStream
}).then((item) => {
// console.log(item);
// returns body of https://dev.onedrive.com/items/upload_put.htm#response
})

items.uploadSession

Create file with session upload. Use this for the files over 4MB. This is a synchronous wrapper around asynchronous method, which means that on the failed upload you can't resume the upload but need to retry the implementation. I am accepting PRs for asynchronous implementation

Returns: Object - Item

| Param | Type | Default | Description | | --- | --- | --- | --- | | params | Object | | | | params.accessToken | String | | OneDrive access token | | params.filename | String | | File name | | params.fileSize | Number | | Size of the file | | [params.parentId] | String | root | Parent id | | [params.parentPath] | String | | Parent path (if parentPath is defined, than parentId is ignored) | | params.readableStream | Object | | Readable Stream with file's content | | params.shared | Boolean | false | A flag to indicated whether this files is owned by the user or shared from another user. If true params.user has to be set. | | params.user | String | | The user who shared the file. Must be set if params.shared is true. | | [params.chunksToUpload] | Number | 20 | Chunks to upload per request. More chunks per request requires more RAM | | [writeStream] | Boolean | false | Return writeStream instead of handling upload directly | | [cb] | Function (err, results) | | Callback for writestream |

// Handle by upload using this library (starts at once)
oneDriveAPI.items.uploadSession({
  accessToken: accessToken,
  filename: filename,
  fileSize: fileSize,
  readableStream: readableStream
}, (bytesUploaded) => {
  console.log(bytesUploaded)
}).then((item) => {
// console.log(item);
// returns body of https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession?view=odsp-graph-online#http-response
}).catch(e => console.log(e))

// Handle upload using write stream
let writestream = await oneDriveAPI.items.uploadSession({
  accessToken: accessToken,
  filename: filename,
  fileSize: fileSize,
  readableStream: readableStream
}, (bytesUploaded) => {
  console.log(bytesUploaded)
}, true, (err, results) => {
  if (err) console.log('Something went wrong when uploading to write stream', err)
  else console.log('Upload completed', results)
})

// Start the upload by piping a readstream
readstream.pipe(writestream)

Changelog