forked from Zimbra/zm-api-js-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.ts
458 lines (434 loc) · 15.9 KB
/
schema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
import { makeExecutableSchema } from 'graphql-tools';
import mapValues from 'lodash/mapValues';
import {
AddMsgInput,
CalendarItemInput,
ClientInfoInput,
CounterAppointmentInput,
CreateContactInput,
CreateIdentityInput,
CreateMountpointInput,
CreateTagInput,
CustomMetadataInput,
DeleteAppointmentInput,
DeleteIdentityInput,
EnableTwoFactorAuthInput,
ExternalAccountAddInput,
ExternalAccountImportInput,
ExternalAccountTestInput,
FilterInput,
FolderActionChangeColorInput,
FolderActionCheckCalendarInput,
ForwardAppointmentInput,
ForwardAppointmentInviteInput,
GetRightsInput,
GrantRightsInput,
InviteReplyInput,
ModifyContactInput,
ModifyIdentityInput,
NameIdInput,
PreferencesInput,
PropertiesInput,
RevokeRightsInput,
SearchFolderInput,
SendMessageInput,
ShareNotificationInput,
SignatureInput,
WhiteBlackListInput,
ZimletPreferenceInput
} from './generated-schema-types';
import { ZimbraSchemaOptions } from './types';
import { ZimbraBatchClient } from '../batch-client';
import { coerceBooleanToString } from '../utils/coerce-boolean';
import { GraphQLSchema } from 'graphql';
import {
ActionOptions,
ActionType,
ApplyFilterRulesOptions,
AppointmentOptions,
AutoCompleteGALOptions,
AutoCompleteOptions,
ChangePasswordOptions,
CreateFolderOptions,
CreateSearchFolderOptions,
ExternalAccountDeleteInput,
ExternalAccountModifyInput,
FreeBusyOptions,
GetContactFrequencyOptions,
GetContactOptions,
GetConversationOptions,
GetCustomMetadataOptions,
GetFolderOptions,
GetMailboxMetadataOptions,
GetMessageOptions,
GetSMimePublicCertsOptions,
LoginOptions,
ModifyProfileImageOptions,
RecoverAccountOptions,
RelatedContactsOptions,
ResetPasswordOptions,
SaveDocumentInput,
SearchOptions,
SetRecoveryAccountOptions,
ShareInfoOptions,
WorkingHoursOptions
} from '../batch-client/types';
import schema from './schema.graphql';
import { SessionHandler } from './session-handler';
export function createZimbraSchema(
options: ZimbraSchemaOptions
): { client: ZimbraBatchClient; schema: GraphQLSchema } {
const { cache, getApolloClient, ...clientOptions } = options;
const sessionHandler = cache ? new SessionHandler({ cache }) : undefined;
const client = new ZimbraBatchClient({
...clientOptions,
sessionHandler
});
const localStoreClient = options.localStoreClient;
const executableSchema = makeExecutableSchema({
typeDefs: schema,
resolvers: {
Query: {
accountInfo: client.accountInfo,
autoComplete: (_, variables) =>
client.autoComplete(variables as AutoCompleteOptions),
autoCompleteGAL: (_, variables) =>
client.autoCompleteGAL(variables as AutoCompleteGALOptions),
discoverRights: client.discoverRights,
downloadAttachment: (_, variables) =>
client.downloadAttachment(variables),
downloadMessage: (_, variables, context = {}) => {
const { local } = context;
if (local) {
return localStoreClient.downloadMessage(variables);
}
return client.downloadMessage(variables);
},
freeBusy: (_, variables) =>
client.freeBusy(variables as FreeBusyOptions),
getContact: (_, variables) =>
client.getContact(variables as GetContactOptions),
clientInfo: (_, variables) =>
client.clientInfo(variables as ClientInfoInput),
getContactFrequency: (_, variables: any) =>
client.getContactFrequency(variables as GetContactFrequencyOptions),
getConversation: (_, variables) =>
client.getConversation(variables as GetConversationOptions),
getCustomMetadata: (_: any, variables) =>
client.getCustomMetadata(variables as GetCustomMetadataOptions),
getFilterRules: client.getFilterRules,
getFolder: (_: any, variables, context = {}) => {
const { local } = context;
if (local) {
return localStoreClient.getFolder(variables as GetFolderOptions);
}
return client.getFolder(variables as GetFolderOptions);
},
getAppointment: (_: any, variables) =>
client.getAppointment(variables as AppointmentOptions),
getAppointments: (_: any, variables) =>
client.search(variables as SearchOptions),
getReminders: (_: any, variables) =>
client.search(variables as SearchOptions),
getTasks: (_: any, variables) =>
client.getTasks(variables as SearchOptions),
getAvailableLocales: (_: any) => client.getAvailableLocales(),
getMailboxMetadata: (_: any, variables) =>
client.getMailboxMetadata(variables as GetMailboxMetadataOptions),
getMessage: (_, variables, context = {}) => {
const { local } = context;
if (local) {
return localStoreClient.getMessage(variables as GetMessageOptions);
}
return client.getMessage(variables as GetMessageOptions);
},
getMessagesMetadata: (_, variables, context = {}) => {
const { local } = context;
if (local) {
return localStoreClient.getMessagesMetadata(
variables as GetMessageOptions
);
}
return client.getMessagesMetadata(variables as GetMessageOptions);
},
getRights: (_, variables) =>
client.getRights(variables as GetRightsInput),
getScratchCodes: client.getScratchCodes,
getSearchFolder: client.getSearchFolder,
getSMimePublicCerts: (_, variables) =>
client.getSMimePublicCerts(variables as GetSMimePublicCertsOptions),
getTrustedDevices: client.getTrustedDevices,
getWorkingHours: (_, variables) =>
client.getWorkingHours(variables as WorkingHoursOptions),
getPreferences: client.getPreferences,
getDataSources: client.getDataSources,
getIdentities: client.getIdentities,
getSignatures: client.getSignatures,
noop: client.noop,
recoverAccount: (_, variables) =>
client.recoverAccount(variables as RecoverAccountOptions),
relatedContacts: (_, variables) =>
client.relatedContacts(variables as RelatedContactsOptions),
search: (_, variables, context = {}) => {
const { local } = context;
if (local) {
return localStoreClient.search(variables as SearchOptions);
}
return client.search(variables as SearchOptions);
},
searchGal: (_, variables) =>
client.searchGal(variables as SearchOptions),
shareInfo: (_, variables) =>
client.shareInfo(variables as ShareInfoOptions),
taskFolders: client.taskFolders,
getWhiteBlackList: client.getWhiteBlackList,
getAppSpecificPasswords: client.getAppSpecificPasswords,
getTag: client.getTag
},
//resolveType is necessary to differentiate for any Union or Interfaces
MailItem: {
__resolveType(obj: any) {
return obj.conversationId ? 'MessageInfo' : 'Conversation';
}
},
Mutation: {
action: (_, { type, ...rest }, context = {}) => {
const { local } = context;
return local
? localStoreClient.action(type, rest as ActionOptions)
: client.action(type, rest as ActionOptions);
},
addMessage: (_, variables, context = {}) => {
const { local } = context;
if (local) {
return localStoreClient.addMessage(variables as AddMsgInput);
}
return client.addMessage(variables as AddMsgInput);
},
applyFilterRules: (_, variables) =>
client.applyFilterRules(variables as ApplyFilterRulesOptions),
cancelTask: (_, variables) => client.cancelTask(variables),
itemAction: (_, variables) =>
client.itemAction(variables as ActionOptions),
login: (_, variables) => client.login(variables as LoginOptions),
logout: client.logout,
disableTwoFactorAuth: client.disableTwoFactorAuth,
enableTwoFactorAuth: (_, { options }) =>
client.enableTwoFactorAuth(options as EnableTwoFactorAuthInput),
messageAction: (_, variables) =>
client.messageAction(variables as ActionOptions),
changePassword: (_, variables) =>
client.changePassword(variables as ChangePasswordOptions),
modifyProfileImage: (_, variables) =>
client.modifyProfileImage(variables as ModifyProfileImageOptions),
contactAction: (_, variables) =>
client.contactAction(variables as ActionOptions),
createAppSpecificPassword: (_, { appName }) =>
client.createAppSpecificPassword(appName),
conversationAction: (_, variables) =>
client.conversationAction(variables as ActionOptions),
createFolder: (_, variables, context) => {
const { local } = context;
if (local) {
return localStoreClient.createFolder(
variables as CreateFolderOptions
);
}
return client.createFolder(variables as CreateFolderOptions);
},
createSearchFolder: (_, variables) =>
client.createSearchFolder(variables as CreateSearchFolderOptions),
createContact: (_, { contact }) =>
client.createContact(contact as CreateContactInput),
createContactList: (_, { contact }) =>
client.createContact(contact as CreateContactInput),
modifyContact: (_, { contact }) =>
client.modifyContact(contact as ModifyContactInput),
modifyContactList: (_, { contact }) =>
client.modifyContact(contact as ModifyContactInput),
createAppointment: (_, { accountName, appointment }) =>
client.createAppointment(
accountName,
appointment as CalendarItemInput
),
snoozeCalendarItem: (_, { appointment, task }) =>
client.snoozeCalendarItem(appointment, task),
dismissCalendarItem: (_, { appointment, task }) =>
client.dismissCalendarItem(appointment, task),
createAppointmentException: (_, { accountName, appointment }) =>
client.createAppointmentException(
accountName,
appointment as CalendarItemInput
),
modifyAppointment: (_, { accountName, appointment }) =>
client.modifyAppointment(
accountName,
appointment as CalendarItemInput
),
createMountpoint: (_, variables) =>
client.createMountpoint(variables as CreateMountpointInput),
deleteAppointment: (_, { appointment }) =>
client.deleteAppointment(appointment as DeleteAppointmentInput),
checkCalendar: (_, variables) =>
client.checkCalendar(variables as FolderActionCheckCalendarInput),
counterAppointment: (_, { counterAppointmentInvite }) =>
client.counterAppointment(
counterAppointmentInvite as CounterAppointmentInput
),
createCalendar: (_, { name, color, url }) =>
client.createFolder({
name,
color,
url,
view: 'appointment',
flags: '#'
} as CreateFolderOptions),
createSharedCalendar: (_, { link }) =>
client.createMountpoint({
link: {
...link,
parentFolderId: 1,
view: 'appointment',
flags: '#'
}
} as CreateMountpointInput),
saveDocument: (_, document) =>
client.saveDocument(document as SaveDocumentInput),
changeFolderColor: (_, variables) =>
client.changeFolderColor(variables as FolderActionChangeColorInput),
declineCounterAppointment: (_, { counterAppointmentInvite }) =>
client.declineCounterAppointment(
counterAppointmentInvite as CounterAppointmentInput
),
folderAction: (_, { action }) => client.folderAction(action),
forwardAppointment: (_, { appointmentInvite }) =>
client.forwardAppointment(
appointmentInvite as ForwardAppointmentInput
),
forwardAppointmentInvite: (_, { appointmentInvite }) =>
client.forwardAppointmentInvite(
appointmentInvite as ForwardAppointmentInviteInput
),
generateScratchCodes: client.generateScratchCodes,
grantRights: (_, variables) =>
client.grantRights(variables.input as GrantRightsInput),
sendShareNotification: (_, { shareNotification }) =>
client.sendShareNotification(
shareNotification as ShareNotificationInput
),
testExternalAccount: (_, { externalAccount }) =>
client.testExternalAccount(
externalAccount as ExternalAccountTestInput
),
addExternalAccount: (_, { externalAccount }) =>
client.addExternalAccount(externalAccount as ExternalAccountAddInput),
modifyExternalAccount: (_, variables) =>
client.modifyExternalAccount(variables as ExternalAccountModifyInput),
deleteExternalAccount: (_, variables) =>
client.deleteExternalAccount(variables as ExternalAccountDeleteInput),
importExternalAccount: (_, { externalAccount }) =>
client.importExternalAccount(
externalAccount as ExternalAccountImportInput
),
prefEnableOutOfOfficeAlertOnLogin: (_, { value }) =>
client
.modifyPrefs({
zimbraPrefOutOfOfficeStatusAlertOnLogin: value
})
.then(Boolean),
prefEnableOutOfOfficeReply: (_, { value }) =>
client
.modifyPrefs({
zimbraPrefOutOfOfficeReplyEnabled: value
})
.then(Boolean),
prefOutOfOfficeFromDate: (_, { value }) =>
client
.modifyPrefs({
zimbraPrefOutOfOfficeFromDate: value
})
.then(() => value),
prefOutOfOfficeUntilDate: (_, { value }) =>
client
.modifyPrefs({ zimbraPrefOutOfOfficeUntilDate: value })
.then(() => value),
prefOutOfOfficeReply: (_, { value }) =>
client
.modifyPrefs({
zimbraPrefOutOfOfficeReply: value
})
.then(() => value),
createIdentity: (_, variables) =>
client.createIdentity(variables as CreateIdentityInput),
modifyIdentity: (_, variables) =>
client.modifyIdentity(variables as ModifyIdentityInput).then(Boolean),
deleteIdentity: (_, variables) =>
client.deleteIdentity(variables as DeleteIdentityInput).then(Boolean),
modifyPrefs: (_, { prefs }) =>
client.modifyPrefs(prefs as PreferencesInput),
modifyProps: (_, { props }) =>
client.modifyProps(props as Array<PropertiesInput>),
modifyZimletPrefs: (_, { zimlets }) =>
client.modifyZimletPrefs(zimlets as Array<ZimletPreferenceInput>),
modifyFilterRules: (_, { filters }) =>
client.modifyFilterRules(filters as Array<FilterInput>),
createSignature: (_, variables) =>
client.createSignature(variables as SignatureInput),
modifySignature: (_, variables) =>
client.modifySignature(variables as SignatureInput),
modifySearchFolder: (_, variables) =>
client.modifySearchFolder(variables as SearchFolderInput),
deleteSignature: (_, variables) =>
client.deleteSignature(variables as NameIdInput),
saveDraft: (_, variables) =>
client.saveDraft(variables as SendMessageInput),
sendMessage: (_, variables) =>
client.sendMessage(variables as SendMessageInput),
sendDeliveryReport: (_, { messageId }) =>
client.sendDeliveryReport(messageId),
uploadMessage: (_, { value }) => client.uploadMessage(value),
createTask: (_, { task }) =>
client.createTask(task as CalendarItemInput),
modifyTask: (_, { task }) =>
client.modifyTask(task as CalendarItemInput),
sendInviteReply: (_, { inviteReply }) =>
client.sendInviteReply(inviteReply as InviteReplyInput),
recoverAccount: (_, variables) =>
client.recoverAccount(variables as RecoverAccountOptions),
resetPassword: (_, variables) =>
client.resetPassword(variables as ResetPasswordOptions),
revokeAppSpecificPassword: (_, { appName }) =>
client.revokeAppSpecificPassword(appName),
revokeOtherTrustedDevices: client.revokeOtherTrustedDevices,
revokeRights: (_, variables) =>
client.revokeRights(variables.input as RevokeRightsInput),
revokeTrustedDevice: client.revokeTrustedDevice,
setCustomMetadata: (_, customMetadata) =>
client.setCustomMetadata(customMetadata as CustomMetadataInput),
setMailboxMetadata: (_: any, variables: any) =>
client
.jsonRequest({
name: 'SetMailboxMetadata',
body: {
meta: {
section: variables.section,
_attrs: mapValues(variables.attrs, coerceBooleanToString)
}
}
})
.then(Boolean),
setRecoveryAccount: (_, variables) =>
client.setRecoveryAccount(variables as SetRecoveryAccountOptions),
modifyWhiteBlackList: (_, { whiteBlackList }) =>
client.modifyWhiteBlackList(whiteBlackList as WhiteBlackListInput),
createTag: (_, { tag }) => client.createTag(tag as CreateTagInput),
tagAction: (_, { action }) => client.action(ActionType.tag, action)
}
}
});
return {
client,
schema: executableSchema
};
}
export { schema };