@commercetools/sdk-client-v2 1.4.1 → 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 +7 -0
- package/dist/commercetools-sdk-client-v2.browser.cjs.js +30 -41
- package/dist/commercetools-sdk-client-v2.browser.esm.js +30 -41
- package/dist/commercetools-sdk-client-v2.cjs.dev.js +30 -41
- package/dist/commercetools-sdk-client-v2.cjs.prod.js +30 -41
- package/dist/commercetools-sdk-client-v2.esm.js +30 -41
- package/dist/commercetools-sdk-client-v2.umd.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
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
|
+
|
|
3
10
|
## 1.4.1
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -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,7 +226,7 @@ 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.
|
|
@@ -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,
|
|
@@ -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) {
|
|
@@ -793,10 +797,10 @@ function createHttpMiddleware({
|
|
|
793
797
|
} // Ensure body is a string if content type is application/json
|
|
794
798
|
|
|
795
799
|
|
|
796
|
-
const body = ['application/json', 'application/graphql'].indexOf(requestHeader['Content-Type']) > -1 && typeof request.body === 'string' ||
|
|
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,7 +1008,7 @@ function createQueueMiddleware({
|
|
|
1019
1008
|
|
|
1020
1009
|
var packageJson = {
|
|
1021
1010
|
name: "@commercetools/sdk-client-v2",
|
|
1022
|
-
version: "1.4.
|
|
1011
|
+
version: "1.4.2",
|
|
1023
1012
|
description: "commercetools Composable Commerce TypeScript SDK client.",
|
|
1024
1013
|
keywords: [
|
|
1025
1014
|
"commercetools",
|
|
@@ -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,7 +217,7 @@ 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.
|
|
@@ -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,
|
|
@@ -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) {
|
|
@@ -784,10 +788,10 @@ function createHttpMiddleware({
|
|
|
784
788
|
} // Ensure body is a string if content type is application/json
|
|
785
789
|
|
|
786
790
|
|
|
787
|
-
const body = ['application/json', 'application/graphql'].indexOf(requestHeader['Content-Type']) > -1 && typeof request.body === 'string' ||
|
|
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,7 +999,7 @@ function createQueueMiddleware({
|
|
|
1010
999
|
|
|
1011
1000
|
var packageJson = {
|
|
1012
1001
|
name: "@commercetools/sdk-client-v2",
|
|
1013
|
-
version: "1.4.
|
|
1002
|
+
version: "1.4.2",
|
|
1014
1003
|
description: "commercetools Composable Commerce TypeScript SDK client.",
|
|
1015
1004
|
keywords: [
|
|
1016
1005
|
"commercetools",
|
|
@@ -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,7 +226,7 @@ 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.
|
|
@@ -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,
|
|
@@ -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) {
|
|
@@ -793,10 +797,10 @@ function createHttpMiddleware({
|
|
|
793
797
|
} // Ensure body is a string if content type is application/json
|
|
794
798
|
|
|
795
799
|
|
|
796
|
-
const body = ['application/json', 'application/graphql'].indexOf(requestHeader['Content-Type']) > -1 && typeof request.body === 'string' ||
|
|
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,7 +1008,7 @@ function createQueueMiddleware({
|
|
|
1019
1008
|
|
|
1020
1009
|
var packageJson = {
|
|
1021
1010
|
name: "@commercetools/sdk-client-v2",
|
|
1022
|
-
version: "1.4.
|
|
1011
|
+
version: "1.4.2",
|
|
1023
1012
|
description: "commercetools Composable Commerce TypeScript SDK client.",
|
|
1024
1013
|
keywords: [
|
|
1025
1014
|
"commercetools",
|
|
@@ -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,7 +226,7 @@ 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.
|
|
@@ -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,
|
|
@@ -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) {
|
|
@@ -793,10 +797,10 @@ function createHttpMiddleware({
|
|
|
793
797
|
} // Ensure body is a string if content type is application/json
|
|
794
798
|
|
|
795
799
|
|
|
796
|
-
const body = ['application/json', 'application/graphql'].indexOf(requestHeader['Content-Type']) > -1 && typeof request.body === 'string' ||
|
|
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,7 +1008,7 @@ function createQueueMiddleware({
|
|
|
1019
1008
|
|
|
1020
1009
|
var packageJson = {
|
|
1021
1010
|
name: "@commercetools/sdk-client-v2",
|
|
1022
|
-
version: "1.4.
|
|
1011
|
+
version: "1.4.2",
|
|
1023
1012
|
description: "commercetools Composable Commerce TypeScript SDK client.",
|
|
1024
1013
|
keywords: [
|
|
1025
1014
|
"commercetools",
|
|
@@ -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,7 +217,7 @@ 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.
|
|
@@ -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,
|
|
@@ -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) {
|
|
@@ -784,10 +788,10 @@ function createHttpMiddleware({
|
|
|
784
788
|
} // Ensure body is a string if content type is application/json
|
|
785
789
|
|
|
786
790
|
|
|
787
|
-
const body = ['application/json', 'application/graphql'].indexOf(requestHeader['Content-Type']) > -1 && typeof request.body === 'string' ||
|
|
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,7 +999,7 @@ function createQueueMiddleware({
|
|
|
1010
999
|
|
|
1011
1000
|
var packageJson = {
|
|
1012
1001
|
name: "@commercetools/sdk-client-v2",
|
|
1013
|
-
version: "1.4.
|
|
1002
|
+
version: "1.4.2",
|
|
1014
1003
|
description: "commercetools Composable Commerce TypeScript SDK client.",
|
|
1015
1004
|
keywords: [
|
|
1016
1005
|
"commercetools",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["@commercetools/sdk-client-v2"]=t():e["@commercetools/sdk-client-v2"]=t()}(self,(()=>(()=>{var e={754:()=>{},169:()=>{},872:()=>{},696:()=>{},305:()=>{},52:()=>{},392:(e,t,r)=>{"use strict";r.d(t,{Z:()=>C});var n=r(872),o=r.n(n),i=r(202),a=r(584),s=r(554),c=r(352),u=r(637),l=r(589),h=r(386),d=r(349),f=r(357),p=r(324),y=r(406),w=function(){return w=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},w.apply(this,arguments)},v=u.Z,g=a.Z,b=s.Z,m=l.Z,j=c.Z;const C=function(){function e(){this.middlewares=[]}return e.prototype.withProjectKey=function(e){return this.projectKey=e,this},e.prototype.defaultClient=function(e,t,r,n){return this.withClientCredentialsFlow({host:r,projectKey:n||this.projectKey,credentials:t}).withHttpMiddleware({host:e,fetch:o()}).withLoggerMiddleware()},e.prototype.withAuthMiddleware=function(e){return this.authMiddleware=e,this},e.prototype.withMiddleware=function(e){return this.middlewares.push(e),this},e.prototype.withClientCredentialsFlow=function(e){return this.withAuthMiddleware(b(w({host:e.host||"https://auth.europe-west1.gcp.commercetools.com",projectKey:e.projectKey||this.projectKey,credentials:{clientId:e.credentials.clientId||"",clientSecret:e.credentials.clientSecret||""},oauthUri:e.oauthUri||"",scopes:e.scopes,fetch:e.fetch||o()},e)))},e.prototype.withPasswordFlow=function(e){return this.withAuthMiddleware(v(w({host:e.host||"https://auth.europe-west1.gcp.commercetools.com",projectKey:e.projectKey||this.projectKey,credentials:{clientId:e.credentials.clientId||"",clientSecret:e.credentials.clientSecret||"",user:{username:e.credentials.user.username||"",password:e.credentials.user.password||""}},fetch:e.fetch||o()},e)))},e.prototype.withAnonymousSessionFlow=function(e){return this.withAuthMiddleware(g(w({host:e.host||"https://auth.europe-west1.gcp.commercetools.com",projectKey:this.projectKey||e.projectKey,credentials:{clientId:e.credentials.clientId||"",clientSecret:e.credentials.clientSecret||"",anonymousId:e.credentials.anonymousId||""},fetch:e.fetch||o()},e)))},e.prototype.withRefreshTokenFlow=function(e){return this.withAuthMiddleware(m(w({host:e.host||"https://auth.europe-west1.gcp.commercetools.com",projectKey:this.projectKey||e.projectKey,credentials:{clientId:e.credentials.clientId||"",clientSecret:e.credentials.clientSecret||""},fetch:e.fetch||o(),refreshToken:e.refreshToken||""},e)))},e.prototype.withExistingTokenFlow=function(e,t){return this.withAuthMiddleware(j(e,w({force:t.force||!0},t)))},e.prototype.withHttpMiddleware=function(e){return this.httpMiddleware=(0,d.Z)(w({host:e.host||"https://api.europe-west1.gcp.commercetools.com",fetch:e.fetch||o()},e)),this},e.prototype.withUserAgentMiddleware=function(e){return this.userAgentMiddleware=(0,y.Z)(e),this},e.prototype.withQueueMiddleware=function(e){return this.queueMiddleware=(0,p.Z)(w({concurrency:e.concurrency||20},e)),this},e.prototype.withLoggerMiddleware=function(){return this.loggerMiddleware=(0,f.Z)(),this},e.prototype.withCorrelationIdMiddleware=function(e){return this.correlationIdMiddleware=(0,h.Z)(w({generate:e.generate||null},e)),this},e.prototype.build=function(){var e=this.middlewares.slice();return this.correlationIdMiddleware&&e.push(this.correlationIdMiddleware),this.userAgentMiddleware&&e.push(this.userAgentMiddleware),this.authMiddleware&&e.push(this.authMiddleware),this.queueMiddleware&&e.push(this.queueMiddleware),this.httpMiddleware&&e.push(this.httpMiddleware),this.loggerMiddleware&&e.push(this.loggerMiddleware),(0,i.Z)({middlewares:e})},e}()},202:(e,t,r)=>{"use strict";r.d(t,{Z:()=>h,N:()=>l});var n=r(305),o=r.n(n);const i=["ACL","BIND","CHECKOUT","CONNECT","COPY","DELETE","GET","HEAD","LINK","LOCK","M-SEARCH","MERGE","MKACTIVITY","MKCALENDAR","MKCOL","MOVE","NOTIFY","OPTIONS","PATCH","POST","PROPFIND","PROPPATCH","PURGE","PUT","REBIND","REPORT","SEARCH","SOURCE","SUBSCRIBE","TRACE","UNBIND","UNLINK","UNLOCK","UNSUBSCRIBE"];function a(e,t,r){if(void 0===r&&(r={allowedMethods:i}),!t)throw new Error('The "'.concat(e,'" function requires a "Request" object as an argument. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest'));if("string"!=typeof t.uri)throw new Error('The "'.concat(e,'" Request object requires a valid uri. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest'));if(!r.allowedMethods.includes(t.method))throw new Error('The "'.concat(e,'" Request object requires a valid method. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest'))}var s,c=function(){return c=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},c.apply(this,arguments)};function u(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return 1===(e=e.filter((function(e){return"function"==typeof e}))).length?e[0]:e.reduce((function(e,t){return function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return e(t.apply(void 0,r))}}))}function l(e,t,r){var n=this;if(a("process",e,{allowedMethods:["GET"]}),"function"!=typeof t)throw new Error('The "process" function accepts a "Function" as a second argument that returns a Promise. See https://commercetools.github.io/nodejs/sdk/api/sdkClient.html#processrequest-processfn-options');var i=c({total:Number.POSITIVE_INFINITY,accumulate:!0},r);return new Promise((function(r,a){var u,l="";if(e&&e.uri){var d=e.uri.split("?"),f=d[0],p=d[1];u=f,l=p}var y=c({},o().parse(l)),w=c({limit:20},y),v=!1,g=i.total,b=function(l,d){return void 0===d&&(d=[]),f=n,p=void 0,m=function(){var n,f,p,y,m,j,C,O,M,E,k,A,T,q;return function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}(this,(function(S){switch(S.label){case 0:n=w.limit<g?w.limit:g,f=o().stringify(c(c({},w),{limit:n})),p=c({sort:"id asc",withTotal:!1},l?{where:'id > "'.concat(l,'"')}:{}),y=o().stringify(p),m=c(c({},e),{uri:"".concat(u,"?").concat(y,"&").concat(f)}),S.label=1;case 1:return S.trys.push([1,4,,5]),[4,h(s).execute(m)];case 2:return j=S.sent(),C=j.body,O=C.results,!(M=C.count)&&v?[2,r(d||[])]:[4,Promise.resolve(t(j))];case 3:return E=S.sent(),k=void 0,v=!0,i.accumulate&&(k=d.concat(E||[])),g-=M,M<w.limit||!g?[2,r(k||[])]:(A=O[M-1],T=A&&A.id,b(T,k),[3,5]);case 4:return q=S.sent(),a(q),[3,5];case 5:return[2]}}))},new((y=void 0)||(y=Promise))((function(e,t){function r(e){try{o(m.next(e))}catch(e){t(e)}}function n(e){try{o(m.throw(e))}catch(e){t(e)}}function o(t){var o;t.done?e(t.value):(o=t.value,o instanceof y?o:new y((function(e){e(o)}))).then(r,n)}o((m=m.apply(f,p||[])).next())}));var f,p,y,m};b()}))}function h(e){if(s=e,!e)throw new Error("Missing required options");if(e.middlewares&&!Array.isArray(e.middlewares))throw new Error("Middlewares should be an array");if(!e.middlewares||!Array.isArray(e.middlewares)||!e.middlewares.length)throw new Error("You need to provide at least one middleware");return{process:l,execute:function(t){return a("exec",t),new Promise((function(r,n){u.apply(void 0,e.middlewares)((function(e,t){if(t.error)t.reject(t.error);else{var r={body:t.body||{},statusCode:t.statusCode};t.headers&&(r.headers=t.headers),t.request&&(r.request=t.request),t.resolve(r)}}))(t,{resolve:r,reject:n,body:void 0,error:void 0})}))}}}},109:(e,t,r)=>{"use strict";r.d(t,{F7:()=>i,ZP:()=>p,oo:()=>a});var n=function(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))};function o(e,t,r){void 0===r&&(r={}),this.status=this.statusCode=this.code=e,this.message=t,Object.assign(this,r),this.name=this.constructor.name,this.constructor.prototype.__proto__=Error.prototype,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}function i(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,0],e,!1))}function a(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this],e,!1))}function s(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,400],e,!1))}function c(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,401],e,!1))}function u(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,403],e,!1))}function l(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,404],e,!1))}function h(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,409],e,!1))}function d(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,500],e,!1))}function f(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,503],e,!1))}function p(e){switch(e){case 0:return i;case 400:return s;case 401:return c;case 403:return u;case 404:return l;case 409:return h;case 500:return d;case 503:return f;default:return}}},584:(e,t,r)=>{"use strict";r.d(t,{Z:()=>s});var n=r(893),o=r(935),i=r(156),a=function(){return a=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},a.apply(this,arguments)};function s(e){var t=(0,i.Z)({}),r=[],s=(0,i.Z)(!1);return function(i){return function(c,u){if(c.headers&&c.headers.authorization||c.headers&&c.headers.Authorization)i(c,u);else{var l=a(a({request:c,response:u},(0,o.Vk)(e)),{pendingTasks:r,requestState:s,tokenCache:t,fetch:e.fetch});(0,n.Z)(l,i,e)}}}}},893:(e,t,r)=>{"use strict";r.d(t,{Z:()=>c});var n=r(935),o=function(){return o=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},o.apply(this,arguments)},i=r(754).Buffer;function a(e,t){return o(o({},t),{headers:o(o({},t.headers),{Authorization:"Bearer ".concat(e)})})}function s(e){var t,r,n,o,s=e.fetcher,c=e.url,u=e.basicAuth,l=e.body,h=e.tokenCache,d=e.requestState,f=e.pendingTasks,p=e.response,y=e.tokenCacheKey;return t=this,r=void 0,o=function(){var e,t,r,n,o,w,v,g,b,m,j;return function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}(this,(function(C){switch(C.label){case 0:return C.trys.push([0,5,,6]),[4,s(c,{method:"POST",headers:{Authorization:"Basic ".concat(u),"Content-Length":i.byteLength(l).toString(),"Content-Type":"application/x-www-form-urlencoded"},body:l})];case 1:return(e=C.sent()).ok?[4,e.json()]:[3,3];case 2:return t=C.sent(),r=t.access_token,n=t.expires_in,o=t.refresh_token,w=function(e){return Date.now()+1e3*e-3e5}(n),h.set({token:r,expirationTime:w,refreshToken:o},y),d.set(!1),v=f.slice(),f=[],v.forEach((function(e){var t=a(r,e.request);e.next(t,e.response)})),[2];case 3:return g=void 0,[4,e.text()];case 4:b=C.sent();try{g=JSON.parse(b)}catch(e){}return m=new Error(g?g.message:b),g&&(m.body=g),d.set(!1),p.reject(m),[3,6];case 5:return j=C.sent(),d.set(!1),p&&"function"==typeof p.reject&&p.reject(j),[3,6];case 6:return[2]}}))},new((n=void 0)||(n=Promise))((function(e,i){function a(e){try{c(o.next(e))}catch(e){i(e)}}function s(e){try{c(o.throw(e))}catch(e){i(e)}}function c(t){var r;t.done?e(t.value):(r=t.value,r instanceof n?r:new n((function(e){e(r)}))).then(a,s)}c((o=o.apply(t,r||[])).next())}))}function c(e,t,r){var i=e.request,c=e.response,u=e.url,l=e.basicAuth,h=e.body,d=e.pendingTasks,f=e.requestState,p=e.tokenCache,y=e.tokenCacheKey,w=e.fetch;if(!w&&"undefined"==typeof fetch)throw new Error("`fetch` is not available. Please pass in `fetch` as an option or have it globally available.");if(w||(w=fetch),i.headers&&i.headers.authorization||i.headers&&i.headers.Authorization)t(i,c);else{var v=p.get(y);if(v&&v.token&&Date.now()<v.expirationTime)t(a(v.token,i),c);else if(d.push({request:i,response:c,next:t}),!f.get())if(f.set(!0),v&&v.refreshToken&&(!v.token||v.token&&Date.now()>v.expirationTime)){if(!r)throw new Error("Missing required options");s(o(o({fetcher:w},(0,n.Um)(o(o({},r),{refreshToken:v.refreshToken}))),{tokenCacheKey:y,tokenCache:p,requestState:f,pendingTasks:d,response:c}))}else s({fetcher:w,url:u,basicAuth:l,body:h,tokenCacheKey:y,tokenCache:p,requestState:f,pendingTasks:d,response:c})}}},935:(e,t,r)=>{"use strict";r.d(t,{BB:()=>i,Um:()=>s,Vk:()=>c,_T:()=>a});var n=function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)},o=r(754).Buffer;function i(e){if(!e)throw new Error("Missing required options");if(!e.host)throw new Error("Missing required option (host)");if(!e.projectKey)throw new Error("Missing required option (projectKey)");if(!e.credentials)throw new Error("Missing required option (credentials)");var t=e.credentials,r=t.clientId,n=t.clientSecret;if(!r||!n)throw new Error("Missing required credentials (clientId, clientSecret)");var i=e.scopes?e.scopes.join(" "):void 0,a=o.from("".concat(r,":").concat(n)).toString("base64"),s=e.oauthUri||"/oauth/token";return{basicAuth:a,url:e.host.replace(/\/$/,"")+s,body:"grant_type=client_credentials".concat(i?"&scope=".concat(i):"")}}function a(e){if(!e)throw new Error("Missing required options");if(!e.host)throw new Error("Missing required option (host)");if(!e.projectKey)throw new Error("Missing required option (projectKey)");if(!e.credentials)throw new Error("Missing required option (credentials)");var t=e.credentials,r=t.clientId,n=t.clientSecret,i=t.user,a=e.projectKey;if(!(r&&n&&i))throw new Error("Missing required credentials (clientId, clientSecret, user)");var s=i.username,c=i.password;if(!s||!c)throw new Error("Missing required user credentials (username, password)");var u=(e.scopes||[]).join(" "),l=u?"&scope=".concat(u):"",h=o.from("".concat(r,":").concat(n)).toString("base64"),d=e.oauthUri||"/oauth/".concat(a,"/customers/token");return{basicAuth:h,url:e.host.replace(/\/$/,"")+d,body:"grant_type=password&username=".concat(encodeURIComponent(s),"&password=").concat(encodeURIComponent(c)).concat(l)}}function s(e){if(!e)throw new Error("Missing required options");if(!e.host)throw new Error("Missing required option (host)");if(!e.projectKey)throw new Error("Missing required option (projectKey)");if(!e.credentials)throw new Error("Missing required option (credentials)");if(!e.refreshToken)throw new Error("Missing required option (refreshToken)");var t=e.credentials,r=t.clientId,n=t.clientSecret;if(!r||!n)throw new Error("Missing required credentials (clientId, clientSecret)");var i=o.from("".concat(r,":").concat(n)).toString("base64"),a=e.oauthUri||"/oauth/token";return{basicAuth:i,url:e.host.replace(/\/$/,"")+a,body:"grant_type=refresh_token&refresh_token=".concat(encodeURIComponent(e.refreshToken))}}function c(e){if(!e)throw new Error("Missing required options");if(!e.projectKey)throw new Error("Missing required option (projectKey)");var t=e.projectKey;e.oauthUri=e.oauthUri||"/oauth/".concat(t,"/anonymous/token");var r=i(e);return e.credentials.anonymousId&&(r.body+="&anonymous_id=".concat(e.credentials.anonymousId)),n({},r)}},554:(e,t,r)=>{"use strict";r.d(t,{Z:()=>c});var n=r(893),o=r(935);function i(e){return{clientId:e.credentials.clientId,host:e.host,projectKey:e.projectKey}}var a=r(156),s=function(){return s=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},s.apply(this,arguments)};function c(e){var t=e.tokenCache||(0,a.Z)({token:"",expirationTime:-1}),r=(0,a.Z)(!1),c=[];return function(a){return function(u,l){if(u.headers&&u.headers.authorization||u.headers&&u.headers.Authorization)a(u,l);else{var h=s(s({request:u,response:l},(0,o.BB)(e)),{pendingTasks:c,requestState:r,tokenCache:t,tokenCacheKey:i(e),fetch:e.fetch});(0,n.Z)(h,a)}}}}},352:(e,t,r)=>{"use strict";r.d(t,{Z:()=>o});var n=function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)};function o(e,t){return void 0===e&&(e=""),void 0===t&&(t={}),function(r){return function(o,i){if("string"!=typeof e)throw new Error("authorization must be a string");var a=void 0===t.force||t.force;if(!e||(o.headers&&o.headers.authorization||o.headers&&o.headers.Authorization)&&!1===a)return r(o,i);var s=n(n({},o),{headers:n(n({},o.headers),{Authorization:e})});return r(s,i)}}}},637:(e,t,r)=>{"use strict";r.d(t,{Z:()=>s});var n=r(893),o=r(935),i=r(156),a=function(){return a=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},a.apply(this,arguments)};function s(e){var t=(0,i.Z)({}),r=[],s=(0,i.Z)(!1);return function(i){return function(c,u){if(c.headers&&c.headers.authorization||c.headers&&c.headers.Authorization)i(c,u);else{var l=a(a({request:c,response:u},(0,o._T)(e)),{pendingTasks:r,requestState:s,tokenCache:t,fetch:e.fetch});(0,n.Z)(l,i,e)}}}}},589:(e,t,r)=>{"use strict";r.d(t,{Z:()=>s});var n=r(893),o=r(935),i=r(156),a=function(){return a=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},a.apply(this,arguments)};function s(e){var t=(0,i.Z)({}),r=[],s=(0,i.Z)(!1);return function(i){return function(c,u){if(c.headers&&c.headers.authorization||c.headers&&c.headers.Authorization)i(c,u);else{var l=a(a({request:c,response:u},(0,o.Um)(e)),{pendingTasks:r,requestState:s,tokenCache:t,fetch:e.fetch});(0,n.Z)(l,i)}}}}},156:(e,t,r)=>{"use strict";function n(e){var t=e;return{get:function(){return t},set:function(e){return t=e}}}r.d(t,{Z:()=>n})},386:(e,t,r)=>{"use strict";r.d(t,{Z:()=>o});var n=function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)};function o(e){return function(t){return function(r,o){var i=n(n({},r),{headers:n(n({},r.headers),{"X-Correlation-ID":e.generate()})});t(i,o)}}}},349:(e,t,r)=>{"use strict";r.d(t,{Z:()=>u});var n=r(109);function o(e){if(e.raw)return e.raw();if(!e.forEach)return{};var t={};return e.forEach((function(e,r){t[r]=e})),t}var i=function(){return i=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},i.apply(this,arguments)},a=r(754).Buffer;function s(e,t,r,n,o){return n&&0!==e?Math.min(Math.round((Math.random()+1)*t*Math.pow(2,e)),o):t}function c(e,t){t&&(e&&e.headers&&e.headers.authorization&&(e.headers.authorization="Bearer ********"),e&&e.headers&&e.headers.Authorization&&(e.headers.Authorization="Bearer ********"))}function u(e){var t,r=e.host,u=e.credentialsMode,l=e.includeResponseHeaders,h=e.includeOriginalRequest,d=e.includeRequestInErrorResponse,f=void 0===d||d,p=e.maskSensitiveHeaderData,y=void 0===p||p,w=e.enableRetry,v=e.timeout,g=e.retryConfig,b=void 0===g?{}:g,m=b.maxRetries,j=void 0===m?10:m,C=b.backoff,O=void 0===C||C,M=b.retryDelay,E=void 0===M?200:M,k=b.maxDelay,A=void 0===k?1/0:k,T=b.retryCodes,q=void 0===T?[503]:T,S=e.fetch,P=e.getAbortController;if(!S&&"undefined"==typeof fetch)throw new Error("`fetch` is not available. Please pass in `fetch` as an option or have it globally available.");if(v&&!P&&"undefined"==typeof AbortController)throw new Error("`AbortController` is not available. Please pass in `getAbortController` as an option or have AbortController globally available when using timeout.");if(t=S||fetch,!Array.isArray(q))throw new Error("`retryCodes` option must be an array of retry status (error) codes.");return function(e){return function(d,p){var g;(v||P)&&(g=(P?P():null)||new AbortController);var b=r.replace(/\/$/,"")+d.uri,m=i({},d.headers);null===m["Content-Type"]&&delete m["Content-Type"],Object.prototype.hasOwnProperty.call(m,"Content-Type")||Object.prototype.hasOwnProperty.call(m,"content-type")||(m["Content-Type"]="application/json");var C=["application/json","application/graphql"].indexOf(m["Content-Type"])>-1&&"string"==typeof d.body||a.isBuffer(d.body)?d.body:JSON.stringify(d.body||void 0);C&&("string"==typeof C||a.isBuffer(C))&&(m["Content-Length"]=a.byteLength(C).toString());var M={method:d.method,headers:m};u&&(M.credentialsMode=u),g&&(M.signal=g.signal),C&&(M.body=C);var k=0;!function r(){var a;v&&(a=setTimeout((function(){g.abort()}),v)),t(b,M).then((function(t){if(t.ok)return"HEAD"===M.method?void e(d,i(i({},p),{statusCode:t.status})):void t.text().then((function(n){var a;try{a=n.length>0?JSON.parse(n):{}}catch(e){if(w&&k<j)return setTimeout(r,s(k,E,0,O,A)),void(k+=1);a=n}var u=i(i({},p),{body:a,statusCode:t.status});l&&(u.headers=o(t.headers)),h&&(u.request=i({},M),c(u.request,y)),e(d,u)}));t.text().then((function(a){var u;try{u=JSON.parse(a)}catch(l){u=a}var l=function(e){var t=e.statusCode,r=e.message,o=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}(e,["statusCode","message"]),i=r||"Unexpected non-JSON error response";404===t&&(i="URI not found: ".concat(o.originalRequest.uri));var a=(0,n.ZP)(t);return a?new a(i,o):new n.oo(t,i,o)}(i(i(i({statusCode:t.status},f?{originalRequest:d}:{}),{retryCount:k,headers:o(t.headers)}),"object"==typeof u?{message:u.message,body:u}:{message:u,body:u}));if(w&&(-1!==q.indexOf(l.statusCode)||-1!==(null==q?void 0:q.indexOf(l.message)))&&k<j)return setTimeout(r,s(k,E,0,O,A)),void(k+=1);c(l.originalRequest,y);var h=i(i({},p),{error:l,statusCode:t.status});e(d,h)}))}),(function(t){if(w&&k<j)return setTimeout(r,s(k,E,0,O,A)),void(k+=1);var o=new n.F7(t.message,i(i({},f?{originalRequest:d}:{}),{retryCount:k}));c(o.originalRequest,y),e(d,i(i({},p),{error:o,statusCode:0}))})).finally((function(){clearTimeout(a)}))}()}}}},357:(e,t,r)=>{"use strict";r.d(t,{Z:()=>o});var n=r(169);function o(){return function(e){return function(t,r){var o=r.error,i=r.body,a=r.statusCode;n.log("Request: ",t),n.log("Response: ",{error:o,body:i,statusCode:a}),e(t,r)}}}},324:(e,t,r)=>{"use strict";r.d(t,{Z:()=>o});var n=function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)};function o(e){var t=e.concurrency,r=void 0===t?20:t,o=[],i=0,a=function(e){if(i-=1,o.length&&i<=r){var t=o.shift();i+=1,e(t.request,t.response)}};return function(e){return function(t,s){var c=n(n({},s),{resolve:function(t){s.resolve(t),a(e)},reject:function(t){s.reject(t),a(e)}});if(o.push({request:t,response:c}),i<r){var u=o.shift();i+=1,e(u.request,u.response)}}}}},406:(e,t,r)=>{"use strict";r.d(t,{Z:()=>a});var n=r(696);function o(){if("undefined"!=typeof window&&window.document&&9===window.document.nodeType)return window.navigator.userAgent;var e=(null==n?void 0:n.version.slice(1))||"12";return"node.js/".concat(e)}var i=function(){return i=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},i.apply(this,arguments)};function a(e){var t=function(e){if(!e||0===Object.keys(e).length||!{}.hasOwnProperty.call(e,"name"))throw new Error("Missing required option `name`");var t=e.version?"".concat(e.name,"/").concat(e.version):e.name,r=null;e.libraryName&&!e.libraryVersion?r=e.libraryName:e.libraryName&&e.libraryVersion&&(r="".concat(e.libraryName,"/").concat(e.libraryVersion));var n=null;return e.contactUrl&&!e.contactEmail?n="(+".concat(e.contactUrl,")"):!e.contactUrl&&e.contactEmail?n="(+".concat(e.contactEmail,")"):e.contactUrl&&e.contactEmail&&(n="(+".concat(e.contactUrl,"; +").concat(e.contactEmail,")")),[t,o(),r,n,e.customAgent||""].filter(Boolean).join(" ")}(i(i({},e),{name:"commercetools-sdk-javascript-v2/".concat("1.4.1")}));return function(e){return function(r,n){var o=i(i({},r),{headers:i(i({},r.headers),{"User-Agent":t})});e(o,n)}}}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{"use strict";r.r(n),r.d(n,{ClientBuilder:()=>e.Z,Process:()=>t.N,createAuthForAnonymousSessionFlow:()=>i.Z,createAuthForClientCredentialsFlow:()=>a.Z,createAuthForPasswordFlow:()=>c.Z,createAuthForRefreshTokenFlow:()=>u.Z,createAuthWithExistingToken:()=>s.Z,createClient:()=>t.Z,createCorrelationIdMiddleware:()=>l.Z,createHttpClient:()=>h.Z,createLoggerMiddleware:()=>d.Z,createQueueMiddleware:()=>f.Z,createUserAgentMiddleware:()=>p.Z,getErrorByCode:()=>o.ZP});var e=r(392),t=r(202),o=r(109),i=r(584),a=r(554),s=r(352),c=r(637),u=r(589),l=r(386),h=r(349),d=r(357),f=r(324),p=r(406),y=r(52),w={};for(const e in y)["default","ClientBuilder","createClient","Process","getErrorByCode","createAuthForAnonymousSessionFlow","createAuthForClientCredentialsFlow","createAuthWithExistingToken","createAuthForPasswordFlow","createAuthForRefreshTokenFlow","createCorrelationIdMiddleware","createHttpClient","createLoggerMiddleware","createQueueMiddleware","createUserAgentMiddleware"].indexOf(e)<0&&(w[e]=()=>y[e]);r.d(n,w)})(),n})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["@commercetools/sdk-client-v2"]=t():e["@commercetools/sdk-client-v2"]=t()}(self,(()=>(()=>{var e={754:()=>{},169:()=>{},872:()=>{},696:()=>{},305:()=>{},52:()=>{},392:(e,t,r)=>{"use strict";r.d(t,{Z:()=>C});var n=r(872),o=r.n(n),i=r(202),a=r(584),s=r(554),c=r(352),u=r(637),l=r(589),h=r(386),d=r(349),f=r(357),p=r(324),y=r(406),w=function(){return w=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},w.apply(this,arguments)},v=u.Z,g=a.Z,m=s.Z,b=l.Z,j=c.Z;const C=function(){function e(){this.middlewares=[]}return e.prototype.withProjectKey=function(e){return this.projectKey=e,this},e.prototype.defaultClient=function(e,t,r,n){return this.withClientCredentialsFlow({host:r,projectKey:n||this.projectKey,credentials:t}).withHttpMiddleware({host:e,fetch:o()}).withLoggerMiddleware()},e.prototype.withAuthMiddleware=function(e){return this.authMiddleware=e,this},e.prototype.withMiddleware=function(e){return this.middlewares.push(e),this},e.prototype.withClientCredentialsFlow=function(e){return this.withAuthMiddleware(m(w({host:e.host||"https://auth.europe-west1.gcp.commercetools.com",projectKey:e.projectKey||this.projectKey,credentials:{clientId:e.credentials.clientId||"",clientSecret:e.credentials.clientSecret||""},oauthUri:e.oauthUri||"",scopes:e.scopes,fetch:e.fetch||o()},e)))},e.prototype.withPasswordFlow=function(e){return this.withAuthMiddleware(v(w({host:e.host||"https://auth.europe-west1.gcp.commercetools.com",projectKey:e.projectKey||this.projectKey,credentials:{clientId:e.credentials.clientId||"",clientSecret:e.credentials.clientSecret||"",user:{username:e.credentials.user.username||"",password:e.credentials.user.password||""}},fetch:e.fetch||o()},e)))},e.prototype.withAnonymousSessionFlow=function(e){return this.withAuthMiddleware(g(w({host:e.host||"https://auth.europe-west1.gcp.commercetools.com",projectKey:this.projectKey||e.projectKey,credentials:{clientId:e.credentials.clientId||"",clientSecret:e.credentials.clientSecret||"",anonymousId:e.credentials.anonymousId||""},fetch:e.fetch||o()},e)))},e.prototype.withRefreshTokenFlow=function(e){return this.withAuthMiddleware(b(w({host:e.host||"https://auth.europe-west1.gcp.commercetools.com",projectKey:this.projectKey||e.projectKey,credentials:{clientId:e.credentials.clientId||"",clientSecret:e.credentials.clientSecret||""},fetch:e.fetch||o(),refreshToken:e.refreshToken||""},e)))},e.prototype.withExistingTokenFlow=function(e,t){return this.withAuthMiddleware(j(e,w({force:t.force||!0},t)))},e.prototype.withHttpMiddleware=function(e){return this.httpMiddleware=(0,d.Z)(w({host:e.host||"https://api.europe-west1.gcp.commercetools.com",fetch:e.fetch||o()},e)),this},e.prototype.withUserAgentMiddleware=function(e){return this.userAgentMiddleware=(0,y.Z)(e),this},e.prototype.withQueueMiddleware=function(e){return this.queueMiddleware=(0,p.Z)(w({concurrency:e.concurrency||20},e)),this},e.prototype.withLoggerMiddleware=function(){return this.loggerMiddleware=(0,f.Z)(),this},e.prototype.withCorrelationIdMiddleware=function(e){return this.correlationIdMiddleware=(0,h.Z)(w({generate:e.generate||null},e)),this},e.prototype.build=function(){var e=this.middlewares.slice();return this.correlationIdMiddleware&&e.push(this.correlationIdMiddleware),this.userAgentMiddleware&&e.push(this.userAgentMiddleware),this.authMiddleware&&e.push(this.authMiddleware),this.queueMiddleware&&e.push(this.queueMiddleware),this.httpMiddleware&&e.push(this.httpMiddleware),this.loggerMiddleware&&e.push(this.loggerMiddleware),(0,i.Z)({middlewares:e})},e}()},202:(e,t,r)=>{"use strict";r.d(t,{Z:()=>h,N:()=>l});var n=r(305),o=r.n(n);const i=["ACL","BIND","CHECKOUT","CONNECT","COPY","DELETE","GET","HEAD","LINK","LOCK","M-SEARCH","MERGE","MKACTIVITY","MKCALENDAR","MKCOL","MOVE","NOTIFY","OPTIONS","PATCH","POST","PROPFIND","PROPPATCH","PURGE","PUT","REBIND","REPORT","SEARCH","SOURCE","SUBSCRIBE","TRACE","UNBIND","UNLINK","UNLOCK","UNSUBSCRIBE"];function a(e,t,r){if(void 0===r&&(r={allowedMethods:i}),!t)throw new Error('The "'.concat(e,'" function requires a "Request" object as an argument. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest'));if("string"!=typeof t.uri)throw new Error('The "'.concat(e,'" Request object requires a valid uri. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest'));if(!r.allowedMethods.includes(t.method))throw new Error('The "'.concat(e,'" Request object requires a valid method. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest'))}var s,c=function(){return c=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},c.apply(this,arguments)};function u(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return 1===(e=e.filter((function(e){return"function"==typeof e}))).length?e[0]:e.reduce((function(e,t){return function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return e(t.apply(void 0,r))}}))}function l(e,t,r){var n=this;if(a("process",e,{allowedMethods:["GET"]}),"function"!=typeof t)throw new Error('The "process" function accepts a "Function" as a second argument that returns a Promise. See https://commercetools.github.io/nodejs/sdk/api/sdkClient.html#processrequest-processfn-options');var i=c({total:Number.POSITIVE_INFINITY,accumulate:!0},r);return new Promise((function(r,a){var u,l="";if(e&&e.uri){var d=e.uri.split("?"),f=d[0],p=d[1];u=f,l=p}var y=c({},o().parse(l)),w=c({limit:20},y),v=!1,g=i.total,m=function(l,d){return void 0===d&&(d=[]),f=n,p=void 0,b=function(){var n,f,p,y,b,j,C,O,M,E,k,T,A,q;return function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}(this,(function(S){switch(S.label){case 0:n=w.limit<g?w.limit:g,f=o().stringify(c(c({},w),{limit:n})),p=c({sort:"id asc",withTotal:!1},l?{where:'id > "'.concat(l,'"')}:{}),y=o().stringify(p),b=c(c({},e),{uri:"".concat(u,"?").concat(y,"&").concat(f)}),S.label=1;case 1:return S.trys.push([1,4,,5]),[4,h(s).execute(b)];case 2:return j=S.sent(),C=j.body,O=C.results,!(M=C.count)&&v?[2,r(d||[])]:[4,Promise.resolve(t(j))];case 3:return E=S.sent(),k=void 0,v=!0,i.accumulate&&(k=d.concat(E||[])),g-=M,M<w.limit||!g?[2,r(k||[])]:(T=O[M-1],A=T&&T.id,m(A,k),[3,5]);case 4:return q=S.sent(),a(q),[3,5];case 5:return[2]}}))},new((y=void 0)||(y=Promise))((function(e,t){function r(e){try{o(b.next(e))}catch(e){t(e)}}function n(e){try{o(b.throw(e))}catch(e){t(e)}}function o(t){var o;t.done?e(t.value):(o=t.value,o instanceof y?o:new y((function(e){e(o)}))).then(r,n)}o((b=b.apply(f,p||[])).next())}));var f,p,y,b};m()}))}function h(e){if(s=e,!e)throw new Error("Missing required options");if(e.middlewares&&!Array.isArray(e.middlewares))throw new Error("Middlewares should be an array");if(!e.middlewares||!Array.isArray(e.middlewares)||!e.middlewares.length)throw new Error("You need to provide at least one middleware");return{process:l,execute:function(t){return a("exec",t),new Promise((function(r,n){u.apply(void 0,e.middlewares)((function(e,t){if(t.error)t.reject(t.error);else{var r={body:t.body||{},statusCode:t.statusCode};t.headers&&(r.headers=t.headers),t.request&&(r.request=t.request),t.resolve(r)}}))(t,{resolve:r,reject:n,body:void 0,error:void 0})}))}}}},109:(e,t,r)=>{"use strict";r.d(t,{F7:()=>i,ZP:()=>p,oo:()=>a});var n=function(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))};function o(e,t,r){void 0===r&&(r={}),this.status=this.statusCode=this.code=e,this.message=t,Object.assign(this,r),this.name=this.constructor.name,this.constructor.prototype.__proto__=Error.prototype,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}function i(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,0],e,!1))}function a(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this],e,!1))}function s(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,400],e,!1))}function c(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,401],e,!1))}function u(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,403],e,!1))}function l(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,404],e,!1))}function h(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,409],e,!1))}function d(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,500],e,!1))}function f(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,503],e,!1))}function p(e){switch(e){case 0:return i;case 400:return s;case 401:return c;case 403:return u;case 404:return l;case 409:return h;case 500:return d;case 503:return f;default:return}}},584:(e,t,r)=>{"use strict";r.d(t,{Z:()=>s});var n=r(893),o=r(935),i=r(156),a=function(){return a=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},a.apply(this,arguments)};function s(e){var t=(0,i.Z)({}),r=[],s=(0,i.Z)(!1);return function(i){return function(c,u){if(c.headers&&c.headers.authorization||c.headers&&c.headers.Authorization)i(c,u);else{var l=a(a({request:c,response:u},(0,o.Vk)(e)),{pendingTasks:r,requestState:s,tokenCache:t,fetch:e.fetch});(0,n.Z)(l,i,e)}}}}},893:(e,t,r)=>{"use strict";r.d(t,{Z:()=>c});var n=r(935),o=function(){return o=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},o.apply(this,arguments)},i=r(754).Buffer;function a(e,t){return o(o({},t),{headers:o(o({},t.headers),{Authorization:"Bearer ".concat(e)})})}function s(e){var t,r,n,o,s=e.fetcher,c=e.url,u=e.basicAuth,l=e.body,h=e.tokenCache,d=e.requestState,f=e.pendingTasks,p=e.response,y=e.tokenCacheKey;return t=this,r=void 0,o=function(){var e,t,r,n,o,w,v,g,m,b,j;return function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}(this,(function(C){switch(C.label){case 0:return C.trys.push([0,5,,6]),[4,s(c,{method:"POST",headers:{Authorization:"Basic ".concat(u),"Content-Length":i.byteLength(l).toString(),"Content-Type":"application/x-www-form-urlencoded"},body:l})];case 1:return(e=C.sent()).ok?[4,e.json()]:[3,3];case 2:return t=C.sent(),r=t.access_token,n=t.expires_in,o=t.refresh_token,w=function(e){return Date.now()+1e3*e-3e5}(n),h.set({token:r,expirationTime:w,refreshToken:o},y),d.set(!1),v=f.slice(),f=[],v.forEach((function(e){var t=a(r,e.request);e.next(t,e.response)})),[2];case 3:return g=void 0,[4,e.text()];case 4:m=C.sent();try{g=JSON.parse(m)}catch(e){}return b=new Error(g?g.message:m),g&&(b.body=g),d.set(!1),p.reject(b),[3,6];case 5:return j=C.sent(),d.set(!1),p&&"function"==typeof p.reject&&p.reject(j),[3,6];case 6:return[2]}}))},new((n=void 0)||(n=Promise))((function(e,i){function a(e){try{c(o.next(e))}catch(e){i(e)}}function s(e){try{c(o.throw(e))}catch(e){i(e)}}function c(t){var r;t.done?e(t.value):(r=t.value,r instanceof n?r:new n((function(e){e(r)}))).then(a,s)}c((o=o.apply(t,r||[])).next())}))}function c(e,t,r){var i=e.request,c=e.response,u=e.url,l=e.basicAuth,h=e.body,d=e.pendingTasks,f=e.requestState,p=e.tokenCache,y=e.tokenCacheKey,w=e.fetch;if(!w&&"undefined"==typeof fetch)throw new Error("`fetch` is not available. Please pass in `fetch` as an option or have it globally available.");if(w||(w=fetch),i.headers&&i.headers.authorization||i.headers&&i.headers.Authorization)t(i,c);else{var v=p.get(y);if(v&&v.token&&Date.now()<v.expirationTime)t(a(v.token,i),c);else if(d.push({request:i,response:c,next:t}),!f.get())if(f.set(!0),v&&v.refreshToken&&(!v.token||v.token&&Date.now()>v.expirationTime)){if(!r)throw new Error("Missing required options");s(o(o({fetcher:w},(0,n.Um)(o(o({},r),{refreshToken:v.refreshToken}))),{tokenCacheKey:y,tokenCache:p,requestState:f,pendingTasks:d,response:c}))}else s({fetcher:w,url:u,basicAuth:l,body:h,tokenCacheKey:y,tokenCache:p,requestState:f,pendingTasks:d,response:c})}}},935:(e,t,r)=>{"use strict";r.d(t,{BB:()=>i,Um:()=>s,Vk:()=>c,_T:()=>a});var n=function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)},o=r(754).Buffer;function i(e){if(!e)throw new Error("Missing required options");if(!e.host)throw new Error("Missing required option (host)");if(!e.projectKey)throw new Error("Missing required option (projectKey)");if(!e.credentials)throw new Error("Missing required option (credentials)");var t=e.credentials,r=t.clientId,n=t.clientSecret;if(!r||!n)throw new Error("Missing required credentials (clientId, clientSecret)");var i=e.scopes?e.scopes.join(" "):void 0,a=o.from("".concat(r,":").concat(n)).toString("base64"),s=e.oauthUri||"/oauth/token";return{basicAuth:a,url:e.host.replace(/\/$/,"")+s,body:"grant_type=client_credentials".concat(i?"&scope=".concat(i):"")}}function a(e){if(!e)throw new Error("Missing required options");if(!e.host)throw new Error("Missing required option (host)");if(!e.projectKey)throw new Error("Missing required option (projectKey)");if(!e.credentials)throw new Error("Missing required option (credentials)");var t=e.credentials,r=t.clientId,n=t.clientSecret,i=t.user,a=e.projectKey;if(!(r&&n&&i))throw new Error("Missing required credentials (clientId, clientSecret, user)");var s=i.username,c=i.password;if(!s||!c)throw new Error("Missing required user credentials (username, password)");var u=(e.scopes||[]).join(" "),l=u?"&scope=".concat(u):"",h=o.from("".concat(r,":").concat(n)).toString("base64"),d=e.oauthUri||"/oauth/".concat(a,"/customers/token");return{basicAuth:h,url:e.host.replace(/\/$/,"")+d,body:"grant_type=password&username=".concat(encodeURIComponent(s),"&password=").concat(encodeURIComponent(c)).concat(l)}}function s(e){if(!e)throw new Error("Missing required options");if(!e.host)throw new Error("Missing required option (host)");if(!e.projectKey)throw new Error("Missing required option (projectKey)");if(!e.credentials)throw new Error("Missing required option (credentials)");if(!e.refreshToken)throw new Error("Missing required option (refreshToken)");var t=e.credentials,r=t.clientId,n=t.clientSecret;if(!r||!n)throw new Error("Missing required credentials (clientId, clientSecret)");var i=o.from("".concat(r,":").concat(n)).toString("base64"),a=e.oauthUri||"/oauth/token";return{basicAuth:i,url:e.host.replace(/\/$/,"")+a,body:"grant_type=refresh_token&refresh_token=".concat(encodeURIComponent(e.refreshToken))}}function c(e){if(!e)throw new Error("Missing required options");if(!e.projectKey)throw new Error("Missing required option (projectKey)");var t=e.projectKey;e.oauthUri=e.oauthUri||"/oauth/".concat(t,"/anonymous/token");var r=i(e);return e.credentials.anonymousId&&(r.body+="&anonymous_id=".concat(e.credentials.anonymousId)),n({},r)}},554:(e,t,r)=>{"use strict";r.d(t,{Z:()=>c});var n=r(893),o=r(935);function i(e){return{clientId:e.credentials.clientId,host:e.host,projectKey:e.projectKey}}var a=r(156),s=function(){return s=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},s.apply(this,arguments)};function c(e){var t=e.tokenCache||(0,a.Z)({token:"",expirationTime:-1}),r=(0,a.Z)(!1),c=[];return function(a){return function(u,l){if(u.headers&&u.headers.authorization||u.headers&&u.headers.Authorization)a(u,l);else{var h=s(s({request:u,response:l},(0,o.BB)(e)),{pendingTasks:c,requestState:r,tokenCache:t,tokenCacheKey:i(e),fetch:e.fetch});(0,n.Z)(h,a)}}}}},352:(e,t,r)=>{"use strict";r.d(t,{Z:()=>o});var n=function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)};function o(e,t){return void 0===e&&(e=""),void 0===t&&(t={}),function(r){return function(o,i){if("string"!=typeof e)throw new Error("authorization must be a string");var a=void 0===t.force||t.force;if(!e||(o.headers&&o.headers.authorization||o.headers&&o.headers.Authorization)&&!1===a)return r(o,i);var s=n(n({},o),{headers:n(n({},o.headers),{Authorization:e})});return r(s,i)}}}},637:(e,t,r)=>{"use strict";r.d(t,{Z:()=>s});var n=r(893),o=r(935),i=r(156),a=function(){return a=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},a.apply(this,arguments)};function s(e){var t=(0,i.Z)({}),r=[],s=(0,i.Z)(!1);return function(i){return function(c,u){if(c.headers&&c.headers.authorization||c.headers&&c.headers.Authorization)i(c,u);else{var l=a(a({request:c,response:u},(0,o._T)(e)),{pendingTasks:r,requestState:s,tokenCache:t,fetch:e.fetch});(0,n.Z)(l,i,e)}}}}},589:(e,t,r)=>{"use strict";r.d(t,{Z:()=>s});var n=r(893),o=r(935),i=r(156),a=function(){return a=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},a.apply(this,arguments)};function s(e){var t=(0,i.Z)({}),r=[],s=(0,i.Z)(!1);return function(i){return function(c,u){if(c.headers&&c.headers.authorization||c.headers&&c.headers.Authorization)i(c,u);else{var l=a(a({request:c,response:u},(0,o.Um)(e)),{pendingTasks:r,requestState:s,tokenCache:t,fetch:e.fetch});(0,n.Z)(l,i)}}}}},156:(e,t,r)=>{"use strict";function n(e){var t=e;return{get:function(){return t},set:function(e){return t=e}}}r.d(t,{Z:()=>n})},386:(e,t,r)=>{"use strict";r.d(t,{Z:()=>o});var n=function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)};function o(e){return function(t){return function(r,o){var i=n(n({},r),{headers:n(n({},r.headers),{"X-Correlation-ID":e.generate()})});t(i,o)}}}},349:(e,t,r)=>{"use strict";r.d(t,{Z:()=>l});var n=r(754);function o(e){if(e.raw)return e.raw();if(!e.forEach)return{};var t={};return e.forEach((function(e,r){t[r]=e})),t}var i=r(109),a=function(){return a=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},a.apply(this,arguments)};function s(e){return null!=e&&null!=e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function c(e,t,r,n,o){return n&&0!==e?Math.min(Math.round((Math.random()+1)*t*Math.pow(2,e)),o):t}function u(e,t){t&&(e&&e.headers&&e.headers.authorization&&(e.headers.authorization="Bearer ********"),e&&e.headers&&e.headers.Authorization&&(e.headers.Authorization="Bearer ********"))}function l(e){var t,r=e.host,l=e.credentialsMode,h=e.includeResponseHeaders,d=e.includeOriginalRequest,f=e.includeRequestInErrorResponse,p=void 0===f||f,y=e.maskSensitiveHeaderData,w=void 0===y||y,v=e.enableRetry,g=e.timeout,m=e.retryConfig,b=void 0===m?{}:m,j=b.maxRetries,C=void 0===j?10:j,O=b.backoff,M=void 0===O||O,E=b.retryDelay,k=void 0===E?200:E,T=b.maxDelay,A=void 0===T?1/0:T,q=b.retryCodes,S=void 0===q?[503]:q,P=e.fetch,Z=e.getAbortController;if(!P)throw new Error("`fetch` is not available. Please pass in `fetch` as an option or have it globally available.");if(g&&!Z)throw new Error("`AbortController` is not available. Please pass in `getAbortController` as an option or have AbortController globally available when using timeout.");if(t=P||fetch,!Array.isArray(S))throw new Error("`retryCodes` option must be an array of retry status (error) codes.");return function(e){return function(f,y){var m;(g||Z)&&(m=(Z?Z():null)||new AbortController);var b=r.replace(/\/$/,"")+f.uri,j=a({},f.headers);null===j["Content-Type"]&&delete j["Content-Type"],Object.prototype.hasOwnProperty.call(j,"Content-Type")||Object.prototype.hasOwnProperty.call(j,"content-type")||(j["Content-Type"]="application/json");var O=["application/json","application/graphql"].indexOf(j["Content-Type"])>-1&&"string"==typeof f.body||s(f.body)?f.body:JSON.stringify(f.body||void 0);O&&("string"==typeof O||s(O))&&(j["Content-Length"]=n.Buffer.byteLength(O).toString());var E={method:f.method,headers:j};l&&(E.credentialsMode=l),m&&(E.signal=m.signal),O&&(E.body=O);var T=0;!function r(){var n;g&&(n=setTimeout((function(){m.abort()}),g)),t(b,E).then((function(t){if(t.ok)return"HEAD"===E.method?void e(f,a(a({},y),{statusCode:t.status})):void t.text().then((function(n){var i;try{i=n.length>0?JSON.parse(n):{}}catch(e){if(v&&T<C)return setTimeout(r,c(T,k,0,M,A)),void(T+=1);i=n}var s=a(a({},y),{body:i,statusCode:t.status});h&&(s.headers=o(t.headers)),d&&(s.request=a({},E),u(s.request,w)),e(f,s)}));t.text().then((function(n){var s;try{s=JSON.parse(n)}catch(l){s=n}var l=function(e){var t=e.statusCode,r=e.message,n=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}(e,["statusCode","message"]),o=r||"Unexpected non-JSON error response";404===t&&(o="URI not found: ".concat(n.originalRequest.uri));var a=(0,i.ZP)(t);return a?new a(o,n):new i.oo(t,o,n)}(a(a(a({statusCode:t.status},p?{originalRequest:f}:{}),{retryCount:T,headers:o(t.headers)}),"object"==typeof s?{message:s.message,body:s}:{message:s,body:s}));if(v&&(-1!==S.indexOf(l.statusCode)||-1!==(null==S?void 0:S.indexOf(l.message)))&&T<C)return setTimeout(r,c(T,k,0,M,A)),void(T+=1);u(l.originalRequest,w);var h=a(a({},y),{error:l,statusCode:t.status});e(f,h)}))}),(function(t){if(v&&T<C)return setTimeout(r,c(T,k,0,M,A)),void(T+=1);var n=new i.F7(t.message,a(a({},p?{originalRequest:f}:{}),{retryCount:T}));u(n.originalRequest,w),e(f,a(a({},y),{error:n,statusCode:0}))})).finally((function(){clearTimeout(n)}))}()}}}},357:(e,t,r)=>{"use strict";r.d(t,{Z:()=>o});var n=r(169);function o(){return function(e){return function(t,r){var o=r.error,i=r.body,a=r.statusCode;n.log("Request: ",t),n.log("Response: ",{error:o,body:i,statusCode:a}),e(t,r)}}}},324:(e,t,r)=>{"use strict";r.d(t,{Z:()=>o});var n=function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)};function o(e){var t=e.concurrency,r=void 0===t?20:t,o=[],i=0,a=function(e){if(i-=1,o.length&&i<=r){var t=o.shift();i+=1,e(t.request,t.response)}};return function(e){return function(t,s){var c=n(n({},s),{resolve:function(t){s.resolve(t),a(e)},reject:function(t){s.reject(t),a(e)}});if(o.push({request:t,response:c}),i<r){var u=o.shift();i+=1,e(u.request,u.response)}}}}},406:(e,t,r)=>{"use strict";r.d(t,{Z:()=>a});var n=r(696);function o(){if("undefined"!=typeof window&&window.document&&9===window.document.nodeType)return window.navigator.userAgent;var e=(null==n?void 0:n.version.slice(1))||"12";return"node.js/".concat(e)}var i=function(){return i=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},i.apply(this,arguments)};function a(e){var t=function(e){if(!e||0===Object.keys(e).length||!{}.hasOwnProperty.call(e,"name"))throw new Error("Missing required option `name`");var t=e.version?"".concat(e.name,"/").concat(e.version):e.name,r=null;e.libraryName&&!e.libraryVersion?r=e.libraryName:e.libraryName&&e.libraryVersion&&(r="".concat(e.libraryName,"/").concat(e.libraryVersion));var n=null;return e.contactUrl&&!e.contactEmail?n="(+".concat(e.contactUrl,")"):!e.contactUrl&&e.contactEmail?n="(+".concat(e.contactEmail,")"):e.contactUrl&&e.contactEmail&&(n="(+".concat(e.contactUrl,"; +").concat(e.contactEmail,")")),[t,o(),r,n,e.customAgent||""].filter(Boolean).join(" ")}(i(i({},e),{name:"commercetools-sdk-javascript-v2/".concat("1.4.2")}));return function(e){return function(r,n){var o=i(i({},r),{headers:i(i({},r.headers),{"User-Agent":t})});e(o,n)}}}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{"use strict";r.r(n),r.d(n,{ClientBuilder:()=>e.Z,Process:()=>t.N,createAuthForAnonymousSessionFlow:()=>i.Z,createAuthForClientCredentialsFlow:()=>a.Z,createAuthForPasswordFlow:()=>c.Z,createAuthForRefreshTokenFlow:()=>u.Z,createAuthWithExistingToken:()=>s.Z,createClient:()=>t.Z,createCorrelationIdMiddleware:()=>l.Z,createHttpClient:()=>h.Z,createLoggerMiddleware:()=>d.Z,createQueueMiddleware:()=>f.Z,createUserAgentMiddleware:()=>p.Z,getErrorByCode:()=>o.ZP});var e=r(392),t=r(202),o=r(109),i=r(584),a=r(554),s=r(352),c=r(637),u=r(589),l=r(386),h=r(349),d=r(357),f=r(324),p=r(406),y=r(52),w={};for(const e in y)["default","ClientBuilder","createClient","Process","getErrorByCode","createAuthForAnonymousSessionFlow","createAuthForClientCredentialsFlow","createAuthWithExistingToken","createAuthForPasswordFlow","createAuthForRefreshTokenFlow","createCorrelationIdMiddleware","createHttpClient","createLoggerMiddleware","createQueueMiddleware","createUserAgentMiddleware"].indexOf(e)<0&&(w[e]=()=>y[e]);r.d(n,w)})(),n})()));
|