diff --git a/package.json b/package.json index 5b111024..019bd7f1 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "license": "BSD-3-Clause", "dependencies": { "@apollo/client": "^3.2.1", - "cross-fetch": "^3.0.6", "dataloader": "^1.4.0", "graphql": "^15.3.0", "graphql-tools": "^7.0.4", diff --git a/rollup.config.js b/rollup.config.js index 501b75fb..58225505 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -15,8 +15,8 @@ let external = FORMAT==='es' ? Object.keys(pkg.dependencies) .concat( ['castArray', 'get','isError', 'isObject', 'mapValues', 'reduce', 'omitBy', 'uniqBy', 'concat', 'uniqBy', 'differenceBy', 'forEach'].map(v => 'lodash/'+v), - ['graphql', '@graphql-tools/schema', 'cross-fetch']) : - ['@graphql-tools/schema', 'cross-fetch']; + ['graphql', '@graphql-tools/schema']) : + ['@graphql-tools/schema']; export default { diff --git a/src/batch-client/index.ts b/src/batch-client/index.ts index 425d25ce..b9882107 100644 --- a/src/batch-client/index.ts +++ b/src/batch-client/index.ts @@ -51,7 +51,8 @@ import { batchJsonRequest, DEFAULT_HOSTNAME, DEFAULT_SOAP_PATHNAME, - jsonRequest + jsonRequest, + setRequestAPI } from '../request'; import { JsonRequestOptions, @@ -333,6 +334,10 @@ export class ZimbraBatchClient { batch: false, cache: false }); + + if(options.requestAPI){ + setRequestAPI(options.requestAPI); + } } public accountInfo = () => diff --git a/src/batch-client/types.ts b/src/batch-client/types.ts index d0b4371f..2ca39067 100644 --- a/src/batch-client/types.ts +++ b/src/batch-client/types.ts @@ -70,6 +70,7 @@ export interface ZimbraClientOptions { userAgent?: UserAgent; zimbraOrigin?: string; authToken?: string; + requestAPI?: any; } export interface FreeBusyOptions { diff --git a/src/request/index.ts b/src/request/index.ts index c84f8a68..eabc9e24 100644 --- a/src/request/index.ts +++ b/src/request/index.ts @@ -13,10 +13,15 @@ import { SingleBatchRequestResponse, SOAPHeader } from './types'; -import fetch from 'cross-fetch'; export const DEFAULT_HOSTNAME = '/@zimbra'; export const DEFAULT_SOAP_PATHNAME = '/service/soap'; +let requestAPI: any; + +export function setRequestAPI(httpRequestAPI: any) { + requestAPI = httpRequestAPI; +} + function soapCommandBody(options: RequestOptions) { return { _jsns: options.namespace || Namespace.Mail, @@ -259,8 +264,9 @@ export function jsonRequest( }; } - // @TODO: Remove third-party(cross-fetch) dependency. - return fetch(url, { + // Use received `requestAPI` passed as params instead of default fetch API + // to make `jsonRequest` method compatible with unsupported platforms, i.e. node.js + return (requestAPI || fetch)(url, { method: 'POST', credentials: options.credentials, body: JSON.stringify({ @@ -271,7 +277,7 @@ export function jsonRequest( ...(fetchOptions && fetchOptions) }) .then(parseJSON) - .then(response => { + .then((response: any) => { const globalFault = get(response.parsed, 'Body.Fault'); if (globalFault) {