@commercetools/sdk-client-v2 2.3.0 → 2.4.1
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 +13 -0
- package/dist/commercetools-sdk-client-v2.browser.cjs.js +49 -25
- package/dist/commercetools-sdk-client-v2.browser.esm.js +49 -25
- package/dist/commercetools-sdk-client-v2.cjs.dev.js +49 -25
- package/dist/commercetools-sdk-client-v2.cjs.prod.js +49 -25
- package/dist/commercetools-sdk-client-v2.esm.js +49 -25
- package/dist/commercetools-sdk-client-v2.umd.js +1 -1
- package/dist/declarations/src/sdk-client/client.d.ts +10 -1
- package/dist/declarations/src/types/sdk.d.ts +16 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @commercetools/sdk-client-v2
|
|
2
2
|
|
|
3
|
+
## 2.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#671](https://github.com/commercetools/commercetools-sdk-typescript/pull/671) [`344fd2d`](https://github.com/commercetools/commercetools-sdk-typescript/commit/344fd2d105f51a65a8a93f247ea9ea8f1a09b095) Thanks [@ajimae](https://github.com/ajimae)! - Fix malformed uri error due to wrong object to uri serialization.
|
|
8
|
+
|
|
9
|
+
## 2.4.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#637](https://github.com/commercetools/commercetools-sdk-typescript/pull/637) [`a000d70`](https://github.com/commercetools/commercetools-sdk-typescript/commit/a000d708a82b39ecfff26acfbb682dda9675e79f) Thanks [@ajimae](https://github.com/ajimae)! - - add functionality to override limit value in process function
|
|
14
|
+
- add sort options to process function to override default value
|
|
15
|
+
|
|
3
16
|
## 2.3.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
|
@@ -9,24 +9,24 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
|
|
|
9
9
|
|
|
10
10
|
var fetch__default = /*#__PURE__*/_interopDefault(fetch$1);
|
|
11
11
|
|
|
12
|
-
function
|
|
13
|
-
if (
|
|
14
|
-
var
|
|
15
|
-
if (
|
|
16
|
-
var
|
|
17
|
-
if (
|
|
12
|
+
function toPrimitive(t, r) {
|
|
13
|
+
if ("object" != typeof t || !t) return t;
|
|
14
|
+
var e = t[Symbol.toPrimitive];
|
|
15
|
+
if (void 0 !== e) {
|
|
16
|
+
var i = e.call(t, r || "default");
|
|
17
|
+
if ("object" != typeof i) return i;
|
|
18
18
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
19
19
|
}
|
|
20
|
-
return (
|
|
20
|
+
return ("string" === r ? String : Number)(t);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function
|
|
24
|
-
var
|
|
25
|
-
return
|
|
23
|
+
function toPropertyKey(t) {
|
|
24
|
+
var i = toPrimitive(t, "string");
|
|
25
|
+
return "symbol" == typeof i ? i : String(i);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
function _defineProperty(obj, key, value) {
|
|
29
|
-
key =
|
|
29
|
+
key = toPropertyKey(key);
|
|
30
30
|
if (key in obj) {
|
|
31
31
|
Object.defineProperty(obj, key, {
|
|
32
32
|
value: value,
|
|
@@ -40,6 +40,14 @@ function _defineProperty(obj, key, value) {
|
|
|
40
40
|
return obj;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
function isDefined(value) {
|
|
44
|
+
return typeof value !== 'undefined' && value !== null;
|
|
45
|
+
}
|
|
46
|
+
function clean(value) {
|
|
47
|
+
if (!isDefined(value)) return '';
|
|
48
|
+
if (typeof value == 'string') return value;
|
|
49
|
+
return Object.fromEntries(Object.entries(value).filter(([_, value]) => ![null, undefined, ''].includes(value)));
|
|
50
|
+
}
|
|
43
51
|
function urlParser(url) {
|
|
44
52
|
const object = {};
|
|
45
53
|
const data = new URLSearchParams(url);
|
|
@@ -52,9 +60,24 @@ function urlParser(url) {
|
|
|
52
60
|
}
|
|
53
61
|
return object;
|
|
54
62
|
}
|
|
63
|
+
function urlStringifier(object) {
|
|
64
|
+
object = clean(object);
|
|
65
|
+
if (!object) return '';
|
|
66
|
+
const params = new URLSearchParams(object);
|
|
67
|
+
for (const [key, value] of Object.entries(object)) {
|
|
68
|
+
if (Array.isArray(value)) {
|
|
69
|
+
params.delete(key);
|
|
70
|
+
value.filter(isDefined).forEach(v => params.append(key, v));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return params.toString();
|
|
74
|
+
}
|
|
55
75
|
function parseURLString(url, parser = urlParser) {
|
|
56
76
|
return parser(url);
|
|
57
77
|
}
|
|
78
|
+
function stringifyURLString(object, stringifier = urlStringifier) {
|
|
79
|
+
return stringifier(object);
|
|
80
|
+
}
|
|
58
81
|
|
|
59
82
|
var METHODS = ['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'];
|
|
60
83
|
|
|
@@ -70,6 +93,7 @@ function validate(funcName, request, options = {
|
|
|
70
93
|
}
|
|
71
94
|
|
|
72
95
|
let _options;
|
|
96
|
+
const PAGE_LIMIT = 20;
|
|
73
97
|
function compose(...funcs) {
|
|
74
98
|
funcs = funcs.filter(func => typeof func === 'function');
|
|
75
99
|
if (funcs.length === 1) return funcs[0];
|
|
@@ -83,6 +107,8 @@ function process$1(request, fn, processOpt) {
|
|
|
83
107
|
|
|
84
108
|
// Set default process options
|
|
85
109
|
const opt = {
|
|
110
|
+
limit: PAGE_LIMIT,
|
|
111
|
+
// defaults
|
|
86
112
|
total: Number.POSITIVE_INFINITY,
|
|
87
113
|
accumulate: true,
|
|
88
114
|
...processOpt
|
|
@@ -102,7 +128,7 @@ function process$1(request, fn, processOpt) {
|
|
|
102
128
|
};
|
|
103
129
|
const query = {
|
|
104
130
|
// defaults
|
|
105
|
-
limit:
|
|
131
|
+
limit: opt.limit,
|
|
106
132
|
// merge given query params
|
|
107
133
|
...requestQuery
|
|
108
134
|
};
|
|
@@ -112,19 +138,20 @@ function process$1(request, fn, processOpt) {
|
|
|
112
138
|
// Use the lesser value between limit and itemsToGet in query
|
|
113
139
|
const limit = query.limit < itemsToGet ? query.limit : itemsToGet;
|
|
114
140
|
// const originalQueryString = qs.stringify({ ...query, limit }, qsOptions)
|
|
115
|
-
const originalQueryString =
|
|
141
|
+
const originalQueryString = stringifyURLString({
|
|
116
142
|
...query,
|
|
117
143
|
limit
|
|
118
|
-
})
|
|
144
|
+
});
|
|
119
145
|
const enhancedQuery = {
|
|
120
|
-
sort: 'id asc',
|
|
146
|
+
sort: opt.sort || 'id asc',
|
|
121
147
|
withTotal: false,
|
|
122
148
|
...(lastId ? {
|
|
123
149
|
where: `id > "${lastId}"`
|
|
124
150
|
} : {})
|
|
125
151
|
};
|
|
152
|
+
|
|
126
153
|
// const enhancedQueryString = qs.stringify(enhancedQuery, qsOptions)
|
|
127
|
-
const enhancedQueryString =
|
|
154
|
+
const enhancedQueryString = stringifyURLString(enhancedQuery);
|
|
128
155
|
const enhancedRequest = {
|
|
129
156
|
...request,
|
|
130
157
|
uri: `${_path}?${enhancedQueryString}&${originalQueryString}`
|
|
@@ -139,7 +166,7 @@ function process$1(request, fn, processOpt) {
|
|
|
139
166
|
return resolve(acc || []);
|
|
140
167
|
}
|
|
141
168
|
const result = await Promise.resolve(fn(payload));
|
|
142
|
-
let accumulated;
|
|
169
|
+
let accumulated = [];
|
|
143
170
|
hasFirstPageBeenProcessed = true;
|
|
144
171
|
if (opt.accumulate) accumulated = acc.concat(result || []);
|
|
145
172
|
itemsToGet -= resultsLength;
|
|
@@ -735,11 +762,9 @@ function createError({
|
|
|
735
762
|
}) {
|
|
736
763
|
let errorMessage = message || 'Unexpected non-JSON error response';
|
|
737
764
|
if (statusCode === 404) {
|
|
738
|
-
|
|
739
|
-
errorMessage = `URI not found: ${((_rest$originalRequest = rest.originalRequest) === null || _rest$originalRequest === void 0 ? void 0 : _rest$originalRequest.uri) || rest.uri}`;
|
|
765
|
+
errorMessage = `URI not found: ${rest.originalRequest?.uri || rest.uri}`;
|
|
740
766
|
delete rest.uri; // remove the `uri` property from the response
|
|
741
767
|
}
|
|
742
|
-
|
|
743
768
|
const ResponseError = getErrorByCode(statusCode);
|
|
744
769
|
if (ResponseError) return new ResponseError(errorMessage, rest);
|
|
745
770
|
return new HttpError(statusCode, errorMessage, rest);
|
|
@@ -929,7 +954,7 @@ function createHttpMiddleware({
|
|
|
929
954
|
body: parsed
|
|
930
955
|
})
|
|
931
956
|
});
|
|
932
|
-
if (enableRetry && (retryCodes.indexOf(error.statusCode) !== -1 ||
|
|
957
|
+
if (enableRetry && (retryCodes.indexOf(error.statusCode) !== -1 || retryCodes?.indexOf(error.message) !== -1)) {
|
|
933
958
|
if (retryCount < maxRetries) {
|
|
934
959
|
setTimeout(executeFetch, calcDelayDuration(retryCount, retryDelay, maxRetries, backoff, maxDelay));
|
|
935
960
|
retryCount += 1;
|
|
@@ -1043,7 +1068,7 @@ function createQueueMiddleware({
|
|
|
1043
1068
|
|
|
1044
1069
|
var packageJson = {
|
|
1045
1070
|
name: "@commercetools/sdk-client-v2",
|
|
1046
|
-
version: "2.
|
|
1071
|
+
version: "2.4.1",
|
|
1047
1072
|
engines: {
|
|
1048
1073
|
node: ">=14"
|
|
1049
1074
|
},
|
|
@@ -1115,9 +1140,8 @@ var packageJson = {
|
|
|
1115
1140
|
*/
|
|
1116
1141
|
const isBrowser = () => window.document && window.document.nodeType === 9;
|
|
1117
1142
|
function getSystemInfo() {
|
|
1118
|
-
var _process;
|
|
1119
1143
|
if (isBrowser()) return window.navigator.userAgent;
|
|
1120
|
-
const nodeVersion =
|
|
1144
|
+
const nodeVersion = process?.version.slice(1) || '12'; // temporary fix for rn environment
|
|
1121
1145
|
// const platformInfo = `(${process.platform}; ${process.arch})`
|
|
1122
1146
|
// return `Node.js/${nodeVersion} ${platformInfo}`
|
|
1123
1147
|
|
|
@@ -1301,7 +1325,7 @@ class ClientBuilder {
|
|
|
1301
1325
|
...rest
|
|
1302
1326
|
} = options;
|
|
1303
1327
|
this.withUserAgentMiddleware({
|
|
1304
|
-
customAgent:
|
|
1328
|
+
customAgent: rest?.userAgent || 'typescript-sdk-apm-middleware'
|
|
1305
1329
|
});
|
|
1306
1330
|
this.telemetryMiddleware = createTelemetryMiddleware(rest);
|
|
1307
1331
|
return this;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import fetch$1 from 'node-fetch';
|
|
2
2
|
import { Buffer } from 'buffer/';
|
|
3
3
|
|
|
4
|
-
function
|
|
5
|
-
if (
|
|
6
|
-
var
|
|
7
|
-
if (
|
|
8
|
-
var
|
|
9
|
-
if (
|
|
4
|
+
function toPrimitive(t, r) {
|
|
5
|
+
if ("object" != typeof t || !t) return t;
|
|
6
|
+
var e = t[Symbol.toPrimitive];
|
|
7
|
+
if (void 0 !== e) {
|
|
8
|
+
var i = e.call(t, r || "default");
|
|
9
|
+
if ("object" != typeof i) return i;
|
|
10
10
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
11
11
|
}
|
|
12
|
-
return (
|
|
12
|
+
return ("string" === r ? String : Number)(t);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
function
|
|
16
|
-
var
|
|
17
|
-
return
|
|
15
|
+
function toPropertyKey(t) {
|
|
16
|
+
var i = toPrimitive(t, "string");
|
|
17
|
+
return "symbol" == typeof i ? i : String(i);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
function _defineProperty(obj, key, value) {
|
|
21
|
-
key =
|
|
21
|
+
key = toPropertyKey(key);
|
|
22
22
|
if (key in obj) {
|
|
23
23
|
Object.defineProperty(obj, key, {
|
|
24
24
|
value: value,
|
|
@@ -32,6 +32,14 @@ function _defineProperty(obj, key, value) {
|
|
|
32
32
|
return obj;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
function isDefined(value) {
|
|
36
|
+
return typeof value !== 'undefined' && value !== null;
|
|
37
|
+
}
|
|
38
|
+
function clean(value) {
|
|
39
|
+
if (!isDefined(value)) return '';
|
|
40
|
+
if (typeof value == 'string') return value;
|
|
41
|
+
return Object.fromEntries(Object.entries(value).filter(([_, value]) => ![null, undefined, ''].includes(value)));
|
|
42
|
+
}
|
|
35
43
|
function urlParser(url) {
|
|
36
44
|
const object = {};
|
|
37
45
|
const data = new URLSearchParams(url);
|
|
@@ -44,9 +52,24 @@ function urlParser(url) {
|
|
|
44
52
|
}
|
|
45
53
|
return object;
|
|
46
54
|
}
|
|
55
|
+
function urlStringifier(object) {
|
|
56
|
+
object = clean(object);
|
|
57
|
+
if (!object) return '';
|
|
58
|
+
const params = new URLSearchParams(object);
|
|
59
|
+
for (const [key, value] of Object.entries(object)) {
|
|
60
|
+
if (Array.isArray(value)) {
|
|
61
|
+
params.delete(key);
|
|
62
|
+
value.filter(isDefined).forEach(v => params.append(key, v));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return params.toString();
|
|
66
|
+
}
|
|
47
67
|
function parseURLString(url, parser = urlParser) {
|
|
48
68
|
return parser(url);
|
|
49
69
|
}
|
|
70
|
+
function stringifyURLString(object, stringifier = urlStringifier) {
|
|
71
|
+
return stringifier(object);
|
|
72
|
+
}
|
|
50
73
|
|
|
51
74
|
var METHODS = ['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'];
|
|
52
75
|
|
|
@@ -62,6 +85,7 @@ function validate(funcName, request, options = {
|
|
|
62
85
|
}
|
|
63
86
|
|
|
64
87
|
let _options;
|
|
88
|
+
const PAGE_LIMIT = 20;
|
|
65
89
|
function compose(...funcs) {
|
|
66
90
|
funcs = funcs.filter(func => typeof func === 'function');
|
|
67
91
|
if (funcs.length === 1) return funcs[0];
|
|
@@ -75,6 +99,8 @@ function process$1(request, fn, processOpt) {
|
|
|
75
99
|
|
|
76
100
|
// Set default process options
|
|
77
101
|
const opt = {
|
|
102
|
+
limit: PAGE_LIMIT,
|
|
103
|
+
// defaults
|
|
78
104
|
total: Number.POSITIVE_INFINITY,
|
|
79
105
|
accumulate: true,
|
|
80
106
|
...processOpt
|
|
@@ -94,7 +120,7 @@ function process$1(request, fn, processOpt) {
|
|
|
94
120
|
};
|
|
95
121
|
const query = {
|
|
96
122
|
// defaults
|
|
97
|
-
limit:
|
|
123
|
+
limit: opt.limit,
|
|
98
124
|
// merge given query params
|
|
99
125
|
...requestQuery
|
|
100
126
|
};
|
|
@@ -104,19 +130,20 @@ function process$1(request, fn, processOpt) {
|
|
|
104
130
|
// Use the lesser value between limit and itemsToGet in query
|
|
105
131
|
const limit = query.limit < itemsToGet ? query.limit : itemsToGet;
|
|
106
132
|
// const originalQueryString = qs.stringify({ ...query, limit }, qsOptions)
|
|
107
|
-
const originalQueryString =
|
|
133
|
+
const originalQueryString = stringifyURLString({
|
|
108
134
|
...query,
|
|
109
135
|
limit
|
|
110
|
-
})
|
|
136
|
+
});
|
|
111
137
|
const enhancedQuery = {
|
|
112
|
-
sort: 'id asc',
|
|
138
|
+
sort: opt.sort || 'id asc',
|
|
113
139
|
withTotal: false,
|
|
114
140
|
...(lastId ? {
|
|
115
141
|
where: `id > "${lastId}"`
|
|
116
142
|
} : {})
|
|
117
143
|
};
|
|
144
|
+
|
|
118
145
|
// const enhancedQueryString = qs.stringify(enhancedQuery, qsOptions)
|
|
119
|
-
const enhancedQueryString =
|
|
146
|
+
const enhancedQueryString = stringifyURLString(enhancedQuery);
|
|
120
147
|
const enhancedRequest = {
|
|
121
148
|
...request,
|
|
122
149
|
uri: `${_path}?${enhancedQueryString}&${originalQueryString}`
|
|
@@ -131,7 +158,7 @@ function process$1(request, fn, processOpt) {
|
|
|
131
158
|
return resolve(acc || []);
|
|
132
159
|
}
|
|
133
160
|
const result = await Promise.resolve(fn(payload));
|
|
134
|
-
let accumulated;
|
|
161
|
+
let accumulated = [];
|
|
135
162
|
hasFirstPageBeenProcessed = true;
|
|
136
163
|
if (opt.accumulate) accumulated = acc.concat(result || []);
|
|
137
164
|
itemsToGet -= resultsLength;
|
|
@@ -727,11 +754,9 @@ function createError({
|
|
|
727
754
|
}) {
|
|
728
755
|
let errorMessage = message || 'Unexpected non-JSON error response';
|
|
729
756
|
if (statusCode === 404) {
|
|
730
|
-
|
|
731
|
-
errorMessage = `URI not found: ${((_rest$originalRequest = rest.originalRequest) === null || _rest$originalRequest === void 0 ? void 0 : _rest$originalRequest.uri) || rest.uri}`;
|
|
757
|
+
errorMessage = `URI not found: ${rest.originalRequest?.uri || rest.uri}`;
|
|
732
758
|
delete rest.uri; // remove the `uri` property from the response
|
|
733
759
|
}
|
|
734
|
-
|
|
735
760
|
const ResponseError = getErrorByCode(statusCode);
|
|
736
761
|
if (ResponseError) return new ResponseError(errorMessage, rest);
|
|
737
762
|
return new HttpError(statusCode, errorMessage, rest);
|
|
@@ -921,7 +946,7 @@ function createHttpMiddleware({
|
|
|
921
946
|
body: parsed
|
|
922
947
|
})
|
|
923
948
|
});
|
|
924
|
-
if (enableRetry && (retryCodes.indexOf(error.statusCode) !== -1 ||
|
|
949
|
+
if (enableRetry && (retryCodes.indexOf(error.statusCode) !== -1 || retryCodes?.indexOf(error.message) !== -1)) {
|
|
925
950
|
if (retryCount < maxRetries) {
|
|
926
951
|
setTimeout(executeFetch, calcDelayDuration(retryCount, retryDelay, maxRetries, backoff, maxDelay));
|
|
927
952
|
retryCount += 1;
|
|
@@ -1035,7 +1060,7 @@ function createQueueMiddleware({
|
|
|
1035
1060
|
|
|
1036
1061
|
var packageJson = {
|
|
1037
1062
|
name: "@commercetools/sdk-client-v2",
|
|
1038
|
-
version: "2.
|
|
1063
|
+
version: "2.4.1",
|
|
1039
1064
|
engines: {
|
|
1040
1065
|
node: ">=14"
|
|
1041
1066
|
},
|
|
@@ -1107,9 +1132,8 @@ var packageJson = {
|
|
|
1107
1132
|
*/
|
|
1108
1133
|
const isBrowser = () => window.document && window.document.nodeType === 9;
|
|
1109
1134
|
function getSystemInfo() {
|
|
1110
|
-
var _process;
|
|
1111
1135
|
if (isBrowser()) return window.navigator.userAgent;
|
|
1112
|
-
const nodeVersion =
|
|
1136
|
+
const nodeVersion = process?.version.slice(1) || '12'; // temporary fix for rn environment
|
|
1113
1137
|
// const platformInfo = `(${process.platform}; ${process.arch})`
|
|
1114
1138
|
// return `Node.js/${nodeVersion} ${platformInfo}`
|
|
1115
1139
|
|
|
@@ -1293,7 +1317,7 @@ class ClientBuilder {
|
|
|
1293
1317
|
...rest
|
|
1294
1318
|
} = options;
|
|
1295
1319
|
this.withUserAgentMiddleware({
|
|
1296
|
-
customAgent:
|
|
1320
|
+
customAgent: rest?.userAgent || 'typescript-sdk-apm-middleware'
|
|
1297
1321
|
});
|
|
1298
1322
|
this.telemetryMiddleware = createTelemetryMiddleware(rest);
|
|
1299
1323
|
return this;
|
|
@@ -9,24 +9,24 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
|
|
|
9
9
|
|
|
10
10
|
var fetch__default = /*#__PURE__*/_interopDefault(fetch$1);
|
|
11
11
|
|
|
12
|
-
function
|
|
13
|
-
if (
|
|
14
|
-
var
|
|
15
|
-
if (
|
|
16
|
-
var
|
|
17
|
-
if (
|
|
12
|
+
function toPrimitive(t, r) {
|
|
13
|
+
if ("object" != typeof t || !t) return t;
|
|
14
|
+
var e = t[Symbol.toPrimitive];
|
|
15
|
+
if (void 0 !== e) {
|
|
16
|
+
var i = e.call(t, r || "default");
|
|
17
|
+
if ("object" != typeof i) return i;
|
|
18
18
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
19
19
|
}
|
|
20
|
-
return (
|
|
20
|
+
return ("string" === r ? String : Number)(t);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function
|
|
24
|
-
var
|
|
25
|
-
return
|
|
23
|
+
function toPropertyKey(t) {
|
|
24
|
+
var i = toPrimitive(t, "string");
|
|
25
|
+
return "symbol" == typeof i ? i : String(i);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
function _defineProperty(obj, key, value) {
|
|
29
|
-
key =
|
|
29
|
+
key = toPropertyKey(key);
|
|
30
30
|
if (key in obj) {
|
|
31
31
|
Object.defineProperty(obj, key, {
|
|
32
32
|
value: value,
|
|
@@ -40,6 +40,14 @@ function _defineProperty(obj, key, value) {
|
|
|
40
40
|
return obj;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
function isDefined(value) {
|
|
44
|
+
return typeof value !== 'undefined' && value !== null;
|
|
45
|
+
}
|
|
46
|
+
function clean(value) {
|
|
47
|
+
if (!isDefined(value)) return '';
|
|
48
|
+
if (typeof value == 'string') return value;
|
|
49
|
+
return Object.fromEntries(Object.entries(value).filter(([_, value]) => ![null, undefined, ''].includes(value)));
|
|
50
|
+
}
|
|
43
51
|
function urlParser(url) {
|
|
44
52
|
const object = {};
|
|
45
53
|
const data = new URLSearchParams(url);
|
|
@@ -52,9 +60,24 @@ function urlParser(url) {
|
|
|
52
60
|
}
|
|
53
61
|
return object;
|
|
54
62
|
}
|
|
63
|
+
function urlStringifier(object) {
|
|
64
|
+
object = clean(object);
|
|
65
|
+
if (!object) return '';
|
|
66
|
+
const params = new URLSearchParams(object);
|
|
67
|
+
for (const [key, value] of Object.entries(object)) {
|
|
68
|
+
if (Array.isArray(value)) {
|
|
69
|
+
params.delete(key);
|
|
70
|
+
value.filter(isDefined).forEach(v => params.append(key, v));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return params.toString();
|
|
74
|
+
}
|
|
55
75
|
function parseURLString(url, parser = urlParser) {
|
|
56
76
|
return parser(url);
|
|
57
77
|
}
|
|
78
|
+
function stringifyURLString(object, stringifier = urlStringifier) {
|
|
79
|
+
return stringifier(object);
|
|
80
|
+
}
|
|
58
81
|
|
|
59
82
|
var METHODS = ['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'];
|
|
60
83
|
|
|
@@ -70,6 +93,7 @@ function validate(funcName, request, options = {
|
|
|
70
93
|
}
|
|
71
94
|
|
|
72
95
|
let _options;
|
|
96
|
+
const PAGE_LIMIT = 20;
|
|
73
97
|
function compose(...funcs) {
|
|
74
98
|
funcs = funcs.filter(func => typeof func === 'function');
|
|
75
99
|
if (funcs.length === 1) return funcs[0];
|
|
@@ -83,6 +107,8 @@ function process$1(request, fn, processOpt) {
|
|
|
83
107
|
|
|
84
108
|
// Set default process options
|
|
85
109
|
const opt = {
|
|
110
|
+
limit: PAGE_LIMIT,
|
|
111
|
+
// defaults
|
|
86
112
|
total: Number.POSITIVE_INFINITY,
|
|
87
113
|
accumulate: true,
|
|
88
114
|
...processOpt
|
|
@@ -102,7 +128,7 @@ function process$1(request, fn, processOpt) {
|
|
|
102
128
|
};
|
|
103
129
|
const query = {
|
|
104
130
|
// defaults
|
|
105
|
-
limit:
|
|
131
|
+
limit: opt.limit,
|
|
106
132
|
// merge given query params
|
|
107
133
|
...requestQuery
|
|
108
134
|
};
|
|
@@ -112,19 +138,20 @@ function process$1(request, fn, processOpt) {
|
|
|
112
138
|
// Use the lesser value between limit and itemsToGet in query
|
|
113
139
|
const limit = query.limit < itemsToGet ? query.limit : itemsToGet;
|
|
114
140
|
// const originalQueryString = qs.stringify({ ...query, limit }, qsOptions)
|
|
115
|
-
const originalQueryString =
|
|
141
|
+
const originalQueryString = stringifyURLString({
|
|
116
142
|
...query,
|
|
117
143
|
limit
|
|
118
|
-
})
|
|
144
|
+
});
|
|
119
145
|
const enhancedQuery = {
|
|
120
|
-
sort: 'id asc',
|
|
146
|
+
sort: opt.sort || 'id asc',
|
|
121
147
|
withTotal: false,
|
|
122
148
|
...(lastId ? {
|
|
123
149
|
where: `id > "${lastId}"`
|
|
124
150
|
} : {})
|
|
125
151
|
};
|
|
152
|
+
|
|
126
153
|
// const enhancedQueryString = qs.stringify(enhancedQuery, qsOptions)
|
|
127
|
-
const enhancedQueryString =
|
|
154
|
+
const enhancedQueryString = stringifyURLString(enhancedQuery);
|
|
128
155
|
const enhancedRequest = {
|
|
129
156
|
...request,
|
|
130
157
|
uri: `${_path}?${enhancedQueryString}&${originalQueryString}`
|
|
@@ -139,7 +166,7 @@ function process$1(request, fn, processOpt) {
|
|
|
139
166
|
return resolve(acc || []);
|
|
140
167
|
}
|
|
141
168
|
const result = await Promise.resolve(fn(payload));
|
|
142
|
-
let accumulated;
|
|
169
|
+
let accumulated = [];
|
|
143
170
|
hasFirstPageBeenProcessed = true;
|
|
144
171
|
if (opt.accumulate) accumulated = acc.concat(result || []);
|
|
145
172
|
itemsToGet -= resultsLength;
|
|
@@ -735,11 +762,9 @@ function createError({
|
|
|
735
762
|
}) {
|
|
736
763
|
let errorMessage = message || 'Unexpected non-JSON error response';
|
|
737
764
|
if (statusCode === 404) {
|
|
738
|
-
|
|
739
|
-
errorMessage = `URI not found: ${((_rest$originalRequest = rest.originalRequest) === null || _rest$originalRequest === void 0 ? void 0 : _rest$originalRequest.uri) || rest.uri}`;
|
|
765
|
+
errorMessage = `URI not found: ${rest.originalRequest?.uri || rest.uri}`;
|
|
740
766
|
delete rest.uri; // remove the `uri` property from the response
|
|
741
767
|
}
|
|
742
|
-
|
|
743
768
|
const ResponseError = getErrorByCode(statusCode);
|
|
744
769
|
if (ResponseError) return new ResponseError(errorMessage, rest);
|
|
745
770
|
return new HttpError(statusCode, errorMessage, rest);
|
|
@@ -929,7 +954,7 @@ function createHttpMiddleware({
|
|
|
929
954
|
body: parsed
|
|
930
955
|
})
|
|
931
956
|
});
|
|
932
|
-
if (enableRetry && (retryCodes.indexOf(error.statusCode) !== -1 ||
|
|
957
|
+
if (enableRetry && (retryCodes.indexOf(error.statusCode) !== -1 || retryCodes?.indexOf(error.message) !== -1)) {
|
|
933
958
|
if (retryCount < maxRetries) {
|
|
934
959
|
setTimeout(executeFetch, calcDelayDuration(retryCount, retryDelay, maxRetries, backoff, maxDelay));
|
|
935
960
|
retryCount += 1;
|
|
@@ -1043,7 +1068,7 @@ function createQueueMiddleware({
|
|
|
1043
1068
|
|
|
1044
1069
|
var packageJson = {
|
|
1045
1070
|
name: "@commercetools/sdk-client-v2",
|
|
1046
|
-
version: "2.
|
|
1071
|
+
version: "2.4.1",
|
|
1047
1072
|
engines: {
|
|
1048
1073
|
node: ">=14"
|
|
1049
1074
|
},
|
|
@@ -1115,9 +1140,8 @@ var packageJson = {
|
|
|
1115
1140
|
*/
|
|
1116
1141
|
const isBrowser = () => typeof window !== 'undefined' && window.document && window.document.nodeType === 9;
|
|
1117
1142
|
function getSystemInfo() {
|
|
1118
|
-
var _process;
|
|
1119
1143
|
if (isBrowser()) return window.navigator.userAgent;
|
|
1120
|
-
const nodeVersion =
|
|
1144
|
+
const nodeVersion = process?.version.slice(1) || '12'; // temporary fix for rn environment
|
|
1121
1145
|
// const platformInfo = `(${process.platform}; ${process.arch})`
|
|
1122
1146
|
// return `Node.js/${nodeVersion} ${platformInfo}`
|
|
1123
1147
|
|
|
@@ -1301,7 +1325,7 @@ class ClientBuilder {
|
|
|
1301
1325
|
...rest
|
|
1302
1326
|
} = options;
|
|
1303
1327
|
this.withUserAgentMiddleware({
|
|
1304
|
-
customAgent:
|
|
1328
|
+
customAgent: rest?.userAgent || 'typescript-sdk-apm-middleware'
|
|
1305
1329
|
});
|
|
1306
1330
|
this.telemetryMiddleware = createTelemetryMiddleware(rest);
|
|
1307
1331
|
return this;
|
|
@@ -9,24 +9,24 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
|
|
|
9
9
|
|
|
10
10
|
var fetch__default = /*#__PURE__*/_interopDefault(fetch$1);
|
|
11
11
|
|
|
12
|
-
function
|
|
13
|
-
if (
|
|
14
|
-
var
|
|
15
|
-
if (
|
|
16
|
-
var
|
|
17
|
-
if (
|
|
12
|
+
function toPrimitive(t, r) {
|
|
13
|
+
if ("object" != typeof t || !t) return t;
|
|
14
|
+
var e = t[Symbol.toPrimitive];
|
|
15
|
+
if (void 0 !== e) {
|
|
16
|
+
var i = e.call(t, r || "default");
|
|
17
|
+
if ("object" != typeof i) return i;
|
|
18
18
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
19
19
|
}
|
|
20
|
-
return (
|
|
20
|
+
return ("string" === r ? String : Number)(t);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function
|
|
24
|
-
var
|
|
25
|
-
return
|
|
23
|
+
function toPropertyKey(t) {
|
|
24
|
+
var i = toPrimitive(t, "string");
|
|
25
|
+
return "symbol" == typeof i ? i : String(i);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
function _defineProperty(obj, key, value) {
|
|
29
|
-
key =
|
|
29
|
+
key = toPropertyKey(key);
|
|
30
30
|
if (key in obj) {
|
|
31
31
|
Object.defineProperty(obj, key, {
|
|
32
32
|
value: value,
|
|
@@ -40,6 +40,14 @@ function _defineProperty(obj, key, value) {
|
|
|
40
40
|
return obj;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
function isDefined(value) {
|
|
44
|
+
return typeof value !== 'undefined' && value !== null;
|
|
45
|
+
}
|
|
46
|
+
function clean(value) {
|
|
47
|
+
if (!isDefined(value)) return '';
|
|
48
|
+
if (typeof value == 'string') return value;
|
|
49
|
+
return Object.fromEntries(Object.entries(value).filter(([_, value]) => ![null, undefined, ''].includes(value)));
|
|
50
|
+
}
|
|
43
51
|
function urlParser(url) {
|
|
44
52
|
const object = {};
|
|
45
53
|
const data = new URLSearchParams(url);
|
|
@@ -52,9 +60,24 @@ function urlParser(url) {
|
|
|
52
60
|
}
|
|
53
61
|
return object;
|
|
54
62
|
}
|
|
63
|
+
function urlStringifier(object) {
|
|
64
|
+
object = clean(object);
|
|
65
|
+
if (!object) return '';
|
|
66
|
+
const params = new URLSearchParams(object);
|
|
67
|
+
for (const [key, value] of Object.entries(object)) {
|
|
68
|
+
if (Array.isArray(value)) {
|
|
69
|
+
params.delete(key);
|
|
70
|
+
value.filter(isDefined).forEach(v => params.append(key, v));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return params.toString();
|
|
74
|
+
}
|
|
55
75
|
function parseURLString(url, parser = urlParser) {
|
|
56
76
|
return parser(url);
|
|
57
77
|
}
|
|
78
|
+
function stringifyURLString(object, stringifier = urlStringifier) {
|
|
79
|
+
return stringifier(object);
|
|
80
|
+
}
|
|
58
81
|
|
|
59
82
|
var METHODS = ['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'];
|
|
60
83
|
|
|
@@ -70,6 +93,7 @@ function validate(funcName, request, options = {
|
|
|
70
93
|
}
|
|
71
94
|
|
|
72
95
|
let _options;
|
|
96
|
+
const PAGE_LIMIT = 20;
|
|
73
97
|
function compose(...funcs) {
|
|
74
98
|
funcs = funcs.filter(func => typeof func === 'function');
|
|
75
99
|
if (funcs.length === 1) return funcs[0];
|
|
@@ -83,6 +107,8 @@ function process$1(request, fn, processOpt) {
|
|
|
83
107
|
|
|
84
108
|
// Set default process options
|
|
85
109
|
const opt = {
|
|
110
|
+
limit: PAGE_LIMIT,
|
|
111
|
+
// defaults
|
|
86
112
|
total: Number.POSITIVE_INFINITY,
|
|
87
113
|
accumulate: true,
|
|
88
114
|
...processOpt
|
|
@@ -102,7 +128,7 @@ function process$1(request, fn, processOpt) {
|
|
|
102
128
|
};
|
|
103
129
|
const query = {
|
|
104
130
|
// defaults
|
|
105
|
-
limit:
|
|
131
|
+
limit: opt.limit,
|
|
106
132
|
// merge given query params
|
|
107
133
|
...requestQuery
|
|
108
134
|
};
|
|
@@ -112,19 +138,20 @@ function process$1(request, fn, processOpt) {
|
|
|
112
138
|
// Use the lesser value between limit and itemsToGet in query
|
|
113
139
|
const limit = query.limit < itemsToGet ? query.limit : itemsToGet;
|
|
114
140
|
// const originalQueryString = qs.stringify({ ...query, limit }, qsOptions)
|
|
115
|
-
const originalQueryString =
|
|
141
|
+
const originalQueryString = stringifyURLString({
|
|
116
142
|
...query,
|
|
117
143
|
limit
|
|
118
|
-
})
|
|
144
|
+
});
|
|
119
145
|
const enhancedQuery = {
|
|
120
|
-
sort: 'id asc',
|
|
146
|
+
sort: opt.sort || 'id asc',
|
|
121
147
|
withTotal: false,
|
|
122
148
|
...(lastId ? {
|
|
123
149
|
where: `id > "${lastId}"`
|
|
124
150
|
} : {})
|
|
125
151
|
};
|
|
152
|
+
|
|
126
153
|
// const enhancedQueryString = qs.stringify(enhancedQuery, qsOptions)
|
|
127
|
-
const enhancedQueryString =
|
|
154
|
+
const enhancedQueryString = stringifyURLString(enhancedQuery);
|
|
128
155
|
const enhancedRequest = {
|
|
129
156
|
...request,
|
|
130
157
|
uri: `${_path}?${enhancedQueryString}&${originalQueryString}`
|
|
@@ -139,7 +166,7 @@ function process$1(request, fn, processOpt) {
|
|
|
139
166
|
return resolve(acc || []);
|
|
140
167
|
}
|
|
141
168
|
const result = await Promise.resolve(fn(payload));
|
|
142
|
-
let accumulated;
|
|
169
|
+
let accumulated = [];
|
|
143
170
|
hasFirstPageBeenProcessed = true;
|
|
144
171
|
if (opt.accumulate) accumulated = acc.concat(result || []);
|
|
145
172
|
itemsToGet -= resultsLength;
|
|
@@ -735,11 +762,9 @@ function createError({
|
|
|
735
762
|
}) {
|
|
736
763
|
let errorMessage = message || 'Unexpected non-JSON error response';
|
|
737
764
|
if (statusCode === 404) {
|
|
738
|
-
|
|
739
|
-
errorMessage = `URI not found: ${((_rest$originalRequest = rest.originalRequest) === null || _rest$originalRequest === void 0 ? void 0 : _rest$originalRequest.uri) || rest.uri}`;
|
|
765
|
+
errorMessage = `URI not found: ${rest.originalRequest?.uri || rest.uri}`;
|
|
740
766
|
delete rest.uri; // remove the `uri` property from the response
|
|
741
767
|
}
|
|
742
|
-
|
|
743
768
|
const ResponseError = getErrorByCode(statusCode);
|
|
744
769
|
if (ResponseError) return new ResponseError(errorMessage, rest);
|
|
745
770
|
return new HttpError(statusCode, errorMessage, rest);
|
|
@@ -929,7 +954,7 @@ function createHttpMiddleware({
|
|
|
929
954
|
body: parsed
|
|
930
955
|
})
|
|
931
956
|
});
|
|
932
|
-
if (enableRetry && (retryCodes.indexOf(error.statusCode) !== -1 ||
|
|
957
|
+
if (enableRetry && (retryCodes.indexOf(error.statusCode) !== -1 || retryCodes?.indexOf(error.message) !== -1)) {
|
|
933
958
|
if (retryCount < maxRetries) {
|
|
934
959
|
setTimeout(executeFetch, calcDelayDuration(retryCount, retryDelay, maxRetries, backoff, maxDelay));
|
|
935
960
|
retryCount += 1;
|
|
@@ -1043,7 +1068,7 @@ function createQueueMiddleware({
|
|
|
1043
1068
|
|
|
1044
1069
|
var packageJson = {
|
|
1045
1070
|
name: "@commercetools/sdk-client-v2",
|
|
1046
|
-
version: "2.
|
|
1071
|
+
version: "2.4.1",
|
|
1047
1072
|
engines: {
|
|
1048
1073
|
node: ">=14"
|
|
1049
1074
|
},
|
|
@@ -1115,9 +1140,8 @@ var packageJson = {
|
|
|
1115
1140
|
*/
|
|
1116
1141
|
const isBrowser = () => typeof window !== 'undefined' && window.document && window.document.nodeType === 9;
|
|
1117
1142
|
function getSystemInfo() {
|
|
1118
|
-
var _process;
|
|
1119
1143
|
if (isBrowser()) return window.navigator.userAgent;
|
|
1120
|
-
const nodeVersion =
|
|
1144
|
+
const nodeVersion = process?.version.slice(1) || '12'; // temporary fix for rn environment
|
|
1121
1145
|
// const platformInfo = `(${process.platform}; ${process.arch})`
|
|
1122
1146
|
// return `Node.js/${nodeVersion} ${platformInfo}`
|
|
1123
1147
|
|
|
@@ -1301,7 +1325,7 @@ class ClientBuilder {
|
|
|
1301
1325
|
...rest
|
|
1302
1326
|
} = options;
|
|
1303
1327
|
this.withUserAgentMiddleware({
|
|
1304
|
-
customAgent:
|
|
1328
|
+
customAgent: rest?.userAgent || 'typescript-sdk-apm-middleware'
|
|
1305
1329
|
});
|
|
1306
1330
|
this.telemetryMiddleware = createTelemetryMiddleware(rest);
|
|
1307
1331
|
return this;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import fetch$1 from 'node-fetch';
|
|
2
2
|
import { Buffer } from 'buffer/';
|
|
3
3
|
|
|
4
|
-
function
|
|
5
|
-
if (
|
|
6
|
-
var
|
|
7
|
-
if (
|
|
8
|
-
var
|
|
9
|
-
if (
|
|
4
|
+
function toPrimitive(t, r) {
|
|
5
|
+
if ("object" != typeof t || !t) return t;
|
|
6
|
+
var e = t[Symbol.toPrimitive];
|
|
7
|
+
if (void 0 !== e) {
|
|
8
|
+
var i = e.call(t, r || "default");
|
|
9
|
+
if ("object" != typeof i) return i;
|
|
10
10
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
11
11
|
}
|
|
12
|
-
return (
|
|
12
|
+
return ("string" === r ? String : Number)(t);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
function
|
|
16
|
-
var
|
|
17
|
-
return
|
|
15
|
+
function toPropertyKey(t) {
|
|
16
|
+
var i = toPrimitive(t, "string");
|
|
17
|
+
return "symbol" == typeof i ? i : String(i);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
function _defineProperty(obj, key, value) {
|
|
21
|
-
key =
|
|
21
|
+
key = toPropertyKey(key);
|
|
22
22
|
if (key in obj) {
|
|
23
23
|
Object.defineProperty(obj, key, {
|
|
24
24
|
value: value,
|
|
@@ -32,6 +32,14 @@ function _defineProperty(obj, key, value) {
|
|
|
32
32
|
return obj;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
function isDefined(value) {
|
|
36
|
+
return typeof value !== 'undefined' && value !== null;
|
|
37
|
+
}
|
|
38
|
+
function clean(value) {
|
|
39
|
+
if (!isDefined(value)) return '';
|
|
40
|
+
if (typeof value == 'string') return value;
|
|
41
|
+
return Object.fromEntries(Object.entries(value).filter(([_, value]) => ![null, undefined, ''].includes(value)));
|
|
42
|
+
}
|
|
35
43
|
function urlParser(url) {
|
|
36
44
|
const object = {};
|
|
37
45
|
const data = new URLSearchParams(url);
|
|
@@ -44,9 +52,24 @@ function urlParser(url) {
|
|
|
44
52
|
}
|
|
45
53
|
return object;
|
|
46
54
|
}
|
|
55
|
+
function urlStringifier(object) {
|
|
56
|
+
object = clean(object);
|
|
57
|
+
if (!object) return '';
|
|
58
|
+
const params = new URLSearchParams(object);
|
|
59
|
+
for (const [key, value] of Object.entries(object)) {
|
|
60
|
+
if (Array.isArray(value)) {
|
|
61
|
+
params.delete(key);
|
|
62
|
+
value.filter(isDefined).forEach(v => params.append(key, v));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return params.toString();
|
|
66
|
+
}
|
|
47
67
|
function parseURLString(url, parser = urlParser) {
|
|
48
68
|
return parser(url);
|
|
49
69
|
}
|
|
70
|
+
function stringifyURLString(object, stringifier = urlStringifier) {
|
|
71
|
+
return stringifier(object);
|
|
72
|
+
}
|
|
50
73
|
|
|
51
74
|
var METHODS = ['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'];
|
|
52
75
|
|
|
@@ -62,6 +85,7 @@ function validate(funcName, request, options = {
|
|
|
62
85
|
}
|
|
63
86
|
|
|
64
87
|
let _options;
|
|
88
|
+
const PAGE_LIMIT = 20;
|
|
65
89
|
function compose(...funcs) {
|
|
66
90
|
funcs = funcs.filter(func => typeof func === 'function');
|
|
67
91
|
if (funcs.length === 1) return funcs[0];
|
|
@@ -75,6 +99,8 @@ function process$1(request, fn, processOpt) {
|
|
|
75
99
|
|
|
76
100
|
// Set default process options
|
|
77
101
|
const opt = {
|
|
102
|
+
limit: PAGE_LIMIT,
|
|
103
|
+
// defaults
|
|
78
104
|
total: Number.POSITIVE_INFINITY,
|
|
79
105
|
accumulate: true,
|
|
80
106
|
...processOpt
|
|
@@ -94,7 +120,7 @@ function process$1(request, fn, processOpt) {
|
|
|
94
120
|
};
|
|
95
121
|
const query = {
|
|
96
122
|
// defaults
|
|
97
|
-
limit:
|
|
123
|
+
limit: opt.limit,
|
|
98
124
|
// merge given query params
|
|
99
125
|
...requestQuery
|
|
100
126
|
};
|
|
@@ -104,19 +130,20 @@ function process$1(request, fn, processOpt) {
|
|
|
104
130
|
// Use the lesser value between limit and itemsToGet in query
|
|
105
131
|
const limit = query.limit < itemsToGet ? query.limit : itemsToGet;
|
|
106
132
|
// const originalQueryString = qs.stringify({ ...query, limit }, qsOptions)
|
|
107
|
-
const originalQueryString =
|
|
133
|
+
const originalQueryString = stringifyURLString({
|
|
108
134
|
...query,
|
|
109
135
|
limit
|
|
110
|
-
})
|
|
136
|
+
});
|
|
111
137
|
const enhancedQuery = {
|
|
112
|
-
sort: 'id asc',
|
|
138
|
+
sort: opt.sort || 'id asc',
|
|
113
139
|
withTotal: false,
|
|
114
140
|
...(lastId ? {
|
|
115
141
|
where: `id > "${lastId}"`
|
|
116
142
|
} : {})
|
|
117
143
|
};
|
|
144
|
+
|
|
118
145
|
// const enhancedQueryString = qs.stringify(enhancedQuery, qsOptions)
|
|
119
|
-
const enhancedQueryString =
|
|
146
|
+
const enhancedQueryString = stringifyURLString(enhancedQuery);
|
|
120
147
|
const enhancedRequest = {
|
|
121
148
|
...request,
|
|
122
149
|
uri: `${_path}?${enhancedQueryString}&${originalQueryString}`
|
|
@@ -131,7 +158,7 @@ function process$1(request, fn, processOpt) {
|
|
|
131
158
|
return resolve(acc || []);
|
|
132
159
|
}
|
|
133
160
|
const result = await Promise.resolve(fn(payload));
|
|
134
|
-
let accumulated;
|
|
161
|
+
let accumulated = [];
|
|
135
162
|
hasFirstPageBeenProcessed = true;
|
|
136
163
|
if (opt.accumulate) accumulated = acc.concat(result || []);
|
|
137
164
|
itemsToGet -= resultsLength;
|
|
@@ -727,11 +754,9 @@ function createError({
|
|
|
727
754
|
}) {
|
|
728
755
|
let errorMessage = message || 'Unexpected non-JSON error response';
|
|
729
756
|
if (statusCode === 404) {
|
|
730
|
-
|
|
731
|
-
errorMessage = `URI not found: ${((_rest$originalRequest = rest.originalRequest) === null || _rest$originalRequest === void 0 ? void 0 : _rest$originalRequest.uri) || rest.uri}`;
|
|
757
|
+
errorMessage = `URI not found: ${rest.originalRequest?.uri || rest.uri}`;
|
|
732
758
|
delete rest.uri; // remove the `uri` property from the response
|
|
733
759
|
}
|
|
734
|
-
|
|
735
760
|
const ResponseError = getErrorByCode(statusCode);
|
|
736
761
|
if (ResponseError) return new ResponseError(errorMessage, rest);
|
|
737
762
|
return new HttpError(statusCode, errorMessage, rest);
|
|
@@ -921,7 +946,7 @@ function createHttpMiddleware({
|
|
|
921
946
|
body: parsed
|
|
922
947
|
})
|
|
923
948
|
});
|
|
924
|
-
if (enableRetry && (retryCodes.indexOf(error.statusCode) !== -1 ||
|
|
949
|
+
if (enableRetry && (retryCodes.indexOf(error.statusCode) !== -1 || retryCodes?.indexOf(error.message) !== -1)) {
|
|
925
950
|
if (retryCount < maxRetries) {
|
|
926
951
|
setTimeout(executeFetch, calcDelayDuration(retryCount, retryDelay, maxRetries, backoff, maxDelay));
|
|
927
952
|
retryCount += 1;
|
|
@@ -1035,7 +1060,7 @@ function createQueueMiddleware({
|
|
|
1035
1060
|
|
|
1036
1061
|
var packageJson = {
|
|
1037
1062
|
name: "@commercetools/sdk-client-v2",
|
|
1038
|
-
version: "2.
|
|
1063
|
+
version: "2.4.1",
|
|
1039
1064
|
engines: {
|
|
1040
1065
|
node: ">=14"
|
|
1041
1066
|
},
|
|
@@ -1107,9 +1132,8 @@ var packageJson = {
|
|
|
1107
1132
|
*/
|
|
1108
1133
|
const isBrowser = () => typeof window !== 'undefined' && window.document && window.document.nodeType === 9;
|
|
1109
1134
|
function getSystemInfo() {
|
|
1110
|
-
var _process;
|
|
1111
1135
|
if (isBrowser()) return window.navigator.userAgent;
|
|
1112
|
-
const nodeVersion =
|
|
1136
|
+
const nodeVersion = process?.version.slice(1) || '12'; // temporary fix for rn environment
|
|
1113
1137
|
// const platformInfo = `(${process.platform}; ${process.arch})`
|
|
1114
1138
|
// return `Node.js/${nodeVersion} ${platformInfo}`
|
|
1115
1139
|
|
|
@@ -1293,7 +1317,7 @@ class ClientBuilder {
|
|
|
1293
1317
|
...rest
|
|
1294
1318
|
} = options;
|
|
1295
1319
|
this.withUserAgentMiddleware({
|
|
1296
|
-
customAgent:
|
|
1320
|
+
customAgent: rest?.userAgent || 'typescript-sdk-apm-middleware'
|
|
1297
1321
|
});
|
|
1298
1322
|
this.telemetryMiddleware = createTelemetryMiddleware(rest);
|
|
1299
1323
|
return this;
|
|
@@ -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:()=>{},52:()=>{},392:(e,t,r)=>{"use strict";r.d(t,{Z:()=>j});var n=r(872),o=r.n(n),i=r(123),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,O=c.Z;const j=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().withUserAgentMiddleware()},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(O(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.withTelemetryMiddleware=function(e){var t=e.createTelemetryMiddleware,r=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,["createTelemetryMiddleware"]);return this.withUserAgentMiddleware({customAgent:(null==r?void 0:r.userAgent)||"typescript-sdk-apm-middleware"}),this.telemetryMiddleware=t(r),this},e.prototype.build=function(){var e=this.middlewares.slice();return this.telemetryMiddleware&&e.push(this.telemetryMiddleware),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}()},123:(e,t,r)=>{"use strict";r.d(t,{Z:()=>y,N:()=>p});var n=function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};function o(e){var t,r,o={},i=new URLSearchParams(e);try{for(var a=n(i.keys()),s=a.next();!s.done;s=a.next()){var c=s.value;i.getAll(c).length>1?o[c]=i.getAll(c):o[c]=i.get(c)}}catch(e){t={error:e}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}return o}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)},u=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{c(n.next(e))}catch(e){i(e)}}function s(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}c((n=n.apply(e,t||[])).next())}))},l=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(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}},h=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a},d=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 f(){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,d([],h(r),!1)))}}))}function p(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 d,f="";if(e&&e.uri){var p=h(e.uri.split("?"),2),w=p[0],v=p[1];d=w,f=v}var g,m=c({},(void 0===g&&(g=o),g(f))),b=c({limit:20},m),O=!1,j=i.total,C=function(o,h){return void 0===h&&(h=[]),u(n,void 0,void 0,(function(){var n,u,f,p,w,v,g,m,M,k,A,S,E,T;return l(this,(function(l){switch(l.label){case 0:n=b.limit<j?b.limit:j,u=new URLSearchParams(c(c({},b),{limit:n})).toString(),f=c({sort:"id asc",withTotal:!1},o?{where:'id > "'.concat(o,'"')}:{}),p=new URLSearchParams(f).toString(),w=c(c({},e),{uri:"".concat(d,"?").concat(p,"&").concat(u)}),l.label=1;case 1:return l.trys.push([1,4,,5]),[4,y(s).execute(w)];case 2:return v=l.sent(),g=v.body,m=g.results,!(M=g.count)&&O?[2,r(h||[])]:[4,Promise.resolve(t(v))];case 3:return k=l.sent(),A=void 0,O=!0,i.accumulate&&(A=h.concat(k||[])),j-=M,M<b.limit||!j?[2,r(A||[])]:(S=m[M-1],E=S&&S.id,C(E,A),[3,5]);case 4:return T=l.sent(),a(T),[3,5];case 5:return[2]}}))}))};C()}))}function y(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:p,execute:function(t){return a("exec",t),new Promise((function(r,n){f.apply(void 0,d([],h(e.middlewares),!1))((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:()=>a,ZP:()=>y,oo:()=>s});var n=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a},o=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 i(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 a(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this,0],n(e),!1))}function s(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this],n(e),!1))}function c(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this,400],n(e),!1))}function u(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this,401],n(e),!1))}function l(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this,403],n(e),!1))}function h(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this,404],n(e),!1))}function d(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this,409],n(e),!1))}function f(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this,500],n(e),!1))}function p(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this,503],n(e),!1))}function y(e){switch(e){case 0:return a;case 400:return c;case 401:return u;case 403:return l;case 404:return h;case 409:return d;case 500:return f;case 503:return p;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=e.tokenCache||(0,i.Z)({token:"",expirationTime:-1}),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:()=>l});var n=r(935),o=r(754),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=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{c(n.next(e))}catch(e){i(e)}}function s(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}c((n=n.apply(e,t||[])).next())}))},s=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(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}};function c(e,t){return i(i({},t),{headers:i(i({},t.headers),{Authorization:"Bearer ".concat(e)})})}function u(e){var t=e.fetcher,r=e.url,n=e.basicAuth,i=e.body,u=e.tokenCache,l=e.requestState,h=e.pendingTasks,d=e.response,f=e.tokenCacheKey;return a(this,void 0,void 0,(function(){var e,a,p,y,w,v,g,m,b,O,j;return s(this,(function(s){switch(s.label){case 0:return s.trys.push([0,5,,6]),[4,t(r,{method:"POST",headers:{Authorization:"Basic ".concat(n),"Content-Length":o.Buffer.byteLength(i).toString(),"Content-Type":"application/x-www-form-urlencoded"},body:i})];case 1:return(e=s.sent()).ok?[4,e.json()]:[3,3];case 2:return a=s.sent(),p=a.access_token,y=a.expires_in,w=a.refresh_token,v=function(e){return Date.now()+1e3*e-3e5}(y),u.set({token:p,expirationTime:v,refreshToken:w},f),l.set(!1),g=h.slice(),h=[],g.forEach((function(e){var t=c(p,e.request);e.next(t,e.response)})),[2];case 3:return m=void 0,[4,e.text()];case 4:b=s.sent();try{m=JSON.parse(b)}catch(e){}return O=new Error(m?m.message:b),m&&(O.body=m),l.set(!1),d.reject(O),[3,6];case 5:return j=s.sent(),l.set(!1),d&&"function"==typeof d.reject&&d.reject(j),[3,6];case 6:return[2]}}))}))}function l(e,t,r){var o=e.request,a=e.response,s=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),o.headers&&o.headers.authorization||o.headers&&o.headers.Authorization)t(o,a);else{var v=p.get(y);if(v&&v.token&&Date.now()<v.expirationTime)t(c(v.token,o),a);else if(d.push({request:o,response:a,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");u(i(i({fetcher:w},(0,n.Um)(i(i({},r),{refreshToken:v.refreshToken}))),{tokenCacheKey:y,tokenCache:p,requestState:f,pendingTasks:d,response:a}))}else u({fetcher:w,url:s,basicAuth:l,body:h,tokenCacheKey:y,tokenCache:p,requestState:f,pendingTasks:d,response:a})}}},935:(e,t,r)=>{"use strict";r.d(t,{BB:()=>i,Um:()=>s,Vk:()=>c,_T:()=>a});var n=r(754),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)};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,o=t.clientSecret;if(!r||!o)throw new Error("Missing required credentials (clientId, clientSecret)");var i=e.scopes?e.scopes.join(" "):void 0,a=n.Buffer.from("".concat(r,":").concat(o)).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,o=t.clientSecret,i=t.user,a=e.projectKey;if(!(r&&o&&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=n.Buffer.from("".concat(r,":").concat(o)).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,o=t.clientSecret;if(!r||!o)throw new Error("Missing required credentials (clientId, clientSecret)");var i=n.Buffer.from("".concat(r,":").concat(o)).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)),o({},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=e.tokenCache||(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=e.tokenCache||(0,i.Z)({token:"",expirationTime:-1}),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(e){return t},set:function(e,r){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:()=>f});var n=r(754),o=r(109);function i(e){if(e.raw)return e.raw();if(!e.forEach)return{};var t={};return e.forEach((function(e,r){t[r]=e})),t}var 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)},s=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},c=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a},u=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 l(e){return null!=e&&null!=e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function h(e,t,r,n,o){return n&&0!==e?Math.min(Math.round((Math.random()+1)*t*Math.pow(2,e)),o):t}function d(e,t){t&&(e&&e.headers&&e.headers.authorization&&(e.headers.authorization="Bearer ********"),e&&e.headers&&e.headers.Authorization&&(e.headers.Authorization="Bearer ********"))}function f(e){var t,r=e.host,f=e.credentialsMode,p=e.includeResponseHeaders,y=e.includeOriginalRequest,w=e.includeRequestInErrorResponse,v=void 0===w||w,g=e.maskSensitiveHeaderData,m=void 0===g||g,b=e.headersWithStringBody,O=void 0===b?[]:b,j=e.enableRetry,C=e.timeout,M=e.retryConfig,k=void 0===M?{}:M,A=k.maxRetries,S=void 0===A?10:A,E=k.backoff,T=void 0===E||E,q=k.retryDelay,P=void 0===q?200:q,x=k.maxDelay,Z=void 0===x?1/0:x,I=k.retryOnAbort,R=void 0!==I&&I,K=k.retryCodes,U=void 0===K?[503]:K,B=e.fetch,F=e.getAbortController;if(!B)throw new Error("`fetch` is not available. Please pass in `fetch` as an option or have it globally available.");if(C&&!F)throw new Error("`AbortController` is not available. Please pass in `getAbortController` as an option or have AbortController globally available when using timeout.");if(t=B||fetch,!Array.isArray(U))throw new Error("`retryCodes` option must be an array of retry status (error) codes.");if(!Array.isArray(O))throw new Error("`headersWithStringBody` option must be an array of strings");return function(e){return function(w,g){var b=r.replace(/\/$/,"")+w.uri,M=a({},w.headers);Object.prototype.hasOwnProperty.call(M,"Content-Type")||Object.prototype.hasOwnProperty.call(M,"content-type")||(M["Content-Type"]="application/json"),null===M["Content-Type"]&&delete M["Content-Type"];var k=u(["application/json","application/graphql"],c(O),!1).indexOf(M["Content-Type"])>-1&&"string"==typeof w.body||l(w.body)?w.body:JSON.stringify(w.body||void 0);k&&("string"==typeof k||l(k))&&(M["Content-Length"]=n.Buffer.byteLength(k).toString());var A={method:w.method,headers:M};f&&(A.credentialsMode=f),k&&(A.body=k);var E=0;!function r(){var n,c;C&&(c=(F?F():null)||new AbortController,A.signal=c.signal,n=setTimeout((function(){c.abort()}),C)),t(b,A).then((function(t){if(t.ok)return"HEAD"===A.method?void e(w,a(a({},g),{statusCode:t.status})):void t.text().then((function(n){var o;try{o=n.length>0?JSON.parse(n):{}}catch(e){if(j&&E<S)return setTimeout(r,h(E,P,0,T,Z)),void(E+=1);o=n}var s=a(a({},g),{body:o,statusCode:t.status});p&&(s.headers=i(t.headers)),y&&(s.request=a({},A),d(s.request,m)),e(w,s)})).catch((function(t){if(j&&E<S)return setTimeout(r,h(E,P,0,T,Z)),void(E+=1);var n=new o.F7(t.message,a(a({},v?{originalRequest:w}:{}),{retryCount:E}));d(n.originalRequest,m),e(w,a(a({},g),{error:n,statusCode:0}))}));t.text().then((function(n){var c;try{c=JSON.parse(n)}catch(u){c=n}var u=function(e){var t,r=e.statusCode,n=e.message,i=s(e,["statusCode","message"]),a=n||"Unexpected non-JSON error response";404===r&&(a="URI not found: ".concat((null===(t=i.originalRequest)||void 0===t?void 0:t.uri)||i.uri),delete i.uri);var c=(0,o.ZP)(r);return c?new c(a,i):new o.oo(r,a,i)}(a(a(a({statusCode:t.status},v?{originalRequest:w}:404===t.status?{uri:w.uri}:{}),{retryCount:E,headers:i(t.headers)}),"object"==typeof c?{message:c.message,body:c}:{message:c,body:c}));if(j&&(-1!==U.indexOf(u.statusCode)||-1!==(null==U?void 0:U.indexOf(u.message)))&&E<S)return setTimeout(r,h(E,P,0,T,Z)),void(E+=1);d(u.originalRequest,m);var l=a(a({},g),{error:u,statusCode:t.status});e(w,l)}))}),(function(t){if(j&&(R||!c||!c.signal)&&E<S)return setTimeout(r,h(E,P,0,T,Z)),void(E+=1);var n=new o.F7(t.message,a(a({},v?{originalRequest:w}:{}),{retryCount:E}));d(n.originalRequest,m),e(w,a(a({},g),{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:()=>s});const n={i8:"2.3.0"};var o=r(696),i=function(){return"undefined"!=typeof window&&window.document&&9===window.document.nodeType};var 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=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,function(){if(i())return window.navigator.userAgent;var e=(null==o?void 0:o.version.slice(1))||"12";return"node.js/".concat(e)}(),r,n,e.customAgent||""].filter(Boolean).join(" ")}(a(a({},e),{name:"commercetools-sdk-javascript-v2/".concat(n.i8)}));return function(e){return function(r,n){var o=a(a({},r),{headers:a(a({},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(123),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={146:()=>{},830:()=>{},33:()=>{},633:()=>{},854:()=>{},435:(e,t,r)=>{"use strict";r.d(t,{A:()=>O});var n=r(33),o=r.n(n),i=r(822),a=r(571),s=r(241),c=r(901),u=r(646),l=r(726),h=r(510),d=r(650),f=r(345),p=r(412),y=r(15),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.A,g=a.A,m=s.A,b=l.A,A=c.A;const O=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().withUserAgentMiddleware()},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(A(e,w({force:t.force||!0},t)))},e.prototype.withHttpMiddleware=function(e){return this.httpMiddleware=(0,d.A)(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.A)(e),this},e.prototype.withQueueMiddleware=function(e){return this.queueMiddleware=(0,p.A)(w({concurrency:e.concurrency||20},e)),this},e.prototype.withLoggerMiddleware=function(){return this.loggerMiddleware=(0,f.A)(),this},e.prototype.withCorrelationIdMiddleware=function(e){return this.correlationIdMiddleware=(0,h.A)(w({generate:e.generate||null},e)),this},e.prototype.withTelemetryMiddleware=function(e){var t=e.createTelemetryMiddleware,r=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,["createTelemetryMiddleware"]);return this.withUserAgentMiddleware({customAgent:(null==r?void 0:r.userAgent)||"typescript-sdk-apm-middleware"}),this.telemetryMiddleware=t(r),this},e.prototype.build=function(){var e=this.middlewares.slice();return this.telemetryMiddleware&&e.push(this.telemetryMiddleware),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.Ay)({middlewares:e})},e}()},822:(e,t,r)=>{"use strict";r.d(t,{Ay:()=>b,eh:()=>m});var n=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a},o=function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};function i(e){return null!=e}function a(e){var t,r,n={},i=new URLSearchParams(e);try{for(var a=o(i.keys()),s=a.next();!s.done;s=a.next()){var c=s.value;i.getAll(c).length>1?n[c]=i.getAll(c):n[c]=i.get(c)}}catch(e){t={error:e}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}return n}function s(e){var t,r,a;if(e=i(a=e)?"string"==typeof a?a:Object.fromEntries(Object.entries(a).filter((function(e){var t=n(e,2),r=(t[0],t[1]);return![null,void 0,""].includes(r)}))):"",!e)return"";var s=new URLSearchParams(e),c=function(e,t){Array.isArray(t)&&(s.delete(e),t.filter(i).forEach((function(t){return s.append(e,t)})))};try{for(var u=o(Object.entries(e)),l=u.next();!l.done;l=u.next()){var h=n(l.value,2);c(h[0],h[1])}}catch(e){t={error:e}}finally{try{l&&!l.done&&(r=u.return)&&r.call(u)}finally{if(t)throw t.error}}return s.toString()}function c(e,t){return void 0===t&&(t=s),t(e)}const u=["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 l(e,t,r){if(void 0===r&&(r={allowedMethods:u}),!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 h,d=function(){return d=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},d.apply(this,arguments)},f=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{c(n.next(e))}catch(e){i(e)}}function s(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}c((n=n.apply(e,t||[])).next())}))},p=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(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}},y=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a},w=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))},v=20;function g(){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,w([],y(r),!1)))}}))}function m(e,t,r){var n=this;if(l("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 o=d({limit:v,total:Number.POSITIVE_INFINITY,accumulate:!0},r);return new Promise((function(r,i){var s,u="";if(e&&e.uri){var l=y(e.uri.split("?"),2),w=l[0],v=l[1];s=w,u=v}var g,m=d({},(void 0===g&&(g=a),g(u))),A=d({limit:o.limit},m),O=!1,j=o.total,C=function(a,u){return void 0===u&&(u=[]),f(n,void 0,void 0,(function(){var n,l,f,y,w,v,g,m,M,E,S,k,T,q;return p(this,(function(p){switch(p.label){case 0:n=A.limit<j?A.limit:j,l=c(d(d({},A),{limit:n})),f=d({sort:o.sort||"id asc",withTotal:!1},a?{where:'id > "'.concat(a,'"')}:{}),y=c(f),w=d(d({},e),{uri:"".concat(s,"?").concat(y,"&").concat(l)}),p.label=1;case 1:return p.trys.push([1,4,,5]),[4,b(h).execute(w)];case 2:return v=p.sent(),g=v.body,m=g.results,!(M=g.count)&&O?[2,r(u||[])]:[4,Promise.resolve(t(v))];case 3:return E=p.sent(),S=[],O=!0,o.accumulate&&(S=u.concat(E||[])),j-=M,M<A.limit||!j?[2,r(S||[])]:(k=m[M-1],T=k&&k.id,C(T,S),[3,5]);case 4:return q=p.sent(),i(q),[3,5];case 5:return[2]}}))}))};C()}))}function b(e){if(h=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:m,execute:function(t){return l("exec",t),new Promise((function(r,n){g.apply(void 0,w([],y(e.middlewares),!1))((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})}))}}}},367:(e,t,r)=>{"use strict";r.d(t,{Ay:()=>y,Dr:()=>a,j$:()=>s});var n=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a},o=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 i(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 a(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this,0],n(e),!1))}function s(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this],n(e),!1))}function c(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this,400],n(e),!1))}function u(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this,401],n(e),!1))}function l(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this,403],n(e),!1))}function h(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this,404],n(e),!1))}function d(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this,409],n(e),!1))}function f(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this,500],n(e),!1))}function p(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.call.apply(i,o([this,503],n(e),!1))}function y(e){switch(e){case 0:return a;case 400:return c;case 401:return u;case 403:return l;case 404:return h;case 409:return d;case 500:return f;case 503:return p;default:return}}},571:(e,t,r)=>{"use strict";r.d(t,{A:()=>s});var n=r(105),o=r(486),i=r(539),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=e.tokenCache||(0,i.A)({token:"",expirationTime:-1}),r=[],s=(0,i.A)(!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.O4)(e)),{pendingTasks:r,requestState:s,tokenCache:t,fetch:e.fetch});(0,n.A)(l,i,e)}}}}},105:(e,t,r)=>{"use strict";r.d(t,{A:()=>l});var n=r(486),o=r(146),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=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{c(n.next(e))}catch(e){i(e)}}function s(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}c((n=n.apply(e,t||[])).next())}))},s=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(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}};function c(e,t){return i(i({},t),{headers:i(i({},t.headers),{Authorization:"Bearer ".concat(e)})})}function u(e){var t=e.fetcher,r=e.url,n=e.basicAuth,i=e.body,u=e.tokenCache,l=e.requestState,h=e.pendingTasks,d=e.response,f=e.tokenCacheKey;return a(this,void 0,void 0,(function(){var e,a,p,y,w,v,g,m,b,A,O;return s(this,(function(s){switch(s.label){case 0:return s.trys.push([0,5,,6]),[4,t(r,{method:"POST",headers:{Authorization:"Basic ".concat(n),"Content-Length":o.Buffer.byteLength(i).toString(),"Content-Type":"application/x-www-form-urlencoded"},body:i})];case 1:return(e=s.sent()).ok?[4,e.json()]:[3,3];case 2:return a=s.sent(),p=a.access_token,y=a.expires_in,w=a.refresh_token,v=function(e){return Date.now()+1e3*e-3e5}(y),u.set({token:p,expirationTime:v,refreshToken:w},f),l.set(!1),g=h.slice(),h=[],g.forEach((function(e){var t=c(p,e.request);e.next(t,e.response)})),[2];case 3:return m=void 0,[4,e.text()];case 4:b=s.sent();try{m=JSON.parse(b)}catch(e){}return A=new Error(m?m.message:b),m&&(A.body=m),l.set(!1),d.reject(A),[3,6];case 5:return O=s.sent(),l.set(!1),d&&"function"==typeof d.reject&&d.reject(O),[3,6];case 6:return[2]}}))}))}function l(e,t,r){var o=e.request,a=e.response,s=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),o.headers&&o.headers.authorization||o.headers&&o.headers.Authorization)t(o,a);else{var v=p.get(y);if(v&&v.token&&Date.now()<v.expirationTime)t(c(v.token,o),a);else if(d.push({request:o,response:a,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");u(i(i({fetcher:w},(0,n.nO)(i(i({},r),{refreshToken:v.refreshToken}))),{tokenCacheKey:y,tokenCache:p,requestState:f,pendingTasks:d,response:a}))}else u({fetcher:w,url:s,basicAuth:l,body:h,tokenCacheKey:y,tokenCache:p,requestState:f,pendingTasks:d,response:a})}}},486:(e,t,r)=>{"use strict";r.d(t,{O4:()=>c,Wh:()=>a,nO:()=>s,wg:()=>i});var n=r(146),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)};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,o=t.clientSecret;if(!r||!o)throw new Error("Missing required credentials (clientId, clientSecret)");var i=e.scopes?e.scopes.join(" "):void 0,a=n.Buffer.from("".concat(r,":").concat(o)).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,o=t.clientSecret,i=t.user,a=e.projectKey;if(!(r&&o&&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=n.Buffer.from("".concat(r,":").concat(o)).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,o=t.clientSecret;if(!r||!o)throw new Error("Missing required credentials (clientId, clientSecret)");var i=n.Buffer.from("".concat(r,":").concat(o)).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)),o({},r)}},241:(e,t,r)=>{"use strict";r.d(t,{A:()=>c});var n=r(105),o=r(486);function i(e){return{clientId:e.credentials.clientId,host:e.host,projectKey:e.projectKey}}var a=r(539),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.A)({token:"",expirationTime:-1}),r=(0,a.A)(!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.wg)(e)),{pendingTasks:c,requestState:r,tokenCache:t,tokenCacheKey:i(e),fetch:e.fetch});(0,n.A)(h,a)}}}}},901:(e,t,r)=>{"use strict";r.d(t,{A:()=>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)}}}},646:(e,t,r)=>{"use strict";r.d(t,{A:()=>s});var n=r(105),o=r(486),i=r(539),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=e.tokenCache||(0,i.A)({}),r=[],s=(0,i.A)(!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.Wh)(e)),{pendingTasks:r,requestState:s,tokenCache:t,fetch:e.fetch});(0,n.A)(l,i,e)}}}}},726:(e,t,r)=>{"use strict";r.d(t,{A:()=>s});var n=r(105),o=r(486),i=r(539),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=e.tokenCache||(0,i.A)({token:"",expirationTime:-1}),r=[],s=(0,i.A)(!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.nO)(e)),{pendingTasks:r,requestState:s,tokenCache:t,fetch:e.fetch});(0,n.A)(l,i)}}}}},539:(e,t,r)=>{"use strict";function n(e){var t=e;return{get:function(e){return t},set:function(e,r){t=e}}}r.d(t,{A:()=>n})},510:(e,t,r)=>{"use strict";r.d(t,{A:()=>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)}}}},650:(e,t,r)=>{"use strict";r.d(t,{A:()=>f});var n=r(146),o=r(367);function i(e){if(e.raw)return e.raw();if(!e.forEach)return{};var t={};return e.forEach((function(e,r){t[r]=e})),t}var 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)},s=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},c=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a},u=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 l(e){return null!=e&&null!=e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function h(e,t,r,n,o){return n&&0!==e?Math.min(Math.round((Math.random()+1)*t*Math.pow(2,e)),o):t}function d(e,t){t&&(e&&e.headers&&e.headers.authorization&&(e.headers.authorization="Bearer ********"),e&&e.headers&&e.headers.Authorization&&(e.headers.Authorization="Bearer ********"))}function f(e){var t,r=e.host,f=e.credentialsMode,p=e.includeResponseHeaders,y=e.includeOriginalRequest,w=e.includeRequestInErrorResponse,v=void 0===w||w,g=e.maskSensitiveHeaderData,m=void 0===g||g,b=e.headersWithStringBody,A=void 0===b?[]:b,O=e.enableRetry,j=e.timeout,C=e.retryConfig,M=void 0===C?{}:C,E=M.maxRetries,S=void 0===E?10:E,k=M.backoff,T=void 0===k||k,q=M.retryDelay,x=void 0===q?200:q,P=M.maxDelay,I=void 0===P?1/0:P,K=M.retryOnAbort,R=void 0!==K&&K,U=M.retryCodes,N=void 0===U?[503]:U,F=e.fetch,B=e.getAbortController;if(!F)throw new Error("`fetch` is not available. Please pass in `fetch` as an option or have it globally available.");if(j&&!B)throw new Error("`AbortController` is not available. Please pass in `getAbortController` as an option or have AbortController globally available when using timeout.");if(t=F||fetch,!Array.isArray(N))throw new Error("`retryCodes` option must be an array of retry status (error) codes.");if(!Array.isArray(A))throw new Error("`headersWithStringBody` option must be an array of strings");return function(e){return function(w,g){var b=r.replace(/\/$/,"")+w.uri,C=a({},w.headers);Object.prototype.hasOwnProperty.call(C,"Content-Type")||Object.prototype.hasOwnProperty.call(C,"content-type")||(C["Content-Type"]="application/json"),null===C["Content-Type"]&&delete C["Content-Type"];var M=u(["application/json","application/graphql"],c(A),!1).indexOf(C["Content-Type"])>-1&&"string"==typeof w.body||l(w.body)?w.body:JSON.stringify(w.body||void 0);M&&("string"==typeof M||l(M))&&(C["Content-Length"]=n.Buffer.byteLength(M).toString());var E={method:w.method,headers:C};f&&(E.credentialsMode=f),M&&(E.body=M);var k=0;!function r(){var n,c;j&&(c=(B?B():null)||new AbortController,E.signal=c.signal,n=setTimeout((function(){c.abort()}),j)),t(b,E).then((function(t){if(t.ok)return"HEAD"===E.method?void e(w,a(a({},g),{statusCode:t.status})):void t.text().then((function(n){var o;try{o=n.length>0?JSON.parse(n):{}}catch(e){if(O&&k<S)return setTimeout(r,h(k,x,0,T,I)),void(k+=1);o=n}var s=a(a({},g),{body:o,statusCode:t.status});p&&(s.headers=i(t.headers)),y&&(s.request=a({},E),d(s.request,m)),e(w,s)})).catch((function(t){if(O&&k<S)return setTimeout(r,h(k,x,0,T,I)),void(k+=1);var n=new o.Dr(t.message,a(a({},v?{originalRequest:w}:{}),{retryCount:k}));d(n.originalRequest,m),e(w,a(a({},g),{error:n,statusCode:0}))}));t.text().then((function(n){var c;try{c=JSON.parse(n)}catch(u){c=n}var u=function(e){var t,r=e.statusCode,n=e.message,i=s(e,["statusCode","message"]),a=n||"Unexpected non-JSON error response";404===r&&(a="URI not found: ".concat((null===(t=i.originalRequest)||void 0===t?void 0:t.uri)||i.uri),delete i.uri);var c=(0,o.Ay)(r);return c?new c(a,i):new o.j$(r,a,i)}(a(a(a({statusCode:t.status},v?{originalRequest:w}:404===t.status?{uri:w.uri}:{}),{retryCount:k,headers:i(t.headers)}),"object"==typeof c?{message:c.message,body:c}:{message:c,body:c}));if(O&&(-1!==N.indexOf(u.statusCode)||-1!==(null==N?void 0:N.indexOf(u.message)))&&k<S)return setTimeout(r,h(k,x,0,T,I)),void(k+=1);d(u.originalRequest,m);var l=a(a({},g),{error:u,statusCode:t.status});e(w,l)}))}),(function(t){if(O&&(R||!c||!c.signal)&&k<S)return setTimeout(r,h(k,x,0,T,I)),void(k+=1);var n=new o.Dr(t.message,a(a({},v?{originalRequest:w}:{}),{retryCount:k}));d(n.originalRequest,m),e(w,a(a({},g),{error:n,statusCode:0}))})).finally((function(){clearTimeout(n)}))}()}}}},345:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var n=r(830);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)}}}},412:(e,t,r)=>{"use strict";r.d(t,{A:()=>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)}}}}},15:(e,t,r)=>{"use strict";r.d(t,{A:()=>s});const n={rE:"2.4.1"};var o=r(633),i=function(){return"undefined"!=typeof window&&window.document&&9===window.document.nodeType};var 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=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,function(){if(i())return window.navigator.userAgent;var e=(null==o?void 0:o.version.slice(1))||"12";return"node.js/".concat(e)}(),r,n,e.customAgent||""].filter(Boolean).join(" ")}(a(a({},e),{name:"commercetools-sdk-javascript-v2/".concat(n.rE)}));return function(e){return function(r,n){var o=a(a({},r),{headers:a(a({},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.A,Process:()=>t.eh,createAuthForAnonymousSessionFlow:()=>i.A,createAuthForClientCredentialsFlow:()=>a.A,createAuthForPasswordFlow:()=>c.A,createAuthForRefreshTokenFlow:()=>u.A,createAuthWithExistingToken:()=>s.A,createClient:()=>t.Ay,createCorrelationIdMiddleware:()=>l.A,createHttpClient:()=>h.A,createLoggerMiddleware:()=>d.A,createQueueMiddleware:()=>f.A,createUserAgentMiddleware:()=>p.A,getErrorByCode:()=>o.Ay});var e=r(435),t=r(822),o=r(367),i=r(571),a=r(241),s=r(901),c=r(646),u=r(726),l=r(510),h=r(650),d=r(345),f=r(412),p=r(15),y=r(854),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,3 +1,12 @@
|
|
|
1
1
|
import { Client, ClientOptions, ClientRequest, ProcessFn, ProcessOptions } from "../types/sdk.js";
|
|
2
|
-
export declare
|
|
2
|
+
export declare const PAGE_LIMIT = 20;
|
|
3
|
+
export declare function process<T = any>(request: ClientRequest, fn: ProcessFn, processOpt: ProcessOptions): Promise<Array<{
|
|
4
|
+
statusCode: 200;
|
|
5
|
+
body: {
|
|
6
|
+
limit: number;
|
|
7
|
+
offset: number;
|
|
8
|
+
count: number;
|
|
9
|
+
results: T[];
|
|
10
|
+
};
|
|
11
|
+
}>>;
|
|
3
12
|
export default function createClient(options: ClientOptions): Client;
|
|
@@ -135,17 +135,30 @@ export type ClientResult = SuccessResult | HttpErrorType
|
|
|
135
135
|
export type ProcessFn = (result: SuccessResult) => Promise<any>
|
|
136
136
|
|
|
137
137
|
export type ProcessOptions = {
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
limit?: number;
|
|
139
|
+
sort?: string;
|
|
140
|
+
accumulate?: boolean;
|
|
141
|
+
total?: number;
|
|
140
142
|
}
|
|
141
143
|
|
|
144
|
+
export type ProcessResult<T = any> = Promise<Array<{
|
|
145
|
+
statusCode: number;
|
|
146
|
+
body: {
|
|
147
|
+
limit: number;
|
|
148
|
+
offset: number;
|
|
149
|
+
count: number;
|
|
150
|
+
total?: number;
|
|
151
|
+
results: T[];
|
|
152
|
+
}
|
|
153
|
+
}>>
|
|
154
|
+
|
|
142
155
|
export type Client = {
|
|
143
156
|
execute: (request: ClientRequest) => Promise<any>
|
|
144
157
|
process: (
|
|
145
158
|
request: ClientRequest,
|
|
146
159
|
fn: ProcessFn,
|
|
147
160
|
processOpt: ProcessOptions
|
|
148
|
-
) =>
|
|
161
|
+
) => ProcessResult;
|
|
149
162
|
}
|
|
150
163
|
|
|
151
164
|
export type ValiadateOption = {
|