UNPKG

1.64 kBJavaScriptView Raw
1import { combine, dateAdd, isUrlAbsolute } from "@pnp/core";
2import { BrowserFetchWithRetry, DefaultParse } from "@pnp/queryable";
3import { DefaultHeaders, DefaultInit } from "./defaults.js";
4import { RequestDigest } from "./request-digest.js";
5export function SPFx(context) {
6 return (instance) => {
7 instance.using(DefaultHeaders(), DefaultInit(), BrowserFetchWithRetry(), DefaultParse(), RequestDigest((url) => {
8 var _a, _b, _c;
9 const sameWeb = (new RegExp(`^${combine(context.pageContext.web.absoluteUrl, "/_api")}`, "i")).test(url);
10 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)) {
11 // account for page lifetime in timeout #2304 & others
12 const expiration = (((_c = context.pageContext.legacyPageContext) === null || _c === void 0 ? void 0 : _c.formDigestTimeoutSeconds) || 1600) - (performance.now() / 1000) - 15;
13 return {
14 value: context.pageContext.legacyPageContext.formDigestValue,
15 expiration: dateAdd(new Date(), "second", expiration),
16 };
17 }
18 }));
19 // we want to fix up the url first
20 instance.on.pre.prepend(async (url, init, result) => {
21 if (!isUrlAbsolute(url)) {
22 url = combine(context.pageContext.web.absoluteUrl, url);
23 }
24 return [url, init, result];
25 });
26 return instance;
27 };
28}
29//# sourceMappingURL=spfx.js.map
\No newline at end of file