Skip to content
Merged
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: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Bug Fixes

### 1.2.0
Updates

* Two output js files, one with polyfills for Fetch-API and ES6-Promises ([lib/graph-js-sdk-web.js](./lib/graph-js-sdk-web.js)) and one without ([lib/graph-js-sdk-core.js](./lib/graph-js-sdk-core.js))
[Refer [README.md](https://github.com/microsoftgraph/msgraph-sdk-javascript#browser) for usage]
* Enum for ResponseType, which lists down the available ResponseType options in autocomplete
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ client
````

### $search
Pass a search string to `.search()` for searching message and person collections.
````js
Pass a search query string to `.search()` for searching in collections. Calling search multiple times will override previous search query. Refer graph [documentation](https://developer.microsoft.com/en-us/graph/docs/concepts/query_parameters#search-parameter) for more.
```js
client
.api("/users")
.search("Irene McGowen")
.api("/me/messages")
.search("from:admin")
.get((err, res) => {
console.log(res)
})
````
console.log(res);
});
```

## Other API methods

Expand Down
3 changes: 2 additions & 1 deletion lib/graph-js-sdk-core.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/graph-js-sdk-web.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/src/GraphRequest.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,6 @@ export declare class GraphRequest {
[key: string]: string | number;
}): GraphRequest;
private createQueryString;
private parseDocumentResponse;
private convertResponseType;
}
862 changes: 451 additions & 411 deletions lib/src/GraphRequest.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/src/GraphRequest.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/src/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export declare const PACKAGE_VERSION = "1.3.0";
* @callback - The anonymous callback function
*/
export interface AuthProviderCallback {
(error: any, accessToken: string): void;
(error: any, accessToken: string | null): void;
}
/**
* @interface {@link https://github.com/bitinn/node-fetch/#options}
Expand Down
58 changes: 51 additions & 7 deletions src/GraphRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ export class GraphRequest {
return this;
}

search(searchStr: string): GraphRequest {
this.urlComponents.oDataQueryParams["$search"] = `"${searchStr}"`;
return this;
}

search(searchStr: string): GraphRequest {
this.urlComponents.oDataQueryParams["$search"] = searchStr;
Expand Down Expand Up @@ -448,21 +452,39 @@ export class GraphRequest {
return "";
}

private parseDocumentResponse(response, type): Promise<any> {
if (typeof DOMParser !== "undefined") {
return new Promise((resolve, reject) => {
response.text().then((xmlString) => {
try {
let parser = new DOMParser(),
xmlDoc = parser.parseFromString(xmlString, type);
resolve(xmlDoc);
} catch (error) {
reject(error);
}
});
});
} else {
return Promise.resolve(response.body);
}
}

private convertResponseType(response: Response): Promise<any> {
let responseValue: any;
if (!this._responseType) {
this._responseType = '';
let self = this,
responseValue: any;
if (!self._responseType) {
self._responseType = '';
}
switch (this._responseType.toLowerCase()) {
switch (self._responseType.toLowerCase()) {
case ResponseType.ARRAYBUFFER:
responseValue = response.arrayBuffer();
break;
case ResponseType.BLOB:
responseValue = response.blob();
break;
case ResponseType.DOCUMENT:
// XMLHTTPRequest only :(
responseValue = response.json();
responseValue = self.parseDocumentResponse(response, "text/xml");
break;
case ResponseType.JSON:
responseValue = response.json();
Expand All @@ -474,7 +496,29 @@ export class GraphRequest {
responseValue = response.text();
break;
default:
responseValue = response.json();
let contentType = response.headers.get("Content-type");
if (contentType !== null) {
let mimeType = contentType.split(";")[0],
documentContentTypes = ["text/html", "text/xml", "application/xml", "application/xhtml+xml"];
if (documentContentTypes.includes(mimeType)) {
responseValue = self.parseDocumentResponse(response, mimeType);
} else {
responseValue = response.json();
}
} else {
/**
* RFC specification {@link https://tools.ietf.org/html/rfc7231#section-3.1.1.5} says:
* A sender that generates a message containing a payload body SHOULD
* generate a Content-Type header field in that message unless the
* intended media type of the enclosed representation is unknown to the
* sender. If a Content-Type header field is not present, the recipient
* MAY either assume a media type of "application/octet-stream"
* ([RFC2046], Section 4.5.1) or examine the data to determine its type.
*
* So assuming it as a stream type so returning the body.
*/
responseValue = Promise.resolve(response.body);
}
break;
}
return responseValue;
Expand Down
2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ oDataQueryNames = oDataQueryNames.concat(oDataQueryNames.map((s) => "$" + s));
* @callback - The anonymous callback function
*/
export interface AuthProviderCallback {
(error: any, accessToken: string): void
(error: any, accessToken: string | null): void
}

/**
Expand Down