@commercetools/sdk-client-v2 1.4.0 → 1.4.2
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/CHANGELOG.md +17 -0
- package/README.md +2 -2
- package/dist/commercetools-sdk-client-v2.browser.cjs.js +40 -50
- package/dist/commercetools-sdk-client-v2.browser.esm.js +40 -50
- package/dist/commercetools-sdk-client-v2.cjs.dev.js +40 -50
- package/dist/commercetools-sdk-client-v2.cjs.prod.js +40 -50
- package/dist/commercetools-sdk-client-v2.esm.js +40 -50
- package/dist/commercetools-sdk-client-v2.umd.js +1 -1
- package/dist/declarations/src/client-builder/ClientBuilder.d.ts +1 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @commercetools/sdk-client-v2
|
|
2
2
|
|
|
3
|
+
## 1.4.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#331](https://github.com/commercetools/commercetools-sdk-typescript/pull/331) [`007d9c6`](https://github.com/commercetools/commercetools-sdk-typescript/commit/007d9c6e056c3286c0c521427576b2cc1df664b2) Thanks [@ajimae](https://github.com/ajimae)! - - Fix issues with buffer request body always being converted to json (`stringified`)
|
|
8
|
+
- Abandon the static `Buffer.isBuffer()` method in favour of custom `isBuffer` function
|
|
9
|
+
|
|
10
|
+
## 1.4.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [#317](https://github.com/commercetools/commercetools-sdk-typescript/pull/317) [`d921acd`](https://github.com/commercetools/commercetools-sdk-typescript/commit/d921acda35dadf135dffb53419b8825c915477b1) Thanks [@ajimae](https://github.com/ajimae)! - Allow `sdk-client` to accept request headers with `application/graphql` content-type.
|
|
15
|
+
|
|
16
|
+
* [#311](https://github.com/commercetools/commercetools-sdk-typescript/pull/311) [`588a0f9`](https://github.com/commercetools/commercetools-sdk-typescript/commit/588a0f9b981a538a16a23a449e810c56956f352c) Thanks [@ajimae](https://github.com/ajimae)! - Change token fetch window from 2 hours to 5 minutes
|
|
17
|
+
|
|
18
|
+
- [#320](https://github.com/commercetools/commercetools-sdk-typescript/pull/320) [`7510e0b`](https://github.com/commercetools/commercetools-sdk-typescript/commit/7510e0bf69cc4b63c43d0431d338502d048524aa) Thanks [@JohnMarsden24](https://github.com/JohnMarsden24)! - fix: make options for `withExistingTokenFlow` method optional
|
|
19
|
+
|
|
3
20
|
## 1.4.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Commercetools TypeScript SDK client
|
|
1
|
+
# Commercetools Composable Commerce TypeScript SDK client
|
|
2
2
|
|
|
3
3
|
## Usage examples
|
|
4
4
|
|
|
@@ -77,7 +77,7 @@ const client = new ClientBuilder()
|
|
|
77
77
|
|
|
78
78
|
const apiRoot = createApiBuilderFromCtpClient(client)
|
|
79
79
|
|
|
80
|
-
// calling the
|
|
80
|
+
// calling the Composable Commerce functions
|
|
81
81
|
// get project details
|
|
82
82
|
apiRoot
|
|
83
83
|
.withProjectKey({
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var fetch$1 = require('node-fetch');
|
|
6
6
|
var qs = require('querystring');
|
|
7
|
+
var _ = require('buffer/');
|
|
7
8
|
|
|
8
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
9
10
|
|
|
@@ -181,7 +182,7 @@ function createClient(options) {
|
|
|
181
182
|
|
|
182
183
|
// POST https://{host}/oauth/token?grant_type=client_credentials&scope={scope}
|
|
183
184
|
// Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
|
|
184
|
-
const Buffer$
|
|
185
|
+
const Buffer$1 = require('buffer/').Buffer;
|
|
185
186
|
|
|
186
187
|
function buildRequestForClientCredentialsFlow(options) {
|
|
187
188
|
if (!options) throw new Error('Missing required options');
|
|
@@ -194,7 +195,7 @@ function buildRequestForClientCredentialsFlow(options) {
|
|
|
194
195
|
} = options.credentials;
|
|
195
196
|
if (!(clientId && clientSecret)) throw new Error('Missing required credentials (clientId, clientSecret)');
|
|
196
197
|
const scope = options.scopes ? options.scopes.join(' ') : undefined;
|
|
197
|
-
const basicAuth = Buffer$
|
|
198
|
+
const basicAuth = Buffer$1.from(`${clientId}:${clientSecret}`).toString('base64'); // This is mostly useful for internal testing purposes to be able to check
|
|
198
199
|
// other oauth endpoints.
|
|
199
200
|
|
|
200
201
|
const oauthUri = options.oauthUri || '/oauth/token';
|
|
@@ -225,14 +226,14 @@ function buildRequestForPasswordFlow(options) {
|
|
|
225
226
|
if (!(username && password)) throw new Error('Missing required user credentials (username, password)');
|
|
226
227
|
const scope = (options.scopes || []).join(' ');
|
|
227
228
|
const scopeStr = scope ? `&scope=${scope}` : '';
|
|
228
|
-
const basicAuth = Buffer$
|
|
229
|
+
const basicAuth = Buffer$1.from(`${clientId}:${clientSecret}`).toString('base64');
|
|
229
230
|
/**
|
|
230
231
|
* This is mostly useful for internal testing purposes to be able to check
|
|
231
232
|
* other oauth endpoints.
|
|
232
233
|
*/
|
|
233
234
|
|
|
234
235
|
const oauthUri = options.oauthUri || `/oauth/${pKey}/customers/token`;
|
|
235
|
-
const url = options.host.replace(/\/$/, '') + oauthUri; // encode username and password as requested by
|
|
236
|
+
const url = options.host.replace(/\/$/, '') + oauthUri; // encode username and password as requested by the system
|
|
236
237
|
|
|
237
238
|
const body = `grant_type=password&username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}${scopeStr}`;
|
|
238
239
|
return {
|
|
@@ -252,7 +253,7 @@ function buildRequestForRefreshTokenFlow(options) {
|
|
|
252
253
|
clientSecret
|
|
253
254
|
} = options.credentials;
|
|
254
255
|
if (!(clientId && clientSecret)) throw new Error('Missing required credentials (clientId, clientSecret)');
|
|
255
|
-
const basicAuth = Buffer$
|
|
256
|
+
const basicAuth = Buffer$1.from(`${clientId}:${clientSecret}`).toString('base64'); // This is mostly useful for internal testing purposes to be able to check
|
|
256
257
|
// other oauth endpoints.
|
|
257
258
|
|
|
258
259
|
const oauthUri = options.oauthUri || '/oauth/token';
|
|
@@ -275,7 +276,7 @@ function buildRequestForAnonymousSessionFlow(options) {
|
|
|
275
276
|
};
|
|
276
277
|
}
|
|
277
278
|
|
|
278
|
-
const Buffer
|
|
279
|
+
const Buffer = require('buffer/').Buffer;
|
|
279
280
|
|
|
280
281
|
function mergeAuthHeader(token, req) {
|
|
281
282
|
return { ...req,
|
|
@@ -286,8 +287,8 @@ function mergeAuthHeader(token, req) {
|
|
|
286
287
|
}
|
|
287
288
|
|
|
288
289
|
function calculateExpirationTime(expiresIn) {
|
|
289
|
-
return Date.now() + // Add a gap of
|
|
290
|
-
expiresIn * 1000 -
|
|
290
|
+
return Date.now() + // Add a gap of 5 minutes before expiration time.
|
|
291
|
+
expiresIn * 1000 - 5 * 60 * 1000;
|
|
291
292
|
}
|
|
292
293
|
|
|
293
294
|
async function executeRequest({
|
|
@@ -306,7 +307,7 @@ async function executeRequest({
|
|
|
306
307
|
method: 'POST',
|
|
307
308
|
headers: {
|
|
308
309
|
Authorization: `Basic ${basicAuth}`,
|
|
309
|
-
'Content-Length': Buffer
|
|
310
|
+
'Content-Length': Buffer.byteLength(body).toString(),
|
|
310
311
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
311
312
|
},
|
|
312
313
|
body
|
|
@@ -627,6 +628,19 @@ function createCorrelationIdMiddleware(options) {
|
|
|
627
628
|
};
|
|
628
629
|
}
|
|
629
630
|
|
|
631
|
+
function parseHeaders(headers) {
|
|
632
|
+
if (headers.raw) // node-fetch
|
|
633
|
+
return headers.raw(); // Tmp fix for Firefox until it supports iterables
|
|
634
|
+
|
|
635
|
+
if (!headers.forEach) return {}; // whatwg-fetch
|
|
636
|
+
|
|
637
|
+
const map = {};
|
|
638
|
+
headers.forEach((value, name) => {
|
|
639
|
+
map[name] = value;
|
|
640
|
+
});
|
|
641
|
+
return map;
|
|
642
|
+
}
|
|
643
|
+
|
|
630
644
|
function defineError(statusCode, message, meta = {}) {
|
|
631
645
|
this.status = this.statusCode = this.code = statusCode;
|
|
632
646
|
this.message = message;
|
|
@@ -698,21 +712,10 @@ function getErrorByCode(code) {
|
|
|
698
712
|
}
|
|
699
713
|
}
|
|
700
714
|
|
|
701
|
-
function
|
|
702
|
-
|
|
703
|
-
return headers.raw(); // Tmp fix for Firefox until it supports iterables
|
|
704
|
-
|
|
705
|
-
if (!headers.forEach) return {}; // whatwg-fetch
|
|
706
|
-
|
|
707
|
-
const map = {};
|
|
708
|
-
headers.forEach((value, name) => {
|
|
709
|
-
map[name] = value;
|
|
710
|
-
});
|
|
711
|
-
return map;
|
|
715
|
+
function isBuffer(obj) {
|
|
716
|
+
return obj != null && obj.constructor != null && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj);
|
|
712
717
|
}
|
|
713
718
|
|
|
714
|
-
const Buffer = require('buffer/').Buffer;
|
|
715
|
-
|
|
716
719
|
function createError({
|
|
717
720
|
statusCode,
|
|
718
721
|
message,
|
|
@@ -760,8 +763,9 @@ function createHttpMiddleware({
|
|
|
760
763
|
fetch: fetcher,
|
|
761
764
|
getAbortController
|
|
762
765
|
}) {
|
|
763
|
-
|
|
764
|
-
if (
|
|
766
|
+
//nodejs v18 has the fetch available and not the version 16
|
|
767
|
+
if (!fetcher) throw new Error('`fetch` is not available. Please pass in `fetch` as an option or have it globally available.');
|
|
768
|
+
if (timeout && !getAbortController) throw new Error('`AbortController` is not available. Please pass in `getAbortController` as an option or have AbortController globally available when using timeout.');
|
|
765
769
|
let fetchFunction;
|
|
766
770
|
|
|
767
771
|
if (fetcher) {
|
|
@@ -788,15 +792,15 @@ function createHttpMiddleware({
|
|
|
788
792
|
delete requestHeader['Content-Type'];
|
|
789
793
|
}
|
|
790
794
|
|
|
791
|
-
if (!Object.prototype.hasOwnProperty.call(requestHeader, 'Content-Type') ||
|
|
795
|
+
if (!(Object.prototype.hasOwnProperty.call(requestHeader, 'Content-Type') || Object.prototype.hasOwnProperty.call(requestHeader, 'content-type'))) {
|
|
792
796
|
requestHeader['Content-Type'] = 'application/json';
|
|
793
797
|
} // Ensure body is a string if content type is application/json
|
|
794
798
|
|
|
795
799
|
|
|
796
|
-
const body = requestHeader['Content-Type']
|
|
800
|
+
const body = ['application/json', 'application/graphql'].indexOf(requestHeader['Content-Type']) > -1 && typeof request.body === 'string' || isBuffer(request.body) ? request.body : JSON.stringify(request.body || undefined);
|
|
797
801
|
|
|
798
|
-
if (body && (typeof body === 'string' ||
|
|
799
|
-
requestHeader['Content-Length'] = Buffer.byteLength(body).toString();
|
|
802
|
+
if (body && (typeof body === 'string' || isBuffer(body))) {
|
|
803
|
+
requestHeader['Content-Length'] = _.Buffer.byteLength(body).toString();
|
|
800
804
|
}
|
|
801
805
|
|
|
802
806
|
const fetchOptions = {
|
|
@@ -864,22 +868,7 @@ function createHttpMiddleware({
|
|
|
864
868
|
next(request, parsedResponse);
|
|
865
869
|
});
|
|
866
870
|
return;
|
|
867
|
-
} //
|
|
868
|
-
// if (retryCount < maxRetries) {
|
|
869
|
-
// setTimeout(
|
|
870
|
-
// executeFetch,
|
|
871
|
-
// calcDelayDuration(
|
|
872
|
-
// retryCount,
|
|
873
|
-
// retryDelay,
|
|
874
|
-
// maxRetries,
|
|
875
|
-
// backoff,
|
|
876
|
-
// maxDelay
|
|
877
|
-
// )
|
|
878
|
-
// )
|
|
879
|
-
// retryCount += 1
|
|
880
|
-
// return
|
|
881
|
-
// }
|
|
882
|
-
// Server responded with an error. Try to parse it as JSON, then
|
|
871
|
+
} // Server responded with an error. Try to parse it as JSON, then
|
|
883
872
|
// return a proper error type with all necessary meta information.
|
|
884
873
|
|
|
885
874
|
|
|
@@ -1019,10 +1008,11 @@ function createQueueMiddleware({
|
|
|
1019
1008
|
|
|
1020
1009
|
var packageJson = {
|
|
1021
1010
|
name: "@commercetools/sdk-client-v2",
|
|
1022
|
-
version: "1.4.
|
|
1023
|
-
description: "commercetools TypeScript SDK client.",
|
|
1011
|
+
version: "1.4.2",
|
|
1012
|
+
description: "commercetools Composable Commerce TypeScript SDK client.",
|
|
1024
1013
|
keywords: [
|
|
1025
1014
|
"commercetools",
|
|
1015
|
+
"composable commerce",
|
|
1026
1016
|
"sdk",
|
|
1027
1017
|
"typescript",
|
|
1028
1018
|
"client",
|
|
@@ -1066,10 +1056,10 @@ var packageJson = {
|
|
|
1066
1056
|
devDependencies: {
|
|
1067
1057
|
"abort-controller": "3.0.0",
|
|
1068
1058
|
"common-tags": "1.8.2",
|
|
1069
|
-
dotenv: "16.0.
|
|
1070
|
-
jest: "
|
|
1059
|
+
dotenv: "16.0.1",
|
|
1060
|
+
jest: "28.1.1",
|
|
1071
1061
|
nock: "12.0.3",
|
|
1072
|
-
"organize-imports-cli": "0.
|
|
1062
|
+
"organize-imports-cli": "0.10.0"
|
|
1073
1063
|
},
|
|
1074
1064
|
scripts: {
|
|
1075
1065
|
organize_imports: "find src -type f -name '*.ts' | xargs organize-imports-cli",
|
|
@@ -1289,9 +1279,9 @@ class ClientBuilder {
|
|
|
1289
1279
|
if (this.correlationIdMiddleware) middlewares.push(this.correlationIdMiddleware);
|
|
1290
1280
|
if (this.userAgentMiddleware) middlewares.push(this.userAgentMiddleware);
|
|
1291
1281
|
if (this.authMiddleware) middlewares.push(this.authMiddleware);
|
|
1292
|
-
if (this.loggerMiddleware) middlewares.push(this.loggerMiddleware);
|
|
1293
1282
|
if (this.queueMiddleware) middlewares.push(this.queueMiddleware);
|
|
1294
1283
|
if (this.httpMiddleware) middlewares.push(this.httpMiddleware);
|
|
1284
|
+
if (this.loggerMiddleware) middlewares.push(this.loggerMiddleware);
|
|
1295
1285
|
return createClient({
|
|
1296
1286
|
middlewares
|
|
1297
1287
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fetch$1 from 'node-fetch';
|
|
2
2
|
import qs from 'querystring';
|
|
3
|
+
import { Buffer as Buffer$2 } from 'buffer/';
|
|
3
4
|
|
|
4
5
|
function _defineProperty(obj, key, value) {
|
|
5
6
|
if (key in obj) {
|
|
@@ -172,7 +173,7 @@ function createClient(options) {
|
|
|
172
173
|
|
|
173
174
|
// POST https://{host}/oauth/token?grant_type=client_credentials&scope={scope}
|
|
174
175
|
// Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
|
|
175
|
-
const Buffer$
|
|
176
|
+
const Buffer$1 = require('buffer/').Buffer;
|
|
176
177
|
|
|
177
178
|
function buildRequestForClientCredentialsFlow(options) {
|
|
178
179
|
if (!options) throw new Error('Missing required options');
|
|
@@ -185,7 +186,7 @@ function buildRequestForClientCredentialsFlow(options) {
|
|
|
185
186
|
} = options.credentials;
|
|
186
187
|
if (!(clientId && clientSecret)) throw new Error('Missing required credentials (clientId, clientSecret)');
|
|
187
188
|
const scope = options.scopes ? options.scopes.join(' ') : undefined;
|
|
188
|
-
const basicAuth = Buffer$
|
|
189
|
+
const basicAuth = Buffer$1.from(`${clientId}:${clientSecret}`).toString('base64'); // This is mostly useful for internal testing purposes to be able to check
|
|
189
190
|
// other oauth endpoints.
|
|
190
191
|
|
|
191
192
|
const oauthUri = options.oauthUri || '/oauth/token';
|
|
@@ -216,14 +217,14 @@ function buildRequestForPasswordFlow(options) {
|
|
|
216
217
|
if (!(username && password)) throw new Error('Missing required user credentials (username, password)');
|
|
217
218
|
const scope = (options.scopes || []).join(' ');
|
|
218
219
|
const scopeStr = scope ? `&scope=${scope}` : '';
|
|
219
|
-
const basicAuth = Buffer$
|
|
220
|
+
const basicAuth = Buffer$1.from(`${clientId}:${clientSecret}`).toString('base64');
|
|
220
221
|
/**
|
|
221
222
|
* This is mostly useful for internal testing purposes to be able to check
|
|
222
223
|
* other oauth endpoints.
|
|
223
224
|
*/
|
|
224
225
|
|
|
225
226
|
const oauthUri = options.oauthUri || `/oauth/${pKey}/customers/token`;
|
|
226
|
-
const url = options.host.replace(/\/$/, '') + oauthUri; // encode username and password as requested by
|
|
227
|
+
const url = options.host.replace(/\/$/, '') + oauthUri; // encode username and password as requested by the system
|
|
227
228
|
|
|
228
229
|
const body = `grant_type=password&username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}${scopeStr}`;
|
|
229
230
|
return {
|
|
@@ -243,7 +244,7 @@ function buildRequestForRefreshTokenFlow(options) {
|
|
|
243
244
|
clientSecret
|
|
244
245
|
} = options.credentials;
|
|
245
246
|
if (!(clientId && clientSecret)) throw new Error('Missing required credentials (clientId, clientSecret)');
|
|
246
|
-
const basicAuth = Buffer$
|
|
247
|
+
const basicAuth = Buffer$1.from(`${clientId}:${clientSecret}`).toString('base64'); // This is mostly useful for internal testing purposes to be able to check
|
|
247
248
|
// other oauth endpoints.
|
|
248
249
|
|
|
249
250
|
const oauthUri = options.oauthUri || '/oauth/token';
|
|
@@ -266,7 +267,7 @@ function buildRequestForAnonymousSessionFlow(options) {
|
|
|
266
267
|
};
|
|
267
268
|
}
|
|
268
269
|
|
|
269
|
-
const Buffer
|
|
270
|
+
const Buffer = require('buffer/').Buffer;
|
|
270
271
|
|
|
271
272
|
function mergeAuthHeader(token, req) {
|
|
272
273
|
return { ...req,
|
|
@@ -277,8 +278,8 @@ function mergeAuthHeader(token, req) {
|
|
|
277
278
|
}
|
|
278
279
|
|
|
279
280
|
function calculateExpirationTime(expiresIn) {
|
|
280
|
-
return Date.now() + // Add a gap of
|
|
281
|
-
expiresIn * 1000 -
|
|
281
|
+
return Date.now() + // Add a gap of 5 minutes before expiration time.
|
|
282
|
+
expiresIn * 1000 - 5 * 60 * 1000;
|
|
282
283
|
}
|
|
283
284
|
|
|
284
285
|
async function executeRequest({
|
|
@@ -297,7 +298,7 @@ async function executeRequest({
|
|
|
297
298
|
method: 'POST',
|
|
298
299
|
headers: {
|
|
299
300
|
Authorization: `Basic ${basicAuth}`,
|
|
300
|
-
'Content-Length': Buffer
|
|
301
|
+
'Content-Length': Buffer.byteLength(body).toString(),
|
|
301
302
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
302
303
|
},
|
|
303
304
|
body
|
|
@@ -618,6 +619,19 @@ function createCorrelationIdMiddleware(options) {
|
|
|
618
619
|
};
|
|
619
620
|
}
|
|
620
621
|
|
|
622
|
+
function parseHeaders(headers) {
|
|
623
|
+
if (headers.raw) // node-fetch
|
|
624
|
+
return headers.raw(); // Tmp fix for Firefox until it supports iterables
|
|
625
|
+
|
|
626
|
+
if (!headers.forEach) return {}; // whatwg-fetch
|
|
627
|
+
|
|
628
|
+
const map = {};
|
|
629
|
+
headers.forEach((value, name) => {
|
|
630
|
+
map[name] = value;
|
|
631
|
+
});
|
|
632
|
+
return map;
|
|
633
|
+
}
|
|
634
|
+
|
|
621
635
|
function defineError(statusCode, message, meta = {}) {
|
|
622
636
|
this.status = this.statusCode = this.code = statusCode;
|
|
623
637
|
this.message = message;
|
|
@@ -689,21 +703,10 @@ function getErrorByCode(code) {
|
|
|
689
703
|
}
|
|
690
704
|
}
|
|
691
705
|
|
|
692
|
-
function
|
|
693
|
-
|
|
694
|
-
return headers.raw(); // Tmp fix for Firefox until it supports iterables
|
|
695
|
-
|
|
696
|
-
if (!headers.forEach) return {}; // whatwg-fetch
|
|
697
|
-
|
|
698
|
-
const map = {};
|
|
699
|
-
headers.forEach((value, name) => {
|
|
700
|
-
map[name] = value;
|
|
701
|
-
});
|
|
702
|
-
return map;
|
|
706
|
+
function isBuffer(obj) {
|
|
707
|
+
return obj != null && obj.constructor != null && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj);
|
|
703
708
|
}
|
|
704
709
|
|
|
705
|
-
const Buffer = require('buffer/').Buffer;
|
|
706
|
-
|
|
707
710
|
function createError({
|
|
708
711
|
statusCode,
|
|
709
712
|
message,
|
|
@@ -751,8 +754,9 @@ function createHttpMiddleware({
|
|
|
751
754
|
fetch: fetcher,
|
|
752
755
|
getAbortController
|
|
753
756
|
}) {
|
|
754
|
-
|
|
755
|
-
if (
|
|
757
|
+
//nodejs v18 has the fetch available and not the version 16
|
|
758
|
+
if (!fetcher) throw new Error('`fetch` is not available. Please pass in `fetch` as an option or have it globally available.');
|
|
759
|
+
if (timeout && !getAbortController) throw new Error('`AbortController` is not available. Please pass in `getAbortController` as an option or have AbortController globally available when using timeout.');
|
|
756
760
|
let fetchFunction;
|
|
757
761
|
|
|
758
762
|
if (fetcher) {
|
|
@@ -779,15 +783,15 @@ function createHttpMiddleware({
|
|
|
779
783
|
delete requestHeader['Content-Type'];
|
|
780
784
|
}
|
|
781
785
|
|
|
782
|
-
if (!Object.prototype.hasOwnProperty.call(requestHeader, 'Content-Type') ||
|
|
786
|
+
if (!(Object.prototype.hasOwnProperty.call(requestHeader, 'Content-Type') || Object.prototype.hasOwnProperty.call(requestHeader, 'content-type'))) {
|
|
783
787
|
requestHeader['Content-Type'] = 'application/json';
|
|
784
788
|
} // Ensure body is a string if content type is application/json
|
|
785
789
|
|
|
786
790
|
|
|
787
|
-
const body = requestHeader['Content-Type']
|
|
791
|
+
const body = ['application/json', 'application/graphql'].indexOf(requestHeader['Content-Type']) > -1 && typeof request.body === 'string' || isBuffer(request.body) ? request.body : JSON.stringify(request.body || undefined);
|
|
788
792
|
|
|
789
|
-
if (body && (typeof body === 'string' ||
|
|
790
|
-
requestHeader['Content-Length'] = Buffer.byteLength(body).toString();
|
|
793
|
+
if (body && (typeof body === 'string' || isBuffer(body))) {
|
|
794
|
+
requestHeader['Content-Length'] = Buffer$2.byteLength(body).toString();
|
|
791
795
|
}
|
|
792
796
|
|
|
793
797
|
const fetchOptions = {
|
|
@@ -855,22 +859,7 @@ function createHttpMiddleware({
|
|
|
855
859
|
next(request, parsedResponse);
|
|
856
860
|
});
|
|
857
861
|
return;
|
|
858
|
-
} //
|
|
859
|
-
// if (retryCount < maxRetries) {
|
|
860
|
-
// setTimeout(
|
|
861
|
-
// executeFetch,
|
|
862
|
-
// calcDelayDuration(
|
|
863
|
-
// retryCount,
|
|
864
|
-
// retryDelay,
|
|
865
|
-
// maxRetries,
|
|
866
|
-
// backoff,
|
|
867
|
-
// maxDelay
|
|
868
|
-
// )
|
|
869
|
-
// )
|
|
870
|
-
// retryCount += 1
|
|
871
|
-
// return
|
|
872
|
-
// }
|
|
873
|
-
// Server responded with an error. Try to parse it as JSON, then
|
|
862
|
+
} // Server responded with an error. Try to parse it as JSON, then
|
|
874
863
|
// return a proper error type with all necessary meta information.
|
|
875
864
|
|
|
876
865
|
|
|
@@ -1010,10 +999,11 @@ function createQueueMiddleware({
|
|
|
1010
999
|
|
|
1011
1000
|
var packageJson = {
|
|
1012
1001
|
name: "@commercetools/sdk-client-v2",
|
|
1013
|
-
version: "1.4.
|
|
1014
|
-
description: "commercetools TypeScript SDK client.",
|
|
1002
|
+
version: "1.4.2",
|
|
1003
|
+
description: "commercetools Composable Commerce TypeScript SDK client.",
|
|
1015
1004
|
keywords: [
|
|
1016
1005
|
"commercetools",
|
|
1006
|
+
"composable commerce",
|
|
1017
1007
|
"sdk",
|
|
1018
1008
|
"typescript",
|
|
1019
1009
|
"client",
|
|
@@ -1057,10 +1047,10 @@ var packageJson = {
|
|
|
1057
1047
|
devDependencies: {
|
|
1058
1048
|
"abort-controller": "3.0.0",
|
|
1059
1049
|
"common-tags": "1.8.2",
|
|
1060
|
-
dotenv: "16.0.
|
|
1061
|
-
jest: "
|
|
1050
|
+
dotenv: "16.0.1",
|
|
1051
|
+
jest: "28.1.1",
|
|
1062
1052
|
nock: "12.0.3",
|
|
1063
|
-
"organize-imports-cli": "0.
|
|
1053
|
+
"organize-imports-cli": "0.10.0"
|
|
1064
1054
|
},
|
|
1065
1055
|
scripts: {
|
|
1066
1056
|
organize_imports: "find src -type f -name '*.ts' | xargs organize-imports-cli",
|
|
@@ -1280,9 +1270,9 @@ class ClientBuilder {
|
|
|
1280
1270
|
if (this.correlationIdMiddleware) middlewares.push(this.correlationIdMiddleware);
|
|
1281
1271
|
if (this.userAgentMiddleware) middlewares.push(this.userAgentMiddleware);
|
|
1282
1272
|
if (this.authMiddleware) middlewares.push(this.authMiddleware);
|
|
1283
|
-
if (this.loggerMiddleware) middlewares.push(this.loggerMiddleware);
|
|
1284
1273
|
if (this.queueMiddleware) middlewares.push(this.queueMiddleware);
|
|
1285
1274
|
if (this.httpMiddleware) middlewares.push(this.httpMiddleware);
|
|
1275
|
+
if (this.loggerMiddleware) middlewares.push(this.loggerMiddleware);
|
|
1286
1276
|
return createClient({
|
|
1287
1277
|
middlewares
|
|
1288
1278
|
});
|