Skip to content

Commit 2e745db

Browse files
U-FAREAST\ramguptU-FAREAST\ramgupt
U-FAREAST\ramgupt
authored and
U-FAREAST\ramgupt
committed
Merge commit 'refs/pull/63/head' of https://github.com/microsoftgraph/msgraph-sdk-javascript into fix-POST-PATCH-PUT-request
2 parents 574974a + 89ab20b commit 2e745db

File tree

10 files changed

+2379
-265
lines changed

10 files changed

+2379
-265
lines changed

lib/graph-js-sdk-web.js

Lines changed: 2163 additions & 113 deletions
Large diffs are not rendered by default.

lib/src/GraphHelper.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export declare class GraphHelper {
2+
static serializeContent(content: any): any;
3+
}

lib/src/GraphHelper.js

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/GraphHelper.js.map

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

lib/src/GraphRequest.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export declare class GraphRequest {
1717
private urlJoin(urlSegments);
1818
buildFullUrl(): string;
1919
version(v: string): GraphRequest;
20-
select(properties: string | [string]): GraphRequest;
21-
expand(properties: string | [string]): GraphRequest;
22-
orderby(properties: string | [string]): GraphRequest;
20+
select(properties: string | string[]): GraphRequest;
21+
expand(properties: string | string[]): GraphRequest;
22+
orderby(properties: string | string[]): GraphRequest;
2323
filter(filterStr: string): GraphRequest;
2424
top(n: number): GraphRequest;
2525
skip(n: number): GraphRequest;

lib/src/GraphRequest.js

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/GraphRequest.js.map

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

samples/node/node-sample.js

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const client = MicrosoftGraph.init({
1515
}
1616
});
1717

