From 66d14e9811ee379238576306d604922eb323d38b Mon Sep 17 00:00:00 2001 From: miteshsavani810 Date: Wed, 19 Jul 2023 19:04:01 +0530 Subject: [PATCH] PREAPPS-7390: Remove zimbraOrigin dependency - 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. --- src/batch-client/index.ts | 11 ++++++++--- src/batch-client/types.ts | 2 ++ src/request/index.ts | 7 +++++-- src/request/types.ts | 1 + 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/batch-client/index.ts b/src/batch-client/index.ts index cb6bdf89..a9e9a9df 100644 --- a/src/batch-client/index.ts +++ b/src/batch-client/index.ts @@ -152,7 +152,6 @@ import { import { CASTING_PREFS } from './constants'; import { Notifier } from './notifier'; - const DEBUG = false; function normalizeMessage( @@ -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; private csrfToken?: string; @@ -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; @@ -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(); @@ -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'; @@ -1913,6 +1916,7 @@ export class ZimbraBatchClient { 'X-Zimbra-Csrf-Token': this.csrfToken }) }, + ...(agent && { agent }), credentials: 'include' }).then((response: any) => { if (response.ok) { @@ -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 }) => { diff --git a/src/batch-client/types.ts b/src/batch-client/types.ts index 9b4f9c48..a0d00d3f 100644 --- a/src/batch-client/types.ts +++ b/src/batch-client/types.ts @@ -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; diff --git a/src/request/index.ts b/src/request/index.ts index 56c15b58..07824c08 100644 --- a/src/request/index.ts +++ b/src/request/index.ts @@ -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; @@ -263,7 +263,10 @@ export function jsonRequest(requestOptions: JsonRequestOptions): Promise { diff --git a/src/request/types.ts b/src/request/types.ts index 3e621359..0b3c1806 100644 --- a/src/request/types.ts +++ b/src/request/types.ts @@ -16,6 +16,7 @@ export interface UserAgent { export interface BaseRequestOptions { accountId?: string; accountName?: string | null; + agent?: any; authToken?: string; credentials?: RequestCredentials; csrfToken?: string | null;