Skip to content

Commit fe087b7

Browse files
Merge remote-tracking branch 'origin/dev' into v2.0.0
2 parents edd80e4 + 0fa7f8c commit fe087b7

17 files changed

+215
-142
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ try {
184184
}
185185
```
186186

187-
For more information, refer: [Calling Pattern](docs/CallingPattern.md), [Actions](docs/Actions.md), [Query Params](docs/QueryParameters.md), [API Methods](docs/APIMethods.md) and [more](docs/).
187+
For more information, refer: [Calling Pattern](docs/CallingPattern.md), [Actions](docs/Actions.md), [Query Params](docs/QueryParameters.md), [API Methods](docs/OtherAPIs.md) and [more](docs/).
188188

189189
## Documentation
190190

docs/CallingPattern.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Calling Pattern
2+
3+
All calls to Microsoft Graph are chained together starting with **.api()**, then chain [query parameters](./QueryParameters.md) and end with an [action](./Actions.md).
4+
5+
## Path supports the following formats
6+
7+
* `me`
8+
* `/me`
9+
* `https://graph.microsoft.com/v1.0/me`
10+
* `https://graph.microsoft.com/beta/me`
11+
* `me/events?$filter=startswith(subject, "Adventure")`
12+
13+
## Promise based calling
14+
15+
Getting user details with `async`/`await`,
16+
17+
```typescript
18+
try {
19+
let res = await client.api("/me").get();
20+
console.log(res);
21+
} catch (error) {
22+
throw error;
23+
}
24+
```
25+
26+
Getting user details with `then`/`catch`,
27+
28+
```typescript
29+
client
30+
.api('/me')
31+
.get()
32+
.then((res) => {
33+
console.log(res);
34+
}).catch((err) => {
35+
console.log(err);
36+
});
37+
```
38+
39+
## Callback based calling
40+
41+
Getting user details by passing `callback`,
42+
43+
```typescript
44+
client
45+
.api('/me')
46+
.get((err, res, rawResponse) => {
47+
console.log(res);
48+
});
49+
```

docs/tasks/LargeFileUploadTask.md

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Large File Upload Task - Uploading large files to OneDrive.
1+
# Large File Upload Task - Uploading large files to OneDrive
22

3-
This task simplifies the implementation of onedrive's [resumable upload](https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_createuploadsession).
3+
This task simplifies the implementation of OneDrive's [resumable upload](https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_createuploadsession).
44

55
## Creating the client instance
66

