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 | return {
|
12 | value: context.pageContext.legacyPageContext.formDigestValue,
|
13 | expiration: dateAdd(new Date(), "second", ((_c = context.pageContext.legacyPageContext) === null || _c === void 0 ? void 0 : _c.formDigestTimeoutSeconds) || 1600),
|
14 | };
|
15 | }
|
16 | }));
|
17 |
|
18 | instance.on.pre.prepend(async (url, init, result) => {
|
19 | if (!isUrlAbsolute(url)) {
|
20 | url = combine(context.pageContext.web.absoluteUrl, url);
|
21 | }
|
22 | return [url, init, result];
|
23 | });
|
24 | return instance;
|
25 | };
|
26 | }
|
27 |
|
\ | No newline at end of file |