forked from microsoftgraph/msgraph-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.ts
More file actions
133 lines (122 loc) · 4.62 KB
/
Copy pathcommon.ts
File metadata and controls
133 lines (122 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
export let oDataQueryNames = ["select", "expand", "orderby", "filter", "top", "skip", "skipToken", "count"]
export const DEFAULT_VERSION = "v1.0";
export const GRAPH_BASE_URL = "https://graph.microsoft.com/";
/**
* @constant
* A package version
* @NOTE: This should be kept up to date with the version used in package.json.
* If you are changing this please ensure you are also changing it in package.json.
*/
export const PACKAGE_VERSION = "1.3.0";
/**
* @extends
* support oData params with and without $ prefix
*/
oDataQueryNames = oDataQueryNames.concat(oDataQueryNames.map((s) => "$" + s));
/**
* @interface
* Signature that defines callback for an authentication provider
* @callback - The anonymous callback function
*/
export interface AuthProviderCallback {
(error: any, accessToken: string): void
}
/**
* @interface {@link https://github.com/bitinn/node-fetch/#options}
* Signature to define the fetch request options for node environment
* @property {number} [follow] - Maximum redirect count. 0 to not follow redirect
* @property {number} [timeout] - Request/Response timeout in milliseconds, it resets on redirect. 0 to disable (OS limit applies)
* @property {number} [compress] - Support gzip/deflate content encoding. false to disable
* @property {number} [size] - Maximum response body size in bytes. 0 to disable
* @property {any} [agent] - HTTP(S).Agent instance, allows custom proxy, certificate, lookup, family etc.
*/
export interface NodeFetchInit {
follow?: number,
timeout?: number,
compress?: boolean,
size?: number,
agent?: any
}
/**
* @interface
* Signature to define the fetch api options which includes both fetch standard options and also the extended node fetch options
* @extends RequestInit @see {@link https://fetch.spec.whatwg.org/#requestinit}
* @extends NodeFetchInit
*/
export interface FetchOptions extends RequestInit, NodeFetchInit {
}
/**
* @interface
* Options for initializing the Graph Client
* @property {boolean} [debugLogging] - The boolean to enable/disable debug logging
* @property {string} [defaultVersion] - The default version that needs to be used while making graph api request
* @property {Function} [authProvider] - The function to get the authentication token
* @property {string} [baseUrl] - Base url that needs to be appended to every request
* @property {FetchOptions} [fetchOptions] - The options for fetch request
*/
export interface Options {
debugLogging?: boolean,
defaultVersion?: string,
authProvider?: (done: AuthProviderCallback) => void,
baseUrl?: string,
fetchOptions?: FetchOptions;
}
//
/**
* @interface
* Signature to define URL components
* @template http://graph.microsoft.com/VERSION/PATH?QUERYSTRING&OTHER_QUERY_PARAMS
*
* @property {string} host - The host to which the request needs to be made
* @property {string} version - Version of the graph endpoint
* @property {string} [path] - The path of the resource request
* @property {[key: string] : string|number} oDataQueryParams - The oData Query Params
* @property {[key: string] : string|number} otherURLQueryParams - The other query params for a request
*/
export interface URLComponents {
host: string,
version: string,
path?: string,
oDataQueryParams: { [key: string]: string | number; },
otherURLQueryParams: { [key: string]: string | number; }
}
/**
* @interface
* Signature to define Default request headers
* @property {string} Authorization - The authorization header
* @property {string} SdkVersion - The sdk version header
*/
export interface DefaultRequestHeaders {
Authorization: string,
SdkVersion: string
}
/**
* @interface
* Signature to define the GraphRequest callback
* @callback - The anonymous callback function
*/
export interface GraphRequestCallback {
(error: GraphError, response: any, rawResponse?: any): void
}
/**
* @interface
* Signature to represent the Graph error object
* @NOTE: This is NOT what is returned from the Graph
* GraphError is created from parsing JSON errors returned from the graph
* Some fields are renamed ie, "request-id" => requestId so you can use dot notation
*
* @property {number} statusCode - The status code of the error
* @property {string} code - The code to represent the request
* @property {string} message - The error message
* @property {string} requestId - The identifier for the request
* @property {Date} date - The request processed date and time
* @property {string} body - The original error response by the graph
*/
export interface GraphError {
statusCode: number,
code: string,
message: string,
requestId: string,
date: Date,
body: string
}