Skip to content

Commit 31a0817

Browse files
committed
Synchronization operations complete, SyncFolderHierarchy and SyncFolderItems works!!. closes gautamsi#42
1 parent ea21300 commit 31a0817

20 files changed

+20223
-17099
lines changed

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ Code sample from [EWS Managed API 2.1.](https://msdn.microsoft.com/en-us/library
2828
Api document generated using TypeDoc and is hosted at [ews-javascript-api.github.io/api](http://ews-javascript-api.github.io/api).
2929
Check [Wiki](https://github.com/gautamsi/ews-javascript-api/wiki) for more details
3030

31+
# Whats new v0.3.0 (including 0.2.8)
32+
33+
* new: ***Mailbox synchronization*** now works, `SyncFolderItems` and `SyncFolderHierarchy` ExchangeService now availbale [see MSDN for example](https://msdn.microsoft.com/en-us/library/office/dn440952(v=exchg.150).aspx)
34+
* new: ***Pull Subscription*** should now work [use MSDN example](https://msdn.microsoft.com/en-us/library/office/dn458790(v=exchg.150).aspx)
35+
* new: `SetTeamMailbox` and `UnpinTeamMailbox` ExchangeService methods now availbale. (`SetTeamMailbox` does not work with Office 365, Access Denied error, on-prem test is pending) See official MSDN reference for detail [ExchangeService.UnpinTeamMailbox method](https://msdn.microsoft.com/en-us/library/office/microsoft.exchange.webservices.data.exchangeservice.unpinteammailbox(v=exchg.80).aspx)
36+
* new: `GetRooms` and `GetRoomLists` ExchangeService methods now availbale. See official MSDN reference for detail [ExchangeService.GetRooms method](https://msdn.microsoft.com/en-us/library/office/microsoft.exchange.webservices.data.exchangeservice.getrooms(v=exchg.80).aspx) and [ExchangeService.GetRoomLists method](https://msdn.microsoft.com/en-us/library/office/microsoft.exchange.webservices.data.exchangeservice.getroomlists(v=exchg.80).aspx)
37+
* new: `ConvertId` and `ConvertIds` ExchangeService methods now availbale, see MSDN detail at [EWS Identifiers in Exchange](https://msdn.microsoft.com/EN-US/library/office/dn605828(v=exchg.150).aspx)
38+
* new: `GetClientAccessToken` ExchangeService method now availbale, used with "Mail App" management, App management (#41) coming later
39+
* fix: `ImpersonatedUserId` bug #34
40+
3141
# Whats new v0.2.7 (including 0.2.5 and 0.2.6)
3242

3343
* new: Streaming Notification code updated, see issue #24 for example. More details at [How to: Stream notifications about mailbox events by using EWS in Exchange](https://msdn.microsoft.com/en-us/library/office/dn458792(v=exchg.150).aspx)
@@ -155,27 +165,37 @@ Review Core/ExchangeService methods in api document, Any method not marked priva
155165
AutodiscoverUrl
156166
BindToGroupItems
157167
BindToItems
168+
ConvertId
169+
ConvertIds
158170
CopyItems
159171
CreateItems
160172
DeleteItems
161173
ExpandGroup
162174
FindAppointments
163175
FindFolders
164176
FindItems
165-
GetAttachments *new
177+
GetAttachments
178+
GetClientAccessToken
166179
GetPasswordExpirationDate
180+
GetRoomLists
181+
GetRooms
167182
GetUserAvailability
183+
GetUserOofSettings
184+
GetUserOofSettings
168185
LoadPropertiesForItems
169186
MarkAsJunk
170187
MoveItems
171188
ResolveName
172-
UpdateItems
173-
GetUserOofSettings
189+
SetTeamMailbox
190+
SetUserOofSettings
174191
SetUserOofSettings
192+
SubscribeToPullNotifications
175193
SubscribeToStreamingNotifications
176194
SubscribeToStreamingNotificationsOnAllFolders
177-
GetUserOofSettings
178-
SetUserOofSettings
195+
SyncFolderHierarchy
196+
SyncFolderItems
197+
UnpinTeamMailbox
198+
UpdateItems
179199

180200

181201

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ews-javascript-api",
3-
"version": "0.2.8",
3+
"version": "0.3.0",
44
"description": "EWS Managed api in JavaScript",
55
"main": "js/ExchangeWebService.js",
66
"scripts": {

src/js/Core/ExchangeService.ts

Lines changed: 160 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {AvailabilityData} from "../Enumerations/AvailabilityData";
1414
import {AvailabilityOptions} from "../Misc/Availability/AvailabilityOptions";
1515
import {BodyType} from "../Enumerations/BodyType";
1616
import {CalendarView} from "../Search/CalendarView";
17+
import {ChangeCollection} from "../Sync/ChangeCollection";
1718
import {ClientAccessTokenRequest} from "../ComplexProperties/ClientAccessTokenRequest";
1819
import {ClientAccessTokenType} from "../Enumerations/ClientAccessTokenType";
1920
import {ConflictResolutionMode} from "../Enumerations/ConflictResolutionMode";
@@ -49,6 +50,7 @@ import {FindItemRequest} from "./Requests/FindItemRequest";
4950
import {FindItemResponse} from "./Responses/FindItemResponse";
5051
import {FindItemsResults} from "../Search/FindItemsResults";
5152
import {Folder} from "./ServiceObjects/Folders/Folder";
53+
import {FolderChange} from "../Sync/FolderChange";
5254
import {FolderId} from "../ComplexProperties/FolderId";
5355
import {FolderView} from "../Search/FolderView";
5456
import {GetAttachmentRequest} from "./Requests/GetAttachmentRequest";
@@ -77,6 +79,7 @@ import {IFileAttachmentContentHandler} from "../Interfaces/IFileAttachmentConten
7779
import {ImpersonatedUserId} from "../Misc/ImpersonatedUserId";
7880
import {IPromise, IXHROptions} from "../Interfaces";
7981
import {Item} from "./ServiceObjects/Items/Item";
82+
import {ItemChange} from "../Sync/ItemChange";
8083
import {ItemId} from "../ComplexProperties/ItemId";
8184
import {KeyValuePair} from "../AltDictionary";
8285
import {Mailbox} from "../ComplexProperties/Mailbox";
@@ -124,6 +127,9 @@ import {Strings} from "../Strings";
124127
import {SubscribeToPullNotificationsRequest} from "./Requests/SubscribeToPullNotificationsRequest";
125128
import {SubscribeToPushNotificationsRequest} from "./Requests/SubscribeToPushNotificationsRequest";
126129
import {SubscribeToStreamingNotificationsRequest} from "./Requests/SubscribeToStreamingNotificationsRequest";
130+
import {SyncFolderHierarchyRequest} from "./Requests/SyncFolderHierarchyRequest";
131+
import {SyncFolderItemsRequest} from "./Requests/SyncFolderItemsRequest";
132+
import {SyncFolderItemsScope} from "../Enumerations/SyncFolderItemsScope";
127133
import {TeamMailboxLifecycleState} from "../Enumerations/TeamMailboxLifecycleState";
128134
import {TimeWindow} from "../Misc/Availability/TimeWindow";
129135
import {TraceFlags} from "../Enumerations/TraceFlags";
@@ -2061,17 +2067,165 @@ export class ExchangeService extends ExchangeServiceBase {
20612067

20622068
// BeginSyncFolderItems(callback: Function /*System.AsyncCallback*/, state: any, syncFolderId: FolderId, propertySet: PropertySet, ignoredItemIds: any[] /*System.Collections.Generic.IEnumerable<T>*/, maxChangesReturned: number, syncScope: SyncFolderItemsScope, syncState: string): Function /*System.IAsyncResult*/ { throw new Error("ExchangeService.ts - BeginSyncFolderItems : Not implemented."); }
20632069
// BeginSyncFolderItems(callback: Function /*System.AsyncCallback*/, state: any, syncFolderId: FolderId, propertySet: PropertySet, ignoredItemIds: any[] /*System.Collections.Generic.IEnumerable<T>*/, maxChangesReturned: number, numberOfDays: number, syncScope: SyncFolderItemsScope, syncState: string): Function /*System.IAsyncResult*/ { throw new Error("ExchangeService.ts - BeginSyncFolderItems : Not implemented."); }
2064-
//BuildSyncFolderItemsRequest(syncFolderId: FolderId, propertySet: PropertySet, ignoredItemIds: any[] /*System.Collections.Generic.IEnumerable<T>*/, maxChangesReturned: number, syncScope: SyncFolderItemsScope, syncState: string): SyncFolderItemsRequest { throw new Error("ExchangeService.ts - BuildSyncFolderItemsRequest : Not implemented."); }
2070+
2071+
/**
2072+
* Builds a request to synchronize the items of a specific folder.
2073+
*
2074+
* @param {FolderId} syncFolderId The Id of the folder containing the items to synchronize with.
2075+
* @param {PropertySet} propertySet The set of properties to retrieve for synchronized items.
2076+
* @param {ItemId[]} ignoredItemIds The optional list of item Ids that should be ignored.
2077+
* @param {number} maxChangesReturned The maximum number of changes that should be returned.
2078+
* @param {number} numberOfDays Limit the changes returned to this many days ago; 0 means no limit.
2079+
* @param {SyncFolderItemsScope} syncScope The sync scope identifying items to include in the ChangeCollection.
2080+
* @param {string} syncState The optional sync state representing the point in time when to start the synchronization.
2081+
* @return {SyncFolderItemsRequest} A request to synchronize the items of a specific folder.
2082+
*/
2083+
private BuildSyncFolderItemsRequest(syncFolderId: FolderId, propertySet: PropertySet, ignoredItemIds: ItemId[], maxChangesReturned: number, numberOfDays: number, syncScope: SyncFolderItemsScope, syncState: string): SyncFolderItemsRequest {
2084+
EwsUtilities.ValidateParam(syncFolderId, "syncFolderId");
2085+
EwsUtilities.ValidateParam(propertySet, "propertySet");
2086+
2087+
let request: SyncFolderItemsRequest = new SyncFolderItemsRequest(this);
2088+
2089+
request.SyncFolderId = syncFolderId;
2090+
request.PropertySet = propertySet;
2091+
if (ignoredItemIds != null) {
2092+
request.IgnoredItemIds.AddRange(ignoredItemIds);
2093+
}
2094+
request.MaxChangesReturned = maxChangesReturned;
2095+
request.NumberOfDays = numberOfDays;
2096+
request.SyncScope = syncScope;
2097+
request.SyncState = syncState;
2098+
2099+
return request;
2100+
}
20652101
//EndSyncFolderItems(asyncResult: Function /*System.IAsyncResult*/): ChangeCollection<ItemChange> { throw new Error("ExchangeService.ts - EndSyncFolderItems : Not implemented."); }
2066-
//SyncFolderItems(syncFolderId: FolderId, propertySet: PropertySet, ignoredItemIds: any[] /*System.Collections.Generic.IEnumerable<T>*/, maxChangesReturned: number, syncScope: SyncFolderItemsScope, syncState: string): ChangeCollection<ItemChange> { throw new Error("ExchangeService.ts - SyncFolderItems : Not implemented."); }
2067-
//SyncFolderItems(syncFolderId: FolderId, propertySet: PropertySet, ignoredItemIds: any[] /*System.Collections.Generic.IEnumerable<T>*/, maxChangesReturned: number, numberOfDays: number, syncScope: SyncFolderItemsScope, syncState: string): ChangeCollection<ItemChange> { throw new Error("ExchangeService.ts - SyncFolderItems : Not implemented."); }
2102+
2103+
/**
2104+
* Synchronizes the items of a specific folder. Calling this method results in a call to EWS.
2105+
*
2106+
* @param {FolderId} syncFolderId The Id of the folder containing the items to synchronize with.
2107+
* @param {PropertySet} propertySet The set of properties to retrieve for synchronized items.
2108+
* @param {ItemId[]} ignoredItemIds The optional list of item Ids that should be ignored.
2109+
* @param {number} maxChangesReturned The maximum number of changes that should be returned.
2110+
* @param {number} numberOfDays Limit the changes returned to this many days ago; 0 means no limit.
2111+
* @param {SyncFolderItemsScope} syncScope The sync scope identifying items to include in the ChangeCollection.
2112+
* @param {string} syncState The optional sync state representing the point in time when to start the synchronization.
2113+
* @return {IPromise<ChangeCollection<ItemChange>>} A ChangeCollection containing a list of changes that occurred in the specified folder :Promise.
2114+
*/
2115+
SyncFolderItems(syncFolderId: FolderId, propertySet: PropertySet, ignoredItemIds: ItemId[], maxChangesReturned: number, syncScope: SyncFolderItemsScope, syncState: string): IPromise<ChangeCollection<ItemChange>>;
2116+
/**
2117+
* Synchronizes the items of a specific folder. Calling this method results in a call to EWS.
2118+
*
2119+
* @param {FolderId} syncFolderId The Id of the folder containing the items to synchronize with.
2120+
* @param {PropertySet} propertySet The set of properties to retrieve for synchronized items.
2121+
* @param {ItemId[]} ignoredItemIds The optional list of item Ids that should be ignored.
2122+
* @param {number} maxChangesReturned The maximum number of changes that should be returned.
2123+
* @param {number} numberOfDays Limit the changes returned to this many days ago; 0 means no limit.
2124+
* @param {SyncFolderItemsScope} syncScope The sync scope identifying items to include in the ChangeCollection.
2125+
* @param {string} syncState The optional sync state representing the point in time when to start the synchronization.
2126+
* @return {IPromise<ChangeCollection<ItemChange>>} A ChangeCollection containing a list of changes that occurred in the specified folder :Promise.
2127+
*/
2128+
SyncFolderItems(syncFolderId: FolderId, propertySet: PropertySet, ignoredItemIds: ItemId[], maxChangesReturned: number, numberOfDays: number, syncScope: SyncFolderItemsScope, syncState: string): IPromise<ChangeCollection<ItemChange>>;
2129+
SyncFolderItems(
2130+
syncFolderId: FolderId,
2131+
propertySet: PropertySet,
2132+
ignoredItemIds: ItemId[],
2133+
maxChangesReturned: number,
2134+
numberOfDaysOrSyncScope: number | SyncFolderItemsScope,
2135+
syncScopeOrSyncState: SyncFolderItemsScope | string,
2136+
syncState: string = null): IPromise<ChangeCollection<ItemChange>> {
2137+
2138+
let numberOfDays: number = 0;
2139+
let syncScope: SyncFolderItemsScope;
2140+
2141+
if (arguments.length === 6) {
2142+
syncState = <string>syncScopeOrSyncState;
2143+
syncScope = numberOfDaysOrSyncScope;
2144+
}
2145+
else {
2146+
numberOfDays = numberOfDaysOrSyncScope;
2147+
syncScope = <SyncFolderItemsScope>syncScopeOrSyncState;
2148+
}
2149+
2150+
return this.BuildSyncFolderItemsRequest(
2151+
syncFolderId,
2152+
propertySet,
2153+
ignoredItemIds,
2154+
maxChangesReturned,
2155+
numberOfDays,
2156+
syncScope,
2157+
syncState).Execute().then((responses) => {
2158+
return responses.__thisIndexer(0).Changes;
2159+
});
2160+
}
20682161

20692162
// BeginSyncFolderHierarchy(callback: Function /*System.AsyncCallback*/, state: any, propertySet: PropertySet, syncState: string): Function /*System.IAsyncResult*/ { throw new Error("ExchangeService.ts - BeginSyncFolderHierarchy : Not implemented."); }
20702163
// //BeginSyncFolderHierarchy(callback: Function /*System.AsyncCallback*/, state: any, syncFolderId: FolderId, propertySet: PropertySet, syncState: string): Function /*System.IAsyncResult*/ { throw new Error("ExchangeService.ts - BeginSyncFolderHierarchy : Not implemented."); }
2071-
//BuildSyncFolderHierarchyRequest(syncFolderId: FolderId, propertySet: PropertySet, syncState: string): SyncFolderHierarchyRequest { throw new Error("ExchangeService.ts - BuildSyncFolderHierarchyRequest : Not implemented."); }
2164+
2165+
/**
2166+
* Builds a request to synchronize the specified folder hierarchy of the mailbox this Service is connected to.
2167+
*
2168+
* @param {FolderId} syncFolderId The Id of the folder containing the items to synchronize with. A null value indicates the root folder of the mailbox.
2169+
* @param {PropertySet} propertySet The set of properties to retrieve for synchronized items.
2170+
* @param {string} syncState The optional sync state representing the point in time when to start the synchronization.
2171+
* @return {SyncFolderHierarchyRequest} A request to synchronize the specified folder hierarchy of the mailbox this Service is connected to.
2172+
*/
2173+
private BuildSyncFolderHierarchyRequest(syncFolderId: FolderId, propertySet: PropertySet, syncState: string): SyncFolderHierarchyRequest {
2174+
EwsUtilities.ValidateParamAllowNull(syncFolderId, "syncFolderId"); // Null syncFolderId is allowed
2175+
EwsUtilities.ValidateParam(propertySet, "propertySet");
2176+
2177+
let request: SyncFolderHierarchyRequest = new SyncFolderHierarchyRequest(this);
2178+
2179+
request.PropertySet = propertySet;
2180+
request.SyncFolderId = syncFolderId;
2181+
request.SyncState = syncState;
2182+
2183+
return request;
2184+
}
2185+
20722186
//EndSyncFolderHierarchy(asyncResult: Function /*System.IAsyncResult*/): ChangeCollection<FolderChange> { throw new Error("ExchangeService.ts - EndSyncFolderHierarchy : Not implemented."); }
2073-
////SyncFolderHierarchy(syncFolderId: FolderId, propertySet: PropertySet, syncState: string): ChangeCollection<FolderChange> { throw new Error("ExchangeService.ts - SyncFolderHierarchy : Not implemented."); }
2074-
//SyncFolderHierarchy(propertySet: PropertySet, syncState: string): ChangeCollection<FolderChange> { throw new Error("ExchangeService.ts - SyncFolderHierarchy : Not implemented."); }
2187+
2188+
/**
2189+
* Synchronizes the sub-folders of a specific folder. Calling this method results in a call to EWS.
2190+
*
2191+
* @param {FolderId} syncFolderId The Id of the folder containing the items to synchronize with. A null value indicates the root folder of the mailbox.
2192+
* @param {PropertySet} propertySet The set of properties to retrieve for synchronized items.
2193+
* @param {string} syncState The optional sync state representing the point in time when to start the synchronization.
2194+
* @return {IPromise<ChangeCollection<FolderChange>>} A ChangeCollection containing a list of changes that occurred in the specified folder :Promise.
2195+
*/
2196+
SyncFolderHierarchy(syncFolderId: FolderId, propertySet: PropertySet, syncState: string): IPromise<ChangeCollection<FolderChange>>;
2197+
/**
2198+
* Synchronizes the entire folder hierarchy of the mailbox this Service is connected to. Calling this method results in a call to EWS.
2199+
*
2200+
* @param {PropertySet} propertySet The set of properties to retrieve for synchronized items.
2201+
* @param {string} syncState The optional sync state representing the point in time when to start the synchronization.
2202+
* @return {IPromise<ChangeCollection<FolderChange>>} A ChangeCollection containing a list of changes that occurred in the specified folder :Promise.
2203+
*/
2204+
SyncFolderHierarchy(propertySet: PropertySet, syncState: string): IPromise<ChangeCollection<FolderChange>>;
2205+
SyncFolderHierarchy(
2206+
syncFolderIdOrPropertySet: FolderId | PropertySet,
2207+
propertySetOrSyncState: PropertySet | string,
2208+
syncState: string = null): IPromise<ChangeCollection<FolderChange>> {
2209+
2210+
let syncFolderId: FolderId = null;
2211+
let propertySet: PropertySet;
2212+
2213+
if (arguments.length === 2) {
2214+
propertySet = <PropertySet>syncFolderIdOrPropertySet;
2215+
syncState = <string>propertySetOrSyncState;
2216+
}
2217+
else {
2218+
syncFolderId = <FolderId>syncFolderIdOrPropertySet;
2219+
propertySet = <PropertySet>propertySetOrSyncState;
2220+
}
2221+
2222+
return this.BuildSyncFolderHierarchyRequest(
2223+
syncFolderId,
2224+
propertySet,
2225+
syncState).Execute().then((responses) => {
2226+
return responses.__thisIndexer(0).Changes;
2227+
});
2228+
}
20752229
/* #endregion Synchronization operations */
20762230

20772231

0 commit comments

Comments
 (0)