Skip to content

Commit

Permalink
PREAPPS-7390: Remove zimbraOrigin dependency
Browse files Browse the repository at this point in the history
- Made default hostname as '' (blank)
- Added support to pass Agent in fetch request
- Added new serverUrl property to set zimbra server absolute url by desktop app such that cloud zimlet can use it for OAuth configuration.
  • Loading branch information
miteshsavani810 committed Aug 3, 2023
1 parent ad800c1 commit 66d14e9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/batch-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ import {

import { CASTING_PREFS } from './constants';
import { Notifier } from './notifier';

const DEBUG = false;

function normalizeMessage(
Expand Down Expand Up @@ -286,8 +285,10 @@ export class ZimbraBatchClient {
public localStoreClient: any;
public notifier: Notifier;
public origin: string;
public serverUrl: string;
public sessionId: any;
public soapPathname: string;
private agent?: any;
private authToken?: string;
private batchDataLoader: DataLoader<RequestOptions, RequestBody>;
private csrfToken?: string;
Expand All @@ -298,6 +299,7 @@ export class ZimbraBatchClient {
private userAgent?: {};

constructor(options: ZimbraClientOptions = {}) {
this.serverUrl = options.serverUrl !== undefined ? options.serverUrl : '';
this.sessionHandler = options.sessionHandler;
this.userAgent = options.userAgent;
this.jwtToken = options.jwtToken;
Expand All @@ -307,6 +309,7 @@ export class ZimbraBatchClient {
this.soapPathname = options.soapPathname || DEFAULT_SOAP_PATHNAME;
this.localStoreClient = options.localStoreClient;
this.customFetch = options.customFetch;
this.agent = options.agent;

this.notifier = new Notifier();

Expand Down Expand Up @@ -1895,7 +1898,7 @@ export class ZimbraBatchClient {
singleRequest: true
}).then(res => mapValuesDeep(get(res, `${accountType}.0`), coerceStringToBoolean));

public uploadMessage = (message: string): any => {
public uploadMessage = (message: string, agent: any = null): any => {
const contentDisposition = 'attachment';
const filename = 'message.eml';
const contentType = 'message/rfc822';
Expand All @@ -1913,6 +1916,7 @@ export class ZimbraBatchClient {
'X-Zimbra-Csrf-Token': this.csrfToken
})
},
...(agent && { agent }),
credentials: 'include'
}).then((response: any) => {
if (response.ok) {
Expand Down Expand Up @@ -2038,7 +2042,8 @@ export class ZimbraBatchClient {
userAgent: this.userAgent,
...(typeof this.notifier.getSequenceNumber() !== 'undefined' && {
sessionSeq: this.notifier.getSequenceNumber()
})
}),
agent: this.agent
});

private normalizeConversation = (conversation: { [key: string]: any }) => {
Expand Down
2 changes: 2 additions & 0 deletions src/batch-client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ export type SessionHandler = {
};

export interface ZimbraClientOptions {
agent?: any;
authToken?: string;
csrfToken?: string;
customFetch?: any;
jwtToken?: string;
localStoreClient?: any;
notificationHandler?: NotificationHandler;
serverUrl?: string;
sessionHandler?: SessionHandler;
soapPathname?: string;
userAgent?: UserAgent;
Expand Down
7 changes: 5 additions & 2 deletions src/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
SingleBatchRequestResponse,
SOAPHeader
} from './types';
export const DEFAULT_HOSTNAME = '/@zimbra';
export const DEFAULT_HOSTNAME = '';
export const DEFAULT_SOAP_PATHNAME = '/service/soap';

let customFetch: any;
Expand Down Expand Up @@ -263,7 +263,10 @@ export function jsonRequest(requestOptions: JsonRequestOptions): Promise<Request
Header: header
}),
headers: options.headers,
...(fetchOptions && fetchOptions)
...(fetchOptions && fetchOptions),
...(requestOptions.agent && {
agent: requestOptions.agent
})
})
.then(parseJSON)
.then((response: any) => {
Expand Down
1 change: 1 addition & 0 deletions src/request/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface UserAgent {
export interface BaseRequestOptions {
accountId?: string;
accountName?: string | null;
agent?: any;
authToken?: string;
credentials?: RequestCredentials;
csrfToken?: string | null;
Expand Down

0 comments on commit 66d14e9

Please sign in to comment.