SharePoint

SharePoint document libraries via Microsoft Graph. Resolves siteUrl and library names; delegates to the OneDrive adapter for the file operations.

Installation

@azure/identity and @microsoft/microsoft-graph-client are optional peer dependencies of files-sdk - install alongside the SDK so the adapter's imports resolve at runtime.

npm install files-sdk @azure/identity @microsoft/microsoft-graph-client

Usage

SharePoint document libraries via Microsoft Graph. Wraps the onedrive adapter and adds SharePoint-shaped resolution - siteUrl parsing, named documentLibrary lookup, and SHAREPOINT_* env-var fallbacks. Resolution is lazy: the first method call triggers Graph traffic to convert names into drive IDs, then subsequent calls reuse the resolved drive.

import { Files } from "files-sdk";
import { sharepoint } from "files-sdk/sharepoint";

const files = new Files({
  adapter: sharepoint({
    siteUrl: "https://contoso.sharepoint.com/sites/marketing",
    documentLibrary: "Reports", // optional, omit for default library
    clientCredentials: {
      tenantId: process.env.SHAREPOINT_TENANT_ID!,
      clientId: process.env.SHAREPOINT_CLIENT_ID!,
      clientSecret: process.env.SHAREPOINT_CLIENT_SECRET!,
    },
    rootFolderPath: "Uploads",
  }),
});

Options

Prop

Type

Limitations

The adapter delegates to onedrive after resolution, so the OneDrive per-method caveats in the table below apply. SharePoint-specific: siteUrl parsing errors and missing documentLibrary names throw Provider on the first method call - resolution is lazy, so construction never fails for these, and the resolved drive is cached for the adapter's lifetime after 1-2 extra Graph round-trips on first use. delete() moves items to the recycle bin (soft delete).

Compatibility

MethodStatusNotes
upload⚠️Delegates to onedrive after site/library resolution: single-PUT simple upload up to OneDrive's 250 MB limit; larger bodies (or any multipart upload) automatically switch to a chunked Graph upload session. User metadata and cacheControl throw - Graph drive items have no native arbitrary-metadata field; use raw to set Open Extensions if you need them.
download
delete
list⚠️Delegates to onedrive: returns immediate-children files only at rootFolderPath - no recursion, and subfolders are filtered out. prefix is filename-prefix only (matched client-side within the page). Pagination uses Graph's @odata.nextLink as the opaque cursor.
search⚠️Built on listAll — inherits this adapter's list behavior above. Client-side key match (glob, regex, substring, exact).
head
exists
copy⚠️Delegates to onedrive: async copy on Graph (POST /items/{id}/copy returns 202 + monitor URL). The adapter polls the monitor every 500 ms until status is completed/failed, capped by copyTimeoutMs (default 60_000). On timeout the call throws Provider; tune copyTimeoutMs for large files.
url⚠️Delegates to onedrive: throws by default - Graph has no signed URL primitive. With publicByDefault: true at construction, upload() calls createLink (anonymous-view scope) and url() returns the share link's webUrl. The link is permanent (expiresIn ignored) and responseContentDisposition always throws. Anonymous links are blocked on tenants where admins disable them.
signedUploadUrl⚠️Delegates to onedrive: initiates a Graph upload session via POST /createUploadSession and returns the session URL as a one-shot PUT (the session URL is pre-authenticated by Graph itself). maxSize and minSize throw because Graph does not enforce a server-side content-length-range policy on upload sessions; enforce size limits at your application gateway instead.

On this page