Skip to content

Commit

Permalink
#174, #178 and #181
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamsi committed May 19, 2017
1 parent c3499fe commit e748623
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 37 deletions.
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ews-javascript-api",
"version": "0.9.0-dev.1",
"version": "0.9.0-dev.6",
"description": "EWS Managed api in JavaScript",
"main": "js/ExchangeWebService.js",
"scripts": {
Expand All @@ -26,14 +26,12 @@
"homepage": "https://github.com/gautamsi/ews-javascript-api",
"dependencies": {
"@types/moment-timezone": "^0.2.34",
"@types/node": "^6.0.46",
"@types/node-uuid": "0.0.28",
"@types/q": "0.0.32",
"@types/node": "^7.0.18",
"@types/uuid": "^2.0.29",
"base64-js": "^1.2.0",
"moment": "^2.17.1",
"moment-timezone": "^0.5.11",
"node-uuid": "^1.4.7",
"reflect-metadata": "^0.1.8",
"uuid": "^3.0.1",
"xmldom": "^0.1.22"
},
"optionalDependencies": {
Expand All @@ -43,7 +41,7 @@
"devDependencies": {
"@types/chai": "^3.4.34",
"@types/chai-as-promised": "0.0.29",
"@types/gulp": "^3.8.32",
"@types/gulp": "^4.0.3",
"@types/mocha": "^2.2.32",
"almond": "^0.3.3",
"chai": "^3.5.0",
Expand Down
2 changes: 1 addition & 1 deletion src/js/Core/Requests/HangingServiceRequestBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class HangingServiceRequestBase extends ServiceRequestBase {
}
}).then((xhrResponse: any) => { //<any> used for progress delegate, not in standard promise
//console.log(xhrResponse);
successDelegate(void 0);
//successDelegate(void 0);
}, (resperr: XMLHttpRequest) => {
if (resperr.status && resperr.getAllResponseHeaders) {
EwsLogging.Log("Error in calling service, error code: " + resperr.status + "\r\n " + resperr.getAllResponseHeaders());
Expand Down
2 changes: 1 addition & 1 deletion src/js/Core/ServiceObjects/Folders/Folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export class Folder extends ServiceObject {
}

if (viewOrSearchFilter instanceof FolderView) {
return this.Service.FindFolders(this.Id, view);
return this.Service.FindFolders(this.Id, viewOrSearchFilter);
}
else if (viewOrSearchFilter instanceof SearchFilter) {
if (typeof view === 'undefined' || !(view instanceof FolderView)) {
Expand Down
2 changes: 1 addition & 1 deletion src/js/ExchangeWebService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ export { SortDirection } from "./Enumerations/SortDirection";
export { StandardUser } from "./Enumerations/StandardUser";
export { StartTimeZonePropertyDefinition } from "./PropertyDefinitions/StartTimeZonePropertyDefinition";
export { StreamingSubscription } from "./Notifications/StreamingSubscription";
export { StreamingSubscriptionConnection } from "./Notifications/StreamingSubscriptionConnection";
export { StreamingSubscriptionConnection, ResponseHeaderDelegate } from "./Notifications/StreamingSubscriptionConnection";
export { StringList } from "./ComplexProperties/StringList";
export { StringPropertyDefinition } from "./PropertyDefinitions/StringPropertyDefinition";
export { Strings } from "./Strings";
Expand Down
2 changes: 1 addition & 1 deletion src/js/ExtensionMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export class xml2JsObject {
else
obj[attr.name] = attr.value;
else if (attr.localName === 'xmlns') {
if (xmlNode.namespaceURI !== attr.value && typeof obj[TYPE_STR] === 'undefiend') {
if (xmlNode.namespaceURI !== attr.value && typeof obj[TYPE_STR] === 'undefined') {
obj[TYPE_STR] = attr.value;
}
nonGenericAttributeCount--;
Expand Down
55 changes: 37 additions & 18 deletions src/js/Guid.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,49 @@
import {StringHelper} from "./ExtensionMethods";
import * as uuid from 'node-uuid';
import { StringHelper } from "./ExtensionMethods";
import * as uuid from 'uuid';
/** Guid proxy class */
export class Guid {
static Empty: Guid = new Guid('00000000-0000-0000-0000-000000000000');
private guid: string = null;
constructor(str: string) {
if (StringHelper.IsNullOrEmpty(str) || str === null) {
throw new TypeError("Guid.ctor - invalid input");
}
str = str.replace("-", "").replace("{", "").replace("}", "").toLowerCase();
var parsed = uuid.parse(str);
if (parsed) {
this.guid = uuid.unparse(parsed);
// if (this.guid.replace("-", "") !== str.toString()) {
// throw new TypeError("Guid.ctor - malformed string")
// }
static Empty: Guid = new Guid();
private guid: string = '00000000-0000-0000-0000-000000000000';
//private regx = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
//private regx_withoutdash = /^[0-9a-f]{8}[0-9a-f]{4}[1-5][0-9a-f]{3}[89ab][0-9a-f]{3}[0-9a-f]{12}$/i;

constructor();
constructor(str: string);
constructor(str?: string) {
let regx = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
if (arguments.length > 0) {
if (StringHelper.IsNullOrEmpty(str) || str === null) {
throw new TypeError("Guid.ctor - invalid input");
}
//str = str.replace("-", "").replace("{", "").replace("}", "").toLowerCase();
str = str.replace("{", "").replace("}", "").toLowerCase();
if (regx.test(str)) {
this.guid = str;
} else {
throw new TypeError("Guid.ctor - invalid input");
}
}
}
ToString() {
return this.guid;
}
toString(){
return this.guid;
}

static NewGuid(): Guid {
return new Guid(uuid.v4());
}
static Parse(str: string): Guid {
var parsed = uuid.parse(str);
if (parsed) {
return new Guid(str);
return new Guid(str);
}

static TryParse(str, _parsed_output: { guid: Guid } = { guid: null }) {
try {
_parsed_output.guid = new Guid(str);
return true;
} catch (error) {
return false;
}
}
}
30 changes: 30 additions & 0 deletions src/js/Notifications/StreamingSubscriptionConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export class StreamingSubscriptionConnection {
*/
OnDisconnect: SubscriptionErrorDelegate[] = [];

/**
* Occurs when a streaming subscription connection gets headers from the server.
*/
OnResponseHeader: ResponseHeaderDelegate[] = [];

/**
* Getting the current subscriptions in this connection.
*/
Expand Down Expand Up @@ -269,6 +274,20 @@ export class StreamingSubscriptionConnection {
}
}

/**
* Internal helper method called when the request receives headers.
*
* @param {any} headers The headerf from server.
*/
private InternalOnResponseHeader(headers: any): void {
if (this.OnResponseHeader && ArrayHelper.isArray(this.OnResponseHeader)) {
try {
this.OnResponseHeader.forEach((onHeader) => { onHeader(headers) });
}
catch (e) { }
}
}

/**
* Issues the general failure.
*
Expand Down Expand Up @@ -399,6 +418,7 @@ export class StreamingSubscriptionConnection {
this.connectionTimeout);

this.currentHangingRequest.OnDisconnect.push(this.OnRequestDisconnect.bind(this)); //todo: fix if needed multiple instance new HangingServiceRequestBase.HangingRequestDisconnectHandler(this.OnRequestDisconnect)
this.currentHangingRequest.OnResponseHeader = this.InternalOnResponseHeader.bind(this); //todo: fix if needed multiple instance new HangingServiceRequestBase.HangingRequestDisconnectHandler(this.OnRequestDisconnect)

return this.currentHangingRequest.InternalExecute();
//}
Expand Down Expand Up @@ -469,4 +489,14 @@ export interface NotificationEventDelegate {
*/
export interface SubscriptionErrorDelegate {
(sender: any, args: SubscriptionErrorEventArgs): void;
}

/**
* Represents a delegate that is invoked when an error occurs within a streaming subscription connection.
*
* @param {any} sender The StreamingSubscriptionConnection instance within which the error occurred.
* @param {SubscriptionErrorEventArgs} args The event data.
*/
export interface ResponseHeaderDelegate {
(header: any): void;
}
14 changes: 7 additions & 7 deletions src/js/Promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,6 @@ export interface PromiseConstructor {

export var Promise: PromiseConstructor;

try {
var promise = require('bluebird');
Promise = promise;
} catch (e) {
Promise = <any>PromiseType;
}

class PromiseType<T> {
constructor() {
throw new NotSupportedException("Promise implementation missing.\nPlease use ConfigurePromise function to assign Promise Object\n" +
Expand All @@ -315,6 +308,13 @@ class PromiseType<T> {
}
}

try {
var promise = require('bluebird');
Promise = promise;
} catch (e) {
Promise = <any>PromiseType;
}

export function ConfigurePromise(promise: PromiseConstructor) {
Promise = promise;
}
2 changes: 1 addition & 1 deletion src/js/PropertyDefinitions/ExtendedPropertyDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class ExtendedPropertyDefinition extends PropertyDefinitionBase {
(extPropDef1.Tag === extPropDef2.Tag) &&
(extPropDef1.Name === extPropDef2.Name) &&
(extPropDef1.PropertySet === extPropDef2.PropertySet) &&
(extPropDef1.propertySetId === extPropDef2.propertySetId));
(String(extPropDef1.propertySetId) === String(extPropDef2.propertySetId)));
}

/**
Expand Down

0 comments on commit e748623

Please sign in to comment.