diff --git a/.gitignore b/.gitignore index 407f781..f4775fa 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ build bundle node_modules serverRoot -src/definitions target/modules target/tests *.user diff --git a/gulpfile.js b/gulpfile.js index 1ec20a2..1f14116 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -16,7 +16,6 @@ var runSequence = require("run-sequence"); var source = require("vinyl-source-stream"); var ts = require("gulp-typescript"); var tslint = require("gulp-tslint"); -var tsd = require("gulp-tsd"); var uglify = require("gulp-uglify"); var PATHS = { @@ -28,29 +27,6 @@ var PATHS = { WEBROOT: "serverRoot/" }; -//////////////////////////////////////// -// SETUP -//////////////////////////////////////// -gulp.task("cleanDefinitions", function (callback) { - return del([ - PATHS.DEFINITIONS - ], callback); -}); - -gulp.task("definitions", function (callback) { - tsd({ - command: "reinstall", - config: "tsd.json" - }, callback); -}); - -gulp.task("setup", function (callback) { - runSequence( - "cleanDefinitions", - "definitions", - callback); -}); - //////////////////////////////////////// // CLEAN //////////////////////////////////////// @@ -66,29 +42,37 @@ gulp.task("clean", function (callback) { //////////////////////////////////////// // COMPILE //////////////////////////////////////// -gulp.task("compile", function() { +gulp.task("compile", function () { + var tsProject = ts.createProject("./tsconfig.json", { + typescript: require('typescript'), + noEmitOnError: true + }) + return gulp.src([PATHS.SRCROOT + "**/*.+(ts|tsx)", "!**/*.d.ts"]) - .pipe(ts({ - module: "commonjs" - })) + .pipe(tsProject()) .pipe(gulp.dest(PATHS.BUILDROOT)); }); //////////////////////////////////////// // TSLINT //////////////////////////////////////// -gulp.task("tslint", function () { - var tsErrorReport = tslint.report("prose", { - emitError: false, - reportLimit: 50 - }); - - var tsFiles = [PATHS.SRCROOT + "**/*.ts", PATHS.SRCROOT + "**/*.tsx", "!" + PATHS.SRCROOT + "**/*.d.ts"]; +//The actual task to run +gulp.task("tslint", function() { + var tsFiles = [ + PATHS.SRCROOT + "**/*.ts", + PATHS.SRCROOT + "**/*.tsx", + "!" + PATHS.SRCROOT + "**/*.d.ts" + ]; return gulp.src(tsFiles) .pipe(plumber()) - .pipe(tslint()) - .pipe(tsErrorReport); + .pipe(tslint({ + formatter: "verbose" + })) + .pipe(tslint.report({ + emitError: false, + summarizeFailureOutput: true + })) }); //////////////////////////////////////// diff --git a/package.json b/package.json index 3492f83..a1105f1 100644 --- a/package.json +++ b/package.json @@ -11,27 +11,27 @@ "url": "git+https://github.com/OneNoteDev/OneNoteApi.git" }, "devDependencies": { - "browserify": "^13.0.0", - "content-type": "^1.0.2", - "del": "^2.0.2", - "file-system": "^2.2.1", - "globby": "^4.0.0", - "gulp": "^3.9.0", + "@types/content-type": "1.0.33", + "@types/es6-promise": "0.0.32", + "@types/qunit": "1.16.30", + "browserify": "13.3.0", + "content-type": "1.0.2", + "del": "2.2.2", + "file-system": "2.2.2", + "globby": "6.1.0", + "gulp": "^3.9.1", "gulp-header": "^1.8.8", - "gulp-plumber": "^1.0.1", + "gulp-plumber": "^1.1.0", "gulp-rename": "^1.2.2", - "gulp-tsd": "^0.0.4", - "gulp-tslint": "^5.0.0", - "gulp-typescript": "^2.9.2", - "gulp-uglify": "^1.5.3", - "jquery": "^2.1.4", - "merge-stream": "^1.0.0", - "node-qunit-phantomjs": "^1.4.0", + "gulp-tslint": "6.1.2", + "gulp-typescript": "3.1.4", + "gulp-uglify": "2.0.1", + "merge-stream": "^1.0.1", + "node-qunit-phantomjs": "^1.5.0", "qunitjs": "^1.20.0", - "run-sequence": "^1.1.4", - "tsd": "^0.6.5", - "tslint": "^3.9.0", - "typescript": "^1.7.3", + "run-sequence": "^1.2.2", + "tslint": "3.15.1", + "typescript": "2.1.5", "vinyl-source-stream": "^1.1.0" }, "files": [ diff --git a/src/scripts/errorUtils.ts b/src/scripts/errorUtils.ts index f99fe85..94b41d9 100644 --- a/src/scripts/errorUtils.ts +++ b/src/scripts/errorUtils.ts @@ -9,7 +9,7 @@ export enum RequestErrorType { export class ErrorUtils { public static createRequestErrorObject(request: XMLHttpRequest, errorType: RequestErrorType): OneNoteApi.RequestError { - if (request === undefined || request === null) { + if (request === undefined) { return; } @@ -47,7 +47,7 @@ export class ErrorUtils { } public static convertResponseHeadersToJson(request: XMLHttpRequest): { [key: string]: string } { - if (request === undefined || request === null) { + if (request === undefined) { return; } diff --git a/src/scripts/oneNoteApi.ts b/src/scripts/oneNoteApi.ts index 1b637b0..7f4e04c 100644 --- a/src/scripts/oneNoteApi.ts +++ b/src/scripts/oneNoteApi.ts @@ -5,16 +5,16 @@ import {BatchRequest} from "./batchRequest"; import {Revision} from "./structuredTypes"; /** -* Wrapper for easier calling of the OneNote APIs. -*/ + * Wrapper for easier calling of the OneNote APIs. + */ export class OneNoteApi extends OneNoteApiBase implements IOneNoteApi { constructor(token: string, timeout = 30000, headers: { [key: string]: string } = {}) { super(token, timeout, headers); } /** - * CreateNotebook - */ + * CreateNotebook + */ public createNotebook(name: string): Promise> { let data = JSON.stringify({ name: name }); @@ -22,8 +22,8 @@ export class OneNoteApi extends OneNoteApiBase implements IOneNoteApi { } /** - * CreatePage - */ + * CreatePage + */ public createPage(page: OneNotePage, sectionId?: string): Promise> { let sectionPath = sectionId ? "/sections/" + sectionId : ""; let url = sectionPath + "/pages"; @@ -34,7 +34,7 @@ export class OneNoteApi extends OneNoteApiBase implements IOneNoteApi { /** * SendBatchRequest - **/ + */ public sendBatchRequest(batchRequest: BatchRequest) { this.enableBetaApi(); return this.requestBasePromise("/$batch", batchRequest.getRequestBody(), batchRequest.getContentType(), "POST").then(this.disableBetaApi.bind(this)); @@ -48,11 +48,17 @@ export class OneNoteApi extends OneNoteApiBase implements IOneNoteApi { return this.requestPromise(pagePath); } + /** + * getPageContent + */ public getPageContent(pageId: string): Promise> { let pagePath = "/pages/" + pageId + "/content"; return this.requestPromise(pagePath); } + /** + * GetPages + */ public getPages(options: { top?: number, sectionId?: string }): Promise> { let pagePath = "/pages"; @@ -78,8 +84,8 @@ export class OneNoteApi extends OneNoteApiBase implements IOneNoteApi { } /** - * CreateSection - */ + * CreateSection + */ public createSection(notebookId: string, name: string): Promise> { let obj: Object = { name: name }; let data = JSON.stringify(obj); @@ -88,41 +94,41 @@ export class OneNoteApi extends OneNoteApiBase implements IOneNoteApi { } /** - * GetNotebooks - */ + * GetNotebooks + */ public getNotebooks(excludeReadOnlyNotebooks = true): Promise> { - return this.requestPromise(this.getNotebooksUrl(null /*expands*/, excludeReadOnlyNotebooks)); + return this.requestPromise(this.getNotebooksUrl(undefined /*expands*/, excludeReadOnlyNotebooks)); } /** - * GetNotebooksWithExpandedSections - */ + * GetNotebooksWithExpandedSections + */ public getNotebooksWithExpandedSections(expands = 2, excludeReadOnlyNotebooks = true): Promise> { return this.requestPromise(this.getNotebooksUrl(expands, excludeReadOnlyNotebooks)); } /** - * GetNotebookbyName - */ + * GetNotebookbyName + */ public getNotebookByName(name: string): Promise> { return this.requestPromise("/notebooks?filter=name%20eq%20%27" + encodeURI(name) + "%27&orderby=createdTime"); } /** - * PagesSearch - */ + * PagesSearch + */ public pagesSearch(query: string): Promise> { return this.requestPromise(this.getSearchUrl(query)); } /** - * GetExpands - * - * Nest expands so we can get notebook elements (sections and section groups) in - * the same call that we get notebooks. - * - * expands specifies how many levels deep to return. - */ + * GetExpands + * + * Nest expands so we can get notebook elements (sections and section groups) in + * the same call that we get notebooks. + * + * expands specifies how many levels deep to return. + */ private getExpands(expands: number): string { if (expands <= 0) { return ""; @@ -134,8 +140,8 @@ export class OneNoteApi extends OneNoteApiBase implements IOneNoteApi { } /** - * GetNotebooksUrl - */ + * GetNotebooksUrl + */ private getNotebooksUrl(numExpands = 0, excludeReadOnlyNotebooks = true): string { // Since this url is most often used to save content to a specific notebook, by default // it does not include a notebook where user has Read only permissions. @@ -145,8 +151,8 @@ export class OneNoteApi extends OneNoteApiBase implements IOneNoteApi { } /** - * GetSearchUrl - */ + * GetSearchUrl + */ private getSearchUrl(query: string): string { return "/pages?search=" + query; } diff --git a/src/scripts/oneNoteApiBase.ts b/src/scripts/oneNoteApiBase.ts index 6b22d0f..3888f89 100644 --- a/src/scripts/oneNoteApiBase.ts +++ b/src/scripts/oneNoteApiBase.ts @@ -1,7 +1,4 @@ -/// /// -/// - import {ErrorUtils, RequestErrorType} from "./errorUtils"; import * as ContentType from "content-type"; @@ -14,8 +11,8 @@ export interface ResponsePackage { } /** -* Base communication layer for talking to the OneNote APIs. -*/ + * Base communication layer for talking to the OneNote APIs. + */ export class OneNoteApiBase { // Whether or not the OneNote Beta APIs should be used. public useBetaApi: boolean = false; @@ -33,7 +30,7 @@ export class OneNoteApiBase { public requestBasePromise(partialUrl: string, data?: XHRData, contentType?: string, httpMethod?: string): Promise | OneNoteApi.RequestError> { let fullUrl = this.generateFullBaseUrl(partialUrl); - if (contentType === null) { + if (contentType === undefined) { contentType = "application/json"; } @@ -43,7 +40,7 @@ export class OneNoteApiBase { protected requestPromise(partialUrl: string, data?: XHRData, contentType?: string, httpMethod?: string): Promise> { let fullUrl = this.generateFullUrl(partialUrl); - if (contentType === null) { + if (contentType === undefined) { contentType = "application/json"; } diff --git a/src/tests/errorUtils_tests.ts b/src/tests/errorUtils_tests.ts index 97b3b64..bf91198 100644 --- a/src/tests/errorUtils_tests.ts +++ b/src/tests/errorUtils_tests.ts @@ -1,5 +1,3 @@ -/// - import {ErrorUtils, RequestErrorType} from "../scripts/errorUtils"; QUnit.module("requestError", {}); diff --git a/src/tests/index.html b/src/tests/index.html index 1f18646..f57e271 100644 --- a/src/tests/index.html +++ b/src/tests/index.html @@ -4,7 +4,6 @@ QUnit Test Suite - diff --git a/src/tests/notebookUtils_tests.ts b/src/tests/notebookUtils_tests.ts index 14ba008..ecafa92 100644 --- a/src/tests/notebookUtils_tests.ts +++ b/src/tests/notebookUtils_tests.ts @@ -1,5 +1,3 @@ -/// - import {SectionParent, SectionPathElement, NotebookUtils} from "../scripts/notebookUtils"; let createNotebook = (id: string, isDefault: boolean, sectionGroups: OneNoteApi.SectionGroup[], sections: OneNoteApi.Section[]): OneNoteApi.Notebook => { diff --git a/src/tests/oneNotePage_tests.ts b/src/tests/oneNotePage_tests.ts index b095e6e..c72ab25 100644 --- a/src/tests/oneNotePage_tests.ts +++ b/src/tests/oneNotePage_tests.ts @@ -1,5 +1,3 @@ -/// - import {OneNotePage} from "../scripts/oneNotePage"; let title = "TITLE"; diff --git a/src/tests/typedFormData_tests.ts b/src/tests/typedFormData_tests.ts index e61703e..953a4bd 100644 --- a/src/tests/typedFormData_tests.ts +++ b/src/tests/typedFormData_tests.ts @@ -1,5 +1,3 @@ -/// - import {TypedFormData} from "../scripts/typedFormData"; QUnit.module("typedFormData", {}); diff --git a/src/tslint.json b/src/tslint.json index 5813cb1..2333afa 100644 --- a/src/tslint.json +++ b/src/tslint.json @@ -7,9 +7,12 @@ "curly": true, "eofline": true, "indent": [ true, "tabs" ], - "no-consecutive-blank-lines": true, + "jsdoc-format": true, + "no-any": false, + "no-consecutive-blank-lines": [ true ], "no-console": [ true ], - "no-inferrable-types": true, + "no-inferrable-types": [ true ], + "no-null-keyword": true, "no-shadowed-variable": true, "no-string-literal": true, "no-switch-case-fall-through": false, @@ -34,8 +37,7 @@ "semicolon": [ true ], "switch-default": true, "triple-equals": [ - true, - "allow-null-check" + true ], "typedef-whitespace": [ true, @@ -67,4 +69,4 @@ "check-type" ] } -} \ No newline at end of file +} diff --git a/target/oneNoteApi.js b/target/oneNoteApi.js index c76d514..488149c 100644 --- a/target/oneNoteApi.js +++ b/target/oneNoteApi.js @@ -73,30 +73,30 @@ exports.BatchRequest = BatchRequest; Definitions of the supported ContentTypes. -------------------------------------------------------------------------*/ "use strict"; +var ContentType; (function (ContentType) { ContentType[ContentType["Html"] = 0] = "Html"; ContentType[ContentType["Image"] = 1] = "Image"; ContentType[ContentType["EnhancedUrl"] = 2] = "EnhancedUrl"; ContentType[ContentType["Url"] = 3] = "Url"; ContentType[ContentType["Onml"] = 4] = "Onml"; -})(exports.ContentType || (exports.ContentType = {})); -var ContentType = exports.ContentType; +})(ContentType = exports.ContentType || (exports.ContentType = {})); },{}],3:[function(require,module,exports){ /// "use strict"; +var RequestErrorType; (function (RequestErrorType) { RequestErrorType[RequestErrorType["NETWORK_ERROR"] = 0] = "NETWORK_ERROR"; RequestErrorType[RequestErrorType["UNEXPECTED_RESPONSE_STATUS"] = 1] = "UNEXPECTED_RESPONSE_STATUS"; RequestErrorType[RequestErrorType["REQUEST_TIMED_OUT"] = 2] = "REQUEST_TIMED_OUT"; RequestErrorType[RequestErrorType["UNABLE_TO_PARSE_RESPONSE"] = 3] = "UNABLE_TO_PARSE_RESPONSE"; -})(exports.RequestErrorType || (exports.RequestErrorType = {})); -var RequestErrorType = exports.RequestErrorType; +})(RequestErrorType = exports.RequestErrorType || (exports.RequestErrorType = {})); var ErrorUtils = (function () { function ErrorUtils() { } ErrorUtils.createRequestErrorObject = function (request, errorType) { - if (request === undefined || request === null) { + if (request === undefined) { return; } return ErrorUtils.createRequestErrorObjectInternal(request.status, request.readyState, request.response, request.getAllResponseHeaders(), request.timeout, errorType); @@ -128,7 +128,7 @@ var ErrorUtils = (function () { return requestErrorObject; }; ErrorUtils.convertResponseHeadersToJson = function (request) { - if (request === undefined || request === null) { + if (request === undefined) { return; } var responseHeaders = request.getAllResponseHeaders(); @@ -313,25 +313,25 @@ var __extends = (this && this.__extends) || function (d, b) { }; var oneNoteApiBase_1 = require("./oneNoteApiBase"); /** -* Wrapper for easier calling of the OneNote APIs. -*/ + * Wrapper for easier calling of the OneNote APIs. + */ var OneNoteApi = (function (_super) { __extends(OneNoteApi, _super); function OneNoteApi(token, timeout, headers) { if (timeout === void 0) { timeout = 30000; } if (headers === void 0) { headers = {}; } - _super.call(this, token, timeout, headers); + return _super.call(this, token, timeout, headers) || this; } /** - * CreateNotebook - */ + * CreateNotebook + */ OneNoteApi.prototype.createNotebook = function (name) { var data = JSON.stringify({ name: name }); return this.requestPromise(this.getNotebooksUrl(), data); }; /** - * CreatePage - */ + * CreatePage + */ OneNoteApi.prototype.createPage = function (page, sectionId) { var sectionPath = sectionId ? "/sections/" + sectionId : ""; var url = sectionPath + "/pages"; @@ -340,7 +340,7 @@ var OneNoteApi = (function (_super) { }; /** * SendBatchRequest - **/ + */ OneNoteApi.prototype.sendBatchRequest = function (batchRequest) { this.enableBetaApi(); return this.requestBasePromise("/$batch", batchRequest.getRequestBody(), batchRequest.getContentType(), "POST").then(this.disableBetaApi.bind(this)); @@ -352,10 +352,16 @@ var OneNoteApi = (function (_super) { var pagePath = "/pages/" + pageId; return this.requestPromise(pagePath); }; + /** + * getPageContent + */ OneNoteApi.prototype.getPageContent = function (pageId) { var pagePath = "/pages/" + pageId + "/content"; return this.requestPromise(pagePath); }; + /** + * GetPages + */ OneNoteApi.prototype.getPages = function (options) { var pagePath = "/pages"; if (options.top > 0 && options.top === Math.floor(options.top)) { @@ -375,48 +381,48 @@ var OneNoteApi = (function (_super) { return this.requestPromise(url, JSON.stringify(revisions), "application/json", "PATCH"); }; /** - * CreateSection - */ + * CreateSection + */ OneNoteApi.prototype.createSection = function (notebookId, name) { var obj = { name: name }; var data = JSON.stringify(obj); return this.requestPromise("/notebooks/" + notebookId + "/sections/", data); }; /** - * GetNotebooks - */ + * GetNotebooks + */ OneNoteApi.prototype.getNotebooks = function (excludeReadOnlyNotebooks) { if (excludeReadOnlyNotebooks === void 0) { excludeReadOnlyNotebooks = true; } - return this.requestPromise(this.getNotebooksUrl(null /*expands*/, excludeReadOnlyNotebooks)); + return this.requestPromise(this.getNotebooksUrl(undefined /*expands*/, excludeReadOnlyNotebooks)); }; /** - * GetNotebooksWithExpandedSections - */ + * GetNotebooksWithExpandedSections + */ OneNoteApi.prototype.getNotebooksWithExpandedSections = function (expands, excludeReadOnlyNotebooks) { if (expands === void 0) { expands = 2; } if (excludeReadOnlyNotebooks === void 0) { excludeReadOnlyNotebooks = true; } return this.requestPromise(this.getNotebooksUrl(expands, excludeReadOnlyNotebooks)); }; /** - * GetNotebookbyName - */ + * GetNotebookbyName + */ OneNoteApi.prototype.getNotebookByName = function (name) { return this.requestPromise("/notebooks?filter=name%20eq%20%27" + encodeURI(name) + "%27&orderby=createdTime"); }; /** - * PagesSearch - */ + * PagesSearch + */ OneNoteApi.prototype.pagesSearch = function (query) { return this.requestPromise(this.getSearchUrl(query)); }; /** - * GetExpands - * - * Nest expands so we can get notebook elements (sections and section groups) in - * the same call that we get notebooks. - * - * expands specifies how many levels deep to return. - */ + * GetExpands + * + * Nest expands so we can get notebook elements (sections and section groups) in + * the same call that we get notebooks. + * + * expands specifies how many levels deep to return. + */ OneNoteApi.prototype.getExpands = function (expands) { if (expands <= 0) { return ""; @@ -425,8 +431,8 @@ var OneNoteApi = (function (_super) { return expands === 1 ? s : s + "(" + this.getExpands(expands - 1) + ")"; }; /** - * GetNotebooksUrl - */ + * GetNotebooksUrl + */ OneNoteApi.prototype.getNotebooksUrl = function (numExpands, excludeReadOnlyNotebooks) { if (numExpands === void 0) { numExpands = 0; } if (excludeReadOnlyNotebooks === void 0) { excludeReadOnlyNotebooks = true; } @@ -436,8 +442,8 @@ var OneNoteApi = (function (_super) { return "/notebooks?" + filter + (numExpands ? "&" + this.getExpands(numExpands) : ""); }; /** - * GetSearchUrl - */ + * GetSearchUrl + */ OneNoteApi.prototype.getSearchUrl = function (query) { return "/pages?search=" + query; }; @@ -469,15 +475,13 @@ var notebookUtils_1 = require("./notebookUtils"); exports.NotebookUtils = notebookUtils_1.NotebookUtils; },{"./batchRequest":1,"./contentType":2,"./errorUtils":3,"./notebookUtils":4,"./oneNoteApiBase":6,"./oneNotePage":7}],6:[function(require,module,exports){ -/// -/// -/// "use strict"; +/// var errorUtils_1 = require("./errorUtils"); var ContentType = require("content-type"); /** -* Base communication layer for talking to the OneNote APIs. -*/ + * Base communication layer for talking to the OneNote APIs. + */ var OneNoteApiBase = (function () { function OneNoteApiBase(token, timeout, headers) { if (headers === void 0) { headers = {}; } @@ -489,7 +493,7 @@ var OneNoteApiBase = (function () { } OneNoteApiBase.prototype.requestBasePromise = function (partialUrl, data, contentType, httpMethod) { var fullUrl = this.generateFullBaseUrl(partialUrl); - if (contentType === null) { + if (contentType === undefined) { contentType = "application/json"; } return this.makeRequest(fullUrl, data, contentType, httpMethod); @@ -497,7 +501,7 @@ var OneNoteApiBase = (function () { OneNoteApiBase.prototype.requestPromise = function (partialUrl, data, contentType, httpMethod) { var _this = this; var fullUrl = this.generateFullUrl(partialUrl); - if (contentType === null) { + if (contentType === undefined) { contentType = "application/json"; } return new Promise((function (resolve, reject) { diff --git a/target/oneNoteApi.min.js b/target/oneNoteApi.min.js index 32abcd0..7c23b80 100644 --- a/target/oneNoteApi.min.js +++ b/target/oneNoteApi.min.js @@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.OneNoteApi=t()}}(function(){return function t(e,r,n){function o(i,s){if(!r[i]){if(!e[i]){var u="function"==typeof require&&require;if(!s&&u)return u(i,!0);if(a)return a(i,!0);var p=new Error("Cannot find module '"+i+"'");throw p.code="MODULE_NOT_FOUND",p}var c=r[i]={exports:{}};e[i][0].call(c.exports,function(t){var r=e[i][1][t];return o(r?r:t)},c,c.exports,t,e,r,n)}return r[i].exports}for(var a="function"==typeof require&&require,i=0;i0&&!(e>=200&&e<300)&&(p.timeout=i),p},t.convertResponseHeadersToJson=function(e){if(void 0!==e&&null!==e){var r=e.getAllResponseHeaders();return t.convertResponseHeadersToJsonInternal(r)}},t.convertResponseHeadersToJsonInternal=function(t){for(var e,r=/([^:]+):\s?(.*)/g,n={};e=r.exec(t);){e.index===r.lastIndex&&r.lastIndex++;var o=e[1].trim(),a=e[2].trim();n[o]=a}return n},t.getAdditionalNetworkErrorInfo=function(t){return": "+JSON.stringify({readyState:t})},t.formatRequestErrorTypeAsString=function(t){var e=n[t];return e.charAt(0).toUpperCase()+e.replace(/_/g," ").toLowerCase().slice(1)},t}();r.ErrorUtils=o},{}],4:[function(t,e,r){"use strict";var n=function(){function t(){}return t.sectionExistsInNotebooks=function(e,r){if(!e||!r)return!1;for(var n=0;n0,n=r?1:0;if(e.sectionGroups)for(var o=0;o0&&t.top===Math.floor(t.top)&&(e+="?top="+t.top),t.sectionId&&(e="/sections/"+t.sectionId+e),this.requestPromise(e)},e.prototype.updatePage=function(t,e){var r="/pages/"+t,n=r+"/content";return this.requestPromise(n,JSON.stringify(e),"application/json","PATCH")},e.prototype.createSection=function(t,e){var r={name:e},n=JSON.stringify(r);return this.requestPromise("/notebooks/"+t+"/sections/",n)},e.prototype.getNotebooks=function(t){return void 0===t&&(t=!0),this.requestPromise(this.getNotebooksUrl(null,t))},e.prototype.getNotebooksWithExpandedSections=function(t,e){return void 0===t&&(t=2),void 0===e&&(e=!0),this.requestPromise(this.getNotebooksUrl(t,e))},e.prototype.getNotebookByName=function(t){return this.requestPromise("/notebooks?filter=name%20eq%20%27"+encodeURI(t)+"%27&orderby=createdTime")},e.prototype.pagesSearch=function(t){return this.requestPromise(this.getSearchUrl(t))},e.prototype.getExpands=function(t){if(t<=0)return"";var e="$expand=sections,sectionGroups";return 1===t?e:e+"("+this.getExpands(t-1)+")"},e.prototype.getNotebooksUrl=function(t,e){void 0===t&&(t=0),void 0===e&&(e=!0);var r=e?"$filter=userRole%20ne%20Microsoft.OneNote.Api.UserRole'Reader'":"";return"/notebooks?"+r+(t?"&"+this.getExpands(t):"")},e.prototype.getSearchUrl=function(t){return"/pages?search="+t},e.prototype.enableBetaApi=function(){this.useBetaApi=!0},e.prototype.disableBetaApi=function(){this.useBetaApi=!1},e}(o.OneNoteApiBase);r.OneNoteApi=a;var i=t("./contentType");r.ContentType=i.ContentType;var s=t("./oneNotePage");r.OneNotePage=s.OneNotePage;var u=t("./batchRequest");r.BatchRequest=u.BatchRequest;var p=t("./errorUtils");r.ErrorUtils=p.ErrorUtils,r.RequestErrorType=p.RequestErrorType;var c=t("./notebookUtils");r.NotebookUtils=c.NotebookUtils},{"./batchRequest":1,"./contentType":2,"./errorUtils":3,"./notebookUtils":4,"./oneNoteApiBase":6,"./oneNotePage":7}],6:[function(t,e,r){"use strict";var n=t("./errorUtils"),o=t("content-type"),a=function(){function t(t,e,r){void 0===r&&(r={}),this.useBetaApi=!1,this.token=t,this.timeout=e,this.headers=r}return t.prototype.requestBasePromise=function(t,e,r,n){var o=this.generateFullBaseUrl(t);return null===r&&(r="application/json"),this.makeRequest(o,e,r,n)},t.prototype.requestPromise=function(t,e,r,n){var o=this,a=this.generateFullUrl(t);return null===r&&(r="application/json"),new Promise(function(t,i){o.makeRequest(a,e,r,n).then(function(e){t(e)},function(t){i(t)})})},t.prototype.generateFullBaseUrl=function(t){var e=this.useBetaApi?"https://www.onenote.com/api/beta":"https://www.onenote.com/api/v1.0";return e+t},t.prototype.generateFullUrl=function(t){var e=this.useBetaApi?"https://www.onenote.com/api/beta/me/notes":"https://www.onenote.com/api/v1.0/me/notes";return e+t},t.prototype.makeRequest=function(e,r,a,i){var s=this;return new Promise(function(u,p){var c,f=new XMLHttpRequest;c=i?i:r?"POST":"GET",f.open(c,e),f.timeout=s.timeout,f.onload=function(){if(200===f.status||201===f.status||204===f.status)try{var t={type:""};try{t=o.parse(f.getResponseHeader("Content-Type"))}catch(e){}var r=f.response;switch(t.type){case"application/json":r=JSON.parse(f.response?f.response:"{}");break;case"text/html":default:r=f.response}u({parsedResponse:r,request:f})}catch(a){p(n.ErrorUtils.createRequestErrorObject(f,n.RequestErrorType.UNABLE_TO_PARSE_RESPONSE))}else p(n.ErrorUtils.createRequestErrorObject(f,n.RequestErrorType.UNEXPECTED_RESPONSE_STATUS))},f.onerror=function(){p(n.ErrorUtils.createRequestErrorObject(f,n.RequestErrorType.NETWORK_ERROR))},f.ontimeout=function(){p(n.ErrorUtils.createRequestErrorObject(f,n.RequestErrorType.REQUEST_TIMED_OUT))},a&&f.setRequestHeader("Content-Type",a),f.setRequestHeader("Authorization","Bearer "+s.token),t.addHeadersToRequest(f,s.headers),f.send(r)})},t.addHeadersToRequest=function(t,e){if(e)for(var r in e)e.hasOwnProperty(r)&&t.setRequestHeader(r,e[r])},t}();r.OneNoteApiBase=a},{"./errorUtils":3,"content-type":9}],7:[function(t,e,r){"use strict";var n=t("./typedFormData"),o=function(){function t(t,e,r,n){void 0===t&&(t=""),void 0===e&&(e=""),void 0===r&&(r="en-us"),void 0===n&&(n=void 0),this.dataParts=[],this.title=t,this.presentationBody=e,this.locale=r,this.pageMetadata=n}return t.prototype.getEntireOnml=function(){return''+t+""},t.prototype.getPageMetadataAsHtml=function(){var t="";if(this.pageMetadata)for(var e in this.pageMetadata)t+='';return t},t.prototype.formUtcOffsetString=function(t){var e=t.getTimezoneOffset(),r=e>=0?"-":"+";e=Math.abs(e);var n=Math.floor(e/60)+"",o=Math.round(e%60)+"";return parseInt(n,10)<10&&(n="0"+n),parseInt(o,10)<10&&(o="0"+o),r+n+":"+o},t.prototype.generateMimePartName=function(t){return t+Math.floor(1e4*Math.random()).toString()},t.prototype.escapeHtmlEntities=function(t){var e=document.createElement("div");return e.innerText=t,e.innerHTML},t.prototype.getTypedFormData=function(){var t=new n.TypedFormData;t.append("Presentation",this.getEntireOnml(),"application/xhtml+xml");for(var e=0;e'),e},t.prototype.addImage=function(t){this.addOnml('')},t.prototype.addObjectUrlAsImage=function(t){this.addOnml('')},t.prototype.addAttachment=function(t,e){var r=this.generateMimePartName("Attachment");return this.dataParts.push({content:t,name:r,type:"application/pdf"}),this.addOnml(''),r},t.prototype.addUrl=function(t){this.addOnml('
')},t.prototype.addCitation=function(t,e,r){this.addOnml(t.replace("{0}",''+e+""))},t}();r.OneNotePage=o},{"./typedFormData":8}],8:[function(t,e,r){"use strict";var n=function(){function t(){this.contentTypeMultipart="multipart/form-data; boundary=",this.dataParts=[],this.boundaryName="OneNoteTypedDataBoundary"+Math.floor(1e3*Math.random())}return t.prototype.getContentType=function(){return this.contentTypeMultipart+this.boundaryName},t.prototype.append=function(t,e,r){this.dataParts.push({content:e,name:t,type:r})},t.prototype.asBlob=function(){for(var t="--"+this.boundaryName,e=[t],r=0;r0&&!(e>=200&&e<300)&&(p.timeout=i),p},t.convertResponseHeadersToJson=function(e){if(void 0!==e){var r=e.getAllResponseHeaders();return t.convertResponseHeadersToJsonInternal(r)}},t.convertResponseHeadersToJsonInternal=function(t){for(var e,r=/([^:]+):\s?(.*)/g,n={};e=r.exec(t);){e.index===r.lastIndex&&r.lastIndex++;var o=e[1].trim(),a=e[2].trim();n[o]=a}return n},t.getAdditionalNetworkErrorInfo=function(t){return": "+JSON.stringify({readyState:t})},t.formatRequestErrorTypeAsString=function(t){var e=n[t];return e.charAt(0).toUpperCase()+e.replace(/_/g," ").toLowerCase().slice(1)},t}();r.ErrorUtils=o},{}],4:[function(t,e,r){"use strict";var n=function(){function t(){}return t.sectionExistsInNotebooks=function(e,r){if(!e||!r)return!1;for(var n=0;n0,n=r?1:0;if(e.sectionGroups)for(var o=0;o0&&t.top===Math.floor(t.top)&&(e+="?top="+t.top),t.sectionId&&(e="/sections/"+t.sectionId+e),this.requestPromise(e)},e.prototype.updatePage=function(t,e){var r="/pages/"+t,n=r+"/content";return this.requestPromise(n,JSON.stringify(e),"application/json","PATCH")},e.prototype.createSection=function(t,e){var r={name:e},n=JSON.stringify(r);return this.requestPromise("/notebooks/"+t+"/sections/",n)},e.prototype.getNotebooks=function(t){return void 0===t&&(t=!0),this.requestPromise(this.getNotebooksUrl(void 0,t))},e.prototype.getNotebooksWithExpandedSections=function(t,e){return void 0===t&&(t=2),void 0===e&&(e=!0),this.requestPromise(this.getNotebooksUrl(t,e))},e.prototype.getNotebookByName=function(t){return this.requestPromise("/notebooks?filter=name%20eq%20%27"+encodeURI(t)+"%27&orderby=createdTime")},e.prototype.pagesSearch=function(t){return this.requestPromise(this.getSearchUrl(t))},e.prototype.getExpands=function(t){if(t<=0)return"";var e="$expand=sections,sectionGroups";return 1===t?e:e+"("+this.getExpands(t-1)+")"},e.prototype.getNotebooksUrl=function(t,e){void 0===t&&(t=0),void 0===e&&(e=!0);var r=e?"$filter=userRole%20ne%20Microsoft.OneNote.Api.UserRole'Reader'":"";return"/notebooks?"+r+(t?"&"+this.getExpands(t):"")},e.prototype.getSearchUrl=function(t){return"/pages?search="+t},e.prototype.enableBetaApi=function(){this.useBetaApi=!0},e.prototype.disableBetaApi=function(){this.useBetaApi=!1},e}(o.OneNoteApiBase);r.OneNoteApi=a;var i=t("./contentType");r.ContentType=i.ContentType;var s=t("./oneNotePage");r.OneNotePage=s.OneNotePage;var u=t("./batchRequest");r.BatchRequest=u.BatchRequest;var p=t("./errorUtils");r.ErrorUtils=p.ErrorUtils,r.RequestErrorType=p.RequestErrorType;var c=t("./notebookUtils");r.NotebookUtils=c.NotebookUtils},{"./batchRequest":1,"./contentType":2,"./errorUtils":3,"./notebookUtils":4,"./oneNoteApiBase":6,"./oneNotePage":7}],6:[function(t,e,r){"use strict";var n=t("./errorUtils"),o=t("content-type"),a=function(){function t(t,e,r){void 0===r&&(r={}),this.useBetaApi=!1,this.token=t,this.timeout=e,this.headers=r}return t.prototype.requestBasePromise=function(t,e,r,n){var o=this.generateFullBaseUrl(t);return void 0===r&&(r="application/json"),this.makeRequest(o,e,r,n)},t.prototype.requestPromise=function(t,e,r,n){var o=this,a=this.generateFullUrl(t);return void 0===r&&(r="application/json"),new Promise(function(t,i){o.makeRequest(a,e,r,n).then(function(e){t(e)},function(t){i(t)})})},t.prototype.generateFullBaseUrl=function(t){var e=this.useBetaApi?"https://www.onenote.com/api/beta":"https://www.onenote.com/api/v1.0";return e+t},t.prototype.generateFullUrl=function(t){var e=this.useBetaApi?"https://www.onenote.com/api/beta/me/notes":"https://www.onenote.com/api/v1.0/me/notes";return e+t},t.prototype.makeRequest=function(e,r,a,i){var s=this;return new Promise(function(u,p){var c,f=new XMLHttpRequest;c=i?i:r?"POST":"GET",f.open(c,e),f.timeout=s.timeout,f.onload=function(){if(200===f.status||201===f.status||204===f.status)try{var t={type:""};try{t=o.parse(f.getResponseHeader("Content-Type"))}catch(t){}var e=f.response;switch(t.type){case"application/json":e=JSON.parse(f.response?f.response:"{}");break;case"text/html":default:e=f.response}u({parsedResponse:e,request:f})}catch(t){p(n.ErrorUtils.createRequestErrorObject(f,n.RequestErrorType.UNABLE_TO_PARSE_RESPONSE))}else p(n.ErrorUtils.createRequestErrorObject(f,n.RequestErrorType.UNEXPECTED_RESPONSE_STATUS))},f.onerror=function(){p(n.ErrorUtils.createRequestErrorObject(f,n.RequestErrorType.NETWORK_ERROR))},f.ontimeout=function(){p(n.ErrorUtils.createRequestErrorObject(f,n.RequestErrorType.REQUEST_TIMED_OUT))},a&&f.setRequestHeader("Content-Type",a),f.setRequestHeader("Authorization","Bearer "+s.token),t.addHeadersToRequest(f,s.headers),f.send(r)})},t.addHeadersToRequest=function(t,e){if(e)for(var r in e)e.hasOwnProperty(r)&&t.setRequestHeader(r,e[r])},t}();r.OneNoteApiBase=a},{"./errorUtils":3,"content-type":9}],7:[function(t,e,r){"use strict";var n=t("./typedFormData"),o=function(){function t(t,e,r,n){void 0===t&&(t=""),void 0===e&&(e=""),void 0===r&&(r="en-us"),void 0===n&&(n=void 0),this.dataParts=[],this.title=t,this.presentationBody=e,this.locale=r,this.pageMetadata=n}return t.prototype.getEntireOnml=function(){return''+t+""},t.prototype.getPageMetadataAsHtml=function(){var t="";if(this.pageMetadata)for(var e in this.pageMetadata)t+='';return t},t.prototype.formUtcOffsetString=function(t){var e=t.getTimezoneOffset(),r=e>=0?"-":"+";e=Math.abs(e);var n=Math.floor(e/60)+"",o=Math.round(e%60)+"";return parseInt(n,10)<10&&(n="0"+n),parseInt(o,10)<10&&(o="0"+o),r+n+":"+o},t.prototype.generateMimePartName=function(t){return t+Math.floor(1e4*Math.random()).toString()},t.prototype.escapeHtmlEntities=function(t){var e=document.createElement("div");return e.innerText=t,e.innerHTML},t.prototype.getTypedFormData=function(){var t=new n.TypedFormData;t.append("Presentation",this.getEntireOnml(),"application/xhtml+xml");for(var e=0;e'),e},t.prototype.addImage=function(t){this.addOnml('')},t.prototype.addObjectUrlAsImage=function(t){this.addOnml('')},t.prototype.addAttachment=function(t,e){var r=this.generateMimePartName("Attachment");return this.dataParts.push({content:t,name:r,type:"application/pdf"}),this.addOnml(''),r},t.prototype.addUrl=function(t){this.addOnml('
')},t.prototype.addCitation=function(t,e,r){this.addOnml(t.replace("{0}",''+e+""))},t}();r.OneNotePage=o},{"./typedFormData":8}],8:[function(t,e,r){"use strict";var n=function(){function t(){this.contentTypeMultipart="multipart/form-data; boundary=",this.dataParts=[],this.boundaryName="OneNoteTypedDataBoundary"+Math.floor(1e3*Math.random())}return t.prototype.getContentType=function(){return this.contentTypeMultipart+this.boundaryName},t.prototype.append=function(t,e,r){this.dataParts.push({content:e,name:t,type:r})},t.prototype.asBlob=function(){for(var t="--"+this.boundaryName,e=[t],r=0;r