@@ -20,47 +20,60 @@ Get files from the input element and start uploading.
2020
async function fileUpload(elem) {
2121
let file = elem.files[0];
2222
try {
23-
let response = await largeFilUpload(client, file, file.name);
23+
let response = await largeFileUpload(client, file, file.name);
24+
console.log(response);
25+
console.log("File Uploaded Successfully.!!");
2426
} catch (error) {
2527
console.error(error);
2628
}
2729
}
30+
31+
async function largeFileUpload(client, file) {
32+
try {
33+
let options = {
34+
path: "/Documents",
35+
fileName: file.name,
36+
rangeSize: 1024 * 1024,
37+
};
38+
const uploadTask = await MicrosoftGraph.OneDriveLargeFileUploadTask.create(client, file, options);
39+
const response = await uploadTask.upload();
40+
return response;
41+
} catch (err) {
42+
throw err;
43+
}
44+
}
2845
```
2946

3047
## Uploading from NodeJS
3148

3249
```typescript
3350
function uploadFile() {
34-
fs.readFile(<PATH_OF_THE_FILE>, {}, function (err, file) {
35-
if(err) {
36-
throw err;
37-
}
38-
let fileName = <NAME_OF_THE_FILE>;
39-
largeFileUpload(client, file, fileName)
40-
.then((response) => {
41-
console.log(response);
42-
})
43-
.catch((error) => {
44-
console.error(error);
45-
});
46-
});
51+
fs.readFile("<PATH_OF_THE_FILE>", {}, function(err, file) {
52+
if (err) {
53+
throw err;
54+
}
55+
let fileName = "<NAME_OF_THE_FILE_WITH_EXTN>";
56+
oneDriveLargeFileUpload(client, file, fileName)
57+
.then((response) => {
58+
console.log(response);
59+
console.log("File Uploaded Successfully.!!");
60+
})
61+
.catch((error) => {
62+
throw err;
63+
});
64+
});
4765
}
48-
```
4966

50-
## Creating session and start uploading
51-
52-
```typescript
53-
async function uploadFile(client, file) {
67+
async function oneDriveLargeFileUpload(client, file, fileName) {
5468
try {
5569
let options = {
5670
path: "/Documents",
57-
fileName: file.name,
71+
fileName,
5872
rangeSize: 1024 * 1024,
5973
};
60-
const uploadTask = await MicrosoftGraph.OneDriveLargeFileUploadTask.create(client, file, options);
74+
const uploadTask = await OneDriveLargeFileUploadTask.create(client, file, options);
6175
const response = await uploadTask.upload();
62-
console.log(response);
63-
console.log("File Uploaded Successfully.!!");
76+
return response;
6477
} catch (err) {
6578
console.log(err);
6679
}
@@ -84,3 +97,35 @@ let range = uploadTask.getNextRange();
8497
let slicedFile = uploadTask.sliceFile(range);
8598
uploadTask.uploadSlice(slicedFile, range, uploadTask.file.size);
8699
```
100+
101+
## Uploading with custom options
102+
103+
_You can pass in the customized options using LargeFileUploadTask_
104+
105+
```typescript
106+
async function largeFileUpload(client, file) {
107+
const filename = file.name;
108+
const driveId = "<YOUR_DRIVE_ID>";
109+
const path = "<LOCATION_TO_STORE_FILE>";
110+
try {
111+
const requestUrl = `/drives/${driveId}/root:${path}/${fileName}:/createUploadSession`;
112+
const payload = {
113+
item: {
114+
"@microsoft.graph.conflictBehavior": "fail",
115+
name: fileName,
116+
},
117+
};
118+
const fileObject = {
119+
size: file.size,
120+
content: file,
121+
name: fileName,
122+
};
123+
const uploadSession = await LargeFileUploadTask.createUploadSession(client, requestUrl, payload);
124+
const uploadTask = await new LargeFileUploadTask(client, fileObject, uploadSession);
125+
const response = await uploadTask.upload();
126+
return response;
127+
} catch (err) {
128+
throw err;
129+
}
130+
}
131+
```

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@microsoft/microsoft-graph-client",
33
"//": "NOTE: The version here should match exactly the exported const PACKAGE_VERSION in Constants.ts. If you change it here, also change it there.",
4-
"version": "1.7.0-Preview.1",
4+
"version": "1.7.0",
55
"description": "Microsoft Graph Client Library",
66
"main": "lib/src/index.js",
77
"module": "lib/es/index.js",

samples/node/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ You can get an access token by doing the following:
1414
## Run Sample
1515

1616
1. Run `npm install` to install the application.
17-
2. Run samples in one of two ways
17+
2. Run `npm run build` to build the library files.
18+
3. Run samples in one of two ways
1819
1. Run and debug the node samples found under ./samples/node/main.js by running the Run node samples configuration from the Debug menu in Visual Studio Code.
19-
2. Run the node samples from the CLI by entering node ./samples/node/main.js (assuming you are at the root of this repository).
20+
2. Run the node samples from the CLI by entering `node ./samples/node/main.js` (assuming you are at the root of this repository).

spec/core/GraphErrorHandler.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,6 @@ describe("GraphErrorHandler.ts", () => {
3030
});
3131
});
3232

33-
describe("constructErrorFromRawResponse", async () => {
34-
it("Should parse error from raw response", async () => {
35-
const body = "unauthorized";
36-
const statusCode = 401;
37-
const errorResponse = new Response(body, {
38-
status: statusCode,
39-
});
40-
const gError = await GraphErrorHandler["constructErrorFromRawResponse"](errorResponse, statusCode);
41-
assert.equal(gError.statusCode, statusCode);
42-
assert.equal(gError.body, body);
43-
});
44-
45-
it("Should parse error without body", async () => {
46-
const statusCode = 401;
47-
const errorResponse = new Response(undefined, {
48-
status: statusCode,
49-
});
50-
const gError = await GraphErrorHandler["constructErrorFromRawResponse"](errorResponse, statusCode);
51-
assert.equal(gError.statusCode, statusCode);
52-
assert.isNull(gError.body);
53-
});
54-
});
55-
5633
describe("constructErrorFromResponse", () => {
5734
const statusCode = 400;
5835
const error: any = {

spec/core/GraphResponseHandler.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,5 @@ describe("GraphResponseHandler.ts", () => {
158158
const responseValue = await GraphResponseHandler.getResponse(response, ResponseType.TEXT);
159159
assert.isDefined(responseValue);
160160
});
161-
162-
it("Should parse from raw response for NOT OK response", async () => {
163-
try {
164-
const response = new Response("NOT OK", status500);
165-
const responseValue = await GraphResponseHandler.getResponse(response, ResponseType.TEXT);
166-
throw new Error("Something wrong with validating OK response");
167-
} catch (error) {
168-
assert.isDefined(error);
169-
assert.isTrue(error instanceof Response);
170-
assert.equal(error.status, 500);
171-
}
172-
});
173161
});
174162
});

spec/tasks/LargeFileUploadTask.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { LargeFileUploadTask } from "../../src/tasks/LargeFileUploadTask";
1111
import { getClient } from "../test-helper";
1212

1313
describe("LargeFileUploadTask.ts", () => {
14+
/* tslint:disable: no-string-literal */
1415
describe("Parsing Range", () => {
1516
const name = "sample_image.jpg";
1617
const arrayBuffer = new ArrayBuffer(80000);
@@ -27,34 +28,33 @@ describe("LargeFileUploadTask.ts", () => {
2728
const options = {};
2829
const uploadTask = new LargeFileUploadTask(getClient(), fileObj, uploadSession, options);
2930
it("Should return default range for given undefined range", (done) => {
30-
const range = uploadTask.parseRange([]);
31+
const range = uploadTask["parseRange"]([]);
3132
assert.equal(range.minValue, -1);
3233
assert.equal(range.maxValue, -1);
3334
done();
3435
});
3536

3637
it("Should return default range for given empty range", (done) => {
37-
const range = uploadTask.parseRange([""]);
38+
const range = uploadTask["parseRange"]([""]);
3839
assert.equal(range.minValue, -1);
3940
assert.equal(range.maxValue, -1);
4041
done();
4142
});
4243

4344
it("Should return valid range for given range with from and to values", (done) => {
44-
const range = uploadTask.parseRange(["100-200"]);
45+
const range = uploadTask["parseRange"](["100-200"]);
4546
assert.equal(range.minValue, 100);
4647
assert.equal(range.maxValue, 200);
4748
done();
4849
});
4950

5051
it("Should return valid range for given range without to value", (done) => {
51-
const range = uploadTask.parseRange(["0-"]);
52+
const range = uploadTask["parseRange"](["0-"]);
5253
assert.equal(range.minValue, 0);
5354
assert.equal(range.maxValue, 99999);
5455
done();
5556
});
5657
});
57-
/* tslint:disable: no-string-literal */
5858
describe("Update Task Status", () => {
5959
const name = "sample_image.jpg";
6060
const arrayBuffer = new ArrayBuffer(80000);
@@ -75,7 +75,7 @@ describe("LargeFileUploadTask.ts", () => {
7575
expirationDateTime: "2018-08-06T09:05:45.195Z",
7676
nextExpectedRanges: ["100-2000"],
7777
};
78-
uploadTask.updateTaskStatus(statusResponse);
78+
uploadTask["updateTaskStatus"](statusResponse);
7979
assert.equal(uploadTask["nextRange"].minValue, 100);
8080
assert.equal(uploadTask["nextRange"].maxValue, 2000);
8181
done();
@@ -85,13 +85,12 @@ describe("LargeFileUploadTask.ts", () => {
8585
expirationDateTime: "2018-08-06T09:05:45.195Z",
8686
nextExpectedRanges: ["100-"],
8787
};
88-
uploadTask.updateTaskStatus(statusResponse);
88+
uploadTask["updateTaskStatus"](statusResponse);
8989
assert.equal(uploadTask["nextRange"].minValue, 100);
9090
assert.equal(uploadTask["nextRange"].maxValue, 99999);
9191
done();
9292
});
9393
});
94-
/* tslint:enable: no-string-literal */
9594

9695
describe("GetNextRange", () => {
9796
const name = "sample_image.jpg";
@@ -123,7 +122,7 @@ describe("LargeFileUploadTask.ts", () => {
123122
expirationDateTime: "2018-08-06T09:05:45.195Z",
124123
nextExpectedRanges: ["327680-"],
125124
};
126-
uploadTask.updateTaskStatus(statusResponse);
125+
uploadTask["updateTaskStatus"](statusResponse);
127126
const nextRange = uploadTask.getNextRange();
128127
assert.equal(nextRange.minValue, 327680);
129128
assert.equal(nextRange.maxValue, 328679);
@@ -135,7 +134,7 @@ describe("LargeFileUploadTask.ts", () => {
135134
expirationDateTime: "2018-08-06T09:05:45.195Z",
136135
nextExpectedRanges: [],
137136
};
138-
uploadTask.updateTaskStatus(statusResponse);
137+
uploadTask["updateTaskStatus"](statusResponse);
139138
const nextRange = uploadTask.getNextRange();
140139
assert.equal(nextRange.minValue, -1);
141140
assert.equal(nextRange.maxValue, -1);
@@ -165,7 +164,7 @@ describe("LargeFileUploadTask.ts", () => {
165164
expirationDateTime: "2018-08-06T09:05:45.195Z",
166165
nextExpectedRanges: [],
167166
};
168-
uploadTask.updateTaskStatus(statusResponse);
167+
uploadTask["updateTaskStatus"](statusResponse);
169168
uploadTask
170169
.upload()
171170
.then((res) => {
@@ -178,4 +177,5 @@ describe("LargeFileUploadTask.ts", () => {
178177
});
179178
});
180179
});
180+
/* tslint:enable: no-string-literal */
181181
});

0 commit comments

Comments
 (0)