rest-client-sdk 7.4.0 → 7.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1087,7 +1087,7 @@ var AbstractClient = /*#__PURE__*/function () {
1087
1087
  url: input
1088
1088
  }, params));
1089
1089
  }
1090
- return fetch(input, params).then(function (response) {
1090
+ return this._fetch(input, params).then(function (response) {
1091
1091
  if (_this6.sdk.logger) {
1092
1092
  _this6.sdk.logger.logResponse(response, logId);
1093
1093
  }
@@ -1101,6 +1101,14 @@ var AbstractClient = /*#__PURE__*/function () {
1101
1101
  throw httpError;
1102
1102
  });
1103
1103
  }
1104
+ }, {
1105
+ key: "_fetch",
1106
+ value: function _fetch(input, init) {
1107
+ var _this$sdk$config$fetc;
1108
+ // eslint-disable-next-line no-restricted-globals -- default for the injectable fetch
1109
+ var fetchFn = (_this$sdk$config$fetc = this.sdk.config.fetch) !== null && _this$sdk$config$fetc !== void 0 ? _this$sdk$config$fetc : fetch;
1110
+ return fetchFn(input, init);
1111
+ }
1104
1112
  }, {
1105
1113
  key: "_getEntityIdentifier",
1106
1114
  value: function _getEntityIdentifier(object) {
@@ -1864,6 +1872,7 @@ var RestClientSdk = /*#__PURE__*/function () {
1864
1872
  }]);
1865
1873
  }();
1866
1874
 
