Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ build
bundle
node_modules
serverRoot
src/definitions
target/modules
target/tests
*.user
58 changes: 21 additions & 37 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
////////////////////////////////////////
Expand All @@ -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
}))
});

////////////////////////////////////////
Expand Down
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/errorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -47,7 +47,7 @@ export class ErrorUtils {
}

public static convertResponseHeadersToJson(request: XMLHttpRequest): { [key: string]: string } {
if (request === undefined || request === null) {
if (request === undefined) {
return;
}

Expand Down
64 changes: 35 additions & 29 deletions src/scripts/oneNoteApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ 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<ResponsePackage<any>> {
let data = JSON.stringify({ name: name });

return this.requestPromise(this.getNotebooksUrl(), data);
}

/**
* CreatePage
*/
* CreatePage
*/
public createPage(page: OneNotePage, sectionId?: string): Promise<ResponsePackage<any>> {
let sectionPath = sectionId ? "/sections/" + sectionId : "";
let url = sectionPath + "/pages";
Expand All @@ -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));
Expand All @@ -48,11 +48,17 @@ export class OneNoteApi extends OneNoteApiBase implements IOneNoteApi {
return this.requestPromise(pagePath);
}

/**
* getPageContent
*/
public getPageContent(pageId: string): Promise<ResponsePackage<any>> {
let pagePath = "/pages/" + pageId + "/content";
return this.requestPromise(pagePath);
}

/**
* GetPages
*/
public getPages(options: { top?: number, sectionId?: string }): Promise<ResponsePackage<any>> {
let pagePath = "/pages";

Expand All @@ -78,8 +84,8 @@ export class OneNoteApi extends OneNoteApiBase implements IOneNoteApi {
}

/**
* CreateSection
*/
* CreateSection
*/
public createSection(notebookId: string, name: string): Promise<ResponsePackage<any>> {
let obj: Object = { name: name };
let data = JSON.stringify(obj);
Expand All @@ -88,41 +94,41 @@ export class OneNoteApi extends OneNoteApiBase implements IOneNoteApi {
}

/**
* GetNotebooks
*/
* GetNotebooks
*/
public getNotebooks(excludeReadOnlyNotebooks = true): Promise<ResponsePackage<any>> {
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<ResponsePackage<any>> {
return this.requestPromise(this.getNotebooksUrl(expands, excludeReadOnlyNotebooks));
}

/**
* GetNotebookbyName
*/
* GetNotebookbyName
*/
public getNotebookByName(name: string): Promise<ResponsePackage<any>> {
return this.requestPromise("/notebooks?filter=name%20eq%20%27" + encodeURI(name) + "%27&orderby=createdTime");
}

/**
* PagesSearch
*/
* PagesSearch
*/
public pagesSearch(query: string): Promise<ResponsePackage<any>> {
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 "";
Expand All @@ -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.
Expand All @@ -145,8 +151,8 @@ export class OneNoteApi extends OneNoteApiBase implements IOneNoteApi {
}

/**
* GetSearchUrl
*/
* GetSearchUrl
*/
private getSearchUrl(query: string): string {
return "/pages?search=" + query;
}
Expand Down
11 changes: 4 additions & 7 deletions src/scripts/oneNoteApiBase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/// <reference path="../definitions/es6-promise/es6-promise.d.ts"/>
/// <reference path="../oneNoteApi.d.ts"/>
/// <reference path="../definitions/content-type/content-type.d.ts"/>

import {ErrorUtils, RequestErrorType} from "./errorUtils";

import * as ContentType from "content-type";
Expand All @@ -14,8 +11,8 @@ export interface ResponsePackage<T> {
}

/**
* 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;
Expand All @@ -33,7 +30,7 @@ export class OneNoteApiBase {
public requestBasePromise(partialUrl: string, data?: XHRData, contentType?: string, httpMethod?: string): Promise<ResponsePackage<any> | OneNoteApi.RequestError> {
let fullUrl = this.generateFullBaseUrl(partialUrl);

if (contentType === null) {
if (contentType === undefined) {
contentType = "application/json";
}

Expand All @@ -43,7 +40,7 @@ export class OneNoteApiBase {
protected requestPromise(partialUrl: string, data?: XHRData, contentType?: string, httpMethod?: string): Promise<ResponsePackage<any>> {
let fullUrl = this.generateFullUrl(partialUrl);

if (contentType === null) {
if (contentType === undefined) {
contentType = "application/json";
}

Expand Down
2 changes: 0 additions & 2 deletions src/tests/errorUtils_tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference path="../definitions/qunit/qunit.d.ts" />

import {ErrorUtils, RequestErrorType} from "../scripts/errorUtils";

QUnit.module("requestError", {});
Expand Down
1 change: 0 additions & 1 deletion src/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<title>QUnit Test Suite</title>
<link rel="stylesheet" href="libs/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="libs/qunit.js"></script>
<script type="text/javascript" src="libs/jquery.js"></script>

<script type="text/javascript" src="notebookUtils_tests.js"></script>
<script type="text/javascript" src="oneNotePage_tests.js"></script>
Expand Down
2 changes: 0 additions & 2 deletions src/tests/notebookUtils_tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference path="../definitions/qunit/qunit.d.ts" />

import {SectionParent, SectionPathElement, NotebookUtils} from "../scripts/notebookUtils";

let createNotebook = (id: string, isDefault: boolean, sectionGroups: OneNoteApi.SectionGroup[], sections: OneNoteApi.Section[]): OneNoteApi.Notebook => {
Expand Down
2 changes: 0 additions & 2 deletions src/tests/oneNotePage_tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference path="../definitions/qunit/qunit.d.ts" />

import {OneNotePage} from "../scripts/oneNotePage";

let title = "TITLE";
Expand Down
2 changes: 0 additions & 2 deletions src/tests/typedFormData_tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference path="../definitions/qunit/qunit.d.ts" />

import {TypedFormData} from "../scripts/typedFormData";

QUnit.module("typedFormData", {});
Expand Down
Loading