Skip to content

Commit 5e8dd6f

Browse files
authored
Merge pull request #74 from Zimbra/PREAPPS-1199
PREAPPS-1199: Adding external account broken, failed due to "t.zimbra.account.addExternal is not a function" error
2 parents 0b065eb + 551ed4c commit 5e8dd6f

File tree

6 files changed

+156
-20
lines changed

6 files changed

+156
-20
lines changed

package-lock.json

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

src/batch-client/index.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ import {
4343
CalendarItemInput,
4444
CreateContactInput,
4545
CreateMountpointInput,
46+
ExternalAccountAddInput,
47+
ExternalAccountImportInput,
48+
ExternalAccountTestInput,
4649
FilterInput,
4750
FolderView,
4851
InviteReplyInput,
@@ -69,6 +72,8 @@ import {
6972
ChangePasswordOptions,
7073
CreateFolderOptions,
7174
CreateSearchFolderOptions,
75+
ExternalAccountDeleteInput,
76+
ExternalAccountModifyInput,
7277
FreeBusyOptions,
7378
GetContactFrequencyOptions,
7479
GetContactOptions,
@@ -162,6 +167,17 @@ export class ZimbraBatchClient {
162167
});
163168
};
164169

170+
public addExternalAccount = ({
171+
accountType,
172+
...accountInfo
173+
}: ExternalAccountAddInput) =>
174+
this.jsonRequest({
175+
name: 'CreateDataSource',
176+
body: {
177+
[<string>accountType]: mapValuesDeep(accountInfo, coerceBooleanToString)
178+
}
179+
}).then(res => get(res, `${accountType}.0.id`));
180+
165181
public autoComplete = (options: AutoCompleteOptions) =>
166182
this.jsonRequest({
167183
name: 'AutoComplete',
@@ -295,6 +311,14 @@ export class ZimbraBatchClient {
295311
}
296312
});
297313

314+
public deleteExternalAccount = ({ id }: ExternalAccountDeleteInput) =>
315+
this.jsonRequest({
316+
name: 'DeleteDataSource',
317+
body: {
318+
dsrc: { id }
319+
}
320+
});
321+
298322
public deleteSignature = (options: SignatureInput) =>
299323
this.jsonRequest({
300324
name: 'DeleteSignature',
@@ -459,6 +483,19 @@ export class ZimbraBatchClient {
459483
namespace: Namespace.Account
460484
});
461485

486+
public importExternalAccount = ({
487+
accountType,
488+
id
489+
}: ExternalAccountImportInput) =>
490+
this.jsonRequest({
491+
name: 'ImportData',
492+
body: {
493+
[<string>accountType]: {
494+
id
495+
}
496+
}
497+
});
498+
462499
public itemAction = (options: ActionOptions) =>
463500
this.action(ActionType.item, options);
464501

@@ -544,6 +581,21 @@ export class ZimbraBatchClient {
544581
}).then(res => normalize(Contact)(res.cn[0]));
545582
};
546583

584+
public modifyExternalAccount = ({
585+
id,
586+
type: accountType,
587+
attrs
588+
}: ExternalAccountModifyInput) =>
589+
this.jsonRequest({
590+
name: 'ModifyDataSource',
591+
body: {
592+
[<string>accountType]: {
593+
id,
594+
...mapValuesDeep(attrs, coerceBooleanToString)
595+
}
596+
}
597+
});
598+
547599
public modifyFilterRules = (filters: Array<FilterInput>) =>
548600
this.jsonRequest({
549601
name: 'ModifyFilterRules',
@@ -723,6 +775,19 @@ export class ZimbraBatchClient {
723775
}
724776
}).then(res => normalize(Folder)(res.folder[0].folder));
725777

