Skip to content

Commit

Permalink
FIX: ApiClient.js Fixes
Browse files Browse the repository at this point in the history
- Converted `defaultHeaders` from a shared global state to a local state within each `ApiClient` instance.
- Fixed the overriding of the Authorization header in `GetUserInfo` when `defaultHeaders` already had an Authorization header.
- Updated the SDK release version.
  • Loading branch information
MGDS01 committed Jul 23, 2024
1 parent 37b6a52 commit 7283d5c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
See [DocuSign Support Center](https://support.docusign.com/en/releasenotes/) for Product Release Notes.


## [v7.0.3] - eSignature API v2.1-24.2.00.00 - 2024-07-23
### Changed
- Converted `defaultHeaders` from a shared global state to a local state within each `ApiClient` instance.
- Fixed the overriding of the Authorization header in `GetUserInfo` when `defaultHeaders` already had an Authorization header.
- Updated the SDK release version.
## [v7.0.2] - eSignature API v2.1-24.1.01.00 - 2024-06-06
### Changed
- Resolved an issue with the PDF download logic that caused corrupted data.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This client SDK is provided as open source, which enables you to customize its f
<a id="versionInformation"></a>
### Version Information
- **API version**: v2.1
- **Latest SDK version**: 7.0.2
- **Latest SDK version**: 7.0.3

<a id="requirements"></a>
## Requirements
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "docusign-esign",
"version": "7.0.2",
"description": "DocuSign Node.js API client.",
"version": "7.0.3",
"description": "Docusign Node.js API client.",
"license": "MIT",
"main": "src/index.js",
"author": "DocuSign Developer Center <devcenter@docusign.com>",
Expand Down
56 changes: 34 additions & 22 deletions src/ApiClient.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* DocuSign REST API
* The DocuSign REST API provides you with a powerful, convenient, and simple Web services API for interacting with DocuSign.
* Docusign eSignature REST API
* The Docusign eSignature REST API provides you with a powerful, convenient, and simple Web services API for interacting with Docusign.
*
* OpenAPI spec version: v2.1
* Contact: devcenter@docusign.com
Expand Down Expand Up @@ -34,12 +34,6 @@
* @type {Array.<String>}
* @default {}
*/
var defaultHeaders = {
"X-DocuSign-SDK": "Node",
"Node-Ver": process.version,
"User-Agent": `Swagger-Codegen/v2.1/7.0.2/node/${process.version}`,
};

var SCOPE_SIGNATURE = "signature";
var SCOPE_EXTENDED = "extended";
var SCOPE_IMPERSONATION = "impersonation";
Expand Down Expand Up @@ -91,6 +85,7 @@
assertion,
oAuthBasePath,
proxy,
defaultHeaders,
callback
) {
const requestConfig = {
Expand Down Expand Up @@ -162,6 +157,14 @@
return exports.prototype.OAuth.BasePath.PRODUCTION;
};

const encodeBase64 = (str) => {
if (typeof Buffer !== 'undefined') {
return Buffer.from(str).toString('base64');
} else {
return btoa(unescape(encodeURIComponent(str)));
}
}

/**
* @module ApiClient
*/
Expand All @@ -179,7 +182,13 @@
oAuthBasePath: require("./OAuth").BasePath.PRODUCTION,
};

opts = Object.assign({},defaults, opts);
this.defaultHeaders = {
"X-DocuSign-SDK": "Node",
"Node-Ver": process.version,
"User-Agent": `Swagger-Codegen/v2.1/7.0.3/node/${process.version}`,
};

opts = {...defaults, ...opts};
opts.oAuthBasePath = deriveOAuthBasePathFromRestBasePath(opts.basePath);

