@microsoft/microsoft-graph-client
Advanced tools
Comparing version 1.5.2 to 1.6.0-Preview.1
@@ -20,7 +20,2 @@ /** | ||
* @private | ||
* A member holding the clientId of an application | ||
*/ | ||
private clientId; | ||
/** | ||
* @private | ||
* A member holding the list of graph scopes | ||
@@ -30,6 +25,6 @@ */ | ||
/** | ||
* @private | ||
* @public | ||
* A member holding an instance of UserAgentApplication returned from MSAL | ||
*/ | ||
private userAgentApplication; | ||
userAgentApplication: any; | ||
/** | ||
@@ -39,3 +34,3 @@ * @public | ||
* Creates an instance of MSALAuthenticationProvider | ||
* @param {string} clientId - The clientId value of an application | ||
* @param {string | any} clientIdOrUserAgentApplication - The clientId value of an application or an instance of UserAgentApplication | ||
* @param {string[]} scopes - An array of graph scopes | ||
@@ -45,3 +40,3 @@ * @param {any} [options] - An options object for MSAL initialization | ||
*/ | ||
constructor(clientId: string, scopes: string[], options?: any); | ||
constructor(clientIdOrUserAgentApplication: string | any, scopes: string[], options?: any); | ||
/** | ||
@@ -48,0 +43,0 @@ * @public |
@@ -20,3 +20,3 @@ "use strict"; | ||
* Creates an instance of MSALAuthenticationProvider | ||
* @param {string} clientId - The clientId value of an application | ||
* @param {string | any} clientIdOrUserAgentApplication - The clientId value of an application or an instance of UserAgentApplication | ||
* @param {string[]} scopes - An array of graph scopes | ||
@@ -26,9 +26,8 @@ * @param {any} [options] - An options object for MSAL initialization | ||
*/ | ||
function MSALAuthenticationProvider(clientId, scopes, options) { | ||
function MSALAuthenticationProvider(clientIdOrUserAgentApplication, scopes, options) { | ||
var callback = function (errorDesc, token, error, tokenType) { | ||
// tslint:disable-line: no-empty | ||
}; | ||
this.clientId = clientId; | ||
this.scopes = scopes; | ||
this.userAgentApplication = new Msal.UserAgentApplication(this.clientId, undefined, callback, options); | ||
this.userAgentApplication = typeof clientIdOrUserAgentApplication === "string" ? new Msal.UserAgentApplication(clientIdOrUserAgentApplication, undefined, callback, options) : clientIdOrUserAgentApplication; | ||
} | ||
@@ -35,0 +34,0 @@ /** |
@@ -26,2 +26,2 @@ /** | ||
*/ | ||
export declare const PACKAGE_VERSION = "1.5.2"; | ||
export declare const PACKAGE_VERSION = "1.6.0-Preview.1"; |
@@ -28,3 +28,3 @@ "use strict"; | ||
*/ | ||
exports.PACKAGE_VERSION = "1.5.2"; | ||
exports.PACKAGE_VERSION = "1.6.0-Preview.1"; | ||
//# sourceMappingURL=Constants.js.map |
@@ -127,3 +127,3 @@ "use strict"; | ||
case 0: | ||
if (!(error instanceof Response)) return [3 /*break*/, 2]; | ||
if (!(error && (error.constructor.name === "Response" || error.constructor.name === "Body"))) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, GraphErrorHandler.constructErrorFromRawResponse(error, statusCode)]; | ||
@@ -137,3 +137,3 @@ case 1: | ||
} | ||
else if (error instanceof Error) { | ||
else if (error && error.constructor.name === "Error") { | ||
gError = GraphErrorHandler.constructError(error, statusCode); | ||
@@ -140,0 +140,0 @@ } |
@@ -13,2 +13,16 @@ /** | ||
/** | ||
* @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 | ||
@@ -21,8 +35,2 @@ * Class for GraphResponseHandler | ||
* @static | ||
* A member holding array of document types | ||
*/ | ||
private static DocumentTypes; | ||
/** | ||
* @private | ||
* @static | ||
* To parse Document response | ||
@@ -29,0 +37,0 @@ * @param {Response} rawResponse - The response object |
@@ -25,4 +25,26 @@ "use strict"; | ||
DocumentType["APPLICATION_XHTML"] = "application/xhtml+xml"; | ||
})(DocumentType || (DocumentType = {})); | ||
})(DocumentType = exports.DocumentType || (exports.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 | ||
@@ -77,5 +99,5 @@ * Class for GraphResponseHandler | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var clonedRawResponse, responseValue, _a, contentType, mimeType, _b, error_1; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
var clonedRawResponse, responseValue, _a, contentType, mimeType, error_1; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
@@ -87,5 +109,5 @@ clonedRawResponse = rawResponse.clone(); | ||
} | ||
_c.label = 1; | ||
_b.label = 1; | ||
case 1: | ||
_c.trys.push([1, 22, , 23]); | ||
_b.trys.push([1, 26, , 27]); | ||
_a = responseType; | ||
@@ -103,41 +125,54 @@ switch (_a) { | ||
case 3: | ||
responseValue = _c.sent(); | ||
return [3 /*break*/, 21]; | ||
responseValue = _b.sent(); | ||
return [3 /*break*/, 25]; | ||
case 4: return [4 /*yield*/, clonedRawResponse.blob()]; | ||
case 5: | ||
responseValue = _c.sent(); | ||
return [3 /*break*/, 21]; | ||
responseValue = _b.sent(); | ||
return [3 /*break*/, 25]; | ||
case 6: return [4 /*yield*/, GraphResponseHandler.parseDocumentResponse(clonedRawResponse, DocumentType.TEXT_XML)]; | ||
case 7: | ||
responseValue = _c.sent(); | ||
return [3 /*break*/, 21]; | ||
responseValue = _b.sent(); | ||
return [3 /*break*/, 25]; | ||
case 8: return [4 /*yield*/, clonedRawResponse.json()]; | ||
case 9: | ||
responseValue = _c.sent(); | ||
return [3 /*break*/, 21]; | ||
responseValue = _b.sent(); | ||
return [3 /*break*/, 25]; | ||
case 10: return [4 /*yield*/, Promise.resolve(clonedRawResponse.body)]; | ||
case 11: | ||
responseValue = _c.sent(); | ||
return [3 /*break*/, 21]; | ||
responseValue = _b.sent(); | ||
return [3 /*break*/, 25]; | ||
case 12: return [4 /*yield*/, clonedRawResponse.text()]; | ||
case 13: | ||
responseValue = _c.sent(); | ||
return [3 /*break*/, 21]; | ||
responseValue = _b.sent(); | ||
return [3 /*break*/, 25]; | ||
case 14: | ||
contentType = clonedRawResponse.headers.get("Content-type"); | ||
if (!(contentType !== null)) return [3 /*break*/, 19]; | ||
if (!(contentType !== null)) return [3 /*break*/, 23]; | ||
mimeType = contentType.split(";")[0]; | ||
if (!GraphResponseHandler.DocumentTypes.includes(mimeType)) return [3 /*break*/, 16]; | ||
if (!new RegExp(ContentTypeRegexStr.DOCUMENT).test(mimeType)) return [3 /*break*/, 16]; | ||
return [4 /*yield*/, GraphResponseHandler.parseDocumentResponse(clonedRawResponse, mimeType)]; | ||
case 15: | ||
_b = _c.sent(); | ||
return [3 /*break*/, 18]; | ||
case 16: return [4 /*yield*/, clonedRawResponse.json()]; | ||
responseValue = _b.sent(); | ||
return [3 /*break*/, 22]; | ||
case 16: | ||
if (!new RegExp(ContentTypeRegexStr.IMAGE).test(mimeType)) return [3 /*break*/, 17]; | ||
responseValue = clonedRawResponse.blob(); | ||
return [3 /*break*/, 22]; | ||
case 17: | ||
_b = _c.sent(); | ||
_c.label = 18; | ||
if (!(mimeType === ContentType.TEXT_PLAIN)) return [3 /*break*/, 19]; | ||
return [4 /*yield*/, clonedRawResponse.text()]; | ||
case 18: | ||
responseValue = _b; | ||
return [3 /*break*/, 20]; | ||
responseValue = _b.sent(); | ||
return [3 /*break*/, 22]; | ||
case 19: | ||
if (!(mimeType === ContentType.APPLICATION_JSON)) return [3 /*break*/, 21]; | ||
return [4 /*yield*/, clonedRawResponse.json()]; | ||
case 20: | ||
responseValue = _b.sent(); | ||
return [3 /*break*/, 22]; | ||
case 21: | ||
responseValue = Promise.resolve(clonedRawResponse.body); | ||
_b.label = 22; | ||
case 22: return [3 /*break*/, 24]; | ||
case 23: | ||
/** | ||
@@ -155,9 +190,9 @@ * RFC specification {@link https://tools.ietf.org/html/rfc7231#section-3.1.1.5} says: | ||
responseValue = Promise.resolve(clonedRawResponse.body); | ||
_c.label = 20; | ||
case 20: return [3 /*break*/, 21]; | ||
case 21: return [3 /*break*/, 23]; | ||
case 22: | ||
error_1 = _c.sent(); | ||
_b.label = 24; | ||
case 24: return [3 /*break*/, 25]; | ||
case 25: return [3 /*break*/, 27]; | ||
case 26: | ||
error_1 = _b.sent(); | ||
throw error_1; | ||
case 23: return [2 /*return*/, responseValue]; | ||
case 27: return [2 /*return*/, responseValue]; | ||
} | ||
@@ -212,8 +247,2 @@ }); | ||
}; | ||
/** | ||
* @private | ||
* @static | ||
* A member holding array of document types | ||
*/ | ||
GraphResponseHandler.DocumentTypes = ["text/html", "text/xml", "application/xml", "application/xhtml+xml"]; | ||
return GraphResponseHandler; | ||
@@ -220,0 +249,0 @@ }()); |
@@ -7,2 +7,6 @@ /** | ||
*/ | ||
/** | ||
* @module MSALAuthenticationProvider | ||
*/ | ||
import { UserAgentApplication } from "msal"; | ||
import { AuthenticationProvider } from "./IAuthenticationProvider"; | ||
@@ -18,7 +22,2 @@ import { AuthenticationProviderOptions } from "./IAuthenticationProviderOptions"; | ||
* @private | ||
* A member holding the clientId of an application | ||
*/ | ||
private clientId; | ||
/** | ||
* @private | ||
* A member holding the list of graph scopes | ||
@@ -28,6 +27,6 @@ */ | ||
/** | ||
* @private | ||
* @public | ||
* A member holding an instance of UserAgentApplication returned from MSAL | ||
*/ | ||
private userAgentApplication; | ||
userAgentApplication: UserAgentApplication; | ||
/** | ||
@@ -37,3 +36,3 @@ * @public | ||
* Creates an instance of MSALAuthenticationProvider | ||
* @param {string} clientId - The clientId value of an application | ||
* @param {string | UserAgentApplication} clientIdOrUserAgentApplication - The clientId value of an application or an instance of UserAgentApplication | ||
* @param {string[]} scopes - An array of graph scopes | ||
@@ -43,3 +42,3 @@ * @param {any} [options] - An options object for MSAL initialization | ||
*/ | ||
constructor(clientId: string, scopes: string[], options?: any); | ||
constructor(clientIdOrUserAgentApplication: string | UserAgentApplication, scopes: string[], options?: any); | ||
/** | ||
@@ -46,0 +45,0 @@ * @public |
@@ -24,3 +24,3 @@ "use strict"; | ||
* Creates an instance of MSALAuthenticationProvider | ||
* @param {string} clientId - The clientId value of an application | ||
* @param {string | UserAgentApplication} clientIdOrUserAgentApplication - The clientId value of an application or an instance of UserAgentApplication | ||
* @param {string[]} scopes - An array of graph scopes | ||
@@ -30,7 +30,6 @@ * @param {any} [options] - An options object for MSAL initialization | ||
*/ | ||
function MSALAuthenticationProvider(clientId, scopes, options) { | ||
function MSALAuthenticationProvider(clientIdOrUserAgentApplication, scopes, options) { | ||
var callback = function (errorDesc, token, error, tokenType) { }; // tslint:disable-line: no-empty | ||
this.clientId = clientId; | ||
this.scopes = scopes; | ||
this.userAgentApplication = new msal_1.UserAgentApplication(this.clientId, undefined, callback, options); | ||
this.userAgentApplication = typeof clientIdOrUserAgentApplication === "string" ? new msal_1.UserAgentApplication(clientIdOrUserAgentApplication, undefined, callback, options) : clientIdOrUserAgentApplication; | ||
} | ||
@@ -37,0 +36,0 @@ /** |
{ | ||
"name": "@microsoft/microsoft-graph-client", | ||
"//": "NOTE: The version here should match exactly the exported const PACKAGE_VERSION in Constants.ts. If you change it here, also change it there.", | ||
"version": "1.5.2", | ||
"version": "1.6.0-Preview.1", | ||
"description": "Microsoft Graph Client Library", | ||
@@ -6,0 +6,0 @@ "main": "lib/src/index.js", |
@@ -63,9 +63,13 @@ # Microsoft Graph JavaScript Client Library | ||
```typescript | ||
const clientID = "your_client_id"; // Client Id of the registered application | ||
const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes | ||
const clientId = "your_client_id"; // Client Id of the registered application | ||
const callback = (errorDesc, token, error, tokenType) => {}; | ||
// An Optional options for initializing the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#configuration-options | ||
const options = { | ||
// An Optional options for initializing the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#configuration-options | ||
redirectUri: "Your redirect URI", | ||
}; | ||
const authProvider = new MicrosoftGraph.MSALAuthenticationProvider(clientId, graphScopes, options); | ||
const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes | ||
// Initialize the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#initialization-of-msal | ||
const userAgentApplication = new Msal.UserAgentApplication(clientId, undefined, callback, options); | ||
const authProvider = new MicrosoftGraph.MSALAuthenticationProvider(userAgentApplication, graphScopes); | ||
``` | ||
@@ -82,11 +86,17 @@ | ||
```typescript | ||
import { UserAgentApplication } from "msal"; | ||
import { MSALAuthenticationProvider } from "./node_modules/@microsoft/microsoft-graph-client/lib/src/MSALAuthenticationProvider"; | ||
const clientId = "your_client_id"; // Client Id of the registered application | ||
const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes | ||
const callback = (errorDesc, token, error, tokenType) => {}; | ||
// An Optional options for initializing the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#configuration-options | ||
const options = { | ||
// An Optional options for initializing the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#configuration-options | ||
redirectUri: "Your redirect URI", | ||
}; | ||
const authProvider = new MSALAuthenticationProvider(clientId, scopes, options); | ||
const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes | ||
// Initialize the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#initialization-of-msal | ||
const userAgentApplication = new UserAgentApplication(clientId, undefined, callback, options); | ||
const authProvider = new MSALAuthenticationProvider(userAgentApplication, scopes); | ||
``` | ||
@@ -93,0 +103,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
627892
6725
215
4