18+
/*
19+
1820
// Get the name of the authenticated user with callbacks
1921
client
2022
.api('/me')
@@ -27,7 +29,8 @@ client
2729
console.log(res.displayName);
2830
});
2931
30-
/*
32+
33+
3134
// Get the name of the authenticated user with promises
3235
client
3336
.api('/me')
@@ -39,11 +42,14 @@ client
3942
console.log(err);
4043
});
4144
45+
*/
46+
4247
// Update the authenticated users birthday.
4348
client
4449
.api('/me')
50+
.header("content-type", "application/json")
4551
.update(
46-
{"birthday": "1908-12-22T00:00:00Z"},
52+
{ "birthday": "1908-12-22T00:00:00Z" },
4753
(err, res) => {
4854
if (err) {
4955
console.log(err);
@@ -54,6 +60,11 @@ client
5460
);
5561

5662

63+
64+
65+
/*
66+
67+
5768
// GET /users
5869
client
5970
.api('/users')
@@ -74,12 +85,13 @@ client
7485
.select("displayName")
7586
.get((err, res) => {
7687
if (err) {
77-
console.log(err)
88+
console.
89+
console.log("%c" + err, 'color: #bada55')
7890
return;
7991
}
80-
const topContacts = res.value.map((u) => {return u.displayName});
92+
const topContacts = res.value.map((u) => { return u.displayName });
8193
console.log("Your top contacts are", topContacts.join(", "));
82-
});
94+
});
8395
8496
8597
// Use promises instead of callbacks
@@ -92,7 +104,7 @@ client
92104
console.log(res.displayName);
93105
})
94106
.catch(console.error);
95-
107+
96108
// Find my top 5 contacts on the beta endpoint
97109
// .select() can be called multiple times
98110
client
@@ -115,7 +127,7 @@ const mail = {
115127
subject: "MicrosoftGraph JavaScript SDK Samples",
116128
toRecipients: [{
117129
emailAddress: {
118-
address: "example@example.com"
130+
address: "mmainer@microsoft.com"
119131
}
120132
}],
121133
body: {
@@ -127,7 +139,7 @@ const mail = {
127139
client
128140
.api('/users/me/sendMail')
129141
.post(
130-
{message: mail},
142+
{ message: mail },
131143
(err, res) => {
132144
if (err)
133145
console.log(err);
@@ -145,30 +157,33 @@ client
145157
return;
146158
}
147159
var upcomingEventNames = []
148-
for (var i=0; i<res.value.length; i++) {
160+
for (var i = 0; i < res.value.length; i++) {
149161
upcomingEventNames.push(res.value[i].subject);
150162
}
151163
console.log("My calendar events include", upcomingEventNames.join(", "))
152164
})
153165
166+
*/
154167

155168
// URL substitution example
156-
let userIds = [secrets.userId1,
157-
secrets.userId2];
158-
159-
for (let i=0; i<userIds.length; i++) {
160-
let fetchUser = client
161-
.api(`/me/people/${userIds[i]}`)
162-
.version('beta')
163-
.select('displayName')
164-
.get((err, res) => {
165-
if (err) {
166-
console.log(err)
167-
return;
168-
}
169-
console.log(res.displayName)
170-
})
171-
}
169+
// let userIds = [secrets.userId1,
170+
// secrets.userId2];
171+
172+
// for (let i = 0; i < userIds.length; i++) {
173+
// let fetchUser = client
174+
// .api(`/me/people/${userIds[i]}`)
175+
// .version('beta')
176+
// .select('displayName')
177+
// .get((err, res) => {
178+
// if (err) {
179+
// console.log(err)
180+
// return;
181+
// }
182+
// console.log(res.displayName)
183+
// })
184+
// }
185+
186+
/*
172187
173188
// Find my top 5 contacts
174189
client
@@ -201,8 +216,8 @@ client
201216
.api('/me')
202217
.select("displayName")
203218
.header('foo1', 'bar1')
204-
.headers({'foo2': 'bar2'}) //.headers() for object, .header() for 2 params
205-
.headers({'foo3': 'bar3', 'foo4': 'bar4'})
219+
.headers({ 'foo2': 'bar2' }) //.headers() for object, .header() for 2 params
220+
.headers({ 'foo3': 'bar3', 'foo4': 'bar4' })
206221
.get((err, res) => {
207222
if (err) {
208223
console.log(err)
@@ -221,6 +236,9 @@ client
221236
console.log(res)
222237
})
223238
239+
*/
240+
241+
/*
224242
225243
// Download a file from OneDrive
226244
let fs = require('fs'); // requires filesystem module

src/GraphHelper.ts

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
export class GraphHelper {
2-
3-
/*
4-
This conversion is required due to the following reasons:
5-
1. Body parameter of Request method of isomorphic-fetch only accepts Blob, ArrayBuffer, FormData, TypedArrays, string.
6-
2. Node.js platform does not suppport Blob, FormData. Javascript File object inherits from Blob so it is also
7-
not supported in node. Therefore content of type Blob, File, FormData will only come from browsers.
8-
3. Parallel to Javascript's arrayBuffer, node provides Buffer interface. Node's Buffer is able to send the arbitary
9-
binary data to the server successfully for both Browser and Node platform. Whereas sending binary data via
10-
ArrayBuffer or TypedArrays was only possible using Browser. To support both Node and Browser, `serializeContent`
11-
converts TypedArrays or ArrayBuffer to `Node Buffer`.
12-
4. If the data received is in JSON format, `serializeContent` converts the JSON to string.
13-
*/
14-
public static serializeContent(content: any): any {
15-
let className: string = content.constructor.name;
16-
17-
if (className === 'Buffer'
18-
|| className === 'Blob'
19-
|| className === 'File'
20-
|| className === 'FormData'
21-
|| typeof content === 'string') {
22-
return content;
23-
}
24-
25-
if (className === 'ArrayBuffer') {
26-
content = Buffer.from(content);
27-
} else if (className === 'Int8Array'
28-
|| className === 'Int16Array'
29-
|| className === 'Int32Array'
30-
|| className === 'Uint8Array'
31-
|| className === 'Uint16Array'
32-
|| className === 'Uint32Array'
33-
|| className === 'Uint8ClampedArray'
34-
|| className === 'Float32Array'
35-
|| className === 'Float64Array'
36-
|| className === 'DataView') {
37-
content = Buffer.from(content.buffer);
38-
} else {
39-
try {
40-
content = JSON.stringify(content);
41-
} catch (error) {
42-
console.log(error);
43-
throw new Error('Invalid JSON content');
44-
}
45-
}
46-
return content;
47-
}
1+
export class GraphHelper {
2+
3+
/*
4+
This conversion is required due to the following reasons:
5+
1. Body parameter of Request method of isomorphic-fetch only accepts Blob, ArrayBuffer, FormData, TypedArrays, string.
6+
2. Node.js platform does not suppport Blob, FormData. Javascript File object inherits from Blob so it is also
7+
not supported in node. Therefore content of type Blob, File, FormData will only come from browsers.
8+
3. Parallel to Javascript's arrayBuffer, node provides Buffer interface. Node's Buffer is able to send the arbitary
9+
binary data to the server successfully for both Browser and Node platform. Whereas sending binary data via
10+
ArrayBuffer or TypedArrays was only possible using Browser. To support both Node and Browser, `serializeContent`
11+
converts TypedArrays or ArrayBuffer to `Node Buffer`.
12+
4. If the data received is in JSON format, `serializeContent` converts the JSON to string.
13+
*/
14+
public static serializeContent(content: any): any {
15+
let className: string = content.constructor.name;
16+
17+
if (className === 'Buffer'
18+
|| className === 'Blob'
19+
|| className === 'File'
20+
|| className === 'FormData'
21+
|| typeof content === 'string') {
22+
return content;
23+
}
24+
25+
if (className === 'ArrayBuffer') {
26+
content = Buffer.from(content);
27+
} else if (className === 'Int8Array'
28+
|| className === 'Int16Array'
29+
|| className === 'Int32Array'
30+
|| className === 'Uint8Array'
31+
|| className === 'Uint16Array'
32+
|| className === 'Uint32Array'
33+
|| className === 'Uint8ClampedArray'
34+
|| className === 'Float32Array'
35+
|| className === 'Float64Array'
36+
|| className === 'DataView') {
37+
content = Buffer.from(content.buffer);
38+
} else {
39+
try {
40+
content = JSON.stringify(content);
41+
} catch (error) {
42+
console.log(error);
43+
throw new Error('Invalid JSON content');
44+
}
45+
}
46+
return content;
47+
}
4848
}

0 commit comments

Comments
 (0)