Skip to content

Commit

Permalink
PREAPPS-5617: Removed cross-fetch and accepting request api from para…
Browse files Browse the repository at this point in the history
…ms in case it presents
  • Loading branch information
sachinpatel88 authored and silentsakky committed May 14, 2021
1 parent f03ded9 commit 10542e3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion src/batch-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ import {
batchJsonRequest,
DEFAULT_HOSTNAME,
DEFAULT_SOAP_PATHNAME,
jsonRequest
jsonRequest,
setRequestAPI
} from '../request';
import {
JsonRequestOptions,
Expand Down Expand Up @@ -333,6 +334,10 @@ export class ZimbraBatchClient {
batch: false,
cache: false
});

if(options.requestAPI){
setRequestAPI(options.requestAPI);
}
}

public accountInfo = () =>
Expand Down
1 change: 1 addition & 0 deletions src/batch-client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export interface ZimbraClientOptions {
userAgent?: UserAgent;
zimbraOrigin?: string;
authToken?: string;
requestAPI?: any;
}

export interface FreeBusyOptions {
Expand Down
14 changes: 10 additions & 4 deletions src/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand All @@ -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) {
Expand Down

0 comments on commit 10542e3

Please sign in to comment.