Add PBandGraphOauth scaffold and auth UI
This commit is contained in:
+51
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { GraphRequest } from "./GraphRequest";
|
||||
import { ClientOptions } from "./IClientOptions";
|
||||
import { Options } from "./IOptions";
|
||||
export declare class Client {
|
||||
/**
|
||||
* @private
|
||||
* A member which stores the Client instance options
|
||||
*/
|
||||
private config;
|
||||
/**
|
||||
* @private
|
||||
* A member which holds the HTTPClient instance
|
||||
*/
|
||||
private httpClient;
|
||||
/**
|
||||
* @public
|
||||
* @static
|
||||
* To create a client instance with options and initializes the default middleware chain
|
||||
* @param {Options} options - The options for client instance
|
||||
* @returns The Client instance
|
||||
*/
|
||||
static init(options: Options): Client;
|
||||
/**
|
||||
* @public
|
||||
* @static
|
||||
* To create a client instance with the Client Options
|
||||
* @param {ClientOptions} clientOptions - The options object for initializing the client
|
||||
* @returns The Client instance
|
||||
*/
|
||||
static initWithMiddleware(clientOptions: ClientOptions): Client;
|
||||
/**
|
||||
* @private
|
||||
* @constructor
|
||||
* Creates an instance of Client
|
||||
* @param {ClientOptions} clientOptions - The options to instantiate the client object
|
||||
*/
|
||||
private constructor();
|
||||
/**
|
||||
* @public
|
||||
* Entry point to make requests
|
||||
* @param {string} path - The path string value
|
||||
* @returns The graph request instance
|
||||
*/
|
||||
api(path: string): GraphRequest;
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module Client
|
||||
*/
|
||||
import { GRAPH_API_VERSION, GRAPH_BASE_URL } from "./Constants";
|
||||
import { CustomAuthenticationProvider } from "./CustomAuthenticationProvider";
|
||||
import { GraphRequest } from "./GraphRequest";
|
||||
import { HTTPClient } from "./HTTPClient";
|
||||
import { HTTPClientFactory } from "./HTTPClientFactory";
|
||||
import { validatePolyFilling } from "./ValidatePolyFilling";
|
||||
export class Client {
|
||||
/**
|
||||
* @public
|
||||
* @static
|
||||
* To create a client instance with options and initializes the default middleware chain
|
||||
* @param {Options} options - The options for client instance
|
||||
* @returns The Client instance
|
||||
*/
|
||||
static init(options) {
|
||||
const clientOptions = {};
|
||||
for (const i in options) {
|
||||
if (Object.prototype.hasOwnProperty.call(options, i)) {
|
||||
clientOptions[i] = i === "authProvider" ? new CustomAuthenticationProvider(options[i]) : options[i];
|
||||
}
|
||||
}
|
||||
return Client.initWithMiddleware(clientOptions);
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @static
|
||||
* To create a client instance with the Client Options
|
||||
* @param {ClientOptions} clientOptions - The options object for initializing the client
|
||||
* @returns The Client instance
|
||||
*/
|
||||
static initWithMiddleware(clientOptions) {
|
||||
return new Client(clientOptions);
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* @constructor
|
||||
* Creates an instance of Client
|
||||
* @param {ClientOptions} clientOptions - The options to instantiate the client object
|
||||
*/
|
||||
constructor(clientOptions) {
|
||||
/**
|
||||
* @private
|
||||
* A member which stores the Client instance options
|
||||
*/
|
||||
this.config = {
|
||||
baseUrl: GRAPH_BASE_URL,
|
||||
debugLogging: false,
|
||||
defaultVersion: GRAPH_API_VERSION,
|
||||
};
|
||||
validatePolyFilling();
|
||||
for (const key in clientOptions) {
|
||||
if (Object.prototype.hasOwnProperty.call(clientOptions, key)) {
|
||||
this.config[key] = clientOptions[key];
|
||||
}
|
||||
}
|
||||
let httpClient;
|
||||
if (clientOptions.authProvider !== undefined && clientOptions.middleware !== undefined) {
|
||||
const error = new Error();
|
||||
error.name = "AmbiguityInInitialization";
|
||||
error.message = "Unable to Create Client, Please provide either authentication provider for default middleware chain or custom middleware chain not both";
|
||||
throw error;
|
||||
}
|
||||
else if (clientOptions.authProvider !== undefined) {
|
||||
httpClient = HTTPClientFactory.createWithAuthenticationProvider(clientOptions.authProvider);
|
||||
}
|
||||
else if (clientOptions.middleware !== undefined) {
|
||||
httpClient = new HTTPClient(...[].concat(clientOptions.middleware));
|
||||
}
|
||||
else {
|
||||
const error = new Error();
|
||||
error.name = "InvalidMiddlewareChain";
|
||||
error.message = "Unable to Create Client, Please provide either authentication provider for default middleware chain or custom middleware chain";
|
||||
throw error;
|
||||
}
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* Entry point to make requests
|
||||
* @param {string} path - The path string value
|
||||
* @returns The graph request instance
|
||||
*/
|
||||
api(path) {
|
||||
return new GraphRequest(this.httpClient, this.config, path);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=Client.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../../../src/Client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,OAAO,MAAM;IAiBlB;;;;;;OAMG;IACI,MAAM,CAAC,IAAI,CAAC,OAAgB;QAClC,MAAM,aAAa,GAAkB,EAAE,CAAC;QACxC,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE;YACxB,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE;gBACrD,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,cAAc,CAAC,CAAC,CAAC,IAAI,4BAA4B,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;aACpG;SACD;QACD,OAAO,MAAM,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC;IACjD,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,kBAAkB,CAAC,aAA4B;QAC5D,OAAO,IAAI,MAAM,CAAC,aAAa,CAAC,CAAC;IAClC,CAAC;IAED;;;;;OAKG;IACH,YAAoB,aAA4B;QAlDhD;;;WAGG;QACK,WAAM,GAAkB;YAC/B,OAAO,EAAE,cAAc;YACvB,YAAY,EAAE,KAAK;YACnB,cAAc,EAAE,iBAAiB;SACjC,CAAC;QA2CD,mBAAmB,EAAE,CAAC;QACtB,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE;YAChC,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC,EAAE;gBAC7D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;aACtC;SACD;QACD,IAAI,UAAsB,CAAC;QAC3B,IAAI,aAAa,CAAC,YAAY,KAAK,SAAS,IAAI,aAAa,CAAC,UAAU,KAAK,SAAS,EAAE;YACvF,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;YAC1B,KAAK,CAAC,IAAI,GAAG,2BAA2B,CAAC;YACzC,KAAK,CAAC,OAAO,GAAG,yIAAyI,CAAC;YAC1J,MAAM,KAAK,CAAC;SACZ;aAAM,IAAI,aAAa,CAAC,YAAY,KAAK,SAAS,EAAE;YACpD,UAAU,GAAG,iBAAiB,CAAC,gCAAgC,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;SAC5F;aAAM,IAAI,aAAa,CAAC,UAAU,KAAK,SAAS,EAAE;YAClD,UAAU,GAAG,IAAI,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;SACpE;aAAM;YACN,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;YAC1B,KAAK,CAAC,IAAI,GAAG,wBAAwB,CAAC;YACtC,KAAK,CAAC,OAAO,GAAG,gIAAgI,CAAC;YACjJ,MAAM,KAAK,CAAC;SACZ;QACD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;IAED;;;;;OAKG;IACI,GAAG,CAAC,IAAY;QACtB,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC7D,CAAC;CACD"}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module Constants
|
||||
*/
|
||||
/**
|
||||
* @constant
|
||||
* A Default API endpoint version for a request
|
||||
*/
|
||||
export declare const GRAPH_API_VERSION = "v1.0";
|
||||
/**
|
||||
* @constant
|
||||
* A Default base url for a request
|
||||
*/
|
||||
export declare const GRAPH_BASE_URL = "https://graph.microsoft.com/";
|
||||
/**
|
||||
* To hold list of the service root endpoints for Microsoft Graph and Graph Explorer for each national cloud.
|
||||
* Set(iterable:Object) is not supported in Internet Explorer. The consumer is recommended to use a suitable polyfill.
|
||||
*/
|
||||
export declare const GRAPH_URLS: Set<string>;
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module Constants
|
||||
*/
|
||||
/**
|
||||
* @constant
|
||||
* A Default API endpoint version for a request
|
||||
*/
|
||||
export const GRAPH_API_VERSION = "v1.0";
|
||||
/**
|
||||
* @constant
|
||||
* A Default base url for a request
|
||||
*/
|
||||
export const GRAPH_BASE_URL = "https://graph.microsoft.com/";
|
||||
/**
|
||||
* To hold list of the service root endpoints for Microsoft Graph and Graph Explorer for each national cloud.
|
||||
* Set(iterable:Object) is not supported in Internet Explorer. The consumer is recommended to use a suitable polyfill.
|
||||
*/
|
||||
export const GRAPH_URLS = new Set(["graph.microsoft.com", "graph.microsoft.us", "dod-graph.microsoft.us", "graph.microsoft.de", "microsoftgraph.chinacloudapi.cn", "canary.graph.microsoft.com"]);
|
||||
//# sourceMappingURL=Constants.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../../src/Constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAExC;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,8BAA8B,CAAC;AAE7D;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,GAAG,CAAS,CAAC,qBAAqB,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,iCAAiC,EAAE,4BAA4B,CAAC,CAAC,CAAC"}
|
||||
Generated
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { AuthenticationProvider } from "./IAuthenticationProvider";
|
||||
import { AuthProvider } from "./IAuthProvider";
|
||||
/**
|
||||
* @class
|
||||
* Class representing CustomAuthenticationProvider
|
||||
* @extends AuthenticationProvider
|
||||
*/
|
||||
export declare class CustomAuthenticationProvider implements AuthenticationProvider {
|
||||
/**
|
||||
* @private
|
||||
* A member to hold authProvider callback
|
||||
*/
|
||||
private provider;
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Creates an instance of CustomAuthenticationProvider
|
||||
* @param {AuthProviderCallback} provider - An authProvider function
|
||||
* @returns An instance of CustomAuthenticationProvider
|
||||
*/
|
||||
constructor(provider: AuthProvider);
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* To get the access token
|
||||
* @returns The promise that resolves to an access token
|
||||
*/
|
||||
getAccessToken(): Promise<any>;
|
||||
}
|
||||
Generated
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { __awaiter } from "tslib";
|
||||
/**
|
||||
* @module CustomAuthenticationProvider
|
||||
*/
|
||||
import { GraphClientError } from "./GraphClientError";
|
||||
/**
|
||||
* @class
|
||||
* Class representing CustomAuthenticationProvider
|
||||
* @extends AuthenticationProvider
|
||||
*/
|
||||
export class CustomAuthenticationProvider {
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Creates an instance of CustomAuthenticationProvider
|
||||
* @param {AuthProviderCallback} provider - An authProvider function
|
||||
* @returns An instance of CustomAuthenticationProvider
|
||||
*/
|
||||
constructor(provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* To get the access token
|
||||
* @returns The promise that resolves to an access token
|
||||
*/
|
||||
getAccessToken() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.provider((error, accessToken) => __awaiter(this, void 0, void 0, function* () {
|
||||
if (accessToken) {
|
||||
resolve(accessToken);
|
||||
}
|
||||
else {
|
||||
if (!error) {
|
||||
const invalidTokenMessage = "Access token is undefined or empty.\
|
||||
Please provide a valid token.\
|
||||
For more help - https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/dev/docs/CustomAuthenticationProvider.md";
|
||||
error = new GraphClientError(invalidTokenMessage);
|
||||
}
|
||||
const err = yield GraphClientError.setGraphClientError(error);
|
||||
reject(err);
|
||||
}
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=CustomAuthenticationProvider.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"CustomAuthenticationProvider.js","sourceRoot":"","sources":["../../../src/CustomAuthenticationProvider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAEH;;GAEG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD;;;;GAIG;AACH,MAAM,OAAO,4BAA4B;IAOxC;;;;;;OAMG;IACH,YAAmB,QAAsB;QACxC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACU,cAAc;;YAC1B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAsC,EAAE,MAA4B,EAAE,EAAE;gBAC3F,IAAI,CAAC,QAAQ,CAAC,CAAO,KAAU,EAAE,WAA0B,EAAE,EAAE;oBAC9D,IAAI,WAAW,EAAE;wBAChB,OAAO,CAAC,WAAW,CAAC,CAAC;qBACrB;yBAAM;wBACN,IAAI,CAAC,KAAK,EAAE;4BACX,MAAM,mBAAmB,GAAG;;6HAE2F,CAAC;4BACxH,KAAK,GAAG,IAAI,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;yBAClD;wBACD,MAAM,GAAG,GAAG,MAAM,gBAAgB,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;wBAC9D,MAAM,CAAC,GAAG,CAAC,CAAC;qBACZ;gBACF,CAAC,CAAA,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACJ,CAAC;KAAA;CACD"}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module GraphClientError
|
||||
*/
|
||||
/**
|
||||
* @class
|
||||
* Create GraphClientError object to handle client-side errors
|
||||
* encountered within the JavaScript Client SDK.
|
||||
* Whereas GraphError Class should be used to handle errors in the response from the Graph API.
|
||||
*/
|
||||
export declare class GraphClientError extends Error {
|
||||
/**
|
||||
* @public
|
||||
* A custom error. This property should set be when the error is not of instanceOf Error/GraphClientError.
|
||||
* Example =
|
||||
* const client = MicrosoftGraph.Client.init({
|
||||
* defaultVersion: "v1.0",
|
||||
* authProvider: (done) => { done({TokenError:"AccessToken cannot be null"}, "<ACCESS_TOKEN>");
|
||||
* });
|
||||
*/
|
||||
customError?: any;
|
||||
/**
|
||||
* @public
|
||||
* @static
|
||||
* @async
|
||||
* To set the GraphClientError object
|
||||
* @param {any} error - The error returned encountered by the Graph JavaScript Client SDK while processing request
|
||||
* @returns GraphClientError object set to the error passed
|
||||
*/
|
||||
static setGraphClientError(error: any): GraphClientError;
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Creates an instance of GraphClientError
|
||||
* @param {string} message? - Error message
|
||||
* @returns An instance of GraphClientError
|
||||
*/
|
||||
constructor(message?: string);
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module GraphClientError
|
||||
*/
|
||||
/**
|
||||
* @class
|
||||
* Create GraphClientError object to handle client-side errors
|
||||
* encountered within the JavaScript Client SDK.
|
||||
* Whereas GraphError Class should be used to handle errors in the response from the Graph API.
|
||||
*/
|
||||
export class GraphClientError extends Error {
|
||||
/**
|
||||
* @public
|
||||
* @static
|
||||
* @async
|
||||
* To set the GraphClientError object
|
||||
* @param {any} error - The error returned encountered by the Graph JavaScript Client SDK while processing request
|
||||
* @returns GraphClientError object set to the error passed
|
||||
*/
|
||||
static setGraphClientError(error) {
|
||||
let graphClientError;
|
||||
if (error instanceof Error) {
|
||||
graphClientError = error;
|
||||
}
|
||||
else {
|
||||
graphClientError = new GraphClientError();
|
||||
graphClientError.customError = error;
|
||||
}
|
||||
return graphClientError;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Creates an instance of GraphClientError
|
||||
* @param {string} message? - Error message
|
||||
* @returns An instance of GraphClientError
|
||||
*/
|
||||
constructor(message) {
|
||||
super(message);
|
||||
Object.setPrototypeOf(this, GraphClientError.prototype);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=GraphClientError.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"GraphClientError.js","sourceRoot":"","sources":["../../../src/GraphClientError.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AAEH;;;;;GAKG;AAEH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAY1C;;;;;;;OAOG;IACI,MAAM,CAAC,mBAAmB,CAAC,KAAU;QAC3C,IAAI,gBAAkC,CAAC;QACvC,IAAI,KAAK,YAAY,KAAK,EAAE;YAC3B,gBAAgB,GAAG,KAAK,CAAC;SACzB;aAAM;YACN,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;YAC1C,gBAAgB,CAAC,WAAW,GAAG,KAAK,CAAC;SACrC;QACD,OAAO,gBAAgB,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACH,YAAmB,OAAgB;QAClC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;CACD"}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module GraphError
|
||||
*/
|
||||
/**
|
||||
* @class
|
||||
* Class for GraphError
|
||||
* @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
|
||||
*/
|
||||
export declare class GraphError extends Error {
|
||||
/**
|
||||
* @public
|
||||
* A member holding status code of the error
|
||||
*/
|
||||
statusCode: number;
|
||||
/**
|
||||
* @public
|
||||
* A member holding code i.e name of the error
|
||||
*/
|
||||
code: string | null;
|
||||
/**
|
||||
* @public
|
||||
* A member holding request-id i.e identifier of the request
|
||||
*/
|
||||
requestId: string | null;
|
||||
/**
|
||||
* @public
|
||||
* A member holding processed date and time of the request
|
||||
*/
|
||||
date: Date;
|
||||
headers?: Headers;
|
||||
/**
|
||||
* @public
|
||||
* A member holding original error response by the graph service
|
||||
*/
|
||||
body: any;
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Creates an instance of GraphError
|
||||
* @param {number} [statusCode = -1] - The status code of the error
|
||||
* @param {string} [message] - The message of the error
|
||||
* @param {Error} [baseError] - The base error
|
||||
* @returns An instance of GraphError
|
||||
*/
|
||||
constructor(statusCode?: number, message?: string, baseError?: Error);
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module GraphError
|
||||
*/
|
||||
/**
|
||||
* @class
|
||||
* Class for GraphError
|
||||
* @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
|
||||
*/
|
||||
export class GraphError extends Error {
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Creates an instance of GraphError
|
||||
* @param {number} [statusCode = -1] - The status code of the error
|
||||
* @param {string} [message] - The message of the error
|
||||
* @param {Error} [baseError] - The base error
|
||||
* @returns An instance of GraphError
|
||||
*/
|
||||
constructor(statusCode = -1, message, baseError) {
|
||||
super(message || (baseError && baseError.message));
|
||||
// https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
||||
Object.setPrototypeOf(this, GraphError.prototype);
|
||||
this.statusCode = statusCode;
|
||||
this.code = null;
|
||||
this.requestId = null;
|
||||
this.date = new Date();
|
||||
this.body = null;
|
||||
this.stack = baseError ? baseError.stack : this.stack;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=GraphError.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"GraphError.js","sourceRoot":"","sources":["../../../src/GraphError.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AAEH;;;;;;GAMG;AAEH,MAAM,OAAO,UAAW,SAAQ,KAAK;IAiCpC;;;;;;;;OAQG;IACH,YAAmB,UAAU,GAAG,CAAC,CAAC,EAAE,OAAgB,EAAE,SAAiB;QACtE,KAAK,CAAC,OAAO,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QACnD,gIAAgI;QAChI,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;QAClD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;IACvD,CAAC;CACD"}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module GraphErrorHandler
|
||||
*/
|
||||
import { GraphError } from "./GraphError";
|
||||
import { GraphRequestCallback } from "./IGraphRequestCallback";
|
||||
/**
|
||||
* @class
|
||||
* Class for GraphErrorHandler
|
||||
*/
|
||||
export declare class GraphErrorHandler {
|
||||
/**
|
||||
* @private
|
||||
* @static
|
||||
* Populates the GraphError instance with Error instance values
|
||||
* @param {Error} error - The error returned by graph service or some native error
|
||||
* @param {number} [statusCode] - The status code of the response
|
||||
* @returns The GraphError instance
|
||||
*/
|
||||
private static constructError;
|
||||
/**
|
||||
* @private
|
||||
* @static
|
||||
* @async
|
||||
* Populates the GraphError instance from the Error returned by graph service
|
||||
* @param {GraphAPIErrorResponse} graphError - The error possibly returned by graph service or some native error
|
||||
* @param {number} statusCode - The status code of the response
|
||||
* @returns A promise that resolves to GraphError instance
|
||||
*
|
||||
* Example error for https://graph.microsoft.com/v1.0/me/events?$top=3&$search=foo
|
||||
* {
|
||||
* "error": {
|
||||
* "code": "SearchEvents",
|
||||
* "message": "The parameter $search is not currently supported on the Events resource.",
|
||||
* "innerError": {
|
||||
* "request-id": "b31c83fd-944c-4663-aa50-5d9ceb367e19",
|
||||
* "date": "2016-11-17T18:37:45"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
private static constructErrorFromResponse;
|
||||
/**
|
||||
* @public
|
||||
* @static
|
||||
* @async
|
||||
* To get the GraphError object
|
||||
* Reference - https://docs.microsoft.com/en-us/graph/errors
|
||||
* @param {any} [error = null] - The error returned by graph service or some native error
|
||||
* @param {number} [statusCode = -1] - The status code of the response
|
||||
* @param {GraphRequestCallback} [callback] - The graph request callback function
|
||||
* @returns A promise that resolves to GraphError instance
|
||||
*/
|
||||
static getError(error?: any, statusCode?: number, callback?: GraphRequestCallback, rawResponse?: Response): Promise<GraphError>;
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { __awaiter } from "tslib";
|
||||
/**
|
||||
* @module GraphErrorHandler
|
||||
*/
|
||||
import { GraphError } from "./GraphError";
|
||||
/**
|
||||
* @class
|
||||
* Class for GraphErrorHandler
|
||||
*/
|
||||
export class GraphErrorHandler {
|
||||
/**
|
||||
* @private
|
||||
* @static
|
||||
* Populates the GraphError instance with Error instance values
|
||||
* @param {Error} error - The error returned by graph service or some native error
|
||||
* @param {number} [statusCode] - The status code of the response
|
||||
* @returns The GraphError instance
|
||||
*/
|
||||
static constructError(error, statusCode, rawResponse) {
|
||||
const gError = new GraphError(statusCode, "", error);
|
||||
if (error.name !== undefined) {
|
||||
gError.code = error.name;
|
||||
}
|
||||
gError.body = error.toString();
|
||||
gError.date = new Date();
|
||||
gError.headers = rawResponse === null || rawResponse === void 0 ? void 0 : rawResponse.headers;
|
||||
return gError;
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* @static
|
||||
* @async
|
||||
* Populates the GraphError instance from the Error returned by graph service
|
||||
* @param {GraphAPIErrorResponse} graphError - The error possibly returned by graph service or some native error
|
||||
* @param {number} statusCode - The status code of the response
|
||||
* @returns A promise that resolves to GraphError instance
|
||||
*
|
||||
* Example error for https://graph.microsoft.com/v1.0/me/events?$top=3&$search=foo
|
||||
* {
|
||||
* "error": {
|
||||
* "code": "SearchEvents",
|
||||
* "message": "The parameter $search is not currently supported on the Events resource.",
|
||||
* "innerError": {
|
||||
* "request-id": "b31c83fd-944c-4663-aa50-5d9ceb367e19",
|
||||
* "date": "2016-11-17T18:37:45"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
static constructErrorFromResponse(graphError, statusCode, rawResponse) {
|
||||
const error = graphError.error;
|
||||
const gError = new GraphError(statusCode, error.message);
|
||||
gError.code = error.code;
|
||||
if (error.innerError !== undefined) {
|
||||
gError.requestId = error.innerError["request-id"];
|
||||
gError.date = new Date(error.innerError.date);
|
||||
}
|
||||
gError.body = JSON.stringify(error);
|
||||
gError.headers = rawResponse === null || rawResponse === void 0 ? void 0 : rawResponse.headers;
|
||||
return gError;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @static
|
||||
* @async
|
||||
* To get the GraphError object
|
||||
* Reference - https://docs.microsoft.com/en-us/graph/errors
|
||||
* @param {any} [error = null] - The error returned by graph service or some native error
|
||||
* @param {number} [statusCode = -1] - The status code of the response
|
||||
* @param {GraphRequestCallback} [callback] - The graph request callback function
|
||||
* @returns A promise that resolves to GraphError instance
|
||||
*/
|
||||
static getError(error = null, statusCode = -1, callback, rawResponse) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let gError;
|
||||
if (error && error.error) {
|
||||
gError = GraphErrorHandler.constructErrorFromResponse(error, statusCode, rawResponse);
|
||||
}
|
||||
else if (error instanceof Error) {
|
||||
gError = GraphErrorHandler.constructError(error, statusCode, rawResponse);
|
||||
}
|
||||
else {
|
||||
gError = new GraphError(statusCode);
|
||||
gError.body = error; // if a custom error is passed which is not instance of Error object or a graph API response
|
||||
}
|
||||
if (typeof callback === "function") {
|
||||
callback(gError, null);
|
||||
}
|
||||
else {
|
||||
return gError;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=GraphErrorHandler.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"GraphErrorHandler.js","sourceRoot":"","sources":["../../../src/GraphErrorHandler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAEH;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAiB1C;;;GAGG;AAEH,MAAM,OAAO,iBAAiB;IAC7B;;;;;;;OAOG;IACK,MAAM,CAAC,cAAc,CAAC,KAAY,EAAE,UAAmB,EAAE,WAAsB;QACtF,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,UAAU,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;QACrD,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE;YAC7B,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;SACzB;QACD,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;QAC/B,MAAM,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,CAAC,OAAO,GAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,CAAC;QACtC,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACK,MAAM,CAAC,0BAA0B,CAAC,UAAiC,EAAE,UAAkB,EAAE,WAAsB;QACtH,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;QAC/B,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QACzD,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACzB,IAAI,KAAK,CAAC,UAAU,KAAK,SAAS,EAAE;YACnC,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;YAClD,MAAM,CAAC,IAAI,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;SAC9C;QAED,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACpC,MAAM,CAAC,OAAO,GAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,CAAC;QAEtC,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;;;;;;;;OAUG;IACI,MAAM,CAAO,QAAQ,CAAC,QAAa,IAAI,EAAE,UAAU,GAAG,CAAC,CAAC,EAAE,QAA+B,EAAE,WAAsB;;YACvH,IAAI,MAAkB,CAAC;YACvB,IAAI,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE;gBACzB,MAAM,GAAG,iBAAiB,CAAC,0BAA0B,CAAC,KAAK,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;aACtF;iBAAM,IAAI,KAAK,YAAY,KAAK,EAAE;gBAClC,MAAM,GAAG,iBAAiB,CAAC,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;aAC1E;iBAAM;gBACN,MAAM,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;gBACpC,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,4FAA4F;aACjH;YACD,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;gBACnC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;aACvB;iBAAM;gBACN,OAAO,MAAM,CAAC;aACd;QACF,CAAC;KAAA;CACD"}
|
||||
+380
@@ -0,0 +1,380 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { HTTPClient } from "./HTTPClient";
|
||||
import { ClientOptions } from "./IClientOptions";
|
||||
import { GraphRequestCallback } from "./IGraphRequestCallback";
|
||||
import { MiddlewareOptions } from "./middleware/options/IMiddlewareOptions";
|
||||
import { ResponseType } from "./ResponseType";
|
||||
/**
|
||||
* @interface
|
||||
* Signature to representing key value pairs
|
||||
* @property {[key: string] : string | number} - The Key value pair
|
||||
*/
|
||||
interface KeyValuePairObjectStringNumber {
|
||||
[key: string]: string | number;
|
||||
}
|
||||
/**
|
||||
* @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 {KeyValuePairObjectStringNumber} oDataQueryParams - The oData Query Params
|
||||
* @property {KeyValuePairObjectStringNumber} otherURLQueryParams - The other query params for a request
|
||||
* @property {string[]} otherURLQueryOptions - The non key-value query parameters. Example- '/me?$whatif'
|
||||
*/
|
||||
export interface URLComponents {
|
||||
host: string;
|
||||
version: string;
|
||||
path?: string;
|
||||
oDataQueryParams: KeyValuePairObjectStringNumber;
|
||||
otherURLQueryParams: KeyValuePairObjectStringNumber;
|
||||
otherURLQueryOptions?: string[];
|
||||
}
|
||||
/**
|
||||
* @class
|
||||
* A Class representing GraphRequest
|
||||
*/
|
||||
export declare class GraphRequest {
|
||||
/**
|
||||
* @private
|
||||
* A member variable to hold HTTPClient instance
|
||||
*/
|
||||
private httpClient;
|
||||
/**
|
||||
* @private
|
||||
* A member variable to hold client options
|
||||
*/
|
||||
private config;
|
||||
/**
|
||||
* @private
|
||||
* A member to hold URL Components data
|
||||
*/
|
||||
private urlComponents;
|
||||
/**
|
||||
* @private
|
||||
* A member to hold custom header options for a request
|
||||
*/
|
||||
private _headers;
|
||||
/**
|
||||
* @private
|
||||
* A member to hold custom options for a request
|
||||
*/
|
||||
private _options;
|
||||
/**
|
||||
* @private
|
||||
* A member to hold the array of middleware options for a request
|
||||
*/
|
||||
private _middlewareOptions;
|
||||
/**
|
||||
* @private
|
||||
* A member to hold custom response type for a request
|
||||
*/
|
||||
private _responseType;
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Creates an instance of GraphRequest
|
||||
* @param {HTTPClient} httpClient - The HTTPClient instance
|
||||
* @param {ClientOptions} config - The options for making request
|
||||
* @param {string} path - A path string
|
||||
*/
|
||||
constructor(httpClient: HTTPClient, config: ClientOptions, path: string);
|
||||
/**
|
||||
* @private
|
||||
* Parses the path string and creates URLComponents out of it
|
||||
* @param {string} path - The request path string
|
||||
* @returns Nothing
|
||||
*/
|
||||
private parsePath;
|
||||
/**
|
||||
* @private
|
||||
* Adds the query parameter as comma separated values
|
||||
* @param {string} propertyName - The name of a property
|
||||
* @param {string|string[]} propertyValue - The vale of a property
|
||||
* @param {IArguments} additionalProperties - The additional properties
|
||||
* @returns Nothing
|
||||
*/
|
||||
private addCsvQueryParameter;
|
||||
/**
|
||||
* @private
|
||||
* Builds the full url from the URLComponents to make a request
|
||||
* @returns The URL string that is qualified to make a request to graph endpoint
|
||||
*/
|
||||
private buildFullUrl;
|
||||
/**
|
||||
* @private
|
||||
* Builds the query string from the URLComponents
|
||||
* @returns The Constructed query string
|
||||
*/
|
||||
private createQueryString;
|
||||
/**
|
||||
* @private
|
||||
* Parses the query parameters to set the urlComponents property of the GraphRequest object
|
||||
* @param {string|KeyValuePairObjectStringNumber} queryDictionaryOrString - The query parameter
|
||||
* @returns The same GraphRequest instance that is being called with
|
||||
*/
|
||||
private parseQueryParameter;
|
||||
/**
|
||||
* @private
|
||||
* Parses the query parameter of string type to set the urlComponents property of the GraphRequest object
|
||||
* @param {string} queryParameter - the query parameters
|
||||
* returns nothing
|
||||
*/
|
||||
private parseQueryParamenterString;
|
||||
/**
|
||||
* @private
|
||||
* Sets values into the urlComponents property of GraphRequest object.
|
||||
* @param {string} paramKey - the query parameter key
|
||||
* @param {string} paramValue - the query paramter value
|
||||
* @returns nothing
|
||||
*/
|
||||
private setURLComponentsQueryParamater;
|
||||
/**
|
||||
* @private
|
||||
* Check if the query parameter string has a valid key-value structure
|
||||
* @param {string} queryString - the query parameter string. Example -> "name=value"
|
||||
* #returns true if the query string has a valid key-value structure else false
|
||||
*/
|
||||
private isValidQueryKeyValuePair;
|
||||
/**
|
||||
* @private
|
||||
* Updates the custom headers and options for a request
|
||||
* @param {FetchOptions} options - The request options object
|
||||
* @returns Nothing
|
||||
*/
|
||||
private updateRequestOptions;
|
||||
/**
|
||||
* @private
|
||||
* @async
|
||||
* Adds the custom headers and options to the request and makes the HTTPClient send request call
|
||||
* @param {RequestInfo} request - The request url string or the Request object value
|
||||
* @param {FetchOptions} options - The options to make a request
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the response content
|
||||
*/
|
||||
private send;
|
||||
/**
|
||||
* @private
|
||||
* Checks if the content-type is present in the _headers property. If not present, defaults the content-type to application/json
|
||||
* @param none
|
||||
* @returns nothing
|
||||
*/
|
||||
private setHeaderContentType;
|
||||
/**
|
||||
* @public
|
||||
* Sets the custom header for a request
|
||||
* @param {string} headerKey - A header key
|
||||
* @param {string} headerValue - A header value
|
||||
* @returns The same GraphRequest instance that is being called with
|
||||
*/
|
||||
header(headerKey: string, headerValue: string): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* Sets the custom headers for a request
|
||||
* @param {KeyValuePairObjectStringNumber | HeadersInit} headers - The request headers
|
||||
* @returns The same GraphRequest instance that is being called with
|
||||
*/
|
||||
headers(headers: KeyValuePairObjectStringNumber | HeadersInit): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* Sets the option for making a request
|
||||
* @param {string} key - The key value
|
||||
* @param {any} value - The value
|
||||
* @returns The same GraphRequest instance that is being called with
|
||||
*/
|
||||
option(key: string, value: any): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* Sets the options for making a request
|
||||
* @param {{ [key: string]: any }} options - The options key value pair
|
||||
* @returns The same GraphRequest instance that is being called with
|
||||
*/
|
||||
options(options: {
|
||||
[key: string]: any;
|
||||
}): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* Sets the middleware options for a request
|
||||
* @param {MiddlewareOptions[]} options - The array of middleware options
|
||||
* @returns The same GraphRequest instance that is being called with
|
||||
*/
|
||||
middlewareOptions(options: MiddlewareOptions[]): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* Sets the api endpoint version for a request
|
||||
* @param {string} version - The version value
|
||||
* @returns The same GraphRequest instance that is being called with
|
||||
*/
|
||||
version(version: string): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* Sets the api endpoint version for a request
|
||||
* @param {ResponseType} responseType - The response type value
|
||||
* @returns The same GraphRequest instance that is being called with
|
||||
*/
|
||||
responseType(responseType: ResponseType): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* To add properties for select OData Query param
|
||||
* @param {string|string[]} properties - The Properties value
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the properties for $select query
|
||||
*/
|
||||
select(properties: string | string[]): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* To add properties for expand OData Query param
|
||||
* @param {string|string[]} properties - The Properties value
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the properties for $expand query
|
||||
*/
|
||||
expand(properties: string | string[]): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* To add properties for orderby OData Query param
|
||||
* @param {string|string[]} properties - The Properties value
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the properties for $orderby query
|
||||
*/
|
||||
orderby(properties: string | string[]): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* To add query string for filter OData Query param. The request URL accepts only one $filter Odata Query option and its value is set to the most recently passed filter query string.
|
||||
* @param {string} filterStr - The filter query string
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the $filter query
|
||||
*/
|
||||
filter(filterStr: string): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* To add criterion for search OData Query param. The request URL accepts only one $search Odata Query option and its value is set to the most recently passed search criterion string.
|
||||
* @param {string} searchStr - The search criterion string
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the $search query criteria
|
||||
*/
|
||||
search(searchStr: string): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* To add number for top OData Query param. The request URL accepts only one $top Odata Query option and its value is set to the most recently passed number value.
|
||||
* @param {number} n - The number value
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the number for $top query
|
||||
*/
|
||||
top(n: number): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* To add number for skip OData Query param. The request URL accepts only one $skip Odata Query option and its value is set to the most recently passed number value.
|
||||
* @param {number} n - The number value
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the number for the $skip query
|
||||
*/
|
||||
skip(n: number): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* To add token string for skipToken OData Query param. The request URL accepts only one $skipToken Odata Query option and its value is set to the most recently passed token value.
|
||||
* @param {string} token - The token value
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the token string for $skipToken query option
|
||||
*/
|
||||
skipToken(token: string): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* To add boolean for count OData Query param. The URL accepts only one $count Odata Query option and its value is set to the most recently passed boolean value.
|
||||
* @param {boolean} isCount - The count boolean
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the boolean value for the $count query option
|
||||
*/
|
||||
count(isCount?: boolean): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* Appends query string to the urlComponent
|
||||
* @param {string|KeyValuePairObjectStringNumber} queryDictionaryOrString - The query value
|
||||
* @returns The same GraphRequest instance that is being called with, after appending the query string to the url component
|
||||
*/
|
||||
query(queryDictionaryOrString: string | KeyValuePairObjectStringNumber): GraphRequest;
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Makes a http request with GET method
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the get response
|
||||
*/
|
||||
get(callback?: GraphRequestCallback): Promise<any>;
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Makes a http request with POST method
|
||||
* @param {any} content - The content that needs to be sent with the request
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the post response
|
||||
*/
|
||||
post(content: any, callback?: GraphRequestCallback): Promise<any>;
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Alias for Post request call
|
||||
* @param {any} content - The content that needs to be sent with the request
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the post response
|
||||
*/
|
||||
create(content: any, callback?: GraphRequestCallback): Promise<any>;
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Makes http request with PUT method
|
||||
* @param {any} content - The content that needs to be sent with the request
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the put response
|
||||
*/
|
||||
put(content: any, callback?: GraphRequestCallback): Promise<any>;
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Makes http request with PATCH method
|
||||
* @param {any} content - The content that needs to be sent with the request
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the patch response
|
||||
*/
|
||||
patch(content: any, callback?: GraphRequestCallback): Promise<any>;
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Alias for PATCH request
|
||||
* @param {any} content - The content that needs to be sent with the request
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the patch response
|
||||
*/
|
||||
update(content: any, callback?: GraphRequestCallback): Promise<any>;
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Makes http request with DELETE method
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the delete response
|
||||
*/
|
||||
delete(callback?: GraphRequestCallback): Promise<any>;
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Alias for delete request call
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the delete response
|
||||
*/
|
||||
del(callback?: GraphRequestCallback): Promise<any>;
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Makes a http request with GET method to read response as a stream.
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the getStream response
|
||||
*/
|
||||
getStream(callback?: GraphRequestCallback): Promise<any>;
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Makes a http request with GET method to read response as a stream.
|
||||
* @param {any} stream - The stream instance
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the putStream response
|
||||
*/
|
||||
putStream(stream: any, callback?: GraphRequestCallback): Promise<any>;
|
||||
}
|
||||
export {};
|
||||
+688
@@ -0,0 +1,688 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { __awaiter } from "tslib";
|
||||
/**
|
||||
* @module GraphRequest
|
||||
*/
|
||||
import { GraphClientError } from "./GraphClientError";
|
||||
import { GraphErrorHandler } from "./GraphErrorHandler";
|
||||
import { oDataQueryNames, serializeContent, urlJoin } from "./GraphRequestUtil";
|
||||
import { GraphResponseHandler } from "./GraphResponseHandler";
|
||||
import { MiddlewareControl } from "./middleware/MiddlewareControl";
|
||||
import { RequestMethod } from "./RequestMethod";
|
||||
import { ResponseType } from "./ResponseType";
|
||||
/**
|
||||
* @class
|
||||
* A Class representing GraphRequest
|
||||
*/
|
||||
export class GraphRequest {
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Creates an instance of GraphRequest
|
||||
* @param {HTTPClient} httpClient - The HTTPClient instance
|
||||
* @param {ClientOptions} config - The options for making request
|
||||
* @param {string} path - A path string
|
||||
*/
|
||||
constructor(httpClient, config, path) {
|
||||
/**
|
||||
* @private
|
||||
* Parses the path string and creates URLComponents out of it
|
||||
* @param {string} path - The request path string
|
||||
* @returns Nothing
|
||||
*/
|
||||
this.parsePath = (path) => {
|
||||
// Strips out the base of the url if they passed in
|
||||
if (path.indexOf("https://") !== -1) {
|
||||
path = path.replace("https://", "");
|
||||
// Find where the host ends
|
||||
const endOfHostStrPos = path.indexOf("/");
|
||||
if (endOfHostStrPos !== -1) {
|
||||
// Parse out the host
|
||||
this.urlComponents.host = "https://" + path.substring(0, endOfHostStrPos);
|
||||
// Strip the host from path
|
||||
path = path.substring(endOfHostStrPos + 1, path.length);
|
||||
}
|
||||
// Remove the following version
|
||||
const endOfVersionStrPos = path.indexOf("/");
|
||||
if (endOfVersionStrPos !== -1) {
|
||||
// Parse out the version
|
||||
this.urlComponents.version = path.substring(0, endOfVersionStrPos);
|
||||
// Strip version from path
|
||||
path = path.substring(endOfVersionStrPos + 1, path.length);
|
||||
}
|
||||
}
|
||||
// Strip out any leading "/"
|
||||
if (path.charAt(0) === "/") {
|
||||
path = path.substr(1);
|
||||
}
|
||||
const queryStrPos = path.indexOf("?");
|
||||
if (queryStrPos === -1) {
|
||||
// No query string
|
||||
this.urlComponents.path = path;
|
||||
}
|
||||
else {
|
||||
this.urlComponents.path = path.substr(0, queryStrPos);
|
||||
// Capture query string into oDataQueryParams and otherURLQueryParams
|
||||
const queryParams = path.substring(queryStrPos + 1, path.length).split("&");
|
||||
for (const queryParam of queryParams) {
|
||||
this.parseQueryParameter(queryParam);
|
||||
}
|
||||
}
|
||||
};
|
||||
this.httpClient = httpClient;
|
||||
this.config = config;
|
||||
this.urlComponents = {
|
||||
host: this.config.baseUrl,
|
||||
version: this.config.defaultVersion,
|
||||
oDataQueryParams: {},
|
||||
otherURLQueryParams: {},
|
||||
otherURLQueryOptions: [],
|
||||
};
|
||||
this._headers = {};
|
||||
this._options = {};
|
||||
this._middlewareOptions = [];
|
||||
this.parsePath(path);
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* Adds the query parameter as comma separated values
|
||||
* @param {string} propertyName - The name of a property
|
||||
* @param {string|string[]} propertyValue - The vale of a property
|
||||
* @param {IArguments} additionalProperties - The additional properties
|
||||
* @returns Nothing
|
||||
*/
|
||||
addCsvQueryParameter(propertyName, propertyValue, additionalProperties) {
|
||||
// If there are already $propertyName value there, append a ","
|
||||
this.urlComponents.oDataQueryParams[propertyName] = this.urlComponents.oDataQueryParams[propertyName] ? this.urlComponents.oDataQueryParams[propertyName] + "," : "";
|
||||
let allValues = [];
|
||||
if (additionalProperties.length > 1 && typeof propertyValue === "string") {
|
||||
allValues = Array.prototype.slice.call(additionalProperties);
|
||||
}
|
||||
else if (typeof propertyValue === "string") {
|
||||
allValues.push(propertyValue);
|
||||
}
|
||||
else {
|
||||
allValues = allValues.concat(propertyValue);
|
||||
}
|
||||
this.urlComponents.oDataQueryParams[propertyName] += allValues.join(",");
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* Builds the full url from the URLComponents to make a request
|
||||
* @returns The URL string that is qualified to make a request to graph endpoint
|
||||
*/
|
||||
buildFullUrl() {
|
||||
const url = urlJoin([this.urlComponents.host, this.urlComponents.version, this.urlComponents.path]) + this.createQueryString();
|
||||
if (this.config.debugLogging) {
|
||||
console.log(url);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* Builds the query string from the URLComponents
|
||||
* @returns The Constructed query string
|
||||
*/
|
||||
createQueryString() {
|
||||
// Combining query params from oDataQueryParams and otherURLQueryParams
|
||||
const urlComponents = this.urlComponents;
|
||||
const query = [];
|
||||
if (Object.keys(urlComponents.oDataQueryParams).length !== 0) {
|
||||
for (const property in urlComponents.oDataQueryParams) {
|
||||
if (Object.prototype.hasOwnProperty.call(urlComponents.oDataQueryParams, property)) {
|
||||
query.push(property + "=" + urlComponents.oDataQueryParams[property]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Object.keys(urlComponents.otherURLQueryParams).length !== 0) {
|
||||
for (const property in urlComponents.otherURLQueryParams) {
|
||||
if (Object.prototype.hasOwnProperty.call(urlComponents.otherURLQueryParams, property)) {
|
||||
query.push(property + "=" + urlComponents.otherURLQueryParams[property]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (urlComponents.otherURLQueryOptions.length !== 0) {
|
||||
for (const str of urlComponents.otherURLQueryOptions) {
|
||||
query.push(str);
|
||||
}
|
||||
}
|
||||
return query.length > 0 ? "?" + query.join("&") : "";
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* Parses the query parameters to set the urlComponents property of the GraphRequest object
|
||||
* @param {string|KeyValuePairObjectStringNumber} queryDictionaryOrString - The query parameter
|
||||
* @returns The same GraphRequest instance that is being called with
|
||||
*/
|
||||
parseQueryParameter(queryDictionaryOrString) {
|
||||
if (typeof queryDictionaryOrString === "string") {
|
||||
if (queryDictionaryOrString.charAt(0) === "?") {
|
||||
queryDictionaryOrString = queryDictionaryOrString.substring(1);
|
||||
}
|
||||
if (queryDictionaryOrString.indexOf("&") !== -1) {
|
||||
const queryParams = queryDictionaryOrString.split("&");
|
||||
for (const str of queryParams) {
|
||||
this.parseQueryParamenterString(str);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.parseQueryParamenterString(queryDictionaryOrString);
|
||||
}
|
||||
}
|
||||
else if (queryDictionaryOrString.constructor === Object) {
|
||||
for (const key in queryDictionaryOrString) {
|
||||
if (Object.prototype.hasOwnProperty.call(queryDictionaryOrString, key)) {
|
||||
this.setURLComponentsQueryParamater(key, queryDictionaryOrString[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* Parses the query parameter of string type to set the urlComponents property of the GraphRequest object
|
||||
* @param {string} queryParameter - the query parameters
|
||||
* returns nothing
|
||||
*/
|
||||
parseQueryParamenterString(queryParameter) {
|
||||
/* The query key-value pair must be split on the first equals sign to avoid errors in parsing nested query parameters.
|
||||
Example-> "/me?$expand=home($select=city)" */
|
||||
if (this.isValidQueryKeyValuePair(queryParameter)) {
|
||||
const indexOfFirstEquals = queryParameter.indexOf("=");
|
||||
const paramKey = queryParameter.substring(0, indexOfFirstEquals);
|
||||
const paramValue = queryParameter.substring(indexOfFirstEquals + 1);
|
||||
this.setURLComponentsQueryParamater(paramKey, paramValue);
|
||||
}
|
||||
else {
|
||||
/* Push values which are not of key-value structure.
|
||||
Example-> Handle an invalid input->.query(test), .query($select($select=name)) and let the Graph API respond with the error in the URL*/
|
||||
this.urlComponents.otherURLQueryOptions.push(queryParameter);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* Sets values into the urlComponents property of GraphRequest object.
|
||||
* @param {string} paramKey - the query parameter key
|
||||
* @param {string} paramValue - the query paramter value
|
||||
* @returns nothing
|
||||
*/
|
||||
setURLComponentsQueryParamater(paramKey, paramValue) {
|
||||
if (oDataQueryNames.indexOf(paramKey) !== -1) {
|
||||
const currentValue = this.urlComponents.oDataQueryParams[paramKey];
|
||||
const isValueAppendable = currentValue && (paramKey === "$expand" || paramKey === "$select" || paramKey === "$orderby");
|
||||
this.urlComponents.oDataQueryParams[paramKey] = isValueAppendable ? currentValue + "," + paramValue : paramValue;
|
||||
}
|
||||
else {
|
||||
this.urlComponents.otherURLQueryParams[paramKey] = paramValue;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* Check if the query parameter string has a valid key-value structure
|
||||
* @param {string} queryString - the query parameter string. Example -> "name=value"
|
||||
* #returns true if the query string has a valid key-value structure else false
|
||||
*/
|
||||
isValidQueryKeyValuePair(queryString) {
|
||||
const indexofFirstEquals = queryString.indexOf("=");
|
||||
if (indexofFirstEquals === -1) {
|
||||
return false;
|
||||
}
|
||||
const indexofOpeningParanthesis = queryString.indexOf("(");
|
||||
if (indexofOpeningParanthesis !== -1 && queryString.indexOf("(") < indexofFirstEquals) {
|
||||
// Example -> .query($select($expand=true));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* Updates the custom headers and options for a request
|
||||
* @param {FetchOptions} options - The request options object
|
||||
* @returns Nothing
|
||||
*/
|
||||
updateRequestOptions(options) {
|
||||
const optionsHeaders = Object.assign({}, options.headers);
|
||||
if (this.config.fetchOptions !== undefined) {
|
||||
const fetchOptions = Object.assign({}, this.config.fetchOptions);
|
||||
Object.assign(options, fetchOptions);
|
||||
if (typeof this.config.fetchOptions.headers !== undefined) {
|
||||
options.headers = Object.assign({}, this.config.fetchOptions.headers);
|
||||
}
|
||||
}
|
||||
Object.assign(options, this._options);
|
||||
if (options.headers !== undefined) {
|
||||
Object.assign(optionsHeaders, options.headers);
|
||||
}
|
||||
Object.assign(optionsHeaders, this._headers);
|
||||
options.headers = optionsHeaders;
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* @async
|
||||
* Adds the custom headers and options to the request and makes the HTTPClient send request call
|
||||
* @param {RequestInfo} request - The request url string or the Request object value
|
||||
* @param {FetchOptions} options - The options to make a request
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the response content
|
||||
*/
|
||||
send(request, options, callback) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let rawResponse;
|
||||
const middlewareControl = new MiddlewareControl(this._middlewareOptions);
|
||||
this.updateRequestOptions(options);
|
||||
const customHosts = (_a = this.config) === null || _a === void 0 ? void 0 : _a.customHosts;
|
||||
try {
|
||||
const context = yield this.httpClient.sendRequest({
|
||||
request,
|
||||
options,
|
||||
middlewareControl,
|
||||
customHosts,
|
||||
});
|
||||
rawResponse = context.response;
|
||||
const response = yield GraphResponseHandler.getResponse(rawResponse, this._responseType, callback);
|
||||
return response;
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof GraphClientError) {
|
||||
throw error;
|
||||
}
|
||||
let statusCode;
|
||||
if (rawResponse) {
|
||||
statusCode = rawResponse.status;
|
||||
}
|
||||
const gError = yield GraphErrorHandler.getError(error, statusCode, callback, rawResponse);
|
||||
throw gError;
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* Checks if the content-type is present in the _headers property. If not present, defaults the content-type to application/json
|
||||
* @param none
|
||||
* @returns nothing
|
||||
*/
|
||||
setHeaderContentType() {
|
||||
if (!this._headers) {
|
||||
this.header("Content-Type", "application/json");
|
||||
return;
|
||||
}
|
||||
const headerKeys = Object.keys(this._headers);
|
||||
for (const headerKey of headerKeys) {
|
||||
if (headerKey.toLowerCase() === "content-type") {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Default the content-type to application/json in case the content-type is not present in the header
|
||||
this.header("Content-Type", "application/json");
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* Sets the custom header for a request
|
||||
* @param {string} headerKey - A header key
|
||||
* @param {string} headerValue - A header value
|
||||
* @returns The same GraphRequest instance that is being called with
|
||||
*/
|
||||
header(headerKey, headerValue) {
|
||||
this._headers[headerKey] = headerValue;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* Sets the custom headers for a request
|
||||
* @param {KeyValuePairObjectStringNumber | HeadersInit} headers - The request headers
|
||||
* @returns The same GraphRequest instance that is being called with
|
||||
*/
|
||||
headers(headers) {
|
||||
for (const key in headers) {
|
||||
if (Object.prototype.hasOwnProperty.call(headers, key)) {
|
||||
this._headers[key] = headers[key];
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* Sets the option for making a request
|
||||
* @param {string} key - The key value
|
||||
* @param {any} value - The value
|
||||
* @returns The same GraphRequest instance that is being called with
|
||||
*/
|
||||
option(key, value) {
|
||||
this._options[key] = value;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* Sets the options for making a request
|
||||
* @param {{ [key: string]: any }} options - The options key value pair
|
||||
* @returns The same GraphRequest instance that is being called with
|
||||
*/
|
||||
options(options) {
|
||||
for (const key in options) {
|
||||
if (Object.prototype.hasOwnProperty.call(options, key)) {
|
||||
this._options[key] = options[key];
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* Sets the middleware options for a request
|
||||
* @param {MiddlewareOptions[]} options - The array of middleware options
|
||||
* @returns The same GraphRequest instance that is being called with
|
||||
*/
|
||||
middlewareOptions(options) {
|
||||
this._middlewareOptions = options;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* Sets the api endpoint version for a request
|
||||
* @param {string} version - The version value
|
||||
* @returns The same GraphRequest instance that is being called with
|
||||
*/
|
||||
version(version) {
|
||||
this.urlComponents.version = version;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* Sets the api endpoint version for a request
|
||||
* @param {ResponseType} responseType - The response type value
|
||||
* @returns The same GraphRequest instance that is being called with
|
||||
*/
|
||||
responseType(responseType) {
|
||||
this._responseType = responseType;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* To add properties for select OData Query param
|
||||
* @param {string|string[]} properties - The Properties value
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the properties for $select query
|
||||
*/
|
||||
/*
|
||||
* Accepts .select("displayName,birthday")
|
||||
* and .select(["displayName", "birthday"])
|
||||
* and .select("displayName", "birthday")
|
||||
*
|
||||
*/
|
||||
select(properties) {
|
||||
this.addCsvQueryParameter("$select", properties, arguments);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* To add properties for expand OData Query param
|
||||
* @param {string|string[]} properties - The Properties value
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the properties for $expand query
|
||||
*/
|
||||
expand(properties) {
|
||||
this.addCsvQueryParameter("$expand", properties, arguments);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* To add properties for orderby OData Query param
|
||||
* @param {string|string[]} properties - The Properties value
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the properties for $orderby query
|
||||
*/
|
||||
orderby(properties) {
|
||||
this.addCsvQueryParameter("$orderby", properties, arguments);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* To add query string for filter OData Query param. The request URL accepts only one $filter Odata Query option and its value is set to the most recently passed filter query string.
|
||||
* @param {string} filterStr - The filter query string
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the $filter query
|
||||
*/
|
||||
filter(filterStr) {
|
||||
this.urlComponents.oDataQueryParams.$filter = filterStr;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* To add criterion for search OData Query param. The request URL accepts only one $search Odata Query option and its value is set to the most recently passed search criterion string.
|
||||
* @param {string} searchStr - The search criterion string
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the $search query criteria
|
||||
*/
|
||||
search(searchStr) {
|
||||
this.urlComponents.oDataQueryParams.$search = searchStr;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* To add number for top OData Query param. The request URL accepts only one $top Odata Query option and its value is set to the most recently passed number value.
|
||||
* @param {number} n - The number value
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the number for $top query
|
||||
*/
|
||||
top(n) {
|
||||
this.urlComponents.oDataQueryParams.$top = n;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* To add number for skip OData Query param. The request URL accepts only one $skip Odata Query option and its value is set to the most recently passed number value.
|
||||
* @param {number} n - The number value
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the number for the $skip query
|
||||
*/
|
||||
skip(n) {
|
||||
this.urlComponents.oDataQueryParams.$skip = n;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* To add token string for skipToken OData Query param. The request URL accepts only one $skipToken Odata Query option and its value is set to the most recently passed token value.
|
||||
* @param {string} token - The token value
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the token string for $skipToken query option
|
||||
*/
|
||||
skipToken(token) {
|
||||
this.urlComponents.oDataQueryParams.$skipToken = token;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* To add boolean for count OData Query param. The URL accepts only one $count Odata Query option and its value is set to the most recently passed boolean value.
|
||||
* @param {boolean} isCount - The count boolean
|
||||
* @returns The same GraphRequest instance that is being called with, after adding the boolean value for the $count query option
|
||||
*/
|
||||
count(isCount = true) {
|
||||
this.urlComponents.oDataQueryParams.$count = isCount.toString();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* Appends query string to the urlComponent
|
||||
* @param {string|KeyValuePairObjectStringNumber} queryDictionaryOrString - The query value
|
||||
* @returns The same GraphRequest instance that is being called with, after appending the query string to the url component
|
||||
*/
|
||||
/*
|
||||
* Accepts .query("displayName=xyz")
|
||||
* and .select({ name: "value" })
|
||||
*/
|
||||
query(queryDictionaryOrString) {
|
||||
return this.parseQueryParameter(queryDictionaryOrString);
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Makes a http request with GET method
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the get response
|
||||
*/
|
||||
get(callback) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const url = this.buildFullUrl();
|
||||
const options = {
|
||||
method: RequestMethod.GET,
|
||||
};
|
||||
const response = yield this.send(url, options, callback);
|
||||
return response;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Makes a http request with POST method
|
||||
* @param {any} content - The content that needs to be sent with the request
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the post response
|
||||
*/
|
||||
post(content, callback) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const url = this.buildFullUrl();
|
||||
const options = {
|
||||
method: RequestMethod.POST,
|
||||
body: serializeContent(content),
|
||||
};
|
||||
const className = content && content.constructor && content.constructor.name;
|
||||
if (className === "FormData") {
|
||||
// Content-Type headers should not be specified in case the of FormData type content
|
||||
options.headers = {};
|
||||
}
|
||||
else {
|
||||
this.setHeaderContentType();
|
||||
options.headers = this._headers;
|
||||
}
|
||||
return yield this.send(url, options, callback);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Alias for Post request call
|
||||
* @param {any} content - The content that needs to be sent with the request
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the post response
|
||||
*/
|
||||
create(content, callback) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return yield this.post(content, callback);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Makes http request with PUT method
|
||||
* @param {any} content - The content that needs to be sent with the request
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the put response
|
||||
*/
|
||||
put(content, callback) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const url = this.buildFullUrl();
|
||||
this.setHeaderContentType();
|
||||
const options = {
|
||||
method: RequestMethod.PUT,
|
||||
body: serializeContent(content),
|
||||
};
|
||||
return yield this.send(url, options, callback);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Makes http request with PATCH method
|
||||
* @param {any} content - The content that needs to be sent with the request
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the patch response
|
||||
*/
|
||||
patch(content, callback) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const url = this.buildFullUrl();
|
||||
this.setHeaderContentType();
|
||||
const options = {
|
||||
method: RequestMethod.PATCH,
|
||||
body: serializeContent(content),
|
||||
};
|
||||
return yield this.send(url, options, callback);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Alias for PATCH request
|
||||
* @param {any} content - The content that needs to be sent with the request
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the patch response
|
||||
*/
|
||||
update(content, callback) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return yield this.patch(content, callback);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Makes http request with DELETE method
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the delete response
|
||||
*/
|
||||
delete(callback) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const url = this.buildFullUrl();
|
||||
const options = {
|
||||
method: RequestMethod.DELETE,
|
||||
};
|
||||
return yield this.send(url, options, callback);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Alias for delete request call
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the delete response
|
||||
*/
|
||||
del(callback) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return yield this.delete(callback);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Makes a http request with GET method to read response as a stream.
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the getStream response
|
||||
*/
|
||||
getStream(callback) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const url = this.buildFullUrl();
|
||||
const options = {
|
||||
method: RequestMethod.GET,
|
||||
};
|
||||
this.responseType(ResponseType.STREAM);
|
||||
return yield this.send(url, options, callback);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Makes a http request with GET method to read response as a stream.
|
||||
* @param {any} stream - The stream instance
|
||||
* @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
|
||||
* @returns A promise that resolves to the putStream response
|
||||
*/
|
||||
putStream(stream, callback) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const url = this.buildFullUrl();
|
||||
const options = {
|
||||
method: RequestMethod.PUT,
|
||||
headers: {
|
||||
"Content-Type": "application/octet-stream",
|
||||
},
|
||||
body: stream,
|
||||
};
|
||||
return yield this.send(url, options, callback);
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=GraphRequest.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+42
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* To hold list of OData query params
|
||||
*/
|
||||
export declare const oDataQueryNames: string[];
|
||||
/**
|
||||
* To construct the URL by appending the segments with "/"
|
||||
* @param {string[]} urlSegments - The array of strings
|
||||
* @returns The constructed URL string
|
||||
*/
|
||||
export declare const urlJoin: (urlSegments: string[]) => string;
|
||||
/**
|
||||
* Serializes the content
|
||||
* @param {any} content - The content value that needs to be serialized
|
||||
* @returns The serialized content
|
||||
*
|
||||
* Note:
|
||||
* This conversion is required due to the following reasons:
|
||||
* Body parameter of Request method of isomorphic-fetch only accepts Blob, ArrayBuffer, FormData, TypedArrays string.
|
||||
* Node.js platform does not support Blob, FormData. Javascript File object inherits from Blob so it is also not supported in node. Therefore content of type Blob, File, FormData will only come from browsers.
|
||||
* Parallel to ArrayBuffer in javascript, node provides Buffer interface. Node's Buffer is able to send the arbitrary binary data to the server successfully for both Browser and Node platform. Whereas sending binary data via ArrayBuffer or TypedArrays was only possible using Browser. To support both Node and Browser, `serializeContent` converts TypedArrays or ArrayBuffer to `Node Buffer`.
|
||||
* If the data received is in JSON format, `serializeContent` converts the JSON to string.
|
||||
*/
|
||||
export declare const serializeContent: (content: any) => any;
|
||||
/**
|
||||
* Checks if the url is one of the service root endpoints for Microsoft Graph and Graph Explorer.
|
||||
* @param {string} url - The url to be verified
|
||||
* @returns {boolean} - Returns true if the url is a Graph URL
|
||||
*/
|
||||
export declare const isGraphURL: (url: string) => boolean;
|
||||
/**
|
||||
* Checks if the url is for one of the custom hosts provided during client initialization
|
||||
* @param {string} url - The url to be verified
|
||||
* @param {Set} customHosts - The url to be verified
|
||||
* @returns {boolean} - Returns true if the url is a for a custom host
|
||||
*/
|
||||
export declare const isCustomHost: (url: string, customHosts: Set<string>) => boolean;
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module GraphRequestUtil
|
||||
*/
|
||||
import { GRAPH_URLS } from "./Constants";
|
||||
import { GraphClientError } from "./GraphClientError";
|
||||
/**
|
||||
* To hold list of OData query params
|
||||
*/
|
||||
export const oDataQueryNames = ["$select", "$expand", "$orderby", "$filter", "$top", "$skip", "$skipToken", "$count"];
|
||||
/**
|
||||
* To construct the URL by appending the segments with "/"
|
||||
* @param {string[]} urlSegments - The array of strings
|
||||
* @returns The constructed URL string
|
||||
*/
|
||||
export const urlJoin = (urlSegments) => {
|
||||
const removePostSlash = (s) => s.replace(/\/+$/, "");
|
||||
const removePreSlash = (s) => s.replace(/^\/+/, "");
|
||||
const joiner = (pre, cur) => [removePostSlash(pre), removePreSlash(cur)].join("/");
|
||||
const parts = Array.prototype.slice.call(urlSegments);
|
||||
return parts.reduce(joiner);
|
||||
};
|
||||
/**
|
||||
* Serializes the content
|
||||
* @param {any} content - The content value that needs to be serialized
|
||||
* @returns The serialized content
|
||||
*
|
||||
* Note:
|
||||
* This conversion is required due to the following reasons:
|
||||
* Body parameter of Request method of isomorphic-fetch only accepts Blob, ArrayBuffer, FormData, TypedArrays string.
|
||||
* Node.js platform does not support Blob, FormData. Javascript File object inherits from Blob so it is also not supported in node. Therefore content of type Blob, File, FormData will only come from browsers.
|
||||
* Parallel to ArrayBuffer in javascript, node provides Buffer interface. Node's Buffer is able to send the arbitrary binary data to the server successfully for both Browser and Node platform. Whereas sending binary data via ArrayBuffer or TypedArrays was only possible using Browser. To support both Node and Browser, `serializeContent` converts TypedArrays or ArrayBuffer to `Node Buffer`.
|
||||
* If the data received is in JSON format, `serializeContent` converts the JSON to string.
|
||||
*/
|
||||
export const serializeContent = (content) => {
|
||||
const className = content && content.constructor && content.constructor.name;
|
||||
if (className === "Buffer" || className === "Blob" || className === "File" || className === "FormData" || typeof content === "string") {
|
||||
return content;
|
||||
}
|
||||
if (className === "ArrayBuffer") {
|
||||
content = Buffer.from(content);
|
||||
}
|
||||
else if (className === "Int8Array" || className === "Int16Array" || className === "Int32Array" || className === "Uint8Array" || className === "Uint16Array" || className === "Uint32Array" || className === "Uint8ClampedArray" || className === "Float32Array" || className === "Float64Array" || className === "DataView") {
|
||||
content = Buffer.from(content.buffer);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
content = JSON.stringify(content);
|
||||
}
|
||||
catch (error) {
|
||||
throw new Error("Unable to stringify the content");
|
||||
}
|
||||
}
|
||||
return content;
|
||||
};
|
||||
/**
|
||||
* Checks if the url is one of the service root endpoints for Microsoft Graph and Graph Explorer.
|
||||
* @param {string} url - The url to be verified
|
||||
* @returns {boolean} - Returns true if the url is a Graph URL
|
||||
*/
|
||||
export const isGraphURL = (url) => {
|
||||
return isValidEndpoint(url);
|
||||
};
|
||||
/**
|
||||
* Checks if the url is for one of the custom hosts provided during client initialization
|
||||
* @param {string} url - The url to be verified
|
||||
* @param {Set} customHosts - The url to be verified
|
||||
* @returns {boolean} - Returns true if the url is a for a custom host
|
||||
*/
|
||||
export const isCustomHost = (url, customHosts) => {
|
||||
customHosts.forEach((host) => isCustomHostValid(host));
|
||||
return isValidEndpoint(url, customHosts);
|
||||
};
|
||||
/**
|
||||
* Checks if the url is for one of the provided hosts.
|
||||
* @param {string} url - The url to be verified
|
||||
* @param {Set<string>} allowedHosts - A set of hosts.
|
||||
* @returns {boolean} - Returns true is for one of the provided endpoints.
|
||||
*/
|
||||
const isValidEndpoint = (url, allowedHosts = GRAPH_URLS) => {
|
||||
// Valid Graph URL pattern - https://graph.microsoft.com/{version}/{resource}?{query-parameters}
|
||||
// Valid Graph URL example - https://graph.microsoft.com/v1.0/
|
||||
url = url.toLowerCase();
|
||||
if (url.indexOf("https://") !== -1) {
|
||||
url = url.replace("https://", "");
|
||||
// Find where the host ends
|
||||
const startofPortNoPos = url.indexOf(":");
|
||||
const endOfHostStrPos = url.indexOf("/");
|
||||
let hostName = "";
|
||||
if (endOfHostStrPos !== -1) {
|
||||
if (startofPortNoPos !== -1 && startofPortNoPos < endOfHostStrPos) {
|
||||
hostName = url.substring(0, startofPortNoPos);
|
||||
return allowedHosts.has(hostName);
|
||||
}
|
||||
// Parse out the host
|
||||
hostName = url.substring(0, endOfHostStrPos);
|
||||
return allowedHosts.has(hostName);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* Throws error if the string is not a valid host/hostname and contains other url parts.
|
||||
* @param {string} host - The host to be verified
|
||||
*/
|
||||
const isCustomHostValid = (host) => {
|
||||
if (host.indexOf("/") !== -1) {
|
||||
throw new GraphClientError("Please add only hosts or hostnames to the CustomHosts config. If the url is `http://example.com:3000/`, host is `example:3000`");
|
||||
}
|
||||
};
|
||||
//# sourceMappingURL=GraphRequestUtil.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"GraphRequestUtil.js","sourceRoot":"","sources":["../../../src/GraphRequestUtil.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC;AAEtH;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,WAAqB,EAAU,EAAE;IACxD,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACrD,MAAM,cAAc,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnF,MAAM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACtD,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAY,EAAO,EAAE;IACrD,MAAM,SAAS,GAAW,OAAO,IAAI,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC;IACrF,IAAI,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,MAAM,IAAI,SAAS,KAAK,MAAM,IAAI,SAAS,KAAK,UAAU,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QACtI,OAAO,OAAO,CAAC;KACf;IACD,IAAI,SAAS,KAAK,aAAa,EAAE;QAChC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;KAC/B;SAAM,IAAI,SAAS,KAAK,WAAW,IAAI,SAAS,KAAK,YAAY,IAAI,SAAS,KAAK,YAAY,IAAI,SAAS,KAAK,YAAY,IAAI,SAAS,KAAK,aAAa,IAAI,SAAS,KAAK,aAAa,IAAI,SAAS,KAAK,mBAAmB,IAAI,SAAS,KAAK,cAAc,IAAI,SAAS,KAAK,cAAc,IAAI,SAAS,KAAK,UAAU,EAAE;QAC9T,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;KACtC;SAAM;QACN,IAAI;YACH,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;SAClC;QAAC,OAAO,KAAK,EAAE;YACf,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;SACnD;KACD;IACD,OAAO,OAAO,CAAC;AAChB,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAW,EAAE;IAClD,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAW,EAAE,WAAwB,EAAW,EAAE;IAC9E,WAAW,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;IACvD,OAAO,eAAe,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;AAC1C,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,eAAe,GAAG,CAAC,GAAW,EAAE,eAA4B,UAAU,EAAW,EAAE;IACxF,gGAAgG;IAChG,8DAA8D;IAC9D,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;IAExB,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE;QACnC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAElC,2BAA2B;QAC3B,MAAM,gBAAgB,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC1C,MAAM,eAAe,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,QAAQ,GAAG,EAAE,CAAC;QAClB,IAAI,eAAe,KAAK,CAAC,CAAC,EAAE;YAC3B,IAAI,gBAAgB,KAAK,CAAC,CAAC,IAAI,gBAAgB,GAAG,eAAe,EAAE;gBAClE,QAAQ,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC;gBAC9C,OAAO,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;aAClC;YACD,qBAAqB;YACrB,QAAQ,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC;YAC7C,OAAO,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;SAClC;KACD;IAED,OAAO,KAAK,CAAC;AACd,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAE,EAAE;IAC1C,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;QAC7B,MAAM,IAAI,gBAAgB,CAAC,gIAAgI,CAAC,CAAC;KAC7J;AACF,CAAC,CAAC"}
|
||||
Generated
Vendored
+62
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module GraphResponseHandler
|
||||
* References - https://fetch.spec.whatwg.org/#responses
|
||||
*/
|
||||
import { GraphRequestCallback } from "./IGraphRequestCallback";
|
||||
import { ResponseType } from "./ResponseType";
|
||||
/**
|
||||
* @enum
|
||||
* Enum for document types
|
||||
* @property {string} TEXT_HTML - The text/html content type
|
||||
* @property {string} TEXT_XML - The text/xml content type
|
||||
* @property {string} APPLICATION_XML - The application/xml content type
|
||||
* @property {string} APPLICATION_XHTML - The application/xhml+xml content type
|
||||
*/
|
||||
export declare enum DocumentType {
|
||||
TEXT_HTML = "text/html",
|
||||
TEXT_XML = "text/xml",
|
||||
APPLICATION_XML = "application/xml",
|
||||
APPLICATION_XHTML = "application/xhtml+xml"
|
||||
}
|
||||
/**
|
||||
* @class
|
||||
* Class for GraphResponseHandler
|
||||
*/
|
||||
export declare class GraphResponseHandler {
|
||||
/**
|
||||
* @private
|
||||
* @static
|
||||
* To parse Document response
|
||||
* @param {Response} rawResponse - The response object
|
||||
* @param {DocumentType} type - The type to which the document needs to be parsed
|
||||
* @returns A promise that resolves to a document content
|
||||
*/
|
||||
private static parseDocumentResponse;
|
||||
/**
|
||||
* @private
|
||||
* @static
|
||||
* @async
|
||||
* To convert the native Response to response content
|
||||
* @param {Response} rawResponse - The response object
|
||||
* @param {ResponseType} [responseType] - The response type value
|
||||
* @returns A promise that resolves to the converted response content
|
||||
*/
|
||||
private static convertResponse;
|
||||
/**
|
||||
* @public
|
||||
* @static
|
||||
* @async
|
||||
* To get the parsed response
|
||||
* @param {Response} rawResponse - The response object
|
||||
* @param {ResponseType} [responseType] - The response type value
|
||||
* @param {GraphRequestCallback} [callback] - The graph request callback function
|
||||
* @returns The parsed response
|
||||
*/
|
||||
static getResponse(rawResponse: Response, responseType?: ResponseType, callback?: GraphRequestCallback): Promise<any>;
|
||||
}
|
||||
Generated
Vendored
+186
@@ -0,0 +1,186 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { __awaiter } from "tslib";
|
||||
import { ResponseType } from "./ResponseType";
|
||||
/**
|
||||
* @enum
|
||||
* Enum for document types
|
||||
* @property {string} TEXT_HTML - The text/html content type
|
||||
* @property {string} TEXT_XML - The text/xml content type
|
||||
* @property {string} APPLICATION_XML - The application/xml content type
|
||||
* @property {string} APPLICATION_XHTML - The application/xhml+xml content type
|
||||
*/
|
||||
export var DocumentType;
|
||||
(function (DocumentType) {
|
||||
DocumentType["TEXT_HTML"] = "text/html";
|
||||
DocumentType["TEXT_XML"] = "text/xml";
|
||||
DocumentType["APPLICATION_XML"] = "application/xml";
|
||||
DocumentType["APPLICATION_XHTML"] = "application/xhtml+xml";
|
||||
})(DocumentType || (DocumentType = {}));
|
||||
/**
|
||||
* @enum
|
||||
* Enum for Content types
|
||||
* @property {string} TEXT_PLAIN - The text/plain content type
|
||||
* @property {string} APPLICATION_JSON - The application/json content type
|
||||
*/
|
||||
var ContentType;
|
||||
(function (ContentType) {
|
||||
ContentType["TEXT_PLAIN"] = "text/plain";
|
||||
ContentType["APPLICATION_JSON"] = "application/json";
|
||||
})(ContentType || (ContentType = {}));
|
||||
/**
|
||||
* @enum
|
||||
* Enum for Content type regex
|
||||
* @property {string} DOCUMENT - The regex to match document content types
|
||||
* @property {string} IMAGE - The regex to match image content types
|
||||
*/
|
||||
var ContentTypeRegexStr;
|
||||
(function (ContentTypeRegexStr) {
|
||||
ContentTypeRegexStr["DOCUMENT"] = "^(text\\/(html|xml))|(application\\/(xml|xhtml\\+xml))$";
|
||||
ContentTypeRegexStr["IMAGE"] = "^image\\/.+";
|
||||
})(ContentTypeRegexStr || (ContentTypeRegexStr = {}));
|
||||
/**
|
||||
* @class
|
||||
* Class for GraphResponseHandler
|
||||
*/
|
||||
export class GraphResponseHandler {
|
||||
/**
|
||||
* @private
|
||||
* @static
|
||||
* To parse Document response
|
||||
* @param {Response} rawResponse - The response object
|
||||
* @param {DocumentType} type - The type to which the document needs to be parsed
|
||||
* @returns A promise that resolves to a document content
|
||||
*/
|
||||
static parseDocumentResponse(rawResponse, type) {
|
||||
if (typeof DOMParser !== "undefined") {
|
||||
return new Promise((resolve, reject) => {
|
||||
rawResponse.text().then((xmlString) => {
|
||||
try {
|
||||
const parser = new DOMParser();
|
||||
const xmlDoc = parser.parseFromString(xmlString, type);
|
||||
resolve(xmlDoc);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
return Promise.resolve(rawResponse.body);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* @static
|
||||
* @async
|
||||
* To convert the native Response to response content
|
||||
* @param {Response} rawResponse - The response object
|
||||
* @param {ResponseType} [responseType] - The response type value
|
||||
* @returns A promise that resolves to the converted response content
|
||||
*/
|
||||
static convertResponse(rawResponse, responseType) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (rawResponse.status === 204) {
|
||||
// NO CONTENT
|
||||
return Promise.resolve();
|
||||
}
|
||||
let responseValue;
|
||||
const contentType = rawResponse.headers.get("Content-type");
|
||||
switch (responseType) {
|
||||
case ResponseType.ARRAYBUFFER:
|
||||
responseValue = yield rawResponse.arrayBuffer();
|
||||
break;
|
||||
case ResponseType.BLOB:
|
||||
responseValue = yield rawResponse.blob();
|
||||
break;
|
||||
case ResponseType.DOCUMENT:
|
||||
responseValue = yield GraphResponseHandler.parseDocumentResponse(rawResponse, DocumentType.TEXT_XML);
|
||||
break;
|
||||
case ResponseType.JSON:
|
||||
responseValue = yield rawResponse.json();
|
||||
break;
|
||||
case ResponseType.STREAM:
|
||||
responseValue = yield Promise.resolve(rawResponse.body);
|
||||
break;
|
||||
case ResponseType.TEXT:
|
||||
responseValue = yield rawResponse.text();
|
||||
break;
|
||||
default:
|
||||
if (contentType !== null) {
|
||||
const mimeType = contentType.split(";")[0];
|
||||
if (new RegExp(ContentTypeRegexStr.DOCUMENT).test(mimeType)) {
|
||||
responseValue = yield GraphResponseHandler.parseDocumentResponse(rawResponse, mimeType);
|
||||
}
|
||||
else if (new RegExp(ContentTypeRegexStr.IMAGE).test(mimeType)) {
|
||||
responseValue = rawResponse.blob();
|
||||
}
|
||||
else if (mimeType === ContentType.TEXT_PLAIN) {
|
||||
responseValue = yield rawResponse.text();
|
||||
}
|
||||
else if (mimeType === ContentType.APPLICATION_JSON) {
|
||||
responseValue = yield rawResponse.json();
|
||||
}
|
||||
else {
|
||||
responseValue = Promise.resolve(rawResponse.body);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/**
|
||||
* RFC specification {@link https://tools.ietf.org/html/rfc7231#section-3.1.1.5} says:
|
||||
* A sender that generates a message containing a payload body SHOULD
|
||||
* generate a Content-Type header field in that message unless the
|
||||
* intended media type of the enclosed representation is unknown to the
|
||||
* sender. If a Content-Type header field is not present, the recipient
|
||||
* MAY either assume a media type of "application/octet-stream"
|
||||
* ([RFC2046], Section 4.5.1) or examine the data to determine its type.
|
||||
*
|
||||
* So assuming it as a stream type so returning the body.
|
||||
*/
|
||||
responseValue = Promise.resolve(rawResponse.body);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return responseValue;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @static
|
||||
* @async
|
||||
* To get the parsed response
|
||||
* @param {Response} rawResponse - The response object
|
||||
* @param {ResponseType} [responseType] - The response type value
|
||||
* @param {GraphRequestCallback} [callback] - The graph request callback function
|
||||
* @returns The parsed response
|
||||
*/
|
||||
static getResponse(rawResponse, responseType, callback) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (responseType === ResponseType.RAW) {
|
||||
return Promise.resolve(rawResponse);
|
||||
}
|
||||
else {
|
||||
const response = yield GraphResponseHandler.convertResponse(rawResponse, responseType);
|
||||
if (rawResponse.ok) {
|
||||
// Status Code 2XX
|
||||
if (typeof callback === "function") {
|
||||
callback(null, response);
|
||||
}
|
||||
else {
|
||||
return response;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// NOT OK Response
|
||||
throw response;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=GraphResponseHandler.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"GraphResponseHandler.js","sourceRoot":"","sources":["../../../src/GraphResponseHandler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAQH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;GAOG;AACH,MAAM,CAAN,IAAY,YAKX;AALD,WAAY,YAAY;IACvB,uCAAuB,CAAA;IACvB,qCAAqB,CAAA;IACrB,mDAAmC,CAAA;IACnC,2DAA2C,CAAA;AAC5C,CAAC,EALW,YAAY,KAAZ,YAAY,QAKvB;AAED;;;;;GAKG;AAEH,IAAK,WAGJ;AAHD,WAAK,WAAW;IACf,wCAAyB,CAAA;IACzB,oDAAqC,CAAA;AACtC,CAAC,EAHI,WAAW,KAAX,WAAW,QAGf;AAED;;;;;GAKG;AACH,IAAK,mBAGJ;AAHD,WAAK,mBAAmB;IACvB,2FAAoE,CAAA;IACpE,4CAAqB,CAAA;AACtB,CAAC,EAHI,mBAAmB,KAAnB,mBAAmB,QAGvB;AAED;;;GAGG;AAEH,MAAM,OAAO,oBAAoB;IAChC;;;;;;;OAOG;IACK,MAAM,CAAC,qBAAqB,CAAC,WAAqB,EAAE,IAAkB;QAC7E,IAAI,OAAO,SAAS,KAAK,WAAW,EAAE;YACrC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACtC,WAAW,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE;oBACrC,IAAI;wBACH,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;wBAC/B,MAAM,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;wBACvD,OAAO,CAAC,MAAM,CAAC,CAAC;qBAChB;oBAAC,OAAO,KAAK,EAAE;wBACf,MAAM,CAAC,KAAK,CAAC,CAAC;qBACd;gBACF,CAAC,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;SACH;aAAM;YACN,OAAO,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;SACzC;IACF,CAAC;IAED;;;;;;;;OAQG;IACK,MAAM,CAAO,eAAe,CAAC,WAAqB,EAAE,YAA2B;;YACtF,IAAI,WAAW,CAAC,MAAM,KAAK,GAAG,EAAE;gBAC/B,aAAa;gBACb,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;aACzB;YACD,IAAI,aAAkB,CAAC;YACvB,MAAM,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YAC5D,QAAQ,YAAY,EAAE;gBACrB,KAAK,YAAY,CAAC,WAAW;oBAC5B,aAAa,GAAG,MAAM,WAAW,CAAC,WAAW,EAAE,CAAC;oBAChD,MAAM;gBACP,KAAK,YAAY,CAAC,IAAI;oBACrB,aAAa,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC;oBACzC,MAAM;gBACP,KAAK,YAAY,CAAC,QAAQ;oBACzB,aAAa,GAAG,MAAM,oBAAoB,CAAC,qBAAqB,CAAC,WAAW,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;oBACrG,MAAM;gBACP,KAAK,YAAY,CAAC,IAAI;oBACrB,aAAa,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC;oBACzC,MAAM;gBACP,KAAK,YAAY,CAAC,MAAM;oBACvB,aAAa,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;oBACxD,MAAM;gBACP,KAAK,YAAY,CAAC,IAAI;oBACrB,aAAa,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC;oBACzC,MAAM;gBACP;oBACC,IAAI,WAAW,KAAK,IAAI,EAAE;wBACzB,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;wBAC3C,IAAI,IAAI,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;4BAC5D,aAAa,GAAG,MAAM,oBAAoB,CAAC,qBAAqB,CAAC,WAAW,EAAE,QAAwB,CAAC,CAAC;yBACxG;6BAAM,IAAI,IAAI,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;4BAChE,aAAa,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC;yBACnC;6BAAM,IAAI,QAAQ,KAAK,WAAW,CAAC,UAAU,EAAE;4BAC/C,aAAa,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC;yBACzC;6BAAM,IAAI,QAAQ,KAAK,WAAW,CAAC,gBAAgB,EAAE;4BACrD,aAAa,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC;yBACzC;6BAAM;4BACN,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;yBAClD;qBACD;yBAAM;wBACN;;;;;;;;;;2BAUG;wBACH,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;qBAClD;oBACD,MAAM;aACP;YACD,OAAO,aAAa,CAAC;QACtB,CAAC;KAAA;IAED;;;;;;;;;OASG;IACI,MAAM,CAAO,WAAW,CAAC,WAAqB,EAAE,YAA2B,EAAE,QAA+B;;YAClH,IAAI,YAAY,KAAK,YAAY,CAAC,GAAG,EAAE;gBACtC,OAAO,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;aACpC;iBAAM;gBACN,MAAM,QAAQ,GAAG,MAAM,oBAAoB,CAAC,eAAe,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;gBACvF,IAAI,WAAW,CAAC,EAAE,EAAE;oBACnB,kBAAkB;oBAClB,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;wBACnC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;qBACzB;yBAAM;wBACN,OAAO,QAAQ,CAAC;qBAChB;iBACD;qBAAM;oBACN,kBAAkB;oBAClB,MAAM,QAAQ,CAAC;iBACf;aACD;QACF,CAAC;KAAA;CACD"}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module HTTPClient
|
||||
*/
|
||||
import { Context } from "./IContext";
|
||||
import { Middleware } from "./middleware/IMiddleware";
|
||||
/**
|
||||
* @class
|
||||
* Class representing HTTPClient
|
||||
*/
|
||||
export declare class HTTPClient {
|
||||
/**
|
||||
* @private
|
||||
* A member holding first middleware of the middleware chain
|
||||
*/
|
||||
private middleware;
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Creates an instance of a HTTPClient
|
||||
* @param {...Middleware} middleware - The first middleware of the middleware chain or a sequence of all the Middleware handlers
|
||||
*/
|
||||
constructor(...middleware: Middleware[]);
|
||||
/**
|
||||
* @private
|
||||
* Processes the middleware parameter passed to set this.middleware property
|
||||
* The calling function should validate if middleware is not undefined or not empty.
|
||||
* @param {...Middleware} middleware - The middleware passed
|
||||
* @returns Nothing
|
||||
*/
|
||||
private setMiddleware;
|
||||
/**
|
||||
* @private
|
||||
* Processes the middleware array to construct the chain
|
||||
* and sets this.middleware property to the first middleware handler of the array
|
||||
* The calling function should validate if middleware is not undefined or not empty
|
||||
* @param {Middleware[]} middlewareArray - The array of middleware handlers
|
||||
* @returns Nothing
|
||||
*/
|
||||
private parseMiddleWareArray;
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* To send the request through the middleware chain
|
||||
* @param {Context} context - The context of a request
|
||||
* @returns A promise that resolves to the Context
|
||||
*/
|
||||
sendRequest(context: Context): Promise<Context>;
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { __awaiter } from "tslib";
|
||||
/**
|
||||
* @class
|
||||
* Class representing HTTPClient
|
||||
*/
|
||||
export class HTTPClient {
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Creates an instance of a HTTPClient
|
||||
* @param {...Middleware} middleware - The first middleware of the middleware chain or a sequence of all the Middleware handlers
|
||||
*/
|
||||
constructor(...middleware) {
|
||||
if (!middleware || !middleware.length) {
|
||||
const error = new Error();
|
||||
error.name = "InvalidMiddlewareChain";
|
||||
error.message = "Please provide a default middleware chain or custom middleware chain";
|
||||
throw error;
|
||||
}
|
||||
this.setMiddleware(...middleware);
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* Processes the middleware parameter passed to set this.middleware property
|
||||
* The calling function should validate if middleware is not undefined or not empty.
|
||||
* @param {...Middleware} middleware - The middleware passed
|
||||
* @returns Nothing
|
||||
*/
|
||||
setMiddleware(...middleware) {
|
||||
if (middleware.length > 1) {
|
||||
this.parseMiddleWareArray(middleware);
|
||||
}
|
||||
else {
|
||||
this.middleware = middleware[0];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* Processes the middleware array to construct the chain
|
||||
* and sets this.middleware property to the first middleware handler of the array
|
||||
* The calling function should validate if middleware is not undefined or not empty
|
||||
* @param {Middleware[]} middlewareArray - The array of middleware handlers
|
||||
* @returns Nothing
|
||||
*/
|
||||
parseMiddleWareArray(middlewareArray) {
|
||||
middlewareArray.forEach((element, index) => {
|
||||
if (index < middlewareArray.length - 1) {
|
||||
element.setNext(middlewareArray[index + 1]);
|
||||
}
|
||||
});
|
||||
this.middleware = middlewareArray[0];
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* To send the request through the middleware chain
|
||||
* @param {Context} context - The context of a request
|
||||
* @returns A promise that resolves to the Context
|
||||
*/
|
||||
sendRequest(context) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (typeof context.request === "string" && context.options === undefined) {
|
||||
const error = new Error();
|
||||
error.name = "InvalidRequestOptions";
|
||||
error.message = "Unable to execute the middleware, Please provide valid options for a request";
|
||||
throw error;
|
||||
}
|
||||
yield this.middleware.execute(context);
|
||||
return context;
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=HTTPClient.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"HTTPClient.js","sourceRoot":"","sources":["../../../src/HTTPClient.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AASH;;;GAGG;AACH,MAAM,OAAO,UAAU;IAOtB;;;;;OAKG;IACH,YAAmB,GAAG,UAAwB;QAC7C,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;YACtC,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;YAC1B,KAAK,CAAC,IAAI,GAAG,wBAAwB,CAAC;YACtC,KAAK,CAAC,OAAO,GAAG,sEAAsE,CAAC;YACvF,MAAM,KAAK,CAAC;SACZ;QACD,IAAI,CAAC,aAAa,CAAC,GAAG,UAAU,CAAC,CAAC;IACnC,CAAC;IAED;;;;;;OAMG;IACK,aAAa,CAAC,GAAG,UAAwB;QAChD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;SACtC;aAAM;YACN,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;SAChC;IACF,CAAC;IAED;;;;;;;OAOG;IACK,oBAAoB,CAAC,eAA6B;QACzD,eAAe,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;YAC1C,IAAI,KAAK,GAAG,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE;gBACvC,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;aAC5C;QACF,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACU,WAAW,CAAC,OAAgB;;YACxC,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE;gBACzE,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;gBAC1B,KAAK,CAAC,IAAI,GAAG,uBAAuB,CAAC;gBACrC,KAAK,CAAC,OAAO,GAAG,8EAA8E,CAAC;gBAC/F,MAAM,KAAK,CAAC;aACZ;YACD,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACvC,OAAO,OAAO,CAAC;QAChB,CAAC;KAAA;CACD"}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module HTTPClientFactory
|
||||
*/
|
||||
import { HTTPClient } from "./HTTPClient";
|
||||
import { AuthenticationProvider } from "./IAuthenticationProvider";
|
||||
import { Middleware } from "./middleware/IMiddleware";
|
||||
/**
|
||||
* @class
|
||||
* Class representing HTTPClientFactory
|
||||
*/
|
||||
export declare class HTTPClientFactory {
|
||||
/**
|
||||
* @public
|
||||
* @static
|
||||
* Creates HTTPClient with default middleware chain
|
||||
* @param {AuthenticationProvider} authProvider - The authentication provider instance
|
||||
* @returns A HTTPClient instance
|
||||
*
|
||||
* NOTE: These are the things that we need to remember while doing modifications in the below default pipeline.
|
||||
* * HTTPMessageHandler should be the last one in the middleware pipeline, because this makes the actual network call of the request
|
||||
* * TelemetryHandler should be the one prior to the last middleware in the chain, because this is the one which actually collects and appends the usage flag and placing this handler * before making the actual network call ensures that the usage of all features are recorded in the flag.
|
||||
* * The best place for AuthenticationHandler is in the starting of the pipeline, because every other handler might have to work for multiple times for a request but the auth token for
|
||||
* them will remain same. For example, Retry and Redirect handlers might be working multiple times for a request based on the response but their auth token would remain same.
|
||||
*/
|
||||
static createWithAuthenticationProvider(authProvider: AuthenticationProvider): HTTPClient;
|
||||
/**
|
||||
* @public
|
||||
* @static
|
||||
* Creates a middleware chain with the given one
|
||||
* @property {...Middleware} middleware - The first middleware of the middleware chain or a sequence of all the Middleware handlers
|
||||
* @returns A HTTPClient instance
|
||||
*/
|
||||
static createWithMiddleware(...middleware: Middleware[]): HTTPClient;
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module HTTPClientFactory
|
||||
*/
|
||||
import { HTTPClient } from "./HTTPClient";
|
||||
import { AuthenticationHandler } from "./middleware/AuthenticationHandler";
|
||||
import { HTTPMessageHandler } from "./middleware/HTTPMessageHandler";
|
||||
import { RedirectHandlerOptions } from "./middleware/options/RedirectHandlerOptions";
|
||||
import { RetryHandlerOptions } from "./middleware/options/RetryHandlerOptions";
|
||||
import { RedirectHandler } from "./middleware/RedirectHandler";
|
||||
import { RetryHandler } from "./middleware/RetryHandler";
|
||||
import { TelemetryHandler } from "./middleware/TelemetryHandler";
|
||||
/**
|
||||
* @private
|
||||
* To check whether the environment is node or not
|
||||
* @returns A boolean representing the environment is node or not
|
||||
*/
|
||||
const isNodeEnvironment = () => {
|
||||
return typeof process === "object" && typeof require === "function";
|
||||
};
|
||||
/**
|
||||
* @class
|
||||
* Class representing HTTPClientFactory
|
||||
*/
|
||||
export class HTTPClientFactory {
|
||||
/**
|
||||
* @public
|
||||
* @static
|
||||
* Creates HTTPClient with default middleware chain
|
||||
* @param {AuthenticationProvider} authProvider - The authentication provider instance
|
||||
* @returns A HTTPClient instance
|
||||
*
|
||||
* NOTE: These are the things that we need to remember while doing modifications in the below default pipeline.
|
||||
* * HTTPMessageHandler should be the last one in the middleware pipeline, because this makes the actual network call of the request
|
||||
* * TelemetryHandler should be the one prior to the last middleware in the chain, because this is the one which actually collects and appends the usage flag and placing this handler * before making the actual network call ensures that the usage of all features are recorded in the flag.
|
||||
* * The best place for AuthenticationHandler is in the starting of the pipeline, because every other handler might have to work for multiple times for a request but the auth token for
|
||||
* them will remain same. For example, Retry and Redirect handlers might be working multiple times for a request based on the response but their auth token would remain same.
|
||||
*/
|
||||
static createWithAuthenticationProvider(authProvider) {
|
||||
const authenticationHandler = new AuthenticationHandler(authProvider);
|
||||
const retryHandler = new RetryHandler(new RetryHandlerOptions());
|
||||
const telemetryHandler = new TelemetryHandler();
|
||||
const httpMessageHandler = new HTTPMessageHandler();
|
||||
authenticationHandler.setNext(retryHandler);
|
||||
if (isNodeEnvironment()) {
|
||||
const redirectHandler = new RedirectHandler(new RedirectHandlerOptions());
|
||||
retryHandler.setNext(redirectHandler);
|
||||
redirectHandler.setNext(telemetryHandler);
|
||||
}
|
||||
else {
|
||||
retryHandler.setNext(telemetryHandler);
|
||||
}
|
||||
telemetryHandler.setNext(httpMessageHandler);
|
||||
return HTTPClientFactory.createWithMiddleware(authenticationHandler);
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @static
|
||||
* Creates a middleware chain with the given one
|
||||
* @property {...Middleware} middleware - The first middleware of the middleware chain or a sequence of all the Middleware handlers
|
||||
* @returns A HTTPClient instance
|
||||
*/
|
||||
static createWithMiddleware(...middleware) {
|
||||
// Middleware should not empty or undefined. This is check is present in the HTTPClient constructor.
|
||||
return new HTTPClient(...middleware);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=HTTPClientFactory.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"HTTPClientFactory.js","sourceRoot":"","sources":["../../../src/HTTPClientFactory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,GAAY,EAAE;IACvC,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,OAAO,KAAK,UAAU,CAAC;AACrE,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAC7B;;;;;;;;;;;;OAYG;IACI,MAAM,CAAC,gCAAgC,CAAC,YAAoC;QAClF,MAAM,qBAAqB,GAAG,IAAI,qBAAqB,CAAC,YAAY,CAAC,CAAC;QACtE,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,IAAI,mBAAmB,EAAE,CAAC,CAAC;QACjE,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;QAChD,MAAM,kBAAkB,GAAG,IAAI,kBAAkB,EAAE,CAAC;QAEpD,qBAAqB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC5C,IAAI,iBAAiB,EAAE,EAAE;YACxB,MAAM,eAAe,GAAG,IAAI,eAAe,CAAC,IAAI,sBAAsB,EAAE,CAAC,CAAC;YAC1E,YAAY,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;YACtC,eAAe,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;SAC1C;aAAM;YACN,YAAY,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;SACvC;QACD,gBAAgB,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAC7C,OAAO,iBAAiB,CAAC,oBAAoB,CAAC,qBAAqB,CAAC,CAAC;IACtE,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,oBAAoB,CAAC,GAAG,UAAwB;QAC7D,oGAAoG;QACpG,OAAO,IAAI,UAAU,CAAC,GAAG,UAAU,CAAC,CAAC;IACtC,CAAC;CACD"}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { AuthProviderCallback } from "./IAuthProviderCallback";
|
||||
/**
|
||||
* @interface
|
||||
* Signature that holds authProvider
|
||||
* @callback - The anonymous callback function which takes a single param
|
||||
*/
|
||||
export type AuthProvider = (done: AuthProviderCallback) => void;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
export {};
|
||||
//# sourceMappingURL=IAuthProvider.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IAuthProvider.js","sourceRoot":"","sources":["../../../src/IAuthProvider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
||||
Generated
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @interface
|
||||
* Signature that defines callback for an authentication provider
|
||||
* @callback - The anonymous callback function which takes two params
|
||||
*/
|
||||
export type AuthProviderCallback = (error: any, accessToken: string | null) => void;
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
export {};
|
||||
//# sourceMappingURL=IAuthProviderCallback.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IAuthProviderCallback.js","sourceRoot":"","sources":["../../../src/IAuthProviderCallback.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
||||
Generated
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { AuthenticationProviderOptions } from "./IAuthenticationProviderOptions";
|
||||
/**
|
||||
* @interface
|
||||
* A signature representing Authentication provider
|
||||
* @property {Function} getAccessToken - The function to get the access token from the authentication provider
|
||||
*/
|
||||
export interface AuthenticationProvider {
|
||||
/**
|
||||
* To get access token from the authentication provider
|
||||
* @param {AuthenticationProviderOptions} [authenticationProviderOptions] - The authentication provider options instance
|
||||
* @returns A promise that resolves to an access token
|
||||
*/
|
||||
getAccessToken: (authenticationProviderOptions?: AuthenticationProviderOptions) => Promise<string>;
|
||||
}
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
export {};
|
||||
//# sourceMappingURL=IAuthenticationProvider.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IAuthenticationProvider.js","sourceRoot":"","sources":["../../../src/IAuthenticationProvider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
||||
Generated
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @interface
|
||||
* A signature represents the Authentication provider options
|
||||
* @property {string[]} [scopes] - The array of scopes
|
||||
*/
|
||||
export interface AuthenticationProviderOptions {
|
||||
scopes?: string[];
|
||||
}
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
export {};
|
||||
//# sourceMappingURL=IAuthenticationProviderOptions.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IAuthenticationProviderOptions.js","sourceRoot":"","sources":["../../../src/IAuthenticationProviderOptions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { AuthenticationProvider } from "./IAuthenticationProvider";
|
||||
import { FetchOptions } from "./IFetchOptions";
|
||||
import { Middleware } from "./middleware/IMiddleware";
|
||||
/**
|
||||
* @interface
|
||||
* Options for initializing the Graph Client
|
||||
* @property {Function} [authProvider] - The authentication provider instance
|
||||
* @property {string} [baseUrl] - Base url that needs to be appended to every request
|
||||
* @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 {FetchOptions} [fetchOptions] - The options for fetch request
|
||||
* @property {Middleware| Middleware[]} [middleware] - The first middleware of the middleware chain or an array of the Middleware handlers
|
||||
* @property {Set<string>}[customHosts] - A set of custom host names. Should contain hostnames only.
|
||||
*/
|
||||
export interface ClientOptions {
|
||||
authProvider?: AuthenticationProvider;
|
||||
baseUrl?: string;
|
||||
debugLogging?: boolean;
|
||||
defaultVersion?: string;
|
||||
fetchOptions?: FetchOptions;
|
||||
middleware?: Middleware | Middleware[];
|
||||
/**
|
||||
* Example - If URL is "https://test_host/v1.0", then set property "customHosts" as "customHosts: Set<string>(["test_host"])"
|
||||
*/
|
||||
customHosts?: Set<string>;
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
export {};
|
||||
//# sourceMappingURL=IClientOptions.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IClientOptions.js","sourceRoot":"","sources":["../../../src/IClientOptions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { FetchOptions } from "./IFetchOptions";
|
||||
import { MiddlewareControl } from "./middleware/MiddlewareControl";
|
||||
/**
|
||||
* @interface
|
||||
* @property {RequestInfo} request - The request url string or the Request instance
|
||||
* @property {FetchOptions} [options] - The options for the request
|
||||
* @property {Response} [response] - The response content
|
||||
* @property {MiddlewareControl} [middlewareControl] - The options for the middleware chain
|
||||
* @property {Set<string>}[customHosts] - A set of custom host names. Should contain hostnames only.
|
||||
*
|
||||
*/
|
||||
export interface Context {
|
||||
request: RequestInfo;
|
||||
options?: FetchOptions;
|
||||
response?: Response;
|
||||
middlewareControl?: MiddlewareControl;
|
||||
/**
|
||||
* Example - If URL is "https://test_host", then set property "customHosts" as "customHosts: Set<string>(["test_host"])"
|
||||
*/
|
||||
customHosts?: Set<string>;
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
export {};
|
||||
//# sourceMappingURL=IContext.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IContext.js","sourceRoot":"","sources":["../../../src/IContext.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @interface {@link https://github.com/bitinn/node-fetch/#options}
|
||||
* Signature to define the fetch request options for node environment
|
||||
* @property {number} [follow] - node-fetch option: maximum redirect count. 0 to not follow redirect
|
||||
* @property {number} [compress] - node-fetch option: support gzip/deflate content encoding. false to disable
|
||||
* @property {number} [size] - node-fetch option: maximum response body size in bytes. 0 to disable
|
||||
* @property {any} [agent] - node-fetch option: HTTP(S).Agent instance, allows custom proxy, certificate, lookup, family etc.
|
||||
* @property {number} [highWaterMark] - node-fetch option: maximum number of bytes to store in the internal buffer before ceasing to read from the underlying resource.
|
||||
* @property {boolean} [insecureHTTPParser] - node-fetch option: use an insecure HTTP parser that accepts invalid HTTP headers when `true`.
|
||||
*/
|
||||
export interface NodeFetchInit {
|
||||
follow?: number;
|
||||
compress?: boolean;
|
||||
size?: number;
|
||||
agent?: any;
|
||||
highWaterMark?: number;
|
||||
insecureHTTPParser?: boolean;
|
||||
}
|
||||
/**
|
||||
* @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 {
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
export {};
|
||||
//# sourceMappingURL=IFetchOptions.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IFetchOptions.js","sourceRoot":"","sources":["../../../src/IFetchOptions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
||||
Generated
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { GraphError } from "./GraphError";
|
||||
/**
|
||||
* @interface
|
||||
* Signature to define the GraphRequest callback
|
||||
* @callback - The anonymous callback function
|
||||
*/
|
||||
export type GraphRequestCallback = (error: GraphError, response: any, rawResponse?: any) => void;
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
export {};
|
||||
//# sourceMappingURL=IGraphRequestCallback.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IGraphRequestCallback.js","sourceRoot":"","sources":["../../../src/IGraphRequestCallback.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { AuthProvider } from "./IAuthProvider";
|
||||
import { FetchOptions } from "./IFetchOptions";
|
||||
/**
|
||||
* @interface
|
||||
* Options for initializing the Graph Client
|
||||
* @property {AuthProvider} authProvider - The function to get the authentication token
|
||||
* @property {string} [baseUrl] - Base url that needs to be appended to every request
|
||||
* @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 {FetchOptions} [fetchOptions] - The options for fetch request
|
||||
* @property {Set<string>}[customHosts] - A set of custom host names. Should contain hostnames only.
|
||||
*/
|
||||
export interface Options {
|
||||
authProvider: AuthProvider;
|
||||
baseUrl?: string;
|
||||
debugLogging?: boolean;
|
||||
defaultVersion?: string;
|
||||
fetchOptions?: FetchOptions;
|
||||
/**
|
||||
* Example - If URL is "https://test_host/v1.0", then set property "customHosts" as "customHosts: Set<string>(["test_host"])"
|
||||
*/
|
||||
customHosts?: Set<string>;
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
export {};
|
||||
//# sourceMappingURL=IOptions.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IOptions.js","sourceRoot":"","sources":["../../../src/IOptions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @enum
|
||||
* Enum for RequestMethods
|
||||
* @property {string} GET - The get request type
|
||||
* @property {string} PATCH - The patch request type
|
||||
* @property {string} POST - The post request type
|
||||
* @property {string} PUT - The put request type
|
||||
* @property {string} DELETE - The delete request type
|
||||
*/
|
||||
export declare enum RequestMethod {
|
||||
GET = "GET",
|
||||
PATCH = "PATCH",
|
||||
POST = "POST",
|
||||
PUT = "PUT",
|
||||
DELETE = "DELETE"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @enum
|
||||
* Enum for RequestMethods
|
||||
* @property {string} GET - The get request type
|
||||
* @property {string} PATCH - The patch request type
|
||||
* @property {string} POST - The post request type
|
||||
* @property {string} PUT - The put request type
|
||||
* @property {string} DELETE - The delete request type
|
||||
*/
|
||||
export var RequestMethod;
|
||||
(function (RequestMethod) {
|
||||
RequestMethod["GET"] = "GET";
|
||||
RequestMethod["PATCH"] = "PATCH";
|
||||
RequestMethod["POST"] = "POST";
|
||||
RequestMethod["PUT"] = "PUT";
|
||||
RequestMethod["DELETE"] = "DELETE";
|
||||
})(RequestMethod || (RequestMethod = {}));
|
||||
//# sourceMappingURL=RequestMethod.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"RequestMethod.js","sourceRoot":"","sources":["../../../src/RequestMethod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;GAQG;AACH,MAAM,CAAN,IAAY,aAMX;AAND,WAAY,aAAa;IACxB,4BAAW,CAAA;IACX,gCAAe,CAAA;IACf,8BAAa,CAAA;IACb,4BAAW,CAAA;IACX,kCAAiB,CAAA;AAClB,CAAC,EANW,aAAa,KAAb,aAAa,QAMxB"}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @enum
|
||||
* Enum for ResponseType values
|
||||
* @property {string} ARRAYBUFFER - To download response content as an [ArrayBuffer]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer}
|
||||
* @property {string} BLOB - To download content as a [binary/blob] {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob}
|
||||
* @property {string} DOCUMENT - This downloads content as a document or stream
|
||||
* @property {string} JSON - To download response content as a json
|
||||
* @property {string} STREAM - To download response as a [stream]{@link https://nodejs.org/api/stream.html}
|
||||
* @property {string} TEXT - For downloading response as a text
|
||||
*/
|
||||
export declare enum ResponseType {
|
||||
ARRAYBUFFER = "arraybuffer",
|
||||
BLOB = "blob",
|
||||
DOCUMENT = "document",
|
||||
JSON = "json",
|
||||
RAW = "raw",
|
||||
STREAM = "stream",
|
||||
TEXT = "text"
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @enum
|
||||
* Enum for ResponseType values
|
||||
* @property {string} ARRAYBUFFER - To download response content as an [ArrayBuffer]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer}
|
||||
* @property {string} BLOB - To download content as a [binary/blob] {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob}
|
||||
* @property {string} DOCUMENT - This downloads content as a document or stream
|
||||
* @property {string} JSON - To download response content as a json
|
||||
* @property {string} STREAM - To download response as a [stream]{@link https://nodejs.org/api/stream.html}
|
||||
* @property {string} TEXT - For downloading response as a text
|
||||
*/
|
||||
export var ResponseType;
|
||||
(function (ResponseType) {
|
||||
ResponseType["ARRAYBUFFER"] = "arraybuffer";
|
||||
ResponseType["BLOB"] = "blob";
|
||||
ResponseType["DOCUMENT"] = "document";
|
||||
ResponseType["JSON"] = "json";
|
||||
ResponseType["RAW"] = "raw";
|
||||
ResponseType["STREAM"] = "stream";
|
||||
ResponseType["TEXT"] = "text";
|
||||
})(ResponseType || (ResponseType = {}));
|
||||
//# sourceMappingURL=ResponseType.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ResponseType.js","sourceRoot":"","sources":["../../../src/ResponseType.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;GASG;AAEH,MAAM,CAAN,IAAY,YAQX;AARD,WAAY,YAAY;IACvB,2CAA2B,CAAA;IAC3B,6BAAa,CAAA;IACb,qCAAqB,CAAA;IACrB,6BAAa,CAAA;IACb,2BAAW,CAAA;IACX,iCAAiB,CAAA;IACjB,6BAAa,CAAA;AACd,CAAC,EARW,YAAY,KAAZ,YAAY,QAQvB"}
|
||||
Generated
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @constant
|
||||
* @function
|
||||
* Validates availability of Promise and fetch in global context
|
||||
* @returns The true in case the Promise and fetch available, otherwise throws error
|
||||
*/
|
||||
export declare const validatePolyFilling: () => boolean;
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @constant
|
||||
* @function
|
||||
* Validates availability of Promise and fetch in global context
|
||||
* @returns The true in case the Promise and fetch available, otherwise throws error
|
||||
*/
|
||||
export const validatePolyFilling = () => {
|
||||
if (typeof Promise === "undefined" && typeof fetch === "undefined") {
|
||||
const error = new Error("Library cannot function without Promise and fetch. So, please provide polyfill for them.");
|
||||
error.name = "PolyFillNotAvailable";
|
||||
throw error;
|
||||
}
|
||||
else if (typeof Promise === "undefined") {
|
||||
const error = new Error("Library cannot function without Promise. So, please provide polyfill for it.");
|
||||
error.name = "PolyFillNotAvailable";
|
||||
throw error;
|
||||
}
|
||||
else if (typeof fetch === "undefined") {
|
||||
const error = new Error("Library cannot function without fetch. So, please provide polyfill for it.");
|
||||
error.name = "PolyFillNotAvailable";
|
||||
throw error;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
//# sourceMappingURL=ValidatePolyFilling.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ValidatePolyFilling.js","sourceRoot":"","sources":["../../../src/ValidatePolyFilling.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAY,EAAE;IAChD,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;QACnE,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,0FAA0F,CAAC,CAAC;QACpH,KAAK,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACpC,MAAM,KAAK,CAAC;KACZ;SAAM,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE;QAC1C,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,8EAA8E,CAAC,CAAC;QACxG,KAAK,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACpC,MAAM,KAAK,CAAC;KACZ;SAAM,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;QACxC,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;QACtG,KAAK,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACpC,MAAM,KAAK,CAAC;KACZ;IACD,OAAO,IAAI,CAAC;AACb,CAAC,CAAC"}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module Version
|
||||
*/
|
||||
export declare const PACKAGE_VERSION = "3.0.7";
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
// THIS FILE IS AUTO GENERATED
|
||||
// ANY CHANGES WILL BE LOST DURING BUILD
|
||||
/**
|
||||
* @module Version
|
||||
*/
|
||||
export const PACKAGE_VERSION = "3.0.7";
|
||||
//# sourceMappingURL=Version.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Version.js","sourceRoot":"","sources":["../../../src/Version.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,8BAA8B;AAC9B,wCAAwC;AAExC;;GAEG;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC"}
|
||||
Generated
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { GetTokenOptions } from "@azure/identity";
|
||||
import { AuthenticationProviderOptions } from "../../IAuthenticationProviderOptions";
|
||||
/**
|
||||
* @interface
|
||||
* A signature represents the Authentication provider options for Token Credentials
|
||||
* @property {getTokenOptions} [GetTokenOptions] - Defines options for TokenCredential.getToken.
|
||||
*/
|
||||
export interface TokenCredentialAuthenticationProviderOptions extends AuthenticationProviderOptions {
|
||||
getTokenOptions?: GetTokenOptions;
|
||||
}
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=ITokenCredentialAuthenticationProviderOptions.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ITokenCredentialAuthenticationProviderOptions.js","sourceRoot":"","sources":["../../../../../src/authentication/azureTokenCredentials/ITokenCredentialAuthenticationProviderOptions.ts"],"names":[],"mappings":""}
|
||||
Generated
Vendored
+48
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { TokenCredential } from "@azure/identity";
|
||||
import { AuthenticationProvider } from "../../IAuthenticationProvider";
|
||||
import { TokenCredentialAuthenticationProviderOptions } from "./ITokenCredentialAuthenticationProviderOptions";
|
||||
/**
|
||||
* @module TokenCredentialAuthenticationProvider
|
||||
*/
|
||||
/**
|
||||
* @class
|
||||
* Class representing TokenCredentialAuthenticationProvider
|
||||
* This feature is introduced in Version 3.0.0
|
||||
* @extends AuthenticationProvider
|
||||
* Reference - https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/README.md
|
||||
*/
|
||||
export declare class TokenCredentialAuthenticationProvider implements AuthenticationProvider {
|
||||
/**
|
||||
* @private
|
||||
* A member holding an instance of @azure/identity TokenCredential
|
||||
*/
|
||||
private tokenCredential;
|
||||
/**
|
||||
* @private
|
||||
* A member holding an instance of TokenCredentialAuthenticationProviderOptions
|
||||
*/
|
||||
private authenticationProviderOptions;
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Creates an instance of TokenCredentialAuthenticationProvider
|
||||
* @param {TokenCredential} tokenCredential - An instance of @azure/identity TokenCredential
|
||||
* @param {TokenCredentialAuthenticationProviderOptions} authenticationProviderOptions - An instance of TokenCredentialAuthenticationProviderOptions
|
||||
* @returns An instance of TokenCredentialAuthenticationProvider
|
||||
*/
|
||||
constructor(tokenCredential: TokenCredential, authenticationProviderOptions: TokenCredentialAuthenticationProviderOptions);
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* To get the access token
|
||||
* @param {TokenCredentialAuthenticationProviderOptions} authenticationProviderOptions - The authentication provider options object
|
||||
* @returns The promise that resolves to an access token
|
||||
*/
|
||||
getAccessToken(): Promise<string>;
|
||||
}
|
||||
Generated
Vendored
+64
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { __awaiter } from "tslib";
|
||||
import { GraphClientError } from "../../GraphClientError";
|
||||
/**
|
||||
* @module TokenCredentialAuthenticationProvider
|
||||
*/
|
||||
/**
|
||||
* @class
|
||||
* Class representing TokenCredentialAuthenticationProvider
|
||||
* This feature is introduced in Version 3.0.0
|
||||
* @extends AuthenticationProvider
|
||||
* Reference - https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/README.md
|
||||
*/
|
||||
export class TokenCredentialAuthenticationProvider {
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Creates an instance of TokenCredentialAuthenticationProvider
|
||||
* @param {TokenCredential} tokenCredential - An instance of @azure/identity TokenCredential
|
||||
* @param {TokenCredentialAuthenticationProviderOptions} authenticationProviderOptions - An instance of TokenCredentialAuthenticationProviderOptions
|
||||
* @returns An instance of TokenCredentialAuthenticationProvider
|
||||
*/
|
||||
constructor(tokenCredential, authenticationProviderOptions) {
|
||||
if (!tokenCredential) {
|
||||
throw new GraphClientError("Please pass a token credential object to the TokenCredentialAuthenticationProvider class constructor");
|
||||
}
|
||||
if (!authenticationProviderOptions) {
|
||||
throw new GraphClientError("Please pass the TokenCredentialAuthenticationProviderOptions with scopes to the TokenCredentialAuthenticationProvider class constructor");
|
||||
}
|
||||
this.authenticationProviderOptions = authenticationProviderOptions;
|
||||
this.tokenCredential = tokenCredential;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* To get the access token
|
||||
* @param {TokenCredentialAuthenticationProviderOptions} authenticationProviderOptions - The authentication provider options object
|
||||
* @returns The promise that resolves to an access token
|
||||
*/
|
||||
getAccessToken() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const scopes = this.authenticationProviderOptions.scopes;
|
||||
const error = new GraphClientError();
|
||||
if (!scopes || scopes.length === 0) {
|
||||
error.name = "Empty Scopes";
|
||||
error.message = "Scopes cannot be empty, Please provide scopes";
|
||||
throw error;
|
||||
}
|
||||
const response = yield this.tokenCredential.getToken(scopes, this.authenticationProviderOptions.getTokenOptions);
|
||||
if (response) {
|
||||
return response.token;
|
||||
}
|
||||
error.message = "Cannot retrieve accessToken from the Token Credential object";
|
||||
error.name = "Access token is undefined";
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=TokenCredentialAuthenticationProvider.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"TokenCredentialAuthenticationProvider.js","sourceRoot":"","sources":["../../../../../src/authentication/azureTokenCredentials/TokenCredentialAuthenticationProvider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAI1D;;GAEG;AAEH;;;;;;GAMG;AACH,MAAM,OAAO,qCAAqC;IAajD;;;;;;;OAOG;IACH,YAAmB,eAAgC,EAAE,6BAA2E;QAC/H,IAAI,CAAC,eAAe,EAAE;YACrB,MAAM,IAAI,gBAAgB,CAAC,sGAAsG,CAAC,CAAC;SACnI;QACD,IAAI,CAAC,6BAA6B,EAAE;YACnC,MAAM,IAAI,gBAAgB,CAAC,yIAAyI,CAAC,CAAC;SACtK;QACD,IAAI,CAAC,6BAA6B,GAAG,6BAA6B,CAAC;QACnE,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACU,cAAc;;YAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,6BAA6B,CAAC,MAAM,CAAC;YACzD,MAAM,KAAK,GAAG,IAAI,gBAAgB,EAAE,CAAC;YAErC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;gBACnC,KAAK,CAAC,IAAI,GAAG,cAAc,CAAC;gBAC5B,KAAK,CAAC,OAAO,GAAG,+CAA+C,CAAC;gBAChE,MAAM,KAAK,CAAC;aACZ;YACD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,6BAA6B,CAAC,eAAe,CAAC,CAAC;YACjH,IAAI,QAAQ,EAAE;gBACb,OAAO,QAAQ,CAAC,KAAK,CAAC;aACtB;YACD,KAAK,CAAC,OAAO,GAAG,8DAA8D,CAAC;YAC/E,KAAK,CAAC,IAAI,GAAG,2BAA2B,CAAC;YACzC,MAAM,KAAK,CAAC;QACb,CAAC;KAAA;CACD"}
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
export { TokenCredentialAuthenticationProviderOptions } from "./ITokenCredentialAuthenticationProviderOptions";
|
||||
export { TokenCredentialAuthenticationProvider } from "./TokenCredentialAuthenticationProvider";
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export { TokenCredentialAuthenticationProvider } from "./TokenCredentialAuthenticationProvider";
|
||||
//# sourceMappingURL=index.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/authentication/azureTokenCredentials/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,qCAAqC,EAAE,MAAM,yCAAyC,CAAC"}
|
||||
Generated
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module AuthCodeMSALBrowserAuthenticationProvider
|
||||
*/
|
||||
import { PublicClientApplication } from "@azure/msal-browser";
|
||||
import { AuthenticationProvider } from "../../IAuthenticationProvider";
|
||||
import { AuthCodeMSALBrowserAuthenticationProviderOptions } from "../msalOptions/MSALAuthenticationProviderOptions";
|
||||
/**
|
||||
* an AuthenticationProvider implementation supporting msal-browser library.
|
||||
* This feature is introduced in Version 3.0.0
|
||||
* @class
|
||||
* @extends AuthenticationProvider
|
||||
*/
|
||||
export declare class AuthCodeMSALBrowserAuthenticationProvider implements AuthenticationProvider {
|
||||
private publicClientApplication;
|
||||
private options;
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Creates an instance of ImplicitMSALAuthenticationProvider
|
||||
* @param {PublicClientApplication} msalApplication - An instance of MSAL PublicClientApplication
|
||||
* @param {AuthCodeMSALBrowserAuthenticationProviderOptions} options - An instance of MSALAuthenticationProviderOptions
|
||||
* @returns An instance of ImplicitMSALAuthenticationProvider
|
||||
*/
|
||||
constructor(publicClientApplication: PublicClientApplication, options: AuthCodeMSALBrowserAuthenticationProviderOptions);
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* To get the access token for the request
|
||||
* @returns The promise that resolves to an access token
|
||||
*/
|
||||
getAccessToken(): Promise<string>;
|
||||
}
|
||||
Generated
Vendored
+80
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { __awaiter } from "tslib";
|
||||
/**
|
||||
* @module AuthCodeMSALBrowserAuthenticationProvider
|
||||
*/
|
||||
import { InteractionRequiredAuthError, InteractionType } from "@azure/msal-browser";
|
||||
import { GraphClientError } from "../../GraphClientError";
|
||||
/**
|
||||
* an AuthenticationProvider implementation supporting msal-browser library.
|
||||
* This feature is introduced in Version 3.0.0
|
||||
* @class
|
||||
* @extends AuthenticationProvider
|
||||
*/
|
||||
export class AuthCodeMSALBrowserAuthenticationProvider {
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Creates an instance of ImplicitMSALAuthenticationProvider
|
||||
* @param {PublicClientApplication} msalApplication - An instance of MSAL PublicClientApplication
|
||||
* @param {AuthCodeMSALBrowserAuthenticationProviderOptions} options - An instance of MSALAuthenticationProviderOptions
|
||||
* @returns An instance of ImplicitMSALAuthenticationProvider
|
||||
*/
|
||||
constructor(publicClientApplication, options) {
|
||||
this.publicClientApplication = publicClientApplication;
|
||||
this.options = options;
|
||||
if (!options || !publicClientApplication) {
|
||||
throw new GraphClientError("Please pass valid PublicClientApplication instance and AuthCodeMSALBrowserAuthenticationProviderOptions instance to instantiate MSALBrowserAuthenticationProvider");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* To get the access token for the request
|
||||
* @returns The promise that resolves to an access token
|
||||
*/
|
||||
getAccessToken() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const scopes = this.options && this.options.scopes;
|
||||
const account = this.options && this.options.account;
|
||||
const error = new GraphClientError();
|
||||
if (!scopes || scopes.length === 0) {
|
||||
error.name = "Empty Scopes";
|
||||
error.message = "Scopes cannot be empty, Please provide scopes";
|
||||
throw error;
|
||||
}
|
||||
try {
|
||||
const response = yield this.publicClientApplication.acquireTokenSilent({
|
||||
scopes,
|
||||
account,
|
||||
});
|
||||
if (!response || !response.accessToken) {
|
||||
error.name = "Access token is undefined";
|
||||
error.message = "Received empty access token from PublicClientApplication";
|
||||
throw error;
|
||||
}
|
||||
return response.accessToken;
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof InteractionRequiredAuthError) {
|
||||
if (this.options.interactionType === InteractionType.Redirect) {
|
||||
this.publicClientApplication.acquireTokenRedirect({ scopes });
|
||||
}
|
||||
else if (this.options.interactionType === InteractionType.Popup) {
|
||||
const response = yield this.publicClientApplication.acquireTokenPopup({ scopes });
|
||||
return response.accessToken;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=AuthCodeMSALBrowserAuthenticationProvider.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"AuthCodeMSALBrowserAuthenticationProvider.js","sourceRoot":"","sources":["../../../../../src/authentication/msal-browser/AuthCodeMSALBrowserAuthenticationProvider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAEH;;GAEG;AAEH,OAAO,EAAwB,4BAA4B,EAAE,eAAe,EAA2B,MAAM,qBAAqB,CAAC;AAEnI,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAI1D;;;;;GAKG;AACH,MAAM,OAAO,yCAAyC;IACrD;;;;;;;OAOG;IACH,YAA2B,uBAAgD,EAAU,OAAyD;QAAnH,4BAAuB,GAAvB,uBAAuB,CAAyB;QAAU,YAAO,GAAP,OAAO,CAAkD;QAC7I,IAAI,CAAC,OAAO,IAAI,CAAC,uBAAuB,EAAE;YACzC,MAAM,IAAI,gBAAgB,CAAC,mKAAmK,CAAC,CAAC;SAChM;IACF,CAAC;IAED;;;;;OAKG;IACU,cAAc;;YAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;YACnD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;YACrD,MAAM,KAAK,GAAG,IAAI,gBAAgB,EAAE,CAAC;YACrC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;gBACnC,KAAK,CAAC,IAAI,GAAG,cAAc,CAAC;gBAC5B,KAAK,CAAC,OAAO,GAAG,+CAA+C,CAAC;gBAChE,MAAM,KAAK,CAAC;aACZ;YACD,IAAI;gBACH,MAAM,QAAQ,GAAyB,MAAM,IAAI,CAAC,uBAAuB,CAAC,kBAAkB,CAAC;oBAC5F,MAAM;oBACN,OAAO;iBACP,CAAC,CAAC;gBACH,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE;oBACvC,KAAK,CAAC,IAAI,GAAG,2BAA2B,CAAC;oBACzC,KAAK,CAAC,OAAO,GAAG,0DAA0D,CAAC;oBAC3E,MAAM,KAAK,CAAC;iBACZ;gBACD,OAAO,QAAQ,CAAC,WAAW,CAAC;aAC5B;YAAC,OAAO,KAAK,EAAE;gBACf,IAAI,KAAK,YAAY,4BAA4B,EAAE;oBAClD,IAAI,IAAI,CAAC,OAAO,CAAC,eAAe,KAAK,eAAe,CAAC,QAAQ,EAAE;wBAC9D,IAAI,CAAC,uBAAuB,CAAC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;qBAC9D;yBAAM,IAAI,IAAI,CAAC,OAAO,CAAC,eAAe,KAAK,eAAe,CAAC,KAAK,EAAE;wBAClE,MAAM,QAAQ,GAAyB,MAAM,IAAI,CAAC,uBAAuB,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;wBACxG,OAAO,QAAQ,CAAC,WAAW,CAAC;qBAC5B;iBACD;qBAAM;oBACN,MAAM,KAAK,CAAC;iBACZ;aACD;QACF,CAAC;KAAA;CACD"}
|
||||
Generated
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
export { AuthCodeMSALBrowserAuthenticationProvider } from "./AuthCodeMSALBrowserAuthenticationProvider";
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
export { AuthCodeMSALBrowserAuthenticationProvider } from "./AuthCodeMSALBrowserAuthenticationProvider";
|
||||
//# sourceMappingURL=index.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/authentication/msal-browser/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,yCAAyC,EAAE,MAAM,6CAA6C,CAAC"}
|
||||
Generated
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module MSALAuthenticationProviderOptions
|
||||
*/
|
||||
import { AccountInfo, InteractionType } from "@azure/msal-browser";
|
||||
import { AuthenticationProviderOptions } from "../../IAuthenticationProviderOptions";
|
||||
export interface AuthCodeMSALBrowserAuthenticationProviderOptions extends AuthenticationProviderOptions {
|
||||
scopes: string[];
|
||||
account: AccountInfo;
|
||||
interactionType: InteractionType;
|
||||
}
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
export {};
|
||||
//# sourceMappingURL=MSALAuthenticationProviderOptions.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"MSALAuthenticationProviderOptions.js","sourceRoot":"","sources":["../../../../../src/authentication/msalOptions/MSALAuthenticationProviderOptions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/// <reference path="../../../../shims.d.ts" />
|
||||
export { BatchRequestStep, BatchRequestData, BatchRequestContent, RequestData, BatchRequestBody } from "../content/BatchRequestContent";
|
||||
export { BatchResponseBody, BatchResponseContent } from "../content/BatchResponseContent";
|
||||
export { AuthenticationHandler } from "../middleware/AuthenticationHandler";
|
||||
export { HTTPMessageHandler } from "../middleware/HTTPMessageHandler";
|
||||
export { Middleware } from "../middleware/IMiddleware";
|
||||
export { RetryHandler } from "../middleware/RetryHandler";
|
||||
export { RedirectHandler } from "../middleware/RedirectHandler";
|
||||
export { TelemetryHandler } from "../middleware/TelemetryHandler";
|
||||
export { MiddlewareFactory } from "../middleware/MiddlewareFactory";
|
||||
export { AuthenticationHandlerOptions } from "../middleware/options/AuthenticationHandlerOptions";
|
||||
export { MiddlewareOptions } from "../middleware/options/IMiddlewareOptions";
|
||||
export { ShouldRetry, RetryHandlerOptions } from "../middleware/options/RetryHandlerOptions";
|
||||
export { ShouldRedirect, RedirectHandlerOptions } from "../middleware/options/RedirectHandlerOptions";
|
||||
export { FeatureUsageFlag, TelemetryHandlerOptions } from "../middleware/options/TelemetryHandlerOptions";
|
||||
export { ChaosHandlerOptions } from "../middleware/options/ChaosHandlerOptions";
|
||||
export { ChaosStrategy } from "../middleware/options/ChaosStrategy";
|
||||
export { ChaosHandler } from "../middleware/ChaosHandler";
|
||||
export { SliceType, LargeFileUploadTaskOptions, LargeFileUploadTask, LargeFileUploadSession, FileObject } from "../tasks/LargeFileUploadTask";
|
||||
export { OneDriveLargeFileUploadTask, OneDriveLargeFileUploadOptions } from "../tasks/OneDriveLargeFileUploadTask";
|
||||
export { getValidRangeSize } from "../tasks/OneDriveLargeFileUploadTaskUtil";
|
||||
export { StreamUpload } from "../tasks/FileUploadTask/FileObjectClasses/StreamUpload";
|
||||
export { FileUpload } from "../tasks/FileUploadTask/FileObjectClasses/FileUpload";
|
||||
export { UploadResult } from "../tasks/FileUploadTask/UploadResult";
|
||||
export { UploadEventHandlers } from "../tasks/FileUploadTask/Interfaces/IUploadEventHandlers";
|
||||
export { Range } from "../tasks/FileUploadTask/Range";
|
||||
export { PageIteratorCallback, PageIterator, PageCollection, GraphRequestOptions } from "../tasks/PageIterator";
|
||||
export { Client } from "../Client";
|
||||
export { CustomAuthenticationProvider } from "../CustomAuthenticationProvider";
|
||||
export { GraphError } from "../GraphError";
|
||||
export { GraphClientError } from "../GraphClientError";
|
||||
export { GraphRequest } from "../GraphRequest";
|
||||
export { AuthProvider } from "../IAuthProvider";
|
||||
export { AuthenticationProvider } from "../IAuthenticationProvider";
|
||||
export { AuthenticationProviderOptions } from "../IAuthenticationProviderOptions";
|
||||
export { AuthProviderCallback } from "../IAuthProviderCallback";
|
||||
export { ClientOptions } from "../IClientOptions";
|
||||
export { Context } from "../IContext";
|
||||
export { NodeFetchInit, FetchOptions } from "../IFetchOptions";
|
||||
export { GraphRequestCallback } from "../IGraphRequestCallback";
|
||||
export { Options } from "../IOptions";
|
||||
export { ResponseType } from "../ResponseType";
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
||||
/// <reference path= "../../shims.d.ts" />
|
||||
export { BatchRequestContent } from "../content/BatchRequestContent";
|
||||
export { BatchResponseContent } from "../content/BatchResponseContent";
|
||||
export { AuthenticationHandler } from "../middleware/AuthenticationHandler";
|
||||
export { HTTPMessageHandler } from "../middleware/HTTPMessageHandler";
|
||||
export { RetryHandler } from "../middleware/RetryHandler";
|
||||
export { RedirectHandler } from "../middleware/RedirectHandler";
|
||||
export { TelemetryHandler } from "../middleware/TelemetryHandler";
|
||||
export { MiddlewareFactory } from "../middleware/MiddlewareFactory";
|
||||
export { AuthenticationHandlerOptions } from "../middleware/options/AuthenticationHandlerOptions";
|
||||
export { RetryHandlerOptions } from "../middleware/options/RetryHandlerOptions";
|
||||
export { RedirectHandlerOptions } from "../middleware/options/RedirectHandlerOptions";
|
||||
export { FeatureUsageFlag, TelemetryHandlerOptions } from "../middleware/options/TelemetryHandlerOptions";
|
||||
export { ChaosHandlerOptions } from "../middleware/options/ChaosHandlerOptions";
|
||||
export { ChaosStrategy } from "../middleware/options/ChaosStrategy";
|
||||
export { ChaosHandler } from "../middleware/ChaosHandler";
|
||||
export { LargeFileUploadTask } from "../tasks/LargeFileUploadTask";
|
||||
export { OneDriveLargeFileUploadTask } from "../tasks/OneDriveLargeFileUploadTask";
|
||||
export { getValidRangeSize } from "../tasks/OneDriveLargeFileUploadTaskUtil";
|
||||
export { StreamUpload } from "../tasks/FileUploadTask/FileObjectClasses/StreamUpload";
|
||||
export { FileUpload } from "../tasks/FileUploadTask/FileObjectClasses/FileUpload";
|
||||
export { UploadResult } from "../tasks/FileUploadTask/UploadResult";
|
||||
export { Range } from "../tasks/FileUploadTask/Range";
|
||||
export { PageIterator } from "../tasks/PageIterator";
|
||||
export { Client } from "../Client";
|
||||
export { CustomAuthenticationProvider } from "../CustomAuthenticationProvider";
|
||||
export { GraphError } from "../GraphError";
|
||||
export { GraphClientError } from "../GraphClientError";
|
||||
export { GraphRequest } from "../GraphRequest";
|
||||
export { ResponseType } from "../ResponseType";
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qEAAqE;AACrE,0CAA0C;AAC1C,OAAO,EAAsC,mBAAmB,EAAiC,MAAM,gCAAgC,CAAC;AACxI,OAAO,EAAqB,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAE1F,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAEtE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAC;AAElG,OAAO,EAAe,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAC7F,OAAO,EAAkB,sBAAsB,EAAE,MAAM,8CAA8C,CAAC;AACtG,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAC;AAC1G,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAyC,mBAAmB,EAAsC,MAAM,8BAA8B,CAAC;AAC9I,OAAO,EAAE,2BAA2B,EAAkC,MAAM,sCAAsC,CAAC;AACnH,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,wDAAwD,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,sDAAsD,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAEpE,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAAwB,YAAY,EAAuC,MAAM,uBAAuB,CAAC;AAEhH,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAU/C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
||||
Generated
Vendored
+144
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @interface
|
||||
* Signature representing BatchRequestStep data
|
||||
* @property {string} id - Unique identity for the request, Should not be an empty string
|
||||
* @property {string[]} [dependsOn] - Array of dependencies
|
||||
* @property {Request} request - The Request object
|
||||
*/
|
||||
export interface BatchRequestStep {
|
||||
id: string;
|
||||
dependsOn?: string[];
|
||||
request: Request;
|
||||
}
|
||||
/**
|
||||
* @interface
|
||||
* Signature representing single request in a Batching
|
||||
* @extends RequestInit
|
||||
* @see {@link https://github.com/Microsoft/TypeScript/blob/master/lib/lib.dom.d.ts#L1337} and {@link https://fetch.spec.whatwg.org/#requestinit}
|
||||
*
|
||||
* @property {string} url - The url value of the request
|
||||
*/
|
||||
export interface RequestData extends RequestInit {
|
||||
url: string;
|
||||
}
|
||||
/**
|
||||
* @interface
|
||||
* Signature representing batch request data
|
||||
* @property {string} id - Unique identity for the request, Should not be an empty string
|
||||
* @property {string[]} [dependsOn] - Array of dependencies
|
||||
*/
|
||||
export interface BatchRequestData extends RequestData {
|
||||
id: string;
|
||||
dependsOn?: string[];
|
||||
}
|
||||
/**
|
||||
* @interface
|
||||
* Signature representing batch request body
|
||||
* @property {BatchRequestData[]} requests - Array of request data, a json representation of requests for batch
|
||||
*/
|
||||
export interface BatchRequestBody {
|
||||
requests: BatchRequestData[];
|
||||
}
|
||||
/**
|
||||
* @class
|
||||
* Class for handling BatchRequestContent
|
||||
*/
|
||||
export declare class BatchRequestContent {
|
||||
/**
|
||||
* @private
|
||||
* @static
|
||||
* Limit for number of requests {@link - https://developer.microsoft.com/en-us/graph/docs/concepts/known_issues#json-batching}
|
||||
*/
|
||||
private static requestLimit;
|
||||
/**
|
||||
* @public
|
||||
* To keep track of requests, key will be id of the request and value will be the request json
|
||||
*/
|
||||
requests: Map<string, BatchRequestStep>;
|
||||
/**
|
||||
* @private
|
||||
* @static
|
||||
* Validates the dependency chain of the requests
|
||||
*
|
||||
* Note:
|
||||
* Individual requests can depend on other individual requests. Currently, requests can only depend on a single other request, and must follow one of these three patterns:
|
||||
* 1. Parallel - no individual request states a dependency in the dependsOn property.
|
||||
* 2. Serial - all individual requests depend on the previous individual request.
|
||||
* 3. Same - all individual requests that state a dependency in the dependsOn property, state the same dependency.
|
||||
* As JSON batching matures, these limitations will be removed.
|
||||
* @see {@link https://developer.microsoft.com/en-us/graph/docs/concepts/known_issues#json-batching}
|
||||
*
|
||||
* @param {Map<string, BatchRequestStep>} requests - The map of requests.
|
||||
* @returns The boolean indicating the validation status
|
||||
*/
|
||||
private static validateDependencies;
|
||||
/**
|
||||
* @private
|
||||
* @static
|
||||
* @async
|
||||
* Converts Request Object instance to a JSON
|
||||
* @param {IsomorphicRequest} request - The IsomorphicRequest Object instance
|
||||
* @returns A promise that resolves to JSON representation of a request
|
||||
*/
|
||||
private static getRequestData;
|
||||
/**
|
||||
* @private
|
||||
* @static
|
||||
* @async
|
||||
* Gets the body of a Request object instance
|
||||
* @param {IsomorphicRequest} request - The IsomorphicRequest object instance
|
||||
* @returns The Promise that resolves to a body value of a Request
|
||||
*/
|
||||
private static getRequestBody;
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Constructs a BatchRequestContent instance
|
||||
* @param {BatchRequestStep[]} [requests] - Array of requests value
|
||||
* @returns An instance of a BatchRequestContent
|
||||
*/
|
||||
constructor(requests?: BatchRequestStep[]);
|
||||
/**
|
||||
* @public
|
||||
* Adds a request to the batch request content
|
||||
* @param {BatchRequestStep} request - The request value
|
||||
* @returns The id of the added request
|
||||
*/
|
||||
addRequest(request: BatchRequestStep): string;
|
||||
/**
|
||||
* @public
|
||||
* Removes request from the batch payload and its dependencies from all dependents
|
||||
* @param {string} requestId - The id of a request that needs to be removed
|
||||
* @returns The boolean indicating removed status
|
||||
*/
|
||||
removeRequest(requestId: string): boolean;
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Serialize content from BatchRequestContent instance
|
||||
* @returns The body content to make batch request
|
||||
*/
|
||||
getContent(): Promise<BatchRequestBody>;
|
||||
/**
|
||||
* @public
|
||||
* Adds a dependency for a given dependent request
|
||||
* @param {string} dependentId - The id of the dependent request
|
||||
* @param {string} [dependencyId] - The id of the dependency request, if not specified the preceding request will be considered as a dependency
|
||||
* @returns Nothing
|
||||
*/
|
||||
addDependency(dependentId: string, dependencyId?: string): void;
|
||||
/**
|
||||
* @public
|
||||
* Removes a dependency for a given dependent request id
|
||||
* @param {string} dependentId - The id of the dependent request
|
||||
* @param {string} [dependencyId] - The id of the dependency request, if not specified will remove all the dependencies of that request
|
||||
* @returns The boolean indicating removed status
|
||||
*/
|
||||
removeDependency(dependentId: string, dependencyId?: string): boolean;
|
||||
}
|
||||
Generated
Vendored
+417
@@ -0,0 +1,417 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
import { __awaiter } from "tslib";
|
||||
/**
|
||||
* @module BatchRequestContent
|
||||
*/
|
||||
import { RequestMethod } from "../RequestMethod";
|
||||
/**
|
||||
* @class
|
||||
* Class for handling BatchRequestContent
|
||||
*/
|
||||
export class BatchRequestContent {
|
||||
/**
|
||||
* @private
|
||||
* @static
|
||||
* Validates the dependency chain of the requests
|
||||
*
|
||||
* Note:
|
||||
* Individual requests can depend on other individual requests. Currently, requests can only depend on a single other request, and must follow one of these three patterns:
|
||||
* 1. Parallel - no individual request states a dependency in the dependsOn property.
|
||||
* 2. Serial - all individual requests depend on the previous individual request.
|
||||
* 3. Same - all individual requests that state a dependency in the dependsOn property, state the same dependency.
|
||||
* As JSON batching matures, these limitations will be removed.
|
||||
* @see {@link https://developer.microsoft.com/en-us/graph/docs/concepts/known_issues#json-batching}
|
||||
*
|
||||
* @param {Map<string, BatchRequestStep>} requests - The map of requests.
|
||||
* @returns The boolean indicating the validation status
|
||||
*/
|
||||
static validateDependencies(requests) {
|
||||
const isParallel = (reqs) => {
|
||||
const iterator = reqs.entries();
|
||||
let cur = iterator.next();
|
||||
while (!cur.done) {
|
||||
const curReq = cur.value[1];
|
||||
if (curReq.dependsOn !== undefined && curReq.dependsOn.length > 0) {
|
||||
return false;
|
||||
}
|
||||
cur = iterator.next();
|
||||
}
|
||||
return true;
|
||||
};
|
||||
const isSerial = (reqs) => {
|
||||
const iterator = reqs.entries();
|
||||
let cur = iterator.next();
|
||||
const firstRequest = cur.value[1];
|
||||
if (firstRequest.dependsOn !== undefined && firstRequest.dependsOn.length > 0) {
|
||||
return false;
|
||||
}
|
||||
let prev = cur;
|
||||
cur = iterator.next();
|
||||
while (!cur.done) {
|
||||
const curReq = cur.value[1];
|
||||
if (curReq.dependsOn === undefined || curReq.dependsOn.length !== 1 || curReq.dependsOn[0] !== prev.value[1].id) {
|
||||
return false;
|
||||
}
|
||||
prev = cur;
|
||||
cur = iterator.next();
|
||||
}
|
||||
return true;
|
||||
};
|
||||
const isSame = (reqs) => {
|
||||
const iterator = reqs.entries();
|
||||
let cur = iterator.next();
|
||||
const firstRequest = cur.value[1];
|
||||
let dependencyId;
|
||||
if (firstRequest.dependsOn === undefined || firstRequest.dependsOn.length === 0) {
|
||||
dependencyId = firstRequest.id;
|
||||
}
|
||||
else {
|
||||
if (firstRequest.dependsOn.length === 1) {
|
||||
const fDependencyId = firstRequest.dependsOn[0];
|
||||
if (fDependencyId !== firstRequest.id && reqs.has(fDependencyId)) {
|
||||
dependencyId = fDependencyId;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
cur = iterator.next();
|
||||
while (!cur.done) {
|
||||
const curReq = cur.value[1];
|
||||
if ((curReq.dependsOn === undefined || curReq.dependsOn.length === 0) && dependencyId !== curReq.id) {
|
||||
return false;
|
||||
}
|
||||
if (curReq.dependsOn !== undefined && curReq.dependsOn.length !== 0) {
|
||||
if (curReq.dependsOn.length === 1 && (curReq.id === dependencyId || curReq.dependsOn[0] !== dependencyId)) {
|
||||
return false;
|
||||
}
|
||||
if (curReq.dependsOn.length > 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
cur = iterator.next();
|
||||
}
|
||||
return true;
|
||||
};
|
||||
if (requests.size === 0) {
|
||||
const error = new Error("Empty requests map, Please provide at least one request.");
|
||||
error.name = "Empty Requests Error";
|
||||
throw error;
|
||||
}
|
||||
return isParallel(requests) || isSerial(requests) || isSame(requests);
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* @static
|
||||
* @async
|
||||
* Converts Request Object instance to a JSON
|
||||
* @param {IsomorphicRequest} request - The IsomorphicRequest Object instance
|
||||
* @returns A promise that resolves to JSON representation of a request
|
||||
*/
|
||||
static getRequestData(request) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const requestData = {
|
||||
url: "",
|
||||
};
|
||||
const hasHttpRegex = new RegExp("^https?://");
|
||||
// Stripping off hostname, port and url scheme
|
||||
requestData.url = hasHttpRegex.test(request.url) ? "/" + request.url.split(/.*?\/\/.*?\//)[1] : request.url;
|
||||
requestData.method = request.method;
|
||||
const headers = {};
|
||||
request.headers.forEach((value, key) => {
|
||||
headers[key] = value;
|
||||
});
|
||||
if (Object.keys(headers).length) {
|
||||
requestData.headers = headers;
|
||||
}
|
||||
if (request.method === RequestMethod.PATCH || request.method === RequestMethod.POST || request.method === RequestMethod.PUT) {
|
||||
requestData.body = yield BatchRequestContent.getRequestBody(request);
|
||||
}
|
||||
/**
|
||||
* TODO: Check any other property needs to be used from the Request object and add them
|
||||
*/
|
||||
return requestData;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* @static
|
||||
* @async
|
||||
* Gets the body of a Request object instance
|
||||
* @param {IsomorphicRequest} request - The IsomorphicRequest object instance
|
||||
* @returns The Promise that resolves to a body value of a Request
|
||||
*/
|
||||
static getRequestBody(request) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let bodyParsed = false;
|
||||
let body;
|
||||
try {
|
||||
const cloneReq = request.clone();
|
||||
body = yield cloneReq.json();
|
||||
bodyParsed = true;
|
||||
}
|
||||
catch (e) {
|
||||
//TODO- Handle empty catches
|
||||
}
|
||||
if (!bodyParsed) {
|
||||
try {
|
||||
if (typeof Blob !== "undefined") {
|
||||
const blob = yield request.blob();
|
||||
const reader = new FileReader();
|
||||
body = yield new Promise((resolve) => {
|
||||
reader.addEventListener("load", () => {
|
||||
const dataURL = reader.result;
|
||||
/**
|
||||
* Some valid dataURL schemes:
|
||||
* 1. data:text/vnd-example+xyz;foo=bar;base64,R0lGODdh
|
||||
* 2. data:text/plain;charset=UTF-8;page=21,the%20data:1234,5678
|
||||
* 3. data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==
|
||||
* 4. data:image/png,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==
|
||||
* 5. data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==
|
||||
* @see Syntax {@link https://en.wikipedia.org/wiki/Data_URI_scheme} for more
|
||||
*/
|
||||
const regex = new RegExp("^s*data:(.+?/.+?(;.+?=.+?)*)?(;base64)?,(.*)s*$");
|
||||
const segments = regex.exec(dataURL);
|
||||
resolve(segments[4]);
|
||||
}, false);
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
}
|
||||
else if (typeof Buffer !== "undefined") {
|
||||
const buffer = yield request.buffer();
|
||||
body = buffer.toString("base64");
|
||||
}
|
||||
bodyParsed = true;
|
||||
}
|
||||
catch (e) {
|
||||
// TODO-Handle empty catches
|
||||
}
|
||||
}
|
||||
return body;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Constructs a BatchRequestContent instance
|
||||
* @param {BatchRequestStep[]} [requests] - Array of requests value
|
||||
* @returns An instance of a BatchRequestContent
|
||||
*/
|
||||
constructor(requests) {
|
||||
this.requests = new Map();
|
||||
if (typeof requests !== "undefined") {
|
||||
const limit = BatchRequestContent.requestLimit;
|
||||
if (requests.length > limit) {
|
||||
const error = new Error(`Maximum requests limit exceeded, Max allowed number of requests are ${limit}`);
|
||||
error.name = "Limit Exceeded Error";
|
||||
throw error;
|
||||
}
|
||||
for (const req of requests) {
|
||||
this.addRequest(req);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* Adds a request to the batch request content
|
||||
* @param {BatchRequestStep} request - The request value
|
||||
* @returns The id of the added request
|
||||
*/
|
||||
addRequest(request) {
|
||||
const limit = BatchRequestContent.requestLimit;
|
||||
if (request.id === "") {
|
||||
const error = new Error(`Id for a request is empty, Please provide an unique id`);
|
||||
error.name = "Empty Id For Request";
|
||||
throw error;
|
||||
}
|
||||
if (this.requests.size === limit) {
|
||||
const error = new Error(`Maximum requests limit exceeded, Max allowed number of requests are ${limit}`);
|
||||
error.name = "Limit Exceeded Error";
|
||||
throw error;
|
||||
}
|
||||
if (this.requests.has(request.id)) {
|
||||
const error = new Error(`Adding request with duplicate id ${request.id}, Make the id of the requests unique`);
|
||||
error.name = "Duplicate RequestId Error";
|
||||
throw error;
|
||||
}
|
||||
this.requests.set(request.id, request);
|
||||
return request.id;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* Removes request from the batch payload and its dependencies from all dependents
|
||||
* @param {string} requestId - The id of a request that needs to be removed
|
||||
* @returns The boolean indicating removed status
|
||||
*/
|
||||
removeRequest(requestId) {
|
||||
const deleteStatus = this.requests.delete(requestId);
|
||||
const iterator = this.requests.entries();
|
||||
let cur = iterator.next();
|
||||
/**
|
||||
* Removing dependencies where this request is present as a dependency
|
||||
*/
|
||||
while (!cur.done) {
|
||||
const dependencies = cur.value[1].dependsOn;
|
||||
if (typeof dependencies !== "undefined") {
|
||||
const index = dependencies.indexOf(requestId);
|
||||
if (index !== -1) {
|
||||
dependencies.splice(index, 1);
|
||||
}
|
||||
if (dependencies.length === 0) {
|
||||
delete cur.value[1].dependsOn;
|
||||
}
|
||||
}
|
||||
cur = iterator.next();
|
||||
}
|
||||
return deleteStatus;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* @async
|
||||
* Serialize content from BatchRequestContent instance
|
||||
* @returns The body content to make batch request
|
||||
*/
|
||||
getContent() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const requests = [];
|
||||
const requestBody = {
|
||||
requests,
|
||||
};
|
||||
const iterator = this.requests.entries();
|
||||
let cur = iterator.next();
|
||||
if (cur.done) {
|
||||
const error = new Error("No requests added yet, Please add at least one request.");
|
||||
error.name = "Empty Payload";
|
||||
throw error;
|
||||
}
|
||||
if (!BatchRequestContent.validateDependencies(this.requests)) {
|
||||
const error = new Error(`Invalid dependency found, Dependency should be:
|
||||
1. Parallel - no individual request states a dependency in the dependsOn property.
|
||||
2. Serial - all individual requests depend on the previous individual request.
|
||||
3. Same - all individual requests that state a dependency in the dependsOn property, state the same dependency.`);
|
||||
error.name = "Invalid Dependency";
|
||||
throw error;
|
||||
}
|
||||
while (!cur.done) {
|
||||
const requestStep = cur.value[1];
|
||||
const batchRequestData = (yield BatchRequestContent.getRequestData(requestStep.request));
|
||||
/**
|
||||
* @see{@https://tools.ietf.org/html/rfc7578#section-4.4}
|
||||
* TODO- Setting/Defaulting of content-type header to the correct value
|
||||
* @see {@link https://developer.microsoft.com/en-us/graph/docs/concepts/json_batching#request-format}
|
||||
*/
|
||||
if (batchRequestData.body !== undefined && (batchRequestData.headers === undefined || batchRequestData.headers["content-type"] === undefined)) {
|
||||
const error = new Error(`Content-type header is not mentioned for request #${requestStep.id}, For request having body, Content-type header should be mentioned`);
|
||||
error.name = "Invalid Content-type header";
|
||||
throw error;
|
||||
}
|
||||
batchRequestData.id = requestStep.id;
|
||||
if (requestStep.dependsOn !== undefined && requestStep.dependsOn.length > 0) {
|
||||
batchRequestData.dependsOn = requestStep.dependsOn;
|
||||
}
|
||||
requests.push(batchRequestData);
|
||||
cur = iterator.next();
|
||||
}
|
||||
requestBody.requests = requests;
|
||||
return requestBody;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* Adds a dependency for a given dependent request
|
||||
* @param {string} dependentId - The id of the dependent request
|
||||
* @param {string} [dependencyId] - The id of the dependency request, if not specified the preceding request will be considered as a dependency
|
||||
* @returns Nothing
|
||||
*/
|
||||
addDependency(dependentId, dependencyId) {
|
||||
if (!this.requests.has(dependentId)) {
|
||||
const error = new Error(`Dependent ${dependentId} does not exists, Please check the id`);
|
||||
error.name = "Invalid Dependent";
|
||||
throw error;
|
||||
}
|
||||
if (typeof dependencyId !== "undefined" && !this.requests.has(dependencyId)) {
|
||||
const error = new Error(`Dependency ${dependencyId} does not exists, Please check the id`);
|
||||
error.name = "Invalid Dependency";
|
||||
throw error;
|
||||
}
|
||||
if (typeof dependencyId !== "undefined") {
|
||||
const dependent = this.requests.get(dependentId);
|
||||
if (dependent.dependsOn === undefined) {
|
||||
dependent.dependsOn = [];
|
||||
}
|
||||
if (dependent.dependsOn.indexOf(dependencyId) !== -1) {
|
||||
const error = new Error(`Dependency ${dependencyId} is already added for the request ${dependentId}`);
|
||||
error.name = "Duplicate Dependency";
|
||||
throw error;
|
||||
}
|
||||
dependent.dependsOn.push(dependencyId);
|
||||
}
|
||||
else {
|
||||
const iterator = this.requests.entries();
|
||||
let prev;
|
||||
let cur = iterator.next();
|
||||
while (!cur.done && cur.value[1].id !== dependentId) {
|
||||
prev = cur;
|
||||
cur = iterator.next();
|
||||
}
|
||||
if (typeof prev !== "undefined") {
|
||||
const dId = prev.value[0];
|
||||
if (cur.value[1].dependsOn === undefined) {
|
||||
cur.value[1].dependsOn = [];
|
||||
}
|
||||
if (cur.value[1].dependsOn.indexOf(dId) !== -1) {
|
||||
const error = new Error(`Dependency ${dId} is already added for the request ${dependentId}`);
|
||||
error.name = "Duplicate Dependency";
|
||||
throw error;
|
||||
}
|
||||
cur.value[1].dependsOn.push(dId);
|
||||
}
|
||||
else {
|
||||
const error = new Error(`Can't add dependency ${dependencyId}, There is only a dependent request in the batch`);
|
||||
error.name = "Invalid Dependency Addition";
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* Removes a dependency for a given dependent request id
|
||||
* @param {string} dependentId - The id of the dependent request
|
||||
* @param {string} [dependencyId] - The id of the dependency request, if not specified will remove all the dependencies of that request
|
||||
* @returns The boolean indicating removed status
|
||||
*/
|
||||
removeDependency(dependentId, dependencyId) {
|
||||
const request = this.requests.get(dependentId);
|
||||
if (typeof request === "undefined" || request.dependsOn === undefined || request.dependsOn.length === 0) {
|
||||
return false;
|
||||
}
|
||||
if (typeof dependencyId !== "undefined") {
|
||||
const index = request.dependsOn.indexOf(dependencyId);
|
||||
if (index === -1) {
|
||||
return false;
|
||||
}
|
||||
request.dependsOn.splice(index, 1);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
delete request.dependsOn;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* @static
|
||||
* Limit for number of requests {@link - https://developer.microsoft.com/en-us/graph/docs/concepts/known_issues#json-batching}
|
||||
*/
|
||||
BatchRequestContent.requestLimit = 20;
|
||||
//# sourceMappingURL=BatchRequestContent.js.map
|
||||
Generated
Vendored
+1
File diff suppressed because one or more lines are too long
Generated
Vendored
+82
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @module BatchResponseContent
|
||||
*/
|
||||
/**
|
||||
* @interface
|
||||
* Signature represents key value pair object
|
||||
*/
|
||||
interface KeyValuePairObject {
|
||||
[key: string]: any;
|
||||
}
|
||||
/**
|
||||
* @interface
|
||||
* Signature representing Batch response body
|
||||
* @property {KeyValuePairObject[]} responses - An array of key value pair representing response object for every request
|
||||
* @property {string} [@odata.nextLink] - The nextLink value to get next set of responses in case of asynchronous batch requests
|
||||
*/
|
||||
export interface BatchResponseBody {
|
||||
responses: KeyValuePairObject[];
|
||||
"@odata.nextLink"?: string;
|
||||
}
|
||||
/**
|
||||
* @class
|
||||
* Class that handles BatchResponseContent
|
||||
*/
|
||||
export declare class BatchResponseContent {
|
||||
/**
|
||||
* To hold the responses
|
||||
*/
|
||||
private responses;
|
||||
/**
|
||||
* Holds the next link url
|
||||
*/
|
||||
private nextLink;
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Creates the BatchResponseContent instance
|
||||
* @param {BatchResponseBody} response - The response body returned for batch request from server
|
||||
* @returns An instance of a BatchResponseContent
|
||||
*/
|
||||
constructor(response: BatchResponseBody);
|
||||
/**
|
||||
* @private
|
||||
* Creates native Response object from the json representation of it.
|
||||
* @param {KeyValuePairObject} responseJSON - The response json value
|
||||
* @returns The Response Object instance
|
||||
*/
|
||||
private createResponseObject;
|
||||
/**
|
||||
* @public
|
||||
* Updates the Batch response content instance with given responses.
|
||||
* @param {BatchResponseBody} response - The response json representing batch response message
|
||||
* @returns Nothing
|
||||
*/
|
||||
update(response: BatchResponseBody): void;
|
||||
/**
|
||||
* @public
|
||||
* To get the response of a request for a given request id
|
||||
* @param {string} requestId - The request id value
|
||||
* @returns The Response object instance for the particular request
|
||||
*/
|
||||
getResponseById(requestId: string): Response;
|
||||
/**
|
||||
* @public
|
||||
* To get all the responses of the batch request
|
||||
* @returns The Map of id and Response objects
|
||||
*/
|
||||
getResponses(): Map<string, Response>;
|
||||
/**
|
||||
* @public
|
||||
* To get the iterator for the responses
|
||||
* @returns The Iterable generator for the response objects
|
||||
*/
|
||||
getResponsesIterator(): IterableIterator<[string, Response]>;
|
||||
}
|
||||
export {};
|
||||
Generated
Vendored
+89
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* @class
|
||||
* Class that handles BatchResponseContent
|
||||
*/
|
||||
export class BatchResponseContent {
|
||||
/**
|
||||
* @public
|
||||
* @constructor
|
||||
* Creates the BatchResponseContent instance
|
||||
* @param {BatchResponseBody} response - The response body returned for batch request from server
|
||||
* @returns An instance of a BatchResponseContent
|
||||
*/
|
||||
constructor(response) {
|
||||
this.responses = new Map();
|
||||
this.update(response);
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* Creates native Response object from the json representation of it.
|
||||
* @param {KeyValuePairObject} responseJSON - The response json value
|
||||
* @returns The Response Object instance
|
||||
*/
|
||||
createResponseObject(responseJSON) {
|
||||
const body = responseJSON.body;
|
||||
const options = {};
|
||||
options.status = responseJSON.status;
|
||||
if (responseJSON.statusText !== undefined) {
|
||||
options.statusText = responseJSON.statusText;
|
||||
}
|
||||
options.headers = responseJSON.headers;
|
||||
if (options.headers !== undefined && options.headers["Content-Type"] !== undefined) {
|
||||
if (options.headers["Content-Type"].split(";")[0] === "application/json") {
|
||||
const bodyString = JSON.stringify(body);
|
||||
return new Response(bodyString, options);
|
||||
}
|
||||
}
|
||||
return new Response(body, options);
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* Updates the Batch response content instance with given responses.
|
||||
* @param {BatchResponseBody} response - The response json representing batch response message
|
||||
* @returns Nothing
|
||||
*/
|
||||
update(response) {
|
||||
this.nextLink = response["@odata.nextLink"];
|
||||
const responses = response.responses;
|
||||
for (let i = 0, l = responses.length; i < l; i++) {
|
||||
this.responses.set(responses[i].id, this.createResponseObject(responses[i]));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* To get the response of a request for a given request id
|
||||
* @param {string} requestId - The request id value
|
||||
* @returns The Response object instance for the particular request
|
||||
*/
|
||||
getResponseById(requestId) {
|
||||
return this.responses.get(requestId);
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* To get all the responses of the batch request
|
||||
* @returns The Map of id and Response objects
|
||||
*/
|
||||
getResponses() {
|
||||
return this.responses;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
* To get the iterator for the responses
|
||||
* @returns The Iterable generator for the response objects
|
||||
*/
|
||||
*getResponsesIterator() {
|
||||
const iterator = this.responses.entries();
|
||||
let cur = iterator.next();
|
||||
while (!cur.done) {
|
||||
yield cur.value;
|
||||
cur = iterator.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=BatchResponseContent.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"BatchResponseContent.js","sourceRoot":"","sources":["../../../../src/content/BatchResponseContent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAyBH;;;GAGG;AACH,MAAM,OAAO,oBAAoB;IAWhC;;;;;;OAMG;IACH,YAAmB,QAA2B;QAC7C,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IACK,oBAAoB,CAAC,YAAgC;QAC5D,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC;QAC/B,MAAM,OAAO,GAAuB,EAAE,CAAC;QACvC,OAAO,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC;QACrC,IAAI,YAAY,CAAC,UAAU,KAAK,SAAS,EAAE;YAC1C,OAAO,CAAC,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC;SAC7C;QACD,OAAO,CAAC,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC;QACvC,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,SAAS,EAAE;YACnF,IAAI,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,kBAAkB,EAAE;gBACzE,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gBACxC,OAAO,IAAI,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;aACzC;SACD;QACD,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,QAA2B;QACxC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;QAC5C,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC;QACrC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;YACjD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC7E;IACF,CAAC;IAED;;;;;OAKG;IACI,eAAe,CAAC,SAAiB;QACvC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACI,YAAY;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACI,CAAC,oBAAoB;QAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC1C,IAAI,GAAG,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE;YACjB,MAAM,GAAG,CAAC,KAAK,CAAC;YAChB,GAAG,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;SACtB;IACF,CAAC;CACD"}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
||||
* See License in the project root for license information.
|
||||
* -------------------------------------------------------------------------------------------
|
||||
*/
|
||||
/// <reference path="../../../shims.d.ts" />
|
||||
export { BatchRequestBody, RequestData, BatchRequestContent, BatchRequestData, BatchRequestStep } from "./content/BatchRequestContent";
|
||||
export { BatchResponseBody, BatchResponseContent } from "./content/BatchResponseContent";
|
||||
export { AuthenticationHandler } from "./middleware/AuthenticationHandler";
|
||||
export { HTTPMessageHandler } from "./middleware/HTTPMessageHandler";
|
||||
export { Middleware } from "./middleware/IMiddleware";
|
||||
export { RetryHandler } from "./middleware/RetryHandler";
|
||||
export { RedirectHandler } from "./middleware/RedirectHandler";
|
||||
export { TelemetryHandler } from "./middleware/TelemetryHandler";
|
||||
export { MiddlewareFactory } from "./middleware/MiddlewareFactory";
|
||||
export { AuthenticationHandlerOptions } from "./middleware/options/AuthenticationHandlerOptions";
|
||||
export { MiddlewareOptions } from "./middleware/options/IMiddlewareOptions";
|
||||
export { RetryHandlerOptions, ShouldRetry } from "./middleware/options/RetryHandlerOptions";
|
||||
export { RedirectHandlerOptions, ShouldRedirect } from "./middleware/options/RedirectHandlerOptions";
|
||||
export { FeatureUsageFlag, TelemetryHandlerOptions } from "./middleware/options/TelemetryHandlerOptions";
|
||||
export { ChaosHandlerOptions } from "./middleware/options/ChaosHandlerOptions";
|
||||
export { ChaosStrategy } from "./middleware/options/ChaosStrategy";
|
||||
export { ChaosHandler } from "./middleware/ChaosHandler";
|
||||
export { FileObject, LargeFileUploadSession, LargeFileUploadTask, LargeFileUploadTaskOptions, SliceType } from "./tasks/LargeFileUploadTask";
|
||||
export { OneDriveLargeFileUploadOptions, OneDriveLargeFileUploadTask } from "./tasks/OneDriveLargeFileUploadTask";
|
||||
export { getValidRangeSize } from "./tasks/OneDriveLargeFileUploadTaskUtil";
|
||||
export { StreamUpload } from "./tasks/FileUploadTask/FileObjectClasses/StreamUpload";
|
||||
export { FileUpload } from "./tasks/FileUploadTask/FileObjectClasses/FileUpload";
|
||||
export { UploadResult } from "./tasks/FileUploadTask/UploadResult";
|
||||
export { UploadEventHandlers } from "./tasks/FileUploadTask/Interfaces/IUploadEventHandlers";
|
||||
export { Range } from "./tasks/FileUploadTask/Range";
|
||||
export { GraphRequestOptions, PageCollection, PageIterator, PageIteratorCallback } from "./tasks/PageIterator";
|
||||
export { Client } from "./Client";
|
||||
export { CustomAuthenticationProvider } from "./CustomAuthenticationProvider";
|
||||
export { GraphError } from "./GraphError";
|
||||
export { GraphClientError } from "./GraphClientError";
|
||||
export { GraphRequest, URLComponents } from "./GraphRequest";
|
||||
export { AuthProvider } from "./IAuthProvider";
|
||||
export { AuthenticationProvider } from "./IAuthenticationProvider";
|
||||
export { AuthenticationProviderOptions } from "./IAuthenticationProviderOptions";
|
||||
export { AuthProviderCallback } from "./IAuthProviderCallback";
|
||||
export { ClientOptions } from "./IClientOptions";
|
||||
export { Context } from "./IContext";
|
||||
export { FetchOptions, NodeFetchInit } from "./IFetchOptions";
|
||||
export { GraphRequestCallback } from "./IGraphRequestCallback";
|
||||
export { Options } from "./IOptions";
|
||||
export { ResponseType } from "./ResponseType";
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user