UNPKG

3.14 kBTypeScriptView Raw
1import { ISPFXContext } from "./spfxcontextinterface.js";
2export interface IConfigOptions {
3 headers?: string[][] | {
4 [key: string]: string;
5 } | Headers;
6 mode?: "navigate" | "same-origin" | "no-cors" | "cors";
7 credentials?: "omit" | "same-origin" | "include";
8 cache?: "default" | "no-store" | "reload" | "no-cache" | "force-cache" | "only-if-cached";
9}
10export interface IFetchOptions extends IConfigOptions {
11 method?: string;
12 body?: any;
13}
14export interface IHttpClientImpl {
15 fetch(url: string, options: IFetchOptions): Promise<Response>;
16}
17export interface IRequestClient {
18 fetch(url: string, options?: IFetchOptions): Promise<Response>;
19 fetchRaw(url: string, options?: IFetchOptions): Promise<Response>;
20 get(url: string, options?: IFetchOptions): Promise<Response>;
21 post(url: string, options?: IFetchOptions): Promise<Response>;
22 patch(url: string, options?: IFetchOptions): Promise<Response>;
23 delete(url: string, options?: IFetchOptions): Promise<Response>;
24}
25export declare function mergeHeaders(target: Headers, source: HeadersInit): void;
26export declare function mergeOptions(target: IConfigOptions, source: IConfigOptions): void;
27/**
28 * Parses out the root of the request url to use as the resource when getting the token
29 *
30 * @param url The url to parse
31 */
32export declare function getADALResource(url: string): string;
33/**
34 * Makes requests using the global/window fetch API
35 */
36export declare class FetchClient implements IHttpClientImpl {
37 fetch(url: string, options: IFetchOptions): Promise<Response>;
38}
39/**
40 * Makes requests using the fetch API adding the supplied token to the Authorization header
41 */
42export declare class BearerTokenFetchClient extends FetchClient {
43 token: string | null;
44 constructor(token: string | null);
45 fetch(url: string, options?: IFetchOptions): Promise<Response>;
46}
47export interface ILambdaTokenFactoryParams {
48 /**
49 * Url to which the request for which we are requesting a token will be sent
50 */
51 url: string;
52 /**
53 * Any options supplied for the request
54 */
55 options: IFetchOptions;
56}
57export declare class LambdaFetchClient extends BearerTokenFetchClient {
58 private tokenFactory;
59 constructor(tokenFactory: (parms: ILambdaTokenFactoryParams) => Promise<string>);
60 /**
61 * Executes a fetch request using the supplied url and options
62 *
63 * @param url Absolute url of the request
64 * @param options Any options
65 */
66 fetch(url: string, options: IFetchOptions): Promise<Response>;
67}
68/**
69 * Client wrapping the aadTokenProvider available from SPFx >= 1.6
70 */
71export declare class SPFxAdalClient extends LambdaFetchClient {
72 private context;
73 /**
74 *
75 * @param context provide the appropriate SPFx Context object
76 */
77 constructor(context: ISPFXContext);
78 /**
79 * Gets an AAD token for the provided resource using the SPFx AADTokenProvider
80 *
81 * @param resource Resource for which a token is to be requested (ex: https://graph.microsoft.com)
82 */
83 getToken(resource: string): Promise<string>;
84}
85//# sourceMappingURL=net.d.ts.map
\No newline at end of file