1875
+ // accepts any config type, but a `fetch` key must be a fetch function when there is one
1867
1876
  var AbstractTokenGenerator = /*#__PURE__*/function () {
1868
1877
  function AbstractTokenGenerator(tokenGeneratorConfig, logger) {
1869
1878
  _classCallCheck(this, AbstractTokenGenerator);
@@ -1878,9 +1887,20 @@ var AbstractTokenGenerator = /*#__PURE__*/function () {
1878
1887
  }
1879
1888
  }
1880
1889
  return _createClass(AbstractTokenGenerator, [{
1890
+ key: "_fetch",
1891
+ value: function _fetch(input, init) {
1892
+ var _config$fetch;
1893
+ // WithOptionalFetch guarantees this type, but TypeScript cannot read a key from a conditional constraint
1894
+ var config = this.tokenGeneratorConfig;
1895
+ // eslint-disable-next-line no-restricted-globals -- default for the injectable fetch
1896
+ var fetchFn = (_config$fetch = config === null || config === void 0 ? void 0 : config.fetch) !== null && _config$fetch !== void 0 ? _config$fetch : fetch;
1897
+ return fetchFn(input, init);
1898
+ }
1899
+
1900
+ /** @deprecated */
1901
+ }, {
1881
1902
  key: "_manageOauthError",
1882
- value: /** @deprecated */
1883
- function _manageOauthError(response) {
1903
+ value: function _manageOauthError(response) {
1884
1904
  return response.clone().json().then(function (body) {
1885
1905
  if (body.error === 'invalid_grant') {
1886
1906
  throw new InvalidGrantError(body.error, getHttpErrorFromResponse(response));
@@ -1933,21 +1953,22 @@ var AuthorizationCodeFlowTokenGenerator = /*#__PURE__*/function (_AbstractTokenG
1933
1953
  headers: {
1934
1954
  'Content-Type': 'application/x-www-form-urlencoded'
1935
1955
  },
1936
- body: new URLSearchParams({
1956
+ body: new URLSearchParams(_objectSpread2(_objectSpread2({
1937
1957
  grant_type: 'authorization_code',
1938
- client_id: this.tokenGeneratorConfig.clientId,
1939
- client_secret: this.tokenGeneratorConfig.clientSecret,
1940
- // TODO : secure this ?
1958
+ client_id: this.tokenGeneratorConfig.clientId
1959
+ }, this._clientSecretParameter()), {}, {
1941
1960
  redirect_uri: this.tokenGeneratorConfig.redirectUri,
1942
1961
  code: parameters.code
1943
- }).toString()
1962
+ }, parameters.codeVerifier ? {
1963
+ code_verifier: parameters.codeVerifier
1964
+ } : {})).toString()
1944
1965
  };
1945
1966
  if (this.logger) {
1946
1967
  this.logger.logRequest(_objectSpread2({
1947
1968
  url: url
1948
1969
  }, params));
1949
1970
  }
1950
- return fetch(url, params);
1971
+ return this._fetch(url, params);
1951
1972
  }
1952
1973
 
1953
1974
  /**
@@ -1969,19 +1990,19 @@ var AuthorizationCodeFlowTokenGenerator = /*#__PURE__*/function (_AbstractTokenG
1969
1990
  headers: {
1970
1991
  'Content-Type': 'application/x-www-form-urlencoded'
1971
1992
  },
1972
- body: new URLSearchParams({
1993
+ body: new URLSearchParams(_objectSpread2(_objectSpread2({
1973
1994
  grant_type: 'refresh_token',
1974
- client_id: this.tokenGeneratorConfig.clientId,
1975
- client_secret: this.tokenGeneratorConfig.clientSecret,
1995
+ client_id: this.tokenGeneratorConfig.clientId
1996
+ }, this._clientSecretParameter()), {}, {
1976
1997
  refresh_token: oldAccessToken.refresh_token
1977
- }).toString()
1998
+ })).toString()
1978
1999
  };
1979
2000
  if (this.logger) {
1980
2001
  this.logger.logRequest(_objectSpread2({
1981
2002
  url: url
1982
2003
  }, params));
1983
2004
  }
1984
- return fetch(url, params);
2005
+ return this._fetch(url, params);
1985
2006
  }
1986
2007
  }, {
1987
2008
  key: "checkTokenGeneratorConfig",
@@ -1992,13 +2013,21 @@ var AuthorizationCodeFlowTokenGenerator = /*#__PURE__*/function (_AbstractTokenG
1992
2013
  if (!(config.path && config.scheme)) {
1993
2014
  throw new RangeError('TokenGenerator config is not valid, it should contain a "path", a "scheme" parameter');
1994
2015
  }
1995
- if (!(config.clientId && config.clientSecret)) {
1996
- throw new RangeError('TokenGenerator config is not valid, it should contain a "clientId", a "clientSecret" parameter');
2016
+ if (!config.clientId) {
2017
+ throw new RangeError('TokenGenerator config is not valid, it should contain a "clientId" parameter');
1997
2018
  }
1998
2019
  if (!config.redirectUri) {
1999
2020
  throw new RangeError('TokenGenerator config is not valid, it should contain a "redirectUri" parameter');
2000
2021
  }
2001
2022
  }
2023
+ }, {
2024
+ key: "_clientSecretParameter",
2025
+ value: function _clientSecretParameter() {
2026
+ var clientSecret = this.tokenGeneratorConfig.clientSecret;
2027
+ return clientSecret ? {
2028
+ client_secret: clientSecret
2029
+ } : {};
2030
+ }
2002
2031
  }, {
2003
2032
  key: "_checkGenerateParameters",
2004
2033
  value: function _checkGenerateParameters(parameters) {
@@ -2086,7 +2115,7 @@ var ClientCredentialsGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2086
2115
  url: url
2087
2116
  }, params));
2088
2117
  }
2089
- return fetch(url, params);
2118
+ return this._fetch(url, params);
2090
2119
  }
2091
2120
  }, {
2092
2121
  key: "refreshToken",
@@ -2151,7 +2180,7 @@ var PasswordGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2151
2180
  url: url
2152
2181
  }, params));
2153
2182
  }
2154
- return fetch(url, params);
2183
+ return this._fetch(url, params);
2155
2184
  }
2156
2185
  }, {
2157
2186
  key: "refreshToken",
@@ -2182,7 +2211,7 @@ var PasswordGenerator = /*#__PURE__*/function (_AbstractTokenGenerat) {
2182
2211
  url: url
2183
2212
  }, params));
2184
2213
  }
2185
- return fetch(url, params);
2214
+ return this._fetch(url, params);
2186
2215
  }
2187
2216
  }, {
2188
2217
  key: "checkTokenGeneratorConfig",