778+
public testExternalAccount = ({
779+
accountType,
780+
...accountInfo
781+
}: ExternalAccountTestInput) =>
782+
this.jsonRequest({
783+
name: 'TestDataSource',
784+
body: {
785+
[<string>accountType]: mapValuesDeep(accountInfo, coerceBooleanToString)
786+
}
787+
}).then(res =>
788+
mapValuesDeep(get(res, `${accountType}.0`), coerceStringToBoolean)
789+
);
790+
726791
public uploadMessage = (message: string) => {
727792
const contentDisposition = 'attachment';
728793
const filename = 'message.eml';

src/batch-client/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {
2+
AccountType,
23
Cursor,
4+
ExternalAccountModifyAttrsInput,
35
FolderView,
46
SearchType,
57
SortBy
@@ -209,3 +211,13 @@ export interface RecoverAccountOptions {
209211
export interface ResetPasswordOptions {
210212
password: string;
211213
}
214+
215+
export interface ExternalAccountModifyInput {
216+
attrs: ExternalAccountModifyAttrsInput;
217+
id: string;
218+
type?: AccountType;
219+
}
220+
221+
export interface ExternalAccountDeleteInput {
222+
id: string;
223+
}

src/schema/generated-schema-types.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ export interface ShareInfo {
967967

968968
export interface Mutation {
969969
action?: boolean | null;
970+
testExternalAccount?: ExternalAccountTestResponse | null;
970971
addExternalAccount?: string | null;
971972
cancelTask?: boolean | null;
972973
changeCalendarColor?: boolean | null;
@@ -987,14 +988,15 @@ export interface Mutation {
987988
createSignature?: SignatureResponse | null;
988989
createTask?: boolean | null;
989990
deleteAppointment?: boolean | null;
990-
deleteExternalAccount?: string | null;
991+
deleteExternalAccount?: boolean | null;
991992
deleteSignature?: string | null;
992993
folderAction?: boolean | null;
993994
itemAction?: boolean | null;
995+
importExternalAccount?: boolean | null;
994996
logout?: boolean | null;
995997
login?: AuthResponse | null;
996998
messageAction?: boolean | null;
997-
modifyExternalAccount?: string | null;
999+
modifyExternalAccount?: boolean | null;
9981000
modifyAppointment?: ModifyAppointmentResponse | null;
9991001
modifyIdentity?: string | null;
10001002
modifyPrefs?: boolean | null;
@@ -1024,6 +1026,11 @@ export interface Mutation {
10241026
setRecoveryAccount?: boolean | null;
10251027
}
10261028

1029+
export interface ExternalAccountTestResponse {
1030+
success: boolean;
1031+
error?: string | null;
1032+
}
1033+
10271034
export interface SignatureResponse {
10281035
signature?: NameId[] | null;
10291036
}
@@ -1122,6 +1129,17 @@ export interface Cursor {
11221129
includeOffset?: boolean | null;
11231130
}
11241131

1132+
export interface ExternalAccountTestInput {
1133+
accountType?: AccountType | null;
1134+
connectionType?: ConnectionType | null;
1135+
emailAddress?: string | null;
1136+
host: string;
1137+
leaveOnServer?: boolean | null;
1138+
port: string;
1139+
username: string;
1140+
password: string;
1141+
}
1142+
11251143
export interface ExternalAccountAddInput {
11261144
accountType?: AccountType | null;
11271145
connectionType?: ConnectionType | null;
@@ -1401,6 +1419,11 @@ export interface GrantInput {
14011419
zimbraId?: string | null;
14021420
}
14031421

1422+
export interface ExternalAccountImportInput {
1423+
accountType?: AccountType | null;
1424+
id: string;
1425+
}
1426+
14041427
export interface ExternalAccountModifyAttrsInput {
14051428
id?: string | null;
14061429
accountType?: AccountType | null;
@@ -1872,6 +1895,9 @@ export interface ActionMutationArgs {
18721895
tagNames?: string | null;
18731896
name?: string | null;
18741897
}
1898+
export interface TestExternalAccountMutationArgs {
1899+
externalAccount: ExternalAccountTestInput;
1900+
}
18751901
export interface AddExternalAccountMutationArgs {
18761902
externalAccount: ExternalAccountAddInput;
18771903
}
@@ -1965,6 +1991,9 @@ export interface ItemActionMutationArgs {
19651991
folderId?: string | null;
19661992
op: string;
19671993
}
1994+
export interface ImportExternalAccountMutationArgs {
1995+
externalAccount: ExternalAccountImportInput;
1996+
}
19681997
export interface LoginMutationArgs {
19691998
username: string;
19701999
password?: string | null;

src/schema/schema.graphql

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,11 @@ type CalendarItemHitInfo { # <appt>; aka AppointmentHitInfo
625625
aid: String
626626
}
627627

628+
type ExternalAccountTestResponse {
629+
success: Boolean!
630+
error: String
631+
}
632+
628633
input ExternalAccount {
629634
id: ID!
630635
name: String!
@@ -1855,6 +1860,17 @@ input ExternalAccountAddInput {
18551860
username: String!
18561861
}
18571862

1863+
input ExternalAccountTestInput {
1864+
accountType: AccountType
1865+
connectionType: ConnectionType
1866+
emailAddress: String
1867+
host: String!
1868+
leaveOnServer: Boolean
1869+
port: String!
1870+
username: String!
1871+
password: String!
1872+
}
1873+
18581874
input ExternalAccountModifyAttrsInput {
18591875
id: ID
18601876
accountType: AccountType
@@ -1879,6 +1895,11 @@ input ExternalAccountModifyAttrsInput {
18791895
smtpPort: String
18801896
}
18811897

1898+
input ExternalAccountImportInput {
1899+
accountType: AccountType
1900+
id: ID!
1901+
}
1902+
18821903
# Include one of these fields to query for a folder
18831904
input GetFolderFolderInput {
18841905
uuid: ID
@@ -2074,7 +2095,8 @@ type Mutation {
20742095
tagNames: String,
20752096
name: String
20762097
): Boolean
2077-
addExternalAccount(externalAccount: ExternalAccountAddInput!): String
2098+
testExternalAccount(externalAccount: ExternalAccountTestInput!): ExternalAccountTestResponse
2099+
addExternalAccount(externalAccount: ExternalAccountAddInput!): ID
20782100
cancelTask(inviteId: ID!): Boolean
20792101
changeCalendarColor(id: String!, color: Int!): Boolean
20802102
changePassword(
@@ -2118,10 +2140,11 @@ type Mutation {
21182140
): SignatureResponse
21192141
createTask(task: CalendarItemInput!): Boolean
21202142
deleteAppointment(inviteId: String!): Boolean
2121-
deleteExternalAccount(id: ID!): String
2143+
deleteExternalAccount(id: ID!): Boolean
21222144
deleteSignature(signature: NameIdInput!): String
21232145
folderAction(action: FolderActionInput!): Boolean
21242146
itemAction(id: ID, ids: [ID], folderId: ID, op: String!): Boolean
2147+
importExternalAccount(externalAccount: ExternalAccountImportInput!): Boolean
21252148
logout: Boolean
21262149
login(username: String!, password: String, recoveryCode: String, tokenType: String): AuthResponse
21272150
messageAction(
@@ -2132,7 +2155,7 @@ type Mutation {
21322155
id: ID!
21332156
type: AccountType
21342157
attrs: ExternalAccountModifyAttrsInput!
2135-
): String
2158+
): Boolean
21362159
modifyAppointment(accountName: String, appointment: CalendarItemInput!): ModifyAppointmentResponse
21372160
modifyIdentity(id: ID!, attrs: IdentityAttrsInput!): String
21382161
modifyPrefs(prefs: PreferencesInput!): Boolean

src/schema/schema.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {
55
CalendarItemInput,
66
CreateContactInput,
77
CreateMountpointInput,
8+
ExternalAccountAddInput,
9+
ExternalAccountImportInput,
10+
ExternalAccountTestInput,
811
FilterInput,
912
FolderView,
1013
InviteReplyInput,
@@ -33,6 +36,8 @@ import {
3336
ChangePasswordOptions,
3437
CreateFolderOptions,
3538
CreateSearchFolderOptions,
39+
ExternalAccountDeleteInput,
40+
ExternalAccountModifyInput,
3641
FreeBusyOptions,
3742
GetContactFrequencyOptions,
3843
GetContactOptions,
@@ -230,18 +235,20 @@ export function createZimbraSchema(
230235
client.sendShareNotification(
231236
shareNotification as ShareNotificationInput
232237
),
233-
addExternalAccount: (_, { externalAccount }, { zimbra }) =>
234-
zimbra.account
235-
.addExternal({
236-
externalAccount
237-
})
238-
.then((id?: string) => {
239-
if (id !== undefined) return id;
240-
}),
241-
modifyExternalAccount: (_, { id, type, attrs }, { zimbra }) =>
242-
zimbra.account.modifyExternal(id, type, attrs),
243-
deleteExternalAccount: (_, { id }, { zimbra }) =>
244-
zimbra.account.deleteExternal({ id }),
238+
testExternalAccount: (_, { externalAccount }) =>
239+
client.testExternalAccount(
240+
externalAccount as ExternalAccountTestInput
241+
),
242+
addExternalAccount: (_, { externalAccount }) =>
243+
client.addExternalAccount(externalAccount as ExternalAccountAddInput),
244+
modifyExternalAccount: (_, variables) =>
245+
client.modifyExternalAccount(variables as ExternalAccountModifyInput),
246+
deleteExternalAccount: (_, variables) =>
247+
client.deleteExternalAccount(variables as ExternalAccountDeleteInput),
248+
importExternalAccount: (_, { externalAccount }) =>
249+
client.importExternalAccount(
250+
externalAccount as ExternalAccountImportInput
251+
),
245252
prefEnableOutOfOfficeAlertOnLogin: (_, { value }) =>
246253
client
247254
.modifyPrefs({

0 commit comments

Comments
 (0)