ConstA SiteConnection whose methods each resolve to a Result and never throw.
import { createSiteConnection } from '@b-jones-rfd/sp-rest-connect'
const connection = createSiteConnection({
username: 'jsmith',
password: process.env.SP_PASSWORD!,
domain: 'CONTOSO',
site: 'sharepoint.contoso.local',
serverRelativeUrl: '/sites/finance',
})
const res = await connection.getListContents({ listName: 'Invoices' })
if (res.success) console.log(res.data)
Binds every action to one SharePoint site.
Credentials are captured in closures and reused for each call; nothing is sent to the server until an action is invoked, so creating a connection never performs network I/O. It does validate the shape of
optionsand throws aTypeErrorfor an obvious misconfiguration (a protocol insidesite, aserverRelativeUrlwithout a leading slash, and so on).