1 | import { combine, dateAdd, isUrlAbsolute } from "@pnp/core";
|
2 | import { BrowserFetchWithRetry, DefaultParse } from "@pnp/queryable";
|
3 | import { DefaultHeaders, DefaultInit } from "./defaults.js";
|
4 | import { RequestDigest } from "./request-digest.js";
|
5 | export 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 |
|
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 |
|
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 |
|
\ | No newline at end of file |