/**
Expand Down Expand Up @@ -266,7 +275,7 @@
header,
value
) {
defaultHeaders[header] = value;
this.defaultHeaders[header] = value;
};

/**
Expand All @@ -276,7 +285,7 @@
if(!token){
throw new Error("Missing the required parameter 'token' when calling setJWTToken.")
}
defaultHeaders["Authorization"] = `Bearer ${token}`;
this.defaultHeaders["Authorization"] = `Bearer ${token}`;
};

/**
Expand Down Expand Up @@ -627,7 +636,7 @@
const _headerParams = this.normalizeParams(headerParams);
requestConfig.headers = {
...requestConfig.headers,
...defaultHeaders,
...this.defaultHeaders,
..._headerParams,
};

Expand Down Expand Up @@ -878,7 +887,7 @@
/**
* @param clientId OAuth2 client ID: Identifies the client making the request.
* Client applications may be scoped to a limited set of system access.
* @param clientSecret the secret key you generated when you set up the integration in DocuSign Admin console.
* @param clientSecret the secret key you generated when you set up the integration in Docusign Admin console.
* @param code The authorization code that you received from the <i>getAuthorizationUri</i> callback.
* @return OAuthToken object.xx
*/
Expand All @@ -898,10 +907,10 @@
code: code,
},
headers = {
Authorization: "Basic " + new Buffer(clientString).toString("base64"),
...this.defaultHeaders,
Authorization: "Basic " + encodeBase64(clientString),
"Cache-Control": "no-store",
Pragma: "no-cache",
...defaultHeaders,
},
OAuthToken = require("./OAuth").OAuthToken;

Expand Down Expand Up @@ -947,10 +956,10 @@
if(!accessToken) throw new Error("Error accessToken is required", null);

var headers = {
...this.defaultHeaders,
Authorization: "Bearer " + accessToken,
"Cache-Control": "no-store",
Pragma: "no-cache",
...defaultHeaders,
};

const requestConfig = {
Expand Down Expand Up @@ -1001,7 +1010,7 @@
* Helper method to build the OAuth JWT grant uri (used once to get a user consent for impersonation)
* @param clientId OAuth2 client ID
* @param redirectURI OAuth2 redirect uri
* @param oAuthBasePath DocuSign OAuth base path (account-d.docusign.com for the developer sandbox
* @param oAuthBasePath Docusign OAuth base path (account-d.docusign.com for the developer sandbox
* and account.docusign.com for the production platform)
* @returns {string} the OAuth JWT grant uri as a String
*/
Expand Down Expand Up @@ -1029,12 +1038,12 @@

/**
* @deprecated since version 4.1.0
* Configures the current instance of ApiClient with a fresh OAuth JWT access token from DocuSign
* Configures the current instance of ApiClient with a fresh OAuth JWT access token from Docusign
* @param privateKeyFilename the filename of the RSA private key
* @param oAuthBasePath DocuSign OAuth base path (account-d.docusign.com for the developer sandbox
* @param oAuthBasePath Docusign OAuth base path (account-d.docusign.com for the developer sandbox
* and account.docusign.com for the production platform)
* @param clientId DocuSign OAuth Client Id (AKA Integrator Key)
* @param userId DocuSign user Id to be impersonated (This is a UUID)
* @param clientId Docusign OAuth Client Id (AKA Integrator Key)
* @param userId Docusign user Id to be impersonated (This is a UUID)
* @param expiresIn in seconds for the token time-to-live
* @param callback the callback function.
*/
Expand Down Expand Up @@ -1072,10 +1081,10 @@
method: "post",
url: "/oauth/token",
headers: {
...this.defaultHeaders,
"Content-Type": "application/x-www-form-urlencoded",
"Cache-Control": "no-store",
Pragma: "no-cache",
...defaultHeaders,
},
timeout: this.timeout,
data: {
Expand Down Expand Up @@ -1124,6 +1133,7 @@
assertion,
this.oAuthBasePath,
this.proxy,
this.defaultHeaders,
callback
);
};
Expand All @@ -1150,6 +1160,7 @@
assertion,
this.oAuthBasePath,
this.proxy,
this.defaultHeaders,
callback
);
};
Expand All @@ -1174,6 +1185,7 @@
assertion,
this.oAuthBasePath,
this.proxy,
this.defaultHeaders,
callback
);
};
Expand Down

0 comments on commit 7283d5c

Please sign in to comment.