@commercetools/sdk-client-v2 2.1.5 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @commercetools/sdk-client-v2
2
2
 
3
+ ## 2.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#458](https://github.com/commercetools/commercetools-sdk-typescript/pull/458) [`c2bf0a5`](https://github.com/commercetools/commercetools-sdk-typescript/commit/c2bf0a5cac18fdcf181dacc8c6714eb760704523) Thanks [@ajimae](https://github.com/ajimae)! - Introduce (newrelic) application performance monitoring
8
+
9
+ - [#458](https://github.com/commercetools/commercetools-sdk-typescript/pull/458) [`c2bf0a5`](https://github.com/commercetools/commercetools-sdk-typescript/commit/c2bf0a5cac18fdcf181dacc8c6714eb760704523) Thanks [@ajimae](https://github.com/ajimae)! - - add newrelic `APM` (application performance monitoring) to the sdk
10
+ - add `withTelemetryMiddleware()` middleware creator method to ClientBuilder class
11
+ - add basic `newrelic` application configuration module
12
+ - add examples to repository example folder to demonstrate how this feature can be used
13
+
14
+ ## 2.1.6
15
+
16
+ ### Patch Changes
17
+
18
+ - [#453](https://github.com/commercetools/commercetools-sdk-typescript/pull/453) [`a83e653`](https://github.com/commercetools/commercetools-sdk-typescript/commit/a83e653c986e50f31f71546edc721263d29990b5) Thanks [@ajimae](https://github.com/ajimae)! - - Remove all `querystring` dependency
19
+ - Add qs dependency to requiring package
20
+ - Refactor code to accommodate new implementation
21
+
3
22
  ## 2.1.5
4
23
 
5
24
  ### Patch Changes
@@ -3,13 +3,11 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var fetch$1 = require('node-fetch');
6
- var qs = require('querystring');
7
6
  var _ = require('buffer/');
8
7
 
9
8
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
10
9
 
11
10
  var fetch__default = /*#__PURE__*/_interopDefault(fetch$1);
12
- var qs__default = /*#__PURE__*/_interopDefault(qs);
13
11
 
14
12
  function _toPrimitive(input, hint) {
15
13
  if (typeof input !== "object" || input === null) return input;
@@ -55,6 +53,22 @@ function validate(funcName, request, options = {
55
53
  if (!options.allowedMethods.includes(request.method)) throw new Error(`The "${funcName}" Request object requires a valid method. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest`);
56
54
  }
57
55
 
56
+ function urlParser(url) {
57
+ const object = {};
58
+ const data = new URLSearchParams(url);
59
+ for (let x of data.keys()) {
60
+ if (data.getAll(x).length > 1) {
61
+ object[x] = data.getAll(x);
62
+ } else {
63
+ object[x] = data.get(x);
64
+ }
65
+ }
66
+ return object;
67
+ }
68
+ function parseURLString(url, parser = urlParser) {
69
+ return parser(url);
70
+ }
71
+
58
72
  let _options;
59
73
  function compose(...funcs) {
60
74
  funcs = funcs.filter(func => typeof func === 'function');
@@ -81,8 +95,10 @@ function process$1(request, fn, processOpt) {
81
95
  _path = path;
82
96
  _queryString = queryString;
83
97
  }
98
+ // const requestQuery = { ...qs.parse(_queryString) }
99
+ // const requestQuery = { ...Object.fromEntries(new URLSearchParams(_queryString)) }
84
100
  const requestQuery = {
85
- ...qs__default["default"].parse(_queryString)
101
+ ...parseURLString(_queryString)
86
102
  };
87
103
  const query = {
88
104
  // defaults
@@ -95,10 +111,11 @@ function process$1(request, fn, processOpt) {
95
111
  const processPage = async (lastId, acc = []) => {
96
112
  // Use the lesser value between limit and itemsToGet in query
97
113
  const limit = query.limit < itemsToGet ? query.limit : itemsToGet;
98
- const originalQueryString = qs__default["default"].stringify({
114
+ // const originalQueryString = qs.stringify({ ...query, limit }, qsOptions)
115
+ const originalQueryString = new URLSearchParams({
99
116
  ...query,
100
117
  limit
101
- });
118
+ }).toString();
102
119
  const enhancedQuery = {
103
120
  sort: 'id asc',
104
121
  withTotal: false,
@@ -106,7 +123,8 @@ function process$1(request, fn, processOpt) {
106
123
  where: `id > "${lastId}"`
107
124
  } : {})
108
125
  };
109
- const enhancedQueryString = qs__default["default"].stringify(enhancedQuery);
126
+ // const enhancedQueryString = qs.stringify(enhancedQuery, qsOptions)
127
+ const enhancedQueryString = new URLSearchParams(enhancedQuery).toString();
110
128
  const enhancedRequest = {
111
129
  ...request,
112
130
  uri: `${_path}?${enhancedQueryString}&${originalQueryString}`
@@ -1021,7 +1039,7 @@ function createQueueMiddleware({
1021
1039
 
1022
1040
  var packageJson = {
1023
1041
  name: "@commercetools/sdk-client-v2",
1024
- version: "2.1.5",
1042
+ version: "2.2.0",
1025
1043
  engines: {
1026
1044
  node: ">=14"
1027
1045
  },
@@ -1055,8 +1073,7 @@ var packageJson = {
1055
1073
  },
1056
1074
  dependencies: {
1057
1075
  buffer: "^6.0.3",
1058
- "node-fetch": "^2.6.1",
1059
- querystring: "^0.2.1"
1076
+ "node-fetch": "^2.6.1"
1060
1077
  },
1061
1078
  files: [
1062
1079
  "dist",
@@ -1157,6 +1174,7 @@ class ClientBuilder {
1157
1174
  _defineProperty(this, "correlationIdMiddleware", void 0);
1158
1175
  _defineProperty(this, "loggerMiddleware", void 0);
1159
1176
  _defineProperty(this, "queueMiddleware", void 0);
1177
+ _defineProperty(this, "telemetryMiddleware", void 0);
1160
1178
  _defineProperty(this, "middlewares", []);
1161
1179
  }
1162
1180
  withProjectKey(key) {
@@ -1273,8 +1291,17 @@ class ClientBuilder {
1273
1291
  });
1274
1292
  return this;
1275
1293
  }
1294
+ withTelemetryMiddleware(options) {
1295
+ const {
1296
+ createTelemetryMiddleware,
1297
+ ...rest
1298
+ } = options;
1299
+ this.telemetryMiddleware = createTelemetryMiddleware(rest);
1300
+ return this;
1301
+ }
1276
1302
  build() {
1277
1303
  const middlewares = this.middlewares.slice();
1304
+ if (this.telemetryMiddleware) middlewares.push(this.telemetryMiddleware);
1278
1305
  if (this.correlationIdMiddleware) middlewares.push(this.correlationIdMiddleware);
1279
1306
  if (this.userAgentMiddleware) middlewares.push(this.userAgentMiddleware);
1280
1307
  if (this.authMiddleware) middlewares.push(this.authMiddleware);
@@ -1,5 +1,4 @@
1
1
  import fetch$1 from 'node-fetch';
2
- import qs from 'querystring';
3
2
  import { Buffer } from 'buffer/';
4
3
 
5
4
  function _toPrimitive(input, hint) {
@@ -46,6 +45,22 @@ function validate(funcName, request, options = {
46
45
  if (!options.allowedMethods.includes(request.method)) throw new Error(`The "${funcName}" Request object requires a valid method. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest`);
47
46
  }
48
47
 
48
+ function urlParser(url) {
49
+ const object = {};
50
+ const data = new URLSearchParams(url);
51
+ for (let x of data.keys()) {
52
+ if (data.getAll(x).length > 1) {
53
+ object[x] = data.getAll(x);
54
+ } else {
55
+ object[x] = data.get(x);
56
+ }
57
+ }
58
+ return object;
59
+ }
60
+ function parseURLString(url, parser = urlParser) {
61
+ return parser(url);
62
+ }
63
+
49
64
  let _options;
50
65
  function compose(...funcs) {
51
66
  funcs = funcs.filter(func => typeof func === 'function');
@@ -72,8 +87,10 @@ function process$1(request, fn, processOpt) {
72
87
  _path = path;
73
88
  _queryString = queryString;
74
89
  }
90
+ // const requestQuery = { ...qs.parse(_queryString) }
91
+ // const requestQuery = { ...Object.fromEntries(new URLSearchParams(_queryString)) }
75
92
  const requestQuery = {
76
- ...qs.parse(_queryString)
93
+ ...parseURLString(_queryString)
77
94
  };
78
95
  const query = {
79
96
  // defaults
@@ -86,10 +103,11 @@ function process$1(request, fn, processOpt) {
86
103
  const processPage = async (lastId, acc = []) => {
87
104
  // Use the lesser value between limit and itemsToGet in query
88
105
  const limit = query.limit < itemsToGet ? query.limit : itemsToGet;
89
- const originalQueryString = qs.stringify({
106
+ // const originalQueryString = qs.stringify({ ...query, limit }, qsOptions)
107
+ const originalQueryString = new URLSearchParams({
90
108
  ...query,
91
109
  limit
92
- });
110
+ }).toString();
93
111
  const enhancedQuery = {
94
112
  sort: 'id asc',
95
113
  withTotal: false,
@@ -97,7 +115,8 @@ function process$1(request, fn, processOpt) {
97
115
  where: `id > "${lastId}"`
98
116
  } : {})
99
117
  };
100
- const enhancedQueryString = qs.stringify(enhancedQuery);
118
+ // const enhancedQueryString = qs.stringify(enhancedQuery, qsOptions)
119
+ const enhancedQueryString = new URLSearchParams(enhancedQuery).toString();
101
120
  const enhancedRequest = {
102
121
  ...request,
103
122
  uri: `${_path}?${enhancedQueryString}&${originalQueryString}`
@@ -1012,7 +1031,7 @@ function createQueueMiddleware({
1012
1031
 
1013
1032
  var packageJson = {
1014
1033
  name: "@commercetools/sdk-client-v2",
1015
- version: "2.1.5",
1034
+ version: "2.2.0",
1016
1035
  engines: {
1017
1036
  node: ">=14"
1018
1037
  },
@@ -1046,8 +1065,7 @@ var packageJson = {
1046
1065
  },
1047
1066
  dependencies: {
1048
1067
  buffer: "^6.0.3",
1049
- "node-fetch": "^2.6.1",
1050
- querystring: "^0.2.1"
1068
+ "node-fetch": "^2.6.1"
1051
1069
  },
1052
1070
  files: [
1053
1071
  "dist",
@@ -1148,6 +1166,7 @@ class ClientBuilder {
1148
1166
  _defineProperty(this, "correlationIdMiddleware", void 0);
1149
1167
  _defineProperty(this, "loggerMiddleware", void 0);
1150
1168
  _defineProperty(this, "queueMiddleware", void 0);
1169
+ _defineProperty(this, "telemetryMiddleware", void 0);
1151
1170
  _defineProperty(this, "middlewares", []);
1152
1171
  }
1153
1172
  withProjectKey(key) {
@@ -1264,8 +1283,17 @@ class ClientBuilder {
1264
1283
  });
1265
1284
  return this;
1266
1285
  }
1286
+ withTelemetryMiddleware(options) {
1287
+ const {
1288
+ createTelemetryMiddleware,
1289
+ ...rest
1290
+ } = options;
1291
+ this.telemetryMiddleware = createTelemetryMiddleware(rest);
1292
+ return this;
1293
+ }
1267
1294
  build() {
1268
1295
  const middlewares = this.middlewares.slice();
1296
+ if (this.telemetryMiddleware) middlewares.push(this.telemetryMiddleware);
1269
1297
  if (this.correlationIdMiddleware) middlewares.push(this.correlationIdMiddleware);
1270
1298
  if (this.userAgentMiddleware) middlewares.push(this.userAgentMiddleware);
1271
1299
  if (this.authMiddleware) middlewares.push(this.authMiddleware);
@@ -3,13 +3,11 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var fetch$1 = require('node-fetch');
6
- var qs = require('querystring');
7
6
  var _ = require('buffer/');
8
7
 
9
8
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
10
9
 
11
10
  var fetch__default = /*#__PURE__*/_interopDefault(fetch$1);
12
- var qs__default = /*#__PURE__*/_interopDefault(qs);
13
11
 
14
12
  function _toPrimitive(input, hint) {
15
13
  if (typeof input !== "object" || input === null) return input;
@@ -55,6 +53,22 @@ function validate(funcName, request, options = {
55
53
  if (!options.allowedMethods.includes(request.method)) throw new Error(`The "${funcName}" Request object requires a valid method. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest`);
56
54
  }
57
55
 
56
+ function urlParser(url) {
57
+ const object = {};
58
+ const data = new URLSearchParams(url);
59
+ for (let x of data.keys()) {
60
+ if (data.getAll(x).length > 1) {
61
+ object[x] = data.getAll(x);
62
+ } else {
63
+ object[x] = data.get(x);
64
+ }
65
+ }
66
+ return object;
67
+ }
68
+ function parseURLString(url, parser = urlParser) {
69
+ return parser(url);
70
+ }
71
+
58
72
  let _options;
59
73
  function compose(...funcs) {
60
74
  funcs = funcs.filter(func => typeof func === 'function');
@@ -81,8 +95,10 @@ function process$1(request, fn, processOpt) {
81
95
  _path = path;
82
96
  _queryString = queryString;
83
97
  }
98
+ // const requestQuery = { ...qs.parse(_queryString) }
99
+ // const requestQuery = { ...Object.fromEntries(new URLSearchParams(_queryString)) }
84
100
  const requestQuery = {
85
- ...qs__default["default"].parse(_queryString)
101
+ ...parseURLString(_queryString)
86
102
  };
87
103
  const query = {
88
104
  // defaults
@@ -95,10 +111,11 @@ function process$1(request, fn, processOpt) {
95
111
  const processPage = async (lastId, acc = []) => {
96
112
  // Use the lesser value between limit and itemsToGet in query
97
113
  const limit = query.limit < itemsToGet ? query.limit : itemsToGet;
98
- const originalQueryString = qs__default["default"].stringify({
114
+ // const originalQueryString = qs.stringify({ ...query, limit }, qsOptions)
115
+ const originalQueryString = new URLSearchParams({
99
116
  ...query,
100
117
  limit
101
- });
118
+ }).toString();
102
119
  const enhancedQuery = {
103
120
  sort: 'id asc',
104
121
  withTotal: false,
@@ -106,7 +123,8 @@ function process$1(request, fn, processOpt) {
106
123
  where: `id > "${lastId}"`
107
124
  } : {})
108
125
  };
109
- const enhancedQueryString = qs__default["default"].stringify(enhancedQuery);
126
+ // const enhancedQueryString = qs.stringify(enhancedQuery, qsOptions)
127
+ const enhancedQueryString = new URLSearchParams(enhancedQuery).toString();
110
128
  const enhancedRequest = {
111
129
  ...request,
112
130
  uri: `${_path}?${enhancedQueryString}&${originalQueryString}`
@@ -1021,7 +1039,7 @@ function createQueueMiddleware({
1021
1039
 
1022
1040
  var packageJson = {
1023
1041
  name: "@commercetools/sdk-client-v2",
1024
- version: "2.1.5",
1042
+ version: "2.2.0",
1025
1043
  engines: {
1026
1044
  node: ">=14"
1027
1045
  },
@@ -1055,8 +1073,7 @@ var packageJson = {
1055
1073
  },
1056
1074
  dependencies: {
1057
1075
  buffer: "^6.0.3",
1058
- "node-fetch": "^2.6.1",
1059
- querystring: "^0.2.1"
1076
+ "node-fetch": "^2.6.1"
1060
1077
  },
1061
1078
  files: [
1062
1079
  "dist",
@@ -1157,6 +1174,7 @@ class ClientBuilder {
1157
1174
  _defineProperty(this, "correlationIdMiddleware", void 0);
1158
1175
  _defineProperty(this, "loggerMiddleware", void 0);
1159
1176
  _defineProperty(this, "queueMiddleware", void 0);
1177
+ _defineProperty(this, "telemetryMiddleware", void 0);
1160
1178
  _defineProperty(this, "middlewares", []);
1161
1179
  }
1162
1180
  withProjectKey(key) {
@@ -1273,8 +1291,17 @@ class ClientBuilder {
1273
1291
  });
1274
1292
  return this;
1275
1293
  }
1294
+ withTelemetryMiddleware(options) {
1295
+ const {
1296
+ createTelemetryMiddleware,
1297
+ ...rest
1298
+ } = options;
1299
+ this.telemetryMiddleware = createTelemetryMiddleware(rest);
1300
+ return this;
1301
+ }
1276
1302
  build() {
1277
1303
  const middlewares = this.middlewares.slice();
1304
+ if (this.telemetryMiddleware) middlewares.push(this.telemetryMiddleware);
1278
1305
  if (this.correlationIdMiddleware) middlewares.push(this.correlationIdMiddleware);
1279
1306
  if (this.userAgentMiddleware) middlewares.push(this.userAgentMiddleware);
1280
1307
  if (this.authMiddleware) middlewares.push(this.authMiddleware);
@@ -3,13 +3,11 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var fetch$1 = require('node-fetch');
6
- var qs = require('querystring');
7
6
  var _ = require('buffer/');
8
7
 
9
8
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
10
9
 
11
10
  var fetch__default = /*#__PURE__*/_interopDefault(fetch$1);
12
- var qs__default = /*#__PURE__*/_interopDefault(qs);
13
11
 
14
12
  function _toPrimitive(input, hint) {
15
13
  if (typeof input !== "object" || input === null) return input;
@@ -55,6 +53,22 @@ function validate(funcName, request, options = {
55
53
  if (!options.allowedMethods.includes(request.method)) throw new Error(`The "${funcName}" Request object requires a valid method. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest`);
56
54
  }
57
55
 
56
+ function urlParser(url) {
57
+ const object = {};
58
+ const data = new URLSearchParams(url);
59
+ for (let x of data.keys()) {
60
+ if (data.getAll(x).length > 1) {
61
+ object[x] = data.getAll(x);
62
+ } else {
63
+ object[x] = data.get(x);
64
+ }
65
+ }
66
+ return object;
67
+ }
68
+ function parseURLString(url, parser = urlParser) {
69
+ return parser(url);
70
+ }
71
+
58
72
  let _options;
59
73
  function compose(...funcs) {
60
74
  funcs = funcs.filter(func => typeof func === 'function');
@@ -81,8 +95,10 @@ function process$1(request, fn, processOpt) {
81
95
  _path = path;
82
96
  _queryString = queryString;
83
97
  }
98
+ // const requestQuery = { ...qs.parse(_queryString) }
99
+ // const requestQuery = { ...Object.fromEntries(new URLSearchParams(_queryString)) }
84
100
  const requestQuery = {
85
- ...qs__default["default"].parse(_queryString)
101
+ ...parseURLString(_queryString)
86
102
  };
87
103
  const query = {
88
104
  // defaults
@@ -95,10 +111,11 @@ function process$1(request, fn, processOpt) {
95
111
  const processPage = async (lastId, acc = []) => {
96
112
  // Use the lesser value between limit and itemsToGet in query
97
113
  const limit = query.limit < itemsToGet ? query.limit : itemsToGet;
98
- const originalQueryString = qs__default["default"].stringify({
114
+ // const originalQueryString = qs.stringify({ ...query, limit }, qsOptions)
115
+ const originalQueryString = new URLSearchParams({
99
116
  ...query,
100
117
  limit
101
- });
118
+ }).toString();
102
119
  const enhancedQuery = {
103
120
  sort: 'id asc',
104
121
  withTotal: false,
@@ -106,7 +123,8 @@ function process$1(request, fn, processOpt) {
106
123
  where: `id > "${lastId}"`
107
124
  } : {})
108
125
  };
109
- const enhancedQueryString = qs__default["default"].stringify(enhancedQuery);
126
+ // const enhancedQueryString = qs.stringify(enhancedQuery, qsOptions)
127
+ const enhancedQueryString = new URLSearchParams(enhancedQuery).toString();
110
128
  const enhancedRequest = {
111
129
  ...request,
112
130
  uri: `${_path}?${enhancedQueryString}&${originalQueryString}`
@@ -1021,7 +1039,7 @@ function createQueueMiddleware({
1021
1039
 
1022
1040
  var packageJson = {
1023
1041
  name: "@commercetools/sdk-client-v2",
1024
- version: "2.1.5",
1042
+ version: "2.2.0",
1025
1043
  engines: {
1026
1044
  node: ">=14"
1027
1045
  },
@@ -1055,8 +1073,7 @@ var packageJson = {
1055
1073
  },
1056
1074
  dependencies: {
1057
1075
  buffer: "^6.0.3",
1058
- "node-fetch": "^2.6.1",
1059
- querystring: "^0.2.1"
1076
+ "node-fetch": "^2.6.1"
1060
1077
  },
1061
1078
  files: [
1062
1079
  "dist",
@@ -1157,6 +1174,7 @@ class ClientBuilder {
1157
1174
  _defineProperty(this, "correlationIdMiddleware", void 0);
1158
1175
  _defineProperty(this, "loggerMiddleware", void 0);
1159
1176
  _defineProperty(this, "queueMiddleware", void 0);
1177
+ _defineProperty(this, "telemetryMiddleware", void 0);
1160
1178
  _defineProperty(this, "middlewares", []);
1161
1179
  }
1162
1180
  withProjectKey(key) {
@@ -1273,8 +1291,17 @@ class ClientBuilder {
1273
1291
  });
1274
1292
  return this;
1275
1293
  }
1294
+ withTelemetryMiddleware(options) {
1295
+ const {
1296
+ createTelemetryMiddleware,
1297
+ ...rest
1298
+ } = options;
1299
+ this.telemetryMiddleware = createTelemetryMiddleware(rest);
1300
+ return this;
1301
+ }
1276
1302
  build() {
1277
1303
  const middlewares = this.middlewares.slice();
1304
+ if (this.telemetryMiddleware) middlewares.push(this.telemetryMiddleware);
1278
1305
  if (this.correlationIdMiddleware) middlewares.push(this.correlationIdMiddleware);
1279
1306
  if (this.userAgentMiddleware) middlewares.push(this.userAgentMiddleware);
1280
1307
  if (this.authMiddleware) middlewares.push(this.authMiddleware);
@@ -1,5 +1,4 @@
1
1
  import fetch$1 from 'node-fetch';
2
- import qs from 'querystring';
3
2
  import { Buffer } from 'buffer/';
4
3
 
5
4
  function _toPrimitive(input, hint) {
@@ -46,6 +45,22 @@ function validate(funcName, request, options = {
46
45
  if (!options.allowedMethods.includes(request.method)) throw new Error(`The "${funcName}" Request object requires a valid method. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest`);
47
46
  }
48
47
 
48
+ function urlParser(url) {
49
+ const object = {};
50
+ const data = new URLSearchParams(url);
51
+ for (let x of data.keys()) {
52
+ if (data.getAll(x).length > 1) {
53
+ object[x] = data.getAll(x);
54
+ } else {
55
+ object[x] = data.get(x);
56
+ }
57
+ }
58
+ return object;
59
+ }
60
+ function parseURLString(url, parser = urlParser) {
61
+ return parser(url);
62
+ }
63
+
49
64
  let _options;
50
65
  function compose(...funcs) {
51
66
  funcs = funcs.filter(func => typeof func === 'function');
@@ -72,8 +87,10 @@ function process$1(request, fn, processOpt) {
72
87
  _path = path;
73
88
  _queryString = queryString;
74
89
  }
90
+ // const requestQuery = { ...qs.parse(_queryString) }
91
+ // const requestQuery = { ...Object.fromEntries(new URLSearchParams(_queryString)) }
75
92
  const requestQuery = {
76
- ...qs.parse(_queryString)
93
+ ...parseURLString(_queryString)
77
94
  };
78
95
  const query = {
79
96
  // defaults
@@ -86,10 +103,11 @@ function process$1(request, fn, processOpt) {
86
103
  const processPage = async (lastId, acc = []) => {
87
104
  // Use the lesser value between limit and itemsToGet in query
88
105
  const limit = query.limit < itemsToGet ? query.limit : itemsToGet;
89
- const originalQueryString = qs.stringify({
106
+ // const originalQueryString = qs.stringify({ ...query, limit }, qsOptions)
107
+ const originalQueryString = new URLSearchParams({
90
108
  ...query,
91
109
  limit
92
- });
110
+ }).toString();
93
111
  const enhancedQuery = {
94
112
  sort: 'id asc',
95
113
  withTotal: false,
@@ -97,7 +115,8 @@ function process$1(request, fn, processOpt) {
97
115
  where: `id > "${lastId}"`
98
116
  } : {})
99
117
  };
100
- const enhancedQueryString = qs.stringify(enhancedQuery);
118
+ // const enhancedQueryString = qs.stringify(enhancedQuery, qsOptions)
119
+ const enhancedQueryString = new URLSearchParams(enhancedQuery).toString();
101
120
  const enhancedRequest = {
102
121
  ...request,
103
122
  uri: `${_path}?${enhancedQueryString}&${originalQueryString}`
@@ -1012,7 +1031,7 @@ function createQueueMiddleware({
1012
1031
 
1013
1032
  var packageJson = {
1014
1033
  name: "@commercetools/sdk-client-v2",
1015
- version: "2.1.5",
1034
+ version: "2.2.0",
1016
1035
  engines: {
1017
1036
  node: ">=14"
1018
1037
  },
@@ -1046,8 +1065,7 @@ var packageJson = {
1046
1065
  },
1047
1066
  dependencies: {
1048
1067
  buffer: "^6.0.3",
1049
- "node-fetch": "^2.6.1",
1050
- querystring: "^0.2.1"
1068
+ "node-fetch": "^2.6.1"
1051
1069
  },
1052
1070
  files: [
1053
1071
  "dist",
@@ -1148,6 +1166,7 @@ class ClientBuilder {
1148
1166
  _defineProperty(this, "correlationIdMiddleware", void 0);
1149
1167
  _defineProperty(this, "loggerMiddleware", void 0);
1150
1168
  _defineProperty(this, "queueMiddleware", void 0);
1169
+ _defineProperty(this, "telemetryMiddleware", void 0);
1151
1170
  _defineProperty(this, "middlewares", []);
1152
1171
  }
1153
1172
  withProjectKey(key) {
@@ -1264,8 +1283,17 @@ class ClientBuilder {
1264
1283
  });
1265
1284
  return this;
1266
1285
  }
1286
+ withTelemetryMiddleware(options) {
1287
+ const {
1288
+ createTelemetryMiddleware,
1289
+ ...rest
1290
+ } = options;
1291
+ this.telemetryMiddleware = createTelemetryMiddleware(rest);
1292
+ return this;
1293
+ }
1267
1294
  build() {
1268
1295
  const middlewares = this.middlewares.slice();
1296
+ if (this.telemetryMiddleware) middlewares.push(this.telemetryMiddleware);
1269
1297
  if (this.correlationIdMiddleware) middlewares.push(this.correlationIdMiddleware);
1270
1298
  if (this.userAgentMiddleware) middlewares.push(this.userAgentMiddleware);
1271
1299
  if (this.authMiddleware) middlewares.push(this.authMiddleware);
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["@commercetools/sdk-client-v2"]=t():e["@commercetools/sdk-client-v2"]=t()}(self,(()=>(()=>{var e={754:()=>{},169:()=>{},872:()=>{},696:()=>{},305:()=>{},52:()=>{},392:(e,t,r)=>{"use strict";r.d(t,{Z:()=>j});var n=r(872),o=r.n(n),i=r(202),a=r(584),s=r(554),c=r(352),u=r(637),l=r(589),h=r(386),d=r(349),f=r(357),p=r(324),y=r(406),w=function(){return w=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},w.apply(this,arguments)},v=u.Z,g=a.Z,m=s.Z,b=l.Z,C=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(C(e,w({force:t.force||!0},t)))},e.prototype.withHttpMiddleware=function(e){return this.httpMiddleware=(0,d.Z)(w({host:e.host||"https://api.europe-west1.gcp.commercetools.com",fetch:e.fetch||o()},e)),this},e.prototype.withUserAgentMiddleware=function(e){return this.userAgentMiddleware=(0,y.Z)(e),this},e.prototype.withQueueMiddleware=function(e){return this.queueMiddleware=(0,p.Z)(w({concurrency:e.concurrency||20},e)),this},e.prototype.withLoggerMiddleware=function(){return this.loggerMiddleware=(0,f.Z)(),this},e.prototype.withCorrelationIdMiddleware=function(e){return this.correlationIdMiddleware=(0,h.Z)(w({generate:e.generate||null},e)),this},e.prototype.build=function(){var e=this.middlewares.slice();return this.correlationIdMiddleware&&e.push(this.correlationIdMiddleware),this.userAgentMiddleware&&e.push(this.userAgentMiddleware),this.authMiddleware&&e.push(this.authMiddleware),this.queueMiddleware&&e.push(this.queueMiddleware),this.httpMiddleware&&e.push(this.httpMiddleware),this.loggerMiddleware&&e.push(this.loggerMiddleware),(0,i.Z)({middlewares:e})},e}()},202:(e,t,r)=>{"use strict";r.d(t,{Z:()=>f,N:()=>d});var n=r(305),o=r.n(n);const i=["ACL","BIND","CHECKOUT","CONNECT","COPY","DELETE","GET","HEAD","LINK","LOCK","M-SEARCH","MERGE","MKACTIVITY","MKCALENDAR","MKCOL","MOVE","NOTIFY","OPTIONS","PATCH","POST","PROPFIND","PROPPATCH","PURGE","PUT","REBIND","REPORT","SEARCH","SOURCE","SUBSCRIBE","TRACE","UNBIND","UNLINK","UNLOCK","UNSUBSCRIBE"];function a(e,t,r){if(void 0===r&&(r={allowedMethods:i}),!t)throw new Error('The "'.concat(e,'" function requires a "Request" object as an argument. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest'));if("string"!=typeof t.uri)throw new Error('The "'.concat(e,'" Request object requires a valid uri. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest'));if(!r.allowedMethods.includes(t.method))throw new Error('The "'.concat(e,'" Request object requires a valid method. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest'))}var s,c=function(){return c=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},c.apply(this,arguments)},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])}}};function h(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return 1===(e=e.filter((function(e){return"function"==typeof e}))).length?e[0]:e.reduce((function(e,t){return function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return e(t.apply(void 0,r))}}))}function d(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 h,d="";if(e&&e.uri){var p=e.uri.split("?"),y=p[0],w=p[1];h=y,d=w}var v=c({},o().parse(d)),g=c({limit:20},v),m=!1,b=i.total,C=function(d,p){return void 0===p&&(p=[]),u(n,void 0,void 0,(function(){var n,u,y,w,v,j,O,M,k,E,T,A,q,S;return l(this,(function(l){switch(l.label){case 0:n=g.limit<b?g.limit:b,u=o().stringify(c(c({},g),{limit:n})),y=c({sort:"id asc",withTotal:!1},d?{where:'id > "'.concat(d,'"')}:{}),w=o().stringify(y),v=c(c({},e),{uri:"".concat(h,"?").concat(w,"&").concat(u)}),l.label=1;case 1:return l.trys.push([1,4,,5]),[4,f(s).execute(v)];case 2:return j=l.sent(),O=j.body,M=O.results,!(k=O.count)&&m?[2,r(p||[])]:[4,Promise.resolve(t(j))];case 3:return E=l.sent(),T=void 0,m=!0,i.accumulate&&(T=p.concat(E||[])),b-=k,k<g.limit||!b?[2,r(T||[])]:(A=M[k-1],q=A&&A.id,C(q,T),[3,5]);case 4:return S=l.sent(),a(S),[3,5];case 5:return[2]}}))}))};C()}))}function f(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:d,execute:function(t){return a("exec",t),new Promise((function(r,n){h.apply(void 0,e.middlewares)((function(e,t){if(t.error)t.reject(t.error);else{var r={body:t.body||{},statusCode:t.statusCode};t.headers&&(r.headers=t.headers),t.request&&(r.request=t.request),t.resolve(r)}}))(t,{resolve:r,reject:n,body:void 0,error:void 0})}))}}}},109:(e,t,r)=>{"use strict";r.d(t,{F7:()=>i,ZP:()=>p,oo:()=>a});var n=function(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))};function o(e,t,r){void 0===r&&(r={}),this.status=this.statusCode=this.code=e,this.message=t,Object.assign(this,r),this.name=this.constructor.name,this.constructor.prototype.__proto__=Error.prototype,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}function i(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,0],e,!1))}function a(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this],e,!1))}function s(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,400],e,!1))}function c(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,401],e,!1))}function u(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,403],e,!1))}function l(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,404],e,!1))}function h(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,409],e,!1))}function d(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,500],e,!1))}function f(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.call.apply(o,n([this,503],e,!1))}function p(e){switch(e){case 0:return i;case 400:return s;case 401:return c;case 403:return u;case 404:return l;case 409:return h;case 500:return d;case 503:return f;default:return}}},584:(e,t,r)=>{"use strict";r.d(t,{Z:()=>s});var n=r(893),o=r(935),i=r(156),a=function(){return a=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},a.apply(this,arguments)};function s(e){var t=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,C,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 C=new Error(m?m.message:b),m&&(C.body=m),l.set(!1),d.reject(C),[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:()=>h});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};function c(e){return null!=e&&null!=e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function u(e,t,r,n,o){return n&&0!==e?Math.min(Math.round((Math.random()+1)*t*Math.pow(2,e)),o):t}function l(e,t){t&&(e&&e.headers&&e.headers.authorization&&(e.headers.authorization="Bearer ********"),e&&e.headers&&e.headers.Authorization&&(e.headers.Authorization="Bearer ********"))}function h(e){var t,r=e.host,h=e.credentialsMode,d=e.includeResponseHeaders,f=e.includeOriginalRequest,p=e.includeRequestInErrorResponse,y=void 0===p||p,w=e.maskSensitiveHeaderData,v=void 0===w||w,g=e.enableRetry,m=e.timeout,b=e.retryConfig,C=void 0===b?{}:b,j=C.maxRetries,O=void 0===j?10:j,M=C.backoff,k=void 0===M||M,E=C.retryDelay,T=void 0===E?200:E,A=C.maxDelay,q=void 0===A?1/0:A,S=C.retryOnAbort,P=void 0!==S&&S,Z=C.retryCodes,I=void 0===Z?[503]:Z,x=e.fetch,K=e.getAbortController;if(!x)throw new Error("`fetch` is not available. Please pass in `fetch` as an option or have it globally available.");if(m&&!K)throw new Error("`AbortController` is not available. Please pass in `getAbortController` as an option or have AbortController globally available when using timeout.");if(t=x||fetch,!Array.isArray(I))throw new Error("`retryCodes` option must be an array of retry status (error) codes.");return function(e){return function(p,w){var b=r.replace(/\/$/,"")+p.uri,C=a({},p.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 j=["application/json","application/graphql"].indexOf(C["Content-Type"])>-1&&"string"==typeof p.body||c(p.body)?p.body:JSON.stringify(p.body||void 0);j&&("string"==typeof j||c(j))&&(C["Content-Length"]=n.Buffer.byteLength(j).toString());var M={method:p.method,headers:C};h&&(M.credentialsMode=h),j&&(M.body=j);var E=0;!function r(){var n,c;m&&(c=(K?K():null)||new AbortController,M.signal=c.signal,n=setTimeout((function(){c.abort()}),m)),t(b,M).then((function(t){if(t.ok)return"HEAD"===M.method?void e(p,a(a({},w),{statusCode:t.status})):void t.text().then((function(n){var o;try{o=n.length>0?JSON.parse(n):{}}catch(e){if(g&&E<O)return setTimeout(r,u(E,T,0,k,q)),void(E+=1);o=n}var s=a(a({},w),{body:o,statusCode:t.status});d&&(s.headers=i(t.headers)),f&&(s.request=a({},M),l(s.request,v)),e(p,s)})).catch((function(t){if(g&&E<O)return setTimeout(r,u(E,T,0,k,q)),void(E+=1);var n=new o.F7(t.message,a(a({},y?{originalRequest:p}:{}),{retryCount:E}));l(n.originalRequest,v),e(p,a(a({},w),{error:n,statusCode:0}))}));t.text().then((function(n){var c;try{c=JSON.parse(n)}catch(h){c=n}var h=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},y?{originalRequest:p}:404===t.status?{uri:p.uri}:{}),{retryCount:E,headers:i(t.headers)}),"object"==typeof c?{message:c.message,body:c}:{message:c,body:c}));if(g&&(-1!==I.indexOf(h.statusCode)||-1!==(null==I?void 0:I.indexOf(h.message)))&&E<O)return setTimeout(r,u(E,T,0,k,q)),void(E+=1);l(h.originalRequest,v);var d=a(a({},w),{error:h,statusCode:t.status});e(p,d)}))}),(function(t){if(g&&(P||!c||!c.signal)&&E<O)return setTimeout(r,u(E,T,0,k,q)),void(E+=1);var n=new o.F7(t.message,a(a({},y?{originalRequest:p}:{}),{retryCount:E}));l(n.originalRequest,v),e(p,a(a({},w),{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.1.5"};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(202),o=r(109),i=r(584),a=r(554),s=r(352),c=r(637),u=r(589),l=r(386),h=r(349),d=r(357),f=r(324),p=r(406),y=r(52),w={};for(const e in y)["default","ClientBuilder","createClient","Process","getErrorByCode","createAuthForAnonymousSessionFlow","createAuthForClientCredentialsFlow","createAuthWithExistingToken","createAuthForPasswordFlow","createAuthForRefreshTokenFlow","createCorrelationIdMiddleware","createHttpClient","createLoggerMiddleware","createQueueMiddleware","createUserAgentMiddleware"].indexOf(e)<0&&(w[e]=()=>y[e]);r.d(n,w)})(),n})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["@commercetools/sdk-client-v2"]=t():e["@commercetools/sdk-client-v2"]=t()}(self,(()=>(()=>{var e={754:()=>{},169:()=>{},872:()=>{},696:()=>{},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.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});const n=["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 o(e,t,r){if(void 0===r&&(r={allowedMethods:n}),!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 i=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 a(e){var t,r,n={},o=new URLSearchParams(e);try{for(var a=i(o.keys()),s=a.next();!s.done;s=a.next()){var c=s.value;o.getAll(c).length>1?n[c]=o.getAll(c):n[c]=o.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}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(o("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,o){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=a),g(f))),b=c({limit:20},m),O=!1,j=i.total,C=function(a,h){return void 0===h&&(h=[]),u(n,void 0,void 0,(function(){var n,u,f,p,w,v,g,m,M,k,E,S,T,A;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},a?{where:'id > "'.concat(a,'"')}:{}),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(),E=void 0,O=!0,i.accumulate&&(E=h.concat(k||[])),j-=M,M<b.limit||!j?[2,r(E||[])]:(S=m[M-1],T=S&&S.id,C(T,E),[3,5]);case 4:return A=l.sent(),o(A),[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 o("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:()=>h});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};function c(e){return null!=e&&null!=e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function u(e,t,r,n,o){return n&&0!==e?Math.min(Math.round((Math.random()+1)*t*Math.pow(2,e)),o):t}function l(e,t){t&&(e&&e.headers&&e.headers.authorization&&(e.headers.authorization="Bearer ********"),e&&e.headers&&e.headers.Authorization&&(e.headers.Authorization="Bearer ********"))}function h(e){var t,r=e.host,h=e.credentialsMode,d=e.includeResponseHeaders,f=e.includeOriginalRequest,p=e.includeRequestInErrorResponse,y=void 0===p||p,w=e.maskSensitiveHeaderData,v=void 0===w||w,g=e.enableRetry,m=e.timeout,b=e.retryConfig,O=void 0===b?{}:b,j=O.maxRetries,C=void 0===j?10:j,M=O.backoff,k=void 0===M||M,E=O.retryDelay,S=void 0===E?200:E,T=O.maxDelay,A=void 0===T?1/0:T,q=O.retryOnAbort,P=void 0!==q&&q,x=O.retryCodes,Z=void 0===x?[503]:x,I=e.fetch,R=e.getAbortController;if(!I)throw new Error("`fetch` is not available. Please pass in `fetch` as an option or have it globally available.");if(m&&!R)throw new Error("`AbortController` is not available. Please pass in `getAbortController` as an option or have AbortController globally available when using timeout.");if(t=I||fetch,!Array.isArray(Z))throw new Error("`retryCodes` option must be an array of retry status (error) codes.");return function(e){return function(p,w){var b=r.replace(/\/$/,"")+p.uri,O=a({},p.headers);Object.prototype.hasOwnProperty.call(O,"Content-Type")||Object.prototype.hasOwnProperty.call(O,"content-type")||(O["Content-Type"]="application/json"),null===O["Content-Type"]&&delete O["Content-Type"];var j=["application/json","application/graphql"].indexOf(O["Content-Type"])>-1&&"string"==typeof p.body||c(p.body)?p.body:JSON.stringify(p.body||void 0);j&&("string"==typeof j||c(j))&&(O["Content-Length"]=n.Buffer.byteLength(j).toString());var M={method:p.method,headers:O};h&&(M.credentialsMode=h),j&&(M.body=j);var E=0;!function r(){var n,c;m&&(c=(R?R():null)||new AbortController,M.signal=c.signal,n=setTimeout((function(){c.abort()}),m)),t(b,M).then((function(t){if(t.ok)return"HEAD"===M.method?void e(p,a(a({},w),{statusCode:t.status})):void t.text().then((function(n){var o;try{o=n.length>0?JSON.parse(n):{}}catch(e){if(g&&E<C)return setTimeout(r,u(E,S,0,k,A)),void(E+=1);o=n}var s=a(a({},w),{body:o,statusCode:t.status});d&&(s.headers=i(t.headers)),f&&(s.request=a({},M),l(s.request,v)),e(p,s)})).catch((function(t){if(g&&E<C)return setTimeout(r,u(E,S,0,k,A)),void(E+=1);var n=new o.F7(t.message,a(a({},y?{originalRequest:p}:{}),{retryCount:E}));l(n.originalRequest,v),e(p,a(a({},w),{error:n,statusCode:0}))}));t.text().then((function(n){var c;try{c=JSON.parse(n)}catch(h){c=n}var h=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},y?{originalRequest:p}:404===t.status?{uri:p.uri}:{}),{retryCount:E,headers:i(t.headers)}),"object"==typeof c?{message:c.message,body:c}:{message:c,body:c}));if(g&&(-1!==Z.indexOf(h.statusCode)||-1!==(null==Z?void 0:Z.indexOf(h.message)))&&E<C)return setTimeout(r,u(E,S,0,k,A)),void(E+=1);l(h.originalRequest,v);var d=a(a({},w),{error:h,statusCode:t.status});e(p,d)}))}),(function(t){if(g&&(P||!c||!c.signal)&&E<C)return setTimeout(r,u(E,S,0,k,A)),void(E+=1);var n=new o.F7(t.message,a(a({},y?{originalRequest:p}:{}),{retryCount:E}));l(n.originalRequest,v),e(p,a(a({},w),{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.2.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,4 +1,4 @@
1
- import { AnonymousAuthMiddlewareOptions, AuthMiddlewareOptions, Client, CorrelationIdMiddlewareOptions, Credentials, ExistingTokenMiddlewareOptions, HttpMiddlewareOptions, HttpUserAgentOptions, Middleware, PasswordAuthMiddlewareOptions, QueueMiddlewareOptions, RefreshAuthMiddlewareOptions } from '../types/sdk';
1
+ import { AnonymousAuthMiddlewareOptions, TelemetryOptions, AuthMiddlewareOptions, Client, CorrelationIdMiddlewareOptions, Credentials, ExistingTokenMiddlewareOptions, HttpMiddlewareOptions, HttpUserAgentOptions, Middleware, PasswordAuthMiddlewareOptions, QueueMiddlewareOptions, RefreshAuthMiddlewareOptions } from '../types/sdk';
2
2
  export default class ClientBuilder {
3
3
  private projectKey;
4
4
  private authMiddleware;
@@ -7,6 +7,7 @@ export default class ClientBuilder {
7
7
  private correlationIdMiddleware;
8
8
  private loggerMiddleware;
9
9
  private queueMiddleware;
10
+ private telemetryMiddleware;
10
11
  private middlewares;
11
12
  withProjectKey(key: string): ClientBuilder;
12
13
  defaultClient(baseUri: string, credentials: Credentials, oauthUri?: string, projectKey?: string): ClientBuilder;
@@ -22,5 +23,6 @@ export default class ClientBuilder {
22
23
  withQueueMiddleware(options: QueueMiddlewareOptions): ClientBuilder;
23
24
  withLoggerMiddleware(): this;
24
25
  withCorrelationIdMiddleware(options: CorrelationIdMiddlewareOptions): ClientBuilder;
26
+ withTelemetryMiddleware<T extends TelemetryOptions<T>>(options: T): ClientBuilder;
25
27
  build(): Client;
26
28
  }
@@ -523,3 +523,14 @@ export type ExistingTokenMiddlewareOptions = {
523
523
  export type CorrelationIdMiddlewareOptions = {
524
524
  generate: () => string
525
525
  }
526
+
527
+ // // TODO: specify specific options
528
+ // // export type ApmMiddlewareOptions = Record<string, any>
529
+ // export type ApmMiddlewareOptions = {
530
+ // createApmMiddleware: (options?: any) => Middleware,
531
+ // apm: any
532
+ // }
533
+
534
+ export type TelemetryOptions<T> = {
535
+ createTelemetryMiddleware: (options?: Omit<T, 'createTelemetryMiddleware'>) => Middleware
536
+ }
@@ -0,0 +1 @@
1
+ export { stringifyURLString, parseURLString } from './url';
@@ -0,0 +1,2 @@
1
+ export declare function parseURLString<T>(url: string | URLSearchParams, parser?: <T>(url: string | URLSearchParams) => T): T;
2
+ export declare function stringifyURLString(object: string | Record<string, any> | Array<Array<string>>, stringifier?: (object: string | Record<string, any> | Array<Array<string>> | URLSearchParams) => string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools/sdk-client-v2",
3
- "version": "2.1.5",
3
+ "version": "2.2.0",
4
4
  "engines": {
5
5
  "node": ">=14"
6
6
  },
@@ -34,8 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "buffer": "^6.0.3",
37
- "node-fetch": "^2.6.1",
38
- "querystring": "^0.2.1"
37
+ "node-fetch": "^2.6.1"
39
38
  },
40
39
  "files": ["dist", "CHANGELOG.md"],
41
40
  "author": "Chukwuemeka Ajima <meeky.ae@gmail.com>",