rest-client-sdk 7.5.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/README.md +21 -0
- package/dist/index.cjs +28 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +28 -8
- package/dist/index.mjs.map +1 -1
- package/dist/types/RestClientSdkInterface.d.ts +1 -0
- package/dist/types/TokenGenerator/AbstractTokenGenerator.d.ts +5 -1
- package/dist/types/TokenGenerator/AuthorizationCodeFlowTokenGenerator.d.ts +1 -0
- package/dist/types/TokenGenerator/ClientCredentialsGenerator.d.ts +1 -0
- package/dist/types/TokenGenerator/PasswordGenerator.d.ts +1 -0
- package/dist/types/client/AbstractClient.d.ts +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -143,6 +143,7 @@ const config = {
|
|
|
143
143
|
onRefreshTokenFailure: () => {
|
|
144
144
|
// do something when the refresh token fails
|
|
145
145
|
},
|
|
146
|
+
fetch: myFetch, // optional, defaults to the global `fetch`
|
|
146
147
|
}; // path and scheme are mandatory
|
|
147
148
|
|
|
148
149
|
const sdk = new RestClientSdk(tokenStorage, config, mapping);
|
|
@@ -156,6 +157,26 @@ import RestClientSdk, { Token } from 'rest-client-sdk';
|
|
|
156
157
|
const sdk = new RestClientSdk<TSMetadata>(tokenStorage, config, mapping);
|
|
157
158
|
```
|
|
158
159
|
|
|
160
|
+
#### Custom fetch
|
|
161
|
+
|
|
162
|
+
By default, the SDK calls the global `fetch`. Pass a `fetch` key with the same signature to use your own implementation, for example in React Native, where you may want a `fetch` that does not rely on JS timers, which Android pauses when the app goes to the background. The `RestClientSdk` config covers the repository calls, and each token generator takes its own `fetch` key for the token calls:
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
const tokenGenerator = new PasswordGenerator({
|
|
166
|
+
path: 'oauth.me',
|
|
167
|
+
scheme: 'https',
|
|
168
|
+
clientId: 'my-client-id',
|
|
169
|
+
clientSecret: 'my-client-secret',
|
|
170
|
+
fetch: myFetch,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const sdk = new RestClientSdk(
|
|
174
|
+
new TokenStorage(tokenGenerator, storage),
|
|
175
|
+
{ path: 'api.me', scheme: 'https', fetch: myFetch },
|
|
176
|
+
mapping
|
|
177
|
+
);
|
|
178
|
+
```
|
|
179
|
+
|
|
159
180
|
#### UnitOfWork
|
|
160
181
|
|
|
161
182
|
Adding the key `unitOfWorkEnabled` to the `config` object passed to the `RestClientSdk` constructor will enable or disable the UnitOfWork
|
package/dist/index.cjs
CHANGED
|
@@ -1090,7 +1090,7 @@
|
|
|
1090
1090
|
url: input
|
|
1091
1091
|
}, params));
|
|
1092
1092
|
}
|
|
1093
|
-
return
|
|
1093
|
+
return this._fetch(input, params).then(function (response) {
|
|
1094
1094
|
if (_this6.sdk.logger) {
|
|
1095
1095
|
_this6.sdk.logger.logResponse(response, logId);
|
|
1096
1096
|
}
|
|
@@ -1104,6 +1104,14 @@
|
|
|
1104
1104
|
throw httpError;
|
|
1105
1105
|
});
|
|
1106
1106
|
}
|
|
1107
|
+
}, {
|
|
1108
|
+
key: "_fetch",
|
|
1109
|
+
value: function _fetch(input, init) {
|
|
1110
|
+
var _this$sdk$config$fetc;
|
|
1111
|
+
// eslint-disable-next-line no-restricted-globals -- default for the injectable fetch
|
|
1112
|
+
var fetchFn = (_this$sdk$config$fetc = this.sdk.config.fetch) !== null && _this$sdk$config$fetc !== void 0 ? _this$sdk$config$fetc : fetch;
|
|
1113
|
+
return fetchFn(input, init);
|
|
1114
|
+
}
|
|
1107
1115
|
}, {
|
|
1108
1116
|
key: "_getEntityIdentifier",
|
|
1109
1117
|
value: function _getEntityIdentifier(object) {
|
|
@@ -1867,6 +1875,7 @@
|
|
|
1867
1875
|
}]);
|
|
1868
1876
|
}();
|
|
1869
1877
|
|
|
1878
|
+
// accepts any config type, but a `fetch` key must be a fetch function when there is one
|
|
1870
1879
|
var AbstractTokenGenerator = /*#__PURE__*/function () {
|
|
1871
1880
|
function AbstractTokenGenerator(tokenGeneratorConfig, logger) {
|
|
1872
1881
|
_classCallCheck(this, AbstractTokenGenerator);
|
|
@@ -1881,9 +1890,20 @@
|
|
|
1881
1890
|
}
|
|
1882
1891
|
}
|
|
1883
1892
|
return _createClass(AbstractTokenGenerator, [{
|
|
1893
|
+
key: "_fetch",
|
|
1894
|
+
value: function _fetch(input, init) {
|
|
1895
|
+
var _config$fetch;
|
|
1896
|
+
// WithOptionalFetch guarantees this type, but TypeScript cannot read a key from a conditional constraint
|
|
1897
|
+
var config = this.tokenGeneratorConfig;
|
|
1898
|
+
// eslint-disable-next-line no-restricted-globals -- default for the injectable fetch
|
|
1899
|
+
var fetchFn = (_config$fetch = config === null || config === void 0 ? void 0 : config.fetch) !== null && _config$fetch !== void 0 ? _config$fetch : fetch;
|
|
1900
|
+
return fetchFn(input, init);
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
/** @deprecated */
|
|
1904
|
+
}, {
|
|
1884
1905
|
key: "_manageOauthError",
|
|
1885
|
-
value:
|
|
1886
|
-
function _manageOauthError(response) {
|
|
1906
|
+
value: function _manageOauthError(response) {
|
|
1887
1907
|
return response.clone().json().then(function (body) {
|
|
1888
1908
|
if (body.error === 'invalid_grant') {
|
|
1889
1909
|
throw new InvalidGrantError(body.error, getHttpErrorFromResponse(response));
|
|
@@ -1951,7 +1971,7 @@
|
|
|
1951
1971
|
url: url
|
|
1952
1972
|
}, params));
|
|
1953
1973
|
}
|
|
1954
|
-
return
|
|
1974
|
+
return this._fetch(url, params);
|
|
1955
1975
|
}
|
|
1956
1976
|
|
|
1957
1977
|
/**
|
|
@@ -1985,7 +2005,7 @@
|
|
|
1985
2005
|
url: url
|
|
1986
2006
|
}, params));
|
|
1987
2007
|
}
|
|
1988
|
-
return
|
|
2008
|
+
return this._fetch(url, params);
|
|
1989
2009
|
}
|
|
1990
2010
|
}, {
|
|
1991
2011
|
key: "checkTokenGeneratorConfig",
|
|
@@ -2098,7 +2118,7 @@
|
|
|
2098
2118
|
url: url
|
|
2099
2119
|
}, params));
|
|
2100
2120
|
}
|
|
2101
|
-
return
|
|
2121
|
+
return this._fetch(url, params);
|
|
2102
2122
|
}
|
|
2103
2123
|
}, {
|
|
2104
2124
|
key: "refreshToken",
|
|
@@ -2163,7 +2183,7 @@
|
|
|
2163
2183
|
url: url
|
|
2164
2184
|
}, params));
|
|
2165
2185
|
}
|
|
2166
|
-
return
|
|
2186
|
+
return this._fetch(url, params);
|
|
2167
2187
|
}
|
|
2168
2188
|
}, {
|
|
2169
2189
|
key: "refreshToken",
|
|
@@ -2194,7 +2214,7 @@
|
|
|
2194
2214
|
url: url
|
|
2195
2215
|
}, params));
|
|
2196
2216
|
}
|
|
2197
|
-
return
|
|
2217
|
+
return this._fetch(url, params);
|
|
2198
2218
|
}
|
|
2199
2219
|
}, {
|
|
2200
2220
|
key: "checkTokenGeneratorConfig",
|