# @harrisoff/onedrive-api

> Core lib of OneDrive Image Hosting

Latest version **1.0.3** (published 2021-11-09) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @harrisoff/onedrive-api
pnpm add @harrisoff/onedrive-api
yarn add @harrisoff/onedrive-api
bun add @harrisoff/onedrive-api
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2021-11-09 |
| First published | 2021-10-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12.0.0 |
| Dependencies | 1 |
| Unpacked size | 57.3 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 16 |
| Author | harrisoff |
| Maintainers | harrisoff |
| Keywords | microsoft, onedrive, api, image, hosting |

## Links

- npm: https://www.npmjs.com/package/@harrisoff/onedrive-api
- Repository: https://github.com/harrisoff/onedrive-api
- Issues: https://github.com/harrisoff/onedrive-api/issues
- npm.io page: https://npm.io/package/@harrisoff/onedrive-api

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^0.23.0

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2021-11-09
- 1.0.2 — 2021-10-30
- 1.0.1 — 2021-10-30
- 1.0.0 — 2021-10-30

## README

# OneDrive API

[![ts](https://badgen.net/badge/Built%20With/TypeScript/blue)](https://github.com/microsoft/TypeScript)
[![npm version](https://badge.fury.io/js/@harrisoff%2Fonedrive-api.svg)](https://www.npmjs.com/package/@harrisoff/onedrive-api)
![license](https://img.shields.io/npm/l/@harrisoff/onedrive-api)

This is the core lib of [OneDrive Image Hosting](https://github.com/harrisoff/onedrive).

This project wraps a small part of OneDrive's APIs, only for uploading files and creating sharing links.

## Usage

### Setting up Application

First, setting up your application [here](https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade), `clientId` and `redirectUri` will be used later.

### Authentication

Here we use [token flow](https://docs.microsoft.com/en-us/onedrive/developer/rest-api/getting-started/graph-oauth?view=odsp-graph-online#token-flow) in authentication. Use helper function `generateAuthUrl` to generate an auth url and open it.

```ts
import { generateAuthUrl } from '@harrisoff/onedrive-api'

const authUrl = generateAuthUrl('your-client-id', 'your-redirect-uri')
```

> Actually there's another field `scope` is required in the auth url.
> This value is set to `openid https://graph.microsoft.com/Files.ReadWrite.All`
> and is unnecessary to be changed.

After redirecting back to your site, `access_token` will be presented in the url.

### API calls

There are two ways to call APIs.

The original APIs are exported so you can use them directly:

```ts
import { uploadSmall, createUploadSession, uploadLargeChunk, share, getShareUrl } from '@harrisoff/onedrive-api'
```

Or you can use constructor to create a client instance, which wraps the original APIs:

```ts
import OneDriveAPI, { getShareUrl } from '@harrisoff/onedrive-api'

const client = new OneDriveApi({ accessToken })
const { id: fileId } = await client.upload(file, filePath)
const { shareId } = await client.share(fileId)
const sharingLink = getShareUrl(shareId)
```

## TODO List

- [ ] more details about setting up application
- [ ] progress callback
- [ ] test suite
- [ ] standardize error code

## Development

For more details, see:

- [Official OneDrive API Document](https://docs.microsoft.com/en-us/onedrive/developer/)
- [some notes for my personal reference](./NOTES.md)

---
_Source: https://npm.io/package/@harrisoff/onedrive-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
