UNPKG

@pnp/sp

Version:

pnp - provides a fluent api for working with SharePoint REST

29 lines 1.64 kB
import { combine, dateAdd, isUrlAbsolute } from "@pnp/core"; import { BrowserFetchWithRetry, DefaultParse } from "@pnp/queryable"; import { DefaultHeaders, DefaultInit } from "./defaults.js"; import { RequestDigest } from "./request-digest.js"; export function SPFx(context) { return (instance) => { instance.using(DefaultHeaders(), DefaultInit(), BrowserFetchWithRetry(), DefaultParse(), RequestDigest((url) => { var _a, _b, _c; const sameWeb = (new RegExp(`^${combine(context.pageContext.web.absoluteUrl, "/_api")}`, "i")).test(url); if (sameWeb && ((_b = (_a = context === null || context === void 0 ? void 0 : context.pageContext) === null || _a === void 0 ? void 0 : _a.legacyPageContext) === null || _b === void 0 ? void 0 : _b.formDigestValue)) { // account for page lifetime in timeout #2304 & others const expiration = (((_c = context.pageContext.legacyPageContext) === null || _c === void 0 ? void 0 : _c.formDigestTimeoutSeconds) || 1600) - (performance.now() / 1000) - 15; return { value: context.pageContext.legacyPageContext.formDigestValue, expiration: dateAdd(new Date(), "second", expiration), }; } })); // we want to fix up the url first instance.on.pre.prepend(async (url, init, result) => { if (!isUrlAbsolute(url)) { url = combine(context.pageContext.web.absoluteUrl, url); } return [url, init, result]; }); return instance; }; } //# sourceMappingURL=spfx.js.map