Skip to content

Commit

Permalink
PREAPPS-5636: Added cross-fetch module to support fetch api for nodej…
Browse files Browse the repository at this point in the history
…s project
  • Loading branch information
sachinpatel88 authored and silentsakky committed May 14, 2021
1 parent 236fccd commit f03ded9
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"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']) :
['@graphql-tools/schema'];
['graphql', '@graphql-tools/schema', 'cross-fetch']) :
['@graphql-tools/schema', 'cross-fetch'];


export default {
Expand Down
5 changes: 5 additions & 0 deletions src/batch-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,14 @@ export class ZimbraBatchClient {
private jwtToken?: string;
private sessionHandler?: SessionHandler;
private userAgent?: {};
private authToken?: string;

constructor(options: ZimbraClientOptions = {}) {
this.sessionHandler = options.sessionHandler;
this.userAgent = options.userAgent;
this.jwtToken = options.jwtToken;
this.csrfToken = options.csrfToken;
this.authToken = options.authToken;
this.origin =
options.zimbraOrigin !== undefined
? options.zimbraOrigin
Expand Down Expand Up @@ -2001,6 +2003,9 @@ export class ZimbraBatchClient {
...(addCsrfToken && {
csrfToken: this.csrfToken
}),
...(this.authToken && {
authToken: this.authToken
}),
sessionId:
this.sessionId ||
(this.sessionHandler && this.sessionHandler.readSessionId()),
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 @@ -69,6 +69,7 @@ export interface ZimbraClientOptions {
soapPathname?: string;
userAgent?: UserAgent;
zimbraOrigin?: string;
authToken?: string;
}

export interface FreeBusyOptions {
Expand Down
7 changes: 6 additions & 1 deletion 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';

import fetch from 'cross-fetch';
export const DEFAULT_HOSTNAME = '/@zimbra';
export const DEFAULT_SOAP_PATHNAME = '/service/soap';

Expand Down Expand Up @@ -243,6 +243,10 @@ export function jsonRequest(
header.context.csrfToken = requestOptions.csrfToken;
}

if (requestOptions.authToken) {
options.headers['Cookie'] = `ZM_AUTH_TOKEN=${requestOptions.authToken}`;
}

const body = {
[soapRequestName]: soapCommandBody(options)
};
Expand All @@ -255,6 +259,7 @@ export function jsonRequest(
};
}

// @TODO: Remove third-party(cross-fetch) dependency.
return fetch(url, {
method: 'POST',
credentials: options.credentials,
Expand Down
1 change: 1 addition & 0 deletions src/request/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface BaseRequestOptions {
singleRequest?: boolean;
soapPathname?: string;
userAgent?: UserAgent;
authToken?: string;
}

export interface RequestOptions {
Expand Down

0 comments on commit f03ded9

Please sign in to comment.