|
2 | 2 | * DocuSign REST API |
3 | 3 | * The DocuSign REST API provides you with a powerful, convenient, and simple Web services API for interacting with DocuSign. |
4 | 4 | * |
5 | | - * OpenAPI spec version: v2 |
| 5 | + * OpenAPI spec version: v2.1 |
6 | 6 | * Contact: devcenter@docusign.com |
7 | 7 | * |
8 | 8 | * NOTE: This class is auto generated. Do not edit the class manually and submit a new issue instead. |
9 | 9 | * |
10 | 10 | */ |
11 | | - |
12 | 11 | (function(root, factory) { |
13 | 12 | if (typeof define === 'function' && define.amd) { |
14 | 13 | // AMD. Register as an anonymous module. |
|
26 | 25 | }(this, function(superagent, opts) { |
27 | 26 | 'use strict'; |
28 | 27 |
|
| 28 | + var SCOPE_SIGNATURE = "signature"; |
| 29 | + var SCOPE_EXTENDED = "extended"; |
| 30 | + var SCOPE_IMPERSONATION = "impersonation"; |
| 31 | + |
29 | 32 | var removeNulls = function(obj) { |
30 | 33 | var isArray = obj instanceof Array; |
31 | 34 | for (var k in obj) { |
|
73 | 76 | 'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer' |
74 | 77 | }); |
75 | 78 |
|
| 79 | + |
76 | 80 | if (!callback){ |
77 | 81 | return new Promise(function(resolve, reject){ |
78 | 82 | request.end(function(err, data){ |
|
82 | 86 | resolve(data); |
83 | 87 | } |
84 | 88 | }) |
85 | | - }) |
| 89 | + }); |
86 | 90 | } else { |
87 | 91 | request.end(callback); |
88 | 92 | } |
|
106 | 110 |
|
107 | 111 | /** |
108 | 112 | * @module ApiClient |
109 | | - * @version 3.0.0 |
110 | 113 | */ |
111 | 114 |
|
112 | 115 | /** |
|
169 | 172 | this.cache = true; |
170 | 173 | }; |
171 | 174 |
|
172 | | - /** |
| 175 | + /** |
173 | 176 | * Gets the API endpoint base URL. |
174 | 177 | */ |
175 | | - exports.prototype.getBasePath = function getBasePath() { |
| 178 | + exports.prototype.getBasePath = function getBasePath() { |
176 | 179 | return this.basePath; |
177 | 180 | }; |
178 | 181 |
|
|
184 | 187 | this.oAuthBasePath = deriveOAuthBasePathFromRestBasePath(basePath); |
185 | 188 | }; |
186 | 189 |
|
187 | | - /** |
| 190 | + /** |
188 | 191 | * Gets the authentication server endpoint base URL. |
189 | 192 | */ |
190 | | - exports.prototype.getOAuthBasePath = function getOAuthBasePath() { |
| 193 | + exports.prototype.getOAuthBasePath = function getOAuthBasePath() { |
191 | 194 | return this.oAuthBasePath; |
192 | 195 | }; |
193 | 196 |
|
|
282 | 285 | exports.prototype.isFileParam = function(param) { |
283 | 286 | // fs.ReadStream in Node.js (but not in runtime like browserify) |
284 | 287 | if (typeof window === 'undefined' && |
285 | | - typeof require === 'function' && |
286 | | - require('fs') && |
287 | | - param instanceof require('fs').ReadStream) { |
| 288 | + typeof require === 'function' && |
| 289 | + require('fs') && |
| 290 | + param instanceof require('fs').ReadStream) { |
288 | 291 | return true; |
289 | 292 | } |
290 | 293 | // Buffer in Node.js |
|
487 | 490 | * @returns {Object} The SuperAgent request object if a callback is specified, else {Promise} A {@link https://www.promisejs.org/|Promise} object. |
488 | 491 | */ |
489 | 492 | exports.prototype.callApi = function callApi(path, httpMethod, pathParams, |
490 | | - queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, |
491 | | - returnType, callback) { |
| 493 | + queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, |
| 494 | + returnType, callback) { |
492 | 495 |
|
493 | 496 | var _this = this; |
494 | 497 | var url = this.buildUrl(path, pathParams); |
|
580 | 583 | }) |
581 | 584 | } |
582 | 585 |
|
583 | | - var data = null; |
584 | | - if (!callback) { |
585 | | - return new Promise(function(resolve, reject){ |
586 | | - request.end(function(error, data) { |
587 | | - if (error) { |
588 | | - reject(error); |
589 | | - } else { |
590 | | - try { |
591 | | - data = _this.deserialize(data, returnType); |
592 | | - resolve(data); |
593 | | - } catch(error) { |
| 586 | + |
| 587 | + var data = null; |
| 588 | + if (!callback) { |
| 589 | + return new Promise(function(resolve, reject){ |
| 590 | + request.end(function(error, data) { |
| 591 | + if (error) { |
594 | 592 | reject(error); |
| 593 | + } else { |
| 594 | + try { |
| 595 | + data = _this.deserialize(data, returnType); |
| 596 | + resolve(data); |
| 597 | + } catch(error){ |
| 598 | + reject(error); |
| 599 | + } |
| 600 | + } |
| 601 | + }) |
| 602 | + }); |
| 603 | + } else { |
| 604 | + request.end(function(error, response) { |
| 605 | + if (!error) { |
| 606 | + try { |
| 607 | + data = _this.deserialize(response, returnType); |
| 608 | + } catch (err) { |
| 609 | + error = err; |
595 | 610 | } |
596 | 611 | } |
597 | | - }) |
598 | | - }); |
599 | | - } else { |
600 | | - request.end(function(error, response) { |
601 | | - if (!error) { |
602 | | - try { |
603 | | - data = _this.deserialize(response, returnType); |
604 | | - } catch (err) { |
605 | | - error = err; |
606 | | - } |
607 | | - } |
608 | | - callback(error, data, response); |
609 | | - }); |
610 | | - return request; |
611 | | - } |
| 612 | + callback(error, data, response); |
| 613 | + }); |
| 614 | + return request; |
| 615 | + } |
612 | 616 | }; |
613 | 617 |
|
614 | 618 | /** |
|
798 | 802 | var request = superagent.get("https://" + this.getOAuthBasePath() + "/oauth/userinfo").set(headers); |
799 | 803 | var UserInfo = require('./OAuth').UserInfo; |
800 | 804 |
|
| 805 | + |
801 | 806 | if(!callback) { |
802 | 807 | try { |
803 | 808 | return new Promise(function (resolve, reject) { |
|
806 | 811 | reject(err); |
807 | 812 | } else { |
808 | 813 | try { |
809 | | - resolve(UserInfo.constructFromObject(res.body)); |
| 814 | + return resolve(UserInfo.constructFromObject(res.body)); |
810 | 815 | } catch (error) { |
811 | 816 | reject(error); |
812 | 817 | } |
813 | 818 | } |
814 | 819 | }); |
815 | 820 | }); |
816 | 821 | } catch (err) { |
817 | | - throw(err) |
| 822 | + throw(err); |
818 | 823 | } |
819 | 824 | } else { |
820 | 825 | request.end(function (err, res) { |
|
839 | 844 | return "https://" + oAuthBasePath + "/oauth/auth" + "?" + |
840 | 845 | "response_type=code&" + |
841 | 846 | "client_id=" + encodeURIComponent(clientId) + "&" + |
842 | | - "scope=" + encodeURIComponent("signature impersonation") + "&" + |
| 847 | + "scope=" + encodeURIComponent(`${SCOPE_SIGNATURE} ${SCOPE_IMPERSONATION}`) + "&" + |
843 | 848 | "redirect_uri=" + encodeURIComponent(redirectURI); |
844 | 849 | }; |
845 | 850 |
|
|
869 | 874 | aud: oAuthBasePath, |
870 | 875 | iat: now, |
871 | 876 | exp: later, |
872 | | - scope: "signature" |
| 877 | + scope: SCOPE_SIGNATURE |
873 | 878 | }; |
874 | 879 |
|
875 | 880 | var assertion = jwt.sign(jwt_payload, private_key, {algorithm: 'RS256'}); |
|
899 | 904 | return ( |
900 | 905 | Array.isArray(scopes) |
901 | 906 | && scopes.length > 0 |
902 | | - && scopes.every(function(scope){ |
903 | | - return Object.keys(validScopes).some(function(key){ |
| 907 | + && scopes.every(function(scope) { |
| 908 | + return Object.keys(validScopes).some(function(key) { |
904 | 909 | return validScopes[key] === scope; |
905 | 910 | }) |
906 | 911 | }) |
|
0 commit comments