import { O as OneDriveFile, a as OneDriveStorageOptions } from "../../packem_shared/types.d-ZrDWKyVi.js"; import { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-CYWYyCUo.js"; import { L as LocalMetaStorageOptions, i as BaseStorageOptions, M as MetaStorage, d as FileInit, O as OperationOptions, e as FilePart, f as FileQuery, g as FileReturn, B as BaseStorage } from "../../packem_shared/storage.d-C9EdfTf1.js"; import { Readable } from 'node:stream'; import { Client } from '@microsoft/microsoft-graph-client'; import 'node:timers'; import 'node:crypto'; import 'node:http'; import 'lru-cache'; declare class SharePointFile extends OneDriveFile {} declare class SharePointMetaStorage extends LocalMetaStorage { constructor(config?: LocalMetaStorageOptions); } /** * Options for the SharePoint storage backend. * * A SharePoint document library is a Microsoft Graph drive. This adapter * resolves a site + document library down to a `driveId` and then delegates * every storage operation to an internal {@link OneDriveStorage}. * * **Site targeting** (resolved in this order): * 1. `driveId` (env `SHAREPOINT_DRIVE_ID`) — short-circuits site resolution. * 2. `siteId` (env `SHAREPOINT_SITE_ID`). * 3. `siteUrl` (env `SHAREPOINT_SITE_URL`) — parsed into hostname + path. * 4. `hostname` (env `SHAREPOINT_HOSTNAME`) + `sitePath`. * * Once the site is known, `documentLibrary` selects a specific drive from the * site's drive list by display name; otherwise the site's default drive is * used. * * **Auth** mirrors {@link OneDriveStorageOptions}. Env fallbacks resolve the * `SHAREPOINT_*` variables first and then the matching `ONEDRIVE_*` * variables. */ interface SharePointStorageOptions extends BaseStorageOptions { /** * Static or dynamic access token. Pass a string for a one-shot token, or * a function returning a fresh token on each call. */ accessToken?: string | (() => string | Promise); /** * Pre-built `@microsoft/microsoft-graph-client` `Client`. Escape hatch for * callers that wire up their own `AuthenticationProvider` and also used to * resolve the site/library when site targeting is required. */ client?: Client; /** * Client-credentials auth — for app-only / daemon scenarios. Same shape as * {@link OneDriveStorageOptions.clientCredentials}. */ clientCredentials?: OneDriveStorageOptions["clientCredentials"]; /** * Timeout, in milliseconds, for polling the async-copy monitor URL. * Defaults to 60_000 (60s). */ copyTimeoutMs?: number; /** * Display name of the document library (drive) to target within the * resolved site. When omitted, the site's default drive is used. */ documentLibrary?: string; /** * Target drive (document library) by ID. Short-circuits site resolution. * Env fallback: `SHAREPOINT_DRIVE_ID`. */ driveId?: string; /** * SharePoint host name (e.g. `contoso.sharepoint.com`). Combined with * `sitePath` to resolve the site. Env fallback: `SHAREPOINT_HOSTNAME`. */ hostname?: string; /** * Configure metafiles storage. Defaults to local tmp directory. */ metaStorageConfig?: LocalMetaStorageOptions; /** * OAuth2 refresh-token auth — for delegated user scenarios. Same shape as * {@link OneDriveStorageOptions.oauth}. */ oauth?: OneDriveStorageOptions["oauth"]; /** * When `true`, `getReadUrl` creates an anonymous shared link with `view` * permission. Otherwise it returns the short-lived pre-authenticated * `@microsoft.graph.downloadUrl` from the item metadata. */ publicByDefault?: boolean; /** * Logical "bucket root" — virtual keys live under this folder path within * the target drive. Must already exist. Defaults to drive root. */ rootFolderPath?: string; /** * Target a SharePoint site by its Graph site ID. Env fallback: * `SHAREPOINT_SITE_ID`. */ siteId?: string; /** * Server-relative site path (e.g. `/sites/Marketing`). Combined with * `hostname` to resolve the site. */ sitePath?: string; /** * Full SharePoint site URL (e.g. * `https://contoso.sharepoint.com/sites/Marketing`). Parsed into a host * name + server-relative path. Env fallback: `SHAREPOINT_SITE_URL`. */ siteUrl?: string; } /** * SharePoint document-library storage backend (Microsoft Graph). * * A SharePoint document library is a Microsoft Graph drive. This adapter * resolves a site + document library to a `driveId` and then delegates every * storage operation to an internal {@link OneDriveStorage}. No Graph upload * logic is reimplemented here. * * Site resolution is lazy: the Graph client is built eagerly (so auth errors * surface at construction) but the site/library → `driveId` lookup runs on the * first storage operation, because resolution is async and constructors cannot * be. * @example * ```ts * import { SharePointStorage } from "@visulima/storage/provider/sharepoint"; * * const storage = new SharePointStorage({ * siteUrl: "https://contoso.sharepoint.com/sites/Marketing", * documentLibrary: "Documents", * clientCredentials: { tenantId, clientId, clientSecret }, * }); * ``` * @remarks * - ⚠️ Per-operation `signal`/`timeout` are best-effort: the underlying SDK does not support request cancellation, so an in-flight call may complete server-side even after abort. `retries` is honored. */ declare class SharePointStorage extends BaseStorage { static override readonly name: string; override checksumTypes: string[]; protected meta: MetaStorage; private readonly client; private inner?; private innerPromise?; private readonly oneDriveAuth; private readonly resolvedConfig; constructor(config: SharePointStorageOptions); override get raw(): Client; create(config: FileInit, options?: OperationOptions): Promise; write(part: FilePart | FileQuery | SharePointFile, options?: OperationOptions): Promise; delete(query: FileQuery, options?: OperationOptions): Promise; get(query: FileQuery, options?: OperationOptions): Promise; copy(name: string, destination: string, options?: OperationOptions & { storageClass?: string; }): Promise; move(name: string, destination: string, options?: OperationOptions): Promise; override exists(query: FileQuery, _options?: OperationOptions): Promise; override list(limit?: number, options?: OperationOptions): Promise; override update(query: FileQuery, metadata: Partial, _options?: OperationOptions): Promise; override getStream(query: FileQuery, _options?: OperationOptions): Promise<{ headers?: Record; size?: number; stream: Readable; }>; override getReadUrl(key: string, options?: { expiresIn?: number; responseContentDisposition?: string; responseContentType?: string; }): Promise; override getUploadUrl(key: string, options?: { contentLength?: number; contentType?: string; expiresIn?: number; }): Promise; /** * Resolve the target document library to a `driveId` and construct the * internal {@link OneDriveStorage}. Memoized so resolution runs at most * once. */ private getInner; private buildInner; private resolveDriveId; private resolveSiteId; } export { SharePointFile, SharePointMetaStorage, SharePointStorage, type SharePointStorageOptions };